gpu: nova-core: gsp: fix the PCI location sent to GSP-RM
Subsystems (8)
Alexandre Courbot
maintainerv2 cover gpu: nova-core: gsp: fix the PCI location sent to GSP-RM
nova-core sends the PCI device ID of the GPU (bus, device, function) where GSP-RM expects the layout built by OpenRM's gpuEncodeDomainBusDevice() (domain, bus, device). Both only match for a GPU at device 0, function 0 of domain 0. Patch 3 fixes this.
Doing so requires extracting the bus and device numbers from the value returned by pci::Device::dev_id. Rather than doing this in the driver (and in every other driver that needs that information), patch 2 adds a Bdf bitfield to the PCI abstractions and makes dev_id return it.
Patch 1 documents the constants that bitfield! generates for each field, which otherwise trigger the missing_docs lint on public bitfields like Bdf.
This series is based on drm-rust-next.
---
Changes in v2:
- Move PCI_DEVID mention to its own doccomment line and reword it (Danilo).
- Add #[doc(alias = "PCI_DEVID")] (Gary).
- Remove devfn aggregate field (Gary).
- Link to v1: https://patch.msgid.link/[email protected]
---
Alexandre Courbot (2):
rust: bitfield: add missing doccomments for associated constants
rust: pci: return a bitfield type for dev_id
John Hubbard (1):
gpu: nova-core: gsp: send the PCI domain, bus and device to GSP-RM
drivers/gpu/nova-core/gsp/fw/commands.rs | 30 +++++++++++++++++++++++++++- rust/kernel/bitfield.rs | 3 +++ rust/kernel/pci.rs | 34 ++++++++++++++++++++++++++++++-- samples/rust/rust_driver_sriov/pf.rs | 2 +- 4 files changed, 65 insertions(+), 4 deletions(-)
---
base-commit: abfb640b2374e26de8ff81d488c39d8254db538e
change-id: 20261127-nova-gsp-dbd-4f3d26be980e
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerPATCH v2 1/3 rust: bitfield: add missing doccomments for associated constants
The associated constants describing the range, mask and shift of each field do not carry any doccomment. This triggers the missing_docs lint on bitfields declared with pub visibility.
Add a simple doccomment to get rid of that warning.
--- rust/kernel/bitfield.rs | 3 +++ 1 file changed, 3 insertions(+)
rust/kernel/bitfield.rs +3 -0
@@ -386,9 +386,12 @@ impl $name { @private_field_accessors $vis:vis $name:ident $storage:ty : $hi:tt:$lo:tt $field:ident ) => { ::kernel::macros::paste!( +#[doc = concat! ( "Bit range of the `" , stringify! ($field), "` field." )] $visconst [<$field:upper_RANGE >]: ::core::ops::RangeInclusive <u8 > = $lo..=$hi; +#[doc = concat! ( "Bit mask of the `" , stringify! ($field), "` field." )] $visconst [<$field:upper _MASK>]: $storage = ((((1 << $hi) -1 ) <<1 ) +1 ) - ((1 << $lo) -1 ); + #[doc =concat! ("Bit shift of the `" ,stringify! ($field),"` field." )] $visconst [<$field:upper_SHIFT >]:u32 = $lo; );
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v2 2/3 rust: pci: return a bitfield type for dev_id
In reply to Alexandre CourbotThe return type of dev_id has a well-defined bit layout encoding the bus, device and function IDs of the PCI device. Add a Bdf bitfield defining that layout and make dev_id return it so users can benefit from it and are not tempted to define their own BDF type.
Also update the current two users of dev_id.
--- drivers/gpu/nova-core/gsp/fw/commands.rs | 2 +- rust/kernel/pci.rs | 34 ++++++++++++++++++++++++++++++-- samples/rust/rust_driver_sriov/pf.rs | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gsp/fw/commands.rs +1 -1
@@ -88,7 +88,7 @@ pub(crate) fn init<'a>( gpuPhysAddr: dev.resource_start(0)?, gpuPhysFbAddr: dev.resource_start(1)?, gpuPhysInstAddr: dev.resource_start(3)?, - nvDomainBusDeviceFunc: u64::from(dev.dev_id()), + nvDomainBusDeviceFunc: u64::from(dev.dev_id().into_raw()),// Using TASK_SIZE in r535_gsp_rpc_set_system_info() seems wrong because // TASK_SIZE is per-task. That's probably a design issue in GSP-RM though.
rust/kernel/pci.rs +32 -2
@@ -6,6 +6,7 @@use crate ::{ bindings, + bitfield, container_of, device, device_id::{
@@ -17,6 +18,7 @@ from_result, to_result, // }, + fmt, io::resource, prelude::*, str::CStr,
@@ -279,6 +281,34 @@ macro_rules! module_pci_driver { }; } +bitfield! { +/// Bus-Device-Function ID of a PCI device. +/// +/// Uses the same layout as the C `PCI_DEVID` macro. +#[doc(alias = "PCI_DEVID" )] +pub struct Bdf (u16 ) { +/// Bus number. +15 :8 bus; +/// Device number. +7 :3 device; +/// Function number. +2 :0 function; + } +} + +/// Formats the ID as `bus:device.function`, like the corresponding part of C's `pci_name()`. +impl fmt::Display for Bdf { +fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { +write! ( + f, +"{:02x}:{:02x}.{}" , + self.bus (), + self.device (), + self.function () + ) + } +} +/// Abstraction for the PCI device ID structure ([`struct pci_device_id`]). /// /// [`struct pci_device_id`]: https://docs.kernel.org/PCI/pci.html#c.pci_device_id
@@ -700,10 +730,10 @@ pub fn revision_id(&self) -> u8 {/// Returns the PCI bus device/function. #[inline] -pub fn dev_id (&self) ->u16 { +pub fn dev_id (&self) ->Bdf {// SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a // `struct pci_dev`. -unsafe { bindings::pci_dev_id (self.as_raw ()) } +Bdf ::from_raw (unsafe { bindings::pci_dev_id (self.as_raw ()) }) }/// Returns the PCI subsystem vendor ID.
samples/rust/rust_driver_sriov/pf.rs +1 -1
@@ -34,7 +34,7 @@ pub(crate) fn submit(vf: &pci::Device<Bound>) -> Result<u64> {dev_info! ( pf.pdev, -"Handle PF request {} from VF devfn {:#x}.\n" , +"Handle PF request {} from VF {}.\n" , request, vf.dev_id () );
Signature · 1 line
2.56.1
Re: [PATCH v2 2/3] rust: pci: return a bitfield type for dev_id
Quoted 9 lines · Alexandre Courbot
The return type of
dev_idhas a well-defined bit layout encoding the bus, device and function IDs of the PCI device. Add aBdfbitfield defining that layout and makedev_idreturn it so users can benefit from it and are not tempted to define their own BDF type.Also update the current two users of
dev_id.Signed-off-by Alexandre Courbot <[email protected]>Acked-by Danilo Krummrich <[email protected]>
Quoted 5 lines
--- drivers/gpu/nova-core/gsp/fw/commands.rs | 2 +- rust/kernel/pci.rs | 34 ++++++++++++++++++++++++++++++-- samples/rust/rust_driver_sriov/pf.rs | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-)
Alexandre Courbot
maintainerPATCH v2 3/3 gpu: nova-core: gsp: send the PCI domain, bus and device to GSP-RM
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
Open RM sends the PCI location of the GPU to GSP-RM as one word, which gpuEncodeDomainBusDevice() builds: the domain in bits 63:32, the bus number in bits 15:8 and the device number in bits 7:0.
Nova-core's system-info command sends the PCI device ID in that word
instead: the bus number, the device number and the function number, with no domain. The two words are equal only for a GPU at device 0, function 0 of domain 0, so GSP-RM receives a wrong location for a GPU anywhere else.
Send the domain, the bus number and the device number instead, in the layout that Open RM uses.
--- drivers/gpu/nova-core/gsp/fw/commands.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gsp/fw/commands.rs +29 -1
@@ -88,7 +88,7 @@ pub(crate) fn init<'a>( gpuPhysAddr: dev.resource_start(0)?, gpuPhysFbAddr: dev.resource_start(1)?, gpuPhysInstAddr: dev.resource_start(3)?, - nvDomainBusDeviceFunc: u64::from(dev.dev_id().into_raw()), + nvDomainBusDeviceFunc: u64::from(DomainBusDevice::new(dev)),// Using TASK_SIZE in r535_gsp_rpc_set_system_info() seems wrong because // TASK_SIZE is per-task. That's probably a design issue in GSP-RM though.
@@ -377,6 +377,34 @@ struct GspInitRequest { } } +bitfield! { +/// A GPU's PCI location as GSP-RM reads it: the domain, the bus number and the device number. +/// +/// The function is omitted on purpose. +struct DomainBusDevice (u64 ) { +/// PCI domain number. +63 :32 domain; +/// PCI bus number. +15 :8 bus; +/// PCI device number. +/// +/// Note: this field is larger than the equivalent one in [`pci::Bdf`]. This follows OpenRM. +7 :0 device; + } +} + +impl DomainBusDevice { +/// Returns the PCI location of `dev`. +fn new (dev: &pci::Device <device::Bound >) ->Self { +let dev_id = dev.dev_id (); + +Self ::zeroed () + .with_domain (dev.domain_nr ()) + .with_bus (u8::from (dev_id.bus ())) + .with_device (u8::from (dev_id.device ())) + } +} +// Decode: // Should decode with UnknownKeyPolicy::Ignore.
Signature · 1 line
2.56.1
[email protected]
AI reviewSashiko has reviewed this 3-patch series and found no issues.
Sashiko has reviewed this 3-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]
Quoted 3 lines · Alexandre Courbot
rust: bitfield: add missing doccomments for associated constants
rust: pci: return a bitfield type fordev_id
gpu: nova-core: gsp: send the PCI domain, bus and device to GSP-RM