blob: 5a575f2905f588a248f0d459b1998d4871419ca3 [file] [log] [blame]
David Gibsonf88df142007-04-30 16:30:56 +10001#ifndef _ASM_POWERPC_PGTABLE_PPC64_H_
2#define _ASM_POWERPC_PGTABLE_PPC64_H_
3/*
4 * This file contains the functions and defines necessary to modify and use
5 * the ppc64 hashed page table.
6 */
7
8#ifndef __ASSEMBLY__
9#include <linux/stddef.h>
David Gibsonf88df142007-04-30 16:30:56 +100010#include <asm/tlbflush.h>
David Gibsonf88df142007-04-30 16:30:56 +100011#endif /* __ASSEMBLY__ */
12
13#ifdef CONFIG_PPC_64K_PAGES
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000014#include <asm/pgtable-ppc64-64k.h>
David Gibsonf88df142007-04-30 16:30:56 +100015#else
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000016#include <asm/pgtable-ppc64-4k.h>
David Gibsonf88df142007-04-30 16:30:56 +100017#endif
18
19#define FIRST_USER_ADDRESS 0
20
21/*
22 * Size of EA range mapped by our pagetables.
23 */
24#define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \
25 PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT)
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +100026#define PGTABLE_RANGE (ASM_CONST(1) << PGTABLE_EADDR_SIZE)
David Gibsonf88df142007-04-30 16:30:56 +100027
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000028
29/* Some sanity checking */
David Gibsonf88df142007-04-30 16:30:56 +100030#if TASK_SIZE_USER64 > PGTABLE_RANGE
31#error TASK_SIZE_USER64 exceeds pagetable range
32#endif
33
34#if TASK_SIZE_USER64 > (1UL << (USER_ESID_BITS + SID_SHIFT))
35#error TASK_SIZE_USER64 exceeds user VSID range
36#endif
37
38/*
39 * Define the address range of the vmalloc VM area.
40 */
41#define VMALLOC_START ASM_CONST(0xD000000000000000)
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +100042#define VMALLOC_SIZE (PGTABLE_RANGE >> 1)
David Gibsonf88df142007-04-30 16:30:56 +100043#define VMALLOC_END (VMALLOC_START + VMALLOC_SIZE)
44
45/*
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +100046 * Define the address ranges for MMIO and IO space :
47 *
48 * ISA_IO_BASE = VMALLOC_END, 64K reserved area
49 * PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces
50 * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE
David Gibsonf88df142007-04-30 16:30:56 +100051 */
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +100052#define FULL_IO_SIZE 0x80000000ul
53#define ISA_IO_BASE (VMALLOC_END)
54#define ISA_IO_END (VMALLOC_END + 0x10000ul)
55#define PHB_IO_BASE (ISA_IO_END)
56#define PHB_IO_END (VMALLOC_END + FULL_IO_SIZE)
57#define IOREMAP_BASE (PHB_IO_END)
58#define IOREMAP_END (VMALLOC_START + PGTABLE_RANGE)
David Gibsonf88df142007-04-30 16:30:56 +100059
60/*
61 * Region IDs
62 */
63#define REGION_SHIFT 60UL
64#define REGION_MASK (0xfUL << REGION_SHIFT)
65#define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT)
66
67#define VMALLOC_REGION_ID (REGION_ID(VMALLOC_START))
68#define KERNEL_REGION_ID (REGION_ID(PAGE_OFFSET))
Benjamin Herrenschmidtcec08e72008-04-30 15:41:48 +100069#define VMEMMAP_REGION_ID (0xfUL)
David Gibsonf88df142007-04-30 16:30:56 +100070#define USER_REGION_ID (0UL)
71
72/*
Benjamin Herrenschmidtcec08e72008-04-30 15:41:48 +100073 * Defines the address of the vmemap area, in its own region
Andy Whitcroftd29eff72007-10-16 01:24:17 -070074 */
Benjamin Herrenschmidtcec08e72008-04-30 15:41:48 +100075#define VMEMMAP_BASE (VMEMMAP_REGION_ID << REGION_SHIFT)
76#define vmemmap ((struct page *)VMEMMAP_BASE)
77
Andy Whitcroftd29eff72007-10-16 01:24:17 -070078
79/*
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000080 * Include the PTE bits definitions
David Gibsonf88df142007-04-30 16:30:56 +100081 */
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000082#include <asm/pte-hash64.h>
David Gibsonf88df142007-04-30 16:30:56 +100083
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000084/* Some other useful definitions */
85#define PTE_RPN_MAX (1UL << (64 - PTE_RPN_SHIFT))
86#define PTE_RPN_MASK (~((1UL<<PTE_RPN_SHIFT)-1))
David Gibsonf88df142007-04-30 16:30:56 +100087
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000088/* _PAGE_CHG_MASK masks of bits that are to be preserved accross
89 * pgprot changes
90 */
91#define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
92 _PAGE_ACCESSED | _PAGE_SPECIAL)
93
Benjamin Herrenschmidt8d1cf342009-03-19 19:34:08 +000094#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
95#define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +000096
David Gibsonf88df142007-04-30 16:30:56 +100097
Benjamin Herrenschmidt8d1cf342009-03-19 19:34:08 +000098/* Permission masks used to generate the __P and __S table,
99 *
100 * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
101 */
102#define PAGE_NONE __pgprot(_PAGE_BASE)
103#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
104#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
David Gibsonf88df142007-04-30 16:30:56 +1000105#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
106#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
107#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
108#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
David Gibsonf88df142007-04-30 16:30:56 +1000109
Benjamin Herrenschmidt8d1cf342009-03-19 19:34:08 +0000110/* Permission masks used for kernel mappings */
111#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
112#define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
113 _PAGE_NO_CACHE)
114#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
115 _PAGE_NO_CACHE | _PAGE_GUARDED)
116#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW | _PAGE_EXEC)
117#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
118#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO | _PAGE_EXEC)
119
120/* Protection bits for use by pte_pgprot() */
121#define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | \
122 _PAGE_NO_CACHE | _PAGE_WRITETHRU | \
123 _PAGE_4K_PFN | _PAGE_USER | _PAGE_RW | \
124 _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_EXEC)
125
David Gibsonf88df142007-04-30 16:30:56 +1000126
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +0000127/* We always have _PAGE_SPECIAL on 64 bit */
128#define __HAVE_ARCH_PTE_SPECIAL
David Gibsonf88df142007-04-30 16:30:56 +1000129
Benjamin Herrenschmidt8d1cf342009-03-19 19:34:08 +0000130/* Make modules code happy. We don't set RO yet */
131#define PAGE_KERNEL_EXEC PAGE_KERNEL_X
David Gibsonf88df142007-04-30 16:30:56 +1000132
133/*
134 * POWER4 and newer have per page execute protection, older chips can only
135 * do this on a segment (256MB) basis.
136 *
137 * Also, write permissions imply read permissions.
138 * This is the closest we can get..
139 *
140 * Note due to the way vm flags are laid out, the bits are XWR
141 */
142#define __P000 PAGE_NONE
143#define __P001 PAGE_READONLY
144#define __P010 PAGE_COPY
145#define __P011 PAGE_COPY
146#define __P100 PAGE_READONLY_X
147#define __P101 PAGE_READONLY_X
148#define __P110 PAGE_COPY_X
149#define __P111 PAGE_COPY_X
150
151#define __S000 PAGE_NONE
152#define __S001 PAGE_READONLY
153#define __S010 PAGE_SHARED
154#define __S011 PAGE_SHARED
155#define __S100 PAGE_READONLY_X
156#define __S101 PAGE_READONLY_X
157#define __S110 PAGE_SHARED_X
158#define __S111 PAGE_SHARED_X
159
Benjamin Herrenschmidt94ee8152008-09-03 13:12:05 +1000160#ifdef CONFIG_PPC_MM_SLICES
David Gibsonf88df142007-04-30 16:30:56 +1000161#define HAVE_ARCH_UNMAPPED_AREA
162#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
Benjamin Herrenschmidt94ee8152008-09-03 13:12:05 +1000163#endif /* CONFIG_PPC_MM_SLICES */
David Gibsonf88df142007-04-30 16:30:56 +1000164
165#ifndef __ASSEMBLY__
166
167/*
Benjamin Herrenschmidtc6057822009-03-10 17:53:29 +0000168 * This is the default implementation of various PTE accessors, it's
169 * used in all cases except Book3S with 64K pages where we have a
170 * concept of sub-pages
171 */
172#ifndef __real_pte
173
174#ifdef STRICT_MM_TYPECHECKS
175#define __real_pte(e,p) ((real_pte_t){(e)})
176#define __rpte_to_pte(r) ((r).pte)
177#else
178#define __real_pte(e,p) (e)
179#define __rpte_to_pte(r) (__pte(r))
180#endif
181#define __rpte_to_hidx(r,index) (pte_val(__rpte_to_pte(r)) >> 12)
182
183#define pte_iterate_hashed_subpages(rpte, psize, va, index, shift) \
184 do { \
185 index = 0; \
186 shift = mmu_psize_defs[psize].shift; \
187
188#define pte_iterate_hashed_end() } while(0)
189
190#ifdef CONFIG_PPC_HAS_HASH_64K
191#define pte_pagesize_index(mm, addr, pte) get_slice_psize(mm, addr)
192#else
193#define pte_pagesize_index(mm, addr, pte) MMU_PAGE_4K
194#endif
195
196#endif /* __real_pte */
197
198
199/*
David Gibsonf88df142007-04-30 16:30:56 +1000200 * Conversion functions: convert a page and protection to a page entry,
201 * and a page entry and page directory to the page they refer to.
202 *
203 * mk_pte takes a (struct page *) as input
204 */
205#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
206
207static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
208{
209 pte_t pte;
210
211
212 pte_val(pte) = (pfn << PTE_RPN_SHIFT) | pgprot_val(pgprot);
213 return pte;
214}
215
216#define pte_modify(_pte, newprot) \
217 (__pte((pte_val(_pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)))
218
219#define pte_none(pte) ((pte_val(pte) & ~_PAGE_HPTEFLAGS) == 0)
220#define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
221
222/* pte_clear moved to later in this file */
223
224#define pte_pfn(x) ((unsigned long)((pte_val(x)>>PTE_RPN_SHIFT)))
225#define pte_page(x) pfn_to_page(pte_pfn(x))
226
227#define PMD_BAD_BITS (PTE_TABLE_SIZE-1)
228#define PUD_BAD_BITS (PMD_TABLE_SIZE-1)
229
230#define pmd_set(pmdp, pmdval) (pmd_val(*(pmdp)) = (pmdval))
231#define pmd_none(pmd) (!pmd_val(pmd))
232#define pmd_bad(pmd) (!is_kernel_addr(pmd_val(pmd)) \
233 || (pmd_val(pmd) & PMD_BAD_BITS))
234#define pmd_present(pmd) (pmd_val(pmd) != 0)
235#define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0)
236#define pmd_page_vaddr(pmd) (pmd_val(pmd) & ~PMD_MASKED_BITS)
237#define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd))
238
239#define pud_set(pudp, pudval) (pud_val(*(pudp)) = (pudval))
240#define pud_none(pud) (!pud_val(pud))
241#define pud_bad(pud) (!is_kernel_addr(pud_val(pud)) \
242 || (pud_val(pud) & PUD_BAD_BITS))
243#define pud_present(pud) (pud_val(pud) != 0)
244#define pud_clear(pudp) (pud_val(*(pudp)) = 0)
245#define pud_page_vaddr(pud) (pud_val(pud) & ~PUD_MASKED_BITS)
246#define pud_page(pud) virt_to_page(pud_page_vaddr(pud))
247
248#define pgd_set(pgdp, pudp) ({pgd_val(*(pgdp)) = (unsigned long)(pudp);})
249
250/*
251 * Find an entry in a page-table-directory. We combine the address region
252 * (the high order N bits) and the pgd portion of the address.
253 */
254/* to avoid overflow in free_pgtables we don't use PTRS_PER_PGD here */
255#define pgd_index(address) (((address) >> (PGDIR_SHIFT)) & 0x1ff)
256
257#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
258
259#define pmd_offset(pudp,addr) \
260 (((pmd_t *) pud_page_vaddr(*(pudp))) + (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)))
261
262#define pte_offset_kernel(dir,addr) \
263 (((pte_t *) pmd_page_vaddr(*(dir))) + (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
264
265#define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
266#define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr))
267#define pte_unmap(pte) do { } while(0)
268#define pte_unmap_nested(pte) do { } while(0)
269
270/* to find an entry in a kernel page-table-directory */
271/* This now only contains the vmalloc pages */
272#define pgd_offset_k(address) pgd_offset(&init_mm, address)
273
274/*
275 * The following only work if pte_present() is true.
276 * Undefined behaviour if not..
277 */
David Gibsonf88df142007-04-30 16:30:56 +1000278static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW;}
David Gibsonf88df142007-04-30 16:30:56 +1000279static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY;}
280static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED;}
281static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE;}
Nick Piggin83ac6a12008-07-27 20:28:03 -0700282static inline int pte_special(pte_t pte) { return pte_val(pte) & _PAGE_SPECIAL; }
David Gibsonf88df142007-04-30 16:30:56 +1000283
David Gibsonf88df142007-04-30 16:30:56 +1000284static inline pte_t pte_wrprotect(pte_t pte) {
285 pte_val(pte) &= ~(_PAGE_RW); return pte; }
286static inline pte_t pte_mkclean(pte_t pte) {
287 pte_val(pte) &= ~(_PAGE_DIRTY); return pte; }
288static inline pte_t pte_mkold(pte_t pte) {
289 pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
David Gibsonf88df142007-04-30 16:30:56 +1000290static inline pte_t pte_mkwrite(pte_t pte) {
291 pte_val(pte) |= _PAGE_RW; return pte; }
292static inline pte_t pte_mkdirty(pte_t pte) {
293 pte_val(pte) |= _PAGE_DIRTY; return pte; }
294static inline pte_t pte_mkyoung(pte_t pte) {
295 pte_val(pte) |= _PAGE_ACCESSED; return pte; }
296static inline pte_t pte_mkhuge(pte_t pte) {
297 return pte; }
Nick Piggin7e675132008-04-28 02:13:00 -0700298static inline pte_t pte_mkspecial(pte_t pte) {
Nick Piggin83ac6a12008-07-27 20:28:03 -0700299 pte_val(pte) |= _PAGE_SPECIAL; return pte; }
David Gibsonf5ea64d2008-10-12 17:54:24 +0000300static inline pgprot_t pte_pgprot(pte_t pte)
Benjamin Herrenschmidta1f242f2008-07-23 21:27:08 -0700301{
David Gibsonf5ea64d2008-10-12 17:54:24 +0000302 return __pgprot(pte_val(pte) & PAGE_PROT_BITS);
Benjamin Herrenschmidta1f242f2008-07-23 21:27:08 -0700303}
David Gibsonf88df142007-04-30 16:30:56 +1000304
305/* Atomic PTE updates */
306static inline unsigned long pte_update(struct mm_struct *mm,
307 unsigned long addr,
308 pte_t *ptep, unsigned long clr,
309 int huge)
310{
311 unsigned long old, tmp;
312
313 __asm__ __volatile__(
314 "1: ldarx %0,0,%3 # pte_update\n\
315 andi. %1,%0,%6\n\
316 bne- 1b \n\
317 andc %1,%0,%4 \n\
318 stdcx. %1,0,%3 \n\
319 bne- 1b"
320 : "=&r" (old), "=&r" (tmp), "=m" (*ptep)
321 : "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY)
322 : "cc" );
323
Benjamin Herrenschmidt8d30c142009-02-10 16:02:37 +0000324 /* huge pages use the old page table lock */
325 if (!huge)
326 assert_pte_locked(mm, addr);
327
David Gibsonf88df142007-04-30 16:30:56 +1000328 if (old & _PAGE_HASHPTE)
329 hpte_need_flush(mm, addr, ptep, old, huge);
330 return old;
331}
332
333static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
334 unsigned long addr, pte_t *ptep)
335{
336 unsigned long old;
337
338 if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
339 return 0;
340 old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0);
341 return (old & _PAGE_ACCESSED) != 0;
342}
343#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
344#define ptep_test_and_clear_young(__vma, __addr, __ptep) \
345({ \
346 int __r; \
347 __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
348 __r; \
349})
350
David Gibsonf88df142007-04-30 16:30:56 +1000351#define __HAVE_ARCH_PTEP_SET_WRPROTECT
352static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
353 pte_t *ptep)
354{
355 unsigned long old;
356
357 if ((pte_val(*ptep) & _PAGE_RW) == 0)
358 return;
359 old = pte_update(mm, addr, ptep, _PAGE_RW, 0);
360}
361
Andy Whitcroft016b33c2008-06-26 19:55:58 +1000362static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
363 unsigned long addr, pte_t *ptep)
364{
365 unsigned long old;
366
David Gibson86df8642008-07-08 15:58:16 +1000367 if ((pte_val(*ptep) & _PAGE_RW) == 0)
368 return;
Andy Whitcroft016b33c2008-06-26 19:55:58 +1000369 old = pte_update(mm, addr, ptep, _PAGE_RW, 1);
370}
David Gibsonf88df142007-04-30 16:30:56 +1000371
372/*
373 * We currently remove entries from the hashtable regardless of whether
374 * the entry was young or dirty. The generic routines only flush if the
375 * entry was young or dirty which is not good enough.
376 *
377 * We should be more intelligent about this but for the moment we override
378 * these functions and force a tlb flush unconditionally
379 */
380#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
381#define ptep_clear_flush_young(__vma, __address, __ptep) \
382({ \
383 int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \
384 __ptep); \
385 __young; \
386})
387
David Gibsonf88df142007-04-30 16:30:56 +1000388#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
389static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
390 unsigned long addr, pte_t *ptep)
391{
392 unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0);
393 return __pte(old);
394}
395
396static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
397 pte_t * ptep)
398{
399 pte_update(mm, addr, ptep, ~0UL, 0);
400}
401
David Gibsonf88df142007-04-30 16:30:56 +1000402
403/* Set the dirty and/or accessed bits atomically in a linux PTE, this
404 * function doesn't need to flush the hash entry
405 */
Benjamin Herrenschmidt8d30c142009-02-10 16:02:37 +0000406static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
David Gibsonf88df142007-04-30 16:30:56 +1000407{
408 unsigned long bits = pte_val(entry) &
Benjamin Herrenschmidt8d1cf342009-03-19 19:34:08 +0000409 (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW |
410 _PAGE_EXEC | _PAGE_HWEXEC);
David Gibsonf88df142007-04-30 16:30:56 +1000411 unsigned long old, tmp;
412
413 __asm__ __volatile__(
414 "1: ldarx %0,0,%4\n\
415 andi. %1,%0,%6\n\
416 bne- 1b \n\
417 or %0,%3,%0\n\
418 stdcx. %0,0,%4\n\
419 bne- 1b"
420 :"=&r" (old), "=&r" (tmp), "=m" (*ptep)
421 :"r" (bits), "r" (ptep), "m" (*ptep), "i" (_PAGE_BUSY)
422 :"cc");
423}
David Gibsonf88df142007-04-30 16:30:56 +1000424
David Gibsonf88df142007-04-30 16:30:56 +1000425#define __HAVE_ARCH_PTE_SAME
426#define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0)
427
428#define pte_ERROR(e) \
429 printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
430#define pmd_ERROR(e) \
431 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
432#define pgd_ERROR(e) \
433 printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
434
David Gibsonf88df142007-04-30 16:30:56 +1000435/* Encode and de-code a swap entry */
436#define __swp_type(entry) (((entry).val >> 1) & 0x3f)
437#define __swp_offset(entry) ((entry).val >> 8)
438#define __swp_entry(type, offset) ((swp_entry_t){((type)<< 1)|((offset)<<8)})
439#define __pte_to_swp_entry(pte) ((swp_entry_t){pte_val(pte) >> PTE_RPN_SHIFT})
440#define __swp_entry_to_pte(x) ((pte_t) { (x).val << PTE_RPN_SHIFT })
441#define pte_to_pgoff(pte) (pte_val(pte) >> PTE_RPN_SHIFT)
442#define pgoff_to_pte(off) ((pte_t) {((off) << PTE_RPN_SHIFT)|_PAGE_FILE})
443#define PTE_FILE_MAX_BITS (BITS_PER_LONG - PTE_RPN_SHIFT)
444
David Gibsonf88df142007-04-30 16:30:56 +1000445void pgtable_cache_init(void);
446
447/*
448 * find_linux_pte returns the address of a linux pte for a given
449 * effective address and directory. If not found, it returns zero.
450 */static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea)
451{
452 pgd_t *pg;
453 pud_t *pu;
454 pmd_t *pm;
455 pte_t *pt = NULL;
456
457 pg = pgdir + pgd_index(ea);
458 if (!pgd_none(*pg)) {
459 pu = pud_offset(pg, ea);
460 if (!pud_none(*pu)) {
461 pm = pmd_offset(pu, ea);
462 if (pmd_present(*pm))
463 pt = pte_offset_kernel(pm, ea);
464 }
465 }
466 return pt;
467}
468
Nick Piggince0ad7f2008-07-30 15:23:13 +1000469pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long address);
470
David Gibsonf88df142007-04-30 16:30:56 +1000471#endif /* __ASSEMBLY__ */
472
473#endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */