From nobody Thu Apr 2 06:32:28 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 023ED387585 for ; Mon, 23 Mar 2026 09:50:00 +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=1774259402; cv=none; b=ity7BNvaZCDGH5C+4ea6ajWZlg0E3N9NwdSfzDc8b8cfTS1qMx5CKKnSDiGzfWAAictnPu35Z72IEgLlJRBomsYXSXTApefEqXpK8hXca6Fhd7IKcmFfg4ocEtcSrOlPrKv70OcWXSgJS9pjtrhBx0YHgZYOsewOJRAgM6PLURo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774259402; c=relaxed/simple; bh=FFceOaqM6wu7CDdoDhopkNKARk15nwOEHek364eGNLA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q1SpfngfjrRqzCkjXcI6X1C2xiqAnu2REWEtFwEu/Fv2PabD0ZrsG+XUROlHZIGnZ7L4J8N6kgMbdREYzstSa+AmbgIUO0FGLqSe4jqB7XZ7KbtRqQ/olqwtWP30QT3c4w6llCENXH50tOt0AVK3Iirl61S3ILBOCE/WHNLaGqQ= 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=F/v5HfO7; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=Dp/O4fWx; 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="F/v5HfO7"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="Dp/O4fWx" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62N7tAQ92291139 for ; Mon, 23 Mar 2026 09:50:00 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= aTJDJgY9ATjCAHRG1W16e0NWqYe38EB68qyE9RQn52c=; b=F/v5HfO705xH/vJB SbtOD/UJD6A0luaLs8qQTTMKjZK1pZymr3FST00FbGEerxLOcogUuB589xEbPphy hrAzmP6O6dDKAMp3OcGbsxNmhBpF0YLOi4upryTxgS2vcq2d/Osa8xVHsXOC4/g5 R5XnMphB3DXKvtFYtNAViMlOsDexgm4/EdVWfbetedbeKkGvA6GFsBJrj0lPySmn pNThk9WcWGCKOdX0ZOom/OxX9TYiOAuoD5XNaxfA1JcEbAEoTs1GpKbXTLn0l3yU sf+OLw8kG+lDgrbj0jr+niLuH9wr8xliur61mwAbQ5VVGzFxIBYE9+W1Xcjtbvew jm0H3w== 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 4d31j70d0f-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 23 Mar 2026 09:50:00 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-35b901d542bso3753962a91.3 for ; Mon, 23 Mar 2026 02:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1774259400; x=1774864200; 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=aTJDJgY9ATjCAHRG1W16e0NWqYe38EB68qyE9RQn52c=; b=Dp/O4fWx2DnGVDRs5IKFLRZUpVXeakcisK8LdU4ohaklkeqxaoen89Ivp0ME3elx+8 79IETGf4LtPBLfDSnJjPAFwiBRiWjDwhxSdubktaaM69vmIAe1sZLj4YpDkIFvUKmMdR dZpoiV6wur3xRKVNA/x14hW92dwg1q8TvGwURuhi38pJl9M0VifeXjASeT19BT4yLkN9 Uq+0IFKYPVWxW0CFJq6oAtq1GEqnmn/lnVmtiQiu9g+F7LdABKe7wiL2YK6fp3woNwHh D93bJnZRbfL0e0Ju9uhiHbo3s4XbvSwOaPBu3lDR5urizPvRN+98rz3Qj6/fwAY7vqlu /XTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774259400; x=1774864200; 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=aTJDJgY9ATjCAHRG1W16e0NWqYe38EB68qyE9RQn52c=; b=DV1BZ2aCvWwUsTngXfddBYMrZYHdn80TLiBM4gggEGlUHs0u1XdfTvxHN0/YZSGORC bOrPtYwL26yA9G7c9JGxgJVmhjNeQs52rixqLAYPHW4E2op7E1+GjkPoneDEiRXqYbmy RTSzFPEmkeUXPyi/bcmoDLcSF/tH2p6gl0/MmM/lWbhqnCIFp5cpK6r9z0+eJSuem9yv A3DaIEMAqO9WgqBd6vv5oGb5P0W6F3TzZ1rRoVkTMUTGrTvJaCdLYQ38EEr7BxwBRj0t /bpzYZuwjti0R38eGBAHNPwbzkqa35Jw0+cueu6p/4s45m2gKfGgd3hV1d4fkE1O2D9x t2+A== X-Forwarded-Encrypted: i=1; AJvYcCWz8q3LKsR+MzNsQCyduTsL1CvUY/VKY4hsbSa4GtecLP69c4UTmekpe+rwaQ3LlKxW4VREuisJZAySJZU=@vger.kernel.org X-Gm-Message-State: AOJu0YySFJlSBS5FpN5lJyPymcsvOb2oRhYsZ/Cv7HMo6dJ1t8r6z5id rJok7os9Q2uiKmNGhhyBnCEGMnL/TLmJRcIKUANnMFrA38QPOrJd2RFvqSIODua4verm0/lc/mS ohCn9uiTY6Ys/BsAG9TGCm95EE00Gw8q9ctG2AT1qFs73CSupt7O+ZXpH0eyw5oAo+Eo= X-Gm-Gg: ATEYQzxpy9ZW97mMT9X1pvKAEQiL1n96vZ4V0bwTE+kpjwcSBIXCqknwfO6eout9Jr3 1ktFs1IUafPNdFL6jD2auf+ZnyiSq4bXsqdvCV1Bf4vFCBUQrbgCP05+qNmfUkGqyi061+xrVNy kCi0WxU61cGgIW7ce5tOtQaXJ2WIpkKwD+oWftbHX61y5UpvKR0imTIY+5K0XvEAxOl6SUP1prY 9f8vF9Xbx9jlDc3mkTqK55W+7tLMZXGU6E6/P/aRTFXOaNHfEv6Dy5SGwllpjMDUL+A7rXVGGkM Op/C/tyRwWKOhL+NyEX5O0zEQYIS0RFuQvkRdgKhfnQadRjInONuThkWwlln/wNTPJBn2tkbG// 6ZyJwB/23qOSY8lTcGl7o5nL6tIz2JSgmJUW+mjf59TJ43by+GyX1eqXETkoraFGR/OkD6rAgK3 aJ8zZwdCmr X-Received: by 2002:a17:90b:4a84:b0:359:ff8a:ee4f with SMTP id 98e67ed59e1d1-35bd2bd8b5cmr10355265a91.7.1774259399440; Mon, 23 Mar 2026 02:49:59 -0700 (PDT) X-Received: by 2002:a17:90b:4a84:b0:359:ff8a:ee4f with SMTP id 98e67ed59e1d1-35bd2bd8b5cmr10355240a91.7.1774259398986; Mon, 23 Mar 2026 02:49:58 -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-c743a939af0sm6591935a12.16.2026.03.23.02.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 02:49:58 -0700 (PDT) From: Jie Gan Date: Mon, 23 Mar 2026 17:49:27 +0800 Subject: [PATCH v16 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: <20260323-enable-byte-cntr-for-ctcu-v16-2-7a413d211b8d@oss.qualcomm.com> References: <20260323-enable-byte-cntr-for-ctcu-v16-0-7a413d211b8d@oss.qualcomm.com> In-Reply-To: <20260323-enable-byte-cntr-for-ctcu-v16-0-7a413d211b8d@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=1774259383; l=6204; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=FFceOaqM6wu7CDdoDhopkNKARk15nwOEHek364eGNLA=; b=IxYt/7EWVEDsCF4b7tnmVPQ9RVLcT/lR15WOFzdR6hqbCMhYuQEXRluud+4FVD3Lk5YXocrsX oWbe/GW9qWtB6KsrbrOt6MFOi22gzWTP6IOOljrd0am8sPMzK69IDG0 X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Authority-Analysis: v=2.4 cv=ArXjHe9P c=1 sm=1 tr=0 ts=69c10cc8 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=AScg1gZdVb1XvqdcXssA:9 a=QEXdDO2ut3YA:10 a=uKXjsCUrEbL0IQVhDsJ9:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-ORIG-GUID: b7A0eFZXGol93X4H9LUL7w2vW24a1myd X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzIzMDA3NSBTYWx0ZWRfX8omAzUw41+gd qLjtzV4kZO4sN/ECwFZ6YPNeLvQHktuFlcfd9ip65Jcz6x7UyXG2hYlPSVyKXdKBofQ84Kv9Yfy 6NZx2VHNF0mtz+4y0bwppH+6sXEo+5lJwSWOhfs8eQeFQERM8s40Kz61TljrTBUFBjHUiMhOk+k 82OdBhQtfKuI7rEbOUafEalkVN1VzTbdd43fltpioV8UUh+FPXcTa5O0DYKPlN1WwwGhVGN47yE XlSTqJA/tTZNPhIZMNv0Qviuu6EpMds7ygfNgXUC+Ped+IboTxpuy86qxiIcS5kvQUbH9gbpyNP Rwjbd9+E7v/r9fH0KV58s0uE82bedvbwsi67EXfoGI/Lpl53mi5HLNxIyLjreS5bolut8gJH5Qn MKXwAhLinnuOsWBlDFiK0qrWaLvJfKdyrwOVMKnQhHsJbRH5BWv0ez/einqddtxXez2TZSrJwIi ytiLjqmcAdaRA5OAb3w== X-Proofpoint-GUID: b7A0eFZXGol93X4H9LUL7w2vW24a1myd 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-23_03,2026-03-20_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 spamscore=0 impostorscore=0 suspectscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603230075 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 | 98 ++++++++++++++++++++= ++++ drivers/hwtracing/coresight/coresight-tmc.h | 17 ++++ 3 files changed, 116 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..306982e88dbb 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1918,6 +1918,104 @@ 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; + + 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 the 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 the sysfs_buf in coming steps through nd->sysfs_buf */ + drvdata->sysfs_buf =3D NULL; + } + /* Free allocated buffers which are not utilized by ETR */ + tmc_etr_free_sysfs_buf(nd->sysfs_buf); + 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; + int i =3D 0, ret =3D 0; + + /* 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) { + /* Directly insert the allocated sysfs_buf into the list first */ + new_node =3D kzalloc_obj(*new_node, GFP_KERNEL); + if (!new_node) + return -ENOMEM; + + new_node->sysfs_buf =3D drvdata->sysfs_buf; + new_node->is_free =3D false; + list_add(&new_node->link, &drvdata->etr_buf_list); + i++; + } + + while (i < num_nodes) { + new_node =3D kzalloc_obj(*new_node, GFP_KERNEL); + if (!new_node) { + ret =3D -ENOMEM; + break; + } + + sysfs_buf =3D tmc_alloc_etr_buf(drvdata, drvdata->size, 0, cpu_to_node(0= ), NULL); + if (!sysfs_buf) { + kfree(new_node); + ret =3D -ENOMEM; + 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_tail(&new_node->link, &drvdata->etr_buf_list); + i++; + } + + /* Clean the list if there is an error */ + if (ret) + tmc_clean_etr_buf_list(drvdata); + + 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..6e994678f926 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: Offset to the start 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