From: John Hubbard <[email protected]>

`Gsp::new()` names each log buffer in the init argument array itself,
which requires the buffers to be visible outside of their module.

Move that code into `LogBuffers::init_arguments()`, using a new
`LibosInitArgs` writer type to fill the arguments while transparently
keeping track of the current position.

No functional change.

Signed-off-by: John Hubbard <[email protected]>
Co-developed-by: Alexandre Courbot <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/gsp.rs           | 57 +++++++++++++++++++++-------------
 drivers/gpu/nova-core/gsp/logbuffer.rs | 21 +++++++++++--
 2 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index bf0028e52e3c..28bd76626cf6 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -98,6 +98,38 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> 
Result<()> {
     }
 }
 
+/// Writer for the `LibosMemoryRegionInitArgument` array passed to the GSP 
bootloader.
+struct LibosInitArgs<'a> {
+    buf: CoherentBox<'a, [LibosMemoryRegionInitArgument]>,
+    len: usize,
+}
+
+impl<'a> LibosInitArgs<'a> {
+    /// Allocates a zeroed `LibosMemoryRegionInitArgument` array for `dev`.
+    fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
+        Ok(Self {
+            buf: CoherentBox::zeroed_slice(
+                dev,
+                GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
+                GFP_KERNEL,
+            )?,
+            len: 0,
+        })
+    }
+
+    /// Appends an entry to the array.
+    fn push(&mut self, arg: impl Init<LibosMemoryRegionInitArgument>) -> 
Result {
+        self.buf.init_at(self.len, arg)?;
+        self.len += 1;
+        Ok(())
+    }
+
+    /// Consumes the writer and returns the underlying coherent DMA allocation.
+    fn finish(self) -> Coherent<'a, [LibosMemoryRegionInitArgument]> {
+        self.buf.into()
+    }
+}
+
 /// GSP runtime data.
 #[pin_data]
 pub(crate) struct Gsp<'gsp> {
@@ -131,27 +163,10 @@ pub(crate) fn new(
                 cmdq <- Cmdq::new(dev, bar),
                 rmargs: Coherent::init(dev, GFP_KERNEL, 
GspArgumentsPadded::new(&cmdq))?,
                 libos: {
-                    let mut libos = CoherentBox::zeroed_slice(
-                        dev,
-                        GSP_PAGE_SIZE / 
size_of::<LibosMemoryRegionInitArgument>(),
-                        GFP_KERNEL,
-                    )?;
-
-                    libos.init_at(
-                        0,
-                        LibosMemoryRegionInitArgument::new("LOGINIT", 
&log_buffers.loginit.0),
-                    )?;
-                    libos.init_at(
-                        1,
-                        LibosMemoryRegionInitArgument::new("LOGINTR", 
&log_buffers.logintr.0),
-                    )?;
-                    libos.init_at(
-                        2,
-                        LibosMemoryRegionInitArgument::new("LOGRM", 
&log_buffers.logrm.0),
-                    )?;
-                    libos.init_at(3, 
LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?;
-
-                    libos.into()
+                    let mut libos = LibosInitArgs::new(dev)?;
+                    log_buffers.init_arguments(&mut libos)?;
+                    libos.push(LibosMemoryRegionInitArgument::new("RMARGS", 
rmargs))?;
+                    libos.finish()
                 },
                 logs <- log_buffers.into_debugfs_scope(),
             }))
diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs 
b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 5455d990ffb4..8ae80fa682a3 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -20,6 +20,8 @@
 
 use crate::{
     gsp::{
+        LibosInitArgs,
+        LibosMemoryRegionInitArgument,
         PteArray,
         GSP_PAGE_SIZE, //
     },
@@ -90,11 +92,11 @@ pub(super) struct LogBuffers<'a> {
     /// Device the buffers belong to.
     dev: &'a device::Device<device::Bound>,
     /// Init log buffer.
-    pub(super) loginit: LogBuffer<'a>,
+    loginit: LogBuffer<'a>,
     /// Interrupts log buffer.
-    pub(super) logintr: LogBuffer<'a>,
+    logintr: LogBuffer<'a>,
     /// RM log buffer.
-    pub(super) logrm: LogBuffer<'a>,
+    logrm: LogBuffer<'a>,
 }
 
 impl<'a> LogBuffers<'a> {
@@ -108,6 +110,19 @@ pub(super) fn new(dev: &'a device::Device<device::Bound>) 
-> Result<Self> {
         })
     }
 
+    /// Appends the log buffers to `libos`, under the names that GSP-RM looks 
them up by.
+    pub(super) fn init_arguments(&self, libos: &mut LibosInitArgs<'_>) -> 
Result {
+        libos.push(LibosMemoryRegionInitArgument::new(
+            "LOGINIT",
+            &self.loginit.0,
+        ))?;
+        libos.push(LibosMemoryRegionInitArgument::new(
+            "LOGINTR",
+            &self.logintr.0,
+        ))?;
+        libos.push(LibosMemoryRegionInitArgument::new("LOGRM", &self.logrm.0))
+    }
+
     /// Exposes the buffers in debugfs, in a directory named after their 
device.
     pub(super) fn into_debugfs_scope(self) -> impl 
PinInit<debugfs::Scope<Self>> + 'a {
         let dev = self.dev;

-- 
2.56.1

Reply via email to