Import 2.3.30pre7
[davej-history.git] / include / asm-ppc / pgtable.h
blob3c1eec8c06576c5ecba01378c53bf12776ed4b03
1 #ifndef _PPC_PGTABLE_H
2 #define _PPC_PGTABLE_H
4 #include <linux/config.h>
6 #ifndef __ASSEMBLY__
7 #include <linux/threads.h>
8 #include <asm/processor.h> /* For TASK_SIZE */
9 #include <asm/mmu.h>
10 #include <asm/page.h>
12 #ifndef CONFIG_8xx
13 struct mm_struct;
14 struct vm_area_struct;
15 extern void local_flush_tlb_all(void);
16 extern void local_flush_tlb_mm(struct mm_struct *mm);
17 extern void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
18 extern void local_flush_tlb_range(struct mm_struct *mm, unsigned long start,
19 unsigned long end);
20 #else /* CONFIG_8xx */
21 #define __tlbia() asm volatile ("tlbia" : : )
23 extern inline void local_flush_tlb_all(void)
24 { __tlbia(); }
25 extern inline void local_flush_tlb_mm(struct mm_struct *mm)
26 { __tlbia(); }
27 extern inline void local_flush_tlb_page(struct vm_area_struct *vma,
28 unsigned long vmaddr)
29 { __tlbia(); }
30 extern inline void local_flush_tlb_range(struct mm_struct *mm,
31 unsigned long start, unsigned long end)
32 { __tlbia(); }
33 extern inline void flush_hash_page(unsigned context, unsigned long va)
34 { }
35 #endif
37 #define flush_tlb_all local_flush_tlb_all
38 #define flush_tlb_mm local_flush_tlb_mm
39 #define flush_tlb_page local_flush_tlb_page
40 #define flush_tlb_range local_flush_tlb_range
43 * No cache flushing is required when address mappings are
44 * changed, because the caches on PowerPCs are physically
45 * addressed.
46 * Also, when SMP we use the coherency (M) bit of the
47 * BATs and PTEs. -- Cort
49 #define flush_cache_all() do { } while (0)
50 #define flush_cache_mm(mm) do { } while (0)
51 #define flush_cache_range(mm, a, b) do { } while (0)
52 #define flush_cache_page(vma, p) do { } while (0)
54 extern void flush_icache_range(unsigned long, unsigned long);
55 extern void __flush_page_to_ram(unsigned long page_va);
56 #define flush_page_to_ram(page) __flush_page_to_ram(page_address(page))
58 extern unsigned long va_to_phys(unsigned long address);
59 extern pte_t *va_to_pte(struct task_struct *tsk, unsigned long address);
60 extern unsigned long ioremap_bot, ioremap_base;
61 #endif /* __ASSEMBLY__ */
64 * The PowerPC MMU uses a hash table containing PTEs, together with
65 * a set of 16 segment registers (on 32-bit implementations), to define
66 * the virtual to physical address mapping.
68 * We use the hash table as an extended TLB, i.e. a cache of currently
69 * active mappings. We maintain a two-level page table tree, much like
70 * that used by the i386, for the sake of the Linux memory management code.
71 * Low-level assembler code in head.S (procedure hash_page) is responsible
72 * for extracting ptes from the tree and putting them into the hash table
73 * when necessary, and updating the accessed and modified bits in the
74 * page table tree.
78 * The PowerPC MPC8xx uses a TLB with hardware assisted, software tablewalk.
79 * We also use the two level tables, but we can put the real bits in them
80 * needed for the TLB and tablewalk. These definitions require Mx_CTR.PPM = 0,
81 * Mx_CTR.PPCS = 0, and MD_CTR.TWAM = 1. The level 2 descriptor has
82 * additional page protection (when Mx_CTR.PPCS = 1) that allows TLB hit
83 * based upon user/super access. The TLB does not have accessed nor write
84 * protect. We assume that if the TLB get loaded with an entry it is
85 * accessed, and overload the changed bit for write protect. We use
86 * two bits in the software pte that are supposed to be set to zero in
87 * the TLB entry (24 and 25) for these indicators. Although the level 1
88 * descriptor contains the guarded and writethrough/copyback bits, we can
89 * set these at the page level since they get copied from the Mx_TWC
90 * register when the TLB entry is loaded. We will use bit 27 for guard, since
91 * that is where it exists in the MD_TWC, and bit 26 for writethrough.
92 * These will get masked from the level 2 descriptor at TLB load time, and
93 * copied to the MD_TWC before it gets loaded.
96 /* PMD_SHIFT determines the size of the area mapped by the second-level page tables */
97 #define PMD_SHIFT 22
98 #define PMD_SIZE (1UL << PMD_SHIFT)
99 #define PMD_MASK (~(PMD_SIZE-1))
101 /* PGDIR_SHIFT determines what a third-level page table entry can map */
102 #define PGDIR_SHIFT 22
103 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
104 #define PGDIR_MASK (~(PGDIR_SIZE-1))
107 * entries per page directory level: our page-table tree is two-level, so
108 * we don't really have any PMD directory.
110 #define PTRS_PER_PTE 1024
111 #define PTRS_PER_PMD 1
112 #define PTRS_PER_PGD 1024
113 #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
115 #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
116 #define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
118 #define pte_ERROR(e) \
119 printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
120 #define pmd_ERROR(e) \
121 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
122 #define pgd_ERROR(e) \
123 printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
126 * Just any arbitrary offset to the start of the vmalloc VM area: the
127 * current 64MB value just means that there will be a 64MB "hole" after the
128 * physical memory until the kernel virtual memory starts. That means that
129 * any out-of-bounds memory accesses will hopefully be caught.
130 * The vmalloc() routines leaves a hole of 4kB between each vmalloced
131 * area for the same reason. ;)
133 * We no longer map larger than phys RAM with the BATs so we don't have
134 * to worry about the VMALLOC_OFFSET causing problems. We do have to worry
135 * about clashes between our early calls to ioremap() that start growing down
136 * from ioremap_base being run into the VM area allocations (growing upwards
137 * from VMALLOC_START). For this reason we have ioremap_bot to check when
138 * we actually run into our mappings setup in the early boot with the VM
139 * system. This really does become a problem for machines with good amounts
140 * of RAM. -- Cort
142 #define VMALLOC_OFFSET (0x1000000) /* 16M */
143 #define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
144 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
145 #define VMALLOC_END ioremap_bot
148 * Bits in a linux-style PTE. These match the bits in the
149 * (hardware-defined) PowerPC PTE as closely as possible.
151 #ifndef CONFIG_8xx
152 /* Definitions for 60x, 740/750, etc. */
153 #define _PAGE_PRESENT 0x001 /* software: pte contains a translation */
154 #define _PAGE_USER 0x002 /* matches one of the PP bits */
155 #define _PAGE_RW 0x004 /* software: user write access allowed */
156 #define _PAGE_GUARDED 0x008
157 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
158 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
159 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
160 #define _PAGE_DIRTY 0x080 /* C: page changed */
161 #define _PAGE_ACCESSED 0x100 /* R: page referenced */
162 #define _PAGE_HWWRITE 0x200 /* software: _PAGE_RW & _PAGE_DIRTY */
163 #define _PAGE_SHARED 0
165 #else
166 /* Definitions for 8xx embedded chips. */
167 #define _PAGE_PRESENT 0x0001 /* Page is valid */
168 #define _PAGE_NO_CACHE 0x0002 /* I: cache inhibit */
169 #define _PAGE_SHARED 0x0004 /* No ASID (context) compare */
171 /* These four software bits must be masked out when the entry is loaded
172 * into the TLB.
174 #define _PAGE_GUARDED 0x0010 /* software: guarded access */
175 #define _PAGE_WRITETHRU 0x0020 /* software: use writethrough cache */
176 #define _PAGE_RW 0x0040 /* software: user write access allowed */
177 #define _PAGE_ACCESSED 0x0080 /* software: page referenced */
179 #define _PAGE_DIRTY 0x0100 /* C: page changed (write protect) */
180 #define _PAGE_USER 0x0800 /* One of the PP bits, the other must be 0 */
182 /* This is used to enable or disable the actual hardware write
183 * protection.
185 #define _PAGE_HWWRITE _PAGE_DIRTY
187 #endif /* CONFIG_8xx */
189 #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
191 #ifdef __SMP__
192 #define _PAGE_BASE _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_COHERENT
193 #else
194 #define _PAGE_BASE _PAGE_PRESENT | _PAGE_ACCESSED
195 #endif
196 #define _PAGE_WRENABLE _PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE
198 #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
200 #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER | \
201 _PAGE_SHARED)
202 #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
203 #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
204 #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED)
205 #define PAGE_KERNEL_CI __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED | \
206 _PAGE_NO_CACHE )
209 * The PowerPC can only do execute protection on a segment (256MB) basis,
210 * not on a page basis. So we consider execute permission the same as read.
211 * Also, write permissions imply read permissions.
212 * This is the closest we can get..
214 #define __P000 PAGE_NONE
215 #define __P001 PAGE_READONLY
216 #define __P010 PAGE_COPY
217 #define __P011 PAGE_COPY
218 #define __P100 PAGE_READONLY
219 #define __P101 PAGE_READONLY
220 #define __P110 PAGE_COPY
221 #define __P111 PAGE_COPY
223 #define __S000 PAGE_NONE
224 #define __S001 PAGE_READONLY
225 #define __S010 PAGE_SHARED
226 #define __S011 PAGE_SHARED
227 #define __S100 PAGE_READONLY
228 #define __S101 PAGE_READONLY
229 #define __S110 PAGE_SHARED
230 #define __S111 PAGE_SHARED
232 #ifndef __ASSEMBLY__
234 * ZERO_PAGE is a global shared page that is always zero: used
235 * for zero-mapped memory areas etc..
237 extern unsigned long empty_zero_page[1024];
238 #define ZERO_PAGE(vaddr) (mem_map + MAP_NR(empty_zero_page))
241 * BAD_PAGETABLE is used when we need a bogus page-table, while
242 * BAD_PAGE is used for a bogus page.
244 * ZERO_PAGE is a global shared page that is always zero: used
245 * for zero-mapped memory areas etc..
247 extern pte_t __bad_page(void);
248 extern pte_t * __bad_pagetable(void);
250 #define BAD_PAGETABLE __bad_pagetable()
251 #define BAD_PAGE __bad_page()
252 #endif /* __ASSEMBLY__ */
254 /* number of bits that fit into a memory pointer */
255 #define BITS_PER_PTR (8*sizeof(unsigned long))
257 /* to align the pointer to a pointer address */
258 #define PTR_MASK (~(sizeof(void*)-1))
260 /* sizeof(void*) == 1<<SIZEOF_PTR_LOG2 */
261 /* 64-bit machines, beware! SRB. */
262 #define SIZEOF_PTR_LOG2 2
264 #define pte_none(pte) (!pte_val(pte))
265 #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
266 #define pte_clear(ptep) do { pte_val(*(ptep)) = 0; } while (0)
267 #define pte_pagenr(x) ((unsigned long)((pte_val(x) >> PAGE_SHIFT)))
269 #define pmd_none(pmd) (!pmd_val(pmd))
270 #define pmd_bad(pmd) ((pmd_val(pmd) & ~PAGE_MASK) != 0)
271 #define pmd_present(pmd) ((pmd_val(pmd) & PAGE_MASK) != 0)
272 #define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0)
275 * Permanent address of a page.
277 #define page_address(page) ({ if (!(page)->virtual) BUG(); (page)->virtual; })
278 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
279 #define pte_page(x) (mem_map+pte_pagenr(x))
281 #ifndef __ASSEMBLY__
283 * The "pgd_xxx()" functions here are trivial for a folded two-level
284 * setup: the pgd is never bad, and a pmd always exists (as it's folded
285 * into the pgd entry)
287 extern inline int pgd_none(pgd_t pgd) { return 0; }
288 extern inline int pgd_bad(pgd_t pgd) { return 0; }
289 extern inline int pgd_present(pgd_t pgd) { return 1; }
290 #define pgd_clear(xp) do { } while (0)
292 #define pgd_page(pgd) \
293 ((unsigned long) __va(pgd_val(pgd) & PAGE_MASK))
296 * The following only work if pte_present() is true.
297 * Undefined behaviour if not..
299 extern inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
300 extern inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
301 extern inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
302 extern inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
303 extern inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
305 extern inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; }
306 extern inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; }
308 extern inline pte_t pte_rdprotect(pte_t pte) {
309 pte_val(pte) &= ~_PAGE_USER; return pte; }
310 extern inline pte_t pte_exprotect(pte_t pte) {
311 pte_val(pte) &= ~_PAGE_USER; return pte; }
312 extern inline pte_t pte_wrprotect(pte_t pte) {
313 pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; }
314 extern inline pte_t pte_mkclean(pte_t pte) {
315 pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; }
316 extern inline pte_t pte_mkold(pte_t pte) {
317 pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
319 extern inline pte_t pte_mkread(pte_t pte) {
320 pte_val(pte) |= _PAGE_USER; return pte; }
321 extern inline pte_t pte_mkexec(pte_t pte) {
322 pte_val(pte) |= _PAGE_USER; return pte; }
323 extern inline pte_t pte_mkwrite(pte_t pte)
325 pte_val(pte) |= _PAGE_RW;
326 if (pte_val(pte) & _PAGE_DIRTY)
327 pte_val(pte) |= _PAGE_HWWRITE;
328 return pte;
330 extern inline pte_t pte_mkdirty(pte_t pte)
332 pte_val(pte) |= _PAGE_DIRTY;
333 if (pte_val(pte) & _PAGE_RW)
334 pte_val(pte) |= _PAGE_HWWRITE;
335 return pte;
337 extern inline pte_t pte_mkyoung(pte_t pte) {
338 pte_val(pte) |= _PAGE_ACCESSED; return pte; }
340 /* Certain architectures need to do special things when pte's
341 * within a page table are directly modified. Thus, the following
342 * hook is made available.
344 #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
347 * Conversion functions: convert a page and protection to a page entry,
348 * and a page entry and page directory to the page they refer to.
351 extern inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
353 pte_t pte;
354 pte_val(pte) = physpage | pgprot_val(pgprot);
355 return pte;
358 #define mk_pte(page,pgprot) \
359 ({ \
360 pte_t pte; \
361 pte_val(pte) = ((page - mem_map) << PAGE_SHIFT) | pgprot_val(pgprot); \
362 pte; \
365 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
367 pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
368 return pte;
371 #define pmd_page(pmd) (pmd_val(pmd))
373 /* to find an entry in a kernel page-table-directory */
374 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
376 /* to find an entry in a page-table-directory */
377 #define pgd_offset(mm, address) ((mm)->pgd + ((address) >> PGDIR_SHIFT))
379 /* Find an entry in the second-level page table.. */
380 extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
382 return (pmd_t *) dir;
385 /* Find an entry in the third-level page table.. */
386 extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
388 return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
391 extern pgd_t swapper_pg_dir[1024];
394 * Page tables may have changed. We don't need to do anything here
395 * as entries are faulted into the hash table by the low-level
396 * data/instruction access exception handlers.
398 #define update_mmu_cache(vma, addr, pte) do { } while (0)
401 * When flushing the tlb entry for a page, we also need to flush the
402 * hash table entry. flush_hash_page is assembler (for speed) in head.S.
404 extern void flush_hash_segments(unsigned low_vsid, unsigned high_vsid);
405 extern void flush_hash_page(unsigned context, unsigned long va);
407 /* Encode and de-code a swap entry */
408 #define SWP_TYPE(entry) (((entry).val >> 1) & 0x3f)
409 #define SWP_OFFSET(entry) ((entry).val >> 8)
410 #define SWP_ENTRY(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) })
411 #define pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
412 #define swp_entry_to_pte(x) ((pte_t) { (x).val })
414 #define module_map vmalloc
415 #define module_unmap vfree
417 /* CONFIG_APUS */
418 /* For virtual address to physical address conversion */
419 extern void cache_clear(__u32 addr, int length);
420 extern void cache_push(__u32 addr, int length);
421 extern int mm_end_of_chunk (unsigned long addr, int len);
422 extern unsigned long iopa(unsigned long addr);
423 extern unsigned long mm_ptov(unsigned long addr) __attribute__ ((const));
425 /* Values for nocacheflag and cmode */
426 /* These are not used by the APUS kernel_map, but prevents
427 compilation errors. */
428 #define KERNELMAP_FULL_CACHING 0
429 #define KERNELMAP_NOCACHE_SER 1
430 #define KERNELMAP_NOCACHE_NONSER 2
431 #define KERNELMAP_NO_COPYBACK 3
434 * Map some physical address range into the kernel address space.
436 extern unsigned long kernel_map(unsigned long paddr, unsigned long size,
437 int nocacheflag, unsigned long *memavailp );
440 * Set cache mode of (kernel space) address range.
442 extern void kernel_set_cachemode (unsigned long address, unsigned long size,
443 unsigned int cmode);
445 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
446 #define PageSkip(page) (0)
447 #define kern_addr_valid(addr) (1)
449 #define io_remap_page_range remap_page_range
452 #endif __ASSEMBLY__
453 #endif /* _PPC_PGTABLE_H */