Skip to content

Commit

Permalink
Added functionality to override edid with -cfledidinject, adapted fro…
Browse files Browse the repository at this point in the history
…m aerror

Signed-off-by: black.dragon74 <nickk.2974@gmail.com>
  • Loading branch information
black-dragon74 committed Nov 24, 2018
1 parent ef3aa16 commit 17282bb
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -55,6 +55,7 @@ Read [FAQs](https://github.com/acidanthera/WhateverGreen/blob/master/Manual/) an
- `igfxcflbklt=opcode` to enable Fraxul's CFL backlight patch
- `igfxcflbklt=wrap` (and `enable-cfl-backlight-fix` property) to enable headkaze's CFL backlight patch
- `igfxcflbklt=freq` to enable RehabMan's CFL backlight patch
- `cfledidinject` to enable patch for EDID on CFL laptops.

#### Credits
- [Apple](https://www.apple.com) for macOS
Expand Down
6 changes: 3 additions & 3 deletions WhateverGreen.xcodeproj/project.pbxproj
Expand Up @@ -560,7 +560,7 @@
MODULE_NAME = as.vit9696.WhateverGreen;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.2.4bd74;
MODULE_VERSION = 1.2.4a1;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down Expand Up @@ -605,7 +605,7 @@
MODULE_NAME = as.vit9696.WhateverGreen;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.2.4bd74;
MODULE_VERSION = 1.2.4a1;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down Expand Up @@ -736,7 +736,7 @@
MODULE_NAME = as.vit9696.WhateverGreen;
MODULE_START = "$(PRODUCT_NAME)_kern_start";
MODULE_STOP = "$(PRODUCT_NAME)_kern_stop";
MODULE_VERSION = 1.2.4bd74;
MODULE_VERSION = 1.2.4a1;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down
3 changes: 3 additions & 0 deletions WhateverGreen/kern_fb.hpp
Expand Up @@ -370,6 +370,9 @@ struct PACKED FramebufferCFL {
uint32_t fSliceCount;
uint32_t fEuCount;
uint32_t unk6[2];
/* For CFL EDID override */
uint8_t overrideEDIDIndex;
uint8_t overrideEDID[];
};

/* Not sure what it is, in CNL value2 is a pointer, and value1 could be size. */
Expand Down
67 changes: 67 additions & 0 deletions WhateverGreen/kern_igfx.cpp
Expand Up @@ -224,6 +224,67 @@ void IGFX::processKernel(KernelPatcher &patcher, DeviceInfo *info) {
else
cflBacklightPatch = CFLBKLTNone;
}

// Enable CFL EDID injection only on laptops and macOS Mojave and up!
if (checkKernelArgument("-cfledidinject")){
cflEDIDInject = true;
}
}

int IGFX::wrapEDIDCheck(IOService *that, unsigned int x, unsigned char *buff){
DBGLOG("igfx", "WRAP EDID called. Preparing for injection...");

int framebufferIndex = *(int*) ((char*)that + 0x1dc); // This is not the index that will be patched.

int retVal = 0, standardEDIDLen = 128;

if (callbackIGFX->orgEDIDCheck){
retVal = FunctionCast(wrapEDIDCheck, callbackIGFX->orgEDIDCheck) (that, x, buff);
}

// Read override EDID to inject from properties if not done so already
if (!callbackIGFX->cflEDIDRead){
callbackIGFX->framebufferPatchFlags.bits.EDIDOverride = 0;
IOService *igpu = that->getProvider();
if (igpu){
auto EDIDData = OSDynamicCast(OSData, igpu->getProperty("edid-override"));
uint8_t EDIDIndex = WIOKit::getOSDataValue<uint32_t>(igpu, "edid-override-index", callbackIGFX->framebufferPatch.overrideEDIDIndex);
if (EDIDData && EDIDIndex){
if (EDIDData->getLength() == standardEDIDLen){
callbackIGFX->framebufferPatchFlags.bits.EDIDOverride = 1;
uint8_t *pd = (uint8_t*)EDIDData->getBytesNoCopy();
for(int i = 0; i < standardEDIDLen; i++){ // EDID data is always 128 Bytes long, prevent excess injection.
callbackIGFX->framebufferPatch.overrideEDID[i] = pd[i];
}
DBGLOG("igfx", "Successfully acquired and read the EDID");
}
else {
DBGLOG("igfx", "EDID data was of excessive size: %d bytes", EDIDData->getLength());
}
}
callbackIGFX->cflEDIDRead = true;
}
}
else {
DBGLOG("igfx", "EDID data already read. No need to read again.");
}

// If EDID is read, patch the selected connector.
if (callbackIGFX->framebufferPatchFlags.bits.EDIDOverride){
if (framebufferIndex == callbackIGFX->framebufferPatch.overrideEDIDIndex){
DBGLOG("igfx", "Starting to patch connector for index: %d", framebufferIndex);
for (int i = 0; i < standardEDIDLen; i++) {
buff[i] = callbackIGFX->framebufferPatch.overrideEDID[i];
}
DBGLOG("igfx", "Successfully patched connector %d for EDID", framebufferIndex);
return 0;
}
}
else {
DBGLOG("igfx", "edid-override property not found in config.");
}

return retVal;
}

bool IGFX::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) {
Expand Down Expand Up @@ -254,6 +315,12 @@ bool IGFX::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t a
return true;
}

if (cflEDIDInject){
SYSLOG("igfx", "CFL EDID patch requested, initializing patches..");
KernelPatcher::RouteRequest request("__ZN21AppleIntelFramebuffer20checkForEDIDOverrideEjPh", wrapEDIDCheck, orgEDIDCheck);
patcher.routeMultiple(index, &request, 1, address, size);
}

if ((currentFramebuffer && currentFramebuffer->loadIndex == index) ||
(currentFramebufferOpt && currentFramebufferOpt->loadIndex == index)) {
if (currentFramebuffer == &kextIntelCFLFb && cflBacklightPatch != CFLBKLTNone) {
Expand Down
21 changes: 21 additions & 0 deletions WhateverGreen/kern_igfx.hpp
Expand Up @@ -69,6 +69,7 @@ class IGFX {
uint8_t FPFBTTArrayHDMIAddr :1;
uint8_t FPFSliceCount :1;
uint8_t FPFEuCount :1;
uint8_t EDIDOverride :1;
} bits;
uint32_t value;
};
Expand Down Expand Up @@ -278,6 +279,11 @@ class IGFX {
*/
mach_vm_address_t orgSetDPCDBacklight {};

/**
* Original EDID Check in CFL framebuffer
*/
mach_vm_address_t orgEDIDCheck {};

/**
* Detected CPU generation of the host system
*/
Expand Down Expand Up @@ -629,6 +635,21 @@ class IGFX {
* Apply DP to HDMI automatic connector type changes
*/
void applyHdmiAutopatch();

/**
* Turn on EDID Injection
*/
bool cflEDIDInject {false};

/**
* Read EDID from config
*/
bool cflEDIDRead {false};

/**
* Wrap EDID Check
*/
static int wrapEDIDCheck(IOService*, unsigned int, unsigned char*);
};

#endif /* kern_igfx_hpp */

0 comments on commit 17282bb

Please sign in to comment.