Skip to contentSkip to conversation

rust, nova-core: PCI Class, Vendor support

PATCH In review John Hubbard 2 participants 10 messages Aug 29, 2025 – Sep 1, 2025

Subsystems (8)
DRM drivers PCI Rust DRM Rust +4 more subsystems
lore
Share & tools
lore
#0 lore raw

v8 cover rust, nova-core: PCI Class, Vendor support

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/[email protected]

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/[email protected]
Cc Danilo Krummrich <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Elle Rhumsaa <[email protected]>

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

Signature · 1 line
2.51.0
#1 lore raw

PATCH v8 1/6 rust: pci: provide access to PCI Class and Class-related items

Allow callers to write Class::STORAGE_SCSI instead of bindings::PCI_CLASS_STORAGE_SCSI, for example.

New APIs:
Class::STORAGE_SCSI, Class::NETWORK_ETHERNET, etc. Class::from_raw() -- Only callable from pci module. Class::as_raw()
ClassMask: Full, ClassSubclass Device::pci_class()

---
 MAINTAINERS           |   1 +
 rust/kernel/pci.rs    |  11 ++
 rust/kernel/pci/id.rs | 231 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 243 insertions(+)
 create mode 100644 rust/kernel/pci/id.rs
MAINTAINERS +1 -0
index fe168477caa4..28e200fa9423 100644
@@ -19532,6 +19532,7 @@ C:	irc://irc.oftc.net/linux-pci
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git
 F:	rust/helpers/pci.c
 F:	rust/kernel/pci.rs
+F:	rust/kernel/pci/
 F:	samples/rust/rust_driver_pci.rs
 
 PCIE BANDWIDTH CONTROLLER
rust/kernel/pci.rs +11 -0
index 887ee611b553..212c4a6834fb 100644
@@ -23,6 +23,10 @@
 };
 use kernel::prelude::*;
 
+mod id;
+
+pub use self::id::{Class, ClassMask};
+
 /// An adapter for the registration of PCI drivers.
 pub struct Adapter<T: Driver>(T);
 
@@ -410,6 +414,13 @@ pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> {
         // - by its type invariant `self.as_raw` is always a valid pointer to a `struct pci_dev`.
         Ok(unsafe { bindings::pci_resource_len(self.as_raw(), bar.try_into()?) })
     }
+
+    /// Returns the PCI class as a `Class` struct.
+    #[inline]
+    pub fn pci_class(&self) -> Class {
+        // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
+        Class::from_raw(unsafe { (*self.as_raw()).class })
+    }
 }
 
 impl Device<device::Bound> {
rust/kernel/pci/id.rs new file +231 -0

231 lines not on this page · raw message

Signature · 1 line
2.51.0
#2 lore raw

PATCH v8 2/6 rust: pci: provide access to PCI Vendor values

In reply to John Hubbard

This allows callers to write Vendor::SOME_COMPANY instead of bindings::PCI_VENDOR_ID_SOME_COMPANY.

New APIs:
Vendor::SOME_COMPANY
Vendor::from_raw() -- Only accessible from the pci (parent) module. Vendor::as_raw()
Vendor: fmt::Display for Vendor

---
 rust/kernel/pci.rs    |   2 +-
 rust/kernel/pci/id.rs | 330 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 330 insertions(+), 2 deletions(-)
rust/kernel/pci.rs +1 -1
index 212c4a6834fb..f15cfd0e76d9 100644
@@ -25,7 +25,7 @@
 
 mod id;
 
-pub use self::id::{Class, ClassMask};
+pub use self::id::{Class, ClassMask, Vendor};
 
 /// An adapter for the registration of PCI drivers.
 pub struct Adapter<T: Driver>(T);
rust/kernel/pci/id.rs +329 -1

345 lines not on this page · raw message

Signature · 1 line
2.51.0
#3 lore raw

PATCH v8 3/6 rust: pci: add DeviceId::from_class_and_vendor() method

In reply to John Hubbard

Add a new method to create PCI DeviceIds that match both a specific vendor and PCI class. This is more targeted than the existing from_class() method as it filters on both vendor and class criteria.

---
 rust/kernel/pci.rs | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
rust/kernel/pci.rs +22 -0
index f15cfd0e76d9..26974cae4a22 100644
@@ -161,6 +161,28 @@ pub const fn from_class(class: u32, class_mask: u32) -> Self {
             override_only: 0,
         })
     }
