[dma] Modify DMA API to simplify calculation of medial addresses

Redefine the value stored within a DMA mapping to be the offset
between physical addresses and DMA addresses within the mapped region.

Provide a dma() wrapper function to calculate the DMA address for any
pointer within a mapped region, thereby simplifying the use cases when
a device needs to be given addresses other than the region start
address.

On a platform using the "flat" DMA implementation the DMA offset for
any mapped region is always zero, with the result that dma_map() can
be optimised away completely and dma() reduces to a straightforward
call to virt_to_phys().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2020-11-25 15:52:00 +00:00
parent 24ef743778
commit cf12a41703
7 changed files with 100 additions and 58 deletions

View File

@@ -335,7 +335,7 @@ static int efipci_dma_map ( struct dma_device *dma, physaddr_t addr, size_t len,
int rc;
/* Sanity check */
assert ( map->addr == 0 );
assert ( map->offset == 0 );
assert ( map->token == NULL );
/* Determine operation */
@@ -374,7 +374,7 @@ static int efipci_dma_map ( struct dma_device *dma, physaddr_t addr, size_t len,
}
/* Populate mapping */
map->addr = bus;
map->offset = ( bus - addr );
map->token = mapping;
/* Increment mapping count (for debugging) */
@@ -408,7 +408,7 @@ static void efipci_dma_unmap ( struct dma_device *dma,
pci_io->Unmap ( pci_io, map->token );
/* Clear mapping */
map->addr = 0;
map->offset = 0;
map->token = NULL;
/* Decrement mapping count (for debugging) */