From 6cc3a29828ff6f4394f206926a71a0dc8bbd11ae Mon Sep 17 00:00:00 2001 From: Filip Strajnar Date: Sat, 26 Oct 2024 19:54:30 +0200 Subject: [PATCH] Created unbind_driver and bind_to_driver. --- src/pci_passthrough_assist/pci_device.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pci_passthrough_assist/pci_device.py b/src/pci_passthrough_assist/pci_device.py index ee97910..491d81d 100644 --- a/src/pci_passthrough_assist/pci_device.py +++ b/src/pci_passthrough_assist/pci_device.py @@ -14,6 +14,19 @@ class PciDevice: def is_vga(self) -> bool: return exists(f"/sys/bus/pci/devices/{self.device_id}/boot_vga") + def unbind_driver(self): + with open(f"/sys/bus/pci/devices/{self.device_id}/driver/unbind", + "w") as device_driver: + device_driver.write(self.device_id) + + def bind_to_driver(self, driver_to_bind: str, unbind_first: bool = True): + if unbind_first: + self.unbind_driver() + + with open(f"/sys/bus/pci/drivers/{driver_to_bind}/bind", + "w") as driver: + driver.write(self.device_id) + def devices_in_iommu_group(self) -> list['PciDevice']: device_ids: list[str] = listdir( f"/sys/bus/pci/devices/{self.device_id}/iommu_group/devices")