cpu_setup_power4.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. mtspr SPRN_HID0,r0
  73. mfspr r0,SPRN_HID0
  74. mfspr r0,SPRN_HID0
  75. mfspr r0,SPRN_HID0
  76. mfspr r0,SPRN_HID0
  77. mfspr r0,SPRN_HID0
  78. mfspr r0,SPRN_HID0
  79. sync
  80. isync
  81. blr
  82. /* Definitions for the table use to save CPU states */
  83. #define CS_HID0 0
  84. #define CS_HID1 8
  85. #define CS_HID4 16
  86. #define CS_HID5 24
  87. #define CS_SIZE 32
  88. .data
  89. .balign L1_CACHE_BYTES,0
  90. cpu_state_storage:
  91. .space CS_SIZE
  92. .balign L1_CACHE_BYTES,0
  93. .text
  94. /* Called in normal context to backup CPU 0 state. This
  95. * does not include cache settings. This function is also
  96. * called for machine sleep. This does not include the MMU
  97. * setup, BATs, etc... but rather the "special" registers
  98. * like HID0, HID1, HID4, etc...
  99. */
  100. _GLOBAL(__save_cpu_setup)
  101. /* Some CR fields are volatile, we back it up all */
  102. mfcr r7
  103. /* Get storage ptr */
  104. LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
  105. /* We only deal with 970 for now */
  106. mfspr r0,SPRN_PVR
  107. srwi r0,r0,16
  108. cmpwi r0,0x39
  109. beq 1f
  110. cmpwi r0,0x3c
  111. beq 1f
  112. cmpwi r0,0x44
  113. bne 2f
  114. 1: /* skip if not running in HV mode */
  115. mfmsr r0
  116. rldicl. r0,r0,4,63
  117. beq 2f
  118. /* Save HID0,1,4 and 5 */
  119. mfspr r3,SPRN_HID0
  120. std r3,CS_HID0(r5)
  121. mfspr r3,SPRN_HID1
  122. std r3,CS_HID1(r5)
  123. mfspr r3,SPRN_HID4
  124. std r3,CS_HID4(r5)
  125. mfspr r3,SPRN_HID5
  126. std r3,CS_HID5(r5)
  127. 2:
  128. mtcr r7
  129. blr
  130. /* Called with no MMU context (typically MSR:IR/DR off) to
  131. * restore CPU state as backed up by the previous
  132. * function. This does not include cache setting
  133. */
  134. _GLOBAL(__restore_cpu_setup)
  135. /* Get storage ptr (FIXME when using anton reloc as we
  136. * are running with translation disabled here
  137. */
  138. LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
  139. /* We only deal with 970 for now */
  140. mfspr r0,SPRN_PVR
  141. srwi r0,r0,16
  142. cmpwi r0,0x39
  143. beq 1f
  144. cmpwi r0,0x3c
  145. beq 1f
  146. cmpwi r0,0x44
  147. bnelr
  148. 1: /* skip if not running in HV mode */
  149. mfmsr r0
  150. rldicl. r0,r0,4,63
  151. beqlr
  152. /* Before accessing memory, we make sure rm_ci is clear */
  153. li r0,0
  154. mfspr r3,SPRN_HID4
  155. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  156. sync
  157. mtspr SPRN_HID4,r3
  158. isync
  159. sync
  160. /* Clear interrupt prefix */
  161. li r0,0
  162. sync
  163. mtspr SPRN_HIOR,0
  164. isync
  165. /* Restore HID0 */
  166. ld r3,CS_HID0(r5)
  167. sync
  168. isync
  169. mtspr SPRN_HID0,r3
  170. mfspr r3,SPRN_HID0
  171. mfspr r3,SPRN_HID0
  172. mfspr r3,SPRN_HID0
  173. mfspr r3,SPRN_HID0
  174. mfspr r3,SPRN_HID0
  175. mfspr r3,SPRN_HID0
  176. sync
  177. isync
  178. /* Restore HID1 */
  179. ld r3,CS_HID1(r5)
  180. sync
  181. isync
  182. mtspr SPRN_HID1,r3
  183. mtspr SPRN_HID1,r3
  184. sync
  185. isync
  186. /* Restore HID4 */
  187. ld r3,CS_HID4(r5)
  188. sync
  189. isync
  190. mtspr SPRN_HID4,r3
  191. sync
  192. isync
  193. /* Restore HID5 */
  194. ld r3,CS_HID5(r5)
  195. sync
  196. isync
  197. mtspr SPRN_HID5,r3
  198. sync
  199. isync
  200. blr