From 22de0c4edf2fe1cdbca5e22c52c86a2289d04816 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 8 Jul 2025 12:38:05 +0100 Subject: [dma] Use virtual addresses for dma_map() Cache management operations must generally be performed on virtual addresses rather than physical addresses. Change the address parameter in dma_map() to be a virtual address, and make dma() the API-level primitive instead of dma_phys(). Signed-off-by: Michael Brown --- src/include/ipxe/dma.h | 42 +++++++++++++----------------------------- src/include/ipxe/iobuf.h | 3 +-- 2 files changed, 14 insertions(+), 31 deletions(-) (limited to 'src/include') diff --git a/src/include/ipxe/dma.h b/src/include/ipxe/dma.h index 6e5c43289..d450ef523 100644 --- a/src/include/ipxe/dma.h +++ b/src/include/ipxe/dma.h @@ -68,7 +68,7 @@ struct dma_operations { * @ret rc Return status code */ int ( * map ) ( struct dma_device *dma, struct dma_mapping *map, - physaddr_t addr, size_t len, int flags ); + void *addr, size_t len, int flags ); /** * Unmap buffer * @@ -178,8 +178,7 @@ struct dma_operations { */ static inline __always_inline int DMAAPI_INLINE ( flat, dma_map ) ( struct dma_device *dma, - struct dma_mapping *map, - physaddr_t addr __unused, + struct dma_mapping *map, void *addr __unused, size_t len __unused, int flags __unused ) { /* Increment mapping count (for debugging) */ @@ -319,32 +318,31 @@ DMAAPI_INLINE ( flat, dma_set_mask ) ( struct dma_device *dma __unused, } /** - * Get DMA address from physical address + * Get DMA address from virtual address * * @v map DMA mapping - * @v addr Physical address within the mapped region + * @v addr Address within the mapped region * @ret addr Device-side DMA address */ static inline __always_inline physaddr_t -DMAAPI_INLINE ( flat, dma_phys ) ( struct dma_mapping *map __unused, - physaddr_t addr ) { +DMAAPI_INLINE ( flat, dma ) ( struct dma_mapping *map __unused, void *addr ) { /* Use physical address as device address */ - return addr; + return virt_to_phys ( addr ); } /** - * Get DMA address from physical address + * Get DMA address from virtual address * * @v map DMA mapping - * @v addr Physical address within the mapped region + * @v addr Address within the mapped region * @ret addr Device-side DMA address */ static inline __always_inline physaddr_t -DMAAPI_INLINE ( op, dma_phys ) ( struct dma_mapping *map, physaddr_t addr ) { +DMAAPI_INLINE ( op, dma ) ( struct dma_mapping *map, void *addr ) { /* Adjust physical address using mapping offset */ - return ( addr + map->offset ); + return ( virt_to_phys ( addr ) + map->offset ); } /** @@ -358,7 +356,7 @@ DMAAPI_INLINE ( op, dma_phys ) ( struct dma_mapping *map, physaddr_t addr ) { * @ret rc Return status code */ int dma_map ( struct dma_device *dma, struct dma_mapping *map, - physaddr_t addr, size_t len, int flags ); + void *addr, size_t len, int flags ); /** * Unmap buffer @@ -417,28 +415,14 @@ void dma_ufree ( struct dma_mapping *map, void *addr, size_t len ); */ void dma_set_mask ( struct dma_device *dma, physaddr_t mask ); -/** - * Get DMA address from physical address - * - * @v map DMA mapping - * @v addr Physical address within the mapped region - * @ret addr Device-side DMA address - */ -physaddr_t dma_phys ( struct dma_mapping *map, physaddr_t addr ); - /** * Get DMA address from virtual address * * @v map DMA mapping - * @v addr Virtual address within the mapped region + * @v addr Address within the mapped region * @ret addr Device-side DMA address */ -static inline __always_inline physaddr_t dma ( struct dma_mapping *map, - void *addr ) { - - /* Get DMA address from corresponding physical address */ - return dma_phys ( map, virt_to_phys ( addr ) ); -} +physaddr_t dma ( struct dma_mapping *map, void *addr ); /** * Check if DMA unmapping is required diff --git a/src/include/ipxe/iobuf.h b/src/include/ipxe/iobuf.h index 2bdca6b5d..df8d0b854 100644 --- a/src/include/ipxe/iobuf.h +++ b/src/include/ipxe/iobuf.h @@ -230,8 +230,7 @@ static inline void iob_populate ( struct io_buffer *iobuf, static inline __always_inline int iob_map ( struct io_buffer *iobuf, struct dma_device *dma, size_t len, int flags ) { - return dma_map ( dma, &iobuf->map, virt_to_phys ( iobuf->data ), - len, flags ); + return dma_map ( dma, &iobuf->map, iobuf->data, len, flags ); } /** -- cgit v1.2.3-55-g7522