cpu_setup_power4.S 4.4 KB

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