From patchwork Sat Jul 10 16:18:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1503543 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=Eb5pKIPb; 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=BboTeshk; 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 4GMZwM6hlGz9sS8 for ; Sun, 11 Jul 2021 02:18:59 +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=UhlQditEuzIF3yK9eecS0aNWfeNIbYpYuRq9+KLuGiE=; b=Eb5pKIPb+YQ2pX 6cB24j5JBzludtnLdBaDhldwR/x1pq7jw67i9+naxyoRHEMBrbZKKc4NfNAdRORkP0fFMdUGli73U nYHKJFMne6j7I9EFUCd1D+4N0I9OhvT3NV+htipoIczvJhYU5nC1EkS7PhgxS2KljiJJcomkRUgQ9 W76YaM35HCNU4C4CQs4mGWiZIsmazcvk6o+AlOVGkklS6hsKB1+VS8/nlJ9qfKugjJOnKbJdvCMzN P7DsN8BRqTVgB51wq3EC3FdDIMplMg3ZiPQE7YIJLBehOQ7Ep4SZycNuWZ35vhGPNUq8xpiqZCtYB q7nlPk353eLhFVwjp7xA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2Fgt-003rsj-2U; Sat, 10 Jul 2021 16:18:55 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2Fgp-003rlt-AG for opensbi@lists.infradead.org; Sat, 10 Jul 2021 16:18:53 +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=1625933947; x=1657469947; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GPTpa3CIqi5snTEPykleGdsBlqqCJSNcjnP3F0VaKCc=; b=BboTeshkGZTxN79lehMf4pKzoV4eGGyBHckJlX3DBrjq1BWFO/ry6I8s KgO8qeNgcsuApZ1HLfLkLZVEP6HdK3jOnciaFtrfVqGgC4990CWlpGUW7 nWF4VqSJEfE6nu2SJiLQTr8TA7zOFAUZoEFlRyBTdmHL8WwJxaJLU9smO 3UIc0Tcu8CvZYA6wP5A7U8Gr+uE/Kd5wLqXg7xlW4Y4OlJjVOOmzURTZ/ U9pM2DVeEpgR1dUi2wQRS0y/r2ziGEmqT6AXVAXjup3HkzPZspU64uJ1e 7p6in5NoD6lobyrQ2l8hQYtk5jeRokc3tlPErcNPyArxkMtF1rWmVYn2j A==; IronPort-SDR: KGPDCwtAj9d3Fp4IIiBvVuDZM4D0+60Spn58+GAwTv2PohsNJ0UBLkH+a6RPPKVXATvgHEdj/C i/2jtCfZ8vKZkeGn+267cXWwNkujsaZYGlzxBBvKozCiFUbMkKoB/gbVoMx43kdzyCaqtOCixL YtJYblxPKHCandGGmnXu/cLLFDRpfS67zIhmm66cWy0cOciV6hmmwwGl5inL+ifAugJ2cy50K4 N/7e6fJvGZ704hYaC3598DLITdd2bvwwBuKQ+JZ8tB6iVqMExK79NGdy1I26plUGicwaEQi2Ly qI0= X-IronPort-AV: E=Sophos;i="5.84,229,1620662400"; d="scan'208";a="278060876" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 11 Jul 2021 00:19:07 +0800 IronPort-SDR: xOixw1VS7ytVvqCwu2kseO8YCrxRPrTc4Qbtucv8BVmI5ufyDFBfe8S20r9uXUV0kU5ZtfChC5 QZba191LcDQWabuD7uy5H6KMx5Cs5X+HyEaIV7fGZcME6zmgmNKX5ZfQI3/sDi8z0hcxiq9Qbm 3uZyqiZsj8Tz2Z8VNyaoxh6RqgeWSUY9WudSeduZ+tbTMWrSEKAV7hIf2l7Dw66QewP4h2sDiq 6ZuyV4FoDu4PbWosUk2jTohRnnrIGlCTPec58WjpM9QIxlNgom7rerm4v0tbzZIi9Q0ZvoKppL Xnvp5DxV5ubqtx2bbmgw6xh8 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; 10 Jul 2021 08:55:40 -0700 IronPort-SDR: w8pcV77KWt8QnsqEsP/uN9XXtnF7X0L50ren7Ykt/d+4K4HzDflvjCN/CQ359eEXqkS0GiNQNI 06QjsyOlnD+qUE7My5f1Gy9jll3gm750AiBF3aOyKv6Hgu/qwXC3VFXXRMqj+jBOUs0cP+lW9w OUMnH7xLR1Cr+rZbgxsCbS0ij3xpL4ap0plqCeZZdNYrpMBIsoDWwAGuk0x20Sa5GiQowkWIhk v6CVsWYWXrIamAU+5a3NUILT1h6/T9mE5WpPoKf/CJ/KJ1xzfD7BwHnRzZGpeVJQjmgF7aDFrt Oxo= WDCIronportException: Internal Received: from unknown (HELO fedora.wdc.com) ([10.225.163.38]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jul 2021 09:18:50 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , Anup Patel Subject: [PATCH v5 11/15] utils: fdt: Add fdt helper functions to parse PMU DT nodes Date: Sat, 10 Jul 2021 09:18:12 -0700 Message-Id: <20210710161816.632364-12-atish.patra@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210710161816.632364-1-atish.patra@wdc.com> References: <20210710161816.632364-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-20210710_091851_483699_0BB8524B X-CRM114-Status: GOOD ( 23.02 ) 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. Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- include/sbi_utils/fdt/fdt_pmu.h | 46 +++++++++++++ lib/utils/fdt/fdt_fixup.c | 2 + lib/utils/fdt/fdt_p [...] 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.143.124 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. Reviewed-by: Anup Patel 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 ++++++++++++++++++++++++++++++++ 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..9ebf1c225017 --- /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, "pmu,event-to-mhpmcounters"); + fdt_delprop(fdt, pmu_offset, "pmu,event-to-mhpmevent"); + fdt_delprop(fdt, pmu_offset, "pmu,raw-event-to-mhpmcounters"); + + 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, "pmu,event-to-mhpmcounters", &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, "pmu,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, "pmu,raw-event-to-mhpmcounters", &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