diff options
| author | Danilo Krummrich <[email protected]> | 2025-06-21 19:43:34 +0000 |
|---|---|---|
| committer | Danilo Krummrich <[email protected]> | 2025-07-08 22:04:33 +0000 |
| commit | 5f512533b7aa780488c15e001791d1b8000ad50e (patch) | |
| tree | 110aa0d2182656b8aa0dca299732d472e2d1fc3a /samples/rust/rust_driver_pci.rs | |
| parent | rust: pci: implement Driver::unbind() (diff) | |
| download | kernel-5f512533b7aa780488c15e001791d1b8000ad50e.tar.gz kernel-5f512533b7aa780488c15e001791d1b8000ad50e.zip | |
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/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
Diffstat (limited to 'samples/rust/rust_driver_pci.rs')
| -rw-r--r-- | samples/rust/rust_driver_pci.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs index 5c35f1414172..606946ff4d7f 100644 --- a/samples/rust/rust_driver_pci.rs +++ b/samples/rust/rust_driver_pci.rs @@ -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 @@ impl pci::Driver for SampleDriver { 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 @@ impl pci::Driver for SampleDriver { 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] |
