rEFIt_UEFI/Platform/Edid.cpp
//Used at OS start
// if EFI_SUCCESS then result in gSettings.Graphics.EDID.CustomEDID != NULL
// first priority is CustomEDID
// second is UEFI EDID from EdidDiscoveredProtocol
Used at OS start
if EFI_SUCCESS then result in gSettings.Graphics.EDID.CustomEDID != NULL
first priority is CustomEDID
second is UEFI EDID from EdidDiscoveredProtocol
Used at OS start if EFI_SUCCESS then result in gSettings . Graphics . EDID . CustomEDID ! = NULL first priority is CustomEDID second is UEFI EDID from EdidDiscoveredProtocol
EFI_STATUS GetEdidDiscovered(void)
{
  EFI_STATUS  Status = EFI_SUCCESS;
  UINTN       N = 0;
  UINT8       NewChecksum;
  if (gSettings.Graphics.EDID.CustomEDID.notEmpty()) {
    N = gSettings.Graphics.EDID.CustomEDID.size();
    DebugDumpEDID("--- Custom EDID Table", N);
  } else {
    Status = gBS->LocateProtocol (&gEfiEdidDiscoveredProtocolGuid, NULL, (void **)&EdidDiscovered);
    if (!EFI_ERROR(Status)) { 
      N = EdidDiscovered->SizeOfEdid;
      if (!gSettings.Boot.DebugLog) {
		  DBG("EdidDiscovered size=%llu\n", N);
      }
      if (N == 0) {
        return EFI_NOT_FOUND;
      }
      gSettings.Graphics.EDID.CustomEDID.ncpy(EdidDiscovered->Edid, N);
      DebugDumpEDID("--- Discovered EDID Table", N);
    }
  }
  if (gSettings.Graphics.EDID.CustomEDID.notEmpty()) {
    if (gSettings.Graphics.EDID.VendorEDID) {
		DBG("    VendorID = 0x%04hx changed to 0x%04hx\n", ((UINT16*)gSettings.Graphics.EDID.CustomEDID.data())[4], gSettings.Graphics.EDID.VendorEDID);
      ((UINT16*)gSettings.Graphics.EDID.CustomEDID.data())[4] = gSettings.Graphics.EDID.VendorEDID;
    }
    if (gSettings.Graphics.EDID.ProductEDID) {
		DBG("    ProductID = 0x%04hx changed to 0x%04hx\n", ((UINT16*)gSettings.Graphics.EDID.CustomEDID.data())[5], gSettings.Graphics.EDID.ProductEDID);
      ((UINT16*)gSettings.Graphics.EDID.CustomEDID.data())[5] = gSettings.Graphics.EDID.ProductEDID;
    }
    if (gSettings.Graphics.EDID.EdidFixHorizontalSyncPulseWidth) {
		DBG("    HorizontalSyncPulseWidth = 0x%02hhx changed to 0x%02hx\n", ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[63], gSettings.Graphics.EDID.EdidFixHorizontalSyncPulseWidth);
      UINT8 LsBits, MsBits;
      LsBits = gSettings.Graphics.EDID.EdidFixHorizontalSyncPulseWidth & 0xff;
      MsBits = (gSettings.Graphics.EDID.EdidFixHorizontalSyncPulseWidth >> 8) & 0x03;
      ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[63] = LsBits;
      LsBits = ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[65] & ~0x30;
      ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[65] = LsBits | (MsBits << 4);
    }
    if (gSettings.Graphics.EDID.EdidFixVideoInputSignal) {
		DBG("    VideoInputSignal = 0x%02hhx changed to 0x%02hhx\n", ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[20], gSettings.Graphics.EDID.EdidFixVideoInputSignal);
      ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[20] = gSettings.Graphics.EDID.EdidFixVideoInputSignal;
    }
    NewChecksum = (UINT8)(256 - Checksum8(gSettings.Graphics.EDID.CustomEDID.data(), 127));
    if ((gSettings.Graphics.EDID.VendorEDID) || (gSettings.Graphics.EDID.ProductEDID) || (gSettings.Graphics.EDID.EdidFixHorizontalSyncPulseWidth) || (gSettings.Graphics.EDID.EdidFixVideoInputSignal)) {
      ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[127] = NewChecksum;
      DebugDumpEDID("--- Patched EDID Table", N);
    } else if (((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[127] != NewChecksum) {
		DBG("    Fix wrong checksum = 0x%02hhx changed to ", ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[127]);
      ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[127] = NewChecksum;
		DBG("0x%02hhx\n", ((UINT8*)gSettings.Graphics.EDID.CustomEDID.data())[127]);
      DebugDumpEDID("--- Patched EDID Table", N);
    }
  }
  return Status;
}
EFI_STATUS GetEdidDiscovered ( void ) { EFI_STATUS Status = EFI_SUCCESS ; UINTN N = 0 ; UINT8 NewChecksum ; if ( gSettings . Graphics . EDID . CustomEDID . notEmpty ( ) ) { N = gSettings . Graphics . EDID . CustomEDID . size ( ) ; DebugDumpEDID ( " " , N ) ; } else { Status = gBS -> LocateProtocol ( & gEfiEdidDiscoveredProtocolGuid , NULL , ( void * * ) & EdidDiscovered ) ; if ( ! EFI_ERROR ( Status ) ) { N = EdidDiscovered -> SizeOfEdid ; if ( ! gSettings . Boot . DebugLog ) { DBG ( " \n " , N ) ; } if ( N == 0 ) { return EFI_NOT_FOUND ; } gSettings . Graphics . EDID . CustomEDID . ncpy ( EdidDiscovered -> Edid , N ) ; DebugDumpEDID ( " " , N ) ; } } if ( gSettings . Graphics . EDID . CustomEDID . notEmpty ( ) ) { if ( gSettings . Graphics . EDID . VendorEDID ) { DBG ( " \n " , ( ( UINT16 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 4 ] , gSettings . Graphics . EDID . VendorEDID ) ; ( ( UINT16 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 4 ] = gSettings . Graphics . EDID . VendorEDID ; } if ( gSettings . Graphics . EDID . ProductEDID ) { DBG ( " \n " , ( ( UINT16 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 5 ] , gSettings . Graphics . EDID . ProductEDID ) ; ( ( UINT16 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 5 ] = gSettings . Graphics . EDID . ProductEDID ; } if ( gSettings . Graphics . EDID . EdidFixHorizontalSyncPulseWidth ) { DBG ( " \n " , ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 63 ] , gSettings . Graphics . EDID . EdidFixHorizontalSyncPulseWidth ) ; UINT8 LsBits , MsBits ; LsBits = gSettings . Graphics . EDID . EdidFixHorizontalSyncPulseWidth & 0xff ; MsBits = ( gSettings . Graphics . EDID . EdidFixHorizontalSyncPulseWidth >> 8 ) & 0x03 ; ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 63 ] = LsBits ; LsBits = ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 65 ] & ~ 0x30 ; ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 65 ] = LsBits | ( MsBits << 4 ) ; } if ( gSettings . Graphics . EDID . EdidFixVideoInputSignal ) { DBG ( " \n " , ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 20 ] , gSettings . Graphics . EDID . EdidFixVideoInputSignal ) ; ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 20 ] = gSettings . Graphics . EDID . EdidFixVideoInputSignal ; } NewChecksum = ( UINT8 ) ( 256 - Checksum8 ( gSettings . Graphics . EDID . CustomEDID . data ( ) , 127 ) ) ; if ( ( gSettings . Graphics . EDID . VendorEDID ) || ( gSettings . Graphics . EDID . ProductEDID ) || ( gSettings . Graphics . EDID . EdidFixHorizontalSyncPulseWidth ) || ( gSettings . Graphics . EDID . EdidFixVideoInputSignal ) ) { ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 127 ] = NewChecksum ; DebugDumpEDID ( " " , N ) ; } else if ( ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 127 ] != NewChecksum ) { DBG ( " " , ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 127 ] ) ; ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 127 ] = NewChecksum ; DBG ( " \n " , ( ( UINT8 * ) gSettings . Graphics . EDID . CustomEDID . data ( ) ) [ 127 ] ) ; DebugDumpEDID ( " " , N ) ; } } return Status ; }
Used at OS start
if EFI_SUCCESS then result in gSettings.Graphics.EDID.CustomEDID != NULL
first priority is CustomEDID
second is UEFI EDID from EdidDiscoveredProtocol
Used at OS start if EFI_SUCCESS then result in gSettings . Graphics . EDID . CustomEDID ! = NULL first priority is CustomEDID second is UEFI EDID from EdidDiscoveredProtocol
//gEDID       = NULL; //discovered //      gSettings.Graphics.EDID.CustomEDID = (__typeof__(gSettings.Graphics.EDID.CustomEDID))AllocateAlignedPages(EFI_SIZE_TO_PAGES(N), 128); // begin patching result