[PATCH v3 23/33] gpu: nova-core: add LIBOS3 log buffers and state monitor buffer

From: John Hubbard

Date: Thu Sep 17 2026 - 21:15:18 EST


GSP-RM runs on LIBOS, and each LIBOS task logs into a buffer that the
driver provides and names in the init argument array. The r000 firmware
runs LIBOS3, which has six logging tasks, and LIBOS3 also expects one
more page, the state monitor buffer, in which GSP-RM reports its own
state.

Nova-core allocated log buffers for three of the six tasks, and no state
monitor buffer.

Allocate the three missing log buffers and the state monitor buffer,
name every log buffer in the init argument array, and give each new log
a debugfs file next to the existing ones. The switch to r000 passes the
state monitor buffer to GSP-RM.

Assisted-by: LLM
Reviewed-by: Timur Tabi <ttabi@xxxxxxxxxx>
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
---
drivers/gpu/nova-core/gsp.rs | 129 ++++++++++++++++++++++++++---------
1 file changed, 98 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 90b4c3380f11..a8aec431b0b1 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -80,7 +80,6 @@ pub(crate) fn dev(&self) -> &'gpu device::Device<device::Bound> {

/// Number of GSP pages to use in a RM log buffer.
const RM_LOG_BUFFER_NUM_PAGES: usize = 0x10;
-const LOG_BUFFER_SIZE: usize = RM_LOG_BUFFER_NUM_PAGES * GSP_PAGE_SIZE;

/// Array of page table entries, as understood by the GSP bootloader.
#[repr(C)]
@@ -116,9 +115,19 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {
/// then pp points to index into the buffer where the next logging entry will
/// be written. Therefore, the logging data is valid if:
/// 1 <= pp < sizeof(buffer)/sizeof(u64)
-struct LogBuffer<'a>(Coherent<'a, [u8; LOG_BUFFER_SIZE]>);
+struct LogBuffer<'a, const NUM_PAGES: usize>(Coherent<'a, [[u8; GSP_PAGE_SIZE]; NUM_PAGES]>);

-impl<'a> LogBuffer<'a> {
+/// A log buffer at the default size, [`RM_LOG_BUFFER_NUM_PAGES`] pages.
+///
+/// Matches the registry defaults for the init, interrupt, RM and MNOC tasks
+/// (`NV_REG_STR_RM_GSP_LOG_BUFFER_SIZE_TASK_*_DEFAULT`).
+type TaskLogBuffer<'a> = LogBuffer<'a, RM_LOG_BUFFER_NUM_PAGES>;
+
+/// A single-page log buffer, the size of the logs of the root task and of the RM state monitor
+/// task.
+type SmallLogBuffer<'a> = LogBuffer<'a, 1>;
+
+impl<'a, const NUM_PAGES: usize> LogBuffer<'a, NUM_PAGES> {
/// Creates a new `LogBuffer` mapped on `dev`.
fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?);
@@ -127,22 +136,90 @@ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {

let pte_view = io_project!(
obj.0,
- [build: size_of::<u64>()..][build: ..RM_LOG_BUFFER_NUM_PAGES * size_of::<u64>()]
+ [build: 0][build: size_of::<u64>()..][build: ..NUM_PAGES * size_of::<u64>()]
)
- .try_cast::<PteArray<RM_LOG_BUFFER_NUM_PAGES>>()?;
+ .try_cast::<PteArray<NUM_PAGES>>()?;
PteArray::init(pte_view, start_addr)?;

Ok(obj)
}
}

