Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

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.

Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Elle Rhumsaa <elle@weathered-steel.dev>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Link: https://lore.kernel.org/r/20250829223632.144030-4-jhubbard@nvidia.com
[ Minor doc-comment improvements. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

John Hubbard and committed by
Danilo Krummrich
dd3933e9 5e20962a

+23
+23
rust/kernel/pci.rs
··· 162 162 override_only: 0, 163 163 }) 164 164 } 165 + 166 + /// Create a new [`DeviceId`] from a class number, mask, and specific vendor. 167 + /// 168 + /// This is more targeted than [`DeviceId::from_class`]: in addition to matching by [`Vendor`], 169 + /// it also matches the PCI [`Class`] (up to the entire 24 bits, depending on the 170 + /// [`ClassMask`]). 171 + #[inline] 172 + pub const fn from_class_and_vendor( 173 + class: Class, 174 + class_mask: ClassMask, 175 + vendor: Vendor, 176 + ) -> Self { 177 + Self(bindings::pci_device_id { 178 + vendor: vendor.as_raw() as u32, 179 + device: DeviceId::PCI_ANY_ID, 180 + subvendor: DeviceId::PCI_ANY_ID, 181 + subdevice: DeviceId::PCI_ANY_ID, 182 + class: class.as_raw(), 183 + class_mask: class_mask.as_raw(), 184 + driver_data: 0, 185 + override_only: 0, 186 + }) 187 + } 165 188 } 166 189 167 190 // SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `pci_device_id` and does not add