Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitute complicated PNLF _UID implementation #91

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Manual/SSDT-PNLF.dsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Adding PNLF device for WhateverGreen.kext and others.
// This is a simplified PNLF version originally taken from RehabMan/OS-X-Clover-Laptop-Config repository:
// https://raw.githubusercontent.com/RehabMan/OS-X-Clover-Laptop-Config/master/hotpatch/SSDT-PNLF.dsl
// Rename GFX0 to anything else if your IGPU name is different.
//
// Licensed under GNU General Public License v2.0
// https://github.com/RehabMan/OS-X-Clover-Laptop-Config/blob/master/License.md

DefinitionBlock ("", "SSDT", 2, "ACDT", "PNLF", 0x00000000)
{
External (_SB_.PCI0.GFX0, DeviceObj) // (from opcode)

Scope (\_SB.PCI0.GFX0)
{
// For backlight control
Device (PNLF)
{
// Name(_ADR, Zero)
Name (_HID, EisaId ("APP0002")) // _HID: Hardware ID
Name (_CID, "backlight") // _CID: Compatible ID
// _UID is set depending on PWMMax to match profiles in WhateverGreen.kext https://github.com/acidanthera/WhateverGreen/blob/1.4.7/WhateverGreen/kern_weg.cpp#L32
// 14: Sandy/Ivy 0x710
// 15: Haswell/Broadwell 0xad9
// 16: Skylake/KabyLake 0x56c (and some Haswell, example 0xa2e0008)
// 17: custom LMAX=0x7a1
// 18: custom LMAX=0x1499
// 19: CoffeeLake 0xffff
// 99: Other (requires custom profile using WhateverGreen.kext via DeviceProperties applbkl-name and applbkl-data)
Name (_UID, Zero) // _UID: Unique ID
Method (_STA, 0, NotSerialized) // _STA: Status
{
If (_OSI ("Darwin"))
{
Return (0x0B)
}
Else
{
Return (Zero)
}
}
}

Method (SUID, 1, NotSerialized)
{
^PNLF._UID = ToInteger (Arg0)
// Return PNLF device name in case of conflict
Return ("PNLF")
}
}
}

2 changes: 2 additions & 0 deletions WhateverGreen/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
<string>10.0.0</string>
<key>com.apple.kpi.unsupported</key>
<string>10.0.0</string>
<key>com.apple.iokit.IOACPIFamily</key>
<string>1.0.0d1</string>
<key>com.apple.iokit.IOPCIFamily</key>
<string>1.0.0b1</string>
<key>as.vit9696.Lilu</key>
Expand Down
70 changes: 70 additions & 0 deletions WhateverGreen/kern_weg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Headers/kern_cpu.hpp>
#include "kern_weg.hpp"

#include <IOKit/acpi/IOACPIPlatformDevice.h>
#include <IOKit/graphics/IOFramebuffer.h>

// This is a hack to let us access protected properties.
Expand Down Expand Up @@ -375,6 +376,47 @@ void WEG::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t ad
return;
}

uint32_t processUID(uint32_t deviceid) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good to just replace it with CPUInfo::CpuGeneration ?

uint32_t uid = 0;
// list from SSDT-PNLF, use CpuGeneration instead?
switch (deviceid) {
// Sandy HD3000
case 0x010b: case 0x0102:
case 0x0106: case 0x1106: case 0x1601: case 0x0116: case 0x0126:
case 0x0112: case 0x0122:
// Ivy
case 0x0152: case 0x0156: case 0x0162: case 0x0166:
case 0x016a:
// Arrandale
case 0x0046: case 0x0042:
uid = 14;
break;

// CoffeeLake and Whiskey Lake and CometLake and IceLake
case 0x3e9b: case 0x3ea5: case 0x3e92: case 0x3e91: case 0x3ea0: case 0x3ea6: case 0x3e98:
case 0x9bc8: case 0x9bc5: case 0x9bc4: case 0xff05: case 0x8a70: case 0x8a71: case 0x8a51:
case 0x8a5c: case 0x8a5d: case 0x8a52: case 0x8a53: case 0x8a56: case 0x8a5a: case 0x8a5b:
case 0x9b41: case 0x9b21: case 0x9bca: case 0x9ba4:
uid = 19;
break;

// Haswell
case 0x0d26: case 0x0a26: case 0x0d22: case 0x0412: case 0x0416: case 0x0a16: case 0x0a1e: case 0x0a2e: case 0x041e: case 0x041a:
// Broadwell
case 0x0bd1: case 0x0bd2: case 0x0bd3: case 0x1606: case 0x160e: case 0x1616: case 0x161e: case 0x1626: case 0x1622: case 0x1612: case 0x162b:
uid = 15;
break;

// assume Skylake/KabyLake/KabyLake-R
// 0x1916, 0x191E, 0x1926, 0x1927, 0x1912, 0x1932, 0x1902, 0x1917, 0x191b,
// 0x5916, 0x5912, 0x591b, others...
default:
uid = 16;
break;
}
return uid;
}

void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) {
auto name = device->getName();

Expand Down Expand Up @@ -424,6 +466,34 @@ void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) {
DBGLOG("weg", "hooked configRead read methods!");
}
}

// Set PNLF _UID by device-id
if (auto adev = OSDynamicCast(IOACPIPlatformDevice, obj->getProperty("acpi-device"))) {
if (adev->validateObject("SUID") == kIOReturnSuccess) {
uint32_t target = processUID(fakeDevice ?: realDevice);
OSObject *params[] = { OSNumber::withNumber(target, 32) };
OSObject *result;
if (adev->evaluateObject("SUID", &result, params, 1) == kIOReturnSuccess) {
DBGLOG("weg", "set PNLF _UID to 0x%x", target);
} else {
SYSLOG("weg", "set PNLF _UID failed");
}
params[0]->release();
// Override _UID property in ioreg with new value
OSString *path = OSDynamicCast(OSString, result);
auto child = adev->childFromPath(path ? path->getCStringNoCopy() : "PNLF", gIOACPIPlane);
if (auto pnlf = OSDynamicCast(IOACPIPlatformDevice, child)) {
OSObject *uid = nullptr;
if (pnlf->evaluateObject("_UID", &uid) == kIOReturnSuccess)
pnlf->setProperty("_UID", uid);
OSSafeReleaseNULL(uid);
}
OSSafeReleaseNULL(result);
OSSafeReleaseNULL(child);
} else {
DBGLOG("weg", "PNLF does not support _UID set");
}
}
} else {
SYSLOG("weg", "invalid IGPU device type");
}
Expand Down