aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sparc/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-sparc/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-sparc/pgtable.h')
-rw-r--r--include/asm-sparc/pgtable.h465
1 files changed, 465 insertions, 0 deletions
diff --git a/include/asm-sparc/pgtable.h b/include/asm-sparc/pgtable.h
new file mode 100644
index 000000000000..373a6c327590
--- /dev/null
+++ b/include/asm-sparc/pgtable.h
@@ -0,0 +1,465 @@
1/* $Id: pgtable.h,v 1.110 2001/12/21 04:56:17 davem Exp $ */
2#ifndef _SPARC_PGTABLE_H
3#define _SPARC_PGTABLE_H
4
5/* asm-sparc/pgtable.h: Defines and functions used to work
6 * with Sparc page tables.
7 *
8 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
9 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
10 */
11
12#include <asm-generic/4level-fixup.h>
13
14#include <linux/config.h>
15#include <linux/spinlock.h>
16#include <linux/swap.h>
17#include <asm/types.h>
18#ifdef CONFIG_SUN4
19#include <asm/pgtsun4.h>
20#else
21#include <asm/pgtsun4c.h>
22#endif
23#include <asm/pgtsrmmu.h>
24#include <asm/vac-ops.h>
25#include <asm/oplib.h>
26#include <asm/btfixup.h>
27#include <asm/system.h>
28
29#ifndef __ASSEMBLY__
30
31struct vm_area_struct;
32struct page;
33
34extern void load_mmu(void);
35extern unsigned long calc_highpages(void);
36
37BTFIXUPDEF_SIMM13(pgdir_shift)
38BTFIXUPDEF_SETHI(pgdir_size)
39BTFIXUPDEF_SETHI(pgdir_mask)
40
41BTFIXUPDEF_SIMM13(ptrs_per_pmd)
42BTFIXUPDEF_SIMM13(ptrs_per_pgd)
43BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
44
45#define pte_ERROR(e) __builtin_trap()
46#define pmd_ERROR(e) __builtin_trap()
47#define pgd_ERROR(e) __builtin_trap()
48
49BTFIXUPDEF_INT(page_none)
50BTFIXUPDEF_INT(page_shared)
51BTFIXUPDEF_INT(page_copy)
52BTFIXUPDEF_INT(page_readonly)
53BTFIXUPDEF_INT(page_kernel)
54
55#define PMD_SHIFT SUN4C_PMD_SHIFT
56#define PMD_SIZE (1UL << PMD_SHIFT)
57#define PMD_MASK (~(PMD_SIZE-1))
58#define PMD_ALIGN(__addr) (((__addr) + ~PMD_MASK) & PMD_MASK)
59#define PGDIR_SHIFT BTFIXUP_SIMM13(pgdir_shift)
60#define PGDIR_SIZE BTFIXUP_SETHI(pgdir_size)
61#define PGDIR_MASK BTFIXUP_SETHI(pgdir_mask)
62#define PTRS_PER_PTE 1024
63#define PTRS_PER_PMD BTFIXUP_SIMM13(ptrs_per_pmd)
64#define PTRS_PER_PGD BTFIXUP_SIMM13(ptrs_per_pgd)
65#define USER_PTRS_PER_PGD BTFIXUP_SIMM13(user_ptrs_per_pgd)
66#define FIRST_USER_PGD_NR 0
67#define PTE_SIZE (PTRS_PER_PTE*4)
68
69#define PAGE_NONE __pgprot(BTFIXUP_INT(page_none))
70#define PAGE_SHARED __pgprot(BTFIXUP_INT(page_shared))
71#define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
72#define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
73
74extern unsigned long page_kernel;
75
76#ifdef MODULE
77#define PAGE_KERNEL page_kernel
78#else
79#define PAGE_KERNEL __pgprot(BTFIXUP_INT(page_kernel))
80#endif
81
82/* Top-level page directory */
83extern pgd_t swapper_pg_dir[1024];
84
85/* Page table for 0-4MB for everybody, on the Sparc this
86 * holds the same as on the i386.
87 */
88extern pte_t pg0[1024];
89extern pte_t pg1[1024];
90extern pte_t pg2[1024];
91extern pte_t pg3[1024];
92
93extern unsigned long ptr_in_current_pgd;
94
95/* Here is a trick, since mmap.c need the initializer elements for
96 * protection_map[] to be constant at compile time, I set the following
97 * to all zeros. I set it to the real values after I link in the
98 * appropriate MMU page table routines at boot time.
99 */
100#define __P000 __pgprot(0)
101#define __P001 __pgprot(0)
102#define __P010 __pgprot(0)
103#define __P011 __pgprot(0)
104#define __P100 __pgprot(0)
105#define __P101 __pgprot(0)
106#define __P110 __pgprot(0)
107#define __P111 __pgprot(0)
108
109#define __S000 __pgprot(0)
110#define __S001 __pgprot(0)
111#define __S010 __pgprot(0)
112#define __S011 __pgprot(0)
113#define __S100 __pgprot(0)
114#define __S101 __pgprot(0)
115#define __S110 __pgprot(0)
116#define __S111 __pgprot(0)
117
118extern int num_contexts;
119
120/* First physical page can be anywhere, the following is needed so that
121 * va-->pa and vice versa conversions work properly without performance
122 * hit for all __pa()/__va() operations.
123 */
124extern unsigned long phys_base;
125extern unsigned long pfn_base;
126
127/*
128 * BAD_PAGETABLE is used when we need a bogus page-table, while
129 * BAD_PAGE is used for a bogus page.
130 *
131 * ZERO_PAGE is a global shared page that is always zero: used
132 * for zero-mapped memory areas etc..
133 */
134extern pte_t * __bad_pagetable(void);
135extern pte_t __bad_page(void);
136extern unsigned long empty_zero_page;
137
138#define BAD_PAGETABLE __bad_pagetable()
139#define BAD_PAGE __bad_page()
140#define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
141
142/*
143 */
144BTFIXUPDEF_CALL_CONST(struct page *, pmd_page, pmd_t)
145BTFIXUPDEF_CALL_CONST(unsigned long, pgd_page, pgd_t)
146
147#define pmd_page(pmd) BTFIXUP_CALL(pmd_page)(pmd)
148#define pgd_page(pgd) BTFIXUP_CALL(pgd_page)(pgd)
149
150BTFIXUPDEF_SETHI(none_mask)
151BTFIXUPDEF_CALL_CONST(int, pte_present, pte_t)
152BTFIXUPDEF_CALL(void, pte_clear, pte_t *)
153BTFIXUPDEF_CALL(int, pte_read, pte_t)
154
155extern __inline__ int pte_none(pte_t pte)
156{
157 return !(pte_val(pte) & ~BTFIXUP_SETHI(none_mask));
158}
159
160#define pte_present(pte) BTFIXUP_CALL(pte_present)(pte)
161#define pte_clear(mm,addr,pte) BTFIXUP_CALL(pte_clear)(pte)
162#define pte_read(pte) BTFIXUP_CALL(pte_read)(pte)
163
164BTFIXUPDEF_CALL_CONST(int, pmd_bad, pmd_t)
165BTFIXUPDEF_CALL_CONST(int, pmd_present, pmd_t)
166BTFIXUPDEF_CALL(void, pmd_clear, pmd_t *)
167
168extern __inline__ int pmd_none(pmd_t pmd)
169{
170 return !(pmd_val(pmd) & ~BTFIXUP_SETHI(none_mask));
171}
172
173#define pmd_bad(pmd) BTFIXUP_CALL(pmd_bad)(pmd)
174#define pmd_present(pmd) BTFIXUP_CALL(pmd_present)(pmd)
175#define pmd_clear(pmd) BTFIXUP_CALL(pmd_clear)(pmd)
176
177BTFIXUPDEF_CALL_CONST(int, pgd_none, pgd_t)
178BTFIXUPDEF_CALL_CONST(int, pgd_bad, pgd_t)
179BTFIXUPDEF_CALL_CONST(int, pgd_present, pgd_t)
180BTFIXUPDEF_CALL(void, pgd_clear, pgd_t *)
181
182#define pgd_none(pgd) BTFIXUP_CALL(pgd_none)(pgd)
183#define pgd_bad(pgd) BTFIXUP_CALL(pgd_bad)(pgd)
184#define pgd_present(pgd) BTFIXUP_CALL(pgd_present)(pgd)
185#define pgd_clear(pgd) BTFIXUP_CALL(pgd_clear)(pgd)
186
187/*
188 * The following only work if pte_present() is true.
189 * Undefined behaviour if not..
190 */
191BTFIXUPDEF_HALF(pte_writei)
192BTFIXUPDEF_HALF(pte_dirtyi)
193BTFIXUPDEF_HALF(pte_youngi)
194
195extern int pte_write(pte_t pte) __attribute_const__;
196extern __inline__ int pte_write(pte_t pte)
197{
198 return pte_val(pte) & BTFIXUP_HALF(pte_writei);
199}
200
201extern int pte_dirty(pte_t pte) __attribute_const__;
202extern __inline__ int pte_dirty(pte_t pte)
203{
204 return pte_val(pte) & BTFIXUP_HALF(pte_dirtyi);
205}
206
207extern int pte_young(pte_t pte) __attribute_const__;
208extern __inline__ int pte_young(pte_t pte)
209{
210 return pte_val(pte) & BTFIXUP_HALF(pte_youngi);
211}
212
213/*
214 * The following only work if pte_present() is not true.
215 */
216BTFIXUPDEF_HALF(pte_filei)
217
218extern int pte_file(pte_t pte) __attribute_const__;
219extern __inline__ int pte_file(pte_t pte)
220{
221 return pte_val(pte) & BTFIXUP_HALF(pte_filei);
222}
223
224/*
225 */
226BTFIXUPDEF_HALF(pte_wrprotecti)
227BTFIXUPDEF_HALF(pte_mkcleani)
228BTFIXUPDEF_HALF(pte_mkoldi)
229
230extern pte_t pte_wrprotect(pte_t pte) __attribute_const__;
231extern __inline__ pte_t pte_wrprotect(pte_t pte)
232{
233 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_wrprotecti));
234}
235
236extern pte_t pte_mkclean(pte_t pte) __attribute_const__;
237extern __inline__ pte_t pte_mkclean(pte_t pte)
238{
239 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkcleani));
240}
241
242extern pte_t pte_mkold(pte_t pte) __attribute_const__;
243extern __inline__ pte_t pte_mkold(pte_t pte)
244{
245 return __pte(pte_val(pte) & ~BTFIXUP_HALF(pte_mkoldi));
246}
247
248BTFIXUPDEF_CALL_CONST(pte_t, pte_mkwrite, pte_t)
249BTFIXUPDEF_CALL_CONST(pte_t, pte_mkdirty, pte_t)
250BTFIXUPDEF_CALL_CONST(pte_t, pte_mkyoung, pte_t)
251
252#define pte_mkwrite(pte) BTFIXUP_CALL(pte_mkwrite)(pte)
253#define pte_mkdirty(pte) BTFIXUP_CALL(pte_mkdirty)(pte)
254#define pte_mkyoung(pte) BTFIXUP_CALL(pte_mkyoung)(pte)
255
256#define page_pte_prot(page, prot) mk_pte(page, prot)
257#define page_pte(page) mk_pte(page, __pgprot(0))
258#define pfn_pte(pfn, prot) mk_pte(pfn_to_page(pfn), prot)
259
260BTFIXUPDEF_CALL(unsigned long, pte_pfn, pte_t)
261#define pte_pfn(pte) BTFIXUP_CALL(pte_pfn)(pte)
262#define pte_page(pte) pfn_to_page(pte_pfn(pte))
263
264/*
265 * Conversion functions: convert a page and protection to a page entry,
266 * and a page entry and page directory to the page they refer to.
267 */
268BTFIXUPDEF_CALL_CONST(pte_t, mk_pte, struct page *, pgprot_t)
269
270BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_phys, unsigned long, pgprot_t)
271BTFIXUPDEF_CALL_CONST(pte_t, mk_pte_io, unsigned long, pgprot_t, int)
272
273#define mk_pte(page,pgprot) BTFIXUP_CALL(mk_pte)(page,pgprot)
274#define mk_pte_phys(page,pgprot) BTFIXUP_CALL(mk_pte_phys)(page,pgprot)
275#define mk_pte_io(page,pgprot,space) BTFIXUP_CALL(mk_pte_io)(page,pgprot,space)
276
277BTFIXUPDEF_INT(pte_modify_mask)
278
279extern pte_t pte_modify(pte_t pte, pgprot_t newprot) __attribute_const__;
280extern __inline__ pte_t pte_modify(pte_t pte, pgprot_t newprot)
281{
282 return __pte((pte_val(pte) & BTFIXUP_INT(pte_modify_mask)) |
283 pgprot_val(newprot));
284}
285
286#define pgd_index(address) ((address) >> PGDIR_SHIFT)
287
288/* to find an entry in a page-table-directory */
289#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
290
291/* to find an entry in a kernel page-table-directory */
292#define pgd_offset_k(address) pgd_offset(&init_mm, address)
293
294/* Find an entry in the second-level page table.. */
295BTFIXUPDEF_CALL(pmd_t *, pmd_offset, pgd_t *, unsigned long)
296#define pmd_offset(dir,addr) BTFIXUP_CALL(pmd_offset)(dir,addr)
297
298/* Find an entry in the third-level page table.. */
299BTFIXUPDEF_CALL(pte_t *, pte_offset_kernel, pmd_t *, unsigned long)
300#define pte_offset_kernel(dir,addr) BTFIXUP_CALL(pte_offset_kernel)(dir,addr)
301
302/*
303 * This shortcut works on sun4m (and sun4d) because the nocache area is static,
304 * and sun4c is guaranteed to have no highmem anyway.
305 */
306#define pte_offset_map(d, a) pte_offset_kernel(d,a)
307#define pte_offset_map_nested(d, a) pte_offset_kernel(d,a)
308
309#define pte_unmap(pte) do{}while(0)
310#define pte_unmap_nested(pte) do{}while(0)
311
312/* The permissions for pgprot_val to make a page mapped on the obio space */
313extern unsigned int pg_iobits;
314
315/* Certain architectures need to do special things when pte's
316 * within a page table are directly modified. Thus, the following
317 * hook is made available.
318 */
319
320BTFIXUPDEF_CALL(void, set_pte, pte_t *, pte_t)
321
322#define set_pte(ptep,pteval) BTFIXUP_CALL(set_pte)(ptep,pteval)
323#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
324
325struct seq_file;
326BTFIXUPDEF_CALL(void, mmu_info, struct seq_file *)
327
328#define mmu_info(p) BTFIXUP_CALL(mmu_info)(p)
329
330/* Fault handler stuff... */
331#define FAULT_CODE_PROT 0x1
332#define FAULT_CODE_WRITE 0x2
333#define FAULT_CODE_USER 0x4
334
335BTFIXUPDEF_CALL(void, update_mmu_cache, struct vm_area_struct *, unsigned long, pte_t)
336
337#define update_mmu_cache(vma,addr,pte) BTFIXUP_CALL(update_mmu_cache)(vma,addr,pte)
338
339BTFIXUPDEF_CALL(void, sparc_mapiorange, unsigned int, unsigned long,
340 unsigned long, unsigned int)
341BTFIXUPDEF_CALL(void, sparc_unmapiorange, unsigned long, unsigned int)
342#define sparc_mapiorange(bus,pa,va,len) BTFIXUP_CALL(sparc_mapiorange)(bus,pa,va,len)
343#define sparc_unmapiorange(va,len) BTFIXUP_CALL(sparc_unmapiorange)(va,len)
344
345extern int invalid_segment;
346
347/* Encode and de-code a swap entry */
348BTFIXUPDEF_CALL(unsigned long, __swp_type, swp_entry_t)
349BTFIXUPDEF_CALL(unsigned long, __swp_offset, swp_entry_t)
350BTFIXUPDEF_CALL(swp_entry_t, __swp_entry, unsigned long, unsigned long)
351
352#define __swp_type(__x) BTFIXUP_CALL(__swp_type)(__x)
353#define __swp_offset(__x) BTFIXUP_CALL(__swp_offset)(__x)
354#define __swp_entry(__type,__off) BTFIXUP_CALL(__swp_entry)(__type,__off)
355
356#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
357#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
358
359/* file-offset-in-pte helpers */
360BTFIXUPDEF_CALL(unsigned long, pte_to_pgoff, pte_t pte);
361BTFIXUPDEF_CALL(pte_t, pgoff_to_pte, unsigned long pgoff);
362
363#define pte_to_pgoff(pte) BTFIXUP_CALL(pte_to_pgoff)(pte)
364#define pgoff_to_pte(off) BTFIXUP_CALL(pgoff_to_pte)(off)
365
366/*
367 * This is made a constant because mm/fremap.c required a constant.
368 * Note that layout of these bits is different between sun4c.c and srmmu.c.
369 */
370#define PTE_FILE_MAX_BITS 24
371
372/*
373 */
374struct ctx_list {
375 struct ctx_list *next;
376 struct ctx_list *prev;
377 unsigned int ctx_number;
378 struct mm_struct *ctx_mm;
379};
380
381extern struct ctx_list *ctx_list_pool; /* Dynamically allocated */
382extern struct ctx_list ctx_free; /* Head of free list */
383extern struct ctx_list ctx_used; /* Head of used contexts list */
384
385#define NO_CONTEXT -1
386
387extern __inline__ void remove_from_ctx_list(struct ctx_list *entry)
388{
389 entry->next->prev = entry->prev;
390 entry->prev->next = entry->next;
391}
392
393extern __inline__ void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
394{
395 entry->next = head;
396 (entry->prev = head->prev)->next = entry;
397 head->prev = entry;
398}
399#define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
400#define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
401
402extern __inline__ unsigned long
403__get_phys (unsigned long addr)
404{
405 switch (sparc_cpu_model){
406 case sun4:
407 case sun4c:
408 return sun4c_get_pte (addr) << PAGE_SHIFT;
409 case sun4m:
410 case sun4d:
411 return ((srmmu_get_pte (addr) & 0xffffff00) << 4);
412 default:
413 return 0;
414 }
415}
416
417extern __inline__ int
418__get_iospace (unsigned long addr)
419{
420 switch (sparc_cpu_model){
421 case sun4:
422 case sun4c:
423 return -1; /* Don't check iospace on sun4c */
424 case sun4m:
425 case sun4d:
426 return (srmmu_get_pte (addr) >> 28);
427 default:
428 return -1;
429 }
430}
431
432extern unsigned long *sparc_valid_addr_bitmap;
433
434/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
435#define kern_addr_valid(addr) \
436 (test_bit(__pa((unsigned long)(addr))>>20, sparc_valid_addr_bitmap))
437
438extern int io_remap_page_range(struct vm_area_struct *vma,
439 unsigned long from, unsigned long to,
440 unsigned long size, pgprot_t prot, int space);
441extern int io_remap_pfn_range(struct vm_area_struct *vma,
442 unsigned long from, unsigned long pfn,
443 unsigned long size, pgprot_t prot);
444
445/*
446 * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
447 * its high 4 bits. These macros/functions put it there or get it from there.
448 */
449#define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
450#define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
451#define GET_PFN(pfn) (pfn & 0x0fffffffUL)
452
453#include <asm-generic/pgtable.h>
454
455#endif /* !(__ASSEMBLY__) */
456
457/* We provide our own get_unmapped_area to cope with VA holes for userland */
458#define HAVE_ARCH_UNMAPPED_AREA
459
460/*
461 * No page table caches to initialise
462 */
463#define pgtable_cache_init() do { } while (0)
464
465#endif /* !(_SPARC_PGTABLE_H) */