[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DDWINZJUGVQ8.POKS7A6ZSRFK@kernel.org>
Date: Fri, 31 Oct 2025 13:46:28 +0100
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Zhi Wang" <zhiw@...dia.com>
Cc: "Bjorn Helgaas" <helgaas@...nel.org>, <rust-for-linux@...r.kernel.org>,
<bhelgaas@...gle.com>, <kwilczynski@...nel.org>, <ojeda@...nel.org>,
<alex.gaynor@...il.com>, <boqun.feng@...il.com>, <gary@...yguo.net>,
<bjorn3_gh@...tonmail.com>, <lossin@...nel.org>, <a.hindborg@...nel.org>,
<aliceryhl@...gle.com>, <tmgross@...ch.edu>, <linux-pci@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <cjia@...dia.com>, <smitra@...dia.com>,
<ankita@...dia.com>, <aniketa@...dia.com>, <kwankhede@...dia.com>,
<targupta@...dia.com>, <zhiwang@...nel.org>, <acourbot@...dia.com>,
<joelagnelf@...dia.com>, <jhubbard@...dia.com>, <markus.probst@...teo.de>
Subject: Re: [PATCH v3 3/5] rust: pci: add a helper to query configuration
space size
On Fri Oct 31, 2025 at 1:16 PM CET, Zhi Wang wrote:
> On Thu, 30 Oct 2025 11:51:15 -0500
> Bjorn Helgaas <helgaas@...nel.org> wrote:
>> Apart from pci-sysfs and vfio, I don't really see any drivers that use
>> pdev->cfg_size today.
>
> It is for the framework so far. If we believe that driver doesn't need
> this in the near term, I can make it private in the next re-spin.
Device::cfg_size() should indeed be private, I don't see a reason for drivers to
call this directly.
However, enum ConfigSpaceSize has to be public, such that we can implement a
method:
pub fn config_space<'a, const SIZE: usize>(&'a self) -> Result<ConfigSpace<'a, SIZE>>
so the driver can assert whether it requires the normal or extended
configuration space size with e.g.:
// Fails if the configuration space does not have an extended size.
let cfg = pdev.config_space::<ConfigSpaceSize::Extended>()?;
Subsequently, we can do infallible accesses within the corresponding guaranteed
range.
Given that there are only two options, normal or extended, we can also drop the
const generic and just provide two separate methods:
pub fn config_space<'a>(&'a self) -> Result<ConfigSpace<'a, ConfigSpaceSize::Normal>>
and
pub fn config_space_extended<'a>(&'a self) -> Result<ConfigSpace<'a, ConfigSpaceSize::Extended>>
Allowing drivers to request a ConfigSpace<'a, 0> with only runtime checks makes
no sense, ConfigSpaceSize::Normal is always the minimum.
- Danilo
Powered by blists - more mailing lists