1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright 2018, IBM Corporation.
5 * This file contains general idle entry/exit functions to save
6 * and restore stack and NVGPRs which allows C code to call idle
7 * states that lose GPRs, and it will return transparently with
8 * SRR1 wakeup reason return value.
10 * The platform / CPU caller must ensure SPRs and any other non-GPR
11 * state is saved and restored correctly, handle KVM, interrupts, etc.
14 #include <asm/ppc_asm.h>
15 #include <asm/asm-offsets.h>
16 #include <asm/ppc-opcode.h>
17 #include <asm/cpuidle.h>
22 * No state will be lost regardless of wakeup mechanism (interrupt or NIA).
24 * An EC=0 type wakeup will return with a value of 0. SRESET wakeup (which can
25 * happen with xscom SRESET and possibly MCE) may clobber volatiles except LR,
26 * and must blr, to return to caller with r3 set according to caller's expected
27 * return code (for Book3S/64 that is SRR1).
29 _GLOBAL(isa300_idle_stop_noloss)
38 * GPRs may be lost, so they are saved here. Wakeup is by interrupt only.
39 * The SRESET wakeup returns to this function's caller by calling
40 * idle_return_gpr_loss with r3 set to desired return value.
42 * A wakeup without GPR loss may alteratively be handled as in
43 * isa300_idle_stop_noloss and blr directly, as an optimisation.
45 * The caller is responsible for saving/restoring SPRs, MSR, timebase,
48 _GLOBAL(isa300_idle_stop_mayloss)
54 * Use the stack red zone rather than a new frame for saving regs since
55 * in the case of no GPR loss the wakeup code branches directly back to
56 * the caller without deallocating the stack frame first.
84 * Desired return value in r3
86 * The idle wakeup SRESET interrupt can call this after calling
87 * to return to the idle sleep function caller with r3 as the return code.
89 * This must not be used if idle was entered via a _noloss function (use
90 * a simple blr instead).
92 _GLOBAL(idle_return_gpr_loss)
99 * KVM nap requires r2 to be saved, rather than just restoring it
100 * from PACATOC. This could be avoided for that less common case
101 * if KVM saved its r2.
125 * This is the sequence required to execute idle instructions, as
126 * specified in ISA v2.07 (and earlier). MSR[IR] and MSR[DR] must be 0.
127 * We have to store a GPR somewhere, ptesync, then reload it, and create
128 * a false dependency on the result of the load. It doesn't matter which
129 * GPR we store, or where we store it. We have already stored r2 to the
130 * stack at -8(r1) in isa206_idle_insn_mayloss, so use that.
132 #define IDLE_STATE_ENTER_SEQ_NORET(IDLE_INST) \
133 /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
137 236: cmpd cr0,r2,r2; \
143 * Desired instruction type in r3
145 * GPRs may be lost, so they are saved here. Wakeup is by interrupt only.
146 * The SRESET wakeup returns to this function's caller by calling
147 * idle_return_gpr_loss with r3 set to desired return value.
149 * A wakeup without GPR loss may alteratively be handled as in
150 * isa300_idle_stop_noloss and blr directly, as an optimisation.
152 * The caller is responsible for saving/restoring SPRs, MSR, timebase,
155 * This must be called in real-mode (MSR_IDLE).
157 _GLOBAL(isa206_idle_insn_mayloss)
162 * Use the stack red zone rather than a new frame for saving regs since
163 * in the case of no GPR loss the wakeup code branches directly back to
164 * the caller without deallocating the stack frame first.
187 cmpwi r3,PNV_THREAD_NAP
189 IDLE_STATE_ENTER_SEQ_NORET(PPC_NAP)
190 1: cmpwi r3,PNV_THREAD_SLEEP
192 IDLE_STATE_ENTER_SEQ_NORET(PPC_SLEEP)
193 2: IDLE_STATE_ENTER_SEQ_NORET(PPC_WINKLE)