mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "John Hubbard" <jhubbard@nvidia.com>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Zhi Wang" <zhiw@nvidia.com>, "David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Bjorn Helgaas" <bhelgaas@google.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>,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	LKML <linux-kernel@vger.kernel.org>,
	linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 1/2] rust: pci: add domain_nr() accessor
Date: Tue, 10 Nov 2026 13:43:38 +0100	[thread overview]
Message-ID: <DMRJG3ZQXY6Q.1WSE0ZB1YLDO8@kernel.org> (raw)
In-Reply-To: <20261110033655.148487-2-jhubbard@nvidia.com>

On Tue Nov 10, 2026 at 4:36 AM CET, John Hubbard wrote:
> The nova-core driver has to send the GPU's PCI location to the GPU's
> firmware as one word that holds the domain, the bus and the device
> number.
>
> The PCI abstraction has dev_id(), which packs the bus, the device and
> the function into one value. It has no accessor that reports the domain.
>
> Add an accessor for the domain number.
>
> Suggested-by: Miguel Ojeda <ojeda@kernel.org>

Is this tag intentional? (Just asking since my tooling flagged it as it wasn't
present in the first submission of this patch and some other criteria.)

> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---
>  rust/helpers/pci.c |  5 +++++
>  rust/kernel/pci.rs | 14 ++++++++++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/rust/helpers/pci.c b/rust/helpers/pci.c
> index a8540f90b13c..49f2c089d236 100644
> --- a/rust/helpers/pci.c
> +++ b/rust/helpers/pci.c
> @@ -7,6 +7,11 @@ __rust_helper u16 rust_helper_pci_dev_id(struct pci_dev *dev)
>  	return PCI_DEVID(dev->bus->number, dev->devfn);
>  }
>  
> +__rust_helper int rust_helper_pci_domain_nr(struct pci_dev *dev)
> +{
> +	return pci_domain_nr(dev->bus);

Rust helpers should generally be transparent wrappers and not provide any
semantics, even if it is just to resolve a pointer.

> +}
> +
>  __rust_helper resource_size_t
>  rust_helper_pci_resource_start(struct pci_dev *pdev, int bar)
>  {
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 769d01d23429..57718e48208d 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -408,6 +408,20 @@ pub fn dev_id(&self) -> u16 {
>          unsafe { bindings::pci_dev_id(self.as_raw()) }
>      }
>  
> +    /// Returns the PCI domain number of the bus that this device is on.
> +    #[inline]
> +    pub fn domain_nr(&self) -> u32 {
> +        // SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a
> +        // `struct pci_dev`.
> +        let domain_nr = unsafe { bindings::pci_domain_nr(self.as_raw()) };
> +
> +        // CAST: `pci_domain_nr()` returns an `int`, but a registered bus never has a negative
> +        // domain, because `pci_register_host_bridge()` fails when the domain allocation fails.
> +        // A negative value here is a kernel bug rather than a condition for a caller to handle.
> +        debug_assert!(domain_nr >= 0);
> +        domain_nr as u32

NIT: Please move the comment directly above the actual cast statement.

> +    }

  reply	other threads:[~2026-11-10 12:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10  3:36 [PATCH 0/2] gpu: nova-core: add two prerequisites for the r000 GSP firmware John Hubbard
2026-11-10  3:36 ` [PATCH 1/2] rust: pci: add domain_nr() accessor John Hubbard
2026-11-10 12:43   ` Danilo Krummrich [this message]
2026-11-10  3:36 ` [PATCH 2/2] gpu: nova-core: factor out and expose Falcon::is_processor_suspended() John Hubbard

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=DMRJG3ZQXY6Q.1WSE0ZB1YLDO8@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=zhiw@nvidia.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

all inboxes | Powered by JetHome®