All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Gary Guo" <gary@garyguo.net>
Cc: "Yury Norov" <yury.norov@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Alistair Popple" <apopple@nvidia.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Zhi Wang" <zhiw@nvidia.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH 2/3] rust: pci: return a bitfield type for dev_id
Date: Sat, 28 Nov 2026 11:06:54 +0900	[thread overview]
Message-ID: <DN6H6EMLR0V2.RWXLLGN754P6@nvidia.com> (raw)
In-Reply-To: <DN62L6PL724V.2HIAY6WVTYPFP@garyguo.net>

On Fri Nov 27, 2026 at 11:40 PM JST, Gary Guo wrote:
> On Fri Nov 27, 2026 at 11:46 AM GMT, Alexandre Courbot wrote:
>> The return type of `dev_id` has a well-defined bit layout encoding
>> the bus, device and function IDs of the PCI device. Add a `Bdf` bitfield
>> defining that layout and make `dev_id` return it so users can benefit
>> from it and are not tempted to define their own BDF type.
>>
>> Also update the current two users of `dev_id`.
>>
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>> ---
>>  drivers/gpu/nova-core/gsp/fw/commands.rs |  2 +-
>>  rust/kernel/pci.rs                       | 33 ++++++++++++++++++++++++++++++--
>>  samples/rust/rust_driver_sriov/pf.rs     |  2 +-
>>  3 files changed, 33 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs
>> index b4bdbddad79f..37b89e62387f 100644
>> --- a/drivers/gpu/nova-core/gsp/fw/commands.rs
>> +++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
>> @@ -88,7 +88,7 @@ pub(crate) fn init<'a>(
>>              gpuPhysAddr: dev.resource_start(0)?,
>>              gpuPhysFbAddr: dev.resource_start(1)?,
>>              gpuPhysInstAddr: dev.resource_start(3)?,
>> -            nvDomainBusDeviceFunc: u64::from(dev.dev_id()),
>> +            nvDomainBusDeviceFunc: u64::from(dev.dev_id().into_raw()),
>>  
>>              // Using TASK_SIZE in r535_gsp_rpc_set_system_info() seems wrong because
>>              // TASK_SIZE is per-task. That's probably a design issue in GSP-RM though.
>> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
>> index 04a6d240afb2..0592b220767c 100644
>> --- a/rust/kernel/pci.rs
>> +++ b/rust/kernel/pci.rs
>> @@ -6,6 +6,7 @@
>>  
>>  use crate::{
>>      bindings,
>> +    bitfield,
>>      container_of,
>>      device,
>>      device_id::{
>> @@ -17,6 +18,7 @@
>>          from_result,
>>          to_result, //
>>      },
>> +    fmt,
>>      io::resource,
>>      prelude::*,
>>      str::CStr,
>> @@ -279,6 +281,33 @@ macro_rules! module_pci_driver {
>>  };
>>  }
>>  
>> +bitfield! {
>> +    /// Bus-Device-Function ID of a PCI device. Equivalent of C's `PCI_DEVID`.
>
> You can use
>
>     #[doc(alias = "PCI_DEVID")]
>
> for doc searchability.

Thanks! Will do.

>
>> +    pub struct Bdf(u16) {
>> +        /// Bus number.
>> +        15:8 bus;
>> +        /// Device number.
>> +        7:3 device;
>> +        /// Function number.
>> +        2:0 function;
>> +        /// Aggregation of `device` and `function`, which are commonly used together in code.
>
> I wonder if this is actually true, or is this just a result of existing API
> being designed to bundle these together? I quick grep shows that the combined
> value is most commonly used to make API happy and packing/unpacking happens
> immediately before/after the API call.
>
> For C code it is done this way before it avoids having bitfields. But given that
> we're using bitfields here already, we can just use `device` and `function` and
> omit `devfn`.

Nobody is using it for now, so this was added proactively and without
evidence I admit. Let's drop it for now.

  reply	other threads:[~2026-11-28  2:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 11:46 [PATCH 0/3] gpu: nova-core: gsp: fix the PCI location sent to GSP-RM Alexandre Courbot
2026-11-27 11:46 ` [PATCH 1/3] rust: bitfield: add missing doccomments for associated constants Alexandre Courbot
2026-11-30 12:56   ` Eliot Courtney
2026-11-30 13:08   ` Gary Guo
2026-11-27 11:46 ` [PATCH 2/3] rust: pci: return a bitfield type for dev_id Alexandre Courbot
2026-11-27 12:44   ` Danilo Krummrich
2026-11-27 14:40   ` Gary Guo
2026-11-28  2:06     ` Alexandre Courbot [this message]
2026-11-27 11:46 ` [PATCH 3/3] gpu: nova-core: gsp: send the PCI domain, bus and device to GSP-RM Alexandre Courbot
2026-11-30 12:56   ` Eliot Courtney
2026-11-30 13:12   ` Gary Guo
2026-12-01  7:03     ` Alexandre Courbot
2026-11-27 11:50 ` [PATCH 0/3] gpu: nova-core: gsp: fix the PCI location sent " sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DN6H6EMLR0V2.RWXLLGN754P6@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=work@onurozkan.dev \
    --cc=yury.norov@gmail.com \
    --cc=zhiw@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.