Rust for Linux List
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: Eliot Courtney <ecourtney@nvidia.com>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	linux-doc@vger.kernel.org,
	"Joel Fernandes" <joelagnelf@nvidia.com>
Subject: Re: [PATCH v2 04/12] gpu: nova-core: mm: Add VramAddress type
Date: Mon, 17 Aug 2026 16:00:37 +1000	[thread overview]
Message-ID: <aoKfPchpfmTVguQf@nvdebian.thelocal> (raw)
In-Reply-To: <20260810-pramin-split-v2-4-65a00b3c7309@nvidia.com>

On 2026-08-10 at 23:55 +1000, Eliot Courtney <ecourtney@nvidia.com> wrote...
> From: Joel Fernandes <joelagnelf@nvidia.com>
> 
> 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.
> 
> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
> [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]
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
> ---
>  drivers/gpu/nova-core/mm.rs        | 60 ++++++++++++++++++++++++++++++++++++++
>  drivers/gpu/nova-core/nova_core.rs |  1 +
>  2 files changed, 61 insertions(+)
> 
> diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs
> new file mode 100644
> index 000000000000..dcd5e5e919bf
> --- /dev/null
> +++ b/drivers/gpu/nova-core/mm.rs
> @@ -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);

Is this the best type here, or should this be bounded via runtime checking to
ensure it refers to a valid address?

I was going to ask if it should be bounded to reflect the physical addressing
capabilities of the GPU in question, but that would actually need to be a
different type as GPU physical addresses might not even refer to local vidmem.

Although I think that's a concern for future series - AFAIK PRAMIN can only
access local VRAM.

> +
> +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()
> +    }
> +}
> diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
> index 35a8b1214b0e..8f59cfa97017 100644
> --- a/drivers/gpu/nova-core/nova_core.rs
> +++ b/drivers/gpu/nova-core/nova_core.rs
> @@ -18,6 +18,7 @@
>  mod gpu;
>  mod gsp;
>  mod mctp;
> +mod mm;
>  #[macro_use]
>  mod num;
>  mod regs;
> 
> -- 
> 2.55.0
> 

  parent reply	other threads:[~2026-08-17  6:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 13:55 [PATCH v2 00/12] gpu: nova-core: add PRAMIN window support Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 01/12] rust: num: use const_assert! in Bounded Eliot Courtney
2026-08-10 14:23   ` Gary Guo
2026-08-10 22:24   ` Danilo Krummrich
2026-08-10 13:55 ` [PATCH v2 02/12] rust: num: reject Bounded::shr overshifts at build time Eliot Courtney
2026-08-10 14:23   ` Gary Guo
2026-08-10 22:25   ` Danilo Krummrich
2026-08-10 13:55 ` [PATCH v2 03/12] rust: num: add Bounded::shr_exact Eliot Courtney
2026-08-10 22:25   ` Danilo Krummrich
2026-08-10 13:55 ` [PATCH v2 04/12] gpu: nova-core: mm: Add VramAddress type Eliot Courtney
2026-08-10 22:24   ` Danilo Krummrich
2026-08-17  6:00   ` Alistair Popple [this message]
2026-08-17  8:20     ` Eliot Courtney
2026-08-17 11:41       ` Alistair Popple
2026-08-10 13:55 ` [PATCH v2 05/12] gpu: nova-core: mm: Implement Alignable and Debug for VramAddress Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 06/12] gpu: nova-core: mm: Add PRAMIN window registers Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 07/12] gpu: nova-core: mm: Add the memory management HAL Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 08/12] gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 09/12] docs: gpu: nova-core: Document the PRAMIN aperture mechanism Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 10/12] gpu: nova-core: mm: Add GpuMm centralized memory manager Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 11/12] gpu: nova-core: Add self-test assertion macros and config option Eliot Courtney
2026-08-10 13:55 ` [PATCH v2 12/12] gpu: nova-core: mm: Add PRAMIN aperture self-tests Eliot Courtney
2026-08-10 22:26 ` [PATCH v2 00/12] gpu: nova-core: add PRAMIN window support Danilo Krummrich
2026-08-11 12:31   ` Miguel Ojeda
2026-08-11 12:31 ` Miguel Ojeda
2026-08-12  4:54   ` Alexandre Courbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aoKfPchpfmTVguQf@nvdebian.thelocal \
    --to=apopple@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=tzimmermann@suse.de \
    --cc=work@onurozkan.dev \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox