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