Skip to content

Commit

Permalink
relocate duplicated code to a standalone function
Browse files Browse the repository at this point in the history
  • Loading branch information
Zormeister committed Aug 28, 2024
1 parent a0438bc commit 6dd0782
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
7 changes: 7 additions & 0 deletions Lilu/Headers/kern_devinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/**
Expand Down
60 changes: 24 additions & 36 deletions Lilu/Sources/kern_devinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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));
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 6dd0782

Please sign in to comment.