diff --git a/arch/risc-v/src/common/riscv_pmp.c b/arch/risc-v/src/common/riscv_pmp.c index 2f63c2596d..3a9daa2ec2 100644 --- a/arch/risc-v/src/common/riscv_pmp.c +++ b/arch/risc-v/src/common/riscv_pmp.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "riscv_internal.h" @@ -89,6 +88,32 @@ typedef struct pmp_entry_s pmp_entry_t; * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: log2ceil + * + * Description: + * Calculate the up-rounded power-of-two for input. + * + * Input Parameters: + * x - Argument to calculate the power-of-two from. + * + * Returned Value: + * Power-of-two for argument, rounded up. + * + ****************************************************************************/ + +static uintptr_t log2ceil(uintptr_t x) +{ + uintptr_t pot = 0; + + for (x = x - 1; x; x >>= 1) + { + pot++; + } + + return pot; +} + /**************************************************************************** * Name: pmp_check_region_attrs * @@ -143,7 +168,7 @@ static bool pmp_check_region_attrs(uintptr_t base, uintptr_t size, /* Get the power-of-two for size, rounded up */ - if ((base & ((UINT64_C(1) << LOG2_CEIL(size)) - 1)) != 0) + if ((base & ((UINT64_C(1) << log2ceil(size)) - 1)) != 0) { /* The start address is not properly aligned with size */