lib: sbi: Few cosmetic improvements to HART feature detection

This patch does few cosmetic improvements to HART feature detection:
1. Remove sbi_ perfix from HART feature detection functions
   because all local/static functions in sbi_hart.c don't have
   sbi_ prefix
2. Remove sbi_hart_set_feature() because it's quite small and
   local/static in sbi_hart.c

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
Anup Patel
2020-05-11 11:42:54 +05:30
committed by Anup Patel
parent 63b0f5f71a
commit 2966510eed

View File

@@ -308,28 +308,20 @@ done:
sbi_strncpy(features_str, "none", nfstr); sbi_strncpy(features_str, "none", nfstr);
} }
static void sbi_hart_set_feature(struct sbi_scratch *scratch, static void hart_detect_features(struct sbi_scratch *scratch)
unsigned long feature)
{
unsigned long *hart_features;
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
*hart_features = *hart_features | feature;
}
static void sbi_hart_detect_features(struct sbi_scratch *scratch)
{ {
struct sbi_trap_info trap = {0}; struct sbi_trap_info trap = {0};
unsigned long feature = 0; unsigned long *hart_features;
unsigned long csr_val; unsigned long csr_val;
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
/* Detect if hart supports PMP feature */ /* Detect if hart supports PMP feature */
csr_val = csr_read_allowed(CSR_PMPCFG0, (unsigned long)&trap); csr_val = csr_read_allowed(CSR_PMPCFG0, (unsigned long)&trap);
if (!trap.cause) { if (!trap.cause) {
csr_write_allowed(CSR_PMPCFG0, (unsigned long)&trap, csr_val); csr_write_allowed(CSR_PMPCFG0, (unsigned long)&trap, csr_val);
if (!trap.cause) if (!trap.cause)
feature |= SBI_HART_HAS_PMP; *hart_features |= SBI_HART_HAS_PMP;
} }
/* Detect if hart supports SCOUNTEREN feature */ /* Detect if hart supports SCOUNTEREN feature */
@@ -339,7 +331,7 @@ static void sbi_hart_detect_features(struct sbi_scratch *scratch)
csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap, csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap,
csr_val); csr_val);
if (!trap.cause) if (!trap.cause)
feature |= SBI_HART_HAS_SCOUNTEREN; *hart_features |= SBI_HART_HAS_SCOUNTEREN;
} }
/* Detect if hart supports MCOUNTEREN feature */ /* Detect if hart supports MCOUNTEREN feature */
@@ -349,16 +341,14 @@ static void sbi_hart_detect_features(struct sbi_scratch *scratch)
csr_write_allowed(CSR_MCOUNTEREN, (unsigned long)&trap, csr_write_allowed(CSR_MCOUNTEREN, (unsigned long)&trap,
csr_val); csr_val);
if (!trap.cause) if (!trap.cause)
feature |= SBI_HART_HAS_MCOUNTEREN; *hart_features |= SBI_HART_HAS_MCOUNTEREN;
} }
/* Detect if hart supports time CSR */ /* Detect if hart supports time CSR */
trap.cause = 0; trap.cause = 0;
csr_read_allowed(CSR_TIME, (unsigned long)&trap); csr_read_allowed(CSR_TIME, (unsigned long)&trap);
if (!trap.cause) if (!trap.cause)
feature |= SBI_HART_HAS_TIME; *hart_features |= SBI_HART_HAS_TIME;
sbi_hart_set_feature(scratch, feature);
} }
int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot) int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
@@ -369,16 +359,18 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
if (cold_boot) { if (cold_boot) {
if (misa_extension('H')) if (misa_extension('H'))
sbi_hart_expected_trap = &__sbi_expected_trap_hext; sbi_hart_expected_trap = &__sbi_expected_trap_hext;
hart_features_offset = sbi_scratch_alloc_offset( hart_features_offset = sbi_scratch_alloc_offset(
sizeof(hart_features), sizeof(*hart_features),
"HART_FEATURES"); "HART_FEATURES");
if (!hart_features_offset) if (!hart_features_offset)
return SBI_ENOMEM; return SBI_ENOMEM;
} }
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset); hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
*hart_features = 0; *hart_features = 0;
sbi_hart_detect_features(scratch);
hart_detect_features(scratch);
mstatus_init(scratch, hartid); mstatus_init(scratch, hartid);