From nobody Tue Apr 7 14:44:45 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 69A73366DBB for ; Fri, 13 Mar 2026 09:02:50 +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=1773392571; cv=none; b=T13lVfOaTkIgzABmsbLecsW97Ea+xQvKADIHFXXMUnhkLkDru2Xjp5OZ0IaoUo5vvaqumyAHGu7jBAypCjvnMB2anqv6GPgtdBUAAo5mrl82khLVfUrSZcDcVOeiU/ZsMOOm9iOihRO4UZXSrZmv5xZ5DMDEu59FBKd3jmuAdAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773392571; c=relaxed/simple; bh=ox7XkapqqQFv6BvdfowOKNWDnDUZ/ZoNrcI2LZNMF5c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mq0xVwYvv+cAmoYG/Vj5oroyrr65AVj+Kvbfi0kWWy6WZA9uC2S6SgTMtR9G5s7i3vWuCFs+hkCFZpv6MlitoyObhfOWmi7ro/k1Tcbw8O6oBXtLugRBsXkbPXI0u0b3XnLf98GpwFmhey5mJZ7hljkrOFxyNLEP2c3LbBU33HY= 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=SC9LSw+P; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=H16XmNy8; 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="SC9LSw+P"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="H16XmNy8" 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 62D5td8c1014895 for ; Fri, 13 Mar 2026 09:02:49 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= KfHNY/tww1SGJwd/uAbJYnDxS5kq3xHdkWpsLjKeguM=; b=SC9LSw+Pkr92IgIC eUAfSTWD7AroXI2r+zTnLCFrBOFwV+3MdubZVPXF8QAFiEgs+FGH9hGodsWdqIu4 +UH0xBwdBYjwB+EbV6jtY8h5CQMjLprrOLDrlbu+4NHCDcGyIo1Me8+apKjZO9+g +mwuHoLrXC73Km4HvIaPJAYr1cWQhbo2ZWjYAOJb7Gzvlo+tUgdOHZgIOHvhNZ6M q4okDNRhy3JOG81K6Um6JGJBbO+Yut1qWCx2PtZyEoEwWP7m3bm1rXm28BmeFmNV 8tvs70FlUGsxqUVJLr45q1YoDQDcQZaa12HndtfL9Hcbmu2j+NDMwTWue+Bvvn/y zIxQRQ== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cumvdmqd7-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Mar 2026 09:02:49 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2aec3f67844so14887765ad.3 for ; Fri, 13 Mar 2026 02:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1773392568; x=1773997368; 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=KfHNY/tww1SGJwd/uAbJYnDxS5kq3xHdkWpsLjKeguM=; b=H16XmNy89KHeRlnRR4yYI4GpxuKgsuLxerxsvX42uE3xx2xrWWTh5q1uk6jepiJEow Fnd/055Pa3XUkNzSdpn1F7MviDXSi5oD+fagzG/P1QFLMf6NOmmhEkTocahLpwKeb1AD YoeOIs61R/M5zvkR4rarZX72VC7K+B/n2ljeyjTTwSxa0R0crvxlPTdKH07s4zUYCa6y BHEKtVY+EKYFIvS5ZSL5Ye/zxsigT2N7EXMicoUZv6/SMy1UBOLCCnRMbJRCf78tX3NP 2V06excWi4RcWptjRUxGnrlnsUATX364U4tdNYq2rVBaNwOVDAsNMoO8iVTZ152Rmln0 gcuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773392568; x=1773997368; 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=KfHNY/tww1SGJwd/uAbJYnDxS5kq3xHdkWpsLjKeguM=; b=aIUthsF78SXJwpVXhXZmciIvLPnPTSxP4ZLNgs9TrbxEqd1AZAdwDsB28xiuhRrq64 hWByCW2kYj23KpN55OAyZ0v/v9U25XtXJIpoe0Rz+RJag4BBAWanhL3Tq8t8YehStdBH hs53Kbpo6yhKgboRK8NcRLJJj5YN/aCRIiautO06QNmg7XXpCPDHDbm0ocEy97HrwX5p jVI3OeFyLLYpZVhBXMRta6RE4agv4wzC4rdF4AebSyItH//EzBBEkSoREyfzpMSWtR7Q Ky1G61JOlKOAyZd+DwUICdU30AXZUud9bzp30RC989EmIKhSxRflDJLlMv0QvPQRDuJk Hudw== X-Forwarded-Encrypted: i=1; AJvYcCWPUz7EHnzSNgLWbDFRzH5Zw570I0PAbtytDvWEwJlChix0YQb6wGwZxH9MkzYj4X9zH0GdSvKlS+59X9k=@vger.kernel.org X-Gm-Message-State: AOJu0YwmWYYPtB8LXJ0gMkIZFT0hhUFxUNjYZcmVyHXluOq0iY1gUFTE VNwIzENn9Wjyty3YIN8rHhfbUwG7Mv6sliUHnr7iVhnlHlESjceI7fhBVTquD6rNf++pzUBDsCY BdOFXNSmmg0+xSLPQmD3BWgv73TBUw/KxmvbzjXygArky2bs5qQrKiZ9nyoWJrd3t+YQ= X-Gm-Gg: ATEYQzyF/dBqtGqNAVMiekBlqJi9mWO+YMF97anH4QMBF2WPb8KXa9IEbg4AvJPE3ua f5XdBXlVk2kuaSyJeuUQvQJYFuXBzVixuLON4sxMgnvzq5f9YdCkEHT7bgEedtCvasVxhAYHpio iddnXRU+X/I5fDW1XkZ3pTg6qRpemGhmPgE0ErJpi+xSMfALBhI7rusHDeeCDTVq3EeoJvjVtFg 8+g2p/mKO4bR6AWnpIVu2MH2I6gbsMVftLOiBfmBhMHPXmJzvHR5WvmF27Kwl8+wNGz0xlQjJKg 66lR48nJPTpooGFeFeS43wTPs58HMaz689OAp8GkVhEArlf1bLKJmmgcohR3Jrw4/4V0DUyKPDT zbiY2rvJ9aDE3n87rzJnBEmdb1FZtzqTt2u9JMQeZuSXsRWodTUkGoVIPkh7FEh3hwv1gAbemX7 GZ5CRYxjbh X-Received: by 2002:a05:6a21:d83:b0:394:5463:7330 with SMTP id adf61e73a8af0-398ecd72c68mr2109268637.51.1773392568060; Fri, 13 Mar 2026 02:02:48 -0700 (PDT) X-Received: by 2002:a05:6a21:d83:b0:394:5463:7330 with SMTP id adf61e73a8af0-398ecd72c68mr2109233637.51.1773392567520; Fri, 13 Mar 2026 02:02:47 -0700 (PDT) Received: from jiegan-gv.ap.qualcomm.com (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c73ebb9ed44sm1269275a12.34.2026.03.13.02.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2026 02:02:47 -0700 (PDT) From: Jie Gan Date: Fri, 13 Mar 2026 17:02:05 +0800 Subject: [PATCH v15 2/7] coresight: tmc: add create/clean functions for etr_buf_list 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: <20260313-enable-byte-cntr-for-ctcu-v15-2-1777f14ed319@oss.qualcomm.com> References: <20260313-enable-byte-cntr-for-ctcu-v15-0-1777f14ed319@oss.qualcomm.com> In-Reply-To: <20260313-enable-byte-cntr-for-ctcu-v15-0-1777f14ed319@oss.qualcomm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Tingwei Zhang , Bjorn Andersson , Konrad Dybcio Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, Jie Gan , Mike Leach X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773392552; l=6645; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=ox7XkapqqQFv6BvdfowOKNWDnDUZ/ZoNrcI2LZNMF5c=; b=jVA1wfsLfdrODOSjsqgCmf1D8+mwe9eT/Kky4CgBmEZDCatvdZiCN1CHUu35Cn59KBw2jJTTV AC264ehcxqhCBP6JFlpVFjSpmslS4XD6tDutbSP8odsSWJIjKfGomAo X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzEzMDA2OSBTYWx0ZWRfX8dsoRRVMTWpM SYcRCICVpPeuXMWykFmIjwAWm1NbeEko+d7uEw+3q39iZFYppWtsn5WEfRfmq00SfTmGGFITahH fPqyIZRXG7sB3JuwLd+0sCZiqDEiLYij5wv+CIQpEVqgg8kaQZwwOwXJG9RrHyGrDhmyV9KXo2G vAfhJewNzq/Gmum7zOnPS0NyKyxyfROef99dGUmjqYJDJUgHzYw/sx90107pF19vN8QSt0xJESm Ul0QARzbuyHwKwqf06jfUw4C9MYqfsAC4rJ2FEpIPVrpCUxDsZZ/tntAIsbj3sy3SDdihdjjEc5 2eXwAU/7DpRHIpjVYN6jb8DTJTMqp4RZAiRQSP1Fdl05+eAKJiX5FZMkokeoSK0SJp2dZyyoyDh VutPivdF4RQafZX5LYAlgpRkF4Ige2x5eaHn87UsTgi5PsQwfMsFWfFnxFNe60dPiX4TtdGnKGZ 8qAzAwTaSnvCJqqHsAw== X-Proofpoint-GUID: 6dko55bW4NzsjOLBTwv6ewDpyMhvJsPP X-Proofpoint-ORIG-GUID: 6dko55bW4NzsjOLBTwv6ewDpyMhvJsPP X-Authority-Analysis: v=2.4 cv=XsT3+FF9 c=1 sm=1 tr=0 ts=69b3d2b9 cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=SmiEMI61MywFhWxRikMA:9 a=QEXdDO2ut3YA:10 a=1OuFwYUASf3TG4hYMiVC:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-13_01,2026-03-12_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 bulkscore=0 clxscore=1015 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603130069 Introduce functions for creating and inserting or removing the etr_buf_node to/from the etr_buf_list. The byte-cntr functionality requires two etr_buf to receive trace data. The active etr_buf collects the trace data from source device, while the byte-cntr reading function accesses the deactivated etr_buf after is has been filled and synced, transferring data to the userspace. Reviewed-by: Mike Leach Signed-off-by: Jie Gan --- drivers/hwtracing/coresight/coresight-tmc-core.c | 1 + drivers/hwtracing/coresight/coresight-tmc-etr.c | 108 +++++++++++++++++++= ++++ drivers/hwtracing/coresight/coresight-tmc.h | 17 ++++ 3 files changed, 126 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwt= racing/coresight/coresight-tmc-core.c index c89fe996af23..bac3278ef4dd 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -835,6 +835,7 @@ static int __tmc_probe(struct device *dev, struct resou= rce *res) idr_init(&drvdata->idr); mutex_init(&drvdata->idr_mutex); dev_list =3D "tmc_etr"; + INIT_LIST_HEAD(&drvdata->etr_buf_list); break; case TMC_CONFIG_TYPE_ETF: desc.groups =3D coresight_etf_groups; diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtr= acing/coresight/coresight-tmc-etr.c index 4dc1defe27a5..fdf23e1c932f 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1918,6 +1918,114 @@ const struct coresight_ops tmc_etr_cs_ops =3D { .panic_ops =3D &tmc_etr_sync_ops, }; =20 +/** + * tmc_clean_etr_buf_list - clean the etr_buf_list. + * @drvdata: driver data of the TMC device. + * + * Remove unused buffers from @drvdata->etr_buf_list and free them. + */ +void tmc_clean_etr_buf_list(struct tmc_drvdata *drvdata) +{ + struct etr_buf_node *nd, *next; + unsigned long flags; + + lockdep_assert_held(&drvdata->spinlock); + list_for_each_entry_safe(nd, next, &drvdata->etr_buf_list, link) { + if (nd->sysfs_buf =3D=3D drvdata->sysfs_buf) { + if (coresight_get_mode(drvdata->csdev) !=3D CS_MODE_DISABLED) { + /* + * Dont free the sysfs_buf, just remove it from list. + * drvdata->sysfs_buf will hold the buffer and free it later. + */ + nd->sysfs_buf =3D NULL; + list_del(&nd->link); + kfree(nd); + continue; + } + } + /* Free allocated buffers which are not utilized by ETR */ + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags); + tmc_etr_free_sysfs_buf(nd->sysfs_buf); + raw_spin_lock_irqsave(&drvdata->spinlock, flags); + drvdata->sysfs_buf =3D NULL; + nd->sysfs_buf =3D NULL; + list_del(&nd->link); + kfree(nd); + } +} +EXPORT_SYMBOL_GPL(tmc_clean_etr_buf_list); + +/** + * tmc_create_etr_buf_list - create a list to manage the etr_buf_node. + * @drvdata: driver data of the TMC device. + * @num_nodes: number of nodes want to create with the list. + * + * Return 0 upon success and return the error number if fail. + */ +int tmc_create_etr_buf_list(struct tmc_drvdata *drvdata, int num_nodes) +{ + struct etr_buf_node *new_node; + struct etr_buf *sysfs_buf; + unsigned long flags; + int i =3D 0, ret =3D 0; + + lockdep_assert_held(&drvdata->spinlock); + /* We dont need a list if there is only one node */ + if (num_nodes < 2) + return -EINVAL; + + /* We expect that sysfs_buf in drvdata has already been allocated. */ + if (drvdata->sysfs_buf) { + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags); + /* Directly insert the allocated sysfs_buf into the list first */ + new_node =3D kzalloc_obj(*new_node, GFP_KERNEL); + if (IS_ERR(new_node)) + return PTR_ERR(new_node); + + raw_spin_lock_irqsave(&drvdata->spinlock, flags); + new_node->sysfs_buf =3D drvdata->sysfs_buf; + new_node->is_free =3D false; + list_add(&new_node->link, &drvdata->etr_buf_list); + i++; + } + + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags); + while (i < num_nodes) { + new_node =3D kzalloc_obj(*new_node, GFP_KERNEL); + if (IS_ERR(new_node)) { + ret =3D PTR_ERR(new_node); + break; + } + + sysfs_buf =3D tmc_alloc_etr_buf(drvdata, drvdata->size, 0, cpu_to_node(0= ), NULL); + if (IS_ERR(sysfs_buf)) { + kfree(new_node); + ret =3D PTR_ERR(sysfs_buf); + break; + } + + /* We dont have a available sysfs_buf in drvdata, setup one */ + if (!drvdata->sysfs_buf) { + drvdata->sysfs_buf =3D sysfs_buf; + new_node->is_free =3D false; + } else + new_node->is_free =3D true; + + new_node->sysfs_buf =3D sysfs_buf; + list_add(&new_node->link, &drvdata->etr_buf_list); + i++; + } + + /* Clean the list if there is an error */ + if (ret) + tmc_clean_etr_buf_list(drvdata); + + raw_spin_lock_irqsave(&drvdata->spinlock, flags); + + return ret; +} +EXPORT_SYMBOL_GPL(tmc_create_etr_buf_list); + int tmc_read_prepare_etr(struct tmc_drvdata *drvdata) { int ret =3D 0; diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracin= g/coresight/coresight-tmc.h index 319a354ede9f..81237944b986 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -208,6 +208,19 @@ struct tmc_resrv_buf { s64 len; }; =20 +/** + * @sysfs_buf: Allocated sysfs_buf. + * @is_free: Indicates whether the buffer is free to choose. + * @pos: Position of the buffer. + * @link: list_head of the node. + */ +struct etr_buf_node { + struct etr_buf *sysfs_buf; + bool is_free; + loff_t pos; + struct list_head link; +}; + /** * struct tmc_drvdata - specifics associated to an TMC component * @atclk: optional clock for the core parts of the TMC. @@ -245,6 +258,7 @@ struct tmc_resrv_buf { * (after crash) by default. * @crash_mdata: Reserved memory for storing tmc crash metadata. * Used by ETR/ETF. + * @etr_buf_list: List that is used to manage allocated etr_buf. */ struct tmc_drvdata { struct clk *atclk; @@ -275,6 +289,7 @@ struct tmc_drvdata { struct etr_buf *perf_buf; struct tmc_resrv_buf resrv_buf; struct tmc_resrv_buf crash_mdata; + struct list_head etr_buf_list; }; =20 struct etr_buf_operations { @@ -447,5 +462,7 @@ struct etr_buf *tmc_etr_get_buffer(struct coresight_dev= ice *csdev, enum cs_mode mode, struct coresight_path *path); extern const struct attribute_group coresight_etr_group; +void tmc_clean_etr_buf_list(struct tmc_drvdata *drvdata); +int tmc_create_etr_buf_list(struct tmc_drvdata *drvdata, int num_nodes); =20 #endif --=20 2.34.1