1 /*
2  * Copyright (c) 2021 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/arch/arc/arch.h>
10 #include <zephyr/linker/linker-defs.h>
11 
12 /*
13  * for secure firmware, MPU entries are only set up for secure world.
14  * All regions not listed here are shared by secure world and normal world.
15  */
16 static struct arc_mpu_region mpu_regions[] = {
17 
18 #if defined(CONFIG_COVERAGE_GCOV) && defined(CONFIG_USERSPACE)
19 	/* Region Coverage */
20 	MPU_REGION_ENTRY("COVERAGE",
21 			 (uint32_t)&(__gcov_bss_start),
22 			 (uint32_t)&__gcov_bss_size,
23 			 REGION_IO_ATTR),
24 #endif /* CONFIG_COVERAGE_GCOV && CONFIG_USERSPACE */
25 
26 #if DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) > 0
27 
28 #ifdef CONFIG_XIP
29 	/* Region RAM */
30 	MPU_REGION_ENTRY("RAM",
31 			 DT_REG_ADDR(DT_CHOSEN(zephyr_sram)),
32 			 DT_REG_SIZE(DT_CHOSEN(zephyr_sram)),
33 			 REGION_KERNEL_RAM_ATTR | REGION_DYNAMIC),
34 #else
35 	/* Region RAM */
36 	/*
37 	 * In case if Zephyr is configured with CONFIG_XIP=n it linked into
38 	 * SRAM. So RAM region should have EXECUTE permission.
39 	 */
40 	MPU_REGION_ENTRY("RAM_RX",
41 			 (uintptr_t)__rom_region_start,
42 			 (uintptr_t)__rom_region_size,
43 			 REGION_ROM_ATTR),
44 
45 	 MPU_REGION_ENTRY("RAM_RW",
46 			(uintptr_t)_image_ram_start,
47 			(uintptr_t)__arc_rw_sram_size,
48 			REGION_KERNEL_RAM_ATTR | REGION_DYNAMIC),
49 #endif /* CONFIG_XIP */
50 
51 #endif /* zephyr_sram > 0 */
52 
53 #if DT_REG_SIZE(DT_CHOSEN(zephyr_flash)) > 0
54 	/* Region DCCM */
55 	MPU_REGION_ENTRY("FLASH",
56 			 DT_REG_ADDR(DT_CHOSEN(zephyr_flash)),
57 			 DT_REG_SIZE(DT_CHOSEN(zephyr_flash)),
58 			 REGION_ROM_ATTR),
59 #endif
60 
61 /*
62  * Region peripheral is shared by secure world and normal world by default,
63  * no need a static mpu entry. If some peripherals belong to secure world,
64  * add it here.
65  */
66 #ifndef CONFIG_ARC_SECURE_FIRMWARE
67 	/* Region Peripheral */
68 	MPU_REGION_ENTRY("PERIPHERAL",
69 			 0xF0000000,
70 			 64 * 1024,
71 			 REGION_KERNEL_RAM_ATTR),
72 #endif
73 };
74 
75 struct arc_mpu_config mpu_config = {
76 	.num_regions = ARRAY_SIZE(mpu_regions),
77 	.mpu_regions = mpu_regions,
78 };
79