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/07/15 07:11:13 UTC

[nuttx] branch master updated (6c1a7c4265 -> cafbbb1ded)

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

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


    from 6c1a7c4265 support esp32c3-devkit gdbstub use wifi
     new 09da8fb651 armv7/8 cache:CSSELR should be set before getting cache info
     new 22d1059c97 armv7/8 cache: add up_get_xcache_size() support
     new 665a140b21 armv7/v8:Fix configuration csselr default configuration error.
     new 823c3b32e7 armv8m:fix warning up_get_cache_size defined but not used.
     new 9c2bc0edbe armv7m/v8m:Restore the CSSELR state before setting.
     new cafbbb1ded armv7amr/v8m:Modify hardcodes to macro definitions and update commit.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/arm/src/armv7-a/arm_cache.c      |  76 +++++++++++++-----
 arch/arm/src/armv7-a/arm_l2cc_pl310.c |  23 +++++-
 arch/arm/src/armv7-a/cp15_cacheops.c  |  84 ++++++++++++++++---
 arch/arm/src/armv7-a/cp15_cacheops.h  |  44 ++++++++--
 arch/arm/src/armv7-a/l2cc.h           |  23 +++++-
 arch/arm/src/armv7-m/arm_cache.c      | 147 +++++++++++++++++++++++++++++++---
 arch/arm/src/armv7-m/nvic.h           |   4 +-
 arch/arm/src/armv7-r/arm_cache.c      |  76 +++++++++++++-----
 arch/arm/src/armv7-r/arm_l2cc_pl310.c |  23 +++++-
 arch/arm/src/armv7-r/cp15_cacheops.c  |  84 ++++++++++++++++---
 arch/arm/src/armv7-r/cp15_cacheops.h  |  44 ++++++++--
 arch/arm/src/armv7-r/l2cc.h           |  23 +++++-
 arch/arm/src/armv8-m/arm_cache.c      | 147 +++++++++++++++++++++++++++++++---
 arch/arm/src/armv8-m/nvic.h           |   4 +-
 include/nuttx/cache.h                 |  40 +++++++++
 15 files changed, 722 insertions(+), 120 deletions(-)


[nuttx] 05/06: armv7m/v8m:Restore the CSSELR state before setting.

Posted by xi...@apache.org.
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 9c2bc0edbea1e8658427743df06c0afd5fa10cd5
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Fri Jun 23 23:52:06 2023 +0800

    armv7m/v8m:Restore the CSSELR state before setting.
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 arch/arm/src/armv7-a/cp15_cacheops.c |  6 +++---
 arch/arm/src/armv7-m/arm_cache.c     | 17 ++++++++++++-----
 arch/arm/src/armv7-r/cp15_cacheops.c |  6 +++---
 arch/arm/src/armv8-m/arm_cache.c     | 17 ++++++++++++-----
 4 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/arch/arm/src/armv7-a/cp15_cacheops.c b/arch/arm/src/armv7-a/cp15_cacheops.c
index d7bf4a4e5e..562cab4723 100644
--- a/arch/arm/src/armv7-a/cp15_cacheops.c
+++ b/arch/arm/src/armv7-a/cp15_cacheops.c
@@ -52,9 +52,7 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
 
   csselr = CP15_GET(CSSELR);
 
-  csselr = (csselr & ~0x01) | (icache & 0x01);
-
-  CP15_SET(CSSELR, csselr);
+  CP15_SET(CSSELR, (csselr & ~0x01) | (icache & 0x01));
 
   ccsidr = CP15_GET(CCSIDR);
 
@@ -68,6 +66,8 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
       *ways = ((ccsidr >> 3) & 0x3ff) + 1;
     }
 
+  CP15_SET(CSSELR, csselr);   /* restore csselr */
+
   return (1 << ((ccsidr & 0x7) + 2)) * 4;
 }
 
diff --git a/arch/arm/src/armv7-m/arm_cache.c b/arch/arm/src/armv7-m/arm_cache.c
index 88bc5ac2b5..f326316f1d 100644
--- a/arch/arm/src/armv7-m/arm_cache.c
+++ b/arch/arm/src/armv7-m/arm_cache.c
@@ -129,17 +129,20 @@ static size_t up_get_cache_linesize(bool icache)
 
   if (icache)
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
     }
   else
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
     }
 
-  putreg32(csselr, NVIC_CSSELR);
   ccsidr = getreg32(NVIC_CCSIDR);
   sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
 
+  putreg32(csselr, NVIC_CSSELR);    /* restore csselr */
+
   return 1 << sshift;
 }
 
@@ -170,11 +173,13 @@ static size_t up_get_cache_size(bool icache)
 
   if (icache)
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
     }
   else
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
     }
 
   ccsidr = getreg32(NVIC_CCSIDR);
@@ -183,6 +188,8 @@ static size_t up_get_cache_size(bool icache)
   sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
   line   = 1 << sshift;
 
+  putreg32(csselr, NVIC_CSSELR);    /* restore csselr */
+
   return sets * ways * line;
 }
 #endif
diff --git a/arch/arm/src/armv7-r/cp15_cacheops.c b/arch/arm/src/armv7-r/cp15_cacheops.c
index 74da551a81..94f4aa3d3a 100644
--- a/arch/arm/src/armv7-r/cp15_cacheops.c
+++ b/arch/arm/src/armv7-r/cp15_cacheops.c
@@ -52,9 +52,7 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
 
   csselr = CP15_GET(CSSELR);
 
-  csselr = (csselr & ~0x01) | (icache & 0x01);
-
-  CP15_SET(CSSELR, csselr);
+  CP15_SET(CSSELR, (csselr & ~0x01) | (icache & 0x01));
 
   ccsidr = CP15_GET(CCSIDR);
 
@@ -68,6 +66,8 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
       *ways = ((ccsidr >> 3) & 0x3ff) + 1;
     }
 
+  CP15_SET(CSSELR, csselr);   /* restore csselr */
+
   return (1 << ((ccsidr & 0x7) + 2)) * 4;
 }
 
diff --git a/arch/arm/src/armv8-m/arm_cache.c b/arch/arm/src/armv8-m/arm_cache.c
index 35aa14d992..e7a7e504ed 100644
--- a/arch/arm/src/armv8-m/arm_cache.c
+++ b/arch/arm/src/armv8-m/arm_cache.c
@@ -129,17 +129,20 @@ static size_t up_get_cache_linesize(bool icache)
 
   if (icache)
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
     }
   else
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
     }
 
-  putreg32(csselr, NVIC_CSSELR);
   ccsidr = getreg32(NVIC_CCSIDR);
   sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
 
+  putreg32(csselr, NVIC_CSSELR);    /* restore csselr */
+
   return 1 << sshift;
 }
 
@@ -170,11 +173,13 @@ static size_t up_get_cache_size(bool icache)
 
   if (icache)
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
     }
   else
     {
-      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
+      putreg32((csselr & ~NVIC_CSSELR_IND) |
+                NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
     }
 
   ccsidr = getreg32(NVIC_CCSIDR);
@@ -183,6 +188,8 @@ static size_t up_get_cache_size(bool icache)
   sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
   line   = 1 << sshift;
 
+  putreg32(csselr, NVIC_CSSELR);    /* restore csselr */
+
   return sets * ways * line;
 }
 #endif


