Skip to content

Commit 6d8185f

Browse files
Merge pull request #1658 from seijikun/mr-pciroot
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
2 parents 78e4342 + d70729b commit 6d8185f

File tree

6 files changed

+154
-5
lines changed

6 files changed

+154
-5
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# uefi-raw - [Unreleased]
22

3+
## Added
4+
- Added `AllocateType`.
5+
- Added `PciRootBridgeIoProtocol`.
6+
37

48
# uefi-raw - 0.11.0 (2025-05-04)
59

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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;
Lines changed: 132 additions & 0 deletions
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+
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+
#[derive(Debug)]
41+
#[repr(C)]
42+
pub struct PciRootBridgeIoAccess {
43+
pub read: unsafe extern "efiapi" fn(
44+
this: *mut 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: *mut PciRootBridgeIoProtocol,
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: *mut 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: *mut 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: *mut 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: *mut 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: *mut 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+
}

uefi-raw/src/table/boot.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use bitflags::bitflags;
99
use core::ffi::c_void;
1010
use core::ops::RangeInclusive;
1111

12+
newtype_enum! {
13+
pub enum AllocateType: u32 => {
14+
ANY_PAGES = 0,
15+
MAX_ADDRESS = 1,
16+
ADDRESS = 2,
17+
MAX_ALLOCATE_TYPE = 3,
18+
}
19+
}
20+
1221
/// Table of pointers to all the boot services.
1322
#[derive(Debug)]
1423
#[repr(C)]
@@ -21,7 +30,7 @@ pub struct BootServices {
2130

2231
// Memory allocation functions
2332
pub allocate_pages: unsafe extern "efiapi" fn(
24-
alloc_ty: u32,
33+
alloc_ty: AllocateType,
2534
mem_ty: MemoryType,
2635
count: usize,
2736
addr: *mut PhysicalAddress,

uefi/src/boot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use core::ptr::{self, NonNull};
4545
use core::sync::atomic::{AtomicPtr, Ordering};
4646
use core::time::Duration;
4747
use core::{mem, slice};
48-
use uefi_raw::table::boot::{InterfaceType, TimerDelay};
48+
use uefi_raw::table::boot::{AllocateType as RawAllocateType, InterfaceType, TimerDelay};
4949
#[cfg(feature = "alloc")]
5050
use {alloc::vec::Vec, uefi::ResultExt};
5151

@@ -154,9 +154,9 @@ pub fn allocate_pages(
154154
let bt = unsafe { bt.as_ref() };
155155

156156
let (ty, initial_addr) = match allocation_type {
157-
AllocateType::AnyPages => (0, 0),
158-
AllocateType::MaxAddress(addr) => (1, addr),
159-
AllocateType::Address(addr) => (2, addr),
157+
AllocateType::AnyPages => (RawAllocateType::ANY_PAGES, 0),
158+
AllocateType::MaxAddress(addr) => (RawAllocateType::MAX_ADDRESS, addr),
159+
AllocateType::Address(addr) => (RawAllocateType::ADDRESS, addr),
160160
};
161161

162162
let mut addr1 = initial_addr;

0 commit comments

Comments
 (0)