diff options
| author | Mayuresh Chitale <[email protected]> | 2023-03-09 18:43:51 +0530 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2023-03-10 13:46:52 +0530 |
| commit | 1fe8dc995566d869836d3caf37e427c28536f453 (patch) | |
| tree | ab708c7d847836efb1a8f6b6a263b6233713f0ed | |
| parent | 506144f398b7911a2395d127fb6a64082a4a79cc (diff) | |
lib: sbi_pmu: add callback for counter width
This patch adds a callback to fetch the number of bits implemented for a
custom firmware counter. If the callback fails or is not implemented then
width defaults to 63.
Signed-off-by: Mayuresh Chitale <[email protected]>
Reviewed-by: Atish Patra <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
| -rw-r--r-- | include/sbi/sbi_pmu.h | 5 | ||||
| -rw-r--r-- | lib/sbi/sbi_pmu.c | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/include/sbi/sbi_pmu.h b/include/sbi/sbi_pmu.h index c3652439..b3b75c1b 100644 --- a/include/sbi/sbi_pmu.h +++ b/include/sbi/sbi_pmu.h @@ -42,6 +42,11 @@ struct sbi_pmu_device { uint32_t event_idx_code); /** + * Fetch the max width of this counter in number of bits. + */ + int (*fw_counter_width)(void); + + /** * Read value of custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 154dbdac..a99c0450 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -761,6 +761,7 @@ unsigned long sbi_pmu_num_ctr(void) int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info) { + int width; union sbi_pmu_ctr_info cinfo = {0}; struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); @@ -782,6 +783,11 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info) cinfo.type = SBI_PMU_CTR_TYPE_FW; /* Firmware counters are always 64 bits wide */ cinfo.width = 63; + if (pmu_dev && pmu_dev->fw_counter_width) { + width = pmu_dev->fw_counter_width(); + if (width) + cinfo.width = width - 1; + } } *ctr_info = cinfo.value; |
