From nobody Tue Dec 9 02:54:11 2025 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 03CE2321428 for ; Thu, 13 Nov 2025 06:41:21 +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=1763016083; cv=none; b=QC6GsjAJco1M1GIjIUOf/pLHakWQVBWr1Lr2ym5DFphMrPotbC/XJVQKAgICQBtr1bM5SnZu6UFQSUiqRjZ8jh58veYAhSS9Nxpnpml6g0fO+0nl0cXEy1sAuDQiVx88+x83Imm+4CZkAxliluXPgoyWtMF4oeOwhQtVlv3M7Hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763016083; c=relaxed/simple; bh=OdLtVtiwW1xAkEP1Tuk8yBW78hA3TuPbGrqvdFREa1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pYrJUgGlNqmHQzDEPtRzVf6QsGpadptREomx9h6Tr2RbZKhiDrO5h2DPRVDClLBhinRRJ82ZM7kltifOxk/95ARDcjNnzLq9JwdgBfP28jr//rhIE5mmGxyD5g+nJJb8BFhkTFzn80POUA1yPQYsHqQkMMga46wdjzVpvpNFzEw= 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=lcrg7R39; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=itXOZaY7; 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="lcrg7R39"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="itXOZaY7" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5AD5S2Mx3440417 for ; Thu, 13 Nov 2025 06:41:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=p+hWMKFKc2m VbzgviX4dn/1pRPQOpQtDu/1ysXFdpkk=; b=lcrg7R39k/JhY3JsjXhOBdEOMng +MhLO3kZspSmlGJ332Tux8Tuo4mnP5zNXdVmVl2aIL41paRaqIggpnHiDJeTVjAM CtxtkBCtKIIcwmUo31z9ty8IcVNQHnm5Ia6vJCmGhNJJ8DpjKhq2R+ygnaNNpEqY GdcWCtzmd5UdbCsX6ThTtAb5HaSZbtKAQ0eLJN2NnrNHoT0JhadMx1QhjowGO4Ku tfe7OXAlQxPOuGHMYKoes23cCD27vtp+AEuEYxBV2ANysgIsyV8GciF1KU8mXcfw PLMdBU+3WM6sE77jlTCqPL8axxuCvPn/3mtOiYaHJ13Eps00381ODLISePg== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ad97887b8-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 13 Nov 2025 06:41:20 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-b55443b4110so456380a12.1 for ; Wed, 12 Nov 2025 22:41:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1763016080; x=1763620880; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p+hWMKFKc2mVbzgviX4dn/1pRPQOpQtDu/1ysXFdpkk=; b=itXOZaY7x1TGX6/xA4E5opkKNxKxU/9ZPG41M+024pX32EnpyQQEWmvG5+5vVfRkLk TI6tJ/p07XMtEZzsoK6OMGjHdqzoSKH3cPB3DjiuxhjVMQP006DzFS3DpqwE2j/vBPjH l71XRKT/QfhP43sRj/l1lVXyIRgFeigXkNG0pI36WAuH9aOFDn90xTlauhivjuKlHB0W EEiusmlsW8j7fce3K5DyYocq5LmscsKqNZweMgxF3vL3i75yo/APtlbidumFTM0DlWn1 z9lnW6wUEgdaQCDQ8Q1a1NIr/z3NU5ggRk/JpAXiKPxoN2B+w8MhBJGcg/ge8RN8coez 5rLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763016080; x=1763620880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p+hWMKFKc2mVbzgviX4dn/1pRPQOpQtDu/1ysXFdpkk=; b=JcORkCSI0VL3lXf6qpqU27SoGcygPVI9S+CkcG/DwMMD8Ld+vvkhdQNrigsIlZIdA5 6M3RXFkxfPs3saAB5y/eAF2WkJ/r58nxbXIJym03JEa3/RgAJh3S1AHZWYDWNwWUR//H YLc6LNU937kmzo7Zc6Sj41OWrxHNzHmL1xwM8ZYms7maCmkN7D8kqBKlVPQiLEt3il4y p0w4DUkguCq32AgCrf3YjpRc5wryNEWltufHPNPMkN9WUAqEIPeahOhrc3JTVgUn6Tbf zSDaCab3+9qHSSuLoZ4bUAqb9a3JJ5gGNqksxKQ4POOF4tveWW8RMaWD4NQtuGXHWTiF t3vQ== X-Forwarded-Encrypted: i=1; AJvYcCXM94EHKZdnHb0ihQO+Cdn25zHdxLf7FmJpDYwcjgAQALf94Ts8iyt9EZYrUcjchpzhhVQZGJTYoqiWsAU=@vger.kernel.org X-Gm-Message-State: AOJu0YxvF277ryUk0rBceRdbJQ0FfO+xnRVjyrKgJKW6xJVOAFfF1JM5 tzJmlFyemDOhIrvtekLA8qFdy6HpLwTjukwTpe2lDTxxbGaqRku5xC76/7GjRPTM0eWdL39tnPV UVN6jRx6bYLcjmvBHRoddnZSWbj5P8S6kB/BM1MkhLd6Kk2ob5/SiZ9v5plCgCU1VJYopvHdYbQ g= X-Gm-Gg: ASbGncsyUseR56UA5u9dfuoZMTcGnw8tsEDxYylFtY4Etua0lEpi7hgfpuBHtR+5Skq 4mTGyzaRDAyMEBS82iIFvo64iNZXsBHCYEymtqyqSX1aFODr+cygXXVND1eFcVGPWnZlAPPsFzP 917ANVBuvxcWjibD2jFVQHvz1T/oXxg2fLQuQj9wRRw+qqyyUDYZ+VfEv4B4MbSY+6Dt0NN1/9N bMdQaCXq3C8iQR/+nsr0Xr9heH+ba2WzFIX/zw1+9dJLv4UG6nWTZophRFeLFWdCcfSBc0R2ITn tU9nFtr8eRAHFUvhDV+tZyFiAwEBB2vmvUqQI5KcuK6pV6JDFFRCfFT/uA40db7Y7xNi52mOUlP wwjYvb5mEGpH7ia+mhpyla6NtGSThrBk= X-Received: by 2002:a05:6a20:914b:b0:354:1d68:4cd with SMTP id adf61e73a8af0-35a4f6924ebmr3655278637.11.1763016079650; Wed, 12 Nov 2025 22:41:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtQXaEJw3cpwnHLq9LAZYgHeBTeUkFAJXdBKUg5ZDdPcbmmAje3PWxAh4kNGtp5umDsqMu7w== X-Received: by 2002:a05:6a20:914b:b0:354:1d68:4cd with SMTP id adf61e73a8af0-35a4f6924ebmr3655234637.11.1763016079132; Wed, 12 Nov 2025 22:41:19 -0800 (PST) Received: from hu-ekangupt-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bc36db25bfbsm1138419a12.1.2025.11.12.22.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 22:41:18 -0800 (PST) From: Ekansh Gupta To: srini@kernel.org, linux-arm-msm@vger.kernel.org Cc: gregkh@linuxfoundation.org, quic_bkumar@quicinc.com, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, dri-devel@lists.freedesktop.org, arnd@arndb.de, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v3 1/3] misc: fastrpc: Move fdlist to invoke context structure Date: Thu, 13 Nov 2025 12:11:09 +0530 Message-Id: <20251113064111.2426325-2-ekansh.gupta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251113064111.2426325-1-ekansh.gupta@oss.qualcomm.com> References: <20251113064111.2426325-1-ekansh.gupta@oss.qualcomm.com> 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: AW1haW4tMjUxMTEzMDA0NCBTYWx0ZWRfX2uycQa99GcYl rtKV0N24QfDXUGHJtLiJRoJ37xTYZ0C4wxUwk0Xz7HUkxmx+m9INePAtp4qLlDVWYpYyVdWaXhs ced0sD9ZJKwoNQuJM3vVKQoaoz3BYM3GzCnK313Tn4BiUuimbe0XySY99tlyb9DOjZTSieL5qYV QfnVfEx7TC3yYI8hdXzzgHctkV+ICWeK7UF+ga01xrq+RLcpzIPwYAKMw0DJ/w8SMuHPfDcW9+r Rmqz3UAWAORTNu/TxWceStLc9JxCDoYoH0b1Hg2c/y1SBwp8C9brv2xXVQsz6wSuJAo/N17Az6s eqfm0wQTSYuGpDrwOufCEgwewpoXpfycNhoIXFuCaTdArLlNTsTMjv53suqMe5bc9qGlzypW0yE kW3U0bQYavzMSVok4C6v3XZrgt3Q4A== X-Proofpoint-ORIG-GUID: jXMFVddvmMZnlvUR_HC24Z3OmXFTJevV X-Proofpoint-GUID: jXMFVddvmMZnlvUR_HC24Z3OmXFTJevV X-Authority-Analysis: v=2.4 cv=PIYCOPqC c=1 sm=1 tr=0 ts=69157d90 cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=hRzSbfjIAxXVlyYcgJ4A:9 a=x9snwWr2DeNwDh03kgHS:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-12_06,2025-11-12_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 spamscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511130044 Content-Type: text/plain; charset="utf-8" The fdlist is currently part of the meta buffer, computed during put_args. This leads to code duplication when preparing and reading critical meta buffer contents used by the FastRPC driver. Move fdlist to the invoke context structure to improve maintainability and reduce redundancy. This centralizes its handling and simplifies meta buffer preparation and reading logic. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index ee652ef01534..679cd8997a00 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -233,6 +233,7 @@ struct fastrpc_invoke_ctx { int pid; int client_id; u32 sc; + u64 *fdlist; u32 *crc; u64 ctxid; u64 msg_sz; @@ -987,6 +988,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_= invoke_ctx *ctx) rpra =3D ctx->buf->virt; list =3D fastrpc_invoke_buf_start(rpra, ctx->nscalars); pages =3D fastrpc_phy_page_start(list, ctx->nscalars); + ctx->fdlist =3D (u64 *)(pages + ctx->nscalars); args =3D (uintptr_t)ctx->buf->virt + metalen; rlen =3D pkt_size - metalen; ctx->rpra =3D rpra; @@ -1089,18 +1091,10 @@ static int fastrpc_put_args(struct fastrpc_invoke_c= tx *ctx, union fastrpc_remote_arg *rpra =3D ctx->rpra; struct fastrpc_user *fl =3D ctx->fl; struct fastrpc_map *mmap =3D NULL; - struct fastrpc_invoke_buf *list; - struct fastrpc_phy_page *pages; - u64 *fdlist; - int i, inbufs, outbufs, handles; + int i, inbufs; int ret =3D 0; =20 inbufs =3D REMOTE_SCALARS_INBUFS(ctx->sc); - outbufs =3D REMOTE_SCALARS_OUTBUFS(ctx->sc); - handles =3D REMOTE_SCALARS_INHANDLES(ctx->sc) + REMOTE_SCALARS_OUTHANDLES= (ctx->sc); - list =3D fastrpc_invoke_buf_start(rpra, ctx->nscalars); - pages =3D fastrpc_phy_page_start(list, ctx->nscalars); - fdlist =3D (uint64_t *)(pages + inbufs + outbufs + handles); =20 for (i =3D inbufs; i < ctx->nbufs; ++i) { if (!ctx->maps[i]) { @@ -1122,9 +1116,9 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx= *ctx, cleanup_fdlist: /* Clean up fdlist which is updated by DSP */ for (i =3D 0; i < FASTRPC_MAX_FDLIST; i++) { - if (!fdlist[i]) + if (!ctx->fdlist[i]) break; - if (!fastrpc_map_lookup(fl, (int)fdlist[i], &mmap)) + if (!fastrpc_map_lookup(fl, (int)ctx->fdlist[i], &mmap)) fastrpc_map_put(mmap); } =20 --=20 2.34.1 From nobody Tue Dec 9 02:54:11 2025 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 8E81D322C97 for ; Thu, 13 Nov 2025 06:41:25 +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=1763016087; cv=none; b=lOfKyq5E8O1tNO2Dnjt79xcEQshAjSThXpqGm4Fwmwf48bsZ/ovhSijJAux+lyV0Ex5N2HAMgfPkQLNshXiNJei8nQMbR/TS06Qv5F8mJFxfd4giqi6nCRI/R5bulEM7EIMyaHV4gqVHYGVmWleKhakl4dHyeHb8VMm/BaLuCXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763016087; c=relaxed/simple; bh=Y8+KA6Hq/h9cqVjom36SFqyO02HmM6mSYiJPIDmdd4w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pFyHpGX5qCVFlLg4jxTOLXIzIgmNLC7G1M412g+sO+4GEaA3PCVAKeCEF5FN2R3lUys6vGAAPAOFy6X5OpKnRQRnvv4vwWACgiqWGLioFXsLdHm4r9wwZUqXSuwsNkOgbbj0QDy47hNkvoxj7nwXvGHBQRRPOi6thxfniql6cq8= 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=b19Jqa1R; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=UtM12bCB; 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="b19Jqa1R"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="UtM12bCB" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5AD11Css2909642 for ; Thu, 13 Nov 2025 06:41:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=ujaoRN0R9JC yofw9Ts/yVME10jsyMAe6gDSjtEx7EKQ=; b=b19Jqa1RFOd3yfv6XD5V16zf4bs uapARixP4ZzMXe/yNqIXrRPgUJgfqz7l+HNWyC08kT5Ogx7SCOY70q9/rSF8kyT8 IDFR5HWFkB7af8EMfzDEpwFqx2kWp7zlZwHmQNKxTH0SQsKqJiL6eZZCnnd2ONQH 3/p5X/Ab4Zq1LrQIUp9WiT8TzinZgQLv4I/ViBBhPQjn1UBSp9t5eleAM0LWDqeB yu2mlGqF7z819Ff5lEaONP7APGQVd8RRWkuLLAQcQ3OhFnUjiwvtETCHoYNzcV25 a2EtkFnptBUd8cWnP3cCM3zPrW1QplADmHy1R88uy5CGvOzL6L1I4cLSh5A== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4acygm9xm1-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 13 Nov 2025 06:41:23 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-b471737e673so767010a12.1 for ; Wed, 12 Nov 2025 22:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1763016083; x=1763620883; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ujaoRN0R9JCyofw9Ts/yVME10jsyMAe6gDSjtEx7EKQ=; b=UtM12bCBOrJ2vIMdf0qgHxws110l9NURALDdK5eP2h9hGzEap0WGN9RxQb2IBCfbXm +fD+JqRANlInGwoLPbyNqOFjTSm/DbLefmBPlJBsTFyzhAb9Y2w0TKbSEuvObRvaN6c+ +P0+EjA4Q+jyEcf1VeBxbfZjKVZPTsFYl6td6+8Et59QcHLGpvZBgAz9wheBLsCYXuZT RECa3i1UhZ5qiG6txBAt564fGvl0UhujppMRpSv89cvd/MKg3R2OrE9nim00imX4GB+0 AY/1wt9WfxYnTvYxE6U9zvh37fnlwIyRPDOaetCNGP2nfTL81M/MMeu9zf8CqVj3SKuR dTkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763016083; x=1763620883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ujaoRN0R9JCyofw9Ts/yVME10jsyMAe6gDSjtEx7EKQ=; b=bWWDKh5KVKD3/lKf9ySswoz+DsKv0AbZqpYQzmLOqDaAR2K3cBHDvNzcU5VDLNgFnx 9YsdnYqBJZWALnQuZQUlZNDox2nkg08aEoZzYPS10UZXdKUZJINrRPhEbGUv62nSuuKb lJrSZhbrpuajJq0PN+WqKTiCciDmnkOKEaontIXvt8NzB0TnxloVeYTCu8QShKCwD73g 4YU/SYiiIUjSZz+Eg71DORnQfuR75phm+I4bqKjyeTWkuY/sitnqMQP65G2XsfeAAIGL gwbJDOduRCL3Ilo/V0ed7d4o2Ws85YkLaHPQ5TyfQGPazq5eznvAbyjSc7YvyJIZVyen G5EA== X-Forwarded-Encrypted: i=1; AJvYcCUD3KSa3Tk9a6ktjQKIu4QkggSa0VkfhBE5T278CylF5mpVXknJ7GZ4h/RPsikbwnu6CUfgH6+0VJbXxgc=@vger.kernel.org X-Gm-Message-State: AOJu0YynyWnHipEIr/SrtiYEKUUVfiHP1owE1VAR0wG+AnEn+fAKM7y5 g8L5qsSDb17Tc+9kOMqx01Dxof6kM7ADz+YCp4m3GRZeHJuDu/2BSYXQjE1GPE0s60aKG32NHam iWy25x2VHUEUYkTVnGpK2alDAD5b+Sdhwsc/+pQ7umeErh7zKLsWeAArdDFr2HOuodhw= X-Gm-Gg: ASbGnctZeIgaQAImcDajAUImCvI8/pSbqJZkIYwFtu+1ZV0I29ayBdSN4cIQX1DkAM7 VOhjJuAy1Fd+ytfCCswHL+8+BH5Y1/YLVAi5f0WET1SsxxKXFKHO6PGcMfGZGWIXVZ3I9Mwmvrd DILoO6y7qwnmQpRRMPyl/NvtirjTGS3aCkAl6pne6s92lx1424q3NyTgmVIsM7FlGxOITO60T2P gfW4zgs1yuC73IYJeI46URz+jtFQEkJE/XrAYKJpNZhRMbVkDznIA4/46MbFRi9Jwyeb62ROJtT u2rrINz2sQB1rtM+1TbWfnYTKJjTBK+vEXbUbyh2d8vSj1uPE59Z2D1FE1WBoC5uSclwZ+Cbzku i0p7rxa4BrM/W5ZWETtXBsJo6S3Rxsd8= X-Received: by 2002:a05:6a20:3943:b0:342:a7cd:9211 with SMTP id adf61e73a8af0-3590b21850dmr8009708637.34.1763016082769; Wed, 12 Nov 2025 22:41:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEF1omhOWcFP3UCNbVCU4ks3UAajf4M3m+Zx0IeTs1GLXY9LvW5xB6kXqRPzKlUs8Flbvshwg== X-Received: by 2002:a05:6a20:3943:b0:342:a7cd:9211 with SMTP id adf61e73a8af0-3590b21850dmr8009670637.34.1763016082300; Wed, 12 Nov 2025 22:41:22 -0800 (PST) Received: from hu-ekangupt-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bc36db25bfbsm1138419a12.1.2025.11.12.22.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 22:41:21 -0800 (PST) From: Ekansh Gupta To: srini@kernel.org, linux-arm-msm@vger.kernel.org Cc: gregkh@linuxfoundation.org, quic_bkumar@quicinc.com, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, dri-devel@lists.freedesktop.org, arnd@arndb.de, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v3 2/3] misc: fastrpc: Update context ID mask for polling mode support Date: Thu, 13 Nov 2025 12:11:10 +0530 Message-Id: <20251113064111.2426325-3-ekansh.gupta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251113064111.2426325-1-ekansh.gupta@oss.qualcomm.com> References: <20251113064111.2426325-1-ekansh.gupta@oss.qualcomm.com> 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-GUID: 5shCb5a4Ilifr0-mBoHqw-sQD783zW0U X-Authority-Analysis: v=2.4 cv=E/fAZKdl c=1 sm=1 tr=0 ts=69157d94 cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=eMrONWwZx6N8dQ6zNQwA:9 a=x9snwWr2DeNwDh03kgHS:22 X-Proofpoint-ORIG-GUID: 5shCb5a4Ilifr0-mBoHqw-sQD783zW0U X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEzMDA0NSBTYWx0ZWRfX6p+ldmROdYjA +/2MbPk8WEbzXHYD59z263QFNkKH73pgt9zP+04dUGpfgRl5Fp96u1s1Zd7P/5b2Bkm2nC0Onz8 KpgS7haKfepwPhjIw4aiBk1HRHq7DrxoUT2wTSIiWjosIZGiZ2VrdSRY9hsn2tIFfbMJoAEpprM R3dg0z3nZXg3hJexBV3nEtinYdCz8K0JZwxmVyruQ6ibgUjHeNoBtgItcYkW7kv67GCVwggFGB7 na7g/YDnMDVhDjKkZ0UbN+Yq8//WMWKCV21Nr8PNpTqv7AzeQ+Ztnt0F1zMpVtRbxAMQT33TTjM KLapziD5SBsGmtDmKhs4Tr+V2pJOayJN/oiBYDLNXTBMbmNDIJdI+rlPBq4eko1nYeSvVjFPQ// NZsgK2weR6c99niTCV+7PGtKx2+CDg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-12_06,2025-11-12_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 bulkscore=0 impostorscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511130045 Content-Type: text/plain; charset="utf-8" Current FastRPC message context uses a 12-bit mask where the upper 8 bits are context ID from idr_alloc_cyclic and the lower 4 bits represent PD type. This design works for normal FastRPC calls but doesn't work as expected for polling mode. To enable polling mode support from DSP(DSP writes to poll memory), DSP expects a 16-bit context where the upper 8 bits are context ID, the lower 4 bits are PD type and the 5th bit from the end denotes async mode(not yet upstreamed). If this bit is set, DSP disables polling. With the current design, odd context IDs set this bit, causing DSP to skip poll memory updates. Update the context mask to ensure a hole which won't get populated, ensuring polling mode works as expected. This is not a bug and the change is added to support polling mode. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 679cd8997a00..ccba3b6dfdfa 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -37,7 +37,8 @@ #define FASTRPC_CTX_MAX (256) #define FASTRPC_INIT_HANDLE 1 #define FASTRPC_DSP_UTILITIES_HANDLE 2 -#define FASTRPC_CTXID_MASK (0xFF0) +#define FASTRPC_CTXID_MASK (0xFF00) +#define FASTRPC_CTXID_POS (8) #define INIT_FILELEN_MAX (2 * 1024 * 1024) #define INIT_FILE_NAMELEN_MAX (128) #define FASTRPC_DEVICE_NAME "fastrpc" @@ -489,7 +490,7 @@ static void fastrpc_context_free(struct kref *ref) fastrpc_buf_free(ctx->buf); =20 spin_lock_irqsave(&cctx->lock, flags); - idr_remove(&cctx->ctx_idr, ctx->ctxid >> 4); + idr_remove(&cctx->ctx_idr, ctx->ctxid >> FASTRPC_CTXID_POS); spin_unlock_irqrestore(&cctx->lock, flags); =20 kfree(ctx->maps); @@ -625,7 +626,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc( spin_unlock_irqrestore(&cctx->lock, flags); goto err_idr; } - ctx->ctxid =3D ret << 4; + ctx->ctxid =3D ret << FASTRPC_CTXID_POS; spin_unlock_irqrestore(&cctx->lock, flags); =20 kref_init(&ctx->refcount); @@ -2451,7 +2452,7 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device= *rpdev, void *data, if (len < sizeof(*rsp)) return -EINVAL; =20 - ctxid =3D ((rsp->ctx & FASTRPC_CTXID_MASK) >> 4); + ctxid =3D ((rsp->ctx & FASTRPC_CTXID_MASK) >> FASTRPC_CTXID_POS); =20 spin_lock_irqsave(&cctx->lock, flags); ctx =3D idr_find(&cctx->ctx_idr, ctxid); --=20 2.34.1 From nobody Tue Dec 9 02:54:11 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 EF996323406 for ; Thu, 13 Nov 2025 06:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763016089; cv=none; b=THdy8Cuh5Lcgzs8IFFaZGCxNDgp0+TIm4YjNu3S4q8UjIRN17eUU937oFxvbaye2SjwBXo35mSGo1QDcc4c9VfKtvYAh103U8pZqIOb1+cgCbqUER/O1BNSb/CIQe5ps3/YmETxjbtxwfMASdwdNF5Z8DtjF9MCt33E8nPY1Acw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763016089; c=relaxed/simple; bh=wq7kR5huZyr0fiDlW2MJCd8AAInIV/L2vbdGTcsc79A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g5bEImlz/j3DeeeQXEuS2kXSA5bnChsdTomXZJ4jPrslZ203AOstmgs0nRqsR5wBdxydp1bnwO1i/yGM+sgib3ZzCQMJ2F4kW0g3NuhwbWYko6r0E3eU4dAg+DjmJBBgIG3EKjW74+khkTFkmfCQLSliz/5ET+W9MrnpM5ujj4M= 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=DMWtt1TA; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=fbec7+al; arc=none smtp.client-ip=205.220.168.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="DMWtt1TA"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="fbec7+al" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5AD11CE43113217 for ; Thu, 13 Nov 2025 06:41:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=fCH6YNeGp5f wf5ePRtG9yuPXtin/dsoqE9OI2lFu4Cc=; b=DMWtt1TANstRrL6/p2z0A3d0LeJ Ahn3GWuQ6EHqJFjUIFZGZAi8sXHIKnZUhId8Oja7TOthV49n2iwaHCPYzpqpAIhO 7ZU6PR0TImvTuAQiV6w4jHqOha+Qzh6QbNjro2VvhT3KxEs132y3OHjQrx1JGxXU j6IFD4/cYbgw39LfxUiiPbkhb9CzKbmuSmt4iftZFcsxlryjJeSQ/DajkCgemPS/ EFbivzbI8dPgr2KsG9/+6Ctdioj4Avx8wFiHnZbZS6RwtMmlbZaQnZn//aFk7uZh x8LtufjPiix9rnBjfW+UjA2U19SU1dANepGa2zs9FvlDEJIQuggBk86nawg== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4acuw4as13-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 13 Nov 2025 06:41:26 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-b99763210e5so486349a12.3 for ; Wed, 12 Nov 2025 22:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1763016086; x=1763620886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fCH6YNeGp5fwf5ePRtG9yuPXtin/dsoqE9OI2lFu4Cc=; b=fbec7+alojI2ajmnoKlxtjlOq9k1tcQ5kteqA9uNCFtmLf6kyBqEqBePfUuZudqQSs 8+8Yj8zGrxFUV2GyPX+BM/fLS3e4gWdDWFfhlgAMw0NCLKaRANBvUN65MRofEXuk1wxT BdiySnaV+xzJW6A1/AfG4xCP8q7D/EJZlVt1dcl9lfV+8KBgogkfMAq7YbvgJUyps/EH lES7knT4r8hwjQ3S/pf+pX5ryZ2beOCc/m2eqz2vcuNS1fXjO1/nlnTM6KD5kA8XaCi2 IG1CjghXh8zCj22ZVHzVjkRbIOQ/rcpngwzcJmBKoyXpe3vt8tBFDWviFu9oOhICCHug rTvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763016086; x=1763620886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fCH6YNeGp5fwf5ePRtG9yuPXtin/dsoqE9OI2lFu4Cc=; b=EC3Jz4uvZXnPidhDAij2rzYn8o8uurbzbABQ6xt/ATUSnisYG2/Bys2il+4PYCM5WG 3CNPuQUVU8qu61D5g1WFJSpqkqs/m97EWlPQAYSkrIj/gEKFwfPx1ExEkQbD9mwt/7+k 5m8CQA5wChk16vmXDaz/rauOUQaM4R0Idp8EZR8pK6RrEq0WkEDhknM7KwMS+tm0vKJB WZDs4JwiUhI5rv1pyq9gSqEs7fCnTVp/VUCamATGbxPm/xyps0B3r5AVzx85PbQZOsV9 1SBkxuWnr+F1divDXBYhAw6ISaczWJ0fgGRmEYQ4GUeieeo/KDdd5DU4TP4EONunifEm MiPw== X-Forwarded-Encrypted: i=1; AJvYcCWsYmPkCBO6oPqAmQMPSRp44QqGIzXi15tHmXlfUTIH89f2302VNPCw7cY+fPzaJ10xv8NLpOqHuvxqbbc=@vger.kernel.org X-Gm-Message-State: AOJu0YxPws+lfS2jZxf2t9DXA6UXfXGuMsS/hgAXuhfrEtUaLs0pQZNH FDzepwhgir7lyU6VflV6LOn2UYw4L6Cg1UKT9OQEUD+M1CPzkRCP6HtHDNGVRETG6zpn+ZJtu9w 6MztYb6AxvrEp13iZzdJFbXElScJcLnmmVSXS4vo09orpL7VtTiC3d/OsEXnX1LRvtOv4AtZuQP M= X-Gm-Gg: ASbGncsEIMore0zmUv3+o3G319J1X8k/wpok79Ic70ehmIyv2wlSB3WMOXzliVpBie4 ZA840g5NdixtvkWwdg1N5f3kkAwKq67PnUlFO2hOTIBNSUJEwU2k6L6tZ6w0E6S8sowOwS66xsd sWvU6Ak8ay7BiauV8plwrOZuxgVIdnaaIVHJ7E9zjy22BY2rHvd2FzsEEPGwZPGdN1Cb4itsZ/4 f1fYXWYwIdkqdTvmIHBd5xL+aHqftBkV4luMD5Qj+D1aCY6mkQD/MpfDX0ytLT/SfyxrihV6mnF S6LfrnIfcz4w8Vplzec/HCxdfkUyBJfpxQL+9Zfdori8ufNvtPcjB6ti0FULxulSmn2xD0yr3vQ CcWuOLGk/UZhnVJqxZ8TpUTF500RjfbA= X-Received: by 2002:a05:6a21:71c6:b0:35a:6e94:a56 with SMTP id adf61e73a8af0-35a6e940d64mr2153411637.17.1763016085846; Wed, 12 Nov 2025 22:41:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEl/1PQ5yuuhOru4P+95jAHAj+dMuPMBq28IfLV5qxM6svlE6drzYH71KBuLA2K3Wu4wtfX1Q== X-Received: by 2002:a05:6a21:71c6:b0:35a:6e94:a56 with SMTP id adf61e73a8af0-35a6e940d64mr2153386637.17.1763016085333; Wed, 12 Nov 2025 22:41:25 -0800 (PST) Received: from hu-ekangupt-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bc36db25bfbsm1138419a12.1.2025.11.12.22.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 22:41:25 -0800 (PST) From: Ekansh Gupta To: srini@kernel.org, linux-arm-msm@vger.kernel.org Cc: gregkh@linuxfoundation.org, quic_bkumar@quicinc.com, linux-kernel@vger.kernel.org, quic_chennak@quicinc.com, dri-devel@lists.freedesktop.org, arnd@arndb.de, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v3 3/3] misc: fastrpc: Add polling mode support for fastRPC driver Date: Thu, 13 Nov 2025 12:11:11 +0530 Message-Id: <20251113064111.2426325-4-ekansh.gupta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251113064111.2426325-1-ekansh.gupta@oss.qualcomm.com> References: <20251113064111.2426325-1-ekansh.gupta@oss.qualcomm.com> 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-ORIG-GUID: Xxl0mzrK9vSmeUA-PHV8cdF4uVdEsTei X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEzMDA0NCBTYWx0ZWRfX2cWOrlHd+ygq 1+PY6CtOboAh3A06pNaeqv/D2o7AiMd0XUnkd4F6iGzCvMfBDMun9+YtEwJYVOI9tSxueuutMXt 0amuatgKCtGxY4+GbIbHxPvWzPhmKoJB40acHgCR1+AKTB/Q3OxnVKVs/HTrd/14Hf1nrWd5lpk oflhlAMKJfQ90jTC1y8NtVypJ9UZAgdSEzR9XjF1ovSapKE3ErDTaGtmluWPqrPbg+xRiyHxpkp SesGkqWGNZV9LjgcTj+dqQodKqGo5XplK73Y1f5wApPZra0rUuljnYg26vTbDk3mY7ZenqtrEBU zOlUtzR9JcwGBiZurFWCkkCsqd6PfeBAi4I/6/CdOUqN+o4AM26BG9ADnUuPMfW3MToUmnkNWSu D9lu7PJfCJI+MxLSGVo9fVT6Xojgfg== X-Authority-Analysis: v=2.4 cv=F+Bat6hN c=1 sm=1 tr=0 ts=69157d96 cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=TEHdEMHTk_fMHrPBF0kA:9 a=x9snwWr2DeNwDh03kgHS:22 X-Proofpoint-GUID: Xxl0mzrK9vSmeUA-PHV8cdF4uVdEsTei X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-12_06,2025-11-12_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511130044 Content-Type: text/plain; charset="utf-8" For any remote call to DSP, after sending an invocation message, fastRPC driver waits for glink response and during this time the CPU can go into low power modes. This adds latency to overall fastrpc call as CPU wakeup and scheduling latencies are included. Add polling mode support with which fastRPC driver will poll continuously on a memory after sending a message to remote subsystem which will eliminate CPU wakeup and scheduling latencies and reduce fastRPC overhead. Poll mode can be enabled by user by making a remote_handle64_control request. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 138 ++++++++++++++++++++++++++++++++++-- include/uapi/misc/fastrpc.h | 9 +++ 2 files changed, 140 insertions(+), 7 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index ccba3b6dfdfa..60de9dcb9815 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include =20 #define ADSP_DOMAIN_ID (0) #define MDSP_DOMAIN_ID (1) @@ -37,6 +39,7 @@ #define FASTRPC_CTX_MAX (256) #define FASTRPC_INIT_HANDLE 1 #define FASTRPC_DSP_UTILITIES_HANDLE 2 +#define FASTRPC_MAX_STATIC_HANDLE (20) #define FASTRPC_CTXID_MASK (0xFF00) #define FASTRPC_CTXID_POS (8) #define INIT_FILELEN_MAX (2 * 1024 * 1024) @@ -106,6 +109,12 @@ =20 #define miscdev_to_fdevice(d) container_of(d, struct fastrpc_device, miscd= ev) =20 +/* Poll response number from remote processor for call completion */ +#define FASTRPC_POLL_RESPONSE (0xdecaf) + +/* Polling mode timeout limit */ +#define FASTRPC_POLL_MAX_TIMEOUT_US (10000) + struct fastrpc_phy_page { u64 addr; /* physical address */ u64 size; /* size of contiguous region */ @@ -236,8 +245,14 @@ struct fastrpc_invoke_ctx { u32 sc; u64 *fdlist; u32 *crc; + /* Poll memory that DSP updates */ + u32 *poll; u64 ctxid; u64 msg_sz; + /* work done status flag */ + bool is_work_done; + /* process updates poll memory instead of glink response */ + bool is_polled; struct kref refcount; struct list_head node; /* list of ctxs */ struct completion work; @@ -301,6 +316,8 @@ struct fastrpc_user { int client_id; int pd; bool is_secure_dev; + /* Flags poll mode state */ + bool poll_mode; /* Lock for lists */ spinlock_t lock; /* lock for allocations */ @@ -894,7 +911,8 @@ static int fastrpc_get_meta_size(struct fastrpc_invoke_= ctx *ctx) sizeof(struct fastrpc_invoke_buf) + sizeof(struct fastrpc_phy_page)) * ctx->nscalars + sizeof(u64) * FASTRPC_MAX_FDLIST + - sizeof(u32) * FASTRPC_MAX_CRCLIST; + sizeof(u32) * FASTRPC_MAX_CRCLIST + + sizeof(u32); =20 return size; } @@ -990,6 +1008,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc= _invoke_ctx *ctx) list =3D fastrpc_invoke_buf_start(rpra, ctx->nscalars); pages =3D fastrpc_phy_page_start(list, ctx->nscalars); ctx->fdlist =3D (u64 *)(pages + ctx->nscalars); + ctx->poll =3D (u32 *)(ctx->fdlist + FASTRPC_MAX_FDLIST + FASTRPC_MAX_CRCL= IST); args =3D (uintptr_t)ctx->buf->virt + metalen; rlen =3D pkt_size - metalen; ctx->rpra =3D rpra; @@ -1158,6 +1177,75 @@ static int fastrpc_invoke_send(struct fastrpc_sessio= n_ctx *sctx, =20 } =20 +static inline u32 fastrpc_poll_op(void *p) +{ + struct fastrpc_invoke_ctx *ctx =3D p; + + dma_rmb(); + return READ_ONCE(*ctx->poll); +} + +static int poll_for_remote_response(struct fastrpc_invoke_ctx *ctx) +{ + u32 val; + int ret; + + /* + * Poll until DSP writes FASTRPC_POLL_RESPONSE into *ctx->poll + * or until another path marks the work done. + */ + ret =3D read_poll_timeout_atomic(fastrpc_poll_op, val, + (val =3D=3D FASTRPC_POLL_RESPONSE) || + ctx->is_work_done, 1, + FASTRPC_POLL_MAX_TIMEOUT_US, false, ctx); + + if (!ret && val =3D=3D FASTRPC_POLL_RESPONSE) { + ctx->is_work_done =3D true; + ctx->retval =3D 0; + } + + if (ret =3D=3D -ETIMEDOUT) + ret =3D -EIO; + + return ret; +} + +static inline int fastrpc_wait_for_response(struct fastrpc_invoke_ctx *ctx, + u32 kernel) +{ + int err =3D 0; + + if (kernel) { + if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) + err =3D -ETIMEDOUT; + } else { + err =3D wait_for_completion_interruptible(&ctx->work); + } + + return err; +} + +static int fastrpc_wait_for_completion(struct fastrpc_invoke_ctx *ctx, + u32 kernel) +{ + int err; + + do { + if (ctx->is_polled) { + err =3D poll_for_remote_response(ctx); + /* If polling timed out, move to normal response mode */ + if (err) + ctx->is_polled =3D false; + } else { + err =3D fastrpc_wait_for_response(ctx, kernel); + if (err) + return err; + } + } while (!ctx->is_work_done); + + return err; +} + static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, u32 handle, u32 sc, struct fastrpc_invoke_args *args) @@ -1193,16 +1281,25 @@ static int fastrpc_internal_invoke(struct fastrpc_u= ser *fl, u32 kernel, if (err) goto bail; =20 - if (kernel) { - if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) - err =3D -ETIMEDOUT; - } else { - err =3D wait_for_completion_interruptible(&ctx->work); - } + /* + * Set message context as polled if the call is for a user PD + * dynamic module and user has enabled poll mode. + */ + if (handle > FASTRPC_MAX_STATIC_HANDLE && fl->pd =3D=3D USER_PD && + fl->poll_mode) + ctx->is_polled =3D true; + + err =3D fastrpc_wait_for_completion(ctx, kernel); =20 if (err) goto bail; =20 + if (!ctx->is_work_done) { + err =3D -ETIMEDOUT; + dev_dbg(fl->sctx->dev, "Invalid workdone state for handle 0x%x, sc 0x%x\= n", + handle, sc); + goto bail; + } /* make sure that all memory writes by DSP are seen by CPU */ dma_rmb(); /* populate all the output buffers with results */ @@ -1780,6 +1877,29 @@ static int fastrpc_get_info_from_kernel(struct fastr= pc_ioctl_capability *cap, return 0; } =20 +static int fastrpc_set_option(struct fastrpc_user *fl, char __user *argp) +{ + struct fastrpc_ioctl_set_option opt =3D {0}; + int i; + + if (copy_from_user(&opt, argp, sizeof(opt))) + return -EFAULT; + + for (i =3D 0; i < ARRAY_SIZE(opt.reserved); i++) { + if (opt.reserved[i] !=3D 0) + return -EINVAL; + } + if (opt.req !=3D FASTRPC_POLL_MODE) + return -EINVAL; + + if (opt.enable) + fl->poll_mode =3D true; + else + fl->poll_mode =3D false; + + return 0; +} + static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_ioctl_capability cap =3D {0}; @@ -2134,6 +2254,9 @@ static long fastrpc_device_ioctl(struct file *file, u= nsigned int cmd, case FASTRPC_IOCTL_MEM_UNMAP: err =3D fastrpc_req_mem_unmap(fl, argp); break; + case FASTRPC_IOCTL_SET_OPTION: + err =3D fastrpc_set_option(fl, argp); + break; case FASTRPC_IOCTL_GET_DSP_INFO: err =3D fastrpc_get_dsp_info(fl, argp); break; @@ -2465,6 +2588,7 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device= *rpdev, void *data, =20 ctx->retval =3D rsp->retval; complete(&ctx->work); + ctx->is_work_done =3D true; =20 /* * The DMA buffer associated with the context cannot be freed in diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index c6e2925f47e6..6c1375ba0042 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -16,6 +16,7 @@ #define FASTRPC_IOCTL_INIT_CREATE_STATIC _IOWR('R', 9, struct fastrpc_init= _create_static) #define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_mem_map) #define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_mem_unmap) +#define FASTRPC_IOCTL_SET_OPTION _IOWR('R', 12, struct fastrpc_ioctl_set_o= ption) #define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_cap= ability) =20 /** @@ -66,6 +67,8 @@ enum fastrpc_proc_attr { =20 /* Fastrpc attribute for memory protection of buffers */ #define FASTRPC_ATTR_SECUREMAP (1) +/* Set option request ID to enable poll mode */ +#define FASTRPC_POLL_MODE (1) =20 struct fastrpc_invoke_args { __u64 ptr; @@ -133,6 +136,12 @@ struct fastrpc_mem_unmap { __s32 reserved[5]; }; =20 +struct fastrpc_ioctl_set_option { + __u32 req; /* request id */ + __u32 enable; /* enable flag */ + __s32 reserved[6]; +}; + struct fastrpc_ioctl_capability { __u32 unused; /* deprecated, ignored by the kernel */ __u32 attribute_id; --=20 2.34.1