SharedPramin was introduced as a temporary wrapper so its mutex could be pin-initialized separately while GpuMm remained movable. This allowed PRAMIN locking to remove the need for mutable GpuMm references before converting GpuMm itself to pin initialization.
Now that GpuMm is pin-initialized, it can embed Mutex<Pramin> directly and hide the mutex's invariant resource lifetime itself. Remove the temporary wrapper. Signed-off-by: Danilo Krummrich <[email protected]> --- drivers/gpu/nova-core/mm.rs | 19 +++++++++++------ drivers/gpu/nova-core/mm/pramin.rs | 34 ------------------------------ 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs index 94c6f425c867..7aa8906d2cb2 100644 --- a/drivers/gpu/nova-core/mm.rs +++ b/drivers/gpu/nova-core/mm.rs @@ -44,13 +44,15 @@ macro_rules! impl_pfn_bounded { GpuBuddy, GpuBuddyParams, // }, + new_mutex, num::Bounded, prelude::*, ptr::{ Alignable, Alignment, // }, - sizes::SZ_4K, // + sizes::SZ_4K, + sync::Mutex, // }; use crate::{ @@ -72,13 +74,18 @@ macro_rules! impl_pfn_bounded { /// /// Provides centralized ownership of memory management resources: /// - [`GpuBuddy`] allocator for VRAM page table allocation. -/// - [`pramin::SharedPramin`] for direct VRAM access. +/// - [`pramin::Pramin`] for direct VRAM access. /// - [`Tlb`] manager for translation buffer flush operations. #[pin_data] -pub(crate) struct GpuMm<'gpu> { +pub(crate) struct GpuMm<'gpu> +where + // Hide the mutex's invariant resource lifetime so `GpuMm` remains covariant. + exists<'res>: 'gpu, +{ buddy: GpuBuddy, #[pin] - pramin: pramin::SharedPramin<'gpu>, + #[uses('res: invariant)] + pramin: Mutex<pramin::Pramin<'res>>, #[pin] tlb: Tlb<'gpu>, } @@ -97,7 +104,7 @@ pub(crate) fn new( try_pin_init!(Self { buddy: GpuBuddy::new(buddy_params)?, - pramin <- pramin::SharedPramin::new(bar, chipset, vram_region), + pramin <- new_mutex!(pramin::Pramin::new(bar, chipset, vram_region)?, "pramin"), tlb <- Tlb::new(bar), }) } @@ -111,7 +118,7 @@ pub(crate) fn buddy(&self) -> &GpuBuddy { /// /// Do not perform reclaimable allocations in `f`. fn with_pramin_locked<R>(&self, f: impl FnOnce(&mut pramin::Pramin<'_>) -> R) -> R { - self.pramin.with_locked(f) + self.with_pramin(|pramin| f(&mut pramin.lock())) } /// Access the [`Tlb`] manager. diff --git a/drivers/gpu/nova-core/mm/pramin.rs b/drivers/gpu/nova-core/mm/pramin.rs index 841289d7bccc..c83b1681d241 100644 --- a/drivers/gpu/nova-core/mm/pramin.rs +++ b/drivers/gpu/nova-core/mm/pramin.rs @@ -13,7 +13,6 @@ Io, Mmio, // }, - new_mutex, prelude::*, ptr::{ Alignable, @@ -23,7 +22,6 @@ SizeConstants, SZ_1M, // }, - sync::Mutex, // }; use crate::{ @@ -56,38 +54,6 @@ PRAMIN: PraminWindow @ 0x700000; } -/// A [`Pramin`] shared between users, serialized by a mutex. -#[pin_data] -pub(super) struct SharedPramin<'gpu> -where - // Hide the mutex's invariant resource lifetime so `SharedPramin` remains covariant. - exists<'res>: 'gpu, -{ - #[pin] - #[uses('res: invariant)] - inner: Mutex<Pramin<'res>>, -} - -impl<'gpu> SharedPramin<'gpu> { - /// Creates the shared window manager for the given VRAM region. - pub(super) fn new( - bar: Bar0<'gpu>, - chipset: Chipset, - vram_range: Range<VramAddress>, - ) -> impl PinInit<Self, Error> { - try_pin_init!(Self { - inner <- new_mutex!(Pramin::new(bar, chipset, vram_range)?, "pramin"), - }) - } - - /// Runs `f` with exclusive access to the PRAMIN window. - /// - /// Do not perform reclaimable allocations in `f`. - pub(super) fn with_locked<R>(&self, f: impl FnOnce(&mut Pramin<'_>) -> R) -> R { - self.with_inner(|inner| f(&mut inner.lock())) - } -} - /// Owner of the PRAMIN window state. /// /// [`Pramin::window_at()`] repositions the window as needed and returns a typed MMIO view into -- 2.56.1
