rtl8366_smi: implement a function for detecting whether the attached switch is RTL836...
[openwrt.git] / target / linux / coldfire / files-2.6.31 / arch / m68k / include / asm / cf_pgtable.h
1 /*
2 * Copyright 2007-2009 Freescale Semiconductor, Inc. All Rights Reserved.
3 */
4
5 #ifndef _CF_PGTABLE_H
6 #define _CF_PGTABLE_H
7
8 #include <asm/cfmmu.h>
9 #include <asm/page.h>
10
11 #ifndef __ASSEMBLY__
12 #include <asm/virtconvert.h>
13 #include <linux/linkage.h>
14
15 /* For virtual address to physical address conversion */
16 #define VTOP(addr) __pa(addr)
17 #define PTOV(addr) __va(addr)
18
19
20 #endif /* !__ASSEMBLY__ */
21
22 /* Page protection values within PTE. */
23
24 /* MMUDR bits, in proper place. */
25 #define CF_PAGE_LOCKED (0x00000002)
26 #define CF_PAGE_EXEC (0x00000004)
27 #define CF_PAGE_WRITABLE (0x00000008)
28 #define CF_PAGE_READABLE (0x00000010)
29 #define CF_PAGE_SYSTEM (0x00000020)
30 #define CF_PAGE_COPYBACK (0x00000040)
31 #define CF_PAGE_NOCACHE (0x00000080)
32
33 #define CF_CACHEMASK (~0x00000040)
34 #define CF_PAGE_MMUDR_MASK (0x000000fe)
35
36 #define _PAGE_NOCACHE030 (CF_PAGE_NOCACHE)
37
38 /* MMUTR bits, need shifting down. */
39 #define CF_PAGE_VALID (0x00000400)
40 #define CF_PAGE_SHARED (0x00000800)
41
42 #define CF_PAGE_MMUTR_MASK (0x00000c00)
43 #define CF_PAGE_MMUTR_SHIFT (10)
44 #define CF_ASID_MMU_SHIFT (2)
45
46 /* Fake bits, not implemented in CF, will get masked out before
47 hitting hardware, and might go away altogether once this port is
48 complete. */
49 #if PAGE_SHIFT < 13
50 #error COLDFIRE Error: Pages must be at least 8k in size
51 #endif
52 #define CF_PAGE_ACCESSED (0x00001000)
53 #define CF_PAGE_FILE (0x00000200)
54 #define CF_PAGE_DIRTY (0x00000001)
55
56 #define _PAGE_CACHE040 0x020 /* 68040 cache mode, cachable, copyback */
57 #define _PAGE_NOCACHE_S 0x040 /* 68040 no-cache mode, serialized */
58 #define _PAGE_NOCACHE 0x060 /* 68040 cache mode, non-serialized */
59 #define _PAGE_CACHE040W 0x000 /* 68040 cache mode, cachable, write-through */
60 #define _DESCTYPE_MASK 0x003
61 #define _CACHEMASK040 (~0x060)
62 #define _PAGE_GLOBAL040 0x400 /* 68040 global bit, used for kva descs */
63
64
65 /* Externally used page protection values. */
66 #define _PAGE_PRESENT (CF_PAGE_VALID)
67 #define _PAGE_ACCESSED (CF_PAGE_ACCESSED)
68 #define _PAGE_DIRTY (CF_PAGE_DIRTY)
69 #define _PAGE_READWRITE (CF_PAGE_WRITABLE \
70 | CF_PAGE_READABLE \
71 | CF_PAGE_SHARED \
72 | CF_PAGE_SYSTEM)
73
74 /* Compound page protection values. */
75 #define PAGE_NONE __pgprot(CF_PAGE_VALID \
76 | CF_PAGE_ACCESSED)
77
78 #define PAGE_SHARED __pgprot(CF_PAGE_VALID \
79 | CF_PAGE_READABLE \
80 | CF_PAGE_WRITABLE \
81 | CF_PAGE_ACCESSED)
82
83 #define PAGE_INIT __pgprot(CF_PAGE_VALID \
84 | CF_PAGE_WRITABLE \
85 | CF_PAGE_READABLE \
86 | CF_PAGE_EXEC \
87 | CF_PAGE_SYSTEM \
88 | CF_PAGE_SHARED)
89
90 #define PAGE_KERNEL __pgprot(CF_PAGE_VALID \
91 | CF_PAGE_WRITABLE \
92 | CF_PAGE_READABLE \
93 | CF_PAGE_EXEC \
94 | CF_PAGE_SYSTEM \
95 | CF_PAGE_SHARED \
96 | CF_PAGE_ACCESSED)
97
98 #define PAGE_COPY __pgprot(CF_PAGE_VALID \
99 | CF_PAGE_ACCESSED \
100 | CF_PAGE_READABLE)
101
102 /*
103 * Page protections for initialising protection_map. See mm/mmap.c
104 * for use. In general, the bit positions are xwr, and P-items are
105 * private, the S-items are shared.
106 */
107
108 #define __P000 PAGE_NONE
109 #define __P100 __pgprot(CF_PAGE_VALID \
110 | CF_PAGE_ACCESSED \
111 | CF_PAGE_EXEC)
112 #define __P010 __pgprot(CF_PAGE_VALID \
113 | CF_PAGE_WRITABLE \
114 | CF_PAGE_ACCESSED)
115 #define __P110 __pgprot(CF_PAGE_VALID \
116 | CF_PAGE_ACCESSED \
117 | CF_PAGE_WRITABLE \
118 | CF_PAGE_EXEC)
119 #define __P001 __pgprot(CF_PAGE_VALID \
120 | CF_PAGE_ACCESSED \
121 | CF_PAGE_READABLE)
122 #define __P101 __pgprot(CF_PAGE_VALID \
123 | CF_PAGE_ACCESSED \
124 | CF_PAGE_READABLE \
125 | CF_PAGE_EXEC)
126 #define __P011 __pgprot(CF_PAGE_VALID \
127 | CF_PAGE_READABLE \
128 | CF_PAGE_WRITABLE \
129 | CF_PAGE_ACCESSED)
130 #define __P111 __pgprot(CF_PAGE_VALID \
131 | CF_PAGE_ACCESSED \
132 | CF_PAGE_WRITABLE \
133 | CF_PAGE_READABLE \
134 | CF_PAGE_EXEC)
135
136 #define __S000 PAGE_NONE
137 #define __S100 __pgprot(CF_PAGE_VALID \
138 | CF_PAGE_ACCESSED \
139 | CF_PAGE_EXEC)
140 #define __S010 PAGE_SHARED
141 #define __S110 __pgprot(CF_PAGE_VALID \
142 | CF_PAGE_ACCESSED \
143 | CF_PAGE_WRITABLE \
144 | CF_PAGE_EXEC)
145 #define __S001 __pgprot(CF_PAGE_VALID \
146 | CF_PAGE_ACCESSED \
147 | CF_PAGE_READABLE)
148 #define __S101 __pgprot(CF_PAGE_VALID \
149 | CF_PAGE_ACCESSED \
150 | CF_PAGE_READABLE \
151 | CF_PAGE_EXEC)
152 #define __S011 PAGE_SHARED
153 #define __S111 __pgprot(CF_PAGE_VALID \
154 | CF_PAGE_ACCESSED \
155 | CF_PAGE_READABLE \
156 | CF_PAGE_WRITABLE \
157 | CF_PAGE_EXEC)
158
159 #define PTE_MASK PAGE_MASK
160 #define CF_PAGE_CHG_MASK (PTE_MASK | CF_PAGE_ACCESSED | CF_PAGE_DIRTY)
161
162 #ifndef __ASSEMBLY__
163
164 /*
165 * Conversion functions: convert a page and protection to a page entry,
166 * and a page entry and page directory to the page they refer to.
167 */
168 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
169
170 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
171 {
172 pte_val(pte) = (pte_val(pte) & CF_PAGE_CHG_MASK) | pgprot_val(newprot);
173 return pte;
174 }
175
176 #define pmd_set(pmdp, ptep) do {} while (0)
177
178 static inline void pgd_set(pgd_t *pgdp, pmd_t *pmdp)
179 {
180 pgd_val(*pgdp) = virt_to_phys(pmdp);
181 }
182
183 #define __pte_page(pte) \
184 ((unsigned long) ((pte_val(pte) & CF_PAGE_PGNUM_MASK) + PAGE_OFFSET))
185 #define __pmd_page(pmd) ((unsigned long) (pmd_val(pmd)))
186
187 extern inline int pte_none(pte_t pte)
188 {
189 return !pte_val(pte);
190 }
191 extern inline int pte_present(pte_t pte)
192 {
193 return pte_val(pte) & CF_PAGE_VALID;
194 }
195 extern inline void pte_clear(struct mm_struct *mm, unsigned long addr,
196 pte_t *ptep)
197 {
198 pte_val(*ptep) = 0;
199 }
200
201 #define pte_pagenr(pte) ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
202 #define pte_page(pte) virt_to_page(__pte_page(pte))
203
204 extern inline int pmd_none2(pmd_t *pmd) { return !pmd_val(*pmd); }
205 #define pmd_none(pmd) pmd_none2(&(pmd))
206 extern inline int pmd_bad2(pmd_t *pmd) { return 0; }
207 #define pmd_bad(pmd) pmd_bad2(&(pmd))
208 #define pmd_present(pmd) (!pmd_none2(&(pmd)))
209 extern inline void pmd_clear(pmd_t *pmdp) { pmd_val(*pmdp) = 0; }
210
211 extern inline int pgd_none(pgd_t pgd) { return 0; }
212 extern inline int pgd_bad(pgd_t pgd) { return 0; }
213 extern inline int pgd_present(pgd_t pgd) { return 1; }
214 extern inline void pgd_clear(pgd_t *pgdp) {}
215
216
217 #define pte_ERROR(e) \
218 printk(KERN_ERR "%s:%d: bad pte %08lx.\n", \
219 __FILE__, __LINE__, pte_val(e))
220 #define pmd_ERROR(e) \
221 printk(KERN_ERR "%s:%d: bad pmd %08lx.\n", \
222 __FILE__, __LINE__, pmd_val(e))
223 #define pgd_ERROR(e) \
224 printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \
225 __FILE__, __LINE__, pgd_val(e))
226
227
228 /*
229 * The following only work if pte_present() is true.
230 * Undefined behaviour if not...
231 * [we have the full set here even if they don't change from m68k]
232 */
233 extern inline int pte_read(pte_t pte) \
234 { return pte_val(pte) & CF_PAGE_READABLE; }
235 extern inline int pte_write(pte_t pte) \
236 { return pte_val(pte) & CF_PAGE_WRITABLE; }
237 extern inline int pte_exec(pte_t pte) \
238 { return pte_val(pte) & CF_PAGE_EXEC; }
239 extern inline int pte_dirty(pte_t pte) \
240 { return pte_val(pte) & CF_PAGE_DIRTY; }
241 extern inline int pte_young(pte_t pte) \
242 { return pte_val(pte) & CF_PAGE_ACCESSED; }
243 extern inline int pte_file(pte_t pte) \
244 { return pte_val(pte) & CF_PAGE_FILE; }
245 static inline int pte_special(pte_t pte) { return 0; }
246
247
248 extern inline pte_t pte_wrprotect(pte_t pte) \
249 { pte_val(pte) &= ~CF_PAGE_WRITABLE; return pte; }
250 extern inline pte_t pte_rdprotect(pte_t pte) \
251 { pte_val(pte) &= ~CF_PAGE_READABLE; return pte; }
252 extern inline pte_t pte_exprotect(pte_t pte) \
253 { pte_val(pte) &= ~CF_PAGE_EXEC; return pte; }
254 extern inline pte_t pte_mkclean(pte_t pte) \
255 { pte_val(pte) &= ~CF_PAGE_DIRTY; return pte; }
256 extern inline pte_t pte_mkold(pte_t pte) \
257 { pte_val(pte) &= ~CF_PAGE_ACCESSED; return pte; }
258 extern inline pte_t pte_mkwrite(pte_t pte) \
259 { pte_val(pte) |= CF_PAGE_WRITABLE; return pte; }
260 extern inline pte_t pte_mkread(pte_t pte) \
261 { pte_val(pte) |= CF_PAGE_READABLE; return pte; }
262 extern inline pte_t pte_mkexec(pte_t pte) \
263 { pte_val(pte) |= CF_PAGE_EXEC; return pte; }
264 extern inline pte_t pte_mkdirty(pte_t pte) \
265 { pte_val(pte) |= CF_PAGE_DIRTY; return pte; }
266 extern inline pte_t pte_mkyoung(pte_t pte) \
267 { pte_val(pte) |= CF_PAGE_ACCESSED; return pte; }
268 extern inline pte_t pte_mknocache(pte_t pte) \
269 { pte_val(pte) |= 0x80 | (pte_val(pte) & ~0x40); return pte; }
270 extern inline pte_t pte_mkcache(pte_t pte) \
271 { pte_val(pte) &= ~CF_PAGE_NOCACHE; return pte; }
272 static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
273
274
275 #define swapper_pg_dir kernel_pg_dir
276 extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
277
278 /* Find an entry in a pagetable directory. */
279 #define pgd_index(address) ((address) >> PGDIR_SHIFT)
280
281 #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
282
283 /* Find an entry in a kernel pagetable directory. */
284 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
285
286 /* Find an entry in the second-level pagetable. */
287 extern inline pmd_t *pmd_offset(pgd_t *pgd, unsigned long address)
288 {
289 return (pmd_t *) pgd;
290 }
291
292 /* Find an entry in the third-level pagetable. */
293 #define __pte_offset(address) ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
294 #define pte_offset_kernel(dir, address) ((pte_t *) __pmd_page(*(dir)) + \
295 __pte_offset(address))
296
297 /* Disable caching for page at given kernel virtual address. */
298 static inline void nocache_page(void *vaddr)
299 {
300 pgd_t *dir;
301 pmd_t *pmdp;
302 pte_t *ptep;
303 unsigned long addr = (unsigned long)vaddr;
304
305 dir = pgd_offset_k(addr);
306 pmdp = pmd_offset(dir, addr);
307 ptep = pte_offset_kernel(pmdp, addr);
308 *ptep = pte_mknocache(*ptep);
309 }
310
311 /* Enable caching for page at given kernel virtual address. */
312 static inline void cache_page(void *vaddr)
313 {
314 pgd_t *dir;
315 pmd_t *pmdp;
316 pte_t *ptep;
317 unsigned long addr = (unsigned long)vaddr;
318
319 dir = pgd_offset_k(addr);
320 pmdp = pmd_offset(dir, addr);
321 ptep = pte_offset_kernel(pmdp, addr);
322 *ptep = pte_mkcache(*ptep);
323 }
324
325 #define PTE_FILE_MAX_BITS 21
326 #define PTE_FILE_SHIFT 11
327
328 static inline unsigned long pte_to_pgoff(pte_t pte)
329 {
330 return pte_val(pte) >> PTE_FILE_SHIFT;
331 }
332
333 static inline pte_t pgoff_to_pte(unsigned pgoff)
334 {
335 pte_t pte = __pte((pgoff << PTE_FILE_SHIFT) + CF_PAGE_FILE);
336 return pte;
337 }
338
339 /* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */
340 #define __swp_entry(type, offset) ((swp_entry_t) { (type) | \
341 (offset << PTE_FILE_SHIFT) })
342 #define __swp_type(x) ((x).val & 0xFF)
343 #define __swp_offset(x) ((x).val >> PTE_FILE_SHIFT)
344 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
345 #define __swp_entry_to_pte(x) (__pte((x).val))
346
347 #define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
348
349 #define pte_offset_map(pmdp, address) ((pte_t *)__pmd_page(*pmdp) + \
350 __pte_offset(address))
351 #define pte_offset_map_nested(pmdp, address) pte_offset_map(pmdp, address)
352 #define pte_unmap(pte) kunmap(pte)
353 #define pte_unmap_nested(pte) kunmap(pte)
354
355 #define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
356 #define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
357
358
359 #endif /* !__ASSEMBLY__ */
360 #endif /* !_CF_PGTABLE_H */
This page took 0.09483 seconds and 5 git commands to generate.