blob: 3365cb97f539a7ede6d2a6e225b2ec69b579b4b6 [file] [log] [blame]
Mike Frysinger8f860012009-06-08 12:49:48 -04001/*
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 Howells5c748742010-10-07 14:08:51 +010011#include <mach/blackfin.h>
12
Mike Frysinger8f860012009-06-08 12:49:48 -040013#ifdef CONFIG_SMP
14# include <asm/pda.h>
15# include <asm/processor.h>
Mike Frysinger8f860012009-06-08 12:49:48 -040016# define bfin_irq_flags cpu_pda[blackfin_core_id()].imask
17#else
18extern unsigned long bfin_irq_flags;
19#endif
20
21static inline void bfin_sti(unsigned long flags)
22{
23 asm volatile("sti %0;" : : "d" (flags));
24}
25
26static inline unsigned long bfin_cli(void)
27{
28 unsigned long flags;
29 asm volatile("cli %0;" : "=d" (flags));
30 return flags;
31}
32
Philippe Gerum06ecc192009-06-16 05:25:37 +020033#ifdef CONFIG_DEBUG_HWERR
34# define bfin_no_irqs 0x3f
35#else
36# define bfin_no_irqs 0x1f
37#endif
38
David Howells3b139cd2010-10-07 14:08:52 +010039/*****************************************************************************/
40/*
41 * Hard, untraced CPU interrupt flag manipulation and access.
42 */
43static inline void __hard_local_irq_disable(void)
44{
45 bfin_cli();
46}
Philippe Gerum06ecc192009-06-16 05:25:37 +020047
David Howells3b139cd2010-10-07 14:08:52 +010048static inline void __hard_local_irq_enable(void)
49{
50 bfin_sti(bfin_irq_flags);
51}
Philippe Gerum06ecc192009-06-16 05:25:37 +020052
David Howells3b139cd2010-10-07 14:08:52 +010053static inline unsigned long hard_local_save_flags(void)
54{
55 return bfin_read_IMASK();
56}
Philippe Gerum06ecc192009-06-16 05:25:37 +020057
David Howells3b139cd2010-10-07 14:08:52 +010058static 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 Gerum06ecc192009-06-16 05:25:37 +020067
David Howells3b139cd2010-10-07 14:08:52 +010068static inline int hard_irqs_disabled_flags(unsigned long flags)
69{
70 return (flags & ~0x3f) == 0;
71}
Philippe Gerum06ecc192009-06-16 05:25:37 +020072
David Howells3b139cd2010-10-07 14:08:52 +010073static inline int hard_irqs_disabled(void)
74{
75 unsigned long flags = hard_local_save_flags();
76 return hard_irqs_disabled_flags(flags);
77}
Philippe Gerum06ecc192009-06-16 05:25:37 +020078
David Howells3b139cd2010-10-07 14:08:52 +010079static inline void __hard_local_irq_restore(unsigned long flags)
80{
81 if (!hard_irqs_disabled_flags(flags))
82 __hard_local_irq_enable();
83}
Philippe Gerum06ecc192009-06-16 05:25:37 +020084
David Howells3b139cd2010-10-07 14:08:52 +010085/*****************************************************************************/
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 */
98static inline void arch_local_irq_disable(void)
99{
100 ipipe_check_context(ipipe_root_domain);
101 __ipipe_stall_root();
102 barrier();
103}
104
105static inline void arch_local_irq_enable(void)
106{
107 barrier();
108 ipipe_check_context(ipipe_root_domain);
109 __ipipe_unstall_root();
110}
111
112static inline unsigned long arch_local_save_flags(void)
113{
114 return __ipipe_test_root() ? bfin_no_irqs : bfin_irq_flags;
115}
116
117static inline int arch_irqs_disabled_flags(unsigned long flags)
118{
119 return flags == bfin_no_irqs;
120}
121
122static 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
128static inline unsigned long arch_local_irq_save(void)
129{
130 ipipe_check_context(ipipe_root_domain);
131 return __hard_local_irq_save();
132}
133
134static inline unsigned long arch_mangle_irq_bits(int virt, unsigned long real)
Philippe Gerum06ecc192009-06-16 05:25:37 +0200135{
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 Howells3b139cd2010-10-07 14:08:52 +0100143static inline int arch_demangle_irq_bits(unsigned long *x)
Philippe Gerum06ecc192009-06-16 05:25:37 +0200144{
145 int virt = (*x & (1 << 31)) != 0;
146 *x &= ~(1L << 31);
147 return virt;
148}
149
David Howells3b139cd2010-10-07 14:08:52 +0100150/*
151 * Interface to various arch routines that may be traced.
152 */
Philippe Gerum06ecc192009-06-16 05:25:37 +0200153#ifdef CONFIG_IPIPE_TRACE_IRQSOFF
David Howells3b139cd2010-10-07 14:08:52 +0100154static 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
162static 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
170static 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
180static 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 Gerum06ecc192009-06-16 05:25:37 +0200188#else /* !CONFIG_IPIPE_TRACE_IRQSOFF */
David Howells3b139cd2010-10-07 14:08:52 +0100189# 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 Gerum06ecc192009-06-16 05:25:37 +0200193#endif /* !CONFIG_IPIPE_TRACE_IRQSOFF */
194
195#else /* CONFIG_IPIPE */
196
David Howells3b139cd2010-10-07 14:08:52 +0100197/*
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 Frysinger8f860012009-06-08 12:49:48 -0400207
David Howells3b139cd2010-10-07 14:08:52 +0100208/*
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 Howells5c748742010-10-07 14:08:51 +0100215
Philippe Gerum06ecc192009-06-16 05:25:37 +0200216
217#endif /* !CONFIG_IPIPE */
Mike Frysinger8f860012009-06-08 12:49:48 -0400218#endif