From 2e1816bb39fcd49820ca61d7e73810b5175e44d4 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:41:40 +1100 Subject: [PATCH 01/15] Change AMD iGPU detection --- Lilu/Sources/kern_devinfo.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 5a37ac02..082d79a4 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -206,9 +206,12 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { continue; if (vendor == WIOKit::VendorID::Intel && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { - DBGLOG("dev", "found IGPU device %s", safeString(name)); - videoBuiltin = obj; - requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; + DBGLOG("dev", "found IGPU device %s", safeString(name)); + videoBuiltin = obj; + requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; + } else if (vendor == WIOKit::VendorID::ATIAMD && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { + DBGLOG("dev", "found AMD iGPU device %s", safeString(name)); + videoBuiltin = obj; } else if (code == WIOKit::ClassCode::HDADevice || code == WIOKit::ClassCode::HDAMmDevice) { if (vendor == WIOKit::VendorID::Intel && name && (!strcmp(name, "HDAU") || !strcmp(name, "B0D3"))) { DBGLOG("dev", "found HDAU device %s", safeString(name)); @@ -272,10 +275,6 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { // To distinguish the devices we use audio card presence as a marker. DBGLOG("dev", "marking audio device as HDEF at %s", safeString(v.audio->getName())); audioBuiltinAnalog = v.audio; - - if (v.video && v.vendor == WIOKit::VendorID::ATIAMD) { - videoBuiltin = v.video; - } } } } From 17c3c6c35022a203b9f6be869a139f39836c3bb0 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Sat, 25 Nov 2023 15:18:10 +1100 Subject: [PATCH 02/15] Proper Device ID detection rather than just marking all AMD devices as an iGPU --- Lilu/Sources/kern_devinfo.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 082d79a4..3aaba310 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -209,9 +209,14 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { DBGLOG("dev", "found IGPU device %s", safeString(name)); videoBuiltin = obj; requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; - } else if (vendor == WIOKit::VendorID::ATIAMD && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { - DBGLOG("dev", "found AMD iGPU device %s", safeString(name)); + } else if (vendor == WIOKit::VendorID::ATIAMD && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { + uint32_t dev = 0; + WIOKit::getOSDataValue(obj, "device-id", dev); + dev = (dev & 0xFF00); + if ((dev == 0x1600 || dev == 1500) || (dev == 0x9800 || dev == 0x1300) || (dev == 0x9900 || dev == 0x9800) || dev == 0x9600) { + DBGLOG("dev", "found IGPU device %s", safeString(name)); videoBuiltin = obj; + } } else if (code == WIOKit::ClassCode::HDADevice || code == WIOKit::ClassCode::HDAMmDevice) { if (vendor == WIOKit::VendorID::Intel && name && (!strcmp(name, "HDAU") || !strcmp(name, "B0D3"))) { DBGLOG("dev", "found HDAU device %s", safeString(name)); From 9ac77d1a6b2c73eea83b704d99555418511ae1f0 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Tue, 26 Mar 2024 05:22:47 +1100 Subject: [PATCH 03/15] remove the etxra 0x9800 check --- Lilu/Sources/kern_devinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 3aaba310..4481c373 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -213,7 +213,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { uint32_t dev = 0; WIOKit::getOSDataValue(obj, "device-id", dev); dev = (dev & 0xFF00); - if ((dev == 0x1600 || dev == 1500) || (dev == 0x9800 || dev == 0x1300) || (dev == 0x9900 || dev == 0x9800) || dev == 0x9600) { + if ((dev == 0x1600 || dev == 1500) || (dev == 0x9800 || dev == 0x1300) || (dev == 0x9900 || dev == 0x9600)) { DBGLOG("dev", "found IGPU device %s", safeString(name)); videoBuiltin = obj; } From 24170950b227efa5fc0e28897413d710d04bc9a4 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Thu, 8 Aug 2024 20:00:02 +1000 Subject: [PATCH 04/15] Fixup typo --- Lilu/Sources/kern_devinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 4481c373..15418731 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -213,7 +213,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { uint32_t dev = 0; WIOKit::getOSDataValue(obj, "device-id", dev); dev = (dev & 0xFF00); - if ((dev == 0x1600 || dev == 1500) || (dev == 0x9800 || dev == 0x1300) || (dev == 0x9900 || dev == 0x9600)) { + if ((dev == 0x1600 || dev == 0x1500) || (dev == 0x9800 || dev == 0x1300) || (dev == 0x9900 || dev == 0x9600)) { DBGLOG("dev", "found IGPU device %s", safeString(name)); videoBuiltin = obj; } From 8f688b5f4a27fc33782aeb29b64ab31f99f907cb Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Thu, 8 Aug 2024 20:15:44 +1000 Subject: [PATCH 05/15] revert formatting changes from the first iGPU detection change commit --- Lilu/Sources/kern_devinfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 15418731..39f88ef0 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -206,9 +206,9 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { continue; if (vendor == WIOKit::VendorID::Intel && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { - DBGLOG("dev", "found IGPU device %s", safeString(name)); - videoBuiltin = obj; - requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; + DBGLOG("dev", "found IGPU device %s", safeString(name)); + videoBuiltin = obj; + requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; } else if (vendor == WIOKit::VendorID::ATIAMD && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { uint32_t dev = 0; WIOKit::getOSDataValue(obj, "device-id", dev); From 52f93707eb26df9e2eb694531df4c8d3ad5fd2d7 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Sat, 17 Aug 2024 12:41:48 +1000 Subject: [PATCH 06/15] convert generic integers to constants --- Lilu/Headers/kern_devinfo.hpp | 35 +++++++++++++++++++++++++++++++++++ Lilu/Sources/kern_devinfo.cpp | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Lilu/Headers/kern_devinfo.hpp b/Lilu/Headers/kern_devinfo.hpp index ce798a4b..eba541fc 100644 --- a/Lilu/Headers/kern_devinfo.hpp +++ b/Lilu/Headers/kern_devinfo.hpp @@ -246,6 +246,41 @@ class DeviceInfo { static constexpr uint32_t ConnectorLessCoffeeLakePlatformId5 {0x9BC50003}; static constexpr uint32_t ConnectorLessCoffeeLakePlatformId6 {0x9BC40003}; + /** + * Kaveri, and also catches the new Granite Ridge rDNA 2 iGPU. + */ + static constexpr uint32_t GenericAMDKvGr = 0x1300; + + /** + * Kabini, Mullins, Carrizo, Stoney Ridge, Wrestler. + */ + static constexpr uint32_t GenericAMDKbMlCzStnWr = 0x9800; + + /** + * Raven/Raven2, Picasso, Barcelo, Phoenix & Phoenix 2 (?) + */ + static constexpr uint32_t GenericAMDRvPcBcPhn = 0x1500; + + /** + * Renoir, Cezanne, Lucienne, Van Gogh, Rembrandt, Raphael. + */ + static constexpr uint32_t GenericAMDRnCznLcVghRmbRph = 0x1600; + + /** + * Trinity + */ + static constexpr uint32_t GenericAMDTrinity = 0x9900; + + /** + * Sumo & Sumo2? + */ + static constexpr uint32_t GenericAMDSumo = 0x9600; + + /** + * Phoenix. + */ + static constexpr uint32_t GenericAMDPhoenix2 = 0x1900; + public: /** * Vesa framebuffer identifier diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 39f88ef0..1b0fdc55 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -213,7 +213,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { uint32_t dev = 0; WIOKit::getOSDataValue(obj, "device-id", dev); dev = (dev & 0xFF00); - if ((dev == 0x1600 || dev == 0x1500) || (dev == 0x9800 || dev == 0x1300) || (dev == 0x9900 || dev == 0x9600)) { + if ((dev == GenericAMDRnCznLcVghRmbRph || dev == GenericAMDRvPcBcPhn) || (dev == GenericAMDKbMlCzStnWr || dev == GenericAMDKvGr) || (dev == GenericAMDTrinity || dev == GenericAMDSumo) || dev == GenericAMDPhoenix2) { DBGLOG("dev", "found IGPU device %s", safeString(name)); videoBuiltin = obj; } From 4a02d2632a3271549d82212624619c21aa22df1e Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 07:24:33 +1000 Subject: [PATCH 07/15] attempt to fix Ryzen iGPU detection --- Lilu/Sources/kern_devinfo.cpp | 42 +++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 1b0fdc55..5f07ab45 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -212,10 +212,21 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { } else if (vendor == WIOKit::VendorID::ATIAMD && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { uint32_t dev = 0; WIOKit::getOSDataValue(obj, "device-id", dev); - dev = (dev & 0xFF00); - if ((dev == GenericAMDRnCznLcVghRmbRph || dev == GenericAMDRvPcBcPhn) || (dev == GenericAMDKbMlCzStnWr || dev == GenericAMDKvGr) || (dev == GenericAMDTrinity || dev == GenericAMDSumo) || dev == GenericAMDPhoenix2) { - DBGLOG("dev", "found IGPU device %s", safeString(name)); - videoBuiltin = obj; + dev &= 0xFF00; + switch (dev) { + case GenericAMDKvGr: + case GenericAMDRvPcBcPhn: + case GenericAMDRnCznLcVghRmbRph: + case GenericAMDPhoenix2: + case GenericAMDSumo: + case GenericAMDKbMlCzStnWr: + case GenericAMDTrinity: + DBGLOG("dev", "found IGPU device %s", safeString(name)); + videoBuiltin = obj; + requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; + break; + default: + break; } } else if (code == WIOKit::ClassCode::HDADevice || code == WIOKit::ClassCode::HDAMmDevice) { if (vendor == WIOKit::VendorID::Intel && name && (!strcmp(name, "HDAU") || !strcmp(name, "B0D3"))) { @@ -253,6 +264,29 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { pcicode == WIOKit::ClassCode::VGAController || pcicode == WIOKit::ClassCode::Ex3DController || pcicode == WIOKit::ClassCode::XGAController) { + if (pcivendor == WIOKit::VendorID::ATIAMD) { + // The iGPU can live in places other than the root bridge. + // This can be seen on some of the newer devices. + // This may be why the older iGPUs had issues. + uint32_t dev = 0; + WIOKit::getOSDataValue(obj, "device-id", dev); + dev &= 0xFF00; + switch (dev) { + case GenericAMDKvGr: + case GenericAMDRvPcBcPhn: + case GenericAMDRnCznLcVghRmbRph: + case GenericAMDPhoenix2: + case GenericAMDSumo: + case GenericAMDKbMlCzStnWr: + case GenericAMDTrinity: + DBGLOG("dev", "found IGPU device %s", safeString(name)); + videoBuiltin = obj; + requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; + continue; + default: + break; + } + } DBGLOG("dev", "found GFX0 device %s at %s by %04X", safeString(pciobj->getName()), safeString(name), pcivendor); v.video = pciobj; From 356559938721144ffd5776673425651e01740562 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 07:36:47 +1000 Subject: [PATCH 08/15] wrong object, it's pciobj --- Lilu/Sources/kern_devinfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 5f07ab45..d76f5a40 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -269,7 +269,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { // This can be seen on some of the newer devices. // This may be why the older iGPUs had issues. uint32_t dev = 0; - WIOKit::getOSDataValue(obj, "device-id", dev); + WIOKit::getOSDataValue(pciobj, "device-id", dev); dev &= 0xFF00; switch (dev) { case GenericAMDKvGr: @@ -280,7 +280,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { case GenericAMDKbMlCzStnWr: case GenericAMDTrinity: DBGLOG("dev", "found IGPU device %s", safeString(name)); - videoBuiltin = obj; + videoBuiltin = pciobj; requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; continue; default: From 95299fcb7ee848d98269107c83f1ae3c9ff412a5 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 07:39:51 +1000 Subject: [PATCH 09/15] Update comments --- Lilu/Sources/kern_devinfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index d76f5a40..786644b0 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -266,8 +266,8 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { pcicode == WIOKit::ClassCode::XGAController) { if (pcivendor == WIOKit::VendorID::ATIAMD) { // The iGPU can live in places other than the root bridge. - // This can be seen on some of the newer devices. - // This may be why the older iGPUs had issues. + // This can be seen in Ryzen Mobile. + // This may be why the older iGPUs had issues, as the device seemingly lives under the root bridge on those platforms. uint32_t dev = 0; WIOKit::getOSDataValue(pciobj, "device-id", dev); dev &= 0xFF00; From e46f4f774e5db84182d99adbb85a2dae28a9314e Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:50:46 +1000 Subject: [PATCH 10/15] change some variable names, fix the name print, also print what generic constant was matched --- Lilu/Sources/kern_devinfo.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 786644b0..0cc0a811 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -268,10 +268,11 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { // The iGPU can live in places other than the root bridge. // This can be seen in Ryzen Mobile. // This may be why the older iGPUs had issues, as the device seemingly lives under the root bridge on those platforms. - uint32_t dev = 0; - WIOKit::getOSDataValue(pciobj, "device-id", dev); - dev &= 0xFF00; - switch (dev) { + uint32_t pcidev = 0; + // change to read from PCI config space? + WIOKit::getOSDataValue(pciobj, "device-id", pcidev); + pcidev &= 0xFF00; + switch (pcidev) { case GenericAMDKvGr: case GenericAMDRvPcBcPhn: case GenericAMDRnCznLcVghRmbRph: @@ -279,7 +280,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { case GenericAMDSumo: case GenericAMDKbMlCzStnWr: case GenericAMDTrinity: - DBGLOG("dev", "found IGPU device %s", safeString(name)); + DBGLOG("dev", "found IGPU device %s at %s (0x%x, by 0x%x)", safeString(pciobj->getName()), safeString(name), pcivendor, pcidev); videoBuiltin = pciobj; requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; continue; @@ -304,6 +305,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { // AZAL audio devices cannot be descrete GPU devices. // On several AMD platforms there is an IGPU, which makes AZAL be recognised as a descrete GPU/HDA pair. // REF: https://github.com/acidanthera/Lilu/pull/65 + // change v.video to videoBuiltin? if (((v.audio && strcmp(v.audio->getName(), "AZAL") != 0) || !v.audio) && v.video) { DBGLOG_COND(v.audio, "dev", "marking audio device as HDAU at %s", safeString(v.audio->getName())); if (!videoExternal.push_back(v)) From c7860149cba47cbb612ad6291db64ccb2ffebb1c Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:47:44 +1000 Subject: [PATCH 11/15] remove some debugging information and fixup the formatting --- Lilu/Sources/kern_devinfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 0cc0a811..8d28dcc4 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -221,8 +221,8 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { case GenericAMDSumo: case GenericAMDKbMlCzStnWr: case GenericAMDTrinity: - DBGLOG("dev", "found IGPU device %s", safeString(name)); - videoBuiltin = obj; + DBGLOG("dev", "found IGPU device %s", safeString(name)); + videoBuiltin = obj; requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; break; default: @@ -280,7 +280,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { case GenericAMDSumo: case GenericAMDKbMlCzStnWr: case GenericAMDTrinity: - DBGLOG("dev", "found IGPU device %s at %s (0x%x, by 0x%x)", safeString(pciobj->getName()), safeString(name), pcivendor, pcidev); + DBGLOG("dev", "found IGPU device %s at %s", safeString(pciobj->getName()), safeString(name)); videoBuiltin = pciobj; requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; continue; From 7e7ba3fde1ea8d0a53fa49b227e94fd54e051d74 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:53:53 +1000 Subject: [PATCH 12/15] fix indentation at line 284 --- Lilu/Sources/kern_devinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 8d28dcc4..78d712b7 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -281,7 +281,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { case GenericAMDKbMlCzStnWr: case GenericAMDTrinity: DBGLOG("dev", "found IGPU device %s at %s", safeString(pciobj->getName()), safeString(name)); - videoBuiltin = pciobj; + videoBuiltin = pciobj; requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; continue; default: From 147c0984787a7a1bd5fecb351fa5006680516664 Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:16:44 +1000 Subject: [PATCH 13/15] remove comment --- Lilu/Sources/kern_devinfo.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 78d712b7..89db40ce 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -305,8 +305,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { // AZAL audio devices cannot be descrete GPU devices. // On several AMD platforms there is an IGPU, which makes AZAL be recognised as a descrete GPU/HDA pair. // REF: https://github.com/acidanthera/Lilu/pull/65 - // change v.video to videoBuiltin? - if (((v.audio && strcmp(v.audio->getName(), "AZAL") != 0) || !v.audio) && v.video) { + if (((v.audio && strcmp(v.audio->getName(), "AZAL") != 0) || !v.audio) && ) { DBGLOG_COND(v.audio, "dev", "marking audio device as HDAU at %s", safeString(v.audio->getName())); if (!videoExternal.push_back(v)) SYSLOG("dev", "failed to push video gpu"); From a0438bc44ed0729879308097e9fbdea1bd82bade Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:44:58 +1000 Subject: [PATCH 14/15] what? --- Lilu/Sources/kern_devinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index 89db40ce..e6fbd631 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -305,7 +305,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { // AZAL audio devices cannot be descrete GPU devices. // On several AMD platforms there is an IGPU, which makes AZAL be recognised as a descrete GPU/HDA pair. // REF: https://github.com/acidanthera/Lilu/pull/65 - if (((v.audio && strcmp(v.audio->getName(), "AZAL") != 0) || !v.audio) && ) { + if (((v.audio && strcmp(v.audio->getName(), "AZAL") != 0) || !v.audio) && v.video) { DBGLOG_COND(v.audio, "dev", "marking audio device as HDAU at %s", safeString(v.audio->getName())); if (!videoExternal.push_back(v)) SYSLOG("dev", "failed to push video gpu"); From 6dd0782e3b45bfc75d771916d73bd82725c6175e Mon Sep 17 00:00:00 2001 From: Zormeister <57213163+Zormeister@users.noreply.github.com> Date: Wed, 28 Aug 2024 20:29:54 +1000 Subject: [PATCH 15/15] relocate duplicated code to a standalone function --- Lilu/Headers/kern_devinfo.hpp | 7 ++++ Lilu/Sources/kern_devinfo.cpp | 60 ++++++++++++++--------------------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Lilu/Headers/kern_devinfo.hpp b/Lilu/Headers/kern_devinfo.hpp index eba541fc..f2f74d08 100644 --- a/Lilu/Headers/kern_devinfo.hpp +++ b/Lilu/Headers/kern_devinfo.hpp @@ -42,6 +42,13 @@ class DeviceInfo { * @param obj wait for (PCI) object publishing */ void awaitPublishing(IORegistryEntry *obj); + + /** + * Checks if an ATIAMD object is an AMD iGPU + * + * @param obj Object to run the check on. + */ + bool checkForAndSetAMDiGPU(IORegistryEntry *obj); public: /** diff --git a/Lilu/Sources/kern_devinfo.cpp b/Lilu/Sources/kern_devinfo.cpp index e6fbd631..cce0f2eb 100644 --- a/Lilu/Sources/kern_devinfo.cpp +++ b/Lilu/Sources/kern_devinfo.cpp @@ -184,6 +184,27 @@ void DeviceInfo::awaitPublishing(IORegistryEntry *obj) { SYSLOG("dev", "found unconfigured pci bridge %s", safeString(obj->getName())); } +bool DeviceInfo::checkForAndSetAMDiGPU(IORegistryEntry *obj) { + uint32_t dev = 0; + WIOKit::getOSDataValue(obj, "device-id", dev); + dev &= 0xFF00; + switch (dev) { + case GenericAMDKvGr: + case GenericAMDRvPcBcPhn: + case GenericAMDRnCznLcVghRmbRph: + case GenericAMDPhoenix2: + case GenericAMDSumo: + case GenericAMDKbMlCzStnWr: + case GenericAMDTrinity: + DBGLOG("dev", "found IGPU device %s", safeString(obj->getName())); + videoBuiltin = obj; + requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; + return true; + default: + return false; + } +} + void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { awaitPublishing(pciRoot); @@ -210,24 +231,7 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { videoBuiltin = obj; requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; } else if (vendor == WIOKit::VendorID::ATIAMD && (code == WIOKit::ClassCode::DisplayController || code == WIOKit::ClassCode::VGAController)) { - uint32_t dev = 0; - WIOKit::getOSDataValue(obj, "device-id", dev); - dev &= 0xFF00; - switch (dev) { - case GenericAMDKvGr: - case GenericAMDRvPcBcPhn: - case GenericAMDRnCznLcVghRmbRph: - case GenericAMDPhoenix2: - case GenericAMDSumo: - case GenericAMDKbMlCzStnWr: - case GenericAMDTrinity: - DBGLOG("dev", "found IGPU device %s", safeString(name)); - videoBuiltin = obj; - requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; - break; - default: - break; - } + checkForAndSetAMDiGPU(obj); } else if (code == WIOKit::ClassCode::HDADevice || code == WIOKit::ClassCode::HDAMmDevice) { if (vendor == WIOKit::VendorID::Intel && name && (!strcmp(name, "HDAU") || !strcmp(name, "B0D3"))) { DBGLOG("dev", "found HDAU device %s", safeString(name)); @@ -268,24 +272,8 @@ void DeviceInfo::grabDevicesFromPciRoot(IORegistryEntry *pciRoot) { // The iGPU can live in places other than the root bridge. // This can be seen in Ryzen Mobile. // This may be why the older iGPUs had issues, as the device seemingly lives under the root bridge on those platforms. - uint32_t pcidev = 0; - // change to read from PCI config space? - WIOKit::getOSDataValue(pciobj, "device-id", pcidev); - pcidev &= 0xFF00; - switch (pcidev) { - case GenericAMDKvGr: - case GenericAMDRvPcBcPhn: - case GenericAMDRnCznLcVghRmbRph: - case GenericAMDPhoenix2: - case GenericAMDSumo: - case GenericAMDKbMlCzStnWr: - case GenericAMDTrinity: - DBGLOG("dev", "found IGPU device %s at %s", safeString(pciobj->getName()), safeString(name)); - videoBuiltin = pciobj; - requestedExternalSwitchOff |= videoBuiltin->getProperty(RequestedExternalSwitchOffName) != nullptr; - continue; - default: - break; + if (checkForAndSetAMDiGPU(pciobj)) { + continue; } } DBGLOG("dev", "found GFX0 device %s at %s by %04X",