+/// The log buffers to which GSP-RM writes its debug output, one per LIBOS3 task.
struct LogBuffers<'a> {
- /// Init log buffer.
- loginit: LogBuffer<'a>,
- /// Interrupts log buffer.
- logintr: LogBuffer<'a>,
- /// RM log buffer.
- logrm: LogBuffer<'a>,
+ /// Init task.
+ loginit: TaskLogBuffer<'a>,
+ /// Interrupt task.
+ logintr: TaskLogBuffer<'a>,
+ /// RM task.
+ logrm: TaskLogBuffer<'a>,
+ /// MNOC task.
+ logmnoc: TaskLogBuffer<'a>,
+ /// Root task.
+ logroot: SmallLogBuffer<'a>,
+ /// RM state monitor task.
+ logrmon: SmallLogBuffer<'a>,
+}
+
+impl<'a> LogBuffers<'a> {
+ /// Number of log buffers.
+ const COUNT: usize = 6;
+
+ /// Allocates the six log buffers, mapped on `dev`.
+ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
+ Ok(Self {
+ loginit: TaskLogBuffer::new(dev)?,
+ logintr: TaskLogBuffer::new(dev)?,
+ logrm: TaskLogBuffer::new(dev)?,
+ logmnoc: TaskLogBuffer::new(dev)?,
+ logroot: SmallLogBuffer::new(dev)?,
+ logrmon: SmallLogBuffer::new(dev)?,
+ })
+ }
+
+ /// Fills the first [`Self::COUNT`] entries of `libos` with the log buffers, under the names
+ /// that GSP-RM looks them up by.
+ fn init_arguments(
+ &self,
+ libos: &mut CoherentBox<'_, [LibosMemoryRegionInitArgument]>,
+ ) -> Result {
+ libos.init_at(
+ 0,
+ LibosMemoryRegionInitArgument::new("LOGINIT", &self.loginit.0),
+ )?;
+ libos.init_at(
+ 1,
+ LibosMemoryRegionInitArgument::new("LOGINTR", &self.logintr.0),
+ )?;
+ libos.init_at(
+ 2,
+ LibosMemoryRegionInitArgument::new("LOGRM", &self.logrm.0),
+ )?;
+ libos.init_at(
+ 3,
+ LibosMemoryRegionInitArgument::new("LOGMNOC", &self.logmnoc.0),
+ )?;
+ libos.init_at(
+ 4,
+ LibosMemoryRegionInitArgument::new("LOGROOT", &self.logroot.0),
+ )?;
+ libos.init_at(
+ 5,
+ LibosMemoryRegionInitArgument::new("LOGRMON", &self.logrmon.0),
+ )?;
+
+ Ok(())
+ }
+
+ /// Exposes each log buffer as a binary file in `dir`, under the lowercase form of its name.
+ fn register_debugfs<'data>(&'data self, dir: &debugfs::ScopedDir<'data, '_>) {
+ dir.read_binary_file(c"loginit", &self.loginit.0);
+ dir.read_binary_file(c"logintr", &self.logintr.0);
+ dir.read_binary_file(c"logrm", &self.logrm.0);
+ dir.read_binary_file(c"logmnoc", &self.logmnoc.0);
+ dir.read_binary_file(c"logroot", &self.logroot.0);
+ dir.read_binary_file(c"logrmon", &self.logrmon.0);
+ }
}

/// GSP runtime data.
@@ -158,6 +235,8 @@ pub(crate) struct Gsp<'gsp> {
pub(crate) cmdq: Cmdq<'gsp>,
/// RM arguments.
rmargs: Coherent<'gsp, GspArgumentsPadded>,
+ /// Buffer in which GSP-RM reports its own state.
+ rm_state_monitor: Coherent<'gsp, [u8; GSP_PAGE_SIZE]>,
}

impl<'gsp> Gsp<'gsp> {
@@ -168,17 +247,12 @@ pub(crate) fn new(
) -> impl PinInit<Self, Error> + 'gsp {
pin_init::pin_init_scope(move || {
let dev = pdev.as_ref();
+ let log_buffers = LogBuffers::new(dev)?;

- let loginit = LogBuffer::new(dev)?;
- let logintr = LogBuffer::new(dev)?;
- let logrm = LogBuffer::new(dev)?;
-
- // Initialise the logging structures. The OpenRM equivalents are in:
- // _kgspInitLibosLoggingStructures (allocates memory for buffers)
- // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
Ok(try_pin_init!(Self {
cmdq <- Cmdq::new(dev, bar),
rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?,
+ rm_state_monitor: Coherent::zeroed(dev, GFP_KERNEL)?,
libos: {
let mut libos = CoherentBox::zeroed_slice(
dev,
@@ -186,20 +260,15 @@ pub(crate) fn new(
GFP_KERNEL,
)?;

- libos.init_at(0, LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.0))?;
- libos.init_at(1, LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.0))?;
- libos.init_at(2, LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0))?;
- libos.init_at(3, LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?;
+ log_buffers.init_arguments(&mut libos)?;
+ libos.init_at(
+ LogBuffers::COUNT,
+ LibosMemoryRegionInitArgument::new("RMARGS", rmargs),
+ )?;

libos.into()
},
logs <- {
- let log_buffers = LogBuffers {
- loginit,
- logintr,
- logrm,
- };
-
#[allow(static_mut_refs)]
// SAFETY: `DEBUGFS_ROOT` is created before driver registration and cleared
// after driver unregistration, so no probe() can race with its modification.
@@ -211,9 +280,7 @@ pub(crate) fn new(
.expect("DEBUGFS_ROOT not initialized");

log_parent.scope(log_buffers, dev.name(), |logs, dir| {
- dir.read_binary_file(c"loginit", &logs.loginit.0);
- dir.read_binary_file(c"logintr", &logs.logintr.0);
- dir.read_binary_file(c"logrm", &logs.logrm.0);
+ logs.register_debugfs(dir)
})
},
}))
--
2.55.0