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: Create rmargs

Initialise the GSP resource manager arguments (rmargs) which provides
initialisation parameters to the GSP firmware during boot. The rmargs
structure contains arguments to configure the GSP message/command queue
location.

These are mapped for coherent DMA and added to the libos data structure
for access when booting GSP.

Signed-off-by: Alistair Popple <apopple@nvidia.com>
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Message-ID: <20251110-gsp_boot-v9-10-8ae4058e3c0e@nvidia.com>

authored by

Alistair Popple and committed by
Alexandre Courbot
4fd4acd9 75f6b1de

+85 -4
+16 -2
drivers/gpu/nova-core/gsp.rs
··· 24 24 25 25 use crate::{ 26 26 gsp::cmdq::Cmdq, 27 - gsp::fw::LibosMemoryRegionInitArgument, 28 - num, // 27 + gsp::fw::{ 28 + GspArgumentsCached, 29 + LibosMemoryRegionInitArgument, // 30 + }, 31 + num, 29 32 }; 30 33 31 34 pub(crate) const GSP_PAGE_SHIFT: usize = 12; ··· 111 108 logrm: LogBuffer, 112 109 /// Command queue. 113 110 pub(crate) cmdq: Cmdq, 111 + /// RM arguments. 112 + rmargs: CoherentAllocation<GspArgumentsCached>, 114 113 } 115 114 116 115 impl Gsp { ··· 139 134 140 135 let cmdq = Cmdq::new(dev)?; 141 136 137 + let rmargs = CoherentAllocation::<GspArgumentsCached>::alloc_coherent( 138 + dev, 139 + 1, 140 + GFP_KERNEL | __GFP_ZERO, 141 + )?; 142 + dma_write!(rmargs[0] = fw::GspArgumentsCached::new(&cmdq))?; 143 + dma_write!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", &rmargs))?; 144 + 142 145 Ok(try_pin_init!(Self { 143 146 libos, 144 147 loginit, 145 148 logintr, 146 149 logrm, 150 + rmargs, 147 151 cmdq, 148 152 })) 149 153 }
+26 -1
drivers/gpu/nova-core/gsp/cmdq.rs
··· 11 11 12 12 use kernel::{ 13 13 device, 14 - dma::CoherentAllocation, 14 + dma::{ 15 + CoherentAllocation, 16 + DmaAddress, // 17 + }, 15 18 dma_write, 16 19 io::poll::read_poll_timeout, 17 20 prelude::*, ··· 36 33 MsgqTxHeader, // 37 34 }, 38 35 PteArray, 36 + GSP_PAGE_SHIFT, 39 37 GSP_PAGE_SIZE, // 40 38 }, 41 39 num, ··· 433 429 } 434 430 435 431 impl Cmdq { 432 + /// Offset of the data after the PTEs. 433 + const POST_PTE_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq); 434 + 435 + /// Offset of command queue ring buffer. 436 + pub(crate) const CMDQ_OFFSET: usize = core::mem::offset_of!(GspMem, cpuq) 437 + + core::mem::offset_of!(Msgq, msgq) 438 + - Self::POST_PTE_OFFSET; 439 + 440 + /// Offset of message queue ring buffer. 441 + pub(crate) const STATQ_OFFSET: usize = core::mem::offset_of!(GspMem, gspq) 442 + + core::mem::offset_of!(Msgq, msgq) 443 + - Self::POST_PTE_OFFSET; 444 + 445 + /// Number of page table entries for the GSP shared region. 446 + pub(crate) const NUM_PTES: usize = size_of::<GspMem>() >> GSP_PAGE_SHIFT; 447 + 436 448 /// Creates a new command queue for `dev`. 437 449 pub(crate) fn new(dev: &device::Device<device::Bound>) -> Result<Cmdq> { 438 450 let gsp_mem = DmaGspMem::new(dev)?; ··· 672 652 )?); 673 653 674 654 result 655 + } 656 + 657 + /// Returns the DMA handle of the command queue's shared memory region. 658 + pub(crate) fn dma_handle(&self) -> DmaAddress { 659 + self.gsp_mem.0.dma_handle() 675 660 } 676 661 }
+43 -1
drivers/gpu/nova-core/gsp/fw.rs
··· 31 31 fb::FbLayout, 32 32 firmware::gsp::GspFirmware, 33 33 gpu::Chipset, 34 - gsp::GSP_PAGE_SIZE, 34 + gsp::{ 35 + cmdq::Cmdq, // 36 + GSP_PAGE_SIZE, 37 + }, 35 38 num::{ 36 39 self, 37 40 FromSafeCast, // ··· 571 568 // SAFETY: This struct only contains integer types for which all bit patterns 572 569 // are valid. 573 570 unsafe impl FromBytes for GspMsgElement {} 571 + 572 + /// Arguments for GSP startup. 573 + #[repr(transparent)] 574 + pub(crate) struct GspArgumentsCached(bindings::GSP_ARGUMENTS_CACHED); 575 + 576 + impl GspArgumentsCached { 577 + /// Creates the arguments for starting the GSP up using `cmdq` as its command queue. 578 + pub(crate) fn new(cmdq: &Cmdq) -> Self { 579 + Self(bindings::GSP_ARGUMENTS_CACHED { 580 + messageQueueInitArguments: MessageQueueInitArguments::new(cmdq).0, 581 + bDmemStack: 1, 582 + ..Default::default() 583 + }) 584 + } 585 + } 586 + 587 + // SAFETY: Padding is explicit and will not contain uninitialized data. 588 + unsafe impl AsBytes for GspArgumentsCached {} 589 + 590 + // SAFETY: This struct only contains integer types for which all bit patterns 591 + // are valid. 592 + unsafe impl FromBytes for GspArgumentsCached {} 593 + 594 + /// Init arguments for the message queue. 595 + #[repr(transparent)] 596 + struct MessageQueueInitArguments(bindings::MESSAGE_QUEUE_INIT_ARGUMENTS); 597 + 598 + impl MessageQueueInitArguments { 599 + /// Creates a new init arguments structure for `cmdq`. 600 + fn new(cmdq: &Cmdq) -> Self { 601 + Self(bindings::MESSAGE_QUEUE_INIT_ARGUMENTS { 602 + sharedMemPhysAddr: cmdq.dma_handle(), 603 + pageTableEntryCount: num::usize_into_u32::<{ Cmdq::NUM_PTES }>(), 604 + cmdQueueOffset: num::usize_as_u64(Cmdq::CMDQ_OFFSET), 605 + statQueueOffset: num::usize_as_u64(Cmdq::STATQ_OFFSET), 606 + ..Default::default() 607 + }) 608 + } 609 + }