From nobody Wed Jun 10 14:02:44 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 D949C3FCB0B for ; Thu, 7 May 2026 14:12:39 +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=1778163161; cv=none; b=ELeFWAyokMdb8yuE576MgGgbxmsre+FiTHfh/UqPNW+0UQws1cs43oS4ZBT5G13a8qvFoKBVZrgvKnZzBbf3ByIbsBq04FKYhQRWSIaqRdA+WfH85lZjjpC59KUT53OBBawqWjUByGuUMDNxpZ+wmDtYQh0YSL59BpoREoHV690= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778163161; c=relaxed/simple; bh=0XKtLb+KNpJzb2pfRF5CKuVsIlfPIhLw3pICGVnZtAs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o6GAy3Iopo0g02F3BSW+sXR26Rtge99Q+l/6uNRfJiqTn+EtxXp6+IaFjg1ZSxvTVuEbdiQW+YWHDu56xfqdzwTI3HKVWO883xzJjDSt6fbiG+i16ToSy+/DNJ30fHjMTmMe6K8hp1QOjDNKozELngGp9jdK7qNsaAyHSLiEDdE= 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=mdfFPFxN; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=ZCuAueRo; 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="mdfFPFxN"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="ZCuAueRo" 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 64797jVV258795 for ; Thu, 7 May 2026 14:12:39 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= /z3TLk3YJ3zjJ3lq98822BJk5JYh6VxSRdK8UVMx+Ug=; b=mdfFPFxNy2sPNcjr j0FmFrSTwLflWsXzpHxg9Qh+5uXaCGTLpQ4MhjLyQ87pWQ7rSJ6A4b3q7Z8H9iAV EaIN2lNwHeJ8fQIxVHsV9SPPHcGqPklQP6l4nJPB0gETHTWd3onwwOAAJp37oc/8 QayyM/qTfJzrzrl+pmMRbKsYgN6+crYiL6eImIXD5qUZAICULRJuFQAz8M2HQT2D /7czGFku1wAty209NJUGKRgy7OsxRyTRscRlEMIYTbz1rr+ip3DbUT0QVdhVKx6b VKhiu2bwbho0RD6w/8XVMzaqW3KJVXXCX2UWinpyA9Ud/KUTyfgp/nhUeEEbYwME TSFwyA== Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e0hr8th00-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 07 May 2026 14:12:39 +0000 (GMT) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-c80b103360cso533235a12.3 for ; Thu, 07 May 2026 07:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778163158; x=1778767958; 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=/z3TLk3YJ3zjJ3lq98822BJk5JYh6VxSRdK8UVMx+Ug=; b=ZCuAueRokJmkq1aC37B10Hkdp4FucfDfr4otXEvUkgawOu3s6UyVm7nSRDRTDTAFeo NJfKW6YFgvkFeS8eW0oPbJC245VH5BJ6TWi3ZPCIWQLpDdaB0QAnzEKuM15rHFZyhlcS f+B4sjucYmeF8QxorImvHzdYbxWz1mS2HnZjqrjeon+2O7vMdXI+WR4/hQGY9KaAxYpl MLZ/IpJuoCPcSa2y0jPjjloVqu9HMcrhIIMoodpjLY7oa4wzI4HjKcJPvgbSGRgj6BsV B2hK/AbmmcwGfvl9HU7F4MhYnpjBA782ne7sqwvJniRd74sAzVJ+vfhghETb0NidtVJv vVmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778163158; x=1778767958; 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=/z3TLk3YJ3zjJ3lq98822BJk5JYh6VxSRdK8UVMx+Ug=; b=MJuEIFscKE0E6xvIorAZYjBTdnzMU6tiV37tpxBfZN1ibgmaDeSFGqlrrTnmUJB4Ex B+k1MkNrOqxOzgRAhc5+1Aj6w3IzhCRZ19QhgjHobPlZGPzurYzMSpaR/spLq1M2T+jI a94NK12MGavKoJbazM9oNGsNjT5U66Dh7ANYizyHMnUKVnNR5yvxyoSasI4DOymixCUM k0ScXmb9hFQUZVLtH9FrrhF1JvD3o0GN+S9v2F2cJok8LOjr48lfnDoiCH3spfpnI9Xe phlZ+1k259zGTAoLupev1OtoU6rhNaFjB7mld4crJ/JCsSdKIuYp6cizqzidb5ehvmx2 rLoQ== X-Forwarded-Encrypted: i=1; AFNElJ+ow6Pk1kjJk6dronr6cKq/AwYjXPqu+mQP8AM6N2ZTRcuA8JJYQsTWGQ3mMD7MeCsX1QxGkXDg0wLW56I=@vger.kernel.org X-Gm-Message-State: AOJu0YxT00fxQx5608+CtcZyd883O66W0Z0RtjffL3fliulzddWr9SXK hYg578GjDlllaCRcs+V8I6HlNDW1VNhxo3fFMfTNorDfjkWhsjZmyhIqLURRQuAjhjNVNuiteSW pvXW3tUDzbz97nRXhZdBXPpxidVNIg0/IVPmtw4DQW5FT1M3PzZAiC9hk3mjt/uRSOgE= X-Gm-Gg: AeBDievYwe1mCA+i+sRXAZYBnhRwPIQO09ZM7InPOvL5yto3FxybEZLXhDelTdleuZH tIq+CfT09FCOw3iUegfvsdmLzcn0oSf/d7P481oU8TSxIBO/O5snhOKerxUYnc+Kod/y+Xo1JYD MY7DXJvS/jdvd0xyp0SS/t0ofu1px/32e3DzVl1ng5JLkb7bQsvdBbeof4QKv1ro2ykyuVTPEot oOBTBkYTbm40hIWjKEC8S395oJ0CLm/Zl74PY/vKjU/GXwd6zj96xUSx620VgBplgetdizfE4kw 4JUHSYZWU1Xl1Y4PMQlhzQjX80U+HrNYx0xEDU+kbybLvdZwMyMZGH2AsjHKeIcr516ELuQBh7g iuf5cEgFlpTgLBZqsULXyTd9srUwICHzW7eDV9obTaRGUUCsilo4OTKyALXmugQpjKS395sS0HA +Y6o0mcm+95NqtZpUzpuA= X-Received: by 2002:a05:6300:218a:b0:3a0:d88:6d6b with SMTP id adf61e73a8af0-3aa5ac0ddf5mr10192218637.49.1778163158474; Thu, 07 May 2026 07:12:38 -0700 (PDT) X-Received: by 2002:a05:6300:218a:b0:3a0:d88:6d6b with SMTP id adf61e73a8af0-3aa5ac0ddf5mr10192166637.49.1778163157864; Thu, 07 May 2026 07:12:37 -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-c8253b493c5sm2343072a12.28.2026.05.07.07.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 07:12:37 -0700 (PDT) From: Jie Gan Date: Thu, 07 May 2026 22:11:57 +0800 Subject: [PATCH v18 1/7] coresight: core: refactor ctcu_get_active_port and make it generic 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: <20260507-enable-byte-cntr-for-ctcu-v18-1-2b2d590463a3@oss.qualcomm.com> References: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@oss.qualcomm.com> In-Reply-To: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@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=1778163146; l=3816; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=0XKtLb+KNpJzb2pfRF5CKuVsIlfPIhLw3pICGVnZtAs=; b=D5cf6pQGKCuusxfGdwFLVMla/i8jhs3iNib8sL+WsPnBr7WuT16FNM2Rk4aS7L5AhjxNGcrZb r6yv0LM/wAeAiYYRxxEr5kalsz3g+7nvRuAzWzkLh701BpKSL4wrbM6 X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Proofpoint-ORIG-GUID: y9SJYaRKiuSZ2pghj1jxYJ3JeQ-47QiH X-Authority-Analysis: v=2.4 cv=caHiaHDM c=1 sm=1 tr=0 ts=69fc9dd7 cx=c_pps a=rz3CxIlbcmazkYymdCej/Q==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=lyq7_Muqgj1vGRpOYO0A:9 a=QEXdDO2ut3YA:10 a=bFCP_H2QrGi7Okbo017w:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-GUID: y9SJYaRKiuSZ2pghj1jxYJ3JeQ-47QiH X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA3MDE0MiBTYWx0ZWRfX305ee7XBvNd6 PbLgLcK2Pf0tkGKXRjyiPgNXbY7RUCRUL+UpwrwrlIc6M2hkxIJHhGNz4xsAPHaiZcwABJuX01K 3Ry5V+bsXiUYeuq9RAC3vC0rFO4+T2fBZ5r1bxeFTS8L/sdX23WFzjByrxSIFwT5h9qiEzFCQ54 WhfgVxgND2MiURd12i05ME84GqNXEii3Ej71LvRwiYFaFPuU6lIzPF+KdZhy3t2QI9E4sQ3UXAn 7YM/Cy+UcnHBzcx9wQDgJTNl9GHRN8JnLmaoV/Hc8rkr+lNhMTAO0st8L77AMJu5Ut1YvRvEee6 4Aui9YQA1a+EHzTQ7/1X9EMzPwfPJqtp7Ge4AvFESlWuqGSKkI/QORMNuBdYTOxpVV/aI+1UDJ/ HNqrRnSOpM10gnZml0D8uNM7J57lDPYa28ajKPFJiHcCpk6lJ4UzM1FltakRlVCf8ZVYdmmQ1AH IyTbUEmkfhHgqeX4t+g== 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-05-07_01,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 suspectscore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 impostorscore=0 spamscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605070142 Remove ctcu_get_active_port from CTCU module and add it to the core framework. The port number is crucial for the CTCU device to identify which ETR it serves. With the port number we can correctly get required parameters of the CTCU device in TMC module. Reviewed-by: Mike Leach Signed-off-by: Jie Gan --- drivers/hwtracing/coresight/coresight-core.c | 27 +++++++++++++++++++= ++++ drivers/hwtracing/coresight/coresight-ctcu-core.c | 19 +--------------- drivers/hwtracing/coresight/coresight-priv.h | 2 ++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 46f247f73cf6..9e19d370c207 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -588,6 +588,33 @@ struct coresight_device *coresight_get_sink(struct cor= esight_path *path) } EXPORT_SYMBOL_GPL(coresight_get_sink); =20 +/** + * coresight_get_in_port: Find the input port number at @remote where the = @csdev + * device is connected to. + * + * @csdev: csdev of the device. + * @remote: csdev of the remote device which is connected to @csdev. + * + * Return: port number upon success or -EINVAL for fail. + */ +int coresight_get_in_port(struct coresight_device *csdev, + struct coresight_device *remote) +{ + struct coresight_platform_data *pdata =3D remote->pdata; + int i; + + for (i =3D 0; i < pdata->nr_inconns; ++i) { + if (!pdata->in_conns[i]) + continue; + + if (pdata->in_conns[i]->src_dev =3D=3D csdev) + return pdata->in_conns[i]->dest_port; + } + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(coresight_get_in_port); + u32 coresight_get_sink_id(struct coresight_device *csdev) { if (!csdev->ea) diff --git a/drivers/hwtracing/coresight/coresight-ctcu-core.c b/drivers/hw= tracing/coresight/coresight-ctcu-core.c index 9043cad42f01..e8720026c9e3 100644 --- a/drivers/hwtracing/coresight/coresight-ctcu-core.c +++ b/drivers/hwtracing/coresight/coresight-ctcu-core.c @@ -116,23 +116,6 @@ static int __ctcu_set_etr_traceid(struct coresight_dev= ice *csdev, u8 traceid, in return 0; } =20 -/* - * Searching the sink device from helper's view in case there are multiple= helper devices - * connected to the sink device. - */ -static int ctcu_get_active_port(struct coresight_device *sink, struct core= sight_device *helper) -{ - struct coresight_platform_data *pdata =3D helper->pdata; - int i; - - for (i =3D 0; i < pdata->nr_inconns; ++i) { - if (pdata->in_conns[i]->src_dev =3D=3D sink) - return pdata->in_conns[i]->dest_port; - } - - return -EINVAL; -} - static int ctcu_set_etr_traceid(struct coresight_device *csdev, struct cor= esight_path *path, bool enable) { @@ -145,7 +128,7 @@ static int ctcu_set_etr_traceid(struct coresight_device= *csdev, struct coresight return -EINVAL; } =20 - port_num =3D ctcu_get_active_port(sink, csdev); + port_num =3D coresight_get_in_port(sink, csdev); if (port_num < 0) return -EINVAL; =20 diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtraci= ng/coresight/coresight-priv.h index 1ea882dffd70..5532ec82e82c 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -155,6 +155,8 @@ void coresight_remove_links(struct coresight_device *or= ig, u32 coresight_get_sink_id(struct coresight_device *csdev); void coresight_path_assign_trace_id(struct coresight_path *path, enum cs_mode mode); +int coresight_get_in_port(struct coresight_device *csdev, + struct coresight_device *remote); =20 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X) int etm_readl_cp14(u32 off, unsigned int *val); --=20 2.34.1 From nobody Wed Jun 10 14:02:44 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 DF48040242C for ; Thu, 7 May 2026 14:12:44 +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=1778163166; cv=none; b=rdkTzCzLXddafSq89cQpTwT32zBrv5XHSJcTVfkS+wzDjc5GT80Se3lByYt+QTmitDJSbhxhWDoyVDGwtYNPMCvDOgUoljJwbDQ4TxF7MeFDZKLaUBrNjuLiVzSnTMWP+AOm0id0ybUIptO0IJ3g/lU05jrSeTOZOizgfJQFWqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778163166; c=relaxed/simple; bh=hixjNT1jMkq758zZZ1hEzrAx1L8FCxRRm5D2VujRxWk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a0y8FAMr274v3jxGgKRfguwr2vr3wKL+RScD43hNiZqQZwhaiI9AL8ygTr5CZXwz0huiWvJlNwtEXlKCnab95uNYpuyREWvn7w/XecSPmTi2SZex6F4O/4FrAfpukGc1l22MB7EtVaL2pKIzJwLCyIGiY+RsccXWh1BbrXknm/M= 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=mD8BaHm3; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=MsFHm51g; 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="mD8BaHm3"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="MsFHm51g" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 647BTr1a682778 for ; Thu, 7 May 2026 14:12:44 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= dNjLWVZN9ymVqqwg7nxMwcVKTOzZb6j0YCHbt9QKnGM=; b=mD8BaHm3MLAwaIZP u5sZcxhdOeMzMDqeR3i7XG2l4WBe3m/MAZ3GdiI2Uv07+VsclECVbd2OMo4M4l2C 6zgVu7Odiu8kYnvRjcGdfBNcssTZcNPx096Py3UrVl1VAdRWnO9y3fYCl7qNlpLc 7LhexuBoU1AhXZeR6Rp03CbUHuJFIiFRy2HoURxx/c3Xx162GGaRX065LCUQp+St 5RTK5bGy7iJJz3RImUKMj1MvCPt1KAO+DpdI++mOcHK1jjxx/PooEGFx9OZdyEOA Zxl5MxHKQjHfpHdHyiL8oTDkcNfeQ3m2H3T73jEaM6AolNyNYICo8knZBqBFmYIw AheKKQ== 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 4e0mhaswta-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 07 May 2026 14:12:44 +0000 (GMT) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2ba3245a43dso10165875ad.0 for ; Thu, 07 May 2026 07:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778163163; x=1778767963; 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=dNjLWVZN9ymVqqwg7nxMwcVKTOzZb6j0YCHbt9QKnGM=; b=MsFHm51gK+wYb/kI+jIdsRx1izMweCjUSQFZ+ZNATk3gmSk69Bo86VClCl0JVaC7Mg 2hRI5EdL1Mh5REjLRSBLwOwWfwEcC//EX7eKO/b4S6H9eLcY0tw9HXNHDHxbXbwwt0E7 zcuNWv1qUKRDHtlt30u0ZqPxIsdXm2Rox3cR6TPH2pPN1p7fz6SPx21KbYX5+zfcLY+S skFlbhF1LeXH7ABEhe89NpNvJbG1nJhDw5gWC/MSPVdv9AZkNeGcXXGtgRhclCqvhapH 5bL2hrozxItVQ2vlRLXAyEbDSqFoll+iXl+mgkDVQsBQNMfdoGG/xoUExdBHXoS5A/QY CsXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778163163; x=1778767963; 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=dNjLWVZN9ymVqqwg7nxMwcVKTOzZb6j0YCHbt9QKnGM=; b=sDgsEb8oWr8Qu6gVnUBrHjhQhu7ITWWK2dW/hgirwZf9siRFc9jaGUYyhH3bi5RQIg ovOA0LteE4qso3uiJFVTpkgq8XmVVbv5Kj92lUWXRDj+enK1iI7PNISF51joZ1I9OG0T xfu+FcxERjCyLTYV3NDN6Z4uyQemlypT8riLzEf5dQye1L2HGq7D9EWzydEdxy2O8bsv bqo4KZ0GfRoU8mJPj2vY3LXBDAa+BYxlFspMuXJrawo0VXnYooN9ZgPQ1oC0tuTLQwha maJtbMIu+UxAlQZAnnGJ7FBaPyGn+W/EHisLyvA3vwnJcPQlQ48tjycHg/RLkIB0GiaU 0sBQ== X-Forwarded-Encrypted: i=1; AFNElJ9k+ZKikOXzo6l06H4u9KFvlY5OEy1WXIq2cfwIX+nT8Ngm4rfh5m7wrPy466LJmDXx8gymrq25O/acOY8=@vger.kernel.org X-Gm-Message-State: AOJu0Yws10mMUBrglAiYxX9h1l/188dY+w5kiBKASgk7TUOTpj8ZwHCu Hf9H+ud3Tmko5OOwJokWHCVG6sE1TCabjC6kOYgP+vrrfCMMXCg1B2of+y2R8K3NXd9CNiiCzp8 5y43fXWLEkylem+aJn35nmgweXa8DsZFEBJldsrriOHTtp+nYnP+kQaalxMoJxGDR/QE= X-Gm-Gg: AeBDievy8F1J9t4vtw2PVbDEBajmuNbyDUbtpAEHTX5/n28KiSMnbOjjK+eb6KWNt/n PKq9sTpzwO99FGUXlkU6+Tigae6HgL+o+J2jg/xCF7ByC3VT/jas49F7ipmpDG6JnCHbI6UdjU6 qSC/et/zsSTQUzgQlVJSIbDaCqR1hIsTzrHApQ1YuAzf3KMBPGLkD8dJGorK2/csTDI51Ak3YBQ 7bZ/HW9ToO4XEpGiBGCsks3md0PicBJDgv8mApOJOMr92mk1fiT/zrP77ojx8j7yKReAsyIVeuk VgB9o3SaaiQG/8HdBC7cq1PA27w7//8K1us4DMWYpiaycE9gR5nd9oENPzSXU9kpG4K3cZ43hua wGtswdKIPhOej93iA5D5Va18BsTaFYx+j/+ZX+PRaoy6YcKSnjB3lHwZ5u3EWmGfmkLWuguOYDI xcjikJ44gGbFjUZU+hq6A= X-Received: by 2002:a05:6a21:3395:b0:3a3:a9c4:3d60 with SMTP id adf61e73a8af0-3aa5ab5e038mr9423430637.27.1778163163397; Thu, 07 May 2026 07:12:43 -0700 (PDT) X-Received: by 2002:a05:6a21:3395:b0:3a3:a9c4:3d60 with SMTP id adf61e73a8af0-3aa5ab5e038mr9423372637.27.1778163162865; Thu, 07 May 2026 07:12:42 -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-c8253b493c5sm2343072a12.28.2026.05.07.07.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 07:12:42 -0700 (PDT) From: Jie Gan Date: Thu, 07 May 2026 22:11:58 +0800 Subject: [PATCH v18 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: <20260507-enable-byte-cntr-for-ctcu-v18-2-2b2d590463a3@oss.qualcomm.com> References: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@oss.qualcomm.com> In-Reply-To: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@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=1778163146; l=6615; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=hixjNT1jMkq758zZZ1hEzrAx1L8FCxRRm5D2VujRxWk=; b=wGzEsqp85TWlVQzZ2kT7yOm4VW8XctBS4r24DeLT9H9rJAFZwpFrzKLX95JGw4H0LaxRm6k/N cSprM1HBNr4DALEpeUXrliKZmBhBMgBLMIIqZgfySpjxbxG0MpK7T94 X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA3MDE0MiBTYWx0ZWRfXxc0lNQ1ZRlIj lcMZeS3H8E/Ui5P2YhxFwy6ryg8ee3aE9ccfWm2Yi8glW8vDIYZMCtu5CtOBbRoDhIiBhfqWY25 pcWSba6D3Re+3Gnu+uH1QwYztIoXirlQdyAxNuMMdD1vqr7VzOU0iQ5zIgu8rS+bq16Kq6sp7ld CoYqOAFRCxaIr0iJh0U7PaLEQgUV5WcZ7xs35ZueNvVYhA4+6OQcHj2ATjuWA+SJvV4feFUkYeN 4xCrtncvgHzS0wEy8u57Xpm+m16tbWH2QvHaej1+4Ck6X10NT9huCz8E7+VpY6YKTBMuhwWSf6y OphCwpmwAET/GqKFCC9gNDPIUIWwOjvCvCseNYW3r6GwlsIWu5XM3N9+LI1dvb5cnqo/dsrk6kt 2BdN86ZlXFHg0KXXl2Vm/nqF2C/hcKZm1RlS6de4QkdpGRhaYjRMFHntTGukZReGoYnAuEBlqA/ 7Dda6rcBHrnRmsJPg/w== X-Proofpoint-ORIG-GUID: ZCeEJV_U1roMxdDr0VVB_I5w1HTX6Vtr X-Proofpoint-GUID: ZCeEJV_U1roMxdDr0VVB_I5w1HTX6Vtr X-Authority-Analysis: v=2.4 cv=ReWgzVtv c=1 sm=1 tr=0 ts=69fc9ddc cx=c_pps a=MTSHoo12Qbhz2p7MsH1ifg==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=SmiEMI61MywFhWxRikMA:9 a=QEXdDO2ut3YA:10 a=GvdueXVYPmCkWapjIL-Q: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-05-07_01,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 impostorscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605070142 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 | 105 +++++++++++++++++++= ++++ drivers/hwtracing/coresight/coresight-tmc.h | 17 ++++ 3 files changed, 123 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..779d9e479aab 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1918,6 +1918,111 @@ 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 all nodes from @drvdata->etr_buf_list and free their buffers. + * If a node holds the live sysfs_buf and the device is active, the node is + * removed but the buffer is not freed; ownership stays with drvdata->sysf= s_buf. + * + * Locking: caller must guarantee exclusive access to @drvdata->etr_buf_li= st, + * either by holding byte_cntr_data->reading (byte-cntr read path) or by b= eing + * in a single-threaded prepare/teardown context. + */ +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 (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_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 From nobody Wed Jun 10 14:02:44 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 C94433FE35F for ; Thu, 7 May 2026 14:12: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=1778163172; cv=none; b=RIj/aCNo2bPzDSyhFqDq8idAej6S1xuZkICEJ9F4ibAkvOqMmJkeEeLBS7pMGgVfQqLDttg8EFp40uBUi1Mdz6YJcTtQadiPjhojB7D1EPrMkAmR4xdiHj1Ix8biy7cl68GbQMKPAuErXkETqQtvSzAuDp4/4J8gZWViUnu8Ko4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778163172; c=relaxed/simple; bh=0THtAIFi5jelKh7Fknxn2c5M5CE76ThTcdKm3o+68rg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SZmBRgIW/g6LnYcvxvI3bEBmpa6iqq6EiXbsBxUDwpVlHnWrFc9V6ppoF3/35IPDs2WmPL/SD9pguitHEMQtpTSRRS7Ux6JYPYw1aBEHNCZsSlve9hi+Rq4fAk3SKDeS1SSyrYPCnW3s0SFexndCnZwcvvaHEO5YayrwM7c203w= 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=jitw2C6h; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=awD4VXD3; 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="jitw2C6h"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="awD4VXD3" 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 647AJTiM150879 for ; Thu, 7 May 2026 14:12:50 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= +1wWjC7fh+aHAvyftVm0FHkxDiI5MU51E2SCcX00kUs=; b=jitw2C6hr89DuaRB h9houTJjaGIp7/rZdVggYv59en0kXLhQ4Iflw9unHxSsn8pqRg4CSBlRDyxVgYvu dSmxXyaYq01/84Ech3GGoNpYRECMU1MwuCTha0UtUeIIZQi1PmLhlNOe1ltpzkRO 8gwF1FQF3kOphNH7V7g6XhyiGe4cYXV5qvlJxXMXQGDlaQQEE5RdPFpW74b+pPsg IAQkkVNSYKooGi8D+tH1ED/ooXojJFVbyCRZxC2Vn2kjf+ywtGleio7oOUhHlX/E Tz79hCjqykDnCxeMdgBQ8JOOk/PgEhTWWztIily5xSbLFXdKWI9E8aS7GC3+pUVp JnHpSA== 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 4e0kctt670-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 07 May 2026 14:12:49 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2ba838d3fa4so10956115ad.3 for ; Thu, 07 May 2026 07:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778163169; x=1778767969; 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=+1wWjC7fh+aHAvyftVm0FHkxDiI5MU51E2SCcX00kUs=; b=awD4VXD3VXWiVxsC5CxbE1NOWfmhZVoRlFe68wpIL2sGWI4eot1eDnkghghIQwTPYc oK2e+PRSgjTZAuTEF80jCbaNWViHqMl0AiqmlBpzz0DW2/NM6av3UAB4cBJqO+jhqJH2 Q4MKNZwE2xI0GVeiXBDQCLO6UmKyb80wjolHPZCsf+KseAe6ZoDCfw+jft30ogeNX9xp 98xTtb/9C40Ddqj+ROfb7cUU9iziQZSQjfy5IrDeboO9JV/W5236cvf/vOUpLMYUHHWX FBwtQo4IHEFS23WxdOgkcvi9MEsJ10tRIJpurhrA8Ias6Vr+h8TkOfeHMUnhL6+fKkT4 fiog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778163169; x=1778767969; 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=+1wWjC7fh+aHAvyftVm0FHkxDiI5MU51E2SCcX00kUs=; b=a8866SKdtTSt5yakohVGS1Ik8KNEx1ZFQip6//zgbNrlMjuEh1YGrqrx5H4hI8fc8g bQLQFSK54UmWq8fWXjRBKcfUQejpf2wkZMDjbOfqjJBGNTvwQTIDAk/7DFTZ0yiFS8/E U89ZhZ6pPVfD7/WHMcyGEdrp9lOyXD+MkRDBOxVERvEtcLnOeWpW+uNqJpCU12y7ZgtU vtAxDoRVWVL3mPj9klIq/EGGy6a+5VAEH673ypaUKj4KemI7YGTxHxssNuC0VBMf6oST aFwCCHcnJs+vA4eAIuLFDdAZHqnWL6Si+HlMvwwDnjnFLpOYIulKnNRp489a2xd74V1k sRtA== X-Forwarded-Encrypted: i=1; AFNElJ8QDyAAG+Ii358ujAI/pnkjxKX7kOUNF9PCdYBFx1FVTo5P4DANV09Mc1DU3iXG7nMbPVsKX8WIWbS9/9k=@vger.kernel.org X-Gm-Message-State: AOJu0YzXS5UFKHDRLdwkpJnESWWd8UiY0nJZbwwNKo8eTOPMAww2nogb 9P5bd7RamrN831h4xMfalPmpr54dZHB7NU9C0dI1wTemQXT66iiuStA3yLdq0i3W94M0sCnBgzg YkAwtz8xQegjW5V0BClj73so9Aof8btBWGheVfpgRiBwmteM87Os9wXB8at0fmfpu9SM= X-Gm-Gg: AeBDieuZCS5+Bq0paqITirgdJ5twIiLNd0dQx4NpNivk4NvSKsY86zIiC7dfRhAXDOi H8J1aUncFOmizI6QAYvHSnJVY87yc6zLo0cdNgAncDxBsm7066GjvJC3vvhGY1CzEnv3Nzcxme8 VM3DLWgpZ/jXQTZKnDmM5yrG6olGN+jVrffT3d6IuUEYrarrf509HeWOrtANtFXiJpQrSY8RsuU iYQnQFnnVSQxL0ysqeBx1gCwSDQt6BIJgOh5SRdrFsANZyIbkWc7nAMYrrCXMRn+9BLx/Pxlb+u /WdKvK6svVfTJUoW15TNRMBpWXfa55uEEy1Lf9YiGzuRNGzNCTN4mNCa378iGbPd9ABhBf4vEyt 8GnJfYbUn0xuiEXzjNDwJJwADbxoEKOUIW2noSC0iHuBAGWupa/qhV3eBN/6iEoG4L3U1JHl2Mf 6yibfhTIzeMmTnB9BcCJ0= X-Received: by 2002:a05:6300:218b:b0:39f:a8fb:3354 with SMTP id adf61e73a8af0-3aa5a70d15fmr9272545637.17.1778163168484; Thu, 07 May 2026 07:12:48 -0700 (PDT) X-Received: by 2002:a05:6300:218b:b0:39f:a8fb:3354 with SMTP id adf61e73a8af0-3aa5a70d15fmr9272497637.17.1778163167982; Thu, 07 May 2026 07:12: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-c8253b493c5sm2343072a12.28.2026.05.07.07.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 07:12:47 -0700 (PDT) From: Jie Gan Date: Thu, 07 May 2026 22:11:59 +0800 Subject: [PATCH v18 3/7] coresight: tmc: introduce tmc_sysfs_ops to wrap sysfs read operations 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: <20260507-enable-byte-cntr-for-ctcu-v18-3-2b2d590463a3@oss.qualcomm.com> References: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@oss.qualcomm.com> In-Reply-To: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@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=1778163146; l=5200; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=0THtAIFi5jelKh7Fknxn2c5M5CE76ThTcdKm3o+68rg=; b=J8K9AyTEoZRr/lTm4JvkvJEyM/VdCHv91RJsmSKJjhYdn5mAM1Y43UtdsxcX4p4+yrTPUWy6r lhvv8Slq1ZTB5x4tKb8J5ayczH2e34PcL56K7HA6InlzqfnNW2Zch9d X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Authority-Analysis: v=2.4 cv=XsPK/1F9 c=1 sm=1 tr=0 ts=69fc9de1 cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=ia3uihG--C1vaqsH_ucA:9 a=QEXdDO2ut3YA:10 a=1OuFwYUASf3TG4hYMiVC:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-GUID: oZoincqBEOZG7weBdnKxuC4EZubWeLJ9 X-Proofpoint-ORIG-GUID: oZoincqBEOZG7weBdnKxuC4EZubWeLJ9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA3MDE0MiBTYWx0ZWRfXxl7TnFjOMXF8 710akihuE6eJu+bN418OnS6WdoAVX8mH1YTpYAOQUvfCk5a/JrryP9yI+LIVWZKKK4TzaDOXAdG MHaZsoXqsv52Un0EX4J6xH53Px4PC5y1sSze0xU/zq0Oyp6UF8ulMjr9XxdaO7CeKzkcXVt2qdw 8/34oxLUfJ1uA1hkNfiJwH8kO6w90GW3DotN3aiZ4MjygNttctbQWhht4VERDAQuz1fk2+NnRyR PyOth4WIeyAy2DQc/kYbBbkOUJuKBqe+0a0984uDa3EIP/ne2yGqWP+h9C95i5yhvP61hnKH8qO 6tVb4Hu2KEPr5BNIFbo+uSHV3VzoU8tp4khsBK841dILHo1bO5GPb8sLhOjoFRJu6U+QFECJ2kc B8kBlTYlFJ80fs1cTtPx+MK8qiaH/QcFSJI60l4yNbdsMyfwCVh5uQoa27sgKcYtfYDxQ0Yhotd /dPWJkVgKuZ71xbnPfg== 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-05-07_01,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 adultscore=0 suspectscore=0 phishscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605070142 Introduce tmc_sysfs_ops as a wrapper, wrap sysfs read operations, for reading trace data from the TMC buffer. Reviewed-by: Mike Leach Signed-off-by: Jie Gan --- drivers/hwtracing/coresight/coresight-tmc-core.c | 51 ++++++++++----------= ---- drivers/hwtracing/coresight/coresight-tmc.h | 15 +++++++ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwt= racing/coresight/coresight-tmc-core.c index bac3278ef4dd..110eedde077f 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -228,17 +228,10 @@ static int tmc_read_prepare(struct tmc_drvdata *drvda= ta) { int ret =3D 0; =20 - switch (drvdata->config_type) { - case TMC_CONFIG_TYPE_ETB: - case TMC_CONFIG_TYPE_ETF: - ret =3D tmc_read_prepare_etb(drvdata); - break; - case TMC_CONFIG_TYPE_ETR: - ret =3D tmc_read_prepare_etr(drvdata); - break; - default: + if (drvdata->sysfs_ops) + ret =3D drvdata->sysfs_ops->read_prepare(drvdata); + else ret =3D -EINVAL; - } =20 if (!ret) dev_dbg(&drvdata->csdev->dev, "TMC read start\n"); @@ -250,17 +243,10 @@ static int tmc_read_unprepare(struct tmc_drvdata *drv= data) { int ret =3D 0; =20 - switch (drvdata->config_type) { - case TMC_CONFIG_TYPE_ETB: - case TMC_CONFIG_TYPE_ETF: - ret =3D tmc_read_unprepare_etb(drvdata); - break; - case TMC_CONFIG_TYPE_ETR: - ret =3D tmc_read_unprepare_etr(drvdata); - break; - default: + if (drvdata->sysfs_ops) + ret =3D drvdata->sysfs_ops->read_unprepare(drvdata); + else ret =3D -EINVAL; - } =20 if (!ret) dev_dbg(&drvdata->csdev->dev, "TMC read end\n"); @@ -287,15 +273,7 @@ static int tmc_open(struct inode *inode, struct file *= file) static ssize_t tmc_get_sysfs_trace(struct tmc_drvdata *drvdata, loff_t pos= , size_t len, char **bufpp) { - switch (drvdata->config_type) { - case TMC_CONFIG_TYPE_ETB: - case TMC_CONFIG_TYPE_ETF: - return tmc_etb_get_sysfs_trace(drvdata, pos, len, bufpp); - case TMC_CONFIG_TYPE_ETR: - return tmc_etr_get_sysfs_trace(drvdata, pos, len, bufpp); - } - - return -EINVAL; + return drvdata->sysfs_ops->get_trace_data(drvdata, pos, len, bufpp); } =20 static ssize_t tmc_read(struct file *file, char __user *data, size_t len, @@ -764,6 +742,18 @@ static void register_crash_dev_interface(struct tmc_dr= vdata *drvdata, "Valid crash tracedata found\n"); } =20 +static const struct tmc_sysfs_ops etb_sysfs_ops =3D { + .read_prepare =3D tmc_read_prepare_etb, + .read_unprepare =3D tmc_read_unprepare_etb, + .get_trace_data =3D tmc_etb_get_sysfs_trace, +}; + +static const struct tmc_sysfs_ops etr_sysfs_ops =3D { + .read_prepare =3D tmc_read_prepare_etr, + .read_unprepare =3D tmc_read_unprepare_etr, + .get_trace_data =3D tmc_etr_get_sysfs_trace, +}; + static int __tmc_probe(struct device *dev, struct resource *res) { int ret =3D 0; @@ -823,6 +813,7 @@ static int __tmc_probe(struct device *dev, struct resou= rce *res) desc.subtype.sink_subtype =3D CORESIGHT_DEV_SUBTYPE_SINK_BUFFER; desc.ops =3D &tmc_etb_cs_ops; dev_list =3D "tmc_etb"; + drvdata->sysfs_ops =3D &etb_sysfs_ops; break; case TMC_CONFIG_TYPE_ETR: desc.groups =3D coresight_etr_groups; @@ -835,6 +826,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"; + drvdata->sysfs_ops =3D &etr_sysfs_ops; INIT_LIST_HEAD(&drvdata->etr_buf_list); break; case TMC_CONFIG_TYPE_ETF: @@ -844,6 +836,7 @@ static int __tmc_probe(struct device *dev, struct resou= rce *res) desc.subtype.link_subtype =3D CORESIGHT_DEV_SUBTYPE_LINK_FIFO; desc.ops =3D &tmc_etf_cs_ops; dev_list =3D "tmc_etf"; + drvdata->sysfs_ops =3D &etb_sysfs_ops; break; default: pr_err("%s: Unsupported TMC config\n", desc.name); diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracin= g/coresight/coresight-tmc.h index 6e994678f926..a14645b04624 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -259,6 +259,7 @@ struct etr_buf_node { * @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. + * @sysfs_ops: Read operations for the sysfs mode. */ struct tmc_drvdata { struct clk *atclk; @@ -290,6 +291,20 @@ struct tmc_drvdata { struct tmc_resrv_buf resrv_buf; struct tmc_resrv_buf crash_mdata; struct list_head etr_buf_list; + const struct tmc_sysfs_ops *sysfs_ops; +}; + +/** + * struct tmc_sysfs_ops - read operations for TMC and its helper devices + * @read_prepare: prepare operation. + * @read_unprepare: unprepare operation. + * @get_trace_data: read operation. + */ +struct tmc_sysfs_ops { + int (*read_prepare)(struct tmc_drvdata *drvdata); + int (*read_unprepare)(struct tmc_drvdata *drvdata); + ssize_t (*get_trace_data)(struct tmc_drvdata *drvdata, loff_t pos, + size_t len, char **bufpp); }; =20 struct etr_buf_operations { --=20 2.34.1 From nobody Wed Jun 10 14:02:44 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 6EB2F40627F for ; Thu, 7 May 2026 14:12:55 +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=1778163176; cv=none; b=LZV2T2ASPRWeu0pn6i0Zcu6gnkN6Kp40lap5KEMMp2PzXkshKRIWc/n4/yQy8qMmiaoMT/Wd+W9Z3mB5zF1xb3YAGhvchgHBV5EnIm1uBUVKJq84Bez+QArapWF6yv5zzDz2Ee2wH2VnO+J0AmDUu5MgdSYpc7b3SKLhjJ2rBck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778163176; c=relaxed/simple; bh=hEbivcKkn+B0aZjxHwDfTngcntTeQ3spTkM8LFWyox0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MoLt+oVt3gxL00rbQdJ9K5/gycCd7YV6zLM6mTcR6k3iGLbOY2lITzmGt7BljcK8R5wiZyqDeSY0n/YZgoKywi1fzhT9AVhG1c/GmqusjLYfedfkbknb4QXZ5zuA6IncLoj1fNYCiSvAPPxyiclgZw4tLkxU+DhNJJCvM2/OJ6c= 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=SVsvkeRv; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=PhQqOUIa; 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="SVsvkeRv"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="PhQqOUIa" 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 647ADTTB026485 for ; Thu, 7 May 2026 14:12:54 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= fTgIUNB2u1bhGm6PTFb6105x0D07MjTNsRT9rz7zUh4=; b=SVsvkeRvrUimCAYj 7dDE4bAs8uzjnXzkIl15CfSbzlHVmJAI3zVIBimjCAPyqWPjRfNr1ONsIf0Wt74+ jyl4gMTKzInG8TWJavMJoArIkCHOOJMkLRs25B32R6Ymjc+sxF5SZcAfnbSoqaAW La5S+Aw8EP2NPvlEd34EP1/w5IPr3Qi5PrN/ao+SYPN13Kc46kRvipTS2hKyQfCp ft3wWmiwOJXL5hvSI81ebuqVf9+OI/qGvBdw9hM0gm69v4V5Gy5bC/A5h5QiONwc NI9vSreTb0h8K09Y+or2+fK2TCy5NCywo4GTGHLEsopD5n+Cf8drbcMFlSp2BUvc bFxsjQ== Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e0k1t28yu-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 07 May 2026 14:12:54 +0000 (GMT) Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-c802862e9f5so921942a12.2 for ; Thu, 07 May 2026 07:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778163173; x=1778767973; 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=fTgIUNB2u1bhGm6PTFb6105x0D07MjTNsRT9rz7zUh4=; b=PhQqOUIajQApOByzpst7ZYwKE8hToPd1Dj9lw3eQP0gDu/2TIG8gObLoGezxEzF7H8 /BFsL77CDWxkjJnNgS2AvF59mm3xKJxyC5fUPakvV3hmvVi73KIiy35OHZfAJ4IgDeRS jwBejD0reURjfsTqKWwQT6UuKXEBVD2SRiItbu2v6TAoE9AHpLCC2CldHKKpLIdmZTnV qx/v8caLwqfwETzkbcaQHYtY5AAk0PQib/0eWtl6/TvTIbBxiu6gZAyAcFqhgfwmcl3Q ic8zfUJXBx3Mly9GyAyjzJpQu4NxyuLF4D7myMeIi4gF9xiQqyeVlpxcZcx3VWDqGQ0D aXQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778163173; x=1778767973; 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=fTgIUNB2u1bhGm6PTFb6105x0D07MjTNsRT9rz7zUh4=; b=OxHoXPJhRyuWXQNW5IR8gvL41AwZfTgeG1adfEJWXQBMfGSmG3tkXurLb5fEJsa9Sq SMHki/sjg25Cw9pb2crc8prSQkyILS78dBBNLFY3MUIKmSE+42NJio88uVMcUXS1GtHs /JTG64IsmWZWTX/rI4VHxkgKwxbUITfxyFY+/qf8xgnTUHEG3Lv5jID+bnaTE/ZHY29V iqBAbESOANUFppycl8436Ap5kY5w2pJmSm2gRjNfieVoReE4/4xtBYeoY6VCdHn1hfHz bJnD7rIMpNjiz1hYyqWp2gIkLx2e8TyauSm9tcIHSj/wq/8cNFVUW74aKhyWQzy87fhS mTpA== X-Forwarded-Encrypted: i=1; AFNElJ+3844IaLT3rD+9H2Fk6gDCJOXsAlGNsHq5MlQGQdy7RZMuVnL5nB+VZoBR9RqJIZ1DFO9+X959n4sSg48=@vger.kernel.org X-Gm-Message-State: AOJu0YzGeCxl+rzTECK74Oq7SEnYRAG00PQkqbzDhjOh8lveHXG0Y9ZX 8r+eLR78XcgcaCxjd1NqoBvslPYogoiKm8aGHJVdFQK5Ck+I3y0JidPLarxtKI5HkUGmawiH031 qdxiT4aOWnnx+kB1kKigAB4GL9/NBQZHjb9H1LTSA7qo40SADVBnhChCXLuBX53XxhJo= X-Gm-Gg: AeBDiet1a8uACIuGiKq/WwvN6WfOTOCoI5sIriyv5u/JfQzMxc7l9qBQ8jyFYa+u2UI Y4JJyCHwdwLnWu+fKA5Scao2wZ85yvmVRrFYu9722l3BuesQIyKXQSpR7bWRGwKCIvw+7JLCzMc 8tCr0vF3gxR/pLJbSPIxE1KklasOjJ5nkuJB/5hyBbPTpHluemwNbNTSxgDpMxDCSC49L+fUHxP xfhqWVsYfa0dn+Q06ipHmgjY/Xb0ECVwwPNjIfg+N+j14G53MC2OPzQNWqhYg3rbSN/S3I3z6VD eeUOQfrAw7nxe9n9JUFDyHTV2waTQGTcq7A/MoWqSNeSzJ44YP354iIl9rVZ2cHfaIqOkXY3rHk fOCJ0G8lGasg+nq7+E3+bG1WrjBJMmkBUKz5gT9CB/m61eAHjVizdOkKF99+GnNO/eKQwkASEQU tY3LGJhxu9Ml0UfVy3roWBsf3b87shYA== X-Received: by 2002:a05:6a20:3d1d:b0:3a3:240d:4fcb with SMTP id adf61e73a8af0-3aa5a8d4ebemr9135156637.13.1778163173418; Thu, 07 May 2026 07:12:53 -0700 (PDT) X-Received: by 2002:a05:6a20:3d1d:b0:3a3:240d:4fcb with SMTP id adf61e73a8af0-3aa5a8d4ebemr9135119637.13.1778163172924; Thu, 07 May 2026 07:12:52 -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-c8253b493c5sm2343072a12.28.2026.05.07.07.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 07:12:52 -0700 (PDT) From: Jie Gan Date: Thu, 07 May 2026 22:12:00 +0800 Subject: [PATCH v18 4/7] coresight: etr: add a new function to retrieve the CTCU device 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: <20260507-enable-byte-cntr-for-ctcu-v18-4-2b2d590463a3@oss.qualcomm.com> References: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@oss.qualcomm.com> In-Reply-To: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@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 X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778163146; l=2348; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=hEbivcKkn+B0aZjxHwDfTngcntTeQ3spTkM8LFWyox0=; b=cWwry+vjlbxC0QyK4KYC3NThL4pvoYwV6BicQS+0HllKJNcokB0qGMnvsAqmlZlqLcteC1lE6 H9aBpK6Hx4RAp4O+o10zqBQznOawn4b9w6LWgVfVLMg+95kVg1gjlF3 X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Authority-Analysis: v=2.4 cv=EoPiaycA c=1 sm=1 tr=0 ts=69fc9de6 cx=c_pps a=Oh5Dbbf/trHjhBongsHeRQ==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=FuIWbRVyn4pKkvqW11oA:9 a=QEXdDO2ut3YA:10 a=_Vgx9l1VpLgwpw_dHYaR:22 X-Proofpoint-ORIG-GUID: jLFMmFoCY5tO4Mw1PrQO_vDwIzNKybxd X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA3MDE0MiBTYWx0ZWRfX22UUQAUPbxfb Trsk/r9ObOYZO1fpxpa0Ymg9fky6qZ3EQktvDjRRT6Fgr9iRlYjjOYfUglroiXhCw45Ia/zEJlv rUZBHiOs2f6XryeAsfb0zTxPjEXVBYF3QCAsJbffCT87mTzgX7Qj8Fz8n4oHlpjVwvoeVKUE7o7 dN8id8yKH8rvyjDXG8MdL18uVbkL86mg58kaAPymdb2pztoyDkX6c5hAqkY2GuKMPdFYovX1c4G 1yWpJ4ZJuM5cHgGACz6eHAhur54GM1yaw8PQ5HIXSqcQumKgd4rzKJKlHZV1NrnTC2WEAKPKv68 SP5ohSKlORwatTNR3EhzxZrqww9FsTYea4bYX9rTXJIqIQzuJrew/ws4GeV6L6sc7jyhDNUZ+CJ E92yWtYvP7lKF4Y7Nc+KmmZECKHHxlIq54wAA13aCFKinCQ6rJ1vMgzCgcne+QD8F3QA9CJrsa+ XAQ3VSzkOPBYTu97rQA== X-Proofpoint-GUID: jLFMmFoCY5tO4Mw1PrQO_vDwIzNKybxd 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-05-07_01,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605070142 Add tmc_etr_get_ctcu_device function to find the ptr of the coresight_device of the CTCU device if the CTCU device is connected to the TMC ETR device. Signed-off-by: Jie Gan --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 24 +++++++++++++++++++++= +++ drivers/hwtracing/coresight/coresight-tmc.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtr= acing/coresight/coresight-tmc-etr.c index 779d9e479aab..b0c5f3559085 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -865,6 +865,30 @@ tmc_etr_get_catu_device(struct tmc_drvdata *drvdata) } EXPORT_SYMBOL_GPL(tmc_etr_get_catu_device); =20 +/* + * TMC ETR could be connected to a CTCU device, which can provide ATID fil= ter + * and byte-cntr service. This is represented by the output port of the TMC + * (ETR) connected to the input port of the CTCU. + * + * Returns : coresight_device ptr for the CTCU device if a CTCU is found. + * : NULL otherwise. + */ +struct coresight_device * +tmc_etr_get_ctcu_device(struct tmc_drvdata *drvdata) +{ + struct coresight_device *etr =3D drvdata->csdev; + union coresight_dev_subtype ctcu_subtype =3D { + .helper_subtype =3D CORESIGHT_DEV_SUBTYPE_HELPER_CTCU + }; + + if (!IS_ENABLED(CONFIG_CORESIGHT_CTCU)) + return NULL; + + return coresight_find_output_type(etr->pdata, CORESIGHT_DEV_TYPE_HELPER, + ctcu_subtype); +} +EXPORT_SYMBOL_GPL(tmc_etr_get_ctcu_device); + static const struct etr_buf_operations *etr_buf_ops[] =3D { [ETR_MODE_FLAT] =3D &etr_flat_buf_ops, [ETR_MODE_ETR_SG] =3D &etr_sg_buf_ops, diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracin= g/coresight/coresight-tmc.h index a14645b04624..fbb015079872 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -470,6 +470,7 @@ static inline uint32_t find_crash_tracedata_crc(struct = tmc_drvdata *drvdata, } =20 struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvda= ta); +struct coresight_device *tmc_etr_get_ctcu_device(struct tmc_drvdata *drvda= ta); =20 void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu); void tmc_etr_remove_catu_ops(void); --=20 2.34.1 From nobody Wed Jun 10 14:02:44 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 A4F814014B7 for ; Thu, 7 May 2026 14:13:00 +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=1778163182; cv=none; b=fZePZfFAlilDxVSKPtAAGffXhmCD+whirKBi0TQp7m96Vqoey3bcyty857b+jrgNfXpfv/mJMJWvb9vSfen169aulBKhKqx7/lLDcc6rSTvkAs7pP/zLJyiPtF+iI5lzm4r+b0/rRqkExXhhvU5oF/kJYIAArUdoE5blrz0ixgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778163182; c=relaxed/simple; bh=DsL6kcYT3hY1q2jvZSOp/rxfO6RBNAUHqHA9yEMzJAk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FwHYNiY+wkzpb8PC8K+QHCvQVmnKv0AxjocWvuBwP3ag4N7U55tsn/yC459NXc/qZozmIBSoy01Ud4A0LavfLJhHdG4CPDpxQQZ8ZnntAHwNqizqxQn7puhuCAnGzyaz4WisAhPhbMMsd0xipm2ClpHnSw88xNPoKuhhFOeZkxM= 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=mcO7vQ5z; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=iSp2WEpX; 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="mcO7vQ5z"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="iSp2WEpX" 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 647AVYpw151029 for ; Thu, 7 May 2026 14:12:59 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= 5AiUjeizRXgIt0pWaEk9wGXXVAIJo5RCeKWJBfIhvcE=; b=mcO7vQ5zrFKDaeqt vZqFkK2dNRnCuiDU5Ge2UVkHSkX9MI+NnMnSehHPT4KARseHSj3d4edmystXwdZb m1/7h9Ba8a6kgq2oM6AxbcAJ80V2W5GhKB3Mg5JrzR9GxZoT2QU3ewxgUcwXC/wW +QL8HwAyZK/nfbKPJDvvNzjEqfJG85k3o+6H/TNDkY0YoW8ZDxCmXqrkK3DnTA/j 8U4J8sLKYjDXV/x6xl4gnA0RUY0LZL0LCqbNIoqfoDz4kst0zJBLa/STugmEbbUS qEm+Wy3jNEd+16ApS5VNluIaeTCLVf8Y1by32t3Xz+IdM0Mk05PPn9uVswjFr83G BSBq5Q== Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e0kctt67t-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 07 May 2026 14:12:59 +0000 (GMT) Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-c823549b1fcso1088694a12.0 for ; Thu, 07 May 2026 07:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778163178; x=1778767978; 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=5AiUjeizRXgIt0pWaEk9wGXXVAIJo5RCeKWJBfIhvcE=; b=iSp2WEpX6QbFb8RpBCD079ioPlJlrMoQVX1x3l7OFI7ZltPkxBLQbhrkS+w2IXYFgk onMyD1iQIMKCnKXJ8aqovu0SuOQqsKo9JBYPWLi2JvI/BaBVyoBpZBHG4DwUUYPplY5U AO+cqjOYBO3gDHsJSrTWN3qC2yaYDVjNEBsOVaTblkt1KdY+X1X/QP0FwtA8YqphxnTN 4UzztEYIPnuxRmIcP0S82dOkqphblW8wlpWTf/bObWqyvx4dh4ReYqEbYx8ECZtYhGJe WSdljFoh0zQSmWZck038U+KHZ/YxExwU67u6zZWxbdqZw+5n7ak88E70FreCur7C2JQI OHcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778163178; x=1778767978; 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=5AiUjeizRXgIt0pWaEk9wGXXVAIJo5RCeKWJBfIhvcE=; b=PImrf+XZA00Tp/almZpPj81Pih4oPDnhLK/AFc/b2D4dNLthiSwQq00XqZxLw9k141 dozefd7pxRO+rCbXLENkNTG2OHcFactZB63Royo4R6p8+WEBk2TfdolCwROuyAT452sk jRq1Y7zPytgYCfO7kgMygsvyTWkbU7yTEeThYAucmnCrYqNod2BsxF92nPBmOiVobelg umjo7+E0gkgsdJfftlU/IIoswdhXH4U2rtizb3gLBAXeAjrxH26OEnDy/MusEsq6oR03 HYK1TapXFhrHT15zI65jFzrAPgOCL/rGOksmRTKwRMq25Va/WPbtmwwt5za9w7t9tRKS BdUQ== X-Forwarded-Encrypted: i=1; AFNElJ8b6kTuoVfkagvc2nZ3yeHshRTqiFW5RxfGHEuG69iZ8dUA9qVqqEqSVXMyZkgKoGUiYPtmtpMHYjv6Z90=@vger.kernel.org X-Gm-Message-State: AOJu0YzSORj/L2+g1C+WYJA8Fe9Ae3U3fffyznyg1KO+SjA43AAyaooo Xt61vbXhZqlD9C6rBBu3Mdu20T6qF1bzU2A6iS6LiuGeT1dZh4xZZwPGs+MYyMiBAqQcL+UVBHD ljqryQQsjyMeezEzi7VkA9v2KNXHHzTz/nTn8DUhoi2/OYsHHmw1XiA7zdR5IW6XKS2M= X-Gm-Gg: AeBDievUOcRheKITM2N0K+Z2n8bDIbsSGhB5v8kYConHX86jzASKByBjmYZ+o+VsFgI uoQv5XXQFO2MScZ8nrZrXLBhoZUR1uaMjXlItCI+uvQ8srv9e1wiTmnrq3zNFwDkk9hCSnLgJEo OdyGDOXAq+fRNzGrMQ1MjPMkwvaSdUgQR/ZhJEbx80Q5jEqIe0VpXosMpJQsXl6eiggCFHhAFUH 991RdR1NL5cET5RNntgxPUgmKX43xoUShTfRX8dflgP3fZq2IUuXO8vEOKO/CHGOfVu3vgmx7Ym oGzEG+d6SQo3rq3c6SVj9wfokgFloa0mT7dbbJfaTfGlDDVVkxzAye3leXMs+mMsy623Y4ePq0H 6xgDPlb3BhMbd/wTXaC7rnLx07vGH9udc8RCEbzWP1h3d33SxYNoX9QHra8kPCV75+RIH/Pqv1w AxLdtC2NdLi/4p3+Sv9PmHLKDkBg0UsA== X-Received: by 2002:a05:6a20:549d:b0:3a0:b781:4c78 with SMTP id adf61e73a8af0-3aa5a8fa74emr8808154637.15.1778163178468; Thu, 07 May 2026 07:12:58 -0700 (PDT) X-Received: by 2002:a05:6a20:549d:b0:3a0:b781:4c78 with SMTP id adf61e73a8af0-3aa5a8fa74emr8808117637.15.1778163178010; Thu, 07 May 2026 07:12: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-c8253b493c5sm2343072a12.28.2026.05.07.07.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 07:12:57 -0700 (PDT) From: Jie Gan Date: Thu, 07 May 2026 22:12:01 +0800 Subject: [PATCH v18 5/7] dt-bindings: arm: add an interrupt property for Coresight CTCU 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: <20260507-enable-byte-cntr-for-ctcu-v18-5-2b2d590463a3@oss.qualcomm.com> References: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@oss.qualcomm.com> In-Reply-To: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@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 , Krzysztof Kozlowski , Mike Leach X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778163147; l=1751; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=DsL6kcYT3hY1q2jvZSOp/rxfO6RBNAUHqHA9yEMzJAk=; b=cbhIVnG1Yhq18s+Tdqc3kFKI5ZPNKCtC78rrD5zLokchh/bY3YK03jTYA0TL39zB1MBdRbNi7 gAn4qnXQvYWC18pDUJo71hQc0WNHjig3kyty4rXNE9xe3WE3/ahbwok X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Authority-Analysis: v=2.4 cv=XsPK/1F9 c=1 sm=1 tr=0 ts=69fc9deb cx=c_pps a=oF/VQ+ItUULfLr/lQ2/icg==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=gSyxy6DGYGa4b6s9XCEA:9 a=QEXdDO2ut3YA:10 a=3WC7DwWrALyhR5TkjVHa:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-GUID: lEp8EaEq9zTprJ_gOCmpkFIlwlc4jT6P X-Proofpoint-ORIG-GUID: lEp8EaEq9zTprJ_gOCmpkFIlwlc4jT6P X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA3MDE0MiBTYWx0ZWRfXxDsDDj8h57F5 7FHjxonumCLOMRR8zwAP9unR7nE72leC/T1qQx5eD1Xc6+4EMw2koDi/bgBZcBbIxrcPRTRMe0G hmUzNTlHZgayCqsSvpHN4MSD/m13NqhXH5k6jiaRdHC1TU5lJB+cm8uY6QhndOZMZqvlg3EgsSc 0HOGPKGlyhATlynSiqRfPRjkfpN2y9lk7a9GIlgtLZ1NRQTwFZ5rbtKl/SJa/1fJiN7gMQqvjG4 LfGWyr0fQXbFky9vkRsVLz1ZUecAGEiO6LUxeqfwrvwkWq0zYI45M7MuV/Va3GBrC1ekpq5ou3W vM2PRHfWSjYrJNBGMtSjNT+eu/I+TzOy/puVX8+x43uuM/ByXoFvDw25FRvwlalYtgMQNnxhfI2 1Sz7WC15rxCZMdaLG8dGkDMy2lo1wFVwhb2zq/5Ov25BlNC+Rj9KdRXB6Kr5YQVXqtFh6pEcASb 1PmHpMdyp9/5Md7VPMg== 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-05-07_01,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 adultscore=0 suspectscore=0 phishscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605070142 Add an interrupt property to CTCU device. The interrupt will be triggered when the data size in the ETR buffer exceeds the threshold of the BYTECNTRVAL register. Programming a threshold in the BYTECNTRVAL register of CTCU device will enable the interrupt. Acked-by: Krzysztof Kozlowski Reviewed-by: Mike Leach Signed-off-by: Jie Gan --- Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml | 10 ++++++= ++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml= b/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml index e002f87361ad..2981001a7d7f 100644 --- a/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml +++ b/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml @@ -44,6 +44,11 @@ properties: items: - const: apb =20 + interrupts: + items: + - description: Interrupt for the ETR device connected to in-port0. + - description: Interrupt for the ETR device connected to in-port1. + label: description: Description of a coresight device. @@ -65,6 +70,8 @@ additionalProperties: false =20 examples: - | + #include + ctcu@1001000 { compatible =3D "qcom,sa8775p-ctcu"; reg =3D <0x1001000 0x1000>; @@ -72,6 +79,9 @@ examples: clocks =3D <&aoss_qmp>; clock-names =3D "apb"; =20 + interrupts =3D , + ; + in-ports { #address-cells =3D <1>; #size-cells =3D <0>; --=20 2.34.1 From nobody Wed Jun 10 14:02:44 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 A31903FB7D9 for ; Thu, 7 May 2026 14:13:06 +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=1778163188; cv=none; b=QSWX3SYJxYpXJlFQ2G5IVBujgT48/ypx3ByA7NQVZDMJklRWIfc2sNHcyrEL2xFhOz95dKeuEZ2scw6amJ5LKHTvWfPIa8tfwFRYO2asuzXFTtq961Ysq3WH7rVh9FSJVsEuEnWbg3db6u8bsqndofdTWQpE5OsMmo3sjxHbDQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778163188; c=relaxed/simple; bh=C43ztlkdXLgHobJVGNfnHS4uALhoFsNh9daMCxVvLLg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T7VK3kKaS9otCzKqHVd0tDng5PbZUEBX2rCtIBphIt7GeasYCvc77fbEmFHbMh+gjrDy5wXA5GrZ/xfHrFHp4Mzc7KUzUlxkvJTpMBe4QBmf+Y8qad0h3PXYD6wy4XIlI/XD1spo7O/LuSCXyCqm9wmXX7wO8zDi29WUFsE7bWU= 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=d4oBa3ej; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=UwwQGJ6g; 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="d4oBa3ej"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="UwwQGJ6g" 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 647AGPfT151128 for ; Thu, 7 May 2026 14:13:05 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= xSan2OkRjcVVa/mUzhx42dSs1y4w5tQ8PI7mAoQHOcA=; b=d4oBa3ejlma+EBuJ w/q/mE577qAj7UKy1H9F7kmECcZbRtEqQ5VPY8tDH3HdUBGGA3YwUuPuPmnfxha1 E5iWEiL5VfmTtkV6VrusuuDYQd2qfeuOm8l+I4pxa1MhKrrV0nKnSmEUdLBMZatD jreQE9oz/0zPlXYAR1p3Jz/dCIlGtrYlG2STLeYyP4qKk9xZYGcGEOILv3kNsft2 mwV/+D3Br1rSPbpP069AJ+3q74aioo+iKf3gF4Z6boRDnMJeD8JzK0hNMUaiLLG0 Fp4x329Eih+apqGYD17fDsAFRLLRSgUnV+tTF7A9E18M0OBaWpiCiSR4SarlTmPQ 2T1s1Q== 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 4e0kctt68e-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 07 May 2026 14:13:05 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-36531a0f95bso1142154a91.0 for ; Thu, 07 May 2026 07:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778163185; x=1778767985; 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=xSan2OkRjcVVa/mUzhx42dSs1y4w5tQ8PI7mAoQHOcA=; b=UwwQGJ6gWA9Y7b9xVpz1an8A6t7wEWrShewfoKyWaFYUs5rTWTR3VzcISsWJQ6zqNr QV5bGlTB5v8nw0AQitNG7m9A2e+/4Z74ogUOBFqk74wEBzaptFEARkkpl/i3K2aDTScm bxcfC6G2fP1omu3BlYLuCkmkC9H4usxh76PU7e4YnLluo/La787tSVd5x3JRDyLiuN1S MtA2ExQaNzuwWZH3RRBuYBf5Nsca2O0FVAYrjuF5zGg6ZVxT/dIddOBXejLeS5IeInpG 5e8bmqPOSter3b1aKQpqy7XtvoEJjpyBifFn57kMPafKI50jR8Cfk16bwvx4Bcxz8dDP SFXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778163185; x=1778767985; 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=xSan2OkRjcVVa/mUzhx42dSs1y4w5tQ8PI7mAoQHOcA=; b=QKnA5N7bezbnfUqKTeunECy6TOzE0ueyLFPLmHbE4XsResXC8Y7RhId7xatDL/tVEc DdTgR+9FGHEofqNBeAkFIJoN/qSLxFtp1ySN/rNBEG/NAAog3wiPIbz5mWjKocXP9JFw 2/+2SkS9eCy6CU9fg71+oWwglN/rC9Qz6GgAtGej0467flIoM+tZdMboA9UgUr7O3sy2 kKIZzHkEHk1vMrGMehh93gYhB/tofq7+8Z0G7oG59TNOrNlNL0uc6L4xcxkdljjL+Bra Ce6PQEQAoNv1aKaPCnS61wyWZ17aOrIgTTW0Gsq+zTf/ELbUGpiZ+4Xv685L/j8uIbeb 4KoQ== X-Forwarded-Encrypted: i=1; AFNElJ/LLPzL6P0XKbiz5xVJT2EIDG/QVGiNQDP+mb9Kfa+cYpykj5k6TtQhRG5WC+Adw0L/UqfJgY+JzhSWNjA=@vger.kernel.org X-Gm-Message-State: AOJu0YzOCVNfiuXcnQMbGm7uB6q5CvuU+gQxxc1ZhKoxPeRr7YN3I+y7 sqQwHMiP+KCqLfVUUx8CbnZ9uf0/FzjON++ih/nytsAkdZY5+zjtFpVVjOICxPSGSwoKe70zLEh ZnwC1bON0wMvgycRmeLOo+a68jK623/O7gRZtXCu2Vd97pfxT39Rm2l0bQxGwT6CmgVw= X-Gm-Gg: AeBDietHelPo+ytHw7YPOIg2XD/S+ujt2es/D31zsEKBmDyfegEL+BVPdjcUyirQFUA OUt9Rm/Nyzslfk5Lstf1tMNdth6KRKg7x+ZkNOL1ZwCXpC2LU8mZ7nuzTuX8n2Ny2zdRiw0+mFG 1CE1HdY0sPvdLoZI9m856ektRAvTpIkFdke+2Yq8aEPUya+uGWMBK5xRD7FFGxo+u4TaVmCZp4C q/smHnrYW8EF37JYWHZrofNr+dlSeUvO3fY1fymex5+wfY5ZGxw3cJiCREQKJbkyVreoPW+VLGz uXRTFnWa4NZ97d0MoLy3CBBUr3R7U7/KDtxiRh3ZyVcMA9Nu1WtxqI/IYJE3vERcHaYMk+Cf+dw MXLf/VqPATCz2nqHvM3+hpGkAHm0/Ummn8Jl/ciM1qHZ+3khiWbQRInQ/s8n8xIhZrHekFXS/fD xIC2K/RWOBVVoDWItCwSI= X-Received: by 2002:a05:6a20:94ca:b0:39b:8dcb:f36d with SMTP id adf61e73a8af0-3aa5aac87ebmr8672915637.35.1778163184114; Thu, 07 May 2026 07:13:04 -0700 (PDT) X-Received: by 2002:a05:6a20:94ca:b0:39b:8dcb:f36d with SMTP id adf61e73a8af0-3aa5aac87ebmr8672835637.35.1778163183146; Thu, 07 May 2026 07:13:03 -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-c8253b493c5sm2343072a12.28.2026.05.07.07.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 07:13:02 -0700 (PDT) From: Jie Gan Date: Thu, 07 May 2026 22:12:02 +0800 Subject: [PATCH v18 6/7] coresight: ctcu: enable byte-cntr for TMC ETR devices 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: <20260507-enable-byte-cntr-for-ctcu-v18-6-2b2d590463a3@oss.qualcomm.com> References: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@oss.qualcomm.com> In-Reply-To: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@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 X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778163147; l=30512; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=C43ztlkdXLgHobJVGNfnHS4uALhoFsNh9daMCxVvLLg=; b=P5kxXzHAvpKbbu1DV/k8m25tPT0OZgSHeN+fIBe0VAMEByxkIOc1gbR0uZYaTlOP+Gow3NGOH PzZWo7IauCSBkxRMTBU1u2MV6zvtw5rz5t+rRALK5lYtheOnzIIKC2L X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Authority-Analysis: v=2.4 cv=XsPK/1F9 c=1 sm=1 tr=0 ts=69fc9df1 cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=o-scWc0g34K81CHX7UgA:9 a=QEXdDO2ut3YA:10 a=rl5im9kqc5Lf4LNbBjHf:22 X-Proofpoint-GUID: NimrOv9ofGw8QbGKsBh0HVgS9tJqDR_D X-Proofpoint-ORIG-GUID: NimrOv9ofGw8QbGKsBh0HVgS9tJqDR_D X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA3MDE0MiBTYWx0ZWRfX5JUqP04No+XQ IMoVS1BSSrHrHCTVcXkYmSXoSxIuGWgnaQpdcOp3rbXnusMpx6x1Nb1njMeABDq8uGGB/GOVdzl TtI+mhzXfbdxqZt1WsLRTE59WPYfWhmB7ycvcpIhOH328/yKCbQCNwK3eG0ZA8mkhmyznieoXA+ KJZX/gAiZvDFnLXDl67dQ/5dpQJheB77zw+0qhAlcBiNWdDhOSpL6T/Euo345S0+9yqu0YVFY5R re5F6LiyVTDWUNo1NRyBjlrWTYGY0Uk2m6K9rSfXnzKG6uNicaYwJD3qxpo9hbJS/0b/pRth5JB X439S0iRWQLpJbnd2Iqpw92i3WcWKnCWUUPmM3qe7Nk4ZwK4gvyH2AUF0uxkRXiOZOU6nWx+Njp 6lTioOMDpsk+vTbqS+bLwDZ4Sv83m85PkRnPGeUQ2fPgHoufjLvCLE4IN5ejhU8p2XNulLbhXUo Wj+aj//CPVNCYc/4KAA== 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-05-07_01,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 adultscore=0 suspectscore=0 phishscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605070142 The byte-cntr function provided by the CTCU device is used to transfer data from the ETR buffer to the userspace. An interrupt is triggered if the data size exceeds the threshold set in the BYTECNTRVAL register. The interrupt handler counts the number of triggered interruptions and the read function will read the data from the synced ETR buffer. Switching the sysfs_buf when current buffer is full or the timeout is triggered and resets rrp and rwp registers after switched the buffer. The synced buffer will become available for reading after the switch. Byte-cntr workflow: start -> ctcu_enable(ctcu_byte_cntr_start) -> tmc_enable_etr_sink -> tmc_read_prepare_etr(jump to tmc_read_prepare_byte_cntr) -> tmc_etr_get_sysfs_trace(jump to tmc_byte_cntr_get_data) -> tmc_disable_etr_sink -> ctcu_disable(ctcu_byte_cntr_stop) -> tmc_read_unprepare_etr(jump to tmc_read_unprepare_byte_cntr) -> finish Signed-off-by: Jie Gan --- .../ABI/testing/sysfs-bus-coresight-devices-ctcu | 9 + drivers/hwtracing/coresight/Makefile | 2 +- .../hwtracing/coresight/coresight-ctcu-byte-cntr.c | 304 +++++++++++++++++= ++++ drivers/hwtracing/coresight/coresight-ctcu-core.c | 127 ++++++++- drivers/hwtracing/coresight/coresight-ctcu.h | 79 +++++- drivers/hwtracing/coresight/coresight-tmc-core.c | 3 +- drivers/hwtracing/coresight/coresight-tmc-etr.c | 114 +++++++- drivers/hwtracing/coresight/coresight-tmc.h | 9 + 8 files changed, 622 insertions(+), 25 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-coresight-devices-ctcu b/D= ocumentation/ABI/testing/sysfs-bus-coresight-devices-ctcu new file mode 100644 index 000000000000..6e53a5197e53 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-coresight-devices-ctcu @@ -0,0 +1,9 @@ +What: /sys/bus/coresight/devices//irq_enabled[0:1] +Date: May 2026 +KernelVersion: 7.2 +Contact: Tingwei Zhang ; Jinlong Ma= o ; Jie Gan +Description: + (RW) Configure the flag to enable interrupt to count data during CTCU en= ablement. + An interrupt is generated when the data size exceeds the value set in th= e IRQ register. + 0 : disable + 1 : enable diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/cores= ight/Makefile index ab16d06783a5..821a1b06b20c 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -55,5 +55,5 @@ coresight-cti-y :=3D coresight-cti-core.o coresight-cti-p= latform.o \ obj-$(CONFIG_ULTRASOC_SMB) +=3D ultrasoc-smb.o obj-$(CONFIG_CORESIGHT_DUMMY) +=3D coresight-dummy.o obj-$(CONFIG_CORESIGHT_CTCU) +=3D coresight-ctcu.o -coresight-ctcu-y :=3D coresight-ctcu-core.o +coresight-ctcu-y :=3D coresight-ctcu-core.o coresight-ctcu-byte-cntr.o obj-$(CONFIG_CORESIGHT_KUNIT_TESTS) +=3D coresight-kunit-tests.o diff --git a/drivers/hwtracing/coresight/coresight-ctcu-byte-cntr.c b/drive= rs/hwtracing/coresight/coresight-ctcu-byte-cntr.c new file mode 100644 index 000000000000..268194f35fd3 --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-ctcu-byte-cntr.c @@ -0,0 +1,304 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#include +#include +#include +#include +#include +#include + +#include "coresight-ctcu.h" +#include "coresight-priv.h" +#include "coresight-tmc.h" + +static irqreturn_t byte_cntr_handler(int irq, void *data) +{ + struct ctcu_byte_cntr *byte_cntr_data =3D data; + + atomic_inc(&byte_cntr_data->irq_cnt); + wake_up(&byte_cntr_data->wq); + + return IRQ_HANDLED; +} + +static void ctcu_cfg_byte_cntr_reg(struct ctcu_drvdata *drvdata, u32 val, + u32 offset) +{ + /* A one value for IRQCTRL register represents 8 bytes */ + ctcu_program_register(drvdata, val / 8, offset); +} + +static struct ctcu_byte_cntr *ctcu_get_byte_cntr(struct coresight_device *= ctcu, + struct coresight_device *etr) +{ + struct ctcu_drvdata *drvdata =3D dev_get_drvdata(ctcu->dev.parent); + int port; + + port =3D coresight_get_in_port(etr, ctcu); + if (port < 0 || port > 1) + return NULL; + + return &drvdata->byte_cntr_data[port]; +} + +static bool ctcu_byte_cntr_switch_buffer(struct tmc_drvdata *etr_drvdata, + struct ctcu_byte_cntr *byte_cntr_data) +{ + struct etr_buf_node *nd, *next, *curr_node =3D NULL, *picked_node =3D NUL= L; + struct etr_buf *curr_buf =3D etr_drvdata->sysfs_buf; + bool found_free_buf =3D false; + + if (WARN_ON(!etr_drvdata || !byte_cntr_data)) + return false; + + /* Stop the ETR before initiating the switch */ + if (coresight_get_mode(etr_drvdata->csdev) !=3D CS_MODE_DISABLED) + tmc_etr_enable_disable_hw(etr_drvdata, false); + + list_for_each_entry_safe(nd, next, &etr_drvdata->etr_buf_list, link) { + /* curr_buf is free for next round */ + if (nd->sysfs_buf =3D=3D curr_buf) { + nd->is_free =3D true; + curr_node =3D nd; + } else if (!found_free_buf && nd->is_free) { + picked_node =3D nd; + found_free_buf =3D true; + } + } + + if (found_free_buf) { + curr_node->pos =3D 0; + curr_node->reading =3D true; + byte_cntr_data->buf_node =3D curr_node; + etr_drvdata->sysfs_buf =3D picked_node->sysfs_buf; + etr_drvdata->etr_buf =3D picked_node->sysfs_buf; + picked_node->is_free =3D false; + /* Reset irq_cnt for next etr_buf */ + atomic_set(&byte_cntr_data->irq_cnt, 0); + /* Restart the ETR once a free buffer is available */ + if (coresight_get_mode(etr_drvdata->csdev) !=3D CS_MODE_DISABLED) + tmc_etr_enable_disable_hw(etr_drvdata, true); + } + + return found_free_buf; +} + +/* + * ctcu_byte_cntr_get_data() - reads data from the deactivated and filled = buffer. + * The byte-cntr reading work reads data from the deactivated and filled b= uffer. + * The read operation waits for a buffer to become available, either fille= d or + * upon timeout, and then reads trace data from the synced buffer. + */ +static ssize_t tmc_byte_cntr_get_data(struct tmc_drvdata *etr_drvdata, lof= f_t pos, + size_t len, char **bufpp) +{ + struct coresight_device *ctcu =3D tmc_etr_get_ctcu_device(etr_drvdata); + struct device *dev =3D &etr_drvdata->csdev->dev; + struct ctcu_byte_cntr *byte_cntr_data; + struct etr_buf *sysfs_buf; + atomic_t *irq_cnt; + ssize_t actual; + int ret; + + byte_cntr_data =3D ctcu_get_byte_cntr(ctcu, etr_drvdata->csdev); + if (!byte_cntr_data || !byte_cntr_data->irq_enabled) + return -EINVAL; + + irq_cnt =3D &byte_cntr_data->irq_cnt; + +wait_buffer: + if (!byte_cntr_data->buf_node) { + ret =3D wait_event_interruptible_timeout(byte_cntr_data->wq, + (atomic_read(irq_cnt) >=3D MAX_IRQ_CNT - 1) || + !byte_cntr_data->enable, + BYTE_CNTR_TIMEOUT); + if (ret < 0) + return ret; + /* + * The current etr_buf is almost full or timeout is triggered, + * so switch the buffer and mark the switched buffer as reading. + */ + if (byte_cntr_data->enable) { + if (!ctcu_byte_cntr_switch_buffer(etr_drvdata, byte_cntr_data)) { + dev_err(dev, "Switch buffer failed for the byte-cntr\n"); + return -ENOMEM; + } + } else { + /* Exit byte-cntr reading */ + return 0; + } + } + + /* Check the status of current etr_buf */ + if (atomic_read(irq_cnt) >=3D MAX_IRQ_CNT) + dev_warn(dev, "Data overwrite happened\n"); + + pos =3D byte_cntr_data->buf_node->pos; + sysfs_buf =3D byte_cntr_data->buf_node->sysfs_buf; + actual =3D tmc_etr_read_sysfs_buf(sysfs_buf, pos, len, bufpp); + if (actual <=3D 0) { + /* Reset buf_node upon reading is finished or failed */ + byte_cntr_data->buf_node->reading =3D false; + byte_cntr_data->buf_node =3D NULL; + + /* + * Nothing in the buffer, waiting for the next buffer + * to be filled. + */ + if (actual =3D=3D 0) + goto wait_buffer; + } + + return actual; +} + +static int tmc_read_prepare_byte_cntr(struct tmc_drvdata *etr_drvdata) +{ + struct coresight_device *ctcu =3D tmc_etr_get_ctcu_device(etr_drvdata); + struct ctcu_byte_cntr *byte_cntr_data; + unsigned long flags; + int ret =3D 0; + + /* byte-cntr is operating with SYSFS mode being enabled only */ + if (coresight_get_mode(etr_drvdata->csdev) !=3D CS_MODE_SYSFS) + return -EINVAL; + + byte_cntr_data =3D ctcu_get_byte_cntr(ctcu, etr_drvdata->csdev); + if (!byte_cntr_data || !byte_cntr_data->irq_enabled) + return -EINVAL; + + raw_spin_lock_irqsave(&byte_cntr_data->spin_lock, flags); + if (byte_cntr_data->reading) { + raw_spin_unlock_irqrestore(&byte_cntr_data->spin_lock, flags); + return -EBUSY; + } + + /* byte_cntr_data->enable may race with ctcu_platform_remove() */ + if (!byte_cntr_data->enable) { + raw_spin_unlock_irqrestore(&byte_cntr_data->spin_lock, flags); + return -ENODEV; + } + + byte_cntr_data->reading =3D true; + raw_spin_unlock_irqrestore(&byte_cntr_data->spin_lock, flags); + /* Setup an available etr_buf_list for byte-cntr */ + ret =3D tmc_create_etr_buf_list(etr_drvdata, 2); + if (ret) { + byte_cntr_data->reading =3D false; + return ret; + } + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + atomic_set(&byte_cntr_data->irq_cnt, 0); + /* + * Configure the byte-cntr register to enable IRQ. The configured + * size is 5% of the buffer_size. + */ + ctcu_cfg_byte_cntr_reg(byte_cntr_data->ctcu_drvdata, + etr_drvdata->size / MAX_IRQ_CNT, + byte_cntr_data->irq_ctrl_offset); + enable_irq_wake(byte_cntr_data->irq); + byte_cntr_data->buf_node =3D NULL; + + return 0; +} + +static int tmc_read_unprepare_byte_cntr(struct tmc_drvdata *etr_drvdata) +{ + struct coresight_device *ctcu =3D tmc_etr_get_ctcu_device(etr_drvdata); + struct ctcu_byte_cntr *byte_cntr_data; + + byte_cntr_data =3D ctcu_get_byte_cntr(ctcu, etr_drvdata->csdev); + if (!byte_cntr_data || !byte_cntr_data->irq_enabled) + return -EINVAL; + + tmc_clean_etr_buf_list(etr_drvdata); + scoped_guard(raw_spinlock_irqsave, &byte_cntr_data->spin_lock) { + /* Configure the byte-cntr register to disable IRQ */ + ctcu_cfg_byte_cntr_reg(byte_cntr_data->ctcu_drvdata, 0, + byte_cntr_data->irq_ctrl_offset); + disable_irq_wake(byte_cntr_data->irq); + byte_cntr_data->buf_node =3D NULL; + byte_cntr_data->reading =3D false; + } + wake_up(&byte_cntr_data->wq); + + return 0; +} + +const struct tmc_sysfs_ops byte_cntr_sysfs_ops =3D { + .read_prepare =3D tmc_read_prepare_byte_cntr, + .read_unprepare =3D tmc_read_unprepare_byte_cntr, + .get_trace_data =3D tmc_byte_cntr_get_data, +}; + +/* Start the byte-cntr function when the path is enabled. */ +void ctcu_byte_cntr_start(struct coresight_device *csdev, struct coresight= _path *path) +{ + struct coresight_device *sink =3D coresight_get_sink(path); + struct ctcu_byte_cntr *byte_cntr_data; + + byte_cntr_data =3D ctcu_get_byte_cntr(csdev, sink); + if (!byte_cntr_data) + return; + + /* Don't start byte-cntr function when irq_enabled is not set. */ + if (!byte_cntr_data->irq_enabled || byte_cntr_data->enable) + return; + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + byte_cntr_data->enable =3D true; +} + +/* Stop the byte-cntr function when the path is disabled. */ +void ctcu_byte_cntr_stop(struct coresight_device *csdev, struct coresight_= path *path) +{ + struct coresight_device *sink =3D coresight_get_sink(path); + struct ctcu_byte_cntr *byte_cntr_data; + + if (coresight_get_mode(sink) =3D=3D CS_MODE_SYSFS) + return; + + byte_cntr_data =3D ctcu_get_byte_cntr(csdev, sink); + if (!byte_cntr_data) + return; + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + byte_cntr_data->enable =3D false; +} + +void ctcu_byte_cntr_init(struct device *dev, struct ctcu_drvdata *drvdata,= int etr_num) +{ + struct ctcu_byte_cntr *byte_cntr_data; + struct device_node *nd =3D dev->of_node; + int irq_num, ret, i, irq_registered =3D 0; + + for (i =3D 0; i < etr_num; i++) { + byte_cntr_data =3D &drvdata->byte_cntr_data[i]; + irq_num =3D of_irq_get(nd, i); + if (irq_num < 0) { + dev_err(dev, "Failed to get IRQ from DT for port%d\n", i); + continue; + } + + ret =3D devm_request_irq(dev, irq_num, byte_cntr_handler, + IRQF_TRIGGER_RISING | IRQF_SHARED, + dev_name(dev), byte_cntr_data); + if (ret) { + dev_err(dev, "Failed to register IRQ for port%d\n", i); + continue; + } + + byte_cntr_data->irq =3D irq_num; + byte_cntr_data->ctcu_drvdata =3D drvdata; + init_waitqueue_head(&byte_cntr_data->wq); + raw_spin_lock_init(&byte_cntr_data->spin_lock); + irq_registered++; + } + + if (irq_registered) + tmc_etr_set_byte_cntr_sysfs_ops(&byte_cntr_sysfs_ops); +} diff --git a/drivers/hwtracing/coresight/coresight-ctcu-core.c b/drivers/hw= tracing/coresight/coresight-ctcu-core.c index e8720026c9e3..2da1a6f3d29f 100644 --- a/drivers/hwtracing/coresight/coresight-ctcu-core.c +++ b/drivers/hwtracing/coresight/coresight-ctcu-core.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights res= erved. + * Copyright (c) 2024-2026 Qualcomm Innovation Center, Inc. All rights res= erved. + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. */ =20 #include @@ -18,6 +19,7 @@ =20 #include "coresight-ctcu.h" #include "coresight-priv.h" +#include "coresight-tmc.h" =20 #define ctcu_writel(drvdata, val, offset) __raw_writel((val), drvdata->bas= e + offset) #define ctcu_readl(drvdata, offset) __raw_readl(drvdata->base + offset) @@ -43,17 +45,21 @@ =20 #define CTCU_ATID_REG_BIT(traceid) (traceid % 32) #define CTCU_ATID_REG_SIZE 0x10 +#define CTCU_ETR0_IRQCTRL 0x6c +#define CTCU_ETR1_IRQCTRL 0x70 #define CTCU_ETR0_ATID0 0xf8 #define CTCU_ETR1_ATID0 0x108 =20 static const struct ctcu_etr_config sa8775p_etr_cfgs[] =3D { { - .atid_offset =3D CTCU_ETR0_ATID0, - .port_num =3D 0, + .atid_offset =3D CTCU_ETR0_ATID0, + .irq_ctrl_offset =3D CTCU_ETR0_IRQCTRL, + .port_num =3D 0, }, { - .atid_offset =3D CTCU_ETR1_ATID0, - .port_num =3D 1, + .atid_offset =3D CTCU_ETR1_ATID0, + .irq_ctrl_offset =3D CTCU_ETR1_IRQCTRL, + .port_num =3D 1, }, }; =20 @@ -62,6 +68,85 @@ static const struct ctcu_config sa8775p_cfgs =3D { .num_etr_config =3D ARRAY_SIZE(sa8775p_etr_cfgs), }; =20 +void ctcu_program_register(struct ctcu_drvdata *drvdata, u32 val, u32 offs= et) +{ + CS_UNLOCK(drvdata->base); + ctcu_writel(drvdata, val, offset); + CS_LOCK(drvdata->base); +} + +static ssize_t irq_enabled_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ctcu_byte_cntr_irq_attribute *irq_attr =3D + container_of(attr, struct ctcu_byte_cntr_irq_attribute, attr); + struct ctcu_drvdata *drvdata =3D dev_get_drvdata(dev->parent); + u8 port =3D irq_attr->port; + + if (!drvdata->byte_cntr_data[port].irq_ctrl_offset) + return -EINVAL; + + return sysfs_emit(buf, "%u\n", + (unsigned int)drvdata->byte_cntr_data[port].irq_enabled); +} + +static ssize_t irq_enabled_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t size) +{ + struct ctcu_byte_cntr_irq_attribute *irq_attr =3D + container_of(attr, struct ctcu_byte_cntr_irq_attribute, attr); + struct ctcu_drvdata *drvdata =3D dev_get_drvdata(dev->parent); + u8 port =3D irq_attr->port; + unsigned long val; + + if (kstrtoul(buf, 0, &val)) + return -EINVAL; + + guard(raw_spinlock_irqsave)(&drvdata->byte_cntr_data[port].spin_lock); + if (drvdata->byte_cntr_data[port].reading) + return -EBUSY; + else if (drvdata->byte_cntr_data[port].irq_ctrl_offset) + drvdata->byte_cntr_data[port].irq_enabled =3D !!val; + + return size; +} + +static umode_t irq_enabled_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device_attribute *dev_attr =3D + container_of(attr, struct device_attribute, attr); + struct ctcu_byte_cntr_irq_attribute *irq_attr =3D + container_of(dev_attr, struct ctcu_byte_cntr_irq_attribute, attr); + struct device *dev =3D kobj_to_dev(kobj); + struct ctcu_drvdata *drvdata =3D dev_get_drvdata(dev->parent); + u8 port =3D irq_attr->port; + + if (drvdata && drvdata->byte_cntr_data[port].irq_ctrl_offset) + return attr->mode; + + return 0; +} + +static struct attribute *ctcu_attrs[] =3D { + ctcu_byte_cntr_irq_rw(0), + ctcu_byte_cntr_irq_rw(1), + NULL, +}; + +static struct attribute_group ctcu_attr_grp =3D { + .attrs =3D ctcu_attrs, + .is_visible =3D irq_enabled_is_visible, +}; + +static const struct attribute_group *ctcu_attr_grps[] =3D { + &ctcu_attr_grp, + NULL, +}; + static void ctcu_program_atid_register(struct ctcu_drvdata *drvdata, u32 r= eg_offset, u8 bit, bool enable) { @@ -140,11 +225,15 @@ static int ctcu_set_etr_traceid(struct coresight_devi= ce *csdev, struct coresight static int ctcu_enable(struct coresight_device *csdev, enum cs_mode mode, struct coresight_path *path) { + ctcu_byte_cntr_start(csdev, path); + return ctcu_set_etr_traceid(csdev, path, true); } =20 static int ctcu_disable(struct coresight_device *csdev, struct coresight_p= ath *path) { + ctcu_byte_cntr_stop(csdev, path); + return ctcu_set_etr_traceid(csdev, path, false); } =20 @@ -195,7 +284,10 @@ static int ctcu_probe(struct platform_device *pdev) for (i =3D 0; i < cfgs->num_etr_config; i++) { etr_cfg =3D &cfgs->etr_cfgs[i]; drvdata->atid_offset[i] =3D etr_cfg->atid_offset; + drvdata->byte_cntr_data[i].irq_ctrl_offset =3D + etr_cfg->irq_ctrl_offset; } + ctcu_byte_cntr_init(dev, drvdata, cfgs->num_etr_config); } } =20 @@ -209,6 +301,7 @@ static int ctcu_probe(struct platform_device *pdev) desc.dev =3D dev; desc.ops =3D &ctcu_ops; desc.access =3D CSDEV_ACCESS_IOMEM(base); + desc.groups =3D ctcu_attr_grps; raw_spin_lock_init(&drvdata->spin_lock); =20 drvdata->csdev =3D coresight_register(&desc); @@ -244,10 +337,34 @@ static int ctcu_platform_probe(struct platform_device= *pdev) static void ctcu_platform_remove(struct platform_device *pdev) { struct ctcu_drvdata *drvdata =3D platform_get_drvdata(pdev); + struct ctcu_byte_cntr *byte_cntr_data; + unsigned long flags; + int i; =20 if (WARN_ON(!drvdata)) return; =20 + /* + * Signal all active byte-cntr readers to exit, then wait for them to + * finish before resetting the ops pointer and freeing driver data. + * Without this, a reader blocked in wait_event_interruptible_timeout() + * would access the freed ctcu_drvdata wait-queue head (use-after-free). + */ + for (i =3D 0; i < ETR_MAX_NUM; i++) { + byte_cntr_data =3D &drvdata->byte_cntr_data[i]; + raw_spin_lock_irqsave(&byte_cntr_data->spin_lock, flags); + /* Set enable=3Dfalse for all ports to signal teardown to racing readers= */ + byte_cntr_data->enable =3D false; + if (!byte_cntr_data->reading) { + raw_spin_unlock_irqrestore(&byte_cntr_data->spin_lock, flags); + continue; + } + raw_spin_unlock_irqrestore(&byte_cntr_data->spin_lock, flags); + wake_up_all(&byte_cntr_data->wq); + wait_event(byte_cntr_data->wq, !byte_cntr_data->reading); + } + + tmc_etr_reset_byte_cntr_sysfs_ops(); ctcu_remove(pdev); pm_runtime_disable(&pdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-ctcu.h b/drivers/hwtraci= ng/coresight/coresight-ctcu.h index e9594c38dd91..a2ae0a0d91d0 100644 --- a/drivers/hwtracing/coresight/coresight-ctcu.h +++ b/drivers/hwtracing/coresight/coresight-ctcu.h @@ -1,23 +1,31 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights res= erved. + * Copyright (c) 2024-2026 Qualcomm Innovation Center, Inc. All rights res= erved. + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. */ =20 #ifndef _CORESIGHT_CTCU_H #define _CORESIGHT_CTCU_H + +#include #include "coresight-trace-id.h" =20 /* Maximum number of supported ETR devices for a single CTCU. */ #define ETR_MAX_NUM 2 =20 +#define BYTE_CNTR_TIMEOUT (3 * HZ) +#define MAX_IRQ_CNT 20 + /** * struct ctcu_etr_config * @atid_offset: offset to the ATID0 Register. - * @port_num: in-port number of CTCU device that connected to ETR. + * @port_num: in-port number of the CTCU device that connected to ETR. + * @irq_ctrl_offset: offset to the BYTECNTRVAL register. */ struct ctcu_etr_config { const u32 atid_offset; const u32 port_num; + const u32 irq_ctrl_offset; }; =20 struct ctcu_config { @@ -25,15 +33,68 @@ struct ctcu_config { int num_etr_config; }; =20 -struct ctcu_drvdata { - void __iomem *base; - struct clk *apb_clk; - struct device *dev; - struct coresight_device *csdev; +/** + * struct ctcu_byte_cntr + * @enable: indicates that byte_cntr function is enabled or not. + * @irq_enabled: indicates that the interruption is enabled. + * @reading: indicates that byte_cntr is reading. + * @irq: allocated number of the IRQ. + * @irq_cnt: IRQ count number of the triggered interruptions. + * @wq: waitqueue for reading data from ETR buffer. + * @spin_lock: spinlock of the byte_cntr_data. + * @irq_ctrl_offset: offset to the BYTECNTVAL Register. + * @ctcu_drvdata: drvdata of the CTCU device. + * @buf_node: etr_buf_node for reading. + */ +struct ctcu_byte_cntr { + bool enable; + bool irq_enabled; + bool reading; + int irq; + atomic_t irq_cnt; + wait_queue_head_t wq; raw_spinlock_t spin_lock; - u32 atid_offset[ETR_MAX_NUM]; + u32 irq_ctrl_offset; + struct ctcu_drvdata *ctcu_drvdata; + struct etr_buf_node *buf_node; +}; + +struct ctcu_drvdata { + void __iomem *base; + struct clk *apb_clk; + struct device *dev; + struct coresight_device *csdev; + struct ctcu_byte_cntr byte_cntr_data[ETR_MAX_NUM]; + raw_spinlock_t spin_lock; + u32 atid_offset[ETR_MAX_NUM]; /* refcnt for each traceid of each sink */ - u8 traceid_refcnt[ETR_MAX_NUM][CORESIGHT_TRACE_ID_RES_TOP]; + u8 traceid_refcnt[ETR_MAX_NUM][CORESIGHT_TRACE_ID_RES_TOP]; }; =20 +/** + * struct ctcu_byte_cntr_irq_attribute + * @attr: The device attribute. + * @port: port number. + */ +struct ctcu_byte_cntr_irq_attribute { + struct device_attribute attr; + u8 port; +}; + +#define ctcu_byte_cntr_irq_rw(port) \ + (&((struct ctcu_byte_cntr_irq_attribute[]) { \ + { \ + __ATTR(irq_enabled##port, 0644, irq_enabled_show, \ + irq_enabled_store), \ + port, \ + } \ + })[0].attr.attr) + +void ctcu_program_register(struct ctcu_drvdata *drvdata, u32 val, u32 offs= et); + +/* Byte-cntr functions */ +void ctcu_byte_cntr_start(struct coresight_device *csdev, struct coresight= _path *path); +void ctcu_byte_cntr_stop(struct coresight_device *csdev, struct coresight_= path *path); +void ctcu_byte_cntr_init(struct device *dev, struct ctcu_drvdata *drvdata,= int port_num); + #endif diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwt= racing/coresight/coresight-tmc-core.c index 110eedde077f..9f4fd86e8c32 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -293,7 +293,8 @@ static ssize_t tmc_read(struct file *file, char __user = *data, size_t len, return -EFAULT; } =20 - *ppos +=3D actual; + if (!tmc_etr_update_buf_node_pos(drvdata, actual)) + *ppos +=3D actual; dev_dbg(&drvdata->csdev->dev, "%zu bytes copied\n", actual); =20 return actual; diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtr= acing/coresight/coresight-tmc-etr.c index b0c5f3559085..54ca9616fa66 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1168,6 +1168,8 @@ static int tmc_etr_enable_hw(struct tmc_drvdata *drvd= ata, return rc; } =20 +static const struct tmc_sysfs_ops *byte_cntr_sysfs_ops; + /* * Return the available trace data in the buffer (starts at etr_buf->offse= t, * limited by etr_buf->len) from @pos, with a maximum limit of @len, @@ -1178,23 +1180,39 @@ static int tmc_etr_enable_hw(struct tmc_drvdata *dr= vdata, * We are protected here by drvdata->reading !=3D 0, which ensures the * sysfs_buf stays alive. */ -ssize_t tmc_etr_get_sysfs_trace(struct tmc_drvdata *drvdata, - loff_t pos, size_t len, char **bufpp) +ssize_t tmc_etr_read_sysfs_buf(struct etr_buf *sysfs_buf, loff_t pos, + size_t len, char **bufpp) { s64 offset; ssize_t actual =3D len; - struct etr_buf *etr_buf =3D drvdata->sysfs_buf; =20 - if (pos + actual > etr_buf->len) - actual =3D etr_buf->len - pos; + if (pos + actual > sysfs_buf->len) + actual =3D sysfs_buf->len - pos; if (actual <=3D 0) return actual; =20 /* Compute the offset from which we read the data */ - offset =3D etr_buf->offset + pos; - if (offset >=3D etr_buf->size) - offset -=3D etr_buf->size; - return tmc_etr_buf_get_data(etr_buf, offset, actual, bufpp); + offset =3D sysfs_buf->offset + pos; + if (offset >=3D sysfs_buf->size) + offset -=3D sysfs_buf->size; + return tmc_etr_buf_get_data(sysfs_buf, offset, actual, bufpp); +} +EXPORT_SYMBOL_GPL(tmc_etr_read_sysfs_buf); + +ssize_t tmc_etr_get_sysfs_trace(struct tmc_drvdata *drvdata, + loff_t pos, size_t len, char **bufpp) +{ + ssize_t ret; + const struct tmc_sysfs_ops *byte_cntr_ops =3D READ_ONCE(byte_cntr_sysfs_o= ps); + + if (byte_cntr_ops) { + ret =3D byte_cntr_ops->get_trace_data(drvdata, pos, len, bufpp); + /* Return the filled buffer */ + if (ret > 0 || ret =3D=3D -ENOMEM) + return ret; + } + + return tmc_etr_read_sysfs_buf(drvdata->sysfs_buf, pos, len, bufpp); } =20 static struct etr_buf * @@ -1248,6 +1266,39 @@ static void __tmc_etr_disable_hw(struct tmc_drvdata = *drvdata) =20 } =20 +static void tmc_etr_reset_sysfs_buf(struct tmc_drvdata *drvdata) +{ + u32 sts; + + CS_UNLOCK(drvdata->base); + tmc_write_rrp(drvdata, drvdata->sysfs_buf->hwaddr); + tmc_write_rwp(drvdata, drvdata->sysfs_buf->hwaddr); + sts =3D readl_relaxed(drvdata->base + TMC_STS) & ~TMC_STS_FULL; + writel_relaxed(sts, drvdata->base + TMC_STS); + CS_LOCK(drvdata->base); +} + +/** + * tmc_etr_enable_disable_hw - enable/disable the ETR hw. + * @drvdata: drvdata of the TMC device. + * @enable: indicates enable/disable. + */ +void tmc_etr_enable_disable_hw(struct tmc_drvdata *drvdata, bool enable) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&drvdata->spinlock, flags); + if (enable) { + tmc_etr_reset_sysfs_buf(drvdata); + __tmc_etr_enable_hw(drvdata); + } else { + __tmc_etr_disable_hw(drvdata); + } + + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags); +} +EXPORT_SYMBOL_GPL(tmc_etr_enable_disable_hw); + void tmc_etr_disable_hw(struct tmc_drvdata *drvdata) { __tmc_etr_disable_hw(drvdata); @@ -2047,15 +2098,54 @@ int tmc_create_etr_buf_list(struct tmc_drvdata *drv= data, int num_nodes) } EXPORT_SYMBOL_GPL(tmc_create_etr_buf_list); =20 +void tmc_etr_set_byte_cntr_sysfs_ops(const struct tmc_sysfs_ops *sysfs_ops) +{ + WRITE_ONCE(byte_cntr_sysfs_ops, sysfs_ops); +} +EXPORT_SYMBOL_GPL(tmc_etr_set_byte_cntr_sysfs_ops); + +void tmc_etr_reset_byte_cntr_sysfs_ops(void) +{ + WRITE_ONCE(byte_cntr_sysfs_ops, NULL); +} +EXPORT_SYMBOL_GPL(tmc_etr_reset_byte_cntr_sysfs_ops); + +bool tmc_etr_update_buf_node_pos(struct tmc_drvdata *drvdata, ssize_t size) +{ + struct etr_buf_node *nd, *next; + + if (drvdata->config_type !=3D TMC_CONFIG_TYPE_ETR) + return false; + + list_for_each_entry_safe(nd, next, &drvdata->etr_buf_list, link) { + if (nd && nd->reading) { + nd->pos +=3D size; + return true; + } + } + + return false; +} + int tmc_read_prepare_etr(struct tmc_drvdata *drvdata) { int ret =3D 0; unsigned long flags; + const struct tmc_sysfs_ops *byte_cntr_ops; =20 /* config types are set a boot time and never change */ if (WARN_ON_ONCE(drvdata->config_type !=3D TMC_CONFIG_TYPE_ETR)) return -EINVAL; =20 + byte_cntr_ops =3D READ_ONCE(byte_cntr_sysfs_ops); + if (byte_cntr_ops) { + ret =3D byte_cntr_ops->read_prepare(drvdata); + if (!ret || ret =3D=3D -EBUSY) + return ret; + + ret =3D 0; + } + raw_spin_lock_irqsave(&drvdata->spinlock, flags); if (drvdata->reading) { ret =3D -EBUSY; @@ -2087,11 +2177,17 @@ int tmc_read_unprepare_etr(struct tmc_drvdata *drvd= ata) { unsigned long flags; struct etr_buf *sysfs_buf =3D NULL; + const struct tmc_sysfs_ops *byte_cntr_ops; =20 /* config types are set a boot time and never change */ if (WARN_ON_ONCE(drvdata->config_type !=3D TMC_CONFIG_TYPE_ETR)) return -EINVAL; =20 + byte_cntr_ops =3D READ_ONCE(byte_cntr_sysfs_ops); + if (byte_cntr_ops) + if (!byte_cntr_ops->read_unprepare(drvdata)) + return 0; + raw_spin_lock_irqsave(&drvdata->spinlock, flags); =20 /* RE-enable the TMC if need be */ diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracin= g/coresight/coresight-tmc.h index fbb015079872..a15e2f93f16a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -211,12 +211,15 @@ struct tmc_resrv_buf { /** * @sysfs_buf: Allocated sysfs_buf. * @is_free: Indicates whether the buffer is free to choose. + * @reading: Indicates byte_cntr is reading the buffer attached to + * the node. * @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; + bool reading; loff_t pos; struct list_head link; }; @@ -480,5 +483,11 @@ struct etr_buf *tmc_etr_get_buffer(struct coresight_de= vice *csdev, 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); +void tmc_etr_set_byte_cntr_sysfs_ops(const struct tmc_sysfs_ops *sysfs_ops= ); +void tmc_etr_reset_byte_cntr_sysfs_ops(void); +void tmc_etr_enable_disable_hw(struct tmc_drvdata *drvdata, bool enable); +bool tmc_etr_update_buf_node_pos(struct tmc_drvdata *drvdata, ssize_t size= ); +ssize_t tmc_etr_read_sysfs_buf(struct etr_buf *sysfs_buf, loff_t pos, + size_t len, char **bufpp); =20 #endif --=20 2.34.1 From nobody Wed Jun 10 14:02:44 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 8E5383FD12B for ; Thu, 7 May 2026 14:13:10 +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=1778163191; cv=none; b=JxVWTTWgXB+QXbK9avuEC58PDDFxbPfgucyYwmDkRBUSU+Ev8Y41/qTvW0wTmYKrGR8+6Hha38+fjmjWLZd0rQjBK8SKvLMkrNAhZMYndVH4pDmnn0k4LziYWWT/XJrCpFXu48NmT8Fxm8Y5tIyuuUUtidQiGKUkizYn7AfVZPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778163191; c=relaxed/simple; bh=T3K0UqY6Cu5YfSXiRIl7BiaaPevFsxba0x8aWptwzq8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g0XNtSx4cc6haRp/nqpYOR0OxMBZKbdarQMIuwiQU1JRVrskNlNfOPlr55XdMY4UVD6XU/TFdDFWm3IFZEOTCIcIKNeRGvZX8ugwtueH4QaNi7cePSFD9kCWEEjH4rSfAKk3c0RtiboIlKBbkOnLAUXQ4euCYhBAu0RquTEXhxk= 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=obji58Nu; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=L/+Ktn1x; 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="obji58Nu"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="L/+Ktn1x" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 647C5dM41971858 for ; Thu, 7 May 2026 14:13:10 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= oT9Ij5h4fUVAikSz23Cjq4bChK5oWSJ3cw6Um53IjgQ=; b=obji58Nu5Gqj7unu WszKTUNm+LSt7bdUl9WT176axS+Cx/oD0+1xmjSpd4pwd3Pn9PZhtjhGOFrV+zvj SwaCSHKGJD7NifcMNmOirpG6zovXl5econsK0Sj6aiJJybAp4QN49G7FtSR6tAKk M/1nsn9SGrGNSHQfKfr8H5psRxu9SZtTbBVHd1p9MZdqHmHmmSx1MQ2YRDa05Dsg /0MliZllnnoW1OMiTz7DD9AKFFf1zU06+iOs6R63eA8dT9goccItGRtxoPTIATeT O6DwrBuBSoshspgE/nYtH2R31ypBf6QSpEDWWCEYJ7pgxZcZnJUvFPNMf+naxmKR S1uLqw== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e0tej8fq9-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 07 May 2026 14:13:09 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-bce224720d8so503723a12.1 for ; Thu, 07 May 2026 07:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778163189; x=1778767989; 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=oT9Ij5h4fUVAikSz23Cjq4bChK5oWSJ3cw6Um53IjgQ=; b=L/+Ktn1xKN2DBlzrq9XHS/H0+FJDLnerp16WzJuBhKeLgSh37zDN8QsaTbA5pbvZIm GSuhNeaIi/bvIKxTZ/BqJl8YVOLAw1eVc2aB3S2ASPM8xBV20TfE/TD4MnJ1WXkXs4E8 uXwPhYcgmYiWStfaKk1GoP3pMyO88Rps+wRsvTltppojvakB6q8kuFW9H6H0OyhnTFkt +pkuBcHPZVl7PE4O5N0vowJgvEKHOLTBjama+93WScYNlS0SwJKYd6iaxbKtbWizh+rw cLidj/jN+2y94I3S6NQDzlQRT4n+WvtDoPklVly4B3K1N23caJWOFV3WzIeVqZcALK0P NKDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778163189; x=1778767989; 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=oT9Ij5h4fUVAikSz23Cjq4bChK5oWSJ3cw6Um53IjgQ=; b=fKvXUkE8ZqiA51b/VNAp5KuwioCKqloNke9SMKmtiar/stZ3SFI1GjG3NTgAXqdojc B8vYXDaL+uz5a1GA6mOmYRO8iGe4PW7jSuXLCinkWc3APyWBE5VyteoXFnyqT6QWz9it GE/M0XDfYtRxSOU0uoX6DpdUOmUf122M5jn8St6QTXP1YStSuEaOL2DzoeuSO9sCWXYI FC1tW9YTJBbwRVDCMH9Dl1IYbb/JQJvDq+Ml26Um706WAdZHKzrE/T94xfoPBiH02802 dhQuK5Hc/+53Uc40xEgZn5bGdvvpd95a/DLPOlp7BQ2Kg3qwurkXYi6C7qw7NubF7q8M pJPA== X-Forwarded-Encrypted: i=1; AFNElJ9CZG3FPbSya9AGsvrVqXAeZwKWtIjwbplW8rsusI685XIJNXSviN7zNYQPSR5Y9CQuDHXwLmP1FGVjBto=@vger.kernel.org X-Gm-Message-State: AOJu0YyrD1iu71yRiwghNvtw5xfpcsOZlU/GB862p2GEMdLDIVAgl7Zs J1vF8Y7KLuxmVHsgWqHjabYwnIJJ8iLvePv64Aqvj8w8W3Uqubhk0RzfWCX/LDArKS3fbQqvYJx 5wviue2tcmoakTKEu47scZ1JhKspWpgpT4ooChBDW/F9IoQJ8y/WOFMUzH5s0MalW7WQ= X-Gm-Gg: AeBDietcQLkfxFe4Wt9Dso4QJRO4cweyZt9wy7TEF6xJXwdPxrqcSNnklHdexAC45jH hNzJHMXNGJg8qISeaM0RtKJLCYyGuuti5duHw1nomGxEiP8ZhbJALoD2sS1Y9BvL0bTJYqvlpCt 9a7o2K0CFDbqK+yYAc6HUfblxo5ZbZ9aBIHfLEYAH5UTBvmNxF79ZxzE/2YOlJI7JC4SLpU/IbL +9ZJ22F/IrXlzg9AquCntizgjGtS2LV0c9iGGlzRaPOWeCwp7I3i+h9uojZbmSh/i2diFcu2otL PMgraNmKqwYKIepD3eTyV1Qln47i0dwmJAaZ2cCkmGJMbCplYxYQhYvvVzbHFIZ9MIrWz/3IUMJ q8g4NP5NF0Q7Xwh/ArwB/D/5o3Ys/cyi7jQVG2ZeXGHWPVRbnlJ2YCG+RhmAF2pM3D4FplVxNcX RN4TLC9o1LTO79Ws7a7uc= X-Received: by 2002:a05:6a20:1591:b0:34f:14d6:15f5 with SMTP id adf61e73a8af0-3aa5a934e9cmr9687590637.29.1778163188785; Thu, 07 May 2026 07:13:08 -0700 (PDT) X-Received: by 2002:a05:6a20:1591:b0:34f:14d6:15f5 with SMTP id adf61e73a8af0-3aa5a934e9cmr9687531637.29.1778163188196; Thu, 07 May 2026 07:13:08 -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-c8253b493c5sm2343072a12.28.2026.05.07.07.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 07:13:07 -0700 (PDT) From: Jie Gan Date: Thu, 07 May 2026 22:12:03 +0800 Subject: [PATCH v18 7/7] arm64: dts: qcom: lemans: add interrupts to CTCU device 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: <20260507-enable-byte-cntr-for-ctcu-v18-7-2b2d590463a3@oss.qualcomm.com> References: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@oss.qualcomm.com> In-Reply-To: <20260507-enable-byte-cntr-for-ctcu-v18-0-2b2d590463a3@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 , Konrad Dybcio X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778163147; l=769; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=T3K0UqY6Cu5YfSXiRIl7BiaaPevFsxba0x8aWptwzq8=; b=sdUjel/sDCFE86TLQatL135VVmhF1NPENX06ZBgfvs2tIhWEvaoHw5CuGwyXPqG1yiqTdbiLh /Flw6geY9VtD44J9V2RyI33NtrFE1YU/yPggQvfsQsNwzrZmJDejfn/ X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA3MDE0MiBTYWx0ZWRfX1wFrxIF/H8QC 7VSk3spherIIBLswIHB9AXSST2WBTCW9NmdYfZPWBufyZbgyhlPNHKcvy2HIbHau7eCzxOtjuIY Y1bOZwpalvgK5LAx8obXrNJl/7k5nBPJJBuzsAFNy7GAAaggTqQ26Hw9vKrPtrolNutIdohrboY z7+2P4GK8plkhITGqUi6ls/4tG5blPvcQGp6Ti+XdSyox77figip9odkO2aAMx5h0vszcDscMyY p5Ch5yRZHwIWIFTsbgc2AHW+oGmdM0rQH/qf3SFyfc6BONCqzwi+P91EISlnrD4YmhcqPjD1RP6 Wci25CrNxtA9LCUl3eB1NJ70WL1CogrFMYzHGWwhwUX7GP38b4GrPIxA4v9Yd6Ug9M62/nIVlbA MMCZ5+AfKyeP5xBIWn357yy33zeBS0HQNUJhKk4eXuEO7LV4Oxk3tgKzeifRP6vb5vV8jTlUCZt 9lI6gaWWudi+BeueLgQ== X-Proofpoint-GUID: qDmyQwZojt--e26TQEeKWteCqyTdWU2g X-Authority-Analysis: v=2.4 cv=VNbtWdPX c=1 sm=1 tr=0 ts=69fc9df5 cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=gBkj9RZkAcI1HbXH1KoA:9 a=QEXdDO2ut3YA:10 a=x9snwWr2DeNwDh03kgHS:22 X-Proofpoint-ORIG-GUID: qDmyQwZojt--e26TQEeKWteCqyTdWU2g 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-05-07_01,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605070142 Add interrupts to enable byte-cntr function for TMC ETR devices. Reviewed-by: Konrad Dybcio Signed-off-by: Jie Gan --- arch/arm64/boot/dts/qcom/lemans.dtsi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/lemans.dtsi b/arch/arm64/boot/dts/qco= m/lemans.dtsi index fe6e76351823..2cc855ec9759 100644 --- a/arch/arm64/boot/dts/qcom/lemans.dtsi +++ b/arch/arm64/boot/dts/qcom/lemans.dtsi @@ -2800,6 +2800,9 @@ ctcu@4001000 { clocks =3D <&aoss_qmp>; clock-names =3D "apb"; =20 + interrupts =3D , + ; + in-ports { #address-cells =3D <1>; #size-cells =3D <0>; --=20 2.34.1