1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef __ASM_OPENRISC_PGTABLE_H
22#define __ASM_OPENRISC_PGTABLE_H
23
24#include <asm-generic/pgtable-nopmd.h>
25
26#ifndef __ASSEMBLY__
27#include <asm/mmu.h>
28#include <asm/fixmap.h>
29
30
31
32
33
34
35
36
37
38
39
40
41
42extern void paging_init(void);
43
44
45
46
47
48#define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
49#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
50
51
52
53
54#define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)
55
56#define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-2))
57#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
58#define PGDIR_MASK (~(PGDIR_SIZE-1))
59
60
61
62
63
64
65
66#define PTRS_PER_PTE (1UL << (PAGE_SHIFT-2))
67
68#define PTRS_PER_PGD (1UL << (32-PGDIR_SHIFT))
69
70
71
72
73
74
75#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91#define VMALLOC_START (PAGE_OFFSET-0x04000000UL)
92#define VMALLOC_END (PAGE_OFFSET)
93#define VMALLOC_VMADDR(x) ((unsigned long)(x))
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120#define _PAGE_CC 0x001
121#define _PAGE_CI 0x002
122#define _PAGE_WBC 0x004
123#define _PAGE_WOM 0x008
124
125#define _PAGE_A 0x010
126#define _PAGE_D 0x020
127#define _PAGE_URE 0x040
128#define _PAGE_UWE 0x080
129
130#define _PAGE_SRE 0x100
131#define _PAGE_SWE 0x200
132#define _PAGE_EXEC 0x400
133#define _PAGE_U_SHARED 0x800
134
135
136
137
138
139
140
141
142#define _PAGE_PRESENT _PAGE_CC
143#define _PAGE_USER _PAGE_URE
144#define _PAGE_WRITE (_PAGE_UWE | _PAGE_SWE)
145#define _PAGE_DIRTY _PAGE_D
146#define _PAGE_ACCESSED _PAGE_A
147#define _PAGE_NO_CACHE _PAGE_CI
148#define _PAGE_SHARED _PAGE_U_SHARED
149#define _PAGE_READ (_PAGE_URE | _PAGE_SRE)
150
151#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
152#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
153#define _PAGE_ALL (_PAGE_PRESENT | _PAGE_ACCESSED)
154#define _KERNPG_TABLE \
155 (_PAGE_BASE | _PAGE_SRE | _PAGE_SWE | _PAGE_ACCESSED | _PAGE_DIRTY)
156
157#define PAGE_NONE __pgprot(_PAGE_ALL)
158#define PAGE_READONLY __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE)
159#define PAGE_READONLY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC)
160#define PAGE_SHARED \
161 __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE \
162 | _PAGE_SHARED)
163#define PAGE_SHARED_X \
164 __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE \
165 | _PAGE_SHARED | _PAGE_EXEC)
166#define PAGE_COPY __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE)
167#define PAGE_COPY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC)
168
169#define PAGE_KERNEL \
170 __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE \
171 | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC)
172#define PAGE_KERNEL_RO \
173 __pgprot(_PAGE_ALL | _PAGE_SRE \
174 | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC)
175#define PAGE_KERNEL_NOCACHE \
176 __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE \
177 | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC | _PAGE_CI)
178
179#define __P000 PAGE_NONE
180#define __P001 PAGE_READONLY_X
181#define __P010 PAGE_COPY
182#define __P011 PAGE_COPY_X
183#define __P100 PAGE_READONLY
184#define __P101 PAGE_READONLY_X
185#define __P110 PAGE_COPY
186#define __P111 PAGE_COPY_X
187
188#define __S000 PAGE_NONE
189#define __S001 PAGE_READONLY_X
190#define __S010 PAGE_SHARED
191#define __S011 PAGE_SHARED_X
192#define __S100 PAGE_READONLY
193#define __S101 PAGE_READONLY_X
194#define __S110 PAGE_SHARED
195#define __S111 PAGE_SHARED_X
196
197
198extern unsigned long empty_zero_page[2048];
199#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
200
201
202#define BITS_PER_PTR (8*sizeof(unsigned long))
203
204
205#define PTR_MASK (~(sizeof(void *)-1))
206
207
208
209#define SIZEOF_PTR_LOG2 2
210
211
212#define PAGE_PTR(address) \
213((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
214
215
216#define SET_PAGE_DIR(tsk, pgdir)
217
218#define pte_none(x) (!pte_val(x))
219#define pte_present(x) (pte_val(x) & _PAGE_PRESENT)
220#define pte_clear(mm, addr, xp) do { pte_val(*(xp)) = 0; } while (0)
221
222#define pmd_none(x) (!pmd_val(x))
223#define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK)) != _KERNPG_TABLE)
224#define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
225#define pmd_clear(xp) do { pmd_val(*(xp)) = 0; } while (0)
226
227
228
229
230
231
232static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; }
233static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
234static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; }
235static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
236static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
237
238static inline pte_t pte_wrprotect(pte_t pte)
239{
240 pte_val(pte) &= ~(_PAGE_WRITE);
241 return pte;
242}
243
244static inline pte_t pte_rdprotect(pte_t pte)
245{
246 pte_val(pte) &= ~(_PAGE_READ);
247 return pte;
248}
249
250static inline pte_t pte_exprotect(pte_t pte)
251{
252 pte_val(pte) &= ~(_PAGE_EXEC);
253 return pte;
254}
255
256static inline pte_t pte_mkclean(pte_t pte)
257{
258 pte_val(pte) &= ~(_PAGE_DIRTY);
259 return pte;
260}
261
262static inline pte_t pte_mkold(pte_t pte)
263{
264 pte_val(pte) &= ~(_PAGE_ACCESSED);
265 return pte;
266}
267
268static inline pte_t pte_mkwrite(pte_t pte)
269{
270 pte_val(pte) |= _PAGE_WRITE;
271 return pte;
272}
273
274static inline pte_t pte_mkread(pte_t pte)
275{
276 pte_val(pte) |= _PAGE_READ;
277 return pte;
278}
279
280static inline pte_t pte_mkexec(pte_t pte)
281{
282 pte_val(pte) |= _PAGE_EXEC;
283 return pte;
284}
285
286static inline pte_t pte_mkdirty(pte_t pte)
287{
288 pte_val(pte) |= _PAGE_DIRTY;
289 return pte;
290}
291
292static inline pte_t pte_mkyoung(pte_t pte)
293{
294 pte_val(pte) |= _PAGE_ACCESSED;
295 return pte;
296}
297
298
299
300
301
302
303
304
305
306
307
308
309static inline pte_t __mk_pte(void *page, pgprot_t pgprot)
310{
311 pte_t pte;
312
313 pte_val(pte) = __pa(page) | pgprot_val(pgprot);
314 return pte;
315}
316
317#define mk_pte(page, pgprot) __mk_pte(page_address(page), (pgprot))
318
319#define mk_pte_phys(physpage, pgprot) \
320({ \
321 pte_t __pte; \
322 \
323 pte_val(__pte) = (physpage) + pgprot_val(pgprot); \
324 __pte; \
325})
326
327static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
328{
329 pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
330 return pte;
331}
332
333
334
335
336
337
338
339
340
341static inline unsigned long __pte_page(pte_t pte)
342{
343
344 return (unsigned long)__va(pte_val(pte) & PAGE_MASK);
345}
346
347#define pte_pagenr(pte) ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
348
349
350
351#define __page_address(page) (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))
352#define pte_page(pte) (mem_map+pte_pagenr(pte))
353
354
355
356
357
358
359static inline void pmd_set(pmd_t *pmdp, pte_t *ptep)
360{
361 pmd_val(*pmdp) = _KERNPG_TABLE | (unsigned long) ptep;
362}
363
364#define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
365
366static inline unsigned long pmd_page_vaddr(pmd_t pmd)
367{
368 return ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK));
369}
370
371#define __pmd_offset(address) \
372 (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
373
374#define pte_pfn(x) ((unsigned long)(((x).pte)) >> PAGE_SHIFT)
375#define pfn_pte(pfn, prot) __pte((((pfn) << PAGE_SHIFT)) | pgprot_val(prot))
376
377#define pte_ERROR(e) \
378 printk(KERN_ERR "%s:%d: bad pte %p(%08lx).\n", \
379 __FILE__, __LINE__, &(e), pte_val(e))
380#define pgd_ERROR(e) \
381 printk(KERN_ERR "%s:%d: bad pgd %p(%08lx).\n", \
382 __FILE__, __LINE__, &(e), pgd_val(e))
383
384extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
385
386struct vm_area_struct;
387
388static inline void update_tlb(struct vm_area_struct *vma,
389 unsigned long address, pte_t *pte)
390{
391}
392
393extern void update_cache(struct vm_area_struct *vma,
394 unsigned long address, pte_t *pte);
395
396static inline void update_mmu_cache(struct vm_area_struct *vma,
397 unsigned long address, pte_t *pte)
398{
399 update_tlb(vma, address, pte);
400 update_cache(vma, address, pte);
401}
402
403
404
405
406
407
408#define __swp_type(x) (((x).val >> 5) & 0x7f)
409#define __swp_offset(x) ((x).val >> 12)
410#define __swp_entry(type, offset) \
411 ((swp_entry_t) { ((type) << 5) | ((offset) << 12) })
412#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
413#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
414
415#define kern_addr_valid(addr) (1)
416
417typedef pte_t *pte_addr_t;
418
419#endif
420#endif
421