From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B234E63F06 for ; Sun, 15 Feb 2026 18:22:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E2ADC10E376; Sun, 15 Feb 2026 18:21:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="JuWDinaw"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="YY9icHVT"; dkim-atps=neutral Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 084B310E375 for ; Sun, 15 Feb 2026 18:21:58 +0000 (UTC) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61FBlKHb850451 for ; Sun, 15 Feb 2026 18:21:57 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 4cb6bugxqc-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-2aad3f8367bso29062225ad.0 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=lists.freedesktop.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=YY9icHVTLLm33d0WQH6nWd7ALp/wBJEsAJmTWO66H/N1azBxzhizuZ4E/ZYWJmsC+r ZekEPbrZD98+klHunogwduZdUovo58tk6ij3gCHROQwXfA9UKWw4OoKQYLwcXzcKnW16 70RWQ39/CMjn+parQZgsR9Glbcqj6iRFuFreY/yhNGpS10UWzuZ0P0svDjm/D5aOIIkG VAc1fqHkPY2LNIkL2kDaKdfEfLeNcP6eioEvZotuHBwZ9Wu7SkBHuLpuCNWBF7H8yxsu quDwtR6DNUnz/yQ7+MWT5/WmJmv9XVNsi4FmhAsTxriCkgwlxn5+KGOz4L91Gj48QU9a gzng== 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=WTe3nhBTww3xHAm20NMjOccEKM91kxYXKfnoUCD/3CNDCQLYtSzedGN7q7R+RsV5t6 oTro+MpuECX0lkRpjJjfcHgKeEhaz8b5tZVxFIgZF0wtFNJn8erpI3dNEA/iP0cqSGSY Wv9o/cRM6NEWQLo0Xq3CU240xOH0uZM3Qge/wL77KZnRU+B82hAZC0mqe0W1BuI52znM jjA/LLGIVsAAODldoxJXOR/83iB5HSH5PkqOhmS7ltizY5nKE9jMrVi/r0mYookIAhbl axQIxP5zoiACljMBN3xzgpjPmWVIO8HvhoQ+HGO74s0ehu1naBxocu94KdTY0E4IgA4D gXgQ== X-Forwarded-Encrypted: i=1; AJvYcCVfgLAe9E21HVea071r1K/uQbyaPnJGHr1h0T8jce5l04pDERwo2EpRn3+cOneoA1Ro4JjN+82y7CU=@lists.freedesktop.org X-Gm-Message-State: AOJu0YzGvo3KaGuMtdmRxyG3ukc3TaSY62qhGRwrsqGZm01lsgxMJ3rY OQagqYdfF9OQ/9gErH+8IZTxk/1RDDZNiP6j8otB4AowocaS1pNF/uDmPRNTL59b678Cgrb9iml IvF5A+wozUYs5rIYqiDy3nATePyz88OjLqslVY7RJqZPuukZZpgbwpc2tKuckK6dM3SfNCks= X-Gm-Gg: AZuq6aKu5d9oeKssF8akLRRRlW/lw77LsAp++ZADWD7XlXNKYwtpg2Cz7dclqmy6Rbs TwCSoZR408/PJnnKHgF8/mFOqHnSMlSUg9XiFF6mgxjE+sBxbqXOsBHFyEbyGbr/ltvrybrysF1 xYvjsqUvuEhloP9y5OnSIMpremUK9gX3Tp92YDSVvbIV17cFqU4dJfER6QHDwLCcMJkoysFG/ic QQdT2o1w3CEUoo5wGl0+Jo0VRzKt88onc/3g6TyJpnRfe8kCncNlPas34QgtrdBY2M7tKUgw/GM cPIUnR7DhKCCJGHUJDulTKm54BGmvheLfvfQDrtODJPdAisra/rL3qBSxA8JSWlSMAAof5iy7gr 4LMz9jy9Dqf6wg8qLmhUrPzoJ3R0mFg1F557sNlMoXxFKRGVWougc4Q== X-Received: by 2002:a05:6a21:7a97:b0:392:e5eb:f0a with SMTP id adf61e73a8af0-39483a3c323mr5039727637.75.1771179716719; 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: jxQGIhMqQDvJBYg646x6U22nPCtG11ep X-Proofpoint-ORIG-GUID: jxQGIhMqQDvJBYg646x6U22nPCtG11ep X-Authority-Analysis: v=2.4 cv=M8dA6iws 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-Spam-Details-Enc: AW1haW4tMjYwMjE1MDE1NCBTYWx0ZWRfXzVzkha0EqhIg ebhQ+UwbYryX+HcJRdVGLbvVJAe5pqBWefZlq+awOvVosBCBpASymh2ruYFtNBkDhK3iEEUeXF9 yVS+Jkdd7k1NyuJvpK3pIj4935Pqn/Ng3n6idUoB8yHxIAF7nhNFTGxbxJtD7RIo9sSciR3/vKR Sb9izemm0LJSjjDrgVbMOopeC/0aU7cjFwuJZod48DETrVWSSlPdfKv0LSlOCIqLxi6yyO9PurX iTTwj+xRKctTIfONRnr5fc6ShuoYSsjYI8femMYJwgP153uX1rR6hrsj7BCFlcoFMH8PQjJB/wX P8EsyvcNJaJufT1Ot068qhQ3SE0obkk6o4YX4vU/W/Eja7HphM2Xo01lo/LRL9iSpTdqgj2no0n Ll9V3rXEI+pzZVjCsBhoOlzu10qRvEnMl1/JEAY8UUZBjDwurwXjwIw28ZB8c5QwhZsYz/9nOiB Xc1lhCILs8Pt9qjDPmw== 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 spamscore=0 adultscore=0 suspectscore=0 bulkscore=0 impostorscore=0 clxscore=1015 phishscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602150154 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 #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 @@ #define miscdev_to_fdevice(d) container_of(d, struct fastrpc_device, miscdev) +/* 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); return size; } @@ -1020,6 +1038,9 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) list = fastrpc_invoke_buf_start(rpra, ctx->nscalars); pages = fastrpc_phy_page_start(list, ctx->nscalars); ctx->fdlist = (u64 *)(pages + ctx->nscalars); + ctx->poll = (u32 *)((uintptr_t)ctx->fdlist + sizeof(u64) * FASTRPC_MAX_FDLIST + + sizeof(u32) * FASTRPC_MAX_CRCLIST); + args = (uintptr_t)ctx->buf->virt + metalen; rlen = pkt_size - metalen; ctx->rpra = rpra; @@ -1188,6 +1209,75 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, } +static inline u32 fastrpc_poll_op(void *p) +{ + struct fastrpc_invoke_ctx *ctx = 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 = read_poll_timeout_atomic(fastrpc_poll_op, val, + (val == FASTRPC_POLL_RESPONSE) || + ctx->is_work_done, 1, + FASTRPC_POLL_MAX_TIMEOUT_US, false, ctx); + + if (!ret && val == FASTRPC_POLL_RESPONSE) { + ctx->is_work_done = true; + ctx->retval = 0; + } + + if (ret == -ETIMEDOUT) + ret = -EIO; + + return ret; +} + +static inline int fastrpc_wait_for_response(struct fastrpc_invoke_ctx *ctx, + u32 kernel) +{ + int err = 0; + + if (kernel) { + if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) + err = -ETIMEDOUT; + } else { + err = 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 = poll_for_remote_response(ctx); + /* If polling timed out, move to normal response mode */ + if (err) + ctx->is_polled = false; + } else { + err = 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_user *fl, u32 kernel, if (err) goto bail; - if (kernel) { - if (!wait_for_completion_timeout(&ctx->work, 10 * HZ)) - err = -ETIMEDOUT; - } else { - err = 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 == USER_PD && + fl->poll_mode) + ctx->is_polled = true; + + err = fastrpc_wait_for_completion(ctx, kernel); if (err) goto bail; + if (!ctx->is_work_done) { + err = -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 fastrpc_ioctl_capability *cap, return 0; } +static int fastrpc_set_option(struct fastrpc_user *fl, char __user *argp) +{ + struct fastrpc_ioctl_set_option opt = {0}; + int i; + + if (copy_from_user(&opt, argp, sizeof(opt))) + return -EFAULT; + + for (i = 0; i < ARRAY_SIZE(opt.reserved); i++) { + if (opt.reserved[i] != 0) + return -EINVAL; + } + + if (opt.req != FASTRPC_POLL_MODE) + return -EINVAL; + + if (opt.value) + fl->poll_mode = true; + else + fl->poll_mode = false; + + return 0; +} + static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_ioctl_capability cap = {0}; @@ -2167,6 +2291,9 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, case FASTRPC_IOCTL_MEM_UNMAP: err = fastrpc_req_mem_unmap(fl, argp); break; + case FASTRPC_IOCTL_SET_OPTION: + err = fastrpc_set_option(fl, argp); + break; case FASTRPC_IOCTL_GET_DSP_INFO: err = fastrpc_get_dsp_info(fl, argp); break; @@ -2518,6 +2645,7 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data, } ctx->retval = rsp->retval; + ctx->is_work_done = true; complete(&ctx->work); /* 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_option) #define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability) /** @@ -67,6 +68,9 @@ enum fastrpc_proc_attr { /* 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) + struct fastrpc_invoke_args { __u64 ptr; __u64 length; @@ -133,6 +137,12 @@ struct fastrpc_mem_unmap { __s32 reserved[5]; }; +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; -- 2.34.1