diff options
| author | Gary Guo <gary@garyguo.net> | 2026-07-06 13:44:31 +0100 |
|---|---|---|
| committer | Danilo Krummrich <dakr@kernel.org> | 2026-07-11 18:09:04 +0200 |
| commit | 6ff7d69b7e6e0b09d53ffde472760f904ea5714f (patch) | |
| tree | eac49c98cea94c40a7e10a31b6f39fed366bc53d /samples | |
| parent | 0722567f5085bfc48d8b01c5c759745997e94785 (diff) | |
| download | linux-6ff7d69b7e6e0b09d53ffde472760f904ea5714f.tar.gz linux-6ff7d69b7e6e0b09d53ffde472760f904ea5714f.zip | |
rust: dma: drop `dma_read!` and `dma_write!` API
The primitive read/write use case is covered by the `io_read!` and
`io_write!` macro. The non-primitive use case was finicky; they should
either be achieved using `CoherentBox` or `as_ref()/as_mut()` to assert the
lack of concurrent access, or should be using memcpy-like APIs to express
the non-atomic and tearable nature.
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20260706-io_projection-v6-18-72cd5d055d54@garyguo.net
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/rust/rust_dma.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index 5046b4628d0e..4af46e99d2dd 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -12,6 +12,10 @@ use kernel::{ Device, DmaMask, // }, + io::{ + io_project, + io_read, // + }, page, pci, prelude::*, scatterlist::{Owned, SGTable}, @@ -77,7 +81,8 @@ impl pci::Driver for DmaSampleDriver { Coherent::zeroed_slice(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?; for (i, value) in TEST_VALUES.into_iter().enumerate() { - kernel::dma_write!(ca, [try: i], MyStruct::new(value.0, value.1)); + // SAFETY: `ca` is not yet shared with device or other threads. + unsafe { *io_project!(ca, [panic: i]).as_mut() = MyStruct::new(value.0, value.1) }; } let size = 4 * page::PAGE_SIZE; @@ -97,8 +102,8 @@ impl pci::Driver for DmaSampleDriver { impl DmaSampleDriver { fn check_dma(&self) { for (i, value) in TEST_VALUES.into_iter().enumerate() { - let val0 = kernel::dma_read!(self.ca, [panic: i].h); - let val1 = kernel::dma_read!(self.ca, [panic: i].b); + let val0 = io_read!(self.ca, [panic: i].h); + let val1 = io_read!(self.ca, [panic: i].b); assert_eq!(val0, value.0); assert_eq!(val1, value.1); |
