mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
samples: rust: pci: reset pci-testdev in unbind()
Reset the pci-testdev when the driver is unbound from its device. Link: https://lore.kernel.org/r/20250621195118.124245-9-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
parent
18ebb25dfa
commit
5f512533b7
|
|
@ -18,7 +18,7 @@ impl Regs {
|
|||
|
||||
type Bar0 = pci::Bar<{ Regs::END }>;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
struct TestIndex(u8);
|
||||
|
||||
impl TestIndex {
|
||||
|
|
@ -30,6 +30,7 @@ struct SampleDriver {
|
|||
pdev: ARef<pci::Device>,
|
||||
#[pin]
|
||||
bar: Devres<Bar0>,
|
||||
index: TestIndex,
|
||||
}
|
||||
|
||||
kernel::pci_device_table!(
|
||||
|
|
@ -79,6 +80,7 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> Result<Pin<KBox<Self>
|
|||
try_pin_init!(Self {
|
||||
pdev: pdev.into(),
|
||||
bar <- pdev.iomap_region_sized::<{ Regs::END }>(0, c_str!("rust_driver_pci")),
|
||||
index: *info,
|
||||
}),
|
||||
GFP_KERNEL,
|
||||
)?;
|
||||
|
|
@ -92,6 +94,13 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> Result<Pin<KBox<Self>
|
|||
|
||||
Ok(drvdata)
|
||||
}
|
||||
|
||||
fn unbind(pdev: &pci::Device<Core>, this: Pin<&Self>) {
|
||||
if let Ok(bar) = this.bar.access(pdev.as_ref()) {
|
||||
// Reset pci-testdev by writing a new test index.
|
||||
bar.write8(this.index.0, Regs::TEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pinned_drop]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user