-
Notifications
You must be signed in to change notification settings - Fork 8.4k
soc: riscv: esp32c6: add RISCV_PMP and USERSPACE support #100971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
soc: riscv: esp32c6: add RISCV_PMP and USERSPACE support #100971
Conversation
|
This PR can be split in 2 if mandatory to make it clear about riscv arch changes and soc itself. However, combining it here gives a better view of the SoC dependency. I gently ask the riscv maintainers to check the PMP memory changes and suggest alternatives if needed. Thanks! |
9d1944a to
809d527
Compare
Add infrastructure for SoCs to define additional PMP regions that need protection beyond the standard ROM region. This uses iterable sections to collect region definitions at link time. The PMP_SOC_REGION_DEFINE macro allows SoCs to register memory regions with specific permissions. These regions become global PMP entries shared between M-mode and U-mode. Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Add device tree node for ESP32-C6 SoC ROM at 0x40000000. This 320KB ROM contains libc and utility functions used by the application. PMP protection is configured separately via PMP_SOC_REGION_DEFINE in pmp_regions.c. Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Add linker script support for CONFIG_USERSPACE: - MPU alignment macros for PMP granularity - User stacks section in noinit area - Application shared memory partitions - Kernel object sections (text, rom, data, priv-stacks) - ROM region size symbol for PMP configuration Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
Enable RISC-V PMP for ESP32-C6 and configure appropriate defaults: - 16 PMP slots available on hardware - Unlocked global entries for XIP flash execution - MEM_ATTR subsystem for device tree memory regions Define SoC-specific PMP regions: - SoC ROM (0x40000000): libc functions, R+X - IRAM text: interrupt handlers and critical code, R+X Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
809d527 to
b25ae26
Compare
|
Question: have you considered using memory region with attributes? See e.g. here: https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/arch/riscv/pmp/mem-attr-entries/memattr_mapping.overlay |
Hi, that was my initial approach before adding the custom PMP region. See, IRAM and DRAM share the same physical memory region (internal SRAM), but need different PMP permissions:
With memory-attr overlays, you define static memory regions in DTS, but ESP32-C6's IRAM text section boundaries (_iram_text_start, _iram_text_end) are only known at link time - they depend on what code gets placed in IRAM. The other way around is to add the whole dram/iram with memory attributes, but that isn't correct. Thoughts? |



Summary
Description
This PR introduces a mechanism for RISC-V SoCs to define custom PMP regions
that are automatically programmed during PMP initialization. This is needed
for SoCs like ESP32-C6 where code execution spans multiple memory regions
(SoC ROM, IRAM, flash) that all need PMP coverage for userspace to work.
Changes
arch/riscv (generic infrastructure):
struct pmp_soc_regionandPMP_SOC_REGION_DEFINE()macro topmp.hpmp.ldfor iterable section collectionz_riscv_pmp_init()soc/espressif/esp32c6:
PMP_NO_LOCK_GLOBAL(required because PMP init runs from IRAMwhile the main rom region is in flash-mapped memory)
default.ldsoc_romdevice tree node for ROM region address/size