[nuttx] 01/06: armv7/8 cache:CSSELR should be set before getting cache info

Posted by xi...@apache.org.
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 09da8fb651d8b8738178a7b546d0e3f733cac7b7
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Sat May 6 16:19:42 2023 +0800

    armv7/8 cache:CSSELR should be set before getting cache info
    
    According to the ARMv7a/r/m and ARMv8m architecture manuals
    The allowed values are
    0 Data or unified cache.
    1 Instruction cache.
    
    "One CCSIDR is implemented for each cache that can be accessed by the processor. CSSELR selects which Cache Size ID Register is accessible, see c0, Cache Size Selection Register (CSSELR)."
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 arch/arm/src/armv7-a/arm_cache.c      | 52 +++++++----------------
 arch/arm/src/armv7-a/arm_l2cc_pl310.c |  4 +-
 arch/arm/src/armv7-a/cp15_cacheops.c  | 78 +++++++++++++++++++++++++++++------
 arch/arm/src/armv7-a/cp15_cacheops.h  | 44 +++++++++++++++++---
 arch/arm/src/armv7-a/l2cc.h           |  6 +--
 arch/arm/src/armv7-m/arm_cache.c      | 47 +++++++++++++++------
 arch/arm/src/armv7-r/arm_cache.c      | 52 +++++++----------------
 arch/arm/src/armv7-r/arm_l2cc_pl310.c |  4 +-
 arch/arm/src/armv7-r/cp15_cacheops.c  | 78 +++++++++++++++++++++++++++++------
 arch/arm/src/armv7-r/cp15_cacheops.h  | 44 +++++++++++++++++---
 arch/arm/src/armv7-r/l2cc.h           |  6 +--
 arch/arm/src/armv8-m/arm_cache.c      | 47 +++++++++++++++------
 12 files changed, 316 insertions(+), 146 deletions(-)

diff --git a/arch/arm/src/armv7-a/arm_cache.c b/arch/arm/src/armv7-a/arm_cache.c
index 95eb5ebae3..e5120cb32f 100644
--- a/arch/arm/src/armv7-a/arm_cache.c
+++ b/arch/arm/src/armv7-a/arm_cache.c
@@ -32,16 +32,16 @@
 #include "l2cc.h"
 
 /****************************************************************************
- * Private Functions
+ * Public Functions
  ****************************************************************************/
 
-#if defined(CONFIG_ARCH_ICACHE) || defined(CONFIG_ARCH_DCACHE)
+#ifdef CONFIG_ARCH_ICACHE
 
 /****************************************************************************
- * Name: up_get_cache_linesize
+ * Name: up_get_icache_linesize
  *
  * Description:
- *   Get cache linesize
+ *   Get icache linesize
  *
  * Input Parameters:
  *   None
@@ -51,45 +51,18 @@
  *
  ****************************************************************************/
 
-static size_t up_get_cache_linesize(void)
+size_t up_get_icache_linesize(void)
 {
   static uint32_t clsize;
 
   if (clsize == 0)
     {
-      clsize = MAX(cp15_cache_linesize(), l2cc_get_linesize());
+      clsize = MAX(cp15_icache_linesize(), l2cc_linesize());
     }
 
   return clsize;
 }
 
-#endif
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-#ifdef CONFIG_ARCH_ICACHE
-
-/****************************************************************************
- * Name: up_get_icache_linesize
- *
- * Description:
- *   Get icache linesize
- *
- * Input Parameters:
- *   None
- *
- * Returned Value:
- *   Cache line size
- *
- ****************************************************************************/
-
-size_t up_get_icache_linesize(void)
-{
-  return up_get_cache_linesize();
-}
-
 /****************************************************************************
  * Name: up_invalidate_icache_all
  *
@@ -189,7 +162,14 @@ void up_disable_icache(void)
 
 size_t up_get_dcache_linesize(void)
 {
-  return up_get_cache_linesize();
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = MAX(cp15_dcache_linesize(), l2cc_linesize());
+    }
+
+  return clsize;
 }
 
 /****************************************************************************
@@ -272,7 +252,7 @@ void up_invalidate_dcache_all(void)
 
 void up_clean_dcache(uintptr_t start, uintptr_t end)
 {
-  if ((end - start) < cp15_cache_size())
+  if ((end - start) < cp15_dcache_size())
     {
       cp15_clean_dcache(start, end);
     }
@@ -336,7 +316,7 @@ void up_clean_dcache_all(void)
 
 void up_flush_dcache(uintptr_t start, uintptr_t end)
 {
-  if ((end - start) < cp15_cache_size())
+  if ((end - start) < cp15_dcache_size())
     {
       cp15_flush_dcache(start, end);
     }
diff --git a/arch/arm/src/armv7-a/arm_l2cc_pl310.c b/arch/arm/src/armv7-a/arm_l2cc_pl310.c
index ceb57a0e92..5744091ee7 100644
--- a/arch/arm/src/armv7-a/arm_l2cc_pl310.c
+++ b/arch/arm/src/armv7-a/arm_l2cc_pl310.c
@@ -397,7 +397,7 @@ void arm_l2ccinitialize(void)
 }
 
 /****************************************************************************
- * Name: l2cc_get_linesize
+ * Name: l2cc_linesize
  *
  * Description:
  *    Get L2CC-P310 L2 cache linesize
@@ -410,7 +410,7 @@ void arm_l2ccinitialize(void)
  *
  ****************************************************************************/
 
-uint32_t l2cc_get_linesize(void)
+uint32_t l2cc_linesize(void)
 {
   return PL310_CACHE_LINE_SIZE;
 }
diff --git a/arch/arm/src/armv7-a/cp15_cacheops.c b/arch/arm/src/armv7-a/cp15_cacheops.c
index 084e46df0c..d7bf4a4e5e 100644
--- a/arch/arm/src/armv7-a/cp15_cacheops.c
+++ b/arch/arm/src/armv7-a/cp15_cacheops.c
@@ -44,9 +44,19 @@ static inline uint32_t ilog2(uint32_t u)
   return i;
 }
 
