cpu_setup_power4.S 3.8 KB

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