cpu_setup_ppc970.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * This file contains low level CPU setup functions.
  4. * Copyright (C) 2003 Benjamin Herrenschmidt ([email protected])
  5. */
  6. #include <asm/processor.h>
  7. #include <asm/page.h>
  8. #include <asm/cputable.h>
  9. #include <asm/ppc_asm.h>
  10. #include <asm/asm-offsets.h>
  11. #include <asm/cache.h>
  12. _GLOBAL(__cpu_preinit_ppc970)
  13. /* Do nothing if not running in HV mode */
  14. mfmsr r0
  15. rldicl. r0,r0,4,63
  16. beqlr
  17. /* Make sure HID4:rm_ci is off before MMU is turned off, that large
  18. * pages are enabled with HID4:61 and clear HID5:DCBZ_size and
  19. * HID5:DCBZ32_ill
  20. */
  21. li r0,0
  22. mfspr r3,SPRN_HID4
  23. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  24. rldimi r3,r0,2,61 /* clear bit 61 (lg_pg_en) */
  25. sync
  26. mtspr SPRN_HID4,r3
  27. isync
  28. sync
  29. mfspr r3,SPRN_HID5
  30. rldimi r3,r0,6,56 /* clear bits 56 & 57 (DCBZ*) */
  31. sync
  32. mtspr SPRN_HID5,r3
  33. isync
  34. sync
  35. /* Setup some basic HID1 features */
  36. mfspr r0,SPRN_HID1
  37. li r3,0x1200 /* enable i-fetch cacheability */
  38. sldi r3,r3,44 /* and prefetch */
  39. or r0,r0,r3
  40. mtspr SPRN_HID1,r0
  41. mtspr SPRN_HID1,r0
  42. isync
  43. /* Clear HIOR */
  44. li r0,0
  45. sync
  46. mtspr SPRN_HIOR,0 /* Clear interrupt prefix */
  47. isync
  48. blr
  49. /* Definitions for the table use to save CPU states */
  50. #define CS_HID0 0
  51. #define CS_HID1 8
  52. #define CS_HID4 16
  53. #define CS_HID5 24
  54. #define CS_SIZE 32
  55. .data
  56. .balign L1_CACHE_BYTES,0
  57. cpu_state_storage:
  58. .space CS_SIZE
  59. .balign L1_CACHE_BYTES,0
  60. .text
  61. _GLOBAL(__setup_cpu_ppc970)
  62. /* Do nothing if not running in HV mode */
  63. mfmsr r0
  64. rldicl. r0,r0,4,63
  65. beq no_hv_mode
  66. mfspr r0,SPRN_HID0
  67. li r11,5 /* clear DOZE and SLEEP */
  68. rldimi r0,r11,52,8 /* set NAP and DPM */
  69. li r11,0
  70. rldimi r0,r11,32,31 /* clear EN_ATTN */
  71. b load_hids /* Jump to shared code */
  72. _GLOBAL(__setup_cpu_ppc970MP)
  73. /* Do nothing if not running in HV mode */
  74. mfmsr r0
  75. rldicl. r0,r0,4,63
  76. beq no_hv_mode
  77. mfspr r0,SPRN_HID0
  78. li r11,0x15 /* clear DOZE and SLEEP */
  79. rldimi r0,r11,52,6 /* set DEEPNAP, NAP and DPM */
  80. li r11,0
  81. rldimi r0,r11,32,31 /* clear EN_ATTN */
  82. load_hids:
  83. mtspr SPRN_HID0,r0
  84. mfspr r0,SPRN_HID0
  85. mfspr r0,SPRN_HID0
  86. mfspr r0,SPRN_HID0
  87. mfspr r0,SPRN_HID0
  88. mfspr r0,SPRN_HID0
  89. mfspr r0,SPRN_HID0
  90. sync
  91. isync
  92. /* Try to set LPES = 01 in HID4 */
  93. mfspr r0,SPRN_HID4
  94. clrldi r0,r0,1 /* clear LPES0 */
  95. ori r0,r0,HID4_LPES1 /* set LPES1 */
  96. sync
  97. mtspr SPRN_HID4,r0
  98. isync
  99. /* Save away cpu state */
  100. LOAD_REG_ADDR(r5,cpu_state_storage)
  101. /* Save HID0,1,4 and 5 */
  102. mfspr r3,SPRN_HID0
  103. std r3,CS_HID0(r5)
  104. mfspr r3,SPRN_HID1
  105. std r3,CS_HID1(r5)
  106. mfspr r4,SPRN_HID4
  107. std r4,CS_HID4(r5)
  108. mfspr r3,SPRN_HID5
  109. std r3,CS_HID5(r5)
  110. /* See if we successfully set LPES1 to 1; if not we are in Apple mode */
  111. andi. r4,r4,HID4_LPES1
  112. bnelr
  113. no_hv_mode:
  114. /* Disable CPU_FTR_HVMODE and exit, since we don't have HV mode */
  115. ld r5,CPU_SPEC_FEATURES(r4)
  116. LOAD_REG_IMMEDIATE(r6,CPU_FTR_HVMODE)
  117. andc r5,r5,r6
  118. std r5,CPU_SPEC_FEATURES(r4)
  119. blr
  120. /* Called with no MMU context (typically MSR:IR/DR off) to
  121. * restore CPU state as backed up by the previous
  122. * function. This does not include cache setting
  123. */
  124. _GLOBAL(__restore_cpu_ppc970)
  125. /* Do nothing if not running in HV mode */
  126. mfmsr r0
  127. rldicl. r0,r0,4,63
  128. beqlr
  129. LOAD_REG_ADDR(r5,cpu_state_storage)
  130. /* Before accessing memory, we make sure rm_ci is clear */
  131. li r0,0
  132. mfspr r3,SPRN_HID4
  133. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  134. sync
  135. mtspr SPRN_HID4,r3
  136. isync
  137. sync
  138. /* Clear interrupt prefix */
  139. li r0,0
  140. sync
  141. mtspr SPRN_HIOR,0
  142. isync
  143. /* Restore HID0 */
  144. ld r3,CS_HID0(r5)
  145. sync
  146. isync
  147. mtspr SPRN_HID0,r3
  148. mfspr r3,SPRN_HID0
  149. mfspr r3,SPRN_HID0
  150. mfspr r3,SPRN_HID0
  151. mfspr r3,SPRN_HID0
  152. mfspr r3,SPRN_HID0
  153. mfspr r3,SPRN_HID0
  154. sync
  155. isync
  156. /* Restore HID1 */
  157. ld r3,CS_HID1(r5)
  158. sync
  159. isync
  160. mtspr SPRN_HID1,r3
  161. mtspr SPRN_HID1,r3
  162. sync
  163. isync
  164. /* Restore HID4 */
  165. ld r3,CS_HID4(r5)
  166. sync
  167. isync
  168. mtspr SPRN_HID4,r3
  169. sync
  170. isync
  171. /* Restore HID5 */
  172. ld r3,CS_HID5(r5)
  173. sync
  174. isync
  175. mtspr SPRN_HID5,r3
  176. sync
  177. isync
  178. blr