Compare commits

..

No commits in common. "8ba146d31e7e462d5ffbdef71408b189a311b35a" and "29b007c2afa6e456d8ee91a2dc2fe65b9feb3e01" have entirely different histories.

2 changed files with 14 additions and 18 deletions

View file

@ -1,4 +1,5 @@
from os import listdir from os import listdir
from os.path import realpath, basename
def all_pci_device_ids() -> list[str]: def all_pci_device_ids() -> list[str]:
@ -7,3 +8,9 @@ def all_pci_device_ids() -> list[str]:
def all_pci_driver_ids() -> list[str]: def all_pci_driver_ids() -> list[str]:
return listdir("/sys/bus/pci/drivers") return listdir("/sys/bus/pci/drivers")
def driver_of_pci_device(pci_device_id: str) -> str:
driver_directory: str = realpath(
f"/sys/bus/pci/devices/{pci_device_id}/driver")
return basename(driver_directory)

View file

@ -1,19 +1,15 @@
from os.path import exists, realpath, basename from pci_passthrough_assist.pci import driver_of_pci_device
from os.path import exists
from os import listdir from os import listdir
class PciDevice: class PciDevice:
def __init__(self, device_id: str): def __init__(self, device_id: str):
assert exists(f"/sys/bus/pci/devices/{device_id}")
self.device_id = device_id self.device_id = device_id
def driver_name(self) -> str: def driver_name(self) -> str:
pci_driver_path = f"/sys/bus/pci/devices/{self.device_id}/driver" return driver_of_pci_device(self.device_id)
if not exists(pci_driver_path):
return "NO-DRIVER-BOUND"
driver_directory: str = realpath(pci_driver_path)
return basename(driver_directory)
def is_vga(self) -> bool: def is_vga(self) -> bool:
return exists(f"/sys/bus/pci/devices/{self.device_id}/boot_vga") return exists(f"/sys/bus/pci/devices/{self.device_id}/boot_vga")
@ -46,20 +42,13 @@ class PciDevice:
if unbind_first: if unbind_first:
self.unbind_driver() self.unbind_driver()
driver_bind_path = f"/sys/bus/pci/drivers/{driver_to_bind}/bind" with open(f"/sys/bus/pci/drivers/{driver_to_bind}/bind",
if not exists(driver_bind_path): "w") as driver:
print(f"Can't bind to driver: {driver_bind_path}.")
return
with open(driver_bind_path, "w") as driver:
driver.write(self.device_id) driver.write(self.device_id)
def devices_in_iommu_group(self) -> list['PciDevice']: def devices_in_iommu_group(self) -> list['PciDevice']:
iommu_group_device_path = f"/sys/bus/pci/devices/{self.device_id}/iommu_group/devices" device_ids: list[str] = listdir(
if not exists(iommu_group_device_path): f"/sys/bus/pci/devices/{self.device_id}/iommu_group/devices")
print("Device does not have iommu_group devices.")
return []
device_ids: list[str] = listdir(iommu_group_device_path)
return [PciDevice(device_id) for device_id in device_ids] return [PciDevice(device_id) for device_id in device_ids]
def __str__(self) -> str: def __str__(self) -> str: