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: gsp: move Cmdq's DMA handle to a struct member

The command-queue structure has a `dma_handle` method that returns the
DMA handle to the memory segment shared with the GSP. This works, but is
not ideal for the following reasons:

- That method is effectively only ever called once, and is technically
an accessor method since the handle doesn't change over time,
- It feels a bit out-of-place with the other methods of `Cmdq` which
only deal with the sending or receiving of messages,
- The method has `pub(crate)` visibility, allowing other driver code to
access this highly-sensitive handle.

Address all these issues by turning `dma_handle` into a struct member
with `pub(super)` visibility. This keeps the method space focused, and
also ensures the member is not visible outside of the modules that need
it.

Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260319-b4-cmdq-dma-handle-v1-1-57840b4a4f90@nvidia.com
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

+16 -12
+15 -11
drivers/gpu/nova-core/gsp/cmdq.rs
··· 30 30 SplitState, // 31 31 }; 32 32 33 + use pin_init::pin_init_scope; 34 + 33 35 use crate::{ 34 36 driver::Bar0, 35 37 gsp::{ ··· 454 452 /// Inner mutex-protected state. 455 453 #[pin] 456 454 inner: Mutex<CmdqInner>, 455 + /// DMA handle of the command queue's shared memory region. 456 + pub(super) dma_handle: DmaAddress, 457 457 } 458 458 459 459 impl Cmdq { ··· 480 476 481 477 /// Creates a new command queue for `dev`. 482 478 pub(crate) fn new(dev: &device::Device<device::Bound>) -> impl PinInit<Self, Error> + '_ { 483 - try_pin_init!(Self { 484 - inner <- new_mutex!(CmdqInner { 485 - dev: dev.into(), 486 - gsp_mem: DmaGspMem::new(dev)?, 487 - seq: 0, 488 - }), 479 + pin_init_scope(move || { 480 + let gsp_mem = DmaGspMem::new(dev)?; 481 + 482 + Ok(try_pin_init!(Self { 483 + dma_handle: gsp_mem.0.dma_handle(), 484 + inner <- new_mutex!(CmdqInner { 485 + dev: dev.into(), 486 + gsp_mem, 487 + seq: 0, 488 + }), 489 + })) 489 490 }) 490 491 } 491 492 ··· 575 566 Error: From<M::InitError>, 576 567 { 577 568 self.inner.lock().receive_msg(timeout) 578 - } 579 - 580 - /// Returns the DMA handle of the command queue's shared memory region. 581 - pub(crate) fn dma_handle(&self) -> DmaAddress { 582 - self.inner.lock().gsp_mem.0.dma_handle() 583 569 } 584 570 } 585 571
+1 -1
drivers/gpu/nova-core/gsp/fw.rs
··· 912 912 #[allow(non_snake_case)] 913 913 fn new(cmdq: &Cmdq) -> impl Init<Self> + '_ { 914 914 init!(MessageQueueInitArguments { 915 - sharedMemPhysAddr: cmdq.dma_handle(), 915 + sharedMemPhysAddr: cmdq.dma_handle, 916 916 pageTableEntryCount: num::usize_into_u32::<{ Cmdq::NUM_PTES }>(), 917 917 cmdQueueOffset: num::usize_as_u64(Cmdq::CMDQ_OFFSET), 918 918 statQueueOffset: num::usize_as_u64(Cmdq::STATQ_OFFSET),