Mike Frysinger | 8f86001 | 2009-06-08 12:49:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * interface to Blackfin CEC |
| 3 | * |
| 4 | * Copyright 2009 Analog Devices Inc. |
| 5 | * Licensed under the GPL-2 or later. |
| 6 | */ |
| 7 | |
| 8 | #ifndef __ASM_BFIN_IRQFLAGS_H__ |
| 9 | #define __ASM_BFIN_IRQFLAGS_H__ |
| 10 | |
David Howells | 5c74874 | 2010-10-07 14:08:51 +0100 | [diff] [blame] | 11 | #include <mach/blackfin.h> |
| 12 | |
Mike Frysinger | 8f86001 | 2009-06-08 12:49:48 -0400 | [diff] [blame] | 13 | #ifdef CONFIG_SMP |
| 14 | # include <asm/pda.h> |
| 15 | # include <asm/processor.h> |
| 16 | /* Forward decl needed due to cdef inter dependencies */ |
| 17 | static inline uint32_t __pure bfin_dspid(void); |
| 18 | # define blackfin_core_id() (bfin_dspid() & 0xff) |
| 19 | # define bfin_irq_flags cpu_pda[blackfin_core_id()].imask |
| 20 | #else |
| 21 | extern unsigned long bfin_irq_flags; |
| 22 | #endif |
| 23 | |
| 24 | static inline void bfin_sti(unsigned long flags) |
| 25 | { |
| 26 | asm volatile("sti %0;" : : "d" (flags)); |
| 27 | } |
| 28 | |
| 29 | static inline unsigned long bfin_cli(void) |
| 30 | { |
| 31 | unsigned long flags; |
| 32 | asm volatile("cli %0;" : "=d" (flags)); |
| 33 | return flags; |
| 34 | } |
| 35 | |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 36 | #ifdef CONFIG_DEBUG_HWERR |
| 37 | # define bfin_no_irqs 0x3f |
| 38 | #else |
| 39 | # define bfin_no_irqs 0x1f |
| 40 | #endif |
| 41 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 42 | /*****************************************************************************/ |
| 43 | /* |
| 44 | * Hard, untraced CPU interrupt flag manipulation and access. |
| 45 | */ |
| 46 | static inline void __hard_local_irq_disable(void) |
| 47 | { |
| 48 | bfin_cli(); |
| 49 | } |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 50 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 51 | static inline void __hard_local_irq_enable(void) |
| 52 | { |
| 53 | bfin_sti(bfin_irq_flags); |
| 54 | } |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 55 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 56 | static inline unsigned long hard_local_save_flags(void) |
| 57 | { |
| 58 | return bfin_read_IMASK(); |
| 59 | } |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 60 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 61 | static inline unsigned long __hard_local_irq_save(void) |
| 62 | { |
| 63 | unsigned long flags; |
| 64 | flags = bfin_cli(); |
| 65 | #ifdef CONFIG_DEBUG_HWERR |
| 66 | bfin_sti(0x3f); |
| 67 | #endif |
| 68 | return flags; |
| 69 | } |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 70 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 71 | static inline int hard_irqs_disabled_flags(unsigned long flags) |
| 72 | { |
| 73 | return (flags & ~0x3f) == 0; |
| 74 | } |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 75 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 76 | static inline int hard_irqs_disabled(void) |
| 77 | { |
| 78 | unsigned long flags = hard_local_save_flags(); |
| 79 | return hard_irqs_disabled_flags(flags); |
| 80 | } |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 81 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 82 | static inline void __hard_local_irq_restore(unsigned long flags) |
| 83 | { |
| 84 | if (!hard_irqs_disabled_flags(flags)) |
| 85 | __hard_local_irq_enable(); |
| 86 | } |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 87 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 88 | /*****************************************************************************/ |
| 89 | /* |
| 90 | * Interrupt pipe handling. |
| 91 | */ |
| 92 | #ifdef CONFIG_IPIPE |
| 93 | |
| 94 | #include <linux/compiler.h> |
| 95 | #include <linux/ipipe_base.h> |
| 96 | #include <linux/ipipe_trace.h> |
| 97 | |
| 98 | /* |
| 99 | * Interrupt pipe interface to linux/irqflags.h. |
| 100 | */ |
| 101 | static inline void arch_local_irq_disable(void) |
| 102 | { |
| 103 | ipipe_check_context(ipipe_root_domain); |
| 104 | __ipipe_stall_root(); |
| 105 | barrier(); |
| 106 | } |
| 107 | |
| 108 | static inline void arch_local_irq_enable(void) |
| 109 | { |
| 110 | barrier(); |
| 111 | ipipe_check_context(ipipe_root_domain); |
| 112 | __ipipe_unstall_root(); |
| 113 | } |
| 114 | |
| 115 | static inline unsigned long arch_local_save_flags(void) |
| 116 | { |
| 117 | return __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags; |
| 118 | } |
| 119 | |
| 120 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
| 121 | { |
| 122 | return flags == bfin_no_irqs; |
| 123 | } |
| 124 | |
| 125 | static inline void arch_local_irq_save_ptr(unsigned long *_flags) |
| 126 | { |
| 127 | x = __ipipe_test_and_stall_root() ? bfin_no_irqs : bfin_irq_flags; |
| 128 | barrier(); |
| 129 | } |
| 130 | |
| 131 | static inline unsigned long arch_local_irq_save(void) |
| 132 | { |
| 133 | ipipe_check_context(ipipe_root_domain); |
| 134 | return __hard_local_irq_save(); |
| 135 | } |
| 136 | |
| 137 | static inline unsigned long arch_mangle_irq_bits(int virt, unsigned long real) |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 138 | { |
| 139 | /* |
| 140 | * Merge virtual and real interrupt mask bits into a single |
| 141 | * 32bit word. |
| 142 | */ |
| 143 | return (real & ~(1 << 31)) | ((virt != 0) << 31); |
| 144 | } |
| 145 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 146 | static inline int arch_demangle_irq_bits(unsigned long *x) |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 147 | { |
| 148 | int virt = (*x & (1 << 31)) != 0; |
| 149 | *x &= ~(1L << 31); |
| 150 | return virt; |
| 151 | } |
| 152 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 153 | /* |
| 154 | * Interface to various arch routines that may be traced. |
| 155 | */ |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 156 | #ifdef CONFIG_IPIPE_TRACE_IRQSOFF |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 157 | static inline void hard_local_irq_disable(void) |
| 158 | { |
| 159 | if (!hard_irqs_disabled()) { |
| 160 | __hard_local_irq_disable(); |
| 161 | ipipe_trace_begin(0x80000000); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | static inline void hard_local_irq_enable(void) |
| 166 | { |
| 167 | if (hard_irqs_disabled()) { |
| 168 | ipipe_trace_end(0x80000000); |
| 169 | __hard_local_irq_enable(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | static inline unsigned long hard_local_irq_save(void) |
| 174 | { |
| 175 | unsigned long flags = hard_local_save_flags(); |
| 176 | if (!hard_irqs_disabled_flags(flags)) { |
| 177 | __hard_local_irq_disable(); |
| 178 | ipipe_trace_begin(0x80000001); |
| 179 | } |
| 180 | return flags; |
| 181 | } |
| 182 | |
| 183 | static inline void hard_local_irq_restore(unsigned long flags) |
| 184 | { |
| 185 | if (!hard_irqs_disabled_flags(flags)) { |
| 186 | ipipe_trace_end(0x80000001); |
| 187 | __hard_local_irq_enable(); |
| 188 | } |
| 189 | } |
| 190 | |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 191 | #else /* !CONFIG_IPIPE_TRACE_IRQSOFF */ |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 192 | # define hard_local_irq_disable() __hard_local_irq_disable() |
| 193 | # define hard_local_irq_enable() __hard_local_irq_enable() |
| 194 | # define hard_local_irq_save() __hard_local_irq_save() |
| 195 | # define hard_local_irq_restore(flags) __hard_local_irq_restore(flags) |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 196 | #endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */ |
| 197 | |
| 198 | #else /* CONFIG_IPIPE */ |
| 199 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 200 | /* |
| 201 | * Direct interface to linux/irqflags.h. |
| 202 | */ |
| 203 | #define arch_local_save_flags() hard_local_save_flags() |
| 204 | #define arch_local_irq_save(flags) __hard_local_irq_save() |
| 205 | #define arch_local_irq_restore(flags) __hard_local_irq_restore(flags) |
| 206 | #define arch_local_irq_enable() __hard_local_irq_enable() |
| 207 | #define arch_local_irq_disable() __hard_local_irq_disable() |
| 208 | #define arch_irqs_disabled_flags(flags) hard_irqs_disabled_flags(flags) |
| 209 | #define arch_irqs_disabled() hard_irqs_disabled() |
Mike Frysinger | 8f86001 | 2009-06-08 12:49:48 -0400 | [diff] [blame] | 210 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 211 | /* |
| 212 | * Interface to various arch routines that may be traced. |
| 213 | */ |
| 214 | #define hard_local_irq_save() __hard_local_irq_save() |
| 215 | #define hard_local_irq_restore(flags) __hard_local_irq_restore(flags) |
| 216 | #define hard_local_irq_enable() __hard_local_irq_enable() |
| 217 | #define hard_local_irq_disable() __hard_local_irq_disable() |
David Howells | 5c74874 | 2010-10-07 14:08:51 +0100 | [diff] [blame] | 218 | |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 219 | |
| 220 | #endif /* !CONFIG_IPIPE */ |
| 221 | |
David Howells | 3b139cd | 2010-10-07 14:08:52 +0100 | [diff] [blame^] | 222 | /* |
| 223 | * Raw interface to linux/irqflags.h. |
| 224 | */ |
| 225 | #define raw_local_save_flags(flags) do { (flags) = arch_local_save_flags(); } while (0) |
| 226 | #define raw_local_irq_save(flags) do { (flags) = arch_local_irq_save(); } while (0) |
| 227 | #define raw_local_irq_restore(flags) arch_local_irq_restore(flags) |
| 228 | #define raw_local_irq_enable() arch_local_irq_enable() |
| 229 | #define raw_local_irq_disable() arch_local_irq_disable() |
| 230 | #define raw_irqs_disabled_flags(flags) arch_irqs_disabled_flags(flags) |
| 231 | #define raw_irqs_disabled() arch_irqs_disabled() |
Philippe Gerum | 06ecc19 | 2009-06-16 05:25:37 +0200 | [diff] [blame] | 232 | |
Mike Frysinger | 8f86001 | 2009-06-08 12:49:48 -0400 | [diff] [blame] | 233 | #endif |