]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: pci: add config space read/write support
authorZhi Wang <zhiw@nvidia.com>
Wed, 21 Jan 2026 20:22:10 +0000 (22:22 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Fri, 23 Jan 2026 20:23:16 +0000 (21:23 +0100)
commit4dc0bacb1d3c4722cbd002c4aab6bd458d30d869
treeaaae06aaf61ea463d288f99c1b0c845589f76863
parent5981d03c27a14df1c03e10570eeb1ab26e9709f7
rust: pci: add config space read/write support

Drivers might need to access PCI config space for querying capability
structures and access the registers inside the structures.

For Rust drivers need to access PCI config space, the Rust PCI abstraction
needs to support it in a way that upholds Rust's safety principles.

Introduce a `ConfigSpace` wrapper in Rust PCI abstraction to provide safe
accessors for PCI config space. The new type implements the `Io` trait and
`IoCapable<T>` for u8, u16, and u32 to share offset validation and
bound-checking logic with other I/O backends.

The `ConfigSpace` type uses marker types (`Normal` and `Extended`) to
represent configuration space sizes at the type level.

Cc: Alexandre Courbot <acourbot@nvidia.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Gary Guo <gary@garyguo.net>
Cc: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Zhi Wang <zhiw@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/all/DFV4IJDQC2J6.1Q91JOAL6CJSG@kernel.org/
Link: https://patch.msgid.link/20260121202212.4438-5-zhiw@nvidia.com
[ Applied the diff from [1], considering subsequent comment; remove
  #[expect(unused)] from define_{read,write}!(). - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/io.rs
rust/kernel/pci.rs
rust/kernel/pci/io.rs