diff options
author | Anup Patel <apatel@ventanamicro.com> | 2023-11-19 18:32:10 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2023-11-22 20:42:24 +0530 |
commit | 16bb9305338b4ae87d95ce776cf029accf07bc49 (patch) | |
tree | f61160369cf30e93c919a6d2e2f65cee81a7c207 | |
parent | dc0bb19bd2f969e8c2b8c55a71b3ae569eedfaf6 (diff) | |
download | opensbi-16bb9305338b4ae87d95ce776cf029accf07bc49.zip opensbi-16bb9305338b4ae87d95ce776cf029accf07bc49.tar.gz opensbi-16bb9305338b4ae87d95ce776cf029accf07bc49.tar.bz2 |
lib: sbi: Fix PMP granularity handling in sbi_hart_map_saddr()
The sbi_hart_map_saddr() must create PMP mapping of size greater
than or equal to PMP granularity otherwise PMP mapping does not
work when size parameter less than sbi_hart_pmp_granularity(scratch).
Fixes: 6e44ef686a9b ("lib: sbi: Add functions to map/unmap shared memory")
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
-rw-r--r-- | lib/sbi/sbi_hart.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 77eef49..bf8792a 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -508,7 +508,8 @@ int sbi_hart_map_saddr(unsigned long addr, unsigned long size) if (is_pmp_entry_mapped(SBI_SMEPMP_RESV_ENTRY)) return SBI_ENOSPC; - for (order = log2roundup(size) ; order <= __riscv_xlen; order++) { + for (order = log2roundup(MAX(sbi_hart_pmp_granularity(scratch), size)); + order <= __riscv_xlen; order++) { if (order < __riscv_xlen) { base = addr & ~((1UL << order) - 1UL); if ((base <= addr) && |