summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sbi/riscv_asm.h2
-rw-r--r--lib/sbi/riscv_asm.c10
-rw-r--r--lib/sbi/sbi_hart.c16
3 files changed, 11 insertions, 17 deletions
diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h
index 0d675f65..6c5c7299 100644
--- a/include/sbi/riscv_asm.h
+++ b/include/sbi/riscv_asm.h
@@ -191,7 +191,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long log2len);
int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
- unsigned long *log2len_out);
+ unsigned long *size);
#endif /* !__ASSEMBLY__ */
diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c
index 79c45f5d..24f87710 100644
--- a/lib/sbi/riscv_asm.c
+++ b/lib/sbi/riscv_asm.c
@@ -249,16 +249,16 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
}
int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
- unsigned long *log2len_out)
+ unsigned long *size)
{
int pmpcfg_csr, pmpcfg_shift, pmpaddr_csr;
unsigned long cfgmask, pmpcfg, prot;
unsigned long t1, addr, log2len;
/* check parameters */
- if (n >= PMP_COUNT || !prot_out || !addr_out || !log2len_out)
+ if (n >= PMP_COUNT || !prot_out || !addr_out || !size)
return SBI_EINVAL;
- *prot_out = *addr_out = *log2len_out = 0;
+ *prot_out = *addr_out = *size = 0;
/* calculate PMP register and offset */
#if __riscv_xlen == 32
@@ -299,7 +299,9 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
/* return details */
*prot_out = prot;
*addr_out = addr;
- *log2len_out = log2len;
+
+ if (log2len < __riscv_xlen)
+ *size = (1UL << log2len);
return 0;
}
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index aa326154..e71725ce 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -125,20 +125,16 @@ unsigned long log2roundup(unsigned long x)
void sbi_hart_pmp_dump(struct sbi_scratch *scratch)
{
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
- unsigned long prot, addr, size, l2l;
+ unsigned long prot, addr, size;
unsigned int i;
if (!sbi_platform_has_pmp(plat))
return;
for (i = 0; i < PMP_COUNT; i++) {
- pmp_get(i, &prot, &addr, &l2l);
+ pmp_get(i, &prot, &addr, &size);
if (!(prot & PMP_A))
continue;
- if (l2l < __riscv_xlen)
- size = (1UL << l2l);
- else
- size = 0;
#if __riscv_xlen == 32
sbi_printf("PMP%d : 0x%08lx-0x%08lx (A",
#else
@@ -160,20 +156,16 @@ void sbi_hart_pmp_dump(struct sbi_scratch *scratch)
int sbi_hart_pmp_check_addr(struct sbi_scratch *scratch, unsigned long addr,
unsigned long attr)
{
- unsigned long prot, size, l2l, i, tempaddr;
+ unsigned long prot, size, i, tempaddr;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
if (!sbi_platform_has_pmp(plat))
return SBI_OK;
for (i = 0; i < PMP_COUNT; i++) {
- pmp_get(i, &prot, &tempaddr, &l2l);
+ pmp_get(i, &prot, &tempaddr, &size);
if (!(prot & PMP_A))
continue;
- if (l2l < __riscv_xlen)
- size = (1UL << l2l);
- else
- size = 0;
if (tempaddr <= addr && addr <= tempaddr + size)
if (!(prot & attr))
return SBI_INVALID_ADDR;