sbi: sbi_pmu: Improve sbi_pmu_init() error handling
authorYu Chien Peter Lin <peterlin@andestech.com>
Thu, 30 Nov 2023 12:42:00 +0000 (20:42 +0800)
committerAnup Patel <anup@brainfault.org>
Wed, 6 Dec 2023 11:54:38 +0000 (17:24 +0530)
This patch makes the following changes:

- As sbi_platform_pmu_init() returns a negative error code on
  failure, let sbi_pmu_init() print out the error code with
  sbi_dprintf().

- 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>
Reviewed-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
lib/sbi/sbi_pmu.c
lib/utils/fdt/fdt_pmu.c
platform/generic/platform.c

index 185068bb1f438e4ad0f16f621717ec291e88b6be..2ee6e62a8f9f8fe164fbd9f699a1c20d82a927d6 100644 (file)
@@ -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,10 @@ 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)
+                       sbi_dprintf("%s: platform pmu init failed "
+                                   "(error %d)\n", __func__, rc);
 
                /* mcycle & minstret is available always */
                if (!hpm_count)
index 83301bb5c1a553cee14b2507c31bc9f01ac0c6a0..a8d764822a6aeea1027058f10d6b1ee8fae7e68b 100644 (file)
@@ -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);
index 85acecd7b8d861ea78bd1f5d3235fb80589a5071..fa400b9e68ed9a8089c1211753fe231e185dbc21 100644 (file)
@@ -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,