Skip to content

Commit 497dbf1

Browse files
committed
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
1 parent be7b241 commit 497dbf1

File tree

4 files changed

+186
-0
lines changed

4 files changed

+186
-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;
+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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+
/// Structure representing a PCI Address for Pci.Read() and Pci.Write()
41+
#[repr(C, packed)]
42+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43+
pub struct PciIoAddress {
44+
pub reg: u8,
45+
pub fun: u8,
46+
pub dev: u8,
47+
pub bus: u8,
48+
pub ext_reg: u32,
49+
}
50+
51+
impl PciIoAddress {
52+
/// Create address pointing to the device identified by `bus`, `dev` and `fun` ids.
53+
#[must_use]
54+
pub const fn new(bus: u8, dev: u8, fun: u8) -> Self {
55+
Self {
56+
bus,
57+
dev,
58+
fun,
59+
reg: 0,
60+
ext_reg: 0,
61+
}
62+
}
63+
64+
/// Configure the **byte**-offset of the register to access.
65+
#[must_use]
66+
pub const fn with_register(&self, reg: u8) -> Self {
67+
let mut addr = *self;
68+
addr.reg = reg;
69+
addr.ext_reg = 0;
70+
addr
71+
}
72+
73+
/// Configure the **byte**-offset of the extended register to access.
74+
#[must_use]
75+
pub const fn with_extended_register(&self, ext_reg: u32) -> Self {
76+
let mut addr = *self;
77+
addr.reg = 0;
78+
addr.ext_reg = ext_reg;
79+
addr
80+
}
81+
}
82+
83+
impl From<PciIoAddress> for u64 {
84+
fn from(value: PciIoAddress) -> Self {
85+
unsafe { core::mem::transmute(value) }
86+
}
87+
}
88+
89+
#[derive(Debug)]
90+
#[repr(C)]
91+
pub struct PciRootBridgeIoAccess {
92+
pub read: unsafe extern "efiapi" fn(
93+
this: *mut PciRootBridgeIoProtocol,
94+
width: PciRootBridgeIoProtocolWidth,
95+
address: u64,
96+
count: usize,
97+
buffer: *mut c_void,
98+
) -> Status,
99+
pub write: unsafe extern "efiapi" fn(
100+
this: *mut PciRootBridgeIoProtocol,
101+
width: PciRootBridgeIoProtocolWidth,
102+
address: u64,
103+
count: usize,
104+
buffer: *const c_void,
105+
) -> Status,
106+
}
107+
108+
#[derive(Debug)]
109+
#[repr(C)]
110+
pub struct PciRootBridgeIoProtocol {
111+
pub parent_handle: Handle,
112+
pub poll_mem: unsafe extern "efiapi" fn(
113+
this: *mut Self,
114+
width: PciRootBridgeIoProtocolWidth,
115+
address: u64,
116+
mask: u64,
117+
value: u64,
118+
delay: u64,
119+
result: *mut u64,
120+
) -> Status,
121+
pub poll_io: unsafe extern "efiapi" fn(
122+
this: *mut Self,
123+
width: PciRootBridgeIoProtocolWidth,
124+
address: u64,
125+
mask: u64,
126+
value: u64,
127+
delay: u64,
128+
result: *mut u64,
129+
) -> Status,
130+
pub mem: PciRootBridgeIoAccess,
131+
pub io: PciRootBridgeIoAccess,
132+
pub pci: PciRootBridgeIoAccess,
133+
pub copy_mem: unsafe extern "efiapi" fn(
134+
this: *mut Self,
135+
width: PciRootBridgeIoProtocolWidth,
136+
dest_addr: u64,
137+
src_addr: u64,
138+
count: usize,
139+
) -> Status,
140+
pub map: unsafe extern "efiapi" fn(
141+
this: *const Self,
142+
operation: PciRootBridgeIoProtocolOperation,
143+
host_addr: *const c_void,
144+
num_bytes: *mut usize,
145+
device_addr: *mut PhysicalAddress,
146+
mapping: *mut *mut c_void,
147+
) -> Status,
148+
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *const c_void) -> Status,
149+
pub allocate_buffer: unsafe extern "efiapi" fn(
150+
this: *const Self,
151+
alloc_ty: AllocateType,
152+
memory_ty: MemoryType,
153+
pages: usize,
154+
host_addr: *mut *const c_void,
155+
attributes: u64,
156+
) -> Status,
157+
pub free_buffer: unsafe extern "efiapi" fn(
158+
this: *const Self,
159+
pages: usize,
160+
host_addr: *const c_void,
161+
) -> Status,
162+
pub flush: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
163+
pub get_attributes: unsafe extern "efiapi" fn(
164+
this: *const Self,
165+
supports: *mut u64,
166+
attributes: *mut u64,
167+
) -> Status,
168+
pub set_attributes: unsafe extern "efiapi" fn(
169+
this: *mut Self,
170+
attributes: u64,
171+
resource_base: *mut u64,
172+
resource_length: *mut u64,
173+
) -> Status,
174+
pub configuration:
175+
unsafe extern "efiapi" fn(this: *const Self, resources: *mut *const c_void) -> Status,
176+
pub segment_number: u32,
177+
}
178+
179+
impl PciRootBridgeIoProtocol {
180+
pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d");
181+
}

0 commit comments

Comments
 (0)