[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DCBI3A82MOFN.3R7O7I6U6D7LN@nvidia.com>
Date: Mon, 25 Aug 2025 21:17:28 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "John Hubbard" <jhubbard@...dia.com>, "Danilo Krummrich"
<dakr@...nel.org>
Cc: "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>, "Elle Rhumsaa" <elle@...thered-steel.dev>
Subject: Re: [PATCH v6 1/5] rust: pci: provide access to PCI Class and
Class-related items
Hi John,
On Fri Aug 22, 2025 at 11:03 AM JST, John Hubbard wrote:
> 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::as_raw()
> Class: From<u32> for Class
> ClassMask: Full, ClassSubclass
> Device::pci_class()
>
> Cc: Danilo Krummrich <dakr@...nel.org>
> Cc: Alexandre Courbot <acourbot@...dia.com>
> Cc: Elle Rhumsaa <elle@...thered-steel.dev>
> Signed-off-by: John Hubbard <jhubbard@...dia.com>
Just one question about the 16 and 24 bit representations below.
<snip>
> +macro_rules! define_all_pci_classes {
> + (
> + $($variant:ident = $binding:expr,)+
> + ) => {
> +
> + impl Class {
> + $(
> + #[allow(missing_docs)]
> + pub const $variant: Self = Self(Self::to_24bit_class($binding));
> + )+
> + }
> +
> + /// Convert a raw 24-bit class code value to a `Class`.
> + impl From<u32> for Class {
> + fn from(value: u32) -> Self {
> + match value {
> + $(x if x == Self::$variant.0 => Self::$variant,)+
> + _ => Self::UNKNOWN,
> + }
> + }
Should we normalize `value` to 24 bits (i.e. call `to_24bit_class`)
before doing the match? The constants we compare against are all
normalized, but if we pass a 16-bit class to this method the result will
be `UNKNOWN`, unless I missed something.
Being able to store a class as either a 16-bit or 24-bit representation
in the same type also opens the door to bugs, which we can avoid if we
always normalize to 24-bit and make the class/subclass representation
accessible through a convenience method only.
> + }
> + };
> +}
> +
> +/// Once constructed, a `Class` contains a valid PCI Class code.
> +impl Class {
> + /// Create a new Class from a raw 24-bit class code.
> + pub fn new(class_code: u32) -> Self {
> + Self::from(class_code)
> + }
Do we need a `new` method when the `From` implementation does exactly
the same thing and has the same signature?
Powered by blists - more mailing lists