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