Skip to main content

uefi_raw/protocol/pci/
root_bridge.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use crate::table::boot::{AllocateType, MemoryType};
4use crate::{Handle, PhysicalAddress, Status, newtype_enum};
5use core::ffi::c_void;
6use uguid::{Guid, guid};
7
8newtype_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
27newtype_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)]
42pub 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)]
61pub 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
130impl PciRootBridgeIoProtocol {
131    pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d");
132}