blob: 9e031786781ce6e7671149b9ee97f4d129dc93a0 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#ifndef _MPU_H
2#define _MPU_H
3
4typedef volatile struct
5{
6 int32_t dwNum;
7 int32_t dwBase;
8 int32_t dwSize;
9 int32_t dwMemAttr;
10 int32_t dwShare;
11 int32_t dwAP;
12 int32_t dwXN;
13 int32_t dwSubRegion;
14}T_Region_Attr;
15
16#define MPU_REGION_SO (0)// strongly-ordered memory
17#define MPU_REGION_SD (1)// ¹²ÏíÉ豸memory
18#define MPU_REGION_NM_INC_ONC (4)// nomal memory,²»ÄÜcache
19#define MPU_REGION_NM_IWBWA_OWBWA (7)// nomal memory, д»ØÐ´·ÖÅä
20#define MPU_REGION_NSD (8)// ·Ç¹²ÏíÉ豸memory
21#define MPU_REGION_NM_IWBWA_ONC (17)// nomal memory,²»ÄÜcacheµ½L2 cache£¬¿ÉÒÔµ½L1 cache д»ØÐ´·ÖÅä
22#define MPU_REGION_NM_INC_OWBWA (20)// nomal memory,²»ÄÜcacheµ½L1 cache£¬¿ÉÒÔµ½L2 cache д»ØÐ´·ÖÅä
23//#define MPU_REGION_NM_IWBWA_OWBWA (21)// nomal memory,¿ÉÒÔµ½L1 cache д»ØÐ´·ÖÅ䣬¿ÉÒÔµ½L2 cache д»ØÐ´·ÖÅä
24
25
26/* mpuÏà¹Ø¼Ä´æÆ÷λÓòºê¶¨Òå */
27/* MPU ÇøÓò»ùÖ·¼Ä´æÆ÷
28* λÖãºcp15 0 c6 c1 0
29* ¹¦ÄÜ˵Ã÷£ºÉèÖÃÇøÓò»ùÖ·
30* ʹÓÃ˵Ã÷£º1)Ö»ÄÜÔÚÌØÈ¨Ä£Ê½Ï·ÃÎÊ 2)ÓëÇøÓò´óС¶ÔÆë
31* Example£º MRC p15,0,<Rt>,c6,c1,0 ; Read
32* +---------------------------+-----------+
33* | 31- 5 | 4 - 0 |
34* +---------------------------+-----------+
35* | Base Address | Reserved |
36* +---------------------------+-----------+
37*/
38
39/* mpuÏà¹Ø¼Ä´æÆ÷λÓòºê¶¨Òå */
40/* MPU ÇøÓò´óС¼°Ê¹ÄܼĴæÆ÷
41* λÖãºcp15 0 c6 c1 2
42* ¹¦ÄÜ˵Ã÷£ºÉèÖÃÇøÓò´óС¼°Ê¹ÄÜÇøÓò¡¢×ÓÇøÓò
43* ʹÓÃ˵Ã÷£º1)Ö»ÄÜÔÚÌØÈ¨Ä£Ê½Ï·ÃÎÊ
44* Example£º MRC p15,0,<Rt>,c6,c1,2 ; Read
45* +---------------------------+-----------+
46* | 31-16| 15-8 | 7-6 | 5-1 | 0 |
47* +---------------------------+-----------+
48* | Re | SubRegion Dis| Re | Size | En |
49* +---------------------------+-----------+
50*/
51#define MPU_EN_POS (0)
52#define MPU_EN_MASK (0x1 << MPU_EN_POS)
53
54#define MPU_SIZE_POS (1)
55#define MPU_SIZE_MASK (0x1f << MPU_SIZE_POS)
56
57#define MPU_SUBREGION_DIS_POS (8)
58#define MPU_SUBREGION_DIS_MASK (0xff << MPU_SUBREGION_DIS_POS)
59
60#define MPU_REGIONG_EN
61#define MPU_REGIONG_DIS
62
63#define REGION_SIZE_256B 0x07
64#define REGION_SIZE_512B 0x08
65#define REGION_SIZE_1K 0x09
66#define REGION_SIZE_2K 0x0a
67#define REGION_SIZE_4K 0x0b
68#define REGION_SIZE_8K 0x0c
69#define REGION_SIZE_16K 0x0d
70#define REGION_SIZE_32K 0x0e
71#define REGION_SIZE_64K 0x0f
72#define REGION_SIZE_128K 0x10
73#define REGION_SIZE_256K 0x11
74#define REGION_SIZE_512K 0x12
75#define REGION_SIZE_1M 0x13
76#define REGION_SIZE_2M 0x14
77#define REGION_SIZE_4M 0x15
78#define REGION_SIZE_8M 0x16
79#define REGION_SIZE_16M 0x17
80#define REGION_SIZE_32M 0x18
81#define REGION_SIZE_64M 0x19
82#define REGION_SIZE_128M 0x1a
83#define REGION_SIZE_256M 0x1b
84#define REGION_SIZE_512M 0x1c
85#define REGION_SIZE_1G 0x1d
86#define REGION_SIZE_2G 0x1e
87#define REGION_SIZE_4G 0x1f
88
89/* mpuÏà¹Ø¼Ä´æÆ÷λÓòºê¶¨Òå */
90/* MPU ÇøÓò·ÃÎÊÊôÐÔ¿ØÖƼĴæÆ÷
91* λÖãºcp15 0 c6 c1 4
92* ¹¦ÄÜ˵Ã÷£ºÉèÖÃÇøÓò·ÃÎÊÊôÐÔ
93* ʹÓÃ˵Ã÷£º1)Ö»ÄÜÔÚÌØÈ¨Ä£Ê½Ï·ÃÎÊ
94* Example£º MRC p15,0,<Rt>,c6,c1,4 ; Read
95* +------------------------------+-----------------+
96* | 31-13 | 12 | 11 | 10-8 | 7-6 | 5-3 | 2 | 1 | 0 |
97* +------------------------------+-----------------+
98* | Re | XN | Re | AP | Re | TEX | S | C | B |
99* +------------------------------+-----------------+
100*/
101#define MPU_REGION_B_POS (0)
102#define MPU_REGION_B_MASK (0x1 << MPU_REGION_B_POS)
103
104#define MPU_REGION_C_POS (1)
105#define MPU_REGION_C_MASK (0x1 << MPU_REGION_C_POS)
106
107#define MPU_REGION_S_POS (2)
108#define MPU_REGION_S_MASK (0x1 << MPU_REGION_S_POS)
109
110#define MPU_REGION_TEX_POS (3)
111#define MPU_REGION_TEX_MASK (0x7 << MPU_REGION_TEX_POS)
112
113#define MPU_REGION_AP_POS (8)
114#define MPU_REGION_AP_MASK (0x7 << MPU_REGION_AP_POS)
115
116#define MPU_REGION_XN_POS (12)
117#define MPU_REGION_XN_MASK (0x1 << MPU_REGION_XN_POS)
118
119/* mpuÏà¹Ø¼Ä´æÆ÷λÓòºê¶¨Òå */
120/* MPU ÇøÓòÑ¡Ôñ¼Ä´æÆ÷
121* λÖãºcp15 0 c6 c2 0
122* ¹¦ÄÜ˵Ã÷£ºÉèÖÃÇøÓò»ùÖ·
123* ʹÓÃ˵Ã÷£º1)Ö»ÄÜÔÚÌØÈ¨Ä£Ê½Ï·ÃÎÊ 2)ÓëÇøÓò´óС¶ÔÆë
124* Example£º MRC p15,0,<Rt>,c6,c2,0 ; Read
125* +---------------------------+-----------+
126* | 31- 4 | 3 - 0 |
127* +---------------------------+-----------+
128* | Re | Region |
129* +---------------------------+-----------+
130*/
131
132
133#define MPU_REGION_NUM_POS (0)
134#define MPU_REGION_NUM_MASK (0xf << MPU_REGION_NUM_POS)
135
136
137
138
139int32_t MPU_RegionInit(T_Region_Attr* ptRegion);
140void MPU_Init(void);
141int32_t MPU_Size2Sec(int32_t dwSize);
142void MPU_RegionDisable(int32_t dwNum, int32_t dwEnable);
143
144
145#endif
146