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