pgtable.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /* $Id: pgtable.h,v 1.156 2002/02/09 19:49:31 davem Exp $
  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. #ifndef _SPARC64_PGTABLE_H
  8. #define _SPARC64_PGTABLE_H
  9. /* This file contains the functions and defines necessary to modify and use
  10. * the SpitFire page tables.
  11. */
  12. #include <asm-generic/pgtable-nopud.h>
  13. #include <linux/compiler.h>
  14. #include <linux/const.h>
  15. #include <asm/types.h>
  16. #include <asm/spitfire.h>
  17. #include <asm/asi.h>
  18. #include <asm/system.h>
  19. #include <asm/page.h>
  20. #include <asm/processor.h>
  21. /* The kernel image occupies 0x4000000 to 0x1000000 (4MB --> 32MB).
  22. * The page copy blockops can use 0x2000000 to 0x4000000.
  23. * The TSB is mapped in the 0x4000000 to 0x6000000 range.
  24. * The PROM resides in an area spanning 0xf0000000 to 0x100000000.
  25. * The vmalloc area spans 0x100000000 to 0x200000000.
  26. * Since modules need to be in the lowest 32-bits of the address space,
  27. * we place them right before the OBP area from 0x10000000 to 0xf0000000.
  28. * There is a single static kernel PMD which maps from 0x0 to address
  29. * 0x400000000.
  30. */
  31. #define TLBTEMP_BASE _AC(0x0000000002000000,UL)
  32. #define TSBMAP_BASE _AC(0x0000000004000000,UL)
  33. #define MODULES_VADDR _AC(0x0000000010000000,UL)
  34. #define MODULES_LEN _AC(0x00000000e0000000,UL)
  35. #define MODULES_END _AC(0x00000000f0000000,UL)
  36. #define LOW_OBP_ADDRESS _AC(0x00000000f0000000,UL)
  37. #define HI_OBP_ADDRESS _AC(0x0000000100000000,UL)
  38. #define VMALLOC_START _AC(0x0000000100000000,UL)
  39. #define VMALLOC_END _AC(0x0000000200000000,UL)
  40. /* XXX All of this needs to be rethought so we can take advantage
  41. * XXX cheetah's full 64-bit virtual address space, ie. no more hole
  42. * XXX in the middle like on spitfire. -DaveM
  43. */
  44. /*
  45. * Given a virtual address, the lowest PAGE_SHIFT bits determine offset
  46. * into the page; the next higher PAGE_SHIFT-3 bits determine the pte#
  47. * in the proper pagetable (the -3 is from the 8 byte ptes, and each page
  48. * table is a single page long). The next higher PMD_BITS determine pmd#
  49. * in the proper pmdtable (where we must have PMD_BITS <= (PAGE_SHIFT-2)
  50. * since the pmd entries are 4 bytes, and each pmd page is a single page
  51. * long). Finally, the higher few bits determine pgde#.
  52. */
  53. /* PMD_SHIFT determines the size of the area a second-level page
  54. * table can map
  55. */
  56. #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
  57. #define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
  58. #define PMD_MASK (~(PMD_SIZE-1))
  59. #define PMD_BITS (PAGE_SHIFT - 2)
  60. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  61. #define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3) + PMD_BITS)
  62. #define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
  63. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  64. #define PGDIR_BITS (PAGE_SHIFT - 2)
  65. #ifndef __ASSEMBLY__
  66. #include <linux/sched.h>
  67. /* Entries per page directory level. */
  68. #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
  69. #define PTRS_PER_PMD (1UL << PMD_BITS)
  70. #define PTRS_PER_PGD (1UL << PGDIR_BITS)
  71. /* Kernel has a separate 44bit address space. */
  72. #define FIRST_USER_ADDRESS 0
  73. #define pte_ERROR(e) __builtin_trap()
  74. #define pmd_ERROR(e) __builtin_trap()
  75. #define pgd_ERROR(e) __builtin_trap()
  76. #endif /* !(__ASSEMBLY__) */
  77. /* PTE bits which are the same in SUN4U and SUN4V format. */
  78. #define _PAGE_VALID _AC(0x8000000000000000,UL) /* Valid TTE */
  79. #define _PAGE_R _AC(0x8000000000000000,UL) /* Keep ref bit uptodate*/
  80. /* SUN4U pte bits... */
  81. #define _PAGE_SZ4MB_4U _AC(0x6000000000000000,UL) /* 4MB Page */
  82. #define _PAGE_SZ512K_4U _AC(0x4000000000000000,UL) /* 512K Page */
  83. #define _PAGE_SZ64K_4U _AC(0x2000000000000000,UL) /* 64K Page */
  84. #define _PAGE_SZ8K_4U _AC(0x0000000000000000,UL) /* 8K Page */
  85. #define _PAGE_NFO_4U _AC(0x1000000000000000,UL) /* No Fault Only */
  86. #define _PAGE_IE_4U _AC(0x0800000000000000,UL) /* Invert Endianness */
  87. #define _PAGE_SOFT2_4U _AC(0x07FC000000000000,UL) /* Software bits, set 2 */
  88. #define _PAGE_RES1_4U _AC(0x0002000000000000,UL) /* Reserved */
  89. #define _PAGE_SZ32MB_4U _AC(0x0001000000000000,UL) /* (Panther) 32MB page */
  90. #define _PAGE_SZ256MB_4U _AC(0x2001000000000000,UL) /* (Panther) 256MB page */
  91. #define _PAGE_SZALL_4U _AC(0x6001000000000000,UL) /* All pgsz bits */
  92. #define _PAGE_SN_4U _AC(0x0000800000000000,UL) /* (Cheetah) Snoop */
  93. #define _PAGE_RES2_4U _AC(0x0000780000000000,UL) /* Reserved */
  94. #define _PAGE_PADDR_4U _AC(0x000007FFFFFFE000,UL) /* (Cheetah) pa[42:13] */
  95. #define _PAGE_SOFT_4U _AC(0x0000000000001F80,UL) /* Software bits: */
  96. #define _PAGE_EXEC_4U _AC(0x0000000000001000,UL) /* Executable SW bit */
  97. #define _PAGE_MODIFIED_4U _AC(0x0000000000000800,UL) /* Modified (dirty) */
  98. #define _PAGE_FILE_4U _AC(0x0000000000000800,UL) /* Pagecache page */
  99. #define _PAGE_ACCESSED_4U _AC(0x0000000000000400,UL) /* Accessed (ref'd) */
  100. #define _PAGE_READ_4U _AC(0x0000000000000200,UL) /* Readable SW Bit */
  101. #define _PAGE_WRITE_4U _AC(0x0000000000000100,UL) /* Writable SW Bit */
  102. #define _PAGE_PRESENT_4U _AC(0x0000000000000080,UL) /* Present */
  103. #define _PAGE_L_4U _AC(0x0000000000000040,UL) /* Locked TTE */
  104. #define _PAGE_CP_4U _AC(0x0000000000000020,UL) /* Cacheable in P-Cache */
  105. #define _PAGE_CV_4U _AC(0x0000000000000010,UL) /* Cacheable in V-Cache */
  106. #define _PAGE_E_4U _AC(0x0000000000000008,UL) /* side-Effect */
  107. #define _PAGE_P_4U _AC(0x0000000000000004,UL) /* Privileged Page */
  108. #define _PAGE_W_4U _AC(0x0000000000000002,UL) /* Writable */
  109. /* SUN4V pte bits... */
  110. #define _PAGE_NFO_4V _AC(0x4000000000000000,UL) /* No Fault Only */
  111. #define _PAGE_SOFT2_4V _AC(0x3F00000000000000,UL) /* Software bits, set 2 */
  112. #define _PAGE_MODIFIED_4V _AC(0x2000000000000000,UL) /* Modified (dirty) */
  113. #define _PAGE_ACCESSED_4V _AC(0x1000000000000000,UL) /* Accessed (ref'd) */
  114. #define _PAGE_READ_4V _AC(0x0800000000000000,UL) /* Readable SW Bit */
  115. #define _PAGE_WRITE_4V _AC(0x0400000000000000,UL) /* Writable SW Bit */
  116. #define _PAGE_PADDR_4V _AC(0x00FFFFFFFFFFE000,UL) /* paddr[55:13] */
  117. #define _PAGE_IE_4V _AC(0x0000000000001000,UL) /* Invert Endianness */
  118. #define _PAGE_E_4V _AC(0x0000000000000800,UL) /* side-Effect */
  119. #define _PAGE_CP_4V _AC(0x0000000000000400,UL) /* Cacheable in P-Cache */
  120. #define _PAGE_CV_4V _AC(0x0000000000000200,UL) /* Cacheable in V-Cache */
  121. #define _PAGE_P_4V _AC(0x0000000000000100,UL) /* Privileged Page */
  122. #define _PAGE_EXEC_4V _AC(0x0000000000000080,UL) /* Executable Page */
  123. #define _PAGE_W_4V _AC(0x0000000000000040,UL) /* Writable */
  124. #define _PAGE_SOFT_4V _AC(0x0000000000000030,UL) /* Software bits */
  125. #define _PAGE_FILE_4V _AC(0x0000000000000020,UL) /* Pagecache page */
  126. #define _PAGE_PRESENT_4V _AC(0x0000000000000010,UL) /* Present */
  127. #define _PAGE_RESV_4V _AC(0x0000000000000008,UL) /* Reserved */
  128. #define _PAGE_SZ16GB_4V _AC(0x0000000000000007,UL) /* 16GB Page */
  129. #define _PAGE_SZ2GB_4V _AC(0x0000000000000006,UL) /* 2GB Page */
  130. #define _PAGE_SZ256MB_4V _AC(0x0000000000000005,UL) /* 256MB Page */
  131. #define _PAGE_SZ32MB_4V _AC(0x0000000000000004,UL) /* 32MB Page */
  132. #define _PAGE_SZ4MB_4V _AC(0x0000000000000003,UL) /* 4MB Page */
  133. #define _PAGE_SZ512K_4V _AC(0x0000000000000002,UL) /* 512K Page */
  134. #define _PAGE_SZ64K_4V _AC(0x0000000000000001,UL) /* 64K Page */
  135. #define _PAGE_SZ8K_4V _AC(0x0000000000000000,UL) /* 8K Page */
  136. #define _PAGE_SZALL_4V _AC(0x0000000000000007,UL) /* All pgsz bits */
  137. #if PAGE_SHIFT == 13
  138. #define _PAGE_SZBITS_4U _PAGE_SZ8K_4U
  139. #define _PAGE_SZBITS_4V _PAGE_SZ8K_4V
  140. #elif PAGE_SHIFT == 16
  141. #define _PAGE_SZBITS_4U _PAGE_SZ64K_4U
  142. #define _PAGE_SZBITS_4V _PAGE_SZ64K_4V
  143. #elif PAGE_SHIFT == 19
  144. #define _PAGE_SZBITS_4U _PAGE_SZ512K_4U
  145. #define _PAGE_SZBITS_4V _PAGE_SZ512K_4V
  146. #elif PAGE_SHIFT == 22
  147. #define _PAGE_SZBITS_4U _PAGE_SZ4MB_4U
  148. #define _PAGE_SZBITS_4V _PAGE_SZ4MB_4V
  149. #else
  150. #error Wrong PAGE_SHIFT specified
  151. #endif
  152. #if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
  153. #define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U
  154. #define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V
  155. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
  156. #define _PAGE_SZHUGE_4U _PAGE_SZ512K_4U
  157. #define _PAGE_SZHUGE_4V _PAGE_SZ512K_4V
  158. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
  159. #define _PAGE_SZHUGE_4U _PAGE_SZ64K_4U
  160. #define _PAGE_SZHUGE_4V _PAGE_SZ64K_4V
  161. #endif
  162. /* These are actually filled in at boot time by sun4{u,v}_pgprot_init() */
  163. #define __P000 __pgprot(0)
  164. #define __P001 __pgprot(0)
  165. #define __P010 __pgprot(0)
  166. #define __P011 __pgprot(0)
  167. #define __P100 __pgprot(0)
  168. #define __P101 __pgprot(0)
  169. #define __P110 __pgprot(0)
  170. #define __P111 __pgprot(0)
  171. #define __S000 __pgprot(0)
  172. #define __S001 __pgprot(0)
  173. #define __S010 __pgprot(0)
  174. #define __S011 __pgprot(0)
  175. #define __S100 __pgprot(0)
  176. #define __S101 __pgprot(0)
  177. #define __S110 __pgprot(0)
  178. #define __S111 __pgprot(0)
  179. #ifndef __ASSEMBLY__
  180. extern pte_t mk_pte_io(unsigned long, pgprot_t, int, unsigned long);
  181. extern unsigned long pte_sz_bits(unsigned long size);
  182. extern pgprot_t PAGE_KERNEL;
  183. extern pgprot_t PAGE_KERNEL_LOCKED;
  184. extern pgprot_t PAGE_COPY;
  185. extern pgprot_t PAGE_SHARED;
  186. /* XXX This uglyness is for the atyfb driver's sparc mmap() support. XXX */
  187. extern unsigned long _PAGE_IE;
  188. extern unsigned long _PAGE_E;
  189. extern unsigned long _PAGE_CACHE;
  190. extern unsigned long pg_iobits;
  191. extern unsigned long _PAGE_ALL_SZ_BITS;
  192. extern unsigned long _PAGE_SZBITS;
  193. extern struct page *mem_map_zero;
  194. #define ZERO_PAGE(vaddr) (mem_map_zero)
  195. /* PFNs are real physical page numbers. However, mem_map only begins to record
  196. * per-page information starting at pfn_base. This is to handle systems where
  197. * the first physical page in the machine is at some huge physical address,
  198. * such as 4GB. This is common on a partitioned E10000, for example.
  199. */
  200. static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
  201. {
  202. unsigned long paddr = pfn << PAGE_SHIFT;
  203. unsigned long sz_bits;
  204. sz_bits = 0UL;
  205. if (_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL) {
  206. __asm__ __volatile__(
  207. "\n661: sethi %%uhi(%1), %0\n"
  208. " sllx %0, 32, %0\n"
  209. " .section .sun4v_2insn_patch, \"ax\"\n"
  210. " .word 661b\n"
  211. " mov %2, %0\n"
  212. " nop\n"
  213. " .previous\n"
  214. : "=r" (sz_bits)
  215. : "i" (_PAGE_SZBITS_4U), "i" (_PAGE_SZBITS_4V));
  216. }
  217. return __pte(paddr | sz_bits | pgprot_val(prot));
  218. }
  219. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  220. /* This one can be done with two shifts. */
  221. static inline unsigned long pte_pfn(pte_t pte)
  222. {
  223. unsigned long ret;
  224. __asm__ __volatile__(
  225. "\n661: sllx %1, %2, %0\n"
  226. " srlx %0, %3, %0\n"
  227. " .section .sun4v_2insn_patch, \"ax\"\n"
  228. " .word 661b\n"
  229. " sllx %1, %4, %0\n"
  230. " srlx %0, %5, %0\n"
  231. " .previous\n"
  232. : "=r" (ret)
  233. : "r" (pte_val(pte)),
  234. "i" (21), "i" (21 + PAGE_SHIFT),
  235. "i" (8), "i" (8 + PAGE_SHIFT));
  236. return ret;
  237. }
  238. #define pte_page(x) pfn_to_page(pte_pfn(x))
  239. static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
  240. {
  241. unsigned long mask, tmp;
  242. /* SUN4U: 0x600307ffffffecb8 (negated == 0x9ffcf80000001347)
  243. * SUN4V: 0x30ffffffffffee17 (negated == 0xcf000000000011e8)
  244. *
  245. * Even if we use negation tricks the result is still a 6
  246. * instruction sequence, so don't try to play fancy and just
  247. * do the most straightforward implementation.
  248. *
  249. * Note: We encode this into 3 sun4v 2-insn patch sequences.
  250. */
  251. __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 |
  272. _PAGE_SZBITS_4U),
  273. "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
  274. _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_E_4V | _PAGE_PRESENT_4V |
  275. _PAGE_SZBITS_4V));
  276. return __pte((pte_val(pte) & mask) | (pgprot_val(prot) & ~mask));
  277. }
  278. static inline pte_t pgoff_to_pte(unsigned long off)
  279. {
  280. off <<= PAGE_SHIFT;
  281. __asm__ __volatile__(
  282. "\n661: or %0, %2, %0\n"
  283. " .section .sun4v_1insn_patch, \"ax\"\n"
  284. " .word 661b\n"
  285. " or %0, %3, %0\n"
  286. " .previous\n"
  287. : "=r" (off)
  288. : "0" (off), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
  289. return __pte(off);
  290. }
  291. static inline pgprot_t pgprot_noncached(pgprot_t prot)
  292. {
  293. unsigned long val = pgprot_val(prot);
  294. __asm__ __volatile__(
  295. "\n661: andn %0, %2, %0\n"
  296. " or %0, %3, %0\n"
  297. " .section .sun4v_2insn_patch, \"ax\"\n"
  298. " .word 661b\n"
  299. " andn %0, %4, %0\n"
  300. " or %0, %5, %0\n"
  301. " .previous\n"
  302. : "=r" (val)
  303. : "0" (val), "i" (_PAGE_CP_4U | _PAGE_CV_4U), "i" (_PAGE_E_4U),
  304. "i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V));
  305. return __pgprot(val);
  306. }
  307. /* Various pieces of code check for platform support by ifdef testing
  308. * on "pgprot_noncached". That's broken and should be fixed, but for
  309. * now...
  310. */
  311. #define pgprot_noncached pgprot_noncached
  312. #ifdef CONFIG_HUGETLB_PAGE
  313. static inline pte_t pte_mkhuge(pte_t pte)
  314. {
  315. unsigned long mask;
  316. __asm__ __volatile__(
  317. "\n661: sethi %%uhi(%1), %0\n"
  318. " sllx %0, 32, %0\n"
  319. " .section .sun4v_2insn_patch, \"ax\"\n"
  320. " .word 661b\n"
  321. " mov %2, %0\n"
  322. " nop\n"
  323. " .previous\n"
  324. : "=r" (mask)
  325. : "i" (_PAGE_SZHUGE_4U), "i" (_PAGE_SZHUGE_4V));
  326. return __pte(pte_val(pte) | mask);
  327. }
  328. #endif
  329. static inline pte_t pte_mkdirty(pte_t pte)
  330. {
  331. unsigned long val = pte_val(pte), tmp;
  332. __asm__ __volatile__(
  333. "\n661: or %0, %3, %0\n"
  334. " nop\n"
  335. "\n662: nop\n"
  336. " nop\n"
  337. " .section .sun4v_2insn_patch, \"ax\"\n"
  338. " .word 661b\n"
  339. " sethi %%uhi(%4), %1\n"
  340. " sllx %1, 32, %1\n"
  341. " .word 662b\n"
  342. " or %1, %%lo(%4), %1\n"
  343. " or %0, %1, %0\n"
  344. " .previous\n"
  345. : "=r" (val), "=r" (tmp)
  346. : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
  347. "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
  348. return __pte(val);
  349. }
  350. static inline pte_t pte_mkclean(pte_t pte)
  351. {
  352. unsigned long val = pte_val(pte), tmp;
  353. __asm__ __volatile__(
  354. "\n661: andn %0, %3, %0\n"
  355. " nop\n"
  356. "\n662: nop\n"
  357. " nop\n"
  358. " .section .sun4v_2insn_patch, \"ax\"\n"
  359. " .word 661b\n"
  360. " sethi %%uhi(%4), %1\n"
  361. " sllx %1, 32, %1\n"
  362. " .word 662b\n"
  363. " or %1, %%lo(%4), %1\n"
  364. " andn %0, %1, %0\n"
  365. " .previous\n"
  366. : "=r" (val), "=r" (tmp)
  367. : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
  368. "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
  369. return __pte(val);
  370. }
  371. static inline pte_t pte_mkwrite(pte_t pte)
  372. {
  373. unsigned long val = pte_val(pte), mask;
  374. __asm__ __volatile__(
  375. "\n661: mov %1, %0\n"
  376. " nop\n"
  377. " .section .sun4v_2insn_patch, \"ax\"\n"
  378. " .word 661b\n"
  379. " sethi %%uhi(%2), %0\n"
  380. " sllx %0, 32, %0\n"
  381. " .previous\n"
  382. : "=r" (mask)
  383. : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
  384. return __pte(val | mask);
  385. }
  386. static inline pte_t pte_wrprotect(pte_t pte)
  387. {
  388. unsigned long val = pte_val(pte), tmp;
  389. __asm__ __volatile__(
  390. "\n661: andn %0, %3, %0\n"
  391. " nop\n"
  392. "\n662: nop\n"
  393. " nop\n"
  394. " .section .sun4v_2insn_patch, \"ax\"\n"
  395. " .word 661b\n"
  396. " sethi %%uhi(%4), %1\n"
  397. " sllx %1, 32, %1\n"
  398. " .word 662b\n"
  399. " or %1, %%lo(%4), %1\n"
  400. " andn %0, %1, %0\n"
  401. " .previous\n"
  402. : "=r" (val), "=r" (tmp)
  403. : "0" (val), "i" (_PAGE_WRITE_4U | _PAGE_W_4U),
  404. "i" (_PAGE_WRITE_4V | _PAGE_W_4V));
  405. return __pte(val);
  406. }
  407. static inline pte_t pte_mkold(pte_t pte)
  408. {
  409. unsigned long mask;
  410. __asm__ __volatile__(
  411. "\n661: mov %1, %0\n"
  412. " nop\n"
  413. " .section .sun4v_2insn_patch, \"ax\"\n"
  414. " .word 661b\n"
  415. " sethi %%uhi(%2), %0\n"
  416. " sllx %0, 32, %0\n"
  417. " .previous\n"
  418. : "=r" (mask)
  419. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  420. mask |= _PAGE_R;
  421. return __pte(pte_val(pte) & ~mask);
  422. }
  423. static inline pte_t pte_mkyoung(pte_t pte)
  424. {
  425. unsigned long mask;
  426. __asm__ __volatile__(
  427. "\n661: mov %1, %0\n"
  428. " nop\n"
  429. " .section .sun4v_2insn_patch, \"ax\"\n"
  430. " .word 661b\n"
  431. " sethi %%uhi(%2), %0\n"
  432. " sllx %0, 32, %0\n"
  433. " .previous\n"
  434. : "=r" (mask)
  435. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  436. mask |= _PAGE_R;
  437. return __pte(pte_val(pte) | mask);
  438. }
  439. static inline unsigned long pte_young(pte_t pte)
  440. {
  441. unsigned long mask;
  442. __asm__ __volatile__(
  443. "\n661: mov %1, %0\n"
  444. " nop\n"
  445. " .section .sun4v_2insn_patch, \"ax\"\n"
  446. " .word 661b\n"
  447. " sethi %%uhi(%2), %0\n"
  448. " sllx %0, 32, %0\n"
  449. " .previous\n"
  450. : "=r" (mask)
  451. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  452. return (pte_val(pte) & mask);
  453. }
  454. static inline unsigned long pte_dirty(pte_t pte)
  455. {
  456. unsigned long mask;
  457. __asm__ __volatile__(
  458. "\n661: mov %1, %0\n"
  459. " nop\n"
  460. " .section .sun4v_2insn_patch, \"ax\"\n"
  461. " .word 661b\n"
  462. " sethi %%uhi(%2), %0\n"
  463. " sllx %0, 32, %0\n"
  464. " .previous\n"
  465. : "=r" (mask)
  466. : "i" (_PAGE_MODIFIED_4U), "i" (_PAGE_MODIFIED_4V));
  467. return (pte_val(pte) & mask);
  468. }
  469. static inline unsigned long pte_write(pte_t pte)
  470. {
  471. unsigned long mask;
  472. __asm__ __volatile__(
  473. "\n661: mov %1, %0\n"
  474. " nop\n"
  475. " .section .sun4v_2insn_patch, \"ax\"\n"
  476. " .word 661b\n"
  477. " sethi %%uhi(%2), %0\n"
  478. " sllx %0, 32, %0\n"
  479. " .previous\n"
  480. : "=r" (mask)
  481. : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
  482. return (pte_val(pte) & mask);
  483. }
  484. static inline unsigned long pte_exec(pte_t pte)
  485. {
  486. unsigned long mask;
  487. __asm__ __volatile__(
  488. "\n661: sethi %%hi(%1), %0\n"
  489. " .section .sun4v_1insn_patch, \"ax\"\n"
  490. " .word 661b\n"
  491. " mov %2, %0\n"
  492. " .previous\n"
  493. : "=r" (mask)
  494. : "i" (_PAGE_EXEC_4U), "i" (_PAGE_EXEC_4V));
  495. return (pte_val(pte) & mask);
  496. }
  497. static inline unsigned long pte_file(pte_t pte)
  498. {
  499. unsigned long val = pte_val(pte);
  500. __asm__ __volatile__(
  501. "\n661: and %0, %2, %0\n"
  502. " .section .sun4v_1insn_patch, \"ax\"\n"
  503. " .word 661b\n"
  504. " and %0, %3, %0\n"
  505. " .previous\n"
  506. : "=r" (val)
  507. : "0" (val), "i" (_PAGE_FILE_4U), "i" (_PAGE_FILE_4V));
  508. return val;
  509. }
  510. static inline unsigned long pte_present(pte_t pte)
  511. {
  512. unsigned long val = pte_val(pte);
  513. __asm__ __volatile__(
  514. "\n661: and %0, %2, %0\n"
  515. " .section .sun4v_1insn_patch, \"ax\"\n"
  516. " .word 661b\n"
  517. " and %0, %3, %0\n"
  518. " .previous\n"
  519. : "=r" (val)
  520. : "0" (val), "i" (_PAGE_PRESENT_4U), "i" (_PAGE_PRESENT_4V));
  521. return val;
  522. }
  523. #define pmd_set(pmdp, ptep) \
  524. (pmd_val(*(pmdp)) = (__pa((unsigned long) (ptep)) >> 11UL))
  525. #define pud_set(pudp, pmdp) \
  526. (pud_val(*(pudp)) = (__pa((unsigned long) (pmdp)) >> 11UL))
  527. #define __pmd_page(pmd) \
  528. ((unsigned long) __va((((unsigned long)pmd_val(pmd))<<11UL)))
  529. #define pmd_page(pmd) virt_to_page((void *)__pmd_page(pmd))
  530. #define pud_page_vaddr(pud) \
  531. ((unsigned long) __va((((unsigned long)pud_val(pud))<<11UL)))
  532. #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
  533. #define pmd_none(pmd) (!pmd_val(pmd))
  534. #define pmd_bad(pmd) (0)
  535. #define pmd_present(pmd) (pmd_val(pmd) != 0U)
  536. #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0U)
  537. #define pud_none(pud) (!pud_val(pud))
  538. #define pud_bad(pud) (0)
  539. #define pud_present(pud) (pud_val(pud) != 0U)
  540. #define pud_clear(pudp) (pud_val(*(pudp)) = 0U)
  541. /* Same in both SUN4V and SUN4U. */
  542. #define pte_none(pte) (!pte_val(pte))
  543. /* to find an entry in a page-table-directory. */
  544. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
  545. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  546. /* to find an entry in a kernel page-table-directory */
  547. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  548. /* Find an entry in the second-level page table.. */
  549. #define pmd_offset(pudp, address) \
  550. ((pmd_t *) pud_page_vaddr(*(pudp)) + \
  551. (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)))
  552. /* Find an entry in the third-level page table.. */
  553. #define pte_index(dir, address) \
  554. ((pte_t *) __pmd_page(*(dir)) + \
  555. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
  556. #define pte_offset_kernel pte_index
  557. #define pte_offset_map pte_index
  558. #define pte_offset_map_nested pte_index
  559. #define pte_unmap(pte) do { } while (0)
  560. #define pte_unmap_nested(pte) do { } while (0)
  561. /* Actual page table PTE updates. */
  562. extern void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, pte_t *ptep, pte_t orig);
  563. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
  564. {
  565. pte_t orig = *ptep;
  566. *ptep = pte;
  567. /* It is more efficient to let flush_tlb_kernel_range()
  568. * handle init_mm tlb flushes.
  569. *
  570. * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U
  571. * and SUN4V pte layout, so this inline test is fine.
  572. */
  573. if (likely(mm != &init_mm) && (pte_val(orig) & _PAGE_VALID))
  574. tlb_batch_add(mm, addr, ptep, orig);
  575. }
  576. #define pte_clear(mm,addr,ptep) \
  577. set_pte_at((mm), (addr), (ptep), __pte(0UL))
  578. #ifdef DCACHE_ALIASING_POSSIBLE
  579. #define __HAVE_ARCH_MOVE_PTE
  580. #define move_pte(pte, prot, old_addr, new_addr) \
  581. ({ \
  582. pte_t newpte = (pte); \
  583. if (tlb_type != hypervisor && pte_present(pte)) { \
  584. unsigned long this_pfn = pte_pfn(pte); \
  585. \
  586. if (pfn_valid(this_pfn) && \
  587. (((old_addr) ^ (new_addr)) & (1 << 13))) \
  588. flush_dcache_page_all(current->mm, \
  589. pfn_to_page(this_pfn)); \
  590. } \
  591. newpte; \
  592. })
  593. #endif
  594. extern pgd_t swapper_pg_dir[2048];
  595. extern pmd_t swapper_low_pmd_dir[2048];
  596. extern void paging_init(void);
  597. extern unsigned long find_ecache_flush_span(unsigned long size);
  598. /* These do nothing with the way I have things setup. */
  599. #define mmu_lockarea(vaddr, len) (vaddr)
  600. #define mmu_unlockarea(vaddr, len) do { } while(0)
  601. struct vm_area_struct;
  602. extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
  603. /* Encode and de-code a swap entry */
  604. #define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0xffUL)
  605. #define __swp_offset(entry) ((entry).val >> (PAGE_SHIFT + 8UL))
  606. #define __swp_entry(type, offset) \
  607. ( (swp_entry_t) \
  608. { \
  609. (((long)(type) << PAGE_SHIFT) | \
  610. ((long)(offset) << (PAGE_SHIFT + 8UL))) \
  611. } )
  612. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  613. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  614. /* File offset in PTE support. */
  615. extern unsigned long pte_file(pte_t);
  616. #define pte_to_pgoff(pte) (pte_val(pte) >> PAGE_SHIFT)
  617. extern pte_t pgoff_to_pte(unsigned long);
  618. #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
  619. extern unsigned long *sparc64_valid_addr_bitmap;
  620. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  621. #define kern_addr_valid(addr) \
  622. (test_bit(__pa((unsigned long)(addr))>>22, sparc64_valid_addr_bitmap))
  623. extern int page_in_phys_avail(unsigned long paddr);
  624. extern int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
  625. unsigned long pfn,
  626. unsigned long size, pgprot_t prot);
  627. /*
  628. * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
  629. * its high 4 bits. These macros/functions put it there or get it from there.
  630. */
  631. #define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
  632. #define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
  633. #define GET_PFN(pfn) (pfn & 0x0fffffffffffffffUL)
  634. #include <asm-generic/pgtable.h>
  635. /* We provide our own get_unmapped_area to cope with VA holes and
  636. * SHM area cache aliasing for userland.
  637. */
  638. #define HAVE_ARCH_UNMAPPED_AREA
  639. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  640. /* We provide a special get_unmapped_area for framebuffer mmaps to try and use
  641. * the largest alignment possible such that larget PTEs can be used.
  642. */
  643. extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
  644. unsigned long, unsigned long,
  645. unsigned long);
  646. #define HAVE_ARCH_FB_UNMAPPED_AREA
  647. extern void pgtable_cache_init(void);
  648. extern void sun4v_register_fault_status(void);
  649. extern void sun4v_ktsb_register(void);
  650. extern unsigned long cmdline_memory_size;
  651. #endif /* !(__ASSEMBLY__) */
  652. #endif /* !(_SPARC64_PGTABLE_H) */