Skip to content

Commit 4fb59de

Browse files
committed
feat: IoMmu protocol
fix: set IoMmu data types to pub feat: uefi-raw IoMmu
1 parent a4b852f commit 4fb59de

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

uefi-raw/src/protocol/iommu.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use crate::{Guid, Handle, Status, guid, table::boot::MemoryType};
4+
use bitflags::bitflags;
5+
use core::ffi::c_void;
6+
7+
use crate::newtype_enum;
8+
9+
/// EDKII IOMMU Protocol GUID
10+
impl EdkiiIommuProtocol {
11+
pub const GUID: Guid = guid!("4e939de9-d948-4b0f-88ed-e6e1ce517c1e");
12+
}
13+
14+
#[derive(Debug)]
15+
#[repr(C)]
16+
pub struct EdkiiIommuProtocol {
17+
pub revision: u64,
18+
pub set_attribute: unsafe extern "efiapi" fn(
19+
this: &Self,
20+
device_handle: Handle,
21+
mapping: *mut c_void,
22+
iommu_access: u64,
23+
) -> Status,
24+
pub map: unsafe extern "efiapi" fn(
25+
this: &Self,
26+
operation: EdkiiIommuOperation,
27+
host_address: *mut c_void,
28+
number_of_bytes: *mut usize,
29+
device_address: *mut u64,
30+
mapping: *mut *mut c_void,
31+
) -> Status,
32+
pub unmap: unsafe extern "efiapi" fn(this: &Self, mapping: *mut c_void) -> Status,
33+
pub allocate_buffer: unsafe extern "efiapi" fn(
34+
this: &Self,
35+
allocate_type: u32,
36+
memory_type: MemoryType,
37+
pages: usize,
38+
host_address: *mut *mut c_void,
39+
attributes: u64,
40+
) -> Status,
41+
pub free_buffer:
42+
unsafe extern "efiapi" fn(this: &Self, pages: usize, host_address: *mut c_void) -> Status,
43+
}
44+
45+
newtype_enum! {
46+
/// IOMMU Operation for Map (matches EDKII_IOMMU_OPERATION)
47+
pub enum EdkiiIommuOperation: u32 => {
48+
/// A read operation from system memory by a bus master that is not capable of producing PCI dual address cycles.
49+
BUS_MASTER_READ = 0,
50+
/// A write operation to system memory by a bus master that is not capable of producing PCI dual address cycles.
51+
BUS_MASTER_WRITE = 1,
52+
/// Provides both read and write access to system memory by both the processor and a bus master that is not capable of producing PCI dual address cycles.
53+
BUS_MASTER_COMMON_BUFFER = 2,
54+
/// A read operation from system memory by a bus master that is capable of producing PCI dual address cycles.
55+
BUS_MASTER_READ64 = 3,
56+
/// A write operation to system memory by a bus master that is capable of producing PCI dual address cycles.
57+
BUS_MASTER_WRITE64 = 4,
58+
/// Provides both read and write access to system memory by both the processor and a bus master that is capable of producing PCI dual address cycles.
59+
BUS_MASTER_COMMON_BUFFER64 = 5,
60+
/// Maximum value (not a valid operation, for bounds checking)
61+
MAXIMUM = 6,
62+
}
63+
}
64+
65+
/// EDKII IOMMU protocol revision constant
66+
pub const EDKII_IOMMU_PROTOCOL_REVISION: u64 = 0x0001_0000;
67+
68+
bitflags! {
69+
/// EDKII IOMMU attribute flags
70+
#[derive(Default)]
71+
pub struct EdkiiIommuAttribute: u64 {
72+
/// Memory is write-combined
73+
const MEMORY_WRITE_COMBINE = 0x0080;
74+
/// Memory is cached
75+
const MEMORY_CACHED = 0x0800;
76+
/// Dual address cycle supported
77+
const DUAL_ADDRESS_CYCLE = 0x8000;
78+
}
79+
}
80+
81+
impl EdkiiIommuAttribute {
82+
/// Valid attributes for allocate_buffer
83+
pub const VALID_FOR_ALLOCATE_BUFFER: Self = Self::from_bits_truncate(
84+
Self::MEMORY_WRITE_COMBINE.bits()
85+
| Self::MEMORY_CACHED.bits()
86+
| Self::DUAL_ADDRESS_CYCLE.bits(),
87+
);
88+
89+
/// Invalid attributes for allocate_buffer (all bits except valid)
90+
pub const INVALID_FOR_ALLOCATE_BUFFER: Self =
91+
Self::from_bits_truncate(!Self::VALID_FOR_ALLOCATE_BUFFER.bits());
92+
}
93+
94+
bitflags! {
95+
/// EDKII IOMMU access flags for SetAttribute
96+
#[derive(Default)]
97+
pub struct EdkiiIommuAccess: u64 {
98+
/// Read access
99+
const READ = 0x1;
100+
/// Write access
101+
const WRITE = 0x2;
102+
}
103+
}

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod driver;
3232
pub mod file_system;
3333
pub mod firmware_volume;
3434
pub mod hii;
35+
pub mod iommu;
3536
pub mod loaded_image;
3637
pub mod media;
3738
pub mod memory_protection;

0 commit comments

Comments
 (0)