* [PATCH v2 1/7] rust: dma: add from-slice constructors for Coherent and CoherentBox
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
@ 2026-03-26 15:22 ` Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 2/7] gpu: nova-core: firmware: riscv: use dma::Coherent Alexandre Courbot
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-26 15:22 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel, Alexandre Courbot
A very common pattern is to create a block of coherent memory with the
content of an already-existing slice of bytes (e.g. a loaded firmware
blob).
`CoherentBox` makes this easier, but still implies a potentially
panicking operation with `copy_from_slice` that requires a `PANIC`
comment.
Add `from_slice_with_attrs` and `from_slice` methods to both `Coherent`
and `CoherentBox` to turn this into a trivial one-step operation.
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
rust/kernel/dma.rs | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 8b7a9572ead2..40799fa418d6 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -453,6 +453,66 @@ pub fn init_at<E>(&mut self, i: usize, init: impl Init<T, E>) -> Result
Ok(())
}
+
+ /// Allocates a region of coherent memory of the same size as `data` and initializes it with a
+ /// copy of its contents.
+ ///
+ /// This is the [`CoherentBox`] variant of [`Coherent::from_slice_with_attrs`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use core::ops::Deref;
+ ///
+ /// # use kernel::device::{Bound, Device};
+ /// use kernel::dma::{
+ /// attrs::*,
+ /// CoherentBox
+ /// };
+ ///
+ /// # fn test(dev: &Device<Bound>) -> Result {
+ /// let data = [0u8, 1u8, 2u8, 3u8];
+ /// let c: CoherentBox<[u8]> =
+ /// CoherentBox::from_slice_with_attrs(dev, &data, GFP_KERNEL, DMA_ATTR_NO_WARN)?;
+ ///
+ /// assert_eq!(c.deref(), &data);
+ /// # Ok::<(), Error>(()) }
+ /// ```
+ pub fn from_slice_with_attrs(
+ dev: &device::Device<Bound>,
+ data: &[T],
+ gfp_flags: kernel::alloc::Flags,
+ dma_attrs: Attrs,
+ ) -> Result<Self>
+ where
+ T: Copy,
+ {
+ let mut slice = Self(Coherent::<T>::alloc_slice_with_attrs(
+ dev,
+ data.len(),
+ gfp_flags,
+ dma_attrs,
+ )?);
+
+ // PANIC: `slice` was created with length `data.len()`.
+ slice.copy_from_slice(data);
+
+ Ok(slice)
+ }
+
+ /// Performs the same functionality as [`CoherentBox::from_slice_with_attrs`], except the
+ /// `dma_attrs` is 0 by default.
+ #[inline]
+ pub fn from_slice(
+ dev: &device::Device<Bound>,
+ data: &[T],
+ gfp_flags: kernel::alloc::Flags,
+ ) -> Result<Self>
+ where
+ T: Copy,
+ {
+ Self::from_slice_with_attrs(dev, data, gfp_flags, Attrs(0))
+ }
}
impl<T: AsBytes + FromBytes> CoherentBox<T> {
@@ -839,6 +899,53 @@ pub fn zeroed_slice(
) -> Result<Coherent<[T]>> {
Self::zeroed_slice_with_attrs(dev, len, gfp_flags, Attrs(0))
}
+
+ /// Allocates a region of coherent memory of the same size as `data` and initializes it with a
+ /// copy of its contents.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// # use kernel::device::{Bound, Device};
+ /// use kernel::dma::{
+ /// attrs::*,
+ /// Coherent
+ /// };
+ ///
+ /// # fn test(dev: &Device<Bound>) -> Result {
+ /// let data = [0u8, 1u8, 2u8, 3u8];
+ /// // `c` has the same content as `data`.
+ /// let c: Coherent<[u8]> =
+ /// Coherent::from_slice_with_attrs(dev, &data, GFP_KERNEL, DMA_ATTR_NO_WARN)?;
+ ///
+ /// # Ok::<(), Error>(()) }
+ /// ```
+ #[inline]
+ pub fn from_slice_with_attrs(
+ dev: &device::Device<Bound>,
+ data: &[T],
+ gfp_flags: kernel::alloc::Flags,
+ dma_attrs: Attrs,
+ ) -> Result<Coherent<[T]>>
+ where
+ T: Copy,
+ {
+ CoherentBox::from_slice_with_attrs(dev, data, gfp_flags, dma_attrs).map(Into::into)
+ }
+
+ /// Performs the same functionality as [`Coherent::from_slice_with_attrs`], except the
+ /// `dma_attrs` is 0 by default.
+ #[inline]
+ pub fn from_slice(
+ dev: &device::Device<Bound>,
+ data: &[T],
+ gfp_flags: kernel::alloc::Flags,
+ ) -> Result<Coherent<[T]>>
+ where
+ T: Copy,
+ {
+ Self::from_slice_with_attrs(dev, data, gfp_flags, Attrs(0))
+ }
}
impl<T> Coherent<[T]> {
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v2 2/7] gpu: nova-core: firmware: riscv: use dma::Coherent
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 1/7] rust: dma: add from-slice constructors for Coherent and CoherentBox Alexandre Courbot
@ 2026-03-26 15:22 ` Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 3/7] gpu: nova-core: firmware: fwsec: " Alexandre Courbot
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-26 15:22 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel, Alexandre Courbot
Replace the nova-core local `DmaObject` with a `Coherent` that can
fulfill the same role.
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/firmware/riscv.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/riscv.rs b/drivers/gpu/nova-core/firmware/riscv.rs
index 14aad2f0ee8a..2afa7f36404e 100644
--- a/drivers/gpu/nova-core/firmware/riscv.rs
+++ b/drivers/gpu/nova-core/firmware/riscv.rs
@@ -5,13 +5,13 @@
use kernel::{
device,
+ dma::Coherent,
firmware::Firmware,
prelude::*,
transmute::FromBytes, //
};
use crate::{
- dma::DmaObject,
firmware::BinFirmware,
num::FromSafeCast, //
};
@@ -66,7 +66,7 @@ pub(crate) struct RiscvFirmware {
/// Application version.
pub(crate) app_version: u32,
/// Device-mapped firmware image.
- pub(crate) ucode: DmaObject,
+ pub(crate) ucode: Coherent<[u8]>,
}
impl RiscvFirmware {
@@ -81,7 +81,7 @@ pub(crate) fn new(dev: &device::Device<device::Bound>, fw: &Firmware) -> Result<
let len = usize::from_safe_cast(bin_fw.hdr.data_size);
let end = start.checked_add(len).ok_or(EINVAL)?;
- DmaObject::from_data(dev, fw.data().get(start..end).ok_or(EINVAL)?)?
+ Coherent::from_slice(dev, fw.data().get(start..end).ok_or(EINVAL)?, GFP_KERNEL)?
};
Ok(Self {
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v2 3/7] gpu: nova-core: firmware: fwsec: use dma::Coherent
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 1/7] rust: dma: add from-slice constructors for Coherent and CoherentBox Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 2/7] gpu: nova-core: firmware: riscv: use dma::Coherent Alexandre Courbot
@ 2026-03-26 15:22 ` Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 4/7] gpu: nova-core: falcon: " Alexandre Courbot
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-26 15:22 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel, Alexandre Courbot
Replace the nova-core local `DmaObject` with a `Coherent` that can
fulfill the same role.
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
index 3b12d90d9412..bcb713a868e2 100644
--- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
@@ -12,6 +12,7 @@
self,
Device, //
},
+ dma::Coherent,
io::{
register::WithBase, //
Io,
@@ -29,7 +30,6 @@
};
use crate::{
- dma::DmaObject,
driver::Bar0,
falcon::{
self,
@@ -129,7 +129,7 @@ unsafe impl AsBytes for BootloaderDmemDescV2 {}
/// operation.
pub(crate) struct FwsecFirmwareWithBl {
/// DMA object the bootloader will copy the firmware from.
- _firmware_dma: DmaObject,
+ _firmware_dma: Coherent<[u8]>,
/// Code of the bootloader to be loaded into non-secure IMEM.
ucode: KVec<u8>,
/// Descriptor to be loaded into DMEM for the bootloader to read.
@@ -211,7 +211,7 @@ pub(crate) fn new(
(
align_padding,
- DmaObject::from_data(dev, firmware_obj.as_slice())?,
+ Coherent::from_slice(dev, firmware_obj.as_slice(), GFP_KERNEL)?,
)
};
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v2 4/7] gpu: nova-core: falcon: use dma::Coherent
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
` (2 preceding siblings ...)
2026-03-26 15:22 ` [PATCH v2 3/7] gpu: nova-core: firmware: fwsec: " Alexandre Courbot
@ 2026-03-26 15:22 ` Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 5/7] gpu: nova-core: fb: use dma::CoherentHandle Alexandre Courbot
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-26 15:22 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel, Alexandre Courbot
Replace the nova-core local `DmaObject` with a `Coherent` that can
fulfill the same role.
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index c49ec6ded909..e0315fda576b 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -10,6 +10,7 @@
Device, //
},
dma::{
+ Coherent,
DmaAddress,
DmaMask, //
},
@@ -28,7 +29,6 @@
use crate::{
bounded_enum,
- dma::DmaObject,
driver::Bar0,
falcon::hal::LoadMethod,
gpu::Chipset,
@@ -504,7 +504,7 @@ pub(crate) fn pio_load<F: FalconFirmware<Target = E> + FalconPioLoadable>(
fn dma_wr(
&self,
bar: &Bar0,
- dma_obj: &DmaObject,
+ dma_obj: &Coherent<[u8]>,
target_mem: FalconMem,
load_offsets: FalconDmaLoadTarget,
) -> Result {
@@ -614,7 +614,7 @@ fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(
fw: &F,
) -> Result {
// Create DMA object with firmware content as the source of the DMA engine.
- let dma_obj = DmaObject::from_data(dev, fw.as_slice())?;
+ let dma_obj = Coherent::from_slice(dev, fw.as_slice(), GFP_KERNEL)?;
self.dma_reset(bar);
bar.update(regs::NV_PFALCON_FBIF_TRANSCFG::of::<E>().at(0), |v| {
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v2 5/7] gpu: nova-core: fb: use dma::CoherentHandle
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
` (3 preceding siblings ...)
2026-03-26 15:22 ` [PATCH v2 4/7] gpu: nova-core: falcon: " Alexandre Courbot
@ 2026-03-26 15:22 ` Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 6/7] gpu: nova-core: firmware: gsp: use dma::Coherent for signatures Alexandre Courbot
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-26 15:22 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel, Alexandre Courbot
Replace the nova-core local `DmaObject` with a `CoherentHandle` that can
fulfill the same role.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/fb.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/nova-core/fb.rs b/drivers/gpu/nova-core/fb.rs
index 62fc90fa6a84..bdd5eed760e1 100644
--- a/drivers/gpu/nova-core/fb.rs
+++ b/drivers/gpu/nova-core/fb.rs
@@ -7,6 +7,7 @@
use kernel::{
device,
+ dma::CoherentHandle,
fmt,
io::Io,
prelude::*,
@@ -19,7 +20,6 @@
};
use crate::{
- dma::DmaObject,
driver::Bar0,
firmware::gsp::GspFirmware,
gpu::Chipset,
@@ -53,7 +53,7 @@ pub(crate) struct SysmemFlush {
chipset: Chipset,
device: ARef<device::Device>,
/// Keep the page alive as long as we need it.
- page: DmaObject,
+ page: CoherentHandle,
}
impl SysmemFlush {
@@ -63,7 +63,7 @@ pub(crate) fn register(
bar: &Bar0,
chipset: Chipset,
) -> Result<Self> {
- let page = DmaObject::new(dev, kernel::page::PAGE_SIZE)?;
+ let page = CoherentHandle::alloc(dev, kernel::page::PAGE_SIZE, GFP_KERNEL)?;
hal::fb_hal(chipset).write_sysmem_flush_page(bar, page.dma_handle())?;
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v2 6/7] gpu: nova-core: firmware: gsp: use dma::Coherent for signatures
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
` (4 preceding siblings ...)
2026-03-26 15:22 ` [PATCH v2 5/7] gpu: nova-core: fb: use dma::CoherentHandle Alexandre Courbot
@ 2026-03-26 15:22 ` Alexandre Courbot
2026-03-26 15:22 ` [PATCH v2 7/7] gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table Alexandre Courbot
2026-03-26 17:24 ` [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Danilo Krummrich
7 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-26 15:22 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel, Alexandre Courbot
Replace the nova-core local `DmaObject` with a `Coherent` that can
fulfill the same role.
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/firmware/gsp.rs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 9488a626352f..1e0d545a74fe 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -3,6 +3,7 @@
use kernel::{
device,
dma::{
+ Coherent,
DataDirection,
DmaAddress, //
},
@@ -140,7 +141,7 @@ pub(crate) struct GspFirmware {
/// Size in bytes of the firmware contained in [`Self::fw`].
pub(crate) size: usize,
/// Device-mapped GSP signatures matching the GPU's [`Chipset`].
- pub(crate) signatures: DmaObject,
+ pub(crate) signatures: Coherent<[u8]>,
/// GSP bootloader, verifies the GSP firmware before loading and running it.
pub(crate) bootloader: RiscvFirmware,
}
@@ -226,7 +227,7 @@ pub(crate) fn new<'a>(
elf::elf64_section(firmware.data(), sigs_section)
.ok_or(EINVAL)
- .and_then(|data| DmaObject::from_data(dev, data))?
+ .and_then(|data| Coherent::from_slice(dev, data, GFP_KERNEL))?
},
bootloader: {
let bl = super::request_firmware(dev, chipset, "bootloader", ver)?;
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v2 7/7] gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
` (5 preceding siblings ...)
2026-03-26 15:22 ` [PATCH v2 6/7] gpu: nova-core: firmware: gsp: use dma::Coherent for signatures Alexandre Courbot
@ 2026-03-26 15:22 ` Alexandre Courbot
2026-03-26 17:24 ` [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Danilo Krummrich
7 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-26 15:22 UTC (permalink / raw)
To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
David Airlie, Simona Vetter
Cc: John Hubbard, Alistair Popple, Joel Fernandes, Timur Tabi,
Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel, Alexandre Courbot
Replace the nova-core local `DmaObject` with a `CoherentBox` that can
fulfill the same role.
Since `CoherentBox` is more flexible than `DmaObject`, we can use the
native `u64` type for page table entries instead of messing with bytes.
The `dma` module becomes unused with that change, so remove it as well.
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/dma.rs | 53 -----------------------------------
drivers/gpu/nova-core/firmware/gsp.rs | 22 ++++++++-------
drivers/gpu/nova-core/nova_core.rs | 1 -
3 files changed, 12 insertions(+), 64 deletions(-)
diff --git a/drivers/gpu/nova-core/dma.rs b/drivers/gpu/nova-core/dma.rs
deleted file mode 100644
index 3c19d5ffcfe8..000000000000
--- a/drivers/gpu/nova-core/dma.rs
+++ /dev/null
@@ -1,53 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-//! Simple DMA object wrapper.
-
-use core::ops::{
- Deref,
- DerefMut, //
-};
-
-use kernel::{
- device,
- dma::Coherent,
- page::PAGE_SIZE,
- prelude::*, //
-};
-
-pub(crate) struct DmaObject {
- dma: Coherent<[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 = Coherent::zeroed_slice(dev, len, GFP_KERNEL)?;
-
- Ok(Self { dma })
- }
-
- pub(crate) fn from_data(dev: &device::Device<device::Bound>, data: &[u8]) -> Result<Self> {
- let dma_obj = Self::new(dev, data.len())?;
- // SAFETY: We have just allocated the DMA memory, we are the only users and
- // we haven't made the device aware of the handle yet.
- unsafe { dma_obj.as_mut()[..data.len()].copy_from_slice(data) };
- Ok(dma_obj)
- }
-}
-
-impl Deref for DmaObject {
- type Target = Coherent<[u8]>;
-
- fn deref(&self) -> &Self::Target {
- &self.dma
- }
-}
-
-impl DerefMut for DmaObject {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.dma
- }
-}
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 1e0d545a74fe..86fb3f074195 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -4,10 +4,10 @@
device,
dma::{
Coherent,
+ CoherentBox,
DataDirection,
DmaAddress, //
},
- kvec,
prelude::*,
scatterlist::{
Owned,
@@ -16,7 +16,6 @@
};
use crate::{
- dma::DmaObject,
firmware::riscv::RiscvFirmware,
gpu::{
Architecture,
@@ -137,7 +136,7 @@ pub(crate) struct GspFirmware {
#[pin]
level1: SGTable<Owned<VVec<u8>>>,
/// Level 0 page table (single 4KB page) with one entry: DMA address of first level 1 page.
- level0: DmaObject,
+ level0: Coherent<[u64]>,
/// Size in bytes of the firmware contained in [`Self::fw`].
pub(crate) size: usize,
/// Device-mapped GSP signatures matching the GPU's [`Chipset`].
@@ -198,17 +197,20 @@ pub(crate) fn new<'a>(
// Allocate the level 0 page table as a device-visible DMA object, and map the
// level 1 page table onto it.
- // Level 0 page table data.
- let mut level0_data = kvec![0u8; GSP_PAGE_SIZE]?;
-
// Fill level 1 page entry.
let level1_entry = level1.iter().next().ok_or(EINVAL)?;
let level1_entry_addr = level1_entry.dma_address();
- let dst = &mut level0_data[..size_of_val(&level1_entry_addr)];
- dst.copy_from_slice(&level1_entry_addr.to_le_bytes());
- // Turn the level0 page table into a [`DmaObject`].
- DmaObject::from_data(dev, &level0_data)?
+ // Create level 0 page table data and fill its first entry with the level 1
+ // table.
+ let mut level0 = CoherentBox::<[u64]>::zeroed_slice(
+ dev,
+ GSP_PAGE_SIZE / size_of::<u64>(),
+ GFP_KERNEL
+ )?;
+ level0[0] = level1_entry_addr.to_le();
+
+ level0.into()
},
size,
signatures: {
diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
index 98675c69d2b7..04a1fa6b25f8 100644
--- a/drivers/gpu/nova-core/nova_core.rs
+++ b/drivers/gpu/nova-core/nova_core.rs
@@ -13,7 +13,6 @@
#[macro_use]
mod bitfield;
-mod dma;
mod driver;
mod falcon;
mod fb;
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core
2026-03-26 15:22 [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Alexandre Courbot
` (6 preceding siblings ...)
2026-03-26 15:22 ` [PATCH v2 7/7] gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table Alexandre Courbot
@ 2026-03-26 17:24 ` Danilo Krummrich
2026-03-27 6:57 ` Alexandre Courbot
7 siblings, 1 reply; 11+ messages in thread
From: Danilo Krummrich @ 2026-03-26 17:24 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Abdiel Janulgue, Daniel Almeida, Robin Murphy, Andreas Hindborg,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, David Airlie,
Simona Vetter, John Hubbard, Alistair Popple, Joel Fernandes,
Timur Tabi, Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel
On 3/26/26 4:22 PM, Alexandre Courbot wrote:
> Based on drm-rust-next, with [1] as extra dependency.
>
> [1] https://lore.kernel.org/all/20260321172749.592387-2-dakr@kernel.org/
[...]
> Alexandre Courbot (7):
> rust: dma: add from-slice constructors for Coherent and CoherentBox
> gpu: nova-core: firmware: riscv: use dma::Coherent
> gpu: nova-core: firmware: fwsec: use dma::Coherent
> gpu: nova-core: falcon: use dma::Coherent
> gpu: nova-core: fb: use dma::CoherentHandle
> gpu: nova-core: firmware: gsp: use dma::Coherent for signatures
> gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Feel free to also take the two DMA patches.
Thanks,
Danilo
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core
2026-03-26 17:24 ` [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core Danilo Krummrich
@ 2026-03-27 6:57 ` Alexandre Courbot
2026-03-28 14:52 ` Alexandre Courbot
0 siblings, 1 reply; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-27 6:57 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Abdiel Janulgue, Daniel Almeida, Robin Murphy, Andreas Hindborg,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, David Airlie,
Simona Vetter, John Hubbard, Alistair Popple, Joel Fernandes,
Timur Tabi, Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel
On Fri Mar 27, 2026 at 2:24 AM JST, Danilo Krummrich wrote:
> On 3/26/26 4:22 PM, Alexandre Courbot wrote:
>> Based on drm-rust-next, with [1] as extra dependency.
>>
>> [1] https://lore.kernel.org/all/20260321172749.592387-2-dakr@kernel.org/
>
> [...]
>
>> Alexandre Courbot (7):
>> rust: dma: add from-slice constructors for Coherent and CoherentBox
>> gpu: nova-core: firmware: riscv: use dma::Coherent
>> gpu: nova-core: firmware: fwsec: use dma::Coherent
>> gpu: nova-core: falcon: use dma::Coherent
>> gpu: nova-core: fb: use dma::CoherentHandle
>> gpu: nova-core: firmware: gsp: use dma::Coherent for signatures
>> gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table
>
> Reviewed-by: Danilo Krummrich <dakr@kernel.org>
>
> Feel free to also take the two DMA patches.
Thanks Danilo! I will leave it ~1 more day for reviews and will push
both unless someone screams.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/7] rust: dma: add from-slice constructors and use them in nova-core
2026-03-27 6:57 ` Alexandre Courbot
@ 2026-03-28 14:52 ` Alexandre Courbot
0 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-03-28 14:52 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Abdiel Janulgue, Daniel Almeida, Robin Murphy, Andreas Hindborg,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, David Airlie,
Simona Vetter, John Hubbard, Alistair Popple, Joel Fernandes,
Timur Tabi, Zhi Wang, Eliot Courtney, driver-core, rust-for-linux,
linux-kernel
On Fri Mar 27, 2026 at 3:57 PM JST, Alexandre Courbot wrote:
> On Fri Mar 27, 2026 at 2:24 AM JST, Danilo Krummrich wrote:
>> On 3/26/26 4:22 PM, Alexandre Courbot wrote:
>>> Based on drm-rust-next, with [1] as extra dependency.
>>>
>>> [1] https://lore.kernel.org/all/20260321172749.592387-2-dakr@kernel.org/
>>
>> [...]
>>
>>> Alexandre Courbot (7):
>>> rust: dma: add from-slice constructors for Coherent and CoherentBox
>>> gpu: nova-core: firmware: riscv: use dma::Coherent
>>> gpu: nova-core: firmware: fwsec: use dma::Coherent
>>> gpu: nova-core: falcon: use dma::Coherent
>>> gpu: nova-core: fb: use dma::CoherentHandle
>>> gpu: nova-core: firmware: gsp: use dma::Coherent for signatures
>>> gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table
>>
>> Reviewed-by: Danilo Krummrich <dakr@kernel.org>
>>
>> Feel free to also take the two DMA patches.
>
> Thanks Danilo! I will leave it ~1 more day for reviews and will push
> both unless someone screams.
Pushed to drm-rust-next, thanks everyone!
^ permalink raw reply [flat|nested] 11+ messages in thread