idle_power7.S 2.6 KB

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