Skip to content

Commit 463b849

Browse files
committed
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
1 parent fc70683 commit 463b849

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-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;
+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
pub fn with_register(bus: u8, dev: u8, fun: u8, reg: u8) -> Self {
52+
Self {
53+
ext_reg: 0,
54+
bus,
55+
dev,
56+
fun,
57+
reg,
58+
}
59+
}
60+
pub fn with_extended_register(bus: u8, dev: u8, fun: u8, ext_reg: u32) -> Self {
61+
Self {
62+
ext_reg,
63+
bus,
64+
dev,
65+
fun,
66+
reg: 0,
67+
}
68+
}
69+
}
70+
71+
#[derive(Debug)]
72+
#[repr(C)]
73+
pub struct PciRootBridgeIoAccess<TAddr> {
74+
pub read: unsafe extern "efiapi" fn(
75+
this: *const PciRootBridgeIoProtocol,
76+
width: PciRootBridgeIoProtocolWidth,
77+
address: TAddr,
78+
count: usize,
79+
buffer: *mut c_void,
80+
) -> Status,
81+
pub write: unsafe extern "efiapi" fn(
82+
this: *const Self,
83+
width: PciRootBridgeIoProtocolWidth,
84+
address: TAddr,
85+
count: usize,
86+
buffer: *const c_void,
87+
) -> Status,
88+
}
89+
90+
#[derive(Debug)]
91+
#[repr(C)]
92+
pub struct PciRootBridgeIoProtocol {
93+
pub parent_handle: Handle,
94+
pub poll_mem: unsafe extern "efiapi" fn(
95+
this: *const Self,
96+
width: PciRootBridgeIoProtocolWidth,
97+
address: u64,
98+
mask: u64,
99+
value: u64,
100+
delay: u64,
101+
result: *mut u64,
102+
) -> Status,
103+
pub poll_io: unsafe extern "efiapi" fn(
104+
this: *const Self,
105+
width: PciRootBridgeIoProtocolWidth,
106+
address: u64,
107+
mask: u64,
108+
value: u64,
109+
delay: u64,
110+
result: *mut u64,
111+
) -> Status,
112+
pub mem: PciRootBridgeIoAccess<u64>,
113+
pub io: PciRootBridgeIoAccess<u64>,
114+
pub pci: PciRootBridgeIoAccess<PciIoAddress>,
115+
pub copy_mem: unsafe extern "efiapi" fn(
116+
this: *const Self,
117+
width: PciRootBridgeIoProtocolWidth,
118+
dest_addr: u64,
119+
src_addr: u64,
120+
count: usize,
121+
) -> Status,
122+
pub map: unsafe extern "efiapi" fn(
123+
this: *const Self,
124+
operation: PciRootBridgeIoProtocolOperation,
125+
host_addr: *const c_void,
126+
num_bytes: *mut usize,
127+
device_addr: *mut PhysicalAddress,
128+
mapping: *mut *mut c_void,
129+
) -> Status,
130+
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *const c_void) -> Status,
131+
pub allocate_buffer: unsafe extern "efiapi" fn(
132+
this: *const Self,
133+
alloc_ty: AllocateType,
134+
memory_ty: MemoryType,
135+
pages: usize,
136+
host_addr: *mut *const c_void,
137+
attributes: u64,
138+
) -> Status,
139+
pub free_buffer: unsafe extern "efiapi" fn(
140+
this: *const Self,
141+
pages: usize,
142+
host_addr: *const c_void,
143+
) -> Status,
144+
pub flush: unsafe extern "efiapi" fn(this: *const Self) -> Status,
145+
pub get_attributes: unsafe extern "efiapi" fn(
146+
this: *const Self,
147+
supports: *mut u64,
148+
attributes: *mut u64,
149+
) -> Status,
150+
pub set_attributes: unsafe extern "efiapi" fn(
151+
this: *const Self,
152+
attributes: u64,
153+
resource_base: *mut u64,
154+
resource_length: *mut u64,
155+
) -> Status,
156+
pub configuration:
157+
unsafe extern "efiapi" fn(this: *const Self, resources: *mut *const c_void) -> Status,
158+
pub segment_number: u32,
159+
}
160+
161+
impl PciRootBridgeIoProtocol {
162+
pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d");
163+
}

0 commit comments

Comments
 (0)