CMSIS: share L1 cache maintenance support across A and R profiles - #319
CMSIS: share L1 cache maintenance support across A and R profiles#319hamtinepeng wants to merge 4 commits into
Conversation
|
Shall we add some checks to Core tests for the new/changed features? |
There was a problem hiding this comment.
🟡 Changes recommended
The new shared cache helper header contains a functional bug in __log2_up(), and the R-profile CP15 headers include an AArch64-only header that is likely to break AArch32 builds.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR refactors CMSIS Core cache-maintenance support by extracting the common L1 cache maintenance helpers into a shared header and reusing it across Armv7-A, Armv7-R, and Armv8-R profile headers.
Changes:
- Added
CMSIS/Core/Include/a-profile/l1_cache.hto host shared L1 cache enable/disable and cache maintenance helpers. - Updated
a-profile/armv7a.hto include the sharedl1_cache.hinstead of defining the helpers inline. - Updated R-profile headers (
armv7r.h,armv8r.h) and CP15 glue headers to pull in the shared cache-maintenance implementation and required CP15 interfaces.
File summaries
| File | Description |
|---|---|
| CMSIS/Core/Include/r-profile/armv8r.h | Includes shared L1 cache maintenance header for Armv8-R profile. |
| CMSIS/Core/Include/r-profile/armv8r_cp15.h | Adjusts CP15 include wiring for Armv8-R (but currently pulls in an AArch64-only header). |
| CMSIS/Core/Include/r-profile/armv7r.h | Includes shared L1 cache maintenance header for Armv7-R profile. |
| CMSIS/Core/Include/r-profile/armv7r_cp15.h | Adjusts CP15 include wiring for Armv7-R (but currently pulls in an AArch64-only header). |
| CMSIS/Core/Include/a-profile/l1_cache.h | New shared header containing L1 cache maintenance helpers reused across profiles. |
| CMSIS/Core/Include/a-profile/armv7a.h | Switches to including the new shared L1 cache maintenance header. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| __STATIC_FORCEINLINE uint8_t __log2_up(uint32_t n) | ||
| { | ||
| if (n < 2U) { | ||
| return 0U; | ||
| } | ||
| uint8_t log = 0U; | ||
| uint32_t t = n; | ||
| while(t > 1U) | ||
| { | ||
| log++; | ||
| t >>= 1U; | ||
| } | ||
| if (n & 1U) { log++; } | ||
| return log; | ||
| } |
There was a problem hiding this comment.
Moving code did not introduce this issue. I already have un upcoming patch to move variable declarations before statements, this issue could be addressed later.
There was a problem hiding this comment.
I am logging this issue for later analysis and resolution.
There was a problem hiding this comment.
Lets fix this issue in a separate PR.
| // The gic-interface is located in the profile folder for cortex-a devices | ||
| #include "../a-profile/armv8a_cp15.h" No newline at end of file | ||
| #include "../a-profile/armv7a_cp15.h" | ||
| #include "../a-profile/armv8a_cp15.h" |
There was a problem hiding this comment.
We should only include ../a-profile/armv8a_cp15.h
| /** \brief Clean instruction cache line by address. | ||
| * \param [in] va Pointer to instructions to clear the cache for. | ||
| */ |
Test Results 256 files - 388 256 suites - 388 0s ⏱️ - 16m 1s Results for commit 93636ac. ± Comparison against base commit 1c1840a. This pull request removes 49 and adds 56 tests. Note that renamed tests count towards both.This pull request removes 5 skipped tests and adds 2 skipped tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Extract the common L1 cache maintenance implementation into l1_cache.h and reuse it for Armv7-A, Armv7-R and Armv8-R.
a02d9f8 to
5429093
Compare
| #include "gicv2.h" | ||
| #endif /* (__GIC_PRESENT == 1U) || defined(DOXYGEN) */ | ||
|
|
||
| #include "../a-profile/l1_cache.h" |
There was a problem hiding this comment.
For gicv2 we placed this include into a separate file, because including A-profile code directly from the R-profile header might be confusing. This has no functional impact.
| #define SCTLR_M_Pos 0U /*!< \brief SCTLR: M Position */ | ||
| #define SCTLR_M_Msk (1UL << SCTLR_M_Pos) /*!< \brief SCTLR: M Mask */ | ||
|
|
||
| #include "../a-profile/l1_cache.h" |
There was a problem hiding this comment.
If not all members of the ARMv8R family require this driver, we should be able to disable the include using a switch. For example:
#if (defined(__L1C_PRESENT) && (__L1C_PRESENT == 1U)) || defined(DOXYGEN)
#include "../a-profile/l1_cache.h"
#endif
There was a problem hiding this comment.
If Cortex‑R82 support is added to CMSIS in the future, __L1C_PRESENT will likely be enabled. Therefore, this condition alone is not sufficient to determine whether the CP15-based cache maintenance implementation can be used. Cortex‑R82 relies on the AArch64 system register interface rather than CP15 accesses.
This option with the aarch64 flag could solve this issue.
| // The gic-interface is located in the profile folder for cortex-a devices | ||
| #include "../a-profile/armv8a_cp15.h" No newline at end of file | ||
| #include "../a-profile/armv7a_cp15.h" | ||
| #include "../a-profile/armv8a_cp15.h" |
There was a problem hiding this comment.
We should only include ../a-profile/armv8a_cp15.h
a2a53c0 to
d12fd55
Compare
| #include "../a-profile/armv8a_cp15.h" No newline at end of file | ||
| // The cp15-interface is located in the profile folder for cortex-a devices | ||
| #include "../a-profile/armv7a_cp15.h" | ||
| #include "../a-profile/armv8a_cp15.h" |
There was a problem hiding this comment.
@Masmiseim36 If I understand correctly, the SCTLR accessor for instance should use the following instruction for Cortex-R4/R5/R7/R8/R52/R52+/R82 when running in aarch32 state:
__asm volatile ("mrc p15, 0, %0, c1, c0, 0" : "=r" (sctlr)); as implemented in armv7a_cp15.h.
For Cortex-R82 running in aarch64 state, the equivalent would be:
__asm volatile ("mrs %0, SCTLR_EL1" : "=r" (sctlr)); as implemented in armv8a_cp15.h.
If that's correct, it seems that the current implementation may be a bit misleading, as the existing accessors do not appear to provide the appropriate SCTLR access mechanism for the aarch32 state.
What approach would you recommend? I can think of a few options, although there may well be better alternatives:
- Make the header selection dependent on the execution state (AArch32 vs AArch64).
- Duplicate armv7a_cp15.h for now, since Cortex-R82 support is not yet available.
- Expose all implementations and select the appropriate accessor based on the execution state or target architecture.
Extract the common L1 cache maintenance implementation into l1_cache.h and reuse it for Armv7-A, Armv7-R and Armv8-R.