static int pmu_ctr_start_hw(uint32_t cidx, uint64_t ival, bool ival_update)
{
- unsigned long mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+ unsigned long mctr_inhbt;
/* Make sure the counter index lies within the range and is not TM bit */
if (cidx > num_hw_ctrs || cidx == 1)
return SBI_EINVAL;
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
+ goto skip_inhibit_update;
+
+ /*
+ * Some of the hardware may not support mcountinhibit but perf stat
+ * still can work if supervisor mode programs the initial value.
+ */
+ mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
if (!__test_bit(cidx, &mctr_inhbt))
return SBI_EALREADY_STARTED;
pmu_ctr_enable_irq_hw(cidx);
csr_write(CSR_MCOUNTINHIBIT, mctr_inhbt);
+skip_inhibit_update:
if (ival_update)
pmu_ctr_write_hw(cidx, ival);
static int pmu_ctr_stop_hw(uint32_t cidx)
{
- unsigned long mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+ unsigned long mctr_inhbt;
+
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
+ return 0;
+
+ mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
/* Make sure the counter index lies within the range and is not TM bit */
if (cidx > num_hw_ctrs || cidx == 1)
unsigned long ctr_mask;
int i, ret = 0, fixed_ctr, ctr_idx = SBI_ENOTSUPP;
struct sbi_pmu_hw_event *temp;
- unsigned long mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
+ unsigned long mctr_inhbt;
+ u32 hartid = current_hartid();
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
if (cbase > num_hw_ctrs)
!sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
return fixed_ctr;
+ if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
+ mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
for (i = 0; i < num_hw_events; i++) {
temp = &hw_event_map[i];
if ((temp->start_idx > event_idx && event_idx < temp->end_idx) ||
ctr_mask = temp->counters & (cmask << cbase) &
(~SBI_PMU_FIXED_CTR_MASK);
for_each_set_bit_from(cbase, &ctr_mask, SBI_PMU_HW_CTR_MAX) {
- if (__test_bit(cbase, &mctr_inhbt)) {
- ctr_idx = cbase;
- break;
- }
+ /**
+ * Some of the platform may not support mcountinhibit.
+ * Checking the active_events is enough for them
+ */
+ if (active_events[hartid][cbase] != SBI_PMU_EVENT_IDX_INVALID)
+ continue;
+ /* If mcountinhibit is supported, the bit must be enabled */
+ if ((sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) &&
+ !__test_bit(cbase, &mctr_inhbt))
+ continue;
+ /* We found a valid counter that is not started yet */
+ ctr_idx = cbase;
}
}
{
u32 hartid = current_hartid();
- /* SBI PMU is not supported if mcountinhibit is not available */
- if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
- return;
+ if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
+ csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
- csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
csr_write(CSR_MCOUNTEREN, -1);
pmu_reset_event_map(hartid);
}
const struct sbi_platform *plat;
u32 hartid = current_hartid();
- /* SBI PMU is not supported if mcountinhibit is not available */
- if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
- return 0;
-
if (cold_boot) {
plat = sbi_platform_ptr(scratch);
/* Initialize hw pmu events */
*/
#include <libfdt.h>
+#include <sbi/sbi_hart.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_pmu.h>
#include <sbi_utils/fdt/fdt_helper.h>
int fdt_pmu_fixup(void *fdt)
{
int pmu_offset;
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
if (!fdt)
return SBI_EINVAL;
fdt_delprop(fdt, pmu_offset, "pmu,event-to-mhpmcounters");
fdt_delprop(fdt, pmu_offset, "pmu,event-to-mhpmevent");
fdt_delprop(fdt, pmu_offset, "pmu,raw-event-to-mhpmcounters");
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
+ fdt_delprop(fdt, pmu_offset, "interrupts-extended");
return 0;
}