Skip to content

Feat: IoMmu protocol #1728

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Feat: IoMmu protocol #1728

wants to merge 1 commit into from

Conversation

PelleKrab
Copy link

This PR adds the IoMmu Protocol to uefi-rs, enabling easy DMA (Direct Memory Access) for devices. This is a draft to get some initial feedback before writing uefi-rs tests. It is already working in my internal project. The main areas I would like feedback on are:

  • Mapping and DMA Buffer Types: Is this too much abstraction? Should we simplify it by requiring the developer to manually call unmap() and free_buffer()?
  • Should free_buffer_raw() and unmap_raw() be made public?
  • Repository Organization: Is the general organization within the repo appropriate?

General Implementation:

// Allocate DMA buffer
let sz = some_buffer.len();
let page_num = bytes_to_pages(sz);
let mut host_buffer = iommu.allocate_buffer(
    MemoryType::BOOT_SERVICES_DATA,
    page_num,
    EdkiiIommuAttribute::MEMORY_CACHED,
)?;

// Map buffer for DMA
let (device_addr, mapping, wrt_size) = iommu.map(
    EdkiiIommuOperation::BUS_MASTER_COMMON_BUFFER,
    &host_buffer,
    size,
)?;

// Give permissions to the specified device 
iommu.set_attribute(some_device_handle, &mapping, EdkiiIommuAccess::READ)?;

// Copy firmware to DMA buffer
let dma_buf = host_buffer.deref_mut();
if sz > wrt_size {
    return Status::BUFFER_TOO_SMALL;
}
dma_buf[..sz].copy_from_slice(&some_buffer[..sz]);

// Notify the Device and pass the `device_addr`

ref:
#1723

@nicholasbishop
Copy link
Member

Thanks for working on this :) I haven't had a chance to look at the uefi wrapper in detail yet, but overall it looks reasonable. Could you split the uefi-raw part out to a separate PR? That should be straightforward to review and merge in isolation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants