idle_power7.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * This file contains the power_save function for Power7 CPUs.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/threads.h>
  10. #include <asm/processor.h>
  11. #include <asm/page.h>
  12. #include <asm/cputable.h>
  13. #include <asm/thread_info.h>
  14. #include <asm/ppc_asm.h>
  15. #include <asm/asm-offsets.h>
  16. #include <asm/ppc-opcode.h>
  17. #include <asm/hw_irq.h>
  18. #include <asm/kvm_book3s_asm.h>
  19. #include <asm/opal.h>
  20. #undef DEBUG
  21. /* Idle state entry routines */
  22. #define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
  23. /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
  24. std r0,0(r1); \
  25. ptesync; \
  26. ld r0,0(r1); \
  27. 1: cmp cr0,r0,r0; \
  28. bne 1b; \
  29. IDLE_INST; \
  30. b .
  31. .text
  32. /*
  33. * Pass requested state in r3:
  34. * 0 - nap
  35. * 1 - sleep
  36. *
  37. * To check IRQ_HAPPENED in r4
  38. * 0 - don't check
  39. * 1 - check
  40. */
  41. _GLOBAL(power7_powersave_common)
  42. /* Use r3 to pass state nap/sleep/winkle */
  43. /* NAP is a state loss, we create a regs frame on the
  44. * stack, fill it up with the state we care about and
  45. * stick a pointer to it in PACAR1. We really only
  46. * need to save PC, some CR bits and the NV GPRs,
  47. * but for now an interrupt frame will do.
  48. */
  49. mflr r0
  50. std r0,16(r1)
  51. stdu r1,-INT_FRAME_SIZE(r1)
  52. std r0,_LINK(r1)
  53. std r0,_NIP(r1)
  54. #ifndef CONFIG_SMP
  55. /* Make sure FPU, VSX etc... are flushed as we may lose
  56. * state when going to nap mode
  57. */
  58. bl discard_lazy_cpu_state
  59. #endif /* CONFIG_SMP */
  60. /* Hard disable interrupts */
  61. mfmsr r9
  62. rldicl r9,r9,48,1
  63. rotldi r9,r9,16
  64. mtmsrd r9,1 /* hard-disable interrupts */
  65. /* Check if something happened while soft-disabled */
  66. lbz r0,PACAIRQHAPPENED(r13)
  67. cmpwi cr0,r0,0
  68. beq 1f
  69. cmpwi cr0,r4,0
  70. beq 1f
  71. addi r1,r1,INT_FRAME_SIZE
  72. ld r0,16(r1)
  73. mtlr r0
  74. blr
  75. 1: /* We mark irqs hard disabled as this is the state we'll
  76. * be in when returning and we need to tell arch_local_irq_restore()
  77. * about it
  78. */
  79. li r0,PACA_IRQ_HARD_DIS
  80. stb r0,PACAIRQHAPPENED(r13)
  81. /* We haven't lost state ... yet */
  82. li r0,0
  83. stb r0,PACA_NAPSTATELOST(r13)
  84. /* Continue saving state */
  85. SAVE_GPR(2, r1)
  86. SAVE_NVGPRS(r1)
  87. mfcr r4
  88. std r4,_CCR(r1)
  89. std r9,_MSR(r1)
  90. std r1,PACAR1(r13)
  91. _GLOBAL(power7_enter_nap_mode)
  92. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  93. /* Tell KVM we're napping */
  94. li r4,KVM_HWTHREAD_IN_NAP
  95. stb r4,HSTATE_HWTHREAD_STATE(r13)
  96. #endif
  97. cmpwi cr0,r3,1
  98. beq 2f
  99. IDLE_STATE_ENTER_SEQ(PPC_NAP)
  100. /* No return */
  101. 2: IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
  102. /* No return */
  103. _GLOBAL(power7_idle)
  104. /* Now check if user or arch enabled NAP mode */
  105. LOAD_REG_ADDRBASE(r3,powersave_nap)
  106. lwz r4,ADDROFF(powersave_nap)(r3)
  107. cmpwi 0,r4,0
  108. beqlr
  109. li r3, 1
  110. /* fall through */
  111. _GLOBAL(power7_nap)
  112. mr r4,r3
  113. li r3,0
  114. b power7_powersave_common
  115. /* No return */
  116. _GLOBAL(power7_sleep)
  117. li r3,1
  118. li r4,1
  119. b power7_powersave_common
  120. /* No return */
  121. _GLOBAL(power7_wakeup_tb_loss)
  122. ld r2,PACATOC(r13);
  123. ld r1,PACAR1(r13)
  124. /* Time base re-sync */
  125. li r0,OPAL_RESYNC_TIMEBASE
  126. LOAD_REG_ADDR(r11,opal);
  127. ld r12,8(r11);
  128. ld r2,0(r11);
  129. mtctr r12
  130. bctrl
  131. /* TODO: Check r3 for failure */
  132. REST_NVGPRS(r1)
  133. REST_GPR(2, r1)
  134. ld r3,_CCR(r1)
  135. ld r4,_MSR(r1)
  136. ld r5,_NIP(r1)
  137. addi r1,r1,INT_FRAME_SIZE
  138. mtcr r3
  139. mfspr r3,SPRN_SRR1 /* Return SRR1 */
  140. mtspr SPRN_SRR1,r4
  141. mtspr SPRN_SRR0,r5
  142. rfid
  143. _GLOBAL(power7_wakeup_loss)
  144. ld r1,PACAR1(r13)
  145. REST_NVGPRS(r1)
  146. REST_GPR(2, r1)
  147. ld r3,_CCR(r1)
  148. ld r4,_MSR(r1)
  149. ld r5,_NIP(r1)
  150. addi r1,r1,INT_FRAME_SIZE
  151. mtcr r3
  152. mtspr SPRN_SRR1,r4
  153. mtspr SPRN_SRR0,r5
  154. rfid
  155. _GLOBAL(power7_wakeup_noloss)
  156. lbz r0,PACA_NAPSTATELOST(r13)
  157. cmpwi r0,0
  158. bne power7_wakeup_loss
  159. ld r1,PACAR1(r13)
  160. ld r4,_MSR(r1)
  161. ld r5,_NIP(r1)
  162. addi r1,r1,INT_FRAME_SIZE
  163. mtspr SPRN_SRR1,r4
  164. mtspr SPRN_SRR0,r5
  165. rfid