mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

A few new dependencies are required to remove some of the TODO items: - A way to safely convert from byte slices to types implementing `FromBytes`, - A way to obtain slices and write into a `CoherentAllocation`, - Several improvements to the `register!()` macro, - Alignment operations to powers of two, and an equivalent to the C `fls`, - Support for `xa_alloc` in the XAlloc bindings. Some items have also become obsolete: - The auxiliary bus abstractions have been implemented and are in use, - The ELF utilities are not considered for being part of the core kernel bindings anymore. - VBIOS, falcon and GPU timer have been completed. We now have quite a few TODO entries in the code, so annotate them with a 4 letter code representing the corresponding task in `todo.rst`. This allows to easily find which part of the code corresponds to a given entry (and conversely). Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250619-nova-frts-v6-24-ecf41ef99252@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//! Simple DMA object wrapper.
|
|
|
|
use core::ops::{Deref, DerefMut};
|
|
|
|
use kernel::device;
|
|
use kernel::dma::CoherentAllocation;
|
|
use kernel::page::PAGE_SIZE;
|
|
use kernel::prelude::*;
|
|
|
|
pub(crate) struct DmaObject {
|
|
dma: CoherentAllocation<u8>,
|
|
}
|
|
|
|
impl DmaObject {
|
|
pub(crate) fn new(dev: &device::Device<device::Bound>, len: usize) -> Result<Self> {
|
|
let len = core::alloc::Layout::from_size_align(len, PAGE_SIZE)
|
|
.map_err(|_| EINVAL)?
|
|
.pad_to_align()
|
|
.size();
|
|
let dma = CoherentAllocation::alloc_coherent(dev, len, GFP_KERNEL | __GFP_ZERO)?;
|
|
|
|
Ok(Self { dma })
|
|
}
|
|
|
|
pub(crate) fn from_data(dev: &device::Device<device::Bound>, data: &[u8]) -> Result<Self> {
|
|
Self::new(dev, data.len()).map(|mut dma_obj| {
|
|
// TODO[COHA]: replace with `CoherentAllocation::write()` once available.
|
|
// SAFETY:
|
|
// - `dma_obj`'s size is at least `data.len()`.
|
|
// - We have just created this object and there is no other user at this stage.
|
|
unsafe {
|
|
core::ptr::copy_nonoverlapping(
|
|
data.as_ptr(),
|
|
dma_obj.dma.start_ptr_mut(),
|
|
data.len(),
|
|
);
|
|
}
|
|
|
|
dma_obj
|
|
})
|
|
}
|
|
}
|
|
|
|
impl Deref for DmaObject {
|
|
type Target = CoherentAllocation<u8>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.dma
|
|
}
|
|
}
|
|
|
|
impl DerefMut for DmaObject {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.dma
|
|
}
|
|
}
|