slb_low.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. /* void slb_allocate_realmode(unsigned long ea);
  24. *
  25. * Create an SLB entry for the given EA (user or kernel).
  26. * r3 = faulting address, r13 = PACA
  27. * r9, r10, r11 are clobbered by this function
  28. * No other registers are examined or changed.
  29. */
  30. _GLOBAL(slb_allocate_realmode)
  31. /* r3 = faulting address */
  32. srdi r9,r3,60 /* get region */
  33. srdi r10,r3,28 /* get esid */
  34. cmpldi cr7,r9,0xc /* cmp PAGE_OFFSET for later use */
  35. /* r3 = address, r10 = esid, cr7 = <> PAGE_OFFSET */
  36. blt cr7,0f /* user or kernel? */
  37. /* kernel address: proto-VSID = ESID */
  38. /* WARNING - MAGIC: we don't use the VSID 0xfffffffff, but
  39. * this code will generate the protoVSID 0xfffffffff for the
  40. * top segment. That's ok, the scramble below will translate
  41. * it to VSID 0, which is reserved as a bad VSID - one which
  42. * will never have any pages in it. */
  43. /* Check if hitting the linear mapping of the vmalloc/ioremap
  44. * 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. b slb_finish_load
  53. 1: /* vmalloc/ioremap mapping encoding bits, the "li" instructions below
  54. * will be patched by the kernel at boot
  55. */
  56. BEGIN_FTR_SECTION
  57. /* check whether this is in vmalloc or ioremap space */
  58. clrldi r11,r10,48
  59. cmpldi r11,(VMALLOC_SIZE >> 28) - 1
  60. bgt 5f
  61. lhz r11,PACAVMALLOCSLLP(r13)
  62. b slb_finish_load
  63. 5:
  64. END_FTR_SECTION_IFCLR(CPU_FTR_CI_LARGE_PAGE)
  65. _GLOBAL(slb_miss_kernel_load_io)
  66. li r11,0
  67. b slb_finish_load
  68. 0: /* user address: proto-VSID = context << 15 | ESID. First check
  69. * if the address is within the boundaries of the user region
  70. */
  71. srdi. r9,r10,USER_ESID_BITS
  72. bne- 8f /* invalid ea bits set */
  73. /* Figure out if the segment contains huge pages */
  74. #ifdef CONFIG_HUGETLB_PAGE
  75. BEGIN_FTR_SECTION
  76. b 1f
  77. END_FTR_SECTION_IFCLR(CPU_FTR_16M_PAGE)
  78. cmpldi r10,16
  79. lhz r9,PACALOWHTLBAREAS(r13)
  80. mr r11,r10
  81. blt 5f
  82. lhz r9,PACAHIGHHTLBAREAS(r13)
  83. srdi r11,r10,(HTLB_AREA_SHIFT-SID_SHIFT)
  84. 5: srd r9,r9,r11
  85. andi. r9,r9,1
  86. beq 1f
  87. _GLOBAL(slb_miss_user_load_huge)
  88. li r11,0
  89. b 2f
  90. 1:
  91. #endif /* CONFIG_HUGETLB_PAGE */
  92. lhz r11,PACACONTEXTSLLP(r13)
  93. 2:
  94. ld r9,PACACONTEXTID(r13)
  95. rldimi r10,r9,USER_ESID_BITS,0
  96. b slb_finish_load
  97. 8: /* invalid EA */
  98. li r10,0 /* BAD_VSID */
  99. li r11,SLB_VSID_USER /* flags don't much matter */
  100. b slb_finish_load
  101. #ifdef __DISABLED__
  102. /* void slb_allocate_user(unsigned long ea);
  103. *
  104. * Create an SLB entry for the given EA (user or kernel).
  105. * r3 = faulting address, r13 = PACA
  106. * r9, r10, r11 are clobbered by this function
  107. * No other registers are examined or changed.
  108. *
  109. * It is called with translation enabled in order to be able to walk the
  110. * page tables. This is not currently used.
  111. */
  112. _GLOBAL(slb_allocate_user)
  113. /* r3 = faulting address */
  114. srdi r10,r3,28 /* get esid */
  115. crset 4*cr7+lt /* set "user" flag for later */
  116. /* check if we fit in the range covered by the pagetables*/
  117. srdi. r9,r3,PGTABLE_EADDR_SIZE
  118. crnot 4*cr0+eq,4*cr0+eq
  119. beqlr
  120. /* now we need to get to the page tables in order to get the page
  121. * size encoding from the PMD. In the future, we'll be able to deal
  122. * with 1T segments too by getting the encoding from the PGD instead
  123. */
  124. ld r9,PACAPGDIR(r13)
  125. cmpldi cr0,r9,0
  126. beqlr
  127. rlwinm r11,r10,8,25,28
  128. ldx r9,r9,r11 /* get pgd_t */
  129. cmpldi cr0,r9,0
  130. beqlr
  131. rlwinm r11,r10,3,17,28
  132. ldx r9,r9,r11 /* get pmd_t */
  133. cmpldi cr0,r9,0
  134. beqlr
  135. /* build vsid flags */
  136. andi. r11,r9,SLB_VSID_LLP
  137. ori r11,r11,SLB_VSID_USER
  138. /* get context to calculate proto-VSID */
  139. ld r9,PACACONTEXTID(r13)
  140. rldimi r10,r9,USER_ESID_BITS,0
  141. /* fall through slb_finish_load */
  142. #endif /* __DISABLED__ */
  143. /*
  144. * Finish loading of an SLB entry and return
  145. *
  146. * r3 = EA, r10 = proto-VSID, r11 = flags, clobbers r9, cr7 = <> PAGE_OFFSET
  147. */
  148. slb_finish_load:
  149. ASM_VSID_SCRAMBLE(r10,r9)
  150. rldimi r11,r10,SLB_VSID_SHIFT,16 /* combine VSID and flags */
  151. /* r3 = EA, r11 = VSID data */
  152. /*
  153. * Find a slot, round robin. Previously we tried to find a
  154. * free slot first but that took too long. Unfortunately we
  155. * dont have any LRU information to help us choose a slot.
  156. */
  157. #ifdef CONFIG_PPC_ISERIES
  158. /*
  159. * On iSeries, the "bolted" stack segment can be cast out on
  160. * shared processor switch so we need to check for a miss on
  161. * it and restore it to the right slot.
  162. */
  163. ld r9,PACAKSAVE(r13)
  164. clrrdi r9,r9,28
  165. clrrdi r3,r3,28
  166. li r10,SLB_NUM_BOLTED-1 /* Stack goes in last bolted slot */
  167. cmpld r9,r3
  168. beq 3f
  169. #endif /* CONFIG_PPC_ISERIES */
  170. ld r10,PACASTABRR(r13)
  171. addi r10,r10,1
  172. /* use a cpu feature mask if we ever change our slb size */
  173. cmpldi r10,SLB_NUM_ENTRIES
  174. blt+ 4f
  175. li r10,SLB_NUM_BOLTED
  176. 4:
  177. std r10,PACASTABRR(r13)
  178. 3:
  179. rldimi r3,r10,0,36 /* r3= EA[0:35] | entry */
  180. oris r10,r3,SLB_ESID_V@h /* r3 |= SLB_ESID_V */
  181. /* r3 = ESID data, r11 = VSID data */
  182. /*
  183. * No need for an isync before or after this slbmte. The exception
  184. * we enter with and the rfid we exit with are context synchronizing.
  185. */
  186. slbmte r11,r10
  187. /* we're done for kernel addresses */
  188. crclr 4*cr0+eq /* set result to "success" */
  189. bgelr cr7
  190. /* Update the slb cache */
  191. lhz r3,PACASLBCACHEPTR(r13) /* offset = paca->slb_cache_ptr */
  192. cmpldi r3,SLB_CACHE_ENTRIES
  193. bge 1f
  194. /* still room in the slb cache */
  195. sldi r11,r3,1 /* r11 = offset * sizeof(u16) */
  196. rldicl r10,r10,36,28 /* get low 16 bits of the ESID */
  197. add r11,r11,r13 /* r11 = (u16 *)paca + offset */
  198. sth r10,PACASLBCACHE(r11) /* paca->slb_cache[offset] = esid */
  199. addi r3,r3,1 /* offset++ */
  200. b 2f
  201. 1: /* offset >= SLB_CACHE_ENTRIES */
  202. li r3,SLB_CACHE_ENTRIES+1
  203. 2:
  204. sth r3,PACASLBCACHEPTR(r13) /* paca->slb_cache_ptr = offset */
  205. crclr 4*cr0+eq /* set result to "success" */
  206. blr