From patchwork Sat Jun 26 00:57:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1497526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: 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=tC09x1W1; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=roL5kc+e; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GBb8C0gzgz9sWQ for ; Sat, 26 Jun 2021 10:58:03 +1000 (AEST) 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=LEGA08Nwu5tAH6l3oidL6Tty/5IXyEuqvjstQQLqza8=; b=tC09x1W1lJ9oRH EX3R4wm5/u869rq7kRF5UjlETSsQBRPRMIP/Xx9OyoN5WBY2GVWztKVnudHQnEudCaID+tg2kb/O0 D1NaTsvo28jkQp7gSRr815bcegMOghIzoNat9xxm2lcnHnjn2/VIJtkeluMJHH7zWcVMmpKl5nJnq QMKv3T9K0v5LPdG4rtBGdo9gGxz3GNLknZSNEMm7Iv6QSMjzdwUh5ppS0WaTFjXCEV+JwoGA0u9Wl OFxBzbQ1qJJgsWU7W0kNwkF/ka2krWUUG+wCB2DXQHA629+7wBbP00ueZwxxZTG+BKjspUBscmpss 5opc7SvIcFf8dmkr7WtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwwdx-003BBM-TT; Sat, 26 Jun 2021 00:57:57 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwwdt-003B6F-Fc for opensbi@lists.infradead.org; Sat, 26 Jun 2021 00:57:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1624669073; x=1656205073; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xhCR0ISdrvCcLtKgf+cB/Z0H37I+OZx3llRS10q8ew8=; b=roL5kc+eknFP1q5flMp9kqj67b5cimnj4qzT8bs5EBgL/j+oN8uhgJj3 7Lz4PqNYoZNaAwP4lgnVWY1l6fEcrqRv2DEUGQMmP2xYIOoMmyum5Is2q XSHHpDGuqWVnaesar7JQvdOWZkirVXoCza/Q/A34/lqrQjW13GIlzvAE5 BA/ePDhGpoMZReVwTrN/ZRaHfjZ7td2bhZU0M2I/OpiluHzJeeadXZaFB 3WzAguabuSXfVfRSmsoYj8sCbljsWDAADUnfLpoUUSUyRJsf5Vakdml5+ WJyAztFzaO0nIX7V9D583E2LWgamVEX0U50/CiS8Yyh4Uonvw7+7gcB93 g==; IronPort-SDR: HoK79pinJZ4oY0u4NcT29NU0sCV7G8sKR7jVVabRaOhxHUubdfSS5NOIHQZxA5it8+fD90blax S2urJUSv8vDld+S6u6uLTJFBNiQw2AYQoIFn+yxTJqAZM2zCpvGvRDQG+RpjS5ZbGSWaY3lWee YY9a0lyqAko+ykOnd0W4S+BDnylNr6w79kmuIPrvNGQlmXxvlM3ak1+20ayzmlLDU4D/AcBYjX Z3a6/CWKAKCY3McNL/I1VQkyHXFKVlYerrT7wqk1l1bNkIORZGCcU9QUAtCMrK7QdBn2VgjTHd xZE= X-IronPort-AV: E=Sophos;i="5.83,300,1616428800"; d="scan'208";a="284438607" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2021 08:57:53 +0800 IronPort-SDR: JpzmKv2srkrz/htj/m+wslmFfq5r2gZPCqLuHusm1tXRUIRacmjugovrf36sC10KgAFyPLt9bv e8RqUOaAl47s5BcDrivD6oOVMNhvBK2jt43vfpyyFZ7CFtX5CmDsW3fgkfWfwrOfye2VsdlBf9 EmapmkNtgZZyFjxlUhD9U69BxNuizoYmBPvr5Q9MaXiVlmcmzw94YzL4j5O+g4EyvcUxKwFydO knoEjl3ZWJHdN59YMuLwvlWmgNnmx8YaBDKiHBwcGK9OSmCaa2/hbd9NlUzWGLbJ+3Lb0S/Nz3 ez4iIEk/IRkYyf8CYII9k+j1 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2021 17:36:25 -0700 IronPort-SDR: c2ynOcNq0hDSjNLzgqWJVR8zCGv7EuKqfDttHhBmtOxT8AszlGu7kDVITCo5vdczQ/mjdIEFZy nZqGXqTatAYouj7PQNy7JcODwvQhU9uO9rRskxrB/uCObr/2R6U8b0Cj0nFqQLtAAfETNte4q9 ERkoZuH3ZYcH0cGImIkA+jNl0d3PESFDqDWbzAYyCS76wtjSw+cxkmcLOu6LIjSwvU0x5QHI1h dAXwjH+n+PL9/WgxK9DrDoy0fsCs6EGTV2eAAQ6+K8M5nglMZ2G7X16CyBWcmyBaj9DyUjcbDn sYc= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.19]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Jun 2021 17:57:52 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v3 11/15] utils: fdt: Add fdt helper functions to parse PMU DT nodes Date: Fri, 25 Jun 2021 17:57:17 -0700 Message-Id: <20210626005721.3600114-12-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210626005721.3600114-1-atish.patra@wdc.com> References: <20210626005721.3600114-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210625_175753_590955_EB171A58 X-CRM114-Status: GOOD ( 23.10 ) X-Spam-Score: -2.5 (--) 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: The PMU DT node bindings are defined in docs/pmu_support.md Add few fdt helper functions to parse the DT node and update the event-counter mapping tables. Signed-off-by: Atish Patra --- include/sbi_utils/fdt/fdt_pmu.h | 46 +++++++++++++ lib/utils/fdt/fdt_fixup.c | 2 + lib/utils/fdt/fdt_pmu.c | 111 ++++++++++++++++++++++++++++++++ l [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 The PMU DT node bindings are defined in docs/pmu_support.md Add few fdt helper functions to parse the DT node and update the event-counter mapping tables. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- include/sbi_utils/fdt/fdt_pmu.h | 46 +++++++++++++ lib/utils/fdt/fdt_fixup.c | 2 + lib/utils/fdt/fdt_pmu.c | 111 ++++++++++++++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + 4 files changed, 160 insertions(+) create mode 100644 include/sbi_utils/fdt/fdt_pmu.h create mode 100644 lib/utils/fdt/fdt_pmu.c diff --git a/include/sbi_utils/fdt/fdt_pmu.h b/include/sbi_utils/fdt/fdt_pmu.h new file mode 100644 index 000000000000..2fa01edc0743 --- /dev/null +++ b/include/sbi_utils/fdt/fdt_pmu.h @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * fdt_pmu.c - Flat Device Tree PMU helper routines + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#ifndef __FDT_PMU_H__ +#define __FDT_PMU_H__ + +#include + +/** + * Fix up the PMU node in the device tree + * + * This routine: + * 1. Disables opensbi specific properties from the DT + * + * It is recommended that platform support call this function in + * their final_init() platform operation. + * + * @param fdt device tree blob + */ +void fdt_pmu_fixup(void *fdt); + +/** + * Setup PMU data from device tree + * + * @param fdt device tree blob + * + * @return 0 on success and negative error code on failure + */ +int fdt_pmu_setup(void *fdt); + +/** + * Get the mhpmevent select value read from DT for a given event + * @param event_idx Event ID of the given event + * + * @return The select value read from DT or 0 if given index was not found + */ +uint64_t fdt_pmu_get_select_value(uint32_t event_idx); + +#endif diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index 14655000b815..ac01ba3dfac1 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -15,6 +15,7 @@ #include #include #include +#include #include void fdt_cpu_fixup(void *fdt) @@ -263,6 +264,7 @@ void fdt_fixups(void *fdt) fdt_plic_fixup(fdt); fdt_reserved_memory_fixup(fdt); + fdt_pmu_fixup(fdt); } diff --git a/lib/utils/fdt/fdt_pmu.c b/lib/utils/fdt/fdt_pmu.c new file mode 100644 index 000000000000..910bf30ee761 --- /dev/null +++ b/lib/utils/fdt/fdt_pmu.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * fdt_pmu.c - Flat Device Tree PMU helper routines + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#include +#include +#include +#include + +#define FDT_PMU_HW_EVENT_MAX (SBI_PMU_HW_EVENT_MAX * 2) + +struct fdt_pmu_hw_event_select { + uint32_t eidx; + uint64_t select; +}; + +static struct fdt_pmu_hw_event_select fdt_pmu_evt_select[FDT_PMU_HW_EVENT_MAX] = {0}; +static uint32_t hw_event_count; + +uint64_t fdt_pmu_get_select_value(uint32_t event_idx) +{ + int i; + struct fdt_pmu_hw_event_select *event; + + for (i = 0; i < SBI_PMU_HW_EVENT_MAX; i++) { + event = &fdt_pmu_evt_select[i]; + if (event->eidx == event_idx) + return event->select; + } + + return 0; +} + +int fdt_pmu_fixup(void *fdt) +{ + int pmu_offset; + + if (!fdt) + return SBI_EINVAL; + + pmu_offset = fdt_node_offset_by_compatible(fdt, -1, "riscv,pmu"); + if (pmu_offset < 0) + return SBI_EFAIL; + + fdt_delprop(fdt, pmu_offset, "opensbi,event-to-counters"); + fdt_delprop(fdt, pmu_offset, "opensbi,event-to-mhpmevent"); + fdt_delprop(fdt, pmu_offset, "opensbi,raw-event-to-counters"); + + return 0; +} + +int fdt_pmu_setup(void *fdt) +{ + int i, pmu_offset, len, result; + const u32 *event_val; + const u32 *event_ctr_map; + struct fdt_pmu_hw_event_select *event; + uint64_t raw_selector; + u32 event_idx_start, event_idx_end, ctr_map; + + if (!fdt) + return SBI_EINVAL; + + pmu_offset = fdt_node_offset_by_compatible(fdt, -1, "riscv,pmu"); + if (pmu_offset < 0) + return SBI_EFAIL; + + event_ctr_map = fdt_getprop(fdt, pmu_offset, "opensbi,event-to-counters", &len); + if (!event_ctr_map || len < 8) + return SBI_EFAIL; + len = len / (sizeof(u32) * 3); + for (i = 0; i < len; i++) { + event_idx_start = fdt32_to_cpu(event_ctr_map[3 * i]); + event_idx_end = fdt32_to_cpu(event_ctr_map[3 * i + 1]); + ctr_map = fdt32_to_cpu(event_ctr_map[3 * i + 2]); + sbi_pmu_add_hw_event_counter_map(event_idx_start, event_idx_end, ctr_map); + } + + event_val = fdt_getprop(fdt, pmu_offset, "opensbi,event-to-mhpmevent", &len); + if (!event_val || len < 8) + return SBI_EFAIL; + len = len / (sizeof(u32) * 3); + for (i = 0; i < len; i++) { + event = &fdt_pmu_evt_select[hw_event_count]; + event->eidx = fdt32_to_cpu(event_val[3 * i]); + event->select = fdt32_to_cpu(event_val[3 * i + 1]); + event->select = (event->select << 32) | fdt32_to_cpu(event_val[3 * i + 2]); + hw_event_count++; + } + + event_val = fdt_getprop(fdt, pmu_offset, "opensbi,raw-event-to-counters", &len); + if (!event_val || len < 8) + return SBI_EFAIL; + len = len / (sizeof(u32) * 3); + for (i = 0; i < len; i++) { + raw_selector = fdt32_to_cpu(event_val[3 * i]); + raw_selector = (raw_selector << 32) | fdt32_to_cpu(event_val[3 * i + 1]); + ctr_map = fdt32_to_cpu(event_val[3 * i + 2]); + result = sbi_pmu_add_raw_event_counter_map(raw_selector, ctr_map); + if (!result) + hw_event_count++; + } + + return 0; +} diff --git a/lib/utils/fdt/objects.mk b/lib/utils/fdt/objects.mk index d9f1eae19292..03800f96d74d 100644 --- a/lib/utils/fdt/objects.mk +++ b/lib/utils/fdt/objects.mk @@ -5,5 +5,6 @@ # libsbiutils-objs-y += fdt/fdt_domain.o +libsbiutils-objs-y += fdt/fdt_pmu.o libsbiutils-objs-y += fdt/fdt_helper.o libsbiutils-objs-y += fdt/fdt_fixup.o