* [PATCH] rust: pci: add HeaderType enum and header_type() helper
@ 2026-01-03 14:38 SeungJong Ha via B4 Relay
2026-01-03 15:17 ` Danilo Krummrich
0 siblings, 1 reply; 6+ messages in thread
From: SeungJong Ha via B4 Relay @ 2026-01-03 14:38 UTC (permalink / raw)
To: Danilo Krummrich, Bjorn Helgaas, Krzysztof Wilczyński,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross
Cc: linux-kernel, linux-pci, rust-for-linux, SeungJong Ha
From: SeungJong Ha <engineer.jjhama@gmail.com>
Add the HeaderType enum to represent PCI configuration space header
types (Normal and Bridge). Also implement the header_type() method in
the Device struct to allow Rust PCI drivers to identify the device
type safely.
This is required for drivers to handle type-specific configuration
registers correctly.
Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>
---
Hello,
This is my first patch to the Linux kernel, specifically targeting the
Rust PCI subsystem.
This patch introduces the HeaderType enum to represent PCI configuration
space header types (Normal and Bridge) and implements the header_type()
method in the Device struct.
I have followed the patch submission checklist, but as this is my first
contribution, please let me know if I have missed any conventions or
if there are areas for improvement.
Thank you for your time and review!
Best regards,
SeungJong Ha
---
| 10 ++++++++++
| 31 +++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
--git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 82e128431..90a0eb54f 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -31,10 +31,12 @@
},
};
+mod header;
mod id;
mod io;
mod irq;
+pub use self::header::HeaderType;
pub use self::id::{
Class,
ClassMask,
@@ -373,6 +375,14 @@ pub fn revision_id(&self) -> u8 {
unsafe { (*self.as_raw()).revision }
}
+ /// Returns the PCI header type.
+ #[inline]
+ pub fn header_type(&self) -> HeaderType {
+ // SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a
+ // `struct pci_dev`.
+ HeaderType::from(unsafe { (*self.as_raw()).hdr_type })
+ }
+
/// Returns the PCI bus device/function.
#[inline]
pub fn dev_id(&self) -> u16 {
--git a/rust/kernel/pci/header.rs b/rust/kernel/pci/header.rs
new file mode 100644
index 000000000..032efeb16
--- /dev/null
+++ b/rust/kernel/pci/header.rs
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! PCI device header type definitions.
+//!
+//! This module contains PCI header type definitions
+
+use kernel::bindings;
+
+/// PCI device header types.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum HeaderType {
+ /// Normal PCI device header (Type 0)
+ NormalDevice,
+ /// PCI-to-PCI bridge header (Type 1)
+ PciToPciBridge,
+ /// CardBus bridge header (Type 2)
+ CardBusBridge,
+ /// Unknown or unsupported header type
+ Unknown,
+}
+
+impl From<u8> for HeaderType {
+ fn from(value: u8) -> Self {
+ match u32::from(value) & bindings::PCI_HEADER_TYPE_MASK {
+ bindings::PCI_HEADER_TYPE_NORMAL => HeaderType::NormalDevice,
+ bindings::PCI_HEADER_TYPE_BRIDGE => HeaderType::PciToPciBridge,
+ bindings::PCI_HEADER_TYPE_CARDBUS => HeaderType::CardBusBridge,
+ _ => HeaderType::Unknown,
+ }
+ }
+}
---
base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da
change-id: 20260103-add-rust-pci-header-type-346249c1ec14
Best regards,
--
SeungJong Ha <engineer.jjhama@gmail.com>
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: pci: add HeaderType enum and header_type() helper
2026-01-03 14:38 [PATCH] rust: pci: add HeaderType enum and header_type() helper SeungJong Ha via B4 Relay
@ 2026-01-03 15:17 ` Danilo Krummrich
2026-01-03 15:39 ` 하승종
0 siblings, 1 reply; 6+ messages in thread
From: Danilo Krummrich @ 2026-01-03 15:17 UTC (permalink / raw)
To: SeungJong Ha via B4 Relay
Cc: engineer.jjhama, Bjorn Helgaas, Krzysztof Wilczyński,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
linux-kernel, linux-pci, rust-for-linux
On Sat Jan 3, 2026 at 3:38 PM CET, SeungJong Ha via B4 Relay wrote:
> This is my first patch to the Linux kernel, specifically targeting the
> Rust PCI subsystem.
Thanks for your contribution!
> This patch introduces the HeaderType enum to represent PCI configuration
> space header types (Normal and Bridge) and implements the header_type()
> method in the Device struct.
We usually do not add dead code in the kernel. Do you work on a user for this
API?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: pci: add HeaderType enum and header_type() helper
2026-01-03 15:17 ` Danilo Krummrich
@ 2026-01-03 15:39 ` 하승종
2026-01-04 12:31 ` Miguel Ojeda
2026-01-04 13:40 ` Danilo Krummrich
0 siblings, 2 replies; 6+ messages in thread
From: 하승종 @ 2026-01-03 15:39 UTC (permalink / raw)
To: Danilo Krummrich
Cc: SeungJong Ha via B4 Relay, Bjorn Helgaas,
Krzysztof Wilczyński, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, linux-kernel, linux-pci, rust-for-linux
2026년 1월 4일 (일) AM 12:17, Danilo Krummrich <dakr@kernel.org>님이 작성:
>
> On Sat Jan 3, 2026 at 3:38 PM CET, SeungJong Ha via B4 Relay wrote:
> > This is my first patch to the Linux kernel, specifically targeting the
> > Rust PCI subsystem.
>
> Thanks for your contribution!
>
> > This patch introduces the HeaderType enum to represent PCI configuration
> > space header types (Normal and Bridge) and implements the header_type()
> > method in the Device struct.
>
> We usually do not add dead code in the kernel. Do you work on a user for this
> API?
Hi Danilo, Thanks for your feedback.
Yes, I am currently developing a Rust-based driver for nvme and ixgbe devices,
which requires identifying the header type to check compatibility on
initialization.
I sent this patch first as it provides a foundational API for the PCI
abstraction.
Best regards, SeungJong Ha
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: pci: add HeaderType enum and header_type() helper
2026-01-03 15:39 ` 하승종
@ 2026-01-04 12:31 ` Miguel Ojeda
2026-01-04 13:40 ` Danilo Krummrich
1 sibling, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-01-04 12:31 UTC (permalink / raw)
To: 하승종
Cc: Danilo Krummrich, SeungJong Ha via B4 Relay, Bjorn Helgaas,
Krzysztof Wilczyński, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, linux-kernel, linux-pci, rust-for-linux
On Sat, Jan 3, 2026 at 4:39 PM 하승종 <engineer.jjhama@gmail.com> wrote:
>
> Yes, I am currently developing a Rust-based driver for nvme and ixgbe devices,
> which requires identifying the header type to check compatibility on
> initialization.
> I sent this patch first as it provides a foundational API for the PCI
> abstraction.
In those cases it is usually a good idea to show the initial user of
the API, even if as an RFC patch, typically as a final patch in a
series.
Even then, landing the abstractions usually need to wait for the
concrete user to be ready to land, depending on what Danilo et al.
decide.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: pci: add HeaderType enum and header_type() helper
2026-01-03 15:39 ` 하승종
2026-01-04 12:31 ` Miguel Ojeda
@ 2026-01-04 13:40 ` Danilo Krummrich
2026-01-04 14:23 ` 하승종
1 sibling, 1 reply; 6+ messages in thread
From: Danilo Krummrich @ 2026-01-04 13:40 UTC (permalink / raw)
To: 하승종
Cc: SeungJong Ha via B4 Relay, Bjorn Helgaas,
Krzysztof Wilczyński, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, linux-kernel, linux-pci, rust-for-linux
On Sat Jan 3, 2026 at 4:39 PM CET, 하승종 wrote:
> 2026년 1월 4일 (일) AM 12:17, Danilo Krummrich <dakr@kernel.org>님이 작성:
>>
>> On Sat Jan 3, 2026 at 3:38 PM CET, SeungJong Ha via B4 Relay wrote:
>> > This is my first patch to the Linux kernel, specifically targeting the
>> > Rust PCI subsystem.
>>
>> Thanks for your contribution!
>>
>> > This patch introduces the HeaderType enum to represent PCI configuration
>> > space header types (Normal and Bridge) and implements the header_type()
>> > method in the Device struct.
>>
>> We usually do not add dead code in the kernel. Do you work on a user for this
>> API?
>
> Hi Danilo, Thanks for your feedback.
>
> Yes, I am currently developing a Rust-based driver for nvme and ixgbe devices,
> which requires identifying the header type to check compatibility on
> initialization.
> I sent this patch first as it provides a foundational API for the PCI
> abstraction.
As Miguel also pointed out in his reply, I'd like to see a patch series with the
driver as an RFC patch.
If it is working, not too far from an "upstreamable" state and the subsystem
maintainers of the driver's target subsystem are indicating willingness to
eventually take the driver, I'm happy to go ahead and merge any dependencies.
- Danilo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: pci: add HeaderType enum and header_type() helper
2026-01-04 13:40 ` Danilo Krummrich
@ 2026-01-04 14:23 ` 하승종
0 siblings, 0 replies; 6+ messages in thread
From: 하승종 @ 2026-01-04 14:23 UTC (permalink / raw)
To: Danilo Krummrich
Cc: SeungJong Ha via B4 Relay, Bjorn Helgaas,
Krzysztof Wilczyński, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, linux-kernel, linux-pci, rust-for-linux
2026년 1월 4일 (일) PM 10:40, Danilo Krummrich <dakr@kernel.org>님이 작성:
>
> On Sat Jan 3, 2026 at 4:39 PM CET, 하승종 wrote:
> > 2026년 1월 4일 (일) AM 12:17, Danilo Krummrich <dakr@kernel.org>님이 작성:
> >>
> >> On Sat Jan 3, 2026 at 3:38 PM CET, SeungJong Ha via B4 Relay wrote:
> >> > This is my first patch to the Linux kernel, specifically targeting the
> >> > Rust PCI subsystem.
> >>
> >> Thanks for your contribution!
> >>
> >> > This patch introduces the HeaderType enum to represent PCI configuration
> >> > space header types (Normal and Bridge) and implements the header_type()
> >> > method in the Device struct.
> >>
> >> We usually do not add dead code in the kernel. Do you work on a user for this
> >> API?
> >
> > Hi Danilo, Thanks for your feedback.
> >
> > Yes, I am currently developing a Rust-based driver for nvme and ixgbe devices,
> > which requires identifying the header type to check compatibility on
> > initialization.
> > I sent this patch first as it provides a foundational API for the PCI
> > abstraction.
>
> As Miguel also pointed out in his reply, I'd like to see a patch series with the
> driver as an RFC patch.
>
> If it is working, not too far from an "upstreamable" state and the subsystem
> maintainers of the driver's target subsystem are indicating willingness to
> eventually take the driver, I'm happy to go ahead and merge any dependencies.
>
> - Danilo
Hi Danilo, Muguel!
Thank you for the encouragement and the clear guidance.
Since my current driver implementation is still in a very early stage
and not yet
ready for public review, I will focus on maturing the codebase first.
I will come back with an RFC patch series that includes both the PCI
abstractions
and the driver once it reaches a more stable state.
Thank you again for your kind feedback and for guiding me through my first patch
submission.
- SeungJong Ha
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-01-04 14:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-03 14:38 [PATCH] rust: pci: add HeaderType enum and header_type() helper SeungJong Ha via B4 Relay
2026-01-03 15:17 ` Danilo Krummrich
2026-01-03 15:39 ` 하승종
2026-01-04 12:31 ` Miguel Ojeda
2026-01-04 13:40 ` Danilo Krummrich
2026-01-04 14:23 ` 하승종
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox