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 | |
Kumar Gala | c7aeffc | 2005-09-19 09:30:27 -0500 | [diff] [blame] | 14 | extern void timer_interrupt(struct pt_regs *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 16 | #ifdef CONFIG_PPC64 |
| 17 | #include <asm/paca.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 19 | static inline unsigned long local_get_flags(void) |
| 20 | { |
Hugh Dickins | ef2b343 | 2006-11-10 21:32:40 +0000 | [diff] [blame] | 21 | unsigned long flags; |
| 22 | |
| 23 | __asm__ __volatile__("lbz %0,%1(13)" |
| 24 | : "=r" (flags) |
| 25 | : "i" (offsetof(struct paca_struct, soft_enabled))); |
| 26 | |
| 27 | return flags; |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 28 | } |
| 29 | |
Benjamin Herrenschmidt | 945feb1 | 2008-04-17 14:35:01 +1000 | [diff] [blame] | 30 | static inline unsigned long raw_local_irq_disable(void) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 31 | { |
Hugh Dickins | ef2b343 | 2006-11-10 21:32:40 +0000 | [diff] [blame] | 32 | unsigned long flags, zero; |
| 33 | |
| 34 | __asm__ __volatile__("li %1,0; lbz %0,%2(13); stb %1,%2(13)" |
| 35 | : "=r" (flags), "=&r" (zero) |
| 36 | : "i" (offsetof(struct paca_struct, soft_enabled)) |
| 37 | : "memory"); |
| 38 | |
| 39 | return flags; |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 40 | } |
| 41 | |
Benjamin Herrenschmidt | 945feb1 | 2008-04-17 14:35:01 +1000 | [diff] [blame] | 42 | extern void raw_local_irq_restore(unsigned long); |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 43 | extern void iseries_handle_interrupts(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Benjamin Herrenschmidt | 945feb1 | 2008-04-17 14:35:01 +1000 | [diff] [blame] | 45 | #define raw_local_irq_enable() raw_local_irq_restore(1) |
| 46 | #define raw_local_save_flags(flags) ((flags) = local_get_flags()) |
| 47 | #define raw_local_irq_save(flags) ((flags) = raw_local_irq_disable()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Benjamin Herrenschmidt | 945feb1 | 2008-04-17 14:35:01 +1000 | [diff] [blame] | 49 | #define raw_irqs_disabled() (local_get_flags() == 0) |
| 50 | #define raw_irqs_disabled_flags(flags) ((flags) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Benjamin Herrenschmidt | e1fa2e1 | 2007-05-10 22:22:45 -0700 | [diff] [blame] | 52 | #define __hard_irq_enable() __mtmsrd(mfmsr() | MSR_EE, 1) |
| 53 | #define __hard_irq_disable() __mtmsrd(mfmsr() & ~MSR_EE, 1) |
| 54 | |
| 55 | #define hard_irq_disable() \ |
| 56 | do { \ |
| 57 | __hard_irq_disable(); \ |
| 58 | get_paca()->soft_enabled = 0; \ |
| 59 | get_paca()->hard_enabled = 0; \ |
| 60 | } while(0) |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 61 | |
Steven Rostedt | e0eca07 | 2008-05-14 23:49:43 -0400 | [diff] [blame] | 62 | static inline int irqs_disabled_flags(unsigned long flags) |
| 63 | { |
| 64 | return flags == 0; |
| 65 | } |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #else |
| 68 | |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 69 | #if defined(CONFIG_BOOKE) |
| 70 | #define SET_MSR_EE(x) mtmsr(x) |
| 71 | #define local_irq_restore(flags) __asm__ __volatile__("wrtee %0" : : "r" (flags) : "memory") |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 72 | #else |
| 73 | #define SET_MSR_EE(x) mtmsr(x) |
| 74 | #define local_irq_restore(flags) mtmsr(flags) |
| 75 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | static inline void local_irq_disable(void) |
| 78 | { |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 79 | #ifdef CONFIG_BOOKE |
| 80 | __asm__ __volatile__("wrteei 0": : :"memory"); |
| 81 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | unsigned long msr; |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 83 | |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 84 | msr = mfmsr(); |
| 85 | SET_MSR_EE(msr & ~MSR_EE); |
| 86 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static inline void local_irq_enable(void) |
| 90 | { |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 91 | #ifdef CONFIG_BOOKE |
| 92 | __asm__ __volatile__("wrteei 1": : :"memory"); |
| 93 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | unsigned long msr; |
Paul Mackerras | 4c75f84 | 2009-06-12 02:00:50 +0000 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | msr = mfmsr(); |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 97 | SET_MSR_EE(msr | MSR_EE); |
| 98 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 101 | static inline void local_irq_save_ptr(unsigned long *flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | unsigned long msr; |
| 104 | msr = mfmsr(); |
| 105 | *flags = msr; |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 106 | #ifdef CONFIG_BOOKE |
| 107 | __asm__ __volatile__("wrteei 0": : :"memory"); |
| 108 | #else |
| 109 | SET_MSR_EE(msr & ~MSR_EE); |
| 110 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 113 | #define local_save_flags(flags) ((flags) = mfmsr()) |
| 114 | #define local_irq_save(flags) local_irq_save_ptr(&flags) |
| 115 | #define irqs_disabled() ((mfmsr() & MSR_EE) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Michael Ellerman | 143db67 | 2006-11-26 17:36:15 +1100 | [diff] [blame] | 117 | #define hard_irq_enable() local_irq_enable() |
| 118 | #define hard_irq_disable() local_irq_disable() |
| 119 | |
Steven Rostedt | e0eca07 | 2008-05-14 23:49:43 -0400 | [diff] [blame] | 120 | static inline int irqs_disabled_flags(unsigned long flags) |
| 121 | { |
| 122 | return (flags & MSR_EE) == 0; |
| 123 | } |
| 124 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 125 | #endif /* CONFIG_PPC64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Ingo Molnar | c0ad90a | 2006-06-29 02:24:44 -0700 | [diff] [blame] | 127 | /* |
| 128 | * interrupt-retrigger: should we handle this via lost interrupts and IPIs |
| 129 | * or should we not care like we do now ? --BenH. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | */ |
Thomas Gleixner | 353bca5 | 2009-03-10 14:46:30 +0000 | [diff] [blame] | 131 | struct irq_chip; |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 132 | |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 133 | #ifdef CONFIG_PERF_COUNTERS |
Paul Mackerras | 105988c | 2009-06-17 21:50:04 +1000 | [diff] [blame] | 134 | |
| 135 | #ifdef CONFIG_PPC64 |
Peter Zijlstra | 925d519 | 2009-03-30 19:07:02 +0200 | [diff] [blame] | 136 | static inline unsigned long test_perf_counter_pending(void) |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 137 | { |
| 138 | unsigned long x; |
| 139 | |
| 140 | asm volatile("lbz %0,%1(13)" |
| 141 | : "=r" (x) |
| 142 | : "i" (offsetof(struct paca_struct, perf_counter_pending))); |
| 143 | return x; |
| 144 | } |
| 145 | |
Paul Mackerras | b6c5a71d | 2009-03-16 21:00:00 +1100 | [diff] [blame] | 146 | static inline void set_perf_counter_pending(void) |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 147 | { |
| 148 | asm volatile("stb %0,%1(13)" : : |
Paul Mackerras | b6c5a71d | 2009-03-16 21:00:00 +1100 | [diff] [blame] | 149 | "r" (1), |
| 150 | "i" (offsetof(struct paca_struct, perf_counter_pending))); |
| 151 | } |
| 152 | |
| 153 | static inline void clear_perf_counter_pending(void) |
| 154 | { |
| 155 | asm volatile("stb %0,%1(13)" : : |
| 156 | "r" (0), |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 157 | "i" (offsetof(struct paca_struct, perf_counter_pending))); |
| 158 | } |
Paul Mackerras | 105988c | 2009-06-17 21:50:04 +1000 | [diff] [blame] | 159 | #endif /* CONFIG_PPC64 */ |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 160 | |
Paul Mackerras | 105988c | 2009-06-17 21:50:04 +1000 | [diff] [blame] | 161 | #else /* CONFIG_PERF_COUNTERS */ |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 162 | |
Peter Zijlstra | 925d519 | 2009-03-30 19:07:02 +0200 | [diff] [blame] | 163 | static inline unsigned long test_perf_counter_pending(void) |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 164 | { |
| 165 | return 0; |
| 166 | } |
| 167 | |
Paul Mackerras | b6c5a71d | 2009-03-16 21:00:00 +1100 | [diff] [blame] | 168 | static inline void clear_perf_counter_pending(void) {} |
Paul Mackerras | 93a6d3c | 2009-01-09 16:52:19 +1100 | [diff] [blame] | 169 | #endif /* CONFIG_PERF_COUNTERS */ |
| 170 | |
Kumar Gala | b671ad2 | 2005-09-21 16:52:55 -0500 | [diff] [blame] | 171 | #endif /* __KERNEL__ */ |
| 172 | #endif /* _ASM_POWERPC_HW_IRQ_H */ |