mirror of
https://github.com/ipxe/ipxe
synced 2025-12-11 05:51:37 +03:00
[riscv] Ensure coherent DMA allocations do not cross cacheline boundaries
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -34,6 +34,13 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** Minimum alignment for coherent DMA allocations
|
||||||
|
*
|
||||||
|
* We set this sufficiently high to ensure that we do not end up with
|
||||||
|
* both cached and uncached uses in the same cacheline.
|
||||||
|
*/
|
||||||
|
#define RISCV_DMA_ALIGN 256
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map buffer for DMA
|
* Map buffer for DMA
|
||||||
*
|
*
|
||||||
@@ -111,6 +118,11 @@ static void * riscv_dma_alloc ( struct dma_device *dma,
|
|||||||
void *addr;
|
void *addr;
|
||||||
void *caddr;
|
void *caddr;
|
||||||
|
|
||||||
|
/* Round up length and alignment */
|
||||||
|
len = ( ( len + RISCV_DMA_ALIGN - 1 ) & ~( RISCV_DMA_ALIGN - 1 ) );
|
||||||
|
if ( align < RISCV_DMA_ALIGN )
|
||||||
|
align = RISCV_DMA_ALIGN;
|
||||||
|
|
||||||
/* Allocate from heap */
|
/* Allocate from heap */
|
||||||
addr = malloc_phys ( len, align );
|
addr = malloc_phys ( len, align );
|
||||||
if ( ! addr )
|
if ( ! addr )
|
||||||
@@ -153,6 +165,9 @@ static void riscv_dma_free ( struct dma_mapping *map,
|
|||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
assert ( virt_to_phys ( addr ) == virt_to_phys ( map->token ) );
|
assert ( virt_to_phys ( addr ) == virt_to_phys ( map->token ) );
|
||||||
|
|
||||||
|
/* Round up length to match allocation */
|
||||||
|
len = ( ( len + RISCV_DMA_ALIGN - 1 ) & ~( RISCV_DMA_ALIGN - 1 ) );
|
||||||
|
|
||||||
/* Free original allocation */
|
/* Free original allocation */
|
||||||
free_phys ( map->token, len );
|
free_phys ( map->token, len );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user