lib: utils: fdt_pmu: Make the fdt_pmu_evt_select table global variable
authorYu Chien Peter Lin <peterlin@andestech.com>
Thu, 30 Nov 2023 12:42:10 +0000 (20:42 +0800)
committerAnup Patel <anup@brainfault.org>
Wed, 6 Dec 2023 12:45:41 +0000 (18:15 +0530)
To allow platform override pmu_init() filling the translation table
fdt_pmu_evt_select[] when PMU node doesn't provide such information,
we need to share the table and its entry counter with other .c file.

We also define the structures of PMU property in fdt_helper.h, so we
can initialize the mappings in arrays.

Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
include/sbi_utils/fdt/fdt_pmu.h
lib/utils/fdt/fdt_pmu.c

index c65cad78d789484956b9f0eb512d35be34aa838a..b10ae270971cbf88889b90b01ee1d05ace9f0e67 100644 (file)
 
 #include <sbi/sbi_types.h>
 
+struct fdt_pmu_hw_event_select_map {
+       uint32_t eidx;
+       uint64_t select;
+};
+
+struct fdt_pmu_hw_event_counter_map {
+       uint32_t eidx_start;
+       uint32_t eidx_end;
+       uint32_t ctr_map;
+};
+
+struct fdt_pmu_raw_event_counter_map {
+       uint64_t select;
+       uint64_t select_mask;
+       uint32_t ctr_map;
+};
+
 #ifdef CONFIG_FDT_PMU
 
 /**
@@ -26,7 +43,7 @@
  *
  * @param fdt device tree blob
  */
-void fdt_pmu_fixup(void *fdt);
+int fdt_pmu_fixup(void *fdt);
 
 /**
  * Setup PMU data from device tree
@@ -45,6 +62,11 @@ int fdt_pmu_setup(void *fdt);
  */
 uint64_t fdt_pmu_get_select_value(uint32_t event_idx);
 
+/** The event index to selector value table instance */
+extern struct fdt_pmu_hw_event_select_map fdt_pmu_evt_select[];
+/** The number of valid entries in fdt_pmu_evt_select[] */
+extern uint32_t hw_event_count;
+
 #else
 
 static inline void fdt_pmu_fixup(void *fdt) { }
index a8d764822a6aeea1027058f10d6b1ee8fae7e68b..684981eb9ba8ff0286f12061e9db09dc36480dec 100644 (file)
 #include <sbi/sbi_pmu.h>
 #include <sbi/sbi_scratch.h>
 #include <sbi_utils/fdt/fdt_helper.h>
+#include <sbi_utils/fdt/fdt_pmu.h>
 
 #define FDT_PMU_HW_EVENT_MAX (SBI_PMU_HW_EVENT_MAX * 2)
 
-struct fdt_pmu_hw_event_select {
-       uint32_t eidx;
-       uint64_t select;
-};
-
-static struct fdt_pmu_hw_event_select fdt_pmu_evt_select[FDT_PMU_HW_EVENT_MAX] = {0};
-static uint32_t hw_event_count;
+struct fdt_pmu_hw_event_select_map fdt_pmu_evt_select[FDT_PMU_HW_EVENT_MAX] = {0};
+uint32_t hw_event_count;
 
 uint64_t fdt_pmu_get_select_value(uint32_t event_idx)
 {
        int i;
-       struct fdt_pmu_hw_event_select *event;
+       struct fdt_pmu_hw_event_select_map *event;
 
        for (i = 0; i < SBI_PMU_HW_EVENT_MAX; i++) {
                event = &fdt_pmu_evt_select[i];
@@ -65,7 +61,7 @@ int fdt_pmu_setup(void *fdt)
        int i, pmu_offset, len, result;
        const u32 *event_val;
        const u32 *event_ctr_map;
-       struct fdt_pmu_hw_event_select *event;
+       struct fdt_pmu_hw_event_select_map *event;
        uint64_t raw_selector, select_mask;
        u32 event_idx_start, event_idx_end, ctr_map;