Commit b74d0bd53406c23636707565d87ddaa55d315b26

Authored by Andrew Morton
Committed by Paul Mackerras
1 parent 40193713df

[PATCH] ppc64: four level pagetables fix

With CONFIG_HUGETLB_PAGE=n:

In file included from kernel/sysctl.c:37:
include/linux/hugetlb.h:104:1: warning: "hugetlb_free_pgd_range" redefined
In file included from include/linux/mm.h:36,
                 from kernel/sysctl.c:23:
include/asm/pgtable.h:492:1: warning: this is the location of the previous definition

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>

Showing 1 changed file with 2 additions and 0 deletions Inline Diff

include/asm-ppc64/pgtable.h
1 #ifndef _PPC64_PGTABLE_H 1 #ifndef _PPC64_PGTABLE_H
2 #define _PPC64_PGTABLE_H 2 #define _PPC64_PGTABLE_H
3 3
4 /* 4 /*
5 * This file contains the functions and defines necessary to modify and use 5 * This file contains the functions and defines necessary to modify and use
6 * the ppc64 hashed page table. 6 * the ppc64 hashed page table.
7 */ 7 */
8 8
9 #ifndef __ASSEMBLY__ 9 #ifndef __ASSEMBLY__
10 #include <linux/config.h> 10 #include <linux/config.h>
11 #include <linux/stddef.h> 11 #include <linux/stddef.h>
12 #include <asm/processor.h> /* For TASK_SIZE */ 12 #include <asm/processor.h> /* For TASK_SIZE */
13 #include <asm/mmu.h> 13 #include <asm/mmu.h>
14 #include <asm/page.h> 14 #include <asm/page.h>
15 #include <asm/tlbflush.h> 15 #include <asm/tlbflush.h>
16 #endif /* __ASSEMBLY__ */ 16 #endif /* __ASSEMBLY__ */
17 17
18 /* 18 /*
19 * Entries per page directory level. The PTE level must use a 64b record 19 * Entries per page directory level. The PTE level must use a 64b record
20 * for each page table entry. The PMD and PGD level use a 32b record for 20 * for each page table entry. The PMD and PGD level use a 32b record for
21 * each entry by assuming that each entry is page aligned. 21 * each entry by assuming that each entry is page aligned.
22 */ 22 */
23 #define PTE_INDEX_SIZE 9 23 #define PTE_INDEX_SIZE 9
24 #define PMD_INDEX_SIZE 7 24 #define PMD_INDEX_SIZE 7
25 #define PUD_INDEX_SIZE 7 25 #define PUD_INDEX_SIZE 7
26 #define PGD_INDEX_SIZE 9 26 #define PGD_INDEX_SIZE 9
27 27
28 #define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE) 28 #define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE)
29 #define PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE) 29 #define PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE)
30 #define PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE) 30 #define PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE)
31 #define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE) 31 #define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE)
32 32
33 #define PTRS_PER_PTE (1 << PTE_INDEX_SIZE) 33 #define PTRS_PER_PTE (1 << PTE_INDEX_SIZE)
34 #define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) 34 #define PTRS_PER_PMD (1 << PMD_INDEX_SIZE)
35 #define PTRS_PER_PUD (1 << PMD_INDEX_SIZE) 35 #define PTRS_PER_PUD (1 << PMD_INDEX_SIZE)
36 #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) 36 #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE)
37 37
38 /* PMD_SHIFT determines what a second-level page table entry can map */ 38 /* PMD_SHIFT determines what a second-level page table entry can map */
39 #define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE) 39 #define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE)
40 #define PMD_SIZE (1UL << PMD_SHIFT) 40 #define PMD_SIZE (1UL << PMD_SHIFT)
41 #define PMD_MASK (~(PMD_SIZE-1)) 41 #define PMD_MASK (~(PMD_SIZE-1))
42 42
43 /* PUD_SHIFT determines what a third-level page table entry can map */ 43 /* PUD_SHIFT determines what a third-level page table entry can map */
44 #define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE) 44 #define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE)
45 #define PUD_SIZE (1UL << PUD_SHIFT) 45 #define PUD_SIZE (1UL << PUD_SHIFT)
46 #define PUD_MASK (~(PUD_SIZE-1)) 46 #define PUD_MASK (~(PUD_SIZE-1))
47 47
48 /* PGDIR_SHIFT determines what a fourth-level page table entry can map */ 48 /* PGDIR_SHIFT determines what a fourth-level page table entry can map */
49 #define PGDIR_SHIFT (PUD_SHIFT + PUD_INDEX_SIZE) 49 #define PGDIR_SHIFT (PUD_SHIFT + PUD_INDEX_SIZE)
50 #define PGDIR_SIZE (1UL << PGDIR_SHIFT) 50 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
51 #define PGDIR_MASK (~(PGDIR_SIZE-1)) 51 #define PGDIR_MASK (~(PGDIR_SIZE-1))
52 52
53 #define FIRST_USER_ADDRESS 0 53 #define FIRST_USER_ADDRESS 0
54 54
55 /* 55 /*
56 * Size of EA range mapped by our pagetables. 56 * Size of EA range mapped by our pagetables.
57 */ 57 */
58 #define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \ 58 #define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \
59 PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT) 59 PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT)
60 #define PGTABLE_RANGE (1UL << PGTABLE_EADDR_SIZE) 60 #define PGTABLE_RANGE (1UL << PGTABLE_EADDR_SIZE)
61 61
62 #if TASK_SIZE_USER64 > PGTABLE_RANGE 62 #if TASK_SIZE_USER64 > PGTABLE_RANGE
63 #error TASK_SIZE_USER64 exceeds pagetable range 63 #error TASK_SIZE_USER64 exceeds pagetable range
64 #endif 64 #endif
65 65
66 #if TASK_SIZE_USER64 > (1UL << (USER_ESID_BITS + SID_SHIFT)) 66 #if TASK_SIZE_USER64 > (1UL << (USER_ESID_BITS + SID_SHIFT))
67 #error TASK_SIZE_USER64 exceeds user VSID range 67 #error TASK_SIZE_USER64 exceeds user VSID range
68 #endif 68 #endif
69 69
70 /* 70 /*
71 * Define the address range of the vmalloc VM area. 71 * Define the address range of the vmalloc VM area.
72 */ 72 */
73 #define VMALLOC_START (0xD000000000000000ul) 73 #define VMALLOC_START (0xD000000000000000ul)
74 #define VMALLOC_SIZE (0x80000000000UL) 74 #define VMALLOC_SIZE (0x80000000000UL)
75 #define VMALLOC_END (VMALLOC_START + VMALLOC_SIZE) 75 #define VMALLOC_END (VMALLOC_START + VMALLOC_SIZE)
76 76
77 /* 77 /*
78 * Bits in a linux-style PTE. These match the bits in the 78 * Bits in a linux-style PTE. These match the bits in the
79 * (hardware-defined) PowerPC PTE as closely as possible. 79 * (hardware-defined) PowerPC PTE as closely as possible.
80 */ 80 */
81 #define _PAGE_PRESENT 0x0001 /* software: pte contains a translation */ 81 #define _PAGE_PRESENT 0x0001 /* software: pte contains a translation */
82 #define _PAGE_USER 0x0002 /* matches one of the PP bits */ 82 #define _PAGE_USER 0x0002 /* matches one of the PP bits */
83 #define _PAGE_FILE 0x0002 /* (!present only) software: pte holds file offset */ 83 #define _PAGE_FILE 0x0002 /* (!present only) software: pte holds file offset */
84 #define _PAGE_EXEC 0x0004 /* No execute on POWER4 and newer (we invert) */ 84 #define _PAGE_EXEC 0x0004 /* No execute on POWER4 and newer (we invert) */
85 #define _PAGE_GUARDED 0x0008 85 #define _PAGE_GUARDED 0x0008
86 #define _PAGE_COHERENT 0x0010 /* M: enforce memory coherence (SMP systems) */ 86 #define _PAGE_COHERENT 0x0010 /* M: enforce memory coherence (SMP systems) */
87 #define _PAGE_NO_CACHE 0x0020 /* I: cache inhibit */ 87 #define _PAGE_NO_CACHE 0x0020 /* I: cache inhibit */
88 #define _PAGE_WRITETHRU 0x0040 /* W: cache write-through */ 88 #define _PAGE_WRITETHRU 0x0040 /* W: cache write-through */
89 #define _PAGE_DIRTY 0x0080 /* C: page changed */ 89 #define _PAGE_DIRTY 0x0080 /* C: page changed */
90 #define _PAGE_ACCESSED 0x0100 /* R: page referenced */ 90 #define _PAGE_ACCESSED 0x0100 /* R: page referenced */
91 #define _PAGE_RW 0x0200 /* software: user write access allowed */ 91 #define _PAGE_RW 0x0200 /* software: user write access allowed */
92 #define _PAGE_HASHPTE 0x0400 /* software: pte has an associated HPTE */ 92 #define _PAGE_HASHPTE 0x0400 /* software: pte has an associated HPTE */
93 #define _PAGE_BUSY 0x0800 /* software: PTE & hash are busy */ 93 #define _PAGE_BUSY 0x0800 /* software: PTE & hash are busy */
94 #define _PAGE_SECONDARY 0x8000 /* software: HPTE is in secondary group */ 94 #define _PAGE_SECONDARY 0x8000 /* software: HPTE is in secondary group */
95 #define _PAGE_GROUP_IX 0x7000 /* software: HPTE index within group */ 95 #define _PAGE_GROUP_IX 0x7000 /* software: HPTE index within group */
96 #define _PAGE_HUGE 0x10000 /* 16MB page */ 96 #define _PAGE_HUGE 0x10000 /* 16MB page */
97 /* Bits 0x7000 identify the index within an HPT Group */ 97 /* Bits 0x7000 identify the index within an HPT Group */
98 #define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | _PAGE_SECONDARY | _PAGE_GROUP_IX) 98 #define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | _PAGE_SECONDARY | _PAGE_GROUP_IX)
99 /* PAGE_MASK gives the right answer below, but only by accident */ 99 /* PAGE_MASK gives the right answer below, but only by accident */
100 /* It should be preserving the high 48 bits and then specifically */ 100 /* It should be preserving the high 48 bits and then specifically */
101 /* preserving _PAGE_SECONDARY | _PAGE_GROUP_IX */ 101 /* preserving _PAGE_SECONDARY | _PAGE_GROUP_IX */
102 #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_HPTEFLAGS) 102 #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_HPTEFLAGS)
103 103
104 #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_COHERENT) 104 #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_COHERENT)
105 105
106 #define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY) 106 #define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY)
107 107
108 /* __pgprot defined in asm-ppc64/page.h */ 108 /* __pgprot defined in asm-ppc64/page.h */
109 #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED) 109 #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
110 110
111 #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER) 111 #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER)
112 #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER | _PAGE_EXEC) 112 #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER | _PAGE_EXEC)
113 #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER) 113 #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
114 #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 114 #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
115 #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER) 115 #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
116 #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 116 #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
117 #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_WRENABLE) 117 #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_WRENABLE)
118 #define PAGE_KERNEL_CI __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 118 #define PAGE_KERNEL_CI __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \
119 _PAGE_WRENABLE | _PAGE_NO_CACHE | _PAGE_GUARDED) 119 _PAGE_WRENABLE | _PAGE_NO_CACHE | _PAGE_GUARDED)
120 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_EXEC) 120 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_EXEC)
121 121
122 #define PAGE_AGP __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_NO_CACHE) 122 #define PAGE_AGP __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_NO_CACHE)
123 #define HAVE_PAGE_AGP 123 #define HAVE_PAGE_AGP
124 124
125 /* 125 /*
126 * This bit in a hardware PTE indicates that the page is *not* executable. 126 * This bit in a hardware PTE indicates that the page is *not* executable.
127 */ 127 */
128 #define HW_NO_EXEC _PAGE_EXEC 128 #define HW_NO_EXEC _PAGE_EXEC
129 129
130 /* 130 /*
131 * POWER4 and newer have per page execute protection, older chips can only 131 * POWER4 and newer have per page execute protection, older chips can only
132 * do this on a segment (256MB) basis. 132 * do this on a segment (256MB) basis.
133 * 133 *
134 * Also, write permissions imply read permissions. 134 * Also, write permissions imply read permissions.
135 * This is the closest we can get.. 135 * This is the closest we can get..
136 * 136 *
137 * Note due to the way vm flags are laid out, the bits are XWR 137 * Note due to the way vm flags are laid out, the bits are XWR
138 */ 138 */
139 #define __P000 PAGE_NONE 139 #define __P000 PAGE_NONE
140 #define __P001 PAGE_READONLY 140 #define __P001 PAGE_READONLY
141 #define __P010 PAGE_COPY 141 #define __P010 PAGE_COPY
142 #define __P011 PAGE_COPY 142 #define __P011 PAGE_COPY
143 #define __P100 PAGE_READONLY_X 143 #define __P100 PAGE_READONLY_X
144 #define __P101 PAGE_READONLY_X 144 #define __P101 PAGE_READONLY_X
145 #define __P110 PAGE_COPY_X 145 #define __P110 PAGE_COPY_X
146 #define __P111 PAGE_COPY_X 146 #define __P111 PAGE_COPY_X
147 147
148 #define __S000 PAGE_NONE 148 #define __S000 PAGE_NONE
149 #define __S001 PAGE_READONLY 149 #define __S001 PAGE_READONLY
150 #define __S010 PAGE_SHARED 150 #define __S010 PAGE_SHARED
151 #define __S011 PAGE_SHARED 151 #define __S011 PAGE_SHARED
152 #define __S100 PAGE_READONLY_X 152 #define __S100 PAGE_READONLY_X
153 #define __S101 PAGE_READONLY_X 153 #define __S101 PAGE_READONLY_X
154 #define __S110 PAGE_SHARED_X 154 #define __S110 PAGE_SHARED_X
155 #define __S111 PAGE_SHARED_X 155 #define __S111 PAGE_SHARED_X
156 156
157 #ifndef __ASSEMBLY__ 157 #ifndef __ASSEMBLY__
158 158
159 /* 159 /*
160 * ZERO_PAGE is a global shared page that is always zero: used 160 * ZERO_PAGE is a global shared page that is always zero: used
161 * for zero-mapped memory areas etc.. 161 * for zero-mapped memory areas etc..
162 */ 162 */
163 extern unsigned long empty_zero_page[PAGE_SIZE/sizeof(unsigned long)]; 163 extern unsigned long empty_zero_page[PAGE_SIZE/sizeof(unsigned long)];
164 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) 164 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
165 #endif /* __ASSEMBLY__ */ 165 #endif /* __ASSEMBLY__ */
166 166
167 /* shift to put page number into pte */ 167 /* shift to put page number into pte */
168 #define PTE_SHIFT (17) 168 #define PTE_SHIFT (17)
169 169
170 #ifdef CONFIG_HUGETLB_PAGE 170 #ifdef CONFIG_HUGETLB_PAGE
171 171
172 #ifndef __ASSEMBLY__ 172 #ifndef __ASSEMBLY__
173 int hash_huge_page(struct mm_struct *mm, unsigned long access, 173 int hash_huge_page(struct mm_struct *mm, unsigned long access,
174 unsigned long ea, unsigned long vsid, int local); 174 unsigned long ea, unsigned long vsid, int local);
175 #endif /* __ASSEMBLY__ */ 175 #endif /* __ASSEMBLY__ */
176 176
177 #define HAVE_ARCH_UNMAPPED_AREA 177 #define HAVE_ARCH_UNMAPPED_AREA
178 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN 178 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
179 #else 179 #else
180 180
181 #define hash_huge_page(mm,a,ea,vsid,local) -1 181 #define hash_huge_page(mm,a,ea,vsid,local) -1
182 182
183 #endif 183 #endif
184 184
185 #ifndef __ASSEMBLY__ 185 #ifndef __ASSEMBLY__
186 186
187 /* 187 /*
188 * Conversion functions: convert a page and protection to a page entry, 188 * Conversion functions: convert a page and protection to a page entry,
189 * and a page entry and page directory to the page they refer to. 189 * and a page entry and page directory to the page they refer to.
190 * 190 *
191 * mk_pte takes a (struct page *) as input 191 * mk_pte takes a (struct page *) as input
192 */ 192 */
193 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) 193 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
194 194
195 static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) 195 static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
196 { 196 {
197 pte_t pte; 197 pte_t pte;
198 198
199 199
200 pte_val(pte) = (pfn << PTE_SHIFT) | pgprot_val(pgprot); 200 pte_val(pte) = (pfn << PTE_SHIFT) | pgprot_val(pgprot);
201 return pte; 201 return pte;
202 } 202 }
203 203
204 #define pte_modify(_pte, newprot) \ 204 #define pte_modify(_pte, newprot) \
205 (__pte((pte_val(_pte) & _PAGE_CHG_MASK) | pgprot_val(newprot))) 205 (__pte((pte_val(_pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)))
206 206
207 #define pte_none(pte) ((pte_val(pte) & ~_PAGE_HPTEFLAGS) == 0) 207 #define pte_none(pte) ((pte_val(pte) & ~_PAGE_HPTEFLAGS) == 0)
208 #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT) 208 #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
209 209
210 /* pte_clear moved to later in this file */ 210 /* pte_clear moved to later in this file */
211 211
212 #define pte_pfn(x) ((unsigned long)((pte_val(x) >> PTE_SHIFT))) 212 #define pte_pfn(x) ((unsigned long)((pte_val(x) >> PTE_SHIFT)))
213 #define pte_page(x) pfn_to_page(pte_pfn(x)) 213 #define pte_page(x) pfn_to_page(pte_pfn(x))
214 214
215 #define pmd_set(pmdp, ptep) ({BUG_ON((u64)ptep < KERNELBASE); pmd_val(*(pmdp)) = (unsigned long)(ptep);}) 215 #define pmd_set(pmdp, ptep) ({BUG_ON((u64)ptep < KERNELBASE); pmd_val(*(pmdp)) = (unsigned long)(ptep);})
216 #define pmd_none(pmd) (!pmd_val(pmd)) 216 #define pmd_none(pmd) (!pmd_val(pmd))
217 #define pmd_bad(pmd) (pmd_val(pmd) == 0) 217 #define pmd_bad(pmd) (pmd_val(pmd) == 0)
218 #define pmd_present(pmd) (pmd_val(pmd) != 0) 218 #define pmd_present(pmd) (pmd_val(pmd) != 0)
219 #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0) 219 #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0)
220 #define pmd_page_kernel(pmd) (pmd_val(pmd)) 220 #define pmd_page_kernel(pmd) (pmd_val(pmd))
221 #define pmd_page(pmd) virt_to_page(pmd_page_kernel(pmd)) 221 #define pmd_page(pmd) virt_to_page(pmd_page_kernel(pmd))
222 222
223 #define pud_set(pudp, pmdp) (pud_val(*(pudp)) = (unsigned long)(pmdp)) 223 #define pud_set(pudp, pmdp) (pud_val(*(pudp)) = (unsigned long)(pmdp))
224 #define pud_none(pud) (!pud_val(pud)) 224 #define pud_none(pud) (!pud_val(pud))
225 #define pud_bad(pud) ((pud_val(pud)) == 0) 225 #define pud_bad(pud) ((pud_val(pud)) == 0)
226 #define pud_present(pud) (pud_val(pud) != 0) 226 #define pud_present(pud) (pud_val(pud) != 0)
227 #define pud_clear(pudp) (pud_val(*(pudp)) = 0) 227 #define pud_clear(pudp) (pud_val(*(pudp)) = 0)
228 #define pud_page(pud) (pud_val(pud)) 228 #define pud_page(pud) (pud_val(pud))
229 229
230 #define pgd_set(pgdp, pudp) ({pgd_val(*(pgdp)) = (unsigned long)(pudp);}) 230 #define pgd_set(pgdp, pudp) ({pgd_val(*(pgdp)) = (unsigned long)(pudp);})
231 #define pgd_none(pgd) (!pgd_val(pgd)) 231 #define pgd_none(pgd) (!pgd_val(pgd))
232 #define pgd_bad(pgd) (pgd_val(pgd) == 0) 232 #define pgd_bad(pgd) (pgd_val(pgd) == 0)
233 #define pgd_present(pgd) (pgd_val(pgd) != 0) 233 #define pgd_present(pgd) (pgd_val(pgd) != 0)
234 #define pgd_clear(pgdp) (pgd_val(*(pgdp)) = 0) 234 #define pgd_clear(pgdp) (pgd_val(*(pgdp)) = 0)
235 #define pgd_page(pgd) (pgd_val(pgd)) 235 #define pgd_page(pgd) (pgd_val(pgd))
236 236
237 /* 237 /*
238 * Find an entry in a page-table-directory. We combine the address region 238 * Find an entry in a page-table-directory. We combine the address region
239 * (the high order N bits) and the pgd portion of the address. 239 * (the high order N bits) and the pgd portion of the address.
240 */ 240 */
241 /* to avoid overflow in free_pgtables we don't use PTRS_PER_PGD here */ 241 /* to avoid overflow in free_pgtables we don't use PTRS_PER_PGD here */
242 #define pgd_index(address) (((address) >> (PGDIR_SHIFT)) & 0x1ff) 242 #define pgd_index(address) (((address) >> (PGDIR_SHIFT)) & 0x1ff)
243 243
244 #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address)) 244 #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
245 245
246 #define pud_offset(pgdp, addr) \ 246 #define pud_offset(pgdp, addr) \
247 (((pud_t *) pgd_page(*(pgdp))) + (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))) 247 (((pud_t *) pgd_page(*(pgdp))) + (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)))
248 248
249 #define pmd_offset(pudp,addr) \ 249 #define pmd_offset(pudp,addr) \
250 (((pmd_t *) pud_page(*(pudp))) + (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))) 250 (((pmd_t *) pud_page(*(pudp))) + (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)))
251 251
252 #define pte_offset_kernel(dir,addr) \ 252 #define pte_offset_kernel(dir,addr) \
253 (((pte_t *) pmd_page_kernel(*(dir))) + (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))) 253 (((pte_t *) pmd_page_kernel(*(dir))) + (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
254 254
255 #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr)) 255 #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
256 #define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr)) 256 #define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr))
257 #define pte_unmap(pte) do { } while(0) 257 #define pte_unmap(pte) do { } while(0)
258 #define pte_unmap_nested(pte) do { } while(0) 258 #define pte_unmap_nested(pte) do { } while(0)
259 259
260 /* to find an entry in a kernel page-table-directory */ 260 /* to find an entry in a kernel page-table-directory */
261 /* This now only contains the vmalloc pages */ 261 /* This now only contains the vmalloc pages */
262 #define pgd_offset_k(address) pgd_offset(&init_mm, address) 262 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
263 263
264 /* 264 /*
265 * The following only work if pte_present() is true. 265 * The following only work if pte_present() is true.
266 * Undefined behaviour if not.. 266 * Undefined behaviour if not..
267 */ 267 */
268 static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER;} 268 static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER;}
269 static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW;} 269 static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW;}
270 static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC;} 270 static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC;}
271 static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY;} 271 static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY;}
272 static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED;} 272 static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED;}
273 static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE;} 273 static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE;}
274 static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE;} 274 static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE;}
275 275
276 static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; } 276 static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; }
277 static inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; } 277 static inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; }
278 278
279 static inline pte_t pte_rdprotect(pte_t pte) { 279 static inline pte_t pte_rdprotect(pte_t pte) {
280 pte_val(pte) &= ~_PAGE_USER; return pte; } 280 pte_val(pte) &= ~_PAGE_USER; return pte; }
281 static inline pte_t pte_exprotect(pte_t pte) { 281 static inline pte_t pte_exprotect(pte_t pte) {
282 pte_val(pte) &= ~_PAGE_EXEC; return pte; } 282 pte_val(pte) &= ~_PAGE_EXEC; return pte; }
283 static inline pte_t pte_wrprotect(pte_t pte) { 283 static inline pte_t pte_wrprotect(pte_t pte) {
284 pte_val(pte) &= ~(_PAGE_RW); return pte; } 284 pte_val(pte) &= ~(_PAGE_RW); return pte; }
285 static inline pte_t pte_mkclean(pte_t pte) { 285 static inline pte_t pte_mkclean(pte_t pte) {
286 pte_val(pte) &= ~(_PAGE_DIRTY); return pte; } 286 pte_val(pte) &= ~(_PAGE_DIRTY); return pte; }
287 static inline pte_t pte_mkold(pte_t pte) { 287 static inline pte_t pte_mkold(pte_t pte) {
288 pte_val(pte) &= ~_PAGE_ACCESSED; return pte; } 288 pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
289 289
290 static inline pte_t pte_mkread(pte_t pte) { 290 static inline pte_t pte_mkread(pte_t pte) {
291 pte_val(pte) |= _PAGE_USER; return pte; } 291 pte_val(pte) |= _PAGE_USER; return pte; }
292 static inline pte_t pte_mkexec(pte_t pte) { 292 static inline pte_t pte_mkexec(pte_t pte) {
293 pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; } 293 pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; }
294 static inline pte_t pte_mkwrite(pte_t pte) { 294 static inline pte_t pte_mkwrite(pte_t pte) {
295 pte_val(pte) |= _PAGE_RW; return pte; } 295 pte_val(pte) |= _PAGE_RW; return pte; }
296 static inline pte_t pte_mkdirty(pte_t pte) { 296 static inline pte_t pte_mkdirty(pte_t pte) {
297 pte_val(pte) |= _PAGE_DIRTY; return pte; } 297 pte_val(pte) |= _PAGE_DIRTY; return pte; }
298 static inline pte_t pte_mkyoung(pte_t pte) { 298 static inline pte_t pte_mkyoung(pte_t pte) {
299 pte_val(pte) |= _PAGE_ACCESSED; return pte; } 299 pte_val(pte) |= _PAGE_ACCESSED; return pte; }
300 static inline pte_t pte_mkhuge(pte_t pte) { 300 static inline pte_t pte_mkhuge(pte_t pte) {
301 pte_val(pte) |= _PAGE_HUGE; return pte; } 301 pte_val(pte) |= _PAGE_HUGE; return pte; }
302 302
303 /* Atomic PTE updates */ 303 /* Atomic PTE updates */
304 static inline unsigned long pte_update(pte_t *p, unsigned long clr) 304 static inline unsigned long pte_update(pte_t *p, unsigned long clr)
305 { 305 {
306 unsigned long old, tmp; 306 unsigned long old, tmp;
307 307
308 __asm__ __volatile__( 308 __asm__ __volatile__(
309 "1: ldarx %0,0,%3 # pte_update\n\ 309 "1: ldarx %0,0,%3 # pte_update\n\
310 andi. %1,%0,%6\n\ 310 andi. %1,%0,%6\n\
311 bne- 1b \n\ 311 bne- 1b \n\
312 andc %1,%0,%4 \n\ 312 andc %1,%0,%4 \n\
313 stdcx. %1,0,%3 \n\ 313 stdcx. %1,0,%3 \n\
314 bne- 1b" 314 bne- 1b"
315 : "=&r" (old), "=&r" (tmp), "=m" (*p) 315 : "=&r" (old), "=&r" (tmp), "=m" (*p)
316 : "r" (p), "r" (clr), "m" (*p), "i" (_PAGE_BUSY) 316 : "r" (p), "r" (clr), "m" (*p), "i" (_PAGE_BUSY)
317 : "cc" ); 317 : "cc" );
318 return old; 318 return old;
319 } 319 }
320 320
321 /* PTE updating functions, this function puts the PTE in the 321 /* PTE updating functions, this function puts the PTE in the
322 * batch, doesn't actually triggers the hash flush immediately, 322 * batch, doesn't actually triggers the hash flush immediately,
323 * you need to call flush_tlb_pending() to do that. 323 * you need to call flush_tlb_pending() to do that.
324 */ 324 */
325 extern void hpte_update(struct mm_struct *mm, unsigned long addr, unsigned long pte, 325 extern void hpte_update(struct mm_struct *mm, unsigned long addr, unsigned long pte,
326 int wrprot); 326 int wrprot);
327 327
328 static inline int __ptep_test_and_clear_young(struct mm_struct *mm, unsigned long addr, pte_t *ptep) 328 static inline int __ptep_test_and_clear_young(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
329 { 329 {
330 unsigned long old; 330 unsigned long old;
331 331
332 if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0) 332 if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
333 return 0; 333 return 0;
334 old = pte_update(ptep, _PAGE_ACCESSED); 334 old = pte_update(ptep, _PAGE_ACCESSED);
335 if (old & _PAGE_HASHPTE) { 335 if (old & _PAGE_HASHPTE) {
336 hpte_update(mm, addr, old, 0); 336 hpte_update(mm, addr, old, 0);
337 flush_tlb_pending(); 337 flush_tlb_pending();
338 } 338 }
339 return (old & _PAGE_ACCESSED) != 0; 339 return (old & _PAGE_ACCESSED) != 0;
340 } 340 }
341 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 341 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
342 #define ptep_test_and_clear_young(__vma, __addr, __ptep) \ 342 #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
343 ({ \ 343 ({ \
344 int __r; \ 344 int __r; \
345 __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \ 345 __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
346 __r; \ 346 __r; \
347 }) 347 })
348 348
349 /* 349 /*
350 * On RW/DIRTY bit transitions we can avoid flushing the hpte. For the 350 * On RW/DIRTY bit transitions we can avoid flushing the hpte. For the
351 * moment we always flush but we need to fix hpte_update and test if the 351 * moment we always flush but we need to fix hpte_update and test if the
352 * optimisation is worth it. 352 * optimisation is worth it.
353 */ 353 */
354 static inline int __ptep_test_and_clear_dirty(struct mm_struct *mm, unsigned long addr, pte_t *ptep) 354 static inline int __ptep_test_and_clear_dirty(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
355 { 355 {
356 unsigned long old; 356 unsigned long old;
357 357
358 if ((pte_val(*ptep) & _PAGE_DIRTY) == 0) 358 if ((pte_val(*ptep) & _PAGE_DIRTY) == 0)
359 return 0; 359 return 0;
360 old = pte_update(ptep, _PAGE_DIRTY); 360 old = pte_update(ptep, _PAGE_DIRTY);
361 if (old & _PAGE_HASHPTE) 361 if (old & _PAGE_HASHPTE)
362 hpte_update(mm, addr, old, 0); 362 hpte_update(mm, addr, old, 0);
363 return (old & _PAGE_DIRTY) != 0; 363 return (old & _PAGE_DIRTY) != 0;
364 } 364 }
365 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY 365 #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
366 #define ptep_test_and_clear_dirty(__vma, __addr, __ptep) \ 366 #define ptep_test_and_clear_dirty(__vma, __addr, __ptep) \
367 ({ \ 367 ({ \
368 int __r; \ 368 int __r; \
369 __r = __ptep_test_and_clear_dirty((__vma)->vm_mm, __addr, __ptep); \ 369 __r = __ptep_test_and_clear_dirty((__vma)->vm_mm, __addr, __ptep); \
370 __r; \ 370 __r; \
371 }) 371 })
372 372
373 #define __HAVE_ARCH_PTEP_SET_WRPROTECT 373 #define __HAVE_ARCH_PTEP_SET_WRPROTECT
374 static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) 374 static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
375 { 375 {
376 unsigned long old; 376 unsigned long old;
377 377
378 if ((pte_val(*ptep) & _PAGE_RW) == 0) 378 if ((pte_val(*ptep) & _PAGE_RW) == 0)
379 return; 379 return;
380 old = pte_update(ptep, _PAGE_RW); 380 old = pte_update(ptep, _PAGE_RW);
381 if (old & _PAGE_HASHPTE) 381 if (old & _PAGE_HASHPTE)
382 hpte_update(mm, addr, old, 0); 382 hpte_update(mm, addr, old, 0);
383 } 383 }
384 384
385 /* 385 /*
386 * We currently remove entries from the hashtable regardless of whether 386 * We currently remove entries from the hashtable regardless of whether
387 * the entry was young or dirty. The generic routines only flush if the 387 * the entry was young or dirty. The generic routines only flush if the
388 * entry was young or dirty which is not good enough. 388 * entry was young or dirty which is not good enough.
389 * 389 *
390 * We should be more intelligent about this but for the moment we override 390 * We should be more intelligent about this but for the moment we override
391 * these functions and force a tlb flush unconditionally 391 * these functions and force a tlb flush unconditionally
392 */ 392 */
393 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH 393 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
394 #define ptep_clear_flush_young(__vma, __address, __ptep) \ 394 #define ptep_clear_flush_young(__vma, __address, __ptep) \
395 ({ \ 395 ({ \
396 int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \ 396 int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \
397 __ptep); \ 397 __ptep); \
398 __young; \ 398 __young; \
399 }) 399 })
400 400
401 #define __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH 401 #define __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH
402 #define ptep_clear_flush_dirty(__vma, __address, __ptep) \ 402 #define ptep_clear_flush_dirty(__vma, __address, __ptep) \
403 ({ \ 403 ({ \
404 int __dirty = __ptep_test_and_clear_dirty((__vma)->vm_mm, __address, \ 404 int __dirty = __ptep_test_and_clear_dirty((__vma)->vm_mm, __address, \
405 __ptep); \ 405 __ptep); \
406 flush_tlb_page(__vma, __address); \ 406 flush_tlb_page(__vma, __address); \
407 __dirty; \ 407 __dirty; \
408 }) 408 })
409 409
410 #define __HAVE_ARCH_PTEP_GET_AND_CLEAR 410 #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
411 static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) 411 static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
412 { 412 {
413 unsigned long old = pte_update(ptep, ~0UL); 413 unsigned long old = pte_update(ptep, ~0UL);
414 414
415 if (old & _PAGE_HASHPTE) 415 if (old & _PAGE_HASHPTE)
416 hpte_update(mm, addr, old, 0); 416 hpte_update(mm, addr, old, 0);
417 return __pte(old); 417 return __pte(old);
418 } 418 }
419 419
420 static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t * ptep) 420 static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t * ptep)
421 { 421 {
422 unsigned long old = pte_update(ptep, ~0UL); 422 unsigned long old = pte_update(ptep, ~0UL);
423 423
424 if (old & _PAGE_HASHPTE) 424 if (old & _PAGE_HASHPTE)
425 hpte_update(mm, addr, old, 0); 425 hpte_update(mm, addr, old, 0);
426 } 426 }
427 427
428 /* 428 /*
429 * set_pte stores a linux PTE into the linux page table. 429 * set_pte stores a linux PTE into the linux page table.
430 */ 430 */
431 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, 431 static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
432 pte_t *ptep, pte_t pte) 432 pte_t *ptep, pte_t pte)
433 { 433 {
434 if (pte_present(*ptep)) { 434 if (pte_present(*ptep)) {
435 pte_clear(mm, addr, ptep); 435 pte_clear(mm, addr, ptep);
436 flush_tlb_pending(); 436 flush_tlb_pending();
437 } 437 }
438 *ptep = __pte(pte_val(pte) & ~_PAGE_HPTEFLAGS); 438 *ptep = __pte(pte_val(pte) & ~_PAGE_HPTEFLAGS);
439 } 439 }
440 440
441 /* Set the dirty and/or accessed bits atomically in a linux PTE, this 441 /* Set the dirty and/or accessed bits atomically in a linux PTE, this
442 * function doesn't need to flush the hash entry 442 * function doesn't need to flush the hash entry
443 */ 443 */
444 #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS 444 #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
445 static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty) 445 static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
446 { 446 {
447 unsigned long bits = pte_val(entry) & 447 unsigned long bits = pte_val(entry) &
448 (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC); 448 (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
449 unsigned long old, tmp; 449 unsigned long old, tmp;
450 450
451 __asm__ __volatile__( 451 __asm__ __volatile__(
452 "1: ldarx %0,0,%4\n\ 452 "1: ldarx %0,0,%4\n\
453 andi. %1,%0,%6\n\ 453 andi. %1,%0,%6\n\
454 bne- 1b \n\ 454 bne- 1b \n\
455 or %0,%3,%0\n\ 455 or %0,%3,%0\n\
456 stdcx. %0,0,%4\n\ 456 stdcx. %0,0,%4\n\
457 bne- 1b" 457 bne- 1b"
458 :"=&r" (old), "=&r" (tmp), "=m" (*ptep) 458 :"=&r" (old), "=&r" (tmp), "=m" (*ptep)
459 :"r" (bits), "r" (ptep), "m" (*ptep), "i" (_PAGE_BUSY) 459 :"r" (bits), "r" (ptep), "m" (*ptep), "i" (_PAGE_BUSY)
460 :"cc"); 460 :"cc");
461 } 461 }
462 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \ 462 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
463 do { \ 463 do { \
464 __ptep_set_access_flags(__ptep, __entry, __dirty); \ 464 __ptep_set_access_flags(__ptep, __entry, __dirty); \
465 flush_tlb_page_nohash(__vma, __address); \ 465 flush_tlb_page_nohash(__vma, __address); \
466 } while(0) 466 } while(0)
467 467
468 /* 468 /*
469 * Macro to mark a page protection value as "uncacheable". 469 * Macro to mark a page protection value as "uncacheable".
470 */ 470 */
471 #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED)) 471 #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
472 472
473 struct file; 473 struct file;
474 extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr, 474 extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr,
475 unsigned long size, pgprot_t vma_prot); 475 unsigned long size, pgprot_t vma_prot);
476 #define __HAVE_PHYS_MEM_ACCESS_PROT 476 #define __HAVE_PHYS_MEM_ACCESS_PROT
477 477
478 #define __HAVE_ARCH_PTE_SAME 478 #define __HAVE_ARCH_PTE_SAME
479 #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0) 479 #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0)
480 480
481 #define pmd_ERROR(e) \ 481 #define pmd_ERROR(e) \
482 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e)) 482 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
483 #define pud_ERROR(e) \ 483 #define pud_ERROR(e) \
484 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pud_val(e)) 484 printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pud_val(e))
485 #define pgd_ERROR(e) \ 485 #define pgd_ERROR(e) \
486 printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) 486 printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
487 487
488 extern pgd_t swapper_pg_dir[]; 488 extern pgd_t swapper_pg_dir[];
489 489
490 extern void paging_init(void); 490 extern void paging_init(void);
491 491
492 #ifdef CONFIG_HUGETLB_PAGE
492 #define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) \ 493 #define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) \
493 free_pgd_range(tlb, addr, end, floor, ceiling) 494 free_pgd_range(tlb, addr, end, floor, ceiling)
495 #endif
494 496
495 /* 497 /*
496 * This gets called at the end of handling a page fault, when 498 * This gets called at the end of handling a page fault, when
497 * the kernel has put a new PTE into the page table for the process. 499 * the kernel has put a new PTE into the page table for the process.
498 * We use it to put a corresponding HPTE into the hash table 500 * We use it to put a corresponding HPTE into the hash table
499 * ahead of time, instead of waiting for the inevitable extra 501 * ahead of time, instead of waiting for the inevitable extra
500 * hash-table miss exception. 502 * hash-table miss exception.
501 */ 503 */
502 struct vm_area_struct; 504 struct vm_area_struct;
503 extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t); 505 extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
504 506
505 /* Encode and de-code a swap entry */ 507 /* Encode and de-code a swap entry */
506 #define __swp_type(entry) (((entry).val >> 1) & 0x3f) 508 #define __swp_type(entry) (((entry).val >> 1) & 0x3f)
507 #define __swp_offset(entry) ((entry).val >> 8) 509 #define __swp_offset(entry) ((entry).val >> 8)
508 #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) }) 510 #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) })
509 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> PTE_SHIFT }) 511 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> PTE_SHIFT })
510 #define __swp_entry_to_pte(x) ((pte_t) { (x).val << PTE_SHIFT }) 512 #define __swp_entry_to_pte(x) ((pte_t) { (x).val << PTE_SHIFT })
511 #define pte_to_pgoff(pte) (pte_val(pte) >> PTE_SHIFT) 513 #define pte_to_pgoff(pte) (pte_val(pte) >> PTE_SHIFT)
512 #define pgoff_to_pte(off) ((pte_t) {((off) << PTE_SHIFT)|_PAGE_FILE}) 514 #define pgoff_to_pte(off) ((pte_t) {((off) << PTE_SHIFT)|_PAGE_FILE})
513 #define PTE_FILE_MAX_BITS (BITS_PER_LONG - PTE_SHIFT) 515 #define PTE_FILE_MAX_BITS (BITS_PER_LONG - PTE_SHIFT)
514 516
515 /* 517 /*
516 * kern_addr_valid is intended to indicate whether an address is a valid 518 * kern_addr_valid is intended to indicate whether an address is a valid
517 * kernel address. Most 32-bit archs define it as always true (like this) 519 * kernel address. Most 32-bit archs define it as always true (like this)
518 * but most 64-bit archs actually perform a test. What should we do here? 520 * but most 64-bit archs actually perform a test. What should we do here?
519 * The only use is in fs/ncpfs/dir.c 521 * The only use is in fs/ncpfs/dir.c
520 */ 522 */
521 #define kern_addr_valid(addr) (1) 523 #define kern_addr_valid(addr) (1)
522 524
523 #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ 525 #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
524 remap_pfn_range(vma, vaddr, pfn, size, prot) 526 remap_pfn_range(vma, vaddr, pfn, size, prot)
525 527
526 void pgtable_cache_init(void); 528 void pgtable_cache_init(void);
527 529
528 /* 530 /*
529 * find_linux_pte returns the address of a linux pte for a given 531 * find_linux_pte returns the address of a linux pte for a given
530 * effective address and directory. If not found, it returns zero. 532 * effective address and directory. If not found, it returns zero.
531 */ 533 */
532 static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea) 534 static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea)
533 { 535 {
534 pgd_t *pg; 536 pgd_t *pg;
535 pud_t *pu; 537 pud_t *pu;
536 pmd_t *pm; 538 pmd_t *pm;
537 pte_t *pt = NULL; 539 pte_t *pt = NULL;
538 pte_t pte; 540 pte_t pte;
539 541
540 pg = pgdir + pgd_index(ea); 542 pg = pgdir + pgd_index(ea);
541 if (!pgd_none(*pg)) { 543 if (!pgd_none(*pg)) {
542 pu = pud_offset(pg, ea); 544 pu = pud_offset(pg, ea);
543 if (!pud_none(*pu)) { 545 if (!pud_none(*pu)) {
544 pm = pmd_offset(pu, ea); 546 pm = pmd_offset(pu, ea);
545 if (pmd_present(*pm)) { 547 if (pmd_present(*pm)) {
546 pt = pte_offset_kernel(pm, ea); 548 pt = pte_offset_kernel(pm, ea);
547 pte = *pt; 549 pte = *pt;
548 if (!pte_present(pte)) 550 if (!pte_present(pte))
549 pt = NULL; 551 pt = NULL;
550 } 552 }
551 } 553 }
552 } 554 }
553 555
554 return pt; 556 return pt;
555 } 557 }
556 558
557 #include <asm-generic/pgtable.h> 559 #include <asm-generic/pgtable.h>
558 560
559 #endif /* __ASSEMBLY__ */ 561 #endif /* __ASSEMBLY__ */
560 562
561 #endif /* _PPC64_PGTABLE_H */ 563 #endif /* _PPC64_PGTABLE_H */
562 564