gpu: nova-core: mm: Add GpuMm centralized memory manager

Introduce GpuMm as the centralized GPU memory manager. At this point in
the series, GpuMm only owns the PRAMIN window for direct VRAM access;
the buddy allocator and TLB manager are added later when those backing
types become available.

This provides a clean ownership model where GpuMm provides accessor
methods for its components that can be used for memory management
operations, and lets follow-on patches (such as the PRAMIN aperture
self-tests) reference `pramin_mut()` cleanly.

Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
[ecourtney: squash the total VRAM end patch, drop its dev_info print]
[ecourtney: take the maximum FB limit before adding one, fail with EINVAL]
[ecourtney: rebase for the Bar0 lifetime and ownership changes, drop Arcs]
[ecourtney: source the chipset through gsp_resources]
[ecourtney: build the VRAM region in new(), pramin() becomes pramin_mut()]
[ecourtney: declare mm before gsp_resources, doc wording cleanups]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260827-pramin-split-v3-8-24b24d7afc52@nvidia.com
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
This commit is contained in:
Joel Fernandes 2026-08-27 17:51:49 +09:00 committed by Alexandre Courbot
parent b4481b9e3b
commit 5958450e98
4 changed files with 61 additions and 1 deletions

View File

@ -29,6 +29,10 @@
Gsp,
GspBootContext, //
},
mm::{
GpuMm,
VramAddress, //
},
vgpu::VgpuManager, //
};
@ -283,6 +287,11 @@ pub(crate) struct Gpu<'gpu> {
spec: Spec,
/// Static GPU information as provided by the GSP.
gsp_static_info: GetGspStaticInfoReply,
/// GPU memory manager owning memory management resources.
///
/// Must be kept declared *before* `gsp_resources`, so that its components are dropped while
/// the GSP is still operational.
mm: GpuMm<'gpu>,
/// GSP and its resources.
#[pin]
gsp_resources: GspResources<'gpu>,
@ -410,7 +419,14 @@ pub(crate) fn new<'a>(
}
info
}
},
// Create GPU memory manager owning memory management resources.
mm: GpuMm::new(
bar,
gsp_resources.spec.chipset,
VramAddress::from_raw(gsp_static_info.total_fb_end),
)?,
})
}
}

View File

@ -216,6 +216,8 @@ pub(crate) struct GetGspStaticInfoReply {
gpu_name: [u8; 64],
/// Usable FB (VRAM) regions for driver memory allocation.
pub(crate) usable_fb_regions: KVec<Range<u64>>,
/// Exclusive end of the FB physical address space.
pub(crate) total_fb_end: u64,
}
impl MessageFromGsp for GetGspStaticInfoReply {
@ -231,10 +233,12 @@ fn read(
for region in msg.usable_fb_regions() {
usable_fb_regions.push(region, GFP_KERNEL)?;
}
let total_fb_end = msg.total_fb_end().ok_or(EINVAL)?;
Ok(GetGspStaticInfoReply {
gpu_name: msg.gpu_name_str(),
usable_fb_regions,
total_fb_end,
})
}
}

View File

@ -165,6 +165,11 @@ pub(crate) fn usable_fb_regions(&self) -> impl Iterator<Item = Range<u64>> + '_
}
})
}
/// Computes the exclusive end of the FB physical address space.
pub(crate) fn total_fb_end(&self) -> Option<u64> {
self.fb_regions().map(|reg| reg.limit).max()?.checked_add(1)
}
}
// SAFETY: Padding is explicit and will not contain uninitialized data.

View File

@ -19,10 +19,45 @@
},
};
use crate::{
driver::Bar0,
gpu::Chipset, //
};
mod hal;
mod pramin;
mod regs;
/// GPU Memory Manager - owns all core MM components.
///
/// Provides centralized ownership of memory management resources:
/// - [`pramin::Pramin`] for direct VRAM access.
pub(crate) struct GpuMm<'gpu> {
pramin: pramin::Pramin<'gpu>,
}
impl<'gpu> GpuMm<'gpu> {
/// Creates the GPU memory manager.
pub(crate) fn new(
bar: Bar0<'gpu>,
chipset: Chipset,
total_fb_end: VramAddress,
) -> Result<Self> {
// 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 {
pramin: pramin::Pramin::new(bar, chipset, vram_region)?,
})
}
/// Access the [`pramin::Pramin`].
fn pramin_mut(&mut self) -> &mut pramin::Pramin<'gpu> {
&mut self.pramin
}
}
/// Physical VRAM address in GPU video memory.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)]