+
+    /// Create a new `pci::DeviceId` from a class number, mask, and specific vendor.
+    ///
+    /// This is more targeted than [`DeviceId::from_class`]: in addition to matching by Vendor, it
+    /// also matches the PCI Class (up to the entire 24 bits, depending on the mask).
+    #[inline]
+    pub const fn from_class_and_vendor(
+        class: Class,
+        class_mask: ClassMask,
+        vendor: Vendor,
+    ) -> Self {
+        Self(bindings::pci_device_id {
+            vendor: vendor.as_raw() as u32,
+            device: DeviceId::PCI_ANY_ID,
+            subvendor: DeviceId::PCI_ANY_ID,
+            subdevice: DeviceId::PCI_ANY_ID,
+            class: class.as_raw(),
+            class_mask: class_mask.as_raw(),
+            driver_data: 0,
+            override_only: 0,
+        })
+    }
 }
 
 // SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `pci_device_id` and does not add
Signature · 1 line
2.51.0
#4 lore raw

PATCH v8 4/6 gpu: nova-core: avoid probing non-display/compute PCI functions

In reply to John Hubbard

NovaCore has so far been too imprecise about figuring out if .probe() has found a supported PCI PF (Physical Function). By that I mean:
.probe() sets up BAR0 (which involves a lot of very careful devres and Device<Bound> details behind the scenes). And then if it is dealing with a non-supported device such as the .1 audio PF on many GPUs, it fails out due to an unexpected BAR0 size. We have been fortunate that the BAR0 sizes are different.

Really, we should be filtering on PCI class ID instead. These days I think we can confidently pick out Nova's supported PF's via PCI class ID. And if not, then we'll revisit.

The approach here is to filter on "Display VGA" or "Display 3D", which is how PCI class IDs express "this is a modern GPU's PF".

---
 drivers/gpu/nova-core/driver.rs | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
drivers/gpu/nova-core/driver.rs +28 -5
index 274989ea1fb4..5d23a91f51dd 100644
@@ -1,6 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0
 
-use kernel::{auxiliary, bindings, c_str, device::Core, pci, prelude::*, sizes::SZ_16M, sync::Arc};
+use kernel::{
+    auxiliary, c_str,
+    device::Core,
+    pci,
+    pci::{Class, ClassMask, Vendor},
+    prelude::*,
+    sizes::SZ_16M,
+    sync::Arc,
+};
 
 use crate::gpu::Gpu;
 
