cpu_setup_power4.S 3.9 KB

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