Skip to content

Commit c6af575

Browse files
committed
soc: xlnx: zynqmp: overhaul MPU regions
Overhaul the MPU region definitions that are being configured when the MPU is set up: - drop local attribute definitions in favor of those already provided in arm_mpu_v7m.h - actually tie the RAM region to the device tree - set up a (potentially overlapping) R/O region for .text and .rodata, which hasn't existed so far - Consider XIP Signed-off-by: Immo Birnbaum <[email protected]>
1 parent fdfb0df commit c6af575

File tree

1 file changed

+64
-50
lines changed

1 file changed

+64
-50
lines changed

soc/xlnx/zynqmp/arm_mpu_regions.c

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,76 @@
11
/* SPDX-License-Identifier: Apache-2.0
22
*
33
* Copyright (c) 2021 Lexmark International, Inc.
4+
* Copyright (c) 2025 Immo Birnbaum
45
*/
56

67
#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>
89

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;
1712

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;
4013
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
6074
};
6175

6276
const struct arm_mpu_config mpu_config = {

0 commit comments

Comments
 (0)