[PATCH 06/14] rust: pci: add is_physfn(), to check for PFs

From: Zhi Wang

Date: Tue Sep 15 2026 - 16:58:49 EST


From: Peter Colberg <pcolberg@xxxxxxxxxx>

Add a method to check if a PCI device is a Physical Function (PF).

zhiw: Keep this role check private to the PCI SR-IOV implementation
instead of extending the public `Device` API. Add a dead-code
expectation because this standalone API commit has no in-tree caller.

Reviewed-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
Signed-off-by: Peter Colberg <pcolberg@xxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
rust/kernel/pci.rs | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 844d73a83670..ed42511911d7 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -507,6 +507,14 @@ pub fn resource_start(&self, bar: u32) -> Result<bindings::resource_size_t> {
Ok(unsafe { bindings::pci_resource_start(self.as_raw(), bar.try_into()?) })
}

+ /// Returns `true` if this device is a Physical Function (PF).
+ #[inline]
+ #[expect(dead_code)]
+ pub(crate) fn is_physfn(&self) -> bool {
+ // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
+ unsafe { (*self.as_raw()).is_physfn() != 0 }
+ }
+
/// Returns `true` if this device is a Virtual Function (VF).
#[inline]
#[expect(dead_code)]