[PATCH v2 3/3] rust: pci: provide access to PCI Vendor values
John Hubbard
jhubbard at nvidia.com
Mon Aug 18 18:59:46 UTC 2025
On 8/18/25 9:06 AM, Danilo Krummrich wrote:
> On Mon Aug 18, 2025 at 3:33 AM CEST, John Hubbard wrote:
>> + /// Create a `Vendor` from the raw vendor ID value, or `None` if the value doesn't
>> + /// match any known vendor.
>> + pub fn from_u32(value: u32) -> Option<Self> {
>> + match value {
>> + $(x if x == Self::$variant.0 => Some(Self::$variant),)+
>> + _ => None,
>> + }
>> + }
>
> Same here, I think this should be `impl TryFrom<u32> for Vendor`.
OK.
>
>> +
>> + /// Get the raw 16-bit vendor ID value.
>> + pub const fn as_u32(self) -> u32 {
>> + self.0
>> + }
>> + }
>> + };
>> +}
>
>> /// An adapter for the registration of PCI drivers.
>> pub struct Adapter<T: Driver>(T);
>>
>> @@ -335,9 +656,9 @@ pub const fn from_class(class: u32, class_mask: u32) -> Self {
>> ///
>> /// 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).
>> - pub const fn from_class_and_vendor(class: Class, class_mask: u32, vendor: u32) -> Self {
>> + pub const fn from_class_and_vendor(class: Class, class_mask: u32, vendor: Vendor) -> Self {
>> Self(bindings::pci_device_id {
>> - vendor,
>> + vendor: vendor.as_u32(),
>> device: DeviceId::PCI_ANY_ID,
>> subvendor: DeviceId::PCI_ANY_ID,
>> subdevice: DeviceId::PCI_ANY_ID,
>> @@ -396,7 +717,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.as_u32(), bindings::PCI_ANY_ID as u32),
>
> We should change DeviceId::from_id() to consume a pci::Vendor value directly.
Interesting. OK.
Thanks for the review!
thanks,
--
John Hubbard
More information about the Nouveau
mailing list