From: John Hubbard <[email protected]> Add a method to check if a PCI device is a Virtual Function (VF) created through Single Root I/O Virtualization (SR-IOV).
Signed-off-by: John Hubbard <[email protected]> Reviewed-by: Alistair Popple <[email protected]> Reviewed-by: Joel Fernandes <[email protected]> Signed-off-by: Peter Colberg <[email protected]> --- Changes in v2: - Add #[inline] to is_virtfn(). This patch was originally part of the series "rust: pci: expose is_virtfn() and reject VFs in nova-core" and modified as follows: - Replace true -> `true` in doc comment. - Shorten description and omit justification specific to nova-core. Link: https://lore.kernel.org/rust-for-linux/[email protected]/ --- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 88bd114970431bf8c3edef94c1d48567d895eaf6..db05641186c3a42922e2b6a463de9c1b099a4673 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -484,6 +484,13 @@ 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 Virtual Function (VF). + #[inline] + pub fn is_virtfn(&self) -> bool { + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. + unsafe { (*self.as_raw()).is_virtfn() != 0 } + } + /// Returns the size of the given PCI BAR resource. pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> { if !Bar::index_is_valid(bar) { -- 2.52.0
