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 _GLOBAL(power7_powersave_common)
44 /* Use r3 to pass state nap/sleep/winkle */
45 /* NAP is a state loss, we create a regs frame on the
46 * stack, fill it up with the state we care about and
47 * stick a pointer to it in PACAR1. We really only
48 * need to save PC, some CR bits and the NV GPRs,
49 * but for now an interrupt frame will do.
53 stdu r1,-INT_FRAME_SIZE(r1)
58 /* Make sure FPU, VSX etc... are flushed as we may lose
59 * state when going to nap mode
61 bl .discard_lazy_cpu_state
62 #endif /* CONFIG_SMP */
64 /* Hard disable interrupts */
68 mtmsrd r9,1 /* hard-disable interrupts */
70 /* Check if something happened while soft-disabled */
71 lbz r0,PACAIRQHAPPENED(r13)
74 addi r1,r1,INT_FRAME_SIZE
79 1: /* We mark irqs hard disabled as this is the state we'll
80 * be in when returning and we need to tell arch_local_irq_restore()
83 li r0,PACA_IRQ_HARD_DIS
84 stb r0,PACAIRQHAPPENED(r13)
86 /* We haven't lost state ... yet */
88 stb r0,PACA_NAPSTATELOST(r13)
90 /* Continue saving state */
98 _GLOBAL(power7_enter_nap_mode)
99 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
100 /* Tell KVM we're napping */
101 li r4,KVM_HWTHREAD_IN_NAP
102 stb r4,HSTATE_HWTHREAD_STATE(r13)
106 IDLE_STATE_ENTER_SEQ(PPC_NAP)
108 2: IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
112 /* Now check if user or arch enabled NAP mode */
113 LOAD_REG_ADDRBASE(r3,powersave_nap)
114 lwz r4,ADDROFF(powersave_nap)(r3)
121 b power7_powersave_common
124 _GLOBAL(power7_sleep)
126 b power7_powersave_common
129 _GLOBAL(power7_wakeup_tb_loss)
133 /* Time base re-sync */
134 li r0,OPAL_RESYNC_TIMEBASE
135 LOAD_REG_ADDR(r11,opal);
141 /* TODO: Check r3 for failure */
148 addi r1,r1,INT_FRAME_SIZE
150 mfspr r3,SPRN_SRR1 /* Return SRR1 */
155 _GLOBAL(power7_wakeup_loss)
162 addi r1,r1,INT_FRAME_SIZE
168 _GLOBAL(power7_wakeup_noloss)
169 lbz r0,PACA_NAPSTATELOST(r13)
171 bne .power7_wakeup_loss
175 addi r1,r1,INT_FRAME_SIZE