slb_low.S 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. /* void slb_allocate_realmode(unsigned long ea);
  25. *
  26. * Create an SLB entry for the given EA (user or kernel).
  27. * r3 = faulting address, r13 = PACA
  28. * r9, r10, r11 are clobbered by this function
  29. * No other registers are examined or changed.
  30. */
  31. _GLOBAL(slb_allocate_realmode)
  32. /* r3 = faulting address */
  33. srdi r9,r3,60 /* get region */
  34. srdi r10,r3,28 /* get esid */
  35. cmpldi cr7,r9,0xc /* cmp PAGE_OFFSET for later use */
  36. /* r3 = address, r10 = esid, cr7 = <> PAGE_OFFSET */
  37. blt cr7,0f /* user or kernel? */
  38. /* kernel address: proto-VSID = ESID */
  39. /* WARNING - MAGIC: we don't use the VSID 0xfffffffff, but
  40. * this code will generate the protoVSID 0xfffffffff for the
  41. * top segment. That's ok, the scramble below will translate
  42. * it to VSID 0, which is reserved as a bad VSID - one which
  43. * will never have any pages in it. */
  44. /* Check if hitting the linear mapping of the vmalloc/ioremap
  45. * kernel space
  46. */
  47. bne cr7,1f
  48. /* Linear mapping encoding bits, the "li" instruction below will
  49. * be patched by the kernel at boot
  50. */
  51. _GLOBAL(slb_miss_kernel_load_linear)
  52. li r11,0
  53. BEGIN_FTR_SECTION
  54. b slb_finish_load
  55. END_FTR_SECTION_IFCLR(CPU_FTR_1T_SEGMENT)
  56. b slb_finish_load_1T
  57. 1: /* vmalloc/ioremap mapping encoding bits, the "li" instructions below
  58. * will be patched by the kernel at boot
  59. */
  60. BEGIN_FTR_SECTION
  61. /* check whether this is in vmalloc or ioremap space */
  62. clrldi r11,r10,48
  63. cmpldi r11,(VMALLOC_SIZE >> 28) - 1
  64. bgt 5f
  65. lhz r11,PACAVMALLOCSLLP(r13)
  66. b 6f
  67. 5:
  68. END_FTR_SECTION_IFCLR(CPU_FTR_CI_LARGE_PAGE)
  69. _GLOBAL(slb_miss_kernel_load_io)
  70. li r11,0
  71. 6:
  72. BEGIN_FTR_SECTION
  73. b slb_finish_load
  74. END_FTR_SECTION_IFCLR(CPU_FTR_1T_SEGMENT)
  75. b slb_finish_load_1T
  76. 0: /* user address: proto-VSID = context << 15 | ESID. First check
  77. * if the address is within the boundaries of the user region
  78. */
  79. srdi. r9,r10,USER_ESID_BITS
  80. bne- 8f /* invalid ea bits set */
  81. /* when using slices, we extract the psize off the slice bitmaps
  82. * and then we need to get the sllp encoding off the mmu_psize_defs
  83. * array.
  84. *
  85. * XXX This is a bit inefficient especially for the normal case,
  86. * so we should try to implement a fast path for the standard page
  87. * size using the old sllp value so we avoid the array. We cannot
  88. * really do dynamic patching unfortunately as processes might flip
  89. * between 4k and 64k standard page size
  90. */
  91. #ifdef CONFIG_PPC_MM_SLICES
  92. cmpldi r10,16
  93. /* Get the slice index * 4 in r11 and matching slice size mask in r9 */
  94. ld r9,PACALOWSLICESPSIZE(r13)
  95. sldi r11,r10,2
  96. blt 5f
  97. ld r9,PACAHIGHSLICEPSIZE(r13)
  98. srdi r11,r10,(SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT - 2)
  99. andi. r11,r11,0x3c
  100. 5: /* Extract the psize and multiply to get an array offset */
  101. srd r9,r9,r11
  102. andi. r9,r9,0xf
  103. mulli r9,r9,MMUPSIZEDEFSIZE
  104. /* Now get to the array and obtain the sllp
  105. */
  106. ld r11,PACATOC(r13)
  107. ld r11,mmu_psize_defs@got(r11)
  108. add r11,r11,r9
  109. ld r11,MMUPSIZESLLP(r11)
  110. ori r11,r11,SLB_VSID_USER
  111. #else
  112. /* paca context sllp already contains the SLB_VSID_USER bits */
  113. lhz r11,PACACONTEXTSLLP(r13)
  114. #endif /* CONFIG_PPC_MM_SLICES */
  115. ld r9,PACACONTEXTID(r13)
  116. BEGIN_FTR_SECTION
  117. cmpldi r10,0x1000
  118. END_FTR_SECTION_IFSET(CPU_FTR_1T_SEGMENT)
  119. rldimi r10,r9,USER_ESID_BITS,0
  120. BEGIN_FTR_SECTION
  121. bge slb_finish_load_1T
  122. END_FTR_SECTION_IFSET(CPU_FTR_1T_SEGMENT)
  123. b slb_finish_load
  124. 8: /* invalid EA */
  125. li r10,0 /* BAD_VSID */
  126. li r11,SLB_VSID_USER /* flags don't much matter */
  127. b slb_finish_load
  128. #ifdef __DISABLED__
  129. /* void slb_allocate_user(unsigned long ea);
  130. *
  131. * Create an SLB entry for the given EA (user or kernel).
  132. * r3 = faulting address, r13 = PACA
  133. * r9, r10, r11 are clobbered by this function
  134. * No other registers are examined or changed.
  135. *
  136. * It is called with translation enabled in order to be able to walk the
  137. * page tables. This is not currently used.
  138. */
  139. _GLOBAL(slb_allocate_user)
  140. /* r3 = faulting address */
  141. srdi r10,r3,28 /* get esid */
  142. crset 4*cr7+lt /* set "user" flag for later */
  143. /* check if we fit in the range covered by the pagetables*/
  144. srdi. r9,r3,PGTABLE_EADDR_SIZE
  145. crnot 4*cr0+eq,4*cr0+eq
  146. beqlr
  147. /* now we need to get to the page tables in order to get the page
  148. * size encoding from the PMD. In the future, we'll be able to deal
  149. * with 1T segments too by getting the encoding from the PGD instead
  150. */
  151. ld r9,PACAPGDIR(r13)
  152. cmpldi cr0,r9,0
  153. beqlr
  154. rlwinm r11,r10,8,25,28
  155. ldx r9,r9,r11 /* get pgd_t */
  156. cmpldi cr0,r9,0
  157. beqlr
  158. rlwinm r11,r10,3,17,28
  159. ldx r9,r9,r11 /* get pmd_t */
  160. cmpldi cr0,r9,0
  161. beqlr
  162. /* build vsid flags */
  163. andi. r11,r9,SLB_VSID_LLP
  164. ori r11,r11,SLB_VSID_USER
  165. /* get context to calculate proto-VSID */
  166. ld r9,PACACONTEXTID(r13)
  167. rldimi r10,r9,USER_ESID_BITS,0
  168. /* fall through slb_finish_load */
  169. #endif /* __DISABLED__ */
  170. /*
  171. * Finish loading of an SLB entry and return
  172. *
  173. * r3 = EA, r10 = proto-VSID, r11 = flags, clobbers r9, cr7 = <> PAGE_OFFSET
  174. */
  175. slb_finish_load:
  176. ASM_VSID_SCRAMBLE(r10,r9,256M)
  177. rldimi r11,r10,SLB_VSID_SHIFT,16 /* combine VSID and flags */
  178. /* r3 = EA, r11 = VSID data */
  179. /*
  180. * Find a slot, round robin. Previously we tried to find a
  181. * free slot first but that took too long. Unfortunately we
  182. * dont have any LRU information to help us choose a slot.
  183. */
  184. #ifdef CONFIG_PPC_ISERIES
  185. BEGIN_FW_FTR_SECTION
  186. /*
  187. * On iSeries, the "bolted" stack segment can be cast out on
  188. * shared processor switch so we need to check for a miss on
  189. * it and restore it to the right slot.
  190. */
  191. ld r9,PACAKSAVE(r13)
  192. clrrdi r9,r9,28
  193. clrrdi r3,r3,28
  194. li r10,SLB_NUM_BOLTED-1 /* Stack goes in last bolted slot */
  195. cmpld r9,r3
  196. beq 3f
  197. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  198. #endif /* CONFIG_PPC_ISERIES */
  199. 7: ld r10,PACASTABRR(r13)
  200. addi r10,r10,1
  201. /* use a cpu feature mask if we ever change our slb size */
  202. cmpldi r10,SLB_NUM_ENTRIES
  203. blt+ 4f
  204. li r10,SLB_NUM_BOLTED
  205. 4:
  206. std r10,PACASTABRR(r13)
  207. 3:
  208. rldimi r3,r10,0,36 /* r3= EA[0:35] | entry */
  209. oris r10,r3,SLB_ESID_V@h /* r3 |= SLB_ESID_V */
  210. /* r3 = ESID data, r11 = VSID data */
  211. /*
  212. * No need for an isync before or after this slbmte. The exception
  213. * we enter with and the rfid we exit with are context synchronizing.
  214. */
  215. slbmte r11,r10
  216. /* we're done for kernel addresses */
  217. crclr 4*cr0+eq /* set result to "success" */
  218. bgelr cr7
  219. /* Update the slb cache */
  220. lhz r3,PACASLBCACHEPTR(r13) /* offset = paca->slb_cache_ptr */
  221. cmpldi r3,SLB_CACHE_ENTRIES
  222. bge 1f
  223. /* still room in the slb cache */
  224. sldi r11,r3,1 /* r11 = offset * sizeof(u16) */
  225. rldicl r10,r10,36,28 /* get low 16 bits of the ESID */
  226. add r11,r11,r13 /* r11 = (u16 *)paca + offset */
  227. sth r10,PACASLBCACHE(r11) /* paca->slb_cache[offset] = esid */
  228. addi r3,r3,1 /* offset++ */
  229. b 2f
  230. 1: /* offset >= SLB_CACHE_ENTRIES */
  231. li r3,SLB_CACHE_ENTRIES+1
  232. 2:
  233. sth r3,PACASLBCACHEPTR(r13) /* paca->slb_cache_ptr = offset */
  234. crclr 4*cr0+eq /* set result to "success" */
  235. blr
  236. /*
  237. * Finish loading of a 1T SLB entry (for the kernel linear mapping) and return.
  238. * We assume legacy iSeries will never have 1T segments.
  239. *
  240. * r3 = EA, r10 = proto-VSID, r11 = flags, clobbers r9
  241. */
  242. slb_finish_load_1T:
  243. srdi r10,r10,40-28 /* get 1T ESID */
  244. ASM_VSID_SCRAMBLE(r10,r9,1T)
  245. rldimi r11,r10,SLB_VSID_SHIFT_1T,16 /* combine VSID and flags */
  246. li r10,MMU_SEGSIZE_1T
  247. rldimi r11,r10,SLB_VSID_SSIZE_SHIFT,0 /* insert segment size */
  248. /* r3 = EA, r11 = VSID data */
  249. clrrdi r3,r3,SID_SHIFT_1T /* clear out non-ESID bits */
  250. b 7b