summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhi Wang <zhiw@nvidia.com>2026-01-21 22:22:11 +0200
committerDanilo Krummrich <dakr@kernel.org>2026-01-23 21:24:59 +0100
commite62e48adf76cc4432c6d749a940da8649f8cb5a7 (patch)
tree7a870e49eae65feafb37c743452eb54a0e679e2a
parent4dc0bacb1d3c4722cbd002c4aab6bd458d30d869 (diff)
sample: rust: pci: add tests for config space routines
Add tests exercising the PCI configuration space helpers. Suggested-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Zhi Wang <zhiw@nvidia.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260121202212.4438-6-zhiw@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
-rw-r--r--samples/rust/rust_driver_pci.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
index 38c949efce38..8eea79e858a2 100644
--- a/samples/rust/rust_driver_pci.rs
+++ b/samples/rust/rust_driver_pci.rs
@@ -5,6 +5,7 @@
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
use kernel::{
+ device::Bound,
device::Core,
devres::Devres,
io::Io,
@@ -65,6 +66,30 @@ impl SampleDriver {
Ok(bar.read32(Regs::COUNT))
}
+
+ fn config_space(pdev: &pci::Device<Bound>) {
+ let config = pdev.config_space();
+
+ // TODO: use the register!() macro for defining PCI configuration space registers once it
+ // has been move out of nova-core.
+ dev_info!(
+ pdev.as_ref(),
+ "pci-testdev config space read8 rev ID: {:x}\n",
+ config.read8(0x8)
+ );
+
+ dev_info!(
+ pdev.as_ref(),
+ "pci-testdev config space read16 vendor ID: {:x}\n",
+ config.read16(0)
+ );
+
+ dev_info!(
+ pdev.as_ref(),
+ "pci-testdev config space read32 BAR 0: {:x}\n",
+ config.read32(0x10)
+ );
+ }
}
impl pci::Driver for SampleDriver {
@@ -96,6 +121,7 @@ impl pci::Driver for SampleDriver {
"pci-testdev data-match count: {}\n",
Self::testdev(info, bar)?
);
+ Self::config_space(pdev);
},
pdev: pdev.into(),
}))