idle_power7.S 2.5 KB

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