slb_low.S 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 or some other kernel space
  45. */
  46. bne cr7,1f
  47. /* Linear mapping encoding bits, the "li" instruction below will
  48. * be patched by the kernel at boot
  49. */
  50. _GLOBAL(slb_miss_kernel_load_linear)
  51. li r11,0
  52. li r9,0x1
  53. /*
  54. * for 1T we shift 12 bits more. slb_finish_load_1T will do
  55. * the necessary adjustment
  56. */
  57. rldimi r10,r9,(CONTEXT_BITS + USER_ESID_BITS),0
  58. BEGIN_FTR_SECTION
  59. b slb_finish_load
  60. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
  61. b slb_finish_load_1T
  62. 1:
  63. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  64. /* Check virtual memmap region. To be patches at kernel boot */
  65. cmpldi cr0,r9,0xf
  66. bne 1f
  67. _GLOBAL(slb_miss_kernel_load_vmemmap)
  68. li r11,0
  69. b 6f
  70. 1:
  71. #endif /* CONFIG_SPARSEMEM_VMEMMAP */
  72. /* vmalloc mapping gets the encoding from the PACA as the mapping
  73. * can be demoted from 64K -> 4K dynamically on some machines
  74. */
  75. clrldi r11,r10,48
  76. cmpldi r11,(VMALLOC_SIZE >> 28) - 1
  77. bgt 5f
  78. lhz r11,PACAVMALLOCSLLP(r13)
  79. b 6f
  80. 5:
  81. /* IO mapping */
  82. _GLOBAL(slb_miss_kernel_load_io)
  83. li r11,0
  84. 6:
  85. li r9,0x1
  86. /*
  87. * for 1T we shift 12 bits more. slb_finish_load_1T will do
  88. * the necessary adjustment
  89. */
  90. rldimi r10,r9,(CONTEXT_BITS + USER_ESID_BITS),0
  91. BEGIN_FTR_SECTION
  92. b slb_finish_load
  93. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
  94. b slb_finish_load_1T
  95. 0: /* user address: proto-VSID = context << 15 | ESID. First check
  96. * if the address is within the boundaries of the user region
  97. */
  98. srdi. r9,r10,USER_ESID_BITS
  99. bne- 8f /* invalid ea bits set */
  100. /* when using slices, we extract the psize off the slice bitmaps
  101. * and then we need to get the sllp encoding off the mmu_psize_defs
  102. * array.
  103. *
  104. * XXX This is a bit inefficient especially for the normal case,
  105. * so we should try to implement a fast path for the standard page
  106. * size using the old sllp value so we avoid the array. We cannot
  107. * really do dynamic patching unfortunately as processes might flip
  108. * between 4k and 64k standard page size
  109. */
  110. #ifdef CONFIG_PPC_MM_SLICES
  111. /* r10 have esid */
  112. cmpldi r10,16
  113. /* below SLICE_LOW_TOP */
  114. blt 5f
  115. /*
  116. * Handle hpsizes,
  117. * r9 is get_paca()->context.high_slices_psize[index], r11 is mask_index
  118. */
  119. srdi r11,r10,(SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT + 1) /* index */
  120. addi r9,r11,PACAHIGHSLICEPSIZE
  121. lbzx r9,r13,r9 /* r9 is hpsizes[r11] */
  122. /* r11 = (r10 >> (SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT)) & 0x1 */
  123. rldicl r11,r10,(64 - (SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT)),63
  124. b 6f
  125. 5:
  126. /*
  127. * Handle lpsizes
  128. * r9 is get_paca()->context.low_slices_psize, r11 is index
  129. */
  130. ld r9,PACALOWSLICESPSIZE(r13)
  131. mr r11,r10
  132. 6:
  133. sldi r11,r11,2 /* index * 4 */
  134. /* Extract the psize and multiply to get an array offset */
  135. srd r9,r9,r11
  136. andi. r9,r9,0xf
  137. mulli r9,r9,MMUPSIZEDEFSIZE
  138. /* Now get to the array and obtain the sllp
  139. */
  140. ld r11,PACATOC(r13)
  141. ld r11,mmu_psize_defs@got(r11)
  142. add r11,r11,r9
  143. ld r11,MMUPSIZESLLP(r11)
  144. ori r11,r11,SLB_VSID_USER
  145. #else
  146. /* paca context sllp already contains the SLB_VSID_USER bits */
  147. lhz r11,PACACONTEXTSLLP(r13)
  148. #endif /* CONFIG_PPC_MM_SLICES */
  149. ld r9,PACACONTEXTID(r13)
  150. BEGIN_FTR_SECTION
  151. cmpldi r10,0x1000
  152. END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
  153. rldimi r10,r9,USER_ESID_BITS,0
  154. BEGIN_FTR_SECTION
  155. bge slb_finish_load_1T
  156. END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
  157. b slb_finish_load
  158. 8: /* invalid EA */
  159. li r10,0 /* BAD_VSID */
  160. li r11,SLB_VSID_USER /* flags don't much matter */
  161. b slb_finish_load
  162. #ifdef __DISABLED__
  163. /* void slb_allocate_user(unsigned long ea);
  164. *
  165. * Create an SLB entry for the given EA (user or kernel).
  166. * r3 = faulting address, r13 = PACA
  167. * r9, r10, r11 are clobbered by this function
  168. * No other registers are examined or changed.
  169. *
  170. * It is called with translation enabled in order to be able to walk the
  171. * page tables. This is not currently used.
  172. */
  173. _GLOBAL(slb_allocate_user)
  174. /* r3 = faulting address */
  175. srdi r10,r3,28 /* get esid */
  176. crset 4*cr7+lt /* set "user" flag for later */
  177. /* check if we fit in the range covered by the pagetables*/
  178. srdi. r9,r3,PGTABLE_EADDR_SIZE
  179. crnot 4*cr0+eq,4*cr0+eq
  180. beqlr
  181. /* now we need to get to the page tables in order to get the page
  182. * size encoding from the PMD. In the future, we'll be able to deal
  183. * with 1T segments too by getting the encoding from the PGD instead
  184. */
  185. ld r9,PACAPGDIR(r13)
  186. cmpldi cr0,r9,0
  187. beqlr
  188. rlwinm r11,r10,8,25,28
  189. ldx r9,r9,r11 /* get pgd_t */
  190. cmpldi cr0,r9,0
  191. beqlr
  192. rlwinm r11,r10,3,17,28
  193. ldx r9,r9,r11 /* get pmd_t */
  194. cmpldi cr0,r9,0
  195. beqlr
  196. /* build vsid flags */
  197. andi. r11,r9,SLB_VSID_LLP
  198. ori r11,r11,SLB_VSID_USER
  199. /* get context to calculate proto-VSID */
  200. ld r9,PACACONTEXTID(r13)
  201. rldimi r10,r9,USER_ESID_BITS,0
  202. /* fall through slb_finish_load */
  203. #endif /* __DISABLED__ */
  204. /*
  205. * Finish loading of an SLB entry and return
  206. *
  207. * r3 = EA, r10 = proto-VSID, r11 = flags, clobbers r9, cr7 = <> PAGE_OFFSET
  208. */
  209. slb_finish_load:
  210. ASM_VSID_SCRAMBLE(r10,r9,256M)
  211. /*
  212. * bits above VSID_BITS_256M need to be ignored from r10
  213. * also combine VSID and flags
  214. */
  215. rldimi r11,r10,SLB_VSID_SHIFT,(64 - (SLB_VSID_SHIFT + VSID_BITS_256M))
  216. /* r3 = EA, r11 = VSID data */
  217. /*
  218. * Find a slot, round robin. Previously we tried to find a
  219. * free slot first but that took too long. Unfortunately we
  220. * dont have any LRU information to help us choose a slot.
  221. */
  222. 7: ld r10,PACASTABRR(r13)
  223. addi r10,r10,1
  224. /* This gets soft patched on boot. */
  225. _GLOBAL(slb_compare_rr_to_size)
  226. cmpldi r10,0
  227. blt+ 4f
  228. li r10,SLB_NUM_BOLTED
  229. 4:
  230. std r10,PACASTABRR(r13)
  231. 3:
  232. rldimi r3,r10,0,36 /* r3= EA[0:35] | entry */
  233. oris r10,r3,SLB_ESID_V@h /* r3 |= SLB_ESID_V */
  234. /* r3 = ESID data, r11 = VSID data */
  235. /*
  236. * No need for an isync before or after this slbmte. The exception
  237. * we enter with and the rfid we exit with are context synchronizing.
  238. */
  239. slbmte r11,r10
  240. /* we're done for kernel addresses */
  241. crclr 4*cr0+eq /* set result to "success" */
  242. bgelr cr7
  243. /* Update the slb cache */
  244. lhz r3,PACASLBCACHEPTR(r13) /* offset = paca->slb_cache_ptr */
  245. cmpldi r3,SLB_CACHE_ENTRIES
  246. bge 1f
  247. /* still room in the slb cache */
  248. sldi r11,r3,2 /* r11 = offset * sizeof(u32) */
  249. srdi r10,r10,28 /* get the 36 bits of the ESID */
  250. add r11,r11,r13 /* r11 = (u32 *)paca + offset */
  251. stw r10,PACASLBCACHE(r11) /* paca->slb_cache[offset] = esid */
  252. addi r3,r3,1 /* offset++ */
  253. b 2f
  254. 1: /* offset >= SLB_CACHE_ENTRIES */
  255. li r3,SLB_CACHE_ENTRIES+1
  256. 2:
  257. sth r3,PACASLBCACHEPTR(r13) /* paca->slb_cache_ptr = offset */
  258. crclr 4*cr0+eq /* set result to "success" */
  259. blr
  260. /*
  261. * Finish loading of a 1T SLB entry (for the kernel linear mapping) and return.
  262. *
  263. * r3 = EA, r10 = proto-VSID, r11 = flags, clobbers r9
  264. */
  265. slb_finish_load_1T:
  266. srdi r10,r10,40-28 /* get 1T ESID */
  267. ASM_VSID_SCRAMBLE(r10,r9,1T)
  268. /*
  269. * bits above VSID_BITS_1T need to be ignored from r10
  270. * also combine VSID and flags
  271. */
  272. rldimi r11,r10,SLB_VSID_SHIFT_1T,(64 - (SLB_VSID_SHIFT_1T + VSID_BITS_1T))
  273. li r10,MMU_SEGSIZE_1T
  274. rldimi r11,r10,SLB_VSID_SSIZE_SHIFT,0 /* insert segment size */
  275. /* r3 = EA, r11 = VSID data */
  276. clrrdi r3,r3,SID_SHIFT_1T /* clear out non-ESID bits */
  277. b 7b