From: Alexandre Courbot <[email protected]>

Both the `CommandToGsp` and `MessageFromGsp` traits support a
variable-length payload, described using a `SBufferIter` of two slices
to represent the fact that the payload might wrap around the message
queue.

The type of this slice is rather convoluted, and does not convey its
purpose, eventually getting in the way of writing clean implementations
of the traits.

Define two type aliases, `CommandPayload` and `MessagePayload` that are
shorter to type and obvious as to their purpose, and use them where
relevant.

Signed-off-by: Alexandre Courbot <[email protected]>
Signed-off-by: Alok Kumar <[email protected]>
---
 drivers/gpu/nova-core/gsp/cmdq/gmc.rs     | 25 ++++++----
 drivers/gpu/nova-core/gsp/commands/gmc.rs | 56 +++++++++++------------
 drivers/gpu/nova-core/gsp/load_exec.rs    |  9 ++--
 3 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs 
b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
index 9e6c9400f3aa..af99e7d8e19c 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
@@ -37,6 +37,18 @@
     sbuffer::SBufferIter, //
 };
 
+/// Payload of a GMC command.
+///
+/// Since the command queue is circular, the payload may loop onto the start 
of the queue. Hence it
+/// is presented as a [`SBufferIter`] of potentially two elements.
+pub(crate) type CommandPayload<'a> = SBufferIter<core::array::IntoIter<&'a mut 
[u8], 2>>;
+
+/// Payload of a GMC message.
+///
+/// Since the message queue is circular, the payload may loop onto the start 
of the queue. Hence it
+/// is presented as a [`SBufferIter`] of potentially two elements.
+pub(crate) type MessagePayload<'a> = SBufferIter<core::array::IntoIter<&'a 
[u8], 2>>;
+
 /// Trait implemented by types representing a GMC command to send to the GSP.
 ///
 /// The main purpose of this trait is to provide [`Cmdq`] with the information 
