blob: 8eb01e379ccc745de14f12855b755cf575dc21ba [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IRQ subsystem internal functions and variables:
3 */
Thomas Gleixnere1447102010-10-01 16:03:45 +02004#include <linux/irqdesc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6extern int noirqdebug;
7
Thomas Gleixnera77c4632010-10-01 14:44:58 +02008#define irq_data_to_desc(data) container_of(data, struct irq_desc, irq_data)
9
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070010/* Set default functions for irq_chip structures: */
11extern void irq_chip_set_defaults(struct irq_chip *chip);
12
13/* Set default handler: */
14extern void compat_irq_chip_set_default_handler(struct irq_desc *desc);
15
David Brownell0c5d1eb2008-10-01 14:46:18 -070016extern int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
17 unsigned long flags);
Rafael J. Wysocki0a0c5162009-03-16 22:33:49 +010018extern void __disable_irq(struct irq_desc *desc, unsigned int irq, bool susp);
19extern void __enable_irq(struct irq_desc *desc, unsigned int irq, bool resume);
David Brownell0c5d1eb2008-10-01 14:46:18 -070020
Yinghai Lu48a1b102008-12-11 00:15:01 -080021extern struct lock_class_key irq_desc_lock_class;
Yinghai Lu85ac16d2009-04-27 18:00:38 -070022extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr);
Yinghai Lu0f3c2a82009-02-08 16:18:03 -080023extern void clear_kstat_irqs(struct irq_desc *desc);
Thomas Gleixner239007b2009-11-17 16:46:45 +010024extern raw_spinlock_t sparse_irq_lock;
Mike Travis0fa0ebb2009-01-10 22:24:06 -080025
Thomas Gleixnere1447102010-10-01 16:03:45 +020026/* Resending of interrupts :*/
27void check_irq_resend(struct irq_desc *desc, unsigned int irq);
28
Mike Travis0fa0ebb2009-01-10 22:24:06 -080029#ifdef CONFIG_SPARSE_IRQ
Yinghai Lu99558f02010-02-10 01:20:34 -080030void replace_irq_desc(unsigned int irq, struct irq_desc *desc);
Mike Travis0fa0ebb2009-01-10 22:24:06 -080031#endif
Yinghai Lu48a1b102008-12-11 00:15:01 -080032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#ifdef CONFIG_PROC_FS
Yinghai Lu2c6927a2008-08-19 20:50:11 -070034extern void register_irq_proc(unsigned int irq, struct irq_desc *desc);
Thomas Gleixner13bfe992010-09-30 02:46:07 +020035extern void unregister_irq_proc(unsigned int irq, struct irq_desc *desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036extern void register_handler_proc(unsigned int irq, struct irqaction *action);
37extern void unregister_handler_proc(unsigned int irq, struct irqaction *action);
38#else
Yinghai Lu2c6927a2008-08-19 20:50:11 -070039static inline void register_irq_proc(unsigned int irq, struct irq_desc *desc) { }
Thomas Gleixner13bfe992010-09-30 02:46:07 +020040static inline void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static inline void register_handler_proc(unsigned int irq,
42 struct irqaction *action) { }
43static inline void unregister_handler_proc(unsigned int irq,
44 struct irqaction *action) { }
45#endif
46
Thomas Gleixnerf6d87f42008-11-07 13:18:30 +010047extern int irq_select_affinity_usr(unsigned int irq);
48
Thomas Gleixner591d2fb2009-07-21 11:09:39 +020049extern void irq_set_thread_affinity(struct irq_desc *desc);
Yinghai Lu57b150c2009-04-27 17:59:53 -070050
Thomas Gleixnerbd151412010-10-01 15:17:14 +020051#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
52static inline void irq_end(unsigned int irq, struct irq_desc *desc)
53{
54 if (desc->irq_data.chip && desc->irq_data.chip->end)
55 desc->irq_data.chip->end(irq);
56}
57#else
58static inline void irq_end(unsigned int irq, struct irq_desc *desc) { }
59#endif
60
Thomas Gleixner70aedd22009-08-13 12:17:48 +020061/* Inline functions for support of irq chips on slow busses */
Thomas Gleixner3876ec92010-09-27 12:44:35 +000062static inline void chip_bus_lock(struct irq_desc *desc)
Thomas Gleixner70aedd22009-08-13 12:17:48 +020063{
Thomas Gleixner3876ec92010-09-27 12:44:35 +000064 if (unlikely(desc->irq_data.chip->irq_bus_lock))
65 desc->irq_data.chip->irq_bus_lock(&desc->irq_data);
Thomas Gleixner70aedd22009-08-13 12:17:48 +020066}
67
Thomas Gleixner3876ec92010-09-27 12:44:35 +000068static inline void chip_bus_sync_unlock(struct irq_desc *desc)
Thomas Gleixner70aedd22009-08-13 12:17:48 +020069{
Thomas Gleixner3876ec92010-09-27 12:44:35 +000070 if (unlikely(desc->irq_data.chip->irq_bus_sync_unlock))
71 desc->irq_data.chip->irq_bus_sync_unlock(&desc->irq_data);
Thomas Gleixner70aedd22009-08-13 12:17:48 +020072}
73
Ingo Molnar43f77752006-06-29 02:24:58 -070074/*
75 * Debugging printout:
76 */
77
78#include <linux/kallsyms.h>
79
80#define P(f) if (desc->status & f) printk("%14s set\n", #f)
81
82static inline void print_irq_desc(unsigned int irq, struct irq_desc *desc)
83{
84 printk("irq %d, desc: %p, depth: %d, count: %d, unhandled: %d\n",
85 irq, desc, desc->depth, desc->irq_count, desc->irqs_unhandled);
86 printk("->handle_irq(): %p, ", desc->handle_irq);
87 print_symbol("%s\n", (unsigned long)desc->handle_irq);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020088 printk("->irq_data.chip(): %p, ", desc->irq_data.chip);
89 print_symbol("%s\n", (unsigned long)desc->irq_data.chip);
Ingo Molnar43f77752006-06-29 02:24:58 -070090 printk("->action(): %p\n", desc->action);
91 if (desc->action) {
92 printk("->action->handler(): %p, ", desc->action->handler);
93 print_symbol("%s\n", (unsigned long)desc->action->handler);
94 }
95
96 P(IRQ_INPROGRESS);
97 P(IRQ_DISABLED);
98 P(IRQ_PENDING);
99 P(IRQ_REPLAY);
100 P(IRQ_AUTODETECT);
101 P(IRQ_WAITING);
102 P(IRQ_LEVEL);
103 P(IRQ_MASKED);
104#ifdef CONFIG_IRQ_PER_CPU
105 P(IRQ_PER_CPU);
106#endif
107 P(IRQ_NOPROBE);
108 P(IRQ_NOREQUEST);
109 P(IRQ_NOAUTOEN);
110}
111
112#undef P
113
Thomas Gleixnere1447102010-10-01 16:03:45 +0200114/* Stuff below will be cleaned up after the sparse allocator is done */
115
116#ifdef CONFIG_SMP
117/**
118 * alloc_desc_masks - allocate cpumasks for irq_desc
119 * @desc: pointer to irq_desc struct
120 * @node: node which will be handling the cpumasks
121 * @boot: true if need bootmem
122 *
123 * Allocates affinity and pending_mask cpumask if required.
124 * Returns true if successful (or not required).
125 */
126static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
127 bool boot)
128{
129 gfp_t gfp = GFP_ATOMIC;
130
131 if (boot)
132 gfp = GFP_NOWAIT;
133
134#ifdef CONFIG_CPUMASK_OFFSTACK
135 if (!alloc_cpumask_var_node(&desc->irq_data.affinity, gfp, node))
136 return false;
137
138#ifdef CONFIG_GENERIC_PENDING_IRQ
139 if (!alloc_cpumask_var_node(&desc->pending_mask, gfp, node)) {
140 free_cpumask_var(desc->irq_data.affinity);
141 return false;
142 }
143#endif
144#endif
145 return true;
146}
147
148static inline void init_desc_masks(struct irq_desc *desc)
149{
150 cpumask_setall(desc->irq_data.affinity);
151#ifdef CONFIG_GENERIC_PENDING_IRQ
152 cpumask_clear(desc->pending_mask);
153#endif
154}
155
156/**
157 * init_copy_desc_masks - copy cpumasks for irq_desc
158 * @old_desc: pointer to old irq_desc struct
159 * @new_desc: pointer to new irq_desc struct
160 *
161 * Insures affinity and pending_masks are copied to new irq_desc.
162 * If !CONFIG_CPUMASKS_OFFSTACK the cpumasks are embedded in the
163 * irq_desc struct so the copy is redundant.
164 */
165
166static inline void init_copy_desc_masks(struct irq_desc *old_desc,
167 struct irq_desc *new_desc)
168{
169#ifdef CONFIG_CPUMASK_OFFSTACK
170 cpumask_copy(new_desc->irq_data.affinity, old_desc->irq_data.affinity);
171
172#ifdef CONFIG_GENERIC_PENDING_IRQ
173 cpumask_copy(new_desc->pending_mask, old_desc->pending_mask);
174#endif
175#endif
176}
177
178static inline void free_desc_masks(struct irq_desc *old_desc,
179 struct irq_desc *new_desc)
180{
181 free_cpumask_var(old_desc->irq_data.affinity);
182
183#ifdef CONFIG_GENERIC_PENDING_IRQ
184 free_cpumask_var(old_desc->pending_mask);
185#endif
186}
187
188#else /* !CONFIG_SMP */
189
190static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
191 bool boot)
192{
193 return true;
194}
195
196static inline void init_desc_masks(struct irq_desc *desc)
197{
198}
199
200static inline void init_copy_desc_masks(struct irq_desc *old_desc,
201 struct irq_desc *new_desc)
202{
203}
204
205static inline void free_desc_masks(struct irq_desc *old_desc,
206 struct irq_desc *new_desc)
207{
208}
209#endif /* CONFIG_SMP */