[PATCH] platform: openpiton: Add PMU initialization
Manuel Hernández Méndez
maherme.dev at gmail.com
Mon Jul 21 09:09:20 PDT 2025
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 at 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
More information about the opensbi
mailing list