@@ -18,10 +26,25 @@ pub(crate) struct NovaCore {
     PCI_TABLE,
     MODULE_PCI_TABLE,
     <NovaCore as pci::Driver>::IdInfo,
-    [(
-        pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_NVIDIA, bindings::PCI_ANY_ID as u32),
-        ()
-    )]
+    [
+        // Modern NVIDIA GPUs will show up as either VGA or 3D controllers.
+        (
+            pci::DeviceId::from_class_and_vendor(
+                Class::DISPLAY_VGA,
+                ClassMask::ClassSubclass,
+                Vendor::NVIDIA
+            ),
+            ()
+        ),
+        (
+            pci::DeviceId::from_class_and_vendor(
+                Class::DISPLAY_3D,
+                ClassMask::ClassSubclass,
+                Vendor::NVIDIA
+            ),
+            ()
+        ),
+    ]
 );
 
 impl pci::Driver for NovaCore {
Signature · 1 line
2.51.0
#5 lore raw

PATCH v8 5/6 rust: pci: use pci::Vendor instead of bindings::PCI_VENDOR_ID_*

In reply to John Hubbard

Change Device::vendor_id() to return a Vendor type, and change DeviceId::from_id() to accept a Vendor type.

Use the new pci::Vendor in the various Rust for Linux callers who were previously using bindings::PCI_VENDOR_ID_*.

Doing so also allows removing "use kernel::bindings" entirely from most of the affected files here.

Also, mark vendor_id() as inline.

---
 rust/kernel/pci.rs                    | 33 +++++++++++++++++++++------
 rust/kernel/pci/id.rs                 |  1 -
 samples/rust/rust_dma.rs              |  6 +----
 samples/rust/rust_driver_auxiliary.rs | 12 ++++------
 samples/rust/rust_driver_pci.rs       |  9 ++++----
 5 files changed, 37 insertions(+), 24 deletions(-)
rust/kernel/pci.rs +26 -7
index 26974cae4a22..39a152da297c 100644
@@ -132,10 +132,10 @@ impl DeviceId {
 
     /// Equivalent to C's `PCI_DEVICE` macro.
     ///
-    /// Create a new `pci::DeviceId` from a vendor and device ID number.
-    pub const fn from_id(vendor: u32, device: u32) -> Self {
+    /// Create a new `pci::DeviceId` from a vendor and device ID.
+    pub const fn from_id(vendor: Vendor, device: u32) -> Self {
         Self(bindings::pci_device_id {
-            vendor,
+            vendor: vendor.as_raw() as u32,
             device,
             subvendor: DeviceId::PCI_ANY_ID,
             subdevice: DeviceId::PCI_ANY_ID,
@@ -232,7 +232,7 @@ macro_rules! pci_device_table {
 ///     <MyDriver as pci::Driver>::IdInfo,
 ///     [
 ///         (
-///             pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, bindings::PCI_ANY_ID as u32),
+///             pci::DeviceId::from_id(pci::Vendor::REDHAT, bindings::PCI_ANY_ID as u32),
 ///             (),
 ///         )
 ///     ]
@@ -413,10 +413,29 @@ fn as_raw(&self) -> *mut bindings::pci_dev {
 }
 
 impl Device {
-    /// Returns the PCI vendor ID.
-    pub fn vendor_id(&self) -> u16 {
+    /// Returns the PCI vendor ID as a validated Vendor.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// # use kernel::{device::Core, pci::{self, Vendor}, prelude::*};
+    /// fn log_device_info(pdev: &pci::Device<Core>) -> Result<()> {
+    ///     // Get the validated PCI vendor ID
+    ///     let vendor = pdev.vendor_id();
+    ///     dev_info!(
+    ///         pdev.as_ref(),
+    ///         "Device: Vendor={}, Device=0x{:x}\n",
+    ///         vendor,
+    ///         pdev.device_id()
+    ///     );
+    ///     Ok(())
+    /// }
+    /// ```
+    #[inline]
+    pub fn vendor_id(&self) -> Vendor {
         // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
-        unsafe { (*self.as_raw()).vendor }
+        let vendor_id = unsafe { (*self.as_raw()).vendor };
+        Vendor::from_raw(vendor_id)
     }
 
     /// Returns the PCI device ID.
rust/kernel/pci/id.rs +0 -1
index a7712df1fc43..47a3595e75be 100644
@@ -132,7 +132,6 @@ impl Vendor {
 impl Vendor {
     /// Create a Vendor from a raw 16-bit vendor ID.
     /// Only accessible from the parent pci module.
-    #[expect(dead_code)]
     #[inline]
     pub(super) fn from_raw(vendor_id: u16) -> Self {
         Self(vendor_id)
samples/rust/rust_dma.rs +1 -5
index c5e7cce68654..f3385c4a7e5b 100644
@@ -5,7 +5,6 @@
 //! To make this driver probe, QEMU must be run with `-device pci-testdev`.
 
 use kernel::{
-    bindings,
     device::Core,
     dma::{CoherentAllocation, Device, DmaMask},
     pci,
@@ -45,10 +44,7 @@ unsafe impl kernel::transmute::FromBytes for MyStruct {}
     PCI_TABLE,
     MODULE_PCI_TABLE,
     <DmaSampleDriver as pci::Driver>::IdInfo,
-    [(
-        pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, 0x5),
-        ()
-    )]
+    [(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())]
 );
 
 impl pci::Driver for DmaSampleDriver {
samples/rust/rust_driver_auxiliary.rs +5 -7
index f2a820683fc3..55ece336ee45 100644
@@ -5,7 +5,7 @@
 //! To make this driver probe, QEMU must be run with `-device pci-testdev`.
 
 use kernel::{
-    auxiliary, bindings, c_str, device::Core, driver, error::Error, pci, prelude::*, InPlaceModule,
+    auxiliary, c_str, device::Core, driver, error::Error, pci, prelude::*, InPlaceModule,
 };
 
 use pin_init::PinInit;
@@ -50,10 +50,7 @@ struct ParentDriver {
     PCI_TABLE,
     MODULE_PCI_TABLE,
     <ParentDriver as pci::Driver>::IdInfo,
-    [(
-        pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, 0x5),
-        ()
-    )]
+    [(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())]
 );
 
 impl pci::Driver for ParentDriver {
@@ -81,11 +78,12 @@ fn connect(adev: &auxiliary::Device) -> Result<()> {
         let parent = adev.parent().ok_or(EINVAL)?;
         let pdev: &pci::Device = parent.try_into()?;
 
+        let vendor = pdev.vendor_id();
         dev_info!(
             adev.as_ref(),
-            "Connect auxiliary {} with parent: VendorID={:#x}, DeviceID={:#x}\n",
+            "Connect auxiliary {} with parent: VendorID={}, DeviceID={:#x}\n",
             adev.id(),
-            pdev.vendor_id(),
+            vendor,
             pdev.device_id()
         );
 
samples/rust/rust_driver_pci.rs +5 -4
index 606946ff4d7f..f3819ac4bad6 100644
@@ -4,7 +4,7 @@
 //!
 //! To make this driver probe, QEMU must be run with `-device pci-testdev`.
 
-use kernel::{bindings, c_str, device::Core, devres::Devres, pci, prelude::*, types::ARef};
+use kernel::{c_str, device::Core, devres::Devres, pci, prelude::*, types::ARef};
 
 struct Regs;
 
@@ -38,7 +38,7 @@ struct SampleDriver {
     MODULE_PCI_TABLE,
     <SampleDriver as pci::Driver>::IdInfo,
     [(
-        pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, 0x5),
+        pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5),
         TestIndex::NO_EVENTFD
     )]
 );
@@ -66,10 +66,11 @@ impl pci::Driver for SampleDriver {
     const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
 
     fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> {
+        let vendor = pdev.vendor_id();
         dev_dbg!(
             pdev.as_ref(),
-            "Probe Rust PCI driver sample (PCI ID: 0x{:x}, 0x{:x}).\n",
-            pdev.vendor_id(),
+            "Probe Rust PCI driver sample (PCI ID: {}, 0x{:x}).\n",
+            vendor,
             pdev.device_id()
         );
 
Signature · 1 line
2.51.0
#6 lore raw

PATCH v8 6/6 rust: pci: inline several tiny functions

In reply to John Hubbard

Several previous commits added Vendor and Class functionality. As part of that, the new functions were inlined where appropriate. But that left this file with inconsistent use of inlining. Fix that by inlining the remaining items that should be.

---
 rust/kernel/pci.rs | 6 ++++++
 1 file changed, 6 insertions(+)
rust/kernel/pci.rs +6 -0
index 39a152da297c..f683af938628 100644
@@ -133,6 +133,7 @@ impl DeviceId {
     /// Equivalent to C's `PCI_DEVICE` macro.
     ///
     /// Create a new `pci::DeviceId` from a vendor and device ID.
+    #[inline]
     pub const fn from_id(vendor: Vendor, device: u32) -> Self {
         Self(bindings::pci_device_id {
             vendor: vendor.as_raw() as u32,
@@ -149,6 +150,7 @@ pub const fn from_id(vendor: Vendor, device: u32) -> Self {
     /// Equivalent to C's `PCI_DEVICE_CLASS` macro.
     ///
     /// Create a new `pci::DeviceId` from a class number and mask.
+    #[inline]
     pub const fn from_class(class: u32, class_mask: u32) -> Self {
         Self(bindings::pci_device_id {
             vendor: DeviceId::PCI_ANY_ID,
@@ -385,6 +387,7 @@ fn release(&self) {
 }
 
 impl Bar {
+    #[inline]
     fn index_is_valid(index: u32) -> bool {
         // A `struct pci_dev` owns an array of resources with at most `PCI_NUM_RESOURCES` entries.
         index < bindings::PCI_NUM_RESOURCES
@@ -407,6 +410,7 @@ fn deref(&self) -> &Self::Target {
 }
 
 impl<Ctx: device::DeviceContext> Device<Ctx> {
+    #[inline]
     fn as_raw(&self) -> *mut bindings::pci_dev {
         self.0.get()
     }
@@ -439,6 +443,7 @@ pub fn vendor_id(&self) -> Vendor {
     }
 
     /// Returns the PCI device ID.
+    #[inline]
     pub fn device_id(&self) -> u16 {
         // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
         unsafe { (*self.as_raw()).device }
@@ -493,6 +498,7 @@ pub fn enable_device_mem(&self) -> Result {
     }
 
     /// Enable bus-mastering for this device.
+    #[inline]
     pub fn set_master(&self) {
         // SAFETY: `self.as_raw` is guaranteed to be a pointer to a valid `struct pci_dev`.
         unsafe { bindings::pci_set_master(self.as_raw()) };
Signature · 1 line
2.51.0
maintainer
#7 lore raw
In reply to John Hubbard
Quoted 7 lines · John Hubbard

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):

rust/kernel/pci/id.rs +8 -2
index f6ce8f8a2a4d..f534133aed3d 100644
@@ -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]
#8 lore raw
Quoted 9 lines · Danilo Krummrich
Quoted 7 lines · John Hubbard

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.

Quoted 5 lines

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

Quoted 34 lines
rust/kernel/pci/id.rs +8 -2
index f6ce8f8a2a4d..f534133aed3d 100644
@@ -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]
maintainer
#9 lore raw
In reply to John Hubbard
Quoted 1 line · John Hubbard

John Hubbard (6):

Applied to driver-core-testing, thanks!

Quoted 1 line

rust: pci: provide access to PCI Class and Class-related items

[ Minor doc-comment improvements, align Debug and Display. - Danilo ]

Quoted 1 line

rust: pci: provide access to PCI Vendor values

[ Minor doc-comment improvements, align Debug and Display. - Danilo ]

Quoted 1 line

rust: pci: add DeviceId::from_class_and_vendor() method

[ Minor doc-comment improvements. - Danilo ]

Quoted 2 lines

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 ]

Quoted 1 line

rust: pci: inline several tiny functions