Skip to content

Commit

Permalink
An attempt to fix a graphics issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Me committed Jan 7, 2023
1 parent 2b8c16c commit 16413cf
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
50 changes: 49 additions & 1 deletion WhateverGreen/kern_igfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,9 @@ bool IGFX::wrapGetOSInformation(IOService *that) {
callbackIGFX->applyFramebufferPatches();
else if (callbackIGFX->applyFramebufferPatch && cpuGeneration == CPUInfo::CpuGeneration::Westmere)
callbackIGFX->applyWestmereFeaturePatches(that);
else if (callbackIGFX->hdmiAutopatch)
else if (callbackIGFX->applyFramebufferPatch && cpuGeneration == CPUInfo::CpuGeneration::CoffeeLake)
callbackIGFX->applyCoffeeLakeFeaturePatches(that);
else if (callbackIGFX->hdmiAutopatch)
callbackIGFX->applyHdmiAutopatch();

#ifdef DEBUG
Expand Down Expand Up @@ -1459,6 +1461,12 @@ bool IGFX::loadPatchesFromDevice(IORegistryEntry *igpu, uint32_t currentFramebuf
framebufferPatchFlags.bitsWestmere.FeatureControlRenderStandby = 1;
framebufferPatchFlags.bitsWestmere.FeatureControlWatermarks = 1;
}
} else if (cpuGeneration == CPUInfo::CpuGeneration::CoffeeLake) {
hasFramebufferPatch = true;
framebufferPatchFlags.bitsCoffeeLake.FeatureControlGamma = WIOKit::getOSDataValue(igpu, "framebuffer-featurecontrol-gamma", framebufferCoffeeLakePatches.FeatureControlGamma);
framebufferPatchFlags.bitsCoffeeLake.FeatureControlIgnorePanelTimings = WIOKit::getOSDataValue(igpu, "framebuffer-featurecontrol-ignorepaneltimings", framebufferCoffeeLakePatches.FeatureControlIgnorePanelTimings);
framebufferPatchFlags.bitsCoffeeLake.FeatureControlCachedEDIDDisable = WIOKit::getOSDataValue(igpu, "framebuffer-featurecontrol-cachedediddisable", framebufferCoffeeLakePatches.FeatureControlCachedEDIDDisable);

} else if (cpuGeneration >= CPUInfo::CpuGeneration::SandyBridge) {
// Note, the casts to uint32_t here and below are required due to device properties always injecting 32-bit types.
framebufferPatchFlags.bits.FPFFramebufferId = WIOKit::getOSDataValue(igpu, "framebuffer-framebufferid", framebufferPatch.framebufferId);
Expand Down Expand Up @@ -2168,3 +2176,43 @@ void IGFX::applyWestmereFeaturePatches(IOService *framebuffer) {
else
DBGLOG("igfx", "applyWestmereFeaturePatches failed %X", callbackIGFX->framebufferPatchFlags.value);
}

void IGFX::applyCoffeeLakeFeaturePatches(IOService *framebuffer) {
bool success = true;

uint32_t patchFeatureControl = 0;
patchFeatureControl |= callbackIGFX->framebufferPatchFlags.bitsCoffeeLake.FeatureControlGamma;
patchFeatureControl |= callbackIGFX->framebufferPatchFlags.bitsCoffeeLake.FeatureControlIgnorePanelTimings;
patchFeatureControl |= callbackIGFX->framebufferPatchFlags.bitsCoffeeLake.FeatureControlCachedEDIDDisable;

if (patchFeatureControl) {
// Try to get existing dictionary, replace if not found.
auto dictFeatureControlOld = OSDynamicCast(OSDictionary, framebuffer->getProperty("FeatureControl"));
OSDictionary *dictFeatureControlNew;
if (dictFeatureControlOld)
dictFeatureControlNew = OSDictionary::withDictionary(dictFeatureControlOld);
else
dictFeatureControlNew = OSDictionary::withCapacity(3);

// Replace any specified properties.
if (dictFeatureControlNew) {
if (callbackIGFX->framebufferPatchFlags.bitsCoffeeLake.FeatureControlGamma)
success &= setDictUInt32(dictFeatureControlNew, "Gamma", framebufferCoffeeLakePatches.FeatureControlGamma);
if (callbackIGFX->framebufferPatchFlags.bitsCoffeeLake.FeatureControlIgnorePanelTimings)
success &= setDictUInt32(dictFeatureControlNew, "IgnorePanelTimings", framebufferCoffeeLakePatches.FeatureControlIgnorePanelTimings);
if (callbackIGFX->framebufferPatchFlags.bitsCoffeeLake.FeatureControlCachedEDIDDisable)
success &= setDictUInt32(dictFeatureControlNew, "CachedEDIDDisable", framebufferCoffeeLakePatches.FeatureControlCachedEDIDDisable);

// Replace FBCControl dictionary.
success &= framebuffer->setProperty("FeatureControl", dictFeatureControlNew);
dictFeatureControlNew->release();
} else {
success = false;
}
}

if (success)
DBGLOG("igfx", "applyCoffeeLakeFeaturePatches successful %X", callbackIGFX->framebufferPatchFlags.value);
else
DBGLOG("igfx", "applyCoffeeLakeFeaturePatches failed %X", callbackIGFX->framebufferPatchFlags.value);
}
25 changes: 25 additions & 0 deletions WhateverGreen/kern_igfx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class IGFX {
uint8_t FeatureControlWatermarks : 1;
} bitsWestmere;

// CoffeeLake bits
struct FramebufferCoffeeLakePatchFlagBits {
uint8_t FeatureControlGamma : 1;
uint8_t FeatureControlIgnorePanelTimings : 1;
uint8_t FeatureControlCachedEDIDDisable : 1;
} bitsCoffeeLake;
uint32_t value;
};

Expand Down Expand Up @@ -199,6 +205,20 @@ class IGFX {
static constexpr uint32_t WESTMERE_LINK_WIDTH_MASK = 0xFFC7FFFF;
static constexpr uint32_t WESTMERE_LINK_WIDTH_SHIFT = 19;

/**
* FeatureControl patches for CoffeeLake framebuffer.
*/
struct FramebufferCoffeeLakePatches {
uint32_t FeatureControlGamma {0};
uint32_t FeatureControlIgnorePanelTimings {0};
uint32_t FeatureControlCachedEDIDDisable {0};
};

/**
* FeatureControl patches for CoffeeLake framebuffer.
*/
FramebufferCoffeeLakePatches framebufferCoffeeLakePatches;

/**
* Framebuffer list, imported from the framebuffer kext
*/
Expand Down Expand Up @@ -2151,6 +2171,11 @@ class IGFX {
* Apply I/O registry FeatureControl and FBCControl patches for first generation framebuffer.
*/
void applyWestmereFeaturePatches(IOService *framebuffer);

/**
* Apply I/O registry FeatureControl patches for CFL framebuffer.
*/
void applyCoffeeLakeFeaturePatches(IOService *framebuffer);
};

#endif /* kern_igfx_hpp */

0 comments on commit 16413cf

Please sign in to comment.