OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Chien Peter Lin <peterlin@andestech.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v2 01/11] sbi: sbi_pmu: Improve sbi_pmu_init() error handling
Date: Thu, 19 Oct 2023 19:37:03 +0800	[thread overview]
Message-ID: <20231019113713.3508153-2-peterlin@andestech.com> (raw)
In-Reply-To: <20231019113713.3508153-1-peterlin@andestech.com>

This patch makes the following changes:

- As sbi_platform_pmu_init() returns a negative error code on
  failure, let sbi_pmu_init() to hang by propagating the error
  code.

- In order to distinguish the SBI_EFAIL error returned by
  sbi_pmu_add_*_counter_map(), return SBI_ENOENT to indicate
  that fdt_pmu_setup() failed to locate "riscv,pmu" node, and
  generic_pmu_init() ignores such case.

Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
---
Changes v1 -> v2:
  - New patch
---
 lib/sbi/sbi_pmu.c           | 5 ++++-
 lib/utils/fdt/fdt_pmu.c     | 2 +-
 platform/generic/platform.c | 8 +++++++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index f4c8fc4..3cbd4ff 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -957,6 +957,7 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot)
 	int hpm_count = sbi_fls(sbi_hart_mhpm_mask(scratch));
 	struct sbi_pmu_hart_state *phs;
 	const struct sbi_platform *plat;
+	int rc;
 
 	if (cold_boot) {
 		hw_event_map = sbi_calloc(sizeof(*hw_event_map),
@@ -972,7 +973,9 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot)
 
 		plat = sbi_platform_ptr(scratch);
 		/* Initialize hw pmu events */
-		sbi_platform_pmu_init(plat);
+		rc = sbi_platform_pmu_init(plat);
+		if (rc)
+			return rc;
 
 		/* mcycle & minstret is available always */
 		if (!hpm_count)
diff --git a/lib/utils/fdt/fdt_pmu.c b/lib/utils/fdt/fdt_pmu.c
index 83301bb..a8d7648 100644
--- a/lib/utils/fdt/fdt_pmu.c
+++ b/lib/utils/fdt/fdt_pmu.c
@@ -74,7 +74,7 @@ int fdt_pmu_setup(void *fdt)
 
 	pmu_offset = fdt_node_offset_by_compatible(fdt, -1, "riscv,pmu");
 	if (pmu_offset < 0)
-		return SBI_EFAIL;
+		return SBI_ENOENT;
 
 	event_ctr_map = fdt_getprop(fdt, pmu_offset,
 				    "riscv,event-to-mhpmcounters", &len);
diff --git a/platform/generic/platform.c b/platform/generic/platform.c
index 66a0b77..cb9270d 100644
--- a/platform/generic/platform.c
+++ b/platform/generic/platform.c
@@ -265,7 +265,13 @@ static u32 generic_tlb_num_entries(void)
 
 static int generic_pmu_init(void)
 {
-	return fdt_pmu_setup(fdt_get_address());
+	int rc;
+
+	rc = fdt_pmu_setup(fdt_get_address());
+	if (rc && rc != SBI_ENOENT)
+		return rc;
+
+	return 0;
 }
 
 static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,
-- 
2.34.1



  reply	other threads:[~2023-10-19 11:37 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19 11:37 [PATCH v2 00/11] Add Andes PMU extension support Yu Chien Peter Lin
2023-10-19 11:37 ` Yu Chien Peter Lin [this message]
2023-11-16  6:32   ` [PATCH v2 01/11] sbi: sbi_pmu: Improve sbi_pmu_init() error handling Anup Patel
2023-10-19 11:37 ` [PATCH v2 02/11] sbi: sbi_pmu: Add hw_counter_filter_mode() to pmu device Yu Chien Peter Lin
2023-11-16  6:36   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 03/11] platform: include: andes45: Add PMU related CSR defines Yu Chien Peter Lin
2023-11-16  6:39   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 04/11] platform: andes: Add Andes custom PMU support Yu Chien Peter Lin
2023-11-16  6:41   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 05/11] platform: andes: Enable Andes PMU for AE350 Yu Chien Peter Lin
2023-11-16  6:45   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 06/11] platform: rzfive: Enable Andes PMU for RZ/Five Yu Chien Peter Lin
2023-11-16  6:45   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 07/11] lib: utils: fdt_fixup: Add fdt_add_pmu_mappings() helper function Yu Chien Peter Lin
2023-10-21 12:25   ` [PATCH v2 10/11] platform: andes: Implement andes_fdt_add_pmu_mappings platform override Inochi Amaoto
2023-10-22  6:50     ` Yu-Chien Peter Lin
2023-11-16  6:59   ` [PATCH v2 07/11] lib: utils: fdt_fixup: Add fdt_add_pmu_mappings() helper function Anup Patel
2023-10-19 11:37 ` [PATCH v2 08/11] lib: utils: fdt_fixup: Allow preserving PMU properties Yu Chien Peter Lin
2023-11-16  6:48   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 09/11] platform: andes: Factor out is_andes() helper Yu Chien Peter Lin
2023-11-16  6:49   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 10/11] platform: andes: Implement andes_fdt_add_pmu_mappings platform override Yu Chien Peter Lin
2023-11-16  6:58   ` Anup Patel
2023-10-19 11:37 ` [PATCH v2 11/11] docs: pmu: Add Andes PMU node example Yu Chien Peter Lin
2023-11-16  7:00   ` Anup Patel
2023-11-16  7:01 ` [PATCH v2 00/11] Add Andes PMU extension support Anup Patel
2023-11-21  7:44   ` Yu-Chien Peter Lin

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=20231019113713.3508153-2-peterlin@andestech.com \
    --to=peterlin@andestech.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