Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpu: nova-core: firmware: gsp: use dma::Coherent for level0 table

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>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260327-b4-nova-dma-removal-v2-7-616e1d0b5cb3@nvidia.com
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

+12 -64
-53
drivers/gpu/nova-core/dma.rs
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - 3 - //! Simple DMA object wrapper. 4 - 5 - use core::ops::{ 6 - Deref, 7 - DerefMut, // 8 - }; 9 - 10 - use kernel::{ 11 - device, 12 - dma::Coherent, 13 - page::PAGE_SIZE, 14 - prelude::*, // 15 - }; 16 - 17 - pub(crate) struct DmaObject { 18 - dma: Coherent<[u8]>, 19 - } 20 - 21 - impl DmaObject { 22 - pub(crate) fn new(dev: &device::Device<device::Bound>, len: usize) -> Result<Self> { 23 - let len = core::alloc::Layout::from_size_align(len, PAGE_SIZE) 24 - .map_err(|_| EINVAL)? 25 - .pad_to_align() 26 - .size(); 27 - let dma = Coherent::zeroed_slice(dev, len, GFP_KERNEL)?; 28 - 29 - Ok(Self { dma }) 30 - } 31 - 32 - pub(crate) fn from_data(dev: &device::Device<device::Bound>, data: &[u8]) -> Result<Self> { 33 - let dma_obj = Self::new(dev, data.len())?; 34 - // SAFETY: We have just allocated the DMA memory, we are the only users and 35 - // we haven't made the device aware of the handle yet. 36 - unsafe { dma_obj.as_mut()[..data.len()].copy_from_slice(data) }; 37 - Ok(dma_obj) 38 - } 39 - } 40 - 41 - impl Deref for DmaObject { 42 - type Target = Coherent<[u8]>; 43 - 44 - fn deref(&self) -> &Self::Target { 45 - &self.dma 46 - } 47 - } 48 - 49 - impl DerefMut for DmaObject { 50 - fn deref_mut(&mut self) -> &mut Self::Target { 51 - &mut self.dma 52 - } 53 - }
+12 -10
drivers/gpu/nova-core/firmware/gsp.rs
··· 4 4 device, 5 5 dma::{ 6 6 Coherent, 7 + CoherentBox, 7 8 DataDirection, 8 9 DmaAddress, // 9 10 }, 10 - kvec, 11 11 prelude::*, 12 12 scatterlist::{ 13 13 Owned, ··· 16 16 }; 17 17 18 18 use crate::{ 19 - dma::DmaObject, 20 19 firmware::riscv::RiscvFirmware, 21 20 gpu::{ 22 21 Architecture, ··· 136 137 #[pin] 137 138 level1: SGTable<Owned<VVec<u8>>>, 138 139 /// Level 0 page table (single 4KB page) with one entry: DMA address of first level 1 page. 139 - level0: DmaObject, 140 + level0: Coherent<[u64]>, 140 141 /// Size in bytes of the firmware contained in [`Self::fw`]. 141 142 pub(crate) size: usize, 142 143 /// Device-mapped GSP signatures matching the GPU's [`Chipset`]. ··· 197 198 // Allocate the level 0 page table as a device-visible DMA object, and map the 198 199 // level 1 page table onto it. 199 200 200 - // Level 0 page table data. 201 - let mut level0_data = kvec![0u8; GSP_PAGE_SIZE]?; 202 - 203 201 // Fill level 1 page entry. 204 202 let level1_entry = level1.iter().next().ok_or(EINVAL)?; 205 203 let level1_entry_addr = level1_entry.dma_address(); 206 - let dst = &mut level0_data[..size_of_val(&level1_entry_addr)]; 207 - dst.copy_from_slice(&level1_entry_addr.to_le_bytes()); 208 204 209 - // Turn the level0 page table into a [`DmaObject`]. 210 - DmaObject::from_data(dev, &level0_data)? 205 + // Create level 0 page table data and fill its first entry with the level 1 206 + // table. 207 + let mut level0 = CoherentBox::<[u64]>::zeroed_slice( 208 + dev, 209 + GSP_PAGE_SIZE / size_of::<u64>(), 210 + GFP_KERNEL 211 + )?; 212 + level0[0] = level1_entry_addr.to_le(); 213 + 214 + level0.into() 211 215 }, 212 216 size, 213 217 signatures: {
-1
drivers/gpu/nova-core/nova_core.rs
··· 13 13 #[macro_use] 14 14 mod bitfield; 15 15 16 - mod dma; 17 16 mod driver; 18 17 mod falcon; 19 18 mod fb;