-static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways)
+static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
+                                           bool icache)
 {
-  uint32_t ccsidr = CP15_GET(CCSIDR);
+  uint32_t ccsidr;
+  uint32_t csselr;
+
+  csselr = CP15_GET(CSSELR);
+
+  csselr = (csselr & ~0x01) | (icache & 0x01);
+
+  CP15_SET(CSSELR, csselr);
+
+  ccsidr = CP15_GET(CCSIDR);
 
   if (sets)
     {
@@ -93,7 +103,7 @@ static void cp15_dcache_op_mva(uintptr_t start, uintptr_t end, int op)
 {
   uint32_t line;
 
-  line = cp15_cache_get_info(NULL, NULL);
+  line = cp15_dcache_linesize();
 
   ARM_DSB();
 
@@ -158,7 +168,7 @@ void cp15_dcache_op_level(uint32_t level, int op)
 
   /* Get cache info */
 
-  line = cp15_cache_get_info(&sets, &ways);
+  line = cp15_cache_get_info(&sets, &ways, false);
 
   way_shift = 32 - ilog2(ways);
   set_shift = ilog2(line);
@@ -209,7 +219,7 @@ void cp15_invalidate_icache(uintptr_t start, uintptr_t end)
 {
   uint32_t line;
 
-  line = cp15_cache_get_info(NULL, NULL);
+  line = cp15_icache_linesize();
   start &= ~(line - 1);
 
   ARM_DSB();
@@ -259,18 +269,60 @@ void cp15_flush_dcache_all(void)
   cp15_dcache_op(CP15_CACHE_CLEANINVALIDATE);
 }
 
-uint32_t cp15_cache_size(void)
+uint32_t cp15_icache_size(void)
 {
-  uint32_t sets;
-  uint32_t ways;
-  uint32_t line;
+  static uint32_t csize;
 
-  line = cp15_cache_get_info(&sets, &ways);
+  if (csize == 0)
+    {
+      uint32_t sets;
+      uint32_t ways;
+      uint32_t line;
 
-  return sets * ways * line;
+      line = cp15_cache_get_info(&sets, &ways, true);
+      csize = sets * ways * line;
+    }
+
+  return csize;
 }
 
-uint32_t cp15_cache_linesize(void)
+uint32_t cp15_dcache_size(void)
 {
-  return cp15_cache_get_info(NULL, NULL);
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      uint32_t sets;
+      uint32_t ways;
+      uint32_t line;
+
+      line = cp15_cache_get_info(&sets, &ways, false);
+      csize = sets * ways * line;
+    }
+
+  return csize;
+}
+
+uint32_t cp15_icache_linesize(void)
+{
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = cp15_cache_get_info(NULL, NULL, true);
+    }
+
+  return clsize;
+}
+
+uint32_t cp15_dcache_linesize(void)
+{
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = cp15_cache_get_info(NULL, NULL, false);
+    }
+
+  return clsize;
 }
diff --git a/arch/arm/src/armv7-a/cp15_cacheops.h b/arch/arm/src/armv7-a/cp15_cacheops.h
index a680c4b5a9..8578746235 100644
--- a/arch/arm/src/armv7-a/cp15_cacheops.h
+++ b/arch/arm/src/armv7-a/cp15_cacheops.h
@@ -1090,11 +1090,27 @@ void cp15_flush_dcache(uintptr_t start, uintptr_t end);
 
 void cp15_flush_dcache_all(void);
 
+/****************************************************************************
+ * Name: cp15_icache_size
+ *
+ * Description:
+ *   Get cp15 icache size in byte
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size in byte
+ *
+ ****************************************************************************/
+
+uint32_t cp15_icache_size(void);
+
 /****************************************************************************
  * Name: cp15_cache_size
  *
  * Description:
- *   Get cp15 cache size in byte
+ *   Get cp15 dcache size in byte
  *
  * Input Parameters:
  *   None
@@ -1104,23 +1120,39 @@ void cp15_flush_dcache_all(void);
  *
  ****************************************************************************/
 
-uint32_t cp15_cache_size(void);
+uint32_t cp15_dcache_size(void);
+
+/****************************************************************************
+ * Name: cp15_icache_linesize
+ *
+ * Description:
+ *   Get cp15 icache linesize in byte
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   ICache linesize in byte
+ *
+ ****************************************************************************/
+
+uint32_t cp15_icache_linesize(void);
 
 /****************************************************************************
- * Name: cp15_cache_linesize
+ * Name: cp15_dcache_linesize
  *
  * Description:
- *   Get cp15 cache linesize in byte
+ *   Get cp15 dcache linesize in byte
  *
  * Input Parameters:
  *   None
  *
  * Returned Value:
- *   Cache linesize in byte
+ *   DCache linesize in byte
  *
  ****************************************************************************/
 
-uint32_t cp15_cache_linesize(void);
+uint32_t cp15_dcache_linesize(void);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/arch/arm/src/armv7-a/l2cc.h b/arch/arm/src/armv7-a/l2cc.h
index eee2e80c73..e0d96974b8 100644
--- a/arch/arm/src/armv7-a/l2cc.h
+++ b/arch/arm/src/armv7-a/l2cc.h
@@ -71,7 +71,7 @@ void arm_l2ccinitialize(void);
 #endif
 
 /****************************************************************************
- * Name: l2cc_get_linesize
+ * Name: l2cc_linesize
  *
  * Description:
  *    Get L2 cache linesize
@@ -84,7 +84,7 @@ void arm_l2ccinitialize(void);
  *
  ****************************************************************************/
 
-uint32_t l2cc_get_linesize(void);
+uint32_t l2cc_linesize(void);
 
 /****************************************************************************
  * Name: l2cc_enable
@@ -245,7 +245,7 @@ void l2cc_flush(uint32_t startaddr, uint32_t endaddr);
    * compilation in one place.
    */
 
-#  define l2cc_get_linesize() 0
+#  define l2cc_linesize() 0
 #  define l2cc_enable()
 #  define l2cc_disable()
 #  define l2cc_sync()
diff --git a/arch/arm/src/armv7-m/arm_cache.c b/arch/arm/src/armv7-m/arm_cache.c
index 34ee70441b..4588ea1e42 100644
--- a/arch/arm/src/armv7-m/arm_cache.c
+++ b/arch/arm/src/armv7-m/arm_cache.c
@@ -111,7 +111,7 @@ static inline uint32_t arm_clz(unsigned int value)
  *   Get cache linesize
  *
  * Input Parameters:
- *   None
+ *   icache - Difference between icache and dcache.
  *
  * Returned Value:
  *   Cache line size
@@ -119,21 +119,28 @@ static inline uint32_t arm_clz(unsigned int value)
  ****************************************************************************/
 
 #if defined(CONFIG_ARMV7M_ICACHE) || defined(CONFIG_ARMV7M_DCACHE)
-static size_t up_get_cache_linesize(void)
+static size_t up_get_cache_linesize(bool icache)
 {
-  static uint32_t clsize;
+  uint32_t ccsidr;
+  uint32_t csselr;
+  uint32_t sshift;
 
-  if (clsize == 0)
-    {
-      uint32_t ccsidr;
-      uint32_t sshift;
+  csselr = getreg32(NVIC_CSSELR);
 
-      ccsidr = getreg32(NVIC_CCSIDR);
-      sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
-      clsize = 1 << sshift;
+  if (icache)
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+    }
+  else
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
     }
 
-  return clsize;
+  putreg32(csselr, NVIC_CSSELR);
+  ccsidr = getreg32(NVIC_CCSIDR);
+  sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
+
+  return 1 << sshift;
 }
 #endif
 
