[PATCH 5/8] rust: pci: add vtable attribute to pci::Driver trait

Peter Colberg
2025-11-19T22:19:28Z

Add the #[vtable] attribute to pci::Driver trait and implementations,
to prepare a subsequent patch that adds an optional bus callback
sriov_configure() to enable or disable the SR-IOV capability.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Peter Colberg <pcolberg@redhat.com>
---
rust/kernel/pci.rs | 1 +
samples/rust/rust_dma.rs | 1 +
samples/rust/rust_driver_auxiliary.rs | 1 +
samples/rust/rust_driver_pci.rs | 1 +
4 files changed, 4 insertions(+)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index edb2bd41c8a14c8cfc421b26cda4dc84f75b546d..24dda12f6402098a1a323f3b5aae884201b26d89 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -275,6 +275,7 @@ macro_rules! pci_device_table {
///```
/// Drivers must implement this trait in order to get a PCI driver registered. Please refer to the
/// `Adapter` documentation for an example.
+#[vtable]
pub trait Driver: Send {
/// The type holding information about each device id supported by the driver.
// TODO: Use `associated_type_defaults` once stabilized:
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index f53bce2a73e3bb619372798c33bc3f13e580fdfc..96aa906984d8a40c5270bb2a7bcf9650a41b7c9e 100644
--- a/samples/rust/rust_dma.rs
+++ b/samples/rust/rust_dma.rs
@@ -51,6 +51,7 @@ unsafe impl kernel::transmute::FromBytes for MyStruct {}
[(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())]
);

+#[vtable]
impl pci::Driver for DmaSampleDriver {
type IdInfo = ();
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index 5761ea314f447643b8023b05ab7e92b60e6a1e17..23488fa6179fcc8c7a44df949d5eeeb1b132bd2d 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -64,6 +64,7 @@ struct ParentDriver {
[(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())]
);

+#[vtable]
impl pci::Driver for ParentDriver {
type IdInfo = ();

diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
index 5823787bea8ec3e9a38ab3e4941f6c88d70e00b4..400db907e061a6a782b1cfebe9e5744815cc2843 100644
--- a/samples/rust/rust_driver_pci.rs
+++ b/samples/rust/rust_driver_pci.rs
@@ -60,6 +60,7 @@ fn testdev(index: &TestIndex, bar: &Bar0) -> Result<u32> {
}
}

+#[vtable]
impl pci::Driver for SampleDriver {
type IdInfo = TestIndex;

--
2.51.1