You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/09/20 17:10:55 UTC

[nuttx] branch master updated: riscv/riscv_pmp.c: fix broken TOR checks

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f5a6930e8 riscv/riscv_pmp.c: fix broken TOR checks
8f5a6930e8 is described below

commit 8f5a6930e80579ad852786b8464bbb7246d39dca
Author: Eero Nurkkala <ee...@offcode.fi>
AuthorDate: Wed Sep 20 15:18:20 2023 +0300

    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 <ee...@offcode.fi>
---
 arch/risc-v/src/common/riscv_pmp.c | 31 +++----------------------------
 1 file changed, 3 insertions(+), 28 deletions(-)

diff --git a/arch/risc-v/src/common/riscv_pmp.c b/arch/risc-v/src/common/riscv_pmp.c
index bf0b19a210..652a6d5614 100644
--- a/arch/risc-v/src/common/riscv_pmp.c
+++ b/arch/risc-v/src/common/riscv_pmp.c
@@ -32,6 +32,7 @@
 #include <nuttx/compiler.h>
 #include <nuttx/arch.h>
 #include <nuttx/irq.h>
+#include <nuttx/lib/math32.h>
 
 #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)
         {