cpu_setup_power.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. /* Entry: r3 = crap, r4 = ptr to cputable entry
  18. *
  19. * Note that we can be called twice for pseudo-PVRs
  20. */
  21. _GLOBAL(__setup_cpu_power7)
  22. mflr r11
  23. bl __init_hvmode_206
  24. mtlr r11
  25. beqlr
  26. li r0,0
  27. mtspr SPRN_LPID,r0
  28. mtspr SPRN_PCR,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. mtspr SPRN_PCR,r0
  42. mfspr r3,SPRN_LPCR
  43. bl __init_LPCR
  44. bl __init_tlb_power7
  45. mtlr r11
  46. blr
  47. _GLOBAL(__setup_cpu_power8)
  48. mflr r11
  49. bl __init_FSCR
  50. bl __init_PMU
  51. bl __init_hvmode_206
  52. mtlr r11
  53. beqlr
  54. li r0,0
  55. mtspr SPRN_LPID,r0
  56. mtspr SPRN_PCR,r0
  57. mfspr r3,SPRN_LPCR
  58. ori r3, r3, LPCR_PECEDH
  59. bl __init_LPCR
  60. bl __init_HFSCR
  61. bl __init_tlb_power8
  62. bl __init_PMU_HV
  63. mtlr r11
  64. blr
  65. _GLOBAL(__restore_cpu_power8)
  66. mflr r11
  67. bl __init_FSCR
  68. bl __init_PMU
  69. mfmsr r3
  70. rldicl. r0,r3,4,63
  71. mtlr r11
  72. beqlr
  73. li r0,0
  74. mtspr SPRN_LPID,r0
  75. mtspr SPRN_PCR,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. mtlr r11
  83. blr
  84. __init_hvmode_206:
  85. /* Disable CPU_FTR_HVMODE and exit if MSR:HV is not set */
  86. mfmsr r3
  87. rldicl. r0,r3,4,63
  88. bnelr
  89. ld r5,CPU_SPEC_FEATURES(r4)
  90. LOAD_REG_IMMEDIATE(r6,CPU_FTR_HVMODE)
  91. xor r5,r5,r6
  92. std r5,CPU_SPEC_FEATURES(r4)
  93. blr
  94. __init_LPCR:
  95. /* Setup a sane LPCR:
  96. * Called with initial LPCR in R3
  97. *
  98. * LPES = 0b01 (HSRR0/1 used for 0x500)
  99. * PECE = 0b111
  100. * DPFD = 4
  101. * HDICE = 0
  102. * VC = 0b100 (VPM0=1, VPM1=0, ISL=0)
  103. * VRMASD = 0b10000 (L=1, LP=00)
  104. *
  105. * Other bits untouched for now
  106. */
  107. li r5,1
  108. rldimi r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
  109. ori r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
  110. li r5,4
  111. rldimi r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
  112. clrrdi r3,r3,1 /* clear HDICE */
  113. li r5,4
  114. rldimi r3,r5, LPCR_VC_SH, 0
  115. li r5,0x10
  116. rldimi r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5
  117. mtspr SPRN_LPCR,r3
  118. isync
  119. blr
  120. __init_FSCR:
  121. mfspr r3,SPRN_FSCR
  122. ori r3,r3,FSCR_TAR|FSCR_DSCR|FSCR_EBB
  123. mtspr SPRN_FSCR,r3
  124. blr
  125. __init_HFSCR:
  126. mfspr r3,SPRN_HFSCR
  127. ori r3,r3,HFSCR_TAR|HFSCR_TM|HFSCR_BHRB|HFSCR_PM|\
  128. HFSCR_DSCR|HFSCR_VECVSX|HFSCR_FP|HFSCR_EBB
  129. mtspr SPRN_HFSCR,r3
  130. blr
  131. /*
  132. * Clear the TLB using the specified IS form of tlbiel instruction
  133. * (invalidate by congruence class). P7 has 128 CCs., P8 has 512.
  134. */
  135. __init_tlb_power7:
  136. li r6,128
  137. mtctr r6
  138. li r7,0xc00 /* IS field = 0b11 */
  139. ptesync
  140. 2: tlbiel r7
  141. addi r7,r7,0x1000
  142. bdnz 2b
  143. ptesync
  144. 1: blr
  145. __init_tlb_power8:
  146. li r6,512
  147. mtctr r6
  148. li r7,0xc00 /* IS field = 0b11 */
  149. ptesync
  150. 2: tlbiel r7
  151. addi r7,r7,0x1000
  152. bdnz 2b
  153. ptesync
  154. 1: blr
  155. __init_PMU_HV:
  156. li r5,0
  157. mtspr SPRN_MMCRC,r5
  158. mtspr SPRN_MMCRH,r5
  159. blr
  160. __init_PMU:
  161. li r5,0
  162. mtspr SPRN_MMCRS,r5
  163. mtspr SPRN_MMCRA,r5
  164. mtspr SPRN_MMCR0,r5
  165. mtspr SPRN_MMCR1,r5
  166. mtspr SPRN_MMCR2,r5
  167. blr