public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Samuel Holland <samuel.holland@sifive.com>
To: "Manuel Hernández Méndez" <maherme.dev@gmail.com>,
	opensbi@lists.infradead.org
Subject: Re: [PATCH] platform: openpiton: Add PMU initialization
Date: Mon, 21 Jul 2025 13:36:48 -0500	[thread overview]
Message-ID: <42fb18cc-d579-490f-b7db-89cb8d228ee8@sifive.com> (raw)
In-Reply-To: <20250721160920.8818-1-maherme.dev@gmail.com>

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@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 = {


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  reply	other threads:[~2025-07-21 18:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-21 16:09 [PATCH] platform: openpiton: Add PMU initialization Manuel Hernández Méndez
2025-07-21 18:36 ` Samuel Holland [this message]
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=42fb18cc-d579-490f-b7db-89cb8d228ee8@sifive.com \
    --to=samuel.holland@sifive.com \
    --cc=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