[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:
Michael Brown
2025-07-10 14:33:34 +01:00
parent 634d9abefb
commit bbabde8ff8
7 changed files with 65 additions and 27 deletions

View File

@@ -79,13 +79,14 @@ static int dma_op_map ( struct dma_device *dma, struct dma_mapping *map,
* Unmap buffer
*
* @v map DMA mapping
* @v len Used length
*/
static void dma_op_unmap ( struct dma_mapping *map ) {
static void dma_op_unmap ( struct dma_mapping *map, size_t len ) {
struct dma_device *dma = map->dma;
assert ( dma != NULL );
assert ( dma->op != NULL );
dma->op->unmap ( dma, map );
dma->op->unmap ( dma, map, len );
}
/**