idle_power7.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. _GLOBAL(power7_powersave_common)
  38. /* Use r3 to pass state nap/sleep/winkle */
  39. /* NAP is a state loss, we create a regs frame on the
  40. * stack, fill it up with the state we care about and
  41. * stick a pointer to it in PACAR1. We really only
  42. * need to save PC, some CR bits and the NV GPRs,
  43. * but for now an interrupt frame will do.
  44. */
  45. mflr r0
  46. std r0,16(r1)
  47. stdu r1,-INT_FRAME_SIZE(r1)
  48. std r0,_LINK(r1)
  49. std r0,_NIP(r1)
  50. #ifndef CONFIG_SMP
  51. /* Make sure FPU, VSX etc... are flushed as we may lose
  52. * state when going to nap mode
  53. */
  54. bl .discard_lazy_cpu_state
  55. #endif /* CONFIG_SMP */
  56. /* Hard disable interrupts */
  57. mfmsr r9
  58. rldicl r9,r9,48,1
  59. rotldi r9,r9,16
  60. mtmsrd r9,1 /* hard-disable interrupts */
  61. /* Check if something happened while soft-disabled */
  62. lbz r0,PACAIRQHAPPENED(r13)
  63. cmpwi cr0,r0,0
  64. beq 1f
  65. addi r1,r1,INT_FRAME_SIZE
  66. ld r0,16(r1)
  67. mtlr r0
  68. blr
  69. 1: /* We mark irqs hard disabled as this is the state we'll
  70. * be in when returning and we need to tell arch_local_irq_restore()
  71. * about it
  72. */
  73. li r0,PACA_IRQ_HARD_DIS
  74. stb r0,PACAIRQHAPPENED(r13)
  75. /* We haven't lost state ... yet */
  76. li r0,0
  77. stb r0,PACA_NAPSTATELOST(r13)
  78. /* Continue saving state */
  79. SAVE_GPR(2, r1)
  80. SAVE_NVGPRS(r1)
  81. mfcr r4
  82. std r4,_CCR(r1)
  83. std r9,_MSR(r1)
  84. std r1,PACAR1(r13)
  85. _GLOBAL(power7_enter_nap_mode)
  86. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  87. /* Tell KVM we're napping */
  88. li r4,KVM_HWTHREAD_IN_NAP
  89. stb r4,HSTATE_HWTHREAD_STATE(r13)
  90. #endif
  91. cmpwi cr0,r3,1
  92. beq 2f
  93. IDLE_STATE_ENTER_SEQ(PPC_NAP)
  94. /* No return */
  95. 2: IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
  96. /* No return */
  97. _GLOBAL(power7_idle)
  98. /* Now check if user or arch enabled NAP mode */
  99. LOAD_REG_ADDRBASE(r3,powersave_nap)
  100. lwz r4,ADDROFF(powersave_nap)(r3)
  101. cmpwi 0,r4,0
  102. beqlr
  103. /* fall through */
  104. _GLOBAL(power7_nap)
  105. li r3,0
  106. b power7_powersave_common
  107. /* No return */
  108. _GLOBAL(power7_sleep)
  109. li r3,1
  110. b power7_powersave_common
  111. /* No return */
  112. _GLOBAL(power7_wakeup_tb_loss)
  113. ld r2,PACATOC(r13);
  114. ld r1,PACAR1(r13)
  115. /* Time base re-sync */
  116. li r0,OPAL_RESYNC_TIMEBASE
  117. LOAD_REG_ADDR(r11,opal);
  118. ld r12,8(r11);
  119. ld r2,0(r11);
  120. mtctr r12
  121. bctrl
  122. /* TODO: Check r3 for failure */
  123. REST_NVGPRS(r1)
  124. REST_GPR(2, r1)
  125. ld r3,_CCR(r1)
  126. ld r4,_MSR(r1)
  127. ld r5,_NIP(r1)
  128. addi r1,r1,INT_FRAME_SIZE
  129. mtcr r3
  130. mfspr r3,SPRN_SRR1 /* Return SRR1 */
  131. mtspr SPRN_SRR1,r4
  132. mtspr SPRN_SRR0,r5
  133. rfid
  134. _GLOBAL(power7_wakeup_loss)
  135. ld r1,PACAR1(r13)
  136. REST_NVGPRS(r1)
  137. REST_GPR(2, r1)
  138. ld r3,_CCR(r1)
  139. ld r4,_MSR(r1)
  140. ld r5,_NIP(r1)
  141. addi r1,r1,INT_FRAME_SIZE
  142. mtcr r3
  143. mtspr SPRN_SRR1,r4
  144. mtspr SPRN_SRR0,r5
  145. rfid
  146. _GLOBAL(power7_wakeup_noloss)
  147. lbz r0,PACA_NAPSTATELOST(r13)
  148. cmpwi r0,0
  149. bne .power7_wakeup_loss
  150. ld r1,PACAR1(r13)
  151. ld r4,_MSR(r1)
  152. ld r5,_NIP(r1)
  153. addi r1,r1,INT_FRAME_SIZE
  154. mtspr SPRN_SRR1,r4
  155. mtspr SPRN_SRR0,r5
  156. rfid