cpu_setup_power4.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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/ppc_asm.h>
  15. #include <asm/cputable.h>
  16. #include <asm/ppc_asm.h>
  17. #include <asm/offsets.h>
  18. #include <asm/cache.h>
  19. _GLOBAL(__970_cpu_preinit)
  20. /*
  21. * Do nothing if not running in HV mode
  22. */
  23. mfmsr r0
  24. rldicl. r0,r0,4,63
  25. beqlr
  26. /*
  27. * Deal only with PPC970 and PPC970FX.
  28. */
  29. mfspr r0,SPRN_PVR
  30. srwi r0,r0,16
  31. cmpwi cr0,r0,0x39
  32. cmpwi cr1,r0,0x3c
  33. cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
  34. bnelr
  35. /* Make sure HID4:rm_ci is off before MMU is turned off, that large
  36. * pages are enabled with HID4:61 and clear HID5:DCBZ_size and
  37. * HID5:DCBZ32_ill
  38. */
  39. li r0,0
  40. mfspr r3,SPRN_HID4
  41. rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */
  42. rldimi r3,r0,2,61 /* clear bit 61 (lg_pg_en) */
  43. sync
  44. mtspr SPRN_HID4,r3
  45. isync
  46. sync
  47. mfspr r3,SPRN_HID5
  48. rldimi r3,r0,6,56 /* clear bits 56 & 57 (DCBZ*) */
  49. sync
  50. mtspr SPRN_HID5,r3
  51. isync
  52. sync
  53. /* Setup some basic HID1 features */
  54. mfspr r0,SPRN_HID1
  55. li r3,0x1200 /* enable i-fetch cacheability */
  56. sldi r3,r3,44 /* and prefetch */
  57. or r0,r0,r3
  58. mtspr SPRN_HID1,r0
  59. mtspr SPRN_HID1,r0
  60. isync
  61. /* Clear HIOR */
  62. li r0,0
  63. sync
  64. mtspr SPRN_HIOR,0 /* Clear interrupt prefix */
  65. isync
  66. blr
  67. _GLOBAL(__setup_cpu_power4)
  68. blr
  69. _GLOBAL(__setup_cpu_be)
  70. /* Set large page sizes LP=0: 16MB, LP=1: 64KB */
  71. addi r3, 0, 0
  72. ori r3, r3, HID6_LB
  73. sldi r3, r3, 32
  74. nor r3, r3, r3
  75. mfspr r4, SPRN_HID6
  76. and r4, r4, r3
  77. addi r3, 0, 0x02000
  78. sldi r3, r3, 32
  79. or r4, r4, r3
  80. mtspr SPRN_HID6, r4
  81. blr
  82. _GLOBAL(__setup_cpu_ppc970)
  83. mfspr r0,SPRN_HID0
  84. li r11,5 /* clear DOZE and SLEEP */
  85. rldimi r0,r11,52,8 /* set NAP and DPM */
  86. mtspr SPRN_HID0,r0
  87. mfspr r0,SPRN_HID0
  88. mfspr r0,SPRN_HID0
  89. mfspr r0,SPRN_HID0
  90. mfspr r0,SPRN_HID0
  91. mfspr r0,SPRN_HID0
  92. mfspr r0,SPRN_HID0
  93. sync
  94. isync
  95. blr
  96. /* Definitions for the table use to save CPU states */
  97. #define CS_HID0 0
  98. #define CS_HID1 8
  99. #define CS_HID4 16
  100. #define CS_HID5 24
  101. #define CS_SIZE 32
  102. .data
  103. .balign L1_CACHE_BYTES,0
  104. cpu_state_storage:
  105. .space CS_SIZE
  106. .balign L1_CACHE_BYTES,0
  107. .text
  108. /* Called in normal context to backup CPU 0 state. This
  109. * does not include cache settings. This function is also
  110. * called for machine sleep. This does not include the MMU
  111. * setup, BATs, etc... but rather the "special" registers
  112. * like HID0, HID1, HID4, etc...
  113. */
  114. _GLOBAL(__save_cpu_setup)
  115. /* Some CR fields are volatile, we back it up all */
  116. mfcr r7
  117. /* Get storage ptr */
  118. LOADADDR(r5,cpu_state_storage)
  119. /* We only deal with 970 for now */
  120. mfspr r0,SPRN_PVR
  121. srwi r0,r0,16
  122. cmpwi cr0,r0,0x39
  123. cmpwi cr1,r0,0x3c
  124. cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
  125. bne 1f
  126. /* Save HID0,1,4 and 5 */
  127. mfspr r3,SPRN_HID0
  128. std r3,CS_HID0(r5)
  129. mfspr r3,SPRN_HID1
  130. std r3,CS_HID1(r5)
  131. mfspr r3,SPRN_HID4
  132. std r3,CS_HID4(r5)
  133. mfspr r3,SPRN_HID5
  134. std r3,CS_HID5(r5)
  135. 1:
  136. mtcr r7
  137. blr
  138. /* Called with no MMU context (typically MSR:IR/DR off) to
  139. * restore CPU state as backed up by the previous
  140. * function. This does not include cache setting
  141. */
  142. _GLOBAL(__restore_cpu_setup)
  143. /* Get storage ptr (FIXME when using anton reloc as we
  144. * are running with translation disabled here
  145. */
  146. LOADADDR(r5,cpu_state_storage)
  147. /* We only deal with 970 for now */
  148. mfspr r0,SPRN_PVR
  149. srwi r0,r0,16
  150. cmpwi cr0,r0,0x39
  151. cmpwi cr1,r0,0x3c
  152. cror 4*cr0+eq,4*cr0+eq,4*cr1+eq
  153. bne 1f
  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. 1:
  203. blr