The queue size, RX header offset and slot count are layout constants
just like the entry offset, so stop passing them as parameters.

No functional change.

Reviewed-by: Eliot Courtney <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/gsp/cmdq.rs | 13 +++++++------
 drivers/gpu/nova-core/gsp/fw.rs   | 23 +++++++++--------------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs 
b/drivers/gpu/nova-core/gsp/cmdq.rs
index 54b5d94d1328..10f6ddcf3eb5 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -7,8 +7,6 @@
 pub(super) mod gmc;
 pub(super) mod rpc;
 
-use core::mem;
-
 use kernel::{
     device,
     dma::{
@@ -176,11 +174,8 @@ struct DmaGspMem<'a> {
 impl<'a> DmaGspMem<'a> {
     /// Allocate a new instance and map it for `dev`.
     fn new(dev: &'a device::Device<device::Bound>, bar: Bar0<'a>) -> 
Result<Self> {
-        const MSGQ_SIZE: u32 = cv!(size_of::<Msgq>());
-        const RX_HDR_OFF: u32 = cv!(mem::offset_of!(Msgq, rx));
-
         let mut gsp_mem = CoherentBox::<'_, GspMem>::zeroed(dev, GFP_KERNEL)?;
-        gsp_mem.cpuq.tx = MsgqTxHeader::new(MSGQ_SIZE, RX_HDR_OFF, 
MSGQ_NUM_PAGES);
+        gsp_mem.cpuq.tx = MsgqTxHeader::new();
         gsp_mem.cpuq.rx = MsgqRxHeader::new();
 
         let gsp_mem: Coherent<'_, _> = gsp_mem.into();
@@ -476,6 +471,12 @@ impl<'cmdq> Cmdq<'cmdq> {
     /// Size of a queue slot. An element spans one or more slots.
     pub(super) const MSG_SIZE: usize = GSP_PAGE_SIZE;
 
+    /// Total size of a queue, headers included.
+    pub(super) const MSGQ_SIZE: usize = size_of::<Msgq>();
+
+    /// Offset of the RX header of a queue from its TX header.
+    pub(super) const MSGQ_RX_HDR_OFFSET: usize = core::mem::offset_of!(Msgq, 
rx);
+
     /// Offset of the ring buffer of a queue from its TX header.
     pub(super) const MSGQ_ENTRY_OFFSET: usize = core::mem::offset_of!(Msgq, 
msgq);
 
diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index ea0bde95d659..86cf62edec2b 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -50,7 +50,10 @@
         Chipset, //
     },
     gsp::{
-        cmdq::Cmdq, //
+        cmdq::{
+            Cmdq,
+            MSGQ_NUM_PAGES, //
+        },
         GSP_PAGE_SIZE,
     },
     mctp::{
@@ -702,24 +705,16 @@ fn id8(name: &str) -> u64 {
 pub(crate) struct MsgqTxHeader(bindings::msgqTxHeader);
 
 impl MsgqTxHeader {
-    /// Create a new TX queue header.
-    ///
-    /// # Arguments
-    ///
-    /// * `msgq_size` - Total size of the message queue structure, in bytes.
-    /// * `rx_hdr_offset` - Offset, in bytes, of the start of the RX header in 
the message queue
-    ///   structure.
-    /// * `msg_count` - Number of messages that can be sent, i.e. the number 
of memory pages
-    ///   allocated for the message queue in the message queue structure.
-    pub(crate) fn new(msgq_size: u32, rx_hdr_offset: u32, msg_count: u32) -> 
Self {
+    /// Create a new TX queue header, describing the queue layout defined by 
[`Cmdq`].
+    pub(crate) fn new() -> Self {
         Self(bindings::msgqTxHeader {
             version: 0,
-            size: msgq_size,
+            size: cv!(Cmdq::MSGQ_SIZE),
             msgSize: cv!(Cmdq::MSG_SIZE),
-            msgCount: msg_count,
+            msgCount: MSGQ_NUM_PAGES,
             writePtr: 0,
             flags: 1,
-            rxHdrOff: rx_hdr_offset,
+            rxHdrOff: cv!(Cmdq::MSGQ_RX_HDR_OFFSET),
             entryOff: cv!(Cmdq::MSGQ_ENTRY_OFFSET),
         })
     }

-- 
2.56.1

Reply via email to