Merge branch 'soc' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/renesas...
[firefly-linux-kernel-4.4.55.git] / arch / powerpc / include / asm / hw_irq.h
1 /*
2  * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
3  */
4 #ifndef _ASM_POWERPC_HW_IRQ_H
5 #define _ASM_POWERPC_HW_IRQ_H
6
7 #ifdef __KERNEL__
8
9 #include <linux/errno.h>
10 #include <linux/compiler.h>
11 #include <asm/ptrace.h>
12 #include <asm/processor.h>
13
14 #ifdef CONFIG_PPC64
15
16 /*
17  * PACA flags in paca->irq_happened.
18  *
19  * This bits are set when interrupts occur while soft-disabled
20  * and allow a proper replay. Additionally, PACA_IRQ_HARD_DIS
21  * is set whenever we manually hard disable.
22  */
23 #define PACA_IRQ_HARD_DIS       0x01
24 #define PACA_IRQ_DBELL          0x02
25 #define PACA_IRQ_EE             0x04
26 #define PACA_IRQ_DEC            0x08 /* Or FIT */
27 #define PACA_IRQ_EE_EDGE        0x10 /* BookE only */
28
29 #endif /* CONFIG_PPC64 */
30
31 #ifndef __ASSEMBLY__
32
33 extern void __replay_interrupt(unsigned int vector);
34
35 extern void timer_interrupt(struct pt_regs *);
36 extern void performance_monitor_exception(struct pt_regs *regs);
37
38 #ifdef CONFIG_PPC64
39 #include <asm/paca.h>
40
41 static inline unsigned long arch_local_save_flags(void)
42 {
43         unsigned long flags;
44
45         asm volatile(
46                 "lbz %0,%1(13)"
47                 : "=r" (flags)
48                 : "i" (offsetof(struct paca_struct, soft_enabled)));
49
50         return flags;
51 }
52
53 static inline unsigned long arch_local_irq_disable(void)
54 {
55         unsigned long flags, zero;
56
57         asm volatile(
58                 "li %1,0; lbz %0,%2(13); stb %1,%2(13)"
59                 : "=r" (flags), "=&r" (zero)
60                 : "i" (offsetof(struct paca_struct, soft_enabled))
61                 : "memory");
62
63         return flags;
64 }
65
66 extern void arch_local_irq_restore(unsigned long);
67
68 static inline void arch_local_irq_enable(void)
69 {
70         arch_local_irq_restore(1);
71 }
72
73 static inline unsigned long arch_local_irq_save(void)
74 {
75         return arch_local_irq_disable();
76 }
77
78 static inline bool arch_irqs_disabled_flags(unsigned long flags)
79 {
80         return flags == 0;
81 }
82
83 static inline bool arch_irqs_disabled(void)
84 {
85         return arch_irqs_disabled_flags(arch_local_save_flags());
86 }
87
88 #ifdef CONFIG_PPC_BOOK3E
89 #define __hard_irq_enable()     asm volatile("wrteei 1" : : : "memory");
90 #define __hard_irq_disable()    asm volatile("wrteei 0" : : : "memory");
91 #else
92 #define __hard_irq_enable()     __mtmsrd(local_paca->kernel_msr | MSR_EE, 1)
93 #define __hard_irq_disable()    __mtmsrd(local_paca->kernel_msr, 1)
94 #endif
95
96 static inline void hard_irq_disable(void)
97 {
98         __hard_irq_disable();
99         get_paca()->soft_enabled = 0;
100         get_paca()->irq_happened |= PACA_IRQ_HARD_DIS;
101 }
102
103 /* include/linux/interrupt.h needs hard_irq_disable to be a macro */
104 #define hard_irq_disable        hard_irq_disable
105
106 /*
107  * This is called by asynchronous interrupts to conditionally
108  * re-enable hard interrupts when soft-disabled after having
109  * cleared the source of the interrupt
110  */
111 static inline void may_hard_irq_enable(void)
112 {
113         get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS;
114         if (!(get_paca()->irq_happened & PACA_IRQ_EE))
115                 __hard_irq_enable();
116 }
117
118 static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
119 {
120         return !regs->softe;
121 }
122
123 #else /* CONFIG_PPC64 */
124
125 #define SET_MSR_EE(x)   mtmsr(x)
126
127 static inline unsigned long arch_local_save_flags(void)
128 {
129         return mfmsr();
130 }
131
132 static inline void arch_local_irq_restore(unsigned long flags)
133 {
134 #if defined(CONFIG_BOOKE)
135         asm volatile("wrtee %0" : : "r" (flags) : "memory");
136 #else
137         mtmsr(flags);
138 #endif
139 }
140
141 static inline unsigned long arch_local_irq_save(void)
142 {
143         unsigned long flags = arch_local_save_flags();
144 #ifdef CONFIG_BOOKE
145         asm volatile("wrteei 0" : : : "memory");
146 #else
147         SET_MSR_EE(flags & ~MSR_EE);
148 #endif
149         return flags;
150 }
151
152 static inline void arch_local_irq_disable(void)
153 {
154 #ifdef CONFIG_BOOKE
155         asm volatile("wrteei 0" : : : "memory");
156 #else
157         arch_local_irq_save();
158 #endif
159 }
160
161 static inline void arch_local_irq_enable(void)
162 {
163 #ifdef CONFIG_BOOKE
164         asm volatile("wrteei 1" : : : "memory");
165 #else
166         unsigned long msr = mfmsr();
167         SET_MSR_EE(msr | MSR_EE);
168 #endif
169 }
170
171 static inline bool arch_irqs_disabled_flags(unsigned long flags)
172 {
173         return (flags & MSR_EE) == 0;
174 }
175
176 static inline bool arch_irqs_disabled(void)
177 {
178         return arch_irqs_disabled_flags(arch_local_save_flags());
179 }
180
181 #define hard_irq_disable()              arch_local_irq_disable()
182
183 static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
184 {
185         return !(regs->msr & MSR_EE);
186 }
187
188 static inline void may_hard_irq_enable(void) { }
189
190 #endif /* CONFIG_PPC64 */
191
192 #define ARCH_IRQ_INIT_FLAGS     IRQ_NOREQUEST
193
194 /*
195  * interrupt-retrigger: should we handle this via lost interrupts and IPIs
196  * or should we not care like we do now ? --BenH.
197  */
198 struct irq_chip;
199
200 #endif  /* __ASSEMBLY__ */
201 #endif  /* __KERNEL__ */
202 #endif  /* _ASM_POWERPC_HW_IRQ_H */