From: Eliot Courtney Date: Fri, 6 Mar 2026 07:22:04 +0000 (+0900) Subject: gpu: nova-core: gsp: add `size` helper to `CommandToGsp` X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adcb40c5fcf085b16327ab1eef11ec157c9f603b;p=thirdparty%2Fkernel%2Flinux.git gpu: nova-core: gsp: add `size` helper to `CommandToGsp` Add a default method to `CommandToGsp` which computes the size of a command. Tested-by: Zhi Wang Signed-off-by: Eliot Courtney Link: https://patch.msgid.link/20260306-cmdq-continuation-v6-7-cc7b629200ee@nvidia.com Signed-off-by: Alexandre Courbot --- diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs index b41a866e24da9..861f5666fe7fd 100644 --- a/drivers/gpu/nova-core/gsp/cmdq.rs +++ b/drivers/gpu/nova-core/gsp/cmdq.rs @@ -94,6 +94,12 @@ pub(crate) trait CommandToGsp { ) -> Result { Ok(()) } + + /// Total size of the command (including its variable-length payload) without the + /// [`GspMsgElement`] header. + fn size(&self) -> usize { + size_of::() + self.variable_payload_len() + } } /// Trait representing messages received from the GSP. @@ -529,10 +535,10 @@ impl Cmdq { // This allows all error types, including `Infallible`, to be used for `M::InitError`. Error: From, { - let command_size = size_of::() + command.variable_payload_len(); + let size_in_bytes = command.size(); let dst = self .gsp_mem - .allocate_command(command_size, Self::ALLOCATE_TIMEOUT)?; + .allocate_command(size_in_bytes, Self::ALLOCATE_TIMEOUT)?; // Extract area for the command itself. The GSP message header and the command header // together are guaranteed to fit entirely into a single page, so it's ok to only look @@ -540,7 +546,7 @@ impl Cmdq { let (cmd, payload_1) = M::Command::from_bytes_mut_prefix(dst.contents.0).ok_or(EIO)?; // Fill the header and command in-place. - let msg_element = GspMsgElement::init(self.seq, command_size, M::FUNCTION); + let msg_element = GspMsgElement::init(self.seq, size_in_bytes, M::FUNCTION); // SAFETY: `msg_header` and `cmd` are valid references, and not touched if the initializer // fails. unsafe {