diff options
| author | Eliot Courtney <ecourtney@nvidia.com> | 2026-08-27 17:51:43 +0900 |
|---|---|---|
| committer | Alexandre Courbot <acourbot@nvidia.com> | 2026-09-07 11:54:00 +0900 |
| commit | 8e43629439b7bbdbe4336300aa33727bae9792ca (patch) | |
| tree | 67d1666f9a74f686136df580832f8ccda40a8ba7 /drivers/gpu | |
| parent | 1473ea0e38b3e3bc76d5e9f89ea4378550ed6328 (diff) | |
gpu: nova-core: mm: Implement Alignable and Debug for VramAddress
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.
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260827-pramin-split-v3-2-24b24d7afc52@nvidia.com
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Diffstat (limited to 'drivers/gpu')
| -rw-r--r-- | drivers/gpu/nova-core/mm.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs index dcd5e5e919bf..f9d80ffbe01d 100644 --- a/drivers/gpu/nova-core/mm.rs +++ b/drivers/gpu/nova-core/mm.rs @@ -10,7 +10,14 @@ use core::{ 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 @@ use kernel::fmt; 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 @@ impl VramAddress { } } +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; |
