The PRAMIN and TLB managers require stable addresses for their mutexes.

Pin-initialize GpuMm so they can be embedded directly instead of
allocating each separately.

Signed-off-by: Danilo Krummrich <[email protected]>
---
 drivers/gpu/nova-core/gpu.rs |  5 +++--
 drivers/gpu/nova-core/mm.rs  | 20 ++++++++++----------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 39e57e724a71..2f0399100885 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -399,6 +399,7 @@ pub(crate) struct Gpu<'gpu> {
     ///
     /// Must be kept declared *before* `gsp_resources`, so that its components 
are dropped while
     /// the GSP is still operational.
+    #[pin]
     mm: GpuMm<'gpu>,
     /// BAR1 user interface for CPU access to GPU virtual memory.
     #[pin]
@@ -562,7 +563,7 @@ pub(crate) fn new<'a>(
             },
 
             // Create GPU memory manager owning memory management resources.
-            mm: {
+            mm <- {
                 let usable_vram = 
gsp_static_info.usable_fb_regions.first().ok_or(ENODEV)?;
                 let buddy_params = GpuBuddyParams {
                     base_offset: usable_vram.start,
@@ -575,7 +576,7 @@ pub(crate) fn new<'a>(
                     gsp_resources.spec.chipset,
                     buddy_params,
                     VramAddress::from_raw(gsp_static_info.total_fb_end),
-                )?
+                )
             },
 
             // Create BAR1 user interface for CPU access to GPU virtual memory.
diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs
index 30a394424e12..94c6f425c867 100644
--- a/drivers/gpu/nova-core/mm.rs
+++ b/drivers/gpu/nova-core/mm.rs
@@ -74,10 +74,13 @@ macro_rules! impl_pfn_bounded {
 /// - [`GpuBuddy`] allocator for VRAM page table allocation.
 /// - [`pramin::SharedPramin`] for direct VRAM access.
 /// - [`Tlb`] manager for translation buffer flush operations.
+#[pin_data]
 pub(crate) struct GpuMm<'gpu> {
     buddy: GpuBuddy,
-    pramin: Pin<KBox<pramin::SharedPramin<'gpu>>>,
-    tlb: Pin<KBox<Tlb<'gpu>>>,
+    #[pin]
+    pramin: pramin::SharedPramin<'gpu>,
+    #[pin]
+    tlb: Tlb<'gpu>,
 }
 
 impl<'gpu> GpuMm<'gpu> {
@@ -87,18 +90,15 @@ pub(crate) fn new(
         chipset: Chipset,
         buddy_params: GpuBuddyParams,
         total_fb_end: VramAddress,
-    ) -> Result<Self> {
+    ) -> impl PinInit<Self, Error> {
         // PRAMIN covers all physical VRAM (including GSP-reserved areas
         // above the usable region, e.g. the BAR1 page directory).
         let vram_region = VramAddress::ZERO..total_fb_end;
 
-        Ok(Self {
+        try_pin_init!(Self {
             buddy: GpuBuddy::new(buddy_params)?,
-            pramin: KBox::pin_init(
-                pramin::SharedPramin::new(bar, chipset, vram_region),
-                GFP_KERNEL,
-            )?,
-            tlb: KBox::pin_init(Tlb::new(bar), GFP_KERNEL)?,
+            pramin <- pramin::SharedPramin::new(bar, chipset, vram_region),
+            tlb <- Tlb::new(bar),
         })
     }
 
@@ -116,7 +116,7 @@ fn with_pramin_locked<R>(&self, f: impl FnOnce(&mut 
pramin::Pramin<'_>) -> R) ->
 
     /// Access the [`Tlb`] manager.
     pub(crate) fn tlb(&self) -> &Tlb<'gpu> {
-        self.tlb.as_ref().get_ref()
+        &self.tlb
     }
 }
 
-- 
2.56.1

Reply via email to