forked from Mirrors/opensbi
lib: sbi: Remove MCOUNTINHIBT hart feature
If a hart implements privileged spec v1.11 (or higher) then we can safely assume that mcountinhibit CSR is present and we don't need MCOUNTINHIBT as a hart feature. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
This commit is contained in:
@@ -26,20 +26,18 @@ enum sbi_hart_priv_versions {
|
|||||||
|
|
||||||
/** Possible feature flags of a hart */
|
/** Possible feature flags of a hart */
|
||||||
enum sbi_hart_features {
|
enum sbi_hart_features {
|
||||||
/** Hart has counter inhibit CSR */
|
|
||||||
SBI_HART_HAS_MCOUNTINHIBIT = (1 << 0),
|
|
||||||
/** Hart has sscofpmf extension */
|
/** Hart has sscofpmf extension */
|
||||||
SBI_HART_HAS_SSCOFPMF = (1 << 1),
|
SBI_HART_HAS_SSCOFPMF = (1 << 0),
|
||||||
/** HART has timer csr implementation in hardware */
|
/** HART has timer csr implementation in hardware */
|
||||||
SBI_HART_HAS_TIME = (1 << 2),
|
SBI_HART_HAS_TIME = (1 << 1),
|
||||||
/** HART has AIA local interrupt CSRs */
|
/** HART has AIA local interrupt CSRs */
|
||||||
SBI_HART_HAS_AIA = (1 << 3),
|
SBI_HART_HAS_AIA = (1 << 2),
|
||||||
/** HART has menvcfg CSR */
|
/** HART has menvcfg CSR */
|
||||||
SBI_HART_HAS_MENVCFG = (1 << 4),
|
SBI_HART_HAS_MENVCFG = (1 << 3),
|
||||||
/** HART has mstateen CSR **/
|
/** HART has mstateen CSR **/
|
||||||
SBI_HART_HAS_SMSTATEEN = (1 << 5),
|
SBI_HART_HAS_SMSTATEEN = (1 << 4),
|
||||||
/** HART has SSTC extension implemented in hardware */
|
/** HART has SSTC extension implemented in hardware */
|
||||||
SBI_HART_HAS_SSTC = (1 << 6),
|
SBI_HART_HAS_SSTC = (1 << 5),
|
||||||
|
|
||||||
/** Last index of Hart features*/
|
/** Last index of Hart features*/
|
||||||
SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SSTC,
|
SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SSTC,
|
||||||
|
@@ -70,7 +70,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
|
|||||||
csr_write(CSR_MCOUNTEREN, -1);
|
csr_write(CSR_MCOUNTEREN, -1);
|
||||||
|
|
||||||
/* All programmable counters will start running at runtime after S-mode request */
|
/* All programmable counters will start running at runtime after S-mode request */
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11)
|
||||||
csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
|
csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -402,9 +402,6 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
switch (feature) {
|
switch (feature) {
|
||||||
case SBI_HART_HAS_MCOUNTINHIBIT:
|
|
||||||
fstr = "mcountinhibit";
|
|
||||||
break;
|
|
||||||
case SBI_HART_HAS_SSCOFPMF:
|
case SBI_HART_HAS_SSCOFPMF:
|
||||||
fstr = "sscofpmf";
|
fstr = "sscofpmf";
|
||||||
break;
|
break;
|
||||||
@@ -613,26 +610,22 @@ __mhpm_skip:
|
|||||||
if (!trap.cause)
|
if (!trap.cause)
|
||||||
hfeatures->priv_version = SBI_HART_PRIV_VER_1_10;
|
hfeatures->priv_version = SBI_HART_PRIV_VER_1_10;
|
||||||
|
|
||||||
/* Detect if hart supports MCOUNTINHIBIT feature */
|
/* Detect if hart supports Priv v1.11 */
|
||||||
val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap);
|
val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap);
|
||||||
if (!trap.cause) {
|
if (!trap.cause &&
|
||||||
csr_write_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap, val);
|
(hfeatures->priv_version >= SBI_HART_PRIV_VER_1_10))
|
||||||
if (!trap.cause) {
|
|
||||||
hfeatures->priv_version = SBI_HART_PRIV_VER_1_11;
|
hfeatures->priv_version = SBI_HART_PRIV_VER_1_11;
|
||||||
hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detect if hart has menvcfg CSR */
|
/* Detect if hart has menvcfg CSR */
|
||||||
csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap);
|
csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap);
|
||||||
if (!trap.cause) {
|
if (!trap.cause &&
|
||||||
|
(hfeatures->priv_version >= SBI_HART_PRIV_VER_1_11)) {
|
||||||
hfeatures->priv_version = SBI_HART_PRIV_VER_1_12;
|
hfeatures->priv_version = SBI_HART_PRIV_VER_1_12;
|
||||||
hfeatures->features |= SBI_HART_HAS_MENVCFG;
|
hfeatures->features |= SBI_HART_HAS_MENVCFG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Counter overflow/filtering is not useful without mcounter/inhibit */
|
/* Counter overflow/filtering is not useful without mcounter/inhibit */
|
||||||
if (hfeatures->features & SBI_HART_HAS_MCOUNTINHIBIT &&
|
if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
|
||||||
hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
|
|
||||||
/* Detect if hart supports sscofpmf */
|
/* Detect if hart supports sscofpmf */
|
||||||
csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap);
|
csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap);
|
||||||
if (!trap.cause)
|
if (!trap.cause)
|
||||||
|
@@ -300,7 +300,7 @@ static int pmu_ctr_start_hw(uint32_t cidx, uint64_t ival, bool ival_update)
|
|||||||
if (cidx > num_hw_ctrs || cidx == 1)
|
if (cidx > num_hw_ctrs || cidx == 1)
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
|
|
||||||
if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
|
if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11)
|
||||||
goto skip_inhibit_update;
|
goto skip_inhibit_update;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -372,7 +372,7 @@ static int pmu_ctr_stop_hw(uint32_t cidx)
|
|||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
unsigned long mctr_inhbt;
|
unsigned long mctr_inhbt;
|
||||||
|
|
||||||
if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
|
if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
|
mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
|
||||||
@@ -528,7 +528,7 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo
|
|||||||
!sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
|
!sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
|
||||||
return fixed_ctr;
|
return fixed_ctr;
|
||||||
|
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11)
|
||||||
mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
|
mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT);
|
||||||
for (i = 0; i < num_hw_events; i++) {
|
for (i = 0; i < num_hw_events; i++) {
|
||||||
temp = &hw_event_map[i];
|
temp = &hw_event_map[i];
|
||||||
@@ -555,7 +555,7 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo
|
|||||||
if (active_events[hartid][cbase] != SBI_PMU_EVENT_IDX_INVALID)
|
if (active_events[hartid][cbase] != SBI_PMU_EVENT_IDX_INVALID)
|
||||||
continue;
|
continue;
|
||||||
/* If mcountinhibit is supported, the bit must be enabled */
|
/* If mcountinhibit is supported, the bit must be enabled */
|
||||||
if ((sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) &&
|
if ((sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11) &&
|
||||||
!__test_bit(cbase, &mctr_inhbt))
|
!__test_bit(cbase, &mctr_inhbt))
|
||||||
continue;
|
continue;
|
||||||
/* We found a valid counter that is not started yet */
|
/* We found a valid counter that is not started yet */
|
||||||
@@ -730,7 +730,7 @@ void sbi_pmu_exit(struct sbi_scratch *scratch)
|
|||||||
{
|
{
|
||||||
u32 hartid = current_hartid();
|
u32 hartid = current_hartid();
|
||||||
|
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11)
|
||||||
csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
|
csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
|
||||||
|
|
||||||
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
||||||
|
Reference in New Issue
Block a user