Add simple excercises to test the scatterlist bindings.
Signed-off-by: Abdiel Janulgue <abdiel.janulgue@gmail.com>
---
samples/rust/rust_dma.rs | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index 874c2c964afa..e3768c1a16b7 100644
--- a/samples/rust/rust_dma.rs
+++ b/samples/rust/rust_dma.rs
@@ -4,11 +4,15 @@
//!
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
-use kernel::{bindings, device::Core, dma::CoherentAllocation, pci, prelude::*, types::ARef};
+use kernel::{
+ bindings, device::Core, dma::CoherentAllocation, page::*, pci, prelude::*,
+ scatterlist::DmaDataDirection::*, scatterlist::*, types::ARef,
+};
struct DmaSampleDriver {
pdev: ARef<pci::Device>,
ca: CoherentAllocation<MyStruct>,
+ _sgt: DeviceSGTable,
}
const TEST_VALUES: [(u32, u32); 5] = [
@@ -62,10 +66,18 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self
Ok(())
}()?;
+ let mut sgt = DeviceSGTable::alloc_table(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?;
+ for sg in sgt.iter_mut() {
+ sg.set_page(&Page::alloc_page(GFP_KERNEL)?, PAGE_SIZE as u32, 0);
+ }
+ sgt.dma_map(DmaToDevice)?;
+
let drvdata = KBox::new(
Self {
pdev: pdev.into(),
ca,
+ // Save object to excercise the destructor.
+ _sgt: sgt,
},
GFP_KERNEL,
)?;
--
2.43.0