Skip to content

Commit 6901e11

Browse files
committed
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
1 parent be7b241 commit 6901e11

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

uefi-raw/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Added
44
- Added `AllocateType`.
5+
- Added `PciRootBridgeIoProtocol`.
56

67

78
# uefi-raw - 0.11.0 (2025-05-04)

uefi-raw/src/protocol/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod memory_protection;
2121
pub mod misc;
2222
pub mod network;
2323
pub mod nvme;
24+
pub mod pci;
2425
pub mod rng;
2526
pub mod scsi;
2627
pub mod shell_params;

uefi-raw/src/protocol/pci/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
pub mod root_bridge;
+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use crate::table::boot::{AllocateType, MemoryType};
4+
use crate::{Handle, PhysicalAddress, Status};
5+
use core::ffi::c_void;
6+
use uguid::{guid, Guid};
7+
8+
newtype_enum! {
9+
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH` enum.
10+
pub enum PciRootBridgeIoProtocolWidth: u32 => {
11+
UINT8 = 0,
12+
UINT16 = 1,
13+
UINT32 = 2,
14+
UINT64 = 3,
15+
FIFO_UINT8 = 4,
16+
FIFO_UINT16 = 5,
17+
FIFO_UINT32 = 6,
18+
FIFO_UINT64 = 7,
19+
FILL_UINT8 = 8,
20+
FILL_UINT16 = 9,
21+
FILL_UINT32 = 10,
22+
FILL_UINT64 = 11,
23+
MAXIMUM = 12,
24+
}
25+
}
26+
27+
newtype_enum! {
28+
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION` enum.
29+
pub enum PciRootBridgeIoProtocolOperation: u32 => {
30+
BUS_MASTER_READ = 0,
31+
BUS_MASTER_WRITE = 1,
32+
BUS_MASTER_COMMON_BUFFER = 2,
33+
BUS_MASTER_READ64 = 3,
34+
BUS_MASTER_WRITE64 = 4,
35+
BUS_MASTER_COMMON_BUFFER64 = 5,
36+
MAXIMUM = 6,
37+
}
38+
}
39+
40+
#[repr(C, packed)]
41+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42+
pub struct PciIoAddress {
43+
pub reg: u8,
44+
pub fun: u8,
45+
pub dev: u8,
46+
pub bus: u8,
47+
pub ext_reg: u32,
48+
}
49+
50+
impl PciIoAddress {
51+
#[must_use]
52+
pub const fn new(bus: u8, dev: u8, fun: u8) -> Self {
53+
Self {
54+
bus,
55+
dev,
56+
fun,
57+
reg: 0,
58+
ext_reg: 0,
59+
}
60+
}
61+
62+
#[must_use]
63+
pub const fn with_register(&self, reg: u8) -> Self {
64+
let mut addr = *self;
65+
addr.reg = reg;
66+
addr.ext_reg = 0;
67+
addr
68+
}
69+
70+
#[must_use]
71+
pub const fn with_extended_register(&self, ext_reg: u32) -> Self {
72+
let mut addr = *self;
73+
addr.reg = 0;
74+
addr.ext_reg = ext_reg;
75+
addr
76+
}
77+
}
78+
79+
impl Into<u64> for PciIoAddress {
80+
fn into(self) -> u64 {
81+
unsafe { core::mem::transmute(self) }
82+
}
83+
}
84+
85+
#[derive(Debug)]
86+
#[repr(C)]
87+
pub struct PciRootBridgeIoAccess {
88+
pub read: unsafe extern "efiapi" fn(
89+
this: *mut PciRootBridgeIoProtocol,
90+
width: PciRootBridgeIoProtocolWidth,
91+
address: u64,
92+
count: usize,
93+
buffer: *mut c_void,
94+
) -> Status,
95+
pub write: unsafe extern "efiapi" fn(
96+
this: *mut Self,
97+
width: PciRootBridgeIoProtocolWidth,
98+
address: u64,
99+
count: usize,
100+
buffer: *const c_void,
101+
) -> Status,
102+
}
103+
104+
#[derive(Debug)]
105+
#[repr(C)]
106+
pub struct PciRootBridgeIoProtocol {
107+
pub parent_handle: Handle,
108+
pub poll_mem: unsafe extern "efiapi" fn(
109+
this: *mut Self,
110+
width: PciRootBridgeIoProtocolWidth,
111+
address: u64,
112+
mask: u64,
113+
value: u64,
114+
delay: u64,
115+
result: *mut u64,
116+
) -> Status,
117+
pub poll_io: unsafe extern "efiapi" fn(
118+
this: *mut Self,
119+
width: PciRootBridgeIoProtocolWidth,
120+
address: u64,
121+
mask: u64,
122+
value: u64,
123+
delay: u64,
124+
result: *mut u64,
125+
) -> Status,
126+
pub mem: PciRootBridgeIoAccess,
127+
pub io: PciRootBridgeIoAccess,
128+
pub pci: PciRootBridgeIoAccess,
129+
pub copy_mem: unsafe extern "efiapi" fn(
130+
this: *mut Self,
131+
width: PciRootBridgeIoProtocolWidth,
132+
dest_addr: u64,
133+
src_addr: u64,
134+
count: usize,
135+
) -> Status,
136+
pub map: unsafe extern "efiapi" fn(
137+
this: *const Self,
138+
operation: PciRootBridgeIoProtocolOperation,
139+
host_addr: *const c_void,
140+
num_bytes: *mut usize,
141+
device_addr: *mut PhysicalAddress,
142+
mapping: *mut *mut c_void,
143+
) -> Status,
144+
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *const c_void) -> Status,
145+
pub allocate_buffer: unsafe extern "efiapi" fn(
146+
this: *const Self,
147+
alloc_ty: AllocateType,
148+
memory_ty: MemoryType,
149+
pages: usize,
150+
host_addr: *mut *const c_void,
151+
attributes: u64,
152+
) -> Status,
153+
pub free_buffer: unsafe extern "efiapi" fn(
154+
this: *const Self,
155+
pages: usize,
156+
host_addr: *const c_void,
157+
) -> Status,
158+
pub flush: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
159+
pub get_attributes: unsafe extern "efiapi" fn(
160+
this: *const Self,
161+
supports: *mut u64,
162+
attributes: *mut u64,
163+
) -> Status,
164+
pub set_attributes: unsafe extern "efiapi" fn(
165+
this: *mut Self,
166+
attributes: u64,
167+
resource_base: *mut u64,
168+
resource_length: *mut u64,
169+
) -> Status,
170+
pub configuration:
171+
unsafe extern "efiapi" fn(this: *const Self, resources: *mut *const c_void) -> Status,
172+
pub segment_number: u32,
173+
}
174+
175+
impl PciRootBridgeIoProtocol {
176+
pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d");
177+
}

0 commit comments

Comments
 (0)