aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-alpha/pgtable.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-alpha/pgtable.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-alpha/pgtable.h')
-rw-r--r--include/asm-alpha/pgtable.h369
1 files changed, 369 insertions, 0 deletions
diff --git a/include/asm-alpha/pgtable.h b/include/asm-alpha/pgtable.h
new file mode 100644
index 000000000000..faae196d8377
--- /dev/null
+++ b/include/asm-alpha/pgtable.h
@@ -0,0 +1,369 @@
1#ifndef _ALPHA_PGTABLE_H
2#define _ALPHA_PGTABLE_H
3
4#include <asm-generic/4level-fixup.h>
5
6/*
7 * This file contains the functions and defines necessary to modify and use
8 * the Alpha page table tree.
9 *
10 * This hopefully works with any standard Alpha page-size, as defined
11 * in <asm/page.h> (currently 8192).
12 */
13#include <linux/config.h>
14#include <linux/mmzone.h>
15
16#include <asm/page.h>
17#include <asm/processor.h> /* For TASK_SIZE */
18#include <asm/machvec.h>
19
20/* Certain architectures need to do special things when PTEs
21 * within a page table are directly modified. Thus, the following
22 * hook is made available.
23 */
24#define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
25#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
26
27/* PMD_SHIFT determines the size of the area a second-level page table can map */
28#define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
29#define PMD_SIZE (1UL << PMD_SHIFT)
30#define PMD_MASK (~(PMD_SIZE-1))
31
32/* PGDIR_SHIFT determines what a third-level page table entry can map */
33#define PGDIR_SHIFT (PAGE_SHIFT + 2*(PAGE_SHIFT-3))
34#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
35#define PGDIR_MASK (~(PGDIR_SIZE-1))
36
37/*
38 * Entries per page directory level: the Alpha is three-level, with
39 * all levels having a one-page page table.
40 */
41#define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
42#define PTRS_PER_PMD (1UL << (PAGE_SHIFT-3))
43#define PTRS_PER_PGD (1UL << (PAGE_SHIFT-3))
44#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
45#define FIRST_USER_PGD_NR 0
46
47/* Number of pointers that fit on a page: this will go away. */
48#define PTRS_PER_PAGE (1UL << (PAGE_SHIFT-3))
49
50#ifdef CONFIG_ALPHA_LARGE_VMALLOC
51#define VMALLOC_START 0xfffffe0000000000
52#else
53#define VMALLOC_START (-2*PGDIR_SIZE)
54#endif
55#define VMALLOC_END (-PGDIR_SIZE)
56
57/*
58 * OSF/1 PAL-code-imposed page table bits
59 */
60#define _PAGE_VALID 0x0001
61#define _PAGE_FOR 0x0002 /* used for page protection (fault on read) */
62#define _PAGE_FOW 0x0004 /* used for page protection (fault on write) */
63#define _PAGE_FOE 0x0008 /* used for page protection (fault on exec) */
64#define _PAGE_ASM 0x0010
65#define _PAGE_KRE 0x0100 /* xxx - see below on the "accessed" bit */
66#define _PAGE_URE 0x0200 /* xxx */
67#define _PAGE_KWE 0x1000 /* used to do the dirty bit in software */
68#define _PAGE_UWE 0x2000 /* used to do the dirty bit in software */
69
70/* .. and these are ours ... */
71#define _PAGE_DIRTY 0x20000
72#define _PAGE_ACCESSED 0x40000
73#define _PAGE_FILE 0x80000 /* set:pagecache, unset:swap */
74
75/*
76 * NOTE! The "accessed" bit isn't necessarily exact: it can be kept exactly
77 * by software (use the KRE/URE/KWE/UWE bits appropriately), but I'll fake it.
78 * Under Linux/AXP, the "accessed" bit just means "read", and I'll just use
79 * the KRE/URE bits to watch for it. That way we don't need to overload the
80 * KWE/UWE bits with both handling dirty and accessed.
81 *
82 * Note that the kernel uses the accessed bit just to check whether to page
83 * out a page or not, so it doesn't have to be exact anyway.
84 */
85
86#define __DIRTY_BITS (_PAGE_DIRTY | _PAGE_KWE | _PAGE_UWE)
87#define __ACCESS_BITS (_PAGE_ACCESSED | _PAGE_KRE | _PAGE_URE)
88
89#define _PFN_MASK 0xFFFFFFFF00000000UL
90
91#define _PAGE_TABLE (_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
92#define _PAGE_CHG_MASK (_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS)
93
94/*
95 * All the normal masks have the "page accessed" bits on, as any time they are used,
96 * the page is accessed. They are cleared only by the page-out routines
97 */
98#define PAGE_NONE __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
99#define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
100#define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
101#define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
102#define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
103
104#define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
105
106#define _PAGE_P(x) _PAGE_NORMAL((x) | (((x) & _PAGE_FOW)?0:_PAGE_FOW))
107#define _PAGE_S(x) _PAGE_NORMAL(x)
108
109/*
110 * The hardware can handle write-only mappings, but as the Alpha
111 * architecture does byte-wide writes with a read-modify-write
112 * sequence, it's not practical to have write-without-read privs.
113 * Thus the "-w- -> rw-" and "-wx -> rwx" mapping here (and in
114 * arch/alpha/mm/fault.c)
115 */
116 /* xwr */
117#define __P000 _PAGE_P(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
118#define __P001 _PAGE_P(_PAGE_FOE | _PAGE_FOW)
119#define __P010 _PAGE_P(_PAGE_FOE)
120#define __P011 _PAGE_P(_PAGE_FOE)
121#define __P100 _PAGE_P(_PAGE_FOW | _PAGE_FOR)
122#define __P101 _PAGE_P(_PAGE_FOW)
123#define __P110 _PAGE_P(0)
124#define __P111 _PAGE_P(0)
125
126#define __S000 _PAGE_S(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
127#define __S001 _PAGE_S(_PAGE_FOE | _PAGE_FOW)
128#define __S010 _PAGE_S(_PAGE_FOE)
129#define __S011 _PAGE_S(_PAGE_FOE)
130#define __S100 _PAGE_S(_PAGE_FOW | _PAGE_FOR)
131#define __S101 _PAGE_S(_PAGE_FOW)
132#define __S110 _PAGE_S(0)
133#define __S111 _PAGE_S(0)
134
135/*
136 * BAD_PAGETABLE is used when we need a bogus page-table, while
137 * BAD_PAGE is used for a bogus page.
138 *
139 * ZERO_PAGE is a global shared page that is always zero: used
140 * for zero-mapped memory areas etc..
141 */
142extern pte_t __bad_page(void);
143extern pmd_t * __bad_pagetable(void);
144
145extern unsigned long __zero_page(void);
146
147#define BAD_PAGETABLE __bad_pagetable()
148#define BAD_PAGE __bad_page()
149#define ZERO_PAGE(vaddr) (virt_to_page(ZERO_PGE))
150
151/* number of bits that fit into a memory pointer */
152#define BITS_PER_PTR (8*sizeof(unsigned long))
153
154/* to align the pointer to a pointer address */
155#define PTR_MASK (~(sizeof(void*)-1))
156
157/* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
158#define SIZEOF_PTR_LOG2 3
159
160/* to find an entry in a page-table */
161#define PAGE_PTR(address) \
162 ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
163
164/*
165 * On certain platforms whose physical address space can overlap KSEG,
166 * namely EV6 and above, we must re-twiddle the physaddr to restore the
167 * correct high-order bits.
168 *
169 * This is extremely confusing until you realize that this is actually
170 * just working around a userspace bug. The X server was intending to
171 * provide the physical address but instead provided the KSEG address.
172 * Or tried to, except it's not representable.
173 *
174 * On Tsunami there's nothing meaningful at 0x40000000000, so this is
175 * a safe thing to do. Come the first core logic that does put something
176 * in this area -- memory or whathaveyou -- then this hack will have
177 * to go away. So be prepared!
178 */
179
180#if defined(CONFIG_ALPHA_GENERIC) && defined(USE_48_BIT_KSEG)
181#error "EV6-only feature in a generic kernel"
182#endif
183#if defined(CONFIG_ALPHA_GENERIC) || \
184 (defined(CONFIG_ALPHA_EV6) && !defined(USE_48_BIT_KSEG))
185#define KSEG_PFN (0xc0000000000UL >> PAGE_SHIFT)
186#define PHYS_TWIDDLE(pfn) \
187 ((((pfn) & KSEG_PFN) == (0x40000000000UL >> PAGE_SHIFT)) \
188 ? ((pfn) ^= KSEG_PFN) : (pfn))
189#else
190#define PHYS_TWIDDLE(pfn) (pfn)
191#endif
192
193/*
194 * Conversion functions: convert a page and protection to a page entry,
195 * and a page entry and page directory to the page they refer to.
196 */
197#ifndef CONFIG_DISCONTIGMEM
198#define page_to_pa(page) (((page) - mem_map) << PAGE_SHIFT)
199
200#define pte_pfn(pte) (pte_val(pte) >> 32)
201#define pte_page(pte) pfn_to_page(pte_pfn(pte))
202#define mk_pte(page, pgprot) \
203({ \
204 pte_t pte; \
205 \
206 pte_val(pte) = (page_to_pfn(page) << 32) | pgprot_val(pgprot); \
207 pte; \
208})
209#endif
210
211extern inline pte_t pfn_pte(unsigned long physpfn, pgprot_t pgprot)
212{ pte_t pte; pte_val(pte) = (PHYS_TWIDDLE(physpfn) << 32) | pgprot_val(pgprot); return pte; }
213
214extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
215{ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
216
217extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
218{ pmd_val(*pmdp) = _PAGE_TABLE | ((((unsigned long) ptep) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
219
220extern inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
221{ pgd_val(*pgdp) = _PAGE_TABLE | ((((unsigned long) pmdp) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
222
223
224extern inline unsigned long
225pmd_page_kernel(pmd_t pmd)
226{
227 return ((pmd_val(pmd) & _PFN_MASK) >> (32-PAGE_SHIFT)) + PAGE_OFFSET;
228}
229
230#ifndef CONFIG_DISCONTIGMEM
231#define pmd_page(pmd) (mem_map + ((pmd_val(pmd) & _PFN_MASK) >> 32))
232#endif
233
234extern inline unsigned long pgd_page(pgd_t pgd)
235{ return PAGE_OFFSET + ((pgd_val(pgd) & _PFN_MASK) >> (32-PAGE_SHIFT)); }
236
237extern inline int pte_none(pte_t pte) { return !pte_val(pte); }
238extern inline int pte_present(pte_t pte) { return pte_val(pte) & _PAGE_VALID; }
239extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
240{
241 pte_val(*ptep) = 0;
242}
243
244extern inline int pmd_none(pmd_t pmd) { return !pmd_val(pmd); }
245extern inline int pmd_bad(pmd_t pmd) { return (pmd_val(pmd) & ~_PFN_MASK) != _PAGE_TABLE; }
246extern inline int pmd_present(pmd_t pmd) { return pmd_val(pmd) & _PAGE_VALID; }
247extern inline void pmd_clear(pmd_t * pmdp) { pmd_val(*pmdp) = 0; }
248
249extern inline int pgd_none(pgd_t pgd) { return !pgd_val(pgd); }
250extern inline int pgd_bad(pgd_t pgd) { return (pgd_val(pgd) & ~_PFN_MASK) != _PAGE_TABLE; }
251extern inline int pgd_present(pgd_t pgd) { return pgd_val(pgd) & _PAGE_VALID; }
252extern inline void pgd_clear(pgd_t * pgdp) { pgd_val(*pgdp) = 0; }
253
254/*
255 * The following only work if pte_present() is true.
256 * Undefined behaviour if not..
257 */
258extern inline int pte_read(pte_t pte) { return !(pte_val(pte) & _PAGE_FOR); }
259extern inline int pte_write(pte_t pte) { return !(pte_val(pte) & _PAGE_FOW); }
260extern inline int pte_exec(pte_t pte) { return !(pte_val(pte) & _PAGE_FOE); }
261extern inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
262extern inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
263extern inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
264
265extern inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) |= _PAGE_FOW; return pte; }
266extern inline pte_t pte_rdprotect(pte_t pte) { pte_val(pte) |= _PAGE_FOR; return pte; }
267extern inline pte_t pte_exprotect(pte_t pte) { pte_val(pte) |= _PAGE_FOE; return pte; }
268extern inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~(__DIRTY_BITS); return pte; }
269extern inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~(__ACCESS_BITS); return pte; }
270extern inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) &= ~_PAGE_FOW; return pte; }
271extern inline pte_t pte_mkread(pte_t pte) { pte_val(pte) &= ~_PAGE_FOR; return pte; }
272extern inline pte_t pte_mkexec(pte_t pte) { pte_val(pte) &= ~_PAGE_FOE; return pte; }
273extern inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= __DIRTY_BITS; return pte; }
274extern inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= __ACCESS_BITS; return pte; }
275
276#define PAGE_DIR_OFFSET(tsk,address) pgd_offset((tsk),(address))
277
278/* to find an entry in a kernel page-table-directory */
279#define pgd_offset_k(address) pgd_offset(&init_mm, (address))
280
281/* to find an entry in a page-table-directory. */
282#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
283#define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
284
285/* Find an entry in the second-level page table.. */
286extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
287{
288 return (pmd_t *) pgd_page(*dir) + ((address >> PMD_SHIFT) & (PTRS_PER_PAGE - 1));
289}
290
291/* Find an entry in the third-level page table.. */
292extern inline pte_t * pte_offset_kernel(pmd_t * dir, unsigned long address)
293{
294 return (pte_t *) pmd_page_kernel(*dir)
295 + ((address >> PAGE_SHIFT) & (PTRS_PER_PAGE - 1));
296}
297
298#define pte_offset_map(dir,addr) pte_offset_kernel((dir),(addr))
299#define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir),(addr))
300#define pte_unmap(pte) do { } while (0)
301#define pte_unmap_nested(pte) do { } while (0)
302
303extern pgd_t swapper_pg_dir[1024];
304
305/*
306 * The Alpha doesn't have any external MMU info: the kernel page
307 * tables contain all the necessary information.
308 */
309extern inline void update_mmu_cache(struct vm_area_struct * vma,
310 unsigned long address, pte_t pte)
311{
312}
313
314/*
315 * Non-present pages: high 24 bits are offset, next 8 bits type,
316 * low 32 bits zero.
317 */
318extern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
319{ pte_t pte; pte_val(pte) = (type << 32) | (offset << 40); return pte; }
320
321#define __swp_type(x) (((x).val >> 32) & 0xff)
322#define __swp_offset(x) ((x).val >> 40)
323#define __swp_entry(type, off) ((swp_entry_t) { pte_val(mk_swap_pte((type), (off))) })
324#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
325#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
326
327#define pte_to_pgoff(pte) (pte_val(pte) >> 32)
328#define pgoff_to_pte(off) ((pte_t) { ((off) << 32) | _PAGE_FILE })
329
330#define PTE_FILE_MAX_BITS 32
331
332#ifndef CONFIG_DISCONTIGMEM
333#define kern_addr_valid(addr) (1)
334#endif
335
336#define io_remap_page_range(vma, start, busaddr, size, prot) \
337({ \
338 void *va = (void __force *)ioremap(busaddr, size); \
339 unsigned long pfn = virt_to_phys(va) >> PAGE_SHIFT; \
340 remap_pfn_range(vma, start, pfn, size, prot); \
341})
342
343#define io_remap_pfn_range(vma, start, pfn, size, prot) \
344 remap_pfn_range(vma, start, pfn, size, prot)
345
346#define MK_IOSPACE_PFN(space, pfn) (pfn)
347#define GET_IOSPACE(pfn) 0
348#define GET_PFN(pfn) (pfn)
349
350#define pte_ERROR(e) \
351 printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
352#define pmd_ERROR(e) \
353 printk("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
354#define pgd_ERROR(e) \
355 printk("%s:%d: bad pgd %016lx.\n", __FILE__, __LINE__, pgd_val(e))
356
357extern void paging_init(void);
358
359#include <asm-generic/pgtable.h>
360
361/*
362 * No page table caches to initialise
363 */
364#define pgtable_cache_init() do { } while (0)
365
366/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT. */
367#define HAVE_ARCH_UNMAPPED_AREA
368
369#endif /* _ALPHA_PGTABLE_H */