summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sbi/sbi_hart.h6
-rw-r--r--lib/sbi/sbi_hart.c46
-rw-r--r--lib/sbi/sbi_init.c2
-rw-r--r--lib/sbi/sbi_timer.c2
-rw-r--r--lib/utils/fdt/fdt_fixup.c7
5 files changed, 32 insertions, 31 deletions
diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h
index a624dfd..ac7a067 100644
--- a/include/sbi/sbi_hart.h
+++ b/include/sbi/sbi_hart.h
@@ -41,9 +41,9 @@ void sbi_hart_delegation_dump(struct sbi_scratch *scratch);
void sbi_hart_pmp_dump(struct sbi_scratch *scratch);
int sbi_hart_pmp_check_addr(struct sbi_scratch *scratch, unsigned long daddr,
unsigned long attr);
-bool sbi_hart_has_feature(u32 hartid, unsigned long feature);
-unsigned long sbi_hart_get_features(u32 hartid);
-void sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr);
+bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature);
+void sbi_hart_get_features_str(struct sbi_scratch *scratch,
+ char *features_str, int nfstr);
void __attribute__((noreturn)) sbi_hart_hang(void);
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index f101395..c0eb6ca 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -42,9 +42,9 @@ static void mstatus_init(struct sbi_scratch *scratch, u32 hartid)
/* Enable user/supervisor use of perf counters */
if (misa_extension('S') &&
- sbi_hart_has_feature(hartid, SBI_HART_HAS_SCOUNTEREN))
+ sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN))
csr_write(CSR_SCOUNTEREN, -1);
- if (!sbi_hart_has_feature(hartid, SBI_HART_HAS_MCOUNTEREN))
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN))
csr_write(CSR_MCOUNTEREN, -1);
/* Disable all interrupts */
@@ -130,7 +130,7 @@ void sbi_hart_pmp_dump(struct sbi_scratch *scratch)
unsigned long prot, addr, size;
unsigned int i;
- if (!sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_PMP))
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_PMP))
return;
for (i = 0; i < PMP_COUNT; i++) {
@@ -160,7 +160,7 @@ int sbi_hart_pmp_check_addr(struct sbi_scratch *scratch, unsigned long addr,
{
unsigned long prot, size, i, tempaddr;
- if (!sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_PMP))
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_PMP))
return SBI_OK;
for (i = 0; i < PMP_COUNT; i++) {
@@ -182,7 +182,7 @@ static int pmp_init(struct sbi_scratch *scratch, u32 hartid)
ulong prot, addr, log2size;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
- if (!sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_PMP))
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_PMP))
return 0;
/* Firmware PMP region to protect OpenSBI firmware */
@@ -210,12 +210,17 @@ static int pmp_init(struct sbi_scratch *scratch, u32 hartid)
return 0;
}
-bool sbi_hart_has_feature(u32 hartid, unsigned long feature)
+/**
+ * Check whether a particular hart feature is available
+ *
+ * @param scratch pointer to the HART scratch space
+ * @param feature the feature to check
+ * @returns true (feature available) or false (feature not available)
+ */
+bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature)
{
unsigned long *hart_features;
- struct sbi_scratch *scratch;
- scratch = sbi_hartid_to_scratch(hartid);
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
if (*hart_features & feature)
@@ -224,12 +229,10 @@ bool sbi_hart_has_feature(u32 hartid, unsigned long feature)
return false;
}
-unsigned long sbi_hart_get_features(u32 hartid)
+static unsigned long hart_get_features(struct sbi_scratch *scratch)
{
unsigned long *hart_features;
- struct sbi_scratch *scratch;
- scratch = sbi_hartid_to_scratch(hartid);
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
return *hart_features;
@@ -265,13 +268,14 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
/**
* Get the hart features in string format
*
- * @param hartid Hart ID of the hart whose feature list is requested
+ * @param scratch pointer to the HART scratch space
* @param features_str pointer to a char array where the features string will be
* updated
* @param nfstr length of the features_str. The feature string will be truncated
* if nfstr is not long enough.
*/
-void sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr)
+void sbi_hart_get_features_str(struct sbi_scratch *scratch,
+ char *features_str, int nfstr)
{
unsigned long features, feat = 1UL;
char *temp;
@@ -281,7 +285,7 @@ void sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr)
return;
sbi_memset(features_str, 0, nfstr);
- features = sbi_hart_get_features(hartid);
+ features = hart_get_features(scratch);
if (!features)
goto done;
@@ -304,26 +308,22 @@ done:
sbi_strncpy(features_str, "none", nfstr);
}
-static void sbi_hart_set_feature(u32 hartid, unsigned long feature)
+static void sbi_hart_set_feature(struct sbi_scratch *scratch,
+ unsigned long feature)
{
unsigned long *hart_features;
- struct sbi_scratch *scratch;
- scratch = sbi_hartid_to_scratch(hartid);
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
*hart_features = *hart_features | feature;
}
-static void sbi_hart_detect_features(u32 hartid)
+static void sbi_hart_detect_features(struct sbi_scratch *scratch)
{
struct sbi_trap_info trap = {0};
unsigned long feature = 0;
unsigned long csr_val;
- if (hartid != current_hartid())
- sbi_hart_hang();
-
/* Detect if hart supports PMP feature */
csr_val = csr_read_allowed(CSR_PMPCFG0, (unsigned long)&trap);
if (!trap.cause) {
@@ -358,7 +358,7 @@ static void sbi_hart_detect_features(u32 hartid)
if (!trap.cause)
feature |= SBI_HART_HAS_TIME;
- sbi_hart_set_feature(hartid, feature);
+ sbi_hart_set_feature(scratch, feature);
}
int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
@@ -378,7 +378,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
hart_features = sbi_scratch_offset_ptr(scratch, hart_features_offset);
*hart_features = 0;
- sbi_hart_detect_features(hartid);
+ sbi_hart_detect_features(scratch);
mstatus_init(scratch, hartid);
diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c
index c573fd8..7b8d6a7 100644
--- a/lib/sbi/sbi_init.c
+++ b/lib/sbi/sbi_init.c
@@ -66,7 +66,7 @@ static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
sbi_printf("Boot HART ID : %u\n", hartid);
misa_string(xlen, str, sizeof(str));
sbi_printf("Boot HART ISA : %s\n", str);
- sbi_hart_get_features_str(hartid, str, sizeof(str));
+ sbi_hart_get_features_str(scratch, str, sizeof(str));
sbi_printf("BOOT HART Features : %s\n", str);
/* Firmware details */
diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c
index 4a3ea24..b571b17 100644
--- a/lib/sbi/sbi_timer.c
+++ b/lib/sbi/sbi_timer.c
@@ -114,7 +114,7 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
if (ret)
return ret;
- if (sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_TIME))
+ if (sbi_hart_has_feature(scratch, SBI_HART_HAS_TIME))
get_time_val = get_ticks;
else if (sbi_platform_has_timer_value(plat))
get_time_val = sbi_platform_timer_value;
diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c
index e69ba1d..6b11b41 100644
--- a/lib/utils/fdt/fdt_fixup.c
+++ b/lib/utils/fdt/fdt_fixup.c
@@ -183,10 +183,11 @@ int fdt_reserved_memory_fixup(void *fdt)
return err;
}
- if (!sbi_hart_has_feature(current_hartid(), SBI_HART_HAS_PMP)) {
- /* update the DT with firmware start & size even if PMP is not
+ if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_PMP)) {
+ /*
+ * Update the DT with firmware start & size even if PMP is not
* supported. This makes sure that supervisor OS is always
- * aware of wheren OpenSBI resident memory area.
+ * aware of OpenSBI resident memory area.
*/
addr = scratch->fw_start & ~(scratch->fw_size - 1UL);
size = (1UL << log2roundup(scratch->fw_size));