idle_6xx.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * This file contains the power_save function for 6xx & 7xxx CPUs
  3. * rewritten in assembler
  4. *
  5. * Warning ! This code assumes that if your machine has a 750fx
  6. * it will have PLL 1 set to low speed mode (used during NAP/DOZE).
  7. * if this is not the case some additional changes will have to
  8. * be done to check a runtime var (a bit like powersave-nap)
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. #include <linux/threads.h>
  16. #include <asm/reg.h>
  17. #include <asm/page.h>
  18. #include <asm/cputable.h>
  19. #include <asm/thread_info.h>
  20. #include <asm/ppc_asm.h>
  21. #include <asm/asm-offsets.h>
  22. .text
  23. /*
  24. * Init idle, called at early CPU setup time from head.S for each CPU
  25. * Make sure no rest of NAP mode remains in HID0, save default
  26. * values for some CPU specific registers. Called with r24
  27. * containing CPU number and r3 reloc offset
  28. */
  29. _GLOBAL(init_idle_6xx)
  30. BEGIN_FTR_SECTION
  31. mfspr r4,SPRN_HID0
  32. rlwinm r4,r4,0,10,8 /* Clear NAP */
  33. mtspr SPRN_HID0, r4
  34. b 1f
  35. END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
  36. blr
  37. 1:
  38. slwi r5,r24,2
  39. add r5,r5,r3
  40. BEGIN_FTR_SECTION
  41. mfspr r4,SPRN_MSSCR0
  42. addis r6,r5, nap_save_msscr0@ha
  43. stw r4,nap_save_msscr0@l(r6)
  44. END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)
  45. BEGIN_FTR_SECTION
  46. mfspr r4,SPRN_HID1
  47. addis r6,r5,nap_save_hid1@ha
  48. stw r4,nap_save_hid1@l(r6)
  49. END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)
  50. blr
  51. /*
  52. * Here is the power_save_6xx function. This could eventually be
  53. * split into several functions & changing the function pointer
  54. * depending on the various features.
  55. */
  56. _GLOBAL(ppc6xx_idle)
  57. /* Check if we can nap or doze, put HID0 mask in r3
  58. */
  59. lis r3, 0
  60. BEGIN_FTR_SECTION
  61. lis r3,HID0_DOZE@h
  62. END_FTR_SECTION_IFSET(CPU_FTR_CAN_DOZE)
  63. BEGIN_FTR_SECTION
  64. /* We must dynamically check for the NAP feature as it
  65. * can be cleared by CPU init after the fixups are done
  66. */
  67. lis r4,cur_cpu_spec@ha
  68. lwz r4,cur_cpu_spec@l(r4)
  69. lwz r4,CPU_SPEC_FEATURES(r4)
  70. andi. r0,r4,CPU_FTR_CAN_NAP
  71. beq 1f
  72. /* Now check if user or arch enabled NAP mode */
  73. lis r4,powersave_nap@ha
  74. lwz r4,powersave_nap@l(r4)
  75. cmpwi 0,r4,0
  76. beq 1f
  77. lis r3,HID0_NAP@h
  78. 1:
  79. END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
  80. cmpwi 0,r3,0
  81. beqlr
  82. /* Some pre-nap cleanups needed on some CPUs */
  83. andis. r0,r3,HID0_NAP@h
  84. beq 2f
  85. BEGIN_FTR_SECTION
  86. /* Disable L2 prefetch on some 745x and try to ensure
  87. * L2 prefetch engines are idle. As explained by errata
  88. * text, we can't be sure they are, we just hope very hard
  89. * that well be enough (sic !). At least I noticed Apple
  90. * doesn't even bother doing the dcbf's here...
  91. */
  92. mfspr r4,SPRN_MSSCR0
  93. rlwinm r4,r4,0,0,29
  94. sync
  95. mtspr SPRN_MSSCR0,r4
  96. sync
  97. isync
  98. lis r4,KERNELBASE@h
  99. dcbf 0,r4
  100. dcbf 0,r4
  101. dcbf 0,r4
  102. dcbf 0,r4
  103. END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)
  104. 2:
  105. BEGIN_FTR_SECTION
  106. /* Go to low speed mode on some 750FX */
  107. lis r4,powersave_lowspeed@ha
  108. lwz r4,powersave_lowspeed@l(r4)
  109. cmpwi 0,r4,0
  110. beq 1f
  111. mfspr r4,SPRN_HID1
  112. oris r4,r4,0x0001
  113. mtspr SPRN_HID1,r4
  114. 1:
  115. END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)
  116. /* Go to NAP or DOZE now */
  117. mfspr r4,SPRN_HID0
  118. lis r5,(HID0_NAP|HID0_SLEEP)@h
  119. BEGIN_FTR_SECTION
  120. oris r5,r5,HID0_DOZE@h
  121. END_FTR_SECTION_IFSET(CPU_FTR_CAN_DOZE)
  122. andc r4,r4,r5
  123. or r4,r4,r3
  124. BEGIN_FTR_SECTION
  125. oris r4,r4,HID0_DPM@h /* that should be done once for all */
  126. END_FTR_SECTION_IFCLR(CPU_FTR_NO_DPM)
  127. mtspr SPRN_HID0,r4
  128. BEGIN_FTR_SECTION
  129. DSSALL
  130. sync
  131. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  132. CURRENT_THREAD_INFO(r9, r1)
  133. lwz r8,TI_LOCAL_FLAGS(r9) /* set napping bit */
  134. ori r8,r8,_TLF_NAPPING /* so when we take an exception */
  135. stw r8,TI_LOCAL_FLAGS(r9) /* it will return to our caller */
  136. mfmsr r7
  137. ori r7,r7,MSR_EE
  138. oris r7,r7,MSR_POW@h
  139. 1: sync
  140. mtmsr r7
  141. isync
  142. b 1b
  143. /*
  144. * Return from NAP/DOZE mode, restore some CPU specific registers,
  145. * we are called with DR/IR still off and r2 containing physical
  146. * address of current. R11 points to the exception frame (physical
  147. * address). We have to preserve r10.
  148. */
  149. _GLOBAL(power_save_ppc32_restore)
  150. lwz r9,_LINK(r11) /* interrupted in ppc6xx_idle: */
  151. stw r9,_NIP(r11) /* make it do a blr */
  152. #ifdef CONFIG_SMP
  153. CURRENT_THREAD_INFO(r12, r11)
  154. lwz r11,TI_CPU(r12) /* get cpu number * 4 */
  155. slwi r11,r11,2
  156. #else
  157. li r11,0
  158. #endif
  159. /* Todo make sure all these are in the same page
  160. * and load r11 (@ha part + CPU offset) only once
  161. */
  162. BEGIN_FTR_SECTION
  163. mfspr r9,SPRN_HID0
  164. andis. r9,r9,HID0_NAP@h
  165. beq 1f
  166. addis r9,r11,(nap_save_msscr0-KERNELBASE)@ha
  167. lwz r9,nap_save_msscr0@l(r9)
  168. mtspr SPRN_MSSCR0, r9
  169. sync
  170. isync
  171. 1:
  172. END_FTR_SECTION_IFSET(CPU_FTR_NAP_DISABLE_L2_PR)
  173. BEGIN_FTR_SECTION
  174. addis r9,r11,(nap_save_hid1-KERNELBASE)@ha
  175. lwz r9,nap_save_hid1@l(r9)
  176. mtspr SPRN_HID1, r9
  177. END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)
  178. b transfer_to_handler_cont
  179. .data
  180. _GLOBAL(nap_save_msscr0)
  181. .space 4*NR_CPUS
  182. _GLOBAL(nap_save_hid1)
  183. .space 4*NR_CPUS
  184. _GLOBAL(powersave_lowspeed)
  185. .long 0