1 /*
2  * Copyright (c) 2017 Synopsys.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef ZEPHYR_INCLUDE_ARCH_ARC_V2_MPU_ARC_MPU_H_
7 #define ZEPHYR_INCLUDE_ARCH_ARC_V2_MPU_ARC_MPU_H_
8 
9 
10 
11 #define AUX_MPU_ATTR_UE  0x008    /* allow user execution */
12 #define AUX_MPU_ATTR_UW  0x010    /* allow user write */
13 #define AUX_MPU_ATTR_UR  0x020    /* allow user read */
14 #define AUX_MPU_ATTR_KE  0x040    /* only allow kernel execution */
15 #define AUX_MPU_ATTR_KW  0x080    /* only allow kernel write */
16 #define AUX_MPU_ATTR_KR  0x100    /* only allow kernel read */
17 #define AUX_MPU_ATTR_S   0x8000   /* secure */
18 #define AUX_MPU_ATTR_N   0x0000   /* normal */
19 
20 
21 /*
22  * a region is dynamic means it can be split into sub regions.
23  * This attribute is meaningful for ARC MPUv3 which does not support mpu
24  * entry overlap. For ARC MPUv2, this attribute will be ignored as it
25  * supports mpu overlap in hardware.
26  */
27 #define REGION_DYNAMIC  0x800  /* dynamic flag */
28 
29 
30 /* Some helper defines for common regions */
31 
32 #define REGION_KERNEL_RAM_ATTR \
33 			(AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR)
34 
35 #define REGION_KERNEL_ROM_ATTR \
36 			(AUX_MPU_ATTR_KE | AUX_MPU_ATTR_KR)
37 
38 #define REGION_RAM_ATTR	\
39 			(AUX_MPU_ATTR_UW | AUX_MPU_ATTR_UR | \
40 			 AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR)
41 
42 #define REGION_ROM_ATTR \
43 			(AUX_MPU_ATTR_UE | AUX_MPU_ATTR_UR | \
44 			 AUX_MPU_ATTR_KE | AUX_MPU_ATTR_KR)
45 
46 #define REGION_IO_ATTR \
47 			(AUX_MPU_ATTR_UW | AUX_MPU_ATTR_UR | \
48 			 AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR)
49 
50 #define REGION_ALL_ATTR \
51 			(AUX_MPU_ATTR_UW | AUX_MPU_ATTR_UR | \
52 			 AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR | \
53 			 AUX_MPU_ATTR_KE | AUX_MPU_ATTR_UE)
54 
55 
56 #define REGION_32B      0x200
57 #define REGION_64B      0x201
58 #define REGION_128B     0x202
59 #define REGION_256B     0x203
60 #define REGION_512B     0x400
61 #define REGION_1K       0x401
62 #define REGION_2K       0x402
63 #define REGION_4K       0x403
64 #define REGION_8K       0x600
65 #define REGION_16K      0x601
66 #define REGION_32K      0x602
67 #define REGION_64K      0x603
68 #define REGION_128K     0x800
69 #define REGION_256K     0x801
70 #define REGION_512K     0x802
71 #define REGION_1M       0x803
72 #define REGION_2M       0xA00
73 #define REGION_4M       0xA01
74 #define REGION_8M       0xA02
75 #define REGION_16M      0xA03
76 #define REGION_32M      0xC00
77 #define REGION_64M      0xC01
78 #define REGION_128M     0xC02
79 #define REGION_256M     0xC03
80 #define REGION_512M     0xE00
81 #define REGION_1G       0xE01
82 #define REGION_2G       0xE02
83 #define REGION_4G       0xE03
84 
85 /* Region definition data structure */
86 struct arc_mpu_region {
87 	/* Region Name */
88 	const char *name;
89 	/* Region Base Address */
90 	uint32_t base;
91 	uint32_t size;
92 	/* Region Attributes */
93 	uint32_t attr;
94 };
95 
96 #define MPU_REGION_ENTRY(_name, _base, _size, _attr) \
97 	{\
98 		.name = _name, \
99 		.base = _base, \
100 		.size = _size, \
101 		.attr = _attr, \
102 	}
103 
104 /* MPU configuration data structure */
105 struct arc_mpu_config {
106 	/* Number of regions */
107 	uint32_t num_regions;
108 	/* Regions */
109 	struct arc_mpu_region *mpu_regions;
110 };
111 
112 /* Reference to the MPU configuration */
113 extern struct arc_mpu_config mpu_config;
114 
115 #endif /* _ARC_CORE_MPU_H_ */
116