1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _ASM_NIOS2_PGTABLE_H
16#define _ASM_NIOS2_PGTABLE_H
17
18#include <linux/io.h>
19#include <linux/bug.h>
20#include <asm/page.h>
21#include <asm/cacheflush.h>
22#include <asm/tlbflush.h>
23
24#include <asm/pgtable-bits.h>
25#include <asm-generic/pgtable-nopmd.h>
26
27#define FIRST_USER_ADDRESS 0UL
28
29#define VMALLOC_START CONFIG_NIOS2_KERNEL_MMU_REGION_BASE
30#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1)
31
32struct mm_struct;
33
34
35#define MKP(x, w, r) __pgprot(_PAGE_PRESENT | _PAGE_CACHED | \
36 ((x) ? _PAGE_EXEC : 0) | \
37 ((r) ? _PAGE_READ : 0) | \
38 ((w) ? _PAGE_WRITE : 0))
39
40
41
42
43
44
45#define __P000 MKP(0, 0, 0)
46#define __P001 MKP(0, 0, 1)
47#define __P010 MKP(0, 0, 0)
48#define __P011 MKP(0, 0, 1)
49#define __P100 MKP(1, 0, 0)
50#define __P101 MKP(1, 0, 1)
51#define __P110 MKP(1, 0, 0)
52#define __P111 MKP(1, 0, 1)
53
54
55#define __S000 MKP(0, 0, 0)
56#define __S001 MKP(0, 0, 1)
57#define __S010 MKP(0, 1, 0)
58#define __S011 MKP(0, 1, 1)
59#define __S100 MKP(1, 0, 0)
60#define __S101 MKP(1, 0, 1)
61#define __S110 MKP(1, 1, 0)
62#define __S111 MKP(1, 1, 1)
63
64
65#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \
66 _PAGE_WRITE | _PAGE_EXEC | _PAGE_GLOBAL)
67
68#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \
69 _PAGE_WRITE | _PAGE_ACCESSED)
70
71#define PAGE_COPY MKP(0, 0, 1)
72
73#define PGD_ORDER 0
74#define PTE_ORDER 0
75
76#define PTRS_PER_PGD ((PAGE_SIZE << PGD_ORDER) / sizeof(pgd_t))
77#define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
78
79#define USER_PTRS_PER_PGD \
80 (CONFIG_NIOS2_KERNEL_MMU_REGION_BASE / PGDIR_SIZE)
81
82#define PGDIR_SHIFT 22
83#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
84#define PGDIR_MASK (~(PGDIR_SIZE-1))
85
86
87
88
89
90extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
91#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
92
93extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
94extern pte_t invalid_pte_table[PAGE_SIZE/sizeof(pte_t)];
95
96
97
98
99
100static inline void set_pmd(pmd_t *pmdptr, pmd_t pmdval)
101{
102 *pmdptr = pmdval;
103}
104
105static inline int pte_write(pte_t pte) \
106 { return pte_val(pte) & _PAGE_WRITE; }
107static inline int pte_dirty(pte_t pte) \
108 { return pte_val(pte) & _PAGE_DIRTY; }
109static inline int pte_young(pte_t pte) \
110 { return pte_val(pte) & _PAGE_ACCESSED; }
111
112#define pgprot_noncached pgprot_noncached
113
114static inline pgprot_t pgprot_noncached(pgprot_t _prot)
115{
116 unsigned long prot = pgprot_val(_prot);
117
118 prot &= ~_PAGE_CACHED;
119
120 return __pgprot(prot);
121}
122
123static inline int pte_none(pte_t pte)
124{
125 return !(pte_val(pte) & ~(_PAGE_GLOBAL|0xf));
126}
127
128static inline int pte_present(pte_t pte) \
129 { return pte_val(pte) & _PAGE_PRESENT; }
130
131
132
133
134
135static inline pte_t pte_wrprotect(pte_t pte)
136{
137 pte_val(pte) &= ~_PAGE_WRITE;
138 return pte;
139}
140
141static inline pte_t pte_mkclean(pte_t pte)
142{
143 pte_val(pte) &= ~_PAGE_DIRTY;
144 return pte;
145}
146
147static inline pte_t pte_mkold(pte_t pte)
148{
149 pte_val(pte) &= ~_PAGE_ACCESSED;
150 return pte;
151}
152
153static inline pte_t pte_mkwrite(pte_t pte)
154{
155 pte_val(pte) |= _PAGE_WRITE;
156 return pte;
157}
158
159static inline pte_t pte_mkdirty(pte_t pte)
160{
161 pte_val(pte) |= _PAGE_DIRTY;
162 return pte;
163}
164
165static inline pte_t pte_mkyoung(pte_t pte)
166{
167 pte_val(pte) |= _PAGE_ACCESSED;
168 return pte;
169}
170
171static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
172{
173 const unsigned long mask = _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC;
174
175 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
176 return pte;
177}
178
179static inline int pmd_present(pmd_t pmd)
180{
181 return (pmd_val(pmd) != (unsigned long) invalid_pte_table)
182 && (pmd_val(pmd) != 0UL);
183}
184
185static inline void pmd_clear(pmd_t *pmdp)
186{
187 pmd_val(*pmdp) = (unsigned long) invalid_pte_table;
188}
189
190#define pte_pfn(pte) (pte_val(pte) & 0xfffff)
191#define pfn_pte(pfn, prot) (__pte(pfn | pgprot_val(prot)))
192#define pte_page(pte) (pfn_to_page(pte_pfn(pte)))
193
194
195
196
197static inline void set_pte(pte_t *ptep, pte_t pteval)
198{
199 *ptep = pteval;
200}
201
202static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
203 pte_t *ptep, pte_t pteval)
204{
205 unsigned long paddr = (unsigned long)page_to_virt(pte_page(pteval));
206
207 flush_dcache_range(paddr, paddr + PAGE_SIZE);
208 set_pte(ptep, pteval);
209}
210
211static inline int pmd_none(pmd_t pmd)
212{
213 return (pmd_val(pmd) ==
214 (unsigned long) invalid_pte_table) || (pmd_val(pmd) == 0UL);
215}
216
217#define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
218
219static inline void pte_clear(struct mm_struct *mm,
220 unsigned long addr, pte_t *ptep)
221{
222 pte_t null;
223
224 pte_val(null) = (addr >> PAGE_SHIFT) & 0xf;
225
226 set_pte_at(mm, addr, ptep, null);
227}
228
229
230
231
232
233#define mk_pte(page, prot) (pfn_pte(page_to_pfn(page), prot))
234
235
236
237
238
239#define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
240#define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
241
242static inline unsigned long pmd_page_vaddr(pmd_t pmd)
243{
244 return pmd_val(pmd);
245}
246
247#define pte_ERROR(e) \
248 pr_err("%s:%d: bad pte %08lx.\n", \
249 __FILE__, __LINE__, pte_val(e))
250#define pgd_ERROR(e) \
251 pr_err("%s:%d: bad pgd %08lx.\n", \
252 __FILE__, __LINE__, pgd_val(e))
253
254
255
256
257
258
259
260
261
262
263
264
265#define __swp_type(swp) (((swp).val >> 26) & 0x3)
266#define __swp_offset(swp) ((swp).val & 0xfffff)
267#define __swp_entry(type, off) ((swp_entry_t) { (((type) & 0x3) << 26) \
268 | ((off) & 0xfffff) })
269#define __swp_entry_to_pte(swp) ((pte_t) { (swp).val })
270#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
271
272#define kern_addr_valid(addr) (1)
273
274extern void __init paging_init(void);
275extern void __init mmu_init(void);
276
277extern void update_mmu_cache(struct vm_area_struct *vma,
278 unsigned long address, pte_t *pte);
279
280#endif
281