it needs to send
@@ -94,10 +106,7 @@ fn variable_payload_len(&self) -> usize {
     /// unwritten space will lead to an error.
     ///
     /// Most commands don't have a variable-length payload, so this does 
nothing by default.
-    fn init_variable_payload(
-        &self,
-        _dst: &mut SBufferIter<core::array::IntoIter<&mut [u8], 2>>,
-    ) -> Result {
+    fn init_variable_payload(&self, _dst: &mut CommandPayload<'_>) -> Result {
         Ok(())
     }
 
@@ -178,18 +187,14 @@ pub(crate) trait MessageFromGsp: Sized {
     type InitError;
 
     /// Method reading the reply from the payload of the message and returning 
it.
-    fn read(
-        payload: &mut SBufferIter<core::array::IntoIter<&[u8], 2>>,
-    ) -> Result<Self, Self::InitError>;
+    fn read(payload: &mut MessagePayload<'_>) -> Result<Self, Self::InitError>;
 }
 
 /// Reply type for commands that the GSP answers with a status and no payload.
 impl MessageFromGsp for () {
     type InitError = Infallible;
 
-    fn read(
-        _payload: &mut SBufferIter<core::array::IntoIter<&[u8], 2>>,
-    ) -> Result<Self, Self::InitError> {
+    fn read(_payload: &mut MessagePayload<'_>) -> Result<Self, 
Self::InitError> {
         Ok(())
     }
 }
diff --git a/drivers/gpu/nova-core/gsp/commands/gmc.rs 
b/drivers/gpu/nova-core/gsp/commands/gmc.rs
index 14e04db90594..e1d47e86c82e 100644
--- a/drivers/gpu/nova-core/gsp/commands/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/commands/gmc.rs
@@ -11,34 +11,33 @@
     transmute::AsBytes, //
 };
 
-use crate::{
-    gsp::{
-        cmdq::{
-            gmc::{
-                CommandToGsp,
-                MessageFromGsp, //
-            },
-            NoReply, //
+use crate::gsp::{
+    cmdq::{
+        gmc::{
+            CommandPayload,
+            CommandToGsp,
+            MessageFromGsp,
+            MessagePayload, //
         },
-        commands::GspStaticInfo,
-        fw::{
-            self,
-            commands::{
-                GspInitRequest,
-                GspInitResponseSchema, //
-            },
-            GmcCommandId, //
-        },
-        nvkv::{
-            Decoder,
-            Encodable,
-            Encoder,
-            Schema,
-            UnknownKeyPolicy, //
+        NoReply,
+    },
+    commands::GspStaticInfo,
+    fw::{
+        self,
+        commands::{
+            GspInitRequest,
+            GspInitResponseSchema, //
         },
-        GspBootContext, //
+        GmcCommandId,
+    },
+    nvkv::{
+        Decoder,
+        Encodable,
+        Encoder,
+        Schema,
+        UnknownKeyPolicy, //
     },
-    sbuffer::SBufferIter, //
+    GspBootContext,
 };
 
 /// The `GSP_INIT` command, which carries the system information and registry 
keys to GSP-RM.
@@ -88,10 +87,7 @@ fn variable_payload_len(&self) -> usize {
         self.payload_bytes().len()
     }
 
-    fn init_variable_payload(
-        &self,
-        dst: &mut SBufferIter<core::array::IntoIter<&mut [u8], 2>>,
-    ) -> Result {
+    fn init_variable_payload(&self, dst: &mut CommandPayload<'_>) -> Result {
         dst.write_all(self.payload_bytes())
     }
 }
@@ -147,7 +143,7 @@ impl MessageFromGsp for GspStaticInfo {
     ///   or omits a required key, if GSP-RM reported no framebuffer region, 
or if the FIFO engine
     ///   count or indexed entries exceed the supported table capacity.
     /// - `ENOMEM` if the words or the decoded regions cannot be allocated.
-    fn read(payload: &mut SBufferIter<core::array::IntoIter<&[u8], 2>>) -> 
Result<Self> {
+    fn read(payload: &mut MessagePayload<'_>) -> Result<Self> {
         let bytes = payload.flush_into_kvec(GFP_KERNEL)?;
 
         let chunks = bytes.chunks_exact(size_of::<u64>());
diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs 
b/drivers/gpu/nova-core/gsp/load_exec.rs
index 6c3dcb0f80d8..e5cec38e049f 100644
--- a/drivers/gpu/nova-core/gsp/load_exec.rs
+++ b/drivers/gpu/nova-core/gsp/load_exec.rs
@@ -12,8 +12,6 @@
 //!   memory (DMEM) of a falcon, and the DMA engine that loads a binary into 
them. The DMA engine
 //!   accesses the framebuffer or system memory through the FBIF (Framebuffer 
Interface).
 
-use core::array;
-
 use kernel::{
     device,
     dma::DmaAddress,
@@ -42,7 +40,8 @@
     gsp::{
         cmdq::gmc::{
             GmcMessage,
-            MessageFromGsp, //
+            MessageFromGsp,
+            MessagePayload, //
         },
         fw::GmcCommandId,
         GspBootContext, //
@@ -384,7 +383,7 @@ struct HsBinaryParams {
 impl MessageFromGsp for HsBinaryParams {
     type InitError = Error;
 
-    fn read(payload: &mut SBufferIter<array::IntoIter<&[u8], 2>>) -> 
Result<Self> {
+    fn read(payload: &mut MessagePayload<'_>) -> Result<Self> {
         let mut params = Self::new_zeroed();
 
         payload.read_exact(params.as_mut_bytes())?;
@@ -500,7 +499,7 @@ fn fbif_target(&self) -> Result<FalconFbifTarget> {
 impl MessageFromGsp for GenericBootloaderParams {
     type InitError = Error;
 
-    fn read(payload: &mut SBufferIter<array::IntoIter<&[u8], 2>>) -> 
Result<Self> {
+    fn read(payload: &mut MessagePayload<'_>) -> Result<Self> {
         let mut params = Self::new_zeroed();
 
         payload.read_exact(params.as_mut_bytes())?;

Reply via email to