rust: pci: add a prerequisite for the r000 GSP firmware
Subsystems (5)
v2 cover rust: pci: add a prerequisite for the r000 GSP firmware
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/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
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
Signature · 1 line
2.56.1
PATCH v2 1/1 rust: pci: add domain_nr() accessor
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.
--- rust/helpers/pci.c | 5 +++++ rust/kernel/pci.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+)
rust/helpers/pci.c +5 -0
@@ -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_trust_helper_pci_resource_start (struct pci_dev *pdev,int bar) {
rust/kernel/pci.rs +16 -0
@@ -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_nras u32 + } +/// Returns the PCI subsystem vendor ID. #[inline] pub fn subsystem_vendor_id (&self) ->u16 {
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v2 1/1] rust: pci: add domain_nr() accessor
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/1] rust: pci: add domain_nr() accessor
In reply to John HubbardQuoted 10 lines · 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 <[email protected]>
Re: [PATCH v2 1/1] rust: pci: add domain_nr() accessor
In reply to John HubbardQuoted 10 lines · 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 <[email protected]>
Quoted 4 lines
--- rust/helpers/pci.c | 5 +++++ rust/kernel/pci.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+)
Quoted 1 line · John Hubbard
[PATCH v2 0/1] rust: pci: add a prerequisite for the r000 GSP firmware
Applied, thanks!
Branch: topic/pci-sriov-7.5-rc1
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
[1/1] rust: pci: add domain_nr() accessor
commit: 002b9422b314
[ Move domain_nr() to Device<Bound>, since pci_domain_nr() may access
host controller data through bus->sysdata. References to the PCI device and bus do not necessarily keep that data alive after host controller removal. The bound context guarantees the required lifetime. - Danilo ]
The patch is in the topic/pci-sriov-7.5-rc1 topic branch and will be merged into the corresponding target branch soon.