From nobody Sun Feb 8 18:57:34 2026 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 389E32D77FA for ; Thu, 6 Nov 2025 05:08:49 +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=1762405730; cv=none; b=UHHMSLmcKv3GqB+rwGj1PP75RLUZLvwG3xh20ZBIn9+ZeFvsAQnN0oY9c4vJ88hL8ziFxMKs8GupJQlk1LmukHQF6hDybnt55SGpFrtC+7zGLvBW8BUPvqTE7719g2jOPdW6eho06Muv32/mYrdFEzig6lN0xj85Iwr+33lxjYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762405730; c=relaxed/simple; bh=OdLtVtiwW1xAkEP1Tuk8yBW78hA3TuPbGrqvdFREa1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MHAIHW57WCE/zHjoxder8a0WcFO4SfKUzpZggKTDG7fZgzvlmYMtL6Lpsfw20irNeDvj42/Cm9susRjmnxIPaQBVw5KaLwBxXphRh0cXaMW3cHn0eJsgE64TuYhjeWY4OIrkd0VnjjXese8w8OaRJED5FH1XOm+un4dZSFEP/ns= 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=aJr7EOIz; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=EMRf05Aa; 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="aJr7EOIz"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="EMRf05Aa" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5A5KFBcM1657055 for ; Thu, 6 Nov 2025 05:08:48 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=aJr7EOIzgAvUY+6EuNLCcqqUO0k 0hOlOF/cmOdgrgwuiCmS0jCQ3FhRZjj+AU+o5mkoWwveuEJedOTwCcA9BjqhWVDX byTOws9ZVIZ1tjY/RRAHmf/VlR8cDRe1pEL2nEXPoRIL/jeT7YS2novXlpA53ptN N+5zGWLY70WUDUpQdfYYm46HYt24eX+bUzqyxf052D32iO/GrSL+o+ASz5Zz8Nc1 jLZBhl8E32ytWuvWkr0lAB0/Aa2kCt6XrI7svpNpqT6T5MkrxTD3TtrXUQDNaf8G 3mlaZtey7Bbso0yDC+WM7fYGjWWSandu54UQPS3aewVunhPllXy/Xoy6/Gw== Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4a8831adw3-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 06 Nov 2025 05:08:48 +0000 (GMT) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-7a99a5f77e0so51941b3a.2 for ; Wed, 05 Nov 2025 21:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1762405728; x=1763010528; 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=EMRf05AanMlQT+0o+n4ytKeE0PzDaV4m3qgueFB0jGCdJlPNMdILMXIRxCP6Pt/jFj QBELx13qGdck9u8Pxz/sFqGfmH96zpSD+ioChH4XRjtjpmQpw2Ans+lO3a1QDTPt868q 29QGJEZmSxhdEoDdUXIvvXjsoQsry03+dpa5GkRAhq8c8XldotMPRIwB3Ic8agHGhT6O kv9qYOFXo9PfDu+H5aO5PT6n9/3H+4zsRq2jMAEe2NERI5W0PaUKT1cxqc9PsWWA9KCT 81Vc7zBNnCo50+yD4BNEYP6eruRDdHWflnyltffxarCW7AWot5MMYrO/CAlYjTbizp1L pKGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762405728; x=1763010528; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p+hWMKFKc2mVbzgviX4dn/1pRPQOpQtDu/1ysXFdpkk=; b=LtW0ffdx1L7M9vEHcPidfVbLIBk6fjqvtylE4dD+eccugBqc41Cv4VRE7OxBVvjqlc p78NVFo83aBdl7FBsE1rjiSrvDZ/RskG0P9kRXr6VGa64ksvI2Pr9s1oiiMCk90FhPnd 4HUlGCzizsQariniJc8TLQq548ibvliJxC9myoeX5aYBHKKWCE0WWAqgBmaCBLi2BaTa lzFavCCuJeSBkGVi7fRz0GIbRLwN7nYP5b3xZXZ0Y9vqv+Z77vsURNTRjraaG0/2m5CD wCV9TRbjyOZnNaURM9lUCYN600DTc1Y4falojGoBxq6RW1sWQOmcD9htO7Y8P96Glg9g ERVw== X-Forwarded-Encrypted: i=1; AJvYcCVPs8rmKuuRpOSKN2/JaQXupPvL/OrZaMLysPEF54ZoSNcD03nc6J5fl5GqQnMs9k9YbP2+d1SFxvhW/Vk=@vger.kernel.org X-Gm-Message-State: AOJu0YzlsP2PgKYs1kMfH3BKFFA6Wjk/vDpeG+hmNo7zR+XVePewcoIj 1dG3s/uG6mG2z/0xHHzy7pVIxa3jMJmlb46YfXhqAiLs+Hd+UIrAE5BIZvrJIWFLixSvw8EI7Fl 8U+gBgU+E2sFuUvjFNu86/mynRAWcltRHWR/vc4fhpk8Hbv5yT5d/c7ze7aAW8fh6Qrk= X-Gm-Gg: ASbGncvk+oDCjDbH0Eku0wpQRl2nP/Wx8HGn5eJC6d5dwTESit/Qowa24OjwdZqP4x8 Xry6yh3oLnsixAVlZy8O6kiVvCX8UeXz13TMLcd61D0gouacKyO0oICBDzoAl0SxMTAcWCAXEP+ ZdkEPxI6AcZs1oguYlMf4h07TcnY8cGHBkcjmEDxtG4u8V7i7dixB8Eb+i8Oldfs2ZgPl13lety i2fzUIqYAHfmfpJNwblOBgmDsBFEUHu0WyN8KRtIcedLby3PSQPLnnaeuWYk556vMowYnODjJj2 sueLnDqsQRkmwvrLmMm7Vrc7ViTrxO1AuykQrGSS71dE5VkZbR8YBDxUqrRWGwzfXDAoxtpwLLg sl+BQgLyXmhoZkPXcufzIakt8mfnmp8s= X-Received: by 2002:a05:6a20:4329:b0:2e5:655c:7f93 with SMTP id adf61e73a8af0-34f866ffcddmr8038723637.33.1762405727759; Wed, 05 Nov 2025 21:08:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9x/9PQXFxurYjajKLl4M0E+BvzwI4iNtYKbcQnSyyKegfSdBjBGyv0hbXFx4kxfKFSUcyZQ== X-Received: by 2002:a05:6a20:4329:b0:2e5:655c:7f93 with SMTP id adf61e73a8af0-34f866ffcddmr8038656637.33.1762405726586; Wed, 05 Nov 2025 21:08:46 -0800 (PST) Received: from hu-ekangupt-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7af7fd5238csm1185862b3a.17.2025.11.05.21.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Nov 2025 21:08:46 -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 v2 1/3] misc: fastrpc: Move fdlist to invoke context structure Date: Thu, 6 Nov 2025 10:38:37 +0530 Message-Id: <20251106050839.3091707-2-ekansh.gupta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251106050839.3091707-1-ekansh.gupta@oss.qualcomm.com> References: <20251106050839.3091707-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: 4PsQkeg-6y39EWGzUJfMQLaoMN3vi-Ip X-Proofpoint-GUID: 4PsQkeg-6y39EWGzUJfMQLaoMN3vi-Ip X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTA2MDAzOSBTYWx0ZWRfX4ygcM5YEBAIb AaAuh2EoJAdLi6Ky/DxQyWqRuW6PfEQCoHdsbWw0urW6vcc2171YtxPd7dZWTXqzNlyuDo9EyT6 R6FNlAnPCPJoyIR+ZVNvLLS/73v3a8/zb7DRUj/Oin0qW5DKUO5T1qhn7B6GHgze1wsdpM5yRMl vaqDH08wrBY1rRXON0WGpduKP7EEW96yxh2aDYFc8zONxzdK7LzTsQLw4c/qUo0P+YVQ94/Pu5I I+q70vfS4zJiI2a+HvO9ZpbLPJ6ukWU4s508z5EdibFb8dG2NV9h69clfvjj7oQO2AMwdoCQvA4 9L4Hq6tjqUrc8KnlYpSLphKck5f6IrRr28nR987q3cA49OK8z4jVetUcAy/y3GykAKn7CJEVwpo N5oIElSRTfNW6v47CZKeqaIhO4OVmg== X-Authority-Analysis: v=2.4 cv=Mdhhep/f c=1 sm=1 tr=0 ts=690c2d60 cx=c_pps a=WW5sKcV1LcKqjgzy2JUPuA==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=hRzSbfjIAxXVlyYcgJ4A:9 a=OpyuDcXvxspvyRM73sMx: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-05_09,2025-11-03_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 suspectscore=0 spamscore=0 clxscore=1015 malwarescore=0 adultscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511060039 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 Sun Feb 8 18:57:34 2026 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 8B54E2D876B for ; Thu, 6 Nov 2025 05:08:51 +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=1762405733; cv=none; b=cJwYVdKzXzZM614L5XWaX+Qk+bD54xiGy5P3jxNSph/kEFz8rgR8Z1NK+us/UHCdka50OgkHB773vpP52ezVbcVizFRatAEUQ0Q3FyvwqSBLQsShcKd8qSuuPhjZppFAQbmOPQ4C6wZa7t9dE3QzmOQAlo+m6x4kA+u8BmWFsoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762405733; c=relaxed/simple; bh=Y8+KA6Hq/h9cqVjom36SFqyO02HmM6mSYiJPIDmdd4w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nN4pcRKBGHd1pTSvO7APrFVn6ufADD2GxJfSxmRZC42hQc8Y/SCocGXWyra+xrEe01PCjZGwRH6ox0wtiztjaG+3v78au/bbL/d+z6vKgX0JKuekJxr6PRn21xrx5yBENV/X3ZAR6Tcd//Jtn9uiRqMgmYrBukZPokB7ChTXx+4= 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=AI1ZSuwy; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=cIpy55ph; 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="AI1ZSuwy"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="cIpy55ph" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5A655ZR63217421 for ; Thu, 6 Nov 2025 05:08:51 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=AI1ZSuwyCsB/CYf8Z9MoEWTkTlh J6zFBGk1mODC6ILBPsc7Rr5w/h9IWEABoIEv3a/XcDA71ou8b4Ovph6h6ieWY7S0 lXqePUkeTUzuvR6TKHT2L2qTdSnweKMesqnk+aY7qyowsnJzQ1yCL8O7IpXYDMs/ AJf27D9wQArXIHrnZl8Hpa0RwWTXyuJjukzRGIGPjBJlbW9YsXCmzGcw07/WRX2i 19EtDc1MuupA/nzo+KN6amf1R3eA4jQaivK33cwfxBuhjL8noHsMa4GI4R803UW4 um8B54x8WCrANTqhvmt6ZmKkstvPjaWRB/ZUXDtV9UoaCm/iI5fjpVx32pA== Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4a8n7pg0a3-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 06 Nov 2025 05:08:50 +0000 (GMT) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-7af85c822c7so586233b3a.2 for ; Wed, 05 Nov 2025 21:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1762405730; x=1763010530; 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=cIpy55phJL2lyorlOk4raviiCPLN9SYo7iNP8RhAfWPbTlv96ujDVwX/fr3jXYlUbj vphQEvfhiiGkMXBf4P9liuzXmMXlbNCRo9TURsxGVpjd0zkia1Wfckl6/B6kyutEGWig C0CfgPbWA09pFEYCxC+8pFOWTKNQibR0HPAH9dNLk4tPBpe5Xue5SwC718LxQmjsu5+h 1ujT96OGmmQJxrDJeKb47jf7oLPmya5e5/m6lKEuX0b+tlu98oIZ4XgjuQD4mK0OY7nt eYDDDOYGhrEqKDJZpLa45Ny/Ls9xA/1MX5J8RiNr2Tsb74Bpd480X/+kCoLCcWz/c5rJ fYOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762405730; x=1763010530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ujaoRN0R9JCyofw9Ts/yVME10jsyMAe6gDSjtEx7EKQ=; b=JPtWyJO8HC39ZD9TvCQEKa1vAZ7HbbAt8QbRbZdEP4Zc5gAMXXavaaqUwqKuNjbQlR +c+vlSd9hBWV+v8U0yfizJVHNn4fgMYZsk4SJoTwebaoCezj1kADdKYp/FL94HF5d/Cw XlvUYWcIMJAQXB6jZ9NEduuWOM6HFoywhhnVwr4dz1ymYrt+8xUOSoEc0I0tDPyVlqwc PPDgC5oqGnhs3IXyEfNXqayluvabYuV2QZIrCVGmhYGyGgt46wYBYFQdAVTjCnWjLxbj IG8AaWOChHZrRLwGIs9rt7XkHtRLqLd4+Ggsg9L34sCYlkVhmMfRK+PefsaweCw517oB 1J9A== X-Forwarded-Encrypted: i=1; AJvYcCUM2XxPFmRSp30BN/Fa5LW5nEz/KWR2weGaJJMg9kqb4+nJVohrOlsAqfxd3YMNaQXMNrrj0/cLHpMkzDo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1vzjo2KjY0VP7TwQTu9sVwbyk45vOAiICk+LMhmdvUo9E/sOC L8yBMo9RBc7NQNC5bwb/1TxQEUftiZOv8HEZaWC9Qj3We4H+W7QtwcHdTBzfDUOJ3MA/M2SvzUl MjXYL3/j6t2LG4jCQ+bBx4g+lO8MAH3HCLlOpMf7/Vk8iWY9pW9+QHA+bVa3uN4DLUTs= X-Gm-Gg: ASbGncuWgsB4YR5/0D9JH6w2ZrJ6kM3kgrZUp9x0rdeT3Ya8oPF9dfVhM2KM60F0gWa j8Awieukd48E8pQaNRvlzjv8JX7f6u9hhUWH0WR5jtPQPnJsiDZlbsFaSg3jE+PqklQk+xHXEml l9cHUpWPOrRiDle/hv+U3Rq7bvdbcYUQjiG0qfoc9C7iqPJYR81538+9e762bjtN91iyHM8+39W cRI4zJJ7Z3WPhxCwcFzMoTUAsBK9daoixN1d1+G5Ru2klhVJzTfCTkG7npAVaabCTbcyr2ABAmq AjAE0OJL+oLs9+yBvGze4qP8ZIX/bF36g0gEhT0c0yGxfCOURZfsU7cV1Uhky7znVrQgJw34vrD WwGw3TSOy8V5C4TRxDNqT1jkBi/UKHmw= X-Received: by 2002:a05:6a00:2d22:b0:77f:2f7c:b709 with SMTP id d2e1a72fcca58-7ae1cc5f5e8mr7330935b3a.5.1762405730150; Wed, 05 Nov 2025 21:08:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcvDhrmBVPROt+wlrWa8IJlto8+biiFvtqHVaANPX8XnmNXEXYFFqELu1OvtY/577w190x3g== X-Received: by 2002:a05:6a00:2d22:b0:77f:2f7c:b709 with SMTP id d2e1a72fcca58-7ae1cc5f5e8mr7330892b3a.5.1762405729612; Wed, 05 Nov 2025 21:08:49 -0800 (PST) Received: from hu-ekangupt-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7af7fd5238csm1185862b3a.17.2025.11.05.21.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Nov 2025 21:08:49 -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 v2 2/3] misc: fastrpc: Update context ID mask for polling mode support Date: Thu, 6 Nov 2025 10:38:38 +0530 Message-Id: <20251106050839.3091707-3-ekansh.gupta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251106050839.3091707-1-ekansh.gupta@oss.qualcomm.com> References: <20251106050839.3091707-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: ct97GGwYZUP-MnYPvdaUdeq822m-K88s X-Proofpoint-GUID: ct97GGwYZUP-MnYPvdaUdeq822m-K88s X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTA2MDAzOCBTYWx0ZWRfX3CXYbZnxzNsT b5fFAJodUt/zrjPXncZ4poga7pw6Q6yc+5ed4wm42l6hE48h0egqR0AorvJP+Af1qBeTI54RozP 21HsIejiWYuQAQTuScIzWIfxlRqwhoiLM76+VWLLSgCFvjr3o1ivYeIyuj55nPK48cWnhbBxsbg G273um9ULbPWfasb5vNlJe+lIkqHY9AFHvSZ/7QIiKNZMkHHp/Jdf/+aoYR62nwqdLUnFzZgmHZ N2WO31XVcU92OWtlwgxIMgCb/vJuPyofQa3waTQf6RtazoVnCK4uGBc4mkftPytqfDqfCy0x/h3 WU/fBnVhsZP1ujigLCpkhn/gVjTRBBle108QdR2JChu5q5nNeITLKJyJccOKRqF6+5VSCNWc0jL qHsTnpn9Eljbhlc1gFnvk6Z0pu4yjg== X-Authority-Analysis: v=2.4 cv=ErnfbCcA c=1 sm=1 tr=0 ts=690c2d62 cx=c_pps a=WW5sKcV1LcKqjgzy2JUPuA==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=eMrONWwZx6N8dQ6zNQwA:9 a=OpyuDcXvxspvyRM73sMx: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-05_09,2025-11-03_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 clxscore=1015 adultscore=0 impostorscore=0 bulkscore=0 priorityscore=1501 suspectscore=0 spamscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511060038 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 Sun Feb 8 18:57:34 2026 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 E59142D94A4 for ; Thu, 6 Nov 2025 05:08:54 +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=1762405736; cv=none; b=ZDKhBZn6YTsCyZAF9BfBmkTq9ZjRcNWp5kT3AT1aBqj52AK2wt1laWt/Vc6GWcgouYB1I+M2ikBrV1BpCbd5vxLpbcOylXg692mjB/xHA9oLD0sCe05JXL/QyHFotzt7R7glylJqsVxkvZQn8KEZMcTqQY0e/d1iGJe4TeAGE8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762405736; c=relaxed/simple; bh=oy+K6ekPn6Jv6VXcs3v3ti0u6RkSGf6yS+Ce36zFuwo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tadaYJZW56ZsGutVJCESH0f0O5+obXP/NjwIkgIYZku7Nb38Bs7klUKoxjK9cWmxYms9+asTD2TL3ezswsNehMfIMgCApZyVY0NAhiOKiQt8NpGw8QNZH+PyMa4Mr+Aze5q+mcf/I5tHWYcczFBnPIIiQ35+M3ag4KckNwX7XQQ= 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=Z9hKH8Ti; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=AP2D9nNC; 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="Z9hKH8Ti"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="AP2D9nNC" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5A5KFAZA1657014 for ; Thu, 6 Nov 2025 05:08:54 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=+RE3hZYUs1r vlduAgjzrIfTd74BQra1K1AtJtAWfdgk=; b=Z9hKH8TitA0NqrIxfavU18pjFyx +HzDvM/zOeHljPwtzeVzflBv6ngQGW/TYn7vT2ZnxsJMnj2ZseKkXEfdUrgB48ut WuDBLf5T0bndSH7pgR8huOCY/SfBMQOitzmFseu8VhJFGcXQkXV+1A7/d3o5c5h9 +zOMP9vH7/vGiuxhNgv3m++GUZdJV7ZbxSlVYaWAYdOSZGwRPG7c4dcvBhaUhGvj 22h6tQP+xubSa/mrC86UUND5InEtvTHILSV/B/Jv9ok+9Z2TZgFZuMBQAlSjtl/C p+XA6Cv+zylmGwH63OBLDDYRUlG1aC6g1690CovdE3jtN+tWK3U8bz2/WBg== 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 4a8831adwc-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 06 Nov 2025 05:08:53 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-33bbbb41a84so108820a91.1 for ; Wed, 05 Nov 2025 21:08:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1762405733; x=1763010533; 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=+RE3hZYUs1rvlduAgjzrIfTd74BQra1K1AtJtAWfdgk=; b=AP2D9nNCJNp/yGMfVxcwQE8zdTtfM3ATnTor2MCANGVkw5k4etvHEt2A1b7YUIeNIA DmvRmFWDyWpfd1l7WEh19JMPkwlkVoVrrsEZ95zLFSDiv9PZuJdFLZBtjz5qpkkN53n1 eE9otKIFGJXTrHFNBh5vkipmtjwuywNUZnWOTd5eBOJWhvDBnUlgwqMsPV5G8XlSPExk Ei02FAvbQhwq4X9/q6u+gu8pqH1zCYxy89rxJmNVb0iy1xMeNgo4fRXBRoB2nhuKaKBP pZqfkdKrhF0Fx5dbSggYLpD6zYOQyM1yAilHfNMJDe1FinCAMIZpKkmKozvwbIb4gO0U +CVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762405733; x=1763010533; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+RE3hZYUs1rvlduAgjzrIfTd74BQra1K1AtJtAWfdgk=; b=iar1SIL5LEXi/DgfbZctaC3X2ZvhmvH/Ce3rdptUf+EKfGoYsJCryIHSHBxnAuKMwK wyROaTVQgGbB7Ur/RdbijGxURgFxGQfS8a2ylPR1QU6zs2Sd7Esg8nBttyMkyLKDjOuf cX5gzqZzFpfyZLFBJ8HYNFFo2f0FMEWG5uGk7RtOZtf0DH/xIefqrVxUC4ScoBZ+Bfzw 2ZpOuZN5ovjehqRYHSpjIHcLKDSEk/K625yNu6P40HJjTYX7XZIJVNzRzdCmCvKjEpE2 /GCDY/BWEol4MUK1eN1MICmo/yjcwrQDOgRjhprdR13j8avdhWwq376ymvlwahRqIzdJ ug9w== X-Forwarded-Encrypted: i=1; AJvYcCVbgM2McCD/nEZkS60CazyKQlhKogTCYt3Ef6p2u5+rJraO6Ttq95y7XIDqZhnFDXLBQBIoYsG8AUQDH4A=@vger.kernel.org X-Gm-Message-State: AOJu0YyeHayYqC+MvUB815Jl2DiXl/c2E0ohVrWLSpqGDveiunYwAHzF FycEWMp5Tnu3kswpkjBGFuVV1o5RoarPGHNfzfZC0M9uMSQqnb7QqbXFAIkPhTyRbXIRbGkbsR1 1hniHMchLep2uiZhgWYtn+HewszorkGkqFOIjRap7ajCIJQWxgpKq+Zpz8dr7j22fY1w= X-Gm-Gg: ASbGnctCDLAUmJEkFhIhW0o3W+FWCyPm6bDa3I7uwhTq+OCtAY6C7Vld24uVyyV8tTE bQQ422g+hSbR3Gm+o7M5e/bJy+ag0nRc5HVbcPsqOxHYR+WYZDorTLuKD38zTHxFMyp1YJWfhs/ QPtNrTASrO9oLL2vv0ri8b4klW6MokjRL4XF8Xf6ADaSXtjQIwWCSve09yOFa/xrUryYMtf4lHg 0Q2lCS4YX9I4Lcg4xbpE2YsIfZrgDWtwcNOkQpMmudpeYWOz4yFwQn6CljJM19S4+LCHrgNMHcf v5G1G0ta8k5LHt2FOZY+3ENVAHJbzXLyFdFcJog/TGQJ6Nqgf6LHztFU/DKqzp1Z1a74K5zOeBI PSKNMvtN4IcD8y8rVQy7RPfIdtavsS/o= X-Received: by 2002:a17:90b:4a81:b0:341:8b42:309e with SMTP id 98e67ed59e1d1-341a6e05f1emr6654251a91.31.1762405733212; Wed, 05 Nov 2025 21:08:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9BLTBuIpf6OX+6TZe3Qc6Ptfo4VSG2q3rM8rq+hGH7GasRpAb1jgAO7HR8w8VZIT3/b4xHA== X-Received: by 2002:a17:90b:4a81:b0:341:8b42:309e with SMTP id 98e67ed59e1d1-341a6e05f1emr6654224a91.31.1762405732701; Wed, 05 Nov 2025 21:08:52 -0800 (PST) Received: from hu-ekangupt-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7af7fd5238csm1185862b3a.17.2025.11.05.21.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Nov 2025 21:08:52 -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 v2 3/3] misc: fastrpc: Add polling mode support for fastRPC driver Date: Thu, 6 Nov 2025 10:38:39 +0530 Message-Id: <20251106050839.3091707-4-ekansh.gupta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251106050839.3091707-1-ekansh.gupta@oss.qualcomm.com> References: <20251106050839.3091707-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: 5EqwpbBtRVHhLMXhpKDL57inlg8dcSfw X-Proofpoint-GUID: 5EqwpbBtRVHhLMXhpKDL57inlg8dcSfw X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTA2MDAzOSBTYWx0ZWRfXximJiM1e9Cp4 0gl+uttZSyIZIIBDV/mhQtQ3iEb4vi2fbytdJhNf0W8p4gtHf7VktcYCJuWXwmmfhaHDZa7JiJT tTIJbt9uyYL2Wt7loVGQdeqYPd57xXgYget5b0Af3XydxQYPSUqzQlwwptqBvVRf2S7cPbupncH JEfmO+09oIhxhhj40a10vF+tWCDt90HMDa8OPDtiStATQRlYvFvpAe3lo1uDXTcSs8k99sxPQ7I +TWoN+tq8RjIxM9yk1WbhM0BEOQNgXcHe9w7DhafFrPzTlyv1CNwBbhjN9BLJ9696Rc40Q/jKSw jc+nvlzlhSRKfRFEBMckL3yVZJBArF1IsHYSFcjTgyg3VoWdO1VKpwirX7MJS0W4/myXdEJz5Eg y3EpnSQWASNEL+vGFhfdf+kRV/MPcQ== X-Authority-Analysis: v=2.4 cv=Mdhhep/f c=1 sm=1 tr=0 ts=690c2d66 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=TEHdEMHTk_fMHrPBF0kA:9 a=uKXjsCUrEbL0IQVhDsJ9: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-05_09,2025-11-03_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 suspectscore=0 spamscore=0 clxscore=1015 malwarescore=0 adultscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511060039 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..c3ba22f094a0 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, err =3D 0; + + 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