-
-
Notifications
You must be signed in to change notification settings - Fork 177
feat: uefi-raw
IoMmu Protocol Impl
#1732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use crate::table::boot::MemoryType; | ||
use crate::{Guid, Handle, Status, guid}; | ||
use bitflags::bitflags; | ||
use core::ffi::c_void; | ||
|
||
use crate::newtype_enum; | ||
|
||
/// EDKII IOMMU Protocol GUID | ||
impl EdkiiIommuProtocol { | ||
pub const GUID: Guid = guid!("4e939de9-d948-4b0f-88ed-e6e1ce517c1e"); | ||
} | ||
|
||
#[derive(Debug)] | ||
#[repr(C)] | ||
pub struct EdkiiIommuProtocol { | ||
pub revision: u64, | ||
pub set_attribute: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
device_handle: Handle, | ||
mapping: *mut c_void, | ||
iommu_access: u64, | ||
) -> Status, | ||
pub map: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
operation: EdkiiIommuOperation, | ||
host_address: *mut c_void, | ||
number_of_bytes: *mut usize, | ||
device_address: *mut u64, | ||
mapping: *mut *mut c_void, | ||
) -> Status, | ||
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *mut c_void) -> Status, | ||
pub allocate_buffer: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
allocate_type: u32, | ||
PelleKrab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
memory_type: MemoryType, | ||
pages: usize, | ||
host_address: *mut *mut c_void, | ||
attributes: u64, | ||
PelleKrab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> Status, | ||
pub free_buffer: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
pages: usize, | ||
host_address: *mut c_void, | ||
) -> Status, | ||
} | ||
|
||
newtype_enum! { | ||
/// IOMMU Operation for Map (matches EDKII_IOMMU_OPERATION) | ||
pub enum EdkiiIommuOperation: u32 => { | ||
/// A read operation from system memory by a bus master that is not capable of producing PCI dual address cycles. | ||
BUS_MASTER_READ = 0, | ||
/// A write operation to system memory by a bus master that is not capable of producing PCI dual address cycles. | ||
BUS_MASTER_WRITE = 1, | ||
/// 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. | ||
BUS_MASTER_COMMON_BUFFER = 2, | ||
/// A read operation from system memory by a bus master that is capable of producing PCI dual address cycles. | ||
BUS_MASTER_READ64 = 3, | ||
/// A write operation to system memory by a bus master that is capable of producing PCI dual address cycles. | ||
BUS_MASTER_WRITE64 = 4, | ||
/// 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. | ||
BUS_MASTER_COMMON_BUFFER64 = 5, | ||
/// Maximum value (not a valid operation, for bounds checking) | ||
MAXIMUM = 6, | ||
} | ||
} | ||
|
||
/// EDKII IOMMU protocol revision constant | ||
pub const EDKII_IOMMU_PROTOCOL_REVISION: u64 = 0x0001_0000; | ||
|
||
bitflags! { | ||
/// EDKII IOMMU attribute flags | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct EdkiiIommuAttribute: u64 { | ||
/// Memory is write-combined | ||
const MEMORY_WRITE_COMBINE = 0x0080; | ||
/// Memory is cached | ||
const MEMORY_CACHED = 0x0800; | ||
/// Dual address cycle supported | ||
const DUAL_ADDRESS_CYCLE = 0x8000; | ||
} | ||
} | ||
|
||
impl EdkiiIommuAttribute { | ||
/// Valid attributes for allocate_buffer | ||
pub const VALID_FOR_ALLOCATE_BUFFER: Self = Self::from_bits_truncate( | ||
Self::MEMORY_WRITE_COMBINE.bits() | ||
| Self::MEMORY_CACHED.bits() | ||
| Self::DUAL_ADDRESS_CYCLE.bits(), | ||
); | ||
|
||
/// Invalid attributes for allocate_buffer (all bits except valid) | ||
pub const INVALID_FOR_ALLOCATE_BUFFER: Self = | ||
Self::from_bits_truncate(!Self::VALID_FOR_ALLOCATE_BUFFER.bits()); | ||
} | ||
|
||
bitflags! { | ||
/// EDKII IOMMU access flags for SetAttribute | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct EdkiiIommuAccess: u64 { | ||
/// Read access | ||
const READ = 0x1; | ||
/// Write access | ||
const WRITE = 0x2; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.