riscv/riscv_pmp.c: fix broken TOR checks
PMPCFG_A_TOR region may have zero size. The pmp configuration currently fails for zero-sized TOR. This patch bypasses such a restriction. Also replace log2ceil with LOG2_CEIL from lib/math32.h. Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
This commit is contained in:
parent
a35ba1e7bc
commit
8f5a6930e8
@ -32,6 +32,7 @@
|
|||||||
#include <nuttx/compiler.h>
|
#include <nuttx/compiler.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
|
#include <nuttx/lib/math32.h>
|
||||||
|
|
||||||
#include "riscv_internal.h"
|
#include "riscv_internal.h"
|
||||||
|
|
||||||
@ -100,32 +101,6 @@ typedef struct pmp_entry_s pmp_entry_t;
|
|||||||
* Private Functions
|
* 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
|
* 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 */
|
/* Check that the size is not too small */
|
||||||
|
|
||||||
if (size < MIN_BLOCK_SIZE)
|
if ((type != PMPCFG_A_TOR) && (size < MIN_BLOCK_SIZE))
|
||||||
{
|
{
|
||||||
return false;
|
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 */
|
/* 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)
|
if ((base & ((UINT64_C(1) << pot) - 1)) != 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user