mirror of
https://github.com/ipxe/ipxe
synced 2026-02-06 21:29:29 +03:00
[riscv] Invalidate data cache on completed RX DMA buffers
The data cache must be invalidated twice for RX DMA buffers: once before passing ownership to the DMA device (in case the cache happens to contain dirty data that will be written back at an undefined future point), and once after receiving ownership from the DMA device (in case the CPU happens to have speculatively accessed data in the buffer while it was owned by the hardware). Only the used portion of the buffer needs to be invalidated after completion, since we do not care about data within the unused portion. Update the DMA API to include the used length as an additional parameter to dma_unmap(), and add the necessary second cache invalidation pass to the RISC-V DMA API implementation. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -74,8 +74,10 @@ struct dma_operations {
|
||||
*
|
||||
* @v dma DMA device
|
||||
* @v map DMA mapping
|
||||
* @v len Used length
|
||||
*/
|
||||
void ( * unmap ) ( struct dma_device *dma, struct dma_mapping *map );
|
||||
void ( * unmap ) ( struct dma_device *dma, struct dma_mapping *map,
|
||||
size_t len );
|
||||
/**
|
||||
* Allocate and map DMA-coherent buffer
|
||||
*
|
||||
@@ -194,9 +196,11 @@ DMAAPI_INLINE ( flat, dma_map ) ( struct dma_device *dma,
|
||||
* Unmap buffer
|
||||
*
|
||||
* @v map DMA mapping
|
||||
* @v len Used length
|
||||
*/
|
||||
static inline __always_inline void
|
||||
DMAAPI_INLINE ( flat, dma_unmap ) ( struct dma_mapping *map ) {
|
||||
DMAAPI_INLINE ( flat, dma_unmap ) ( struct dma_mapping *map,
|
||||
size_t len __unused ) {
|
||||
|
||||
/* Decrement mapping count (for debugging) */
|
||||
if ( DBG_LOG ) {
|
||||
@@ -365,8 +369,9 @@ int dma_map ( struct dma_device *dma, struct dma_mapping *map,
|
||||
* Unmap buffer
|
||||
*
|
||||
* @v map DMA mapping
|
||||
* @v len Used length
|
||||
*/
|
||||
void dma_unmap ( struct dma_mapping *map );
|
||||
void dma_unmap ( struct dma_mapping *map, size_t len );
|
||||
|
||||
/**
|
||||
* Allocate and map DMA-coherent buffer
|
||||
|
||||
@@ -276,7 +276,7 @@ static inline __always_inline physaddr_t iob_dma ( struct io_buffer *iobuf ) {
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline __always_inline void iob_unmap ( struct io_buffer *iobuf ) {
|
||||
dma_unmap ( &iobuf->map );
|
||||
dma_unmap ( &iobuf->map, iob_len ( iobuf ) );
|
||||
}
|
||||
|
||||
extern struct io_buffer * __malloc alloc_iob_raw ( size_t len, size_t align,
|
||||
|
||||
Reference in New Issue
Block a user