1 /* SPDX-License-Identifier: Apache-2.0
2  *
3  * Copyright (c) 2021 Lexmark International, Inc.
4  * Copyright (c) 2024 Antmicro <www.antmicro.com>
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/arch/arm/mpu/arm_mpu.h>
9 
10 #define MPUTYPE_READ_ONLY \
11 	{ \
12 		.rasr = (P_RO_U_RO_Msk \
13 				| (7 << MPU_RASR_TEX_Pos) \
14 				| MPU_RASR_C_Msk \
15 				| MPU_RASR_B_Msk \
16 				| MPU_RASR_XN_Msk) \
17 	}
18 
19 #define MPUTYPE_READ_ONLY_PRIV \
20 	{ \
21 		.rasr = (P_RO_U_RO_Msk \
22 				| (5 << MPU_RASR_TEX_Pos) \
23 				| MPU_RASR_B_Msk) \
24 	}
25 
26 #define MPUTYPE_PRIV_WBWACACHE_XN \
27 	{ \
28 		.rasr = (P_RW_U_NA_Msk \
29 				| (5 << MPU_RASR_TEX_Pos) \
30 				| MPU_RASR_B_Msk \
31 				| MPU_RASR_XN_Msk) \
32 	}
33 
34 #define MPUTYPE_PRIV_DEVICE \
35 	{ \
36 		.rasr = (P_RW_U_NA_Msk \
37 				| (2 << MPU_RASR_TEX_Pos)) \
38 	}
39 
40 extern uint32_t _image_rom_end_order;
41 static const struct arm_mpu_region mpu_regions[] = {
42 	MPU_REGION_ENTRY("FLASH0",
43 			0xc0000000,
44 			REGION_32M,
45 			MPUTYPE_READ_ONLY),
46 
47 	MPU_REGION_ENTRY("SRAM_PRIV",
48 			0x00000000,
49 			REGION_2G,
50 			MPUTYPE_PRIV_WBWACACHE_XN),
51 
52 	MPU_REGION_ENTRY("SRAM",
53 			0x00000000,
54 			((uint32_t)&_image_rom_end_order),
55 			MPUTYPE_READ_ONLY_PRIV),
56 
57 	MPU_REGION_ENTRY("REGISTERS",
58 			0xf8000000,
59 			REGION_128M,
60 			MPUTYPE_PRIV_DEVICE),
61 };
62 
63 const struct arm_mpu_config mpu_config = {
64 	.num_regions = ARRAY_SIZE(mpu_regions),
65 	.mpu_regions = mpu_regions,
66 };
67