Skip to contentSkip to conversation

gpu: nova-core: add PRAMIN window support

PATCH Superseded Eliot Courtney 5 participants 27 messages Aug 5 – Aug 10

Subsystems (10)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

[1]: https://lore.kernel.org/all/[email protected]/

This is based on drm-rust-next.

---
Eliot Courtney (6):
rust: io: add Region::try_subregion
rust: num: reject Bounded::shr overshifts at build time
rust: num: add Bounded::shr_exact
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

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       | 285 +++++++++++++++++++++++++++++++
 drivers/gpu/nova-core/mm/regs.rs         |  57 +++++++
 drivers/gpu/nova-core/nova_core.rs       |   3 +
 drivers/gpu/nova-core/selftest.rs        |  64 +++++++
 rust/kernel/io.rs                        |  31 +++-
 rust/kernel/num/bounded.rs               |  31 ++++
 18 files changed, 975 insertions(+), 2 deletions(-)

---
base-commit: 44e7e7f7cffb10a93bb88e7cb59b7b8b3e2deb1c
change-id: 20260804-pramin-split-950e210b6e3f

Best regards,

Signature · 1 line
Eliot Courtney <[email protected]>
#1 lore raw

PATCH 1/12 rust: io: add Region::try_subregion

Add a helper to get a subregion of an IO view fallibly.

---
 rust/kernel/io.rs | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
rust/kernel/io.rs +30 -1
index 95f46bb75f9e..85fbdcc50c8f 100644
@@ -6,7 +6,8 @@
 
 use core::{
     marker::PhantomData,
-    mem::MaybeUninit, //
+    mem::MaybeUninit,
+    ops::Range, //
 };
 
 use crate::{
@@ -80,6 +81,34 @@ pub fn ptr_try_from_raw_parts_mut(base: *mut u8, size: usize) -> Result<*mut Sel
 
         Ok(Self::ptr_from_raw_parts_mut(base, size))
     }