@@ -158,7 +165,14 @@ static size_t up_get_cache_linesize(void)
 #ifdef CONFIG_ARMV7M_ICACHE
 size_t up_get_icache_linesize(void)
 {
-  return up_get_cache_linesize();
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = up_get_cache_linesize(true);
+    }
+
+  return clsize;
 }
 #endif
 
@@ -344,7 +358,14 @@ void up_invalidate_icache_all(void)
 #ifdef CONFIG_ARMV7M_DCACHE
 size_t up_get_dcache_linesize(void)
 {
-  return up_get_cache_linesize();
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = up_get_cache_linesize(false);
+    }
+
+  return clsize;
 }
 #endif
 
diff --git a/arch/arm/src/armv7-r/arm_cache.c b/arch/arm/src/armv7-r/arm_cache.c
index 0163f176cb..323da0bce3 100644
--- a/arch/arm/src/armv7-r/arm_cache.c
+++ b/arch/arm/src/armv7-r/arm_cache.c
@@ -32,16 +32,16 @@
 #include "l2cc.h"
 
 /****************************************************************************
- * Private Functions
+ * Public Functions
  ****************************************************************************/
 
-#if defined(CONFIG_ARCH_ICACHE) || defined(CONFIG_ARCH_DCACHE)
+#ifdef CONFIG_ARCH_ICACHE
 
 /****************************************************************************
- * Name: up_get_cache_linesize
+ * Name: up_get_icache_linesize
  *
  * Description:
- *   Get cache linesize
+ *   Get icache linesize
  *
  * Input Parameters:
  *   None
@@ -51,45 +51,18 @@
  *
  ****************************************************************************/
 
-static size_t up_get_cache_linesize(void)
+size_t up_get_icache_linesize(void)
 {
   static uint32_t clsize;
 
   if (clsize == 0)
     {
-      clsize = MAX(cp15_cache_linesize(), l2cc_get_linesize());
+      clsize = MAX(cp15_icache_linesize(), l2cc_linesize());
     }
 
   return clsize;
 }
 
-#endif
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-#ifdef CONFIG_ARCH_ICACHE
-
-/****************************************************************************
- * Name: up_get_icache_linesize
- *
- * Description:
- *   Get icache linesize
- *
- * Input Parameters:
- *   None
- *
- * Returned Value:
- *   Cache line size
- *
- ****************************************************************************/
-
-size_t up_get_icache_linesize(void)
-{
-  return up_get_cache_linesize();
-}
-
 /****************************************************************************
  * Name: up_invalidate_icache_all
  *
@@ -189,7 +162,14 @@ void up_disable_icache(void)
 
 size_t up_get_dcache_linesize(void)
 {
-  return up_get_cache_linesize();
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = MAX(cp15_dcache_linesize(), l2cc_linesize());
+    }
+
+  return clsize;
 }
 
 /****************************************************************************
@@ -272,7 +252,7 @@ void up_invalidate_dcache_all(void)
 
 void up_clean_dcache(uintptr_t start, uintptr_t end)
 {
-  if ((end - start) < cp15_cache_size())
+  if ((end - start) < cp15_dcache_size())
     {
       cp15_clean_dcache(start, end);
     }
@@ -336,7 +316,7 @@ void up_clean_dcache_all(void)
 
 void up_flush_dcache(uintptr_t start, uintptr_t end)
 {
-  if ((end - start) < cp15_cache_size())
+  if ((end - start) < cp15_dcache_size())
     {
       cp15_flush_dcache(start, end);
     }
diff --git a/arch/arm/src/armv7-r/arm_l2cc_pl310.c b/arch/arm/src/armv7-r/arm_l2cc_pl310.c
index 39ce67cfd8..bd5e5a54b7 100644
--- a/arch/arm/src/armv7-r/arm_l2cc_pl310.c
+++ b/arch/arm/src/armv7-r/arm_l2cc_pl310.c
@@ -397,7 +397,7 @@ void arm_l2ccinitialize(void)
 }
 
 /****************************************************************************
- * Name: l2cc_get_linesize
+ * Name: l2cc_linesize
  *
  * Description:
  *    Get L2CC-P310 L2 cache linesize
@@ -410,7 +410,7 @@ void arm_l2ccinitialize(void)
  *
  ****************************************************************************/
 
-uint32_t l2cc_get_linesize(void)
+uint32_t l2cc_linesize(void)
 {
   return PL310_CACHE_LINE_SIZE;
 }
diff --git a/arch/arm/src/armv7-r/cp15_cacheops.c b/arch/arm/src/armv7-r/cp15_cacheops.c
index bc542fc35c..74da551a81 100644
--- a/arch/arm/src/armv7-r/cp15_cacheops.c
+++ b/arch/arm/src/armv7-r/cp15_cacheops.c
@@ -44,9 +44,19 @@ static inline uint32_t ilog2(uint32_t u)
   return i;
 }
 
-static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways)
+static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
+                                           bool icache)
 {
-  uint32_t ccsidr = CP15_GET(CCSIDR);
+  uint32_t ccsidr;
+  uint32_t csselr;
+
+  csselr = CP15_GET(CSSELR);
+
+  csselr = (csselr & ~0x01) | (icache & 0x01);
+
+  CP15_SET(CSSELR, csselr);
+
+  ccsidr = CP15_GET(CCSIDR);
 
   if (sets)
     {
@@ -93,7 +103,7 @@ static void cp15_dcache_op_mva(uintptr_t start, uintptr_t end, int op)
 {
   uint32_t line;
 
-  line = cp15_cache_get_info(NULL, NULL);
+  line = cp15_dcache_linesize();
 
   ARM_DSB();
 
@@ -158,7 +168,7 @@ void cp15_dcache_op_level(uint32_t level, int op)
 
   /* Get cache info */
 
-  line = cp15_cache_get_info(&sets, &ways);
+  line = cp15_cache_get_info(&sets, &ways, false);
 
   way_shift = 32 - ilog2(ways);
   set_shift = ilog2(line);
@@ -209,7 +219,7 @@ void cp15_invalidate_icache(uintptr_t start, uintptr_t end)
 {
   uint32_t line;
 
-  line = cp15_cache_get_info(NULL, NULL);
+  line = cp15_icache_linesize();
   start &= ~(line - 1);
 
   ARM_DSB();
@@ -259,18 +269,60 @@ void cp15_flush_dcache_all(void)
   cp15_dcache_op(CP15_CACHE_CLEANINVALIDATE);
 }
 
-uint32_t cp15_cache_size(void)
+uint32_t cp15_icache_size(void)
 {
-  uint32_t sets;
-  uint32_t ways;
-  uint32_t line;
+  static uint32_t csize;
 
-  line = cp15_cache_get_info(&sets, &ways);
+  if (csize == 0)
+    {
+      uint32_t sets;
+      uint32_t ways;
+      uint32_t line;
 
-  return sets * ways * line;
+      line = cp15_cache_get_info(&sets, &ways, true);
+      csize = sets * ways * line;
+    }
+
+  return csize;
 }
 
-uint32_t cp15_cache_linesize(void)
+uint32_t cp15_dcache_size(void)
 {
-  return cp15_cache_get_info(NULL, NULL);
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      uint32_t sets;
+      uint32_t ways;
+      uint32_t line;
+
+      line = cp15_cache_get_info(&sets, &ways, false);
+      csize = sets * ways * line;
+    }
+
+  return csize;
+}
+
+uint32_t cp15_icache_linesize(void)
+{
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = cp15_cache_get_info(NULL, NULL, true);
+    }
+
+  return clsize;
+}
+
+uint32_t cp15_dcache_linesize(void)
+{
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = cp15_cache_get_info(NULL, NULL, false);
+    }
+
+  return clsize;
 }
