Skip to content

Commit 1576b41

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

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-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;
+132
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+
/// 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+
#[derive(Debug)]
41+
#[repr(C)]
42+
pub struct PciRootBridgeIoAccess {
43+
pub read: unsafe extern "efiapi" fn(
44+
this: *const 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: *const Self,
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: *const 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: *const 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: *const 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: *const 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: *const 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)