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 |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame] | 30 | #define PACA_IRQ_PMI 0x40 |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 31 | |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 32 | /* |
Nicholas Piggin | 6cc3f91 | 2018-02-03 17:17:50 +1000 | [diff] [blame] | 33 | * Some soft-masked interrupts must be hard masked until they are replayed |
| 34 | * (e.g., because the soft-masked handler does not clear the exception). |
| 35 | */ |
| 36 | #ifdef CONFIG_PPC_BOOK3S |
| 37 | #define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE|PACA_IRQ_PMI) |
| 38 | #else |
| 39 | #define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE) |
| 40 | #endif |
| 41 | |
| 42 | /* |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 43 | * flags for paca->irq_soft_mask |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 44 | */ |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 45 | #define IRQS_ENABLED 0 |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame] | 46 | #define IRQS_DISABLED 1 /* local_irq_disable() interrupts */ |
| 47 | #define IRQS_PMI_DISABLED 2 |
| 48 | #define IRQS_ALL_DISABLED (IRQS_DISABLED | IRQS_PMI_DISABLED) |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 49 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 50 | #endif /* CONFIG_PPC64 */ |
| 51 | |
| 52 | #ifndef __ASSEMBLY__ |
| 53 | |
Nicholas Piggin | 6de6638 | 2017-11-05 23:33:55 +1100 | [diff] [blame] | 54 | extern void replay_system_reset(void); |
Nicholas Piggin | 6cc0c16 | 2020-02-26 03:35:37 +1000 | [diff] [blame] | 55 | extern void replay_soft_interrupts(void); |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 56 | |
Kumar Gala | c7aeffc | 2005-09-19 09:30:27 -0500 | [diff] [blame] | 57 | extern void timer_interrupt(struct pt_regs *); |
Nicholas Piggin | 3f98462 | 2018-05-05 03:19:31 +1000 | [diff] [blame] | 58 | extern void timer_broadcast_interrupt(void); |
Alexander Graf | 7cc1e8e | 2012-02-22 16:26:34 +0100 | [diff] [blame] | 59 | extern void performance_monitor_exception(struct pt_regs *regs); |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 60 | extern void WatchdogException(struct pt_regs *regs); |
| 61 | extern void unknown_exception(struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 63 | #ifdef CONFIG_PPC64 |
| 64 | #include <asm/paca.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 66 | static inline notrace unsigned long irq_soft_mask_return(void) |
Madhavan Srinivasan | e0b5687 | 2017-12-20 09:25:46 +0530 | [diff] [blame] | 67 | { |
| 68 | unsigned long flags; |
| 69 | |
| 70 | asm volatile( |
| 71 | "lbz %0,%1(13)" |
| 72 | : "=r" (flags) |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 73 | : "i" (offsetof(struct paca_struct, irq_soft_mask))); |
Madhavan Srinivasan | e0b5687 | 2017-12-20 09:25:46 +0530 | [diff] [blame] | 74 | |
| 75 | return flags; |
| 76 | } |
| 77 | |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 78 | /* |
| 79 | * The "memory" clobber acts as both a compiler barrier |
| 80 | * for the critical section and as a clobber because |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 81 | * we changed paca->irq_soft_mask |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 82 | */ |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 83 | static inline notrace void irq_soft_mask_set(unsigned long mask) |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 84 | { |
Madhavan Srinivasan | 9aa8818 | 2017-12-20 09:25:54 +0530 | [diff] [blame] | 85 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 86 | /* |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 87 | * The irq mask must always include the STD bit if any are set. |
| 88 | * |
| 89 | * and interrupts don't get replayed until the standard |
| 90 | * interrupt (local_irq_disable()) is unmasked. |
| 91 | * |
| 92 | * Other masks must only provide additional masking beyond |
| 93 | * the standard, and they are also not replayed until the |
| 94 | * standard interrupt becomes unmasked. |
| 95 | * |
| 96 | * This could be changed, but it will require partial |
| 97 | * unmasks to be replayed, among other things. For now, take |
| 98 | * the simple approach. |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 99 | */ |
| 100 | WARN_ON(mask && !(mask & IRQS_DISABLED)); |
| 101 | #endif |
| 102 | |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 103 | asm volatile( |
| 104 | "stb %0,%1(13)" |
| 105 | : |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 106 | : "r" (mask), |
| 107 | "i" (offsetof(struct paca_struct, irq_soft_mask)) |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 108 | : "memory"); |
| 109 | } |
| 110 | |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 111 | static inline notrace unsigned long irq_soft_mask_set_return(unsigned long mask) |
Madhavan Srinivasan | a67c543 | 2017-12-20 09:25:47 +0530 | [diff] [blame] | 112 | { |
| 113 | unsigned long flags; |
| 114 | |
Madhavan Srinivasan | 9aa8818 | 2017-12-20 09:25:54 +0530 | [diff] [blame] | 115 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 116 | WARN_ON(mask && !(mask & IRQS_DISABLED)); |
| 117 | #endif |
| 118 | |
Madhavan Srinivasan | a67c543 | 2017-12-20 09:25:47 +0530 | [diff] [blame] | 119 | asm volatile( |
| 120 | "lbz %0,%1(13); stb %2,%1(13)" |
| 121 | : "=&r" (flags) |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 122 | : "i" (offsetof(struct paca_struct, irq_soft_mask)), |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 123 | "r" (mask) |
Madhavan Srinivasan | a67c543 | 2017-12-20 09:25:47 +0530 | [diff] [blame] | 124 | : "memory"); |
| 125 | |
| 126 | return flags; |
| 127 | } |
| 128 | |
Madhavan Srinivasan | c642438 | 2017-12-20 09:25:55 +0530 | [diff] [blame] | 129 | static inline notrace unsigned long irq_soft_mask_or_return(unsigned long mask) |
| 130 | { |
| 131 | unsigned long flags, tmp; |
| 132 | |
| 133 | asm volatile( |
| 134 | "lbz %0,%2(13); or %1,%0,%3; stb %1,%2(13)" |
| 135 | : "=&r" (flags), "=r" (tmp) |
| 136 | : "i" (offsetof(struct paca_struct, irq_soft_mask)), |
| 137 | "r" (mask) |
| 138 | : "memory"); |
| 139 | |
| 140 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
| 141 | WARN_ON((mask | flags) && !((mask | flags) & IRQS_DISABLED)); |
| 142 | #endif |
| 143 | |
| 144 | return flags; |
| 145 | } |
| 146 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 147 | static inline unsigned long arch_local_save_flags(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 148 | { |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 149 | return irq_soft_mask_return(); |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 150 | } |
| 151 | |
Madhavan Srinivasan | b5c1bd6 | 2017-12-20 09:25:44 +0530 | [diff] [blame] | 152 | static inline void arch_local_irq_disable(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 153 | { |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 154 | irq_soft_mask_set(IRQS_DISABLED); |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 155 | } |
| 156 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 157 | extern void arch_local_irq_restore(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 159 | static inline void arch_local_irq_enable(void) |
| 160 | { |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 161 | arch_local_irq_restore(IRQS_ENABLED); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 164 | static inline unsigned long arch_local_irq_save(void) |
| 165 | { |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 166 | return irq_soft_mask_set_return(IRQS_DISABLED); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
| 170 | { |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 171 | return flags & IRQS_DISABLED; |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static inline bool arch_irqs_disabled(void) |
| 175 | { |
| 176 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 177 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Madhavan Srinivasan | c642438 | 2017-12-20 09:25:55 +0530 | [diff] [blame] | 179 | #ifdef CONFIG_PPC_BOOK3S |
| 180 | /* |
| 181 | * To support disabling and enabling of irq with PMI, set of |
| 182 | * new powerpc_local_irq_pmu_save() and powerpc_local_irq_restore() |
| 183 | * functions are added. These macros are implemented using generic |
| 184 | * linux local_irq_* code from include/linux/irqflags.h. |
| 185 | */ |
| 186 | #define raw_local_irq_pmu_save(flags) \ |
| 187 | do { \ |
| 188 | typecheck(unsigned long, flags); \ |
| 189 | flags = irq_soft_mask_or_return(IRQS_DISABLED | \ |
| 190 | IRQS_PMI_DISABLED); \ |
| 191 | } while(0) |
| 192 | |
| 193 | #define raw_local_irq_pmu_restore(flags) \ |
| 194 | do { \ |
| 195 | typecheck(unsigned long, flags); \ |
| 196 | arch_local_irq_restore(flags); \ |
| 197 | } while(0) |
| 198 | |
| 199 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 200 | #define powerpc_local_irq_pmu_save(flags) \ |
| 201 | do { \ |
| 202 | raw_local_irq_pmu_save(flags); \ |
| 203 | trace_hardirqs_off(); \ |
| 204 | } while(0) |
| 205 | #define powerpc_local_irq_pmu_restore(flags) \ |
| 206 | do { \ |
| 207 | if (raw_irqs_disabled_flags(flags)) { \ |
| 208 | raw_local_irq_pmu_restore(flags); \ |
| 209 | trace_hardirqs_off(); \ |
| 210 | } else { \ |
| 211 | trace_hardirqs_on(); \ |
| 212 | raw_local_irq_pmu_restore(flags); \ |
| 213 | } \ |
| 214 | } while(0) |
| 215 | #else |
| 216 | #define powerpc_local_irq_pmu_save(flags) \ |
| 217 | do { \ |
| 218 | raw_local_irq_pmu_save(flags); \ |
| 219 | } while(0) |
| 220 | #define powerpc_local_irq_pmu_restore(flags) \ |
| 221 | do { \ |
| 222 | raw_local_irq_pmu_restore(flags); \ |
| 223 | } while (0) |
| 224 | #endif /* CONFIG_TRACE_IRQFLAGS */ |
| 225 | |
| 226 | #endif /* CONFIG_PPC_BOOK3S */ |
| 227 | |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 228 | #ifdef CONFIG_PPC_BOOK3E |
Christophe Leroy | b020aa9 | 2019-08-29 08:45:13 +0000 | [diff] [blame] | 229 | #define __hard_irq_enable() wrtee(MSR_EE) |
| 230 | #define __hard_irq_disable() wrtee(0) |
Nicholas Piggin | 68b3458 | 2020-02-26 03:35:34 +1000 | [diff] [blame] | 231 | #define __hard_EE_RI_disable() wrtee(0) |
| 232 | #define __hard_RI_enable() do { } while (0) |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 233 | #else |
Nicholas Piggin | 54071e4 | 2018-05-05 03:19:28 +1000 | [diff] [blame] | 234 | #define __hard_irq_enable() __mtmsrd(MSR_EE|MSR_RI, 1) |
| 235 | #define __hard_irq_disable() __mtmsrd(MSR_RI, 1) |
Nicholas Piggin | 68b3458 | 2020-02-26 03:35:34 +1000 | [diff] [blame] | 236 | #define __hard_EE_RI_disable() __mtmsrd(0, 1) |
| 237 | #define __hard_RI_enable() __mtmsrd(MSR_RI, 1) |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 238 | #endif |
Benjamin Herrenschmidt | e1fa2e1 | 2007-05-10 22:22:45 -0700 | [diff] [blame] | 239 | |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame] | 240 | #define hard_irq_disable() do { \ |
| 241 | unsigned long flags; \ |
| 242 | __hard_irq_disable(); \ |
| 243 | flags = irq_soft_mask_set_return(IRQS_ALL_DISABLED); \ |
| 244 | local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \ |
Michael Ellerman | 7b08729 | 2018-05-02 23:07:26 +1000 | [diff] [blame] | 245 | if (!arch_irqs_disabled_flags(flags)) { \ |
| 246 | asm ("stdx %%r1, 0, %1 ;" \ |
| 247 | : "=m" (local_paca->saved_r1) \ |
| 248 | : "b" (&local_paca->saved_r1)); \ |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame] | 249 | trace_hardirqs_off(); \ |
Michael Ellerman | 7b08729 | 2018-05-02 23:07:26 +1000 | [diff] [blame] | 250 | } \ |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 251 | } while(0) |
Paul Mackerras | f948501 | 2012-06-15 14:51:39 +1000 | [diff] [blame] | 252 | |
Michael Ellerman | 0094368 | 2020-05-03 00:33:16 +1000 | [diff] [blame^] | 253 | static inline bool __lazy_irq_pending(u8 irq_happened) |
| 254 | { |
| 255 | return !!(irq_happened & ~PACA_IRQ_HARD_DIS); |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * Check if a lazy IRQ is pending. Should be called with IRQs hard disabled. |
| 260 | */ |
Anton Blanchard | 0b17ba7 | 2012-06-27 13:13:52 +0000 | [diff] [blame] | 261 | static inline bool lazy_irq_pending(void) |
| 262 | { |
Michael Ellerman | 0094368 | 2020-05-03 00:33:16 +1000 | [diff] [blame^] | 263 | return __lazy_irq_pending(get_paca()->irq_happened); |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Check if a lazy IRQ is pending, with no debugging checks. |
| 268 | * Should be called with IRQs hard disabled. |
| 269 | * For use in RI disabled code or other constrained situations. |
| 270 | */ |
| 271 | static inline bool lazy_irq_pending_nocheck(void) |
| 272 | { |
| 273 | return __lazy_irq_pending(local_paca->irq_happened); |
Anton Blanchard | 0b17ba7 | 2012-06-27 13:13:52 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 276 | /* |
| 277 | * This is called by asynchronous interrupts to conditionally |
Nicholas Piggin | 9b81c02 | 2018-06-03 22:24:32 +1000 | [diff] [blame] | 278 | * re-enable hard interrupts after having cleared the source |
| 279 | * of the interrupt. They are kept disabled if there is a different |
| 280 | * soft-masked interrupt pending that requires hard masking. |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 281 | */ |
| 282 | static inline void may_hard_irq_enable(void) |
| 283 | { |
Nicholas Piggin | 9b81c02 | 2018-06-03 22:24:32 +1000 | [diff] [blame] | 284 | if (!(get_paca()->irq_happened & PACA_IRQ_MUST_HARD_MASK)) { |
| 285 | get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS; |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 286 | __hard_irq_enable(); |
Nicholas Piggin | 9b81c02 | 2018-06-03 22:24:32 +1000 | [diff] [blame] | 287 | } |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 288 | } |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 289 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 290 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 291 | { |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 292 | return (regs->softe & IRQS_DISABLED); |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 293 | } |
| 294 | |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 295 | extern bool prep_irq_for_idle(void); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 296 | extern bool prep_irq_for_idle_irqsoff(void); |
Nicholas Piggin | 771d430 | 2017-06-13 23:05:47 +1000 | [diff] [blame] | 297 | extern void irq_set_pending_from_srr1(unsigned long srr1); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 298 | |
| 299 | #define fini_irq_for_idle_irqsoff() trace_hardirqs_off(); |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 300 | |
Benjamin Herrenschmidt | 1d607bb | 2016-07-08 16:37:07 +1000 | [diff] [blame] | 301 | extern void force_external_irq_replay(void); |
| 302 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 303 | #else /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 305 | static inline unsigned long arch_local_save_flags(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 307 | return mfmsr(); |
| 308 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 309 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 310 | static inline void arch_local_irq_restore(unsigned long flags) |
| 311 | { |
Christophe Leroy | b020aa9 | 2019-08-29 08:45:13 +0000 | [diff] [blame] | 312 | if (IS_ENABLED(CONFIG_BOOKE)) |
| 313 | wrtee(flags); |
| 314 | else |
| 315 | mtmsr(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 318 | static inline unsigned long arch_local_irq_save(void) |
| 319 | { |
| 320 | unsigned long flags = arch_local_save_flags(); |
Christophe Leroy | b020aa9 | 2019-08-29 08:45:13 +0000 | [diff] [blame] | 321 | |
| 322 | if (IS_ENABLED(CONFIG_BOOKE)) |
| 323 | wrtee(0); |
| 324 | else if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 325 | wrtspr(SPRN_EID); |
| 326 | else |
| 327 | mtmsr(flags & ~MSR_EE); |
| 328 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 329 | return flags; |
| 330 | } |
| 331 | |
| 332 | static inline void arch_local_irq_disable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Christophe Leroy | b020aa9 | 2019-08-29 08:45:13 +0000 | [diff] [blame] | 334 | if (IS_ENABLED(CONFIG_BOOKE)) |
| 335 | wrtee(0); |
| 336 | else if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 337 | wrtspr(SPRN_EID); |
| 338 | else |
| 339 | mtmsr(mfmsr() & ~MSR_EE); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 340 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 341 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 342 | static inline void arch_local_irq_enable(void) |
| 343 | { |
Christophe Leroy | b020aa9 | 2019-08-29 08:45:13 +0000 | [diff] [blame] | 344 | if (IS_ENABLED(CONFIG_BOOKE)) |
| 345 | wrtee(MSR_EE); |
| 346 | else if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 347 | wrtspr(SPRN_EIE); |
| 348 | else |
| 349 | mtmsr(mfmsr() | MSR_EE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 352 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
Steven Rostedt | e0eca07 | 2008-05-14 23:49:43 -0400 | [diff] [blame] | 353 | { |
| 354 | return (flags & MSR_EE) == 0; |
| 355 | } |
| 356 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 357 | static inline bool arch_irqs_disabled(void) |
| 358 | { |
| 359 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 360 | } |
| 361 | |
| 362 | #define hard_irq_disable() arch_local_irq_disable() |
| 363 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 364 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 365 | { |
| 366 | return !(regs->msr & MSR_EE); |
| 367 | } |
| 368 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 369 | static inline void may_hard_irq_enable(void) { } |
| 370 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 371 | #endif /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Thomas Gleixner | 089fb44 | 2011-01-21 06:12:28 +0000 | [diff] [blame] | 373 | #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST |
| 374 | |
Ingo Molnar | c0ad90a | 2006-06-29 02:24:44 -0700 | [diff] [blame] | 375 | /* |
| 376 | * interrupt-retrigger: should we handle this via lost interrupts and IPIs |
| 377 | * or should we not care like we do now ? --BenH. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | */ |
Thomas Gleixner | 353bca5 | 2009-03-10 14:46:30 +0000 | [diff] [blame] | 379 | struct irq_chip; |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 380 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 381 | #endif /* __ASSEMBLY__ */ |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 382 | #endif /* __KERNEL__ */ |
| 383 | #endif /* _ASM_POWERPC_HW_IRQ_H */ |