Commit 5f512533 authored by Danilo Krummrich's avatar Danilo Krummrich
Browse files

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: default avatarDanilo Krummrich <dakr@kernel.org>
parent 18ebb25d
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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]