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

commit e9c33195a3f86b9a02a2894e5a9cc33725cbb052
Author: hujun5 <[email protected]>
AuthorDate: Tue Aug 12 11:02:35 2025 +0800

    arm64: add mpu_usedregion interface
    
    Add mpu_usedregion() function to query the number of MPU regions currently 
in use.
    This interface complements existing mpu_allocregion() and mpu_freeregion() 
functions,
    allowing callers to determine the occupancy of the MPU region pool.
    
    Signed-off-by: hujun5 <[email protected]>
---
 arch/arm64/src/common/arm64_mpu.c | 28 ++++++++++++++++++++++++++++
 arch/arm64/src/common/arm64_mpu.h | 16 ++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/arch/arm64/src/common/arm64_mpu.c 
b/arch/arm64/src/common/arm64_mpu.c
index 35bed5c0bc1..60286540d24 100644
--- a/arch/arm64/src/common/arm64_mpu.c
+++ b/arch/arm64/src/common/arm64_mpu.c
@@ -162,6 +162,34 @@ unsigned int mpu_allocregion(void)
   return i;
 }
 
+/****************************************************************************
+ * Name: mpu_allocregion
+ *
+ * Description:
+ *   Get the number of MPU region used
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   The the number of MPU region used
+ *
+ ****************************************************************************/
+
+unsigned int mpu_usedregion(void)
+{
+  unsigned int n = g_mpu_region[this_cpu()];
+  unsigned int count = 0;
+
+  while (n)
+    {
+      count += n & 1;
+      n >>= 1;
+    }
+
+  return count;
+}
+
 /****************************************************************************
  * Name: mpu_freeregion
  *
diff --git a/arch/arm64/src/common/arm64_mpu.h 
b/arch/arm64/src/common/arm64_mpu.h
index ff7256ab991..e88ca5b6381 100644
--- a/arch/arm64/src/common/arm64_mpu.h
+++ b/arch/arm64/src/common/arm64_mpu.h
@@ -383,6 +383,22 @@ unsigned int mpu_allocregion(void);
 
 void mpu_freeregion(unsigned int region);
 
+/****************************************************************************
+ * Name: mpu_allocregion
+ *
+ * Description:
+ *   Get the number of MPU region used
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   The the number of MPU region used
+ *
+ ****************************************************************************/
+
+unsigned int mpu_usedregion(void);
+
 /****************************************************************************
  * Name: arm64_mpu_enable
  *

Reply via email to