2019-09-03 11:58:42 +02:00
|
|
|
//Slice 2013
|
|
|
|
|
2020-08-17 21:40:52 +02:00
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
2020-04-16 09:15:26 +02:00
|
|
|
#include "AcpiPatcher.h"
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
#ifndef DEBUG_ALL
|
|
|
|
#define DEBUG_EDID 1
|
|
|
|
#else
|
|
|
|
#define DEBUG_EDID DEBUG_ALL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG_EDID == 0
|
|
|
|
#define DBG(...)
|
|
|
|
#else
|
|
|
|
#define DBG(...) DebugLog(DEBUG_EDID, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EFI_STATUS EFIAPI GetEdidImpl(
|
|
|
|
IN EFI_EDID_OVERRIDE_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE *ChildHandle,
|
|
|
|
OUT UINT32 *Attributes,
|
|
|
|
IN OUT UINTN *EdidSize,
|
|
|
|
IN OUT UINT8 **Edid
|
|
|
|
)
|
|
|
|
{
|
|
|
|
*Edid = gSettings.CustomEDID;
|
|
|
|
*EdidSize = 128;
|
|
|
|
*Attributes = 0;
|
|
|
|
if (*Edid) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_EDID_OVERRIDE_PROTOCOL gEdidOverride =
|
|
|
|
{
|
|
|
|
GetEdidImpl
|
|
|
|
};
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
InitializeEdidOverride ()
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_EDID_OVERRIDE_PROTOCOL *EdidOverride;
|
|
|
|
|
2019-12-21 01:31:49 +01:00
|
|
|
EdidOverride = (__typeof__(EdidOverride))AllocateCopyPool(sizeof(EFI_EDID_OVERRIDE_PROTOCOL), &gEdidOverride);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&gImageHandle,
|
|
|
|
&gEfiEdidOverrideProtocolGuid,
|
|
|
|
EdidOverride,
|
|
|
|
NULL
|
|
|
|
);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
DBG("Can't install EdidOverride on ImageHandle\n");
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//used only if VBiosPatchNeeded and if no CustomEDID
|
2020-10-03 19:02:31 +02:00
|
|
|
UINT8* getCurrentEdid (void)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_EDID_ACTIVE_PROTOCOL *EdidProtocol;
|
|
|
|
UINT8 *Edid;
|
|
|
|
|
2020-04-23 18:05:21 +02:00
|
|
|
DBG("EdidActive:");
|
2019-09-03 11:58:42 +02:00
|
|
|
Edid = NULL;
|
2020-10-03 19:02:31 +02:00
|
|
|
Status = gBS->LocateProtocol (&gEfiEdidActiveProtocolGuid, NULL, (void**)&EdidProtocol);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
DBG(" size=%d", EdidProtocol->SizeOfEdid);
|
|
|
|
if (EdidProtocol->SizeOfEdid > 0) {
|
2020-04-27 17:16:43 +02:00
|
|
|
Edid = (__typeof__(Edid))AllocateCopyPool(EdidProtocol->SizeOfEdid, EdidProtocol->Edid);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG(" %s\n", Edid != NULL ? "found" : "not found");
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
return Edid;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:02:31 +02:00
|
|
|
void DebugDumpEDID(CONST CHAR8 *Message, INTN N)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
INTN i,j;
|
|
|
|
// Don't dump in the case of debug logging because of too slow output
|
2021-02-02 10:02:21 +01:00
|
|
|
if (gSettings.Boot.DebugLog) {
|
2019-09-03 11:58:42 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG("%s size:%lld\n", Message, N);
|
2019-09-03 11:58:42 +02:00
|
|
|
for (i=0; i<N; i+=10) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG("%03lld |", i);
|
2019-09-03 11:58:42 +02:00
|
|
|
for (j=0; j<10; j++) {
|
|
|
|
if (i+j > N-1) break;
|
2020-04-17 15:14:24 +02:00
|
|
|
DBG(" %02hhX", gSettings.CustomEDID[i+j]);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
DBG("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Used at OS start
|
|
|
|
// if EFI_SUCCESS then result in gSettings.CustomEDID != NULL
|
|
|
|
// first priority is CustomEDID
|
|
|
|
// second is UEFI EDID from EdidDiscoveredProtocol
|
2020-10-03 19:02:31 +02:00
|
|
|
EFI_STATUS GetEdidDiscovered(void)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status = EFI_SUCCESS;
|
|
|
|
UINTN N = 0;
|
|
|
|
UINT8 NewChecksum;
|
|
|
|
//gEDID = NULL;
|
|
|
|
|
|
|
|
if (gSettings.CustomEDID) {
|
|
|
|
N = gSettings.CustomEDIDsize;
|
|
|
|
DebugDumpEDID("--- Custom EDID Table", N);
|
|
|
|
} else {
|
2020-10-03 19:02:31 +02:00
|
|
|
Status = gBS->LocateProtocol (&gEfiEdidDiscoveredProtocolGuid, NULL, (void **)&EdidDiscovered);
|
2020-04-23 11:08:10 +02:00
|
|
|
if (!EFI_ERROR(Status)) { //discovered
|
2019-09-03 11:58:42 +02:00
|
|
|
N = EdidDiscovered->SizeOfEdid;
|
2021-02-02 10:02:21 +01:00
|
|
|
if (!gSettings.Boot.DebugLog) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG("EdidDiscovered size=%llu\n", N);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
if (N == 0) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
2019-12-21 01:31:49 +01:00
|
|
|
gSettings.CustomEDID = (__typeof__(gSettings.CustomEDID))AllocateAlignedPages(EFI_SIZE_TO_PAGES(N), 128);
|
2019-09-03 11:58:42 +02:00
|
|
|
CopyMem(gSettings.CustomEDID, EdidDiscovered->Edid, N);
|
|
|
|
DebugDumpEDID("--- Discovered EDID Table", N);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.CustomEDID) {
|
|
|
|
// begin patching result
|
|
|
|
if (gSettings.VendorEDID) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG(" VendorID = 0x%04hx changed to 0x%04hx\n", ((UINT16*)gSettings.CustomEDID)[4], gSettings.VendorEDID);
|
2019-09-03 11:58:42 +02:00
|
|
|
((UINT16*)gSettings.CustomEDID)[4] = gSettings.VendorEDID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.ProductEDID) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG(" ProductID = 0x%04hx changed to 0x%04hx\n", ((UINT16*)gSettings.CustomEDID)[5], gSettings.ProductEDID);
|
2019-09-03 11:58:42 +02:00
|
|
|
((UINT16*)gSettings.CustomEDID)[5] = gSettings.ProductEDID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.EdidFixHorizontalSyncPulseWidth) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG(" HorizontalSyncPulseWidth = 0x%02hhx changed to 0x%02hx\n", ((UINT8*)gSettings.CustomEDID)[63], gSettings.EdidFixHorizontalSyncPulseWidth);
|
2019-09-03 11:58:42 +02:00
|
|
|
UINT8 LsBits, MsBits;
|
|
|
|
LsBits = gSettings.EdidFixHorizontalSyncPulseWidth & 0xff;
|
|
|
|
MsBits = (gSettings.EdidFixHorizontalSyncPulseWidth >> 8) & 0x03;
|
|
|
|
((UINT8*)gSettings.CustomEDID)[63] = LsBits;
|
|
|
|
LsBits = ((UINT8*)gSettings.CustomEDID)[65] & ~0x30;
|
|
|
|
((UINT8*)gSettings.CustomEDID)[65] = LsBits | (MsBits << 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSettings.EdidFixVideoInputSignal) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG(" VideoInputSignal = 0x%02hhx changed to 0x%02hhx\n", ((UINT8*)gSettings.CustomEDID)[20], gSettings.EdidFixVideoInputSignal);
|
2019-09-03 11:58:42 +02:00
|
|
|
((UINT8*)gSettings.CustomEDID)[20] = gSettings.EdidFixVideoInputSignal;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewChecksum = (UINT8)(256 - Checksum8(gSettings.CustomEDID, 127));
|
|
|
|
if ((gSettings.VendorEDID) || (gSettings.ProductEDID) || (gSettings.EdidFixHorizontalSyncPulseWidth) || (gSettings.EdidFixVideoInputSignal)) {
|
|
|
|
((UINT8*)gSettings.CustomEDID)[127] = NewChecksum;
|
|
|
|
DebugDumpEDID("--- Patched EDID Table", N);
|
|
|
|
} else if (((UINT8*)gSettings.CustomEDID)[127] != NewChecksum) {
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG(" Fix wrong checksum = 0x%02hhx changed to ", ((UINT8*)gSettings.CustomEDID)[127]);
|
2019-09-03 11:58:42 +02:00
|
|
|
((UINT8*)gSettings.CustomEDID)[127] = NewChecksum;
|
2020-03-25 19:32:44 +01:00
|
|
|
DBG("0x%02hhx\n", ((UINT8*)gSettings.CustomEDID)[127]);
|
2019-09-03 11:58:42 +02:00
|
|
|
DebugDumpEDID("--- Patched EDID Table", N);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|