diff --git a/arch/arm/src/armv7-r/cp15_cacheops.h b/arch/arm/src/armv7-r/cp15_cacheops.h
index 4561844fc2..6b0cb759f5 100644
--- a/arch/arm/src/armv7-r/cp15_cacheops.h
+++ b/arch/arm/src/armv7-r/cp15_cacheops.h
@@ -1097,11 +1097,27 @@ void cp15_flush_dcache(uintptr_t start, uintptr_t end);
 
 void cp15_flush_dcache_all(void);
 
+/****************************************************************************
+ * Name: cp15_icache_size
+ *
+ * Description:
+ *   Get cp15 icache size in byte
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size in byte
+ *
+ ****************************************************************************/
+
+uint32_t cp15_icache_size(void);
+
 /****************************************************************************
  * Name: cp15_cache_size
  *
  * Description:
- *   Get cp15 cache size in byte
+ *   Get cp15 dcache size in byte
  *
  * Input Parameters:
  *   None
@@ -1111,23 +1127,39 @@ void cp15_flush_dcache_all(void);
  *
  ****************************************************************************/
 
-uint32_t cp15_cache_size(void);
+uint32_t cp15_dcache_size(void);
+
+/****************************************************************************
+ * Name: cp15_icache_linesize
+ *
+ * Description:
+ *   Get cp15 icache linesize in byte
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   ICache linesize in byte
+ *
+ ****************************************************************************/
+
+uint32_t cp15_icache_linesize(void);
 
 /****************************************************************************
- * Name: cp15_cache_linesize
+ * Name: cp15_dcache_linesize
  *
  * Description:
- *   Get cp15 cache linesize in byte
+ *   Get cp15 dcache linesize in byte
  *
  * Input Parameters:
  *   None
  *
  * Returned Value:
- *   Cache linesize in byte
+ *   DCache linesize in byte
  *
  ****************************************************************************/
 
-uint32_t cp15_cache_linesize(void);
+uint32_t cp15_dcache_linesize(void);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/arch/arm/src/armv7-r/l2cc.h b/arch/arm/src/armv7-r/l2cc.h
index c0b659d534..fa62baf3bf 100644
--- a/arch/arm/src/armv7-r/l2cc.h
+++ b/arch/arm/src/armv7-r/l2cc.h
@@ -71,7 +71,7 @@ void arm_l2ccinitialize(void);
 #endif
 
 /****************************************************************************
- * Name: l2cc_get_linesize
+ * Name: l2cc_linesize
  *
  * Description:
  *    Get L2 cache linesize
@@ -84,7 +84,7 @@ void arm_l2ccinitialize(void);
  *
  ****************************************************************************/
 
-uint32_t l2cc_get_linesize(void);
+uint32_t l2cc_linesize(void);
 
 /****************************************************************************
  * Name: l2cc_enable
@@ -245,7 +245,7 @@ void l2cc_flush(uint32_t startaddr, uint32_t endaddr);
    * compilation in one place.
    */
 
-#  define l2cc_get_linesize() 0
+#  define l2cc_linesize() 0
 #  define l2cc_enable()
 #  define l2cc_disable()
 #  define l2cc_sync()
diff --git a/arch/arm/src/armv8-m/arm_cache.c b/arch/arm/src/armv8-m/arm_cache.c
index eab92de3ab..4028f3d5a2 100644
--- a/arch/arm/src/armv8-m/arm_cache.c
+++ b/arch/arm/src/armv8-m/arm_cache.c
@@ -111,7 +111,7 @@ static inline uint32_t arm_clz(unsigned int value)
  *   Get cache linesize
  *
  * Input Parameters:
- *   None
+ *   icache - Difference between icache and dcache.
  *
  * Returned Value:
  *   Cache line size
@@ -119,21 +119,28 @@ static inline uint32_t arm_clz(unsigned int value)
  ****************************************************************************/
 
 #if defined(CONFIG_ARMV8M_ICACHE) || defined(CONFIG_ARMV8M_DCACHE)
-static size_t up_get_cache_linesize(void)
+static size_t up_get_cache_linesize(bool icache)
 {
-  static uint32_t clsize;
+  uint32_t ccsidr;
+  uint32_t csselr;
+  uint32_t sshift;
 
-  if (clsize == 0)
-    {
-      uint32_t ccsidr;
-      uint32_t sshift;
+  csselr = getreg32(NVIC_CSSELR);
 
-      ccsidr = getreg32(NVIC_CCSIDR);
-      sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
-      clsize = 1 << sshift;
+  if (icache)
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+    }
+  else
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
     }
 
-  return clsize;
+  putreg32(csselr, NVIC_CSSELR);
+  ccsidr = getreg32(NVIC_CCSIDR);
+  sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
+
+  return 1 << sshift;
 }
 #endif
 
@@ -158,7 +165,14 @@ static size_t up_get_cache_linesize(void)
 #ifdef CONFIG_ARMV8M_ICACHE
 size_t up_get_icache_linesize(void)
 {
-  return up_get_cache_linesize();
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = up_get_cache_linesize(true);
+    }
+
+  return clsize;
 }
 #endif
 
@@ -344,7 +358,14 @@ void up_invalidate_icache_all(void)
 #ifdef CONFIG_ARMV8M_DCACHE
 size_t up_get_dcache_linesize(void)
 {
-  return up_get_cache_linesize();
+  static uint32_t clsize;
+
+  if (clsize == 0)
+    {
+      clsize = up_get_cache_linesize(false);
+    }
+
+  return clsize;
 }
 #endif
 


[nuttx] 02/06: armv7/8 cache: add up_get_xcache_size() support

Posted by xi...@apache.org.
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 22d1059c97f767f2c204725cd4d8bcd7a40373a7
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Fri May 5 11:18:06 2023 +0800

    armv7/8 cache: add up_get_xcache_size() support
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 arch/arm/src/armv7-a/arm_cache.c      | 52 +++++++++++++++++++
 arch/arm/src/armv7-a/arm_l2cc_pl310.c | 19 +++++++
 arch/arm/src/armv7-a/l2cc.h           | 17 +++++++
 arch/arm/src/armv7-m/arm_cache.c      | 95 +++++++++++++++++++++++++++++++++++
 arch/arm/src/armv7-r/arm_cache.c      | 52 +++++++++++++++++++
 arch/arm/src/armv7-r/arm_l2cc_pl310.c | 19 +++++++
 arch/arm/src/armv7-r/l2cc.h           | 17 +++++++
 arch/arm/src/armv8-m/arm_cache.c      | 95 +++++++++++++++++++++++++++++++++++
 include/nuttx/cache.h                 | 40 +++++++++++++++
 9 files changed, 406 insertions(+)

