From nobody Fri Apr 3 01:24:22 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 DE25024A07C for ; Sun, 15 Feb 2026 18:21:58 +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=1771179721; cv=none; b=Hkk8rsWrHrP78Y3ilsv79VznbEfMpw3K3nlIXpbDAae+1Ab/BSmQxcvjfUF0S6khKx+0Pu09W8eFy95k8WqpE3Qe9AsdLnLM35ftIXMZKlkkVLZn8qZcYsttQ9iNDo2lyjZF6Rv3W5OBawOqi+0MHPIH+1heyXmCzOKE9ox2HFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771179721; c=relaxed/simple; bh=STY/1vpCxJE+Z5mXhfQq3qbVCUwkW8XKChaHH3/w+TQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eJuZffyXQeKueN/v19Pg4UrbuK0+SSH8psEift7ipl42q/ePqPxUuXGp2FZbKIANsv3Koqou6fqhkR1nd5C2rGRMr9r811JsLXQvWv9ZLw3Z9wcA5son3iPBGnG67hqX88xXTbAVR8rNzST6Oam1V682cKxjYAjiPr2bN8bOXVs= 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=JuWDinaw; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=Gy8WGiEO; 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="JuWDinaw"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="Gy8WGiEO" 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 61FGNlOc1628544 for ; Sun, 15 Feb 2026 18:21:58 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=gGsuTZLqUpw Y7hBhRIBjA23F5oruK4sDevnmC00HExE=; b=JuWDinawK4rIemrbhe67N3ndm5I CCQm+M1r9uRXN3kY1ano5HhqIdcq3YXaVw+/4lmwFXR6gd/KuEj+9Yxn4fdGCwEw h3pBY8bthhkvwnfl7GmESir16JE7KzhmhVF5eI2XtJtadS4bt4zJXU7iUVNTq/0o TLREoi1inxSImpYi7zKN7ymmm47004gp16CzvkHOJOHIqSTBUanxRdOo30tS0bvm WsvFERx7E11HFNaqqSAJgbpZdQnNZPRRQoduo+WvJvbqSqNDPPnG7XLE/BO7f/l7 PwIaS2IAUBe5W8o+yqXWMz+1ASeYY2gRodU0/Bey3LeLIHisJB8j2GcmEgw== Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cahe62n5v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sun, 15 Feb 2026 18:21:57 +0000 (GMT) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2a7701b6353so32119915ad.3 for ; Sun, 15 Feb 2026 10:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1771179717; x=1771784517; 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=gGsuTZLqUpwY7hBhRIBjA23F5oruK4sDevnmC00HExE=; b=Gy8WGiEO34Boj3G7sT1xnf3FY0VxRnx4Cn8ovZ4n9NfUdDof7UFYzxCrSlce+Eqlti 2C9wJy1DOcaSBiVTRV1Bkx7wnlqFqSIKl/vy7+zwxSVc72XafOq6fW/XmcbTFMTxZzV8 pihs8Mg6A14K2/0flz1IrdtlxbHHPPa1vzavL8z1w6eTXf1uj6Fy0+KHrF6v+/tH01SI 6ywWCtic2O5ddTXQecWAD9jZV3uZF76XHlpubC9xHak3SCWT0rMYIDxMDwjr5zWgN4lw 6DZqDJO6njFwOTWWPb3ka8YOIlGgRf3U7FHzStQwCyymBNTwSbIbg2qW/4hr3ZlCuIXO JKhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771179717; x=1771784517; 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=gGsuTZLqUpwY7hBhRIBjA23F5oruK4sDevnmC00HExE=; b=uREHO63RJftI6EPIP6CFp4rRSEE81tb8W4mZw1Xu7MP8Mf+519qbxAmsw/sK9NRbIk zvIFghWsrhz3UHmVFgT+TmYOvzgjAQyHsUORIdU2sNW6+BsJpAX93pjF3l20lA/XuNrW 29fdac1kGjiXTokddcK8UEFXZT/W5/HydujcbyuD9KDOwk+jfgVxlF8NA87ZnjTfFCRF +374yuYF4m459Sa/USPA11QTPaC6uZF57AuuMUUBNiRzyTm8CwVXPowcBqLV4aL45LQh f+UHh4YZvZtjyJziHg9x/iAr8gJx9N2zV2A6xGz3zeQ82F7ypUDn3dH4S8rlqNeG6mNk pX3g== X-Forwarded-Encrypted: i=1; AJvYcCUDxxNxQLPL7tWNpa/q49M7ucKaG99GJEkMSjfA32CvQHsuOEEFODLI+pGubMpLCLdOFi7C5XiH4kFOCMw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2S6qppVWIRly7ZdlyWLh56iz4jkkY7oXYUIlDGutCYabhtqly +HHn/kdoJH9UtZhrQmLPIGOPOIWY5w4J1GvltpiwcC2TCqPZuWTyDZDnQOcPCSbR+uBq54XJ3LI iyZxDTil5hM3pzYng/10hzLoyNIhuhc8yD17lca9B4XhH4MVqPb07h0JFhEmaiEa/W7I= X-Gm-Gg: AZuq6aJ8ckhpiAbUbQcVC5moeuv59nZ33O9odYwP415mlx6RtWuxtel/thZZH+9S9s+ aV4KueLc/0aeo94wj+CTsBJWZUKCg92UkyVBreSAvdNLvi+HJwjBomoC99OrYDc1JAr1D4BaLmA GQpsrLmf6Jc2eHHrznSD9qcUQ0rh38RxL0jhVN/LemqHvTTNlfhDP0H9cjskeK4u7tQ9yRcDXy/ QIcc+rx+7mo4COYTXT0N0S0NHJF74K6mMe9ipTLLbEz0pJUltBglwhNfFaFo1mb7WpAgxyaSQ/I NOwjShb5diNlFNy2TxGXdI4fJCfrBq+qDc+74rOJykmpGYhingc4tQqGywQZGbePgwkvGftbEXZ 8hImowdq2pU16Iwnj+viN+6sqPNV7OgaFEGv/gMO7MiUz8fqMozF+0Q== X-Received: by 2002:a05:6a21:7a97:b0:392:e5eb:f0a with SMTP id adf61e73a8af0-39483a3c323mr5039728637.75.1771179716720; Sun, 15 Feb 2026 10:21:56 -0800 (PST) X-Received: by 2002:a05:6a21:7a97:b0:392:e5eb:f0a with SMTP id adf61e73a8af0-39483a3c323mr5039711637.75.1771179716098; Sun, 15 Feb 2026 10:21:56 -0800 (PST) Received: from hu-ekangupt-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35662e537desm17425381a91.4.2026.02.15.10.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Feb 2026 10:21:55 -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 v6 4/4] misc: fastrpc: Add polling mode support for fastRPC driver Date: Sun, 15 Feb 2026 23:51:35 +0530 Message-Id: <20260215182136.3995111-5-ekansh.gupta@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260215182136.3995111-1-ekansh.gupta@oss.qualcomm.com> References: <20260215182136.3995111-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-Authority-Analysis: v=2.4 cv=c5WmgB9l c=1 sm=1 tr=0 ts=69920ec5 cx=c_pps a=MTSHoo12Qbhz2p7MsH1ifg==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=EUspDBNiAAAA:8 a=TEHdEMHTk_fMHrPBF0kA:9 a=GvdueXVYPmCkWapjIL-Q:22 X-Proofpoint-GUID: deAS_iovSkiraU49ttU0N1I8zmezU2Ze X-Proofpoint-ORIG-GUID: deAS_iovSkiraU49ttU0N1I8zmezU2Ze X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjE1MDE1NCBTYWx0ZWRfX/wnMrDUK05MZ PL2OZL1fErWzUN6KM7b2l0lFlDlFV7Lzd6m1vXmPK0QT0lZvQfRrt9biKV4axLHnIgHU+xRHNFA 63JXmczyTaimsU9ZwgkwanwQ8JHXPFuKPazy7IyUKapesCFfFuaLc6R36XAjjPiu1Ds3Od2Be5/ OzpvtmwM8PN5Kt/DbrLpj+VrOi8OBdMIHKy6/ThTzQ5FmjxfRH97Pkq8I+gjacf9TmIrtFzXv8N SCrOA3wsGf+htx8S6zd40D7gkcqRBsZCLReqPfEyyWBaJFPOt2U3k0JdlD30NSyE78+PiNaL9rX Z86QTHrjAzXYkFcnvbYFrkWPExK0BLjZJOrFKckQOMiAjqBgq985fhB8IzDvVPMY+jIOTE0mSDN BK3UuuINYAMxQV4mGHwolDXw3zS7P7KTura2wV4IWspCaSoNgGngZAbsXfpg01+eigRp58QMCAP p+H54/InSBk4BMiUTVg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-15_06,2026-02-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1015 malwarescore=0 bulkscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602150154 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 using FASTRPC_IOCTL_SET_OPTION ioctl request with FASTRPC_POLL_MODE request id. Signed-off-by: Ekansh Gupta --- drivers/misc/fastrpc.c | 142 ++++++++++++++++++++++++++++++++++-- include/uapi/misc/fastrpc.h | 10 +++ 2 files changed, 145 insertions(+), 7 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index e935ae3776b4..c1e67dbacf2c 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -23,6 +23,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 GENMASK(15, 8) #define INIT_FILELEN_MAX (2 * 1024 * 1024) #define INIT_FILE_NAMELEN_MAX (128) @@ -105,6 +108,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 { dma_addr_t addr; /* dma address */ u64 size; /* size of contiguous region */ @@ -235,8 +244,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; @@ -307,6 +322,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 */ @@ -924,7 +941,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; } @@ -1020,6 +1038,9 @@ static int fastrpc_get_args(u32 kernel, struct fastrp= c_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 *)((uintptr_t)ctx->fdlist + sizeof(u64) * FASTRPC_MAX_= FDLIST + + sizeof(u32) * FASTRPC_MAX_CRCLIST); + args =3D (uintptr_t)ctx->buf->virt + metalen; rlen =3D pkt_size - metalen; ctx->rpra =3D rpra; @@ -1188,6 +1209,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) @@ -1223,16 +1313,26 @@ 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 */ @@ -1812,6 +1912,30 @@ 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.value) + 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}; @@ -2167,6 +2291,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; @@ -2518,6 +2645,7 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device= *rpdev, void *data, } =20 ctx->retval =3D rsp->retval; + ctx->is_work_done =3D true; complete(&ctx->work); =20 /* diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index c6e2925f47e6..c37e24a764ae 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 /** @@ -67,6 +68,9 @@ enum fastrpc_proc_attr { /* Fastrpc attribute for memory protection of buffers */ #define FASTRPC_ATTR_SECUREMAP (1) =20 +/* Set option request ID to enable poll mode */ +#define FASTRPC_POLL_MODE (1) + struct fastrpc_invoke_args { __u64 ptr; __u64 length; @@ -133,6 +137,12 @@ struct fastrpc_mem_unmap { __s32 reserved[5]; }; =20 +struct fastrpc_ioctl_set_option { + __u32 req; /* request id */ + __u32 value; /* value */ + __s32 reserved[6]; +}; + struct fastrpc_ioctl_capability { __u32 unused; /* deprecated, ignored by the kernel */ __u32 attribute_id; --=20 2.34.1