hardware 0.0.9

A no_std bare-metal hardware abstraction layer — all port I/O, memory and swap allocations are guarded at runtime. Do not consider this dependency stable before x.1.x
Documentation
use crate::dma::buffer::DmaBuffer;
use crate::iommu::controller;

pub struct GpuAllocator;

impl GpuAllocator {
    pub fn alloc_framebuffer(size: usize, align: usize) -> Option<DmaBuffer> {
        DmaBuffer::new(size, align)
    }

    pub fn map_for_device(buf: &DmaBuffer, align: usize) -> Option<usize> {
        if let Some(ctrl) = controller::get() {
            ctrl.map_dma_buffer(buf, align)
        } else {
            Some(buf.phys_addr())
        }
    }

    pub fn unmap_iova(iova: usize) {
        let ok = crate::dma::engine::DmaEngine::unmap_iova(iova);
        debug_assert!(ok);
    }
}