Skip to content

Commit fb53dc6

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

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-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
@@ -20,6 +20,7 @@ pub mod media;
2020
pub mod memory_protection;
2121
pub mod misc;
2222
pub mod network;
23+
pub mod pci;
2324
pub mod nvme;
2425
pub mod rng;
2526
pub mod scsi;

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;
+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use crate::{
4+
table::boot::{AllocateType, MemoryType},
5+
Handle, PhysicalAddress, Status,
6+
};
7+
use core::ffi::c_void;
8+
use uguid::{guid, Guid};
9+
10+
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH` enum.
11+
#[repr(u32)]
12+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13+
pub enum PciRootBridgeIoProtocolWidth {
14+
Uint8 = 0,
15+
Uint16 = 1,
16+
Uint32 = 2,
17+
Uint64 = 3,
18+
FifoUint8 = 4,
19+
FifoUint16 = 5,
20+
FifoUint32 = 6,
21+
FifoUint64 = 7,
22+
FillUint8 = 8,
23+
FillUint16 = 9,
24+
FillUint32 = 10,
25+
FillUint64 = 11,
26+
Maximum = 12,
27+
}
28+
29+
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION` enum.
30+
#[repr(u32)]
31+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32+
pub enum PciRootBridgeIoProtocolOperation {
33+
BusMasterRead = 0,
34+
BusMasterWrite = 1,
35+
BusMasterCommonBuffer = 2,
36+
BusMasterRead64 = 3,
37+
BusMasterWrite64 = 4,
38+
BusMasterCommonBuffer64 = 5,
39+
Maximum = 6,
40+
}
41+
42+
#[derive(Debug)]
43+
#[repr(C)]
44+
pub struct PciRootBridgeIoAccess {
45+
pub read: unsafe extern "efiapi" fn(
46+
this: *const PciRootBridgeIoProtocol,
47+
width: PciRootBridgeIoProtocolWidth,
48+
address: u64,
49+
count: usize,
50+
buffer: *mut c_void,
51+
) -> Status,
52+
pub write: unsafe extern "efiapi" fn(
53+
this: *const Self,
54+
width: PciRootBridgeIoProtocolWidth,
55+
address: u64,
56+
count: usize,
57+
buffer: *const c_void,
58+
) -> Status,
59+
}
60+
61+
#[derive(Debug)]
62+
#[repr(C)]
63+
pub struct PciRootBridgeIoProtocol {
64+
pub parent_handle: Handle,
65+
pub poll_mem: unsafe extern "efiapi" fn(
66+
this: *const Self,
67+
width: PciRootBridgeIoProtocolWidth,
68+
address: u64,
69+
mask: u64,
70+
value: u64,
71+
delay: u64,
72+
result: *mut u64,
73+
) -> Status,
74+
pub poll_io: unsafe extern "efiapi" fn(
75+
this: *const Self,
76+
width: PciRootBridgeIoProtocolWidth,
77+
address: u64,
78+
mask: u64,
79+
value: u64,
80+
delay: u64,
81+
result: *mut u64,
82+
) -> Status,
83+
pub mem: PciRootBridgeIoAccess,
84+
pub io: PciRootBridgeIoAccess,
85+
pub pci: PciRootBridgeIoAccess,
86+
pub copy_mem: unsafe extern "efiapi" fn(
87+
this: *const Self,
88+
width: PciRootBridgeIoProtocolWidth,
89+
dest_addr: u64,
90+
src_addr: u64,
91+
count: usize,
92+
) -> Status,
93+
pub map: unsafe extern "efiapi" fn(
94+
this: *const Self,
95+
operation: PciRootBridgeIoProtocolOperation,
96+
host_addr: *const c_void,
97+
num_bytes: *mut usize,
98+
device_addr: *mut PhysicalAddress,
99+
mapping: *mut *mut c_void,
100+
) -> Status,
101+
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *const c_void) -> Status,
102+
pub allocate_buffer: unsafe extern "efiapi" fn(
103+
this: *const Self,
104+
alloc_ty: AllocateType,
105+
memory_ty: MemoryType,
106+
pages: usize,
107+
host_addr: *mut *const c_void,
108+
attributes: u64,
109+
) -> Status,
110+
pub free_buffer: unsafe extern "efiapi" fn(
111+
this: *const Self,
112+
pages: usize,
113+
host_addr: *const c_void,
114+
) -> Status,
115+
pub flush: unsafe extern "efiapi" fn(this: *const Self) -> Status,
116+
pub get_attributes: unsafe extern "efiapi" fn(
117+
this: *const Self,
118+
supports: *mut u64,
119+
attributes: *mut u64,
120+
) -> Status,
121+
pub set_attributes: unsafe extern "efiapi" fn(
122+
this: *const Self,
123+
attributes: u64,
124+
resource_base: *mut u64,
125+
resource_length: *mut u64,
126+
) -> Status,
127+
pub configuration:
128+
unsafe extern "efiapi" fn(this: *const Self, resources: *mut *const c_void) -> Status,
129+
pub segment_number: u32,
130+
}
131+
132+
impl PciRootBridgeIoProtocol {
133+
pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d");
134+
}

0 commit comments

Comments
 (0)