mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 10:04:04 +02:00
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>
This commit is contained in:
parent
4dc0bacb1d
commit
e62e48adf7
|
|
@ -5,6 +5,7 @@
|
||||||
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
|
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
|
||||||
|
|
||||||
use kernel::{
|
use kernel::{
|
||||||
|
device::Bound,
|
||||||
device::Core,
|
device::Core,
|
||||||
devres::Devres,
|
devres::Devres,
|
||||||
io::Io,
|
io::Io,
|
||||||
|
|
@ -65,6 +66,30 @@ fn testdev(index: &TestIndex, bar: &Bar0) -> Result<u32> {
|
||||||
|
|
||||||
Ok(bar.read32(Regs::COUNT))
|
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 {
|
impl pci::Driver for SampleDriver {
|
||||||
|
|
@ -96,6 +121,7 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> impl PinInit<Self, Er
|
||||||
"pci-testdev data-match count: {}\n",
|
"pci-testdev data-match count: {}\n",
|
||||||
Self::testdev(info, bar)?
|
Self::testdev(info, bar)?
|
||||||
);
|
);
|
||||||
|
Self::config_space(pdev);
|
||||||
},
|
},
|
||||||
pdev: pdev.into(),
|
pdev: pdev.into(),
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user