cpu_setup_power4.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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: /* Save HID0,1,4 and 5 */
  116. mfspr r3,SPRN_HID0
  117. std r3,CS_HID0(r5)
  118. mfspr r3,SPRN_HID1
  119. std r3,CS_HID1(r5)
  120. mfspr r3,SPRN_HID4
  121. std r3,CS_HID4(r5)
  122. mfspr r3,SPRN_HID5
  123. std r3,CS_HID5(r5)
  124. 2:
  125. mtcr r7
  126. blr
  127. /* Called with no MMU context (typically MSR:IR/DR off) to
  128. * restore CPU state as backed up by the previous
  129. * function. This does not include cache setting
  130. */
  131. _GLOBAL(__restore_cpu_setup)
  132. /* Get storage ptr (FIXME when using anton reloc as we
  133. * are running with translation disabled here
  134. */
  135. LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
  136. /* We only deal with 970 for now */
  137. mfspr r0,SPRN_PVR
  138. srwi r0,r0,16
  139. cmpwi r0,0x39
  140. beq 1f
  141. cmpwi r0,0x3c
  142. beq 1f
  143. cmpwi r0,0x44
  144. bnelr
  145. 1: /* Before accessing memory, we make sure rm_ci is clear */
  146. li r0,0
  147. mfspr r3,SPRN_HID4
  148. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  149. sync
  150. mtspr SPRN_HID4,r3
  151. isync
  152. sync
  153. /* Clear interrupt prefix */
  154. li r0,0
  155. sync
  156. mtspr SPRN_HIOR,0
  157. isync
  158. /* Restore HID0 */
  159. ld r3,CS_HID0(r5)
  160. sync
  161. isync
  162. mtspr SPRN_HID0,r3
  163. mfspr r3,SPRN_HID0
  164. mfspr r3,SPRN_HID0
  165. mfspr r3,SPRN_HID0
  166. mfspr r3,SPRN_HID0
  167. mfspr r3,SPRN_HID0
  168. mfspr r3,SPRN_HID0
  169. sync
  170. isync
  171. /* Restore HID1 */
  172. ld r3,CS_HID1(r5)
  173. sync
  174. isync
  175. mtspr SPRN_HID1,r3
  176. mtspr SPRN_HID1,r3
  177. sync
  178. isync
  179. /* Restore HID4 */
  180. ld r3,CS_HID4(r5)
  181. sync
  182. isync
  183. mtspr SPRN_HID4,r3
  184. sync
  185. isync
  186. /* Restore HID5 */
  187. ld r3,CS_HID5(r5)
  188. sync
  189. isync
  190. mtspr SPRN_HID5,r3
  191. sync
  192. isync
  193. blr