Skip to content

Commit d70729b

Browse files
committed
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
1 parent 44a3bde commit d70729b

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
#[derive(Debug)]
41+
#[repr(C)]
42+
pub struct PciRootBridgeIoAccess {
43+
pub read: unsafe extern "efiapi" fn(
44+
this: *mut PciRootBridgeIoProtocol,
45+
width: PciRootBridgeIoProtocolWidth,
46+
address: u64,
47+
count: usize,
48+
buffer: *mut c_void,
49+
) -> Status,
50+
pub write: unsafe extern "efiapi" fn(
51+
this: *mut PciRootBridgeIoProtocol,
52+
width: PciRootBridgeIoProtocolWidth,
53+
address: u64,
54+
count: usize,
55+
buffer: *const c_void,
56+
) -> Status,
57+
}
58+
59+
#[derive(Debug)]
60+
#[repr(C)]
61+
pub struct PciRootBridgeIoProtocol {
62+
pub parent_handle: Handle,
63+
pub poll_mem: unsafe extern "efiapi" fn(
64+
this: *mut Self,
65+
width: PciRootBridgeIoProtocolWidth,
66+
address: u64,
67+
mask: u64,
68+
value: u64,
69+
delay: u64,
70+
result: *mut u64,
71+
) -> Status,
72+
pub poll_io: unsafe extern "efiapi" fn(
73+
this: *mut Self,
74+
width: PciRootBridgeIoProtocolWidth,
75+
address: u64,
76+
mask: u64,
77+
value: u64,
78+
delay: u64,
79+
result: *mut u64,
80+
) -> Status,
81+
pub mem: PciRootBridgeIoAccess,
82+
pub io: PciRootBridgeIoAccess,
83+
pub pci: PciRootBridgeIoAccess,
84+
pub copy_mem: unsafe extern "efiapi" fn(
85+
this: *mut Self,
86+
width: PciRootBridgeIoProtocolWidth,
87+
dest_addr: u64,
88+
src_addr: u64,
89+
count: usize,
90+
) -> Status,
91+
pub map: unsafe extern "efiapi" fn(
92+
this: *const Self,
93+
operation: PciRootBridgeIoProtocolOperation,
94+
host_addr: *const c_void,
95+
num_bytes: *mut usize,
96+
device_addr: *mut PhysicalAddress,
97+
mapping: *mut *mut c_void,
98+
) -> Status,
99+
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *const c_void) -> Status,
100+
pub allocate_buffer: unsafe extern "efiapi" fn(
101+
this: *const Self,
102+
alloc_ty: AllocateType,
103+
memory_ty: MemoryType,
104+
pages: usize,
105+
host_addr: *mut *const c_void,
106+
attributes: u64,
107+
) -> Status,
108+
pub free_buffer: unsafe extern "efiapi" fn(
109+
this: *const Self,
110+
pages: usize,
111+
host_addr: *const c_void,
112+
) -> Status,
113+
pub flush: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
114+
pub get_attributes: unsafe extern "efiapi" fn(
115+
this: *const Self,
116+
supports: *mut u64,
117+
attributes: *mut u64,
118+
) -> Status,
119+
pub set_attributes: unsafe extern "efiapi" fn(
120+
this: *mut Self,
121+
attributes: u64,
122+
resource_base: *mut u64,
123+
resource_length: *mut u64,
124+
) -> Status,
125+
pub configuration:
126+
unsafe extern "efiapi" fn(this: *const Self, resources: *mut *const c_void) -> Status,
127+
pub segment_number: u32,
128+
}
129+
130+
impl PciRootBridgeIoProtocol {
131+
pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d");
132+
}

0 commit comments

Comments
 (0)