From 2966510eedf03e47e13f3e1a88039bd4199c1085 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 11 May 2020 11:42:54 +0530 Subject: [PATCH] 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 Reviewed-by: Atish Patra --- lib/sbi/sbi_hart.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index c0eb6ca1..e62992d6 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -308,28 +308,20 @@ done: sbi_strncpy(features_str, "none", nfstr); } -static void sbi_hart_set_feature(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) +static void hart_detect_features(struct sbi_scratch *scratch) { struct sbi_trap_info trap = {0}; - unsigned long feature = 0; + unsigned long *hart_features; unsigned long csr_val; + hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset); + /* Detect if hart supports PMP feature */ csr_val = csr_read_allowed(CSR_PMPCFG0, (unsigned long)&trap); if (!trap.cause) { csr_write_allowed(CSR_PMPCFG0, (unsigned long)&trap, csr_val); if (!trap.cause) - feature |= SBI_HART_HAS_PMP; + *hart_features |= SBI_HART_HAS_PMP; } /* 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_val); if (!trap.cause) - feature |= SBI_HART_HAS_SCOUNTEREN; + *hart_features |= SBI_HART_HAS_SCOUNTEREN; } /* 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_val); if (!trap.cause) - feature |= SBI_HART_HAS_MCOUNTEREN; + *hart_features |= SBI_HART_HAS_MCOUNTEREN; } /* Detect if hart supports time CSR */ trap.cause = 0; csr_read_allowed(CSR_TIME, (unsigned long)&trap); if (!trap.cause) - feature |= SBI_HART_HAS_TIME; - - sbi_hart_set_feature(scratch, feature); + *hart_features |= SBI_HART_HAS_TIME; } 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 (misa_extension('H')) sbi_hart_expected_trap = &__sbi_expected_trap_hext; + hart_features_offset = sbi_scratch_alloc_offset( - sizeof(hart_features), - "HART_FEATURES"); + sizeof(*hart_features), + "HART_FEATURES"); if (!hart_features_offset) return SBI_ENOMEM; } hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset); *hart_features = 0; - sbi_hart_detect_features(scratch); + + hart_detect_features(scratch); mstatus_init(scratch, hartid);