blob: a7b5091f3b13e89b652dcf2e304f09de89c7671c [file] [log] [blame]
Sam Ravnborgf5e706a2008-07-17 21:55:51 -07001/*
2 * pgtable.h: SpitFire page table operations.
3 *
4 * Copyright 1996,1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#ifndef _SPARC64_PGTABLE_H
9#define _SPARC64_PGTABLE_H
10
11/* This file contains the functions and defines necessary to modify and use
12 * the SpitFire page tables.
13 */
14
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070015#include <linux/compiler.h>
16#include <linux/const.h>
17#include <asm/types.h>
18#include <asm/spitfire.h>
19#include <asm/asi.h>
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070020#include <asm/page.h>
21#include <asm/processor.h>
22
Aaro Koskinen2533e822012-04-01 08:54:38 +000023#include <asm-generic/pgtable-nopud.h>
24
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070025/* The kernel image occupies 0x4000000 to 0x6000000 (4MB --> 96MB).
26 * The page copy blockops can use 0x6000000 to 0x8000000.
27 * The TSB is mapped in the 0x8000000 to 0xa000000 range.
28 * The PROM resides in an area spanning 0xf0000000 to 0x100000000.
29 * The vmalloc area spans 0x100000000 to 0x200000000.
30 * Since modules need to be in the lowest 32-bits of the address space,
31 * we place them right before the OBP area from 0x10000000 to 0xf0000000.
32 * There is a single static kernel PMD which maps from 0x0 to address
33 * 0x400000000.
34 */
35#define TLBTEMP_BASE _AC(0x0000000006000000,UL)
36#define TSBMAP_BASE _AC(0x0000000008000000,UL)
37#define MODULES_VADDR _AC(0x0000000010000000,UL)
38#define MODULES_LEN _AC(0x00000000e0000000,UL)
39#define MODULES_END _AC(0x00000000f0000000,UL)
40#define LOW_OBP_ADDRESS _AC(0x00000000f0000000,UL)
41#define HI_OBP_ADDRESS _AC(0x0000000100000000,UL)
42#define VMALLOC_START _AC(0x0000000100000000,UL)
David S. Miller1b6b9d62009-09-28 14:39:58 -070043#define VMALLOC_END _AC(0x0000010000000000,UL)
44#define VMEMMAP_BASE _AC(0x0000010000000000,UL)
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070045
46#define vmemmap ((struct page *)VMEMMAP_BASE)
47
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070048/* PMD_SHIFT determines the size of the area a second-level page
49 * table can map
50 */
David Miller56a70b82012-10-08 16:34:20 -070051#define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-4))
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070052#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
53#define PMD_MASK (~(PMD_SIZE-1))
54#define PMD_BITS (PAGE_SHIFT - 2)
55
56/* PGDIR_SHIFT determines what a third-level page table entry can map */
David Miller56a70b82012-10-08 16:34:20 -070057#define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-4) + PMD_BITS)
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070058#define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
59#define PGDIR_MASK (~(PGDIR_SIZE-1))
60#define PGDIR_BITS (PAGE_SHIFT - 2)
61
David Miller56a70b82012-10-08 16:34:20 -070062#if (PGDIR_SHIFT + PGDIR_BITS) != 44
63#error Page table parameters do not cover virtual address space properly.
64#endif
65
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070066#ifndef __ASSEMBLY__
67
68#include <linux/sched.h>
69
70/* Entries per page directory level. */
David Miller56a70b82012-10-08 16:34:20 -070071#define PTRS_PER_PTE (1UL << (PAGE_SHIFT-4))
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070072#define PTRS_PER_PMD (1UL << PMD_BITS)
73#define PTRS_PER_PGD (1UL << PGDIR_BITS)
74
75/* Kernel has a separate 44bit address space. */
76#define FIRST_USER_ADDRESS 0
77
78#define pte_ERROR(e) __builtin_trap()
79#define pmd_ERROR(e) __builtin_trap()
80#define pgd_ERROR(e) __builtin_trap()
81
82#endif /* !(__ASSEMBLY__) */
83
84/* PTE bits which are the same in SUN4U and SUN4V format. */
85#define _PAGE_VALID _AC(0x8000000000000000,UL) /* Valid TTE */
86#define _PAGE_R _AC(0x8000000000000000,UL) /* Keep ref bit uptodate*/
David S. Miller683d2fa2011-07-25 17:12:21 -070087#define _PAGE_SPECIAL _AC(0x0200000000000000,UL) /* Special page */
88
89/* Advertise support for _PAGE_SPECIAL */
90#define __HAVE_ARCH_PTE_SPECIAL
Sam Ravnborgf5e706a2008-07-17 21:55:51 -070091
92/* SUN4U pte bits... */
93#define _PAGE_SZ4MB_4U _AC(0x6000000000000000,UL) /* 4MB Page */
94#define _PAGE_SZ512K_4U _AC(0x4000000000000000,UL) /* 512K Page */
95#define _PAGE_SZ64K_4U _AC(0x2000000000000000,UL) /* 64K Page */
96#define _PAGE_SZ8K_4U _AC(0x0000000000000000,UL) /* 8K Page */
97#define _PAGE_NFO_4U _AC(0x1000000000000000,UL) /* No Fault Only */
98#define _PAGE_IE_4U _AC(0x0800000000000000,UL) /* Invert Endianness */
99#define _PAGE_SOFT2_4U _AC(0x07FC000000000000,UL) /* Software bits, set 2 */
David S. Miller683d2fa2011-07-25 17:12:21 -0700100#define _PAGE_SPECIAL_4U _AC(0x0200000000000000,UL) /* Special page */
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700101#define _PAGE_RES1_4U _AC(0x0002000000000000,UL) /* Reserved */
102#define _PAGE_SZ32MB_4U _AC(0x0001000000000000,UL) /* (Panther) 32MB page */
103#define _PAGE_SZ256MB_4U _AC(0x2001000000000000,UL) /* (Panther) 256MB page */
104#define _PAGE_SZALL_4U _AC(0x6001000000000000,UL) /* All pgsz bits */
105#define _PAGE_SN_4U _AC(0x0000800000000000,UL) /* (Cheetah) Snoop */
106#define _PAGE_RES2_4U _AC(0x0000780000000000,UL) /* Reserved */
107#define _PAGE_PADDR_4U _AC(0x000007FFFFFFE000,UL) /* (Cheetah) pa[42:13] */
108#define _PAGE_SOFT_4U _AC(0x0000000000001F80,UL) /* Software bits: */
109#define _PAGE_EXEC_4U _AC(0x0000000000001000,UL) /* Executable SW bit */
110#define _PAGE_MODIFIED_4U _AC(0x0000000000000800,UL) /* Modified (dirty) */
111#define _PAGE_FILE_4U _AC(0x0000000000000800,UL) /* Pagecache page */
112#define _PAGE_ACCESSED_4U _AC(0x0000000000000400,UL) /* Accessed (ref'd) */
113#define _PAGE_READ_4U _AC(0x0000000000000200,UL) /* Readable SW Bit */
114#define _PAGE_WRITE_4U _AC(0x0000000000000100,UL) /* Writable SW Bit */
115#define _PAGE_PRESENT_4U _AC(0x0000000000000080,UL) /* Present */
116#define _PAGE_L_4U _AC(0x0000000000000040,UL) /* Locked TTE */
117#define _PAGE_CP_4U _AC(0x0000000000000020,UL) /* Cacheable in P-Cache */
118#define _PAGE_CV_4U _AC(0x0000000000000010,UL) /* Cacheable in V-Cache */
119#define _PAGE_E_4U _AC(0x0000000000000008,UL) /* side-Effect */
120#define _PAGE_P_4U _AC(0x0000000000000004,UL) /* Privileged Page */
121#define _PAGE_W_4U _AC(0x0000000000000002,UL) /* Writable */
122
123/* SUN4V pte bits... */
124#define _PAGE_NFO_4V _AC(0x4000000000000000,UL) /* No Fault Only */
125#define _PAGE_SOFT2_4V _AC(0x3F00000000000000,UL) /* Software bits, set 2 */
126#define _PAGE_MODIFIED_4V _AC(0x2000000000000000,UL) /* Modified (dirty) */
127#define _PAGE_ACCESSED_4V _AC(0x1000000000000000,UL) /* Accessed (ref'd) */
128#define _PAGE_READ_4V _AC(0x0800000000000000,UL) /* Readable SW Bit */
129#define _PAGE_WRITE_4V _AC(0x0400000000000000,UL) /* Writable SW Bit */
David S. Miller683d2fa2011-07-25 17:12:21 -0700130#define _PAGE_SPECIAL_4V _AC(0x0200000000000000,UL) /* Special page */
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700131#define _PAGE_PADDR_4V _AC(0x00FFFFFFFFFFE000,UL) /* paddr[55:13] */
132#define _PAGE_IE_4V _AC(0x0000000000001000,UL) /* Invert Endianness */
133#define _PAGE_E_4V _AC(0x0000000000000800,UL) /* side-Effect */
134#define _PAGE_CP_4V _AC(0x0000000000000400,UL) /* Cacheable in P-Cache */
135#define _PAGE_CV_4V _AC(0x0000000000000200,UL) /* Cacheable in V-Cache */
136#define _PAGE_P_4V _AC(0x0000000000000100,UL) /* Privileged Page */
137#define _PAGE_EXEC_4V _AC(0x0000000000000080,UL) /* Executable Page */
138#define _PAGE_W_4V _AC(0x0000000000000040,UL) /* Writable */
139#define _PAGE_SOFT_4V _AC(0x0000000000000030,UL) /* Software bits */
140#define _PAGE_FILE_4V _AC(0x0000000000000020,UL) /* Pagecache page */
141#define _PAGE_PRESENT_4V _AC(0x0000000000000010,UL) /* Present */
142#define _PAGE_RESV_4V _AC(0x0000000000000008,UL) /* Reserved */
143#define _PAGE_SZ16GB_4V _AC(0x0000000000000007,UL) /* 16GB Page */
144#define _PAGE_SZ2GB_4V _AC(0x0000000000000006,UL) /* 2GB Page */
145#define _PAGE_SZ256MB_4V _AC(0x0000000000000005,UL) /* 256MB Page */
146#define _PAGE_SZ32MB_4V _AC(0x0000000000000004,UL) /* 32MB Page */
147#define _PAGE_SZ4MB_4V _AC(0x0000000000000003,UL) /* 4MB Page */
148#define _PAGE_SZ512K_4V _AC(0x0000000000000002,UL) /* 512K Page */
149#define _PAGE_SZ64K_4V _AC(0x0000000000000001,UL) /* 64K Page */
150#define _PAGE_SZ8K_4V _AC(0x0000000000000000,UL) /* 8K Page */
151#define _PAGE_SZALL_4V _AC(0x0000000000000007,UL) /* All pgsz bits */
152
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700153#define _PAGE_SZBITS_4U _PAGE_SZ8K_4U
154#define _PAGE_SZBITS_4V _PAGE_SZ8K_4V
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700155
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700156#define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U
157#define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700158
159/* These are actually filled in at boot time by sun4{u,v}_pgprot_init() */
160#define __P000 __pgprot(0)
161#define __P001 __pgprot(0)
162#define __P010 __pgprot(0)
163#define __P011 __pgprot(0)
164#define __P100 __pgprot(0)
165#define __P101 __pgprot(0)
166#define __P110 __pgprot(0)
167#define __P111 __pgprot(0)
168
169#define __S000 __pgprot(0)
170#define __S001 __pgprot(0)
171#define __S010 __pgprot(0)
172#define __S011 __pgprot(0)
173#define __S100 __pgprot(0)
174#define __S101 __pgprot(0)
175#define __S110 __pgprot(0)
176#define __S111 __pgprot(0)
177
178#ifndef __ASSEMBLY__
179
180extern pte_t mk_pte_io(unsigned long, pgprot_t, int, unsigned long);
181
182extern unsigned long pte_sz_bits(unsigned long size);
183
184extern pgprot_t PAGE_KERNEL;
185extern pgprot_t PAGE_KERNEL_LOCKED;
186extern pgprot_t PAGE_COPY;
187extern pgprot_t PAGE_SHARED;
188
189/* XXX This uglyness is for the atyfb driver's sparc mmap() support. XXX */
190extern unsigned long _PAGE_IE;
191extern unsigned long _PAGE_E;
192extern unsigned long _PAGE_CACHE;
193
194extern unsigned long pg_iobits;
195extern unsigned long _PAGE_ALL_SZ_BITS;
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700196
197extern struct page *mem_map_zero;
198#define ZERO_PAGE(vaddr) (mem_map_zero)
199
200/* PFNs are real physical page numbers. However, mem_map only begins to record
201 * per-page information starting at pfn_base. This is to handle systems where
202 * the first physical page in the machine is at some huge physical address,
203 * such as 4GB. This is common on a partitioned E10000, for example.
204 */
205static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
206{
207 unsigned long paddr = pfn << PAGE_SHIFT;
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700208
David Miller15b93502012-10-08 16:34:19 -0700209 BUILD_BUG_ON(_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL);
210 return __pte(paddr | pgprot_val(prot));
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700211}
212#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
213
214/* This one can be done with two shifts. */
215static inline unsigned long pte_pfn(pte_t pte)
216{
217 unsigned long ret;
218
219 __asm__ __volatile__(
220 "\n661: sllx %1, %2, %0\n"
221 " srlx %0, %3, %0\n"
222 " .section .sun4v_2insn_patch, \"ax\"\n"
223 " .word 661b\n"
224 " sllx %1, %4, %0\n"
225 " srlx %0, %5, %0\n"
226 " .previous\n"
227 : "=r" (ret)
228 : "r" (pte_val(pte)),
229 "i" (21), "i" (21 + PAGE_SHIFT),
230 "i" (8), "i" (8 + PAGE_SHIFT));
231
232 return ret;
233}
234#define pte_page(x) pfn_to_page(pte_pfn(x))
235
236static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
237{
238 unsigned long mask, tmp;
239
240 /* SUN4U: 0x600307ffffffecb8 (negated == 0x9ffcf80000001347)
241 * SUN4V: 0x30ffffffffffee17 (negated == 0xcf000000000011e8)
242 *
243 * Even if we use negation tricks the result is still a 6
244 * instruction sequence, so don't try to play fancy and just
245 * do the most straightforward implementation.
246 *
247 * Note: We encode this into 3 sun4v 2-insn patch sequences.
248 */
249
David Miller15b93502012-10-08 16:34:19 -0700250 BUILD_BUG_ON(_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700251 __asm__ __volatile__(
252 "\n661: sethi %%uhi(%2), %1\n"
253 " sethi %%hi(%2), %0\n"
254 "\n662: or %1, %%ulo(%2), %1\n"
255 " or %0, %%lo(%2), %0\n"
256 "\n663: sllx %1, 32, %1\n"
257 " or %0, %1, %0\n"
258 " .section .sun4v_2insn_patch, \"ax\"\n"
259 " .word 661b\n"
260 " sethi %%uhi(%3), %1\n"
261 " sethi %%hi(%3), %0\n"
262 " .word 662b\n"
263 " or %1, %%ulo(%3), %1\n"
264 " or %0, %%lo(%3), %0\n"
265 " .word 663b\n"
266 " sllx %1, 32, %1\n"
267 " or %0, %1, %0\n"
268 " .previous\n"
269 : "=r" (mask), "=r" (tmp)
270 : "i" (_PAGE_PADDR_4U | _PAGE_MODIFIED_4U | _PAGE_ACCESSED_4U |
271 _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_E_4U | _PAGE_PRESENT_4U |
David Miller15b93502012-10-08 16:34:19 -0700272 _PAGE_SPECIAL),
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700273 "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
274 _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_E_4V | _PAGE_PRESENT_4V |
David Miller15b93502012-10-08 16:34:19 -0700275 _PAGE_SPECIAL));
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700276
277 return __pte((pte_val(pte) & mask) | (pgprot_val(prot) & ~mask));
278}
279
280static inline pte_t pgoff_to_pte(unsigned long off)
281{
282 off <<= PAGE_SHIFT;
283
284 __asm__ __volatile__(
285 "\n661: or %0, %2, %0\n"
286 " .section .sun4v_1insn_patch, \"ax\"\n"
287 " .word 661b\n"
288 " or %0, %3, %0\n"
289 " .previous\n"
290 : "=r" (off)
291 : "0" (off), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
292
293 return __pte(off);
294}
295
296static inline pgprot_t pgprot_noncached(pgprot_t prot)
297{
298 unsigned long val = pgprot_val(prot);
299
300 __asm__ __volatile__(
301 "\n661: andn %0, %2, %0\n"
302 " or %0, %3, %0\n"
303 " .section .sun4v_2insn_patch, \"ax\"\n"
304 " .word 661b\n"
305 " andn %0, %4, %0\n"
306 " or %0, %5, %0\n"
307 " .previous\n"
308 : "=r" (val)
309 : "0" (val), "i" (_PAGE_CP_4U | _PAGE_CV_4U), "i" (_PAGE_E_4U),
310 "i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V));
311
312 return __pgprot(val);
313}
314/* Various pieces of code check for platform support by ifdef testing
315 * on "pgprot_noncached". That's broken and should be fixed, but for
316 * now...
317 */
318#define pgprot_noncached pgprot_noncached
319
320#ifdef CONFIG_HUGETLB_PAGE
321static inline pte_t pte_mkhuge(pte_t pte)
322{
323 unsigned long mask;
324
325 __asm__ __volatile__(
326 "\n661: sethi %%uhi(%1), %0\n"
327 " sllx %0, 32, %0\n"
328 " .section .sun4v_2insn_patch, \"ax\"\n"
329 " .word 661b\n"
330 " mov %2, %0\n"
331 " nop\n"
332 " .previous\n"
333 : "=r" (mask)
334 : "i" (_PAGE_SZHUGE_4U), "i" (_PAGE_SZHUGE_4V));
335
336 return __pte(pte_val(pte) | mask);
337}
338#endif
339
340static inline pte_t pte_mkdirty(pte_t pte)
341{
342 unsigned long val = pte_val(pte), tmp;
343
344 __asm__ __volatile__(
345 "\n661: or %0, %3, %0\n"
346 " nop\n"
347 "\n662: nop\n"
348 " nop\n"
349 " .section .sun4v_2insn_patch, \"ax\"\n"
350 " .word 661b\n"
351 " sethi %%uhi(%4), %1\n"
352 " sllx %1, 32, %1\n"
353 " .word 662b\n"
354 " or %1, %%lo(%4), %1\n"
355 " or %0, %1, %0\n"
356 " .previous\n"
357 : "=r" (val), "=r" (tmp)
358 : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
359 "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
360
361 return __pte(val);
362}
363
364static inline pte_t pte_mkclean(pte_t pte)
365{
366 unsigned long val = pte_val(pte), tmp;
367
368 __asm__ __volatile__(
369 "\n661: andn %0, %3, %0\n"
370 " nop\n"
371 "\n662: nop\n"
372 " nop\n"
373 " .section .sun4v_2insn_patch, \"ax\"\n"
374 " .word 661b\n"
375 " sethi %%uhi(%4), %1\n"
376 " sllx %1, 32, %1\n"
377 " .word 662b\n"
378 " or %1, %%lo(%4), %1\n"
379 " andn %0, %1, %0\n"
380 " .previous\n"
381 : "=r" (val), "=r" (tmp)
382 : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
383 "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
384
385 return __pte(val);
386}
387
388static inline pte_t pte_mkwrite(pte_t pte)
389{
390 unsigned long val = pte_val(pte), mask;
391
392 __asm__ __volatile__(
393 "\n661: mov %1, %0\n"
394 " nop\n"
395 " .section .sun4v_2insn_patch, \"ax\"\n"
396 " .word 661b\n"
397 " sethi %%uhi(%2), %0\n"
398 " sllx %0, 32, %0\n"
399 " .previous\n"
400 : "=r" (mask)
401 : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
402
403 return __pte(val | mask);
404}
405
406static inline pte_t pte_wrprotect(pte_t pte)
407{
408 unsigned long val = pte_val(pte), tmp;
409
410 __asm__ __volatile__(
411 "\n661: andn %0, %3, %0\n"
412 " nop\n"
413 "\n662: nop\n"
414 " nop\n"
415 " .section .sun4v_2insn_patch, \"ax\"\n"
416 " .word 661b\n"
417 " sethi %%uhi(%4), %1\n"
418 " sllx %1, 32, %1\n"
419 " .word 662b\n"
420 " or %1, %%lo(%4), %1\n"
421 " andn %0, %1, %0\n"
422 " .previous\n"
423 : "=r" (val), "=r" (tmp)
424 : "0" (val), "i" (_PAGE_WRITE_4U | _PAGE_W_4U),
425 "i" (_PAGE_WRITE_4V | _PAGE_W_4V));
426
427 return __pte(val);
428}
429
430static inline pte_t pte_mkold(pte_t pte)
431{
432 unsigned long mask;
433
434 __asm__ __volatile__(
435 "\n661: mov %1, %0\n"
436 " nop\n"
437 " .section .sun4v_2insn_patch, \"ax\"\n"
438 " .word 661b\n"
439 " sethi %%uhi(%2), %0\n"
440 " sllx %0, 32, %0\n"
441 " .previous\n"
442 : "=r" (mask)
443 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
444
445 mask |= _PAGE_R;
446
447 return __pte(pte_val(pte) & ~mask);
448}
449
450static inline pte_t pte_mkyoung(pte_t pte)
451{
452 unsigned long mask;
453
454 __asm__ __volatile__(
455 "\n661: mov %1, %0\n"
456 " nop\n"
457 " .section .sun4v_2insn_patch, \"ax\"\n"
458 " .word 661b\n"
459 " sethi %%uhi(%2), %0\n"
460 " sllx %0, 32, %0\n"
461 " .previous\n"
462 : "=r" (mask)
463 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
464
465 mask |= _PAGE_R;
466
467 return __pte(pte_val(pte) | mask);
468}
469
470static inline pte_t pte_mkspecial(pte_t pte)
471{
David S. Miller683d2fa2011-07-25 17:12:21 -0700472 pte_val(pte) |= _PAGE_SPECIAL;
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700473 return pte;
474}
475
476static inline unsigned long pte_young(pte_t pte)
477{
478 unsigned long mask;
479
480 __asm__ __volatile__(
481 "\n661: mov %1, %0\n"
482 " nop\n"
483 " .section .sun4v_2insn_patch, \"ax\"\n"
484 " .word 661b\n"
485 " sethi %%uhi(%2), %0\n"
486 " sllx %0, 32, %0\n"
487 " .previous\n"
488 : "=r" (mask)
489 : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
490
491 return (pte_val(pte) & mask);
492}
493
494static inline unsigned long pte_dirty(pte_t pte)
495{
496 unsigned long mask;
497
498 __asm__ __volatile__(
499 "\n661: mov %1, %0\n"
500 " nop\n"
501 " .section .sun4v_2insn_patch, \"ax\"\n"
502 " .word 661b\n"
503 " sethi %%uhi(%2), %0\n"
504 " sllx %0, 32, %0\n"
505 " .previous\n"
506 : "=r" (mask)
507 : "i" (_PAGE_MODIFIED_4U), "i" (_PAGE_MODIFIED_4V));
508
509 return (pte_val(pte) & mask);
510}
511
512static inline unsigned long pte_write(pte_t pte)
513{
514 unsigned long mask;
515
516 __asm__ __volatile__(
517 "\n661: mov %1, %0\n"
518 " nop\n"
519 " .section .sun4v_2insn_patch, \"ax\"\n"
520 " .word 661b\n"
521 " sethi %%uhi(%2), %0\n"
522 " sllx %0, 32, %0\n"
523 " .previous\n"
524 : "=r" (mask)
525 : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
526
527 return (pte_val(pte) & mask);
528}
529
530static inline unsigned long pte_exec(pte_t pte)
531{
532 unsigned long mask;
533
534 __asm__ __volatile__(
535 "\n661: sethi %%hi(%1), %0\n"
536 " .section .sun4v_1insn_patch, \"ax\"\n"
537 " .word 661b\n"
538 " mov %2, %0\n"
539 " .previous\n"
540 : "=r" (mask)
541 : "i" (_PAGE_EXEC_4U), "i" (_PAGE_EXEC_4V));
542
543 return (pte_val(pte) & mask);
544}
545
546static inline unsigned long pte_file(pte_t pte)
547{
548 unsigned long val = pte_val(pte);
549
550 __asm__ __volatile__(
551 "\n661: and %0, %2, %0\n"
552 " .section .sun4v_1insn_patch, \"ax\"\n"
553 " .word 661b\n"
554 " and %0, %3, %0\n"
555 " .previous\n"
556 : "=r" (val)
557 : "0" (val), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
558
559 return val;
560}
561
562static inline unsigned long pte_present(pte_t pte)
563{
564 unsigned long val = pte_val(pte);
565
566 __asm__ __volatile__(
567 "\n661: and %0, %2, %0\n"
568 " .section .sun4v_1insn_patch, \"ax\"\n"
569 " .word 661b\n"
570 " and %0, %3, %0\n"
571 " .previous\n"
572 : "=r" (val)
573 : "0" (val), "i" (_PAGE_PRESENT_4U), "i" (_PAGE_PRESENT_4V));
574
575 return val;
576}
577
David S. Miller683d2fa2011-07-25 17:12:21 -0700578static inline unsigned long pte_special(pte_t pte)
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700579{
David S. Miller683d2fa2011-07-25 17:12:21 -0700580 return pte_val(pte) & _PAGE_SPECIAL;
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700581}
582
583#define pmd_set(pmdp, ptep) \
584 (pmd_val(*(pmdp)) = (__pa((unsigned long) (ptep)) >> 11UL))
585#define pud_set(pudp, pmdp) \
586 (pud_val(*(pudp)) = (__pa((unsigned long) (pmdp)) >> 11UL))
587#define __pmd_page(pmd) \
588 ((unsigned long) __va((((unsigned long)pmd_val(pmd))<<11UL)))
589#define pmd_page(pmd) virt_to_page((void *)__pmd_page(pmd))
590#define pud_page_vaddr(pud) \
591 ((unsigned long) __va((((unsigned long)pud_val(pud))<<11UL)))
592#define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
593#define pmd_none(pmd) (!pmd_val(pmd))
594#define pmd_bad(pmd) (0)
595#define pmd_present(pmd) (pmd_val(pmd) != 0U)
596#define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0U)
597#define pud_none(pud) (!pud_val(pud))
598#define pud_bad(pud) (0)
599#define pud_present(pud) (pud_val(pud) != 0U)
600#define pud_clear(pudp) (pud_val(*(pudp)) = 0U)
601
602/* Same in both SUN4V and SUN4U. */
603#define pte_none(pte) (!pte_val(pte))
604
605/* to find an entry in a page-table-directory. */
606#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
607#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
608
609/* to find an entry in a kernel page-table-directory */
610#define pgd_offset_k(address) pgd_offset(&init_mm, address)
611
612/* Find an entry in the second-level page table.. */
613#define pmd_offset(pudp, address) \
614 ((pmd_t *) pud_page_vaddr(*(pudp)) + \
615 (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)))
616
617/* Find an entry in the third-level page table.. */
618#define pte_index(dir, address) \
619 ((pte_t *) __pmd_page(*(dir)) + \
620 ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
621#define pte_offset_kernel pte_index
622#define pte_offset_map pte_index
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700623#define pte_unmap(pte) do { } while (0)
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700624
625/* Actual page table PTE updates. */
Peter Zijlstra90f08e32011-05-24 17:11:50 -0700626extern void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
627 pte_t *ptep, pte_t orig, int fullmm);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700628
Peter Zijlstra90f08e32011-05-24 17:11:50 -0700629static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
630 pte_t *ptep, pte_t pte, int fullmm)
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700631{
632 pte_t orig = *ptep;
633
634 *ptep = pte;
635
636 /* It is more efficient to let flush_tlb_kernel_range()
637 * handle init_mm tlb flushes.
638 *
639 * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U
640 * and SUN4V pte layout, so this inline test is fine.
641 */
642 if (likely(mm != &init_mm) && (pte_val(orig) & _PAGE_VALID))
Peter Zijlstra90f08e32011-05-24 17:11:50 -0700643 tlb_batch_add(mm, addr, ptep, orig, fullmm);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700644}
645
Peter Zijlstra90f08e32011-05-24 17:11:50 -0700646#define set_pte_at(mm,addr,ptep,pte) \
647 __set_pte_at((mm), (addr), (ptep), (pte), 0)
648
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700649#define pte_clear(mm,addr,ptep) \
650 set_pte_at((mm), (addr), (ptep), __pte(0UL))
651
Peter Zijlstra90f08e32011-05-24 17:11:50 -0700652#define __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL
653#define pte_clear_not_present_full(mm,addr,ptep,fullmm) \
654 __set_pte_at((mm), (addr), (ptep), __pte(0UL), (fullmm))
655
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700656#ifdef DCACHE_ALIASING_POSSIBLE
657#define __HAVE_ARCH_MOVE_PTE
658#define move_pte(pte, prot, old_addr, new_addr) \
659({ \
660 pte_t newpte = (pte); \
661 if (tlb_type != hypervisor && pte_present(pte)) { \
662 unsigned long this_pfn = pte_pfn(pte); \
663 \
664 if (pfn_valid(this_pfn) && \
665 (((old_addr) ^ (new_addr)) & (1 << 13))) \
666 flush_dcache_page_all(current->mm, \
667 pfn_to_page(this_pfn)); \
668 } \
669 newpte; \
670})
671#endif
672
673extern pgd_t swapper_pg_dir[2048];
674extern pmd_t swapper_low_pmd_dir[2048];
675
676extern void paging_init(void);
677extern unsigned long find_ecache_flush_span(unsigned long size);
678
Sam Ravnborgcb1b8202011-04-21 15:45:45 -0700679struct seq_file;
680extern void mmu_info(struct seq_file *);
681
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700682struct vm_area_struct;
Russell King4b3073e2009-12-18 16:40:18 +0000683extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700684
685/* Encode and de-code a swap entry */
686#define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0xffUL)
687#define __swp_offset(entry) ((entry).val >> (PAGE_SHIFT + 8UL))
688#define __swp_entry(type, offset) \
689 ( (swp_entry_t) \
690 { \
691 (((long)(type) << PAGE_SHIFT) | \
692 ((long)(offset) << (PAGE_SHIFT + 8UL))) \
693 } )
694#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
695#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
696
697/* File offset in PTE support. */
698extern unsigned long pte_file(pte_t);
699#define pte_to_pgoff(pte) (pte_val(pte) >> PAGE_SHIFT)
700extern pte_t pgoff_to_pte(unsigned long);
701#define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
702
David S. Millerd8ed1d42009-08-25 16:47:46 -0700703extern unsigned long sparc64_valid_addr_bitmap[];
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700704
705/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
David S. Millerd8ed1d42009-08-25 16:47:46 -0700706static inline bool kern_addr_valid(unsigned long addr)
707{
708 unsigned long paddr = __pa(addr);
709
710 if ((paddr >> 41UL) != 0UL)
711 return false;
712 return test_bit(paddr >> 22, sparc64_valid_addr_bitmap);
713}
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700714
715extern int page_in_phys_avail(unsigned long paddr);
716
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700717/*
718 * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
719 * its high 4 bits. These macros/functions put it there or get it from there.
720 */
721#define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
722#define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
723#define GET_PFN(pfn) (pfn & 0x0fffffffffffffffUL)
724
David S. Miller3e37fd32011-11-17 18:17:59 -0800725extern int remap_pfn_range(struct vm_area_struct *, unsigned long, unsigned long,
726 unsigned long, pgprot_t);
727
728static inline int io_remap_pfn_range(struct vm_area_struct *vma,
729 unsigned long from, unsigned long pfn,
730 unsigned long size, pgprot_t prot)
731{
732 unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
733 int space = GET_IOSPACE(pfn);
734 unsigned long phys_base;
735
736 phys_base = offset | (((unsigned long) space) << 32UL);
737
738 return remap_pfn_range(vma, from, phys_base >> PAGE_SHIFT, size, prot);
739}
740
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700741#include <asm-generic/pgtable.h>
742
743/* We provide our own get_unmapped_area to cope with VA holes and
744 * SHM area cache aliasing for userland.
745 */
746#define HAVE_ARCH_UNMAPPED_AREA
747#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
748
749/* We provide a special get_unmapped_area for framebuffer mmaps to try and use
750 * the largest alignment possible such that larget PTEs can be used.
751 */
752extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
753 unsigned long, unsigned long,
754 unsigned long);
755#define HAVE_ARCH_FB_UNMAPPED_AREA
756
757extern void pgtable_cache_init(void);
758extern void sun4v_register_fault_status(void);
759extern void sun4v_ktsb_register(void);
760extern void __init cheetah_ecache_flush_init(void);
761extern void sun4v_patch_tlb_handlers(void);
762
763extern unsigned long cmdline_memory_size;
764
David S. Millerb539c462008-09-12 00:10:32 -0700765extern asmlinkage void do_sparc64_fault(struct pt_regs *regs);
766
Sam Ravnborgf5e706a2008-07-17 21:55:51 -0700767#endif /* !(__ASSEMBLY__) */
768
769#endif /* !(_SPARC64_PGTABLE_H) */