From: Danilo Krummrich VFIO variant drivers need override-only IDs and VFIO-specific module aliases so userspace can select them for PCI assignment. Add a DeviceId constructor equivalent to PCI_DRIVER_OVERRIDE_DEVICE_VFIO, matching a vendor and device without restricting the PCI class. Signed-off-by: Danilo Krummrich Signed-off-by: Zhi Wang Signed-off-by: Simon Song --- rust/kernel/pci.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 4887052d31b1..fa67f2fc26bf 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -209,6 +209,21 @@ macro_rules! module_pci_driver { impl DeviceId { const PCI_ANY_ID: u32 = !0; + /// Create a new `pci::DeviceId` for a VFIO driver from a vendor and device ID. + /// + /// The ID matches every device with this vendor and device ID, whatever its class, but only + /// once userspace has selected the driver for the device through `driver_override`. The + /// driver is never bound to a matching device automatically. The module alias generated for + /// the ID has the `vfio_pci:` prefix, which lets userspace find the VFIO driver for a device. + /// + /// Equivalent to C's `PCI_DRIVER_OVERRIDE_DEVICE_VFIO` macro. + #[inline] + pub const fn from_id_vfio_override(vendor: Vendor, device: u32) -> Self { + let mut id = Self::from_id(vendor, device); + id.0.override_only = bindings::PCI_ID_F_VFIO_DRIVER_OVERRIDE; + id + } + /// Equivalent to C's `PCI_DEVICE` macro. /// /// Create a new `pci::DeviceId` from a vendor and device ID. -- 2.43.7