1 /*
2  * Copyright (c) 2017 Synopsys
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/devicetree.h>
8 #include <zephyr/arch/arc/v2/mpu/arc_mpu.h>
9 #include <zephyr/linker/linker-defs.h>
10 
11 /*
12  * for secure firmware, MPU entries are only set up for secure world.
13  * All regions not listed here are shared by secure world and normal world.
14  */
15 static struct arc_mpu_region mpu_regions[] = {
16 #if DT_REG_SIZE(DT_INST(0, arc_iccm)) > 0
17 	/* Region ICCM */
18 	MPU_REGION_ENTRY("ICCM",
19 			 DT_REG_ADDR(DT_INST(0, arc_iccm)),
20 			 DT_REG_SIZE(DT_INST(0, arc_iccm)),
21 			 REGION_ROM_ATTR),
22 #endif
23 #if DT_REG_SIZE(DT_INST(0, arc_dccm)) > 0
24 	/* Region DCCM */
25 	MPU_REGION_ENTRY("DCCM",
26 			 DT_REG_ADDR(DT_INST(0, arc_dccm)),
27 			 DT_REG_SIZE(DT_INST(0, arc_dccm)),
28 			 REGION_KERNEL_RAM_ATTR | REGION_DYNAMIC),
29 #endif
30 
31 #if DT_REG_SIZE(DT_INST(0, arc_xccm)) > 0
32 	/* Region XCCM */
33 	MPU_REGION_ENTRY("XCCM",
34 			 DT_REG_ADDR(DT_INST(0, arc_xccm)),
35 			 DT_REG_SIZE(DT_INST(0, arc_xccm)),
36 			 REGION_KERNEL_RAM_ATTR | REGION_DYNAMIC),
37 #endif
38 #if DT_REG_SIZE(DT_INST(0, arc_yccm)) > 0
39 	/* Region YCCM */
40 	MPU_REGION_ENTRY("YCCM",
41 			 DT_REG_ADDR(DT_INST(0, arc_yccm)),
42 			 DT_REG_SIZE(DT_INST(0, arc_yccm)),
43 			 REGION_KERNEL_RAM_ATTR | REGION_DYNAMIC),
44 #endif
45 
46 #if DT_REG_SIZE(DT_INST(0, mmio_sram)) > 0
47 	/* Region DDR RAM */
48 	MPU_REGION_ENTRY("DDR RAM",
49 			DT_REG_ADDR(DT_INST(0, mmio_sram)),
50 			DT_REG_SIZE(DT_INST(0, mmio_sram)),
51 			AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR | AUX_MPU_ATTR_UR |
52 			AUX_MPU_ATTR_KE | AUX_MPU_ATTR_UE | REGION_DYNAMIC),
53 #endif
54 
55 /*
56  * Region peripheral is shared by secure world and normal world by default,
57  * no need a static mpu entry. If some peripherals belong to secure world,
58  * add it here.
59  */
60 #ifndef CONFIG_ARC_SECURE_FIRMWARE
61 	/* Region Peripheral */
62 	MPU_REGION_ENTRY("PERIPHERAL",
63 			 0xF0000000,
64 			 64 * 1024,
65 			 REGION_KERNEL_RAM_ATTR)
66 #endif
67 };
68 
69 struct arc_mpu_config mpu_config = {
70 	.num_regions = ARRAY_SIZE(mpu_regions),
71 	.mpu_regions = mpu_regions,
72 };
73