Skip to content

Commit c7081ec

Browse files
author
Danilo Krummrich
committed
rust: dma: add type alias for bindings::dma_addr_t
Add a type alias for bindings::dma_addr_t (DmaAddress), such that we do not have to access bindings directly. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Suggested-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20250828133323.53311-3-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent c2437c4 commit c7081ec

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

drivers/gpu/nova-core/falcon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
55
use core::ops::Deref;
66
use hal::FalconHal;
7-
use kernel::bindings;
87
use kernel::device;
8+
use kernel::dma::DmaAddress;
99
use kernel::prelude::*;
1010
use kernel::sync::aref::ARef;
1111
use kernel::time::Delta;
@@ -455,7 +455,7 @@ impl<E: FalconEngine + 'static> Falcon<E> {
455455
fw.dma_handle_with_offset(load_offsets.src_start as usize)?,
456456
),
457457
};
458-
if dma_start % bindings::dma_addr_t::from(DMA_LEN) > 0 {
458+
if dma_start % DmaAddress::from(DMA_LEN) > 0 {
459459
dev_err!(
460460
self.dev,
461461
"DMA transfer start addresses must be a multiple of {}",

rust/kernel/dma.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ use crate::{
1313
types::ARef,
1414
};
1515

16+
/// DMA address type.
17+
///
18+
/// Represents a bus address used for Direct Memory Access (DMA) operations.
19+
///
20+
/// This is an alias of the kernel's `dma_addr_t`, which may be `u32` or `u64` depending on
21+
/// `CONFIG_ARCH_DMA_ADDR_T_64BIT`.
22+
///
23+
/// Note that this may be `u64` even on 32-bit architectures.
24+
pub type DmaAddress = bindings::dma_addr_t;
25+
1626
/// Trait to be implemented by DMA capable bus devices.
1727
///
1828
/// The [`dma::Device`](Device) trait should be implemented by bus specific device representations,
@@ -343,7 +353,7 @@ impl From<DataDirection> for bindings::dma_data_direction {
343353
// entire `CoherentAllocation` including the allocated memory itself.
344354
pub struct CoherentAllocation<T: AsBytes + FromBytes> {
345355
dev: ARef<device::Device>,
346-
dma_handle: bindings::dma_addr_t,
356+
dma_handle: DmaAddress,
347357
count: usize,
348358
cpu_addr: *mut T,
349359
dma_attrs: Attrs,
@@ -444,21 +454,21 @@ impl<T: AsBytes + FromBytes> CoherentAllocation<T> {
444454

445455
/// Returns a DMA handle which may be given to the device as the DMA address base of
446456
/// the region.
447-
pub fn dma_handle(&self) -> bindings::dma_addr_t {
457+
pub fn dma_handle(&self) -> DmaAddress {
448458
self.dma_handle
449459
}
450460

451461
/// Returns a DMA handle starting at `offset` (in units of `T`) which may be given to the
452462
/// device as the DMA address base of the region.
453463
///
454464
/// Returns `EINVAL` if `offset` is not within the bounds of the allocation.
455-
pub fn dma_handle_with_offset(&self, offset: usize) -> Result<bindings::dma_addr_t> {
465+
pub fn dma_handle_with_offset(&self, offset: usize) -> Result<DmaAddress> {
456466
if offset >= self.count {
457467
Err(EINVAL)
458468
} else {
459469
// INVARIANT: The type invariant of `Self` guarantees that `size_of::<T> * count` fits
460470
// into a `usize`, and `offset` is inferior to `count`.
461-
Ok(self.dma_handle + (offset * core::mem::size_of::<T>()) as bindings::dma_addr_t)
471+
Ok(self.dma_handle + (offset * core::mem::size_of::<T>()) as DmaAddress)
462472
}
463473
}
464474

0 commit comments

Comments
 (0)