From nobody Tue Dec 2 01:07:14 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 DE4F72D7DE1 for ; Sun, 23 Nov 2025 14:19:46 +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=1763907588; cv=none; b=rNKcCmgvlsWiaZ7mnFjnzcCjP+wvV1nDOr1VuqWNL+dc7BPr7dZvyI4Pi86ncCMFUdaHMaedc7FM879lQ6Uc5UkbgJUkmufu2fBV6TFGSekGbKQjz3rQPrN/Amu15NLqMYg2I/BpwGjf3An6wGfXI/qiAGawXa309FZjOeT20VI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763907588; c=relaxed/simple; bh=VWfQc5BZbIwnD7HFRfx9d6Vuelk597XYQ25h6fQm2O8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZmUNuRR5QQqHu/5Hde7QcJqJMv28eJMfkPaBu6jXxDz2bTsBxOC562tEahyNQFo9qdpdsL2shFasSlA82cFgO66ubX3D0+mjB/vyktuZUP7Nh/vi7bBCemvizxZMP6aKBjX9kyr5ZMSg6h5QpFdRTYuRBIQOwtNKWAkOADsPmv8= 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=K8Kp3vqO; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=ARIYhOQd; 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="K8Kp3vqO"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="ARIYhOQd" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5AN9cEjq1076440 for ; Sun, 23 Nov 2025 14:19:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= cI76CvmHHMELmH2oLlkSsdIIMgj/IOI288biHSI0Pxg=; b=K8Kp3vqOf6Q/Wi7o j/7e4cvLjAfePEHHnSKTOWR6nCs1v9sdiJXiSAQtg4SmF6I1E/7yiGBrdwqoOF9S 8/PvOZ2U9mcw7xVtFuZX1JZNFI3j8CijZeycjsnIF3fxzXhuEJGycBnfS8F+qvPv lPWki36DZNZmqfw8f/9VcgQUxEHnzkV+p6LIXeBC4R3TTngQkx995Q0DOd7KvLAj 6r2Bxbpt+JvBQP7O8GyyC1yL+oxjtJJ/Zu6g7arcZ8gtuU1AXFRbwrZFQjY/AwKj Y4/e0NMD92ATaYfMXo9xCn+I/AA+lxZhnVkKykL7fKAXLY9nLT1nJxg1yAJw4rEO SjFwGw== Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ak6a52ftm-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sun, 23 Nov 2025 14:19:45 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-3438b1220bcso3886807a91.2 for ; Sun, 23 Nov 2025 06:19:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1763907585; x=1764512385; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cI76CvmHHMELmH2oLlkSsdIIMgj/IOI288biHSI0Pxg=; b=ARIYhOQd+BiRTaC2SQHzlRUOFH20JGMpj1Ael3QByBiNfpctbwJZuHaAgNgz1K99/6 UaeOOwDzjETh/o4/6tmmdbHy0nujzanEizefOnLtpMYSz9LDMRRNEjU75+2/ZremqPs9 ZszKl98ZafZA25G/fnYrS5MjFbXNSDjwp1Dd63oj7pZ71S2J/DYJlj45m0UchLK6sVee JcpehAay+HdL28qhb23ynKAEIEjGzeCknVZ8Fc39DdpZz2iZu8B+aZw4qu0So0Be3YCm JrAR6Gw4DnzDgjVLNJDEa5qUhG2SMACn7XkixLdH0CGi8Pk2/uUHZ1x/V+Mb7jnKp5cr pBrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763907585; x=1764512385; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=cI76CvmHHMELmH2oLlkSsdIIMgj/IOI288biHSI0Pxg=; b=Hhh+fwbMXC2JEFpDnmO/wmSYupVZ0ub84oMuCCIv7oCkAorOY6bw+pBOTfJEX5Zfoh RMHnc4BdAdfo5NY2Gd32uVFxAvn6BiaTVbZzEY2Be+3Msd2uES5HRG7qzVmKuEIZA7gj 7wqqCUBjelku5PjC/NcaDZe7Hz92WkVkXM682/Y1jqfEXcDro+G2JhOH3ZvFxl43W8o2 2hznPLai6UuZtajpU3hGo4tEkE9Lg1DzrEubBgDNBlvDJVIdQDt6gaaGlbv9HFpm+Z6h kASzMWIvMq5eEoxjzQPcUurmfwUWznY25UvjaZ/vZBWEGErB6MWbQnY+LWJNJyKACnVC 3QCw== X-Forwarded-Encrypted: i=1; AJvYcCWEu6QkCmLX64OBLmfp8O2TmTLfzp5Qekw6oVqd8jX54VpvkzJt2iC3SUlYT1JhrgowIuszO6Jl6wKUtao=@vger.kernel.org X-Gm-Message-State: AOJu0YykYJDFTVg+SSjqbzbwoHYsTBd+CDeS7oJio1gSWdHRx8cWVopt ZlxuaqrxrjwMwlhF1X54ScE3UY0fORxLuDFUfjJe7Xd4b5qCAPq4db14/8uVZz0WY5tAsK8daZI x989hHf69qxJ7wsgyvfOjenJjjJUOoQ1uaAUvs2+3QzZTPo59crweG+Izjo32cFQUVl8= X-Gm-Gg: ASbGncu//lJ/kqe7D/GSmtQbtcZFxZ5dSgFoPJhGlNTqHQs7s/VpQyrY4nKdoEBzKvC ppCZWPKF9qH97x11XmfSR9yvXe+zUP79fzhnvg+yILz6P05/u/0hB6KM6dDAI9Rwg2VONBbg3R/ bhjyAEGaYXTpbP8Za8A9bXpGzum/cMgnpjwCamvFxid7LV6sYkQiaafzTt3myRQ1XtGQd9MRFn5 xTeYWaD0qZm5eOkp/36AppDkMqMSQmEhbFXvIJwpIRrfErmm+u7mL9Ie9/uvwojPV+G5jRAQMDw zAKh5l0MJ/nq+RvdR5gUnmpBaEKwR5JPf9VlLGnIyHs5jsQPSQMN3WXPBIvsAGA0yRBCHciRDjO 4Y85B6VUQZETBDVrin2uFItrCz73avMoT+/yu5Fcszp1pqA== X-Received: by 2002:a17:90b:3841:b0:32e:a8b7:e9c with SMTP id 98e67ed59e1d1-34733f3d1ffmr8017761a91.29.1763907584758; Sun, 23 Nov 2025 06:19:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHa7GoWiQzcPIOP1Al9nvBo7LmLvBsNdSNsbET1/efKSwpai3tKC85VypYSqMq2KwEYy6/LgQ== X-Received: by 2002:a17:90b:3841:b0:32e:a8b7:e9c with SMTP id 98e67ed59e1d1-34733f3d1ffmr8017738a91.29.1763907584197; Sun, 23 Nov 2025 06:19:44 -0800 (PST) Received: from hu-spratap-hyd.qualcomm.com ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-345af0ca952sm10135992a91.0.2025.11.23.06.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Nov 2025 06:19:43 -0800 (PST) From: Shivendra Pratap Date: Sun, 23 Nov 2025 19:49:31 +0530 Subject: [PATCH v9 2/3] firmware: qcom_scm: Support multiple waitq contexts Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251123-multi_waitq_scm-v9-2-0080fc259d4d@oss.qualcomm.com> References: <20251123-multi_waitq_scm-v9-0-0080fc259d4d@oss.qualcomm.com> In-Reply-To: <20251123-multi_waitq_scm-v9-0-0080fc259d4d@oss.qualcomm.com> To: Bjorn Andersson , Konrad Dybcio Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Unnathi Chalicheemala , Shivendra Pratap X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1763907576; l=5927; i=shivendra.pratap@oss.qualcomm.com; s=20250710; h=from:subject:message-id; bh=MTXV4biGU2m/VveAT3FCxiawD238PKh6quPNNW4oQ/0=; b=r0K+uUCt9prvD89u74QQb4pqmbw/Wt2eZG/ok1/ukzrg/8MfzQCK/U39LmJ2WrDazpnOhH8N+ veig/hOeJtrCZwl8xQaMM7ghWdx1oJPCsBxnoIJDtacGdnjKyuQ9TbC X-Developer-Key: i=shivendra.pratap@oss.qualcomm.com; a=ed25519; pk=CpsuL7yZ8NReDPhGgq6Xn/SRoa59mAvzWOW0QZoo4gw= X-Authority-Analysis: v=2.4 cv=Hup72kTS c=1 sm=1 tr=0 ts=69231801 cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=IkcTkHD0fZMA:10 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=QwukUx79tW4PgYOutgUA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=rl5im9kqc5Lf4LNbBjHf:22 X-Proofpoint-GUID: 679ohVmkC-f2IUabPeFWsCWc3TuyjC1R X-Proofpoint-ORIG-GUID: 679ohVmkC-f2IUabPeFWsCWc3TuyjC1R X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTIzMDEyOSBTYWx0ZWRfX4vaDxhyxHCeb pxjSqdYaKs2BQQLrsN8SbVQ2VyTMhE75o3lmZLBEYFBEEfb4EzpUhSQ1AyTfQYm21mphNFFDCdc joWwEikgoVUk5Dl+o45LJSg7qbIFOYPewN93HVrC3orVyA/9SoNRpuS/Zf1ADbeVBqpGPgJk5KE 7rg7t65QchzT9cAefuMLZvqZetBWsH1Jg7FJkOTlZPinhyjBmmC8CWeGKA+FP7LQ5jJEgD5/oph iaoXn1IlfXZmvqizDcANCBW9RNoqddciqML2qyuR1pjQjGp3ALo5sOpzZ5E8/QGwwpogMzBY3B5 TxAR9om0UbjYDFBuskQkijcYAc5HSb77hGjLOaFChe8LDQMRtVX8/68QLQQ/meRUosi7+9AJVV7 hU2zVkbPhUTv7DuriLZFUhVs5VYsJQ== 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-23_05,2025-11-21_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 phishscore=0 spamscore=0 clxscore=1015 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511230129 From: Unnathi Chalicheemala Currently, only a single waitqueue context exists in the driver. Multi-waitqueue mechanism is added in firmware to support the case, when multiple VMs make SMC calls or single VM making multiple calls on same CPU. Enhance the driver to support multiple waitqueue when support is present in the firmware. When VMs make a SMC call, firmware allocates a waitqueue context, assuming the SMC call to be a blocking call. The SMC calls that cannot acquire resources, while execution in firmware, are returned to sleep in the calling VM. When the resource becomes available in the firmware, the VM gets notified to wake the sleeping thread and resume SMC call. The current qcom_scm driver supports single waitqueue as the old firmwares support only single waitqueue with waitqueue id zero. Multi-waitqueue mechanism is added in firmware starting SM8650 to support the case when multiple VMs make SMC calls or single VM making multiple calls on same CPU. To enable this support in qcom_scm driver, add support for handling multiple waitqueues. For instance, SM8650 firmware can allocate two such waitq contexts, so the driver needs to implement two waitqueue contexts. For a generalized approach, the number of supported waitqueues can be queried from the firmware using a SMC call. Introduce qcom_scm_query_waitq_count to get the number of waitqueue contexts supported by the firmware and allocate =E2=80=9CN=E2=80=9D unique = waitqueue contexts with a dynamic sized array where each unique wq_ctx is associated with a struct completion variable for easy lookup. Older targets which support only a single waitqueue, may return an error for qcom_scm_query_waitq_count, set the wq_cnt to one for such failures. Signed-off-by: Unnathi Chalicheemala Signed-off-by: Shivendra Pratap Reviewed-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm.c | 76 ++++++++++++++++++++++++++++--------= ---- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_= scm.c index 28979f95e51fbee94b84c1570a4d88a76f72db4e..149c2ccec2a5ff77054178fa021= fd0b721d9f8d7 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -47,7 +47,7 @@ struct qcom_scm { struct clk *iface_clk; struct clk *bus_clk; struct icc_path *path; - struct completion waitq_comp; + struct completion *waitq_comps; struct reset_controller_dev reset; =20 /* control access to the interconnect path */ @@ -57,6 +57,7 @@ struct qcom_scm { u64 dload_mode_addr; =20 struct qcom_tzmem_pool *mempool; + unsigned int wq_cnt; }; =20 struct qcom_scm_current_perm_info { @@ -2247,6 +2248,25 @@ static int qcom_scm_fill_irq_fwspec_params(struct ir= q_fwspec *fwspec, u32 virq) return 0; } =20 +static int qcom_scm_query_waitq_count(struct qcom_scm *scm) +{ + int ret; + struct qcom_scm_desc desc =3D { + .svc =3D QCOM_SCM_SVC_WAITQ, + .cmd =3D QCOM_SCM_WAITQ_GET_INFO, + .owner =3D ARM_SMCCC_OWNER_SIP + }; + struct qcom_scm_res res; + + ret =3D qcom_scm_call_atomic(scm->dev, &desc, &res); + if (ret) { + dev_info(scm->dev, "Multi-waitqueue support unavailable\n"); + return ret; + } + + return res.result[0] & GENMASK(7, 0); +} + static int qcom_scm_get_waitq_irq(struct qcom_scm *scm) { int ret; @@ -2280,42 +2300,40 @@ static int qcom_scm_get_waitq_irq(struct qcom_scm *= scm) return ret; } =20 -static int qcom_scm_assert_valid_wq_ctx(u32 wq_ctx) +static struct completion *qcom_scm_get_completion(u32 wq_ctx) { - /* FW currently only supports a single wq_ctx (zero). - * TODO: Update this logic to include dynamic allocation and lookup of - * completion structs when FW supports more wq_ctx values. - */ - if (wq_ctx !=3D 0) { - dev_err(__scm->dev, "Firmware unexpectedly passed non-zero wq_ctx\n"); - return -EINVAL; - } + struct completion *wq; =20 - return 0; + if (WARN_ON_ONCE(wq_ctx >=3D __scm->wq_cnt)) + return ERR_PTR(-EINVAL); + + wq =3D &__scm->waitq_comps[wq_ctx]; + + return wq; } =20 int qcom_scm_wait_for_wq_completion(u32 wq_ctx) { - int ret; + struct completion *wq; =20 - ret =3D qcom_scm_assert_valid_wq_ctx(wq_ctx); - if (ret) - return ret; + wq =3D qcom_scm_get_completion(wq_ctx); + if (IS_ERR(wq)) + return PTR_ERR(wq); =20 - wait_for_completion(&__scm->waitq_comp); + wait_for_completion(wq); =20 return 0; } =20 static int qcom_scm_waitq_wakeup(unsigned int wq_ctx) { - int ret; + struct completion *wq; =20 - ret =3D qcom_scm_assert_valid_wq_ctx(wq_ctx); - if (ret) - return ret; + wq =3D qcom_scm_get_completion(wq_ctx); + if (IS_ERR(wq)) + return PTR_ERR(wq); =20 - complete(&__scm->waitq_comp); + complete(wq); =20 return 0; } @@ -2391,6 +2409,7 @@ static int qcom_scm_probe(struct platform_device *pde= v) struct qcom_tzmem_pool_config pool_config; struct qcom_scm *scm; int irq, ret; + int i; =20 scm =3D devm_kzalloc(&pdev->dev, sizeof(*scm), GFP_KERNEL); if (!scm) @@ -2401,7 +2420,6 @@ static int qcom_scm_probe(struct platform_device *pde= v) if (ret < 0) return ret; =20 - init_completion(&scm->waitq_comp); mutex_init(&scm->scm_bw_lock); =20 scm->path =3D devm_of_icc_get(&pdev->dev, NULL); @@ -2453,6 +2471,20 @@ static int qcom_scm_probe(struct platform_device *pd= ev) return dev_err_probe(scm->dev, PTR_ERR(scm->mempool), "Failed to create the SCM memory pool\n"); =20 + ret =3D qcom_scm_query_waitq_count(scm); + if (ret <=3D 0) + scm->wq_cnt =3D 1; + else + scm->wq_cnt =3D ret; + + scm->waitq_comps =3D devm_kcalloc(&pdev->dev, scm->wq_cnt, sizeof(*scm->w= aitq_comps), + GFP_KERNEL); + if (!scm->waitq_comps) + return -ENOMEM; + + for (i =3D 0; i < scm->wq_cnt; i++) + init_completion(&scm->waitq_comps[i]); + irq =3D qcom_scm_get_waitq_irq(scm); if (irq < 0) irq =3D platform_get_irq_optional(pdev, 0); --=20 2.34.1