Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 5 | #ifndef _ASM_POWERPC_HW_IRQ_H |
| 6 | #define _ASM_POWERPC_HW_IRQ_H |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/errno.h> |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 11 | #include <linux/compiler.h> |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 12 | #include <asm/ptrace.h> |
| 13 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 15 | #ifdef CONFIG_PPC64 |
| 16 | |
| 17 | /* |
| 18 | * PACA flags in paca->irq_happened. |
| 19 | * |
| 20 | * This bits are set when interrupts occur while soft-disabled |
| 21 | * and allow a proper replay. Additionally, PACA_IRQ_HARD_DIS |
| 22 | * is set whenever we manually hard disable. |
| 23 | */ |
| 24 | #define PACA_IRQ_HARD_DIS 0x01 |
| 25 | #define PACA_IRQ_DBELL 0x02 |
| 26 | #define PACA_IRQ_EE 0x04 |
| 27 | #define PACA_IRQ_DEC 0x08 /* Or FIT */ |
| 28 | #define PACA_IRQ_EE_EDGE 0x10 /* BookE only */ |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 29 | #define PACA_IRQ_HMI 0x20 |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 30 | |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 31 | /* |
| 32 | * flags for paca->soft_enabled |
| 33 | */ |
| 34 | #define IRQS_ENABLED 1 |
| 35 | #define IRQS_DISABLED 0 |
| 36 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 37 | #endif /* CONFIG_PPC64 */ |
| 38 | |
| 39 | #ifndef __ASSEMBLY__ |
| 40 | |
Nicholas Piggin | 6de6638 | 2017-11-05 23:33:55 +1100 | [diff] [blame] | 41 | extern void replay_system_reset(void); |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 42 | extern void __replay_interrupt(unsigned int vector); |
| 43 | |
Kumar Gala | c7aeffc | 2005-09-19 09:30:27 -0500 | [diff] [blame] | 44 | extern void timer_interrupt(struct pt_regs *); |
Alexander Graf | 7cc1e8e | 2012-02-22 16:26:34 +0100 | [diff] [blame] | 45 | extern void performance_monitor_exception(struct pt_regs *regs); |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 46 | extern void WatchdogException(struct pt_regs *regs); |
| 47 | extern void unknown_exception(struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 49 | #ifdef CONFIG_PPC64 |
| 50 | #include <asm/paca.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Madhavan Srinivasan | e0b5687 | 2017-12-20 09:25:46 +0530 | [diff] [blame^] | 52 | static inline notrace unsigned long soft_enabled_return(void) |
| 53 | { |
| 54 | unsigned long flags; |
| 55 | |
| 56 | asm volatile( |
| 57 | "lbz %0,%1(13)" |
| 58 | : "=r" (flags) |
| 59 | : "i" (offsetof(struct paca_struct, soft_enabled))); |
| 60 | |
| 61 | return flags; |
| 62 | } |
| 63 | |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 64 | /* |
| 65 | * The "memory" clobber acts as both a compiler barrier |
| 66 | * for the critical section and as a clobber because |
| 67 | * we changed paca->soft_enabled |
| 68 | */ |
| 69 | static inline notrace void soft_enabled_set(unsigned long enable) |
| 70 | { |
| 71 | asm volatile( |
| 72 | "stb %0,%1(13)" |
| 73 | : |
| 74 | : "r" (enable), |
| 75 | "i" (offsetof(struct paca_struct, soft_enabled)) |
| 76 | : "memory"); |
| 77 | } |
| 78 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 79 | static inline unsigned long arch_local_save_flags(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 80 | { |
Madhavan Srinivasan | e0b5687 | 2017-12-20 09:25:46 +0530 | [diff] [blame^] | 81 | return soft_enabled_return(); |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 82 | } |
| 83 | |
Madhavan Srinivasan | b5c1bd6 | 2017-12-20 09:25:44 +0530 | [diff] [blame] | 84 | static inline void arch_local_irq_disable(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 85 | { |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 86 | soft_enabled_set(IRQS_DISABLED); |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 87 | } |
| 88 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 89 | extern void arch_local_irq_restore(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 91 | static inline void arch_local_irq_enable(void) |
| 92 | { |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 93 | arch_local_irq_restore(IRQS_ENABLED); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 96 | static inline unsigned long arch_local_irq_save(void) |
| 97 | { |
Madhavan Srinivasan | b5c1bd6 | 2017-12-20 09:25:44 +0530 | [diff] [blame] | 98 | unsigned long flags; |
| 99 | |
| 100 | asm volatile( |
| 101 | "lbz %0,%1(13); stb %2,%1(13)" |
| 102 | : "=&r" (flags) |
| 103 | : "i" (offsetof(struct paca_struct, soft_enabled)), |
| 104 | "r" (IRQS_DISABLED) |
| 105 | : "memory"); |
| 106 | |
| 107 | return flags; |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
| 111 | { |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 112 | return flags == IRQS_DISABLED; |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static inline bool arch_irqs_disabled(void) |
| 116 | { |
| 117 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 120 | #ifdef CONFIG_PPC_BOOK3E |
Benjamin Herrenschmidt | 21b2de3 | 2012-07-10 18:37:56 +1000 | [diff] [blame] | 121 | #define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory") |
| 122 | #define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory") |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 123 | #else |
Benjamin Herrenschmidt | d9ada91 | 2012-03-02 11:33:52 +1100 | [diff] [blame] | 124 | #define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1) |
| 125 | #define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1) |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 126 | #endif |
Benjamin Herrenschmidt | e1fa2e1 | 2007-05-10 22:22:45 -0700 | [diff] [blame] | 127 | |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 128 | #define hard_irq_disable() do { \ |
Tiejun Chen | 0b88f77 | 2013-07-15 10:36:04 +0800 | [diff] [blame] | 129 | u8 _was_enabled; \ |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 130 | __hard_irq_disable(); \ |
Tiejun Chen | 0b88f77 | 2013-07-15 10:36:04 +0800 | [diff] [blame] | 131 | _was_enabled = local_paca->soft_enabled; \ |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 132 | local_paca->soft_enabled = IRQS_DISABLED;\ |
Tiejun Chen | 0b88f77 | 2013-07-15 10:36:04 +0800 | [diff] [blame] | 133 | local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \ |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 134 | if (_was_enabled == IRQS_ENABLED) \ |
Scott Wood | 4a3b8d0 | 2013-05-09 22:09:41 -0500 | [diff] [blame] | 135 | trace_hardirqs_off(); \ |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 136 | } while(0) |
Paul Mackerras | f948501 | 2012-06-15 14:51:39 +1000 | [diff] [blame] | 137 | |
Anton Blanchard | 0b17ba7 | 2012-06-27 13:13:52 +0000 | [diff] [blame] | 138 | static inline bool lazy_irq_pending(void) |
| 139 | { |
| 140 | return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS); |
| 141 | } |
| 142 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 143 | /* |
| 144 | * This is called by asynchronous interrupts to conditionally |
| 145 | * re-enable hard interrupts when soft-disabled after having |
| 146 | * cleared the source of the interrupt |
| 147 | */ |
| 148 | static inline void may_hard_irq_enable(void) |
| 149 | { |
| 150 | get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS; |
| 151 | if (!(get_paca()->irq_happened & PACA_IRQ_EE)) |
| 152 | __hard_irq_enable(); |
| 153 | } |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 154 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 155 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 156 | { |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 157 | return (regs->softe == IRQS_DISABLED); |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 158 | } |
| 159 | |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 160 | extern bool prep_irq_for_idle(void); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 161 | extern bool prep_irq_for_idle_irqsoff(void); |
Nicholas Piggin | 771d430 | 2017-06-13 23:05:47 +1000 | [diff] [blame] | 162 | extern void irq_set_pending_from_srr1(unsigned long srr1); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 163 | |
| 164 | #define fini_irq_for_idle_irqsoff() trace_hardirqs_off(); |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 165 | |
Benjamin Herrenschmidt | 1d607bb | 2016-07-08 16:37:07 +1000 | [diff] [blame] | 166 | extern void force_external_irq_replay(void); |
| 167 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 168 | #else /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 170 | #define SET_MSR_EE(x) mtmsr(x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 172 | static inline unsigned long arch_local_save_flags(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 174 | return mfmsr(); |
| 175 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 176 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 177 | static inline void arch_local_irq_restore(unsigned long flags) |
| 178 | { |
| 179 | #if defined(CONFIG_BOOKE) |
| 180 | asm volatile("wrtee %0" : : "r" (flags) : "memory"); |
| 181 | #else |
| 182 | mtmsr(flags); |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 183 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 186 | static inline unsigned long arch_local_irq_save(void) |
| 187 | { |
| 188 | unsigned long flags = arch_local_save_flags(); |
| 189 | #ifdef CONFIG_BOOKE |
| 190 | asm volatile("wrteei 0" : : : "memory"); |
Christophe Leroy | 834e5a6 | 2016-08-23 15:58:56 +0200 | [diff] [blame] | 191 | #elif defined(CONFIG_PPC_8xx) |
| 192 | wrtspr(SPRN_EID); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 193 | #else |
| 194 | SET_MSR_EE(flags & ~MSR_EE); |
| 195 | #endif |
| 196 | return flags; |
| 197 | } |
| 198 | |
| 199 | static inline void arch_local_irq_disable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 201 | #ifdef CONFIG_BOOKE |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 202 | asm volatile("wrteei 0" : : : "memory"); |
Christophe Leroy | 834e5a6 | 2016-08-23 15:58:56 +0200 | [diff] [blame] | 203 | #elif defined(CONFIG_PPC_8xx) |
| 204 | wrtspr(SPRN_EID); |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 205 | #else |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 206 | arch_local_irq_save(); |
| 207 | #endif |
| 208 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 209 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 210 | static inline void arch_local_irq_enable(void) |
| 211 | { |
| 212 | #ifdef CONFIG_BOOKE |
| 213 | asm volatile("wrteei 1" : : : "memory"); |
Christophe Leroy | 834e5a6 | 2016-08-23 15:58:56 +0200 | [diff] [blame] | 214 | #elif defined(CONFIG_PPC_8xx) |
| 215 | wrtspr(SPRN_EIE); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 216 | #else |
| 217 | unsigned long msr = mfmsr(); |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 218 | SET_MSR_EE(msr | MSR_EE); |
| 219 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 222 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
Steven Rostedt | e0eca07 | 2008-05-14 23:49:43 -0400 | [diff] [blame] | 223 | { |
| 224 | return (flags & MSR_EE) == 0; |
| 225 | } |
| 226 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 227 | static inline bool arch_irqs_disabled(void) |
| 228 | { |
| 229 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 230 | } |
| 231 | |
| 232 | #define hard_irq_disable() arch_local_irq_disable() |
| 233 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 234 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 235 | { |
| 236 | return !(regs->msr & MSR_EE); |
| 237 | } |
| 238 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 239 | static inline void may_hard_irq_enable(void) { } |
| 240 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 241 | #endif /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Thomas Gleixner | 089fb44 | 2011-01-21 06:12:28 +0000 | [diff] [blame] | 243 | #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST |
| 244 | |
Ingo Molnar | c0ad90a | 2006-06-29 02:24:44 -0700 | [diff] [blame] | 245 | /* |
| 246 | * interrupt-retrigger: should we handle this via lost interrupts and IPIs |
| 247 | * or should we not care like we do now ? --BenH. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | */ |
Thomas Gleixner | 353bca5 | 2009-03-10 14:46:30 +0000 | [diff] [blame] | 249 | struct irq_chip; |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 250 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 251 | #endif /* __ASSEMBLY__ */ |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 252 | #endif /* __KERNEL__ */ |
| 253 | #endif /* _ASM_POWERPC_HW_IRQ_H */ |