+
+    /// Try to create a subregion of `io` at the given range.
+    ///
+    /// Runtime checks that `range` is within this region, is at least as large as the given new
+    /// minimum size `NEW_SIZE`, and that [`Region`]'s alignment requirements are satisfied.
+    #[inline]
+    pub fn try_subregion<'a, const NEW_SIZE: usize, IO>(
+        io: IO,
+        range: Range<usize>,
+    ) -> Result<<IO::Backend as IoBackend>::View<'a, Region<NEW_SIZE>>>
+    where
+        IO: IoBase<'a, Target = Self>,
+    {
+        let view = io.as_view();
+        let ptr = IO::Backend::as_ptr(view);
+
+        let size = KnownSize::size(ptr);
+        if range.start > size || range.end > size {
+            return Err(EINVAL);
+        }
+        let region = Region::ptr_try_from_raw_parts_mut(
+            ptr.cast::<u8>().wrapping_add(range.start),
+            range.len(),
+        )?;
+
+        // SAFETY: We have checked bounds and alignment, so this is a valid projection.
+        Ok(unsafe { IO::Backend::project_view(view, region) })
+    }
 }
 
 impl<const SIZE: usize> KnownSize for Region<SIZE> {
Signature · 1 line
2.55.0
reviewer
#2 lore raw

Re: [PATCH 01/12] rust: io: add Region::try_subregion

Quoted 6 lines · Eliot Courtney

Add a helper to get a subregion of an IO view fallibly.

---
 rust/kernel/io.rs | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

Looks like the case where you need this don't actually require a Region (dynamically sized type) but rather a fixed size window?

In that case the next version of
https://lore.kernel.org/rust-for-linux/[email protected]/
will contain what you need.

Best,
Gary

Quoted 50 lines
rust/kernel/io.rs +30 -1
index 95f46bb75f9e..85fbdcc50c8f 100644
@@ -6,7 +6,8 @@
 
 use core::{
     marker::PhantomData,
-    mem::MaybeUninit, //
+    mem::MaybeUninit,
+    ops::Range, //
 };
 
 use crate::{
@@ -80,6 +81,34 @@ pub fn ptr_try_from_raw_parts_mut(base: *mut u8, size: usize) -> Result<*mut Sel
 
         Ok(Self::ptr_from_raw_parts_mut(base, size))
     }
+
+    /// Try to create a subregion of `io` at the given range.
+    ///
+    /// Runtime checks that `range` is within this region, is at least as large as the given new
+    /// minimum size `NEW_SIZE`, and that [`Region`]'s alignment requirements are satisfied.
+    #[inline]
+    pub fn try_subregion<'a, const NEW_SIZE: usize, IO>(
+        io: IO,
+        range: Range<usize>,
+    ) -> Result<<IO::Backend as IoBackend>::View<'a, Region<NEW_SIZE>>>
+    where
+        IO: IoBase<'a, Target = Self>,
+    {
+        let view = io.as_view();
+        let ptr = IO::Backend::as_ptr(view);
+
+        let size = KnownSize::size(ptr);
+        if range.start > size || range.end > size {
+            return Err(EINVAL);
+        }
+        let region = Region::ptr_try_from_raw_parts_mut(
+            ptr.cast::<u8>().wrapping_add(range.start),
+            range.len(),
+        )?;
+
+        // SAFETY: We have checked bounds and alignment, so this is a valid projection.
+        Ok(unsafe { IO::Backend::project_view(view, region) })
+    }
 }
 
 impl<const SIZE: usize> KnownSize for Region<SIZE> {
#3 lore raw

Re: [PATCH 01/12] rust: io: add Region::try_subregion

Quoted 8 lines · Gary Guo
Quoted 6 lines · Eliot Courtney

Add a helper to get a subregion of an IO view fallibly.

---
 rust/kernel/io.rs | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
Quoted 6 lines

Looks like the case where you need this don't actually require a Region (dynamically sized type) but rather a fixed size window?

In that case the next version of
https://lore.kernel.org/rust-for-linux/[email protected]/
will contain what you need.

Yeah you are right. I think a previous version I was working on needed runtime lengths. But yes it should work with your compile time subregion stuff.

#4 lore raw

Re: [PATCH 01/12] rust: io: add Region::try_subregion

In reply to Gary Guo
Quoted 8 lines · Gary Guo
Quoted 6 lines · Eliot Courtney

Add a helper to get a subregion of an IO view fallibly.

---
 rust/kernel/io.rs | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
Quoted 6 lines

Looks like the case where you need this don't actually require a Region (dynamically sized type) but rather a fixed size window?

In that case the next version of
https://lore.kernel.org/rust-for-linux/[email protected]/
will contain what you need.

Looks like we are going to need to full series (or at least until and including patch 11) before this can get in. Gary, what tree are you planning to merge the register projection series into? It would be nice if we could do it in a way that makes it possible for this series to be merged shortly after (either through drm-rust-next, or a merged signed tag) for the next cycle.

reviewer
#5 lore raw

Re: [PATCH 01/12] rust: io: add Region::try_subregion

Quoted 16 lines · Alexandre Courbot
Quoted 8 lines · Gary Guo
Quoted 6 lines · Eliot Courtney

Add a helper to get a subregion of an IO view fallibly.

---
 rust/kernel/io.rs | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
Quoted 6 lines

Looks like the case where you need this don't actually require a Region (dynamically sized type) but rather a fixed size window?

In that case the next version of
https://lore.kernel.org/rust-for-linux/[email protected]/
will contain what you need.

Quoted 6 lines

Looks like we are going to need to full series (or at least until and including patch 11) before this can get in. Gary, what tree are you planning to merge the register projection series into? It would be nice if we could do it in a way that makes it possible for this series to be merged shortly after (either through drm-rust-next, or a merged signed tag) for the next cycle.

I think a topic branch next cycle would be the best approach. That said, given that all non-sample drivers using it is drm, this can be taken through drm-rust too. I guess it's Danilo's call.

Best,
Gary

#6 lore raw

Re: [PATCH 01/12] rust: io: add Region::try_subregion

In reply to Gary Guo
Quoted 11 lines · Gary Guo
Quoted 6 lines · Eliot Courtney

Add a helper to get a subregion of an IO view fallibly.

---
 rust/kernel/io.rs | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

Looks like the case where you need this don't actually require a Region (dynamically sized type) but rather a fixed size window?

Quoted 6 lines

In that case the next version of
https://lore.kernel.org/rust-for-linux/[email protected]/
will contain what you need.

Best,
Gary

Thanks! I updated the code to use your v2 of that. To support the runtime offset I ended up having to use OffsetLoc which you have as #[doc(hidden)]. I will send the respin shortly.

#7 lore raw

PATCH 2/12 rust: num: reject Bounded::shr overshifts at build time

In reply to Eliot Courtney

Make shr reject shifts of at least the type's bit width at build time, instead of panicking or masking the shift amount at runtime.

---
 rust/kernel/num/bounded.rs | 1 +
 1 file changed, 1 insertion(+)
rust/kernel/num/bounded.rs +1 -0
index dafe77782d79..f263107f001e 100644
@@ -485,6 +485,7 @@ pub fn cast<U>(self) -> Bounded<U, N>
     /// assert_eq!(v_shifted.get(), 0xff);
     /// ```
     pub fn shr<const SHIFT: u32, const RES: u32>(self) -> Bounded<T, RES> {
+        const { assert!(SHIFT < T::BITS) }
         const { assert!(RES + SHIFT >= N) }
 
         // SAFETY: We shift the value right by `SHIFT`, reducing the number of bits needed to
Signature · 1 line
2.55.0
#8 lore raw

Re: [PATCH 02/12] rust: num: reject Bounded::shr overshifts at build time

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Medium] The Bounded struct derives Default, which safely bypasses the required compile-time invariant checks in Bounded::__new. --

--- Patch [2]: [PATCH 02/12] rust: num: reject Bounded::shr overshifts at build time --- commit a9c888d83116c04cce01b982b58983e2d81e53c5
Author: Eliot Courtney <[email protected]>

rust: num: reject Bounded::shr overshifts at build time

This commit updates shr in the Bounded struct to reject shifts that are greater than or equal to the type's bit width at build time. This prevents runtime panics or masked shift amounts.

rust/kernel/num/bounded.rs

Quoted 4 lines
rust/kernel/num/bounded.rs +0 -0
index dafe77782d797..f263107f001ed 100644

[Severity: Medium]
This is a pre-existing issue, but does deriving Default on Bounded safely bypass the required compile-time invariant checks?

Looking at the struct definition in rust/kernel/num/bounded.rs:

#[derive(Clone, Copy, Debug, Default, Hash)]
pub struct Bounded<T: Integer, const N: u32>(T);

The Bounded struct defines strict type invariants (such as N > 0 and N <= T::BITS) which are enforced at compile time in its __new constructor. However, deriving Default automatically implements a constructor that initializes the tuple struct field via Self(T::default()), completely bypassing __new.

Can safe downstream code construct an invalid instance using Bounded::<u32, 0>::default()?

If this invalid instance is dereferenced, deref evaluates fits_within(0, 0), calculating 32 - 0 = 32. Does left-shifting by 32 bits then trigger a runtime panic in debug builds due to an overshift, or mask the shift amount in release builds?

[ ... ]

Quoted 8 lines
rust/kernel/num/bounded.rs +1 -0
@@ -485,6 +485,7 @@ pub fn cast<U>(self) -> Bounded<U, N>
     /// assert_eq!(v_shifted.get(), 0xff);
     /// ```
     pub fn shr<const SHIFT: u32, const RES: u32>(self) -> Bounded<T, RES> {
+        const { assert!(SHIFT < T::BITS) }
         const { assert!(RES + SHIFT >= N) }
 
         // SAFETY: We shift the value right by `SHIFT`, reducing the number of bits needed to
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer Acked-by on v1 2/12
#9 lore raw

Re: [PATCH 02/12] rust: num: reject Bounded::shr overshifts at build time

In reply to Eliot Courtney
Quoted 4 lines · Eliot Courtney

Make shr reject shifts of at least the type's bit width at build time, instead of panicking or masking the shift amount at runtime.

Indeed it looks like this would panic with the kernel build, and can be easily caught at build-time since SHIFT is a constant.

#10 lore raw

Re: [PATCH 02/12] rust: num: reject Bounded::shr overshifts at build time

Quoted 5 lines · Alexandre Courbot

Indeed it looks like this would panic with the kernel build, and can be easily caught at build-time since SHIFT is a constant.

Do you want me to take it this cycle? And maybe the next one too?

Cheers,
Miguel

#11 lore raw

Re: [PATCH 02/12] rust: num: reject Bounded::shr overshifts at build time

Quoted 8 lines · Miguel Ojeda
Quoted 5 lines · Alexandre Courbot

Indeed it looks like this would panic with the kernel build, and can be easily caught at build-time since SHIFT is a constant.

Do you want me to take it this cycle? And maybe the next one too?

If this works for you it would remove them off the plate. OTOH I don't think we will have another user besides PRAMIN for the short term, so next cycle together with the rest of the series would work as well, as long as they are merged into the same tree.

Thanks!
Alex.

reviewer
#12 lore raw

Re: [PATCH 02/12] rust: num: reject Bounded::shr overshifts at build time

In reply to Eliot Courtney
Quoted 13 lines · Eliot Courtney

Make shr reject shifts of at least the type's bit width at build time, instead of panicking or masking the shift amount at runtime.

---
 rust/kernel/num/bounded.rs | 1 +
 1 file changed, 1 insertion(+)
rust/kernel/num/bounded.rs +0 -0
index dafe77782d79..f263107f001e 100644

rust/kernel/num/bounded.rs pub fn cast<U>(self) -> Bounded<U, N> · line 488

Quoted 4 lines
rust/kernel/num/bounded.rs +1 -0
@@ -485,6 +485,7 @@ pub fn cast<U>(self) -> Bounded<U, N>
     /// assert_eq!(v_shifted.get(), 0xff);
     /// ```
     pub fn shr<const SHIFT: u32, const RES: u32>(self) -> Bounded<T, RES> {
+        const { assert!(SHIFT < T::BITS) }

This should use const_assert!()

Best,
Gary

Quoted 3 lines
rust/kernel/num/bounded.rs +0 -0
         const { assert!(RES + SHIFT >= N) }
 
         // SAFETY: We shift the value right by `SHIFT`, reducing the number of bits needed to
#13 lore raw

PATCH 3/12 rust: num: add Bounded::shr_exact

In reply to Eliot Courtney

Add shr_exact in the vein of try_shrink which shifts a bounded right only if it loses no set bits. This is useful for getting a shifted down integer while simultaneously checking that it's aligned.

---
 rust/kernel/num/bounded.rs | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
rust/kernel/num/bounded.rs +30 -0
index f263107f001e..2695a7858d8a 100644
@@ -493,6 +493,36 @@ pub fn shr<const SHIFT: u32, const RES: u32>(self) -> Bounded<T, RES> {
         unsafe { Bounded::__new(self.0 >> SHIFT) }
     }
 
+    /// Right-shifts `self` by `SHIFT` if that loses no set bits, and returns the result as a
+    /// `Bounded<_, RES>`, where `RES >= N - SHIFT`.
+    ///
+    /// Returns [`None`] if any of the `SHIFT` least significant bits of `self` is set.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use kernel::num::Bounded;
+    ///
+    /// let v = Bounded::<u32, 16>::new::<0xff00>();
+    /// let v_shifted: Option<Bounded<u32, 8>> = v.shr_exact::<8, _>();
+    ///
+    /// assert_eq!(v_shifted.map(|v| v.get()), Some(0xff));
+    ///
+    /// // A set bit would be shifted out.
+    /// let v = Bounded::<u32, 16>::new::<0xff01>();
+    /// let v_shifted: Option<Bounded<u32, 8>> = v.shr_exact::<8, _>();
+    ///
+    /// assert!(v_shifted.is_none());
+    /// ```
+    pub fn shr_exact<const SHIFT: u32, const RES: u32>(self) -> Option<Bounded<T, RES>> {
+        let shifted = self.shr::<SHIFT, RES>();
+        if shifted.get() << SHIFT == self.0 {
+            Some(shifted)
+        } else {
+            None
+        }
+    }
+
     /// Left-shifts `self` by `SHIFT` and returns the result as a `Bounded<_, RES>`, where `RES >=
     /// N + SHIFT`.
     ///
Signature · 1 line
2.55.0
#14 lore raw

Re: [PATCH 03/12] rust: num: add Bounded::shr_exact

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The small abstraction function `shr_exact` is missing the `#[inline]` attribute. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The small abstraction function shr_exact is missing the #[inline] attribute. --

--- Patch [3]: [PATCH 03/12] rust: num: add Bounded::shr_exact --- commit fe8d74a80e41351c792119ee859ab7990c063f88
Author: Eliot Courtney <[email protected]>

rust: num: add Bounded::shr_exact

This commit adds shr_exact to shift a bounded value right only if it loses no set bits. This is useful for getting a shifted down integer while simultaneously checking that it is aligned.

Quoted 4 lines
rust/kernel/num/bounded.rs +0 -0
index f263107f001ed..2695a7858d8ad 100644

[ ... ]

rust/kernel/num/bounded.rs pub fn shr<const SHIFT: u32, const RES: u32>(self) -> Bounded<T, RES> { · line 517

Quoted 7 lines
rust/kernel/num/bounded.rs +7 -0
+    /// // A set bit would be shifted out.
+    /// let v = Bounded::<u32, 16>::new::<0xff01>();
+    /// let v_shifted: Option<Bounded<u32, 8>> = v.shr_exact::<8, _>();
+    ///
+    /// assert!(v_shifted.is_none());
+    /// ```
+    pub fn shr_exact<const SHIFT: u32, const RES: u32>(self) -> Option<Bounded<T, RES>> {

[Severity: Low]
This isn't a bug, but should this small abstraction function be annotated with #[inline]? According to the Rust subsystem coding guidelines, functions that are small or forwarding to a binding call should be annotated with #[inline].

Quoted 7 lines
rust/kernel/num/bounded.rs +7 -0
+        let shifted = self.shr::<SHIFT, RES>();
+        if shifted.get() << SHIFT == self.0 {
+            Some(shifted)
+        } else {
+            None
+        }
+    }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer Acked-by on v1 3/12
#15 lore raw

Re: [PATCH 03/12] rust: num: add Bounded::shr_exact

In reply to Eliot Courtney
Quoted 5 lines · Eliot Courtney

Add shr_exact in the vein of try_shrink which shifts a bounded right only if it loses no set bits. This is useful for getting a shifted down integer while simultaneously checking that it's aligned.

Maybe it is worth briefly mentioning that an equivalent method exists in the standard library (in nightly) for primitive types [1].

With the missing #[inline] mentioned by Sashiko fixed,

[1] https://doc.rust-lang.org/std/primitive.u32.html#method.shr_exact

#16 lore raw

PATCH 4/12 gpu: nova-core: mm: Add VramAddress type

In reply to Eliot Courtney

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.

[ecourtney: create mm.rs here, squashing in the arithmetic patch]
[ecourtney: splice the two commit bodies]
[ecourtney: drop the Pfn fields, open-coding what bitfield! generated]
[ecourtney: drop align_down and the IntoVramOffset/IntoVramRange traits]
[ecourtney: make checked_add() const over a plain u64, derive the ordering]
[ecourtney: doc wording, header, import, and signature cleanups]
---
 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
new file mode 100644
index 000000000000..dcd5e5e919bf
@@ -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
index 35a8b1214b0e..8f59cfa97017 100644
@@ -18,6 +18,7 @@
 mod gpu;
 mod gsp;
 mod mctp;
+mod mm;
 #[macro_use]
 mod num;
 mod regs;
Signature · 1 line
2.55.0
#17 lore raw

Re: [PATCH 04/12] gpu: nova-core: mm: Add VramAddress type

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Nested import groups are used instead of the kernel vertical import style. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Nested import groups are used instead of the kernel vertical import style. --

--- Patch [4]: [PATCH 04/12] gpu: nova-core: mm: Add VramAddress type --- commit c94d87cb8d48e350527f7f52cc4f004c23fd4d17
Author: Joel Fernandes <[email protected]>

gpu: nova-core: mm: Add VramAddress type

This commit adds the VramAddress type to represent a physical address in VRAM. It also includes arithmetic helpers, comparisons, and operator overloads required for address arithmetic.

Quoted 7 lines
drivers/gpu/nova-core/mm.rs new file +1 -0
new file mode 100644
index 0000000000000..dcd5e5e919bf2
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0

drivers/gpu/nova-core/mm.rs line 11

Quoted 10 lines
drivers/gpu/nova-core/mm.rs new file +10 -0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! Memory management subsystems.
+
+#![expect(dead_code)]
+
+use core::{
+    fmt::LowerHex,
+    ops, //
+};

[Severity: Low]
This isn't a bug, but does this follow the kernel vertical import style? According to the Rust coding guidelines, imports should be organized vertically rather than using nested import groups.

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#18 lore raw

PATCH 5/12 gpu: nova-core: mm: Implement Alignable and Debug for VramAddress

In reply to Eliot Courtney

Later 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
index dcd5e5e919bf..f9d80ffbe01d 100644
@@ -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
#19 lore raw

PATCH 6/12 gpu: nova-core: mm: Add PRAMIN window registers

In reply to Eliot Courtney

From: 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.

[ecourtney: split the registers out of the PRAMIN patch into mm/regs.rs]
[ecourtney: drop the register read path]
[ecourtney: reword the message for the split, narrow visibility to mm]
[ecourtney: plain base fields, as the bitfield cast+shift patch is dropped]
[ecourtney: rename the target to VidMem, fix derives, redo the target docs]
---
 drivers/gpu/nova-core/mm.rs      |  2 ++
 drivers/gpu/nova-core/mm/regs.rs | 57 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
drivers/gpu/nova-core/mm.rs +2 -0
index f9d80ffbe01d..7d24ad790310 100644
@@ -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 +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.55.0
#20 lore raw

PATCH 7/12 gpu: nova-core: mm: Add the memory management HAL

In reply to Eliot Courtney

Positioning 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
index 7d24ad790310..07dce4ce2473 100644
@@ -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
new file mode 100644
index 000000000000..3781e143dea7
@@ -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
new file mode 100644
index 000000000000..8af384db2921
@@ -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
new file mode 100644
index 000000000000..e4fe7561223c
@@ -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
#21 lore raw

PATCH 8/12 gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM

In reply to Eliot Courtney

From: 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.

[ecourtney: split the registers and HAL into the two preceding patches]
[ecourtney: rebase w.r.t. Bar0 lifetime changes]
[ecourtney: drop the window guard and mutex, use &mut self]
[ecourtney: position at init to avoid reads, reposition in window_offset]
[ecourtney: return typed MMIO views instead of read/write accessors]
[ecourtney: insert an ordering read when a view drops]
[ecourtney: rename the aperture constants, drop the doc examples]
[ecourtney: add the copyright header, doc and naming cleanups]
[ecourtney: the pramin module is mm-internal]
---
 drivers/gpu/nova-core/mm.rs        |   1 +
 drivers/gpu/nova-core/mm/pramin.rs | 156 +++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+)
drivers/gpu/nova-core/mm.rs +1 -0
index 07dce4ce2473..ef5b1cad56c3 100644
@@ -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 +156 -0

156 lines not on this page · raw message

Signature · 1 line
2.55.0
#22 lore raw

PATCH 9/12 docs: gpu: nova-core: Document the PRAMIN aperture mechanism

In reply to Eliot Courtney

From: 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.

[ecourtney: fix the TARGET encodings, KiB/MiB units, wording nits]
[ecourtney: wrap at 80 columns]
---
 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
new file mode 100644
index 000000000000..f50b052d73ba
@@ -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
index 1783513cbd05..5ebbfd76fdac 100644
@@ -33,3 +33,4 @@ vGPU manager VFIO driver and the nova-drm driver.
    core/fsp
    core/fwsec
    core/falcon
+   core/pramin
Signature · 1 line
2.55.0
#23 lore raw

PATCH 10/12 gpu: nova-core: mm: Add GpuMm centralized memory manager

In reply to Eliot Courtney

From: 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.

[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]
---
 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
index 42a4cd7971fa..e29e07488e78 100644
@@ -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(
                 }
 
                 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
index ffc25fd8c47b..eea1c9ed4684 100644
@@ -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,
         })
     }
 }
