pgtable.h 24 KB

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