From 6eb73857caa3bc848fb348a9f653970db82e7f02 Mon Sep 17 00:00:00 2001 From: zhen-zen <66577170+zhen-zen@users.noreply.github.com> Date: Sun, 12 Sep 2021 14:57:55 -0700 Subject: [PATCH 1/6] Move PNLF _UID processing to WhateverGreen --- Manual/SSDT-PNLF.dsl | 41 +++++++++++++++ WhateverGreen.xcodeproj/project.pbxproj | 2 + WhateverGreen/Info.plist | 2 + WhateverGreen/kern_weg.cpp | 69 +++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 Manual/SSDT-PNLF.dsl diff --git a/Manual/SSDT-PNLF.dsl b/Manual/SSDT-PNLF.dsl new file mode 100644 index 00000000..4b436327 --- /dev/null +++ b/Manual/SSDT-PNLF.dsl @@ -0,0 +1,41 @@ +// 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) + + If (_OSI ("Darwin")) { + 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 + Name (_STA, 0x0B) // _STA: Status + + Method (SUID, 1, NotSerialized) + { + _UID = ToInteger (Arg0) + } + } + } + } +} + diff --git a/WhateverGreen.xcodeproj/project.pbxproj b/WhateverGreen.xcodeproj/project.pbxproj index 064ff767..bd20c9e3 100644 --- a/WhateverGreen.xcodeproj/project.pbxproj +++ b/WhateverGreen.xcodeproj/project.pbxproj @@ -93,6 +93,7 @@ 5B9131F2258A8EFB0008530D /* FAQ.IntelHD.en.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = FAQ.IntelHD.en.md; sourceTree = ""; }; 5B9131F3258A8F090008530D /* FAQ.IntelHD.cn.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = FAQ.IntelHD.cn.md; sourceTree = ""; }; 5B9131F4258A8F1C0008530D /* FAQ.OldPlugins.en.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = FAQ.OldPlugins.en.md; sourceTree = ""; }; + 6FA3CCFC26EEAF2A00EE07F0 /* SSDT-PNLF.dsl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "SSDT-PNLF.dsl"; sourceTree = ""; }; CE1970FD21C380DF00B02AB4 /* kern_nvhda.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = kern_nvhda.cpp; sourceTree = ""; }; CE1970FE21C380DF00B02AB4 /* kern_nvhda.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_nvhda.hpp; sourceTree = ""; }; CE1F61B82432DEE800201DF4 /* kern_igfx_debug.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = kern_igfx_debug.cpp; sourceTree = ""; }; @@ -335,6 +336,7 @@ CE7FC0D020F6882400138088 /* FAQ.Shiki.zh_CN.md */, CE271B4C1F319BD000D2BC1C /* reference.cpp */, CEAEA1191F26905A00918651 /* Sample.dsl */, + 6FA3CCFC26EEAF2A00EE07F0 /* SSDT-PNLF.dsl */, ); path = Manual; sourceTree = ""; diff --git a/WhateverGreen/Info.plist b/WhateverGreen/Info.plist index a25f305e..2d23e898 100644 --- a/WhateverGreen/Info.plist +++ b/WhateverGreen/Info.plist @@ -71,6 +71,8 @@ 10.0.0 com.apple.kpi.unsupported 10.0.0 + com.apple.iokit.IOACPIFamily + 1.0.0d1 com.apple.iokit.IOPCIFamily 1.0.0b1 as.vit9696.Lilu diff --git a/WhateverGreen/kern_weg.cpp b/WhateverGreen/kern_weg.cpp index ff99f15e..3e9a361e 100644 --- a/WhateverGreen/kern_weg.cpp +++ b/WhateverGreen/kern_weg.cpp @@ -11,6 +11,7 @@ #include #include "kern_weg.hpp" +#include #include // This is a hack to let us access protected properties. @@ -375,6 +376,47 @@ void WEG::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t ad return; } +uint32_t processUID(uint32_t real) { + uint32_t uid = 0; + // list from SSDT-PNLF, use CpuGeneration instead? + switch (real) { + // 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(); @@ -424,6 +466,33 @@ void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) { DBGLOG("weg", "hooked configRead read methods!"); } } + + if (auto adev = OSDynamicCast(IOACPIPlatformDevice, obj->getProperty("acpi-device"))) { + auto pnlf = OSDynamicCast(IOACPIPlatformDevice, adev->childFromPath("PNLF", gIOACPIPlane)); + if (pnlf) { + DBGLOG("weg", "found PNLF at %s", safeString(pnlf->getName())); + IOReturn ret; + ret = pnlf->validateObject("SUID"); + if (ret == kIOReturnSuccess) { + uint32_t target = processUID(realDevice); + OSObject *params[] = { OSNumber::withNumber(target, 32) }; + ret = pnlf->evaluateObject("SUID", nullptr, params, 1); + if (ret == kIOReturnSuccess) { + DBGLOG("weg", "PNLF _UID set to 0x%x", target); + } else { + SYSLOG("weg", "failed to set PNLF _UID"); + } + params[0]->release(); + } else { + DBGLOG("weg", "PNLF doesn't support _UID set"); + } + OSObject *result = nullptr; + ret = pnlf->evaluateObject("_UID", &result); + if (ret == kIOReturnSuccess) + pnlf->setProperty("_UID", result); + OSSafeReleaseNULL(result); + } + } } else { SYSLOG("weg", "invalid IGPU device type"); } From 3ffbb99e86e45a3696128b13ac3134550ca358b5 Mon Sep 17 00:00:00 2001 From: zhen-zen <66577170+zhen-zen@users.noreply.github.com> Date: Sun, 12 Sep 2021 17:55:05 -0700 Subject: [PATCH 2/6] Fix Clang analyze --- WhateverGreen/kern_weg.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WhateverGreen/kern_weg.cpp b/WhateverGreen/kern_weg.cpp index 3e9a361e..0c34da03 100644 --- a/WhateverGreen/kern_weg.cpp +++ b/WhateverGreen/kern_weg.cpp @@ -468,7 +468,8 @@ void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) { } if (auto adev = OSDynamicCast(IOACPIPlatformDevice, obj->getProperty("acpi-device"))) { - auto pnlf = OSDynamicCast(IOACPIPlatformDevice, adev->childFromPath("PNLF", gIOACPIPlane)); + auto child = adev->childFromPath("PNLF", gIOACPIPlane); + auto pnlf = OSDynamicCast(IOACPIPlatformDevice, child); if (pnlf) { DBGLOG("weg", "found PNLF at %s", safeString(pnlf->getName())); IOReturn ret; @@ -492,6 +493,7 @@ void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) { pnlf->setProperty("_UID", result); OSSafeReleaseNULL(result); } + OSSafeReleaseNULL(child); } } else { SYSLOG("weg", "invalid IGPU device type"); From d652dd398f4c9941872d4a5c8097a7cc84b1a596 Mon Sep 17 00:00:00 2001 From: zhen-zen <66577170+zhen-zen@users.noreply.github.com> Date: Sun, 12 Sep 2021 18:01:55 -0700 Subject: [PATCH 3/6] Follow fakeDevice --- WhateverGreen/kern_weg.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/WhateverGreen/kern_weg.cpp b/WhateverGreen/kern_weg.cpp index 0c34da03..c5ce8572 100644 --- a/WhateverGreen/kern_weg.cpp +++ b/WhateverGreen/kern_weg.cpp @@ -376,10 +376,10 @@ void WEG::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t ad return; } -uint32_t processUID(uint32_t real) { +uint32_t processUID(uint32_t deviceid) { uint32_t uid = 0; // list from SSDT-PNLF, use CpuGeneration instead? - switch (real) { + switch (deviceid) { // Sandy HD3000 case 0x010b: case 0x0102: case 0x0106: case 0x1106: case 0x1601: case 0x0116: case 0x0126: @@ -469,13 +469,12 @@ void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) { if (auto adev = OSDynamicCast(IOACPIPlatformDevice, obj->getProperty("acpi-device"))) { auto child = adev->childFromPath("PNLF", gIOACPIPlane); - auto pnlf = OSDynamicCast(IOACPIPlatformDevice, child); - if (pnlf) { + if (auto pnlf = OSDynamicCast(IOACPIPlatformDevice, child)) { DBGLOG("weg", "found PNLF at %s", safeString(pnlf->getName())); IOReturn ret; ret = pnlf->validateObject("SUID"); if (ret == kIOReturnSuccess) { - uint32_t target = processUID(realDevice); + uint32_t target = processUID(fakeDevice ?: realDevice); OSObject *params[] = { OSNumber::withNumber(target, 32) }; ret = pnlf->evaluateObject("SUID", nullptr, params, 1); if (ret == kIOReturnSuccess) { From 602b673d1a8e51a88f693497956c31c95dc26070 Mon Sep 17 00:00:00 2001 From: zhen-zen <66577170+zhen-zen@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:03:41 -0700 Subject: [PATCH 4/6] Move SUID to GFX0 for customized PNLF name --- Manual/SSDT-PNLF.dsl | 8 ++--- WhateverGreen.xcodeproj/project.pbxproj | 2 -- WhateverGreen/kern_weg.cpp | 42 ++++++++++++------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/Manual/SSDT-PNLF.dsl b/Manual/SSDT-PNLF.dsl index 4b436327..b470afeb 100644 --- a/Manual/SSDT-PNLF.dsl +++ b/Manual/SSDT-PNLF.dsl @@ -29,11 +29,11 @@ DefinitionBlock ("", "SSDT", 2, "ACDT", "PNLF", 0x00000000) // 99: Other (requires custom profile using WhateverGreen.kext via DeviceProperties applbkl-name and applbkl-data) Name (_UID, Zero) // _UID: Unique ID Name (_STA, 0x0B) // _STA: Status + } - Method (SUID, 1, NotSerialized) - { - _UID = ToInteger (Arg0) - } + Method (SUID, 1, NotSerialized) + { + ^PNLF._UID = ToInteger (Arg0) } } } diff --git a/WhateverGreen.xcodeproj/project.pbxproj b/WhateverGreen.xcodeproj/project.pbxproj index bd20c9e3..064ff767 100644 --- a/WhateverGreen.xcodeproj/project.pbxproj +++ b/WhateverGreen.xcodeproj/project.pbxproj @@ -93,7 +93,6 @@ 5B9131F2258A8EFB0008530D /* FAQ.IntelHD.en.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = FAQ.IntelHD.en.md; sourceTree = ""; }; 5B9131F3258A8F090008530D /* FAQ.IntelHD.cn.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = FAQ.IntelHD.cn.md; sourceTree = ""; }; 5B9131F4258A8F1C0008530D /* FAQ.OldPlugins.en.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = FAQ.OldPlugins.en.md; sourceTree = ""; }; - 6FA3CCFC26EEAF2A00EE07F0 /* SSDT-PNLF.dsl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "SSDT-PNLF.dsl"; sourceTree = ""; }; CE1970FD21C380DF00B02AB4 /* kern_nvhda.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = kern_nvhda.cpp; sourceTree = ""; }; CE1970FE21C380DF00B02AB4 /* kern_nvhda.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_nvhda.hpp; sourceTree = ""; }; CE1F61B82432DEE800201DF4 /* kern_igfx_debug.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = kern_igfx_debug.cpp; sourceTree = ""; }; @@ -336,7 +335,6 @@ CE7FC0D020F6882400138088 /* FAQ.Shiki.zh_CN.md */, CE271B4C1F319BD000D2BC1C /* reference.cpp */, CEAEA1191F26905A00918651 /* Sample.dsl */, - 6FA3CCFC26EEAF2A00EE07F0 /* SSDT-PNLF.dsl */, ); path = Manual; sourceTree = ""; diff --git a/WhateverGreen/kern_weg.cpp b/WhateverGreen/kern_weg.cpp index c5ce8572..799fd71d 100644 --- a/WhateverGreen/kern_weg.cpp +++ b/WhateverGreen/kern_weg.cpp @@ -467,32 +467,30 @@ void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) { } } + // Set PNLF _UID by device-id if (auto adev = OSDynamicCast(IOACPIPlatformDevice, obj->getProperty("acpi-device"))) { - auto child = adev->childFromPath("PNLF", gIOACPIPlane); - if (auto pnlf = OSDynamicCast(IOACPIPlatformDevice, child)) { - DBGLOG("weg", "found PNLF at %s", safeString(pnlf->getName())); - IOReturn ret; - ret = pnlf->validateObject("SUID"); - if (ret == kIOReturnSuccess) { - uint32_t target = processUID(fakeDevice ?: realDevice); - OSObject *params[] = { OSNumber::withNumber(target, 32) }; - ret = pnlf->evaluateObject("SUID", nullptr, params, 1); - if (ret == kIOReturnSuccess) { - DBGLOG("weg", "PNLF _UID set to 0x%x", target); - } else { - SYSLOG("weg", "failed to set PNLF _UID"); - } - params[0]->release(); + if (adev->validateObject("SUID") == kIOReturnSuccess) { + uint32_t target = processUID(fakeDevice ?: realDevice); + OSObject *params[] = { OSNumber::withNumber(target, 32) }; + if (adev->evaluateObject("SUID", nullptr, params, 1) == kIOReturnSuccess) { + DBGLOG("weg", "set PNLF _UID to 0x%x", target); } else { - DBGLOG("weg", "PNLF doesn't support _UID set"); + SYSLOG("weg", "set PNLF _UID failed"); } - OSObject *result = nullptr; - ret = pnlf->evaluateObject("_UID", &result); - if (ret == kIOReturnSuccess) - pnlf->setProperty("_UID", result); - OSSafeReleaseNULL(result); + params[0]->release(); + + // Override _UID property in ioreg with new value + auto child = adev->childFromPath("PNLF", gIOACPIPlane); + if (auto pnlf = OSDynamicCast(IOACPIPlatformDevice, child)) { + OSObject *result = nullptr; + if (pnlf->evaluateObject("_UID", &result) == kIOReturnSuccess) + pnlf->setProperty("_UID", result); + OSSafeReleaseNULL(result); + } + OSSafeReleaseNULL(child); + } else { + DBGLOG("weg", "PNLF does not support _UID set"); } - OSSafeReleaseNULL(child); } } else { SYSLOG("weg", "invalid IGPU device type"); From 41040c2dfac661dbc0d385365d49032f08961ae9 Mon Sep 17 00:00:00 2001 From: zhen-zen <66577170+zhen-zen@users.noreply.github.com> Date: Mon, 27 Sep 2021 00:41:45 -0700 Subject: [PATCH 5/6] Return new _UID result; revert to old _STA style OS check --- Manual/SSDT-PNLF.dsl | 53 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/Manual/SSDT-PNLF.dsl b/Manual/SSDT-PNLF.dsl index b470afeb..c4ec55fb 100644 --- a/Manual/SSDT-PNLF.dsl +++ b/Manual/SSDT-PNLF.dsl @@ -10,32 +10,41 @@ DefinitionBlock ("", "SSDT", 2, "ACDT", "PNLF", 0x00000000) { External (_SB_.PCI0.GFX0, DeviceObj) // (from opcode) - If (_OSI ("Darwin")) { - Scope (\_SB.PCI0.GFX0) + Scope (\_SB.PCI0.GFX0) + { + // For backlight control + Device (PNLF) { - // 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 { - // 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 - Name (_STA, 0x0B) // _STA: Status - } - - Method (SUID, 1, NotSerialized) - { - ^PNLF._UID = ToInteger (Arg0) + If (_OSI ("Darwin")) + { + Return (0x0B) + } + Else + { + Return (Zero) + } } } + + Method (SUID, 1, NotSerialized) + { + ^PNLF._UID = ToInteger (Arg0) + Return (^PNLF._UID) + } } } From 2097bffa423655c895ad8f4f6e8d4860689646a5 Mon Sep 17 00:00:00 2001 From: zhen-zen <66577170+zhen-zen@users.noreply.github.com> Date: Mon, 27 Sep 2021 00:58:02 -0700 Subject: [PATCH 6/6] Return PNLF device name to allow different name on laptops with existing object named PNLF --- Manual/SSDT-PNLF.dsl | 5 +++-- WhateverGreen/kern_weg.cpp | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Manual/SSDT-PNLF.dsl b/Manual/SSDT-PNLF.dsl index c4ec55fb..2a4354f3 100644 --- a/Manual/SSDT-PNLF.dsl +++ b/Manual/SSDT-PNLF.dsl @@ -39,11 +39,12 @@ DefinitionBlock ("", "SSDT", 2, "ACDT", "PNLF", 0x00000000) } } } - + Method (SUID, 1, NotSerialized) { ^PNLF._UID = ToInteger (Arg0) - Return (^PNLF._UID) + // Return PNLF device name in case of conflict + Return ("PNLF") } } } diff --git a/WhateverGreen/kern_weg.cpp b/WhateverGreen/kern_weg.cpp index 799fd71d..1178e051 100644 --- a/WhateverGreen/kern_weg.cpp +++ b/WhateverGreen/kern_weg.cpp @@ -472,21 +472,23 @@ void WEG::processBuiltinProperties(IORegistryEntry *device, DeviceInfo *info) { if (adev->validateObject("SUID") == kIOReturnSuccess) { uint32_t target = processUID(fakeDevice ?: realDevice); OSObject *params[] = { OSNumber::withNumber(target, 32) }; - if (adev->evaluateObject("SUID", nullptr, params, 1) == kIOReturnSuccess) { + 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 - auto child = adev->childFromPath("PNLF", gIOACPIPlane); + OSString *path = OSDynamicCast(OSString, result); + auto child = adev->childFromPath(path ? path->getCStringNoCopy() : "PNLF", gIOACPIPlane); if (auto pnlf = OSDynamicCast(IOACPIPlatformDevice, child)) { - OSObject *result = nullptr; - if (pnlf->evaluateObject("_UID", &result) == kIOReturnSuccess) - pnlf->setProperty("_UID", result); - OSSafeReleaseNULL(result); + 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");