platform_drv: support enforced 1:1 DMA mapping

Follow up commit of

"platfrom_drv: map DMA memory non-natural when iommu is present"

Issue #4665
This commit is contained in:
Alexander Boettcher 2022-11-22 13:58:31 +01:00 committed by Christian Helmuth
parent b596db3eed
commit a91467f3a8

View File

@ -71,28 +71,26 @@ addr_t Device_pd::_dma_addr(addr_t const phys_addr,
size_t const size, size_t const size,
bool const force_phys_addr) bool const force_phys_addr)
{ {
using Range_ok = Range_allocator::Range_ok;
using Alloc_error = Allocator::Alloc_error; using Alloc_error = Allocator::Alloc_error;
if (!_iommu) return phys_addr; if (!_iommu) return phys_addr;
/* /*
* 1:1 mapping (remove from DMA memory allocator) * 1:1 mapping (allocate at specified range from DMA memory allocator)
*/ */
if (force_phys_addr) { if (force_phys_addr) {
_dma_alloc.remove_range(phys_addr, size).with_result( return _dma_alloc.alloc_addr(size, phys_addr).convert<addr_t>(
[&] (Range_ok) -> addr_t { return phys_addr; }, [&] (void *) -> addr_t { return phys_addr; },
[&] (Alloc_error err) -> addr_t { [&] (Alloc_error err) -> addr_t {
switch (err) { switch (err) {
case Alloc_error::OUT_OF_RAM: throw Out_of_ram(); case Alloc_error::OUT_OF_RAM: throw Out_of_ram();
case Alloc_error::OUT_OF_CAPS: throw Out_of_caps(); case Alloc_error::OUT_OF_CAPS: throw Out_of_caps();
case Alloc_error::DENIED: case Alloc_error::DENIED:
error("Could not free DMA range ", error("Could not attach DMA range at ",
Hex(phys_addr), " - ", Hex(phys_addr + size - 1), Hex_range(phys_addr, size), " (error: ", err, ")");
" (error: ", err, ")");
break; break;
} }
return 0; return 0UL;
}); });
} }