MAINTAINERS | 1 + drivers/gpu/nova-core/driver.rs | 33 +- rust/kernel/pci.rs | 72 +++- rust/kernel/pci/id.rs | 558 ++++++++++++++++++++++++++ samples/rust/rust_dma.rs | 6 +- samples/rust/rust_driver_auxiliary.rs | 12 +- samples/rust/rust_driver_pci.rs | 9 +- 7 files changed, 663 insertions(+), 28 deletions(-) create mode 100644 rust/kernel/pci/id.rs
Changes since v7: * Applied changes from Danilo's and Alex's and reviews (thanks!): * Removed a blank line, one each, from the Class and Vendor macros. * Moved example code location from struct Vendor, to vendor_id(), and introduced it in a later commit, in its final form. * Applied Alex's Reviewed-by tag to the series. Changes since v6: * Applied changes from Danilo's and Alex's and Elle's reviews (thanks!): * Rebased onto driver-core-next, which is here: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git * Changed pci::Vendor to be a u16, instead of a u32. * Inlined all of the tiniest functions. * Changed from Class/Vendor new(), to from_raw(). * Made from_raw() only accessible to super, which in this case is the pci module. * Restored infallible operations. That causes Alex's request for the following reasonable behavior to work once again: from_raw(0x10de).as_raw() == 0x10de * Added a new patch, to inline the remaining PCI operations. This provides consistent inline choices throughout pci.rs. Changes since v5: * Applied changes from Danilo's review (thanks!): * Split the nova-core patch into two patches, for nova and pci. * Added rust/kernel/pci/ to MAINTAINERS. Changes since v4: * Applied changes from Danilo's and Alex's review (thanks!): * Reorganized the patches so that the Nova changes consume the results of Class and Vendor upgrades, all in one shot. * Made Class and Vendor types get constructed infallibly. * This was all somewhat disruptive, and also required one more patch in order to properly separate the various steps. But I think it is all correct now. And CLIPPY=1 builds cleanly too. * Elle Rhumsaa provided a Reviewed-by for v4 (thanks!), but due to the churn in v5 here, I thought it best to not add that tag to v5 yet. Instead, I have directly Cc'd Elle on the patches for now. Changes since v3: * Applied changes from Danilo's review (thanks!): * Moved Class and Vendor to a new pci/id.rs file. * Added ClassMask, to constrain callers to use only the two valid masks. * Removed pci_class_code_raw() * Changed Class and Vendor .as_u32() to .as_raw(), because after Danilo's comment I looked around rust/kernel and learned that .as_raw() is the overwhelmingly used convention. * Changed vendor_id() to return a Vendor instance directly. * Also, validated Vendor during construction, just as is done with Class. Both of these items are expected to match known values, even for new devices, so that's a reasonable move. Changes since v2: * Applied changes from Danilo's and Alex's review (thanks!): * Moved everything possible out of the new define_all_pci_classes!() and define_all_pci_vendors!() macros. * Used "impl TryFrom<u32> for Class/Vendor", instead of .from_u32(). * Made the new DeviceId methods infallible. * Upgraded DeviceId::from_id() to accept a Vendor struct. * Changed the names to be a little clearer: * class_code_raw() --> pci_class_code_raw() * class_enum() --> pci_class() * Added doctests for the items that are not yet used in real drivers. v2 is here: https://lore.kernel.org/20250818013305.1089446-1-jhubbard@nvidia.com Changes since v1: 1) Use the pci_device_table for filtering, instead of open-coding filters in the .probe() callback. 2) Add PCI Class (class, subclass, implementation) and PCI Vendor to Rust for Linux. 3) Rebased onto the latest nova-next branch, which is here: https://gitlab.freedesktop.org/drm/nova.git v1 is here: https://lore.kernel.org/20250813232859.224316-1-jhubbard@nvidia.com Cc: Danilo Krummrich <dakr@kernel.org> Cc: Alexandre Courbot <acourbot@nvidia.com> Cc: Elle Rhumsaa <elle@weathered-steel.dev> John Hubbard (6): rust: pci: provide access to PCI Class and Class-related items rust: pci: provide access to PCI Vendor values rust: pci: add DeviceId::from_class_and_vendor() method gpu: nova-core: avoid probing non-display/compute PCI functions rust: pci: use pci::Vendor instead of bindings::PCI_VENDOR_ID_* rust: pci: inline several tiny functions MAINTAINERS | 1 + drivers/gpu/nova-core/driver.rs | 33 +- rust/kernel/pci.rs | 72 +++- rust/kernel/pci/id.rs | 558 ++++++++++++++++++++++++++ samples/rust/rust_dma.rs | 6 +- samples/rust/rust_driver_auxiliary.rs | 12 +- samples/rust/rust_driver_pci.rs | 9 +- 7 files changed, 663 insertions(+), 28 deletions(-) create mode 100644 rust/kernel/pci/id.rs base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585 -- 2.51.0
On Sat Aug 30, 2025 at 12:36 AM CEST, John Hubbard wrote: > Changes since v7: > > * Applied changes from Danilo's and Alex's and reviews (thanks!): > * Removed a blank line, one each, from the Class and Vendor macros. > * Moved example code location from struct Vendor, to vendor_id(), > and introduced it in a later commit, in its final form. > * Applied Alex's Reviewed-by tag to the series. I think you forgot to align Debug and Display, i.e. Debug still prints decimal values. Is this intentional? If not, no worries, I can fix it up on apply (which a few minor doc-comment nits): diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs index f6ce8f8a2a4d..f534133aed3d 100644 --- a/rust/kernel/pci/id.rs +++ b/rust/kernel/pci/id.rs @@ -26,7 +26,7 @@ /// Ok(()) /// } /// ``` -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq)] #[repr(transparent)] pub struct Class(u32); @@ -81,12 +81,18 @@ const fn to_24bit_class(val: u32) -> u32 { } } -impl fmt::Display for Class { +impl fmt::Debug for Class { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "0x{:06x}", self.0) } } +impl fmt::Display for Class { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + <Self as fmt::Debug>::fmt(self, f) + } +} + impl ClassMask { /// Get the raw mask value. #[inline]
On 9/1/25 7:58 AM, Danilo Krummrich wrote: > On Sat Aug 30, 2025 at 12:36 AM CEST, John Hubbard wrote: >> Changes since v7: >> >> * Applied changes from Danilo's and Alex's and reviews (thanks!): >> * Removed a blank line, one each, from the Class and Vendor macros. >> * Moved example code location from struct Vendor, to vendor_id(), >> and introduced it in a later commit, in its final form. >> * Applied Alex's Reviewed-by tag to the series. > > I think you forgot to align Debug and Display, i.e. Debug still prints decimal > values. > > Is this intentional? If not, no worries, I can fix it up on apply (which a few > minor doc-comment nits): Yes, I missed that one. Fixup on apply would be great, yes. thanks, John Hubbard > > diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs > index f6ce8f8a2a4d..f534133aed3d 100644 > --- a/rust/kernel/pci/id.rs > +++ b/rust/kernel/pci/id.rs > @@ -26,7 +26,7 @@ > /// Ok(()) > /// } > /// ``` > -#[derive(Debug, Clone, Copy, PartialEq, Eq)] > +#[derive(Clone, Copy, PartialEq, Eq)] > #[repr(transparent)] > pub struct Class(u32); > > @@ -81,12 +81,18 @@ const fn to_24bit_class(val: u32) -> u32 { > } > } > > -impl fmt::Display for Class { > +impl fmt::Debug for Class { > fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { > write!(f, "0x{:06x}", self.0) > } > } > > +impl fmt::Display for Class { > + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { > + <Self as fmt::Debug>::fmt(self, f) > + } > +} > + > impl ClassMask { > /// Get the raw mask value. > #[inline]
On Sat Aug 30, 2025 at 12:36 AM CEST, John Hubbard wrote: > John Hubbard (6): Applied to driver-core-testing, thanks! > rust: pci: provide access to PCI Class and Class-related items [ Minor doc-comment improvements, align Debug and Display. - Danilo ] > rust: pci: provide access to PCI Vendor values [ Minor doc-comment improvements, align Debug and Display. - Danilo ] > rust: pci: add DeviceId::from_class_and_vendor() method [ Minor doc-comment improvements. - Danilo ] > gpu: nova-core: avoid probing non-display/compute PCI functions > rust: pci: use pci::Vendor instead of bindings::PCI_VENDOR_ID_* [ Replace "as a validated vendor" with "as [`Vendor`]". - Danilo ] > rust: pci: inline several tiny functions
© 2016 - 2025 Red Hat, Inc.