diff options
author | Michael Brown <mcb30@ipxe.org> | 2020-11-29 10:55:14 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2020-11-29 11:25:40 +0000 |
commit | 6e01b74a8ac6a3c3c6806ae286df033f71962f9a (patch) | |
tree | e5281b29e916093266f5fce323938284faf5e287 /src/include/ipxe/dma.h | |
parent | a8442750e6059335f1f7f5ce8b2fb803a6953789 (diff) | |
download | ipxe-6e01b74a8ac6a3c3c6806ae286df033f71962f9a.tar.gz |
[dma] Provide dma_umalloc() for allocating large DMA-coherent buffers
Some devices (e.g. xHCI USB host controllers) may require the use of
large areas of host memory for private use by the device. These
allocations cannot be satisfied from iPXE's limited heap space, and so
are currently allocated using umalloc() which will allocate external
system memory (and alter the system memory map as needed).
Provide dma_umalloc() to provide such allocations as part of the DMA
API, since there is otherwise no way to guarantee that the allocated
regions are usable for coherent DMA.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/dma.h')
-rw-r--r-- | src/include/ipxe/dma.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/include/ipxe/dma.h b/src/include/ipxe/dma.h index b3fa24e47..385e4baf7 100644 --- a/src/include/ipxe/dma.h +++ b/src/include/ipxe/dma.h @@ -13,6 +13,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/api.h> #include <ipxe/io.h> #include <ipxe/malloc.h> +#include <ipxe/umalloc.h> #include <config/ioapi.h> #ifdef DMAAPI_OP @@ -97,6 +98,28 @@ struct dma_operations { void ( * free ) ( struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len ); /** + * Allocate and map DMA-coherent buffer from external (user) memory + * + * @v dma DMA device + * @v map DMA mapping to fill in + * @v len Length of buffer + * @v align Physical alignment + * @ret addr Buffer address, or NULL on error + */ + userptr_t ( * umalloc ) ( struct dma_device *dma, + struct dma_mapping *map, + size_t len, size_t align ); + /** + * Unmap and free DMA-coherent buffer from external (user) memory + * + * @v dma DMA device + * @v map DMA mapping + * @v addr Buffer address + * @v len Length of buffer + */ + void ( * ufree ) ( struct dma_device *dma, struct dma_mapping *map, + userptr_t addr, size_t len ); + /** * Set addressable space mask * * @v dma DMA device @@ -234,6 +257,55 @@ DMAAPI_INLINE ( flat, dma_free ) ( struct dma_mapping *map, } /** + * Allocate and map DMA-coherent buffer from external (user) memory + * + * @v dma DMA device + * @v map DMA mapping to fill in + * @v len Length of buffer + * @v align Physical alignment + * @ret addr Buffer address, or NULL on error + */ +static inline __always_inline userptr_t +DMAAPI_INLINE ( flat, dma_umalloc ) ( struct dma_device *dma, + struct dma_mapping *map, + size_t len, size_t align __unused ) { + userptr_t addr; + + /* Allocate buffer */ + addr = umalloc ( len ); + + /* Increment mapping count (for debugging) */ + if ( DBG_LOG && addr ) { + map->dma = dma; + dma->mapped++; + } + + return addr; +} + +/** + * Unmap and free DMA-coherent buffer from external (user) memory + * + * @v map DMA mapping + * @v addr Buffer address + * @v len Length of buffer + */ +static inline __always_inline void +DMAAPI_INLINE ( flat, dma_ufree ) ( struct dma_mapping *map, + userptr_t addr, size_t len __unused ) { + + /* Free buffer */ + ufree ( addr ); + + /* Decrement mapping count (for debugging) */ + if ( DBG_LOG ) { + assert ( map->dma != NULL ); + map->dma->mapped--; + map->dma = NULL; + } +} + +/** * Set addressable space mask * * @v dma DMA device @@ -317,6 +389,27 @@ void * dma_alloc ( struct dma_device *dma, struct dma_mapping *map, void dma_free ( struct dma_mapping *map, void *addr, size_t len ); /** + * Allocate and map DMA-coherent buffer from external (user) memory + * + * @v dma DMA device + * @v map DMA mapping to fill in + * @v len Length of buffer + * @v align Physical alignment + * @ret addr Buffer address, or NULL on error + */ +userptr_t dma_umalloc ( struct dma_device *dma, struct dma_mapping *map, + size_t len, size_t align ); + +/** + * Unmap and free DMA-coherent buffer from external (user) memory + * + * @v map DMA mapping + * @v addr Buffer address + * @v len Length of buffer + */ +void dma_ufree ( struct dma_mapping *map, userptr_t addr, size_t len ); + +/** * Set addressable space mask * * @v dma DMA device |