From 1846c0f2c58becf59288e3ac719fa1d1f3efcfdf Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Mon, 16 May 2016 15:13:51 +0000 Subject: POSTREAD needs to flush the D-cache since speculative loads might (and do) bring back cache lines after a PREREAD. Eliminates random data corruption on my CuBox-i4Pro. ok jsg@ --- sys/arch/arm/arm/bus_dma.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'sys') diff --git a/sys/arch/arm/arm/bus_dma.c b/sys/arch/arm/arm/bus_dma.c index 4290e5406b1..cdd7c21282b 100644 --- a/sys/arch/arm/arm/bus_dma.c +++ b/sys/arch/arm/arm/bus_dma.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bus_dma.c,v 1.29 2016/03/10 10:22:43 tobiasu Exp $ */ +/* $OpenBSD: bus_dma.c,v 1.30 2016/05/16 15:13:50 kettenis Exp $ */ /* $NetBSD: bus_dma.c,v 1.38 2003/10/30 08:44:13 scw Exp $ */ /*- @@ -421,6 +421,19 @@ _bus_dmamap_sync_segment(vaddr_t va, paddr_t pa, vsize_t len, int ops) cpu_dcache_wb_range(va, len); cpu_sdcache_wb_range(va, pa, len); break; + + /* + * Cortex CPUs can do speculative loads so we need to clean the cache + * after a DMA read to deal with any speculatively loaded cache lines. + * Since these can't be dirty, we can just invalidate them and don't + * have to worry about having to write back their contents. + */ + case BUS_DMASYNC_POSTREAD: + case BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE: + membar_sync(); + cpu_dcache_inv_range(va, len); + cpu_sdcache_inv_range(va, pa, len); + break; } } -- cgit v1.2.3