1
2
3
4
5
6
7
8#ifndef __ASM_AVR32_PGTABLE_H
9#define __ASM_AVR32_PGTABLE_H
10
11#include <asm/addrspace.h>
12
13#ifndef __ASSEMBLY__
14#include <linux/sched.h>
15
16#endif
17
18
19
20
21#include <asm/pgtable-2level.h>
22
23
24
25
26
27#define PMD_SIZE (1UL << PMD_SHIFT)
28#define PMD_MASK (~(PMD_SIZE-1))
29#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
30#define PGDIR_MASK (~(PGDIR_SIZE-1))
31
32#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
33#define FIRST_USER_ADDRESS 0
34
35#ifndef __ASSEMBLY__
36extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
37extern void paging_init(void);
38
39
40
41
42
43extern struct page *empty_zero_page;
44#define ZERO_PAGE(vaddr) (empty_zero_page)
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62#define VMALLOC_OFFSET (8 * 1024 * 1024)
63#define VMALLOC_START (P3SEG + VMALLOC_OFFSET)
64#define VMALLOC_END (P4SEG - VMALLOC_OFFSET)
65#endif
66
67
68
69
70
71#define _TLBEHI_BIT_VALID 9
72#define _TLBEHI_VALID (1 << _TLBEHI_BIT_VALID)
73
74#define _PAGE_BIT_WT 0
75#define _PAGE_BIT_DIRTY 1
76#define _PAGE_BIT_SZ0 2
77#define _PAGE_BIT_SZ1 3
78#define _PAGE_BIT_EXECUTE 4
79#define _PAGE_BIT_RW 5
80#define _PAGE_BIT_USER 6
81#define _PAGE_BIT_BUFFER 7
82#define _PAGE_BIT_GLOBAL 8
83#define _PAGE_BIT_CACHABLE 9
84
85
86#define _PAGE_BIT_PRESENT 10
87#define _PAGE_BIT_ACCESSED 11
88
89
90#define _PAGE_BIT_FILE 0
91
92#define _PAGE_WT (1 << _PAGE_BIT_WT)
93#define _PAGE_DIRTY (1 << _PAGE_BIT_DIRTY)
94#define _PAGE_EXECUTE (1 << _PAGE_BIT_EXECUTE)
95#define _PAGE_RW (1 << _PAGE_BIT_RW)
96#define _PAGE_USER (1 << _PAGE_BIT_USER)
97#define _PAGE_BUFFER (1 << _PAGE_BIT_BUFFER)
98#define _PAGE_GLOBAL (1 << _PAGE_BIT_GLOBAL)
99#define _PAGE_CACHABLE (1 << _PAGE_BIT_CACHABLE)
100
101
102#define _PAGE_ACCESSED (1 << _PAGE_BIT_ACCESSED)
103#define _PAGE_PRESENT (1 << _PAGE_BIT_PRESENT)
104#define _PAGE_FILE (1 << _PAGE_BIT_FILE)
105
106
107
108
109
110
111
112
113
114
115
116#define _PAGE_TYPE_MASK ((1 << _PAGE_BIT_SZ0) | (1 << _PAGE_BIT_SZ1))
117#define _PAGE_TYPE_NONE (0 << _PAGE_BIT_SZ0)
118#define _PAGE_TYPE_SMALL (1 << _PAGE_BIT_SZ0)
119#define _PAGE_TYPE_MEDIUM (2 << _PAGE_BIT_SZ0)
120#define _PAGE_TYPE_LARGE (3 << _PAGE_BIT_SZ0)
121
122
123
124
125
126
127
128#define _PAGE_FLAGS_HARDWARE_MASK 0xfffff3ff
129
130#define _PAGE_FLAGS_CACHE_MASK (_PAGE_CACHABLE | _PAGE_BUFFER | _PAGE_WT)
131
132
133
134#define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_TYPE_SMALL | _PAGE_RW \
135 | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
136
137#define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_TYPE_SMALL | _PAGE_RW \
138 | _PAGE_ACCESSED | _PAGE_DIRTY)
139
140#define _PAGE_CHG_MASK (PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY \
141 | _PAGE_FLAGS_CACHE_MASK)
142
143#define _PAGE_FLAGS_READ (_PAGE_CACHABLE | _PAGE_BUFFER)
144#define _PAGE_FLAGS_WRITE (_PAGE_FLAGS_READ | _PAGE_RW | _PAGE_DIRTY)
145
146#define _PAGE_NORMAL(x) __pgprot((x) | _PAGE_PRESENT | _PAGE_TYPE_SMALL \
147 | _PAGE_ACCESSED)
148
149#define PAGE_NONE (_PAGE_ACCESSED | _PAGE_TYPE_NONE)
150#define PAGE_READ (_PAGE_FLAGS_READ | _PAGE_USER)
151#define PAGE_EXEC (_PAGE_FLAGS_READ | _PAGE_EXECUTE | _PAGE_USER)
152#define PAGE_WRITE (_PAGE_FLAGS_WRITE | _PAGE_USER)
153#define PAGE_KERNEL _PAGE_NORMAL(_PAGE_FLAGS_WRITE | _PAGE_EXECUTE | _PAGE_GLOBAL)
154#define PAGE_KERNEL_RO _PAGE_NORMAL(_PAGE_FLAGS_READ | _PAGE_EXECUTE | _PAGE_GLOBAL)
155
156#define _PAGE_P(x) _PAGE_NORMAL((x) & ~(_PAGE_RW | _PAGE_DIRTY))
157#define _PAGE_S(x) _PAGE_NORMAL(x)
158
159#define PAGE_COPY _PAGE_P(PAGE_WRITE | PAGE_READ)
160#define PAGE_SHARED _PAGE_S(PAGE_WRITE | PAGE_READ)
161
162#ifndef __ASSEMBLY__
163
164
165
166
167
168
169
170
171
172
173#define __P000 __pgprot(PAGE_NONE)
174#define __P001 _PAGE_P(PAGE_READ)
175#define __P010 _PAGE_P(PAGE_WRITE)
176#define __P011 _PAGE_P(PAGE_WRITE | PAGE_READ)
177#define __P100 _PAGE_P(PAGE_EXEC)
178#define __P101 _PAGE_P(PAGE_EXEC | PAGE_READ)
179#define __P110 _PAGE_P(PAGE_EXEC | PAGE_WRITE)
180#define __P111 _PAGE_P(PAGE_EXEC | PAGE_WRITE | PAGE_READ)
181
182#define __S000 __pgprot(PAGE_NONE)
183#define __S001 _PAGE_S(PAGE_READ)
184#define __S010 _PAGE_S(PAGE_WRITE)
185#define __S011 _PAGE_S(PAGE_WRITE | PAGE_READ)
186#define __S100 _PAGE_S(PAGE_EXEC)
187#define __S101 _PAGE_S(PAGE_EXEC | PAGE_READ)
188#define __S110 _PAGE_S(PAGE_EXEC | PAGE_WRITE)
189#define __S111 _PAGE_S(PAGE_EXEC | PAGE_WRITE | PAGE_READ)
190
191#define pte_none(x) (!pte_val(x))
192#define pte_present(x) (pte_val(x) & _PAGE_PRESENT)
193
194#define pte_clear(mm,addr,xp) \
195 do { \
196 set_pte_at(mm, addr, xp, __pte(0)); \
197 } while (0)
198
199
200
201
202
203static inline int pte_write(pte_t pte)
204{
205 return pte_val(pte) & _PAGE_RW;
206}
207static inline int pte_dirty(pte_t pte)
208{
209 return pte_val(pte) & _PAGE_DIRTY;
210}
211static inline int pte_young(pte_t pte)
212{
213 return pte_val(pte) & _PAGE_ACCESSED;
214}
215
216
217
218
219static inline int pte_file(pte_t pte)
220{
221 return pte_val(pte) & _PAGE_FILE;
222}
223
224
225static inline pte_t pte_wrprotect(pte_t pte)
226{
227 set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW));
228 return pte;
229}
230static inline pte_t pte_mkclean(pte_t pte)
231{
232 set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY));
233 return pte;
234}
235static inline pte_t pte_mkold(pte_t pte)
236{
237 set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED));
238 return pte;
239}
240static inline pte_t pte_mkwrite(pte_t pte)
241{
242 set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW));
243 return pte;
244}
245static inline pte_t pte_mkdirty(pte_t pte)
246{
247 set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY));
248 return pte;
249}
250static inline pte_t pte_mkyoung(pte_t pte)
251{
252 set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED));
253 return pte;
254}
255
256#define pmd_none(x) (!pmd_val(x))
257#define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
258#define pmd_clear(xp) do { set_pmd(xp, __pmd(0)); } while (0)
259#define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) \
260 != _KERNPG_TABLE)
261
262
263
264
265
266#define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
267#define pte_page(x) (pfn_to_page(pte_pfn(x)))
268
269
270
271
272#define pgprot_noncached(prot) \
273 __pgprot(pgprot_val(prot) & ~(_PAGE_BUFFER | _PAGE_CACHABLE))
274
275
276
277
278#define pgprot_writecombine(prot) \
279 __pgprot((pgprot_val(prot) & ~_PAGE_CACHABLE) | _PAGE_BUFFER)
280
281
282
283
284
285
286
287#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
288
289static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
290{
291 set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK)
292 | pgprot_val(newprot)));
293 return pte;
294}
295
296#define page_pte(page) page_pte_prot(page, __pgprot(0))
297
298#define pmd_page_vaddr(pmd) \
299 ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
300
301#define pmd_page(pmd) (phys_to_page(pmd_val(pmd)))
302
303
304#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
305#define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
306#define pgd_offset_current(address) \
307 ((pgd_t *)__mfsr(SYSREG_PTBR) + pgd_index(address))
308
309
310#define pgd_offset_k(address) pgd_offset(&init_mm, address)
311
312
313#define pte_index(address) \
314 ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
315#define pte_offset(dir, address) \
316 ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(address))
317#define pte_offset_kernel(dir, address) \
318 ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(address))
319#define pte_offset_map(dir, address) pte_offset_kernel(dir, address)
320#define pte_offset_map_nested(dir, address) pte_offset_kernel(dir, address)
321#define pte_unmap(pte) do { } while (0)
322#define pte_unmap_nested(pte) do { } while (0)
323
324struct vm_area_struct;
325extern void update_mmu_cache(struct vm_area_struct * vma,
326 unsigned long address, pte_t pte);
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343#define __swp_type(x) (((x).val >> 4) & 0x3f)
344#define __swp_offset(x) ((x).val >> 11)
345#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 4) | ((offset) << 11) })
346#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
347#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
348
349
350
351
352
353
354#define PTE_FILE_MAX_BITS 30
355#define pte_to_pgoff(pte) (((pte_val(pte) >> 1) & 0x1ff) \
356 | ((pte_val(pte) >> 11) << 9))
357#define pgoff_to_pte(off) ((pte_t) { ((((off) & 0x1ff) << 1) \
358 | (((off) >> 9) << 11) \
359 | _PAGE_FILE) })
360
361typedef pte_t *pte_addr_t;
362
363#define kern_addr_valid(addr) (1)
364
365#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
366 remap_pfn_range(vma, vaddr, pfn, size, prot)
367
368
369#define pgtable_cache_init() do { } while(0)
370
371#include <asm-generic/pgtable.h>
372
373#endif
374
375#endif
376