genirq: remove sparse irq code
[safe/jmp/linux-2.6] / include / linux / irq.h
1 #ifndef _LINUX_IRQ_H
2 #define _LINUX_IRQ_H
3
4 /*
5  * Please do not include this file in generic code.  There is currently
6  * no requirement for any architecture to implement anything held
7  * within this file.
8  *
9  * Thanks. --rmk
10  */
11
12 #include <linux/smp.h>
13
14 #ifndef CONFIG_GENERIC_HARDIRQS
15 # define nr_irqs                NR_IRQS
16
17 # define for_each_irq_desc(irq, desc)           \
18         for (irq = 0; irq < nr_irqs; irq++)
19 #else
20 extern int nr_irqs;
21
22 # define for_each_irq_desc(irq, desc)           \
23         for (irq = 0, desc = irq_desc; irq < nr_irqs; irq++, desc++)
24 #endif
25
26 #ifndef CONFIG_S390
27
28 #include <linux/linkage.h>
29 #include <linux/cache.h>
30 #include <linux/spinlock.h>
31 #include <linux/cpumask.h>
32 #include <linux/irqreturn.h>
33 #include <linux/errno.h>
34
35 #include <asm/irq.h>
36 #include <asm/ptrace.h>
37 #include <asm/irq_regs.h>
38
39 struct irq_desc;
40 typedef void (*irq_flow_handler_t)(unsigned int irq,
41                                             struct irq_desc *desc);
42
43
44 /*
45  * IRQ line status.
46  *
47  * Bits 0-7 are reserved for the IRQF_* bits in linux/interrupt.h
48  *
49  * IRQ types
50  */
51 #define IRQ_TYPE_NONE           0x00000000      /* Default, unspecified type */
52 #define IRQ_TYPE_EDGE_RISING    0x00000001      /* Edge rising type */
53 #define IRQ_TYPE_EDGE_FALLING   0x00000002      /* Edge falling type */
54 #define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)
55 #define IRQ_TYPE_LEVEL_HIGH     0x00000004      /* Level high type */
56 #define IRQ_TYPE_LEVEL_LOW      0x00000008      /* Level low type */
57 #define IRQ_TYPE_SENSE_MASK     0x0000000f      /* Mask of the above */
58 #define IRQ_TYPE_PROBE          0x00000010      /* Probing in progress */
59
60 /* Internal flags */
61 #define IRQ_INPROGRESS          0x00000100      /* IRQ handler active - do not enter! */
62 #define IRQ_DISABLED            0x00000200      /* IRQ disabled - do not enter! */
63 #define IRQ_PENDING             0x00000400      /* IRQ pending - replay on enable */
64 #define IRQ_REPLAY              0x00000800      /* IRQ has been replayed but not acked yet */
65 #define IRQ_AUTODETECT          0x00001000      /* IRQ is being autodetected */
66 #define IRQ_WAITING             0x00002000      /* IRQ not yet seen - for autodetection */
67 #define IRQ_LEVEL               0x00004000      /* IRQ level triggered */
68 #define IRQ_MASKED              0x00008000      /* IRQ masked - shouldn't be seen again */
69 #define IRQ_PER_CPU             0x00010000      /* IRQ is per CPU */
70 #define IRQ_NOPROBE             0x00020000      /* IRQ is not valid for probing */
71 #define IRQ_NOREQUEST           0x00040000      /* IRQ cannot be requested */
72 #define IRQ_NOAUTOEN            0x00080000      /* IRQ will not be enabled on request irq */
73 #define IRQ_WAKEUP              0x00100000      /* IRQ triggers system wakeup */
74 #define IRQ_MOVE_PENDING        0x00200000      /* need to re-target IRQ destination */
75 #define IRQ_NO_BALANCING        0x00400000      /* IRQ is excluded from balancing */
76 #define IRQ_SPURIOUS_DISABLED   0x00800000      /* IRQ was disabled by the spurious trap */
77 #define IRQ_MOVE_PCNTXT 0x01000000      /* IRQ migration from process context */
78
79 #ifdef CONFIG_IRQ_PER_CPU
80 # define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
81 # define IRQ_NO_BALANCING_MASK  (IRQ_PER_CPU | IRQ_NO_BALANCING)
82 #else
83 # define CHECK_IRQ_PER_CPU(var) 0
84 # define IRQ_NO_BALANCING_MASK  IRQ_NO_BALANCING
85 #endif
86
87 struct proc_dir_entry;
88 struct msi_desc;
89
90 /**
91  * struct irq_chip - hardware interrupt chip descriptor
92  *
93  * @name:               name for /proc/interrupts
94  * @startup:            start up the interrupt (defaults to ->enable if NULL)
95  * @shutdown:           shut down the interrupt (defaults to ->disable if NULL)
96  * @enable:             enable the interrupt (defaults to chip->unmask if NULL)
97  * @disable:            disable the interrupt (defaults to chip->mask if NULL)
98  * @ack:                start of a new interrupt
99  * @mask:               mask an interrupt source
100  * @mask_ack:           ack and mask an interrupt source
101  * @unmask:             unmask an interrupt source
102  * @eoi:                end of interrupt - chip level
103  * @end:                end of interrupt - flow level
104  * @set_affinity:       set the CPU affinity on SMP machines
105  * @retrigger:          resend an IRQ to the CPU
106  * @set_type:           set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
107  * @set_wake:           enable/disable power-management wake-on of an IRQ
108  *
109  * @release:            release function solely used by UML
110  * @typename:           obsoleted by name, kept as migration helper
111  */
112 struct irq_chip {
113         const char      *name;
114         unsigned int    (*startup)(unsigned int irq);
115         void            (*shutdown)(unsigned int irq);
116         void            (*enable)(unsigned int irq);
117         void            (*disable)(unsigned int irq);
118
119         void            (*ack)(unsigned int irq);
120         void            (*mask)(unsigned int irq);
121         void            (*mask_ack)(unsigned int irq);
122         void            (*unmask)(unsigned int irq);
123         void            (*eoi)(unsigned int irq);
124
125         void            (*end)(unsigned int irq);
126         void            (*set_affinity)(unsigned int irq, cpumask_t dest);
127         int             (*retrigger)(unsigned int irq);
128         int             (*set_type)(unsigned int irq, unsigned int flow_type);
129         int             (*set_wake)(unsigned int irq, unsigned int on);
130
131         /* Currently used only by UML, might disappear one day.*/
132 #ifdef CONFIG_IRQ_RELEASE_METHOD
133         void            (*release)(unsigned int irq, void *dev_id);
134 #endif
135         /*
136          * For compatibility, ->typename is copied into ->name.
137          * Will disappear.
138          */
139         const char      *typename;
140 };
141
142 struct timer_rand_state;
143 struct irq_2_iommu;
144 /**
145  * struct irq_desc - interrupt descriptor
146  *
147  * @handle_irq:         highlevel irq-events handler [if NULL, __do_IRQ()]
148  * @chip:               low level interrupt hardware access
149  * @msi_desc:           MSI descriptor
150  * @handler_data:       per-IRQ data for the irq_chip methods
151  * @chip_data:          platform-specific per-chip private data for the chip
152  *                      methods, to allow shared chip implementations
153  * @action:             the irq action chain
154  * @status:             status information
155  * @depth:              disable-depth, for nested irq_disable() calls
156  * @wake_depth:         enable depth, for multiple set_irq_wake() callers
157  * @irq_count:          stats field to detect stalled irqs
158  * @irqs_unhandled:     stats field for spurious unhandled interrupts
159  * @last_unhandled:     aging timer for unhandled count
160  * @lock:               locking for SMP
161  * @affinity:           IRQ affinity on SMP
162  * @cpu:                cpu index useful for balancing
163  * @pending_mask:       pending rebalanced interrupts
164  * @dir:                /proc/irq/ procfs entry
165  * @affinity_entry:     /proc/irq/smp_affinity procfs entry on SMP
166  * @name:               flow handler name for /proc/interrupts output
167  */
168 struct irq_desc {
169         unsigned int            irq;
170 #ifdef CONFIG_HAVE_DYN_ARRAY
171         unsigned int            *kstat_irqs;
172 #endif
173         irq_flow_handler_t      handle_irq;
174         struct irq_chip         *chip;
175         struct msi_desc         *msi_desc;
176         void                    *handler_data;
177         void                    *chip_data;
178         struct irqaction        *action;        /* IRQ action list */
179         unsigned int            status;         /* IRQ status */
180
181         unsigned int            depth;          /* nested irq disables */
182         unsigned int            wake_depth;     /* nested wake enables */
183         unsigned int            irq_count;      /* For detecting broken IRQs */
184         unsigned int            irqs_unhandled;
185         unsigned long           last_unhandled; /* Aging timer for unhandled count */
186         spinlock_t              lock;
187 #ifdef CONFIG_SMP
188         cpumask_t               affinity;
189         unsigned int            cpu;
190 #endif
191 #ifdef CONFIG_GENERIC_PENDING_IRQ
192         cpumask_t               pending_mask;
193 #endif
194 #ifdef CONFIG_PROC_FS
195         struct proc_dir_entry   *dir;
196 #endif
197         const char              *name;
198 } ____cacheline_internodealigned_in_smp;
199
200
201 #ifndef CONFIG_HAVE_DYN_ARRAY
202 /* could be removed if we get rid of all irq_desc reference */
203 extern struct irq_desc irq_desc[NR_IRQS];
204 #else
205 extern struct irq_desc *irq_desc;
206 #endif
207
208 static inline struct irq_desc *irq_to_desc(unsigned int irq)
209 {
210         return (irq < nr_irqs) ? irq_desc + irq : NULL;
211 }
212
213 static inline struct irq_desc *irq_to_desc_alloc(unsigned int irq)
214 {
215         return irq_to_desc(irq);
216 }
217
218 #ifdef CONFIG_HAVE_DYN_ARRAY
219 #define kstat_irqs_this_cpu(DESC) \
220         ((DESC)->kstat_irqs[smp_processor_id()])
221 #endif
222
223 /*
224  * Migration helpers for obsolete names, they will go away:
225  */
226 #define hw_interrupt_type       irq_chip
227 typedef struct irq_chip         hw_irq_controller;
228 #define no_irq_type             no_irq_chip
229 typedef struct irq_desc         irq_desc_t;
230
231 /*
232  * Pick up the arch-dependent methods:
233  */
234 #include <asm/hw_irq.h>
235
236 extern int setup_irq(unsigned int irq, struct irqaction *new);
237
238 #ifdef CONFIG_GENERIC_HARDIRQS
239
240 #ifdef CONFIG_SMP
241
242 #ifdef CONFIG_GENERIC_PENDING_IRQ
243
244 void set_pending_irq(unsigned int irq, cpumask_t mask);
245 void move_native_irq(int irq);
246 void move_masked_irq(int irq);
247
248 #else /* CONFIG_GENERIC_PENDING_IRQ */
249
250 static inline void move_irq(int irq)
251 {
252 }
253
254 static inline void move_native_irq(int irq)
255 {
256 }
257
258 static inline void move_masked_irq(int irq)
259 {
260 }
261
262 static inline void set_pending_irq(unsigned int irq, cpumask_t mask)
263 {
264 }
265
266 #endif /* CONFIG_GENERIC_PENDING_IRQ */
267
268 #else /* CONFIG_SMP */
269
270 #define move_native_irq(x)
271 #define move_masked_irq(x)
272
273 #endif /* CONFIG_SMP */
274
275 extern int no_irq_affinity;
276
277 static inline int irq_balancing_disabled(unsigned int irq)
278 {
279         struct irq_desc *desc;
280
281         desc = irq_to_desc(irq);
282         return desc->status & IRQ_NO_BALANCING_MASK;
283 }
284
285 /* Handle irq action chains: */
286 extern int handle_IRQ_event(unsigned int irq, struct irqaction *action);
287
288 /*
289  * Built-in IRQ handlers for various IRQ types,
290  * callable via desc->chip->handle_irq()
291  */
292 extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
293 extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
294 extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
295 extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
296 extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
297 extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
298
299 /*
300  * Monolithic do_IRQ implementation.
301  */
302 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
303 extern unsigned int __do_IRQ(unsigned int irq);
304 #endif
305
306 /*
307  * Architectures call this to let the generic IRQ layer
308  * handle an interrupt. If the descriptor is attached to an
309  * irqchip-style controller then we call the ->handle_irq() handler,
310  * and it calls __do_IRQ() if it's attached to an irqtype-style controller.
311  */
312 static inline void generic_handle_irq_desc(unsigned int irq, struct irq_desc *desc)
313 {
314 #ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
315         desc->handle_irq(irq, desc);
316 #else
317         if (likely(desc->handle_irq))
318                 desc->handle_irq(irq, desc);
319         else
320                 __do_IRQ(irq);
321 #endif
322 }
323
324 static inline void generic_handle_irq(unsigned int irq)
325 {
326         generic_handle_irq_desc(irq, irq_to_desc(irq));
327 }
328
329 /* Handling of unhandled and spurious interrupts: */
330 extern void note_interrupt(unsigned int irq, struct irq_desc *desc,
331                            int action_ret);
332
333 /* Resending of interrupts :*/
334 void check_irq_resend(struct irq_desc *desc, unsigned int irq);
335
336 /* Enable/disable irq debugging output: */
337 extern int noirqdebug_setup(char *str);
338
339 /* Checks whether the interrupt can be requested by request_irq(): */
340 extern int can_request_irq(unsigned int irq, unsigned long irqflags);
341
342 /* Dummy irq-chip implementations: */
343 extern struct irq_chip no_irq_chip;
344 extern struct irq_chip dummy_irq_chip;
345
346 extern void
347 set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
348                          irq_flow_handler_t handle);
349 extern void
350 set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
351                               irq_flow_handler_t handle, const char *name);
352
353 extern void
354 __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
355                   const char *name);
356
357 /* caller has locked the irq_desc and both params are valid */
358 static inline void __set_irq_handler_unlocked(int irq,
359                                               irq_flow_handler_t handler)
360 {
361         struct irq_desc *desc;
362
363         desc = irq_to_desc(irq);
364         desc->handle_irq = handler;
365 }
366
367 /*
368  * Set a highlevel flow handler for a given IRQ:
369  */
370 static inline void
371 set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
372 {
373         __set_irq_handler(irq, handle, 0, NULL);
374 }
375
376 /*
377  * Set a highlevel chained flow handler for a given IRQ.
378  * (a chained handler is automatically enabled and set to
379  *  IRQ_NOREQUEST and IRQ_NOPROBE)
380  */
381 static inline void
382 set_irq_chained_handler(unsigned int irq,
383                         irq_flow_handler_t handle)
384 {
385         __set_irq_handler(irq, handle, 1, NULL);
386 }
387
388 extern void set_irq_noprobe(unsigned int irq);
389 extern void set_irq_probe(unsigned int irq);
390
391 /* Handle dynamic irq creation and destruction */
392 extern unsigned int create_irq_nr(unsigned int irq_want);
393 extern int create_irq(void);
394 extern void destroy_irq(unsigned int irq);
395
396 /* Test to see if a driver has successfully requested an irq */
397 static inline int irq_has_action(unsigned int irq)
398 {
399         struct irq_desc *desc = irq_to_desc(irq);
400         return desc->action != NULL;
401 }
402
403 /* Dynamic irq helper functions */
404 extern void dynamic_irq_init(unsigned int irq);
405 extern void dynamic_irq_cleanup(unsigned int irq);
406
407 /* Set/get chip/data for an IRQ: */
408 extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
409 extern int set_irq_data(unsigned int irq, void *data);
410 extern int set_irq_chip_data(unsigned int irq, void *data);
411 extern int set_irq_type(unsigned int irq, unsigned int type);
412 extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
413
414 #define get_irq_chip(irq)       (irq_to_desc(irq)->chip)
415 #define get_irq_chip_data(irq)  (irq_to_desc(irq)->chip_data)
416 #define get_irq_data(irq)       (irq_to_desc(irq)->handler_data)
417 #define get_irq_msi(irq)        (irq_to_desc(irq)->msi_desc)
418
419 #endif /* CONFIG_GENERIC_HARDIRQS */
420
421 #endif /* !CONFIG_S390 */
422
423 #endif /* _LINUX_IRQ_H */