From: "Manuel Hernández Méndez" <maherme.dev@gmail.com>
To: opensbi@lists.infradead.org
Cc: "Manuel Hernández Méndez" <maherme.dev@gmail.com>
Subject: [PATCH] platform: openpiton: Add PMU initialization
Date: Mon, 21 Jul 2025 18:09:20 +0200 [thread overview]
Message-ID: <20250721160920.8818-1-maherme.dev@gmail.com> (raw)
The OpenPiton framework has a generic PMU that is not used by OpenSBI.
Due to OpenSBI’s build system we cannot directly reuse the generic
platform functions, so simply copy them to the OpenPiton platform.
Signed-off-by: Manuel Hernández Méndez <maherme.dev@gmail.com>
---
platform/fpga/openpiton/platform.c | 39 ++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c
index d2cf3e32..08136859 100644
--- a/platform/fpga/openpiton/platform.c
+++ b/platform/fpga/openpiton/platform.c
@@ -11,6 +11,7 @@
#include <sbi/sbi_platform.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/fdt/fdt_fixup.h>
+#include <sbi_utils/fdt/fdt_pmu.h>
#include <sbi_utils/ipi/aclint_mswi.h>
#include <sbi_utils/irqchip/plic.h>
#include <sbi_utils/serial/uart8250.h>
@@ -156,6 +157,42 @@ static int openpiton_timer_init(void)
return aclint_mtimer_cold_init(&mtimer, NULL);
}
+/*
+ * Initialize openpiton pmu during cold boot.
+ */
+int openpiton_pmu_init(void)
+{
+ int rc;
+
+ rc = fdt_pmu_setup(fdt_get_address());
+ if (rc && rc != SBI_ENOENT)
+ return rc;
+
+ return 0;
+}
+
+uint64_t openpiton_pmu_xlate_to_mhpmevent(uint32_t event_idx, uint64_t data)
+{
+ uint64_t evt_val = 0;
+
+ /* data is valid only for raw events and is equal to event selector */
+ if (event_idx == SBI_PMU_EVENT_RAW_IDX ||
+ event_idx == SBI_PMU_EVENT_RAW_V2_IDX)
+ evt_val = data;
+ else {
+ /**
+ * Generic platform follows the SBI specification recommendation
+ * i.e. zero extended event_idx is used as mhpmevent value for
+ * hardware general/cache events if platform does't define one.
+ */
+ evt_val = fdt_pmu_get_select_value(event_idx);
+ if (!evt_val)
+ evt_val = (uint64_t)event_idx;
+ }
+
+ return evt_val;
+}
+
/*
* Platform descriptor.
*/
@@ -165,6 +202,8 @@ const struct sbi_platform_operations platform_ops = {
.irqchip_init = openpiton_irqchip_init,
.ipi_init = openpiton_ipi_init,
.timer_init = openpiton_timer_init,
+ .pmu_init = openpiton_pmu_init,
+ .pmu_xlate_to_mhpmevent = openpiton_pmu_xlate_to_mhpmevent,
};
const struct sbi_platform platform = {
--
2.34.1
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next reply other threads:[~2025-07-21 17:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 16:09 Manuel Hernández Méndez [this message]
2025-07-21 18:36 ` [PATCH] platform: openpiton: Add PMU initialization Samuel Holland
2025-08-13 10:42 ` [PATCH] platform: openpiton: Move openpiton platform from fpga to generic Manuel Hernández Méndez
2025-08-13 10:47 ` [PATCH v2] " Manuel Hernández Méndez
2025-08-26 11:25 ` Anup Patel
2025-08-26 11:42 ` Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250721160920.8818-1-maherme.dev@gmail.com \
--to=maherme.dev@gmail.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox