1414#include <rtthread.h>
1515#include <mm_aspace.h>
1616
17- #define DESC_SEC (0x2)
17+
18+ /**
19+ * Level 1 translation table entry format
20+ *
21+ * It has 4 types:
22+ * Fault type: bit[1:0] = 0b00
23+ * Point L2 page type: bit[1:0] = 0b01
24+ * Section type: bit[1:0] = 0b10 and bit[18] = 0
25+ * Supersection type: bit[1:0] = 0b10 and bit[18] = 1
26+ *
27+ * The following defines are for section type entry
28+ * bit[01:00]: 0b10
29+ * bit[02] : B
30+ * bit[03] : C
31+ * bit[04] : XN
32+ * bit[08:05]: Domain
33+ * bit[09] : P
34+ * bit[11:10]: AP
35+ * bit[14:12]: TEX
36+ * bit[15] : APX
37+ * bit[16] : S
38+ * bit[17] : nG
39+ * bit[18] : 0
40+ * bit[19] : SBZ
41+ * bit[31:20]: Section Bass Address
42+ */
43+
44+ #define DESC_SEC (0x2) /* for section type */
45+
46+ /* memory types and attributes(TEX C B) */
1847#define MEMWBWA ((1<<12)|(3<<2)) /* write back, write allocate */
19- #define MEMWB (3<<2) /* write back, no write allocate */
20- #define MEMWT (2<<2) /* write through, no write allocate */
21- #define SHAREDEVICE (1<<2) /* shared device */
22- #define STRONGORDER (0<<2) /* strong ordered */
23- #define XN (1<<4) /* eXecute Never */
48+ #define MEMWB (3<<2) /* write back, no write allocate */
49+ #define MEMWT (2<<2) /* write through, no write allocate */
50+ #define SHAREDEVICE (1<<2) /* shared device */
51+ #define STRONGORDER (0<<2) /* strong ordered */
52+
53+ #define XN (1<<4)
54+
55+ /* memory access permissions(AP APX) */
2456#ifdef RT_USING_SMART
25- #define AP_RW (1<<10) /* supervisor=RW, user=No */
26- #define AP_RO ((1<<10) |(1 << 15)) /* supervisor=RW , user=No */
57+ #define AP_RW (1<<10) /* supervisor=RW, user=No */
58+ #define AP_RO ((1<<10) | (1 << 15)) /* supervisor=RO , user=No */
2759#else
28- #define AP_RW (3<<10) /* supervisor=RW, user=RW */
29- #define AP_RO (2<<10) /* supervisor=RW, user=RO */
60+ #define AP_RW (3<<10) /* supervisor=RW, user=RW */
61+ #define AP_RO (2<<10) /* supervisor=RW, user=RO */
3062#endif
3163
32- #define SHARED (1<<16) /* shareable */
64+ #define SHARED (1 << 16)
65+
66+ /* DACR, Domain n access permission */
67+ #define DOMAIN_FAULT (0x0) /* 0b00: No access */
68+ #define DOMAIN_CHK (0x1) /* 0b01: Client */
69+ #define DOMAIN_NOTCHK (0x3) /* 0b11: No check */
3370
34- #define DOMAIN_FAULT (0x0)
35- #define DOMAIN_CHK (0x1)
36- #define DOMAIN_NOTCHK (0x3)
71+ /* Domain */
3772#define DOMAIN0 (0x0<<5)
3873#define DOMAIN1 (0x1<<5)
3974
40- #define DOMAIN0_ATTR (DOMAIN_CHK<<0)
41- #define DOMAIN1_ATTR (DOMAIN_FAULT<<2)
42-
43- /* device mapping type */
44- #define DEVICE_MEM (SHARED|AP_RW|DOMAIN0|SHAREDEVICE|DESC_SEC|XN)
45- /* normal memory mapping type */
46- #define NORMAL_MEM (SHARED|AP_RW|DOMAIN0|MEMWBWA|DESC_SEC)
75+ /* DACR */
76+ #define DOMAIN0_ATTR (DOMAIN_CHK<<0) /* domain0 use client mode */
77+ #define DOMAIN1_ATTR (DOMAIN_FAULT<<2) /* domain1 use no access mode */
4778
79+ /* Memory types */
80+ #define DEVICE_MEM (SHARED|AP_RW|DOMAIN0|SHAREDEVICE|DESC_SEC|XN)
81+ #define NORMAL_MEM (SHARED|AP_RW|DOMAIN0|MEMWBWA|DESC_SEC)
4882#define STRONG_ORDER_MEM (SHARED|AP_RO|XN|DESC_SEC)
4983
5084struct mem_desc
@@ -56,6 +90,26 @@ struct mem_desc
5690 struct rt_varea varea ;
5791};
5892
93+ /**
94+ * Level 2 translation table entry format
95+ *
96+ * It has 3 types:
97+ * Fault: bit[1:0] = 0b00
98+ * Larger page: bit[1:0] = 0b01
99+ * Small page: bit[1:0] = 0b1x
100+ *
101+ * The following defines are for small page type entry
102+ * bit[00]: XN
103+ * bit[01]: 1
104+ * bit[02]: B
105+ * bit[03]: C
106+ * bit[05:04]: AP
107+ * bit[08:06]: TEX
108+ * bit[09]: APX
109+ * bit[10]: S
110+ * bit[11]: nG
111+ * bit[31:12]: Small Page Base Address
112+ */
59113#define MMU_MAP_MTBL_XN (1<<0)
60114#define MMU_MAP_MTBL_A (1<<1)
61115#define MMU_MAP_MTBL_B (1<<2)
@@ -101,12 +155,12 @@ struct mem_desc
101155 */
102156#define ARCH_MAP_FAILED ((void *)-1)
103157
104- #define RT_HW_MMU_PROT_READ 1
105- #define RT_HW_MMU_PROT_WRITE 2
158+ #define RT_HW_MMU_PROT_READ 1
159+ #define RT_HW_MMU_PROT_WRITE 2
106160#define RT_HW_MMU_PROT_EXECUTE 4
107- #define RT_HW_MMU_PROT_KERNEL 8
108- #define RT_HW_MMU_PROT_USER 16
109- #define RT_HW_MMU_PROT_CACHE 32
161+ #define RT_HW_MMU_PROT_KERNEL 8
162+ #define RT_HW_MMU_PROT_USER 16
163+ #define RT_HW_MMU_PROT_CACHE 32
110164
111165int rt_hw_mmu_ioremap_init (struct rt_aspace * aspace , void * v_address , size_t size );
112166void rt_hw_init_mmu_table (struct mem_desc * mdesc , rt_uint32_t size );
@@ -128,7 +182,7 @@ int rt_hw_mmu_control(struct rt_aspace *aspace, void *vaddr, size_t size, enum r
128182void * rt_hw_mmu_pgtbl_create (void );
129183void rt_hw_mmu_pgtbl_delete (void * pgtbl );
130184
131- #define AP_APX_MASK (MMU_MAP_MTBL_AP2(0x1) | MMU_MAP_MTBL_AP01(0x3))
185+ #define AP_APX_MASK (MMU_MAP_MTBL_AP2(0x1) | MMU_MAP_MTBL_AP01(0x3))
132186#define AP_APX_URW_KRW (MMU_MAP_MTBL_AP2(0x0) | MMU_MAP_MTBL_AP01(0x3))
133187#define AP_APX_URO_KRO (MMU_MAP_MTBL_AP2(0x1) | MMU_MAP_MTBL_AP01(0x2))
134188
0 commit comments