diff --git a/arch/risc-v/src/common/riscv_pmp.c b/arch/risc-v/src/common/riscv_pmp.c index bf0b19a210f..652a6d56142 100644 --- a/arch/risc-v/src/common/riscv_pmp.c +++ b/arch/risc-v/src/common/riscv_pmp.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "riscv_internal.h" @@ -100,32 +101,6 @@ typedef struct pmp_entry_s pmp_entry_t; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: log2ceil - * - * Description: - * Calculate the up-rounded power-of-two for input. - * - * Input Parameters: - * size - The size of the PMP region. - * - * Returned Value: - * Power-of-two for argument, rounded up. - * - ****************************************************************************/ - -static uintptr_t log2ceil(uintptr_t size) -{ - uintptr_t pot = 0; - - for (size = size - 1; size > 1; size >>= 1) - { - pot++; - } - - return pot; -} - /**************************************************************************** * Name: pmp_check_addrmatch_type * @@ -191,7 +166,7 @@ static bool pmp_check_region_attrs(uintptr_t base, uintptr_t size, { /* Check that the size is not too small */ - if (size < MIN_BLOCK_SIZE) + if ((type != PMPCFG_A_TOR) && (size < MIN_BLOCK_SIZE)) { return false; } @@ -216,7 +191,7 @@ static bool pmp_check_region_attrs(uintptr_t base, uintptr_t size, { /* Get the power-of-two for size, rounded up */ - uintptr_t pot = log2ceil(size); + uintptr_t pot = LOG2_CEIL(size); if ((base & ((UINT64_C(1) << pot) - 1)) != 0) {