diff --git a/arch/arm/src/armv7-a/arm_cache.c b/arch/arm/src/armv7-a/arm_cache.c
index e5120cb32f..545a05c1af 100644
--- a/arch/arm/src/armv7-a/arm_cache.c
+++ b/arch/arm/src/armv7-a/arm_cache.c
@@ -63,6 +63,32 @@ size_t up_get_icache_linesize(void)
   return clsize;
 }
 
+/****************************************************************************
+ * Name: up_get_icache_size
+ *
+ * Description:
+ *   Get icache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_icache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = MAX(cp15_icache_size(), l2cc_size());
+    }
+
+  return csize;
+}
+
 /****************************************************************************
  * Name: up_invalidate_icache_all
  *
@@ -172,6 +198,32 @@ size_t up_get_dcache_linesize(void)
   return clsize;
 }
 
+/****************************************************************************
+ * Name: up_get_dcache_size
+ *
+ * Description:
+ *   Get dcache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_dcache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = MAX(cp15_dcache_size(), l2cc_size());
+    }
+
+  return csize;
+}
+
 /****************************************************************************
  * Name: up_invalidate_dcache
  *
diff --git a/arch/arm/src/armv7-a/arm_l2cc_pl310.c b/arch/arm/src/armv7-a/arm_l2cc_pl310.c
index 5744091ee7..993cb2c30b 100644
--- a/arch/arm/src/armv7-a/arm_l2cc_pl310.c
+++ b/arch/arm/src/armv7-a/arm_l2cc_pl310.c
@@ -415,6 +415,25 @@ uint32_t l2cc_linesize(void)
   return PL310_CACHE_LINE_SIZE;
 }
 
+/****************************************************************************
+ * Name: l2cc_size
+ *
+ * Description:
+ *    Get L2CC-P310 L2 cache size
+ *
+ * Input Parameters:
+ *    None
+ *
+ * Returned Value:
+ *    L2 cache size
+ *
+ ****************************************************************************/
+
+uint32_t l2cc_size(void)
+{
+  return PL310_CACHE_SIZE;
+}
+
 /****************************************************************************
  * Name: l2cc_enable
  *
diff --git a/arch/arm/src/armv7-a/l2cc.h b/arch/arm/src/armv7-a/l2cc.h
index e0d96974b8..368bc02c2c 100644
--- a/arch/arm/src/armv7-a/l2cc.h
+++ b/arch/arm/src/armv7-a/l2cc.h
@@ -86,6 +86,22 @@ void arm_l2ccinitialize(void);
 
 uint32_t l2cc_linesize(void);
 
+/****************************************************************************
+ * Name: l2cc_size
+ *
+ * Description:
+ *    Get L2CC-P310 L2 cache size
+ *
+ * Input Parameters:
+ *    None
+ *
+ * Returned Value:
+ *    L2 cache size
+ *
+ ****************************************************************************/
+
+uint32_t l2cc_size(void);
+
 /****************************************************************************
  * Name: l2cc_enable
  *
@@ -245,6 +261,7 @@ void l2cc_flush(uint32_t startaddr, uint32_t endaddr);
    * compilation in one place.
    */
 
+#  define l2cc_size() 0
 #  define l2cc_linesize() 0
 #  define l2cc_enable()
 #  define l2cc_disable()
diff --git a/arch/arm/src/armv7-m/arm_cache.c b/arch/arm/src/armv7-m/arm_cache.c
index 4588ea1e42..88bc5ac2b5 100644
--- a/arch/arm/src/armv7-m/arm_cache.c
+++ b/arch/arm/src/armv7-m/arm_cache.c
@@ -142,6 +142,49 @@ static size_t up_get_cache_linesize(bool icache)
 
   return 1 << sshift;
 }
+
+/****************************************************************************
+ * Name: up_get_cache_size
+ *
+ * Description:
+ *   Get cache size
+ *
+ * Input Parameters:
+ *   level - Difference between icache and dcache.
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+static size_t up_get_cache_size(bool icache)
+{
+  uint32_t ccsidr;
+  uint32_t csselr;
+  uint32_t sshift;
+  uint32_t sets;
+  uint32_t ways;
+  uint32_t line;
+
+  csselr = getreg32(NVIC_CSSELR);
+
+  if (icache)
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+    }
+  else
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
+    }
+
+  ccsidr = getreg32(NVIC_CCSIDR);
+  sets   = CCSIDR_SETS(ccsidr) + 1;
+  ways   = CCSIDR_WAYS(ccsidr) + 1;
+  sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
+  line   = 1 << sshift;
+
+  return sets * ways * line;
+}
 #endif
 
 /****************************************************************************
@@ -174,6 +217,32 @@ size_t up_get_icache_linesize(void)
 
   return clsize;
 }
+
+/****************************************************************************
+ * Name: up_get_icache_size
+ *
+ * Description:
+ *   Get icache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_icache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = up_get_cache_size(true);
+    }
+
+  return csize;
+}
 #endif
 
 /****************************************************************************
@@ -367,6 +436,32 @@ size_t up_get_dcache_linesize(void)
 
   return clsize;
 }
+
+/****************************************************************************
+ * Name: up_get_dcache_size
+ *
+ * Description:
+ *   Get icache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_dcache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = up_get_cache_size(false);
+    }
+
+  return csize;
+}
 #endif
 
 /****************************************************************************
diff --git a/arch/arm/src/armv7-r/arm_cache.c b/arch/arm/src/armv7-r/arm_cache.c
index 323da0bce3..c626a34a87 100644
--- a/arch/arm/src/armv7-r/arm_cache.c
+++ b/arch/arm/src/armv7-r/arm_cache.c
@@ -63,6 +63,32 @@ size_t up_get_icache_linesize(void)
   return clsize;
 }
 
+/****************************************************************************
+ * Name: up_get_icache_size
+ *
+ * Description:
+ *   Get icache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_icache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = MAX(cp15_icache_size(), l2cc_size());
+    }
+
+  return csize;
+}
+
 /****************************************************************************
  * Name: up_invalidate_icache_all
  *
@@ -172,6 +198,32 @@ size_t up_get_dcache_linesize(void)
   return clsize;
 }
 
+/****************************************************************************
+ * Name: up_get_dcache_size
+ *
+ * Description:
+ *   Get dcache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_dcache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = MAX(cp15_dcache_size(), l2cc_size());
+    }
+
+  return csize;
+}
+
 /****************************************************************************
  * Name: up_invalidate_dcache
  *
diff --git a/arch/arm/src/armv7-r/arm_l2cc_pl310.c b/arch/arm/src/armv7-r/arm_l2cc_pl310.c
index bd5e5a54b7..ef381b3501 100644
--- a/arch/arm/src/armv7-r/arm_l2cc_pl310.c
+++ b/arch/arm/src/armv7-r/arm_l2cc_pl310.c
@@ -415,6 +415,25 @@ uint32_t l2cc_linesize(void)
   return PL310_CACHE_LINE_SIZE;
 }
 
+/****************************************************************************
+ * Name: l2cc_size
+ *
+ * Description:
+ *    Get L2CC-P310 L2 cache size
+ *
+ * Input Parameters:
+ *    None
+ *
+ * Returned Value:
+ *    L2 cache size
+ *
+ ****************************************************************************/
+
+uint32_t l2cc_size(void)
+{
+  return PL310_CACHE_SIZE;
+}
+
 /****************************************************************************
  * Name: l2cc_enable
  *
diff --git a/arch/arm/src/armv7-r/l2cc.h b/arch/arm/src/armv7-r/l2cc.h
index fa62baf3bf..916d1d8d87 100644
--- a/arch/arm/src/armv7-r/l2cc.h
+++ b/arch/arm/src/armv7-r/l2cc.h
@@ -86,6 +86,22 @@ void arm_l2ccinitialize(void);
 
 uint32_t l2cc_linesize(void);
 
+/****************************************************************************
+ * Name: l2cc_size
+ *
+ * Description:
+ *    Get L2CC-P310 L2 cache size
+ *
+ * Input Parameters:
+ *    None
+ *
+ * Returned Value:
+ *    L2 cache size
+ *
+ ****************************************************************************/
+
+uint32_t l2cc_size(void);
+
 /****************************************************************************
  * Name: l2cc_enable
  *
@@ -245,6 +261,7 @@ void l2cc_flush(uint32_t startaddr, uint32_t endaddr);
    * compilation in one place.
    */
 
