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: 170039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp2908680vqx; Sun, 26 Nov 2023 23:27:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcA4hGKvKPfQFd0NaUSVugpKYbmTOBM+HtsWYOqEXavF11ZnGRfSBUfmjI7uc+TmjJNAjS X-Received: by 2002:a17:903:1c3:b0:1cf:b818:68d1 with SMTP id e3-20020a17090301c300b001cfb81868d1mr7433882plh.49.1701070022328; Sun, 26 Nov 2023 23:27:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701070022; cv=pass; d=google.com; s=arc-20160816; b=k6c78meXqk84U/aWHYIi/t2z8BghPDdXePMLkipKx+B4Q/bSm70nMHeBQ/J3hr7s1l aRo7FhKi9qPDmMEIAmsE7cxkM5A/j5Eg1sMAUSErSIsUbU40o/hxCGlFucX9qUOv9uIy U6DDzDPLFaLxXq22JuczYbsetvq0jILHjKoPXbvtwEpAjvmaA9UdCOPk8hL9wXw+muE2 /4egU/QFlba/NvEoN69z9mq5gAW4YMK+LeoVTjA4LVLJGsluZTWum5hhwK1LyUNTajZs EqZA5Qq8Yf8L24qK7Qv8NwCcWCaQ5M6j+lA9eUxfmg9xfdCReLISh56ZIsAAXFBaiTTb cABw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=76SLADWkTS3QXMmnUjlMjEpbBQAbk2qEx9d8SojKME4=; fh=ukokmL/bDQ3qZ5qAvawar1lZd3CJf4+qRHBuo8gx+G8=; b=BlVU1j94Edc1lqZLn7yJPBnT4IMytp+M5Ob1nT2EhJlYAf2w+qTMrnDcUubzeddJmE wyePDG5izRl4PA0pXQhmSiO1vIsdL68fSLexDkrMODFSRKAZrSJAn1s2aHBfeOLKanYm E7WTpgxahljm5Uvrq4LfuHk6ZAwi9RHCHT4UNgAjaqhe6X38VAjg7vd38XZrtS0wplI8 HUtyDeXre9y+YgN593jIzWB/h3Enqv0/+YW/noJPATAqOHuxOpTix02evBZ/n9BLAeJ7 vLlnAmF7cqzoNMpmmgp3erwiaM5YG02sWu68d3O3XVhSuUHktJho5k0IrIasovkykd2m DPbA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=H3fBnwUQ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u13-20020a170903124d00b001b045d65aedsi9185752plh.228.2023.11.26.23.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 23:27:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=H3fBnwUQ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8E944805F3EC; Sun, 26 Nov 2023 23:26:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbjK0H0o (ORCPT + 99 others); Mon, 27 Nov 2023 02:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjK0H0i (ORCPT ); Mon, 27 Nov 2023 02:26:38 -0500 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2048.outbound.protection.outlook.com [40.107.15.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 586A912F; Sun, 26 Nov 2023 23:26:43 -0800 (PST) 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-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 26 Nov 2023 23:26:56 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783701199611931111 X-GMAIL-MSGID: 1783701199611931111 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);