[PATCH] platform: openpiton: Add PMU initialization
Samuel Holland
samuel.holland at sifive.com
Mon Jul 21 11:36:48 PDT 2025
Hi,
On 2025-07-21 11:09 AM, Manuel Hernández Méndez wrote:
> 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.
Since you must be using a FDT for the new PMU functions to work, is there
anything preventing you from using that FDT with the generic platform? The
generic platform is where new features are added; the other platforms get only
minimal maintenance and testing. So it might be better to migrate OpenPiton to
the generic platform if possible.
If firmware size is a concern, we can create a slimmed-down defconfig -- a
generic platform build with a limited set of drivers is only about 13 KiB larger
than a fpga/openpiton build.
> 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());
You would also need a defconfig change enabling CONFIG_FDT_PMU for this function
call to do anything.
Regards,
Samuel
> + 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 = {
More information about the opensbi
mailing list