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: create GSP-RM logging buffers debugfs entries

Create read-only debugfs entries for LOGINIT, LOGRM, and LOGINTR, which
are the three primary printf logging buffers from GSP-RM. LOGPMU will
be added at a later date, as it requires support for its RPC message
first.

This patch uses the `pin_init_scope` feature to create the entries.
`pin_init_scope` solves the lifetime issue over the `DEBUGFS_ROOT`
reference by delaying its acquisition until the time the entry is
actually initialized.

Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Timur Tabi <ttabi@nvidia.com>
Tested-by: John Hubbard <jhubbard@nvidia.com>
Tested-by: Eliot Courtney <ecourtney@nvidia.com>
Link: https://patch.msgid.link/20260319212658.2541610-7-ttabi@nvidia.com
[ Rebase onto Coherent<T> changes. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Timur Tabi and committed by
Danilo Krummrich
dff8302c 09691f5d

+39 -8
+39 -8
drivers/gpu/nova-core/gsp.rs
··· 3 3 mod boot; 4 4 5 5 use kernel::{ 6 + debugfs, 6 7 device, 7 8 dma::{ 8 9 Coherent, ··· 107 106 } 108 107 } 109 108 110 - /// GSP runtime data. 111 - #[pin_data] 112 - pub(crate) struct Gsp { 113 - /// Libos arguments. 114 - pub(crate) libos: Coherent<[LibosMemoryRegionInitArgument]>, 109 + struct LogBuffers { 115 110 /// Init log buffer. 116 111 loginit: LogBuffer, 117 112 /// Interrupts log buffer. 118 113 logintr: LogBuffer, 119 114 /// RM log buffer. 120 115 logrm: LogBuffer, 116 + } 117 + 118 + /// GSP runtime data. 119 + #[pin_data] 120 + pub(crate) struct Gsp { 121 + /// Libos arguments. 122 + pub(crate) libos: Coherent<[LibosMemoryRegionInitArgument]>, 123 + /// Log buffers, optionally exposed via debugfs. 124 + #[pin] 125 + logs: debugfs::Scope<LogBuffers>, 121 126 /// Command queue. 122 127 #[pin] 123 128 pub(crate) cmdq: Cmdq, ··· 137 130 pin_init::pin_init_scope(move || { 138 131 let dev = pdev.as_ref(); 139 132 133 + let loginit = LogBuffer::new(dev)?; 134 + let logintr = LogBuffer::new(dev)?; 135 + let logrm = LogBuffer::new(dev)?; 136 + 140 137 // Initialise the logging structures. The OpenRM equivalents are in: 141 138 // _kgspInitLibosLoggingStructures (allocates memory for buffers) 142 139 // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array) 143 140 Ok(try_pin_init!(Self { 144 - loginit: LogBuffer::new(dev)?, 145 - logintr: LogBuffer::new(dev)?, 146 - logrm: LogBuffer::new(dev)?, 147 141 cmdq <- Cmdq::new(dev), 148 142 rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?, 149 143 libos: { ··· 160 152 libos.init_at(3, LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?; 161 153 162 154 libos.into() 155 + }, 156 + logs <- { 157 + let log_buffers = LogBuffers { 158 + loginit, 159 + logintr, 160 + logrm, 161 + }; 162 + 163 + #[allow(static_mut_refs)] 164 + // SAFETY: `DEBUGFS_ROOT` is created before driver registration and cleared 165 + // after driver unregistration, so no probe() can race with its modification. 166 + // 167 + // PANIC: `DEBUGFS_ROOT` cannot be `None` here. It is set before driver 168 + // registration and cleared after driver unregistration, so it is always 169 + // `Some` for the entire lifetime that probe() can be called. 170 + let log_parent: &debugfs::Dir = unsafe { crate::DEBUGFS_ROOT.as_ref() } 171 + .expect("DEBUGFS_ROOT not initialized"); 172 + 173 + log_parent.scope(log_buffers, dev.name(), |logs, dir| { 174 + dir.read_binary_file(c"loginit", &logs.loginit.0); 175 + dir.read_binary_file(c"logintr", &logs.logintr.0); 176 + dir.read_binary_file(c"logrm", &logs.logrm.0); 177 + }) 163 178 }, 164 179 })) 165 180 })