On Fri Jun 12, 2026 at 1:28 AM JST, Gary Guo wrote: > In order to support I/O projection, we are splitting I/O types into two > categories: owned objects and views. Owned objects have a specific type > that is related to setting up and tearing down, while views can have their > type changed with I/O projection. > > Things like `IoMem` or `Bar` are owned objects, which requires setting up > mapping and cleaning up on drop. On the other side, `ConfigSpace` is really > just a view, as the resource is associated with the `pci::Device`. > > Remove the `ConfigSpaceKind` bound on `ConfigSpace` and make it a generic > view. This means that `ConfigSpace` object now represents a subregion and > therefore encodes offset (as address of pointers) and size (as metadata of > pointers) itself. The full region case is still supported with offset 0 and > size of `cfg_size`. > > Signed-off-by: Gary Guo <[email protected]> > --- > rust/kernel/pci/io.rs | 64 > +++++++++++++++++++++++++++++---------------------- > 1 file changed, 36 insertions(+), 28 deletions(-) > > diff --git a/rust/kernel/pci/io.rs b/rust/kernel/pci/io.rs > index e0acb62f58a2..89f4bb483a7f 100644 > --- a/rust/kernel/pci/io.rs > +++ b/rust/kernel/pci/io.rs > @@ -18,7 +18,6 @@ > ptr::KnownSize, // > }; > use core::{ > - marker::PhantomData, > ops::Deref, // > }; > > @@ -53,33 +52,42 @@ pub const fn into_raw(self) -> usize { > /// Alias for extended (4096-byte) PCIe configuration space. > pub type Extended = Region<4096>; > > -/// Trait for PCI configuration space size markers. > -/// > -/// This trait is implemented by [`Normal`] and [`Extended`] to provide > -/// compile-time knowledge of the configuration space size. > -pub trait ConfigSpaceKind: KnownSize {} > - > -impl ConfigSpaceKind for Normal {} > - > -impl ConfigSpaceKind for Extended {} > - > -/// The PCI configuration space of a device. > +/// A view of PCI configuration space of a device. > /// > /// Provides typed read and write accessors for configuration registers > /// using the standard `pci_read_config_*` and `pci_write_config_*` helpers. > /// > -/// The generic parameter `S` indicates the maximum size of the > configuration space. > -/// Use [`Normal`] for 256-byte legacy configuration space or [`Extended`] > for > -/// 4096-byte PCIe extended configuration space (default). > -pub struct ConfigSpace<'a, S: ?Sized + ConfigSpaceKind = Extended> { > +/// The generic parameter `T` is the type of the view. The full > configuration space is also a > +/// special type of view; in such cases, `T` can be [`Normal`] for 256-byte > legacy configuration > +/// space or [`Extended`] for 4096-byte PCIe extended configuration space > (default). > +/// > +/// # Invariants > +/// > +/// `ptr` is aligned and range `ptr..ptr + KnownSize::size(ptr)` is within > +/// `0..pdev.cfg_size().into_raw()`. > +pub struct ConfigSpace<'a, T: ?Sized = Extended> { > pub(crate) pdev: &'a Device<device::Bound>, > - _marker: PhantomData<S>, > + ptr: *mut T,
`ptr` is used as a pseudo-pointer here, can its documentation be more explicit about that? Regardless, Reviewed-by: Alexandre Courbot <[email protected]>
