cpu_setup_power4.S 4.2 KB

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