Skip to contentSkip to conversation

Introduce page table types, vmm and bar1 mapping support

PATCH New Joel Fernandes 1 participant 17 messages May 18

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Introduce page table types, vmm and bar1 mapping support

This series introduces page-table types and a Virtual Memory Manager (VMM) for the nova-core driver, plus a BAR1 user (with selftests) layered on top. The page-table layer uses trait-based generics (PteOps, PdeOps, DualPdeOps, MmuConfig) to dispatch between MMU v2 and v3 formats. The Vmm tracks virtual-address ranges with a maple tree, and the BAR1 user exposes mapped CPU access to VRAM through a small allocation API exercised by the selftests.

This series is based on drm-rust-next.

It depends on the prerequisite series "Introduce nova-core mm prerequisites" posted alongside this one:
https://lore.kernel.org/all/[email protected]/
Please apply the prerequisite series first, or pull the git tag below which contains everything.

Dependencies (not yet merged):

- Alexandre Courbot's bitfield series. Tested on v2:
https://lore.kernel.org/all/[email protected]/
A newer v3 of bitfield is available and should also work (haven't tested):
https://lore.kernel.org/all/[email protected]/

- rust: maple_tree: implement Send and Sync for MapleTree (v3):
https://lore.kernel.org/all/[email protected]/

The git tree (containing the dependencies above, the prerequisite series "Introduce nova-core mm prerequisites", and this series) can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/jfern/linux.git (tag: nova-mm-v1-20260518)

Change log:

Changes from v12 to v1 (split-out):

- Part 2 of 2; depends on the prereq series posted just before:
https://lore.kernel.org/all/[email protected]/
- Kept the virtual-memory portion of v12's "Add common memory management types" patch here as "Add common types for virtual memory management".
- Folded v12's "Add TLB flush support" into a new "Add buddy allocator and TLB to GpuMm" patch.
- Split v12's "Add page table entry operation traits" into PteOps, PdeOps, and DualPdeOps trait patches.
- Extracted "Add MmuConfig trait" into its own patch.
- Moved "rust: maple_tree: Send and Sync" out as a standalone dependency; VMM's maple-tree-backed range tracking remains.
- Smaller code touch-ups across most carried-over patches.

Link to v12: https://lore.kernel.org/all/[email protected]/

Joel Fernandes (16):
gpu: nova-core: mm: Add common types for virtual memory management
gpu: nova-core: mm: Add buddy allocator and TLB to GpuMm
gpu: nova-core: mm: Add common types for all page table formats
gpu: nova-core: mm: pagetable: Add PteOps trait
gpu: nova-core: mm: pagetable: Add PdeOps trait
gpu: nova-core: mm: pagetable: Add DualPdeOps trait
gpu: nova-core: mm: Add MMU v2 page table types
gpu: nova-core: mm: Add MMU v3 page table types
gpu: nova-core: mm: pagetable: Add MmuConfig trait
gpu: nova-core: mm: Add page table walker for MMU v2/v3
gpu: nova-core: mm: Add Virtual Memory Manager
gpu: nova-core: mm: Add virtual address range tracking to VMM
gpu: nova-core: mm: Add multi-page mapping API to VMM
gpu: nova-core: Add BAR1 aperture type and size constant
gpu: nova-core: mm: Add BAR1 user interface
gpu: nova-core: mm: Add BAR1 memory management self-tests

 drivers/gpu/nova-core/Kconfig              |   1 +
 drivers/gpu/nova-core/driver.rs            |  22 +
 drivers/gpu/nova-core/gpu.rs               |  71 +++-
 drivers/gpu/nova-core/gsp/commands.rs      |   4 +-
 drivers/gpu/nova-core/gsp/fw/commands.rs   |   8 +
 drivers/gpu/nova-core/mm.rs                | 108 ++++-
 drivers/gpu/nova-core/mm/bar_user.rs       | 447 +++++++++++++++++++++
 drivers/gpu/nova-core/mm/pagetable.rs      | 414 +++++++++++++++++++
 drivers/gpu/nova-core/mm/pagetable/map.rs  | 367 +++++++++++++++++
 drivers/gpu/nova-core/mm/pagetable/ver2.rs | 271 +++++++++++++
 drivers/gpu/nova-core/mm/pagetable/ver3.rs | 421 +++++++++++++++++++
 drivers/gpu/nova-core/mm/pagetable/walk.rs | 258 ++++++++++++
 drivers/gpu/nova-core/mm/tlb.rs            | 130 ++++++
 drivers/gpu/nova-core/mm/vmm.rs            | 361 +++++++++++++++++
 drivers/gpu/nova-core/regs.rs              |  65 +++
 15 files changed, 2941 insertions(+), 7 deletions(-)
 create mode 100644 drivers/gpu/nova-core/mm/bar_user.rs
 create mode 100644 drivers/gpu/nova-core/mm/pagetable.rs
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/map.rs
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/ver2.rs
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/ver3.rs
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/walk.rs
 create mode 100644 drivers/gpu/nova-core/mm/tlb.rs
 create mode 100644 drivers/gpu/nova-core/mm/vmm.rs

base-commit: 03f35250485a1f78f5055c034ce7073b4c887636

Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/16 gpu: nova-core: mm: Add common types for virtual memory management

Add common virtual memory memory management types: PAGE_SIZE constant, VirtualAddress bitfield type, Vfn (Virtual Frame Number) type.

---
 drivers/gpu/nova-core/mm.rs | 66 +++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
drivers/gpu/nova-core/mm.rs +66 -0
index 08d74710f790..b23667a55ecd 100644
@@ -42,6 +42,7 @@ macro_rules! impl_pfn_bounded {
     num::Bounded,
     pci,
     prelude::*,
+    sizes::SZ_4K,
     sync::Arc, //
 };
 
@@ -99,6 +100,9 @@ pub(crate) fn run_mm_selftests(
     Ok(())
 }
 
+/// Page size in bytes (4 KiB).
+pub(crate) const PAGE_SIZE: usize = SZ_4K;
+
 bitfield! {
     /// Physical VRAM address in GPU video memory.
     pub(crate) struct VramAddress(u64) {
@@ -207,6 +211,29 @@ fn into_vram_range(self) -> Range<VramAddress> {
     }
 }
 
+bitfield! {
+    /// Virtual address in GPU address space.
+    pub(crate) struct VirtualAddress(u64) {
+        /// Offset within 4KB page.
+        11:0    offset;
+        /// Virtual frame number.
+        63:12   frame_number => Vfn;
+    }
+}
+
+impl VirtualAddress {
+    /// Create a new virtual address from a raw value.
+    pub(crate) const fn new(addr: u64) -> Self {
+        Self::from_raw(addr)
+    }
+}
+
+impl From<Vfn> for VirtualAddress {
+    fn from(vfn: Vfn) -> Self {
+        Self::zeroed().with_frame_number(vfn)
+    }
+}
+
 /// Physical Frame Number.
 ///
 /// Represents a physical page in VRAM.
@@ -245,3 +272,42 @@ fn from(pfn: Pfn) -> Self {
 }
 
 impl_pfn_bounded!(52);
+
+/// Virtual Frame Number.
+///
+/// Represents a virtual page in GPU address space.
+#[repr(transparent)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+pub(crate) struct Vfn(u64);
+
+impl Vfn {
+    /// Create a new VFN from a frame number.
+    pub(crate) const fn new(frame_number: u64) -> Self {
+        Self(frame_number)
+    }
+
+    /// Get the raw frame number.
+    pub(crate) const fn raw(self) -> u64 {
+        self.0
+    }
+}
+
+impl From<VirtualAddress> for Vfn {
+    fn from(addr: VirtualAddress) -> Self {
+        addr.frame_number()
+    }
+}
+
+impl From<u64> for Vfn {
+    fn from(val: u64) -> Self {
+        Self(val)
+    }
+}
+
+impl From<Vfn> for u64 {
+    fn from(vfn: Vfn) -> Self {
+        vfn.0
+    }
+}
+
+impl_frame_number_bounded!(Vfn, 52);
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/16 gpu: nova-core: mm: Add buddy allocator and TLB to GpuMm

In reply to Joel Fernandes

Extend GpuMm with the remaining two memory-management components:

- Buddy allocator for VRAM allocation.
- TLB manager for translation buffer operations.

PRAMIN was added in an earlier commit; this completes the centralized ownership model with accessor methods for each component.

---
 drivers/gpu/nova-core/Kconfig         |   1 +
 drivers/gpu/nova-core/gpu.rs          |  22 ++++-
 drivers/gpu/nova-core/gsp/commands.rs |   1 -
 drivers/gpu/nova-core/mm.rs           |  27 ++++++
 drivers/gpu/nova-core/mm/tlb.rs       | 130 ++++++++++++++++++++++++++
 drivers/gpu/nova-core/regs.rs         |  65 +++++++++++++
 6 files changed, 244 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/nova-core/mm/tlb.rs
drivers/gpu/nova-core/Kconfig +1 -0
index abf10e82647b..8eebb430856a 100644
@@ -5,6 +5,7 @@ config NOVA_CORE
 	depends on RUST
 	depends on !CPU_BIG_ENDIAN
 	select AUXILIARY_BUS
+	select GPU_BUDDY
 	select RUST_FW_LOADER_ABSTRACTIONS
 	default n
 	help
drivers/gpu/nova-core/gpu.rs +21 -1
index aa047fe91054..f789d956cc49 100644
@@ -4,11 +4,16 @@
     device,
     devres::Devres,
     fmt,
+    gpu::buddy::GpuBuddyParams,
     io::Io,
     num::Bounded,
     pci,
     prelude::*,
-    sizes::SizeConstants,
+    ptr::Alignment,
+    sizes::{
+        SizeConstants,
+        SZ_4K, //
+    },
     sync::Arc, //
 };
 
@@ -305,6 +310,13 @@ pub(crate) fn new<'a>(
             gsp_static_info: gsp
                 .boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)
                 .inspect(|info| {
+                    dev_info!(
+                        pdev.as_ref(),
+                        "Using FB region: {:#x}..{:#x}\n",
+                        info.usable_fb_region.start,
+                        info.usable_fb_region.end
+                    );
+
                     dev_info!(
                         pdev.as_ref(),
                         "Total physical VRAM: {} MiB\n",
@@ -314,14 +326,22 @@ pub(crate) fn new<'a>(
 
             // Create GPU memory manager owning memory management resources.
             mm: {
+                let usable_vram = &gsp_static_info.usable_fb_region;
+
                 // PRAMIN covers all physical VRAM (including GSP-reserved areas
                 // above the usable region, e.g. the BAR1 page directory).
                 let pramin_vram_region = (0..gsp_static_info.total_fb_end).into_vram_range();
+                let buddy_params = GpuBuddyParams {
+                    base_offset: usable_vram.start,
+                    size: usable_vram.end - usable_vram.start,
+                    chunk_size: Alignment::new::<SZ_4K>(),
+                };
                 Arc::pin_init(
                     GpuMm::new(
                         devres_bar.clone(),
                         pdev.as_ref(),
                         spec.chipset,
+                        buddy_params,
                         pramin_vram_region,
                     )?,
                     GFP_KERNEL,
drivers/gpu/nova-core/gsp/commands.rs +0 -1
index 172411d7b475..5abd7950320b 100644
@@ -194,7 +194,6 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> {
 pub(crate) struct GetGspStaticInfoReply {
     gpu_name: [u8; 64],
     /// Usable FB (VRAM) region for driver memory allocation.
-    #[expect(dead_code)]
     pub(crate) usable_fb_region: Range<u64>,
     /// End of VRAM.
     pub(crate) total_fb_end: u64,
drivers/gpu/nova-core/mm.rs +27 -0
index b23667a55ecd..ea415a88b221 100644
@@ -32,6 +32,7 @@ macro_rules! impl_pfn_bounded {
 }
 
 pub(crate) mod pramin;
+pub(super) mod tlb;
 
 use core::ops::Range;
 
@@ -39,6 +40,10 @@ macro_rules! impl_pfn_bounded {
     bitfield,
     device,
     devres::Devres,
+    gpu::buddy::{
+        GpuBuddy,
+        GpuBuddyParams, //
+    },
     num::Bounded,
     pci,
     prelude::*,
@@ -51,14 +56,21 @@ macro_rules! impl_pfn_bounded {
     gpu::Chipset, //
 };
 
+pub(crate) use tlb::Tlb;
+
 /// GPU Memory Manager - owns all core MM components.
 ///
 /// Provides centralized ownership of memory management resources:
+/// - [`GpuBuddy`] allocator for VRAM page table allocation.
 /// - [`pramin::Pramin`] for direct VRAM access.
+/// - [`Tlb`] manager for translation buffer flush operations.
 #[pin_data]
 pub(crate) struct GpuMm {
+    buddy: GpuBuddy,
     #[pin]
     pramin: pramin::Pramin,
+    #[pin]
+    tlb: Tlb,
 }
 
 impl GpuMm {
@@ -70,19 +82,34 @@ pub(crate) fn new(
         bar: Arc<Devres<Bar0>>,
         dev: &device::Device<device::Bound>,
         chipset: Chipset,
+        buddy_params: GpuBuddyParams,
         pramin_vram_region: Range<VramAddress>,
     ) -> Result<impl PinInit<Self>> {
+        let buddy = GpuBuddy::new(buddy_params)?;
+        let tlb_init = Tlb::new(bar.clone());
         let pramin_init = pramin::Pramin::new(bar, dev, chipset, pramin_vram_region)?;
 
         Ok(pin_init!(Self {
+            buddy,
             pramin <- pramin_init,
+            tlb <- tlb_init,
         }))
     }
 
+    /// Access the [`GpuBuddy`] allocator.
+    pub(crate) fn buddy(&self) -> &GpuBuddy {
+        &self.buddy
+    }
+
     /// Access the [`pramin::Pramin`].
     pub(crate) fn pramin(&self) -> &pramin::Pramin {
         &self.pramin
     }
+
+    /// Access the [`Tlb`] manager.
+    pub(crate) fn tlb(&self) -> &Tlb {
+        &self.tlb
+    }
 }
 
 /// Run MM subsystem self-tests during probe.
drivers/gpu/nova-core/mm/tlb.rs new file +130 -0

130 lines not on this page · raw message

drivers/gpu/nova-core/regs.rs +65 -0

74 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/16 gpu: nova-core: mm: Add common types for all page table formats

In reply to Joel Fernandes

Add common page table types shared between MMU v2 and v3. These types are hardware-agnostic and used by both MMU versions.

---
 drivers/gpu/nova-core/mm.rs           |   1 +
 drivers/gpu/nova-core/mm/pagetable.rs | 158 ++++++++++++++++++++++++++
 2 files changed, 159 insertions(+)
 create mode 100644 drivers/gpu/nova-core/mm/pagetable.rs
drivers/gpu/nova-core/mm.rs +1 -0
index ea415a88b221..66cc33389159 100644
@@ -31,6 +31,7 @@ macro_rules! impl_pfn_bounded {
     };
 }
 
+pub(super) mod pagetable;
 pub(crate) mod pramin;
 pub(super) mod tlb;
 
drivers/gpu/nova-core/mm/pagetable.rs new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/16 gpu: nova-core: mm: pagetable: Add PteOps trait

In reply to Joel Fernandes

Introduce a trait for GPU Page Table Entries (PTEs). New read()/write() helpers are provided that go through a PraminWindow).

The forthcoming MMU v2, v3 PTE structs will each implement PteOps, allowing the later page-table walker and mapper to call PTE operations.

---
 drivers/gpu/nova-core/mm/pagetable.rs | 38 +++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/gpu/nova-core/mm/pagetable.rs +38 -0
index ed0f3d731c63..a92add82eb10 100644
@@ -8,9 +8,16 @@
 
 #![expect(dead_code)]
 
+use kernel::prelude::*;
+
 use kernel::num::Bounded;
 
 use crate::gpu::Architecture;
+use crate::mm::{
+    pramin,
+    Pfn,
+    VramAddress, //
+};
 
 /// Extracts the page table index at a given level from a virtual address.
 pub(super) trait VaLevelIndex {
@@ -84,6 +91,37 @@ pub(super) const fn as_index(&self) -> u64 {
     }
 }
 
+// Trait abstractions for page table operations.
+
+/// Operations on Page Table Entries (`PTE`s).
+pub(super) trait PteOps: Copy + core::fmt::Debug + Into<u64> {
+    /// Create a `PTE` from a raw `u64` value.
+    fn from_raw(val: u64) -> Self;
+
+    /// Create an invalid `PTE`.
+    fn invalid() -> Self;
+
+    /// Create a valid `PTE` for the given memory aperture.
+    fn new(aperture: AperturePte, pfn: Pfn, writable: bool) -> Self;
+
+    /// Check if this `PTE` is valid.
+    fn is_valid(&self) -> bool;
+
+    /// Get the physical frame number.
+    fn frame_number(&self) -> Pfn;
+
+    /// Read a `PTE` from VRAM.
+    fn read(window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Result<Self> {
+        let val = window.try_read64(addr)?;
+        Ok(Self::from_raw(val))
+    }
+
+    /// Write this `PTE` to VRAM.
+    fn write(&self, window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Result {
+        window.try_write64(addr, (*self).into())
+    }
+}
+
 /// Memory aperture for Page Table Entries (`PTE`s).
 ///
 /// Determines which memory region the `PTE` points to.
Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/16 gpu: nova-core: mm: pagetable: Add PdeOps trait

In reply to Joel Fernandes

Introduce a trait for GPU Page Directory Entries
(PDEs). Default read()/write() helpers via a PraminWindow are provided.

The forthcoming MMU v2, v3 PDE structs will each implement PdeOps, allowing the later page-table walker and mapper to call PDE operations.

---
 drivers/gpu/nova-core/mm/pagetable.rs | 37 +++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
drivers/gpu/nova-core/mm/pagetable.rs +37 -0
index a92add82eb10..1c94b3afa8b2 100644
@@ -122,6 +122,43 @@ fn write(&self, window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Res
     }
 }
 
+/// Operations on Page Directory Entries (`PDE`s).
+pub(super) trait PdeOps: Copy + core::fmt::Debug + Into<u64> {
+    /// Create a `PDE` from a raw `u64` value.
+    fn from_raw(val: u64) -> Self;
+
+    /// Create a valid `PDE` pointing to a page table in the given aperture.
+    fn new(aperture: AperturePde, table_pfn: Pfn) -> Self;
+
+    /// Create an invalid `PDE`.
+    fn invalid() -> Self;
+
+    /// Check if this `PDE` is valid.
+    fn is_valid(&self) -> bool;
+
+    /// Get the memory aperture of this `PDE`.
+    fn aperture(&self) -> AperturePde;
+
+    /// Get the VRAM address of the page table.
+    fn table_vram_address(&self) -> VramAddress;
+
+    /// Read a `PDE` from VRAM.
+    fn read(window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Result<Self> {
+        let val = window.try_read64(addr)?;
+        Ok(Self::from_raw(val))
+    }
+
+    /// Write this `PDE` to VRAM.
+    fn write(&self, window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Result {
+        window.try_write64(addr, (*self).into())
+    }
+
+    /// Check if this `PDE` is valid and points to video memory.
+    fn is_valid_vram(&self) -> bool {
+        self.is_valid() && self.aperture() == AperturePde::VideoMemory
+    }
+}
+
 /// Memory aperture for Page Table Entries (`PTE`s).
 ///
 /// Determines which memory region the `PTE` points to.
Signature · 1 line
2.34.1
#6 lore raw

PATCH 6/16 gpu: nova-core: mm: pagetable: Add DualPdeOps trait

In reply to Joel Fernandes

Introduce a trait for 128-bit Dual Page Directory Entries. The read()/write() helpers issue two 64-bit accesses through a PraminWindow to load/store the 128-bit value.

---
 drivers/gpu/nova-core/mm/pagetable.rs | 34 +++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/gpu/nova-core/mm/pagetable.rs +34 -0
index 1c94b3afa8b2..7ea090024d91 100644
@@ -159,6 +159,40 @@ fn is_valid_vram(&self) -> bool {
     }
 }
 
+/// Operations on Dual Page Directory Entries (128-bit `DualPde`s).
+pub(super) trait DualPdeOps: Copy + core::fmt::Debug {
+    /// Create a `DualPde` from raw 128-bit value (two `u64`s).
+    fn from_raw(big: u64, small: u64) -> Self;
+
+    /// Create a `DualPde` with only the small page table pointer set.
+    fn new_small(table_pfn: Pfn) -> Self;
+
+    /// Check if the small page table pointer is valid.
+    fn has_small(&self) -> bool;
+
+    /// Get the small page table VRAM address.
+    fn small_vram_address(&self) -> VramAddress;
+
+    /// Get the raw `u64` value of the big PDE.
+    fn big_raw_u64(&self) -> u64;
+
+    /// Get the raw `u64` value of the small PDE.
+    fn small_raw_u64(&self) -> u64;
+
+    /// Read a dual PDE (128-bit) from VRAM.
+    fn read(window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Result<Self> {
+        let lo = window.try_read64(addr)?;
+        let hi = window.try_read64(addr + 8)?;
+        Ok(Self::from_raw(lo, hi))
+    }
+
+    /// Write this dual PDE (128-bit) to VRAM.
+    fn write(&self, window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Result {
+        window.try_write64(addr, self.big_raw_u64())?;
+        window.try_write64(addr + 8, self.small_raw_u64())
+    }
+}
+
 /// Memory aperture for Page Table Entries (`PTE`s).
 ///
 /// Determines which memory region the `PTE` points to.
Signature · 1 line
2.34.1
#7 lore raw

PATCH 7/16 gpu: nova-core: mm: Add MMU v2 page table types

In reply to Joel Fernandes

Add page table entry and directory structures for MMU version 2 used by Hopper and later GPUs. The Pte, Pde, and DualPde types each implement the PteOps, PdeOps, and DualPdeOps traits introduced earlier in the series, providing the version-agnostic API used by the forthcoming page-table walker and mapper.

---
 drivers/gpu/nova-core/mm/pagetable.rs      |   2 +
 drivers/gpu/nova-core/mm/pagetable/ver2.rs | 271 +++++++++++++++++++++
 2 files changed, 273 insertions(+)
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/ver2.rs
drivers/gpu/nova-core/mm/pagetable.rs +2 -0
index 7ea090024d91..df041fc89390 100644
@@ -8,6 +8,8 @@
 
 #![expect(dead_code)]
 
+pub(super) mod ver2;
+
 use kernel::prelude::*;
 
 use kernel::num::Bounded;
drivers/gpu/nova-core/mm/pagetable/ver2.rs new file +271 -0

271 lines not on this page · raw message

Signature · 1 line
2.34.1
#8 lore raw

PATCH 8/16 gpu: nova-core: mm: Add MMU v3 page table types

In reply to Joel Fernandes

Add page table entry and directory structures for MMU version 3 used by Hopper and later GPUs. The Pte, Pde, and DualPde types each implement the PteOps, PdeOps, and DualPdeOps traits introduced earlier in the series, providing the version-agnostic API used by the forthcoming page-table walker and mapper.

---
 drivers/gpu/nova-core/mm/pagetable.rs      |   1 +
 drivers/gpu/nova-core/mm/pagetable/ver3.rs | 421 +++++++++++++++++++++
 2 files changed, 422 insertions(+)
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/ver3.rs
drivers/gpu/nova-core/mm/pagetable.rs +1 -0
index df041fc89390..3cc546f94fdb 100644
@@ -9,6 +9,7 @@
 #![expect(dead_code)]
 
 pub(super) mod ver2;
+pub(super) mod ver3;
 
 use kernel::prelude::*;
 
drivers/gpu/nova-core/mm/pagetable/ver3.rs new file +421 -0

421 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

PATCH 9/16 gpu: nova-core: mm: pagetable: Add MmuConfig trait

In reply to Joel Fernandes

Introduce MmuConfig, the trait that ties the entry-operation traits (PteOps, PdeOps, DualPdeOps) together with the version-specific constants and helpers.

MmuV2 and MmuV3 are zero-sized marker structs that implement MmuConfig for Turing/Ampere/Ada and Hopper/Blackwell respectively. Dispatch is fully resolved at compile time through these markers, so version-specific code is selected without runtime overhead and without wrapper enums.

This enables version-agnostic page-table operations while keeping version-specific implementation details encapsulated in the ver2 and ver3 modules.

---
 drivers/gpu/nova-core/mm/pagetable.rs | 109 ++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)
drivers/gpu/nova-core/mm/pagetable.rs +109 -0
index 3cc546f94fdb..38f4f0c6e8ce 100644
@@ -19,6 +19,7 @@
 use crate::mm::{
     pramin,
     Pfn,
+    VirtualAddress,
     VramAddress, //
 };
 
@@ -196,6 +197,114 @@ fn write(&self, window: &mut pramin::PraminWindow<'_>, addr: VramAddress) -> Res
     }
 }
 
+/// MMU configuration trait -- encodes version-specific constants and types.
+pub(super) trait MmuConfig: 'static {
+    /// Page Table Entry type.
+    type Pte: PteOps;
+    /// Page Directory Entry type.
+    type Pde: PdeOps;
+    /// Dual Page Directory Entry type (128-bit).
+    type DualPde: DualPdeOps;
+
+    /// PDE levels (excluding PTE level) for page table walking.
+    const PDE_LEVELS: &'static [PageTableLevel];
+    /// PTE level for this MMU version.
+    const PTE_LEVEL: PageTableLevel;
+    /// Dual PDE level (128-bit entries) for this MMU version.
+    const DUAL_PDE_LEVEL: PageTableLevel;
+
+    /// Get the number of entries per page table page for a given level.
+    fn entries_per_page(level: PageTableLevel) -> usize;
+
+    /// Extract the page table index at `level` from `va`.
+    fn level_index(va: VirtualAddress, level: u64) -> u64;
+
+    /// Get the entry size in bytes for a given level.
+    fn entry_size(level: PageTableLevel) -> usize {
+        if level == Self::DUAL_PDE_LEVEL {
+            16 // 128-bit dual PDE
+        } else {
+            8 // 64-bit PDE/PTE
+        }
+    }
+
+    /// Compute upper bound on page table pages needed for `num_virt_pages`.
+    ///
+    /// Walks from PTE level up through PDE levels, accumulating the tree.
+    fn pt_pages_upper_bound(num_virt_pages: usize) -> usize {
+        let mut total = 0;
+
+        // PTE pages at the leaf level.
+        let pte_epp = Self::entries_per_page(Self::PTE_LEVEL);
+        let mut pages_at_level = num_virt_pages.div_ceil(pte_epp);
+        total += pages_at_level;
+
+        // Walk PDE levels bottom-up (reverse of PDE_LEVELS).
+        for &level in Self::PDE_LEVELS.iter().rev() {
+            let epp = Self::entries_per_page(level);
+
+            // How many pages at this level do we need to point to
+            // the previous pages_at_level?
+            pages_at_level = pages_at_level.div_ceil(epp);
+            total += pages_at_level;
+        }
+
+        total
+    }
+}
+
+/// Marker struct for MMU v2 (Turing/Ampere/Ada).
+pub(super) struct MmuV2;
+
+impl MmuConfig for MmuV2 {
+    type Pte = ver2::Pte;
+    type Pde = ver2::Pde;
+    type DualPde = ver2::DualPde;
+
+    const PDE_LEVELS: &'static [PageTableLevel] = ver2::PDE_LEVELS;
+    const PTE_LEVEL: PageTableLevel = ver2::PTE_LEVEL;
+    const DUAL_PDE_LEVEL: PageTableLevel = ver2::DUAL_PDE_LEVEL;
+
+    fn entries_per_page(level: PageTableLevel) -> usize {
+        // TODO: Calculate these values from the bitfield dynamically
+        // instead of hardcoding them.
+        match level {
+            PageTableLevel::Pdb => 4,  // PD3 root: bits [48:47] = 2 bits
+            PageTableLevel::L3 => 256, // PD0 dual: bits [28:21] = 8 bits
+            _ => 512,                  // PD2, PD1, PT: 9 bits each
+        }
+    }
+
+    fn level_index(va: VirtualAddress, level: u64) -> u64 {
+        ver2::VirtualAddressV2::new(va).level_index(level)
+    }
+}
+
+/// Marker struct for MMU v3 (Hopper and later).
+pub(super) struct MmuV3;
+
+impl MmuConfig for MmuV3 {
+    type Pte = ver3::Pte;
+    type Pde = ver3::Pde;
+    type DualPde = ver3::DualPde;
+
+    const PDE_LEVELS: &'static [PageTableLevel] = ver3::PDE_LEVELS;
+    const PTE_LEVEL: PageTableLevel = ver3::PTE_LEVEL;
+    const DUAL_PDE_LEVEL: PageTableLevel = ver3::DUAL_PDE_LEVEL;
+
+    fn entries_per_page(level: PageTableLevel) -> usize {
+        match level {
+            PageTableLevel::Pdb => 2,  // PDE4 root: bit [56] = 1 bit, 2 entries
+            PageTableLevel::L4 => 256, // PDE0 dual: bits [28:21] = 8 bits
+            _ => 512,                  // PDE3, PDE2, PDE1, PT: 9 bits each
+        }
+    }
+
+    fn level_index(va: VirtualAddress, level: u64) -> u64 {
+        ver3::VirtualAddressV3::new(va).level_index(level)
+    }
+}
+
 /// Memory aperture for Page Table Entries (`PTE`s).
 ///
 /// Determines which memory region the `PTE` points to.
Signature · 1 line
2.34.1
#10 lore raw

PATCH 10/16 gpu: nova-core: mm: Add page table walker for MMU v2/v3

In reply to Joel Fernandes

Add the page table walker implementation that traverses the page table hierarchy for both MMU v2 (5-level) and MMU v3 (6-level) to resolve virtual addresses to physical addresses or find PTE locations.

Currently only v2 has been tested (nova-core currently boots pre-hopper) with some initial preparatory work done for v3.

---
 drivers/gpu/nova-core/mm/pagetable.rs      |   1 +
 drivers/gpu/nova-core/mm/pagetable/walk.rs | 258 +++++++++++++++++++++
 2 files changed, 259 insertions(+)
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/walk.rs
drivers/gpu/nova-core/mm/pagetable.rs +1 -0
index 38f4f0c6e8ce..5e192679f27c 100644
@@ -10,6 +10,7 @@
 
 pub(super) mod ver2;
 pub(super) mod ver3;
+pub(super) mod walk;
 
 use kernel::prelude::*;
 
drivers/gpu/nova-core/mm/pagetable/walk.rs new file +258 -0

258 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

PATCH 11/16 gpu: nova-core: mm: Add Virtual Memory Manager

In reply to Joel Fernandes

Add the Virtual Memory Manager (VMM) infrastructure for GPU address space management. Each Vmm instance manages a single address space identified by its Page Directory Base (PDB) address, used for Channel, BAR1 and BAR2 mappings.

Mapping APIs and virtual address range tracking are added in later commits.

---
 drivers/gpu/nova-core/mm.rs     |  1 +
 drivers/gpu/nova-core/mm/vmm.rs | 64 +++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100644 drivers/gpu/nova-core/mm/vmm.rs
drivers/gpu/nova-core/mm.rs +1 -0
index 66cc33389159..502c7fdceba2 100644
@@ -34,6 +34,7 @@ macro_rules! impl_pfn_bounded {
 pub(super) mod pagetable;
 pub(crate) mod pramin;
 pub(super) mod tlb;
+pub(super) mod vmm;
 
 use core::ops::Range;
 
drivers/gpu/nova-core/mm/vmm.rs new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.34.1
#12 lore raw

PATCH 12/16 gpu: nova-core: mm: Add virtual address range tracking to VMM

In reply to Joel Fernandes

Add virtual address range tracking to the VMM using a maple tree allocator. This enables contiguous virtual address range allocation for mappings.

---
 drivers/gpu/nova-core/mm/vmm.rs | 83 +++++++++++++++++++++++++++++----
 1 file changed, 74 insertions(+), 9 deletions(-)
drivers/gpu/nova-core/mm/vmm.rs +74 -9
index 3e18adc23b68..05ff77c5f888 100644
@@ -9,18 +9,27 @@
 use kernel::{
     device,
     gpu::buddy::AllocatedBlocks,
+    maple_tree::MapleTreeAlloc,
     prelude::*, //
 };
 
-use crate::mm::{
-    pagetable::{
-        walk::{PtWalk, WalkResult},
-        MmuVersion, //
+use core::ops::Range;
+
+use crate::{
+    mm::{
+        pagetable::{
+            walk::{PtWalk, WalkResult},
+            MmuVersion, //
+        },
+        GpuMm,
+        Pfn,
+        Vfn,
+        VramAddress,
+        PAGE_SIZE, //
+    },
+    num::{
+        IntoSafeCast, //
     },
-    GpuMm,
-    Pfn,
-    Vfn,
-    VramAddress, //
 };
 
 /// Virtual Memory Manager for a GPU address space.
@@ -35,18 +44,74 @@ pub(crate) struct Vmm {
     mmu_version: MmuVersion,
     /// Page table allocations required for mappings.
     page_table_allocs: KVec<Pin<KBox<AllocatedBlocks>>>,
+    /// Maple tree allocator for virtual address range tracking.
+    virt_alloc: Pin<KBox<MapleTreeAlloc<()>>>,
+    /// Total number of pages in the virtual address space.
+    va_pages: usize,
 }
 
 impl Vmm {
     /// Create a new [`Vmm`] for the given Page Directory Base address.
-    pub(crate) fn new(pdb_addr: VramAddress, mmu_version: MmuVersion) -> Result<Self> {
+    ///
+    /// The [`Vmm`] will manage a virtual address space of `va_size` bytes.
+    pub(crate) fn new(
+        pdb_addr: VramAddress,
+        mmu_version: MmuVersion,
+        va_size: u64,
+    ) -> Result<Self> {
+        let page_size: u64 = PAGE_SIZE.into_safe_cast();
+        let va_pages: usize = (va_size / page_size).into_safe_cast();
+        let virt_alloc = KBox::pin_init(MapleTreeAlloc::<()>::new(), GFP_KERNEL)?;
+
         Ok(Self {
             pdb_addr,
             mmu_version,
             page_table_allocs: KVec::new(),
+            virt_alloc,
+            va_pages,
         })
     }
 
+    /// Allocate a contiguous virtual frame number range.
+    ///
+    /// # Arguments
+    ///
+    /// - `num_pages`: Number of pages to allocate.
+    /// - `va_range`: `None` = allocate anywhere, `Some(range)` = constrain allocation to the given
+    ///   range.
+    fn alloc_vfn_range(&self, num_pages: usize, va_range: Option<Range<u64>>) -> Result<Vfn> {
+        let page_size: u64 = PAGE_SIZE.into_safe_cast();
+
+        let start_vfn = match va_range {
+            Some(r) => {
+                let num_pages_u64: u64 = num_pages.into_safe_cast();
+                let size = num_pages_u64.checked_mul(page_size).ok_or(EOVERFLOW)?;
+                let range_size = r.end.checked_sub(r.start).ok_or(EOVERFLOW)?;
+                if range_size != size {
+                    return Err(EINVAL);
+                }
+                let start_vfn: usize = (r.start / page_size).into_safe_cast();
+                let end_vfn: usize = (r.end / page_size).into_safe_cast();
+                self.virt_alloc
+                    .insert_range(start_vfn..end_vfn, (), GFP_KERNEL)?;
+                start_vfn
+            }
+            None => self
+                .virt_alloc
+                .alloc_range(num_pages, (), ..self.va_pages, GFP_KERNEL)?,
+        };
+
+        Ok(Vfn::new(start_vfn.into_safe_cast()))
+    }
+
+    /// Free a virtual frame number range back to the maple tree.
+    fn free_vfn(&self, vfn: Vfn) {
+        let vfn_index: usize = vfn.raw().into_safe_cast();
+        if self.virt_alloc.erase(vfn_index).is_none() {
+            kernel::pr_warn!("free_vfn: VFN {} not found in maple tree\n", vfn_index);
+        }
+    }
+
     /// Read the [`Pfn`] for a mapped [`Vfn`] if one is mapped.
     pub(super) fn read_mapping(
         &self,
Signature · 1 line
2.34.1
#13 lore raw

PATCH 13/16 gpu: nova-core: mm: Add multi-page mapping API to VMM

In reply to Joel Fernandes

Add the page table mapping and unmapping API to the Virtual Memory Manager, implementing a two-phase prepare/execute model suitable for use both inside and outside the DMA fence signalling critical path.

---
 drivers/gpu/nova-core/mm/pagetable.rs     |   1 +
 drivers/gpu/nova-core/mm/pagetable/map.rs | 367 ++++++++++++++++++++++
 drivers/gpu/nova-core/mm/vmm.rs           | 270 ++++++++++++++--
 3 files changed, 619 insertions(+), 19 deletions(-)
 create mode 100644 drivers/gpu/nova-core/mm/pagetable/map.rs
drivers/gpu/nova-core/mm/pagetable.rs +1 -0
index 5e192679f27c..042584e5178b 100644
@@ -8,6 +8,7 @@
 
 #![expect(dead_code)]
 
+pub(super) mod map;
 pub(super) mod ver2;
 pub(super) mod ver3;
 pub(super) mod walk;
drivers/gpu/nova-core/mm/pagetable/map.rs new file +367 -0

367 lines not on this page · raw message

drivers/gpu/nova-core/mm/vmm.rs +251 -19

326 lines not on this page · raw message

Signature · 1 line
2.34.1
#14 lore raw

PATCH 14/16 gpu: nova-core: Add BAR1 aperture type and size constant

In reply to Joel Fernandes

Add BAR1_SIZE constant and Bar1 type alias for the 256MB BAR1 aperture. These are prerequisites for BAR1 memory access functionality.

---
 drivers/gpu/nova-core/driver.rs          | 2 ++
 drivers/gpu/nova-core/gsp/commands.rs    | 4 ++++
 drivers/gpu/nova-core/gsp/fw/commands.rs | 8 ++++++++
 3 files changed, 14 insertions(+)
drivers/gpu/nova-core/driver.rs +2 -0
index 77746d6949d7..b14d4b599783 100644
@@ -47,6 +47,8 @@ pub(crate) struct NovaCore {
 const GPU_DMA_BITS: u32 = 47;
 
 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
+#[expect(dead_code)]
+pub(crate) type Bar1 = pci::Bar;
 
 kernel::pci_device_table!(
     PCI_TABLE,
drivers/gpu/nova-core/gsp/commands.rs +4 -0
index 5abd7950320b..bee7539eff60 100644
@@ -193,6 +193,9 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> {
 /// The reply from the GSP to the [`GetGspStaticInfo`] command.
 pub(crate) struct GetGspStaticInfoReply {
     gpu_name: [u8; 64],
+    /// BAR1 Page Directory Entry base address.
+    #[expect(dead_code)]
+    pub(crate) bar1_pde_base: u64,
     /// Usable FB (VRAM) region for driver memory allocation.
     pub(crate) usable_fb_region: Range<u64>,
     /// End of VRAM.
@@ -212,6 +215,7 @@ fn read(
 
         Ok(GetGspStaticInfoReply {
             gpu_name: msg.gpu_name_str(),
+            bar1_pde_base: msg.bar1_pde_base(),
             usable_fb_region: msg.usable_fb_regions_iter().next().ok_or(ENODEV)?,
             total_fb_end,
         })
drivers/gpu/nova-core/gsp/fw/commands.rs +8 -0
index ea663079d95c..13418b494a73 100644
@@ -127,6 +127,14 @@ impl GspStaticConfigInfo {
         self.0.gpuNameString
     }
 
+    /// Returns the BAR1 Page Directory Entry base address.
+    ///
+    /// This is the root page table address for BAR1 virtual memory,
+    /// set up by GSP-RM firmware.
+    pub(crate) fn bar1_pde_base(&self) -> u64 {
+        self.0.bar1PdeBase
+    }
+
     /// Returns an iterator over valid FB regions from GSP firmware data.
     fn fb_regions(
         &self,
Signature · 1 line
2.34.1
#15 lore raw

PATCH 15/16 gpu: nova-core: mm: Add BAR1 user interface

In reply to Joel Fernandes

Add the BAR1 user interface for CPU access to GPU virtual memory through the BAR1 aperture.

---
 drivers/gpu/nova-core/driver.rs       |  22 ++-
 drivers/gpu/nova-core/gpu.rs          |  41 +++++-
 drivers/gpu/nova-core/gsp/commands.rs |   1 -
 drivers/gpu/nova-core/mm.rs           |   1 +
 drivers/gpu/nova-core/mm/bar_user.rs  | 194 ++++++++++++++++++++++++++
 5 files changed, 255 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/nova-core/mm/bar_user.rs
drivers/gpu/nova-core/driver.rs +21 -1
index b14d4b599783..207ba164cf4e 100644
@@ -2,10 +2,12 @@
 
 use kernel::{
     auxiliary,
+    device::Bound,
     device::Core,
     devres::Devres,
     dma::Device,
     dma::DmaMask,
+    io::resource,
     pci,
     pci::{
         Class,
@@ -47,9 +49,27 @@ pub(crate) struct NovaCore {
 const GPU_DMA_BITS: u32 = 47;
 
 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
-#[expect(dead_code)]
 pub(crate) type Bar1 = pci::Bar;
 
+/// Returns the Linux PCI resource index that holds BAR1 for an NVIDIA GPU.
+///
+/// On Maxwell through Ada, BAR0 is a 32-bit memory BAR occupying a single
+/// Linux PCI resource slot, so BAR1 lives at index 1. Starting with Blackwell
+/// (and on some Ampere GA100 / Hopper SKUs) BAR0 is a 64-bit memory BAR that
+/// consumes two consecutive resource slots: index 0 holds the low 32 bits and
+/// index 1 holds the high 32 bits (with no `flags` / or size of its own),
+/// shifting BAR1 to index 2.
+pub(crate) fn bar1_resource_index(pdev: &pci::Device<Bound>) -> Result<u32> {
+    // Probe the `IORESOURCE_MEM_64` flag of BAR0 as a robust way of exposing
+    // if BAR0 and hence BAR1 is 64-bit.
+    let flags0 = pdev.resource_flags(0)?;
+    if flags0.contains(resource::Flags::IORESOURCE_MEM_64) {
+        Ok(2)
+    } else {
+        Ok(1)
+    }
+}
+
 kernel::pci_device_table!(
     PCI_TABLE,
     MODULE_PCI_TABLE,
drivers/gpu/nova-core/gpu.rs +39 -2

78 lines not on this page · raw message

drivers/gpu/nova-core/gsp/commands.rs +0 -1
index bee7539eff60..301c95686efd 100644
@@ -194,7 +194,6 @@ fn init(&self) -> impl Init<Self::Command, Self::InitError> {
 pub(crate) struct GetGspStaticInfoReply {
     gpu_name: [u8; 64],
     /// BAR1 Page Directory Entry base address.
-    #[expect(dead_code)]
     pub(crate) bar1_pde_base: u64,
     /// Usable FB (VRAM) region for driver memory allocation.
     pub(crate) usable_fb_region: Range<u64>,
drivers/gpu/nova-core/mm.rs +1 -0
index 502c7fdceba2..4741ef60593b 100644
@@ -31,6 +31,7 @@ macro_rules! impl_pfn_bounded {
     };
 }
 
+pub(crate) mod bar_user;
 pub(super) mod pagetable;
 pub(crate) mod pramin;
 pub(super) mod tlb;
drivers/gpu/nova-core/mm/bar_user.rs new file +194 -0

194 lines not on this page · raw message

Signature · 1 line
2.34.1
#16 lore raw

PATCH 16/16 gpu: nova-core: mm: Add BAR1 memory management self-tests

In reply to Joel Fernandes

Add self-tests for BAR1 access during driver probe when CONFIG_NOVA_MM_SELFTESTS is enabled (default disabled). This results in testing the Vmm, GPU buddy allocator and BAR1 region all of which should function correctly for the tests to pass.

---
 drivers/gpu/nova-core/gpu.rs          |   8 +-
 drivers/gpu/nova-core/mm.rs           |  12 +-
 drivers/gpu/nova-core/mm/bar_user.rs  | 253 ++++++++++++++++++++++++++
 drivers/gpu/nova-core/mm/pagetable.rs |  33 ++++
 4 files changed, 303 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gpu.rs +7 -1
index b0eebe6406e5..6ed486503957 100644
@@ -405,7 +405,13 @@ pub(crate) fn run_selftests(
         self: Pin<&mut Self>,
         pdev: &pci::Device<device::Bound>,
     ) -> Result {
-        crate::mm::run_mm_selftests(pdev, &self.mm, self.spec.chipset)?;
+        crate::mm::run_mm_selftests(
+            pdev,
+            &self.mm,
+            &self.bar1,
+            self.gsp_static_info.bar1_pde_base,
+            self.spec.chipset,
+        )?;
         Ok(())
     }
 }
drivers/gpu/nova-core/mm.rs +10 -2
index 4741ef60593b..ed77162db848 100644
@@ -55,7 +55,10 @@ macro_rules! impl_pfn_bounded {
 };
 
 use crate::{
-    driver::Bar0,
+    driver::{
+        Bar0,
+        Bar1, //
+    },
     gpu::Chipset, //
 };
 
@@ -122,10 +125,15 @@ pub(crate) fn tlb(&self) -> &Tlb {
 pub(crate) fn run_mm_selftests(
     pdev: &pci::Device<device::Bound>,
     mm: &Arc<GpuMm>,
+    bar1: &Arc<Devres<Bar1>>,
+    bar1_pde_base: u64,
     chipset: Chipset,
 ) -> Result {
     #[cfg(CONFIG_NOVA_MM_SELFTESTS)]
-    pramin::run_self_test(pdev.as_ref(), mm.pramin(), chipset)?;
+    {
+        pramin::run_self_test(pdev.as_ref(), mm.pramin(), chipset)?;
+        bar_user::run_self_test(pdev.as_ref(), mm, bar1, bar1_pde_base, chipset)?;
+    }
 
     Ok(())
 }
drivers/gpu/nova-core/mm/bar_user.rs +253 -0

256 lines not on this page · raw message

drivers/gpu/nova-core/mm/pagetable.rs +33 -0
index 042584e5178b..fb573f07b4cf 100644
@@ -17,6 +17,9 @@
 
 use kernel::num::Bounded;
 
+#[cfg(CONFIG_NOVA_MM_SELFTESTS)]
+use kernel::device;
+
 use crate::gpu::Architecture;
 use crate::mm::{
     pramin,
@@ -379,3 +382,33 @@ fn from(val: AperturePde) -> Self {
         Bounded::from_expr(val as u64 & 0x3)
     }
 }
+
+/// Check if the PDB has valid, VRAM-backed page tables.
+#[cfg(CONFIG_NOVA_MM_SELFTESTS)]
+fn check_pdb_inner<M: MmuConfig>(
+    dev: &device::Device<device::Bound>,
+    pramin: &pramin::Pramin,
+    pdb_addr: VramAddress,
+) -> Result {
+    let mut window = pramin.get_window(dev)?;
+    let raw = window.try_read64(pdb_addr)?;
+
+    if !M::Pde::from_raw(raw).is_valid_vram() {
+        return Err(ENOENT);
+    }
+    Ok(())
+}
+
+/// Check if the PDB has valid, VRAM-backed page tables, dispatching by MMU version.
+#[cfg(CONFIG_NOVA_MM_SELFTESTS)]
+pub(super) fn check_pdb_valid(
+    dev: &device::Device<device::Bound>,
+    pramin: &pramin::Pramin,
+    pdb_addr: VramAddress,
+    chipset: crate::gpu::Chipset,
+) -> Result {
+    match MmuVersion::from(chipset.arch()) {
+        MmuVersion::V2 => check_pdb_inner::<MmuV2>(dev, pramin, pdb_addr),
+        MmuVersion::V3 => check_pdb_inner::<MmuV3>(dev, pramin, pdb_addr),
+    }
+}
Signature · 1 line
2.34.1