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