+#  define l2cc_size() 0
 #  define l2cc_linesize() 0
 #  define l2cc_enable()
 #  define l2cc_disable()
diff --git a/arch/arm/src/armv8-m/arm_cache.c b/arch/arm/src/armv8-m/arm_cache.c
index 4028f3d5a2..c4d0ec1ccc 100644
--- a/arch/arm/src/armv8-m/arm_cache.c
+++ b/arch/arm/src/armv8-m/arm_cache.c
@@ -144,6 +144,49 @@ static size_t up_get_cache_linesize(bool icache)
 }
 #endif
 
+/****************************************************************************
+ * Name: up_get_cache_size
+ *
+ * Description:
+ *   Get cache size
+ *
+ * Input Parameters:
+ *   level - Difference between icache and dcache.
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+static size_t up_get_cache_size(bool icache)
+{
+  uint32_t ccsidr;
+  uint32_t csselr;
+  uint32_t sshift;
+  uint32_t sets;
+  uint32_t ways;
+  uint32_t line;
+
+  csselr = getreg32(NVIC_CSSELR);
+
+  if (icache)
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
+    }
+  else
+    {
+      csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
+    }
+
+  ccsidr = getreg32(NVIC_CCSIDR);
+  sets   = CCSIDR_SETS(ccsidr) + 1;
+  ways   = CCSIDR_WAYS(ccsidr) + 1;
+  sshift = CCSIDR_LSSHIFT(ccsidr) + 4;   /* log2(cache-line-size-in-bytes) */
+  line   = 1 << sshift;
+
+  return sets * ways * line;
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -174,6 +217,32 @@ size_t up_get_icache_linesize(void)
 
   return clsize;
 }
+
+/****************************************************************************
+ * Name: up_get_icache_size
+ *
+ * Description:
+ *   Get icache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_icache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = up_get_cache_size(true);
+    }
+
+  return csize;
+}
 #endif
 
 /****************************************************************************
@@ -367,6 +436,32 @@ size_t up_get_dcache_linesize(void)
 
   return clsize;
 }
+
+/****************************************************************************
+ * Name: up_get_dcache_size
+ *
+ * Description:
+ *   Get icache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+size_t up_get_dcache_size(void)
+{
+  static uint32_t csize;
+
+  if (csize == 0)
+    {
+      csize = up_get_cache_size(false);
+    }
+
+  return csize;
+}
 #endif
 
 /****************************************************************************
diff --git a/include/nuttx/cache.h b/include/nuttx/cache.h
index 7814165fd1..b978c01e7a 100644
--- a/include/nuttx/cache.h
+++ b/include/nuttx/cache.h
@@ -68,6 +68,26 @@ size_t up_get_icache_linesize(void);
 #  define up_get_icache_linesize() 0
 #endif
 
+/****************************************************************************
+ * Name: up_get_icache_size
+ *
+ * Description:
+ *   Get icache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_ICACHE
+size_t up_get_icache_size(void);
+#else
+#  define up_get_icache_size() 0
+#endif
+
 /****************************************************************************
  * Name: up_enable_icache
  *
@@ -237,6 +257,26 @@ size_t up_get_dcache_linesize(void);
 #  define up_get_dcache_linesize() 0
 #endif
 
+/****************************************************************************
+ * Name: up_get_dcache_size
+ *
+ * Description:
+ *   Get dcache size
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   Cache size
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_DCACHE
+size_t up_get_dcache_size(void);
+#else
+#  define up_get_dcache_size() 0
+#endif
+
 /****************************************************************************
  * Name: up_enable_dcache
  *


[nuttx] 06/06: armv7amr/v8m:Modify hardcodes to macro definitions and update commit.

Posted by xi...@apache.org.
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 cafbbb1ded4d605ae494da765905f37ad0e11888
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Thu Jul 13 15:24:33 2023 +0800

    armv7amr/v8m:Modify hardcodes to macro definitions and update commit.
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 arch/arm/src/armv7-a/cp15_cacheops.c | 8 +++++++-
 arch/arm/src/armv7-m/nvic.h          | 4 ++--
 arch/arm/src/armv7-r/cp15_cacheops.c | 8 +++++++-
 arch/arm/src/armv8-m/nvic.h          | 4 ++--
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/arch/arm/src/armv7-a/cp15_cacheops.c b/arch/arm/src/armv7-a/cp15_cacheops.c
index 562cab4723..59d6f04b09 100644
--- a/arch/arm/src/armv7-a/cp15_cacheops.c
+++ b/arch/arm/src/armv7-a/cp15_cacheops.c
@@ -28,6 +28,12 @@
 
 #include "cp15_cacheops.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NVIC_CSSELR_IND (1 << 0)
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -52,7 +58,7 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
 
   csselr = CP15_GET(CSSELR);
 
-  CP15_SET(CSSELR, (csselr & ~0x01) | (icache & 0x01));
+  CP15_SET(CSSELR, (csselr & ~NVIC_CSSELR_IND) | (icache & NVIC_CSSELR_IND));
 
   ccsidr = CP15_GET(CCSIDR);
 
diff --git a/arch/arm/src/armv7-m/nvic.h b/arch/arm/src/armv7-m/nvic.h
index 50d8f671b5..b98be5b511 100644
--- a/arch/arm/src/armv7-m/nvic.h
+++ b/arch/arm/src/armv7-m/nvic.h
@@ -679,8 +679,8 @@
 /* Cache Size Selection Register (Cortex-M7) */
 
 #define NVIC_CSSELR_IND                 (1 << 0)  /* Bit 0: Selects either instruction or data cache */
