From patchwork Mon Nov 27 07:32:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13469254 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 E2458C4167B for ; Mon, 27 Nov 2023 07:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=bZu2oYff/4GBqW9XR9JfRIX7CpIobclxp0Bt3g6nyYA=; b=pLXqA4rZKZRS+X opPDoT0aOMPVtJAmcFQ/HBWXb3ot08TZLez30tKrWgypcCVy7YEHr1Ut3ojsDl7KOCXQ+sT2snUFz eDqtN/u+06AHcFBXoK/zCyy9McflfkLHM1J7QIxL8QEIq0vtP8RAX8xCpTswRCMqPdH7vPKu8B8uL f/+8StNVPAO6VW/RTh733tNHC5t+PeIXg6E/QrX4dEdX9iVpHgY3iEctZZsRZWVtHyU2fysrE3o+y 3xq+4BpX7l6U8wTGrLTiYAqOcF2eaRDG4AaUVuMbMURvtlaZWsTKqLTg2vSuYyaFPLflMss4EOZSC SVOp6QLEnhrgGj6pl39w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7WEo-001kkd-2h; Mon, 27 Nov 2023 07:41:02 +0000 Received: from mail-dbaeur03on20630.outbound.protection.outlook.com ([2a01:111:f400:fe1a::630] helo=EUR03-DBA-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7WEk-001kk9-0A for linux-arm-kernel@lists.infradead.org; Mon, 27 Nov 2023 07:41:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dqf3mEvmpF7pa+Ja8DT2nXPnIIIsUC4LLRUMy+dYJ6d9iD8VIahflabFJI7A7aDc1Z/uqIvQ6sLjCJPYIRowgGAREFijT6Sqe8olcE92gFpIwpi/xe5FYusHE2oV1yATHGjuwWrnRST/+uixSDiAKRcwgR/LbfkGAImYKekYe6AcTeWGnqxOapSAKI+zGkkw8bi3lG/N63ifYue+K4zEYslxhg7Dth7+ImQrQBDZ7F2v3OGqAVOynqniuAea4dufYgxVMFv4PtchupJCIlA1mKVgmijcDKcldQTm76tcpysNTT/QCV8t0jF1rW4SM6pJbnk9qox/MPSwqb25Qf4ZQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=76SLADWkTS3QXMmnUjlMjEpbBQAbk2qEx9d8SojKME4=; b=MTbmEYW9l+fZteoMB/HUguA8avXFZtGLNosEgX73LrzL7ycB1U06lE6UDJ5nbh1ITvo/ToCmerfJ7K3jN3AuvsIWFLcH+L18yNgrzDiH60eEknFii/YQzPvMqNmU8WWBI8zG3hRBPLNkfiISLPvJDFDWl+DoLle7mw2Jetfl7kgAAIe9cogytmkJuquyMKvhcRDihxBccQ3Td7XTMPSCaQoaWEFxw4YK8fo3kKSkQN+7ouUH8gNqe4Hk8pnM2Ajs7Zew/CewN10/19CeWbbd8U3xQ93mct99V2LLQtSoZFHBiau5eN91FZJP7nP0JIUuCFl4qarboD4EBm8KCyHLWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=76SLADWkTS3QXMmnUjlMjEpbBQAbk2qEx9d8SojKME4=; b=H3fBnwUQkXaGJRWoGWgECJMJM+pw9P7ITxdV+Br/phWkFUSOhloF6DuvxvVAscm0WVlp+00+yLD6kcMv7wUuwPRrmTuFak096enFqZcvLzHihVf1l6M+107U9hsWkj8zQBDdb8P9nkNTqEeE8oTLCjmwJ55kJG4ik8Oavires1w= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB5146.eurprd04.prod.outlook.com (2603:10a6:10:23::16) by DUZPR04MB9871.eurprd04.prod.outlook.com (2603:10a6:10:4b1::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.19; Mon, 27 Nov 2023 07:26:40 +0000 Received: from DB7PR04MB5146.eurprd04.prod.outlook.com ([fe80::709e:6876:7df0:fc30]) by DB7PR04MB5146.eurprd04.prod.outlook.com ([fe80::709e:6876:7df0:fc30%7]) with mapi id 15.20.7046.015; Mon, 27 Nov 2023 07:26:40 +0000 From: Xu Yang To: Frank.li@nxp.com, will@kernel.org, mark.rutland@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, irogers@google.com, namhyung@kernel.org, acme@kernel.org, john.g.garry@oracle.com Cc: james.clark@arm.com, mike.leach@linaro.org, leo.yan@linaro.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] perf: imx_perf: add support for i.MX95 platform Date: Mon, 27 Nov 2023 15:32:07 +0800 Message-Id: <20231127073208.1055466-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127073208.1055466-1-xu.yang_2@nxp.com> References: <20231127073208.1055466-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI2PR04CA0006.apcprd04.prod.outlook.com (2603:1096:4:197::13) To DB7PR04MB5146.eurprd04.prod.outlook.com (2603:10a6:10:23::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB5146:EE_|DUZPR04MB9871:EE_ X-MS-Office365-Filtering-Correlation-Id: fea5c770-59b8-4051-c919-08dbef1a32c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b8JTRCrpB7DyOJ9r9hT9bGiNATw0Yg/D3ymgXxzsO8IgM8rt5e5883KJm4VbuIzJfCa62PZ7EQrQ3uUlcsK7PUSM6SYpl6+NNh+XoXOMhicipCJK7FyzAaVEfLv1ejd5LiIfPlpQ5qOr9FEZWpAdeempE1MJ3TEcxKmTKpf8Zl68WUQybYnhfaeZzw70glB9DjDtPr0QHCPmPIf00fLgVBegZ7wh5J1st6aPiQKBqfnVR/myeK/vdFE4I+vWghHWB25Tp+xlNyxH/qCZsQVgbPvyHR6H2HpUlYL+Ls6re61N5fQmFNKLpHNICneMFcvcYEqTOFBNcF6mxkSTgut8tJmAj0Vcm2UbOxHT0d1uETdwsXU/DCOSmdwqIH+B6ahVlwcR/yGTulD1wEA9Ro/wKFEv7fhrFY3WRdmTtazI5+wZz4iFz7Ef7Io5tI/wdHxFH7I1j86Nef+Xk7YV/WJTIWphSh+KO+dNGHGKcKSfWeGMjcAAujR4Ztm6Y2NtKXWk1sV9IR8W4en+cXKA4U83QgUQknPOeTVO4foA7cBQhZfKDPebttYOpSLq4/sNm+V6yLHn9G5TkKJaNcqfVbPxU9C5VFAJThdslZiFYCTYRmpr0XtfOsdCDVvOHUzLYFWI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB5146.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(366004)(396003)(39860400002)(346002)(136003)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(26005)(1076003)(6486002)(2616005)(6506007)(6666004)(52116002)(478600001)(6512007)(38100700002)(921008)(38350700005)(36756003)(86362001)(5660300002)(41300700001)(2906002)(7416002)(66946007)(83380400001)(30864003)(66556008)(66476007)(316002)(4326008)(8936002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KlIFib8NZNPlTZXMKviYQ9lusyBN171RTSmB4jSQphkT5CWAbg7h9AyZCjgr+YJg+R8cWB4O7MWGc7HT6D0UfmQAaJ1kioQcBvX/iLEcdDmlG8AKcHMc8WaNltddTFSf3VsMDyU20QLZLVPNH0x0hdl9c1FXVGsvdgmzqeNRvJ+DHN1K63EkpD4De7o9/9CKxl2wYSYNFaPDOiw9Beog6XUZFFJoMmkwYVEp5V62NJRR/jnxv07lAaIoSZI0mkDhoNK9x4cBtBkOeUrYYBMRvAcB5Xt9lUn2c+USBOazYWNhOMqvNmDbm56SfEXSa3lcG5GKVQcj6nzUgpD6jL6Lj3qHj45zw9PZRSWo9eMMBJVQ4zNxdc4v/mxgL4qWO8BUI1ysZAGexD7t107txuZfeOjg/VvXm6n7h7Jzj9GlGbRvRgpHD5X1oxN+NIfH2j3dhuxLxA7v6+4UT9M/QOi9hUbz7xfGu1a954t5oiNARuVUhHV8ew8tno+SX3Lemx9vU1Ui1LFvwkHIfoF3/ijddK03xD6xM0i5DOrgH7iU2P8tRpFDf/NdfoRCNis5l7073d+YHzwrg97iKEifw7IQHceR+gpMZpRW3RaB5uLyXE8DjKDtww6v9ZFxUihO5epXahfcUtzbk292509lzUloyzcS3sob8xm5PS7Grvavm0foAtVquBPfgNLqCFkkB5HyVpCQaU5wEQNllZty8MXIQqg1/46Z4BvrnGyqGMNbCCmF4FiHl2mlqwkGIc76N8oWzbFA5LJHwtiomqqXiqLPj/PagtRyJPS4zBblk11smGZ4X6hE6R8f37pidrwV3OdaUJKVao70pNC2ed33G2HR9vFpiArcuC6dbjuSF2GFe12M9LfE8Z+d1KZp/N4fYwVNb9UZI7V2+yi8+tqdMQEioIwO900WgDsUvBtTYiO4jMNBquTCqfW6uPA2Vgevrz9Xavv8iPGrF8aCubS1+aKM9dklQYJqx7pqXmYR8SYAglh2mIlXc5tsZMEGi90Nw1sZQmEneXTN5fmgZA+vptYVFiA+7NtRrB58w7TuyKY2ZpDsq7RKQB//u/CmSLApNtTX4hNiirfUWG54/bd/0+96jsA/tvVc+Ws4v1W1cKBI6sr7NFoaQ4wdQBefrX+MzmE/1klCpQDmaMu1I6jVnCgxUu8taSft4+ItpqHBWml/QQ9cuYA4NLMzuiT6Zgf92dDFOxeJDDrCctXm2jKOq2KfTpM3bBj4JoBDgcazgCE5WAy3wG42jhKJptt0pt+bdmORQXwaP8sR13g4fK/Yj2hKHuBuWgf5j80oXO8Lq9oK+zwmFQTD7VEDzSDOl7EhkPpLi/R9xJDwIcwOBOjWP+XfrvlYiA01scMNFSPF1m/S2BZHqGGRctyOiQf9cplxIbbAyOVPzCJmo2EK5PPEQk27QWb8t0W872j68tI/G4uaiy6vsC4oNv1k5bBEL6H6NM3UDm5Npon72wUbfP5rl/YBOv9YLK/m0GpoYkhuNbkrtEtc4xhozhzRT+4yhifqiD+OUeyvxrbo1y1z8HU3wsRYY3427KoFOxdjATmQ00nJKDwfrBkb/5lacb2+VDhh2Cit X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fea5c770-59b8-4051-c919-08dbef1a32c0 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB5146.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2023 07:26:40.5639 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0Uic+w5xftM1dvF8FlL0JAqPy3zRYFAiNmd3d6OaoCAe7jE8I4o1/40e2d0QVlH/jKFEgv3mPBZguo9+3+O83Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9871 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231126_234058_332982_E2D0844D X-CRM114-Status: GOOD ( 16.88 ) 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 i.MX95 has a DDR PMU which is almostly same as i.MX93, it now supports read beat and write beat filter capabilities. This will add support for i.MX95 and enhance the driver to support specific filter handling for it. Usage: For read beat: ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt2,counter=3,axi_mask=ID_MASK,axi_id=ID/ ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt1,counter=4,axi_mask=ID_MASK,axi_id=ID/ ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt0,counter=5,axi_mask=ID_MASK,axi_id=ID/ eg: For edma2: perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt0,counter=5,axi_mask=0x00f,axi_id=0x00c/ For write beat: ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_wr_beat_filt,counter=2,axi_mask=ID_MASK,axi_id=ID/ eg: For edma2: perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_wr_beat_filt,counter=2,axi_mask=0x00f,axi_id=0x00c/ Signed-off-by: Xu Yang --- drivers/perf/fsl_imx9_ddr_perf.c | 187 +++++++++++++++++++++++++++---- 1 file changed, 164 insertions(+), 23 deletions(-) diff --git a/drivers/perf/fsl_imx9_ddr_perf.c b/drivers/perf/fsl_imx9_ddr_perf.c index 5cf770a1bc31..5e531d94cf3b 100644 --- a/drivers/perf/fsl_imx9_ddr_perf.c +++ b/drivers/perf/fsl_imx9_ddr_perf.c @@ -11,14 +11,24 @@ #include /* Performance monitor configuration */ -#define PMCFG1 0x00 -#define PMCFG1_RD_TRANS_FILT_EN BIT(31) -#define PMCFG1_WR_TRANS_FILT_EN BIT(30) -#define PMCFG1_RD_BT_FILT_EN BIT(29) -#define PMCFG1_ID_MASK GENMASK(17, 0) +#define PMCFG1 0x00 +#define MX93_PMCFG1_RD_TRANS_FILT_EN BIT(31) +#define MX93_PMCFG1_WR_TRANS_FILT_EN BIT(30) +#define MX93_PMCFG1_RD_BT_FILT_EN BIT(29) +#define MX93_PMCFG1_ID_MASK GENMASK(17, 0) -#define PMCFG2 0x04 -#define PMCFG2_ID GENMASK(17, 0) +#define MX95_PMCFG1_WR_BEAT_FILT_EN BIT(31) +#define MX95_PMCFG1_RD_BEAT_FILT_EN BIT(30) + +#define PMCFG2 0x04 +#define MX93_PMCFG2_ID GENMASK(17, 0) + +#define PMCFG3 0x08 +#define PMCFG4 0x0C +#define PMCFG5 0x10 +#define PMCFG6 0x14 +#define MX95_PMCFG_ID_MASK GENMASK(9, 0) +#define MX95_PMCFG_ID GENMASK(25, 16) /* Global control register affects all counters and takes priority over local control registers */ #define PMGC0 0x40 @@ -71,12 +81,22 @@ static const struct imx_ddr_devtype_data imx93_devtype_data = { .identifier = "imx93", }; +static const struct imx_ddr_devtype_data imx95_devtype_data = { + .identifier = "imx95", +}; + static const struct of_device_id imx_ddr_pmu_dt_ids[] = { {.compatible = "fsl,imx93-ddr-pmu", .data = &imx93_devtype_data}, + {.compatible = "fsl,imx95-ddr-pmu", .data = &imx95_devtype_data}, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, imx_ddr_pmu_dt_ids); +static inline bool is_imx93(struct ddr_pmu *pmu) +{ + return pmu->devtype_data == &imx93_devtype_data; +} + static ssize_t ddr_perf_identifier_show(struct device *dev, struct device_attribute *attr, char *page) @@ -178,7 +198,6 @@ static struct attribute *ddr_perf_events_attrs[] = { IMX9_DDR_PMU_EVENT_ATTR(ddrc_ld_wiq_6, 70), IMX9_DDR_PMU_EVENT_ATTR(ddrc_ld_wiq_7, 71), IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pmon_empty, 72), - IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_rd_trans_filt, 73), /* counter3 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_collision_0, 64), @@ -190,7 +209,6 @@ static struct attribute *ddr_perf_events_attrs[] = { IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_collision_6, 70), IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_collision_7, 71), IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pmon_full, 72), - IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_wr_trans_filt, 73), /* counter4 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_open_0, 64), @@ -202,7 +220,6 @@ static struct attribute *ddr_perf_events_attrs[] = { IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_open_6, 70), IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_open_7, 71), IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pmon_ld_rdq2_rmw, 72), - IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_rd_beat_filt, 73), /* counter5 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_valid_start_0, 64), @@ -242,6 +259,26 @@ static const struct attribute_group ddr_perf_events_attr_group = { .attrs = ddr_perf_events_attrs, }; +static struct attribute *imx93_ddr_perf_events_attrs[] = { + /* counter2 specific events */ + IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_rd_trans_filt, 73), + /* counter3 specific events */ + IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_wr_trans_filt, 73), + /* counter4 specific events */ + IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_rd_beat_filt, 73), +}; + +static struct attribute *imx95_ddr_perf_events_attrs[] = { + /* counter2 specific events */ + IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_wr_beat_filt, 73), + /* counter3 specific events */ + IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_rd_beat_filt2, 73), + /* counter4 specific events */ + IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_rd_beat_filt1, 73), + /* counter5 specific events */ + IMX9_DDR_PMU_EVENT_ATTR(eddrtq_pm_rd_beat_filt0, 73), +}; + PMU_FORMAT_ATTR(event, "config:0-7"); PMU_FORMAT_ATTR(counter, "config:8-15"); PMU_FORMAT_ATTR(axi_id, "config1:0-17"); @@ -361,7 +398,7 @@ static void ddr_perf_counter_local_config(struct ddr_pmu *pmu, int config, } } -static void ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1, int cfg2) +static void imx93_ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1, int cfg2) { u32 pmcfg1, pmcfg2; int event, counter; @@ -372,30 +409,80 @@ static void ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1, int pmcfg1 = readl_relaxed(pmu->base + PMCFG1); if (counter == 2 && event == 73) - pmcfg1 |= PMCFG1_RD_TRANS_FILT_EN; + pmcfg1 |= MX93_PMCFG1_RD_TRANS_FILT_EN; else if (counter == 2 && event != 73) - pmcfg1 &= ~PMCFG1_RD_TRANS_FILT_EN; + pmcfg1 &= ~MX93_PMCFG1_RD_TRANS_FILT_EN; if (counter == 3 && event == 73) - pmcfg1 |= PMCFG1_WR_TRANS_FILT_EN; + pmcfg1 |= MX93_PMCFG1_WR_TRANS_FILT_EN; else if (counter == 3 && event != 73) - pmcfg1 &= ~PMCFG1_WR_TRANS_FILT_EN; + pmcfg1 &= ~MX93_PMCFG1_WR_TRANS_FILT_EN; if (counter == 4 && event == 73) - pmcfg1 |= PMCFG1_RD_BT_FILT_EN; + pmcfg1 |= MX93_PMCFG1_RD_BT_FILT_EN; else if (counter == 4 && event != 73) - pmcfg1 &= ~PMCFG1_RD_BT_FILT_EN; + pmcfg1 &= ~MX93_PMCFG1_RD_BT_FILT_EN; - pmcfg1 &= ~FIELD_PREP(PMCFG1_ID_MASK, 0x3FFFF); - pmcfg1 |= FIELD_PREP(PMCFG1_ID_MASK, cfg2); + pmcfg1 &= ~FIELD_PREP(MX93_PMCFG1_ID_MASK, 0x3FFFF); + pmcfg1 |= FIELD_PREP(MX93_PMCFG1_ID_MASK, cfg2); writel(pmcfg1, pmu->base + PMCFG1); pmcfg2 = readl_relaxed(pmu->base + PMCFG2); - pmcfg2 &= ~FIELD_PREP(PMCFG2_ID, 0x3FFFF); - pmcfg2 |= FIELD_PREP(PMCFG2_ID, cfg1); + pmcfg2 &= ~FIELD_PREP(MX93_PMCFG2_ID, 0x3FFFF); + pmcfg2 |= FIELD_PREP(MX93_PMCFG2_ID, cfg1); writel(pmcfg2, pmu->base + PMCFG2); } +static void imx95_ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1, int cfg2) +{ + u32 pmcfg1, pmcfg, offset = 0; + int event, counter; + + event = cfg & 0x000000FF; + counter = (cfg & 0x0000FF00) >> 8; + + pmcfg1 = readl_relaxed(pmu->base + PMCFG1); + + if (counter == 2 && event == 73) { + pmcfg1 |= MX95_PMCFG1_WR_BEAT_FILT_EN; + offset = PMCFG3; + } else if (counter == 2 && event != 73) { + pmcfg1 &= ~MX95_PMCFG1_WR_BEAT_FILT_EN; + } + + if (counter == 3 && event == 73) { + pmcfg1 |= MX95_PMCFG1_RD_BEAT_FILT_EN; + offset = PMCFG4; + } else if (counter == 3 && event != 73) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN; + } + + if (counter == 4 && event == 73) { + pmcfg1 |= MX95_PMCFG1_RD_BEAT_FILT_EN; + offset = PMCFG5; + } else if (counter == 4 && event != 73) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN; + } + + if (counter == 5 && event == 73) { + pmcfg1 |= MX95_PMCFG1_RD_BEAT_FILT_EN; + offset = PMCFG6; + } else if (counter == 5 && event != 73) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN; + } + + writel(pmcfg1, pmu->base + PMCFG1); + + if (offset) { + pmcfg = readl_relaxed(pmu->base + offset); + pmcfg &= ~FIELD_PREP(MX95_PMCFG_ID_MASK, 0x3FF); + pmcfg |= FIELD_PREP(MX95_PMCFG_ID_MASK, cfg2); + pmcfg &= ~FIELD_PREP(MX95_PMCFG_ID, 0x3FF); + pmcfg |= FIELD_PREP(MX95_PMCFG_ID, cfg1); + writel(pmcfg, pmu->base + offset); + } +} + static void ddr_perf_event_update(struct perf_event *event) { struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); @@ -479,8 +566,13 @@ static int ddr_perf_event_add(struct perf_event *event, int flags) if (flags & PERF_EF_START) ddr_perf_event_start(event, flags); - /* read trans, write trans, read beat */ - ddr_perf_monitor_config(pmu, cfg, cfg1, cfg2); + if (is_imx93(pmu)) { + /* read trans, write trans, read beat */ + imx93_ddr_perf_monitor_config(pmu, cfg, cfg1, cfg2); + } else { + /* write beat, read beat2, read beat1, read beat */ + imx95_ddr_perf_monitor_config(pmu, cfg, cfg1, cfg2); + } return 0; } @@ -596,6 +688,49 @@ static int ddr_perf_offline_cpu(unsigned int cpu, struct hlist_node *node) return 0; } +static int ddr_perf_add_events(struct ddr_pmu *pmu) +{ + int i, ret, events; + struct attribute **attrs; + struct device *pmu_dev = pmu->pmu.dev; + + if (is_imx93(pmu)) { + events = sizeof(imx93_ddr_perf_events_attrs)/sizeof(struct attribute *); + attrs = imx93_ddr_perf_events_attrs; + } else { + events = sizeof(imx95_ddr_perf_events_attrs)/sizeof(struct attribute *); + attrs = imx95_ddr_perf_events_attrs; + } + + for (i = 0; i < events; i++) { + ret = sysfs_add_file_to_group(&pmu_dev->kobj, attrs[i], "events"); + if (ret) { + dev_warn(pmu->dev, "i.MX9 DDR Perf add events failed (%d)\n", ret); + return ret; + } + } + + return 0; +} + +static void ddr_perf_remove_events(struct ddr_pmu *pmu) +{ + int i, events; + struct attribute **attrs; + struct device *pmu_dev = pmu->pmu.dev; + + if (is_imx93(pmu)) { + events = sizeof(imx93_ddr_perf_events_attrs)/sizeof(struct attribute *); + attrs = imx93_ddr_perf_events_attrs; + } else { + events = sizeof(imx95_ddr_perf_events_attrs)/sizeof(struct attribute *); + attrs = imx95_ddr_perf_events_attrs; + } + + for (i = 0; i < events; i++) + sysfs_remove_file_from_group(&pmu_dev->kobj, attrs[i], "events"); +} + static int ddr_perf_probe(struct platform_device *pdev) { struct ddr_pmu *pmu; @@ -666,6 +801,10 @@ static int ddr_perf_probe(struct platform_device *pdev) if (ret) goto ddr_perf_err; + ret = ddr_perf_add_events(pmu); + if (ret) + dev_warn(&pdev->dev, "i.MX9 DDR Perf filter events are missing\n"); + return 0; ddr_perf_err: @@ -683,6 +822,8 @@ static int ddr_perf_remove(struct platform_device *pdev) { struct ddr_pmu *pmu = platform_get_drvdata(pdev); + ddr_perf_remove_events(pmu); + cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node); cpuhp_remove_multi_state(pmu->cpuhp_state);