|
1 | 1 | /* SPDX-License-Identifier: Apache-2.0 |
2 | 2 | * |
3 | 3 | * Copyright (c) 2021 Lexmark International, Inc. |
| 4 | + * Copyright (c) 2025 Immo Birnbaum |
4 | 5 | */ |
5 | 6 |
|
6 | 7 | #include <zephyr/kernel.h> |
7 | | -#include <zephyr/arch/arm/mpu/arm_mpu.h> |
| 8 | +#include <zephyr/arch/arm/cortex_m/arm_mpu_mem_cfg.h> |
8 | 9 |
|
9 | | -#define MPUTYPE_READ_ONLY \ |
10 | | - { \ |
11 | | - .rasr = (P_RO_U_RO_Msk \ |
12 | | - | (7 << MPU_RASR_TEX_Pos) \ |
13 | | - | MPU_RASR_C_Msk \ |
14 | | - | MPU_RASR_B_Msk \ |
15 | | - | MPU_RASR_XN_Msk) \ |
16 | | - } |
| 10 | +extern const uint32_t __rom_region_start; |
| 11 | +extern const uint32_t __rom_region_mpu_size_bits; |
17 | 12 |
|
18 | | -#define MPUTYPE_READ_ONLY_PRIV \ |
19 | | - { \ |
20 | | - .rasr = (P_RO_U_RO_Msk \ |
21 | | - | (5 << MPU_RASR_TEX_Pos) \ |
22 | | - | MPU_RASR_B_Msk) \ |
23 | | - } |
24 | | - |
25 | | -#define MPUTYPE_PRIV_WBWACACHE_XN \ |
26 | | - { \ |
27 | | - .rasr = (P_RW_U_NA_Msk \ |
28 | | - | (5 << MPU_RASR_TEX_Pos) \ |
29 | | - | MPU_RASR_B_Msk \ |
30 | | - | MPU_RASR_XN_Msk) \ |
31 | | - } |
32 | | - |
33 | | -#define MPUTYPE_PRIV_DEVICE \ |
34 | | - { \ |
35 | | - .rasr = (P_RW_U_NA_Msk \ |
36 | | - | (2 << MPU_RASR_TEX_Pos)) \ |
37 | | - } |
38 | | - |
39 | | -extern uint32_t _image_rom_end_order; |
40 | 13 | static const struct arm_mpu_region mpu_regions[] = { |
41 | | - MPU_REGION_ENTRY("FLASH0", |
42 | | - 0xc0000000, |
43 | | - REGION_32M, |
44 | | - MPUTYPE_READ_ONLY), |
45 | | - |
46 | | - MPU_REGION_ENTRY("SRAM_PRIV", |
47 | | - 0x00000000, |
48 | | - REGION_2G, |
49 | | - MPUTYPE_PRIV_WBWACACHE_XN), |
50 | | - |
51 | | - MPU_REGION_ENTRY("SRAM", |
52 | | - 0x00000000, |
53 | | - ((uint32_t)&_image_rom_end_order), |
54 | | - MPUTYPE_READ_ONLY_PRIV), |
55 | | - |
56 | | - MPU_REGION_ENTRY("REGISTERS", |
57 | | - 0xf8000000, |
58 | | - REGION_128M, |
59 | | - MPUTYPE_PRIV_DEVICE), |
| 14 | + /* |
| 15 | + * The address of the vectors is determined by arch/arm/core/cortex_a_r/prep_c.c |
| 16 | + * -> for v7-R, there's no other option than 0x0, HIVECS always gets cleared |
| 17 | + */ |
| 18 | + MPU_REGION_ENTRY( |
| 19 | + "vectors", |
| 20 | + 0x00000000, |
| 21 | + REGION_64B, |
| 22 | + {.rasr = P_RO_U_NA_Msk | |
| 23 | + NORMAL_OUTER_INNER_NON_CACHEABLE_NON_SHAREABLE}), |
| 24 | + /* Basic SRAM mapping is all data, R/W + XN */ |
| 25 | + MPU_REGION_ENTRY( |
| 26 | + "sram", |
| 27 | + CONFIG_SRAM_BASE_ADDRESS, |
| 28 | + REGION_SRAM_SIZE, |
| 29 | + {.rasr = P_RW_U_NA_Msk | |
| 30 | + NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_SHAREABLE | |
| 31 | + NOT_EXEC}), |
| 32 | +#if defined(CONFIG_XIP) |
| 33 | + /* .text and .rodata (=rom_region) are in flash, must be RO + executable */ |
| 34 | + MPU_REGION_ENTRY( |
| 35 | + "rom_region", |
| 36 | + CONFIG_FLASH_BASE_ADDRESS, |
| 37 | + REGION_FLASH_SIZE, |
| 38 | + {.rasr = P_RO_U_RO_Msk | |
| 39 | + NORMAL_OUTER_INNER_WRITE_BACK_NON_SHAREABLE}), |
| 40 | + /* RAM contains R/W data, non-executable */ |
| 41 | +#else /* !CONFIG_XIP */ |
| 42 | + /* .text and .rodata are in RAM, flash is data only -> RO + XN */ |
| 43 | + MPU_REGION_ENTRY( |
| 44 | + "flash", |
| 45 | + CONFIG_FLASH_BASE_ADDRESS, |
| 46 | + REGION_FLASH_SIZE, |
| 47 | + {.rasr = P_RO_U_RO_Msk | |
| 48 | + NORMAL_OUTER_INNER_WRITE_BACK_NON_SHAREABLE | |
| 49 | + NOT_EXEC}), |
| 50 | + /* add rom_region mapping for SRAM which is RO + executable */ |
| 51 | + MPU_REGION_ENTRY( |
| 52 | + "rom_region", |
| 53 | + (uint32_t)(&__rom_region_start), |
| 54 | + (uint32_t)(&__rom_region_mpu_size_bits), |
| 55 | + {.rasr = P_RO_U_RO_Msk | |
| 56 | + NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_SHAREABLE}), |
| 57 | +#endif /* CONFIG_XIP */ |
| 58 | + MPU_REGION_ENTRY( |
| 59 | + "peripherals", |
| 60 | + 0xf8000000, |
| 61 | + REGION_128M, |
| 62 | + {.rasr = P_RW_U_NA_Msk | |
| 63 | + DEVICE_SHAREABLE | |
| 64 | + NOT_EXEC}), |
| 65 | +#if (DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ocm), okay)) |
| 66 | + MPU_REGION_ENTRY( |
| 67 | + "ocm", |
| 68 | + DT_REG_ADDR(DT_CHOSEN(zephyr_ocm)), |
| 69 | + REGION_256K, |
| 70 | + {.rasr = FULL_ACCESS_Msk | |
| 71 | + STRONGLY_ORDERED_SHAREABLE | |
| 72 | + NOT_EXEC}), |
| 73 | +#endif |
60 | 74 | }; |
61 | 75 |
|
62 | 76 | const struct arm_mpu_config mpu_config = { |
|
0 commit comments