-#  define NVIC_CSSELR_IND_ICACHE        (1 << 0)  /*   0=Instruction Cache */
-#  define NVIC_CSSELR_IND_DCACHE        (0 << 0)  /*   1=Data Cache */
+#  define NVIC_CSSELR_IND_ICACHE        (1 << 0)  /*   1=Instruction Cache */
+#  define NVIC_CSSELR_IND_DCACHE        (0 << 0)  /*   0=Data Cache */
 
 #define NVIC_CSSELR_LEVEL_SHIFT         (1)       /* Bit 1-3: Selects cache level */
 #define NVIC_CSSELR_LEVEL_MASK          (7 << NVIC_CSSELR_LEVEL_SHIFT)
diff --git a/arch/arm/src/armv7-r/cp15_cacheops.c b/arch/arm/src/armv7-r/cp15_cacheops.c
index 94f4aa3d3a..3aa4564c91 100644
--- a/arch/arm/src/armv7-r/cp15_cacheops.c
+++ b/arch/arm/src/armv7-r/cp15_cacheops.c
@@ -28,6 +28,12 @@
 
 #include "cp15_cacheops.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NVIC_CSSELR_IND (1 << 0)
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -52,7 +58,7 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
 
   csselr = CP15_GET(CSSELR);
 
-  CP15_SET(CSSELR, (csselr & ~0x01) | (icache & 0x01));
+  CP15_SET(CSSELR, (csselr & ~NVIC_CSSELR_IND) | (icache & NVIC_CSSELR_IND));
 
   ccsidr = CP15_GET(CCSIDR);
 
diff --git a/arch/arm/src/armv8-m/nvic.h b/arch/arm/src/armv8-m/nvic.h
index fa280faf2d..8f62f5c67b 100644
--- a/arch/arm/src/armv8-m/nvic.h
+++ b/arch/arm/src/armv8-m/nvic.h
@@ -778,8 +778,8 @@
 /* Cache Size Selection Register */
 
 #define NVIC_CSSELR_IND                 (1 << 0)  /* Bit 0: Selects either instruction or data cache */
-#  define NVIC_CSSELR_IND_ICACHE        (1 << 0)  /*   0=Instruction Cache */
-#  define NVIC_CSSELR_IND_DCACHE        (0 << 0)  /*   1=Data Cache */
+#  define NVIC_CSSELR_IND_ICACHE        (1 << 0)  /*   1=Instruction Cache */
+#  define NVIC_CSSELR_IND_DCACHE        (0 << 0)  /*   0=Data Cache */
 
 #define NVIC_CSSELR_LEVEL_SHIFT         (1)       /* Bit 1-3: Selects cache level */
 #define NVIC_CSSELR_LEVEL_MASK          (7 << NVIC_CSSELR_LEVEL_SHIFT)


[nuttx] 03/06: armv7/v8:Fix configuration csselr default configuration error.

Posted by xi...@apache.org.
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 665a140b213dad8e89742dbc79415ac56101b352
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Fri May 26 19:18:34 2023 +0800

    armv7/v8:Fix configuration csselr default configuration error.
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 arch/arm/src/armv7-m/nvic.h | 4 ++--
 arch/arm/src/armv8-m/nvic.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/src/armv7-m/nvic.h b/arch/arm/src/armv7-m/nvic.h
index a1a77bec22..50d8f671b5 100644
--- a/arch/arm/src/armv7-m/nvic.h
+++ b/arch/arm/src/armv7-m/nvic.h
@@ -679,8 +679,8 @@
 /* Cache Size Selection Register (Cortex-M7) */
 
 #define NVIC_CSSELR_IND                 (1 << 0)  /* Bit 0: Selects either instruction or data cache */
-#  define NVIC_CSSELR_IND_ICACHE        (0 << 0)  /*   0=Instruction Cache */
-#  define NVIC_CSSELR_IND_DCACHE        (1 << 0)  /*   1=Data Cache */
+#  define NVIC_CSSELR_IND_ICACHE        (1 << 0)  /*   0=Instruction Cache */
+#  define NVIC_CSSELR_IND_DCACHE        (0 << 0)  /*   1=Data Cache */
 
 #define NVIC_CSSELR_LEVEL_SHIFT         (1)       /* Bit 1-3: Selects cache level */
 #define NVIC_CSSELR_LEVEL_MASK          (7 << NVIC_CSSELR_LEVEL_SHIFT)
diff --git a/arch/arm/src/armv8-m/nvic.h b/arch/arm/src/armv8-m/nvic.h
index 0478b24909..fa280faf2d 100644
--- a/arch/arm/src/armv8-m/nvic.h
+++ b/arch/arm/src/armv8-m/nvic.h
@@ -778,8 +778,8 @@
 /* Cache Size Selection Register */
 
 #define NVIC_CSSELR_IND                 (1 << 0)  /* Bit 0: Selects either instruction or data cache */
-#  define NVIC_CSSELR_IND_ICACHE        (0 << 0)  /*   0=Instruction Cache */
-#  define NVIC_CSSELR_IND_DCACHE        (1 << 0)  /*   1=Data Cache */
+#  define NVIC_CSSELR_IND_ICACHE        (1 << 0)  /*   0=Instruction Cache */
+#  define NVIC_CSSELR_IND_DCACHE        (0 << 0)  /*   1=Data Cache */
 
 #define NVIC_CSSELR_LEVEL_SHIFT         (1)       /* Bit 1-3: Selects cache level */
 #define NVIC_CSSELR_LEVEL_MASK          (7 << NVIC_CSSELR_LEVEL_SHIFT)


[nuttx] 04/06: armv8m:fix warning up_get_cache_size defined but not used.

Posted by xi...@apache.org.
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 823c3b32e77d5cda559b90fe3c175360b64ae0ad
Author: chenrun1 <ch...@xiaomi.com>
AuthorDate: Thu Jun 8 18:44:26 2023 +0800

    armv8m:fix warning up_get_cache_size defined but not used.
    
    Signed-off-by: chenrun1 <ch...@xiaomi.com>
---
 arch/arm/src/armv8-m/arm_cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/src/armv8-m/arm_cache.c b/arch/arm/src/armv8-m/arm_cache.c
index c4d0ec1ccc..35aa14d992 100644
--- a/arch/arm/src/armv8-m/arm_cache.c
+++ b/arch/arm/src/armv8-m/arm_cache.c
@@ -142,7 +142,6 @@ static size_t up_get_cache_linesize(bool icache)
 
   return 1 << sshift;
 }
-#endif
 
 /****************************************************************************
  * Name: up_get_cache_size
@@ -186,6 +185,7 @@ static size_t up_get_cache_size(bool icache)
 
   return sets * ways * line;
 }
+#endif
 
 /****************************************************************************
  * Public Functions