Skip to content

Commit 397aafc

Browse files
committed
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
1 parent fc70683 commit 397aafc

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

uefi-raw/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Added `Usb2HostControllerProtocol`.
2020
- Added `DevicePathProtocol::length()` properly constructing the `u16` value
2121
- Added `AllocateType`.
22+
- Added `PciRootBridgeIoProtocol`.
2223

2324
## Changed
2425
- `DevicePathProtocol` now derives

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;
+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH` enum.
9+
#[repr(u32)]
10+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11+
pub enum PciRootBridgeIoProtocolWidth {
12+
Uint8 = 0,
13+
Uint16 = 1,
14+
Uint32 = 2,
15+
Uint64 = 3,
16+
FifoUint8 = 4,
17+
FifoUint16 = 5,
18+
FifoUint32 = 6,
19+
FifoUint64 = 7,
20+
FillUint8 = 8,
21+
FillUint16 = 9,
22+
FillUint32 = 10,
23+
FillUint64 = 11,
24+
Maximum = 12,
25+
}
26+
27+
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION` enum.
28+
#[repr(u32)]
29+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30+
pub enum PciRootBridgeIoProtocolOperation {
31+
BusMasterRead = 0,
32+
BusMasterWrite = 1,
33+
BusMasterCommonBuffer = 2,
34+
BusMasterRead64 = 3,
35+
BusMasterWrite64 = 4,
36+
BusMasterCommonBuffer64 = 5,
37+
Maximum = 6,
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 fn with_register(bus: u8, dev: u8, fun: u8, reg: u8) -> Self {
53+
Self {
54+
ext_reg: 0,
55+
bus,
56+
dev,
57+
fun,
58+
reg,
59+
}
60+
}
61+
#[must_use]
62+
pub fn with_extended_register(bus: u8, dev: u8, fun: u8, ext_reg: u32) -> Self {
63+
Self {
64+
ext_reg,
65+
bus,
66+
dev,
67+
fun,
68+
reg: 0,
69+
}
70+
}
71+
}
72+
73+
#[derive(Debug)]
74+
#[repr(C)]
75+
pub struct PciRootBridgeIoAccess<TAddr> {
76+
pub read: unsafe extern "efiapi" fn(
77+
this: *mut PciRootBridgeIoProtocol,
78+
width: PciRootBridgeIoProtocolWidth,
79+
address: TAddr,
80+
count: usize,
81+
buffer: *mut c_void,
82+
) -> Status,
83+
pub write: unsafe extern "efiapi" fn(
84+
this: *mut Self,
85+
width: PciRootBridgeIoProtocolWidth,
86+
address: TAddr,
87+
count: usize,
88+
buffer: *const c_void,
89+
) -> Status,
90+
}
91+
92+
#[derive(Debug)]
93+
#[repr(C)]
94+
pub struct PciRootBridgeIoProtocol {
95+
pub parent_handle: Handle,
96+
pub poll_mem: unsafe extern "efiapi" fn(
97+
this: *mut Self,
98+
width: PciRootBridgeIoProtocolWidth,
99+
address: u64,
100+
mask: u64,
101+
value: u64,
102+
delay: u64,
103+
result: *mut u64,
104+
) -> Status,
105+
pub poll_io: unsafe extern "efiapi" fn(
106+
this: *mut Self,
107+
width: PciRootBridgeIoProtocolWidth,
108+
address: u64,
109+
mask: u64,
110+
value: u64,
111+
delay: u64,
112+
result: *mut u64,
113+
) -> Status,
114+
pub mem: PciRootBridgeIoAccess<u64>,
115+
pub io: PciRootBridgeIoAccess<u64>,
116+
pub pci: PciRootBridgeIoAccess<PciIoAddress>,
117+
pub copy_mem: unsafe extern "efiapi" fn(
118+
this: *mut Self,
119+
width: PciRootBridgeIoProtocolWidth,
120+
dest_addr: u64,
121+
src_addr: u64,
122+
count: usize,
123+
) -> Status,
124+
pub map: unsafe extern "efiapi" fn(
125+
this: *const Self,
126+
operation: PciRootBridgeIoProtocolOperation,
127+
host_addr: *const c_void,
128+
num_bytes: *mut usize,
129+
device_addr: *mut PhysicalAddress,
130+
mapping: *mut *mut c_void,
131+
) -> Status,
132+
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *const c_void) -> Status,
133+
pub allocate_buffer: unsafe extern "efiapi" fn(
134+
this: *const Self,
135+
alloc_ty: AllocateType,
136+
memory_ty: MemoryType,
137+
pages: usize,
138+
host_addr: *mut *const c_void,
139+
attributes: u64,
140+
) -> Status,
141+
pub free_buffer: unsafe extern "efiapi" fn(
142+
this: *const Self,
143+
pages: usize,
144+
host_addr: *const c_void,
145+
) -> Status,
146+
pub flush: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
147+
pub get_attributes: unsafe extern "efiapi" fn(
148+
this: *const Self,
149+
supports: *mut u64,
150+
attributes: *mut u64,
151+
) -> Status,
152+
pub set_attributes: unsafe extern "efiapi" fn(
153+
this: *mut Self,
154+
attributes: u64,
155+
resource_base: *mut u64,
156+
resource_length: *mut u64,
157+
) -> Status,
158+
pub configuration:
159+
unsafe extern "efiapi" fn(this: *const Self, resources: *mut *const c_void) -> Status,
160+
pub segment_number: u32,
161+
}
162+
163+
impl PciRootBridgeIoProtocol {
164+
pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d");
165+
}

0 commit comments

Comments
 (0)