summaryrefslogtreecommitdiff
path: root/lib/utils/fdt
diff options
context:
space:
mode:
authorVincent Chen <vincent.chen@sifive.com>2021-12-02 04:45:42 +0300
committerAnup Patel <anup@brainfault.org>2021-12-03 07:07:03 +0300
commit2428987cc06310f0e54abd4ce2efe3ed60f52245 (patch)
tree5b57280da17750b6ec2c9b3b307011a806528bbe /lib/utils/fdt
parent14faee6916bc973b9fdb816c5f4a45096e3f645a (diff)
downloadopensbi-2428987cc06310f0e54abd4ce2efe3ed60f52245.tar.xz
lib: pmu: support the event ID encoded by a bitmap.
RISC-V privilege specification does not specify how to encode the event ID. Therefore, each platform is allowed to customize its own encoding rule. The common encoding methods are as follow, directly assigning a number to an event, or every bit in the mphmevent CSR controls one specified event or mixes the above two methods. To enable OpenSBI to support the above three encoding methods simultaneously, this patch repurpose the dt property "riscv,raw-event-to-mhpmcounters". The "riscv,raw-event-to-mhpmcounters" will describes the one or multiple raw events that could be counted by a set of counters. But, the column number of "riscv,raw-event-to-mhpmcounters" is extended from 2 to 3. The 1st column (64bit) is the ID of the raw events. The 2nd column (64bit) represents a select_mask now to represent the bits used for event ID encoding. If a platform directly encodes each raw PMU event as a unique ID, the value of select_mask will be 0xffffffff_ffffffff. Signed-off-by: Vincent Chen <vincent.chen@sifive.com> Signed-off-by: Atish Patra<atishp@rivosinc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'lib/utils/fdt')
-rw-r--r--lib/utils/fdt/fdt_pmu.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/utils/fdt/fdt_pmu.c b/lib/utils/fdt/fdt_pmu.c
index 529ee42..a2b048f 100644
--- a/lib/utils/fdt/fdt_pmu.c
+++ b/lib/utils/fdt/fdt_pmu.c
@@ -65,7 +65,7 @@ int fdt_pmu_setup(void *fdt)
const u32 *event_val;
const u32 *event_ctr_map;
struct fdt_pmu_hw_event_select *event;
- uint64_t raw_selector;
+ uint64_t raw_selector, select_mask;
u32 event_idx_start, event_idx_end, ctr_map;
if (!fdt)
@@ -99,14 +99,16 @@ int fdt_pmu_setup(void *fdt)
}
event_val = fdt_getprop(fdt, pmu_offset, "riscv,raw-event-to-mhpmcounters", &len);
- if (!event_val || len < 8)
+ if (!event_val || len < 20)
return SBI_EFAIL;
- len = len / (sizeof(u32) * 3);
+ len = len / (sizeof(u32) * 5);
for (i = 0; i < len; i++) {
- raw_selector = fdt32_to_cpu(event_val[3 * i]);
- raw_selector = (raw_selector << 32) | fdt32_to_cpu(event_val[3 * i + 1]);
- ctr_map = fdt32_to_cpu(event_val[3 * i + 2]);
- result = sbi_pmu_add_raw_event_counter_map(raw_selector, ctr_map);
+ raw_selector = fdt32_to_cpu(event_val[5 * i]);
+ raw_selector = (raw_selector << 32) | fdt32_to_cpu(event_val[5 * i + 1]);
+ select_mask = fdt32_to_cpu(event_val[5 * i + 2]);
+ select_mask = (select_mask << 32) | fdt32_to_cpu(event_val[5 * i + 3]);
+ ctr_map = fdt32_to_cpu(event_val[5 * i + 4]);
+ result = sbi_pmu_add_raw_event_counter_map(raw_selector, select_mask, ctr_map);
if (!result)
hw_event_count++;
}