hujun260 opened a new pull request, #18157:
URL: https://github.com/apache/nuttx/pull/18157
## Summary
This pull request series improves the ARM64 Memory Protection Unit (MPU)
implementation across three incremental commits:
1. **Explicit naming**: Rename MPU attribute macros to clearly indicate
access permissions (REGION_RAM_ATTR → REGION_RW_NA_ATTR, etc.)
2. **Unified interface**: Refactor MPU configuration functions to use
consistent parameters across all architectures
3. **Code simplification**: Consolidate macro definitions to eliminate
duplication while preserving functionality
These changes improve code clarity, ensure consistency across ARM64 variants
(including Cortex-R82), and reduce maintenance burden.
## Changes
**Commit 1: Rename MPU attribute macros (61 lines)**
- Rename `REGION_RAM_ATTR` → `REGION_RW_NA_ATTR` (Kernel Read/Write, User No
Access)
- Rename `REGION_URAM_ATTR` → `REGION_RW_RW_ATTR` (Kernel & User Read/Write)
- Rename `REGION_RAM_TEXT_ATTR` → `REGION_KTEXT_ATTR` (Kernel Text)
- Rename `REGION_RAM_UTEXT_ATTR` → `REGION_UTEXT_ATTR` (User Text)
- Add `REGION_RO_RO_ATTR` for read-only regions accessible to all
- Add `REGION_RO_NA_ATTR` for kernel read-only, user no access regions
- Update boot code to use new macro names
**Commit 2: Unify MPU interface (73 lines)**
- Change `mpu_modify_region(region, table)` → `mpu_modify_region(region,
base, size, flags1, flags2)`
- Change `mpu_configure_region(table)` → `mpu_configure_region(base, size,
flags1, flags2)`
- Direct parameter interface eliminates struct dependency
- Ensures consistency across all ARM64 MPU variants
- Update all callers in boot code
**Commit 3: Simplify macro definitions (125 lines)**
- Introduce unified `SHAREABLE_MSK` macro:
- CONFIG_SMP: `SHAREABLE_MSK = INNER_SHAREABLE_MSK`
- CONFIG_UP: `SHAREABLE_MSK = NON_SHAREABLE_MSK`
- Consolidate duplicated CONFIG_SMP/CONFIG_UP macro blocks
- Replace individual REGION_*_ATTR definitions with unified versions
- Result: 83 lines removed, 42 lines added (net -41 lines)
**Total Changes**: ~150 net lines simplified, improved consistency and
clarity
## Impact
- **Clarity**: Explicit permission semantics in macro names (RW_NA, RO_RO,
etc.)
- **Consistency**: Same interface across Cortex-A72, Cortex-R82, and other
ARM64 variants
- **Maintainability**: Reduced macro duplication and configuration complexity
- **Code reduction**: 41 net lines removed through consolidation
- **Extensibility**: Easier to add new attribute combinations
## Technical Details
**Naming convention improvements:**
| Old Name | New Name | Meaning |
|----------|----------|---------|
| REGION_RAM_ATTR | REGION_RW_NA_ATTR | Kernel RW, User NA |
| REGION_URAM_ATTR | REGION_RW_RW_ATTR | Kernel RW, User RW |
| REGION_RAM_TEXT_ATTR | REGION_KTEXT_ATTR | Kernel Text (Read-Only) |
| REGION_RAM_UTEXT_ATTR | REGION_UTEXT_ATTR | User Text (Read-Only) |
| NEW | REGION_RO_RO_ATTR | Kernel RO, User RO |
| NEW | REGION_RO_NA_ATTR | Kernel RO, User NA |
**Interface unification:**
```c
// Before: Struct-based (inconsistent across architectures)
struct arm64_mpu_region table = { ... };
mpu_modify_region(region, &table);
// After: Direct parameters (consistent everywhere)
mpu_modify_region(region, base, size, flags1, flags2);
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]