f77dc5618d7e958d7153bdf673fac03c3164c213
[cascardo/linux.git] / include / linux / irqdesc.h
1 #ifndef _LINUX_IRQDESC_H
2 #define _LINUX_IRQDESC_H
3
4 /*
5  * Core internal functions to deal with irq descriptors
6  *
7  * This include will move to kernel/irq once we cleaned up the tree.
8  * For now it's included from <linux/irq.h>
9  */
10
11 struct proc_dir_entry;
12 struct timer_rand_state;
13 /**
14  * struct irq_desc - interrupt descriptor
15  * @irq_data:           per irq and chip data passed down to chip functions
16  * @timer_rand_state:   pointer to timer rand state struct
17  * @kstat_irqs:         irq stats per cpu
18  * @handle_irq:         highlevel irq-events handler [if NULL, __do_IRQ()]
19  * @action:             the irq action chain
20  * @status:             status information
21  * @depth:              disable-depth, for nested irq_disable() calls
22  * @wake_depth:         enable depth, for multiple set_irq_wake() callers
23  * @irq_count:          stats field to detect stalled irqs
24  * @last_unhandled:     aging timer for unhandled count
25  * @irqs_unhandled:     stats field for spurious unhandled interrupts
26  * @lock:               locking for SMP
27  * @pending_mask:       pending rebalanced interrupts
28  * @threads_active:     number of irqaction threads currently running
29  * @wait_for_threads:   wait queue for sync_irq to wait for threaded handlers
30  * @dir:                /proc/irq/ procfs entry
31  * @name:               flow handler name for /proc/interrupts output
32  */
33 struct irq_desc {
34
35 #ifdef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
36         struct irq_data         irq_data;
37 #else
38         /*
39          * This union will go away, once we fixed the direct access to
40          * irq_desc all over the place. The direct fields are a 1:1
41          * overlay of irq_data.
42          */
43         union {
44                 struct irq_data         irq_data;
45                 struct {
46                         unsigned int            irq;
47                         unsigned int            node;
48                         struct irq_chip         *chip;
49                         void                    *handler_data;
50                         void                    *chip_data;
51                         struct msi_desc         *msi_desc;
52 #ifdef CONFIG_SMP
53                         cpumask_var_t           affinity;
54 #endif
55                 };
56         };
57 #endif
58
59         struct timer_rand_state *timer_rand_state;
60         unsigned int            *kstat_irqs;
61         irq_flow_handler_t      handle_irq;
62         struct irqaction        *action;        /* IRQ action list */
63         unsigned int            status;         /* IRQ status */
64
65         unsigned int            depth;          /* nested irq disables */
66         unsigned int            wake_depth;     /* nested wake enables */
67         unsigned int            irq_count;      /* For detecting broken IRQs */
68         unsigned long           last_unhandled; /* Aging timer for unhandled count */
69         unsigned int            irqs_unhandled;
70         raw_spinlock_t          lock;
71 #ifdef CONFIG_SMP
72         const struct cpumask    *affinity_hint;
73 #ifdef CONFIG_GENERIC_PENDING_IRQ
74         cpumask_var_t           pending_mask;
75 #endif
76 #endif
77         atomic_t                threads_active;
78         wait_queue_head_t       wait_for_threads;
79 #ifdef CONFIG_PROC_FS
80         struct proc_dir_entry   *dir;
81 #endif
82         const char              *name;
83 } ____cacheline_internodealigned_in_smp;
84
85 extern void arch_init_copy_chip_data(struct irq_desc *old_desc,
86                                         struct irq_desc *desc, int node);
87 extern void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc);
88
89 #ifndef CONFIG_SPARSE_IRQ
90 extern struct irq_desc irq_desc[NR_IRQS];
91 #endif
92
93 #ifdef CONFIG_NUMA_IRQ_DESC
94 extern struct irq_desc *move_irq_desc(struct irq_desc *old_desc, int node);
95 #else
96 static inline struct irq_desc *move_irq_desc(struct irq_desc *desc, int node)
97 {
98         return desc;
99 }
100 #endif
101
102 extern struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node);
103
104 #ifdef CONFIG_GENERIC_HARDIRQS
105
106 #define get_irq_desc_chip(desc)         ((desc)->irq_data.chip)
107 #define get_irq_desc_chip_data(desc)    ((desc)->irq_data.chip_data)
108 #define get_irq_desc_data(desc)         ((desc)->irq_data.handler_data)
109 #define get_irq_desc_msi(desc)          ((desc)->irq_data.msi_desc)
110
111 /*
112  * Monolithic do_IRQ implementation.
113  */
114 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
115 extern unsigned int __do_IRQ(unsigned int irq);
116 #endif
117
118 /*
119  * Architectures call this to let the generic IRQ layer
120  * handle an interrupt. If the descriptor is attached to an
121  * irqchip-style controller then we call the ->handle_irq() handler,
122  * and it calls __do_IRQ() if it's attached to an irqtype-style controller.
123  */
124 static inline void generic_handle_irq_desc(unsigned int irq, struct irq_desc *desc)
125 {
126 #ifdef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
127         desc->handle_irq(irq, desc);
128 #else
129         if (likely(desc->handle_irq))
130                 desc->handle_irq(irq, desc);
131         else
132                 __do_IRQ(irq);
133 #endif
134 }
135
136 static inline void generic_handle_irq(unsigned int irq)
137 {
138         generic_handle_irq_desc(irq, irq_to_desc(irq));
139 }
140
141 /* Test to see if a driver has successfully requested an irq */
142 static inline int irq_has_action(unsigned int irq)
143 {
144         struct irq_desc *desc = irq_to_desc(irq);
145         return desc->action != NULL;
146 }
147
148 static inline int irq_balancing_disabled(unsigned int irq)
149 {
150         struct irq_desc *desc;
151
152         desc = irq_to_desc(irq);
153         return desc->status & IRQ_NO_BALANCING_MASK;
154 }
155
156 /* caller has locked the irq_desc and both params are valid */
157 static inline void __set_irq_handler_unlocked(int irq,
158                                               irq_flow_handler_t handler)
159 {
160         struct irq_desc *desc;
161
162         desc = irq_to_desc(irq);
163         desc->handle_irq = handler;
164 }
165 #endif
166
167 #endif