drivers/gpu/nova-core/gsp/fw/commands.rs +5 -0
index 6dc31d1bf5ae..6e85442a4b13 100644
@@ -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
index ef5b1cad56c3..58dce211a337 100644
@@ -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
#24 lore raw

Re: [PATCH 10/12] gpu: nova-core: mm: Add GpuMm centralized memory manager

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] `pramin_mut` is missing the `pub(crate)` visibility modifier, making it private to the `mm`…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] pramin_mut is missing the pub(crate) visibility modifier, making it private to the mm module. --

--- Patch [10]: [PATCH 10/12] gpu: nova-core: mm: Add GpuMm centralized memory manager --- commit 0abff5539341f15cd592232acd203deec02947c6
Author: Joel Fernandes <[email protected]>

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

This commit introduces GpuMm as a centralized GPU memory manager in the nova-core driver. It initially owns the PRAMIN window for direct VRAM access and provides an accessor method for use by follow-on patches. It also updates the static info parsing to compute the total FB end.

[ ... ]

Quoted 4 lines
drivers/gpu/nova-core/mm.rs +0 -0
index ef5b1cad56c31..58dce211a3373 100644

[ ... ]

drivers/gpu/nova-core/mm.rs line 56

Quoted 2 lines
drivers/gpu/nova-core/mm.rs +2 -0
+    /// Access the [`pramin::Pramin`].
+    fn pramin_mut(&mut self) -> &mut pramin::Pramin<'gpu> {

