summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-04-23 09:22:30 +0300
committerAnup Patel <anup@brainfault.org>2020-04-27 11:27:27 +0300
commit1bb00ab3aeabde78579774eef8eadc7b7e765924 (patch)
tree119d29d80996c9db45105fa9f688ef8b1aef5265 /lib
parent9f1b72ce66d659e91013b358939e832fb27223f5 (diff)
downloadopensbi-1bb00ab3aeabde78579774eef8eadc7b7e765924.tar.xz
lib: No need to provide default PMP region using platform callbacks
The default (usually last) PMP region provides S-mode access to complete memory range not covered by other PMP regions. Currently, the default PMP region is described as platform specific PMP region which is not appropriate because all platforms need it and default PMP region should be part of generic library. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_hart.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index b5df7c4..24c3637 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -188,7 +188,7 @@ int sbi_hart_pmp_check_addr(struct sbi_scratch *scratch, unsigned long addr,
static int pmp_init(struct sbi_scratch *scratch, u32 hartid)
{
- u32 i, count;
+ u32 i, pmp_idx = 0, count;
unsigned long fw_start, fw_size_log2;
ulong prot, addr, log2size;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
@@ -196,22 +196,28 @@ static int pmp_init(struct sbi_scratch *scratch, u32 hartid)
if (!sbi_platform_has_pmp(plat))
return 0;
+ /* Firmware PMP region to protect OpenSBI firmware */
fw_size_log2 = log2roundup(scratch->fw_size);
- fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL);
-
- pmp_set(0, 0, fw_start, fw_size_log2);
+ fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL);
+ pmp_set(pmp_idx++, 0, fw_start, fw_size_log2);
+ /* Platform specific PMP regions */
count = sbi_platform_pmp_region_count(plat, hartid);
- if ((PMP_COUNT - 1) < count)
- count = (PMP_COUNT - 1);
-
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count && pmp_idx < (PMP_COUNT - 1); i++) {
if (sbi_platform_pmp_region_info(plat, hartid, i, &prot, &addr,
&log2size))
continue;
- pmp_set(i + 1, prot, addr, log2size);
+ pmp_set(pmp_idx++, prot, addr, log2size);
}
+ /*
+ * Default PMP region for allowing S-mode and U-mode access to
+ * memory not covered by:
+ * 1) Firmware PMP region
+ * 2) Platform specific PMP regions
+ */
+ pmp_set(pmp_idx++, PMP_R | PMP_W | PMP_X, 0, __riscv_xlen);
+
return 0;
}