pgtable_64.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. /*
  2. * pgtable.h: SpitFire page table operations.
  3. *
  4. * Copyright 1996,1997 David S. Miller ([email protected])
  5. * Copyright 1997,1998 Jakub Jelinek ([email protected])
  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 <linux/compiler.h>
  13. #include <linux/const.h>
  14. #include <asm/types.h>
  15. #include <asm/spitfire.h>
  16. #include <asm/asi.h>
  17. #include <asm/page.h>
  18. #include <asm/processor.h>
  19. /* The kernel image occupies 0x4000000 to 0x6000000 (4MB --> 96MB).
  20. * The page copy blockops can use 0x6000000 to 0x8000000.
  21. * The 8K TSB is mapped in the 0x8000000 to 0x8400000 range.
  22. * The 4M TSB is mapped in the 0x8400000 to 0x8800000 range.
  23. * The PROM resides in an area spanning 0xf0000000 to 0x100000000.
  24. * The vmalloc area spans 0x100000000 to 0x200000000.
  25. * Since modules need to be in the lowest 32-bits of the address space,
  26. * we place them right before the OBP area from 0x10000000 to 0xf0000000.
  27. * There is a single static kernel PMD which maps from 0x0 to address
  28. * 0x400000000.
  29. */
  30. #define TLBTEMP_BASE _AC(0x0000000006000000,UL)
  31. #define TSBMAP_8K_BASE _AC(0x0000000008000000,UL)
  32. #define TSBMAP_4M_BASE _AC(0x0000000008400000,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 VMEMMAP_BASE VMALLOC_END
  40. /* PMD_SHIFT determines the size of the area a second-level page
  41. * table can map
  42. */
  43. #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
  44. #define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
  45. #define PMD_MASK (~(PMD_SIZE-1))
  46. #define PMD_BITS (PAGE_SHIFT - 3)
  47. /* PUD_SHIFT determines the size of the area a third-level page
  48. * table can map
  49. */
  50. #define PUD_SHIFT (PMD_SHIFT + PMD_BITS)
  51. #define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
  52. #define PUD_MASK (~(PUD_SIZE-1))
  53. #define PUD_BITS (PAGE_SHIFT - 3)
  54. /* PGDIR_SHIFT determines what a fourth-level page table entry can map */
  55. #define PGDIR_SHIFT (PUD_SHIFT + PUD_BITS)
  56. #define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
  57. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  58. #define PGDIR_BITS (PAGE_SHIFT - 3)
  59. #if (MAX_PHYS_ADDRESS_BITS > PGDIR_SHIFT + PGDIR_BITS)
  60. #error MAX_PHYS_ADDRESS_BITS exceeds what kernel page tables can support
  61. #endif
  62. #if (PGDIR_SHIFT + PGDIR_BITS) != 53
  63. #error Page table parameters do not cover virtual address space properly.
  64. #endif
  65. #if (PMD_SHIFT != HPAGE_SHIFT)
  66. #error PMD_SHIFT must equal HPAGE_SHIFT for transparent huge pages.
  67. #endif
  68. #ifndef __ASSEMBLY__
  69. extern unsigned long VMALLOC_END;
  70. #define vmemmap ((struct page *)VMEMMAP_BASE)
  71. #include <linux/sched.h>
  72. bool kern_addr_valid(unsigned long addr);
  73. /* Entries per page directory level. */
  74. #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
  75. #define PTRS_PER_PMD (1UL << PMD_BITS)
  76. #define PTRS_PER_PUD (1UL << PUD_BITS)
  77. #define PTRS_PER_PGD (1UL << PGDIR_BITS)
  78. /* Kernel has a separate 44bit address space. */
  79. #define FIRST_USER_ADDRESS 0UL
  80. #define pmd_ERROR(e) \
  81. pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \
  82. __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
  83. #define pud_ERROR(e) \
  84. pr_err("%s:%d: bad pud %p(%016lx) seen at (%pS)\n", \
  85. __FILE__, __LINE__, &(e), pud_val(e), __builtin_return_address(0))
  86. #define pgd_ERROR(e) \
  87. pr_err("%s:%d: bad pgd %p(%016lx) seen at (%pS)\n", \
  88. __FILE__, __LINE__, &(e), pgd_val(e), __builtin_return_address(0))
  89. #endif /* !(__ASSEMBLY__) */
  90. /* PTE bits which are the same in SUN4U and SUN4V format. */
  91. #define _PAGE_VALID _AC(0x8000000000000000,UL) /* Valid TTE */
  92. #define _PAGE_R _AC(0x8000000000000000,UL) /* Keep ref bit uptodate*/
  93. #define _PAGE_SPECIAL _AC(0x0200000000000000,UL) /* Special page */
  94. #define _PAGE_PMD_HUGE _AC(0x0100000000000000,UL) /* Huge page */
  95. #define _PAGE_PUD_HUGE _PAGE_PMD_HUGE
  96. /* Advertise support for _PAGE_SPECIAL */
  97. #define __HAVE_ARCH_PTE_SPECIAL
  98. /* SUN4U pte bits... */
  99. #define _PAGE_SZ4MB_4U _AC(0x6000000000000000,UL) /* 4MB Page */
  100. #define _PAGE_SZ512K_4U _AC(0x4000000000000000,UL) /* 512K Page */
  101. #define _PAGE_SZ64K_4U _AC(0x2000000000000000,UL) /* 64K Page */
  102. #define _PAGE_SZ8K_4U _AC(0x0000000000000000,UL) /* 8K Page */
  103. #define _PAGE_NFO_4U _AC(0x1000000000000000,UL) /* No Fault Only */
  104. #define _PAGE_IE_4U _AC(0x0800000000000000,UL) /* Invert Endianness */
  105. #define _PAGE_SOFT2_4U _AC(0x07FC000000000000,UL) /* Software bits, set 2 */
  106. #define _PAGE_SPECIAL_4U _AC(0x0200000000000000,UL) /* Special page */
  107. #define _PAGE_PMD_HUGE_4U _AC(0x0100000000000000,UL) /* Huge page */
  108. #define _PAGE_RES1_4U _AC(0x0002000000000000,UL) /* Reserved */
  109. #define _PAGE_SZ32MB_4U _AC(0x0001000000000000,UL) /* (Panther) 32MB page */
  110. #define _PAGE_SZ256MB_4U _AC(0x2001000000000000,UL) /* (Panther) 256MB page */
  111. #define _PAGE_SZALL_4U _AC(0x6001000000000000,UL) /* All pgsz bits */
  112. #define _PAGE_SN_4U _AC(0x0000800000000000,UL) /* (Cheetah) Snoop */
  113. #define _PAGE_RES2_4U _AC(0x0000780000000000,UL) /* Reserved */
  114. #define _PAGE_PADDR_4U _AC(0x000007FFFFFFE000,UL) /* (Cheetah) pa[42:13] */
  115. #define _PAGE_SOFT_4U _AC(0x0000000000001F80,UL) /* Software bits: */
  116. #define _PAGE_EXEC_4U _AC(0x0000000000001000,UL) /* Executable SW bit */
  117. #define _PAGE_MODIFIED_4U _AC(0x0000000000000800,UL) /* Modified (dirty) */
  118. #define _PAGE_ACCESSED_4U _AC(0x0000000000000400,UL) /* Accessed (ref'd) */
  119. #define _PAGE_READ_4U _AC(0x0000000000000200,UL) /* Readable SW Bit */
  120. #define _PAGE_WRITE_4U _AC(0x0000000000000100,UL) /* Writable SW Bit */
  121. #define _PAGE_PRESENT_4U _AC(0x0000000000000080,UL) /* Present */
  122. #define _PAGE_L_4U _AC(0x0000000000000040,UL) /* Locked TTE */
  123. #define _PAGE_CP_4U _AC(0x0000000000000020,UL) /* Cacheable in P-Cache */
  124. #define _PAGE_CV_4U _AC(0x0000000000000010,UL) /* Cacheable in V-Cache */
  125. #define _PAGE_E_4U _AC(0x0000000000000008,UL) /* side-Effect */
  126. #define _PAGE_P_4U _AC(0x0000000000000004,UL) /* Privileged Page */
  127. #define _PAGE_W_4U _AC(0x0000000000000002,UL) /* Writable */
  128. /* SUN4V pte bits... */
  129. #define _PAGE_NFO_4V _AC(0x4000000000000000,UL) /* No Fault Only */
  130. #define _PAGE_SOFT2_4V _AC(0x3F00000000000000,UL) /* Software bits, set 2 */
  131. #define _PAGE_MODIFIED_4V _AC(0x2000000000000000,UL) /* Modified (dirty) */
  132. #define _PAGE_ACCESSED_4V _AC(0x1000000000000000,UL) /* Accessed (ref'd) */
  133. #define _PAGE_READ_4V _AC(0x0800000000000000,UL) /* Readable SW Bit */
  134. #define _PAGE_WRITE_4V _AC(0x0400000000000000,UL) /* Writable SW Bit */
  135. #define _PAGE_SPECIAL_4V _AC(0x0200000000000000,UL) /* Special page */
  136. #define _PAGE_PMD_HUGE_4V _AC(0x0100000000000000,UL) /* Huge page */
  137. #define _PAGE_PADDR_4V _AC(0x00FFFFFFFFFFE000,UL) /* paddr[55:13] */
  138. #define _PAGE_IE_4V _AC(0x0000000000001000,UL) /* Invert Endianness */
  139. #define _PAGE_E_4V _AC(0x0000000000000800,UL) /* side-Effect */
  140. #define _PAGE_CP_4V _AC(0x0000000000000400,UL) /* Cacheable in P-Cache */
  141. #define _PAGE_CV_4V _AC(0x0000000000000200,UL) /* Cacheable in V-Cache */
  142. #define _PAGE_P_4V _AC(0x0000000000000100,UL) /* Privileged Page */
  143. #define _PAGE_EXEC_4V _AC(0x0000000000000080,UL) /* Executable Page */
  144. #define _PAGE_W_4V _AC(0x0000000000000040,UL) /* Writable */
  145. #define _PAGE_SOFT_4V _AC(0x0000000000000030,UL) /* Software bits */
  146. #define _PAGE_PRESENT_4V _AC(0x0000000000000010,UL) /* Present */
  147. #define _PAGE_RESV_4V _AC(0x0000000000000008,UL) /* Reserved */
  148. #define _PAGE_SZ16GB_4V _AC(0x0000000000000007,UL) /* 16GB Page */
  149. #define _PAGE_SZ2GB_4V _AC(0x0000000000000006,UL) /* 2GB Page */
  150. #define _PAGE_SZ256MB_4V _AC(0x0000000000000005,UL) /* 256MB Page */
  151. #define _PAGE_SZ32MB_4V _AC(0x0000000000000004,UL) /* 32MB Page */
  152. #define _PAGE_SZ4MB_4V _AC(0x0000000000000003,UL) /* 4MB Page */
  153. #define _PAGE_SZ512K_4V _AC(0x0000000000000002,UL) /* 512K Page */
  154. #define _PAGE_SZ64K_4V _AC(0x0000000000000001,UL) /* 64K Page */
  155. #define _PAGE_SZ8K_4V _AC(0x0000000000000000,UL) /* 8K Page */
  156. #define _PAGE_SZALL_4V _AC(0x0000000000000007,UL) /* All pgsz bits */
  157. #define _PAGE_SZBITS_4U _PAGE_SZ8K_4U
  158. #define _PAGE_SZBITS_4V _PAGE_SZ8K_4V
  159. #if REAL_HPAGE_SHIFT != 22
  160. #error REAL_HPAGE_SHIFT and _PAGE_SZHUGE_foo must match up
  161. #endif
  162. #define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U
  163. #define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V
  164. /* These are actually filled in at boot time by sun4{u,v}_pgprot_init() */
  165. #define __P000 __pgprot(0)
  166. #define __P001 __pgprot(0)
  167. #define __P010 __pgprot(0)
  168. #define __P011 __pgprot(0)
  169. #define __P100 __pgprot(0)
  170. #define __P101 __pgprot(0)
  171. #define __P110 __pgprot(0)
  172. #define __P111 __pgprot(0)
  173. #define __S000 __pgprot(0)
  174. #define __S001 __pgprot(0)
  175. #define __S010 __pgprot(0)
  176. #define __S011 __pgprot(0)
  177. #define __S100 __pgprot(0)
  178. #define __S101 __pgprot(0)
  179. #define __S110 __pgprot(0)
  180. #define __S111 __pgprot(0)
  181. #ifndef __ASSEMBLY__
  182. pte_t mk_pte_io(unsigned long, pgprot_t, int, unsigned long);
  183. unsigned long pte_sz_bits(unsigned long size);
  184. extern pgprot_t PAGE_KERNEL;
  185. extern pgprot_t PAGE_KERNEL_LOCKED;
  186. extern pgprot_t PAGE_COPY;
  187. extern pgprot_t PAGE_SHARED;
  188. /* XXX This ugliness is for the atyfb driver's sparc mmap() support. XXX */
  189. extern unsigned long _PAGE_IE;
  190. extern unsigned long _PAGE_E;
  191. extern unsigned long _PAGE_CACHE;
  192. extern unsigned long pg_iobits;
  193. extern unsigned long _PAGE_ALL_SZ_BITS;
  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. BUILD_BUG_ON(_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL);
  205. return __pte(paddr | pgprot_val(prot));
  206. }
  207. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  208. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  209. static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
  210. {
  211. pte_t pte = pfn_pte(page_nr, pgprot);
  212. return __pmd(pte_val(pte));
  213. }
  214. #define mk_pmd(page, pgprot) pfn_pmd(page_to_pfn(page), (pgprot))
  215. #endif
  216. /* This one can be done with two shifts. */
  217. static inline unsigned long pte_pfn(pte_t pte)
  218. {
  219. unsigned long ret;
  220. __asm__ __volatile__(
  221. "\n661: sllx %1, %2, %0\n"
  222. " srlx %0, %3, %0\n"
  223. " .section .sun4v_2insn_patch, \"ax\"\n"
  224. " .word 661b\n"
  225. " sllx %1, %4, %0\n"
  226. " srlx %0, %5, %0\n"
  227. " .previous\n"
  228. : "=r" (ret)
  229. : "r" (pte_val(pte)),
  230. "i" (21), "i" (21 + PAGE_SHIFT),
  231. "i" (8), "i" (8 + PAGE_SHIFT));
  232. return ret;
  233. }
  234. #define pte_page(x) pfn_to_page(pte_pfn(x))
  235. static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
  236. {
  237. unsigned long mask, tmp;
  238. /* SUN4U: 0x630107ffffffec38 (negated == 0x9cfef800000013c7)
  239. * SUN4V: 0x33ffffffffffee07 (negated == 0xcc000000000011f8)
  240. *
  241. * Even if we use negation tricks the result is still a 6
  242. * instruction sequence, so don't try to play fancy and just
  243. * do the most straightforward implementation.
  244. *
  245. * Note: We encode this into 3 sun4v 2-insn patch sequences.
  246. */
  247. BUILD_BUG_ON(_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL);
  248. __asm__ __volatile__(
  249. "\n661: sethi %%uhi(%2), %1\n"
  250. " sethi %%hi(%2), %0\n"
  251. "\n662: or %1, %%ulo(%2), %1\n"
  252. " or %0, %%lo(%2), %0\n"
  253. "\n663: sllx %1, 32, %1\n"
  254. " or %0, %1, %0\n"
  255. " .section .sun4v_2insn_patch, \"ax\"\n"
  256. " .word 661b\n"
  257. " sethi %%uhi(%3), %1\n"
  258. " sethi %%hi(%3), %0\n"
  259. " .word 662b\n"
  260. " or %1, %%ulo(%3), %1\n"
  261. " or %0, %%lo(%3), %0\n"
  262. " .word 663b\n"
  263. " sllx %1, 32, %1\n"
  264. " or %0, %1, %0\n"
  265. " .previous\n"
  266. " .section .sun_m7_2insn_patch, \"ax\"\n"
  267. " .word 661b\n"
  268. " sethi %%uhi(%4), %1\n"
  269. " sethi %%hi(%4), %0\n"
  270. " .word 662b\n"
  271. " or %1, %%ulo(%4), %1\n"
  272. " or %0, %%lo(%4), %0\n"
  273. " .word 663b\n"
  274. " sllx %1, 32, %1\n"
  275. " or %0, %1, %0\n"
  276. " .previous\n"
  277. : "=r" (mask), "=r" (tmp)
  278. : "i" (_PAGE_PADDR_4U | _PAGE_MODIFIED_4U | _PAGE_ACCESSED_4U |
  279. _PAGE_CP_4U | _PAGE_CV_4U | _PAGE_E_4U |
  280. _PAGE_SPECIAL | _PAGE_PMD_HUGE | _PAGE_SZALL_4U),
  281. "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
  282. _PAGE_CP_4V | _PAGE_CV_4V | _PAGE_E_4V |
  283. _PAGE_SPECIAL | _PAGE_PMD_HUGE | _PAGE_SZALL_4V),
  284. "i" (_PAGE_PADDR_4V | _PAGE_MODIFIED_4V | _PAGE_ACCESSED_4V |
  285. _PAGE_CP_4V | _PAGE_E_4V |
  286. _PAGE_SPECIAL | _PAGE_PMD_HUGE | _PAGE_SZALL_4V));
  287. return __pte((pte_val(pte) & mask) | (pgprot_val(prot) & ~mask));
  288. }
  289. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  290. static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
  291. {
  292. pte_t pte = __pte(pmd_val(pmd));
  293. pte = pte_modify(pte, newprot);
  294. return __pmd(pte_val(pte));
  295. }
  296. #endif
  297. static inline pgprot_t pgprot_noncached(pgprot_t prot)
  298. {
  299. unsigned long val = pgprot_val(prot);
  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. " .section .sun_m7_2insn_patch, \"ax\"\n"
  309. " .word 661b\n"
  310. " andn %0, %6, %0\n"
  311. " or %0, %5, %0\n"
  312. " .previous\n"
  313. : "=r" (val)
  314. : "0" (val), "i" (_PAGE_CP_4U | _PAGE_CV_4U), "i" (_PAGE_E_4U),
  315. "i" (_PAGE_CP_4V | _PAGE_CV_4V), "i" (_PAGE_E_4V),
  316. "i" (_PAGE_CP_4V));
  317. return __pgprot(val);
  318. }
  319. /* Various pieces of code check for platform support by ifdef testing
  320. * on "pgprot_noncached". That's broken and should be fixed, but for
  321. * now...
  322. */
  323. #define pgprot_noncached pgprot_noncached
  324. #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
  325. static inline unsigned long __pte_huge_mask(void)
  326. {
  327. unsigned long mask;
  328. __asm__ __volatile__(
  329. "\n661: sethi %%uhi(%1), %0\n"
  330. " sllx %0, 32, %0\n"
  331. " .section .sun4v_2insn_patch, \"ax\"\n"
  332. " .word 661b\n"
  333. " mov %2, %0\n"
  334. " nop\n"
  335. " .previous\n"
  336. : "=r" (mask)
  337. : "i" (_PAGE_SZHUGE_4U), "i" (_PAGE_SZHUGE_4V));
  338. return mask;
  339. }
  340. static inline pte_t pte_mkhuge(pte_t pte)
  341. {
  342. return __pte(pte_val(pte) | _PAGE_PMD_HUGE | __pte_huge_mask());
  343. }
  344. static inline bool is_hugetlb_pte(pte_t pte)
  345. {
  346. return !!(pte_val(pte) & __pte_huge_mask());
  347. }
  348. static inline bool is_hugetlb_pmd(pmd_t pmd)
  349. {
  350. return !!(pmd_val(pmd) & _PAGE_PMD_HUGE);
  351. }
  352. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  353. static inline pmd_t pmd_mkhuge(pmd_t pmd)
  354. {
  355. pte_t pte = __pte(pmd_val(pmd));
  356. pte = pte_mkhuge(pte);
  357. pte_val(pte) |= _PAGE_PMD_HUGE;
  358. return __pmd(pte_val(pte));
  359. }
  360. #endif
  361. #else
  362. static inline bool is_hugetlb_pte(pte_t pte)
  363. {
  364. return false;
  365. }
  366. #endif
  367. static inline pte_t pte_mkdirty(pte_t pte)
  368. {
  369. unsigned long val = pte_val(pte), tmp;
  370. __asm__ __volatile__(
  371. "\n661: or %0, %3, %0\n"
  372. " nop\n"
  373. "\n662: nop\n"
  374. " nop\n"
  375. " .section .sun4v_2insn_patch, \"ax\"\n"
  376. " .word 661b\n"
  377. " sethi %%uhi(%4), %1\n"
  378. " sllx %1, 32, %1\n"
  379. " .word 662b\n"
  380. " or %1, %%lo(%4), %1\n"
  381. " or %0, %1, %0\n"
  382. " .previous\n"
  383. : "=r" (val), "=r" (tmp)
  384. : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
  385. "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
  386. return __pte(val);
  387. }
  388. static inline pte_t pte_mkclean(pte_t pte)
  389. {
  390. unsigned long val = pte_val(pte), tmp;
  391. __asm__ __volatile__(
  392. "\n661: andn %0, %3, %0\n"
  393. " nop\n"
  394. "\n662: nop\n"
  395. " nop\n"
  396. " .section .sun4v_2insn_patch, \"ax\"\n"
  397. " .word 661b\n"
  398. " sethi %%uhi(%4), %1\n"
  399. " sllx %1, 32, %1\n"
  400. " .word 662b\n"
  401. " or %1, %%lo(%4), %1\n"
  402. " andn %0, %1, %0\n"
  403. " .previous\n"
  404. : "=r" (val), "=r" (tmp)
  405. : "0" (val), "i" (_PAGE_MODIFIED_4U | _PAGE_W_4U),
  406. "i" (_PAGE_MODIFIED_4V | _PAGE_W_4V));
  407. return __pte(val);
  408. }
  409. static inline pte_t pte_mkwrite(pte_t pte)
  410. {
  411. unsigned long val = pte_val(pte), mask;
  412. __asm__ __volatile__(
  413. "\n661: mov %1, %0\n"
  414. " nop\n"
  415. " .section .sun4v_2insn_patch, \"ax\"\n"
  416. " .word 661b\n"
  417. " sethi %%uhi(%2), %0\n"
  418. " sllx %0, 32, %0\n"
  419. " .previous\n"
  420. : "=r" (mask)
  421. : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
  422. return __pte(val | mask);
  423. }
  424. static inline pte_t pte_wrprotect(pte_t pte)
  425. {
  426. unsigned long val = pte_val(pte), tmp;
  427. __asm__ __volatile__(
  428. "\n661: andn %0, %3, %0\n"
  429. " nop\n"
  430. "\n662: nop\n"
  431. " nop\n"
  432. " .section .sun4v_2insn_patch, \"ax\"\n"
  433. " .word 661b\n"
  434. " sethi %%uhi(%4), %1\n"
  435. " sllx %1, 32, %1\n"
  436. " .word 662b\n"
  437. " or %1, %%lo(%4), %1\n"
  438. " andn %0, %1, %0\n"
  439. " .previous\n"
  440. : "=r" (val), "=r" (tmp)
  441. : "0" (val), "i" (_PAGE_WRITE_4U | _PAGE_W_4U),
  442. "i" (_PAGE_WRITE_4V | _PAGE_W_4V));
  443. return __pte(val);
  444. }
  445. static inline pte_t pte_mkold(pte_t pte)
  446. {
  447. unsigned long mask;
  448. __asm__ __volatile__(
  449. "\n661: mov %1, %0\n"
  450. " nop\n"
  451. " .section .sun4v_2insn_patch, \"ax\"\n"
  452. " .word 661b\n"
  453. " sethi %%uhi(%2), %0\n"
  454. " sllx %0, 32, %0\n"
  455. " .previous\n"
  456. : "=r" (mask)
  457. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  458. mask |= _PAGE_R;
  459. return __pte(pte_val(pte) & ~mask);
  460. }
  461. static inline pte_t pte_mkyoung(pte_t pte)
  462. {
  463. unsigned long mask;
  464. __asm__ __volatile__(
  465. "\n661: mov %1, %0\n"
  466. " nop\n"
  467. " .section .sun4v_2insn_patch, \"ax\"\n"
  468. " .word 661b\n"
  469. " sethi %%uhi(%2), %0\n"
  470. " sllx %0, 32, %0\n"
  471. " .previous\n"
  472. : "=r" (mask)
  473. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  474. mask |= _PAGE_R;
  475. return __pte(pte_val(pte) | mask);
  476. }
  477. static inline pte_t pte_mkspecial(pte_t pte)
  478. {
  479. pte_val(pte) |= _PAGE_SPECIAL;
  480. return pte;
  481. }
  482. static inline unsigned long pte_young(pte_t pte)
  483. {
  484. unsigned long mask;
  485. __asm__ __volatile__(
  486. "\n661: mov %1, %0\n"
  487. " nop\n"
  488. " .section .sun4v_2insn_patch, \"ax\"\n"
  489. " .word 661b\n"
  490. " sethi %%uhi(%2), %0\n"
  491. " sllx %0, 32, %0\n"
  492. " .previous\n"
  493. : "=r" (mask)
  494. : "i" (_PAGE_ACCESSED_4U), "i" (_PAGE_ACCESSED_4V));
  495. return (pte_val(pte) & mask);
  496. }
  497. static inline unsigned long pte_dirty(pte_t pte)
  498. {
  499. unsigned long mask;
  500. __asm__ __volatile__(
  501. "\n661: mov %1, %0\n"
  502. " nop\n"
  503. " .section .sun4v_2insn_patch, \"ax\"\n"
  504. " .word 661b\n"
  505. " sethi %%uhi(%2), %0\n"
  506. " sllx %0, 32, %0\n"
  507. " .previous\n"
  508. : "=r" (mask)
  509. : "i" (_PAGE_MODIFIED_4U), "i" (_PAGE_MODIFIED_4V));
  510. return (pte_val(pte) & mask);
  511. }
  512. static inline unsigned long pte_write(pte_t pte)
  513. {
  514. unsigned long mask;
  515. __asm__ __volatile__(
  516. "\n661: mov %1, %0\n"
  517. " nop\n"
  518. " .section .sun4v_2insn_patch, \"ax\"\n"
  519. " .word 661b\n"
  520. " sethi %%uhi(%2), %0\n"
  521. " sllx %0, 32, %0\n"
  522. " .previous\n"
  523. : "=r" (mask)
  524. : "i" (_PAGE_WRITE_4U), "i" (_PAGE_WRITE_4V));
  525. return (pte_val(pte) & mask);
  526. }
  527. static inline unsigned long pte_exec(pte_t pte)
  528. {
  529. unsigned long mask;
  530. __asm__ __volatile__(
  531. "\n661: sethi %%hi(%1), %0\n"
  532. " .section .sun4v_1insn_patch, \"ax\"\n"
  533. " .word 661b\n"
  534. " mov %2, %0\n"
  535. " .previous\n"
  536. : "=r" (mask)
  537. : "i" (_PAGE_EXEC_4U), "i" (_PAGE_EXEC_4V));
  538. return (pte_val(pte) & mask);
  539. }
  540. static inline unsigned long pte_present(pte_t pte)
  541. {
  542. unsigned long val = pte_val(pte);
  543. __asm__ __volatile__(
  544. "\n661: and %0, %2, %0\n"
  545. " .section .sun4v_1insn_patch, \"ax\"\n"
  546. " .word 661b\n"
  547. " and %0, %3, %0\n"
  548. " .previous\n"
  549. : "=r" (val)
  550. : "0" (val), "i" (_PAGE_PRESENT_4U), "i" (_PAGE_PRESENT_4V));
  551. return val;
  552. }
  553. #define pte_accessible pte_accessible
  554. static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
  555. {
  556. return pte_val(a) & _PAGE_VALID;
  557. }
  558. static inline unsigned long pte_special(pte_t pte)
  559. {
  560. return pte_val(pte) & _PAGE_SPECIAL;
  561. }
  562. static inline unsigned long pmd_large(pmd_t pmd)
  563. {
  564. pte_t pte = __pte(pmd_val(pmd));
  565. return pte_val(pte) & _PAGE_PMD_HUGE;
  566. }
  567. static inline unsigned long pmd_pfn(pmd_t pmd)
  568. {
  569. pte_t pte = __pte(pmd_val(pmd));
  570. return pte_pfn(pte);
  571. }
  572. #define __HAVE_ARCH_PMD_WRITE
  573. static inline unsigned long pmd_write(pmd_t pmd)
  574. {
  575. pte_t pte = __pte(pmd_val(pmd));
  576. return pte_write(pte);
  577. }
  578. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  579. static inline unsigned long pmd_dirty(pmd_t pmd)
  580. {
  581. pte_t pte = __pte(pmd_val(pmd));
  582. return pte_dirty(pte);
  583. }
  584. static inline unsigned long pmd_young(pmd_t pmd)
  585. {
  586. pte_t pte = __pte(pmd_val(pmd));
  587. return pte_young(pte);
  588. }
  589. static inline unsigned long pmd_trans_huge(pmd_t pmd)
  590. {
  591. pte_t pte = __pte(pmd_val(pmd));
  592. return pte_val(pte) & _PAGE_PMD_HUGE;
  593. }
  594. static inline pmd_t pmd_mkold(pmd_t pmd)
  595. {
  596. pte_t pte = __pte(pmd_val(pmd));
  597. pte = pte_mkold(pte);
  598. return __pmd(pte_val(pte));
  599. }
  600. static inline pmd_t pmd_wrprotect(pmd_t pmd)
  601. {
  602. pte_t pte = __pte(pmd_val(pmd));
  603. pte = pte_wrprotect(pte);
  604. return __pmd(pte_val(pte));
  605. }
  606. static inline pmd_t pmd_mkdirty(pmd_t pmd)
  607. {
  608. pte_t pte = __pte(pmd_val(pmd));
  609. pte = pte_mkdirty(pte);
  610. return __pmd(pte_val(pte));
  611. }
  612. static inline pmd_t pmd_mkclean(pmd_t pmd)
  613. {
  614. pte_t pte = __pte(pmd_val(pmd));
  615. pte = pte_mkclean(pte);
  616. return __pmd(pte_val(pte));
  617. }
  618. static inline pmd_t pmd_mkyoung(pmd_t pmd)
  619. {
  620. pte_t pte = __pte(pmd_val(pmd));
  621. pte = pte_mkyoung(pte);
  622. return __pmd(pte_val(pte));
  623. }
  624. static inline pmd_t pmd_mkwrite(pmd_t pmd)
  625. {
  626. pte_t pte = __pte(pmd_val(pmd));
  627. pte = pte_mkwrite(pte);
  628. return __pmd(pte_val(pte));
  629. }
  630. static inline pgprot_t pmd_pgprot(pmd_t entry)
  631. {
  632. unsigned long val = pmd_val(entry);
  633. return __pgprot(val);
  634. }
  635. #endif
  636. static inline int pmd_present(pmd_t pmd)
  637. {
  638. return pmd_val(pmd) != 0UL;
  639. }
  640. #define pmd_none(pmd) (!pmd_val(pmd))
  641. /* pmd_bad() is only called on non-trans-huge PMDs. Our encoding is
  642. * very simple, it's just the physical address. PTE tables are of
  643. * size PAGE_SIZE so make sure the sub-PAGE_SIZE bits are clear and
  644. * the top bits outside of the range of any physical address size we
  645. * support are clear as well. We also validate the physical itself.
  646. */
  647. #define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
  648. #define pud_none(pud) (!pud_val(pud))
  649. #define pud_bad(pud) (pud_val(pud) & ~PAGE_MASK)
  650. #define pgd_none(pgd) (!pgd_val(pgd))
  651. #define pgd_bad(pgd) (pgd_val(pgd) & ~PAGE_MASK)
  652. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  653. void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  654. pmd_t *pmdp, pmd_t pmd);
  655. #else
  656. static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  657. pmd_t *pmdp, pmd_t pmd)
  658. {
  659. *pmdp = pmd;
  660. }
  661. #endif
  662. static inline void pmd_set(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
  663. {
  664. unsigned long val = __pa((unsigned long) (ptep));
  665. pmd_val(*pmdp) = val;
  666. }
  667. #define pud_set(pudp, pmdp) \
  668. (pud_val(*(pudp)) = (__pa((unsigned long) (pmdp))))
  669. static inline unsigned long __pmd_page(pmd_t pmd)
  670. {
  671. pte_t pte = __pte(pmd_val(pmd));
  672. unsigned long pfn;
  673. pfn = pte_pfn(pte);
  674. return ((unsigned long) __va(pfn << PAGE_SHIFT));
  675. }
  676. #define pmd_page(pmd) virt_to_page((void *)__pmd_page(pmd))
  677. #define pud_page_vaddr(pud) \
  678. ((unsigned long) __va(pud_val(pud)))
  679. #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
  680. #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0UL)
  681. #define pud_present(pud) (pud_val(pud) != 0U)
  682. #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
  683. #define pgd_page_vaddr(pgd) \
  684. ((unsigned long) __va(pgd_val(pgd)))
  685. #define pgd_present(pgd) (pgd_val(pgd) != 0U)
  686. #define pgd_clear(pgdp) (pgd_val(*(pgd)) = 0UL)
  687. static inline unsigned long pud_large(pud_t pud)
  688. {
  689. pte_t pte = __pte(pud_val(pud));
  690. return pte_val(pte) & _PAGE_PMD_HUGE;
  691. }
  692. static inline unsigned long pud_pfn(pud_t pud)
  693. {
  694. pte_t pte = __pte(pud_val(pud));
  695. return pte_pfn(pte);
  696. }
  697. /* Same in both SUN4V and SUN4U. */
  698. #define pte_none(pte) (!pte_val(pte))
  699. #define pgd_set(pgdp, pudp) \
  700. (pgd_val(*(pgdp)) = (__pa((unsigned long) (pudp))))
  701. /* to find an entry in a page-table-directory. */
  702. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
  703. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  704. /* to find an entry in a kernel page-table-directory */
  705. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  706. /* Find an entry in the third-level page table.. */
  707. #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
  708. #define pud_offset(pgdp, address) \
  709. ((pud_t *) pgd_page_vaddr(*(pgdp)) + pud_index(address))
  710. /* Find an entry in the second-level page table.. */
  711. #define pmd_offset(pudp, address) \
  712. ((pmd_t *) pud_page_vaddr(*(pudp)) + \
  713. (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)))
  714. /* Find an entry in the third-level page table.. */
  715. #define pte_index(dir, address) \
  716. ((pte_t *) __pmd_page(*(dir)) + \
  717. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
  718. #define pte_offset_kernel pte_index
  719. #define pte_offset_map pte_index
  720. #define pte_unmap(pte) do { } while (0)
  721. /* Actual page table PTE updates. */
  722. void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
  723. pte_t *ptep, pte_t orig, int fullmm);
  724. static void maybe_tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
  725. pte_t *ptep, pte_t orig, int fullmm)
  726. {
  727. /* It is more efficient to let flush_tlb_kernel_range()
  728. * handle init_mm tlb flushes.
  729. *
  730. * SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U
  731. * and SUN4V pte layout, so this inline test is fine.
  732. */
  733. if (likely(mm != &init_mm) && pte_accessible(mm, orig))
  734. tlb_batch_add(mm, vaddr, ptep, orig, fullmm);
  735. }
  736. #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
  737. static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
  738. unsigned long addr,
  739. pmd_t *pmdp)
  740. {
  741. pmd_t pmd = *pmdp;
  742. set_pmd_at(mm, addr, pmdp, __pmd(0UL));
  743. return pmd;
  744. }
  745. static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
  746. pte_t *ptep, pte_t pte, int fullmm)
  747. {
  748. pte_t orig = *ptep;
  749. *ptep = pte;
  750. maybe_tlb_batch_add(mm, addr, ptep, orig, fullmm);
  751. }
  752. #define set_pte_at(mm,addr,ptep,pte) \
  753. __set_pte_at((mm), (addr), (ptep), (pte), 0)
  754. #define pte_clear(mm,addr,ptep) \
  755. set_pte_at((mm), (addr), (ptep), __pte(0UL))
  756. #define __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL
  757. #define pte_clear_not_present_full(mm,addr,ptep,fullmm) \
  758. __set_pte_at((mm), (addr), (ptep), __pte(0UL), (fullmm))
  759. #ifdef DCACHE_ALIASING_POSSIBLE
  760. #define __HAVE_ARCH_MOVE_PTE
  761. #define move_pte(pte, prot, old_addr, new_addr) \
  762. ({ \
  763. pte_t newpte = (pte); \
  764. if (tlb_type != hypervisor && pte_present(pte)) { \
  765. unsigned long this_pfn = pte_pfn(pte); \
  766. \
  767. if (pfn_valid(this_pfn) && \
  768. (((old_addr) ^ (new_addr)) & (1 << 13))) \
  769. flush_dcache_page_all(current->mm, \
  770. pfn_to_page(this_pfn)); \
  771. } \
  772. newpte; \
  773. })
  774. #endif
  775. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  776. void paging_init(void);
  777. unsigned long find_ecache_flush_span(unsigned long size);
  778. struct seq_file;
  779. void mmu_info(struct seq_file *);
  780. struct vm_area_struct;
  781. void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
  782. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  783. void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
  784. pmd_t *pmd);
  785. #define __HAVE_ARCH_PMDP_INVALIDATE
  786. extern pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
  787. pmd_t *pmdp);
  788. #define __HAVE_ARCH_PGTABLE_DEPOSIT
  789. void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
  790. pgtable_t pgtable);
  791. #define __HAVE_ARCH_PGTABLE_WITHDRAW
  792. pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
  793. #endif
  794. /* Encode and de-code a swap entry */
  795. #define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0xffUL)
  796. #define __swp_offset(entry) ((entry).val >> (PAGE_SHIFT + 8UL))
  797. #define __swp_entry(type, offset) \
  798. ( (swp_entry_t) \
  799. { \
  800. (((long)(type) << PAGE_SHIFT) | \
  801. ((long)(offset) << (PAGE_SHIFT + 8UL))) \
  802. } )
  803. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  804. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  805. int page_in_phys_avail(unsigned long paddr);
  806. /*
  807. * For sparc32&64, the pfn in io_remap_pfn_range() carries <iospace> in
  808. * its high 4 bits. These macros/functions put it there or get it from there.
  809. */
  810. #define MK_IOSPACE_PFN(space, pfn) (pfn | (space << (BITS_PER_LONG - 4)))
  811. #define GET_IOSPACE(pfn) (pfn >> (BITS_PER_LONG - 4))
  812. #define GET_PFN(pfn) (pfn & 0x0fffffffffffffffUL)
  813. int remap_pfn_range(struct vm_area_struct *, unsigned long, unsigned long,
  814. unsigned long, pgprot_t);
  815. static inline int io_remap_pfn_range(struct vm_area_struct *vma,
  816. unsigned long from, unsigned long pfn,
  817. unsigned long size, pgprot_t prot)
  818. {
  819. unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
  820. int space = GET_IOSPACE(pfn);
  821. unsigned long phys_base;
  822. phys_base = offset | (((unsigned long) space) << 32UL);
  823. return remap_pfn_range(vma, from, phys_base >> PAGE_SHIFT, size, prot);
  824. }
  825. #define io_remap_pfn_range io_remap_pfn_range
  826. #include <asm/tlbflush.h>
  827. #include <asm-generic/pgtable.h>
  828. /* We provide our own get_unmapped_area to cope with VA holes and
  829. * SHM area cache aliasing for userland.
  830. */
  831. #define HAVE_ARCH_UNMAPPED_AREA
  832. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  833. /* We provide a special get_unmapped_area for framebuffer mmaps to try and use
  834. * the largest alignment possible such that larget PTEs can be used.
  835. */
  836. unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
  837. unsigned long, unsigned long,
  838. unsigned long);
  839. #define HAVE_ARCH_FB_UNMAPPED_AREA
  840. void pgtable_cache_init(void);
  841. void sun4v_register_fault_status(void);
  842. void sun4v_ktsb_register(void);
  843. void __init cheetah_ecache_flush_init(void);
  844. void sun4v_patch_tlb_handlers(void);
  845. extern unsigned long cmdline_memory_size;
  846. asmlinkage void do_sparc64_fault(struct pt_regs *regs);
  847. #endif /* !(__ASSEMBLY__) */
  848. #endif /* !(_SPARC64_PGTABLE_H) */