[PATCH v3 07/33] gpu: nova-core: gsp: make command allocation generic over the header
From: John Hubbard
Date: Thu Sep 17 2026 - 21:09:53 EST
The r000 firmware accepts GMC (GPU Management Controller) API commands,
which open with a different element header from RPC commands. The two
kinds of command go into the same command queue, so the wait for free
space, the maximum element size and the split of a command across the
end of the ring buffer are the same for both.
Nova-core's queue allocation named the RPC element header directly, so
there was no way to reserve queue space for a command with another
header.
Make the allocation generic over the header type, along with the handle
that it returns for the command. The one existing caller passes an RPC
element header and is unchanged.
No functional changes.
Assisted-by: LLM
Reviewed-by: Timur Tabi <ttabi@xxxxxxxxxx>
Reviewed-by: Zhi Wang <zhiw@xxxxxxxxxx>
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
---
drivers/gpu/nova-core/gsp/cmdq.rs | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index f4545e3b52b3..80e6e79c5f3c 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -129,8 +129,8 @@ fn init_variable_payload(
Ok(())
}
- /// Total size of the command (including its variable-length payload) without the
- /// [`GspMsgElement`] header.
+ /// Total size of the command, its variable-length payload included, without the headers that
+ /// open the queue element.
fn size(&self) -> usize {
size_of::<Self::Command>() + self.variable_payload_len()
}
@@ -374,14 +374,19 @@ fn driver_write_area_size(&self) -> usize {
///
/// - `EMSGSIZE` if the command is larger than [`GSP_MSG_QUEUE_ELEMENT_SIZE_MAX`].
/// - `ETIMEDOUT` if space does not become available within the timeout.
- /// - `EIO` if the command header is not properly aligned.
- fn allocate_command(&mut self, size: usize, timeout: Delta) -> Result<GspCommand<'_>> {
- if size_of::<GspMsgElement>() + size > GSP_MSG_QUEUE_ELEMENT_SIZE_MAX {
+ /// - `EIO` if the first free slot is too short for the headers of type `H`, or misaligned for
+ /// them.
+ fn allocate_command<H: FromBytes + AsBytes>(
+ &mut self,
+ size: usize,
+ timeout: Delta,
+ ) -> Result<GspCommand<'_, H>> {
+ if size_of::<H>() + size > GSP_MSG_QUEUE_ELEMENT_SIZE_MAX {
return Err(EMSGSIZE);
}
read_poll_timeout(
|| Ok(self.driver_write_area_size()),
- |available_bytes| *available_bytes >= size_of::<GspMsgElement>() + size,
+ |available_bytes| *available_bytes >= size_of::<H>() + size,
Delta::from_micros(1),
timeout,
)?;
@@ -393,8 +398,7 @@ fn allocate_command(&mut self, size: usize, timeout: Delta) -> Result<GspCommand
(slice_1.as_flattened_mut(), slice_2.as_flattened_mut())
};
- // Extract area for the `GspMsgElement`.
- let (header, slice_1) = GspMsgElement::from_bytes_mut_prefix(slice_1).ok_or(EIO)?;
+ let (header, slice_1) = H::from_bytes_mut_prefix(slice_1).ok_or(EIO)?;
// Create the contents area.
let (slice_1, slice_2) = if slice_1.len() > size {
@@ -486,10 +490,12 @@ fn advance_cpu_write_ptr(&mut self, elem_count: u32) {
/// A command ready to be sent on the command queue.
///
+/// `H` is the type of the headers that open the element, such as [`GspMsgElement`] for an RM RPC.
+///
/// This is the type returned by [`DmaGspMem::allocate_command`].
-struct GspCommand<'a> {
+struct GspCommand<'a, H> {
// Writable reference to the header of the command.
- header: &'a mut GspMsgElement,
+ header: &'a mut H,
// Writable slices to the contents of the command. The second slice is zero unless the command
// loops over the command queue.
contents: (&'a mut [u8], &'a mut [u8]),
--
2.55.0