slb_low.S 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * Low-level SLB routines
  3. *
  4. * Copyright (C) 2004 David Gibson <dwg@au.ibm.com>, IBM
  5. *
  6. * Based on earlier C version:
  7. * Dave Engebretsen and Mike Corrigan {engebret|mikejc}@us.ibm.com
  8. * Copyright (c) 2001 Dave Engebretsen
  9. * Copyright (C) 2002 Anton Blanchard <anton@au.ibm.com>, IBM
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <asm/processor.h>
  17. #include <asm/ppc_asm.h>
  18. #include <asm/asm-offsets.h>
  19. #include <asm/cputable.h>
  20. #include <asm/page.h>
  21. #include <asm/mmu.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/firmware.h>
  24. /*
  25. * This macro generates asm code to compute the VSID scramble
  26. * function. Used in slb_allocate() and do_stab_bolted. The function
  27. * computed is: (protovsid*VSID_MULTIPLIER) % VSID_MODULUS
  28. *
  29. * rt = register containing the proto-VSID and into which the
  30. * VSID will be stored
  31. * rx = scratch register (clobbered)
  32. * rf = flags
  33. *
  34. * - rt and rx must be different registers
  35. * - The answer will end up in the low VSID_BITS bits of rt. The higher
  36. * bits may contain other garbage, so you may need to mask the
  37. * result.
  38. */
  39. #define ASM_VSID_SCRAMBLE(rt, rx, rf, size) \
  40. lis rx,VSID_MULTIPLIER_##size@h; \
  41. ori rx,rx,VSID_MULTIPLIER_##size@l; \
  42. mulld rt,rt,rx; /* rt = rt * MULTIPLIER */ \
  43. /* \
  44. * powermac get slb fault before feature fixup, so make 65 bit part \
  45. * the default part of feature fixup \
  46. */ \
  47. BEGIN_MMU_FTR_SECTION \
  48. srdi rx,rt,VSID_BITS_65_##size; \
  49. clrldi rt,rt,(64-VSID_BITS_65_##size); \
  50. add rt,rt,rx; \
  51. addi rx,rt,1; \
  52. srdi rx,rx,VSID_BITS_65_##size; \
  53. add rt,rt,rx; \
  54. rldimi rf,rt,SLB_VSID_SHIFT_##size,(64 - (SLB_VSID_SHIFT_##size + VSID_BITS_65_##size)); \
  55. MMU_FTR_SECTION_ELSE \
  56. srdi rx,rt,VSID_BITS_##size; \
  57. clrldi rt,rt,(64-VSID_BITS_##size); \
  58. add rt,rt,rx; /* add high and low bits */ \
  59. addi rx,rt,1; \
  60. srdi rx,rx,VSID_BITS_##size; /* extract 2^VSID_BITS bit */ \
  61. add rt,rt,rx; \
  62. rldimi rf,rt,SLB_VSID_SHIFT_##size,(64 - (SLB_VSID_SHIFT_##size + VSID_BITS_##size)); \
  63. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_68_BIT_VA)
  64. /* void slb_allocate(unsigned long ea);
  65. *
  66. * Create an SLB entry for the given EA (user or kernel).
  67. * r3 = faulting address, r13 = PACA
  68. * r9, r10, r11 are clobbered by this function
  69. * r3 is preserved.
  70. * No other registers are examined or changed.
  71. */
  72. _GLOBAL(slb_allocate)
  73. /*
  74. * check for bad kernel/user address
  75. * (ea & ~REGION_MASK) >= PGTABLE_RANGE
  76. */
  77. rldicr. r9,r3,4,(63 - H_PGTABLE_EADDR_SIZE - 4)
  78. bne- 8f
  79. srdi r9,r3,60 /* get region */
  80. srdi r10,r3,SID_SHIFT /* get esid */
  81. cmpldi cr7,r9,0xc /* cmp PAGE_OFFSET for later use */
  82. /* r3 = address, r10 = esid, cr7 = <> PAGE_OFFSET */
  83. blt cr7,0f /* user or kernel? */
  84. /* Check if hitting the linear mapping or some other kernel space
  85. */
  86. bne cr7,1f
  87. /* Linear mapping encoding bits, the "li" instruction below will
  88. * be patched by the kernel at boot
  89. */
  90. .globl slb_miss_kernel_load_linear
  91. slb_miss_kernel_load_linear:
  92. li r11,0
  93. /*
  94. * context = (ea >> 60) - (0xc - 1)
  95. * r9 = region id.
  96. */
  97. subi r9,r9,KERNEL_REGION_CONTEXT_OFFSET
  98. BEGIN_FTR_SECTION
  99. b .Lslb_finish_load
  100. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
  101. b .Lslb_finish_load_1T
  102. 1:
  103. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  104. cmpldi cr0,r9,0xf
  105. bne 1f
  106. /* Check virtual memmap region. To be patched at kernel boot */
  107. .globl slb_miss_kernel_load_vmemmap
  108. slb_miss_kernel_load_vmemmap:
  109. li r11,0
  110. b 6f
  111. 1:
  112. #endif /* CONFIG_SPARSEMEM_VMEMMAP */
  113. /*
  114. * r10 contains the ESID, which is the original faulting EA shifted
  115. * right by 28 bits. We need to compare that with (H_VMALLOC_END >> 28)
  116. * which is 0xd00038000. That can't be used as an immediate, even if we
  117. * ignored the 0xd, so we have to load it into a register, and we only
  118. * have one register free. So we must load all of (H_VMALLOC_END >> 28)
  119. * into a register and compare ESID against that.
  120. */
  121. lis r11,(H_VMALLOC_END >> 32)@h // r11 = 0xffffffffd0000000
  122. ori r11,r11,(H_VMALLOC_END >> 32)@l // r11 = 0xffffffffd0003800
  123. // Rotate left 4, then mask with 0xffffffff0
  124. rldic r11,r11,4,28 // r11 = 0xd00038000
  125. cmpld r10,r11 // if r10 >= r11
  126. bge 5f // goto io_mapping
  127. /*
  128. * vmalloc mapping gets the encoding from the PACA as the mapping
  129. * can be demoted from 64K -> 4K dynamically on some machines.
  130. */
  131. lhz r11,PACAVMALLOCSLLP(r13)
  132. b 6f
  133. 5:
  134. /* IO mapping */
  135. .globl slb_miss_kernel_load_io
  136. slb_miss_kernel_load_io:
  137. li r11,0
  138. 6:
  139. /*
  140. * context = (ea >> 60) - (0xc - 1)
  141. * r9 = region id.
  142. */
  143. subi r9,r9,KERNEL_REGION_CONTEXT_OFFSET
  144. BEGIN_FTR_SECTION
  145. b .Lslb_finish_load
  146. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
  147. b .Lslb_finish_load_1T
  148. 0: /*
  149. * For userspace addresses, make sure this is region 0.
  150. */
  151. cmpdi r9, 0
  152. bne- 8f
  153. /*
  154. * user space make sure we are within the allowed limit
  155. */
  156. ld r11,PACA_SLB_ADDR_LIMIT(r13)
  157. cmpld r3,r11
  158. bge- 8f
  159. /* when using slices, we extract the psize off the slice bitmaps
  160. * and then we need to get the sllp encoding off the mmu_psize_defs
  161. * array.
  162. *
  163. * XXX This is a bit inefficient especially for the normal case,
  164. * so we should try to implement a fast path for the standard page
  165. * size using the old sllp value so we avoid the array. We cannot
  166. * really do dynamic patching unfortunately as processes might flip
  167. * between 4k and 64k standard page size
  168. */
  169. #ifdef CONFIG_PPC_MM_SLICES
  170. /* r10 have esid */
  171. cmpldi r10,16
  172. /* below SLICE_LOW_TOP */
  173. blt 5f
  174. /*
  175. * Handle hpsizes,
  176. * r9 is get_paca()->context.high_slices_psize[index], r11 is mask_index
  177. */
  178. srdi r11,r10,(SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT + 1) /* index */
  179. addi r9,r11,PACAHIGHSLICEPSIZE
  180. lbzx r9,r13,r9 /* r9 is hpsizes[r11] */
  181. /* r11 = (r10 >> (SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT)) & 0x1 */
  182. rldicl r11,r10,(64 - (SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT)),63
  183. b 6f
  184. 5:
  185. /*
  186. * Handle lpsizes
  187. * r9 is get_paca()->context.low_slices_psize, r11 is index
  188. */
  189. ld r9,PACALOWSLICESPSIZE(r13)
  190. mr r11,r10
  191. 6:
  192. sldi r11,r11,2 /* index * 4 */
  193. /* Extract the psize and multiply to get an array offset */
  194. srd r9,r9,r11
  195. andi. r9,r9,0xf
  196. mulli r9,r9,MMUPSIZEDEFSIZE
  197. /* Now get to the array and obtain the sllp
  198. */
  199. ld r11,PACATOC(r13)
  200. ld r11,mmu_psize_defs@got(r11)
  201. add r11,r11,r9
  202. ld r11,MMUPSIZESLLP(r11)
  203. ori r11,r11,SLB_VSID_USER
  204. #else
  205. /* paca context sllp already contains the SLB_VSID_USER bits */
  206. lhz r11,PACACONTEXTSLLP(r13)
  207. #endif /* CONFIG_PPC_MM_SLICES */
  208. ld r9,PACACONTEXTID(r13)
  209. BEGIN_FTR_SECTION
  210. cmpldi r10,0x1000
  211. bge .Lslb_finish_load_1T
  212. END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
  213. b .Lslb_finish_load
  214. 8: /* invalid EA - return an error indication */
  215. crset 4*cr0+eq /* indicate failure */
  216. blr
  217. /*
  218. * Finish loading of an SLB entry and return
  219. *
  220. * r3 = EA, r9 = context, r10 = ESID, r11 = flags, clobbers r9, cr7 = <> PAGE_OFFSET
  221. */
  222. .Lslb_finish_load:
  223. rldimi r10,r9,ESID_BITS,0
  224. ASM_VSID_SCRAMBLE(r10,r9,r11,256M)
  225. /* r3 = EA, r11 = VSID data */
  226. /*
  227. * Find a slot, round robin. Previously we tried to find a
  228. * free slot first but that took too long. Unfortunately we
  229. * dont have any LRU information to help us choose a slot.
  230. */
  231. mr r9,r3
  232. /* slb_finish_load_1T continues here. r9=EA with non-ESID bits clear */
  233. 7: ld r10,PACASTABRR(r13)
  234. addi r10,r10,1
  235. /* This gets soft patched on boot. */
  236. .globl slb_compare_rr_to_size
  237. slb_compare_rr_to_size:
  238. cmpldi r10,0
  239. blt+ 4f
  240. li r10,SLB_NUM_BOLTED
  241. 4:
  242. std r10,PACASTABRR(r13)
  243. 3:
  244. rldimi r9,r10,0,36 /* r9 = EA[0:35] | entry */
  245. oris r10,r9,SLB_ESID_V@h /* r10 = r9 | SLB_ESID_V */
  246. /* r9 = ESID data, r11 = VSID data */
  247. /*
  248. * No need for an isync before or after this slbmte. The exception
  249. * we enter with and the rfid we exit with are context synchronizing.
  250. */
  251. slbmte r11,r10
  252. /* we're done for kernel addresses */
  253. crclr 4*cr0+eq /* set result to "success" */
  254. bgelr cr7
  255. /* Update the slb cache */
  256. lhz r9,PACASLBCACHEPTR(r13) /* offset = paca->slb_cache_ptr */
  257. cmpldi r9,SLB_CACHE_ENTRIES
  258. bge 1f
  259. /* still room in the slb cache */
  260. sldi r11,r9,2 /* r11 = offset * sizeof(u32) */
  261. srdi r10,r10,28 /* get the 36 bits of the ESID */
  262. add r11,r11,r13 /* r11 = (u32 *)paca + offset */
  263. stw r10,PACASLBCACHE(r11) /* paca->slb_cache[offset] = esid */
  264. addi r9,r9,1 /* offset++ */
  265. b 2f
  266. 1: /* offset >= SLB_CACHE_ENTRIES */
  267. li r9,SLB_CACHE_ENTRIES+1
  268. 2:
  269. sth r9,PACASLBCACHEPTR(r13) /* paca->slb_cache_ptr = offset */
  270. crclr 4*cr0+eq /* set result to "success" */
  271. blr
  272. /*
  273. * Finish loading of a 1T SLB entry (for the kernel linear mapping) and return.
  274. *
  275. * r3 = EA, r9 = context, r10 = ESID(256MB), r11 = flags, clobbers r9
  276. */
  277. .Lslb_finish_load_1T:
  278. srdi r10,r10,(SID_SHIFT_1T - SID_SHIFT) /* get 1T ESID */
  279. rldimi r10,r9,ESID_BITS_1T,0
  280. ASM_VSID_SCRAMBLE(r10,r9,r11,1T)
  281. li r10,MMU_SEGSIZE_1T
  282. rldimi r11,r10,SLB_VSID_SSIZE_SHIFT,0 /* insert segment size */
  283. /* r3 = EA, r11 = VSID data */
  284. clrrdi r9,r3,SID_SHIFT_1T /* clear out non-ESID bits */
  285. b 7b
  286. _ASM_NOKPROBE_SYMBOL(slb_allocate)
  287. _ASM_NOKPROBE_SYMBOL(slb_miss_kernel_load_linear)
  288. _ASM_NOKPROBE_SYMBOL(slb_miss_kernel_load_io)
  289. _ASM_NOKPROBE_SYMBOL(slb_compare_rr_to_size)
  290. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  291. _ASM_NOKPROBE_SYMBOL(slb_miss_kernel_load_vmemmap)
  292. #endif