]> err.no Git - linux-2.6/blob - include/asm-sh/pgtable.h
sh: page table alloc cleanups and page fault optimizations.
[linux-2.6] / include / asm-sh / pgtable.h
1 /*
2  * This file contains the functions and defines necessary to modify and
3  * use the SuperH page table tree.
4  *
5  * Copyright (C) 1999 Niibe Yutaka
6  * Copyright (C) 2002 - 2005 Paul Mundt
7  *
8  * This file is subject to the terms and conditions of the GNU General
9  * Public License.  See the file "COPYING" in the main directory of this
10  * archive for more details.
11  */
12 #ifndef __ASM_SH_PGTABLE_H
13 #define __ASM_SH_PGTABLE_H
14
15 #include <asm-generic/pgtable-nopmd.h>
16 #include <asm/page.h>
17
18 #define PTRS_PER_PGD            1024
19
20 #ifndef __ASSEMBLY__
21 #include <asm/addrspace.h>
22 #include <asm/fixmap.h>
23
24 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
25 extern void paging_init(void);
26
27 /*
28  * ZERO_PAGE is a global shared page that is always zero: used
29  * for zero-mapped memory areas etc..
30  */
31 extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
32 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
33
34 #endif /* !__ASSEMBLY__ */
35
36 /* traditional two-level paging structure */
37 #define PGDIR_SHIFT     22
38 #define PTRS_PER_PMD    1
39 #define PTRS_PER_PTE    1024
40 #define PMD_SIZE        (1UL << PMD_SHIFT)
41 #define PMD_MASK        (~(PMD_SIZE-1))
42 #define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
43 #define PGDIR_MASK      (~(PGDIR_SIZE-1))
44
45 #define USER_PTRS_PER_PGD       (TASK_SIZE/PGDIR_SIZE)
46 #define FIRST_USER_ADDRESS      0
47
48 #define PTE_PHYS_MASK   0x1ffff000
49
50 /*
51  * First 1MB map is used by fixed purpose.
52  * Currently only 4-enty (16kB) is used (see arch/sh/mm/cache.c)
53  */
54 #define VMALLOC_START   (P3SEG+0x00100000)
55 #define VMALLOC_END     (FIXADDR_START-2*PAGE_SIZE)
56
57 #define _PAGE_WT        0x001  /* WT-bit on SH-4, 0 on SH-3 */
58 #define _PAGE_HW_SHARED 0x002  /* SH-bit  : page is shared among processes */
59 #define _PAGE_DIRTY     0x004  /* D-bit   : page changed */
60 #define _PAGE_CACHABLE  0x008  /* C-bit   : cachable */
61 #define _PAGE_SZ0       0x010  /* SZ0-bit : Size of page */
62 #define _PAGE_RW        0x020  /* PR0-bit : write access allowed */
63 #define _PAGE_USER      0x040  /* PR1-bit : user space access allowed */
64 #define _PAGE_SZ1       0x080  /* SZ1-bit : Size of page (on SH-4) */
65 #define _PAGE_PRESENT   0x100  /* V-bit   : page is valid */
66 #define _PAGE_PROTNONE  0x200  /* software: if not present  */
67 #define _PAGE_ACCESSED  0x400  /* software: page referenced */
68 #define _PAGE_U0_SHARED 0x800  /* software: page is shared in user space */
69
70 #define _PAGE_FILE      _PAGE_WT  /* software: pagecache or swap? */
71
72 /* software: moves to PTEA.TC (Timing Control) */
73 #define _PAGE_PCC_AREA5 0x00000000      /* use BSC registers for area5 */
74 #define _PAGE_PCC_AREA6 0x80000000      /* use BSC registers for area6 */
75
76 /* software: moves to PTEA.SA[2:0] (Space Attributes) */
77 #define _PAGE_PCC_IODYN 0x00000001      /* IO space, dynamically sized bus */
78 #define _PAGE_PCC_IO8   0x20000000      /* IO space, 8 bit bus */
79 #define _PAGE_PCC_IO16  0x20000001      /* IO space, 16 bit bus */
80 #define _PAGE_PCC_COM8  0x40000000      /* Common Memory space, 8 bit bus */
81 #define _PAGE_PCC_COM16 0x40000001      /* Common Memory space, 16 bit bus */
82 #define _PAGE_PCC_ATR8  0x60000000      /* Attribute Memory space, 8 bit bus */
83 #define _PAGE_PCC_ATR16 0x60000001      /* Attribute Memory space, 6 bit bus */
84
85 /* Mask which drop software flags
86  * We also drop WT bit since it is used for _PAGE_FILE
87  * bit in this implementation.
88  */
89 #define _PAGE_CLEAR_FLAGS       (_PAGE_WT | _PAGE_PROTNONE | _PAGE_ACCESSED | _PAGE_U0_SHARED)
90
91 #if defined(CONFIG_CPU_SH3)
92 /*
93  * MMU on SH-3 has bug on SH-bit: We can't use it if MMUCR.IX=1.
94  * Work around: Just drop SH-bit.
95  */
96 #define _PAGE_FLAGS_HARDWARE_MASK       (0x1fffffff & ~(_PAGE_CLEAR_FLAGS | _PAGE_HW_SHARED))
97 #else
98 #define _PAGE_FLAGS_HARDWARE_MASK       (0x1fffffff & ~(_PAGE_CLEAR_FLAGS))
99 #endif
100
101 /* Hardware flags: SZ0=1 (4k-byte) */
102 #define _PAGE_FLAGS_HARD        _PAGE_SZ0
103
104 #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
105 #define _PAGE_SZHUGE    (_PAGE_SZ1)
106 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
107 #define _PAGE_SZHUGE    (_PAGE_SZ0 | _PAGE_SZ1)
108 #endif
109
110 #define _PAGE_SHARED    _PAGE_U0_SHARED
111
112 #define _PAGE_TABLE     (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
113 #define _KERNPG_TABLE   (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
114 #define _PAGE_CHG_MASK  (PTE_MASK | _PAGE_ACCESSED | _PAGE_CACHABLE | _PAGE_DIRTY | _PAGE_SHARED)
115
116 #ifndef __ASSEMBLY__
117
118 #ifdef CONFIG_MMU
119 #define PAGE_NONE       __pgprot(_PAGE_PROTNONE | _PAGE_CACHABLE |_PAGE_ACCESSED | _PAGE_FLAGS_HARD)
120 #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_CACHABLE |_PAGE_ACCESSED | _PAGE_SHARED | _PAGE_FLAGS_HARD)
121 #define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | _PAGE_ACCESSED | _PAGE_FLAGS_HARD)
122 #define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | _PAGE_ACCESSED | _PAGE_FLAGS_HARD)
123 #define PAGE_KERNEL     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_CACHABLE | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_HW_SHARED | _PAGE_FLAGS_HARD)
124 #define PAGE_KERNEL_NOCACHE \
125                         __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_HW_SHARED | _PAGE_FLAGS_HARD)
126 #define PAGE_KERNEL_RO  __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_HW_SHARED | _PAGE_FLAGS_HARD)
127 #define PAGE_KERNEL_PCC(slot, type) \
128                         __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_FLAGS_HARD | (slot ? _PAGE_PCC_AREA5 : _PAGE_PCC_AREA6) | (type))
129 #else /* no mmu */
130 #define PAGE_NONE               __pgprot(0)
131 #define PAGE_SHARED             __pgprot(0)
132 #define PAGE_COPY               __pgprot(0)
133 #define PAGE_READONLY           __pgprot(0)
134 #define PAGE_KERNEL             __pgprot(0)
135 #define PAGE_KERNEL_NOCACHE     __pgprot(0)
136 #define PAGE_KERNEL_RO          __pgprot(0)
137 #define PAGE_KERNEL_PCC         __pgprot(0)
138 #endif
139
140 #endif /* __ASSEMBLY__ */
141
142 /*
143  * As i386 and MIPS, SuperH can't do page protection for execute, and
144  * considers that the same as a read.  Also, write permissions imply
145  * read permissions. This is the closest we can get..
146  */
147 #define __P000  PAGE_NONE
148 #define __P001  PAGE_READONLY
149 #define __P010  PAGE_COPY
150 #define __P011  PAGE_COPY
151 #define __P100  PAGE_READONLY
152 #define __P101  PAGE_READONLY
153 #define __P110  PAGE_COPY
154 #define __P111  PAGE_COPY
155
156 #define __S000  PAGE_NONE
157 #define __S001  PAGE_READONLY
158 #define __S010  PAGE_SHARED
159 #define __S011  PAGE_SHARED
160 #define __S100  PAGE_READONLY
161 #define __S101  PAGE_READONLY
162 #define __S110  PAGE_SHARED
163 #define __S111  PAGE_SHARED
164
165 #ifndef __ASSEMBLY__
166
167 /*
168  * Certain architectures need to do special things when PTEs
169  * within a page table are directly modified.  Thus, the following
170  * hook is made available.
171  */
172 #define set_pte(pteptr, pteval) (*(pteptr) = pteval)
173 #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
174
175 /*
176  * (pmds are folded into pgds so this doesn't get actually called,
177  * but the define is needed for a generic inline function.)
178  */
179 #define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)
180
181 #define pte_pfn(x)              ((unsigned long)(((x).pte >> PAGE_SHIFT)))
182 #define pfn_pte(pfn, prot)      __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
183 #define pfn_pmd(pfn, prot)      __pmd(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
184
185 #define pte_none(x)     (!pte_val(x))
186 #define pte_present(x)  (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE))
187 #define pte_clear(mm,addr,xp)   do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)
188
189 #define pmd_none(x)     (!pmd_val(x))
190 #define pmd_present(x)  (pmd_val(x) & _PAGE_PRESENT)
191 #define pmd_clear(xp)   do { set_pmd(xp, __pmd(0)); } while (0)
192 #define pmd_bad(x)      ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
193
194 #define pages_to_mb(x)  ((x) >> (20-PAGE_SHIFT))
195 #define pte_page(x)     phys_to_page(pte_val(x)&PTE_PHYS_MASK)
196
197 /*
198  * The following only work if pte_present() is true.
199  * Undefined behaviour if not..
200  */
201 static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
202 static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
203 static inline int pte_dirty(pte_t pte){ return pte_val(pte) & _PAGE_DIRTY; }
204 static inline int pte_young(pte_t pte){ return pte_val(pte) & _PAGE_ACCESSED; }
205 static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
206 static inline int pte_write(pte_t pte){ return pte_val(pte) & _PAGE_RW; }
207 static inline int pte_not_present(pte_t pte){ return !(pte_val(pte) & _PAGE_PRESENT); }
208
209 static inline pte_t pte_rdprotect(pte_t pte)    { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
210 static inline pte_t pte_exprotect(pte_t pte)    { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
211 static inline pte_t pte_mkclean(pte_t pte)      { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
212 static inline pte_t pte_mkold(pte_t pte)        { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
213 static inline pte_t pte_wrprotect(pte_t pte)    { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW)); return pte; }
214 static inline pte_t pte_mkread(pte_t pte)       { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
215 static inline pte_t pte_mkexec(pte_t pte)       { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
216 static inline pte_t pte_mkdirty(pte_t pte)      { set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
217 static inline pte_t pte_mkyoung(pte_t pte)      { set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
218 static inline pte_t pte_mkwrite(pte_t pte)      { set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; }
219 #ifdef CONFIG_HUGETLB_PAGE
220 static inline pte_t pte_mkhuge(pte_t pte)       { set_pte(&pte, __pte(pte_val(pte) | _PAGE_SZHUGE)); return pte; }
221 #endif
222
223 /*
224  * Macro and implementation to make a page protection as uncachable.
225  */
226 #define pgprot_noncached pgprot_noncached
227
228 static inline pgprot_t pgprot_noncached(pgprot_t _prot)
229 {
230         unsigned long prot = pgprot_val(_prot);
231
232         prot &= ~_PAGE_CACHABLE;
233         return __pgprot(prot);
234 }
235
236 #define pgprot_writecombine(prot) __pgprot(pgprot_val(prot) & ~_PAGE_CACHABLE)
237
238 /*
239  * Conversion functions: convert a page and protection to a page entry,
240  * and a page entry and page directory to the page they refer to.
241  *
242  * extern pte_t mk_pte(struct page *page, pgprot_t pgprot)
243  */
244 #define mk_pte(page, pgprot)    pfn_pte(page_to_pfn(page), (pgprot))
245
246 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
247 { set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot))); return pte; }
248
249 #define pmd_page_vaddr(pmd) \
250 ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
251
252 #define pmd_page(pmd) \
253         (phys_to_page(pmd_val(pmd)))
254
255 /* to find an entry in a page-table-directory. */
256 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
257 #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
258
259 /* to find an entry in a kernel page-table-directory */
260 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
261
262 /* Find an entry in the third-level page table.. */
263 #define pte_index(address) \
264                 ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
265 #define pte_offset_kernel(dir, address) \
266         ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(address))
267 #define pte_offset_map(dir, address) pte_offset_kernel(dir, address)
268 #define pte_offset_map_nested(dir, address) pte_offset_kernel(dir, address)
269 #define pte_unmap(pte)          do { } while (0)
270 #define pte_unmap_nested(pte)   do { } while (0)
271
272 #define pte_ERROR(e) \
273         printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
274 #define pgd_ERROR(e) \
275         printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
276
277 struct vm_area_struct;
278 extern void update_mmu_cache(struct vm_area_struct * vma,
279                              unsigned long address, pte_t pte);
280
281 /* Encode and de-code a swap entry */
282 /*
283  * NOTE: We should set ZEROs at the position of _PAGE_PRESENT
284  *       and _PAGE_PROTNONE bits
285  */
286 #define __swp_type(x)           ((x).val & 0xff)
287 #define __swp_offset(x)         ((x).val >> 10)
288 #define __swp_entry(type, offset) ((swp_entry_t) { (type) | ((offset) << 10) })
289 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 1 })
290 #define __swp_entry_to_pte(x)   ((pte_t) { (x).val << 1 })
291
292 /*
293  * Encode and decode a nonlinear file mapping entry
294  */
295 #define PTE_FILE_MAX_BITS       29
296 #define pte_to_pgoff(pte)       (pte_val(pte) >> 1)
297 #define pgoff_to_pte(off)       ((pte_t) { ((off) << 1) | _PAGE_FILE })
298
299 typedef pte_t *pte_addr_t;
300
301 #define kern_addr_valid(addr)   (1)
302
303 #define io_remap_pfn_range(vma, vaddr, pfn, size, prot)         \
304                 remap_pfn_range(vma, vaddr, pfn, size, prot)
305
306 #define MK_IOSPACE_PFN(space, pfn)      (pfn)
307 #define GET_IOSPACE(pfn)                0
308 #define GET_PFN(pfn)                    (pfn)
309
310 struct mm_struct;
311
312 /*
313  * No page table caches to initialise
314  */
315 #define pgtable_cache_init()    do { } while (0)
316
317 #ifndef CONFIG_MMU
318 extern unsigned int kobjsize(const void *objp);
319 #endif /* !CONFIG_MMU */
320
321 #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
322 #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
323 extern pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
324 #endif
325
326 #include <asm-generic/pgtable.h>
327
328 #endif /* !__ASSEMBLY__ */
329
330 #endif /* __ASM_SH_PAGE_H */
331