idle_power7.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #undef DEBUG
  20. .text
  21. _GLOBAL(power7_idle)
  22. /* Now check if user or arch enabled NAP mode */
  23. LOAD_REG_ADDRBASE(r3,powersave_nap)
  24. lwz r4,ADDROFF(powersave_nap)(r3)
  25. cmpwi 0,r4,0
  26. beqlr
  27. /* fall through */
  28. _GLOBAL(power7_nap)
  29. /* NAP is a state loss, we create a regs frame on the
  30. * stack, fill it up with the state we care about and
  31. * stick a pointer to it in PACAR1. We really only
  32. * need to save PC, some CR bits and the NV GPRs,
  33. * but for now an interrupt frame will do.
  34. */
  35. mflr r0
  36. std r0,16(r1)
  37. stdu r1,-INT_FRAME_SIZE(r1)
  38. std r0,_LINK(r1)
  39. std r0,_NIP(r1)
  40. #ifndef CONFIG_SMP
  41. /* Make sure FPU, VSX etc... are flushed as we may lose
  42. * state when going to nap mode
  43. */
  44. bl .discard_lazy_cpu_state
  45. #endif /* CONFIG_SMP */
  46. /* Hard disable interrupts */
  47. mfmsr r9
  48. rldicl r9,r9,48,1
  49. rotldi r9,r9,16
  50. mtmsrd r9,1 /* hard-disable interrupts */
  51. /* Check if something happened while soft-disabled */
  52. lbz r0,PACAIRQHAPPENED(r13)
  53. cmpwi cr0,r0,0
  54. beq 1f
  55. addi r1,r1,INT_FRAME_SIZE
  56. ld r0,16(r1)
  57. mtlr r0
  58. blr
  59. 1: /* We mark irqs hard disabled as this is the state we'll
  60. * be in when returning and we need to tell arch_local_irq_restore()
  61. * about it
  62. */
  63. li r0,PACA_IRQ_HARD_DIS
  64. stb r0,PACAIRQHAPPENED(r13)
  65. /* We haven't lost state ... yet */
  66. li r0,0
  67. stb r0,PACA_NAPSTATELOST(r13)
  68. /* Continue saving state */
  69. SAVE_GPR(2, r1)
  70. SAVE_NVGPRS(r1)
  71. mfcr r3
  72. std r3,_CCR(r1)
  73. std r9,_MSR(r1)
  74. std r1,PACAR1(r13)
  75. #ifdef CONFIG_KVM_BOOK3S_64_HV
  76. /* Tell KVM we're napping */
  77. li r4,KVM_HWTHREAD_IN_NAP
  78. stb r4,HSTATE_HWTHREAD_STATE(r13)
  79. #endif
  80. /* Magic NAP mode enter sequence */
  81. std r0,0(r1)
  82. ptesync
  83. ld r0,0(r1)
  84. 1: cmp cr0,r0,r0
  85. bne 1b
  86. PPC_NAP
  87. b .
  88. _GLOBAL(power7_wakeup_loss)
  89. ld r1,PACAR1(r13)
  90. REST_NVGPRS(r1)
  91. REST_GPR(2, r1)
  92. ld r3,_CCR(r1)
  93. ld r4,_MSR(r1)
  94. ld r5,_NIP(r1)
  95. addi r1,r1,INT_FRAME_SIZE
  96. mtcr r3
  97. mtspr SPRN_SRR1,r4
  98. mtspr SPRN_SRR0,r5
  99. rfid
  100. _GLOBAL(power7_wakeup_noloss)
  101. lbz r0,PACA_NAPSTATELOST(r13)
  102. cmpwi r0,0
  103. bne .power7_wakeup_loss
  104. ld r1,PACAR1(r13)
  105. ld r4,_MSR(r1)
  106. ld r5,_NIP(r1)
  107. addi r1,r1,INT_FRAME_SIZE
  108. mtspr SPRN_SRR1,r4
  109. mtspr SPRN_SRR0,r5
  110. rfid