From patchwork Thu Oct 19 11:37:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=WveTg+bD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5Q75ckpz20Zj for ; Thu, 19 Oct 2023 22:41:01 +1100 (AEDT) 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=/THFIRsTWxD6GGk2AXTPzaIpK6DzXjWOdmfo0mc/4M4=; b=WveTg+bDyYpd4v cA/YeL5Y43OqcJuzfDIE4tKZ7eMpVnGfoc9OA4rS/60Zq4byTDXAf80cmnwykWaJMZ0eh5YHWz5A0 +VjYsbX1TddwwupCxQe1HYZIM+J1jRGvYyzzQI9aJYv+f+/cB7uqk38+jp7xFBq46ekQFKaqDvChq 1iU6qWVBLaXAHG2hSexEGoovF3rkeIycgcJjKLcuzEoIHrl3Nyax72nEJDQLMYH40t8CUo9vnMsmY 7oSjPRX+KwNJtA1SBu3LMxi/IuNSk9c6Js3Bg4NzOnvBoHvUq12hzf8PwMW0eDKw22uLcfkMtdYAb 6kkPS5WO/5hWnHviLBxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtRON-00HBvs-0i; Thu, 19 Oct 2023 11:40:43 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROH-00HBsB-1B for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:40:41 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBeLVl049421; Thu, 19 Oct 2023 19:40:21 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:17 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 01/11] sbi: sbi_pmu: Improve sbi_pmu_init() error handling Date: Thu, 19 Oct 2023 19:37:03 +0800 Message-ID: <20231019113713.3508153-2-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBeLVl049421 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044037_847780_78F3A704 X-CRM114-Status: GOOD ( 12.28 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This patch makes the following changes: - As sbi_platform_pmu_init() returns a negative error code on failure, let sbi_pmu_init() to hang by propagating the error code. - In order to distinguish the SBI_EFAIL error returned by sbi_pmu_add_*_counter_map(), return SBI_ENOENT to indicate that fdt_pmu_setup() failed to locate "riscv,pmu" node, and generic_pmu_init() igno [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch makes the following changes: - As sbi_platform_pmu_init() returns a negative error code on failure, let sbi_pmu_init() to hang by propagating the error code. - In order to distinguish the SBI_EFAIL error returned by sbi_pmu_add_*_counter_map(), return SBI_ENOENT to indicate that fdt_pmu_setup() failed to locate "riscv,pmu" node, and generic_pmu_init() ignores such case. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Anup Patel --- Changes v1 -> v2: - New patch --- lib/sbi/sbi_pmu.c | 5 ++++- lib/utils/fdt/fdt_pmu.c | 2 +- platform/generic/platform.c | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index f4c8fc4..3cbd4ff 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -957,6 +957,7 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot) int hpm_count = sbi_fls(sbi_hart_mhpm_mask(scratch)); struct sbi_pmu_hart_state *phs; const struct sbi_platform *plat; + int rc; if (cold_boot) { hw_event_map = sbi_calloc(sizeof(*hw_event_map), @@ -972,7 +973,9 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot) plat = sbi_platform_ptr(scratch); /* Initialize hw pmu events */ - sbi_platform_pmu_init(plat); + rc = sbi_platform_pmu_init(plat); + if (rc) + return rc; /* mcycle & minstret is available always */ if (!hpm_count) diff --git a/lib/utils/fdt/fdt_pmu.c b/lib/utils/fdt/fdt_pmu.c index 83301bb..a8d7648 100644 --- a/lib/utils/fdt/fdt_pmu.c +++ b/lib/utils/fdt/fdt_pmu.c @@ -74,7 +74,7 @@ int fdt_pmu_setup(void *fdt) pmu_offset = fdt_node_offset_by_compatible(fdt, -1, "riscv,pmu"); if (pmu_offset < 0) - return SBI_EFAIL; + return SBI_ENOENT; event_ctr_map = fdt_getprop(fdt, pmu_offset, "riscv,event-to-mhpmcounters", &len); diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 66a0b77..cb9270d 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -265,7 +265,13 @@ static u32 generic_tlb_num_entries(void) static int generic_pmu_init(void) { - return fdt_pmu_setup(fdt_get_address()); + int rc; + + rc = fdt_pmu_setup(fdt_get_address()); + if (rc && rc != SBI_ENOENT) + return rc; + + return 0; } static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx, From patchwork Thu Oct 19 11:37:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Q9y0QGKp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5Q75dcpz23jP for ; Thu, 19 Oct 2023 22:41:01 +1100 (AEDT) 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=8PJITw3lm04Q7IlryvktJugPw0cZqoEDkxoYjttVTAw=; b=Q9y0QGKpGWCkhA NZvduoeXtuGUNBkyyIntdez+xSrebIyPz5LOzE+chDA9F8dcASdsmk8GrFbgJ+a5qlIeHSDayiSYY SpjVjzhsmZ++qfN7Bi4JMsmr4PfovxynZDXVfNXBzarCjbxxXp/50rN/FzJhIl1jjYz+jQYyhQpK+ xA+3nAElW/pWYh/9sZ8vNApTrSUNaVQI6n+Iaab8M4pfWm2oHVAaTsFBnNg2pq4zUPj8wzPq+2o3W 9g6uRS7m4T9rLxKYoXAjIPmpWYrLU7p5h7JzGRlF6fSEjzjM5+EgT2zxccsiHksi/bg8eDU/3th4W sDH/bvk7KVMVP9h7UHWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROL-00HBuc-00; Thu, 19 Oct 2023 11:40:41 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROH-00HBsP-1B for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:40:39 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBeQG8049437; Thu, 19 Oct 2023 19:40:26 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:22 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 02/11] sbi: sbi_pmu: Add hw_counter_filter_mode() to pmu device Date: Thu, 19 Oct 2023 19:37:04 +0800 Message-ID: <20231019113713.3508153-3-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBeQG8049437 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044037_849374_639B3591 X-CRM114-Status: GOOD ( 12.22 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add support for custom PMU extensions to set inhibit bits on custom CSRs by introducing the PMU device callback hw_counter_filter_mode(). This allows the perf tool to restrict event counting under a s [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add support for custom PMU extensions to set inhibit bits on custom CSRs by introducing the PMU device callback hw_counter_filter_mode(). This allows the perf tool to restrict event counting under a specified privileged mode by appending a modifier, e.g. perf record -e event:k to count events only happening in kernel mode. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang --- Changes v1 -> v2: - No change --- include/sbi/sbi_pmu.h | 6 ++++++ lib/sbi/sbi_pmu.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_pmu.h b/include/sbi/sbi_pmu.h index 16f6877..d63149c 100644 --- a/include/sbi/sbi_pmu.h +++ b/include/sbi/sbi_pmu.h @@ -89,6 +89,12 @@ struct sbi_pmu_device { * Custom function returning the machine-specific irq-bit. */ int (*hw_counter_irq_bit)(void); + + /** + * Custom function to inhibit counting of events while in + * specified mode. + */ + void (*hw_counter_filter_mode)(unsigned long flags, int counter_index); }; /** Get the PMU platform device */ diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 3cbd4ff..7e3723f 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -599,7 +599,10 @@ static int pmu_update_hw_mhpmevent(struct sbi_pmu_hw_event *hw_evt, int ctr_idx, pmu_dev->hw_counter_disable_irq(ctr_idx); /* Update the inhibit flags based on inhibit flags received from supervisor */ - pmu_update_inhibit_flags(flags, &mhpmevent_val); + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) + pmu_update_inhibit_flags(flags, &mhpmevent_val); + if (pmu_dev && pmu_dev->hw_counter_filter_mode) + pmu_dev->hw_counter_filter_mode(flags, ctr_idx); #if __riscv_xlen == 32 csr_write_num(CSR_MHPMEVENT3 + ctr_idx - 3, mhpmevent_val & 0xFFFFFFFF); From patchwork Thu Oct 19 11:37:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=t94Aaw+G; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5Q760sNz23kJ for ; Thu, 19 Oct 2023 22:41:03 +1100 (AEDT) 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=4u40uwAyAfIny39J+6M9ohcc8IJILAC3NrF1Oi7ylyk=; b=t94Aaw+GILLCDp diiBSnmEh77QG+MDsgKshKaQHffWiEpbd2jKGGF2Z27fT0q5MpX3J1zt7unhCMR3ctsWLWby+7Oh/ SWCIAqSKi3Lofyjbuj0cZjUSHJcRyVjbnBmseNYkrZnEiHCMHxoQCZqdnLF402k/t4v4YPZuF3BUs NtH3fkE9kwUO8hAlnTgISMl9Rf3KNBHpmVHTpWKIBDSM2BPGh2FyRStDo2L9OwCdboZZ7tUiHo9XW nJN/dMOwqMYIK2uT1OsI5/9HMc2scyL8VXURibeL1j7cr/Re4ZY96W3Vtis2VYsZQVGwl1cAZ+MYc tVfD4u84LW9BRYSW5LUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROP-00HBxD-2P; Thu, 19 Oct 2023 11:40:45 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtRON-00HBv8-0M for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:40:44 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBeVJ0049457; Thu, 19 Oct 2023 19:40:31 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:27 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 03/11] platform: include: andes45: Add PMU related CSR defines Date: Thu, 19 Oct 2023 19:37:05 +0800 Message-ID: <20231019113713.3508153-4-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBeVJ0049457 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044043_589994_3C432F6E X-CRM114-Status: UNSURE ( 7.60 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This patch adds CSR for Andes PMU extension. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang --- Changes v1 -> v2: - Rename andes_pmu() -> has_andes_pmu() --- platform/generic/incl [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch adds CSR for Andes PMU extension. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang Reviewed-by: Anup Patel --- Changes v1 -> v2: - Rename andes_pmu() -> has_andes_pmu() --- platform/generic/include/andes/andes45.h | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/platform/generic/include/andes/andes45.h b/platform/generic/include/andes/andes45.h index f570994..ce31617 100644 --- a/platform/generic/include/andes/andes45.h +++ b/platform/generic/include/andes/andes45.h @@ -12,6 +12,17 @@ #define CSR_MDCM_CFG 0xfc1 #define CSR_MMSC_CFG 0xfc2 +/* Machine Trap Related Registers */ +#define CSR_MSLIDELEG 0x7d5 + +/* Counter Related Registers */ +#define CSR_MCOUNTERWEN 0x7ce +#define CSR_MCOUNTERINTEN 0x7cf +#define CSR_MCOUNTERMASK_M 0x7d1 +#define CSR_MCOUNTERMASK_S 0x7d2 +#define CSR_MCOUNTERMASK_U 0x7d3 +#define CSR_MCOUNTEROVF 0x7d4 + #define MICM_CFG_ISZ_OFFSET 6 #define MICM_CFG_ISZ_MASK (0x7 << MICM_CFG_ISZ_OFFSET) @@ -26,4 +37,19 @@ #define MCACHE_CTL_CCTL_SUEN_OFFSET 8 #define MCACHE_CTL_CCTL_SUEN_MASK (0x1 << MCACHE_CTL_CCTL_SUEN_OFFSET) +/* Performance monitor */ +#define MMSC_CFG_PMNDS_MASK (1 << 15) +#define MIP_PMOVI (1 << 18) + +#ifndef __ASSEMBLER__ + +#define has_andes_pmu() \ +({ \ + (((csr_read(CSR_MMSC_CFG) & \ + MMSC_CFG_PMNDS_MASK) \ + && misa_extension('S')) ? true : false); \ +}) + +#endif /* __ASSEMBLER__ */ + #endif /* _RISCV_ANDES45_H */ From patchwork Thu Oct 19 11:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=rZy2vvko; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5Q7686wz23kQ for ; Thu, 19 Oct 2023 22:41:01 +1100 (AEDT) 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=P7desPYywh96K8pBPIUhBN5Cg291sSr0aykgx1sAjaw=; b=rZy2vvkonqHMgR Vf50xci7U4UqUXxG8wZ4yChY7eZ0vq6vdHZg8rVmQWnL8sNmcHyBuIoSmKM9yLbCs5bDIdsyyzPYm 5OxpPJRKvTNwlJgLl0EZS+70ZaD9vnrCpPH0OispIzP+NVjnFnH+/PhNpIGqLXS3nmS3Qpwoal6ko QPk3Pc7ZkwHk/xRBahlXG4iWPuxWDYxQ2LzUsKxwp/BELGWF6UF0aGfOru3oC2uOnnyMu2HyNzozJ 9YYb+oGLEEw82h+9nPm/c+T5rGG4aRfErw8fThwo/AafR1FH5wrMAx1F+8JZEmn5NHOfLnfUttG+G ImIt16+KjaPZ0tyBBOhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROR-00HBxo-1i; Thu, 19 Oct 2023 11:40:47 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROO-00HBvq-1p for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:40:46 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBeadL049504; Thu, 19 Oct 2023 19:40:36 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:32 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 04/11] platform: andes: Add Andes custom PMU support Date: Thu, 19 Oct 2023 19:37:06 +0800 Message-ID: <20231019113713.3508153-5-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBeadL049504 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044045_039139_D22ECD45 X-CRM114-Status: GOOD ( 18.32 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Before the ratification of Sscofpmf, the Andes PMU extension was designed to support the sampling and filtering with hardware performance counters, it works with the current SBI PMU extension and Linu [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Before the ratification of Sscofpmf, the Andes PMU extension was designed to support the sampling and filtering with hardware performance counters, it works with the current SBI PMU extension and Linux SBI PMU driver. This patch implements the PMU device callbacks that update the corresponding bits on custom CSRs. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang Reviewed-by: Anup Patel --- Changes v1 -> v2: - Fix mode filtering in andes_hw_counter_filter_mode() - Return early if pmu is not supported in andes_pmu_init() (suggested by Prabhakar) - Don't grant write permissions via CSR_MCOUNTERWEN as not needed --- platform/generic/andes/Kconfig | 4 ++ platform/generic/andes/andes_pmu.c | 81 ++++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes_pmu.h | 8 +++ 4 files changed, 94 insertions(+) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.h diff --git a/platform/generic/andes/Kconfig b/platform/generic/andes/Kconfig index a91fb9c..555e4fe 100644 --- a/platform/generic/andes/Kconfig +++ b/platform/generic/andes/Kconfig @@ -7,3 +7,7 @@ config ANDES45_PMA config ANDES_SBI bool "Andes SBI support" default n + +config ANDES_PMU + bool "Andes custom PMU extension support" + default n diff --git a/platform/generic/andes/andes_pmu.c b/platform/generic/andes/andes_pmu.c new file mode 100644 index 0000000..0f6ecc0 --- /dev/null +++ b/platform/generic/andes/andes_pmu.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (C) 2023 Andes Technology Corporation + */ +#include +#include +#include +#include +#include +#include +#include +#include + +static void andes_hw_counter_enable_irq(uint32_t ctr_idx) +{ + unsigned long mip_val; + + if (ctr_idx >= SBI_PMU_HW_CTR_MAX) + return; + + mip_val = csr_read(CSR_MIP); + if (!(mip_val & MIP_PMOVI)) + csr_clear(CSR_MCOUNTEROVF, BIT(ctr_idx)); + + csr_set(CSR_MCOUNTERINTEN, BIT(ctr_idx)); +} + +static void andes_hw_counter_disable_irq(uint32_t ctr_idx) +{ + csr_clear(CSR_MCOUNTERINTEN, BIT(ctr_idx)); +} + +static void andes_hw_counter_filter_mode(unsigned long flags, int ctr_idx) +{ + if (flags & SBI_PMU_CFG_FLAG_SET_UINH) + csr_set(CSR_MCOUNTERMASK_U, BIT(ctr_idx)); + else + csr_clear(CSR_MCOUNTERMASK_U, BIT(ctr_idx)); + + if (flags & SBI_PMU_CFG_FLAG_SET_SINH) + csr_set(CSR_MCOUNTERMASK_S, BIT(ctr_idx)); + else + csr_clear(CSR_MCOUNTERMASK_S, BIT(ctr_idx)); +} + +static struct sbi_pmu_device andes_pmu = { + .name = "andes_pmu", + .hw_counter_enable_irq = andes_hw_counter_enable_irq, + .hw_counter_disable_irq = andes_hw_counter_disable_irq, + /* + * We set delegation of supervisor local interrupts via + * 18th bit on mslideleg instead of mideleg, so leave + * hw_counter_irq_bit() callback unimplemented. + */ + .hw_counter_irq_bit = NULL, + .hw_counter_filter_mode = andes_hw_counter_filter_mode +}; + +int andes_pmu_init(void) +{ + if (!has_andes_pmu()) + return SBI_ENOTSUPP; + + /* + * It is not reasonable for an Andes CPU to support + * both Andes PMU and standard Sscofpmf, as they + * serve the same purpose. + */ + if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(), + SBI_HART_EXT_SSCOFPMF)) + sbi_hart_hang(); + + /* Inhibit HPM counter in M-mode */ + csr_write(CSR_MCOUNTERMASK_M, 0xfffffffd); + /* Delegate S-mode local interrupt to S-mode */ + csr_write(CSR_MSLIDELEG, MIP_PMOVI); + + sbi_pmu_set_device(&andes_pmu); + + return 0; +} diff --git a/platform/generic/andes/objects.mk b/platform/generic/andes/objects.mk index e8f86ea..6a8c66c 100644 --- a/platform/generic/andes/objects.mk +++ b/platform/generic/andes/objects.mk @@ -7,3 +7,4 @@ platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o andes/sleep.o platform-objs-$(CONFIG_ANDES45_PMA) += andes/andes45-pma.o platform-objs-$(CONFIG_ANDES_SBI) += andes/andes_sbi.o +platform-objs-$(CONFIG_ANDES_PMU) += andes/andes_pmu.o diff --git a/platform/generic/include/andes/andes_pmu.h b/platform/generic/include/andes/andes_pmu.h new file mode 100644 index 0000000..70b3a12 --- /dev/null +++ b/platform/generic/include/andes/andes_pmu.h @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: BSD-2-Clause + +#ifndef _RISCV_ANDES_PMU_H +#define _RISCV_ANDES_PMU_H + +int andes_pmu_init(void); + +#endif /* _RISCV_ANDES_PMU_H */ From patchwork Thu Oct 19 11:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=jl+8n5yS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5QJ5lKrz20Zj for ; Thu, 19 Oct 2023 22:41:12 +1100 (AEDT) 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=ezj9md04CZ2hZwXUjbzQMq9SVLU0JHpGJ6eMiaPpeX0=; b=jl+8n5ySE6LuSI oczCSvC5MjbhgaNYhQXlgEen/knxRKfkc85s00jhiIAN3JQpV51KSm8D+uh7f+jzRpd5+FEzkFgbE Fp/F/lv5zdMX+tZfE6+4ZPSASxRZq1HM7oumtrI9/tpC/vlXsZ0od+skernF6uv1qxv8KcvRvtAt1 cd8Vw/9SVBvs5cFPyV8UuMnzUtIG47Juz63cmuFZVybLSd8L3NP/COVCk77KMKPZ7VZ1LZ6npZ3xX kFSPMnwjbePkxQccIkcHDEFUrTTL3XIv5VkblVSbNWscGHOw656wk/yVbJ2HcZJ9q27WlgRsiSAm3 QO6J0LSXuXh/nnEhLcAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROd-00HC1p-0w; Thu, 19 Oct 2023 11:40:59 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROa-00HBzr-14 for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:40:58 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBefq9049523; Thu, 19 Oct 2023 19:40:41 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:37 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 05/11] platform: andes: Enable Andes PMU for AE350 Date: Thu, 19 Oct 2023 19:37:07 +0800 Message-ID: <20231019113713.3508153-6-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBefq9049523 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044056_803606_0BE395F1 X-CRM114-Status: GOOD ( 10.11 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Enable Andes PMU extension support for AE350 platforms. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang --- Changes v1 -> v2: - Implement ae350_extensions_init() --- platform/generic/Kconfig [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Enable Andes PMU extension support for AE350 platforms. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang --- Changes v1 -> v2: - Implement ae350_extensions_init() --- platform/generic/Kconfig | 1 + platform/generic/andes/ae350.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/platform/generic/Kconfig b/platform/generic/Kconfig index e7bd94e..9b2f9c7 100644 --- a/platform/generic/Kconfig +++ b/platform/generic/Kconfig @@ -31,6 +31,7 @@ config PLATFORM_ALLWINNER_D1 config PLATFORM_ANDES_AE350 bool "Andes AE350 support" select SYS_ATCSMU + select ANDES_PMU default n config PLATFORM_RENESAS_RZFIVE diff --git a/platform/generic/andes/ae350.c b/platform/generic/andes/ae350.c index 80eca05..c3f280d 100644 --- a/platform/generic/andes/ae350.c +++ b/platform/generic/andes/ae350.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -110,6 +111,17 @@ static int ae350_final_init(bool cold_boot, const struct fdt_match *match) return 0; } +static int ae350_extensions_init(const struct fdt_match *match, + struct sbi_hart_features *hfeatures) +{ + int rc; + rc = andes_pmu_init(); + if (rc && rc != SBI_ENOTSUPP) + return rc; + + return 0; +} + static const struct fdt_match andes_ae350_match[] = { { .compatible = "andestech,ae350" }, { }, @@ -118,4 +130,5 @@ static const struct fdt_match andes_ae350_match[] = { const struct platform_override andes_ae350 = { .match_table = andes_ae350_match, .final_init = ae350_final_init, + .extensions_init = ae350_extensions_init, }; From patchwork Thu Oct 19 11:37:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=AVCeQSCg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5QH0lzWz20Zj for ; Thu, 19 Oct 2023 22:41:11 +1100 (AEDT) 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=r5XT970p3BeDO3wNVrjHDK9nOPQOk0bRB3K3Gfsd+fw=; b=AVCeQSCg58jH96 kRHkI0OhTujew/P+Gtfx6nlAYk/PVT9WcIPAvZ73jACls/Cdne0eNbUFdotUlbTXeHPsOMYHF2VIc XVuUhK1KraTQCdXLmE9Pu4SbP0xXPn/gH2iQlfHi43mGhYiEb7EbVhy1ko0tZ7JGZLgAWFDZ9kjX8 B9SR1VKGeK0Lp5SJupt5c1IoBpEJPpdxPqpKMzCNWG1hJZU4QsymOvR5XC2I/VNLisO7SwrBPf9p6 K/JcisLmWGqZTijWq+zaeCzwQlxrjcmhZR8s0VUGjyomqSCpKKEgltfHg0wGUvFn4H+Wg70gloMy6 nbR7DK0ZiJwsqhsImr4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROe-00HC2i-2T; Thu, 19 Oct 2023 11:41:00 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROb-00HC0U-2R for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:40:59 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBekTS049543; Thu, 19 Oct 2023 19:40:46 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:42 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 06/11] platform: rzfive: Enable Andes PMU for RZ/Five Date: Thu, 19 Oct 2023 19:37:08 +0800 Message-ID: <20231019113713.3508153-7-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBekTS049543 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044058_236874_3E869000 X-CRM114-Status: GOOD ( 12.79 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Enable Andes PMU extension support for RZ/Five. This patch also staticize renesas_rzfive_early_init() as it is not used outside of this unit. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang --- Changes v1 -> v2: - Implement renesas_rzfive_extensions_init() - staticize renesas_ [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Enable Andes PMU extension support for RZ/Five. This patch also staticize renesas_rzfive_early_init() as it is not used outside of this unit. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Leo Yu-Chi Liang --- Changes v1 -> v2: - Implement renesas_rzfive_extensions_init() - staticize renesas_rzfive_early_init() --- platform/generic/Kconfig | 1 + platform/generic/renesas/rzfive/rzfive.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/platform/generic/Kconfig b/platform/generic/Kconfig index 9b2f9c7..d6dafef 100644 --- a/platform/generic/Kconfig +++ b/platform/generic/Kconfig @@ -38,6 +38,7 @@ config PLATFORM_RENESAS_RZFIVE bool "Renesas RZ/Five support" select ANDES45_PMA select ANDES_SBI + select ANDES_PMU default n config PLATFORM_SIFIVE_FU540 diff --git a/platform/generic/renesas/rzfive/rzfive.c b/platform/generic/renesas/rzfive/rzfive.c index a69797b..2f772c8 100644 --- a/platform/generic/renesas/rzfive/rzfive.c +++ b/platform/generic/renesas/rzfive/rzfive.c @@ -5,9 +5,11 @@ */ #include +#include #include #include #include +#include #include static const struct andes45_pma_region renesas_rzfive_pma_regions[] = { @@ -29,7 +31,7 @@ static int renesas_rzfive_final_init(bool cold_boot, const struct fdt_match *mat array_size(renesas_rzfive_pma_regions)); } -int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match) +static int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match) { /* * Renesas RZ/Five RISC-V SoC has Instruction local memory and @@ -47,6 +49,17 @@ int renesas_rzfive_early_init(bool cold_boot, const struct fdt_match *match) SBI_DOMAIN_MEMREGION_M_RWX); } +static int renesas_rzfive_extensions_init(const struct fdt_match *match, + struct sbi_hart_features *hfeatures) +{ + int rc; + rc = andes_pmu_init(); + if (rc && rc != SBI_ENOTSUPP) + return rc; + + return 0; +} + static const struct fdt_match renesas_rzfive_match[] = { { .compatible = "renesas,r9a07g043f01" }, { /* sentinel */ } @@ -57,4 +70,5 @@ const struct platform_override renesas_rzfive = { .early_init = renesas_rzfive_early_init, .final_init = renesas_rzfive_final_init, .vendor_ext_provider = andes_sbi_vendor_ext_provider, + .extensions_init = renesas_rzfive_extensions_init, }; From patchwork Thu Oct 19 11:37:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851600 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=d5JOis5W; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5QR2YFMz20Zj for ; Thu, 19 Oct 2023 22:41:19 +1100 (AEDT) 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=ZTtgiqBIXmfdQNF1DBdgl3/zqL3yLG5KT4hcWTIXL84=; b=d5JOis5W0VQmRP z6jyXK48Mx9D2YbEV++cZTDItgGVEfRXHmFCNsrXjGDtf5Uw+fpJtL75uG+Hmugj299lgbw6weNJ5 Rjut9Fzlvl+gYDQh1pbvMLKj0f2EoKAzuTkLtl5iikDmsmccPUrAAxVfv9QkJcjv9Zz9yiFETZjtc VB/cF2q7AOYcbcFSOgL2LvmTFZhRAMw1Uehcs0tkC3PrNeOTCgtf6W8ttmgiwlwlIQY5AmNBe/9BL 6p6E2J0mmbOvlPvmFxAIbUDQ8UGiGNdK3/NcyKvAiPGkZy7gz29OBnzvbc1hBRwqaRm1hXuVXQ/dw Cw0XBg4pnaq+U0yAjmPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROn-00HC9p-0c; Thu, 19 Oct 2023 11:41:09 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROj-00HC5Q-0W for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:41:07 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBepim049631; Thu, 19 Oct 2023 19:40:51 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:47 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 07/11] lib: utils: fdt_fixup: Add fdt_add_pmu_mappings() helper function Date: Thu, 19 Oct 2023 19:37:09 +0800 Message-ID: <20231019113713.3508153-8-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBepim049631 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044105_640240_9A0264CA X-CRM114-Status: GOOD ( 17.47 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add fdt_add_pmu_mappings() that creates entries of riscv,*event-to-mhpm* property from arrays right before fdt_pmu_setup() populating the mapping tables (i.e. hw_event_map[] and fdt_pmu_evt_select[]). Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add fdt_add_pmu_mappings() that creates entries of riscv,*event-to-mhpm* property from arrays right before fdt_pmu_setup() populating the mapping tables (i.e. hw_event_map[] and fdt_pmu_evt_select[]). The helper function will skip the creation of those properties if a "/pmu" node with "riscv,pmu" compatible string is provided. Signed-off-by: Yu Chien Peter Lin --- Changes v1 -> v2: - New patch --- include/sbi_utils/fdt/fdt_fixup.h | 48 ++++++++++ lib/utils/fdt/fdt_fixup.c | 95 ++++++++++++++++++++ platform/generic/include/platform_override.h | 1 + platform/generic/platform.c | 10 ++- 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/include/sbi_utils/fdt/fdt_fixup.h b/include/sbi_utils/fdt/fdt_fixup.h index ecd55a7..9b72df8 100644 --- a/include/sbi_utils/fdt/fdt_fixup.h +++ b/include/sbi_utils/fdt/fdt_fixup.h @@ -19,6 +19,54 @@ struct sbi_cpu_idle_state { uint32_t wakeup_latency_us; }; +struct sbi_pmu_event_select_map { + /** + * The description of an entry in + * riscv,event-to-mhpmevent property + */ + uint32_t eidx; + uint64_t select; +}; + +struct sbi_pmu_event_counter_map { + /** + * The description of an entry in + * riscv,event-to-mhpmcounters property + */ + uint32_t eidx_start; + uint32_t eidx_end; + uint32_t ctr_map; +}; + +struct sbi_pmu_raw_event_counter_map { + /** + * The description of an entry in + * riscv,raw-event-to-mhpmcounters property + */ + uint64_t select; + uint64_t select_mask; + uint32_t ctr_map; +}; + +/** + * Add PMU properties in the DT + * + * Add information about event to selector/counter mappings to the + * devicetree. + * + * @param fdt: device tree blob + * @param selects: array of event index to selector value mapping + * descriptions, ending with empty element + * @param counters: array of event indexes to counters mapping + * descriptions, ending with empty element + * @param rcounters: array of raw events to counters mapping + * descriptions, ending with empty element + * @return zero on success and -ve on failure + */ +int fdt_add_pmu_mappings(void *fdt, const struct sbi_pmu_event_select_map *selects, + const struct sbi_pmu_event_counter_map *counters, + const struct sbi_pmu_raw_event_counter_map *rcounters); + /** * Add CPU idle states to cpu nodes in the DT * diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index e213ded..67e2e2e 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -20,6 +20,101 @@ #include #include +int fdt_add_pmu_mappings(void *fdt, const struct sbi_pmu_event_select_map *selects, + const struct sbi_pmu_event_counter_map *counters, + const struct sbi_pmu_raw_event_counter_map *rcounters) +{ + int i, err, pmu_noff, root_noff; + const char *comp; + fdt32_t evt_to_mhpmevent[3]; + fdt32_t evt_to_mhpmcounters[3]; + fdt32_t raw_evt_to_mhpmcounters[5]; + + /* Try to locate pmu node */ + pmu_noff = fdt_path_offset(fdt, "/pmu"); + + if (pmu_noff > 0) { + /* + * If compatible string is "riscv,pmu", + * we assume a valid pmu node has been + * provided. + */ + comp = fdt_getprop(fdt, pmu_noff, "compatible", NULL); + if (comp && !strcmp(comp, "riscv,pmu")) + return 0; + else + return -FDT_ERR_BADVALUE; + } + + if (pmu_noff < 0 && pmu_noff != -FDT_ERR_NOTFOUND) + return pmu_noff; + + /* + * If "riscv,event-to-mhpmevent" is present, "riscv,event-to-mhpmcounters" + * must be provided as well, but not vice versa (OpenSBI will direct mapping + * event_idx as selector value). + */ + if (selects && !counters) { + sbi_printf("%s: ERR: riscv,event-to-mhpmcounters is mandatory if" + " riscv,event-to-mhpmevent is present.", __func__); + return SBI_EINVAL; + } + + /* + * Create pmu node based on given @selects, @counters + * and @rcounters. + */ + root_noff = fdt_path_offset(fdt, "/"); + pmu_noff = fdt_add_subnode(fdt, root_noff, "pmu"); + if (pmu_noff < 0) + return pmu_noff; + + err = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + 1024); + if (err < 0) + return err; + + err = fdt_setprop_string(fdt, pmu_noff, "compatible", "riscv,pmu"); + if (err) + return err; + + /* Add riscv,event-to-mhpmevent */ + for (i = 0; selects && selects[i].eidx; i++) { + evt_to_mhpmevent[0] = cpu_to_fdt32(selects[i].eidx); + evt_to_mhpmevent[1] = cpu_to_fdt32(selects[i].select >> 32); + evt_to_mhpmevent[2] = cpu_to_fdt32(selects[i].select & ~0UL); + err = fdt_appendprop(fdt, pmu_noff, "riscv,event-to-mhpmevent", + evt_to_mhpmevent, 3 * sizeof(fdt32_t)); + if (err) + return err; + } + + /* Add riscv,event-to-mhpmcounters */ + for (i = 0; counters && counters[i].eidx_start; i++) { + evt_to_mhpmcounters[0] = cpu_to_fdt32(counters[i].eidx_start); + evt_to_mhpmcounters[1] = cpu_to_fdt32(counters[i].eidx_end); + evt_to_mhpmcounters[2] = cpu_to_fdt32(counters[i].ctr_map); + err = fdt_appendprop(fdt, pmu_noff, "riscv,event-to-mhpmcounters", + evt_to_mhpmcounters, 3 * sizeof(fdt32_t)); + if (err) + return err; + } + + /* Add riscv,raw-event-to-mhpmcounters */ + for (i = 0; rcounters && rcounters[i].select; i++) { + raw_evt_to_mhpmcounters[0] = cpu_to_fdt32(rcounters[i].select >> 32); + raw_evt_to_mhpmcounters[1] = cpu_to_fdt32(rcounters[i].select & ~0UL); + raw_evt_to_mhpmcounters[2] = cpu_to_fdt32(rcounters[i].select_mask >> 32); + raw_evt_to_mhpmcounters[3] = cpu_to_fdt32(rcounters[i].select_mask & ~0UL); + raw_evt_to_mhpmcounters[4] = cpu_to_fdt32(rcounters[i].ctr_map); + err = fdt_appendprop(fdt, pmu_noff, "riscv,raw-event-to-mhpmcounters", + raw_evt_to_mhpmcounters, 5 * sizeof(fdt32_t)); + if (err) + return err; + } + + return 0; +} + int fdt_add_cpu_idle_states(void *fdt, const struct sbi_cpu_idle_state *state) { int cpu_node, cpus_node, err, idle_states_node; diff --git a/platform/generic/include/platform_override.h b/platform/generic/include/platform_override.h index bf4b112..bd34d2a 100644 --- a/platform/generic/include/platform_override.h +++ b/platform/generic/include/platform_override.h @@ -19,6 +19,7 @@ struct platform_override { u64 (*features)(const struct fdt_match *match); u64 (*tlbr_flush_limit)(const struct fdt_match *match); u32 (*tlb_num_entries)(const struct fdt_match *match); + int (*fdt_add_pmu_mappings)(void *fdt, const struct fdt_match *match); bool (*cold_boot_allowed)(u32 hartid, const struct fdt_match *match); int (*early_init)(bool cold_boot, const struct fdt_match *match); int (*final_init)(bool cold_boot, const struct fdt_match *match); diff --git a/platform/generic/platform.c b/platform/generic/platform.c index cb9270d..a48a8b7 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -265,9 +265,17 @@ static u32 generic_tlb_num_entries(void) static int generic_pmu_init(void) { + void *fdt = fdt_get_address(); int rc; - rc = fdt_pmu_setup(fdt_get_address()); + if (generic_plat && generic_plat->fdt_add_pmu_mappings) { + rc = generic_plat->fdt_add_pmu_mappings(fdt, + generic_plat_match); + if (rc) + return rc; + } + + rc = fdt_pmu_setup(fdt); if (rc && rc != SBI_ENOENT) return rc; From patchwork Thu Oct 19 11:37:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=gL3ohtwx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5Qb5sMXz20Zj for ; Thu, 19 Oct 2023 22:41:27 +1100 (AEDT) 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=z/nZy3ws4kzRIseIk885qTC9EyfuoYNDPRnPcIMTYaw=; b=gL3ohtwxxxBjBN wMjTq0aGyXyoo2mlNULFcDlJTr48Ms1RS1uRqrvlVKxeFGJVQ/fuOkQ/5DQemRV78iCHEJpAziday 0i53GzN+iazpyzH/v9vGRELhQdx2LG42oEtZM7yeNA6Ilv3KJXUXVeEz6flyXsLRf3QJmtxVlc5Ya 94lnuIQKkE3Bca9R2nfYYcCqty0zeOUegjIHemckroitvEUhekEsmrGfTaMgfJ3BrC+UdWqvzTWkA dQMfKTQsKiWizXQjOFptfm5nR4tUeSZ7ymBGgqBJwDZ5KJflyclYG+XBq/oX1qXKqyqqYmWI86RpZ 1OF3ny8P/Q0EeAFJDvig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROv-00HCEJ-03; Thu, 19 Oct 2023 11:41:17 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROs-00HCCB-1Z for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:41:16 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBeujl049673; Thu, 19 Oct 2023 19:40:56 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:53 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 08/11] lib: utils: fdt_fixup: Allow preserving PMU properties Date: Thu, 19 Oct 2023 19:37:10 +0800 Message-ID: <20231019113713.3508153-9-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBeujl049673 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044114_957913_B50E466D X-CRM114-Status: GOOD ( 10.33 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a scratch option to control PMU fixup, so the next stage software can dump the PMU node including event mapping information for debugging purposes. Signed-off-by: Yu Chien Peter Lin --- Changes v1 -> v2: - New patch --- include/sbi/sbi_scratch.h | 2 ++ lib/utils/fdt/fdt_fixup.c | 6 +++++- 2 files changed, 7 insertions(+), [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add a scratch option to control PMU fixup, so the next stage software can dump the PMU node including event mapping information for debugging purposes. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Anup Patel --- Changes v1 -> v2: - New patch --- include/sbi/sbi_scratch.h | 2 ++ lib/utils/fdt/fdt_fixup.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index e6a33ba..7914dfb 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -151,6 +151,8 @@ enum sbi_scratch_options { SBI_SCRATCH_NO_BOOT_PRINTS = (1 << 0), /** Enable runtime debug prints */ SBI_SCRATCH_DEBUG_PRINTS = (1 << 1), + /** Preserve PMU node properties */ + SBI_SCRATCH_PRESERVE_PMU_PROP = (1 << 2), }; /** Get pointer to sbi_scratch for current HART */ diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index 67e2e2e..b0c885f 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -482,6 +482,8 @@ int fdt_reserved_memory_fixup(void *fdt) void fdt_fixups(void *fdt) { + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + fdt_aplic_fixup(fdt); fdt_imsic_fixup(fdt); @@ -489,5 +491,7 @@ void fdt_fixups(void *fdt) fdt_plic_fixup(fdt); fdt_reserved_memory_fixup(fdt); - fdt_pmu_fixup(fdt); + + if (!(scratch->options & SBI_SCRATCH_PRESERVE_PMU_PROP)) + fdt_pmu_fixup(fdt); } From patchwork Thu Oct 19 11:37:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851602 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=QzH8XCJy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5Qf49wSz20Zj for ; Thu, 19 Oct 2023 22:41:30 +1100 (AEDT) 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=G6/ZhtmqRljzgMlYB03Pa9xHkGhxUflXHiOLweSqACw=; b=QzH8XCJy9mFABJ MIhLhu1mMY/Pi8x7BzFjpJR+bLUAyphEybyZFYz6q4YRFkIMpv7TQPY0aAF7VvLoy4jpE/lz4QXjp 4JXLmS5+Z/JoomZ/yjOezTfRFGYi+CMsDovYMJ6ZoLP2VpofKSVbe2xSIxxVcRwXGPJLSnHA2y5HJ Gp79kemX3Zie0GfNSjgf6c4xhmFAvXqAORgiow3K7Cxe/ZqXmp9Y6E2SqFHCutWajUjFzuhL80fVX MrsEFt4XO2V1dfOmUfYH527KDtEBMcaUcNRGoF21hktvFHmqSoCyRSkU8pt1ydk7HXOODRoBi4egV SDV5YkYFSe3tieFmpxng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtROw-00HCFX-2g; Thu, 19 Oct 2023 11:41:18 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtROt-00HCCj-2I for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:41:17 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBf1dY049709; Thu, 19 Oct 2023 19:41:01 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:40:57 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 09/11] platform: andes: Factor out is_andes() helper Date: Thu, 19 Oct 2023 19:37:11 +0800 Message-ID: <20231019113713.3508153-10-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBf1dY049709 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044116_193393_4B82DB39 X-CRM114-Status: GOOD ( 11.63 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: We will need is_andes(45) in the following patch, so factor out the code that parses marchid to make it reusable for checking any Andes CPU variants. Also improves the comment in ae350_hart_start(). Signed-off-by: Yu Chien Peter Lin --- Changes v1 -> v2: - New patch --- platform/generic/andes/ae350.c | 16 +++++++--------- platform/generic/include/andes/andes45.h | 6 +++++ [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We will need is_andes(45) in the following patch, so factor out the code that parses marchid to make it reusable for checking any Andes CPU variants. Also improves the comment in ae350_hart_start(). Signed-off-by: Yu Chien Peter Lin Reviewed-by: Anup Patel --- Changes v1 -> v2: - New patch --- platform/generic/andes/ae350.c | 16 +++++++--------- platform/generic/include/andes/andes45.h | 6 ++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/platform/generic/andes/ae350.c b/platform/generic/andes/ae350.c index c3f280d..80cd294 100644 --- a/platform/generic/andes/ae350.c +++ b/platform/generic/andes/ae350.c @@ -24,16 +24,14 @@ static struct smu_data smu = { 0 }; extern void __ae350_enable_coherency_warmboot(void); extern void __ae350_disable_coherency(void); -static __always_inline bool is_andes25(void) -{ - ulong marchid = csr_read(CSR_MARCHID); - return !!(EXTRACT_FIELD(marchid, CSR_MARCHID_MICROID) == 0xa25); -} - static int ae350_hart_start(u32 hartid, ulong saddr) { - /* Don't send wakeup command at boot-time */ - if (!sbi_init_count(hartid) || (is_andes25() && hartid == 0)) + /* + * Don't send wakeup command + * 1) at boot-time + * 2) the target hart is non-sleepable 25-series hart0 + */ + if (!sbi_init_count(hartid) || (is_andes(25) && hartid == 0)) return sbi_ipi_raw_send(sbi_hartid_to_hartindex(hartid)); /* Write wakeup command to the sleep hart */ @@ -52,7 +50,7 @@ static int ae350_hart_stop(void) * L2-cache, instead of turning it off, it should fall * through and jump to warmboot_addr. */ - if (is_andes25() && hartid == 0) + if (is_andes(25) && hartid == 0) return SBI_ENOTSUPP; if (!smu_support_sleep_mode(&smu, DEEPSLEEP_MODE, hartid)) diff --git a/platform/generic/include/andes/andes45.h b/platform/generic/include/andes/andes45.h index ce31617..01f63d4 100644 --- a/platform/generic/include/andes/andes45.h +++ b/platform/generic/include/andes/andes45.h @@ -43,6 +43,12 @@ #ifndef __ASSEMBLER__ +#define is_andes(series) \ +({ \ + char value = csr_read(CSR_MARCHID) & 0xff; \ + (series) == (value >> 4) * 10 + (value & 0x0f); \ +}) + #define has_andes_pmu() \ ({ \ (((csr_read(CSR_MMSC_CFG) & \ From patchwork Thu Oct 19 11:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851603 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YKcqJU07; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5Qz203Pz20Zj for ; Thu, 19 Oct 2023 22:41:47 +1100 (AEDT) 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=3J/LKAERhaWARBsJkODim+3RTU5w2XsgXON2sT95MqE=; b=YKcqJU073eU5Yr Sk1YnkHpm1aLcRuxDKhTMeJGclpjRNr4V+BkBZ5+TkUNViOuzDrUFFILp3y4V3H6mPrgKhOsVwfCZ Mkgoe8atIcCdeF4PpxY7RGTwirR/ib/PaF7UGVAFmVplORuoS21aumEBhX2BoaRxs8BVBql/vWteR dgR7ns458I2UipF+yirVFe593lIVj6Ai7+169ElIepWur2KJAlE1OmEX7hy41hT9Sb3n4wkjHIyJk l6PlXGdnHIxQ63f2uZYX4eJkWQ1tOBfRXB5DZ/DSyrRTxFmcmDyaPYHUDeZ75HXNM0sZrPZtoHK7T Pw/9Aobng+bd86zHneCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtRPD-00HCOj-2M; Thu, 19 Oct 2023 11:41:35 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtRP9-00HCLm-2b for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:41:34 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBf6PE049883; Thu, 19 Oct 2023 19:41:06 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:41:02 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 10/11] platform: andes: Implement andes_fdt_add_pmu_mappings platform override Date: Thu, 19 Oct 2023 19:37:12 +0800 Message-ID: <20231019113713.3508153-11-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBf6PE049883 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044132_502549_35891061 X-CRM114-Status: GOOD ( 19.86 ) X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Implement the andes_fdt_add_pmu_mappings() callback, which creates PMU node properties that will later be populated with mapping tables. Currently we only support 45-series event mappings. Signed-off-by: Yu Chien Peter Lin --- Changes v1 -> v2: - New patch --- include/sbi/sbi_ecall_interface.h | 5 + platform/generic/Kconfig | 2 + platform/generic/andes/Kconfig | [...] Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Implement the andes_fdt_add_pmu_mappings() callback, which creates PMU node properties that will later be populated with mapping tables. Currently we only support 45-series event mappings. Signed-off-by: Yu Chien Peter Lin --- Changes v1 -> v2: - New patch --- include/sbi/sbi_ecall_interface.h | 5 + platform/generic/Kconfig | 2 + platform/generic/andes/Kconfig | 7 + platform/generic/andes/ae350.c | 2 + platform/generic/andes/andes_hpm.c | 381 +++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes_hpm.h | 83 +++++ platform/generic/renesas/rzfive/rzfive.c | 2 + 8 files changed, 483 insertions(+) create mode 100644 platform/generic/andes/andes_hpm.c create mode 100644 platform/generic/include/andes/andes_hpm.h diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index 1fe469e..89187e7 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -155,6 +155,11 @@ enum sbi_pmu_hw_cache_op_result_id { SBI_PMU_HW_CACHE_RESULT_MAX, }; +#define SBI_PMU_HW_CACHE_EVENT_IDX(id, op, res) \ + (SBI_PMU_EVENT_TYPE_HW_CACHE << SBI_PMU_EVENT_IDX_TYPE_OFFSET | \ + SBI_PMU_HW_CACHE_##id << 3 | SBI_PMU_HW_CACHE_OP_##op << 1 | \ + SBI_PMU_HW_CACHE_RESULT_##res) + /** * Special "firmware" events provided by the OpenSBI, even if the hardware * does not support performance events. These events are encoded as a raw diff --git a/platform/generic/Kconfig b/platform/generic/Kconfig index d6dafef..fbcd870 100644 --- a/platform/generic/Kconfig +++ b/platform/generic/Kconfig @@ -31,6 +31,7 @@ config PLATFORM_ALLWINNER_D1 config PLATFORM_ANDES_AE350 bool "Andes AE350 support" select SYS_ATCSMU + select ANDES_HPM select ANDES_PMU default n @@ -38,6 +39,7 @@ config PLATFORM_RENESAS_RZFIVE bool "Renesas RZ/Five support" select ANDES45_PMA select ANDES_SBI + select ANDES_HPM select ANDES_PMU default n diff --git a/platform/generic/andes/Kconfig b/platform/generic/andes/Kconfig index 555e4fe..8af2704 100644 --- a/platform/generic/andes/Kconfig +++ b/platform/generic/andes/Kconfig @@ -8,6 +8,13 @@ config ANDES_SBI bool "Andes SBI support" default n +config ANDES_HPM + bool "Andes HPM support" + default n + help + This provides Andes platform override for creating + event to counter mappings in pmu node. + config ANDES_PMU bool "Andes custom PMU extension support" default n diff --git a/platform/generic/andes/ae350.c b/platform/generic/andes/ae350.c index 80cd294..28c187e 100644 --- a/platform/generic/andes/ae350.c +++ b/platform/generic/andes/ae350.c @@ -19,6 +19,7 @@ #include #include #include +#include static struct smu_data smu = { 0 }; extern void __ae350_enable_coherency_warmboot(void); @@ -128,5 +129,6 @@ static const struct fdt_match andes_ae350_match[] = { const struct platform_override andes_ae350 = { .match_table = andes_ae350_match, .final_init = ae350_final_init, + .fdt_add_pmu_mappings = andes_fdt_add_pmu_mappings, .extensions_init = ae350_extensions_init, }; diff --git a/platform/generic/andes/andes_hpm.c b/platform/generic/andes/andes_hpm.c new file mode 100644 index 0000000..f9e6d2e --- /dev/null +++ b/platform/generic/andes/andes_hpm.c @@ -0,0 +1,381 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Andes Technology Corporation + */ + +#include +#include +#include +#include +#include + +static const struct sbi_pmu_event_select_map andes45_hw_evt_selects[] = { + /* Hardware general events (Type #0) */ + { + /* perf: cycles (eidx: 0x1) */ + .eidx = SBI_PMU_HW_CPU_CYCLES, + .select = ANDES_CYCLES + }, + { + /* perf: instructions (eidx: 0x2) */ + .eidx = SBI_PMU_HW_INSTRUCTIONS, + .select = ANDES_INSTRET + }, + { + /* perf: cache-references (eidx: 0x3) */ + .eidx = SBI_PMU_HW_CACHE_REFERENCES, + .select = ANDES_DCACHE_ACCESS + }, + { + /* perf: cache-misses (eidx: 0x4) */ + .eidx = SBI_PMU_HW_CACHE_MISSES, + .select = ANDES_DCACHE_MISS + }, + { + /* perf: branches (eidx: 0x5) */ + .eidx = SBI_PMU_HW_BRANCH_INSTRUCTIONS, + .select = ANDES_CONDITION_BR, + }, + { + /* perf: branch-misses (eidx: 0x6) */ + .eidx = SBI_PMU_HW_BRANCH_MISSES, + .select = ANDES_MISPREDICT_CONDITION_BR, + }, + /* Hardware cache events (Type #1) */ + { + /* perf: L1-dcache-loads (eidx: 0x10000) */ + .eidx = SBI_PMU_HW_CACHE_EVENT_IDX(L1D, READ, ACCESS), + .select = ANDES_DCACHE_LOAD_ACCESS + }, + { + /* perf: L1-dcache-loads-misses (eidx: 0x10001) */ + .eidx = SBI_PMU_HW_CACHE_EVENT_IDX(L1D, READ, MISS), + .select = ANDES_DCACHE_LOAD_MISS + }, + { + /* perf: L1-dcache-stores (eidx: 0x10002) */ + .eidx = SBI_PMU_HW_CACHE_EVENT_IDX(L1D, WRITE, ACCESS), + .select = ANDES_DCACHE_STORE_ACCESS + }, + { + /* perf: L1-dcache-store-misses (eidx: 0x10003) */ + .eidx = SBI_PMU_HW_CACHE_EVENT_IDX(L1D, WRITE, MISS), + .select = ANDES_DCACHE_STORE_MISS + }, + { + /* perf: L1-icache-load (eidx: 0x10008) */ + .eidx = SBI_PMU_HW_CACHE_EVENT_IDX(L1I, READ, ACCESS), + .select = ANDES_ICACHE_ACCESS + }, + { + /* perf: L1-icache-load-misses (eidx: 0x10009) */ + .eidx = SBI_PMU_HW_CACHE_EVENT_IDX(L1I, READ, MISS), + .select = ANDES_ICACHE_MISS + }, + { /* sentinel */ } +}; + +static const struct sbi_pmu_event_counter_map andes45_hw_evt_counters[] = { + { + /* perf: cycles (eidx: 0x1) */ + .eidx_start = SBI_PMU_HW_CPU_CYCLES, + /* perf: branch-misses (eidx: 0x6) */ + .eidx_end = SBI_PMU_HW_BRANCH_MISSES, + .ctr_map = ANDES_MHPM_MAP, + }, + { + /* perf: L1-dcache-loads (eidx: 0x10000) */ + .eidx_start = SBI_PMU_HW_CACHE_EVENT_IDX(L1D, READ, ACCESS), + /* perf: L1-dcache-store-misses (eidx: 0x10003) */ + .eidx_end = SBI_PMU_HW_CACHE_EVENT_IDX(L1D, WRITE, MISS), + .ctr_map = ANDES_MHPM_MAP, + }, + { + /* perf: L1-icache-load (eidx: 0x10008) */ + .eidx_start = SBI_PMU_HW_CACHE_EVENT_IDX(L1I, READ, ACCESS), + /* perf: L1-icache-load-misses (eidx: 0x10009) */ + .eidx_end = SBI_PMU_HW_CACHE_EVENT_IDX(L1I, READ, MISS), + .ctr_map = ANDES_MHPM_MAP, + }, + { /* sentinel */ } +}; + +static const struct sbi_pmu_raw_event_counter_map andes45_raw_evt_counters[] = { + { + .select = ANDES_CYCLES, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_INSTRET, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_INT_LOAD_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_INT_STORE_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_ATOMIC_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_SYS_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_INT_COMPUTE_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_CONDITION_BR, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_TAKEN_CONDITION_BR, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_JAL_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_JALR_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_RET_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_CONTROL_TRANS_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_EX9_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_INT_MUL_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_INT_DIV_REMAINDER_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_FLOAT_LOAD_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_FLOAT_STORE_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_FLOAT_ADD_SUB_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_FLOAT_MUL_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_FLOAT_FUSED_MULADD_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_FLOAT_DIV_SQUARE_ROOT_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_OTHER_FLOAT_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_INT_MUL_AND_SUB_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_RETIRED_OP, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_ILM_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DLM_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_ICACHE_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_ICACHE_MISS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DCACHE_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DCACHE_MISS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DCACHE_LOAD_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DCACHE_LOAD_MISS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DCACHE_STORE_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DCACHE_STORE_MISS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_DCACHE_WB, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_CYCLE_WAIT_ICACHE_FILL, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_CYCLE_WAIT_DCACHE_FILL, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_UNCACHED_IFETCH_FROM_BUS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_UNCACHED_LOAD_FROM_BUS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_CYCLE_WAIT_UNCACHED_IFETCH, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_CYCLE_WAIT_UNCACHED_LOAD, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_MAIN_ITLB_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_MAIN_ITLB_MISS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_MAIN_DTLB_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_MAIN_DTLB_MISS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_CYCLE_WAIT_ITLB_FILL, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_PIPE_STALL_CYCLE_DTLB_MISS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_HW_PREFETCH_BUS_ACCESS, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_MISPREDICT_CONDITION_BR, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_MISPREDICT_TAKE_CONDITION_BR, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { + .select = ANDES_MISPREDICT_TARGET_RET_INST, + .select_mask = ANDES_RAW_EVENT_MASK, + .ctr_map = ANDES_MHPM_MAP + }, + { /* sentinel */ } +}; + +int andes_fdt_add_pmu_mappings(void *fdt, const struct fdt_match *match) +{ + /* + * At the moment, simply create mapping for any 45-series core + * based on marchid, we may check and differentiate the mapping + * by mimpid. + */ + if (is_andes(45)) + return fdt_add_pmu_mappings(fdt, andes45_hw_evt_selects, + andes45_hw_evt_counters, + andes45_raw_evt_counters); + + return 0; +} diff --git a/platform/generic/andes/objects.mk b/platform/generic/andes/objects.mk index 6a8c66c..57caaf6 100644 --- a/platform/generic/andes/objects.mk +++ b/platform/generic/andes/objects.mk @@ -8,3 +8,4 @@ platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o andes/sleep.o platform-objs-$(CONFIG_ANDES45_PMA) += andes/andes45-pma.o platform-objs-$(CONFIG_ANDES_SBI) += andes/andes_sbi.o platform-objs-$(CONFIG_ANDES_PMU) += andes/andes_pmu.o +platform-objs-$(CONFIG_ANDES_HPM) += andes/andes_hpm.o diff --git a/platform/generic/include/andes/andes_hpm.h b/platform/generic/include/andes/andes_hpm.h new file mode 100644 index 0000000..0f301db --- /dev/null +++ b/platform/generic/include/andes/andes_hpm.h @@ -0,0 +1,83 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Andes Technology Corporation + */ + +#ifndef _ANDES_HPM_H_ +#define _ANDES_HPM_H_ + +#include + +#define ANDES_MHPM_MAP 0x78 +#define ANDES_RAW_EVENT_MASK ~0ULL + +/* Event code for instruction commit events */ +#define ANDES_CYCLES 0x10 +#define ANDES_INSTRET 0x20 +#define ANDES_INT_LOAD_INST 0x30 +#define ANDES_INT_STORE_INST 0x40 +#define ANDES_ATOMIC_INST 0x50 +#define ANDES_SYS_INST 0x60 +#define ANDES_INT_COMPUTE_INST 0x70 +#define ANDES_CONDITION_BR 0x80 +#define ANDES_TAKEN_CONDITION_BR 0x90 +#define ANDES_JAL_INST 0xA0 +#define ANDES_JALR_INST 0xB0 +#define ANDES_RET_INST 0xC0 +#define ANDES_CONTROL_TRANS_INST 0xD0 +#define ANDES_EX9_INST 0xE0 +#define ANDES_INT_MUL_INST 0xF0 +#define ANDES_INT_DIV_REMAINDER_INST 0x100 +#define ANDES_FLOAT_LOAD_INST 0x110 +#define ANDES_FLOAT_STORE_INST 0x120 +#define ANDES_FLOAT_ADD_SUB_INST 0x130 +#define ANDES_FLOAT_MUL_INST 0x140 +#define ANDES_FLOAT_FUSED_MULADD_INST 0x150 +#define ANDES_FLOAT_DIV_SQUARE_ROOT_INST 0x160 +#define ANDES_OTHER_FLOAT_INST 0x170 +#define ANDES_INT_MUL_AND_SUB_INST 0x180 +#define ANDES_RETIRED_OP 0x190 + +/* Event code for memory system events */ +#define ANDES_ILM_ACCESS 0x01 +#define ANDES_DLM_ACCESS 0x11 +#define ANDES_ICACHE_ACCESS 0x21 +#define ANDES_ICACHE_MISS 0x31 +#define ANDES_DCACHE_ACCESS 0x41 +#define ANDES_DCACHE_MISS 0x51 +#define ANDES_DCACHE_LOAD_ACCESS 0x61 +#define ANDES_DCACHE_LOAD_MISS 0x71 +#define ANDES_DCACHE_STORE_ACCESS 0x81 +#define ANDES_DCACHE_STORE_MISS 0x91 +#define ANDES_DCACHE_WB 0xA1 +#define ANDES_CYCLE_WAIT_ICACHE_FILL 0xB1 +#define ANDES_CYCLE_WAIT_DCACHE_FILL 0xC1 +#define ANDES_UNCACHED_IFETCH_FROM_BUS 0xD1 +#define ANDES_UNCACHED_LOAD_FROM_BUS 0xE1 +#define ANDES_CYCLE_WAIT_UNCACHED_IFETCH 0xF1 +#define ANDES_CYCLE_WAIT_UNCACHED_LOAD 0x101 +#define ANDES_MAIN_ITLB_ACCESS 0x111 +#define ANDES_MAIN_ITLB_MISS 0x121 +#define ANDES_MAIN_DTLB_ACCESS 0x131 +#define ANDES_MAIN_DTLB_MISS 0x141 +#define ANDES_CYCLE_WAIT_ITLB_FILL 0x151 +#define ANDES_PIPE_STALL_CYCLE_DTLB_MISS 0x161 +#define ANDES_HW_PREFETCH_BUS_ACCESS 0x171 + +/* Event code for microarchitecture events */ +#define ANDES_MISPREDICT_CONDITION_BR 0x02 +#define ANDES_MISPREDICT_TAKE_CONDITION_BR 0x12 +#define ANDES_MISPREDICT_TARGET_RET_INST 0x22 + +#ifdef CONFIG_ANDES_HPM + +int andes_fdt_add_pmu_mappings(void *fdt, const struct fdt_match *match); + +#else + +int andes_fdt_add_pmu_mappings(void *fdt, const struct fdt_match *match) { return 0; } + +#endif /* CONFIG_ANDES_HPM */ + +#endif /* _ANDES_HPM_H_ */ diff --git a/platform/generic/renesas/rzfive/rzfive.c b/platform/generic/renesas/rzfive/rzfive.c index 2f772c8..fafbff0 100644 --- a/platform/generic/renesas/rzfive/rzfive.c +++ b/platform/generic/renesas/rzfive/rzfive.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -69,6 +70,7 @@ const struct platform_override renesas_rzfive = { .match_table = renesas_rzfive_match, .early_init = renesas_rzfive_early_init, .final_init = renesas_rzfive_final_init, + .fdt_add_pmu_mappings = andes_fdt_add_pmu_mappings, .vendor_ext_provider = andes_sbi_vendor_ext_provider, .extensions_init = renesas_rzfive_extensions_init, }; From patchwork Thu Oct 19 11:37:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 1851604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1c3FyBtJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB5RC2mfdz20Zj for ; Thu, 19 Oct 2023 22:41:59 +1100 (AEDT) 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=l4AeQkTukvx3OTOZwBjNxoqRL38dQuLYxXpH7e2NT1s=; b=1c3FyBtJcvUyoq EQUpfEnx3TbP3AFUkc6uHabEn+ipbZS9j/ZEssezJ1wpo1XEJvFNq16XDdYJliHPHyWdqdnbxhwD2 2zmEACUdbztEasL3oj6AMGz2eTEoAcFgDOETTvDGFHzd7sCtH9xQjzqHLXWxtdkK568PtDq8xKKD8 1BBxGUPdUOf+kJZ5UAg6raAAQuOBpL/Lgshmgnbc4AtpWNybs+s+GZKr+Gd7ehL8h6V9RQbd7MUWc AfKeBbOYjlzJOaux+RYpVbRCyYKpgGYjzLRDKFkruArCIpJ/JpMqjnIcaIAk/77xaKAh56ajSM+BZ 9myoMGenfKIVXBXFFNOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtRPO-00HCSS-1W; Thu, 19 Oct 2023 11:41:46 +0000 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtRPJ-00HCQf-0r for opensbi@lists.infradead.org; Thu, 19 Oct 2023 11:41:44 +0000 Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 39JBfBfr049929; Thu, 19 Oct 2023 19:41:11 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 19 Oct 2023 19:41:08 +0800 From: Yu Chien Peter Lin To: CC: , , , , , , , , Yu Chien Peter Lin Subject: [PATCH v2 11/11] docs: pmu: Add Andes PMU node example Date: Thu, 19 Oct 2023 19:37:13 +0800 Message-ID: <20231019113713.3508153-12-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com> References: <20231019113713.3508153-1-peterlin@andestech.com> MIME-Version: 1.0 X-Originating-IP: [10.0.15.183] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 39JBfBfr049929 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_044141_768225_344588FD X-CRM114-Status: UNSURE ( 8.31 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add PMU node example for event index to counter index mapping and selector value translation of Andes' CPUs. Currently, there are 4 HPM counters that can be used to monitor all of the events for each hart. Content analysis details: (0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 TVD_RCVD_IP Message was received from an IP address -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.4 RDNS_DYNAMIC Delivered to internal network by host with dynamic-looking rDNS X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add PMU node example for event index to counter index mapping and selector value translation of Andes' CPUs. Currently, there are 4 HPM counters that can be used to monitor all of the events for each hart. Signed-off-by: Yu Chien Peter Lin Reviewed-by: Locus Wei-Han Chen Reviewed-by: Leo Yu-Chi Liang Reviewed-by: Anup Patel --- Changes v1 -> v2: - sync up with datasheet --- docs/pmu_support.md | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/docs/pmu_support.md b/docs/pmu_support.md index 8cfa08c..9b48f1e 100644 --- a/docs/pmu_support.md +++ b/docs/pmu_support.md @@ -125,3 +125,85 @@ pmu { <0x0 0x2 0xffffffff 0xffffe0ff 0x18>; }; ``` + +### Example 3 + +``` +/* + * For Andes 45-series platforms. The encodings can be found in the + * "Machine Performance Monitoring Event Selector" section + * http://www.andestech.com/wp-content/uploads/AX45MP-1C-Rev.-5.0.0-Datasheet.pdf + */ +pmu { + compatible = "riscv,pmu"; + riscv,event-to-mhpmevent = + <0x1 0x0000 0x10>, /* CPU_CYCLES -> Cycle count */ + <0x2 0x0000 0x20>, /* INSTRUCTIONS -> Retired instruction count */ + <0x3 0x0000 0x41>, /* CACHE_REFERENCES -> D-Cache access */ + <0x4 0x0000 0x51>, /* CACHE_MISSES -> D-Cache miss */ + <0x5 0x0000 0x80>, /* BRANCH_INSTRUCTIONS -> Conditional branch instruction count */ + <0x6 0x0000 0x02>, /* BRANCH_MISSES -> Misprediction of conditional branches */ + <0x10000 0x0000 0x61>, /* L1D_READ_ACCESS -> D-Cache load access */ + <0x10001 0x0000 0x71>, /* L1D_READ_MISS -> D-Cache load miss */ + <0x10002 0x0000 0x81>, /* L1D_WRITE_ACCESS -> D-Cache store access */ + <0x10003 0x0000 0x91>, /* L1D_WRITE_MISS -> D-Cache store miss */ + <0x10008 0x0000 0x21>, /* L1I_READ_ACCESS -> I-Cache access */ + <0x10009 0x0000 0x31>; /* L1I_READ_MISS -> I-Cache miss */ + riscv,event-to-mhpmcounters = <0x1 0x6 0x78>, + <0x10000 0x10003 0x78>, + <0x10008 0x10009 0x78>; + riscv,raw-event-to-mhpmcounters = + <0x0 0x10 0xffffffff 0xffffffff 0x78>, /* Cycle count */ + <0x0 0x20 0xffffffff 0xffffffff 0x78>, /* Retired instruction count */ + <0x0 0x30 0xffffffff 0xffffffff 0x78>, /* Integer load instruction count */ + <0x0 0x40 0xffffffff 0xffffffff 0x78>, /* Integer store instruction count */ + <0x0 0x50 0xffffffff 0xffffffff 0x78>, /* Atomic instruction count */ + <0x0 0x60 0xffffffff 0xffffffff 0x78>, /* System instruction count */ + <0x0 0x70 0xffffffff 0xffffffff 0x78>, /* Integer computational instruction count */ + <0x0 0x80 0xffffffff 0xffffffff 0x78>, /* Conditional branch instruction count */ + <0x0 0x90 0xffffffff 0xffffffff 0x78>, /* Taken conditional branch instruction count */ + <0x0 0xA0 0xffffffff 0xffffffff 0x78>, /* JAL instruction count */ + <0x0 0xB0 0xffffffff 0xffffffff 0x78>, /* JALR instruction count */ + <0x0 0xC0 0xffffffff 0xffffffff 0x78>, /* Return instruction count */ + <0x0 0xD0 0xffffffff 0xffffffff 0x78>, /* Control transfer instruction count */ + <0x0 0xE0 0xffffffff 0xffffffff 0x78>, /* EXEC.IT instruction count */ + <0x0 0xF0 0xffffffff 0xffffffff 0x78>, /* Integer multiplication instruction count */ + <0x0 0x100 0xffffffff 0xffffffff 0x78>, /* Integer division instruction count */ + <0x0 0x110 0xffffffff 0xffffffff 0x78>, /* Floating-point load instruction count */ + <0x0 0x120 0xffffffff 0xffffffff 0x78>, /* Floating-point store instruction count */ + <0x0 0x130 0xffffffff 0xffffffff 0x78>, /* Floating-point addition/subtraction instruction count */ + <0x0 0x140 0xffffffff 0xffffffff 0x78>, /* Floating-point multiplication instruction count */ + <0x0 0x150 0xffffffff 0xffffffff 0x78>, /* Floating-point fused multiply-add instruction count */ + <0x0 0x160 0xffffffff 0xffffffff 0x78>, /* Floating-point division or square-root instruction count */ + <0x0 0x170 0xffffffff 0xffffffff 0x78>, /* Other floating-point instruction count */ + <0x0 0x180 0xffffffff 0xffffffff 0x78>, /* Integer multiplication and add/sub instruction count */ + <0x0 0x190 0xffffffff 0xffffffff 0x78>, /* Retired operation count */ + <0x0 0x01 0xffffffff 0xffffffff 0x78>, /* ILM access */ + <0x0 0x11 0xffffffff 0xffffffff 0x78>, /* DLM access */ + <0x0 0x21 0xffffffff 0xffffffff 0x78>, /* I-Cache access */ + <0x0 0x31 0xffffffff 0xffffffff 0x78>, /* I-Cache miss */ + <0x0 0x41 0xffffffff 0xffffffff 0x78>, /* D-Cache access */ + <0x0 0x51 0xffffffff 0xffffffff 0x78>, /* D-Cache miss */ + <0x0 0x61 0xffffffff 0xffffffff 0x78>, /* D-Cache load access */ + <0x0 0x71 0xffffffff 0xffffffff 0x78>, /* D-Cache load miss */ + <0x0 0x81 0xffffffff 0xffffffff 0x78>, /* D-Cache store access */ + <0x0 0x91 0xffffffff 0xffffffff 0x78>, /* D-Cache store miss */ + <0x0 0xA1 0xffffffff 0xffffffff 0x78>, /* D-Cache writeback */ + <0x0 0xB1 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for I-Cache fill data */ + <0x0 0xC1 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for D-Cache fill data */ + <0x0 0xD1 0xffffffff 0xffffffff 0x78>, /* Uncached fetch data access from bus */ + <0x0 0xE1 0xffffffff 0xffffffff 0x78>, /* Uncached load data access from bus */ + <0x0 0xF1 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for uncached fetch data from bus */ + <0x0 0x101 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for uncached load data from bus */ + <0x0 0x111 0xffffffff 0xffffffff 0x78>, /* Main ITLB access */ + <0x0 0x121 0xffffffff 0xffffffff 0x78>, /* Main ITLB miss */ + <0x0 0x131 0xffffffff 0xffffffff 0x78>, /* Main DTLB access */ + <0x0 0x141 0xffffffff 0xffffffff 0x78>, /* Main DTLB miss */ + <0x0 0x151 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for Main ITLB fill data */ + <0x0 0x161 0xffffffff 0xffffffff 0x78>, /* Pipeline stall cycles caused by Main DTLB miss */ + <0x0 0x171 0xffffffff 0xffffffff 0x78>, /* Hardware prefetch bus access */ + <0x0 0x02 0xffffffff 0xffffffff 0x78>, /* Misprediction of conditional branches */ + <0x0 0x12 0xffffffff 0xffffffff 0x78>, /* Misprediction of taken conditional branches */ + <0x0 0x22 0xffffffff 0xffffffff 0x78>; /* Misprediction of targets of Return instructions */ +}; +```