Re: [PATCH v3 4/5] rust: pci: add config space read/write support

From: Danilo Krummrich

Date: Fri Oct 31 2025 - 08:48:47 EST


On Thu Oct 30, 2025 at 4:48 PM CET, Zhi Wang wrote:
> +impl<'a, const SIZE: usize> Io<SIZE> for ConfigSpace<'a, SIZE> {
> + /// Returns the base address of this mapping.
> + #[inline]
> + fn addr(&self) -> usize {
> + 0
> + }
> +
> + /// Returns the maximum size of this mapping.
> + #[inline]
> + fn maxsize(&self) -> usize {
> + self.pdev.cfg_size().map_or(0, |v| v as usize)
> + }
> +
> + define_read!(fallible, try_read8, call_config_read, pci_read_config_byte -> u8);
> + define_read!(fallible, try_read16, call_config_read, pci_read_config_word -> u16);
> + define_read!(fallible, try_read32, call_config_read, pci_read_config_dword -> u32);
> +
> + define_write!(fallible, try_write8, call_config_write, pci_write_config_byte <- u8);
> + define_write!(fallible, try_write16, call_config_write, pci_write_config_word <- u16);
> + define_write!(fallible, try_write32, call_config_write, pci_write_config_dword <- u32);
> +}

Please also implement the infallible ones.

> +
> /// A PCI BAR to perform I/O-Operations on.
> ///
> /// # Invariants
> @@ -615,6 +670,11 @@ pub fn set_master(&self) {
> // SAFETY: `self.as_raw` is guaranteed to be a pointer to a valid `struct pci_dev`.
> unsafe { bindings::pci_set_master(self.as_raw()) };
> }
> +
> + /// Return an initialized config space object.
> + pub fn config_space<'a>(&'a self) -> Result<ConfigSpace<'a>> {
> + Ok(ConfigSpace { pdev: self })
> + }

Please see [1].

[1] https://lore.kernel.org/lkml/DDWINZJUGVQ8.POKS7A6ZSRFK@xxxxxxxxxx/