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 | |
| 31 | #endif /* CONFIG_PPC64 */ |
| 32 | |
| 33 | #ifndef __ASSEMBLY__ |
| 34 | |
| 35 | extern void __replay_interrupt(unsigned int vector); |
| 36 | |
Kumar Gala | c7aeffc | 2005-09-19 09:30:27 -0500 | [diff] [blame] | 37 | extern void timer_interrupt(struct pt_regs *); |
Alexander Graf | 7cc1e8e | 2012-02-22 16:26:34 +0100 | [diff] [blame] | 38 | extern void performance_monitor_exception(struct pt_regs *regs); |
Bharat Bhushan | 6328e59 | 2012-06-20 05:56:53 +0000 | [diff] [blame] | 39 | extern void WatchdogException(struct pt_regs *regs); |
| 40 | extern void unknown_exception(struct pt_regs *regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 42 | #ifdef CONFIG_PPC64 |
| 43 | #include <asm/paca.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 45 | static inline unsigned long arch_local_save_flags(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 46 | { |
Hugh Dickins | ef2b343 | 2006-11-10 21:32:40 +0000 | [diff] [blame] | 47 | unsigned long flags; |
| 48 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 49 | asm volatile( |
| 50 | "lbz %0,%1(13)" |
| 51 | : "=r" (flags) |
| 52 | : "i" (offsetof(struct paca_struct, soft_enabled))); |
Hugh Dickins | ef2b343 | 2006-11-10 21:32:40 +0000 | [diff] [blame] | 53 | |
| 54 | return flags; |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 55 | } |
| 56 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 57 | static inline unsigned long arch_local_irq_disable(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 58 | { |
Hugh Dickins | ef2b343 | 2006-11-10 21:32:40 +0000 | [diff] [blame] | 59 | unsigned long flags, zero; |
| 60 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 61 | asm volatile( |
| 62 | "li %1,0; lbz %0,%2(13); stb %1,%2(13)" |
| 63 | : "=r" (flags), "=&r" (zero) |
| 64 | : "i" (offsetof(struct paca_struct, soft_enabled)) |
| 65 | : "memory"); |
Hugh Dickins | ef2b343 | 2006-11-10 21:32:40 +0000 | [diff] [blame] | 66 | |
| 67 | return flags; |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 68 | } |
| 69 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 70 | extern void arch_local_irq_restore(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 72 | static inline void arch_local_irq_enable(void) |
| 73 | { |
| 74 | arch_local_irq_restore(1); |
| 75 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 77 | static inline unsigned long arch_local_irq_save(void) |
| 78 | { |
| 79 | return arch_local_irq_disable(); |
| 80 | } |
| 81 | |
| 82 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
| 83 | { |
| 84 | return flags == 0; |
| 85 | } |
| 86 | |
| 87 | static inline bool arch_irqs_disabled(void) |
| 88 | { |
| 89 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 92 | #ifdef CONFIG_PPC_BOOK3E |
Benjamin Herrenschmidt | 21b2de3 | 2012-07-10 18:37:56 +1000 | [diff] [blame] | 93 | #define __hard_irq_enable() asm volatile("wrteei 1" : : : "memory") |
| 94 | #define __hard_irq_disable() asm volatile("wrteei 0" : : : "memory") |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 95 | #else |
Benjamin Herrenschmidt | d9ada91 | 2012-03-02 11:33:52 +1100 | [diff] [blame] | 96 | #define __hard_irq_enable() __mtmsrd(local_paca->kernel_msr | MSR_EE, 1) |
| 97 | #define __hard_irq_disable() __mtmsrd(local_paca->kernel_msr, 1) |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 98 | #endif |
Benjamin Herrenschmidt | e1fa2e1 | 2007-05-10 22:22:45 -0700 | [diff] [blame] | 99 | |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 100 | #define hard_irq_disable() do { \ |
Tiejun Chen | 0b88f77 | 2013-07-15 10:36:04 +0800 | [diff] [blame] | 101 | u8 _was_enabled; \ |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 102 | __hard_irq_disable(); \ |
Tiejun Chen | 0b88f77 | 2013-07-15 10:36:04 +0800 | [diff] [blame] | 103 | _was_enabled = local_paca->soft_enabled; \ |
| 104 | local_paca->soft_enabled = 0; \ |
| 105 | local_paca->irq_happened |= PACA_IRQ_HARD_DIS; \ |
Scott Wood | 4a3b8d0 | 2013-05-09 22:09:41 -0500 | [diff] [blame] | 106 | if (_was_enabled) \ |
| 107 | trace_hardirqs_off(); \ |
Benjamin Herrenschmidt | 5737789 | 2013-05-06 21:04:02 +0000 | [diff] [blame] | 108 | } while(0) |
Paul Mackerras | f948501 | 2012-06-15 14:51:39 +1000 | [diff] [blame] | 109 | |
Anton Blanchard | 0b17ba7 | 2012-06-27 13:13:52 +0000 | [diff] [blame] | 110 | static inline bool lazy_irq_pending(void) |
| 111 | { |
| 112 | return !!(get_paca()->irq_happened & ~PACA_IRQ_HARD_DIS); |
| 113 | } |
| 114 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 115 | /* |
| 116 | * This is called by asynchronous interrupts to conditionally |
| 117 | * re-enable hard interrupts when soft-disabled after having |
| 118 | * cleared the source of the interrupt |
| 119 | */ |
| 120 | static inline void may_hard_irq_enable(void) |
| 121 | { |
| 122 | get_paca()->irq_happened &= ~PACA_IRQ_HARD_DIS; |
| 123 | if (!(get_paca()->irq_happened & PACA_IRQ_EE)) |
| 124 | __hard_irq_enable(); |
| 125 | } |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 126 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 127 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 128 | { |
| 129 | return !regs->softe; |
| 130 | } |
| 131 | |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 132 | extern bool prep_irq_for_idle(void); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 133 | extern bool prep_irq_for_idle_irqsoff(void); |
Nicholas Piggin | 771d430 | 2017-06-13 23:05:47 +1000 | [diff] [blame] | 134 | extern void irq_set_pending_from_srr1(unsigned long srr1); |
Nicholas Piggin | 2201f99 | 2017-06-13 23:05:45 +1000 | [diff] [blame] | 135 | |
| 136 | #define fini_irq_for_idle_irqsoff() trace_hardirqs_off(); |
Benjamin Herrenschmidt | be2cf20 | 2012-07-10 18:36:40 +1000 | [diff] [blame] | 137 | |
Benjamin Herrenschmidt | 1d607bb | 2016-07-08 16:37:07 +1000 | [diff] [blame] | 138 | extern void force_external_irq_replay(void); |
| 139 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 140 | #else /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 142 | #define SET_MSR_EE(x) mtmsr(x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 144 | static inline unsigned long arch_local_save_flags(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 146 | return mfmsr(); |
| 147 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 148 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 149 | static inline void arch_local_irq_restore(unsigned long flags) |
| 150 | { |
| 151 | #if defined(CONFIG_BOOKE) |
| 152 | asm volatile("wrtee %0" : : "r" (flags) : "memory"); |
| 153 | #else |
| 154 | mtmsr(flags); |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 155 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 158 | static inline unsigned long arch_local_irq_save(void) |
| 159 | { |
| 160 | unsigned long flags = arch_local_save_flags(); |
| 161 | #ifdef CONFIG_BOOKE |
| 162 | asm volatile("wrteei 0" : : : "memory"); |
Christophe Leroy | 834e5a6 | 2016-08-23 15:58:56 +0200 | [diff] [blame] | 163 | #elif defined(CONFIG_PPC_8xx) |
| 164 | wrtspr(SPRN_EID); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 165 | #else |
| 166 | SET_MSR_EE(flags & ~MSR_EE); |
| 167 | #endif |
| 168 | return flags; |
| 169 | } |
| 170 | |
| 171 | static inline void arch_local_irq_disable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 173 | #ifdef CONFIG_BOOKE |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 174 | asm volatile("wrteei 0" : : : "memory"); |
Christophe Leroy | 834e5a6 | 2016-08-23 15:58:56 +0200 | [diff] [blame] | 175 | #elif defined(CONFIG_PPC_8xx) |
| 176 | wrtspr(SPRN_EID); |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 177 | #else |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 178 | arch_local_irq_save(); |
| 179 | #endif |
| 180 | } |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 181 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 182 | static inline void arch_local_irq_enable(void) |
| 183 | { |
| 184 | #ifdef CONFIG_BOOKE |
| 185 | asm volatile("wrteei 1" : : : "memory"); |
Christophe Leroy | 834e5a6 | 2016-08-23 15:58:56 +0200 | [diff] [blame] | 186 | #elif defined(CONFIG_PPC_8xx) |
| 187 | wrtspr(SPRN_EIE); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 188 | #else |
| 189 | unsigned long msr = mfmsr(); |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 190 | SET_MSR_EE(msr | MSR_EE); |
| 191 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 194 | static inline bool arch_irqs_disabled_flags(unsigned long flags) |
Steven Rostedt | e0eca07 | 2008-05-14 23:49:43 -0400 | [diff] [blame] | 195 | { |
| 196 | return (flags & MSR_EE) == 0; |
| 197 | } |
| 198 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 199 | static inline bool arch_irqs_disabled(void) |
| 200 | { |
| 201 | return arch_irqs_disabled_flags(arch_local_save_flags()); |
| 202 | } |
| 203 | |
| 204 | #define hard_irq_disable() arch_local_irq_disable() |
| 205 | |
Benjamin Herrenschmidt | a546498 | 2012-03-07 16:48:45 +1100 | [diff] [blame] | 206 | static inline bool arch_irq_disabled_regs(struct pt_regs *regs) |
| 207 | { |
| 208 | return !(regs->msr & MSR_EE); |
| 209 | } |
| 210 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 211 | static inline void may_hard_irq_enable(void) { } |
| 212 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 213 | #endif /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Thomas Gleixner | 089fb44 | 2011-01-21 06:12:28 +0000 | [diff] [blame] | 215 | #define ARCH_IRQ_INIT_FLAGS IRQ_NOREQUEST |
| 216 | |
Ingo Molnar | c0ad90a | 2006-06-29 02:24:44 -0700 | [diff] [blame] | 217 | /* |
| 218 | * interrupt-retrigger: should we handle this via lost interrupts and IPIs |
| 219 | * or should we not care like we do now ? --BenH. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | */ |
Thomas Gleixner | 353bca5 | 2009-03-10 14:46:30 +0000 | [diff] [blame] | 221 | struct irq_chip; |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 222 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 223 | #endif /* __ASSEMBLY__ */ |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 224 | #endif /* __KERNEL__ */ |
| 225 | #endif /* _ASM_POWERPC_HW_IRQ_H */ |