Compare commits

...

4 commits

2 changed files with 23 additions and 2 deletions

2
.gitignore vendored
View file

@ -160,3 +160,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
/*util.sh

View file

@ -14,11 +14,30 @@ class PciDevice:
def is_vga(self) -> bool:
return exists(f"/sys/bus/pci/devices/{self.device_id}/boot_vga")
def vendor_code(self, remove_prefix: bool = True) -> str:
with open(f"/sys/bus/pci/devices/{self.device_id}/vendor") as vendor:
return vendor.read() if not remove_prefix else vendor.read(
).lstrip("0x")
def device_code(self, remove_prefix: bool = True) -> str:
with open(f"/sys/bus/pci/devices/{self.device_id}/vendor") as device:
return device.read() if not remove_prefix else device.read(
).lstrip("0x")
def unbind_driver(self):
with open(f"/sys/bus/pci/devices/{self.device_id}/driver/unbind",
"w") as device_driver:
driver_unbind_path = f"/sys/bus/pci/devices/{self.device_id}/driver/unbind"
if not exists(driver_unbind_path):
print("Device is not bound to any driver.")
return
with open(driver_unbind_path, "w") as device_driver:
device_driver.write(self.device_id)
def set_driver_override(self, reserved_for_driver: str):
with open(f"/sys/bus/pci/devices/{self.device_id}/driver_override",
"w") as driver_override:
driver_override.write(reserved_for_driver)
def bind_to_driver(self, driver_to_bind: str, unbind_first: bool = True):
if unbind_first:
self.unbind_driver()