2 * This file contains the power_save function for Power7 CPUs.
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.
10 #include <linux/threads.h>
11 #include <asm/processor.h>
13 #include <asm/cputable.h>
14 #include <asm/thread_info.h>
15 #include <asm/ppc_asm.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/ppc-opcode.h>
18 #include <asm/hw_irq.h>
19 #include <asm/kvm_book3s_asm.h>
24 /* Idle state entry routines */
26 #define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
27 /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
39 * Pass requested state in r3:
43 * To check IRQ_HAPPENED in r4
47 _GLOBAL(power7_powersave_common)
48 /* Use r3 to pass state nap/sleep/winkle */
49 /* NAP is a state loss, we create a regs frame on the
50 * stack, fill it up with the state we care about and
51 * stick a pointer to it in PACAR1. We really only
52 * need to save PC, some CR bits and the NV GPRs,
53 * but for now an interrupt frame will do.
57 stdu r1,-INT_FRAME_SIZE(r1)
62 /* Make sure FPU, VSX etc... are flushed as we may lose
63 * state when going to nap mode
65 bl discard_lazy_cpu_state
66 #endif /* CONFIG_SMP */
68 /* Hard disable interrupts */
72 mtmsrd r9,1 /* hard-disable interrupts */
74 /* Check if something happened while soft-disabled */
75 lbz r0,PACAIRQHAPPENED(r13)
80 addi r1,r1,INT_FRAME_SIZE
85 1: /* We mark irqs hard disabled as this is the state we'll
86 * be in when returning and we need to tell arch_local_irq_restore()
89 li r0,PACA_IRQ_HARD_DIS
90 stb r0,PACAIRQHAPPENED(r13)
92 /* We haven't lost state ... yet */
94 stb r0,PACA_NAPSTATELOST(r13)
96 /* Continue saving state */
104 _GLOBAL(power7_enter_nap_mode)
105 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
106 /* Tell KVM we're napping */
107 li r4,KVM_HWTHREAD_IN_NAP
108 stb r4,HSTATE_HWTHREAD_STATE(r13)
112 IDLE_STATE_ENTER_SEQ(PPC_NAP)
114 2: IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
118 /* Now check if user or arch enabled NAP mode */
119 LOAD_REG_ADDRBASE(r3,powersave_nap)
120 lwz r4,ADDROFF(powersave_nap)(r3)
129 b power7_powersave_common
132 _GLOBAL(power7_sleep)
135 b power7_powersave_common
139 * Make opal call in realmode. This is a generic function to be called
140 * from realmode from reset vector. It handles endianess.
150 /* Set opal return address */
151 LOAD_REG_ADDR(r0,return_from_opal_call)
153 /* Handle endian-ness */
158 mr r0,r3 /* Move opal token to r0 */
159 LOAD_REG_ADDR(r11,opal)
165 return_from_opal_call:
171 #define CHECK_HMI_INTERRUPT \
172 mfspr r0,SPRN_SRR1; \
173 BEGIN_FTR_SECTION_NESTED(66); \
174 rlwinm r0,r0,45-31,0xf; /* extract wake reason field (P8) */ \
175 FTR_SECTION_ELSE_NESTED(66); \
176 rlwinm r0,r0,45-31,0xe; /* P7 wake reason field is 3 bits */ \
177 ALT_FTR_SECTION_END_NESTED_IFSET(CPU_FTR_ARCH_207S, 66); \
178 cmpwi r0,0xa; /* Hypervisor maintenance ? */ \
180 /* Invoke opal call to handle hmi */ \
181 ld r2,PACATOC(r13); \
183 std r3,ORIG_GPR3(r1); /* Save original r3 */ \
184 li r3,OPAL_HANDLE_HMI; /* Pass opal token argument*/ \
185 bl opal_call_realmode; \
186 ld r3,ORIG_GPR3(r1); /* Restore original r3 */ \
190 _GLOBAL(power7_wakeup_tb_loss)
196 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
197 /* Time base re-sync */
198 li r3,OPAL_RESYNC_TIMEBASE
199 bl opal_call_realmode;
201 /* TODO: Check r3 for failure */
208 addi r1,r1,INT_FRAME_SIZE
210 mfspr r3,SPRN_SRR1 /* Return SRR1 */
215 _GLOBAL(power7_wakeup_loss)
219 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
225 addi r1,r1,INT_FRAME_SIZE
231 _GLOBAL(power7_wakeup_noloss)
232 lbz r0,PACA_NAPSTATELOST(r13)
234 bne power7_wakeup_loss
237 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
241 addi r1,r1,INT_FRAME_SIZE