This source file includes following definitions.
- pte_none
- pte_present
- pte_inuse
- pte_clear
- pte_reuse
- pmd_none
- pmd_bad
- pmd_present
- pmd_inuse
- pmd_inuse
- pmd_clear
- pmd_reuse
- pgd_none
- pgd_bad
- pgd_present
- pgd_inuse
- pgd_clear
- pte_read
- pte_write
- pte_exec
- pte_dirty
- pte_young
- pte_cow
- pte_wrprotect
- pte_rdprotect
- pte_exprotect
- pte_mkclean
- pte_mkold
- pte_uncow
- pte_mkwrite
- pte_mkread
- pte_mkexec
- pte_mkdirty
- pte_mkyoung
- pte_mkcow
- mk_pte
- pte_modify
- pte_page
- pmd_page
- pgd_offset
- pmd_offset
- pte_offset
- pte_free_kernel
- pte_alloc_kernel
- pmd_free_kernel
- pmd_alloc_kernel
- pte_free
- pte_alloc
- pmd_free
- pmd_alloc
- pgd_free
- pgd_alloc
- update_mmu_cache
1 #ifndef _I386_PGTABLE_H
2 #define _I386_PGTABLE_H
3
4
5
6
7
8 #define CONFIG_PENTIUM_MM 1
9
10
11
12
13
14
15
16
17
18
19
20
21 #define PMD_SHIFT 22
22 #define PMD_SIZE (1UL << PMD_SHIFT)
23 #define PMD_MASK (~(PMD_SIZE-1))
24
25
26 #define PGDIR_SHIFT 22
27 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
28 #define PGDIR_MASK (~(PGDIR_SIZE-1))
29
30
31
32
33
34 #define PTRS_PER_PTE 1024
35 #define PTRS_PER_PMD 1
36 #define PTRS_PER_PGD 1024
37
38
39
40
41
42
43
44
45 #define VMALLOC_OFFSET (8*1024*1024)
46 #define VMALLOC_START ((high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
47 #define VMALLOC_VMADDR(x) (TASK_SIZE + (unsigned long)(x))
48
49
50
51
52
53
54
55
56 #define _PAGE_PRESENT 0x001
57 #define _PAGE_RW 0x002
58 #define _PAGE_USER 0x004
59 #define _PAGE_PCD 0x010
60 #define _PAGE_ACCESSED 0x020
61 #define _PAGE_DIRTY 0x040
62 #define _PAGE_4M 0x080
63 #define _PAGE_COW 0x200
64
65 #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
66 #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
67
68 #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
69 #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
70 #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_COW)
71 #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
72 #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
73
74
75
76
77
78 #define __P000 PAGE_NONE
79 #define __P001 PAGE_READONLY
80 #define __P010 PAGE_COPY
81 #define __P011 PAGE_COPY
82 #define __P100 PAGE_READONLY
83 #define __P101 PAGE_READONLY
84 #define __P110 PAGE_COPY
85 #define __P111 PAGE_COPY
86
87 #define __S000 PAGE_NONE
88 #define __S001 PAGE_READONLY
89 #define __S010 PAGE_SHARED
90 #define __S011 PAGE_SHARED
91 #define __S100 PAGE_READONLY
92 #define __S101 PAGE_READONLY
93 #define __S110 PAGE_SHARED
94 #define __S111 PAGE_SHARED
95
96
97
98
99
100
101 #undef CONFIG_TEST_VERIFY_AREA
102
103
104 extern unsigned long pg0[1024];
105
106 extern unsigned long empty_zero_page[1024];
107
108
109
110
111
112
113
114
115 extern pte_t __bad_page(void);
116 extern pte_t * __bad_pagetable(void);
117
118 #define BAD_PAGETABLE __bad_pagetable()
119 #define BAD_PAGE __bad_page()
120 #define ZERO_PAGE ((unsigned long) empty_zero_page)
121
122
123 #define BITS_PER_PTR (8*sizeof(unsigned long))
124
125
126 #define PTR_MASK (~(sizeof(void*)-1))
127
128
129
130 #define SIZEOF_PTR_LOG2 2
131
132
133 #define PAGE_PTR(address) \
134 ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
135
136
137 #define SET_PAGE_DIR(tsk,pgdir) \
138 do { \
139 (tsk)->tss.cr3 = (unsigned long) (pgdir); \
140 if ((tsk) == current) \
141 __asm__ __volatile__("movl %0,%%cr3": :"a" ((tsk)->tss.cr3)); \
142 } while (0)
143
144 extern inline int pte_none(pte_t pte) { return !pte_val(pte); }
145 extern inline int pte_present(pte_t pte) { return pte_val(pte) & _PAGE_PRESENT; }
146 extern inline int pte_inuse(pte_t *ptep) { return mem_map[MAP_NR(ptep)].reserved || mem_map[MAP_NR(ptep)].count != 1; }
147 extern inline void pte_clear(pte_t *ptep) { pte_val(*ptep) = 0; }
148 extern inline void pte_reuse(pte_t * ptep)
149 {
150 if (!mem_map[MAP_NR(ptep)].reserved)
151 mem_map[MAP_NR(ptep)].count++;
152 }
153
154 extern inline int pmd_none(pmd_t pmd) { return !pmd_val(pmd); }
155 extern inline int pmd_bad(pmd_t pmd) { return (pmd_val(pmd) & ~PAGE_MASK) != _PAGE_TABLE || pmd_val(pmd) > high_memory; }
156 extern inline int pmd_present(pmd_t pmd) { return pmd_val(pmd) & _PAGE_PRESENT; }
157 #ifdef CONFIG_PENTIUM_MM
158 extern inline int pmd_inuse(pmd_t *pmdp) { return (pmd_val(*pmdp) & _PAGE_4M) != 0; }
159 #else
160 extern inline int pmd_inuse(pmd_t *pmdp) { return 0; }
161 #endif
162 extern inline void pmd_clear(pmd_t * pmdp) { pmd_val(*pmdp) = 0; }
163 extern inline void pmd_reuse(pmd_t * pmdp) { }
164
165
166
167
168
169
170 extern inline int pgd_none(pgd_t pgd) { return 0; }
171 extern inline int pgd_bad(pgd_t pgd) { return 0; }
172 extern inline int pgd_present(pgd_t pgd) { return 1; }
173 extern inline int pgd_inuse(pgd_t * pgdp) { return mem_map[MAP_NR(pgdp)].reserved; }
174 extern inline void pgd_clear(pgd_t * pgdp) { }
175
176
177
178
179
180 extern inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
181 extern inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
182 extern inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
183 extern inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
184 extern inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
185 extern inline int pte_cow(pte_t pte) { return pte_val(pte) & _PAGE_COW; }
186
187 extern inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) &= ~_PAGE_RW; return pte; }
188 extern inline pte_t pte_rdprotect(pte_t pte) { pte_val(pte) &= ~_PAGE_USER; return pte; }
189 extern inline pte_t pte_exprotect(pte_t pte) { pte_val(pte) &= ~_PAGE_USER; return pte; }
190 extern inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
191 extern inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
192 extern inline pte_t pte_uncow(pte_t pte) { pte_val(pte) &= ~_PAGE_COW; return pte; }
193 extern inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) |= _PAGE_RW; return pte; }
194 extern inline pte_t pte_mkread(pte_t pte) { pte_val(pte) |= _PAGE_USER; return pte; }
195 extern inline pte_t pte_mkexec(pte_t pte) { pte_val(pte) |= _PAGE_USER; return pte; }
196 extern inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= _PAGE_DIRTY; return pte; }
197 extern inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
198 extern inline pte_t pte_mkcow(pte_t pte) { pte_val(pte) |= _PAGE_COW; return pte; }
199
200
201
202
203
204 extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
205 { pte_t pte; pte_val(pte) = page | pgprot_val(pgprot); return pte; }
206
207 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
208 { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
209
210 extern inline unsigned long pte_page(pte_t pte)
211 { return pte_val(pte) & PAGE_MASK; }
212
213 extern inline unsigned long pmd_page(pmd_t pmd)
214 { return pmd_val(pmd) & PAGE_MASK; }
215
216
217 extern inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address)
218 {
219 return mm->pgd + (address >> PGDIR_SHIFT);
220 }
221
222
223 extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
224 {
225 return (pmd_t *) dir;
226 }
227
228
229 extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
230 {
231 return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
232 }
233
234
235
236
237
238
239 extern inline void pte_free_kernel(pte_t * pte)
240 {
241 mem_map[MAP_NR(pte)].reserved = 0;
242 free_page((unsigned long) pte);
243 }
244
245 extern inline pte_t * pte_alloc_kernel(pmd_t * pmd, unsigned long address)
246 {
247 address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
248 if (pmd_none(*pmd)) {
249 pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
250 if (pmd_none(*pmd)) {
251 if (page) {
252 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
253 mem_map[MAP_NR(page)].reserved = 1;
254 return page + address;
255 }
256 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
257 return NULL;
258 }
259 free_page((unsigned long) page);
260 }
261 if (pmd_bad(*pmd)) {
262 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
263 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
264 return NULL;
265 }
266 return (pte_t *) pmd_page(*pmd) + address;
267 }
268
269
270
271
272
273 extern inline void pmd_free_kernel(pmd_t * pmd)
274 {
275 pmd_val(*pmd) = 0;
276 }
277
278 extern inline pmd_t * pmd_alloc_kernel(pgd_t * pgd, unsigned long address)
279 {
280 return (pmd_t *) pgd;
281 }
282
283 extern inline void pte_free(pte_t * pte)
284 {
285 free_page((unsigned long) pte);
286 }
287
288 extern inline pte_t * pte_alloc(pmd_t * pmd, unsigned long address)
289 {
290 address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
291 if (pmd_none(*pmd)) {
292 pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
293 if (pmd_none(*pmd)) {
294 if (page) {
295 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
296 return page + address;
297 }
298 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
299 return NULL;
300 }
301 free_page((unsigned long) page);
302 }
303 if (pmd_bad(*pmd)) {
304 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
305 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
306 return NULL;
307 }
308 return (pte_t *) pmd_page(*pmd) + address;
309 }
310
311
312
313
314
315 extern inline void pmd_free(pmd_t * pmd)
316 {
317 pmd_val(*pmd) = 0;
318 }
319
320 extern inline pmd_t * pmd_alloc(pgd_t * pgd, unsigned long address)
321 {
322 return (pmd_t *) pgd;
323 }
324
325 extern inline void pgd_free(pgd_t * pgd)
326 {
327 free_page((unsigned long) pgd);
328 }
329
330 extern inline pgd_t * pgd_alloc(void)
331 {
332 return (pgd_t *) get_free_page(GFP_KERNEL);
333 }
334
335 extern pgd_t swapper_pg_dir[1024];
336
337
338
339
340
341 extern inline void update_mmu_cache(struct vm_area_struct * vma,
342 unsigned long address, pte_t pte)
343 {
344 }
345
346 #define SWP_TYPE(entry) (((entry) >> 1) & 0x7f)
347 #define SWP_OFFSET(entry) ((entry) >> 8)
348 #define SWP_ENTRY(type,offset) (((type) << 1) | ((offset) << 8))
349
350 #endif