From patchwork Fri Mar 19 22:13:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456058 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=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.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=desiato.20200630 header.b=HwgTo2DD; 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=IMF0kZiS; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (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 4F2J8X0nFtz9sSC for ; Sat, 20 Mar 2021 09:14:20 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=WWfAwuFdfBOpYJM5dkg6hU1jrn4hJwCQumud03F6dto=; b=HwgTo2DDPGiKv6XSfZbbYcXxq HGzqghXt1qZ6cyxL6/OV/zMMGT9Cvo8vdXs2bI3AQIg5H1jNJN/in+dzMeMoBYytYixYvqfyvIZcu mhIlfiikg4AnF6K00vYZkyNumTIewBiJm3LND7eXhsClybMPipbBqh8cmibpp4rVIokpnSpnbGAnf g59i8w8AuXuGzqw120DFGYC/RgpS0bTNjTcDkeh5Ie2P3Xqd9MwECWqHzd+vq+i8u9A4K1I6Ua7mf U/XVvH7dn4oNVYTQCY0Cir3LJ3KjbHTKZ1VU+Ec9vCShyyAKxMpZ5BSeh1EfUyMQdm/VA+mAFVTse 1mzVKwmlw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNo-008Faf-Iq; Fri, 19 Mar 2021 22:14:16 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNH-008FLJ-37 for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:46 +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=1616192024; x=1647728024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gPBYcaMAoNRjuNuLLQhHPUZskbCJaOVajL8ogMr+lIs=; b=IMF0kZiSW/OsVX2PKlghVoZFZMif8CZmh7sX6dRwfyCdEHnvQZdYRbng 51YXkI5vnRorz6Hv3rhdK/wKVUNa9qZnWUh/cm6rTDKUvv25fT8T1/5X7 repW3jkr+4tUwc/u1OImtzTCc4y0f9UyEO++ocB/1whi+tPDkuU0XVlKj s6sNp6UgaDf/ydJv/aBTR4As+oRvZQzflobqDrQ3pufrD3wv4T4djgw4Y H/53kC05U8jQ5V1la7oDT7RCX+FPabd6zFoFkUYzWIgVBe5EXtVjeJ3Yy wVWq8XrS16l+U8iwmBuOhjTriITVG62/76npaaQ0ef3bnqnHMeUBi3riO g==; IronPort-SDR: CcB1PpFgPIXm+Y2CL4EFyVDdqKU4JlCT+oYhXdMsJIOlozQt7Bjtwdk8sbndFbrjgsOA95/Nim nwNfD8wXpnV3mdF7G2GdddPg2bTHC1jSJMn/hEwL8FH0yNQ82r2e4DwibNG9XYcwSnACf9kUGP 3yNVFks7i2QKibOHAsze7ryIWO1icNSDfRmpb5XVkopUaEEckZGNjAl8wNLrz4wBRDLaneI/S6 nohds4oM1qI6GMG2NdAsKefhUENhFplHGcmFBmHChfOVbWE7vWpyV+vjS94w3HOP5dz6GEFN6f xnk= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713911" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:20 +0800 IronPort-SDR: MtpZuiH0CTWquqe0cd/X0O660kik4d4lfBfVEvfVY2GZRVIZn9X7wz5nXSGs95RQYChxhLAGkI hfd6xbzRA/DiAZFQFG5XEdLcPnXniRZhlU8tzpZNLPzuBVYIrgi3bbeAZ/clUNKb6S5+fRx8RK IHmzOKwdu08sDYFOCrjfrL7PR7jM7Ug4X1Y+oK+5kmUg7PPYpGoEC2MuQ1rReZ/wskk1wNTFsO dKXB9mlepCDfKojUYLUAyDW6PNik2ymO3ZYiphZHQDKt2m/PlULicgcuQpv/13e9zjl7ntlps+ QMzfu0FxLM/q7/1mh+pYLXJl Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:51 -0700 IronPort-SDR: okRc4F1WH/R/j7y3VkNKRgzVoHHEyY43dy6f4XAJYk038MEAZhgkE7Aw3nEhbmAO4Ys2SbAG0w BfQExLj1KzsDLX57yuKbQqbUfo+6QocFaCZgn0AqADJBQunTmADvw70z4ht7Bxr7PVZHI492Dk mAl21Jquwcjw0i1Ibb9CUNYWZYHIE4lKgQ9AI1z5+102TmGoy1TZaNr9dvkEz4jLOiZOYOpccL MGJjnGoOChrpJ16Kgh988wJUvWVFhtQJh/UNCOjZmjjjXDSjgAR8idb+TanEimctYh32TlV0l4 YUg= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:20 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 11/14] utils: fdt: Add fdt helper functions to parse PMU DT nodes Date: Fri, 19 Mar 2021 15:13:02 -0700 Message-Id: <20210319221305.2138412-12-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-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-20210319_221344_446982_157FB6EF X-CRM114-Status: GOOD ( 23.89 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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 | 110 ++++++++++++++++++++++++++++++++ l [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's 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 --- include/sbi_utils/fdt/fdt_pmu.h | 46 +++++++++++++ lib/utils/fdt/fdt_fixup.c | 2 + lib/utils/fdt/fdt_pmu.c | 110 ++++++++++++++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + 4 files changed, 159 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 eea450d80492..ab351e408c86 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) @@ -260,6 +261,7 @@ void fdt_fixups(void *fdt) fdt_plic_fixup(fdt, "riscv,plic0"); 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..5053ab7568d8 --- /dev/null +++ b/lib/utils/fdt/fdt_pmu.c @@ -0,0 +1,110 @@ +// 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 + +struct sbi_pmu_hw_event_select { + uint32_t eidx; + uint64_t select; +}; + +static struct sbi_pmu_hw_event_select fdt_pmu_evt_select[SBI_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 sbi_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 sbi_pmu_hw_event_select *event; + 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++) { + event = &fdt_pmu_evt_select[hw_event_count]; + event->eidx = SBI_PMU_EVENT_RAW_IDX; + event->select = fdt32_to_cpu(event_val[3 * i]); + event->select = (event->select << 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(event->select, 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