[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DC5OKZHPTDWC.L6YD327Z0WJN@kernel.org>
Date: Mon, 18 Aug 2025 18:06:42 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "John Hubbard" <jhubbard@...dia.com>
Cc: "Alexandre Courbot" <acourbot@...dia.com>, "Joel Fernandes"
<joelagnelf@...dia.com>, "Timur Tabi" <ttabi@...dia.com>, "Alistair Popple"
<apopple@...dia.com>, "David Airlie" <airlied@...il.com>, "Simona Vetter"
<simona@...ll.ch>, "Bjorn Helgaas" <bhelgaas@...gle.com>,
Krzysztof Wilczyński <kwilczynski@...nel.org>, "Miguel
Ojeda" <ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun
Feng" <boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Alice
Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
<nouveau@...ts.freedesktop.org>, <linux-pci@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>, "LKML" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 3/3] rust: pci: provide access to PCI Vendor values
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`.
> +
> + /// 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.
Powered by blists - more mailing lists