Skip to content

Commit 45b4059

Browse files
committed
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
1 parent a6956a7 commit 45b4059

File tree

4 files changed

+176
-0
lines changed

4 files changed

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

0 commit comments

Comments
 (0)