Message ID | 20240926131659.1477-1-popeblei@gmail.com |
---|---|
State | New |
Headers | show |
Series | Support TOR mode in pmp_set | expand |
Dear all: I added support for the TOR mode in the pmp_set function. When the log2len value is 0, we will configure the PMP according to the TOR mode. Best Regards! On Thu, Sep 26, 2024 at 9:17 PM Pope B.Lei <popeblei@gmail.com> wrote: > > Signed-off-by: Pope B.Lei <popeblei@gmail.com> > --- > include/sbi/riscv_encoding.h | 2 ++ > lib/sbi/riscv_asm.c | 19 ++++++++++++++++--- > 2 files changed, 18 insertions(+), 3 deletions(-) > > diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h > index 980abdb..387c011 100644 > --- a/include/sbi/riscv_encoding.h > +++ b/include/sbi/riscv_encoding.h > @@ -154,6 +154,8 @@ > #define PMP_A_NAPOT _UL(0x18) > #define PMP_L _UL(0x80) > > +#define PMP_USE_TOR _UL(0x00) > + > #define PMP_SHIFT 2 > #define PMP_COUNT 64 > #if __riscv_xlen == 64 > diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c > index c7d75ac..4518b2c 100644 > --- a/lib/sbi/riscv_asm.c > +++ b/lib/sbi/riscv_asm.c > @@ -309,7 +309,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, > unsigned long addrmask, pmpaddr; > > /* check parameters */ > - if (n >= PMP_COUNT || log2len > __riscv_xlen || log2len < PMP_SHIFT) > + if (n >= PMP_COUNT || log2len > __riscv_xlen || (log2len < PMP_SHIFT && log2len != PMP_USE_TOR )) > return SBI_EINVAL; > > /* calculate PMP register and offset */ > @@ -326,13 +326,26 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, > > /* encode PMP config */ > prot &= ~PMP_A; > - prot |= (log2len == PMP_SHIFT) ? PMP_A_NA4 : PMP_A_NAPOT; > + > + switch(log2len){ > + case PMP_USE_TOR:{ > + prot |= PMP_A_TOR; > + break; > + } > + case PMP_SHIFT:{ > + prot |= PMP_A_NA4; > + break; > + } > + default: > + prot |= PMP_A_NAPOT; > + } > + > cfgmask = ~(0xffUL << pmpcfg_shift); > pmpcfg = (csr_read_num(pmpcfg_csr) & cfgmask); > pmpcfg |= ((prot << pmpcfg_shift) & ~cfgmask); > > /* encode PMP address */ > - if (log2len == PMP_SHIFT) { > + if (log2len == PMP_SHIFT || log2len == PMP_USE_TOR) { > pmpaddr = (addr >> PMP_SHIFT); > } else { > if (log2len == __riscv_xlen) { > -- > 2.35.2.windows.1 >
diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 980abdb..387c011 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -154,6 +154,8 @@ #define PMP_A_NAPOT _UL(0x18) #define PMP_L _UL(0x80) +#define PMP_USE_TOR _UL(0x00) + #define PMP_SHIFT 2 #define PMP_COUNT 64 #if __riscv_xlen == 64 diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index c7d75ac..4518b2c 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -309,7 +309,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, unsigned long addrmask, pmpaddr; /* check parameters */ - if (n >= PMP_COUNT || log2len > __riscv_xlen || log2len < PMP_SHIFT) + if (n >= PMP_COUNT || log2len > __riscv_xlen || (log2len < PMP_SHIFT && log2len != PMP_USE_TOR )) return SBI_EINVAL; /* calculate PMP register and offset */ @@ -326,13 +326,26 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, /* encode PMP config */ prot &= ~PMP_A; - prot |= (log2len == PMP_SHIFT) ? PMP_A_NA4 : PMP_A_NAPOT; + + switch(log2len){ + case PMP_USE_TOR:{ + prot |= PMP_A_TOR; + break; + } + case PMP_SHIFT:{ + prot |= PMP_A_NA4; + break; + } + default: + prot |= PMP_A_NAPOT; + } + cfgmask = ~(0xffUL << pmpcfg_shift); pmpcfg = (csr_read_num(pmpcfg_csr) & cfgmask); pmpcfg |= ((prot << pmpcfg_shift) & ~cfgmask); /* encode PMP address */ - if (log2len == PMP_SHIFT) { + if (log2len == PMP_SHIFT || log2len == PMP_USE_TOR) { pmpaddr = (addr >> PMP_SHIFT); } else { if (log2len == __riscv_xlen) {
Signed-off-by: Pope B.Lei <popeblei@gmail.com> --- include/sbi/riscv_encoding.h | 2 ++ lib/sbi/riscv_asm.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-)