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