mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/1] rust: pci: add a prerequisite for the r000 GSP firmware
@ 2026-11-11 20:05 John Hubbard
  2026-11-11 20:05 ` [PATCH v2 1/1] rust: pci: add domain_nr() accessor John Hubbard
  0 siblings, 1 reply; 2+ messages in thread
From: John Hubbard @ 2026-11-11 20:05 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Timur Tabi, Alistair Popple, Eliot Courtney,
	Zhi Wang, David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Daniel Almeida, Tamir Duberstein, Onur Özkan,
	linux-pci, rust-for-linux, nova-gpu, dri-devel, LKML,
	John Hubbard

Here is a preparatory change for (or more accurately, from) the r000
GSP firmware series [1], which enables nova-core to work with the GSP
firmware for r615+ releases.

For the Rust PCI abstraction, add an accessor for the PCI domain
number. The patch stands on its own, so posting it now helps avoid
reviewing a huge-er r000 series. :)

This applies to today's drm-rust-next: commit 6e557330b874 ("gpu:
nova-core: factor out and expose Falcon::is_processor_suspended()")

Changes since v1 [2]:

* The helper takes a struct pci_bus pointer and only calls
  pci_domain_nr(), so that it is a transparent wrapper (Danilo). The v1
  helper took a struct pci_dev pointer, which broke the powerpc and
  s390 builds (Sashiko).

* The CAST comment is directly above the cast (Danilo).

* The CAST comment no longer cites pci_register_host_bridge(), which
  checks the domain only under CONFIG_PCI_DOMAINS_GENERIC.

* v2 has no Suggested-by tag, because Miguel suggested the
  debug_assert!() and not the accessor (Danilo).

* Patch 2/2 of v1 is in drm-rust-next, so v2 is a single patch.

An LLM coding assistant (Claude Code) helped write this patch, but I
have fussed over every line of both the code and the commit message.

Testing: booted nova-core on my 3-GPU test system (Turing, Ampere and
Blackwell GPUs) with all KUnit and built-in Nova tests enabled, as
usual.

[1] https://lore.kernel.org/all/20260918010719.1176945-1-jhubbard@nvidia.com/
[2] https://lore.kernel.org/all/20261110033655.148487-1-jhubbard@nvidia.com/


John Hubbard (1):
  rust: pci: add domain_nr() accessor

 rust/helpers/pci.c |  5 +++++
 rust/kernel/pci.rs | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)


base-commit: 6e557330b874b0e1fdd03e8fe4c438f36c93eefa
-- 
2.56.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2 1/1] rust: pci: add domain_nr() accessor
  2026-11-11 20:05 [PATCH v2 0/1] rust: pci: add a prerequisite for the r000 GSP firmware John Hubbard
@ 2026-11-11 20:05 ` John Hubbard
  0 siblings, 0 replies; 2+ messages in thread
From: John Hubbard @ 2026-11-11 20:05 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Timur Tabi, Alistair Popple, Eliot Courtney,
	Zhi Wang, David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Daniel Almeida, Tamir Duberstein, Onur Özkan,
	linux-pci, rust-for-linux, nova-gpu, dri-devel, LKML,
	John Hubbard

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.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 rust/helpers/pci.c |  5 +++++
 rust/kernel/pci.rs | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/rust/helpers/pci.c b/rust/helpers/pci.c
index a8540f90b13c..a1e033531419 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_bus *bus)
+{
+	return pci_domain_nr(bus);
+}
+
 __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..60e0d8518266 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -408,6 +408,22 @@ 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`, which holds a reference to the `struct pci_bus` that its `bus` field
+        // points to.
+        let domain_nr = unsafe { bindings::pci_domain_nr((*self.as_raw()).bus) };
+
+        debug_assert!(domain_nr >= 0);
+
+        // CAST: `pci_domain_nr()` returns an `int`, but a registered bus never has a negative
+        // domain. A negative value here is a kernel bug rather than a condition for a caller to
+        // handle.
+        domain_nr as u32
+    }
+
     /// Returns the PCI subsystem vendor ID.
     #[inline]
     pub fn subsystem_vendor_id(&self) -> u16 {
-- 
2.56.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-11 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 20:05 [PATCH v2 0/1] rust: pci: add a prerequisite for the r000 GSP firmware John Hubbard
2026-11-11 20:05 ` [PATCH v2 1/1] rust: pci: add domain_nr() accessor John Hubbard

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®