Re: [PATCH v3] misc: fastrpc: Add cache maintenance for non-coherent platforms
From: Abhinav Parihar
Date: Mon Nov 30 2026 - 04:11:33 EST
On 11/24/2026 5:59 PM, Arnd Bergmann wrote:
On Tue, Nov 24, 2026, at 13:06, Abhinav Parihar wrote:
Some platforms using fastrpc do not support DMA coherency onThe dma-mapping abstraction is meant to hide this from drivers,
HLOS. On such systems, explicit cache maintenance is
required to ensure data consistency for RPC argument buffers.
Add cache maintenance for argument buffers when operating on
non-coherent platforms:
- Flush input buffers before invoking RPC to ensure CPU writes are
visible to the DSP
- Invalidate output buffers after RPC completion to ensure DSP
writes are visible to the CPU
Introduce helper functions fastrpc_flush_args() and
fastrpc_inv_args() to perform the required dma-buf cache
operations. These are invoked only when the device is not marked
as DMA coherent.
The coherency capability is determined using the "dma-coherent"
device tree property and stored per session context.
why does this driver need to know?
I added that check because I thought coherency varied across targets and wanted to avoid unnecessary operations
for IO coherent targets.
The data flow is that userspace allocates the dma-buf (system heap), FastRPC driver attaches and maps it for the HLOS SMMU,
and the resulting IOVA is passed to the DSP, which maps and accesses the buffer in its own address space. Goal is that inbufs
are updated in DDR before DSP reads them and outbufs cache lines are invalidated before HLOS reads the DSP results.
@@ -1078,6 +1086,54 @@ static int fastrpc_create_maps(structThis does not look like an appropriate interface: the driver
fastrpc_invoke_ctx *ctx)
return 0;
}
+static void fastrpc_flush_args(struct fastrpc_invoke_ctx *ctx)
+{
+ union fastrpc_remote_arg *rpra = ctx->rpra;
+ int i, inbufs;
+
+ inbufs = REMOTE_SCALARS_INBUFS(ctx->sc);
+
+ for (i = 0; i < ctx->nbufs; ++i) {
+ int raix = ctx->olaps[i].raix;
+ struct fastrpc_map *map = ctx->maps[raix];
+
+ if (raix + 1 > inbufs)
+ continue;
+ if (!map || !map->buf)
+ continue;
+
+ if (rpra[raix].buf.len && (ctx->olaps[i].mstart ||
ctx->olaps[i].do_cmo)) {
+ dma_buf_begin_cpu_access(map->buf, DMA_TO_DEVICE);
+ dma_buf_end_cpu_access(map->buf, DMA_TO_DEVICE);
+ }
+ }
+}
should not have to worry about platform specific details
of 'flush' or 'invalidate' and only access the data between
'begin' and 'end' here. E.g. if there is an iommu or swiotlb,
the buffer may become inaccessible again after 'end'.
Can you change this to have separate loops to manage
ownership before and after the access?
Arnd
I was calling dma_buf_begin_cpu_access() and dma_buf_end_cpu_access() back-to-back to trigger cache maintenance.
Currently we are treating these calls as flush/invalidate primitives.
Since FastRPC passes the mapping to the DSP rather than accessing the buffer contents in the kernel, could you advise which
interface is appropriate for this case?