[Severity: Medium]
The commit message states that this provides an accessor method so follow-on patches can reference pramin_mut() cleanly. However, without a pub(crate) visibility modifier, won't this method be private to the mm module?

Will this prevent other modules from calling it as intended, and potentially trigger a dead_code compiler warning?

Quoted 3 lines
drivers/gpu/nova-core/mm.rs +3 -0
+        &mut self.pramin
+    }
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#25 lore raw

PATCH 11/12 gpu: nova-core: Add self-test assertion macros and config option

In reply to Eliot Courtney

The 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
index f918f69e0599..cb7f0b00f796 100644
@@ -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
index 8f59cfa97017..1133c6ce5c55 100644
@@ -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
#26 lore raw

PATCH 12/12 gpu: nova-core: mm: Add PRAMIN aperture self-tests

In reply to Eliot Courtney

From: 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.

[ecourtney: convert the tests to window_at(), macros, and the new types]
[ecourtney: cfg-gate the tests and expect(dead_code), not a runtime no-op]
[ecourtney: run the self-tests on all architectures, drop the chipset arg]
[ecourtney: test within a usable FB region, skip when none is large enough]
[ecourtney: report failures without failing probe, start banner at dev_dbg]
[ecourtney: removed the mm-specific Kconfig option]
---
 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 | 129 +++++++++++++++++++++++++++++++++++++
 4 files changed, 183 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/driver.rs +3 -0
index 5738d4ac521b..2c11eeee92d2 100644
@@ -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
index e29e07488e78..04e1e30eeed7 100644
@@ -429,4 +429,16 @@ pub(crate) fn new(
             )?,
         })
     }
+
+    /// 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
index 58dce211a337..9e4338c7c393 100644
@@ -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) = base else {
+            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 +129 -0

132 lines not on this page · raw message

Signature · 1 line
2.55.0