[NTOS]: Define portable MI_MAKE_ACCESSED_PAGE macro.
[reactos.git] / reactos / ntoskrnl / include / internal / arm / mm.h
1 #pragma once
2
3 #define PDE_SHIFT 20
4
5 //
6 // Number of bits corresponding to the area that a coarse page table entry represents (4KB)
7 //
8 #define PTE_SHIFT 12
9 #define PTE_SIZE (1 << PTE_SHIFT)
10
11 //
12 // Number of bits corresponding to the area that a coarse page table occupies (1KB)
13 //
14 #define CPT_SHIFT 10
15 #define CPT_SIZE (1 << CPT_SHIFT)
16
17 //
18 // Base Addresses
19 //
20 #define PTE_BASE 0xC0000000
21 #define PTE_TOP 0xC03FFFFF
22 #define PDE_BASE 0xC0400000
23 #define PDE_TOP 0xC04FFFFF
24 #define HYPER_SPACE 0xC0500000
25
26 #if 0
27 typedef struct _HARDWARE_PDE_ARMV6
28 {
29 ULONG Valid:1; // Only for small pages
30 ULONG LargePage:1; // Note, if large then Valid = 0
31 ULONG Buffered:1;
32 ULONG Cached:1;
33 ULONG NoExecute:1;
34 ULONG Domain:4;
35 ULONG Ecc:1;
36 ULONG PageFrameNumber:22;
37 } HARDWARE_PDE_ARMV6, *PHARDWARE_PDE_ARMV6;
38
39 typedef struct _HARDWARE_LARGE_PTE_ARMV6
40 {
41 ULONG Valid:1; // Only for small pages
42 ULONG LargePage:1; // Note, if large then Valid = 0
43 ULONG Buffered:1;
44 ULONG Cached:1;
45 ULONG NoExecute:1;
46 ULONG Domain:4;
47 ULONG Ecc:1;
48 ULONG Accessed:1;
49 ULONG Owner:1;
50 ULONG CacheAttributes:3;
51 ULONG ReadOnly:1;
52 ULONG Shared:1;
53 ULONG NonGlobal:1;
54 ULONG SuperLagePage:1;
55 ULONG Reserved:1;
56 ULONG PageFrameNumber:12;
57 } HARDWARE_LARGE_PTE_ARMV6, *PHARDWARE_LARGE_PTE_ARMV6;
58
59 typedef struct _HARDWARE_PTE_ARMV6
60 {
61 ULONG NoExecute:1;
62 ULONG Valid:1;
63 ULONG Buffered:1;
64 ULONG Cached:1;
65 ULONG Accessed:1;
66 ULONG Owner:1;
67 ULONG CacheAttributes:3;
68 ULONG ReadOnly:1;
69 ULONG Shared:1;
70 ULONG NonGlobal:1;
71 ULONG PageFrameNumber:20;
72 } HARDWARE_PTE_ARMV6, *PHARDWARE_PTE_ARMV6;
73
74 C_ASSERT(sizeof(HARDWARE_PDE_ARMV6) == sizeof(ULONG));
75 C_ASSERT(sizeof(HARDWARE_LARGE_PTE_ARMV6) == sizeof(ULONG));
76 C_ASSERT(sizeof(HARDWARE_PTE_ARMV6) == sizeof(ULONG));
77 #endif
78
79 /* For FreeLDR */
80 typedef struct _PAGE_TABLE_ARM
81 {
82 HARDWARE_PTE_ARMV6 Pte[1024];
83 } PAGE_TABLE_ARM, *PPAGE_TABLE_ARM;
84
85 typedef struct _PAGE_DIRECTORY_ARM
86 {
87 union
88 {
89 HARDWARE_PDE_ARMV6 Pde[4096];
90 HARDWARE_LARGE_PTE_ARMV6 Pte[4096];
91 };
92 } PAGE_DIRECTORY_ARM, *PPAGE_DIRECTORY_ARM;
93
94 C_ASSERT(sizeof(PAGE_TABLE_ARM) == PAGE_SIZE);
95 C_ASSERT(sizeof(PAGE_DIRECTORY_ARM) == (4 * PAGE_SIZE));
96
97 typedef enum _ARM_DOMAIN
98 {
99 FaultDomain,
100 ClientDomain,
101 InvalidDomain,
102 ManagerDomain
103 } ARM_DOMAIN;
104
105 struct _EPROCESS;
106 PULONG MmGetPageDirectory(VOID);
107
108 #define MI_MAKE_LOCAL_PAGE(x) ((x)->u.Hard.NonGlobal = 1)
109 #define MI_MAKE_DIRTY_PAGE(x)
110 #define MI_MAKE_ACCESSED_PAGE(x)
111 #define MI_MAKE_OWNER_PAGE(x) ((x)->u.Hard.Owner = 1)
112 #define MI_MAKE_WRITE_PAGE(x) ((x)->u.Hard.ReadOnly = 0)
113 #define MI_PAGE_DISABLE_CACHE(x) ((x)->u.Hard.Cached = 0)
114 #define MI_PAGE_WRITE_THROUGH(x) ((x)->u.Hard.Buffered = 0)
115 #define MI_PAGE_WRITE_COMBINED(x) ((x)->u.Hard.Buffered = 1)
116 #define MI_IS_PAGE_WRITEABLE(x) ((x)->u.Hard.ReadOnly == 0)
117 #define MI_IS_PAGE_COPY_ON_WRITE(x)FALSE
118 #define MI_IS_PAGE_DIRTY(x) TRUE
119
120 /* Easy accessing PFN in PTE */
121 #define PFN_FROM_PTE(v) ((v)->u.Hard.PageFrameNumber)
122
123 #define NR_SECTION_PAGE_TABLES 1024
124 #define NR_SECTION_PAGE_ENTRIES 256
125
126 /* See PDR definition */
127 #define MI_HYPERSPACE_PTES (256 - 1)
128 #define MI_ZERO_PTES (32)
129 #define MI_MAPPING_RANGE_START ((ULONG)HYPER_SPACE)
130 #define MI_MAPPING_RANGE_END (MI_MAPPING_RANGE_START + \
131 MI_HYPERSPACE_PTES * PAGE_SIZE)
132 #define MI_ZERO_PTE (PMMPTE)(MI_MAPPING_RANGE_END + \
133 PAGE_SIZE)
134
135 /* Retrives the PDE entry for the given VA */
136 #define MiGetPdeAddress(x) ((PMMPDE)(PDE_BASE + (((ULONG)(x) >> 20) << 2)))
137 #define MiAddressToPde(x) MiGetPdeAddress(x)
138
139 /* Retrieves the PTE entry for the given VA */
140 #define MiGetPteAddress(x) ((PMMPTE)(PTE_BASE + (((ULONG)(x) >> 12) << 2)))
141 #define MiAddressToPte(x) MiGetPteAddress(x)
142
143 /* Retrives the PDE offset for the given VA */
144 #define MiGetPdeOffset(x) (((ULONG)(x)) >> 20)
145
146 /* Convert a PTE into a corresponding address */
147 #define MiPteToAddress(x) ((PVOID)((ULONG)(x) << 10))
148 #define MiPdeToAddress(x) ((PVOID)((ULONG)(x) << 18))
149
150 #define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
151 ((x) / (4*1024*1024))
152
153 #define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) \
154 ((((x)) % (4*1024*1024)) / (4*1024))
155
156 #define MM_CACHE_LINE_SIZE 64