Skip to content

Commit

Permalink
device_probe.py: Handle VPCI erroring
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed Feb 3, 2022
1 parent bea1e92 commit c747061
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions resources/device_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ def vendor_detect(self, *, inherits: ClassVar[Any] = None, classes: list = None)
def detect(cls, device):
return device.vendor_id == cls.VENDOR_ID and ((device.class_code == cls.CLASS_CODE) if getattr(cls, "CLASS_CODE", None) else True) # type: ignore # pylint: disable=no-member

# def acpi_path(self):
# # Eventually
# raise NotImplementedError

def populate_pci_path(self, original_entry: ioreg.io_registry_entry_t):
# Based off gfxutil logic, seems to work.
paths = []
entry = original_entry
while entry:
if ioreg.IOObjectConformsTo(entry, "IOPCIDevice".encode()):
location = [hex(int(i, 16)) for i in ioreg.io_name_t_to_str(ioreg.IORegistryEntryGetLocationInPlane(entry, "IOService".encode(), None)[1]).split(",") + ["0"]]
paths.append(f"Pci({location[0]},{location[1]})")
# Virtual PCI devices provide a botched IOService path (us.electronic.kext.vusb)
# We only care about physical devices, so skip them
try:
location = [hex(int(i, 16)) for i in ioreg.io_name_t_to_str(ioreg.IORegistryEntryGetLocationInPlane(entry, "IOService".encode(), None)[1]).split(",") + ["0"]]
paths.append(f"Pci({location[0]},{location[1]})")
except ValueError:
break
elif ioreg.IOObjectConformsTo(entry, "IOACPIPlatformDevice".encode()):
paths.append(f"PciRoot({hex(int(ioreg.corefoundation_to_native(ioreg.IORegistryEntryCreateCFProperty(entry, '_UID', ioreg.kCFAllocatorDefault, ioreg.kNilOptions)) or 0))})") # type: ignore
break
Expand Down

0 comments on commit c747061

Please sign in to comment.