cpu_setup_power.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * This file contains low level CPU setup functions.
  3. * Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. */
  11. #include <asm/processor.h>
  12. #include <asm/page.h>
  13. #include <asm/cputable.h>
  14. #include <asm/ppc_asm.h>
  15. #include <asm/asm-offsets.h>
  16. #include <asm/cache.h>
  17. #include <asm/book3s/64/mmu-hash.h>
  18. /* Entry: r3 = crap, r4 = ptr to cputable entry
  19. *
  20. * Note that we can be called twice for pseudo-PVRs
  21. */
  22. _GLOBAL(__setup_cpu_power7)
  23. mflr r11
  24. bl __init_hvmode_206
  25. mtlr r11
  26. beqlr
  27. li r0,0
  28. mtspr SPRN_LPID,r0
  29. mfspr r3,SPRN_LPCR
  30. bl __init_LPCR
  31. bl __init_tlb_power7
  32. mtlr r11
  33. blr
  34. _GLOBAL(__restore_cpu_power7)
  35. mflr r11
  36. mfmsr r3
  37. rldicl. r0,r3,4,63
  38. beqlr
  39. li r0,0
  40. mtspr SPRN_LPID,r0
  41. mfspr r3,SPRN_LPCR
  42. bl __init_LPCR
  43. bl __init_tlb_power7
  44. mtlr r11
  45. blr
  46. _GLOBAL(__setup_cpu_power8)
  47. mflr r11
  48. bl __init_FSCR
  49. bl __init_PMU
  50. bl __init_PMU_ISA207
  51. bl __init_hvmode_206
  52. mtlr r11
  53. beqlr
  54. li r0,0
  55. mtspr SPRN_LPID,r0
  56. mfspr r3,SPRN_LPCR
  57. ori r3, r3, LPCR_PECEDH
  58. bl __init_LPCR
  59. bl __init_HFSCR
  60. bl __init_tlb_power8
  61. bl __init_PMU_HV
  62. bl __init_PMU_HV_ISA207
  63. mtlr r11
  64. blr
  65. _GLOBAL(__restore_cpu_power8)
  66. mflr r11
  67. bl __init_FSCR
  68. bl __init_PMU
  69. bl __init_PMU_ISA207
  70. mfmsr r3
  71. rldicl. r0,r3,4,63
  72. mtlr r11
  73. beqlr
  74. li r0,0
  75. mtspr SPRN_LPID,r0
  76. mfspr r3,SPRN_LPCR
  77. ori r3, r3, LPCR_PECEDH
  78. bl __init_LPCR
  79. bl __init_HFSCR
  80. bl __init_tlb_power8
  81. bl __init_PMU_HV
  82. bl __init_PMU_HV_ISA207
  83. mtlr r11
  84. blr
  85. _GLOBAL(__setup_cpu_power9)
  86. mflr r11
  87. bl __init_FSCR
  88. bl __init_PMU
  89. bl __init_hvmode_206
  90. mtlr r11
  91. beqlr
  92. li r0,0
  93. mtspr SPRN_PSSCR,r0
  94. mtspr SPRN_LPID,r0
  95. mfspr r3,SPRN_LPCR
  96. LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE)
  97. or r3, r3, r4
  98. LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
  99. andc r3, r3, r4
  100. bl __init_LPCR
  101. bl __init_HFSCR
  102. bl __init_tlb_power9
  103. bl __init_PMU_HV
  104. mtlr r11
  105. blr
  106. _GLOBAL(__restore_cpu_power9)
  107. mflr r11
  108. bl __init_FSCR
  109. bl __init_PMU
  110. mfmsr r3
  111. rldicl. r0,r3,4,63
  112. mtlr r11
  113. beqlr
  114. li r0,0
  115. mtspr SPRN_PSSCR,r0
  116. mtspr SPRN_LPID,r0
  117. mfspr r3,SPRN_LPCR
  118. LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE)
  119. or r3, r3, r4
  120. LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
  121. andc r3, r3, r4
  122. bl __init_LPCR
  123. bl __init_HFSCR
  124. bl __init_tlb_power9
  125. bl __init_PMU_HV
  126. mtlr r11
  127. blr
  128. __init_hvmode_206:
  129. /* Disable CPU_FTR_HVMODE and exit if MSR:HV is not set */
  130. mfmsr r3
  131. rldicl. r0,r3,4,63
  132. bnelr
  133. ld r5,CPU_SPEC_FEATURES(r4)
  134. LOAD_REG_IMMEDIATE(r6,CPU_FTR_HVMODE)
  135. xor r5,r5,r6
  136. std r5,CPU_SPEC_FEATURES(r4)
  137. blr
  138. __init_LPCR:
  139. /* Setup a sane LPCR:
  140. * Called with initial LPCR in R3
  141. *
  142. * LPES = 0b01 (HSRR0/1 used for 0x500)
  143. * PECE = 0b111
  144. * DPFD = 4
  145. * HDICE = 0
  146. * VC = 0b100 (VPM0=1, VPM1=0, ISL=0)
  147. * VRMASD = 0b10000 (L=1, LP=00)
  148. *
  149. * Other bits untouched for now
  150. */
  151. li r5,1
  152. rldimi r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
  153. ori r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
  154. li r5,4
  155. rldimi r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
  156. clrrdi r3,r3,1 /* clear HDICE */
  157. li r5,4
  158. rldimi r3,r5, LPCR_VC_SH, 0
  159. li r5,0x10
  160. rldimi r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5
  161. mtspr SPRN_LPCR,r3
  162. isync
  163. blr
  164. __init_FSCR:
  165. mfspr r3,SPRN_FSCR
  166. ori r3,r3,FSCR_TAR|FSCR_DSCR|FSCR_EBB
  167. mtspr SPRN_FSCR,r3
  168. blr
  169. __init_HFSCR:
  170. mfspr r3,SPRN_HFSCR
  171. ori r3,r3,HFSCR_TAR|HFSCR_TM|HFSCR_BHRB|HFSCR_PM|\
  172. HFSCR_DSCR|HFSCR_VECVSX|HFSCR_FP|HFSCR_EBB|HFSCR_MSGP
  173. mtspr SPRN_HFSCR,r3
  174. blr
  175. /*
  176. * Clear the TLB using the specified IS form of tlbiel instruction
  177. * (invalidate by congruence class). P7 has 128 CCs., P8 has 512.
  178. */
  179. __init_tlb_power7:
  180. li r6,POWER7_TLB_SETS
  181. mtctr r6
  182. li r7,0xc00 /* IS field = 0b11 */
  183. ptesync
  184. 2: tlbiel r7
  185. addi r7,r7,0x1000
  186. bdnz 2b
  187. ptesync
  188. 1: blr
  189. __init_tlb_power8:
  190. li r6,POWER8_TLB_SETS
  191. mtctr r6
  192. li r7,0xc00 /* IS field = 0b11 */
  193. ptesync
  194. 2: tlbiel r7
  195. addi r7,r7,0x1000
  196. bdnz 2b
  197. ptesync
  198. 1: blr
  199. __init_tlb_power9:
  200. li r6,POWER9_TLB_SETS_HASH
  201. mtctr r6
  202. li r7,0xc00 /* IS field = 0b11 */
  203. ptesync
  204. 2: tlbiel r7
  205. addi r7,r7,0x1000
  206. bdnz 2b
  207. ptesync
  208. 1: blr
  209. __init_PMU_HV:
  210. li r5,0
  211. mtspr SPRN_MMCRC,r5
  212. blr
  213. __init_PMU_HV_ISA207:
  214. li r5,0
  215. mtspr SPRN_MMCRH,r5
  216. blr
  217. __init_PMU:
  218. li r5,0
  219. mtspr SPRN_MMCRA,r5
  220. mtspr SPRN_MMCR0,r5
  221. mtspr SPRN_MMCR1,r5
  222. mtspr SPRN_MMCR2,r5
  223. blr
  224. __init_PMU_ISA207:
  225. li r5,0
  226. mtspr SPRN_MMCRS,r5
  227. blr