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 |
Nicholas Piggin | 1379974 | 2021-06-18 01:51:11 +1000 | [diff] [blame] | 21 | * and allow a proper replay. |
| 22 | * |
| 23 | * The PACA_IRQ_HARD_DIS is set whenever we hard disable. It is almost |
| 24 | * always in synch with the MSR[EE] state, except: |
| 25 | * - A window in interrupt entry, where hardware disables MSR[EE] and that |
| 26 | * must be "reconciled" with the soft mask state. |
| 27 | * - NMI interrupts that hit in awkward places, until they fix the state. |
| 28 | * - When local irqs are being enabled and state is being fixed up. |
| 29 | * - When returning from an interrupt there are some windows where this |
| 30 | * can become out of synch, but gets fixed before the RFI or before |
| 31 | * executing the next user instruction (see arch/powerpc/kernel/interrupt.c). |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 32 | */ |
| 33 | #define PACA_IRQ_HARD_DIS 0x01 |
| 34 | #define PACA_IRQ_DBELL 0x02 |
| 35 | #define PACA_IRQ_EE 0x04 |
| 36 | #define PACA_IRQ_DEC 0x08 /* Or FIT */ |
Nicholas Piggin | 012a9a9 | 2020-09-15 21:46:47 +1000 | [diff] [blame] | 37 | #define PACA_IRQ_HMI 0x10 |
| 38 | #define PACA_IRQ_PMI 0x20 |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 39 | |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 40 | /* |
Nicholas Piggin | 6cc3f91 | 2018-02-03 17:17:50 +1000 | [diff] [blame] | 41 | * Some soft-masked interrupts must be hard masked until they are replayed |
| 42 | * (e.g., because the soft-masked handler does not clear the exception). |
| 43 | */ |
| 44 | #ifdef CONFIG_PPC_BOOK3S |
| 45 | #define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE|PACA_IRQ_PMI) |
| 46 | #else |
| 47 | #define PACA_IRQ_MUST_HARD_MASK (PACA_IRQ_EE) |
| 48 | #endif |
| 49 | |
Christophe Leroy | fb5608f | 2021-02-08 15:10:24 +0000 | [diff] [blame] | 50 | #endif /* CONFIG_PPC64 */ |
| 51 | |
Nicholas Piggin | 6cc3f91 | 2018-02-03 17:17:50 +1000 | [diff] [blame] | 52 | /* |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 53 | * flags for paca->irq_soft_mask |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 54 | */ |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 55 | #define IRQS_ENABLED 0 |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame] | 56 | #define IRQS_DISABLED 1 /* local_irq_disable() interrupts */ |
| 57 | #define IRQS_PMI_DISABLED 2 |
| 58 | #define IRQS_ALL_DISABLED (IRQS_DISABLED | IRQS_PMI_DISABLED) |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 59 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 60 | #ifndef __ASSEMBLY__ |
| 61 | |
Christophe Leroy | 0835377 | 2021-02-08 15:10:25 +0000 | [diff] [blame] | 62 | static inline void __hard_irq_enable(void) |
| 63 | { |
Christophe Leroy | 047a6fd | 2021-10-19 09:29:25 +0200 | [diff] [blame] | 64 | if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) |
Christophe Leroy | 0835377 | 2021-02-08 15:10:25 +0000 | [diff] [blame] | 65 | wrtee(MSR_EE); |
| 66 | else if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 67 | wrtspr(SPRN_EIE); |
| 68 | else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) |
| 69 | __mtmsrd(MSR_EE | MSR_RI, 1); |
| 70 | else |
| 71 | mtmsr(mfmsr() | MSR_EE); |
| 72 | } |
| 73 | |
| 74 | static inline void __hard_irq_disable(void) |
| 75 | { |
Christophe Leroy | 047a6fd | 2021-10-19 09:29:25 +0200 | [diff] [blame] | 76 | if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) |
Christophe Leroy | 0835377 | 2021-02-08 15:10:25 +0000 | [diff] [blame] | 77 | wrtee(0); |
| 78 | else if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 79 | wrtspr(SPRN_EID); |
| 80 | else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) |
| 81 | __mtmsrd(MSR_RI, 1); |
| 82 | else |
| 83 | mtmsr(mfmsr() & ~MSR_EE); |
| 84 | } |
| 85 | |
| 86 | static inline void __hard_EE_RI_disable(void) |
| 87 | { |
Christophe Leroy | 047a6fd | 2021-10-19 09:29:25 +0200 | [diff] [blame] | 88 | if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) |
Christophe Leroy | 0835377 | 2021-02-08 15:10:25 +0000 | [diff] [blame] | 89 | wrtee(0); |
| 90 | else if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 91 | wrtspr(SPRN_NRI); |
| 92 | else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) |
| 93 | __mtmsrd(0, 1); |
| 94 | else |
| 95 | mtmsr(mfmsr() & ~(MSR_EE | MSR_RI)); |
| 96 | } |
| 97 | |
| 98 | static inline void __hard_RI_enable(void) |
| 99 | { |
Christophe Leroy | 047a6fd | 2021-10-19 09:29:25 +0200 | [diff] [blame] | 100 | if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) |
Christophe Leroy | 0835377 | 2021-02-08 15:10:25 +0000 | [diff] [blame] | 101 | return; |
| 102 | |
| 103 | if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 104 | wrtspr(SPRN_EID); |
| 105 | else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) |
| 106 | __mtmsrd(MSR_RI, 1); |
| 107 | else |
| 108 | mtmsr(mfmsr() | MSR_RI); |
| 109 | } |
| 110 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 111 | #ifdef CONFIG_PPC64 |
| 112 | #include <asm/paca.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 114 | static inline notrace unsigned long irq_soft_mask_return(void) |
Madhavan Srinivasan | e0b5687 | 2017-12-20 09:25:46 +0530 | [diff] [blame] | 115 | { |
| 116 | unsigned long flags; |
| 117 | |
| 118 | asm volatile( |
| 119 | "lbz %0,%1(13)" |
| 120 | : "=r" (flags) |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 121 | : "i" (offsetof(struct paca_struct, irq_soft_mask))); |
Madhavan Srinivasan | e0b5687 | 2017-12-20 09:25:46 +0530 | [diff] [blame] | 122 | |
| 123 | return flags; |
| 124 | } |
| 125 | |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 126 | /* |
| 127 | * The "memory" clobber acts as both a compiler barrier |
| 128 | * for the critical section and as a clobber because |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 129 | * we changed paca->irq_soft_mask |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 130 | */ |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 131 | static inline notrace void irq_soft_mask_set(unsigned long mask) |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 132 | { |
Madhavan Srinivasan | 9aa8818 | 2017-12-20 09:25:54 +0530 | [diff] [blame] | 133 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 134 | /* |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 135 | * The irq mask must always include the STD bit if any are set. |
| 136 | * |
| 137 | * and interrupts don't get replayed until the standard |
| 138 | * interrupt (local_irq_disable()) is unmasked. |
| 139 | * |
| 140 | * Other masks must only provide additional masking beyond |
| 141 | * the standard, and they are also not replayed until the |
| 142 | * standard interrupt becomes unmasked. |
| 143 | * |
| 144 | * This could be changed, but it will require partial |
| 145 | * unmasks to be replayed, among other things. For now, take |
| 146 | * the simple approach. |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 147 | */ |
| 148 | WARN_ON(mask && !(mask & IRQS_DISABLED)); |
| 149 | #endif |
| 150 | |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 151 | asm volatile( |
| 152 | "stb %0,%1(13)" |
| 153 | : |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 154 | : "r" (mask), |
| 155 | "i" (offsetof(struct paca_struct, irq_soft_mask)) |
Madhavan Srinivasan | 0b63acf | 2017-12-20 09:25:45 +0530 | [diff] [blame] | 156 | : "memory"); |
| 157 | } |
| 158 | |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 159 | 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] | 160 | { |
| 161 | unsigned long flags; |
| 162 | |
Madhavan Srinivasan | 9aa8818 | 2017-12-20 09:25:54 +0530 | [diff] [blame] | 163 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 164 | WARN_ON(mask && !(mask & IRQS_DISABLED)); |
| 165 | #endif |
| 166 | |
Madhavan Srinivasan | a67c543 | 2017-12-20 09:25:47 +0530 | [diff] [blame] | 167 | asm volatile( |
| 168 | "lbz %0,%1(13); stb %2,%1(13)" |
| 169 | : "=&r" (flags) |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 170 | : "i" (offsetof(struct paca_struct, irq_soft_mask)), |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 171 | "r" (mask) |
Madhavan Srinivasan | a67c543 | 2017-12-20 09:25:47 +0530 | [diff] [blame] | 172 | : "memory"); |
| 173 | |
| 174 | return flags; |
| 175 | } |
| 176 | |
Madhavan Srinivasan | c642438 | 2017-12-20 09:25:55 +0530 | [diff] [blame] | 177 | static inline notrace unsigned long irq_soft_mask_or_return(unsigned long mask) |
| 178 | { |
| 179 | unsigned long flags, tmp; |
| 180 | |
| 181 | asm volatile( |
| 182 | "lbz %0,%2(13); or %1,%0,%3; stb %1,%2(13)" |
| 183 | : "=&r" (flags), "=r" (tmp) |
| 184 | : "i" (offsetof(struct paca_struct, irq_soft_mask)), |
| 185 | "r" (mask) |
| 186 | : "memory"); |
| 187 | |
| 188 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
| 189 | WARN_ON((mask | flags) && !((mask | flags) & IRQS_DISABLED)); |
| 190 | #endif |
| 191 | |
| 192 | return flags; |
| 193 | } |
| 194 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 195 | static inline unsigned long arch_local_save_flags(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 196 | { |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 197 | return irq_soft_mask_return(); |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 198 | } |
| 199 | |
Madhavan Srinivasan | b5c1bd6 | 2017-12-20 09:25:44 +0530 | [diff] [blame] | 200 | static inline void arch_local_irq_disable(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 201 | { |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 202 | irq_soft_mask_set(IRQS_DISABLED); |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 203 | } |
| 204 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 205 | extern void arch_local_irq_restore(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 207 | static inline void arch_local_irq_enable(void) |
| 208 | { |
Madhavan Srinivasan | c2e480b | 2017-12-20 09:25:42 +0530 | [diff] [blame] | 209 | arch_local_irq_restore(IRQS_ENABLED); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 212 | static inline unsigned long arch_local_irq_save(void) |
| 213 | { |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 214 | return irq_soft_mask_set_return(IRQS_DISABLED); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
| 218 | { |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 219 | return flags & IRQS_DISABLED; |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static inline bool arch_irqs_disabled(void) |
| 223 | { |
| 224 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Athira Rajeev | 2c9ac51 | 2021-07-21 01:48:29 -0400 | [diff] [blame] | 227 | static inline void set_pmi_irq_pending(void) |
| 228 | { |
| 229 | /* |
| 230 | * Invoked from PMU callback functions to set PMI bit in the paca. |
| 231 | * This has to be called with irq's disabled (via hard_irq_disable()). |
| 232 | */ |
| 233 | if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) |
| 234 | WARN_ON_ONCE(mfmsr() & MSR_EE); |
| 235 | |
| 236 | get_paca()->irq_happened |= PACA_IRQ_PMI; |
| 237 | } |
| 238 | |
| 239 | static inline void clear_pmi_irq_pending(void) |
| 240 | { |
| 241 | /* |
| 242 | * Invoked from PMU callback functions to clear the pending PMI bit |
| 243 | * in the paca. |
| 244 | */ |
| 245 | if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) |
| 246 | WARN_ON_ONCE(mfmsr() & MSR_EE); |
| 247 | |
| 248 | get_paca()->irq_happened &= ~PACA_IRQ_PMI; |
| 249 | } |
| 250 | |
| 251 | static inline bool pmi_irq_pending(void) |
| 252 | { |
| 253 | /* |
| 254 | * Invoked from PMU callback functions to check if there is a pending |
| 255 | * PMI bit in the paca. |
| 256 | */ |
| 257 | if (get_paca()->irq_happened & PACA_IRQ_PMI) |
| 258 | return true; |
| 259 | |
| 260 | return false; |
| 261 | } |
| 262 | |
Madhavan Srinivasan | c642438 | 2017-12-20 09:25:55 +0530 | [diff] [blame] | 263 | #ifdef CONFIG_PPC_BOOK3S |
| 264 | /* |
| 265 | * To support disabling and enabling of irq with PMI, set of |
| 266 | * new powerpc_local_irq_pmu_save() and powerpc_local_irq_restore() |
| 267 | * functions are added. These macros are implemented using generic |
| 268 | * linux local_irq_* code from include/linux/irqflags.h. |
| 269 | */ |
| 270 | #define raw_local_irq_pmu_save(flags) \ |
| 271 | do { \ |
| 272 | typecheck(unsigned long, flags); \ |
| 273 | flags = irq_soft_mask_or_return(IRQS_DISABLED | \ |
| 274 | IRQS_PMI_DISABLED); \ |
| 275 | } while(0) |
| 276 | |
| 277 | #define raw_local_irq_pmu_restore(flags) \ |
| 278 | do { \ |
| 279 | typecheck(unsigned long, flags); \ |
| 280 | arch_local_irq_restore(flags); \ |
| 281 | } while(0) |
| 282 | |
| 283 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 284 | #define powerpc_local_irq_pmu_save(flags) \ |
| 285 | do { \ |
| 286 | raw_local_irq_pmu_save(flags); \ |
Nicholas Piggin | 044d0d6 | 2020-07-23 20:56:14 +1000 | [diff] [blame] | 287 | if (!raw_irqs_disabled_flags(flags)) \ |
| 288 | trace_hardirqs_off(); \ |
Madhavan Srinivasan | c642438 | 2017-12-20 09:25:55 +0530 | [diff] [blame] | 289 | } while(0) |
| 290 | #define powerpc_local_irq_pmu_restore(flags) \ |
| 291 | do { \ |
Nicholas Piggin | 044d0d6 | 2020-07-23 20:56:14 +1000 | [diff] [blame] | 292 | if (!raw_irqs_disabled_flags(flags)) \ |
Madhavan Srinivasan | c642438 | 2017-12-20 09:25:55 +0530 | [diff] [blame] | 293 | trace_hardirqs_on(); \ |
Nicholas Piggin | 044d0d6 | 2020-07-23 20:56:14 +1000 | [diff] [blame] | 294 | raw_local_irq_pmu_restore(flags); \ |
Madhavan Srinivasan | c642438 | 2017-12-20 09:25:55 +0530 | [diff] [blame] | 295 | } while(0) |
| 296 | #else |
| 297 | #define powerpc_local_irq_pmu_save(flags) \ |
| 298 | do { \ |
| 299 | raw_local_irq_pmu_save(flags); \ |
| 300 | } while(0) |
| 301 | #define powerpc_local_irq_pmu_restore(flags) \ |
| 302 | do { \ |
| 303 | raw_local_irq_pmu_restore(flags); \ |
| 304 | } while (0) |
| 305 | #endif /* CONFIG_TRACE_IRQFLAGS */ |
| 306 | |
| 307 | #endif /* CONFIG_PPC_BOOK3S */ |
| 308 | |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame] | 309 | #define hard_irq_disable() do { \ |
| 310 | unsigned long flags; \ |
| 311 | __hard_irq_disable(); \ |
| 312 | flags = irq_soft_mask_set_return(IRQS_ALL_DISABLED); \ |
| 313 | local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \ |
Michael Ellerman | 7b08729 | 2018-05-02 23:07:26 +1000 | [diff] [blame] | 314 | if (!arch_irqs_disabled_flags(flags)) { \ |
| 315 | asm ("stdx %%r1, 0, %1 ;" \ |
| 316 | : "=m" (local_paca->saved_r1) \ |
| 317 | : "b" (&local_paca->saved_r1)); \ |
Madhavan Srinivasan | f442d00 | 2017-12-20 09:25:53 +0530 | [diff] [blame] | 318 | trace_hardirqs_off(); \ |
Michael Ellerman | 7b08729 | 2018-05-02 23:07:26 +1000 | [diff] [blame] | 319 | } \ |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 320 | } while(0) |
Paul Mackerras | f948501 | 2012-06-15 14:51:39 +1000 | [diff] [blame] | 321 | |
Michael Ellerman | 0094368 | 2020-05-03 00:33:16 +1000 | [diff] [blame] | 322 | static inline bool __lazy_irq_pending(u8 irq_happened) |
| 323 | { |
| 324 | return !!(irq_happened & ~PACA_IRQ_HARD_DIS); |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * Check if a lazy IRQ is pending. Should be called with IRQs hard disabled. |
| 329 | */ |
Anton Blanchard | 0b17ba7 | 2012-06-27 13:13:52 +0000 | [diff] [blame] | 330 | static inline bool lazy_irq_pending(void) |
| 331 | { |
Michael Ellerman | 0094368 | 2020-05-03 00:33:16 +1000 | [diff] [blame] | 332 | return __lazy_irq_pending(get_paca()->irq_happened); |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * Check if a lazy IRQ is pending, with no debugging checks. |
| 337 | * Should be called with IRQs hard disabled. |
| 338 | * For use in RI disabled code or other constrained situations. |
| 339 | */ |
| 340 | static inline bool lazy_irq_pending_nocheck(void) |
| 341 | { |
| 342 | return __lazy_irq_pending(local_paca->irq_happened); |
Anton Blanchard | 0b17ba7 | 2012-06-27 13:13:52 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Nicholas Piggin | 5a7745b | 2021-09-23 00:54:49 +1000 | [diff] [blame] | 345 | bool power_pmu_wants_prompt_pmi(void); |
| 346 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 347 | /* |
Nicholas Piggin | 0faf20a | 2021-09-23 00:54:50 +1000 | [diff] [blame] | 348 | * This is called by asynchronous interrupts to check whether to |
| 349 | * conditionally re-enable hard interrupts after having cleared |
| 350 | * the source of the interrupt. They are kept disabled if there |
| 351 | * is a different soft-masked interrupt pending that requires hard |
| 352 | * masking. |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 353 | */ |
Nicholas Piggin | 0faf20a | 2021-09-23 00:54:50 +1000 | [diff] [blame] | 354 | static inline bool should_hard_irq_enable(void) |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 355 | { |
Nicholas Piggin | 0faf20a | 2021-09-23 00:54:50 +1000 | [diff] [blame] | 356 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
| 357 | WARN_ON(irq_soft_mask_return() == IRQS_ENABLED); |
| 358 | WARN_ON(mfmsr() & MSR_EE); |
| 359 | #endif |
| 360 | #ifdef CONFIG_PERF_EVENTS |
| 361 | /* |
| 362 | * If the PMU is not running, there is not much reason to enable |
| 363 | * MSR[EE] in irq handlers because any interrupts would just be |
| 364 | * soft-masked. |
| 365 | * |
| 366 | * TODO: Add test for 64e |
| 367 | */ |
| 368 | if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !power_pmu_wants_prompt_pmi()) |
| 369 | return false; |
| 370 | |
| 371 | if (get_paca()->irq_happened & PACA_IRQ_MUST_HARD_MASK) |
| 372 | return false; |
| 373 | |
| 374 | return true; |
| 375 | #else |
| 376 | return false; |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Do the hard enabling, only call this if should_hard_irq_enable is true. |
| 382 | */ |
| 383 | static inline void do_hard_irq_enable(void) |
| 384 | { |
| 385 | #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG |
| 386 | WARN_ON(irq_soft_mask_return() == IRQS_ENABLED); |
| 387 | WARN_ON(get_paca()->irq_happened & PACA_IRQ_MUST_HARD_MASK); |
| 388 | WARN_ON(mfmsr() & MSR_EE); |
| 389 | #endif |
| 390 | /* |
| 391 | * This allows PMI interrupts (and watchdog soft-NMIs) through. |
| 392 | * There is no other reason to enable this way. |
| 393 | */ |
| 394 | get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS; |
| 395 | __hard_irq_enable(); |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 396 | } |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 397 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 398 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 399 | { |
Madhavan Srinivasan | 01417c6 | 2017-12-20 09:25:49 +0530 | [diff] [blame] | 400 | return (regs->softe & IRQS_DISABLED); |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 401 | } |
| 402 | |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 403 | extern bool prep_irq_for_idle(void); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 404 | extern bool prep_irq_for_idle_irqsoff(void); |
Nicholas Piggin | 771d430 | 2017-06-13 23:05:47 +1000 | [diff] [blame] | 405 | extern void irq_set_pending_from_srr1(unsigned long srr1); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 406 | |
| 407 | #define fini_irq_for_idle_irqsoff() trace_hardirqs_off(); |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 408 | |
Benjamin Herrenschmidt | 1d607bb | 2016-07-08 16:37:07 +1000 | [diff] [blame] | 409 | extern void force_external_irq_replay(void); |
| 410 | |
Christophe Leroy | fb5608f | 2021-02-08 15:10:24 +0000 | [diff] [blame] | 411 | static inline void irq_soft_mask_regs_set_state(struct pt_regs *regs, unsigned long val) |
| 412 | { |
| 413 | regs->softe = val; |
| 414 | } |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 415 | #else /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Christophe Leroy | 6650c47 | 2021-02-08 15:10:26 +0000 | [diff] [blame] | 417 | static inline notrace unsigned long irq_soft_mask_return(void) |
| 418 | { |
| 419 | return 0; |
| 420 | } |
| 421 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 422 | static inline unsigned long arch_local_save_flags(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 424 | return mfmsr(); |
| 425 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 426 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 427 | static inline void arch_local_irq_restore(unsigned long flags) |
| 428 | { |
Christophe Leroy | b020aa9 | 2019-08-29 08:45:13 +0000 | [diff] [blame] | 429 | if (IS_ENABLED(CONFIG_BOOKE)) |
| 430 | wrtee(flags); |
| 431 | else |
| 432 | mtmsr(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 435 | static inline unsigned long arch_local_irq_save(void) |
| 436 | { |
| 437 | unsigned long flags = arch_local_save_flags(); |
Christophe Leroy | b020aa9 | 2019-08-29 08:45:13 +0000 | [diff] [blame] | 438 | |
| 439 | if (IS_ENABLED(CONFIG_BOOKE)) |
| 440 | wrtee(0); |
| 441 | else if (IS_ENABLED(CONFIG_PPC_8xx)) |
| 442 | wrtspr(SPRN_EID); |
| 443 | else |
| 444 | mtmsr(flags & ~MSR_EE); |
| 445 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 446 | return flags; |
| 447 | } |
| 448 | |
| 449 | static inline void arch_local_irq_disable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { |
Christophe Leroy | 0835377 | 2021-02-08 15:10:25 +0000 | [diff] [blame] | 451 | __hard_irq_disable(); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 452 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 453 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 454 | static inline void arch_local_irq_enable(void) |
| 455 | { |
Christophe Leroy | 0835377 | 2021-02-08 15:10:25 +0000 | [diff] [blame] | 456 | __hard_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 459 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
Steven Rostedt | e0eca07 | 2008-05-14 23:49:43 -0400 | [diff] [blame] | 460 | { |
| 461 | return (flags & MSR_EE) == 0; |
| 462 | } |
| 463 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 464 | static inline bool arch_irqs_disabled(void) |
| 465 | { |
| 466 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 467 | } |
| 468 | |
| 469 | #define hard_irq_disable() arch_local_irq_disable() |
| 470 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 471 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 472 | { |
| 473 | return !(regs->msr & MSR_EE); |
| 474 | } |
| 475 | |
Christophe Leroy | 87b9d74 | 2022-01-10 15:29:53 +0000 | [diff] [blame] | 476 | static __always_inline bool should_hard_irq_enable(void) |
Nicholas Piggin | 59dc5bf | 2021-06-18 01:51:03 +1000 | [diff] [blame] | 477 | { |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | static inline void do_hard_irq_enable(void) |
| 482 | { |
| 483 | BUILD_BUG(); |
| 484 | } |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 485 | |
Athira Rajeev | 2c9ac51 | 2021-07-21 01:48:29 -0400 | [diff] [blame] | 486 | static inline void clear_pmi_irq_pending(void) { } |
| 487 | static inline void set_pmi_irq_pending(void) { } |
| 488 | static inline bool pmi_irq_pending(void) { return false; } |
| 489 | |
Christophe Leroy | fb5608f | 2021-02-08 15:10:24 +0000 | [diff] [blame] | 490 | static inline void irq_soft_mask_regs_set_state(struct pt_regs *regs, unsigned long val) |
| 491 | { |
| 492 | } |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 493 | #endif /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Thomas Gleixner | 089fb44 | 2011-01-21 06:12:28 +0000 | [diff] [blame] | 495 | #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST |
| 496 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 497 | #endif /* __ASSEMBLY__ */ |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 498 | #endif /* __KERNEL__ */ |
| 499 | #endif /* _ASM_POWERPC_HW_IRQ_H */ |