diff options
| author | Heiko Stuebner <[email protected]> | 2022-10-04 18:42:23 +0200 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2022-10-13 09:52:01 +0530 |
| commit | e54cb3298bfcaa2ac56fe51d0f39c901d5397166 (patch) | |
| tree | 2ca3a04a00a34c7cf39d073de068657117d70b20 | |
| parent | 3f3d401d2dfbed232d77012ba9289b62e98ad519 (diff) | |
lib: sbi_pmu: move pmu irq information into pmu itself
Don't spread checking for pmu extensions through the code
but instead introduce a sbi-pmu function that other code can
call to get the correct information about the existence of the
pmu interrupt.
Add a sbi_pmu_device override function to allow overridung this
bit as well if needed.
Reviewed-by: Atish Patra <[email protected]>
Reviewed-by: Andrew Jones <[email protected]>
Reviewed-by: Guo Ren <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
Signed-off-by: Heiko Stuebner <[email protected]>
| -rw-r--r-- | include/sbi/sbi_pmu.h | 8 | ||||
| -rw-r--r-- | lib/sbi/sbi_hart.c | 4 | ||||
| -rw-r--r-- | lib/sbi/sbi_pmu.c | 12 |
3 files changed, 22 insertions, 2 deletions
diff --git a/include/sbi/sbi_pmu.h b/include/sbi/sbi_pmu.h index a2ce42da..c3652439 100644 --- a/include/sbi/sbi_pmu.h +++ b/include/sbi/sbi_pmu.h @@ -73,6 +73,11 @@ struct sbi_pmu_device { * Note: 0 <= counter_index < SBI_PMU_HW_CTR_MAX */ void (*hw_counter_disable_irq)(uint32_t counter_index); + + /** + * Custom function returning the machine-specific irq-bit. + */ + int (*hw_counter_irq_bit)(void); }; /** Get the PMU platform device */ @@ -87,6 +92,9 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot); /** Reset PMU during hart exit */ void sbi_pmu_exit(struct sbi_scratch *scratch); +/** Return the pmu irq bit depending on extension existence */ +int sbi_pmu_irq_bit(void); + /** * Add the hardware event to counter mapping information. This should be called * from the platform code to update the mapping table. diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 12948684..447f99e4 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -19,6 +19,7 @@ #include <sbi/sbi_hart.h> #include <sbi/sbi_math.h> #include <sbi/sbi_platform.h> +#include <sbi/sbi_pmu.h> #include <sbi/sbi_string.h> #include <sbi/sbi_trap.h> @@ -208,8 +209,7 @@ static int delegate_traps(struct sbi_scratch *scratch) /* Send M-mode interrupts and most exceptions to S-mode */ interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; - if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) - interrupts |= MIP_LCOFIP; + interrupts |= sbi_pmu_irq_bit(); exceptions = (1U << CAUSE_MISALIGNED_FETCH) | (1U << CAUSE_BREAKPOINT) | (1U << CAUSE_USER_ECALL); diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 214d5e8a..91d9ccc3 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -344,6 +344,18 @@ skip_inhibit_update: return 0; } +int sbi_pmu_irq_bit(void) +{ + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) + return MIP_LCOFIP; + if (pmu_dev && pmu_dev->hw_counter_irq_bit) + return pmu_dev->hw_counter_irq_bit(); + + return 0; +} + static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, uint64_t ival, bool ival_update) { |
