From patchwork Mon Mar 10 09:04:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Gan X-Patchwork-Id: 14009426 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F806C28B2E for ; Mon, 10 Mar 2025 09:06:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/y3ccLGRS28rbxxS8x8ptTcuQEA4QZ6Z9IHOOS7Jtj0=; b=a/QQG+Jg4ue2ksoy2fTjHE60ag mQW5GSL2nxEMFqUjU0CNgMh5lZMuyDB6nqhGWSBVOvglgMY5Dw6wG3L/T5Jt05XZu8CgrazH0s2v9 FLslgah9o4Qhn59b+5+YUHWDhj18ZfxQDNl7oqHSr62q9JrRO6O1sTH8u0h/LinU2HvcvDSjI2Rml lJlEqxd6cyAbbpDbDpz9B9PSLYm4VfUYT2BbPIAoYxK+s9cbMFQaaKBxpkSZ6GAI8eeGD6BwvErDv afNVrSWLeC2yrmeThKFiz9n14H3QtP7pKaYOnGyBNARoyxFiFPRZmJCRwI1RbNwH4M5XU2C04Iv/y TbkRXZyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1trZ5s-000000021Ks-3BLb; Mon, 10 Mar 2025 09:06:40 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1trZ4E-000000020gu-02Yj for linux-arm-kernel@lists.infradead.org; Mon, 10 Mar 2025 09:04:59 +0000 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 529LDiLj013127; Mon, 10 Mar 2025 09:04:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /y3ccLGRS28rbxxS8x8ptTcuQEA4QZ6Z9IHOOS7Jtj0=; b=dBU5GcSkVasDyJxG iIXVFoftvoQLIGg0srMZe1xG+kTM5vbY3UXB2Wxl2mVfe+TTFgRc14zO9yveey9k AKnnD+xXcxZaz5mfPh8N57mlyqOf/Hg1Yy6TDtPht36kfhyGMlG2yoiGmFiygCq+ 4uRsRb37m/NBw5ths8blzuLpjXgLGVgFirFXJ1T3l4gryx4r7xwfIk0qvzRCdQbR 2aqduWT90FHfccVxKulXym0pEO6YIpCLtRNXzmjW7LyhUm2oK3N6x+6ZmxCgPSp8 LhQsr5NHdb2PwcWQWCJmuxegzunvOeJ5Oc7zWQo2bzJOkAQ+bQWvc6ACb2Kc10g8 gLCtZQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 458f0w4869-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:39 +0000 (GMT) Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 52A94ccn024865 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:38 GMT Received: from jiegan-gv.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 10 Mar 2025 02:04:33 -0700 From: Jie Gan To: Suzuki K Poulose , Mike Leach , James Clark , "Alexander Shishkin" , Maxime Coquelin , Alexandre Torgue , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio CC: Tingwei Zhang , Jinlong Mao , , , , , , Subject: [PATCH v1 1/4] coresight: tmc: Introduce new APIs to get the RWP offset of ETR buffer Date: Mon, 10 Mar 2025 17:04:04 +0800 Message-ID: <20250310090407.2069489-2-quic_jiegan@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310090407.2069489-1-quic_jiegan@quicinc.com> References: <20250310090407.2069489-1-quic_jiegan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: wFn8xYvhJG6QyQN_corUmwD4YwxRiQIf X-Proofpoint-GUID: wFn8xYvhJG6QyQN_corUmwD4YwxRiQIf X-Authority-Analysis: v=2.4 cv=MICamNZl c=1 sm=1 tr=0 ts=67ceab27 cx=c_pps a=ouPCqIW2jiPt+lZRy3xVPw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=GEpy-HfZoHoA:10 a=Vs1iUdzkB0EA:10 a=COk6AnOGAAAA:8 a=NC6d20HEQiqhJ-MTNCwA:9 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-10_03,2025-03-07_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=576 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2503100071 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250310_020458_057269_07B59494 X-CRM114-Status: GOOD ( 14.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The new functions calculate and return the offset to the write pointer of the ETR buffer based on whether the memory mode is SG, flat or reserved. The functions have the RWP offset can directly read data from ETR buffer, enabling the transfer of data to any required location. Signed-off-by: Jie Gan --- .../hwtracing/coresight/coresight-tmc-etr.c | 40 +++++++++++++++++++ drivers/hwtracing/coresight/coresight-tmc.h | 1 + 2 files changed, 41 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index eda7cdad0e2b..ec636ab1fd75 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -267,6 +267,46 @@ void tmc_free_sg_table(struct tmc_sg_table *sg_table) } EXPORT_SYMBOL_GPL(tmc_free_sg_table); +static long tmc_flat_resrv_get_rwp_offset(struct tmc_drvdata *drvdata) +{ + dma_addr_t paddr = drvdata->sysfs_buf->hwaddr; + u64 rwp; + + rwp = tmc_read_rwp(drvdata); + return rwp - paddr; +} + +static long tmc_sg_get_rwp_offset(struct tmc_drvdata *drvdata) +{ + struct etr_buf *etr_buf = drvdata->sysfs_buf; + struct etr_sg_table *etr_table = etr_buf->private; + struct tmc_sg_table *table = etr_table->sg_table; + long w_offset; + u64 rwp; + + rwp = tmc_read_rwp(drvdata); + w_offset = tmc_sg_get_data_page_offset(table, rwp); + + return w_offset; +} + +/* + * Retrieve the offset to the write pointer of the ETR buffer based on whether + * the memory mode is SG, flat or reserved. + */ +long tmc_get_rwp_offset(struct tmc_drvdata *drvdata) +{ + struct etr_buf *etr_buf = drvdata->sysfs_buf; + + if (etr_buf->mode == ETR_MODE_ETR_SG) + return tmc_sg_get_rwp_offset(drvdata); + else if (etr_buf->mode == ETR_MODE_FLAT || etr_buf->mode == ETR_MODE_RESRV) + return tmc_flat_resrv_get_rwp_offset(drvdata); + else + return -EINVAL; +} +EXPORT_SYMBOL_GPL(tmc_get_rwp_offset); + /* * Alloc pages for the table. Since this will be used by the device, * allocate the pages closer to the device (i.e, dev_to_node(dev) diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index b48bc9a01cc0..baedb4dcfc3f 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -442,5 +442,6 @@ void tmc_etr_remove_catu_ops(void); struct etr_buf *tmc_etr_get_buffer(struct coresight_device *csdev, enum cs_mode mode, void *data); extern const struct attribute_group coresight_etr_group; +long tmc_get_rwp_offset(struct tmc_drvdata *drvdata); #endif From patchwork Mon Mar 10 09:04:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Gan X-Patchwork-Id: 14009428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD175C282DE for ; Mon, 10 Mar 2025 09:10:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=epICJwpsniGzAa+mydO1lj6USFz6nDK8cnXneWo8u4Q=; b=b7FYnbb47UgYJ8JAwE3IAmcMPG 9YEXaAXVOAR02XtGWrp0QgyMGSpAjK4m3a7aH2+Mj9isCsJCGjmkOLHHp/wch+4DQVGZ0CQEKCaRh lwpYSPGA7HOxXqkAtGqjt1EQNaSq/r3iGKJPAjjv9RqKnBS/1N0qURsno4Dsqoi7xAm6LPFkjgLBS cGRn5C4J46YYJ0JvAR3Eey1+VCni57TG80757Ulf3IUxLfSyZIa7JivsojkJyDyF81fSG7MQpE1Wp Yc32Ebrv199jVqAA253/p7sgUk+weZ6WNnudixqf9ilYRr9eF1T+eLu8QrRByvnny017pPIdRk6nI 8gY47GZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1trZ95-000000021nk-0Pbi; Mon, 10 Mar 2025 09:09:59 +0000 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1trZ4V-000000020r4-0XjN for linux-arm-kernel@lists.infradead.org; Mon, 10 Mar 2025 09:05:16 +0000 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 529NEB54018337; Mon, 10 Mar 2025 09:04:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= epICJwpsniGzAa+mydO1lj6USFz6nDK8cnXneWo8u4Q=; b=n0w1D13DPxLLZn+h AMfkhUwRqqUMw5FnMKKAP6YuKLSGzWsHBW9ZgZL5iuEDhVjPejDpHQf3C88L5Fy8 L+/oiofwMXLrem0vfuQ9ltbkvi5sXr66u55zf53w0aiHXoVvSWXCYA7fD3ARifci iG2wkWey9C89jznxx0GTS87zgy7bfxzkRTGphePoueRdagxbnshjmEcNxBQMosaK f7UxM9gQ2jBE/pD3MAlRiZYQuPNCjH5by7rZ54ChuKk26lDWGhUu/W1rfwIUoaZ3 o017kJPSX/Fhs6PXLhFeucoKI55FekqEQoXa7IKOohlCOrqj8ngw5MWiHbXJJ3mA TPOFrA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 458f0pv6pp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:45 +0000 (GMT) Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 52A94isY005832 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:44 GMT Received: from jiegan-gv.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 10 Mar 2025 02:04:38 -0700 From: Jie Gan To: Suzuki K Poulose , Mike Leach , James Clark , "Alexander Shishkin" , Maxime Coquelin , Alexandre Torgue , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio CC: Tingwei Zhang , Jinlong Mao , , , , , , Subject: [PATCH v1 2/4] dt-bindings: arm: Add an interrupt property for Coresight CTCU Date: Mon, 10 Mar 2025 17:04:05 +0800 Message-ID: <20250310090407.2069489-3-quic_jiegan@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310090407.2069489-1-quic_jiegan@quicinc.com> References: <20250310090407.2069489-1-quic_jiegan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: n_-0Z9s_sPyBZv-i7ad1wHCUdDU-nw3r X-Authority-Analysis: v=2.4 cv=KK2gDEFo c=1 sm=1 tr=0 ts=67ceab2d cx=c_pps a=ouPCqIW2jiPt+lZRy3xVPw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=GEpy-HfZoHoA:10 a=Vs1iUdzkB0EA:10 a=COk6AnOGAAAA:8 a=gSyxy6DGYGa4b6s9XCEA:9 a=adZxlrsHB6HFTpVwR5mc:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-ORIG-GUID: n_-0Z9s_sPyBZv-i7ad1wHCUdDU-nw3r X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-10_03,2025-03-07_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 clxscore=1015 malwarescore=0 adultscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2503100070 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250310_020515_289468_97A323EB X-CRM114-Status: GOOD ( 12.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add an interrupt property to CTCU device. The interrupt will be triggered when the data size in the ETR buffer exceeds the threshlod of the BYTECNTRVAL register. Programming a threshold in the BYTECNTRVAL register of CTCU device will enable the interrupt. Signed-off-by: Jie Gan --- .../bindings/arm/qcom,coresight-ctcu.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml b/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml index 843b52eaf872..ea05ad8f3dd3 100644 --- a/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml +++ b/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml @@ -39,6 +39,16 @@ properties: items: - const: apb + interrupts: + items: + - description: Byte cntr interrupt for etr0 + - description: Byte cntr interrupt for etr1 + + interrupt-names: + items: + - const: etr0 + - const: etr1 + in-ports: $ref: /schemas/graph.yaml#/properties/ports @@ -56,6 +66,8 @@ additionalProperties: false examples: - | + #include + ctcu@1001000 { compatible = "qcom,sa8775p-ctcu"; reg = <0x1001000 0x1000>; @@ -63,6 +75,11 @@ examples: clocks = <&aoss_qmp>; clock-names = "apb"; + interrupts = , + ; + interrupt-names = "etr0", + "etr1"; + in-ports { #address-cells = <1>; #size-cells = <0>; From patchwork Mon Mar 10 09:04:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Gan X-Patchwork-Id: 14009427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC561C282DE for ; Mon, 10 Mar 2025 09:08:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/aO5YbNlXTtwvmMBaXLCtlM0PhxiyAhiBZ9cxleLVVU=; b=a9jW8Uxe0UZ2pDdXQcf6QMav23 Qg30x3kxnuDxOISIHsUCHB981KTEFjTN59kHx/xPZszB+Yw3BtMYTZ6BWUfhWH/19YoYC13kBsFPu ljdxPtmMSc03ITK6BYQwXIFZBVhXkFQef8daT7qelQKd7eMaSh41pV2r+qsS2FrIJRtxfo/asYTOU dXXNfDJs2otscWkKJLK22Q5coLRTT3uG8sUQ6UYmyxLN11eNMlMHGZcgNZVCVBb3X1BOMikfxLpsS Gq3KIylEJNZjkDNq/aBMpY0JKDBjr17+/8pP3J8OFlUf1J9V7ST6eY9i/v1t4yZqY7zSYyQCdLFJ9 sCrr86wA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1trZ7U-000000021a5-1kuN; Mon, 10 Mar 2025 09:08:20 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1trZ4Q-000000020o2-1Ivj for linux-arm-kernel@lists.infradead.org; Mon, 10 Mar 2025 09:05:11 +0000 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 529LXgmM009677; Mon, 10 Mar 2025 09:04:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /aO5YbNlXTtwvmMBaXLCtlM0PhxiyAhiBZ9cxleLVVU=; b=VciTcfQq/5nJrX6N u/zYeEyfvvFKJZ6WB0k9LFEfSyi1Xc1LAhS5sfF9Dq9pOsJp0II5eDa7dY8i4SHY dq5V+tZ6ON4x0uDP/hUebjdaeMHgFPPr0F6qPyqAz3fVhFnl6qxruWbth6lMjtw0 WgrTMqpK86Zm8yNM2o9jrMblv1REsQtyl7LBUbU6dVZUWS5GYWiIhLKLdPORGPqH DtJS9/PY0Xm8oDdvyHfO72iqZ7FpFDEBH7UAgZeoXwKPUzNITeUSXAqSdx6T1Z0T prLRsMqWt19ZfMKQWGLOgmT3DdZzLpvTQ61diUEbsKVmDPAMWMCU8oJ3MDDJP1bb omo6kA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 458eypc744-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:51 +0000 (GMT) Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 52A94oIB005905 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:50 GMT Received: from jiegan-gv.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 10 Mar 2025 02:04:44 -0700 From: Jie Gan To: Suzuki K Poulose , Mike Leach , James Clark , "Alexander Shishkin" , Maxime Coquelin , Alexandre Torgue , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio CC: Tingwei Zhang , Jinlong Mao , , , , , , Subject: [PATCH v1 3/4] coresight: ctcu: Enable byte-cntr for TMC ETR devices Date: Mon, 10 Mar 2025 17:04:06 +0800 Message-ID: <20250310090407.2069489-4-quic_jiegan@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310090407.2069489-1-quic_jiegan@quicinc.com> References: <20250310090407.2069489-1-quic_jiegan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Authority-Analysis: v=2.4 cv=A9yWP7WG c=1 sm=1 tr=0 ts=67ceab33 cx=c_pps a=ouPCqIW2jiPt+lZRy3xVPw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=GEpy-HfZoHoA:10 a=Vs1iUdzkB0EA:10 a=COk6AnOGAAAA:8 a=qkhKFYCmI9jF0lKWm-MA:9 a=RVmHIydaz68A:10 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-ORIG-GUID: N1rXsQ1rDv0s7hLPhZCGklsCZJaP2Eft X-Proofpoint-GUID: N1rXsQ1rDv0s7hLPhZCGklsCZJaP2Eft X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-10_03,2025-03-07_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 impostorscore=0 spamscore=0 suspectscore=0 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2503100071 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250310_020510_372408_DD3D24EC X-CRM114-Status: GOOD ( 32.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 ETR buffer if the IRQ count is greater than 0. Each successful read process will decrement the IRQ count by 1. Signed-off-by: Jie Gan --- drivers/hwtracing/coresight/Makefile | 2 +- .../coresight/coresight-ctcu-byte-cntr.c | 339 ++++++++++++++++++ .../hwtracing/coresight/coresight-ctcu-core.c | 96 ++++- drivers/hwtracing/coresight/coresight-ctcu.h | 59 ++- .../hwtracing/coresight/coresight-tmc-etr.c | 5 +- drivers/hwtracing/coresight/coresight-tmc.h | 2 + 6 files changed, 493 insertions(+), 10 deletions(-) create mode 100644 drivers/hwtracing/coresight/coresight-ctcu-byte-cntr.c diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index 8e62c3150aeb..c90a06768a18 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -52,4 +52,4 @@ coresight-cti-y := coresight-cti-core.o coresight-cti-platform.o \ obj-$(CONFIG_ULTRASOC_SMB) += ultrasoc-smb.o obj-$(CONFIG_CORESIGHT_DUMMY) += coresight-dummy.o obj-$(CONFIG_CORESIGHT_CTCU) += coresight-ctcu.o -coresight-ctcu-y := coresight-ctcu-core.o +coresight-ctcu-y := coresight-ctcu-core.o coresight-ctcu-byte-cntr.o diff --git a/drivers/hwtracing/coresight/coresight-ctcu-byte-cntr.c b/drivers/hwtracing/coresight/coresight-ctcu-byte-cntr.c new file mode 100644 index 000000000000..0d16385663f5 --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-ctcu-byte-cntr.c @@ -0,0 +1,339 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "coresight-ctcu.h" +#include "coresight-priv.h" +#include "coresight-tmc.h" + +#define BYTE_CNTR_CLASS_STR "byte-cntr-class" + +static struct class *byte_cntr_class; +static dev_t byte_cntr_base; + +static irqreturn_t byte_cntr_handler(int irq, void *data) +{ + struct ctcu_byte_cntr *byte_cntr_data = (struct ctcu_byte_cntr *)data; + + atomic_inc(&byte_cntr_data->irq_cnt); + wake_up(&byte_cntr_data->wq); + + return IRQ_HANDLED; +} + +/* Read the data from ETR's DDR buffer. */ +static void __ctcu_byte_cntr_read_etr_bytes(struct ctcu_byte_cntr *byte_cntr_data, + size_t *len, char **bufp) +{ + struct tmc_drvdata *tmcdrvdata = dev_get_drvdata(byte_cntr_data->sink->dev.parent); + size_t actual, bytes = byte_cntr_data->thresh_val; + struct etr_buf *etr_buf = tmcdrvdata->sysfs_buf; + long r_offset; + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + r_offset = byte_cntr_data->r_offset; + if (*len >= bytes) + *len = bytes; + else if ((r_offset % bytes) + *len > bytes) + *len = bytes - (r_offset % bytes); + + actual = tmc_etr_buf_get_data(etr_buf, r_offset, *len, bufp); + *len = actual; + if (actual == bytes || (actual + r_offset) % bytes == 0) + atomic_dec(&byte_cntr_data->irq_cnt); +} + +/* Flush the remaining data in the ETR buffer after the byte cntr has stopped. */ +static ssize_t ctcu_flush_etr_buffer(struct ctcu_byte_cntr *byte_cntr_data, size_t len, + char **bufpp) +{ + struct tmc_drvdata *tmcdrvdata = dev_get_drvdata(byte_cntr_data->sink->dev.parent); + struct etr_buf *etr_buf = tmcdrvdata->sysfs_buf; + ssize_t read_len = 0, remaining_len; + long r_offset, w_offset; + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + r_offset = byte_cntr_data->r_offset; + w_offset = byte_cntr_data->w_offset; + if (w_offset < r_offset) + remaining_len = tmcdrvdata->size + w_offset - r_offset; + else + remaining_len = w_offset - r_offset; + + if (remaining_len > len) + remaining_len = len; + + if (remaining_len > 0) + read_len = tmc_etr_buf_get_data(etr_buf, r_offset, remaining_len, bufpp); + + return read_len; +} + +static ssize_t ctcu_byte_cntr_copy_data(char __user *data, size_t len, char *bufp, + struct ctcu_byte_cntr *byte_cntr_data, + struct tmc_drvdata *tmcdrvdata) +{ + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + if (copy_to_user(data, bufp, len)) + return -EFAULT; + + byte_cntr_data->total_size += len; + if (byte_cntr_data->r_offset + len >= tmcdrvdata->size) + byte_cntr_data->r_offset = 0; + else + byte_cntr_data->r_offset += len; + + return len; +} + +/* The read function for /dev/byte-cntr%d */ +static ssize_t ctcu_byte_cntr_read_etr_bytes(struct file *fp, char __user *data, + size_t len, loff_t *ppos) +{ + struct ctcu_byte_cntr *byte_cntr_data = fp->private_data; + struct tmc_drvdata *tmcdrvdata = dev_get_drvdata(byte_cntr_data->sink->dev.parent); + char *bufp = NULL; + ssize_t read_len; + + if (!data) + return -EINVAL; + + /* + * Flush the remaining data in the ETR buffer based on the write + * offset of the ETR buffer when the byte cntr function has stopped. + */ + if (!byte_cntr_data->read_active || !byte_cntr_data->enable) { + read_len = ctcu_flush_etr_buffer(byte_cntr_data, len, &bufp); + if (read_len > 0) + return ctcu_byte_cntr_copy_data(data, read_len, bufp, + byte_cntr_data, tmcdrvdata); + + return -EINVAL; + } + + if (!atomic_read(&byte_cntr_data->irq_cnt)) { + if (wait_event_interruptible(byte_cntr_data->wq, + atomic_read(&byte_cntr_data->irq_cnt) > 0 || + !byte_cntr_data->enable)) + return -ERESTARTSYS; + } + + __ctcu_byte_cntr_read_etr_bytes(byte_cntr_data, &len, &bufp); + + return ctcu_byte_cntr_copy_data(data, len, bufp, byte_cntr_data, tmcdrvdata); +} + +/* Start the byte-cntr function when the path is enabled. */ +void ctcu_byte_cntr_start(struct coresight_device *csdev, struct coresight_path *path) +{ + struct ctcu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + struct coresight_device *sink = coresight_get_sink(path); + struct ctcu_byte_cntr *byte_cntr_data; + int port_num; + + if (!sink) + return; + + port_num = ctcu_get_active_port(sink, csdev); + if (port_num < 0) + return; + + byte_cntr_data = &drvdata->byte_cntr_data[port_num]; + /* Don't start byte-cntr function when threshold is not set. */ + if (!byte_cntr_data->thresh_val) + return; + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + atomic_set(&byte_cntr_data->irq_cnt, 0); + byte_cntr_data->sink = sink; + byte_cntr_data->enable = 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 ctcu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + struct coresight_device *sink = coresight_get_sink(path); + struct ctcu_byte_cntr *byte_cntr_data; + struct tmc_drvdata *tmcdrvdata; + int port_num; + + if (!sink) + return; + + port_num = ctcu_get_active_port(sink, csdev); + if (port_num < 0) + return; + + byte_cntr_data = &drvdata->byte_cntr_data[port_num]; + tmcdrvdata = dev_get_drvdata(byte_cntr_data->sink->dev.parent); + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + /* Store the w_offset of the ETR buffer when stopping. */ + byte_cntr_data->w_offset = tmc_get_rwp_offset(tmcdrvdata); + atomic_set(&byte_cntr_data->irq_cnt, 0); + byte_cntr_data->read_active = false; + byte_cntr_data->enable = false; + /* + * Wakeup once to force the read function to read the remaining + * data of the ETR buffer. + */ + wake_up(&byte_cntr_data->wq); +} + +static int ctcu_byte_cntr_release(struct inode *in, struct file *fp) +{ + struct ctcu_byte_cntr *byte_cntr_data = fp->private_data; + struct device *dev = &byte_cntr_data->sink->dev; + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + atomic_set(&byte_cntr_data->irq_cnt, 0); + byte_cntr_data->read_active = false; + disable_irq_wake(byte_cntr_data->byte_cntr_irq); + dev_dbg(dev, "send data total size: %llu bytes, r_offset: %ld w_offset: %ld\n", + byte_cntr_data->total_size, byte_cntr_data->r_offset, + byte_cntr_data->w_offset); + + return 0; +} + +static int ctcu_byte_cntr_open(struct inode *in, struct file *fp) +{ + struct ctcu_byte_cntr *byte_cntr_data = container_of(in->i_cdev, + struct ctcu_byte_cntr, c_dev); + struct tmc_drvdata *tmcdrvdata; + + if (byte_cntr_data->read_active) + return -EBUSY; + + if (!byte_cntr_data->thresh_val || !byte_cntr_data->sink || + (coresight_get_mode(byte_cntr_data->sink) != CS_MODE_SYSFS)) + return -EINVAL; + + guard(raw_spinlock_irqsave)(&byte_cntr_data->spin_lock); + enable_irq_wake(byte_cntr_data->byte_cntr_irq); + fp->private_data = byte_cntr_data; + nonseekable_open(in, fp); + tmcdrvdata = dev_get_drvdata(byte_cntr_data->sink->dev.parent); + /* + * The original r_offset is the w_offset of the ETR buffer at the + * start of the byte-cntr. + */ + byte_cntr_data->r_offset = tmc_get_rwp_offset(tmcdrvdata); + byte_cntr_data->total_size = 0; + byte_cntr_data->read_active = true; + byte_cntr_data->enable = true; + + return 0; +} + +static const struct file_operations byte_cntr_fops = { + .owner = THIS_MODULE, + .open = ctcu_byte_cntr_open, + .read = ctcu_byte_cntr_read_etr_bytes, + .release = ctcu_byte_cntr_release, +}; + +static int ctcu_byte_cntr_register_chardev(struct ctcu_byte_cntr *byte_cntr_data, + int port_num) +{ + struct device *device; + dev_t devt; + int ret; + + cdev_init(&byte_cntr_data->c_dev, &byte_cntr_fops); + devt = MKDEV(MAJOR(byte_cntr_base), MINOR(byte_cntr_base) + port_num); + ret = cdev_add(&byte_cntr_data->c_dev, devt, 1); + if (ret < 0) + return -ENOMEM; + + device = device_create(byte_cntr_class, NULL, devt, byte_cntr_data, + byte_cntr_data->name); + + if (IS_ERR(device)) + return -ENOMEM; + + return 0; +} + +static void ctcu_byte_cntr_unregister_chardev(struct ctcu_drvdata *drvdata) +{ + struct ctcu_byte_cntr *byte_cntr_data; + int i; + + for (i = 0; i < ETR_MAX_NUM; i++) { + byte_cntr_data = &drvdata->byte_cntr_data[i]; + device_destroy(byte_cntr_class, byte_cntr_data->c_dev.dev); + } +} + +int 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 = dev->of_node; + int byte_cntr_irq, ret, i; + + ret = alloc_chrdev_region(&byte_cntr_base, 0, ETR_MAX_NUM, BYTE_CNTR_CLASS_STR); + if (ret < 0) + return -ENOMEM; + + byte_cntr_class = class_create(BYTE_CNTR_CLASS_STR); + if (IS_ERR(byte_cntr_class)) { + unregister_chrdev_region(byte_cntr_base, ETR_MAX_NUM); + return -ENOMEM; + } + + for (i = 0; i < etr_num; i++) { + byte_cntr_data = &drvdata->byte_cntr_data[i]; + byte_cntr_irq = of_irq_get_byname(nd, byte_cntr_data->irq_name); + if (byte_cntr_irq < 0) { + ret = byte_cntr_irq; + goto err_exit; + } + + ret = devm_request_irq(dev, byte_cntr_irq, byte_cntr_handler, + IRQF_TRIGGER_RISING | IRQF_SHARED, + dev_name(dev), byte_cntr_data); + if (ret) { + dev_err(dev, "Failed to register IRQ for %s\n", + byte_cntr_data->name); + goto err_exit; + } + + ret = ctcu_byte_cntr_register_chardev(byte_cntr_data, i); + if (ret) { + dev_err(dev, "Failed to register chardev for %s\n", + byte_cntr_data->name); + goto err_exit; + } + + byte_cntr_data->byte_cntr_irq = byte_cntr_irq; + atomic_set(&byte_cntr_data->irq_cnt, 0); + init_waitqueue_head(&byte_cntr_data->wq); + } + + return 0; + +err_exit: + ctcu_byte_cntr_unregister_chardev(drvdata); + class_destroy(byte_cntr_class); + unregister_chrdev_region(byte_cntr_base, ETR_MAX_NUM); + return ret; +} + +void ctcu_byte_cntr_remove(struct ctcu_drvdata *drvdata) +{ + ctcu_byte_cntr_unregister_chardev(drvdata); + class_destroy(byte_cntr_class); + unregister_chrdev_region(byte_cntr_base, ETR_MAX_NUM); +} diff --git a/drivers/hwtracing/coresight/coresight-ctcu-core.c b/drivers/hwtracing/coresight/coresight-ctcu-core.c index da35d8b4d579..5782655a5f39 100644 --- a/drivers/hwtracing/coresight/coresight-ctcu-core.c +++ b/drivers/hwtracing/coresight/coresight-ctcu-core.c @@ -46,16 +46,24 @@ DEFINE_CORESIGHT_DEVLIST(ctcu_devs, "ctcu"); #define CTCU_ATID_REG_BIT(traceid) (traceid % 32) #define CTCU_ATID_REG_SIZE 0x10 #define CTCU_ETR0_ATID0 0xf8 +#define CTCU_ETR0_IRQCTRL 0x6c #define CTCU_ETR1_ATID0 0x108 +#define CTCU_ETR1_IRQCTRL 0x70 static const struct ctcu_etr_config sa8775p_etr_cfgs[] = { { - .atid_offset = CTCU_ETR0_ATID0, - .port_num = 0, + .atid_offset = CTCU_ETR0_ATID0, + .irq_ctrl_offset = CTCU_ETR0_IRQCTRL, + .irq_name = "etr0", + .byte_cntr_name = "byte-cntr0", + .port_num = 0, }, { - .atid_offset = CTCU_ETR1_ATID0, - .port_num = 1, + .atid_offset = CTCU_ETR1_ATID0, + .irq_ctrl_offset = CTCU_ETR1_IRQCTRL, + .irq_name = "etr1", + .byte_cntr_name = "byte-cntr1", + .port_num = 1, }, }; @@ -64,6 +72,69 @@ static const struct ctcu_config sa8775p_cfgs = { .num_etr_config = ARRAY_SIZE(sa8775p_etr_cfgs), }; +static ssize_t byte_cntr_val_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct ctcu_drvdata *drvdata = dev_get_drvdata(dev->parent); + int i, len = 0; + + for (i = 0; i < ETR_MAX_NUM; i++) { + if (drvdata->byte_cntr_data[i].irq_ctrl_offset) + len += scnprintf(buf + len, PAGE_SIZE - len, "%u ", + drvdata->byte_cntr_data[i].thresh_val); + } + + len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); + + return len; +} + +static ssize_t byte_cntr_val_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t size) +{ + struct ctcu_drvdata *drvdata = dev_get_drvdata(dev->parent); + u32 thresh_vals[ETR_MAX_NUM] = { 0 }; + u32 irq_ctrl_offset; + int num, i; + + num = sscanf(buf, "%i %i", &thresh_vals[0], &thresh_vals[1]); + if (num <= 0 || num > ETR_MAX_NUM) + return -EINVAL; + + /* Threshold 0 disables the interruption. */ + guard(raw_spinlock_irqsave)(&drvdata->spin_lock); + for (i = 0; i < num; i++) { + /* A small threshold will result in a large number of interruptions */ + if (thresh_vals[i] && thresh_vals[i] < 4096) + return -EINVAL; + + if (drvdata->byte_cntr_data[i].irq_ctrl_offset) { + drvdata->byte_cntr_data[i].thresh_val = thresh_vals[i]; + irq_ctrl_offset = drvdata->byte_cntr_data[i].irq_ctrl_offset; + CS_UNLOCK(drvdata->base); + writel_relaxed(thresh_vals[i], drvdata->base + irq_ctrl_offset); + CS_LOCK(drvdata->base); + } + } + + return size; +} +static DEVICE_ATTR_RW(byte_cntr_val); + +static struct attribute *ctcu_attrs[] = { + &dev_attr_byte_cntr_val.attr, + NULL, +}; + +static struct attribute_group ctcu_attr_grp = { + .attrs = ctcu_attrs, +}; + +static const struct attribute_group *ctcu_attr_grps[] = { + &ctcu_attr_grp, + NULL, +}; + static void ctcu_program_atid_register(struct ctcu_drvdata *drvdata, u32 reg_offset, u8 bit, bool enable) { @@ -122,7 +193,7 @@ static int __ctcu_set_etr_traceid(struct coresight_device *csdev, u8 traceid, in * 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 coresight_device *helper) +int ctcu_get_active_port(struct coresight_device *sink, struct coresight_device *helper) { struct coresight_platform_data *pdata = helper->pdata; int i; @@ -160,6 +231,8 @@ static int ctcu_enable(struct coresight_device *csdev, enum cs_mode mode, void * { struct coresight_path *path = (struct coresight_path *)data; + ctcu_byte_cntr_start(csdev, path); + return ctcu_set_etr_traceid(csdev, path, true); } @@ -167,6 +240,8 @@ static int ctcu_disable(struct coresight_device *csdev, void *data) { struct coresight_path *path = (struct coresight_path *)data; + ctcu_byte_cntr_stop(csdev, path); + return ctcu_set_etr_traceid(csdev, path, false); } @@ -188,7 +263,7 @@ static int ctcu_probe(struct platform_device *pdev) const struct ctcu_config *cfgs; struct ctcu_drvdata *drvdata; void __iomem *base; - int i; + int ret, i; desc.name = coresight_alloc_device_name(&ctcu_devs, dev); if (!desc.name) @@ -217,7 +292,14 @@ static int ctcu_probe(struct platform_device *pdev) for (i = 0; i < cfgs->num_etr_config; i++) { etr_cfg = &cfgs->etr_cfgs[i]; drvdata->atid_offset[i] = etr_cfg->atid_offset; + drvdata->byte_cntr_data[i].irq_name = etr_cfg->irq_name; + drvdata->byte_cntr_data[i].name = etr_cfg->byte_cntr_name; + drvdata->byte_cntr_data[i].irq_ctrl_offset = + etr_cfg->irq_ctrl_offset; } + ret = ctcu_byte_cntr_init(dev, drvdata, cfgs->num_etr_config); + if (ret < 0) + dev_warn(dev, "Byte cntr init failed\n"); } } @@ -229,6 +311,7 @@ static int ctcu_probe(struct platform_device *pdev) desc.subtype.helper_subtype = CORESIGHT_DEV_SUBTYPE_HELPER_CTCU; desc.pdata = pdata; desc.dev = dev; + desc.groups = ctcu_attr_grps; desc.ops = &ctcu_ops; desc.access = CSDEV_ACCESS_IOMEM(base); @@ -247,6 +330,7 @@ static void ctcu_remove(struct platform_device *pdev) { struct ctcu_drvdata *drvdata = platform_get_drvdata(pdev); + ctcu_byte_cntr_remove(drvdata); coresight_unregister(drvdata->csdev); } diff --git a/drivers/hwtracing/coresight/coresight-ctcu.h b/drivers/hwtracing/coresight/coresight-ctcu.h index e9594c38dd91..e38535c91090 100644 --- a/drivers/hwtracing/coresight/coresight-ctcu.h +++ b/drivers/hwtracing/coresight/coresight-ctcu.h @@ -5,6 +5,8 @@ #ifndef _CORESIGHT_CTCU_H #define _CORESIGHT_CTCU_H +#include + #include "coresight-trace-id.h" /* Maximum number of supported ETR devices for a single CTCU. */ @@ -13,10 +15,16 @@ /** * struct ctcu_etr_config * @atid_offset: offset to the ATID0 Register. - * @port_num: in-port number of CTCU device that connected to ETR. + * @irq_ctrl_offset: offset to the BYTECNTRVAL register. + * @irq_name: IRQ name in dt node. + * @byte_cntr_name: name of the byte cntr device node. + * @port_num: in-port number of the CTCU device that connected to ETR. */ struct ctcu_etr_config { const u32 atid_offset; + const u32 irq_ctrl_offset; + const char *irq_name; + const char *byte_cntr_name; const u32 port_num; }; @@ -25,15 +33,64 @@ struct ctcu_config { int num_etr_config; }; +/** + * struct ctcu_byte_cntr + * @c_dev: cdev for byte_cntr. + * @sink csdev of sink device. + * @enable: indicates that byte_cntr function is enabled or not. + * @read_active: indicates that byte-cntr node is opened or not. + * @thresh_val: threshold to trigger a interruption. + * @total_size total size of transferred data. + * @byte_cntr_irq: IRQ number. + * @irq_cnt: IRQ count. + * @wq: workqueue of reading ETR data. + * @read_work: work of reading ETR data. + * @spin_lock: spinlock of byte cntr data. + * @r_offset: offset of the pointer where reading begins. + * @w_offset: offset of the write pointer in the ETR buffer when + * the byte cntr is stopped. + * @irq_ctrl_offset: offset to the BYTECNTRVAL Register. + * @name: the name of byte cntr device node. + * @irq_name: IRQ name in DT. + */ +struct ctcu_byte_cntr { + struct cdev c_dev; + struct coresight_device *sink; + bool enable; + bool read_active; + u32 thresh_val; + u64 total_size; + int byte_cntr_irq; + atomic_t irq_cnt; + wait_queue_head_t wq; + struct work_struct read_work; + raw_spinlock_t spin_lock; + long r_offset; + long w_offset; + u32 irq_ctrl_offset; + const char *name; + const char *irq_name; +}; + 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]; }; +/* Generic functions */ +int ctcu_get_active_port(struct coresight_device *sink, struct coresight_device *helper); + +/* 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); +int ctcu_byte_cntr_init(struct device *dev, struct ctcu_drvdata *drvdata, int port_num); +void ctcu_byte_cntr_remove(struct ctcu_drvdata *drvdata); + #endif diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index ec636ab1fd75..5dc94e890927 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1040,14 +1040,15 @@ static void tmc_free_etr_buf(struct etr_buf *etr_buf) * Returns: The size of the linear data available @pos, with *bufpp * updated to point to the buffer. */ -static ssize_t tmc_etr_buf_get_data(struct etr_buf *etr_buf, - u64 offset, size_t len, char **bufpp) +ssize_t tmc_etr_buf_get_data(struct etr_buf *etr_buf, + u64 offset, size_t len, char **bufpp) { /* Adjust the length to limit this transaction to end of buffer */ len = (len < (etr_buf->size - offset)) ? len : etr_buf->size - offset; return etr_buf->ops->get_data(etr_buf, (u64)offset, len, bufpp); } +EXPORT_SYMBOL_GPL(tmc_etr_buf_get_data); static inline s64 tmc_etr_buf_insert_barrier_packet(struct etr_buf *etr_buf, u64 offset) diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index baedb4dcfc3f..2fc77fd4ea25 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -443,5 +443,7 @@ struct etr_buf *tmc_etr_get_buffer(struct coresight_device *csdev, enum cs_mode mode, void *data); extern const struct attribute_group coresight_etr_group; long tmc_get_rwp_offset(struct tmc_drvdata *drvdata); +ssize_t tmc_etr_buf_get_data(struct etr_buf *etr_buf, u64 offset, size_t len, + char **bufpp); #endif From patchwork Mon Mar 10 09:04:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Gan X-Patchwork-Id: 14009434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BDAA4C282DE for ; Mon, 10 Mar 2025 09:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hikquEb8hpodf6jIlqXoBWFejspidQqPqbCespXj9q0=; b=hAY+sUI3SDtAt5TonsWrTPq/ND 9Ba97Kk6TB9GlfvXayF8dO0g3BEEgz6fLlzT1eIQpURWgHIY+zVwW/iuXwWKNs5BJ+WXZATqSUkLs JltBjNmMASqEVRWsiVCbCryHQAZldON7/1LA1j9ZTF0mPKrqYoefwdu1+csqdibLr0Duv5a/1O3ZC +KwFUkZGhVOz25e0oeS2DdFG5+DhP29PiCuabzy1Qcn6awqQWvKu7W9LmJBdPpae8sqhVz9lIYIyN 9NmrY+ozufpGizcfiQLwjljiKYqOMfdts3s4H5XGa46K6da/4cXrg4EnUywxZOSJGg6NW0rjzu+7U P+u6XkWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1trZAg-000000021xo-37zU; Mon, 10 Mar 2025 09:11:38 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1trZ4c-000000020wb-35y4 for linux-arm-kernel@lists.infradead.org; Mon, 10 Mar 2025 09:05:23 +0000 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 529MwHwD006531; Mon, 10 Mar 2025 09:04:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= hikquEb8hpodf6jIlqXoBWFejspidQqPqbCespXj9q0=; b=NPYaQRC3HBQr+7x6 cp7r81Llq2tqNy4HNe2cziZO7uduhDoCSwyueK1TRLHlC8c8dbRi1jzvEdX5k1JR EgHfjXaMIEDReXT99VudQI69UZNcsBqjFCZuG0QGLiQIgaiaruiw8U7gRzIbdsKo FESIjsm0KAXUujbyuCfiS4k64+rJw/eyByxR7F7XTXLxpxKD7sAt1xJm73XyoU98 g6p+G0w2lFSLDOviA4RQ0HcIQQh8UgTqFsawgxHcT8TIdMT/u0x/gZCoQ6idHbXN NGAj0r2F7rb+J2fpLKDA08CLrTk9mcCwihr588XHYjkHFu1BH+dOoKncOpuOuYI+ EfcgWg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 458ex6v8tq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:56 +0000 (GMT) Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 52A94trs010246 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Mar 2025 09:04:56 GMT Received: from jiegan-gv.qualcomm.com (10.80.80.8) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 10 Mar 2025 02:04:50 -0700 From: Jie Gan To: Suzuki K Poulose , Mike Leach , James Clark , "Alexander Shishkin" , Maxime Coquelin , Alexandre Torgue , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio CC: Tingwei Zhang , Jinlong Mao , , , , , , Subject: [PATCH v1 4/4] arm64: dts: qcom: sa8775p: Add interrupts to CTCU device Date: Mon, 10 Mar 2025 17:04:07 +0800 Message-ID: <20250310090407.2069489-5-quic_jiegan@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250310090407.2069489-1-quic_jiegan@quicinc.com> References: <20250310090407.2069489-1-quic_jiegan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Authority-Analysis: v=2.4 cv=G8bmE8k5 c=1 sm=1 tr=0 ts=67ceab38 cx=c_pps a=ouPCqIW2jiPt+lZRy3xVPw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=GEpy-HfZoHoA:10 a=Vs1iUdzkB0EA:10 a=COk6AnOGAAAA:8 a=wB5yJZRArZ6K3lEFQq8A:9 a=VwTNVE38tNj-EdhTN1jR:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-GUID: 6GN6IUPd_KPNxvMiuNjyzU5-UyRhz2-d X-Proofpoint-ORIG-GUID: 6GN6IUPd_KPNxvMiuNjyzU5-UyRhz2-d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-10_03,2025-03-07_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=619 phishscore=0 malwarescore=0 mlxscore=0 suspectscore=0 clxscore=1015 bulkscore=0 adultscore=6 priorityscore=1501 lowpriorityscore=0 spamscore=0 impostorscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2503100071 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250310_020522_778344_4447C35D X-CRM114-Status: GOOD ( 10.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add interrupts to enable byte-cntr function for TMC ETR devices. Signed-off-by: Jie Gan --- Dependency: prerequisite-message-id: 20250303032931.2500935-11-quic_jiegan@quicinc.com --- arch/arm64/boot/dts/qcom/sa8775p.dtsi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/sa8775p.dtsi b/arch/arm64/boot/dts/qcom/sa8775p.dtsi index 93ca37843990..091ae73774fa 100644 --- a/arch/arm64/boot/dts/qcom/sa8775p.dtsi +++ b/arch/arm64/boot/dts/qcom/sa8775p.dtsi @@ -2425,6 +2425,11 @@ ctcu@4001000 { clocks = <&aoss_qmp>; clock-names = "apb"; + interrupts = , + ; + interrupt-names = "etr0", + "etr1"; + in-ports { #address-cells = <1>; #size-cells = <0>;