pgtable.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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/config.h>
  14. #include <linux/compiler.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. #include <asm/const.h>
  22. /* The kernel image occupies 0x4000000 to 0x1000000 (4MB --> 32MB).
  23. * The page copy blockops can use 0x2000000 to 0x4000000.
  24. * The TSB is mapped in the 0x4000000 to 0x6000000 range.
  25. * The PROM resides in an area spanning 0xf0000000 to 0x100000000.
  26. * The vmalloc area spans 0x100000000 to 0x200000000.
  27. * Since modules need to be in the lowest 32-bits of the address space,
  28. * we place them right before the OBP area from 0x10000000 to 0xf0000000.
  29. * There is a single static kernel PMD which maps from 0x0 to address
  30. * 0x400000000.
  31. */
  32. #define TLBTEMP_BASE _AC(0x0000000002000000,UL)
  33. #define TSBMAP_BASE _AC(0x0000000004000000,UL)
  34. #define MODULES_VADDR _AC(0x0000000010000000,UL)
  35. #define MODULES_LEN _AC(0x00000000e0000000,UL)
  36. #define MODULES_END _AC(0x00000000f0000000,UL)
  37. #define LOW_OBP_ADDRESS _AC(0x00000000f0000000,UL)
  38. #define HI_OBP_ADDRESS _AC(0x0000000100000000,UL)
  39. #define VMALLOC_START _AC(0x0000000100000000,UL)
  40. #define VMALLOC_END _AC(0x0000000200000000,UL)
  41. /* XXX All of this needs to be rethought so we can take advantage
  42. * XXX cheetah's full 64-bit virtual address space, ie. no more hole
  43. * XXX in the middle like on spitfire. -DaveM
  44. */
  45. /*
  46. * Given a virtual address, the lowest PAGE_SHIFT bits determine offset
  47. * into the page; the next higher PAGE_SHIFT-3 bits determine the pte#
  48. * in the proper pagetable (the -3 is from the 8 byte ptes, and each page
  49. * table is a single page long). The next higher PMD_BITS determine pmd#
  50. * in the proper pmdtable (where we must have PMD_BITS <= (PAGE_SHIFT-2)
  51. * since the pmd entries are 4 bytes, and each pmd page is a single page
  52. * long). Finally, the higher few bits determine pgde#.
  53. */
  54. /* PMD_SHIFT determines the size of the area a second-level page
  55. * table can map
  56. */
  57. #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
  58. #define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
  59. #define PMD_MASK (~(PMD_SIZE-1))
  60. #define PMD_BITS (PAGE_SHIFT - 2)
  61. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  62. #define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3) + PMD_BITS)
  63. #define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
  64. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  65. #define PGDIR_BITS (PAGE_SHIFT - 2)
  66. #ifndef __ASSEMBLY__
  67. #include <linux/sched.h>
  68. /* Entries per page directory level. */
  69. #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
  70. #define PTRS_PER_PMD (1UL << PMD_BITS)
  71. #define PTRS_PER_PGD (1UL << PGDIR_BITS)
  72. /* Kernel has a separate 44bit address space. */
  73. #define FIRST_USER_ADDRESS 0
  74. #define pte_ERROR(e) __builtin_trap()
  75. #define pmd_ERROR(e) __builtin_trap()
  76. #define pgd_ERROR(e) __builtin_trap()
  77. #endif /* !(__ASSEMBLY__) */
  78. /* PTE bits which are the same in SUN4U and SUN4V format. */
  79. #define _PAGE_VALID _AC(0x8000000000000000,UL) /* Valid TTE */
  80. #define _PAGE_R _AC(0x8000000000000000,UL) /* Keep ref bit uptodate*/
  81. /* SUN4U pte bits... */
  82. #define _PAGE_SZ4MB_4U _AC(0x6000000000000000,UL) /* 4MB Page */
  83. #define _PAGE_SZ512K_4U _AC(0x4000000000000000,UL) /* 512K Page */
  84. #define _PAGE_SZ64K_4U _AC(0x2000000000000000,UL) /* 64K Page */
  85. #define _PAGE_SZ8K_4U _AC(0x0000000000000000,UL) /* 8K Page */
  86. #define _PAGE_NFO_4U _AC(0x1000000000000000,UL) /* No Fault Only */
  87. #define _PAGE_IE_4U _AC(0x0800000000000000,UL) /* Invert Endianness */
  88. #define _PAGE_SOFT2_4U _AC(0x07FC000000000000,UL) /* Software bits, set 2 */
  89. #define _PAGE_RES1_4U _AC(0x0002000000000000,UL) /* Reserved */
  90. #define _PAGE_SZ32MB_4U _AC(0x0001000000000000,UL) /* (Panther) 32MB page */
  91. #define _PAGE_SZ256MB_4U _AC(0x2001000000000000,UL) /* (Panther) 256MB page */
  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. #if PAGE_SHIFT == 13
  137. #define _PAGE_SZBITS_4U _PAGE_SZ8K_4U
  138. #define _PAGE_SZBITS_4V _PAGE_SZ8K_4V
  139. #elif PAGE_SHIFT == 16
  140. #define _PAGE_SZBITS_4U _PAGE_SZ64K_4U
  141. #define _PAGE_SZBITS_4V _PAGE_SZ64K_4V
  142. #elif PAGE_SHIFT == 19
  143. #define _PAGE_SZBITS_4U _PAGE_SZ512K_4U
  144. #define _PAGE_SZBITS_4V _PAGE_SZ512K_4V
  145. #elif PAGE_SHIFT == 22
  146. #define _PAGE_SZBITS_4U _PAGE_SZ4MB_4U
  147. #define _PAGE_SZBITS_4V _PAGE_SZ4MB_4V
  148. #else
  149. #error Wrong PAGE_SHIFT specified
  150. #endif
  151. #if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
  152. #define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U
  153. #define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V
  154. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
  155. #define _PAGE_SZHUGE_4U _PAGE_SZ512K_4U
  156. #define _PAGE_SZHUGE_4V _PAGE_SZ512K_4V
  157. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
  158. #define _PAGE_SZHUGE_4U _PAGE_SZ64K_4U
  159. #define _PAGE_SZHUGE_4V _PAGE_SZ64K_4V
  160. #endif
  161. /* These are actually filled in at boot time by sun4{u,v}_pgprot_init() */
  162. #define __P000 __pgprot(0)
  163. #define __P001 __pgprot(0)
  164. #define __P010 __pgprot(0)
  165. #define __P011 __pgprot(0)
  166. #define __P100 __pgprot(0)
  167. #define __P101 __pgprot(0)
  168. #define __P110 __pgprot(0)
  169. #define __P111 __pgprot(0)
  170. #define __S000 __pgprot(0)
  171. #define __S001 __pgprot(0)
  172. #define __S010 __pgprot(0)
  173. #define __S011 __pgprot(0)
  174. #define __S100 __pgprot(0)
  175. #define __S101 __pgprot(0)
  176. #define __S110 __pgprot(0)
  177. #define __S111 __pgprot(0)
  178. #ifndef __ASSEMBLY__
  179. extern pte_t mk_pte_io(unsigned long, pgprot_t, int, unsigned long);
  180. extern unsigned long pte_sz_bits(unsigned long size);
  181. extern pgprot_t PAGE_KERNEL;
  182. extern pgprot_t PAGE_KERNEL_LOCKED;
  183. extern pgprot_t PAGE_COPY;
  184. /* XXX This uglyness is for the atyfb driver's sparc mmap() support. XXX */
  185. extern unsigned long _PAGE_IE;
  186. extern unsigned long _PAGE_E;
  187. extern unsigned long _PAGE_CACHE;
  188. extern unsigned long pg_iobits;
  189. extern unsigned long _PAGE_ALL_SZ_BITS;
  190. extern unsigned long _PAGE_SZBITS;
  191. extern unsigned long phys_base;
  192. extern unsigned long pfn_base;
  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, %3, %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. static inline pte_t pte_mkhuge(pte_t pte)
  313. {
  314. unsigned long mask;
  315. __asm__ __volatile__(
  316. "\n661: sethi %%uhi(%1), %0\n"
  317. " sllx %0, 32, %0\n"
  318. " .section .sun4v_2insn_patch, \"ax\"\n"
  319. " .word 661b\n"
  320. " mov %2, %0\n"
  321. " nop\n"
  322. " .previous\n"
  323. : "=r" (mask)
  324. : "i" (_PAGE_SZHUGE_4U), "i" (_PAGE_SZHUGE_4V));
  325. return __pte(pte_val(pte) | mask);
  326. }
  327. static inline pte_t pte_mkdirty(pte_t pte)
  328. {
  329. unsigned long val = pte_val(pte), tmp;
  330. __asm__ __volatile__(
  331. "\n661: or %0, %3, %0\n"
  332. " nop\n"
  333. "\n662: nop\n"
  334. " nop\n"
  335. " .section .sun4v_2insn_patch, \"ax\"\n"
  336. " .word 661b\n"
  337. " sethi %%uhi(%4), %1\n"
  338. " sllx %1, 32, %1\n"
  339. " .word 662b\n"
  340. " or %1, %%lo(%4), %1\n"
  341. " or %0, %1, %0\n"
  342. " .previous\n"
  343. : "=r" (val), "=r" (tmp)
  344. : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
  345. "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
  346. return __pte(val);
  347. }
  348. static inline pte_t pte_mkclean(pte_t pte)
  349. {
  350. unsigned long val = pte_val(pte), tmp;
  351. __asm__ __volatile__(
  352. "\n661: andn %0, %3, %0\n"
  353. " nop\n"
  354. "\n662: nop\n"
  355. " nop\n"
  356. " .section .sun4v_2insn_patch, \"ax\"\n"
  357. " .word 661b\n"
  358. " sethi %%uhi(%4), %1\n"
  359. " sllx %1, 32, %1\n"
  360. " .word 662b\n"
  361. " or %1, %%lo(%4), %1\n"
  362. " andn %0, %1, %0\n"
  363. " .previous\n"
  364. : "=r" (val), "=r" (tmp)
  365. : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
  366. "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
  367. return __pte(val);
  368. }
  369. static inline pte_t pte_mkwrite(pte_t pte)
  370. {
  371. unsigned long val = pte_val(pte), mask;
  372. __asm__ __volatile__(
  373. "\n661: mov %1, %0\n"
  374. " nop\n"
  375. " .section .sun4v_2insn_patch, \"ax\"\n"
  376. " .word 661b\n"
  377. " sethi %%uhi(%2), %0\n"
  378. " sllx %0, 32, %0\n"
  379. " .previous\n"
  380. : "=r" (mask)
  381. : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
  382. return __pte(val | mask);
  383. }
  384. static inline pte_t pte_wrprotect(pte_t pte)
  385. {
  386. unsigned long val = pte_val(pte), tmp;
  387. __asm__ __volatile__(
  388. "\n661: andn %0, %3, %0\n"
  389. " nop\n"
  390. "\n662: nop\n"
  391. " nop\n"
  392. " .section .sun4v_2insn_patch, \"ax\"\n"
  393. " .word 661b\n"
  394. " sethi %%uhi(%4), %1\n"
  395. " sllx %1, 32, %1\n"
  396. " .word 662b\n"
  397. " or %1, %%lo(%4), %1\n"
  398. " andn %0, %1, %0\n"
  399. " .previous\n"
  400. : "=r" (val), "=r" (tmp)
  401. : "0" (val), "i" (_PAGE_WRITE_4U | _PAGE_W_4U),
  402. "i" (_PAGE_WRITE_4V | _PAGE_W_4V));
  403. return __pte(val);
  404. }
  405. static inline pte_t pte_mkold(pte_t pte)
  406. {
  407. unsigned long mask;
  408. __asm__ __volatile__(
  409. "\n661: mov %1, %0\n"
  410. " nop\n"
  411. " .section .sun4v_2insn_patch, \"ax\"\n"
  412. " .word 661b\n"
  413. " sethi %%uhi(%2), %0\n"
  414. " sllx %0, 32, %0\n"
  415. " .previous\n"
  416. : "=r" (mask)
  417. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  418. mask |= _PAGE_R;
  419. return __pte(pte_val(pte) & ~mask);
  420. }
  421. static inline pte_t pte_mkyoung(pte_t pte)
  422. {
  423. unsigned long mask;
  424. __asm__ __volatile__(
  425. "\n661: mov %1, %0\n"
  426. " nop\n"
  427. " .section .sun4v_2insn_patch, \"ax\"\n"
  428. " .word 661b\n"
  429. " sethi %%uhi(%2), %0\n"
  430. " sllx %0, 32, %0\n"
  431. " .previous\n"
  432. : "=r" (mask)
  433. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  434. mask |= _PAGE_R;
  435. return __pte(pte_val(pte) | mask);
  436. }
  437. static inline unsigned long pte_young(pte_t pte)
  438. {
  439. unsigned long mask;
  440. __asm__ __volatile__(
  441. "\n661: mov %1, %0\n"
  442. " nop\n"
  443. " .section .sun4v_2insn_patch, \"ax\"\n"
  444. " .word 661b\n"
  445. " sethi %%uhi(%2), %0\n"
  446. " sllx %0, 32, %0\n"
  447. " .previous\n"
  448. : "=r" (mask)
  449. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  450. return (pte_val(pte) & mask);
  451. }
  452. static inline unsigned long pte_dirty(pte_t pte)
  453. {
  454. unsigned long mask;
  455. __asm__ __volatile__(
  456. "\n661: mov %1, %0\n"
  457. " nop\n"
  458. " .section .sun4v_2insn_patch, \"ax\"\n"
  459. " .word 661b\n"
  460. " sethi %%uhi(%2), %0\n"
  461. " sllx %0, 32, %0\n"
  462. " .previous\n"
  463. : "=r" (mask)
  464. : "i" (_PAGE_MODIFIED_4U), "i" (_PAGE_MODIFIED_4V));
  465. return (pte_val(pte) & mask);
  466. }
  467. static inline unsigned long pte_write(pte_t pte)
  468. {
  469. unsigned long mask;
  470. __asm__ __volatile__(
  471. "\n661: mov %1, %0\n"
  472. " nop\n"
  473. " .section .sun4v_2insn_patch, \"ax\"\n"
  474. " .word 661b\n"
  475. " sethi %%uhi(%2), %0\n"
  476. " sllx %0, 32, %0\n"
  477. " .previous\n"
  478. : "=r" (mask)
  479. : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
  480. return (pte_val(pte) & mask);
  481. }
  482. static inline unsigned long pte_exec(pte_t pte)
  483. {
  484. unsigned long mask;
  485. __asm__ __volatile__(
  486. "\n661: sethi %%hi(%1), %0\n"
  487. " .section .sun4v_1insn_patch, \"ax\"\n"
  488. " .word 661b\n"
  489. " mov %2, %0\n"
  490. " .previous\n"
  491. : "=r" (mask)
  492. : "i" (_PAGE_EXEC_4U), "i" (_PAGE_EXEC_4V));
  493. return (pte_val(pte) & mask);
  494. }
  495. static inline unsigned long pte_read(pte_t pte)
  496. {
  497. unsigned long mask;
  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_READ_4U), "i" (_PAGE_READ_4V));
  508. return (pte_val(pte) & mask);
  509. }
  510. static inline unsigned long pte_file(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_FILE_4U), "i" (_PAGE_FILE_4V));
  521. return val;
  522. }
  523. static inline unsigned long pte_present(pte_t pte)
  524. {
  525. unsigned long val = pte_val(pte);
  526. __asm__ __volatile__(
  527. "\n661: and %0, %2, %0\n"
  528. " .section .sun4v_1insn_patch, \"ax\"\n"
  529. " .word 661b\n"
  530. " and %0, %3, %0\n"
  531. " .previous\n"
  532. : "=r" (val)
  533. : "0" (val), "i" (_PAGE_PRESENT_4U), "i" (_PAGE_PRESENT_4V));
  534. return val;
  535. }
  536. #define pmd_set(pmdp, ptep) \
  537. (pmd_val(*(pmdp)) = (__pa((unsigned long) (ptep)) >> 11UL))
  538. #define pud_set(pudp, pmdp) \
  539. (pud_val(*(pudp)) = (__pa((unsigned long) (pmdp)) >> 11UL))
  540. #define __pmd_page(pmd) \
  541. ((unsigned long) __va((((unsigned long)pmd_val(pmd))<<11UL)))
  542. #define pmd_page(pmd) virt_to_page((void *)__pmd_page(pmd))
  543. #define pud_page(pud) \
  544. ((unsigned long) __va((((unsigned long)pud_val(pud))<<11UL)))
  545. #define pmd_none(pmd) (!pmd_val(pmd))
  546. #define pmd_bad(pmd) (0)
  547. #define pmd_present(pmd) (pmd_val(pmd) != 0U)
  548. #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0U)
  549. #define pud_none(pud) (!pud_val(pud))
  550. #define pud_bad(pud) (0)
  551. #define pud_present(pud) (pud_val(pud) != 0U)
  552. #define pud_clear(pudp) (pud_val(*(pudp)) = 0U)
  553. /* Same in both SUN4V and SUN4U. */
  554. #define pte_none(pte) (!pte_val(pte))
  555. extern unsigned long pte_present(pte_t);
  556. /* The following only work if pte_present() is true.
  557. * Undefined behaviour if not..
  558. */
  559. extern unsigned long pte_read(pte_t);
  560. extern unsigned long pte_exec(pte_t);
  561. extern unsigned long pte_write(pte_t);
  562. extern unsigned long pte_dirty(pte_t);
  563. extern unsigned long pte_young(pte_t);
  564. extern pte_t pte_wrprotect(pte_t);
  565. extern pte_t pte_rdprotect(pte_t);
  566. extern pte_t pte_mkclean(pte_t);
  567. extern pte_t pte_mkold(pte_t);
  568. /* Be very careful when you change these three, they are delicate. */
  569. extern pte_t pte_mkyoung(pte_t);
  570. extern pte_t pte_mkwrite(pte_t);
  571. extern pte_t pte_mkdirty(pte_t);
  572. extern pte_t pte_mkhuge(pte_t);
  573. /* to find an entry in a page-table-directory. */
  574. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
  575. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  576. /* to find an entry in a kernel page-table-directory */
  577. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  578. /* Find an entry in the second-level page table.. */
  579. #define pmd_offset(pudp, address) \
  580. ((pmd_t *) pud_page(*(pudp)) + \
  581. (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)))
  582. /* Find an entry in the third-level page table.. */
  583. #define pte_index(dir, address) \
  584. ((pte_t *) __pmd_page(*(dir)) + \
  585. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
  586. #define pte_offset_kernel pte_index
  587. #define pte_offset_map pte_index
  588. #define pte_offset_map_nested pte_index
  589. #define pte_unmap(pte) do { } while (0)
  590. #define pte_unmap_nested(pte) do { } while (0)
  591. /* Actual page table PTE updates. */
  592. extern void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr, pte_t *ptep, pte_t orig);
  593. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
  594. {
  595. pte_t orig = *ptep;
  596. *ptep = pte;
  597. /* It is more efficient to let flush_tlb_kernel_range()
  598. * handle init_mm tlb flushes.
  599. *
  600. * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U
  601. * and SUN4V pte layout, so this inline test is fine.
  602. */
  603. if (likely(mm != &init_mm) && (pte_val(orig) & _PAGE_VALID))
  604. tlb_batch_add(mm, addr, ptep, orig);
  605. }
  606. #define pte_clear(mm,addr,ptep) \
  607. set_pte_at((mm), (addr), (ptep), __pte(0UL))
  608. extern pgd_t swapper_pg_dir[2048];
  609. extern pmd_t swapper_low_pmd_dir[2048];
  610. extern void paging_init(void);
  611. extern unsigned long find_ecache_flush_span(unsigned long size);
  612. /* These do nothing with the way I have things setup. */
  613. #define mmu_lockarea(vaddr, len) (vaddr)
  614. #define mmu_unlockarea(vaddr, len) do { } while(0)
  615. struct vm_area_struct;
  616. extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
  617. /* Encode and de-code a swap entry */
  618. #define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0xffUL)
  619. #define __swp_offset(entry) ((entry).val >> (PAGE_SHIFT + 8UL))
  620. #define __swp_entry(type, offset) \
  621. ( (swp_entry_t) \
  622. { \
  623. (((long)(type) << PAGE_SHIFT) | \
  624. ((long)(offset) << (PAGE_SHIFT + 8UL))) \
  625. } )
  626. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  627. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  628. /* File offset in PTE support. */
  629. extern unsigned long pte_file(pte_t);
  630. #define pte_to_pgoff(pte) (pte_val(pte) >> PAGE_SHIFT)
  631. extern pte_t pgoff_to_pte(unsigned long);
  632. #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
  633. extern unsigned long prom_virt_to_phys(unsigned long, int *);
  634. extern unsigned long sun4u_get_pte(unsigned long);
  635. static inline unsigned long __get_phys(unsigned long addr)
  636. {
  637. return sun4u_get_pte(addr);
  638. }
  639. static inline int __get_iospace(unsigned long addr)
  640. {
  641. return ((sun4u_get_pte(addr) & 0xf0000000) >> 28);
  642. }
  643. extern unsigned long *sparc64_valid_addr_bitmap;
  644. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  645. #define kern_addr_valid(addr) \
  646. (test_bit(__pa((unsigned long)(addr))>>22, sparc64_valid_addr_bitmap))
  647. extern int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
  648. unsigned long pfn,
  649. unsigned long size, pgprot_t prot);
  650. /* Clear virtual and physical cachability, set side-effect bit. */
  651. extern pgprot_t pgprot_noncached(pgprot_t);
  652. /*
  653. * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
  654. * its high 4 bits. These macros/functions put it there or get it from there.
  655. */
  656. #define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
  657. #define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
  658. #define GET_PFN(pfn) (pfn & 0x0fffffffffffffffUL)
  659. #include <asm-generic/pgtable.h>
  660. /* We provide our own get_unmapped_area to cope with VA holes for userland */
  661. #define HAVE_ARCH_UNMAPPED_AREA
  662. /* We provide a special get_unmapped_area for framebuffer mmaps to try and use
  663. * the largest alignment possible such that larget PTEs can be used.
  664. */
  665. extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
  666. unsigned long, unsigned long,
  667. unsigned long);
  668. #define HAVE_ARCH_FB_UNMAPPED_AREA
  669. extern void pgtable_cache_init(void);
  670. extern void sun4v_register_fault_status(void);
  671. extern void sun4v_ktsb_register(void);
  672. #endif /* !(__ASSEMBLY__) */
  673. #endif /* !(_SPARC64_PGTABLE_H) */