powerpc/64: Re-fix race condition between going idle and entering guest
[cascardo/linux.git] / arch / powerpc / kernel / idle_book3s.S
1 /*
2  *  This file contains idle entry/exit functions for POWER7,
3  *  POWER8 and POWER9 CPUs.
4  *
5  *  This program is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU General Public License
7  *  as published by the Free Software Foundation; either version
8  *  2 of the License, or (at your option) any later version.
9  */
10
11 #include <linux/threads.h>
12 #include <asm/processor.h>
13 #include <asm/page.h>
14 #include <asm/cputable.h>
15 #include <asm/thread_info.h>
16 #include <asm/ppc_asm.h>
17 #include <asm/asm-offsets.h>
18 #include <asm/ppc-opcode.h>
19 #include <asm/hw_irq.h>
20 #include <asm/kvm_book3s_asm.h>
21 #include <asm/opal.h>
22 #include <asm/cpuidle.h>
23 #include <asm/book3s/64/mmu-hash.h>
24 #include <asm/mmu.h>
25
26 #undef DEBUG
27
28 /*
29  * Use unused space in the interrupt stack to save and restore
30  * registers for winkle support.
31  */
32 #define _SDR1   GPR3
33 #define _RPR    GPR4
34 #define _SPURR  GPR5
35 #define _PURR   GPR6
36 #define _TSCR   GPR7
37 #define _DSCR   GPR8
38 #define _AMOR   GPR9
39 #define _WORT   GPR10
40 #define _WORC   GPR11
41 #define _PTCR   GPR12
42
43 #define PSSCR_HV_TEMPLATE       PSSCR_ESL | PSSCR_EC | \
44                                 PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
45                                 PSSCR_MTL_MASK
46
47         .text
48
49 /*
50  * Used by threads before entering deep idle states. Saves SPRs
51  * in interrupt stack frame
52  */
53 save_sprs_to_stack:
54         /*
55          * Note all register i.e per-core, per-subcore or per-thread is saved
56          * here since any thread in the core might wake up first
57          */
58 BEGIN_FTR_SECTION
59         mfspr   r3,SPRN_PTCR
60         std     r3,_PTCR(r1)
61         /*
62          * Note - SDR1 is dropped in Power ISA v3. Hence not restoring
63          * SDR1 here
64          */
65 FTR_SECTION_ELSE
66         mfspr   r3,SPRN_SDR1
67         std     r3,_SDR1(r1)
68 ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_300)
69         mfspr   r3,SPRN_RPR
70         std     r3,_RPR(r1)
71         mfspr   r3,SPRN_SPURR
72         std     r3,_SPURR(r1)
73         mfspr   r3,SPRN_PURR
74         std     r3,_PURR(r1)
75         mfspr   r3,SPRN_TSCR
76         std     r3,_TSCR(r1)
77         mfspr   r3,SPRN_DSCR
78         std     r3,_DSCR(r1)
79         mfspr   r3,SPRN_AMOR
80         std     r3,_AMOR(r1)
81         mfspr   r3,SPRN_WORT
82         std     r3,_WORT(r1)
83         mfspr   r3,SPRN_WORC
84         std     r3,_WORC(r1)
85
86         blr
87
88 /*
89  * Used by threads when the lock bit of core_idle_state is set.
90  * Threads will spin in HMT_LOW until the lock bit is cleared.
91  * r14 - pointer to core_idle_state
92  * r15 - used to load contents of core_idle_state
93  */
94
95 core_idle_lock_held:
96         HMT_LOW
97 3:      lwz     r15,0(r14)
98         andi.   r15,r15,PNV_CORE_IDLE_LOCK_BIT
99         bne     3b
100         HMT_MEDIUM
101         lwarx   r15,0,r14
102         blr
103
104 /*
105  * Pass requested state in r3:
106  *      r3 - PNV_THREAD_NAP/SLEEP/WINKLE in POWER8
107  *         - Requested STOP state in POWER9
108  *
109  * To check IRQ_HAPPENED in r4
110  *      0 - don't check
111  *      1 - check
112  *
113  * Address to 'rfid' to in r5
114  */
115 _GLOBAL(pnv_powersave_common)
116         /* Use r3 to pass state nap/sleep/winkle */
117         /* NAP is a state loss, we create a regs frame on the
118          * stack, fill it up with the state we care about and
119          * stick a pointer to it in PACAR1. We really only
120          * need to save PC, some CR bits and the NV GPRs,
121          * but for now an interrupt frame will do.
122          */
123         mflr    r0
124         std     r0,16(r1)
125         stdu    r1,-INT_FRAME_SIZE(r1)
126         std     r0,_LINK(r1)
127         std     r0,_NIP(r1)
128
129         /* Hard disable interrupts */
130         mfmsr   r9
131         rldicl  r9,r9,48,1
132         rotldi  r9,r9,16
133         mtmsrd  r9,1                    /* hard-disable interrupts */
134
135         /* Check if something happened while soft-disabled */
136         lbz     r0,PACAIRQHAPPENED(r13)
137         andi.   r0,r0,~PACA_IRQ_HARD_DIS@l
138         beq     1f
139         cmpwi   cr0,r4,0
140         beq     1f
141         addi    r1,r1,INT_FRAME_SIZE
142         ld      r0,16(r1)
143         li      r3,0                    /* Return 0 (no nap) */
144         mtlr    r0
145         blr
146
147 1:      /* We mark irqs hard disabled as this is the state we'll
148          * be in when returning and we need to tell arch_local_irq_restore()
149          * about it
150          */
151         li      r0,PACA_IRQ_HARD_DIS
152         stb     r0,PACAIRQHAPPENED(r13)
153
154         /* We haven't lost state ... yet */
155         li      r0,0
156         stb     r0,PACA_NAPSTATELOST(r13)
157
158         /* Continue saving state */
159         SAVE_GPR(2, r1)
160         SAVE_NVGPRS(r1)
161         mfcr    r4
162         std     r4,_CCR(r1)
163         std     r9,_MSR(r1)
164         std     r1,PACAR1(r13)
165
166         /*
167          * Go to real mode to do the nap, as required by the architecture.
168          * Also, we need to be in real mode before setting hwthread_state,
169          * because as soon as we do that, another thread can switch
170          * the MMU context to the guest.
171          */
172         LOAD_REG_IMMEDIATE(r7, MSR_IDLE)
173         li      r6, MSR_RI
174         andc    r6, r9, r6
175         mtmsrd  r6, 1           /* clear RI before setting SRR0/1 */
176         mtspr   SPRN_SRR0, r5
177         mtspr   SPRN_SRR1, r7
178         rfid
179
180         .globl pnv_enter_arch207_idle_mode
181 pnv_enter_arch207_idle_mode:
182 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
183         /* Tell KVM we're entering idle */
184         li      r4,KVM_HWTHREAD_IN_IDLE
185         /******************************************************/
186         /*  N O T E   W E L L    ! ! !    N O T E   W E L L   */
187         /* The following store to HSTATE_HWTHREAD_STATE(r13)  */
188         /* MUST occur in real mode, i.e. with the MMU off,    */
189         /* and the MMU must stay off until we clear this flag */
190         /* and test HSTATE_HWTHREAD_REQ(r13) in the system    */
191         /* reset interrupt vector in exceptions-64s.S.        */
192         /* The reason is that another thread can switch the   */
193         /* MMU to a guest context whenever this flag is set   */
194         /* to KVM_HWTHREAD_IN_IDLE, and if the MMU was on,    */
195         /* that would potentially cause this thread to start  */
196         /* executing instructions from guest memory in        */
197         /* hypervisor mode, leading to a host crash or data   */
198         /* corruption, or worse.                              */
199         /******************************************************/
200         stb     r4,HSTATE_HWTHREAD_STATE(r13)
201 #endif
202         stb     r3,PACA_THREAD_IDLE_STATE(r13)
203         cmpwi   cr3,r3,PNV_THREAD_SLEEP
204         bge     cr3,2f
205         IDLE_STATE_ENTER_SEQ(PPC_NAP)
206         /* No return */
207 2:
208         /* Sleep or winkle */
209         lbz     r7,PACA_THREAD_MASK(r13)
210         ld      r14,PACA_CORE_IDLE_STATE_PTR(r13)
211 lwarx_loop1:
212         lwarx   r15,0,r14
213
214         andi.   r9,r15,PNV_CORE_IDLE_LOCK_BIT
215         bnel    core_idle_lock_held
216
217         andc    r15,r15,r7                      /* Clear thread bit */
218
219         andi.   r15,r15,PNV_CORE_IDLE_THREAD_BITS
220
221 /*
222  * If cr0 = 0, then current thread is the last thread of the core entering
223  * sleep. Last thread needs to execute the hardware bug workaround code if
224  * required by the platform.
225  * Make the workaround call unconditionally here. The below branch call is
226  * patched out when the idle states are discovered if the platform does not
227  * require it.
228  */
229 .global pnv_fastsleep_workaround_at_entry
230 pnv_fastsleep_workaround_at_entry:
231         beq     fastsleep_workaround_at_entry
232
233         stwcx.  r15,0,r14
234         bne-    lwarx_loop1
235         isync
236
237 common_enter: /* common code for all the threads entering sleep or winkle */
238         bgt     cr3,enter_winkle
239         IDLE_STATE_ENTER_SEQ(PPC_SLEEP)
240
241 fastsleep_workaround_at_entry:
242         ori     r15,r15,PNV_CORE_IDLE_LOCK_BIT
243         stwcx.  r15,0,r14
244         bne-    lwarx_loop1
245         isync
246
247         /* Fast sleep workaround */
248         li      r3,1
249         li      r4,1
250         bl      opal_rm_config_cpu_idle_state
251
252         /* Clear Lock bit */
253         li      r0,0
254         lwsync
255         stw     r0,0(r14)
256         b       common_enter
257
258 enter_winkle:
259         bl      save_sprs_to_stack
260
261         IDLE_STATE_ENTER_SEQ(PPC_WINKLE)
262
263 /*
264  * r3 - requested stop state
265  */
266 power_enter_stop:
267 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
268         /* Tell KVM we're entering idle */
269         li      r4,KVM_HWTHREAD_IN_IDLE
270         /* DO THIS IN REAL MODE!  See comment above. */
271         stb     r4,HSTATE_HWTHREAD_STATE(r13)
272 #endif
273 /*
274  * Check if the requested state is a deep idle state.
275  */
276         LOAD_REG_ADDRBASE(r5,pnv_first_deep_stop_state)
277         ld      r4,ADDROFF(pnv_first_deep_stop_state)(r5)
278         cmpd    r3,r4
279         bge     2f
280         IDLE_STATE_ENTER_SEQ(PPC_STOP)
281 2:
282 /*
283  * Entering deep idle state.
284  * Clear thread bit in PACA_CORE_IDLE_STATE, save SPRs to
285  * stack and enter stop
286  */
287         lbz     r7,PACA_THREAD_MASK(r13)
288         ld      r14,PACA_CORE_IDLE_STATE_PTR(r13)
289
290 lwarx_loop_stop:
291         lwarx   r15,0,r14
292         andi.   r9,r15,PNV_CORE_IDLE_LOCK_BIT
293         bnel    core_idle_lock_held
294         andc    r15,r15,r7                      /* Clear thread bit */
295
296         stwcx.  r15,0,r14
297         bne-    lwarx_loop_stop
298         isync
299
300         bl      save_sprs_to_stack
301
302         IDLE_STATE_ENTER_SEQ(PPC_STOP)
303
304 _GLOBAL(power7_idle)
305         /* Now check if user or arch enabled NAP mode */
306         LOAD_REG_ADDRBASE(r3,powersave_nap)
307         lwz     r4,ADDROFF(powersave_nap)(r3)
308         cmpwi   0,r4,0
309         beqlr
310         li      r3, 1
311         /* fall through */
312
313 _GLOBAL(power7_nap)
314         mr      r4,r3
315         li      r3,PNV_THREAD_NAP
316         LOAD_REG_ADDR(r5, pnv_enter_arch207_idle_mode)
317         b       pnv_powersave_common
318         /* No return */
319
320 _GLOBAL(power7_sleep)
321         li      r3,PNV_THREAD_SLEEP
322         li      r4,1
323         LOAD_REG_ADDR(r5, pnv_enter_arch207_idle_mode)
324         b       pnv_powersave_common
325         /* No return */
326
327 _GLOBAL(power7_winkle)
328         li      r3,PNV_THREAD_WINKLE
329         li      r4,1
330         LOAD_REG_ADDR(r5, pnv_enter_arch207_idle_mode)
331         b       pnv_powersave_common
332         /* No return */
333
334 #define CHECK_HMI_INTERRUPT                                             \
335         mfspr   r0,SPRN_SRR1;                                           \
336 BEGIN_FTR_SECTION_NESTED(66);                                           \
337         rlwinm  r0,r0,45-31,0xf;  /* extract wake reason field (P8) */  \
338 FTR_SECTION_ELSE_NESTED(66);                                            \
339         rlwinm  r0,r0,45-31,0xe;  /* P7 wake reason field is 3 bits */  \
340 ALT_FTR_SECTION_END_NESTED_IFSET(CPU_FTR_ARCH_207S, 66);                \
341         cmpwi   r0,0xa;                 /* Hypervisor maintenance ? */  \
342         bne     20f;                                                    \
343         /* Invoke opal call to handle hmi */                            \
344         ld      r2,PACATOC(r13);                                        \
345         ld      r1,PACAR1(r13);                                         \
346         std     r3,ORIG_GPR3(r1);       /* Save original r3 */          \
347         li      r3,0;                   /* NULL argument */             \
348         bl      hmi_exception_realmode;                                 \
349         nop;                                                            \
350         ld      r3,ORIG_GPR3(r1);       /* Restore original r3 */       \
351 20:     nop;
352
353
354 /*
355  * r3 - requested stop state
356  */
357 _GLOBAL(power9_idle_stop)
358         LOAD_REG_IMMEDIATE(r4, PSSCR_HV_TEMPLATE)
359         or      r4,r4,r3
360         mtspr   SPRN_PSSCR, r4
361         li      r4, 1
362         LOAD_REG_ADDR(r5,power_enter_stop)
363         b       pnv_powersave_common
364         /* No return */
365 /*
366  * Called from reset vector. Check whether we have woken up with
367  * hypervisor state loss. If yes, restore hypervisor state and return
368  * back to reset vector.
369  *
370  * r13 - Contents of HSPRG0
371  * cr3 - set to gt if waking up with partial/complete hypervisor state loss
372  */
373 _GLOBAL(pnv_restore_hyp_resource)
374 BEGIN_FTR_SECTION
375         ld      r2,PACATOC(r13);
376         /*
377          * POWER ISA 3. Use PSSCR to determine if we
378          * are waking up from deep idle state
379          */
380         LOAD_REG_ADDRBASE(r5,pnv_first_deep_stop_state)
381         ld      r4,ADDROFF(pnv_first_deep_stop_state)(r5)
382
383         mfspr   r5,SPRN_PSSCR
384         /*
385          * 0-3 bits correspond to Power-Saving Level Status
386          * which indicates the idle state we are waking up from
387          */
388         rldicl  r5,r5,4,60
389         cmpd    cr4,r5,r4
390         bge     cr4,pnv_wakeup_tb_loss
391         /*
392          * Waking up without hypervisor state loss. Return to
393          * reset vector
394          */
395         blr
396
397 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
398
399         /*
400          * POWER ISA 2.07 or less.
401          * Check if last bit of HSPGR0 is set. This indicates whether we are
402          * waking up from winkle.
403          */
404         clrldi  r5,r13,63
405         clrrdi  r13,r13,1
406
407         /* Now that we are sure r13 is corrected, load TOC */
408         ld      r2,PACATOC(r13);
409         cmpwi   cr4,r5,1
410         mtspr   SPRN_HSPRG0,r13
411
412         lbz     r0,PACA_THREAD_IDLE_STATE(r13)
413         cmpwi   cr2,r0,PNV_THREAD_NAP
414         bgt     cr2,pnv_wakeup_tb_loss  /* Either sleep or Winkle */
415
416         /*
417          * We fall through here if PACA_THREAD_IDLE_STATE shows we are waking
418          * up from nap. At this stage CR3 shouldn't contains 'gt' since that
419          * indicates we are waking with hypervisor state loss from nap.
420          */
421         bgt     cr3,.
422
423         blr     /* Return back to System Reset vector from where
424                    pnv_restore_hyp_resource was invoked */
425
426 /*
427  * Called if waking up from idle state which can cause either partial or
428  * complete hyp state loss.
429  * In POWER8, called if waking up from fastsleep or winkle
430  * In POWER9, called if waking up from stop state >= pnv_first_deep_stop_state
431  *
432  * r13 - PACA
433  * cr3 - gt if waking up with partial/complete hypervisor state loss
434  * cr4 - gt or eq if waking up from complete hypervisor state loss.
435  */
436 _GLOBAL(pnv_wakeup_tb_loss)
437         ld      r1,PACAR1(r13)
438         /*
439          * Before entering any idle state, the NVGPRs are saved in the stack
440          * and they are restored before switching to the process context. Hence
441          * until they are restored, they are free to be used.
442          *
443          * Save SRR1 and LR in NVGPRs as they might be clobbered in
444          * opal_call() (called in CHECK_HMI_INTERRUPT). SRR1 is required
445          * to determine the wakeup reason if we branch to kvm_start_guest. LR
446          * is required to return back to reset vector after hypervisor state
447          * restore is complete.
448          */
449         mflr    r17
450         mfspr   r16,SPRN_SRR1
451 BEGIN_FTR_SECTION
452         CHECK_HMI_INTERRUPT
453 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
454
455         lbz     r7,PACA_THREAD_MASK(r13)
456         ld      r14,PACA_CORE_IDLE_STATE_PTR(r13)
457 lwarx_loop2:
458         lwarx   r15,0,r14
459         andi.   r9,r15,PNV_CORE_IDLE_LOCK_BIT
460         /*
461          * Lock bit is set in one of the 2 cases-
462          * a. In the sleep/winkle enter path, the last thread is executing
463          * fastsleep workaround code.
464          * b. In the wake up path, another thread is executing fastsleep
465          * workaround undo code or resyncing timebase or restoring context
466          * In either case loop until the lock bit is cleared.
467          */
468         bnel    core_idle_lock_held
469
470         cmpwi   cr2,r15,0
471
472         /*
473          * At this stage
474          * cr2 - eq if first thread to wakeup in core
475          * cr3-  gt if waking up with partial/complete hypervisor state loss
476          * cr4 - gt or eq if waking up from complete hypervisor state loss.
477          */
478
479         ori     r15,r15,PNV_CORE_IDLE_LOCK_BIT
480         stwcx.  r15,0,r14
481         bne-    lwarx_loop2
482         isync
483
484 BEGIN_FTR_SECTION
485         lbz     r4,PACA_SUBCORE_SIBLING_MASK(r13)
486         and     r4,r4,r15
487         cmpwi   r4,0    /* Check if first in subcore */
488
489         or      r15,r15,r7              /* Set thread bit */
490         beq     first_thread_in_subcore
491 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
492
493         or      r15,r15,r7              /* Set thread bit */
494         beq     cr2,first_thread_in_core
495
496         /* Not first thread in core or subcore to wake up */
497         b       clear_lock
498
499 first_thread_in_subcore:
500         /*
501          * If waking up from sleep, subcore state is not lost. Hence
502          * skip subcore state restore
503          */
504         blt     cr4,subcore_state_restored
505
506         /* Restore per-subcore state */
507         ld      r4,_SDR1(r1)
508         mtspr   SPRN_SDR1,r4
509
510         ld      r4,_RPR(r1)
511         mtspr   SPRN_RPR,r4
512         ld      r4,_AMOR(r1)
513         mtspr   SPRN_AMOR,r4
514
515 subcore_state_restored:
516         /*
517          * Check if the thread is also the first thread in the core. If not,
518          * skip to clear_lock.
519          */
520         bne     cr2,clear_lock
521
522 first_thread_in_core:
523
524         /*
525          * First thread in the core waking up from any state which can cause
526          * partial or complete hypervisor state loss. It needs to
527          * call the fastsleep workaround code if the platform requires it.
528          * Call it unconditionally here. The below branch instruction will
529          * be patched out if the platform does not have fastsleep or does not
530          * require the workaround. Patching will be performed during the
531          * discovery of idle-states.
532          */
533 .global pnv_fastsleep_workaround_at_exit
534 pnv_fastsleep_workaround_at_exit:
535         b       fastsleep_workaround_at_exit
536
537 timebase_resync:
538         /*
539          * Use cr3 which indicates that we are waking up with atleast partial
540          * hypervisor state loss to determine if TIMEBASE RESYNC is needed.
541          */
542         ble     cr3,clear_lock
543         /* Time base re-sync */
544         bl      opal_rm_resync_timebase;
545         /*
546          * If waking up from sleep, per core state is not lost, skip to
547          * clear_lock.
548          */
549         blt     cr4,clear_lock
550
551         /*
552          * First thread in the core to wake up and its waking up with
553          * complete hypervisor state loss. Restore per core hypervisor
554          * state.
555          */
556 BEGIN_FTR_SECTION
557         ld      r4,_PTCR(r1)
558         mtspr   SPRN_PTCR,r4
559         ld      r4,_RPR(r1)
560         mtspr   SPRN_RPR,r4
561 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
562
563         ld      r4,_TSCR(r1)
564         mtspr   SPRN_TSCR,r4
565         ld      r4,_WORC(r1)
566         mtspr   SPRN_WORC,r4
567
568 clear_lock:
569         andi.   r15,r15,PNV_CORE_IDLE_THREAD_BITS
570         lwsync
571         stw     r15,0(r14)
572
573 common_exit:
574         /*
575          * Common to all threads.
576          *
577          * If waking up from sleep, hypervisor state is not lost. Hence
578          * skip hypervisor state restore.
579          */
580         blt     cr4,hypervisor_state_restored
581
582         /* Waking up from winkle */
583
584 BEGIN_MMU_FTR_SECTION
585         b       no_segments
586 END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
587         /* Restore SLB  from PACA */
588         ld      r8,PACA_SLBSHADOWPTR(r13)
589
590         .rept   SLB_NUM_BOLTED
591         li      r3, SLBSHADOW_SAVEAREA
592         LDX_BE  r5, r8, r3
593         addi    r3, r3, 8
594         LDX_BE  r6, r8, r3
595         andis.  r7,r5,SLB_ESID_V@h
596         beq     1f
597         slbmte  r6,r5
598 1:      addi    r8,r8,16
599         .endr
600 no_segments:
601
602         /* Restore per thread state */
603
604         ld      r4,_SPURR(r1)
605         mtspr   SPRN_SPURR,r4
606         ld      r4,_PURR(r1)
607         mtspr   SPRN_PURR,r4
608         ld      r4,_DSCR(r1)
609         mtspr   SPRN_DSCR,r4
610         ld      r4,_WORT(r1)
611         mtspr   SPRN_WORT,r4
612
613         /* Call cur_cpu_spec->cpu_restore() */
614         LOAD_REG_ADDR(r4, cur_cpu_spec)
615         ld      r4,0(r4)
616         ld      r12,CPU_SPEC_RESTORE(r4)
617 #ifdef PPC64_ELF_ABI_v1
618         ld      r12,0(r12)
619 #endif
620         mtctr   r12
621         bctrl
622
623 hypervisor_state_restored:
624
625         mtspr   SPRN_SRR1,r16
626         mtlr    r17
627         blr     /* Return back to System Reset vector from where
628                    pnv_restore_hyp_resource was invoked */
629
630 fastsleep_workaround_at_exit:
631         li      r3,1
632         li      r4,0
633         bl      opal_rm_config_cpu_idle_state
634         b       timebase_resync
635
636 /*
637  * R3 here contains the value that will be returned to the caller
638  * of power7_nap.
639  */
640 _GLOBAL(pnv_wakeup_loss)
641         ld      r1,PACAR1(r13)
642 BEGIN_FTR_SECTION
643         CHECK_HMI_INTERRUPT
644 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
645         REST_NVGPRS(r1)
646         REST_GPR(2, r1)
647         ld      r6,_CCR(r1)
648         ld      r4,_MSR(r1)
649         ld      r5,_NIP(r1)
650         addi    r1,r1,INT_FRAME_SIZE
651         mtcr    r6
652         mtspr   SPRN_SRR1,r4
653         mtspr   SPRN_SRR0,r5
654         rfid
655
656 /*
657  * R3 here contains the value that will be returned to the caller
658  * of power7_nap.
659  */
660 _GLOBAL(pnv_wakeup_noloss)
661         lbz     r0,PACA_NAPSTATELOST(r13)
662         cmpwi   r0,0
663         bne     pnv_wakeup_loss
664 BEGIN_FTR_SECTION
665         CHECK_HMI_INTERRUPT
666 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
667         ld      r1,PACAR1(r13)
668         ld      r6,_CCR(r1)
669         ld      r4,_MSR(r1)
670         ld      r5,_NIP(r1)
671         addi    r1,r1,INT_FRAME_SIZE
672         mtcr    r6
673         mtspr   SPRN_SRR1,r4
674         mtspr   SPRN_SRR0,r5
675         rfid