From nobody Mon Jun 8 07:24:34 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E7783C4B72 for ; Thu, 4 Jun 2026 19:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780602520; cv=none; b=TB97AJvutqKDaHJ+VxpRPeNEKoYNcVlZPmnKPEvhj3AwkdHOYEUX8bA8hX3G23nOmbxt1Ov/M38+VWbZmUYAWSXwcbSJHvJ0aopohvfNLcEEjfu7WnO+lvYX2DTLQLLdHe/keiCxtoX5g84olRR0quB8U7tjrOopJCJG60B7Tzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780602520; c=relaxed/simple; bh=jh2lEf+6eMBipLm3VD8oJ3QVgFOzdIJmSl73PZFad9s=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Y+taBb20O8Fpr6ufw9UuJCz5jz5T0zPK4zeEYY+kd9o63/BdgrIKUy1sldc1MqazSquI5Ic2sfXmfayI5WU+ccnDyTbiZrm89X4ZxAiyj3sa5/B7xoOwZLma4UDkRtem8hgKaD/KI81dsAKRCkb3fpfckqVidhQa8/vFhhDWuIM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=FI7YkdtT; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=b/+0CPQI; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="FI7YkdtT"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="b/+0CPQI" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 654IQBkA1813872 for ; Thu, 4 Jun 2026 19:48:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=sRxjmDJb+ltIpXrcELq5y5l3qHN5CLUNKQ4 NUVtbFo0=; b=FI7YkdtTWDJGlNmsgtR3JBqCnhDM90lpW6W8L4u2TOY7kQay677 BnyLwGqmANG2lvioFQYgmSWnuUjGXjH6qEWG7PKUDDbioq3x3Iad0qbHRzPopE5B ZHVwpwcXyoY4hT0orlvBXMmVKRre4hVmQULGigX/Lzlsk1/xkL8ob4xZIo+omeqA 7NqeviynjcJzCrCfjUcQ70QVDOXYvU1UsM6CO4MAHuaw1PgU67A/P6yDCf8oTStO 0H4YSBxn674U6eyvSzeWT5M2PTUUo8O+/hJWq3rIPfn1Dj0r+rRAwpWDYB7XZEC/ doTNh29th0q5vOiIMInkUB33Wcymx9Bju+w== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4eken00aky-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 04 Jun 2026 19:48:36 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-36d98b54cf2so918760a91.1 for ; Thu, 04 Jun 2026 12:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1780602515; x=1781207315; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sRxjmDJb+ltIpXrcELq5y5l3qHN5CLUNKQ4NUVtbFo0=; b=b/+0CPQIgAZlMdcUEK52XYRrO9fnJ+inhkbmDN+c5jUWQQGwzQzC2Cp33i52bRlf0h fM8Z9U2QXKdXI8JaDGyTKIT7gEwJpFXBhL+xOkUoEo3vtQr4EPTvGFxyK6LQ8h818Vws 2P/dMCTV+xkTcAPficM64HyQujK/66te+AUjC3BR1q/33jC0B9iDWu4p5cL+H7vPuD5v p190KXkudonhqSvyqomrSPw0WPSqAZ/XcrFJgWhxoPgkE3+T3thyIeiMQjH/4vYkTfvA qQTSpbxfR7NjbIcqMOjK72L3yk0V4Nd67w1ZDQwrYW0VnEAQQGyYsDByi446GebEUG8M JzJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780602515; x=1781207315; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sRxjmDJb+ltIpXrcELq5y5l3qHN5CLUNKQ4NUVtbFo0=; b=CHFSydNwFDpv9Ex2fNFUBLrYj9eVOxBwORJbk2SGlitZPOw/jwpLncYl1bQkSf5G04 M4rDzXZ8JbKUhH/7/rnzzsvs86rgPQhzo0mEYktCjOBTRpxcnbKWlQo8iem3RHZcgeZX Q0RoTxqBfg8ZK4+180JYB8UPyvNqtIDNt7mrmXAhOnA7NJ7/ybPOvbDe1Z6Y35AY3D+L cum3oy4xbXK+ROyMsup2Y18gVbX3Hw0i0FN8TCYZIHAQsdKaupyEV828WQnZFCA1t0rL PR67Z89vFuVOPi2wBSwDrMKo4zMeKkV7yrC62MPBzgVu1qcL4ByMM8lHp2UvT+F+d+in ryJw== X-Forwarded-Encrypted: i=1; AFNElJ8ATXmYVFWHDVWOWTCrg/Ulei175fCV55tlzh6/eGBBTYhu3s9XmCDzqs7lNzBS1SI/duMX4sChvCSxUUU=@vger.kernel.org X-Gm-Message-State: AOJu0YwsK1drNilYvMFvZESaY+XzGU/BS1X1ngHkD61/SDZYPTEAxWey sIGmKo6lYoK8NWdHXM77OjGLaeDeTDgm+OWiiNN3vo2l4S4Rw2c0TVZe+QWpENzLCOar5uzpTjy okdi6kq7UlDTKaivdazbmWszwRXB3vJ3z5ga0cy30corUiiIWEA6s8iPSgw/eFpHnXNk= X-Gm-Gg: Acq92OE0pBbISmZIkIZSYM3chCWIZrnb6GPCIWO0OseDtXsFKo8Cxdtlqcnui5xcVKc dqw4EsL80QQs6VZuOcZc+T3/DglkEYeAqbD5ms/1zvbltq4R6uzioIktJ2njDe7rQ66qCl+af7v H6Yp7wlhxWT1EPeS6eluUupyTgTvTOMhb92dipCTNHhjm8MihSDrdp+QrU1qN+x1XkIm48dFF9O EBDZfBqu2jrlRM3lOZZV2GE4r2zmqcg/iKZbI9dFcYS/wXvKAmwPEqPy3vmFIBjQUJEVHtRnhKx EJ6hyJZlVkCg+5txVlZYkE9MbVGz5DjLgjjmBT3jZb6OQLAN3gt2qbVyy2w+KKvJsHJul2PH2pv 91HwPn5MyH8hkgMM4e82bxP7xPWk4IVBYtlXnQFprBf6J4ikO4pfnSBR+i1/Q584nXHY= X-Received: by 2002:a17:90b:4a46:b0:36d:bbe0:de7c with SMTP id 98e67ed59e1d1-370eeff19bamr421826a91.12.1780602515320; Thu, 04 Jun 2026 12:48:35 -0700 (PDT) X-Received: by 2002:a17:90b:4a46:b0:36d:bbe0:de7c with SMTP id 98e67ed59e1d1-370eeff19bamr421807a91.12.1780602514837; Thu, 04 Jun 2026 12:48:34 -0700 (PDT) Received: from hu-parihar-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-370f913bb37sm108567a91.2.2026.06.04.12.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 12:48:34 -0700 (PDT) From: Abhinav Parihar To: srinivas.kandagatla@linaro.org, linux-arm-msm@vger.kernel.org Cc: Abhinav Parihar , gregkh@linuxfoundation.org, quic_bkumar@quicinc.com, ekansh.gupta@oss.qualcomm.com, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, dri-devel@lists.freedesktop.org, arnd@arndb.de Subject: [PATCH v1] misc: fastrpc: Add cache maintenance for non-coherent platforms Date: Fri, 5 Jun 2026 01:18:11 +0530 Message-Id: <20260604194811.2437567-1-abhinav.parihar@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjA0MDE5NCBTYWx0ZWRfXw4sGtpTkstDv 1uGbIhe51LO6EdC1bY0O/j/5vZx2Iba1Uf53pqcpNLJjwWZrG0s+jB5c5ILKb4MroT2QxjvUJCW gcIP/yiFU09lxVv2T7jhKq0r9ffvEqKBjDXdIo7LGQGhxiZYuSvY/WCCdz1ikwd6uQrgtvjRs7P MWKyPlvLQuRs9pMkjxBjaX/47kVNcOjp6gM+o2ktJ17dIr6UYDtOrZH34/tpi6kNsBh11FRlF2X sVFgDHeiitxbaa1Jx8d/TMqXutEdu9JuF98pTnna7ZQ4NgyHgrfABUGPEvZA8CY25NNQECdjZmG Nalo0kcEihNowEUU+Hjmu/qaRYow1MmI+paWf+bi+8hcojuBmjd8KQi1zg99bj+feVdCvah8R4X 9zSK6FSgReskVEMWFyL+TTUbCF832OXZG+Ze78VEbhAcKcQEYueArBHB0zBGe1d0OhrTmNoUZrH UhKaGUYmJglEcfHaBaQ== X-Proofpoint-ORIG-GUID: X408E6tGxRtGfhz1DagEdP_ucpXtMNbr X-Proofpoint-GUID: X408E6tGxRtGfhz1DagEdP_ucpXtMNbr X-Authority-Analysis: v=2.4 cv=B96JFutM c=1 sm=1 tr=0 ts=6a21d694 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=EUspDBNiAAAA:8 a=4mxDCDZnYOL6Ru_i_akA:9 a=uKXjsCUrEbL0IQVhDsJ9:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-04_05,2026-05-28_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1011 spamscore=0 malwarescore=0 adultscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 suspectscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605210000 definitions=main-2606040194 Content-Type: text/plain; charset="utf-8" Some platforms using fastrpc do not support DMA coherency on 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. This ensures correct data synchronization on platforms lacking DMA coherency, while avoiding unnecessary overhead on coherent systems. Signed-off-by: Abhinav Parihar --- drivers/misc/fastrpc.c | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 1080f9acf70a..043b6a5548fb 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -255,6 +255,7 @@ struct fastrpc_session_ctx { int sid; bool used; bool valid; + bool coherent; }; =20 struct fastrpc_soc_data { @@ -973,6 +974,64 @@ static int fastrpc_create_maps(struct fastrpc_invoke_c= tx *ctx) return 0; } =20 +static void fastrpc_flush_args(struct fastrpc_invoke_ctx *ctx) +{ + union fastrpc_remote_arg *rpra =3D ctx->rpra; + int i, inbufs, outbufs; + + inbufs =3D REMOTE_SCALARS_INBUFS(ctx->sc); + outbufs =3D REMOTE_SCALARS_OUTBUFS(ctx->sc); + + for (i =3D 0; i < inbufs + outbufs; ++i) { + int raix =3D ctx->olaps[i].raix; + struct fastrpc_map *map =3D ctx->maps[raix]; + + if (raix + 1 > inbufs) + continue; + if (!map || !map->buf) + continue; + + if (rpra[raix].buf.len && ctx->olaps[i].mstart) { + dma_buf_begin_cpu_access(map->buf, DMA_TO_DEVICE); + dma_buf_end_cpu_access(map->buf, DMA_TO_DEVICE); + } + } +} + +static void fastrpc_inv_args(struct fastrpc_invoke_ctx *ctx) +{ + union fastrpc_remote_arg *rpra =3D ctx->rpra; + int i, inbufs, outbufs; + + inbufs =3D REMOTE_SCALARS_INBUFS(ctx->sc); + outbufs =3D REMOTE_SCALARS_OUTBUFS(ctx->sc); + + for (i =3D 0; i < inbufs + outbufs; ++i) { + int raix =3D ctx->olaps[i].raix; + struct fastrpc_map *map =3D ctx->maps[raix]; + + if (raix + 1 <=3D inbufs) + continue; + if (!rpra[raix].buf.len) + continue; + if (!map || !map->buf) + continue; + + /* + * Skip invalidation if the argument overlaps with the + * RPC control header page. + */ + if (((uintptr_t)rpra & PAGE_MASK) =3D=3D + ((uintptr_t)rpra[raix].buf.pv & PAGE_MASK)) + continue; + + if (ctx->olaps[i].mstart) { + dma_buf_begin_cpu_access(map->buf, DMA_FROM_DEVICE); + dma_buf_end_cpu_access(map->buf, DMA_TO_DEVICE); + } + } +} + static struct fastrpc_invoke_buf *fastrpc_invoke_buf_start(union fastrpc_r= emote_arg *pra, int len) { return (struct fastrpc_invoke_buf *)(&pra[len]); @@ -1093,6 +1152,9 @@ static int fastrpc_get_args(u32 kernel, struct fastrp= c_invoke_ctx *ctx) } } =20 + if (!ctx->fl->sctx->coherent) + fastrpc_flush_args(ctx); + for (i =3D ctx->nbufs; i < ctx->nscalars; ++i) { list[i].num =3D ctx->args[i].length ? 1 : 0; list[i].pgidx =3D i; @@ -1239,6 +1301,9 @@ static int fastrpc_internal_invoke(struct fastrpc_use= r *fl, u32 kernel, =20 /* make sure that all memory writes by DSP are seen by CPU */ dma_rmb(); + if (!fl->sctx->coherent) + fastrpc_inv_args(ctx); + /* populate all the output buffers with results */ err =3D fastrpc_put_args(ctx, kernel); if (err) @@ -2217,6 +2282,7 @@ static int fastrpc_cb_probe(struct platform_device *p= dev) sess->used =3D false; sess->valid =3D true; sess->dev =3D dev; + sess->coherent =3D of_property_read_bool(dev->of_node, "dma-coherent"); dev_set_drvdata(dev, sess); =20 if (cctx->domain_id =3D=3D CDSP_DOMAIN_ID) --=20 2.34.1