gpu: nova-core: add PRAMIN window support
Subsystems (8)
v3 cover gpu: nova-core: add PRAMIN window support
This series adds support for the PRAMIN window, plus some documentation. Some of these patches were originally written by Joel Fernandes [1]. I have updated them with changelog notes in each patch. For example, I updated them for the newer IO machinery from Gary Guo.
This series adds a Pramin structure which deals with updating the PRAMIN window and handing out typed MMIO views. The PRAMIN window is a method that lets arbitrary VRAM be written over BAR0 by configuring a 1 MiB window through GPU registers. That 1 MiB window can point anywhere in VRAM. This is useful for bootstrapping e.g. GPU side page tables.
The Pramin structure hands out typed MMIO views to do writes through rather than letting callers write directly through it. A follow up series will add support for GPU side page table entry writing through this mechanism. This abstraction is important for later since we will eventually want to write the PTEs via BAR2 not PRAMIN - using a view that we grab from the Pramin structure can abstract this out.
This is based on next-20260817 (e6664f2b33db), with Gary's register IO projection v3 series [2] applied on top.
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://patch.msgid.link/[email protected]
---
Changes in v3:
- Dropped first three Bounded patches which are merged now
- Rebase on v3 of IO reg projections
- Carry Gary's Io::cast patch which was dropped in the v3 since we use
it.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Rebase onto Gary's IO register projection series
- Drop Region::try_subregion patch in favour of Gary's reg projection
- Convert Pramin code to use Gary's reg projection
- Fix const {assert!} -> const_assert! (Gary)
- Add #[inline] to shr_exact (Sashiko, Alex)
- Link to v1: https://patch.msgid.link/[email protected]
---
Eliot Courtney (3):
gpu: nova-core: mm: Implement Alignable and Debug for VramAddress
gpu: nova-core: mm: Add the memory management HAL
gpu: nova-core: Add self-test assertion macros and config option
Gary Guo (1):
rust: io: add static cast() method for views
Joel Fernandes (6):
gpu: nova-core: mm: Add VramAddress type
gpu: nova-core: mm: Add PRAMIN window registers
gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM
docs: gpu: nova-core: Document the PRAMIN aperture mechanism
gpu: nova-core: mm: Add GpuMm centralized memory manager
gpu: nova-core: mm: Add PRAMIN aperture self-tests
Documentation/gpu/nova/core/pramin.rst | 128 +++++++++++++ Documentation/gpu/nova/index.rst | 1 + drivers/gpu/nova-core/Kconfig | 9 + drivers/gpu/nova-core/driver.rs | 3 + drivers/gpu/nova-core/gpu.rs | 30 ++- drivers/gpu/nova-core/gsp/commands.rs | 4 + drivers/gpu/nova-core/gsp/fw/commands.rs | 5 + drivers/gpu/nova-core/mm.rs | 163 ++++++++++++++++ drivers/gpu/nova-core/mm/hal.rs | 56 ++++++ drivers/gpu/nova-core/mm/hal/gb100.rs | 35 ++++ drivers/gpu/nova-core/mm/hal/gh100.rs | 35 ++++ drivers/gpu/nova-core/mm/hal/tu102.rs | 37 ++++ drivers/gpu/nova-core/mm/pramin.rs | 312 +++++++++++++++++++++++++++++++ drivers/gpu/nova-core/mm/regs.rs | 70 +++++++ drivers/gpu/nova-core/nova_core.rs | 3 + drivers/gpu/nova-core/selftest.rs | 64 +++++++ rust/kernel/io.rs | 39 ++++ 17 files changed, 993 insertions(+), 1 deletion(-)
---
base-commit: e6664f2b33db9b6811eb4cec109f06cb2b4f458d
change-id: 20260804-pramin-split-950e210b6e3f
prerequisite-change-id: 20260721-typed_register-176eab3abee7:v3
prerequisite-patch-id: 9d08451e181409e33cda3549dd2f6a18ad742a38
prerequisite-patch-id: 35e98efa10cce8cdd6c9df954c34d778a8b57e97
prerequisite-patch-id: 9dc002f047fb0c688c0ccce751535161fde8c216
prerequisite-patch-id: 551843cf854964cd9ef49378aa99000c8af73710
prerequisite-patch-id: 798405871b568af61cb6b9f0bf035c03b50eafe7
prerequisite-patch-id: fd9f266b3d8c80cc7ef4a3d59e302c25af9bb145
prerequisite-patch-id: 131291b0a4dc1ee7e43dd038f6f99fc5dc0eb99b
prerequisite-patch-id: 7c66eb2438e79edc6566b9e977ee33137d3e7fa1
prerequisite-patch-id: 8224018b7cfec0b00cce46b238abd9f68240e187
prerequisite-patch-id: cc910d5993c190268077d2dd56d787abd984465d
prerequisite-patch-id: 9590fa1a5c856c952eec73b630949a50e90ab4e8
prerequisite-patch-id: 511ce76481fe20bb1c498f020a5151bb008525f1
prerequisite-patch-id: 127be60ba6331574f6784cc8a5013d4f91b47df4
prerequisite-patch-id: d2faa8292625cbdc43f262f3773a1c5cc1f90935
prerequisite-patch-id: c447b4c47960e45497bd75bea84e6f1aea30eb74
prerequisite-patch-id: 5051a948fa965dd94348da1ec2f93bee8ff86106
Best regards,
Signature · 1 line
Eliot Courtney <[email protected]>
PATCH v3 1/10 gpu: nova-core: mm: Add VramAddress type
From: Joel Fernandes <[email protected]>
Add the VramAddress type representing a physical address in VRAM. Also add an arithmetic helper, comparison, and operator overloads which are required in later patches for address arithmetic.
--- drivers/gpu/nova-core/mm.rs | 60 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 1 + 2 files changed, 61 insertions(+)
drivers/gpu/nova-core/mm.rs new file +60 -0
@@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! Memory management subsystems. + +#![expect(dead_code)] + +use core::{ + fmt::LowerHex , + ops,// +}; + +use kernel::fmt; + +/// Physical VRAM address in GPU video memory. +#[derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord )] +#[repr(transparent)] +pub (crate )struct VramAddress (u64 ); + +impl VramAddress { +/// Creates an address from a raw value. +pub (crate )const fn from_raw (addr:u64 ) ->Self { +Self (addr) + } + +/// Returns the address as a raw value. +pub (crate )const fn into_raw (self) ->u64 { + self.0 + } + +/// Adds `rhs` to this address, returning [`None`] on overflow. +pub (crate )const fn checked_add (self, rhs:u64 ) ->Option <Self > { +match self.into_raw ().checked_add (rhs) { +Some (addr) =>Some (Self ::from_raw (addr)), +None =>None , + } + } +} + +impl LowerHex for VramAddress { +fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { +LowerHex ::fmt (&self.into_raw (), f) + } +} + +impl ops::Add <u64 >for VramAddress { +type Output =Self ; + +fn add (self, rhs:u64 ) ->Self ::Output { +Self ::from_raw (self.into_raw () + rhs) + } +} + +impl ops::Sub for VramAddress { +type Output =u64 ; + +fn sub (self, rhs:Self ) ->Self ::Output { + self.into_raw () - rhs.into_raw () + } +}
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -18,6 +18,7 @@mod gpu;mod gsp;mod mctp; +mod mm;#[macro_use] mod num;mod regs;
Signature · 1 line
2.55.0
PATCH v3 2/10 gpu: nova-core: mm: Implement Alignable and Debug for VramAddress
In reply to Eliot CourtneyLater patches align VRAM addresses down to the PRAMIN window. Implement Alignable trait for VramAddress and plus add a ZERO constant.
Also print the address in hex under {:?}, so it reads well in debug output.
--- drivers/gpu/nova-core/mm.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/mm.rs +27 -1
@@ -10,7 +10,14 @@ ops, // }; -use kernel::fmt; +use kernel::{ + fmt, + prelude::*, + ptr::{ +Alignable , +Alignment ,// + }, +};/// Physical VRAM address in GPU video memory. #[derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord )]
@@ -18,6 +25,9 @@pub (crate )struct VramAddress (u64 );impl VramAddress { +/// The zero address. +pub (crate )const ZERO :Self =Self ::from_raw (0 ); +/// Creates an address from a raw value. pub (crate )const fn from_raw (addr:u64 ) ->Self {Self (addr)
@@ -37,12 +47,28 @@ pub(crate) const fn checked_add(self, rhs: u64) -> Option<Self> { } } +impl Alignable for VramAddress { +fn align_down (self, alignment:Alignment ) ->Self { +Self ::from_raw (self.into_raw ().align_down (alignment)) + } + +fn align_up (self, alignment:Alignment ) ->Option <Self > { + self.into_raw ().align_up (alignment).map (Self ::from_raw) + } +} +impl LowerHex for VramAddress {fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result {LowerHex ::fmt (&self.into_raw (), f) } } +impl fmt::Debug for VramAddress { +fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { + f.write_fmt (fmt! ("{:#x}" , self)) + } +} +impl ops::Add <u64 >for VramAddress {type Output =Self ;
Signature · 1 line
2.55.0
PATCH v3 3/10 gpu: nova-core: mm: Add PRAMIN window registers
In reply to Eliot CourtneyFrom: Joel Fernandes <[email protected]>
PRAMIN apertures are a crucial mechanism for direct CPU read/write to VRAM. Add the BAR0 window registers that position the PRAMIN aperture on all supported GPU architectures: Turing, Ampere, Ada (via NV_PBUS_BAR0_WINDOW), Hopper (via gh100::NV_XAL_EP_BAR0_WINDOW), and Blackwell (via gb100::NV_XAL_EP_BAR0_WINDOW).
Hopper/Blackwell window-base registers are based on Eliot Courtney's offlist reference patch.
--- drivers/gpu/nova-core/mm.rs | 2 ++ drivers/gpu/nova-core/mm/regs.rs | 70 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
drivers/gpu/nova-core/mm.rs +2 -0
@@ -19,6 +19,8 @@ }, }; +mod regs; +/// Physical VRAM address in GPU video memory. #[derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord )] #[repr(transparent)]
drivers/gpu/nova-core/mm/regs.rs new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v3 4/10 gpu: nova-core: mm: Add the memory management HAL
In reply to Eliot CourtneyPositioning the PRAMIN window requires writing an architecture-specific
register: NV_PBUS_BAR0_WINDOW on Turing, Ampere and Ada, and NV_XAL_EP_BAR0_WINDOW with a different field width on Hopper and on Blackwell.
A MmHal trait with one implementation per hardware family hides the register choice from the rest of the mm code, matching the layout of the driver's other HALs.
--- drivers/gpu/nova-core/mm.rs | 1 + drivers/gpu/nova-core/mm/hal.rs | 56 +++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/mm/hal/gb100.rs | 35 ++++++++++++++++++++++ drivers/gpu/nova-core/mm/hal/gh100.rs | 35 ++++++++++++++++++++++ drivers/gpu/nova-core/mm/hal/tu102.rs | 37 +++++++++++++++++++++++ 5 files changed, 164 insertions(+)
drivers/gpu/nova-core/mm.rs +1 -0
@@ -19,6 +19,7 @@ }, }; +mod hal;mod regs;/// Physical VRAM address in GPU video memory.
drivers/gpu/nova-core/mm/hal.rs new file +56 -0
56 lines not on this page · raw message
drivers/gpu/nova-core/mm/hal/gb100.rs new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! Blackwell GB10x/GB20x memory management HAL. + +use kernel::{ + io::Io , + prelude::*,// +}; + +use crate ::{ + driver::Bar0 , + mm::{ + hal::{ + window_base, +MmHal ,// + }, + regs, +VramAddress ,// + }, +}; + +struct Gb100 ; + +impl MmHal for Gb100 { +fn write_pramin_window_base (&self, bar:Bar0 <'_>, base:VramAddress ) ->Result { + bar.write_reg ( + regs::gb100::NV_XAL_EP_BAR0_WINDOW ::zeroed ().with_base (window_base (base)?.cast ()), + ); +Ok (()) + } +} + +const GB100 :Gb100 =Gb100 ; +pub (super )const GB100_HAL : &dyn MmHal = &GB100 ;
drivers/gpu/nova-core/mm/hal/gh100.rs new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! Hopper memory management HAL. + +use kernel::{ + io::Io , + prelude::*,// +}; + +use crate ::{ + driver::Bar0 , + mm::{ + hal::{ + window_base, +MmHal ,// + }, + regs, +VramAddress ,// + }, +}; + +struct Gh100 ; + +impl MmHal for Gh100 { +fn write_pramin_window_base (&self, bar:Bar0 <'_>, base:VramAddress ) ->Result { + bar.write_reg ( + regs::gh100::NV_XAL_EP_BAR0_WINDOW ::zeroed ().with_base (window_base (base)?.cast ()), + ); +Ok (()) + } +} + +const GH100 :Gh100 =Gh100 ; +pub (super )const GH100_HAL : &dyn MmHal = &GH100 ;
drivers/gpu/nova-core/mm/hal/tu102.rs new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! Turing, Ampere and Ada memory management HAL. + +use kernel::{ + io::Io , + prelude::*,// +}; + +use crate ::{ + driver::Bar0 , + mm::{ + hal::{ + window_base, +MmHal ,// + }, + regs, +VramAddress ,// + }, +}; + +struct Tu102 ; + +impl MmHal for Tu102 { +fn write_pramin_window_base (&self, bar:Bar0 <'_>, base:VramAddress ) ->Result { + bar.write_reg ( + regs::NV_PBUS_BAR0_WINDOW ::zeroed () + .with_target (regs::Bar0WindowTarget ::VidMem ) + .with_base (window_base (base)?.cast ()), + ); +Ok (()) + } +} + +const TU102 :Tu102 =Tu102 ; +pub (super )const TU102_HAL : &dyn MmHal = &TU102 ;
Signature · 1 line
2.55.0
PATCH v3 5/10 rust: io: add static `cast()` method for views
In reply to Eliot CourtneyFrom: Gary Guo <[email protected]>
Add a compile-time checked variant of try_cast() using the minimum size and alignment information.
--- rust/kernel/io.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
rust/kernel/io.rs +39 -0
@@ -436,6 +436,45 @@ fn is_empty<T>(self) -> bool self.len () ==0 } +/// Convert into a different typed I/O view. +/// +/// The target type must be known (statically) to be of the same or smaller size to current +/// type, and the current view must be properly aligned for the target type. +/// +/// # Examples +/// +/// ```no_run +/// use kernel::io::{ +/// io_project, +/// Mmio, +/// Io, +/// Region, +/// }; +/// #[derive(FromBytes, IntoBytes)] +/// #[repr(C)] +/// struct MyStruct { field: u32, } +/// +/// # fn test(mmio: &Mmio<'_, Region<0x1000>>) { +/// // let mmio: Mmio<'_, Region<0x1000>>; +/// let whole: Mmio<'_, MyStruct> = mmio.cast(); +/// # } +/// ``` +#[inline] +fn cast <U >(self) -> <Self ::Backend as IoBackend >::View <'a,U > +where +Self ::Target :FromBytes +IntoBytes , +U :FromBytes +IntoBytes , + { +let view = self.as_view (); +let ptr =Self ::Backend ::as_ptr (view); + +const_assert! (size_of ::<U >() <=Self ::Target ::MIN_SIZE ); +const_assert! (align_of ::<U >() <=Self ::Target ::MIN_ALIGN .as_usize ()); + +// SAFETY: We have checked bounds and alignment, so this is a valid projection. +unsafe {Self ::Backend ::project_view (view, ptr.cast ()) } + } +/// Try to convert into a different typed I/O view. /// /// A runtime check is performed to ensure that the target type is of same or smaller size to
Signature · 1 line
2.55.0
Alexandre Courbot
maintainerRe: [PATCH v3 05/10] rust: io: add static `cast()` method for views
Quoted 9 lines · Eliot Courtney
From: Gary Guo <[email protected]>
Add a compile-time checked variant of
try_cast()using the minimum size and alignment information.Signed-off-by Gary Guo <[email protected]>[ecourtney: fix the doc example type and doc grammar per v2 review]Signed-off-by Eliot Courtney <[email protected]>
So I am basically ready to merge this series, but need an ack on this one patch; I/O maintainers, does this look good to you?
PATCH v3 6/10 gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM
In reply to Eliot CourtneyFrom: Joel Fernandes <[email protected]>
PRAMIN apertures are a crucial mechanism for direct CPU read/write to VRAM. Add a Pramin manager whose window_at() returns a typed MMIO view of VRAM through the 1 MiB PRAMIN aperture in BAR0, validating the view against the VRAM region and repositioning the window as needed for the accessed address.
A view borrows Pramin mutably, so the window cannot move while the view is in use, and it inserts an ordering point on Drop.
--- drivers/gpu/nova-core/mm.rs | 1 + drivers/gpu/nova-core/mm/pramin.rs | 178 +++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+)
drivers/gpu/nova-core/mm.rs +1 -0
@@ -20,6 +20,7 @@ };mod hal; +mod pramin;mod regs;/// Physical VRAM address in GPU video memory.
drivers/gpu/nova-core/mm/pramin.rs new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 06/10] gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Low] Compilation fails unconditionally because `kernel::io::register::OffsetLoc` is missing from the…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Low] Compilation fails unconditionally because kernel::io::register::OffsetLoc is missing from the kernel tree.
- [Low] The io_project! macro is invoked with unbracketed projection specifications, causing a compilation error.
- [Low] The Drop implementation for PraminAccess will fail to compile with a zero-sized type due to a const assertion failure in cast::<u8>(). --
commit da741ebe3207f602c3f762361899c60fcf5605a3
Author: Joel Fernandes <[email protected]>
gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM
This commit adds a Pramin manager to handle direct CPU read/write to VRAM via PRAMIN apertures. It returns an MMIO view of VRAM and handles repositioning and alignment of the window.
Quoted 6 lines
drivers/gpu/nova-core/mm/pramin.rs new file +0
-0@@ -0,0 +1,178 @@
[ ... ]
drivers/gpu/nova-core/mm/pramin.rs line 12
Quoted 5 lines
drivers/gpu/nova-core/mm/pramin.rs new file +5
-0+use kernel::{ + io::{ + io_project, + register, + register::OffsetLoc ,
[Severity: Low]
Does this code build? kernel::io::register::OffsetLoc appears to be missing from the kernel tree.
Quoted 3 lines
drivers/gpu/nova-core/mm/pramin.rs new file +3
-0+ Io, + Mmio, // + },
[ ... ]
drivers/gpu/nova-core/mm/pramin.rs line 100
Quoted 7 lines
drivers/gpu/nova-core/mm/pramin.rs new file +7
-0+impl <T >Drop for PraminAccess <'_,T > +where +T :FromBytes +IntoBytes , +{ +fn drop (&mut self) { +// Insert an ordering point after previous writes through this window. + self.view.cast ::<u8 >().read_val ();
[Severity: Low]
Will this fail to compile if PraminAccess is instantiated with a zero-sized type? Mmio::cast::<u8>() statically asserts that
size_of::<u8>() <= T::MIN_SIZE, which evaluates to 1 <= 0 for ZSTs and fails during monomorphization.
Quoted 4 lines
drivers/gpu/nova-core/mm/pramin.rs new file +4
-0+ } +} + +impl <'gpu>Pramin <'gpu> {
[ ... ]
drivers/gpu/nova-core/mm/pramin.rs line 115
Quoted 7 lines
drivers/gpu/nova-core/mm/pramin.rs new file +7
-0+pub (super )fn new ( + bar:Bar0 <'gpu>, + chipset:Chipset , + vram_range:Range <VramAddress >, + ) ->Result <Self > { +let hal = hal::mm_hal (chipset); +let window =io_project! (bar, build:PRAMIN );
[Severity: Low]
Is this macro syntax correct? The io_project! macro expects bracketed syntax for array and offset projections. Should this be [build: PRAMIN]?
Quoted 1 line
+ let base =
vram_range.start.align_down(Self::BASE_ALIGN);
[ ... ]
drivers/gpu/nova-core/mm/pramin.rs line 174
Quoted 9 lines
drivers/gpu/nova-core/mm/pramin.rs new file +9
-0+pub (super )fn window_at <'a,T >( + &'amut self, + vram_addr:VramAddress , + ) ->Result <PraminAccess <'a,T >> +where +T :FromBytes +IntoBytes , + { +let offset = self.window_offset (vram_addr,size_of ::<T >())?; +let view =io_project! (self.window, try:OffsetLoc ::new (offset));
[Severity: Low]
Does this also require bracketed macro syntax, like
[try: OffsetLoc::new(offset)]? Also, as noted above, OffsetLoc is missing from the kernel tree.
Quoted 4 lines
drivers/gpu/nova-core/mm/pramin.rs new file +4
-0+ +Ok (PraminAccess { view }) + } +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v3 7/10 docs: gpu: nova-core: Document the PRAMIN aperture mechanism
In reply to Eliot CourtneyFrom: Joel Fernandes <[email protected]>
Add documentation for the PRAMIN aperture mechanism used by nova-core for direct VRAM access.
Nova only uses TARGET=VRAM for VRAM access. The SYS_MEM target values are documented for completeness but not used by the driver.
--- Documentation/gpu/nova/core/pramin.rst | 128 +++++++++++++++++++++++++++++++++ Documentation/gpu/nova/index.rst | 1 + 2 files changed, 129 insertions(+)
Documentation/gpu/nova/core/pramin.rst new file +128 -0
@@ -0,0 +1,128 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========================= +PRAMIN aperture mechanism +========================= + +.. note:: + The following description is approximate and current as of the Ampere + family. It may change for future generations and is intended to assist in + understanding the driver code. + +Introduction +============ + +PRAMIN is a hardware aperture mechanism that provides CPU access to GPU Video +RAM (VRAM) before the GPU's Memory Management Unit (MMU) and page tables are +initialized. This 1 MiB sliding window, located at a fixed offset within BAR0, +is essential for setting up page tables and other critical GPU data structures +without relying on the GPU's MMU. + +Architecture Overview +===================== + +The PRAMIN aperture mechanism is logically implemented by the GPU's PBUS (PCIe +Bus Controller Unit) and provides a CPU-accessible window into VRAM through the +PCIe interface:: + + +-----------------+ PCIe +------------------------------+ + | CPU |<----------->| GPU | + +-----------------+ | | + | +----------------------+ | + | | PBUS | | + | | (Bus Controller) | | + | | | | + | | +--------------+ <------------ [1] + | | | PRAMIN | | | + | | | Window | | | + | | | (1 MiB) | | | + | | +--------------+ | | + | | | | | + | +---------|------------+ | + | | | + | v | + | +----------------------+ <------- [2] + | | VRAM | | + | | (Several GiB) | | + | | | | + | | FB[0x0000000000] | | + | | ... | | + | | FB[0xFFFFFFFFFF] | | + | +----------------------+ | + +------------------------------+ + + [1] Window starts at BAR0 + 0x700000. + [2] Program PRAMIN to any 64 KiB-aligned VRAM boundary. + +PBUS is responsible for, among other things, handling MMIO +accesses to the BAR registers. + +PRAMIN Window Operation +======================= + +The PRAMIN window provides a 1 MiB sliding aperture that can be repositioned +over the entire VRAM address space using the ``NV_PBUS_BAR0_WINDOW`` register. + +Window Control Mechanism +------------------------- + +:: + + NV_PBUS_BAR0_WINDOW Register (0x1700): + +-------+--------+--------------------------------------+ + | 31:26 | 25:24 | 23:0 | + | RSVD | TARGET | BASE_ADDR | + | | | (bits 39:16 of VRAM address) | + +-------+--------+--------------------------------------+ + + The 24-bit BASE_ADDR field encodes bits [39:16] of the target VRAM address, + providing 40-bit (1 TiB) address space coverage with 64 KiB alignment. + + TARGET field (bits 25:24): + - 0x0: VRAM (Video Memory) + - 0x1: Reserved (unused) + - 0x2: SYS_MEM_COH (Coherent System Memory) + - 0x3: SYS_MEM_NONCOH (Non-coherent System Memory) + +.. note:: + Nova only uses TARGET=VRAM (0x0) for video memory access. The SYS_MEM + target values are documented here for hardware completeness but are + not used by the driver. + +64 KiB Alignment Requirement +---------------------------- + +The PRAMIN window must be aligned to 64 KiB boundaries in VRAM. This is enforced +by the ``BASE_ADDR`` field representing bits [39:16] of the target address:: + + VRAM Address Calculation: + actual_vram_addr = (BASE_ADDR << 16) + pramin_offset + Where: + - BASE_ADDR: 24-bit value from NV_PBUS_BAR0_WINDOW[23:0] + - pramin_offset: 20-bit offset within the PRAMIN window [0x00000-0xFFFFF] + + Example Window Positioning: + +---------------------------------------------------------+ + | VRAM Space | + | | + | 0x0000000000 +-----------------+ <-- 64 KiB aligned | + | | PRAMIN Window | | + | | (1 MiB) | | + | 0x00000FFFFF +-----------------+ | + | | + | | ^ | + | | | Window can slide | + | v | to any 64 KiB-aligned boundary | + | | + | 0x0123400000 +-----------------+ <-- 64 KiB aligned | + | | PRAMIN Window | | + | | (1 MiB) | | + | 0x01234FFFFF +-----------------+ | + | | + | ... | + | | + | 0xFFFFF00000 +-----------------+ <-- 64 KiB aligned | + | | PRAMIN Window | | + | | (1 MiB) | | + | 0xFFFFFFFFFF +-----------------+ | + +---------------------------------------------------------+
Documentation/gpu/nova/index.rst +1 -0
@@ -34,3 +34,4 @@ vGPU manager VFIO driver and the nova-drm driver. core/fwsec core/falcon core/tlv + core/pramin
Signature · 1 line
2.55.0
PATCH v3 8/10 gpu: nova-core: mm: Add GpuMm centralized memory manager
In reply to Eliot CourtneyFrom: Joel Fernandes <[email protected]>
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.
--- drivers/gpu/nova-core/gpu.rs | 18 +++++++++++++++- drivers/gpu/nova-core/gsp/commands.rs | 4 ++++ drivers/gpu/nova-core/gsp/fw/commands.rs | 5 +++++ drivers/gpu/nova-core/mm.rs | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gpu.rs +17 -1
@@ -29,6 +29,10 @@ Gsp, GspBootContext, // }, + mm::{ + GpuMm, + VramAddress, // + }, regs, 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), + )?, }) } }
drivers/gpu/nova-core/gsp/commands.rs +4 -0
@@ -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 regionin 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, }) } }
drivers/gpu/nova-core/gsp/fw/commands.rs +5 -0
@@ -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.
drivers/gpu/nova-core/mm.rs +35 -0
@@ -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)]
Signature · 1 line
2.55.0
PATCH v3 9/10 gpu: nova-core: Add self-test assertion macros and config option
In reply to Eliot CourtneyThe existing assert! and assert_eq! macros cause a panic. For self tests in nova-core, it's inconvenient to cause a panic since these need to be run on actual hardware. Instead, define similar macros that log an error then return an Err.
Also add the NOVA_CORE_SELFTESTS Kconfig option that gates the driver self-tests.
--- drivers/gpu/nova-core/Kconfig | 9 ++++++ drivers/gpu/nova-core/nova_core.rs | 2 ++ drivers/gpu/nova-core/selftest.rs | 64 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+)
drivers/gpu/nova-core/Kconfig +9 -0
@@ -15,3 +15,12 @@ config NOVA_CORE This driver is work in progress and may not be functional. If M is selected, the module will be called nova-core. + +config NOVA_CORE_SELFTESTS + bool "Nova Core driver self-tests" + depends on NOVA_CORE + default n + help + Build the driver self-tests and run them when the GPU is probed. + + If unsure, say N.
drivers/gpu/nova-core/nova_core.rs +2 -0
@@ -23,6 +23,8 @@mod num;mod regs;mod sbuffer; +#[cfg( CONFIG_NOVA_CORE_SELFTESTS )] +mod selftest;mod vbios;mod vgpu;
drivers/gpu/nova-core/selftest.rs new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v3 10/10 gpu: nova-core: mm: Add PRAMIN aperture self-tests
In reply to Eliot CourtneyFrom: Joel Fernandes <[email protected]>
Add self-tests for the PRAMIN aperture mechanism to verify correct operation during GPU probe. The tests validate various alignment requirements and corner cases.
The tests are default disabled and behind CONFIG_NOVA_CORE_SELFTESTS. When enabled, tests run after GSP boot during probe.
--- drivers/gpu/nova-core/driver.rs | 3 + drivers/gpu/nova-core/gpu.rs | 12 ++++ drivers/gpu/nova-core/mm.rs | 40 ++++++++++- drivers/gpu/nova-core/mm/pramin.rs | 134 +++++++++++++++++++++++++++++++++++++ 4 files changed, 188 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/driver.rs +3 -0
@@ -86,6 +86,9 @@ fn probe<'bound>(// (`try_pin_init!()` initializes fields in declaration order), lives at a pinned // stable address, and is dropped after `gpu` (struct field drop order). gpu <- Gpu::new(pdev, unsafe { &*core::ptr::from_ref(bar) }), +// Run optional GPU selftests. +#[cfg( CONFIG_NOVA_CORE_SELFTESTS )] + _: { gpu.run_selftests(pdev) }, _reg: auxiliary::Registration::new( pdev.as_ref (), c"nova-drm",
drivers/gpu/nova-core/gpu.rs +12 -0
@@ -429,4 +429,16 @@ pub(crate) fn new<'a>( )?, }) } + +/// Runs self-tests on the constructed [`Gpu`], logging failures without failing probe. +#[cfg( CONFIG_NOVA_CORE_SELFTESTS )] +pub (crate )fn run_selftests (self:Pin <&mut Self >, pdev: &pci::Device <device::Bound >) { +let this = self.project (); +let dev = pdev.as_ref (); +let regions = &this.gsp_static_info.usable_fb_regions; + +if let Err (err) =crate ::mm::selftest::run (dev, this.mm, regions) { +dev_err! (dev,"self-tests failed: {:?}\n" , err); + } + } }
drivers/gpu/nova-core/mm.rs +39 -1
@@ -3,7 +3,7 @@//! Memory management subsystems. -#![expect(dead_code)] +#![cfg_attr(not( CONFIG_NOVA_CORE_SELFTESTS ), expect(dead_code))] use core::{ fmt::LowerHex ,
@@ -123,3 +123,41 @@ fn sub(self, rhs: Self) -> Self::Output { self.into_raw () - rhs.into_raw () } } + +#[cfg( CONFIG_NOVA_CORE_SELFTESTS )] +pub (crate )mod selftest { +use core::ops::Range ; + +use kernel::{ + device, + sizes::SizeConstants ,// + }; + +use super ::*; + +/// Run MM subsystem self-tests during probe. +pub (crate )fn run ( + dev: &device::Device <device::Bound >, + mm: &mut GpuMm <'_>, + usable_fb_regions: &[Range <u64 >], + ) ->Result { +// VRAM span the self-tests are free to overwrite, from the chosen test base. +const SELFTEST_SPAN :u64 = u64::SZ_64M ; + +let base = usable_fb_regions.iter ().find_map (|region| { +// Tests rely on this being 8 byte aligned for checking misalignment handling. +let base = region.start.align_up (Alignment ::new ::<8 >())?; + (base.checked_add (SELFTEST_SPAN )? <= region.end).then_some (base) + }); +let Some (base) = baseelse { +dev_warn! ( + dev, +"PRAMIN: skipping self-tests, no usable VRAM region of {:#x} bytes\n" , +SELFTEST_SPAN + ); +return Ok (()); + }; + + pramin::selftest::run (dev, mm.pramin_mut (),VramAddress ::from_raw (base)) + } +}
drivers/gpu/nova-core/mm/pramin.rs +134 -0
137 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v3 10/10] gpu: nova-core: mm: Add PRAMIN aperture self-tests
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The misalignment selftest for `u64` will fail on 32-bit architectures because…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The misalignment selftest for u64 will fail on 32-bit architectures because align_of::<u64>() is 4, not 8.
- [Low] Compilation error when CONFIG_NOVA_CORE_SELFTESTS is enabled: calling run_selftests on an unpinned mutable reference. --
commit 0fa1da2e573acbda3f74539dc8e29525a6f4dfba
Author: Joel Fernandes <[email protected]>
gpu: nova-core: mm: Add PRAMIN aperture self-tests
This commit adds self-tests for the PRAMIN aperture mechanism to verify correct operation during GPU probe. The tests validate various alignment requirements and corner cases, and are gated behind the CONFIG_NOVA_CORE_SELFTESTS configuration.
drivers/gpu/nova-core/driver.rs fn probe<'bound>( · line 90
Quoted 10 lines
drivers/gpu/nova-core/driver.rs +3
-0@@ -85,6 +85,9 @@ fn probe<'bound>(// (try_pin_init!() initializes fields in declaration order), lives at a pinned // stable address, and is dropped after gpu (struct field drop order). gpu <- Gpu::new(pdev, unsafe { &*core::ptr::from_ref(bar) }), +// Run optional GPU selftests. +#[cfg( CONFIG_NOVA_CORE_SELFTESTS )] + _: { gpu.run_selftests(pdev) },
[Severity: Low]
Will this cause a compilation error in the probe function when CONFIG_NOVA_CORE_SELFTESTS is enabled?
The gpu field exposed within the try_pin_init closure is a standard mutable reference, but the run_selftests method expects a pinned mutable reference. Since these types do not automatically coerce, this looks like it will result in a build failure during probe execution.
[ ... ]
Quoted 3 lines
drivers/gpu/nova-core/mm/pramin.rs +0
-0
[ ... ]
Quoted 4 lines
drivers/gpu/nova-core/mm/pramin.rs +4
-0+/// Test that misaligned accesses are rejected. +fn test_misaligned_access ( + dev: &device::Device <device::Bound >, + pramin: &mut Pramin<'_>,
drivers/gpu/nova-core/mm/pramin.rs pub(super) fn window_at<'a, T>( · line 283
Quoted 10 lines
drivers/gpu/nova-core/mm/pramin.rs +10
-0+ base: VramAddress, + ) -> Result { + // u16 at odd offset (not 2-byte aligned). + selftest_assert!(dev, pramin.window_at::<u16>(base + 0x21).is_err()); + +// u32 at 2-byte-aligned (not 4-byte-aligned) offset. +selftest_assert! (dev, pramin.window_at ::<u32 >(base +2 ).is_err ()); + +// u64 at a 4-byte-aligned (not 8-byte-aligned) address. +selftest_assert! (dev, pramin.window_at ::<u64 >(base +0x44 ).is_err ());
[Severity: Medium]
Will this assertion in test_misaligned_access fail on 32-bit architectures?
On 32-bit systems, the memory alignment requirement for a u64 is typically 4 bytes rather than 8 bytes. Since the offset 0x44 is a multiple of 4, the window_at call would succeed rather than returning an error, which seems like it would cause a spurious selftest failure.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Quoted 21 lines · Eliot Courtney
This series adds support for the PRAMIN window, plus some documentation. Some of these patches were originally written by Joel Fernandes [1]. I have updated them with changelog notes in each patch. For example, I updated them for the newer IO machinery from Gary Guo.
This series adds a Pramin structure which deals with updating the PRAMIN window and handing out typed MMIO views. The PRAMIN window is a method that lets arbitrary VRAM be written over BAR0 by configuring a 1 MiB window through GPU registers. That 1 MiB window can point anywhere in VRAM. This is useful for bootstrapping e.g. GPU side page tables.
The Pramin structure hands out typed MMIO views to do writes through rather than letting callers write directly through it. A follow up series will add support for GPU side page table entry writing through this mechanism. This abstraction is important for later since we will eventually want to write the PTEs via BAR2 not PRAMIN - using a view that we grab from the Pramin structure can abstract this out.
This is based on next-20260817 (
e6664f2b33db), with Gary's register IO projection v3 series [2] applied on top.
Quoted 8 lines
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://patch.msgid.link/[email protected]Signed-off-by Eliot Courtney <[email protected]>---
Changes in v3:
- Dropped first three Bounded patches which are merged now
- Rebase on v3 of IO reg projections
Looks like this series still applies cleanly on top of the v4 of Gary's IO register projections.
Quoted 8 lines · Eliot Courtney
Eliot Courtney (3):
gpu: nova-core: mm: Implement Alignable and Debug for VramAddress
gpu: nova-core: mm: Add the memory management HAL
gpu: nova-core: Add self-test assertion macros and config optionGary Guo (1):
rust: io: add staticcast()method for views
Quoted 7 lines
Joel Fernandes (6):
gpu: nova-core: mm: Add VramAddress type
gpu: nova-core: mm: Add PRAMIN window registers
gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM
docs: gpu: nova-core: Document the PRAMIN aperture mechanism
gpu: nova-core: mm: Add GpuMm centralized memory manager
gpu: nova-core: mm: Add PRAMIN aperture self-tests
Quoted 5 lines · Eliot Courtney
This series adds support for the PRAMIN window, plus some documentation. Some of these patches were originally written by Joel Fernandes [1]. I have updated them with changelog notes in each patch. For example, I updated them for the newer IO machinery from Gary Guo.
Quoted 7 lines
This series adds a Pramin structure which deals with updating the PRAMIN window and handing out typed MMIO views. The PRAMIN window is a method that lets arbitrary VRAM be written over BAR0 by configuring a 1 MiB window through GPU registers. That 1 MiB window can point anywhere in VRAM. This is useful for bootstrapping e.g. GPU side page tables.
[...]
Applied to drm-rust-next, thanks!
[01/10] gpu: nova-core: mm: Add VramAddress type
commit: 1473ea0e38b3e3bc76d5e9f89ea4378550ed6328
[02/10] gpu: nova-core: mm: Implement Alignable and Debug for VramAddress
commit: 8e43629439b7bbdbe4336300aa33727bae9792ca
[03/10] gpu: nova-core: mm: Add PRAMIN window registers
commit: d3bd73dcf51d88ae116a574ce2f49209c7b48944
[04/10] gpu: nova-core: mm: Add the memory management HAL
commit: b05ff82081b7b90fdd70cc7d07b3da9d85184f88
[05/10] rust: io: add static `cast()` method for views
commit: 9aa6069d624ea877a17b7d0952c993d2eb07dc22
[06/10] gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM
commit: a14a957c0e619437fd3a67bc435120b0b6270914
[07/10] docs: gpu: nova-core: Document the PRAMIN aperture mechanism
commit: b4481b9e3b5a3e1b45b5a70880cc2b730bc3700a
[08/10] gpu: nova-core: mm: Add GpuMm centralized memory manager
commit: 5958450e98e52adb61c4967d67b76734ff9052c0
[09/10] gpu: nova-core: Add self-test assertion macros and config option
commit: 2c76c4ec9eb0c91f7b37795f83df8a34d4172285
[10/10] gpu: nova-core: mm: Add PRAMIN aperture self-tests
commit: e6a2c988ed96a5a3af51ed97ecba980521bf2fc0