lib: sbi: simplify pmp_set(), pmp_get()
PATCH v2 1/1 lib: sbi: simplify pmp_set(), pmp_get()
pmpcfg_csr and pmpcfg_shift are only negative for an unexpected value of __riscv_xlen. We can immediately return in this case.
---
v2:
adjust pmp_get too
--- lib/sbi/riscv_asm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
lib/sbi/riscv_asm.c +2 -8
@@ -261,12 +261,9 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* encode PMP config */ prot &= ~PMP_A ;
@@ -315,12 +312,9 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* decode PMP config */ cfgmask = (0xffUL << pmpcfg_shift);
Signature · 1 line
2.33.1
PATCH v2 1/1 lib: sbi: simplify pmp_set(), pmp_get()
Quoted 7 lines · Heinrich Schuchardt heinrich.schuchardt at canonical.com
pmpcfg_csrandpmpcfg_shiftare only negative for an unexpected value of__riscv_xlen. We can immediately return in this case.Signed-off-by Heinrich Schuchardt <[email protected]>---
v2:
adjustpmp_gettoo
Looks good to me. Thx.
Quoted 40 lines
---
lib/sbi/riscv_asm.c| 10 ++--------1 file changed, 2 insertions(+), 8 deletions(-)lib/sbi/riscv_asm.c +1
-4@@ -261,12 +261,9 @@ int pmp_set(unsigned int n, unsigned long prot, unsignedlong addr, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* encode PMP config */ prot &= ~PMP_A;lib/sbi/riscv_asm.c +1
-4@@ -315,12 +312,9 @@ int pmp_get(unsigned int n, unsigned long *prot_out,unsigned long *addr_out, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* decode PMP config */ cfgmask = (0xffUL << pmpcfg_shift);--
2.33.1
PATCH v2 1/1 lib: sbi: simplify pmp_set(), pmp_get()
In reply to Heinrich SchuchardtQuoted 5 lines · Heinrich Schuchardt
pmpcfg_csrandpmpcfg_shiftare only negative for an unexpected value of__riscv_xlen. We can immediately return in this case.Signed-off-by Heinrich Schuchardt <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 42 lines
---
v2:
adjustpmp_gettoo--- lib/sbi/riscv_asm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)lib/sbi/riscv_asm.c +2
-9@@ -261,12 +261,9 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* encode PMP config */ prot &= ~PMP_A ;@@ -315,12 +312,9 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* decode PMP config */ cfgmask = (0xffUL << pmpcfg_shift); --2.33.1
Anup Patel
AppliedPATCH v2 1/1 lib: sbi: simplify pmp_set(), pmp_get()
Quoted 4 lines · Anup Patel
Quoted 1 line · Heinrich Schuchardt
Quoted 8 lines
Quoted 4 lines
pmpcfg_csrandpmpcfg_shiftare only negative for an unexpected value of__riscv_xlen. We can immediately return in this case.Signed-off-by Heinrich Schuchardt <[email protected]>Looks good to me.
Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 46 lines
Regards,
AnupQuoted 42 lines
---
v2:
adjustpmp_gettoo--- lib/sbi/riscv_asm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)lib/sbi/riscv_asm.c +2
-9@@ -261,12 +261,9 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* encode PMP config */ prot &= ~PMP_A ;@@ -315,12 +312,9 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out, pmpcfg_csr = (CSR_PMPCFG0 + (n >>2 )) & ~1 ; pmpcfg_shift = (n &7 ) <<3 ;#else - pmpcfg_csr =-1 ; - pmpcfg_shift =-1 ; +return SBI_ENOTSUPP ;#endif pmpaddr_csr =CSR_PMPADDR0 + n; -if (pmpcfg_csr <0 || pmpcfg_shift <0 ) -return SBI_ENOTSUPP ;/* decode PMP config */ cfgmask = (0xffUL << pmpcfg_shift); --2.33.1