cpu_setup_power4.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. _GLOBAL(__970_cpu_preinit)
  18. /*
  19. * Do nothing if not running in HV mode
  20. */
  21. mfmsr r0
  22. rldicl. r0,r0,4,63
  23. beqlr
  24. /*
  25. * Deal only with PPC970 and PPC970FX.
  26. */
  27. mfspr r0,SPRN_PVR
  28. srwi r0,r0,16
  29. cmpwi r0,0x39
  30. beq 1f
  31. cmpwi r0,0x3c
  32. beq 1f
  33. cmpwi r0,0x44
  34. bnelr
  35. 1:
  36. /* Make sure HID4:rm_ci is off before MMU is turned off, that large
  37. * pages are enabled with HID4:61 and clear HID5:DCBZ_size and
  38. * HID5:DCBZ32_ill
  39. */
  40. li r0,0
  41. mfspr r3,SPRN_HID4
  42. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  43. rldimi r3,r0,2,61 /* clear bit 61 (lg_pg_en) */
  44. sync
  45. mtspr SPRN_HID4,r3
  46. isync
  47. sync
  48. mfspr r3,SPRN_HID5
  49. rldimi r3,r0,6,56 /* clear bits 56 & 57 (DCBZ*) */
  50. sync
  51. mtspr SPRN_HID5,r3
  52. isync
  53. sync
  54. /* Setup some basic HID1 features */
  55. mfspr r0,SPRN_HID1
  56. li r3,0x1200 /* enable i-fetch cacheability */
  57. sldi r3,r3,44 /* and prefetch */
  58. or r0,r0,r3
  59. mtspr SPRN_HID1,r0
  60. mtspr SPRN_HID1,r0
  61. isync
  62. /* Clear HIOR */
  63. li r0,0
  64. sync
  65. mtspr SPRN_HIOR,0 /* Clear interrupt prefix */
  66. isync
  67. blr
  68. _GLOBAL(__setup_cpu_ppc970)
  69. mfspr r0,SPRN_HID0
  70. li r11,5 /* clear DOZE and SLEEP */
  71. rldimi r0,r11,52,8 /* set NAP and DPM */
  72. li r11,0
  73. rldimi r0,r11,32,31 /* clear EN_ATTN */
  74. mtspr SPRN_HID0,r0
  75. mfspr r0,SPRN_HID0
  76. mfspr r0,SPRN_HID0
  77. mfspr r0,SPRN_HID0
  78. mfspr r0,SPRN_HID0
  79. mfspr r0,SPRN_HID0
  80. mfspr r0,SPRN_HID0
  81. sync
  82. isync
  83. blr
  84. /* Definitions for the table use to save CPU states */
  85. #define CS_HID0 0
  86. #define CS_HID1 8
  87. #define CS_HID4 16
  88. #define CS_HID5 24
  89. #define CS_SIZE 32
  90. .data
  91. .balign L1_CACHE_BYTES,0
  92. cpu_state_storage:
  93. .space CS_SIZE
  94. .balign L1_CACHE_BYTES,0
  95. .text
  96. /* Called in normal context to backup CPU 0 state. This
  97. * does not include cache settings. This function is also
  98. * called for machine sleep. This does not include the MMU
  99. * setup, BATs, etc... but rather the "special" registers
  100. * like HID0, HID1, HID4, etc...
  101. */
  102. _GLOBAL(__save_cpu_setup)
  103. /* Some CR fields are volatile, we back it up all */
  104. mfcr r7
  105. /* Get storage ptr */
  106. LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
  107. /* We only deal with 970 for now */
  108. mfspr r0,SPRN_PVR
  109. srwi r0,r0,16
  110. cmpwi r0,0x39
  111. beq 1f
  112. cmpwi r0,0x3c
  113. beq 1f
  114. cmpwi r0,0x44
  115. bne 2f
  116. 1: /* skip if not running in HV mode */
  117. mfmsr r0
  118. rldicl. r0,r0,4,63
  119. beq 2f
  120. /* Save HID0,1,4 and 5 */
  121. mfspr r3,SPRN_HID0
  122. std r3,CS_HID0(r5)
  123. mfspr r3,SPRN_HID1
  124. std r3,CS_HID1(r5)
  125. mfspr r3,SPRN_HID4
  126. std r3,CS_HID4(r5)
  127. mfspr r3,SPRN_HID5
  128. std r3,CS_HID5(r5)
  129. 2:
  130. mtcr r7
  131. blr
  132. /* Called with no MMU context (typically MSR:IR/DR off) to
  133. * restore CPU state as backed up by the previous
  134. * function. This does not include cache setting
  135. */
  136. _GLOBAL(__restore_cpu_setup)
  137. /* Get storage ptr (FIXME when using anton reloc as we
  138. * are running with translation disabled here
  139. */
  140. LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
  141. /* We only deal with 970 for now */
  142. mfspr r0,SPRN_PVR
  143. srwi r0,r0,16
  144. cmpwi r0,0x39
  145. beq 1f
  146. cmpwi r0,0x3c
  147. beq 1f
  148. cmpwi r0,0x44
  149. bnelr
  150. 1: /* skip if not running in HV mode */
  151. mfmsr r0
  152. rldicl. r0,r0,4,63
  153. beqlr
  154. /* Before accessing memory, we make sure rm_ci is clear */
  155. li r0,0
  156. mfspr r3,SPRN_HID4
  157. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  158. sync
  159. mtspr SPRN_HID4,r3
  160. isync
  161. sync
  162. /* Clear interrupt prefix */
  163. li r0,0
  164. sync
  165. mtspr SPRN_HIOR,0
  166. isync
  167. /* Restore HID0 */
  168. ld r3,CS_HID0(r5)
  169. sync
  170. isync
  171. mtspr SPRN_HID0,r3
  172. mfspr r3,SPRN_HID0
  173. mfspr r3,SPRN_HID0
  174. mfspr r3,SPRN_HID0
  175. mfspr r3,SPRN_HID0
  176. mfspr r3,SPRN_HID0
  177. mfspr r3,SPRN_HID0
  178. sync
  179. isync
  180. /* Restore HID1 */
  181. ld r3,CS_HID1(r5)
  182. sync
  183. isync
  184. mtspr SPRN_HID1,r3
  185. mtspr SPRN_HID1,r3
  186. sync
  187. isync
  188. /* Restore HID4 */
  189. ld r3,CS_HID4(r5)
  190. sync
  191. isync
  192. mtspr SPRN_HID4,r3
  193. sync
  194. isync
  195. /* Restore HID5 */
  196. ld r3,CS_HID5(r5)
  197. sync
  198. isync
  199. mtspr SPRN_HID5,r3
  200. sync
  201. isync
  202. blr