blob: cb06b39f8e61f89dc5b6d14147a135c29fe349f8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifdef __KERNEL__
Paul Mackerras1b923132005-10-10 22:54:57 +10002#ifndef _ASM_POWERPC_IRQ_H
3#define _ASM_POWERPC_IRQ_H
4
5/*
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Grant Likelybae1d8f2012-02-14 14:06:50 -070012#include <linux/irqdomain.h>
Paul Mackerras1b923132005-10-10 22:54:57 +100013#include <linux/threads.h>
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100014#include <linux/list.h>
15#include <linux/radix-tree.h>
Paul Mackerras1b923132005-10-10 22:54:57 +100016
17#include <asm/types.h>
Arun Sharma600634972011-07-26 16:09:06 -070018#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100020
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100021/* Define a way to iterate across irqs. */
22#define for_each_irq(i) \
23 for ((i) = 0; (i) < NR_IRQS; ++(i))
24
25extern atomic_t ppc_n_lost_interrupts;
26
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100027/* This number is used when no interrupt has been assigned */
28#define NO_IRQ (0)
29
30/* This is a special irq number to return from get_irq() to tell that
31 * no interrupt happened _and_ ignore it (don't count it as bad). Some
32 * platforms like iSeries rely on that.
33 */
34#define NO_IRQ_IGNORE ((unsigned int)-1)
35
Michael Ellerman551b81f2009-10-13 19:44:44 +000036/* Total number of virq in the platform */
37#define NR_IRQS CONFIG_NR_IRQS
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100038
39/* Number of irqs reserved for the legacy controller */
40#define NUM_ISA_INTERRUPTS 16
41
Michael Ellermancd015702009-10-13 19:45:03 +000042/* Same thing, used by the generic IRQ code */
43#define NR_IRQS_LEGACY NUM_ISA_INTERRUPTS
44
Grant Likelybae1d8f2012-02-14 14:06:50 -070045/*
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100046 * The host code and data structures are fairly agnostic to the fact that
47 * we use an open firmware device-tree. We do have references to struct
48 * device_node in two places: in irq_find_host() to find the host matching
49 * a given interrupt controller node, and of course as an argument to its
50 * counterpart host->ops->match() callback. However, those are treated as
51 * generic pointers by the core and the fact that it's actually a device-node
52 * pointer is purely a convention between callers and implementation. This
53 * code could thus be used on other architectures by replacing those two
54 * by some sort of arch-specific void * "token" used to identify interrupt
55 * controllers.
56 */
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100057
Grant Likely476eb492011-05-04 15:02:15 +100058struct irq_data;
59extern irq_hw_number_t irqd_to_hwirq(struct irq_data *d);
Olof Johansson35923f122007-06-04 14:47:04 +100060extern irq_hw_number_t virq_to_hw(unsigned int virq);
Grant Likelybae1d8f2012-02-14 14:06:50 -070061extern bool virq_is_host(unsigned int virq, struct irq_domain *host);
Benjamin Herrenschmidt0b05ac62011-04-04 13:46:58 +100062
Michael Ellerman40681b92006-08-02 11:13:50 +100063/**
Grant Likelybae1d8f2012-02-14 14:06:50 -070064 * irq_alloc_host - Allocate a new irq_domain data structure
Michael Ellerman52964f82007-08-28 18:47:54 +100065 * @of_node: optional device-tree node of the interrupt controller
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100066 * @revmap_type: type of reverse mapping to use
Grant Likelybae1d8f2012-02-14 14:06:50 -070067 * @revmap_arg: for IRQ_DOMAIN_MAP_LINEAR linear only: size of the map
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100068 * @ops: map/unmap host callbacks
69 * @inval_irq: provide a hw number in that host space that is always invalid
70 *
Grant Likelybae1d8f2012-02-14 14:06:50 -070071 * Allocates and initialize and irq_domain structure. Note that in the case of
72 * IRQ_DOMAIN_MAP_LEGACY, the map() callback will be called before this returns
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100073 * for all legacy interrupts except 0 (which is always the invalid irq for
Grant Likelybae1d8f2012-02-14 14:06:50 -070074 * a legacy controller). For a IRQ_DOMAIN_MAP_LINEAR, the map is allocated by
75 * this call as well. For a IRQ_DOMAIN_MAP_TREE, the radix tree will be allocated
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100076 * later during boot automatically (the reverse mapping will use the slow path
77 * until that happens).
78 */
Grant Likelybae1d8f2012-02-14 14:06:50 -070079extern struct irq_domain *irq_alloc_host(struct device_node *of_node,
Michael Ellerman52964f82007-08-28 18:47:54 +100080 unsigned int revmap_type,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100081 unsigned int revmap_arg,
Grant Likelybae1d8f2012-02-14 14:06:50 -070082 struct irq_domain_ops *ops,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100083 irq_hw_number_t inval_irq);
84
85
Michael Ellerman40681b92006-08-02 11:13:50 +100086/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100087 * irq_find_host - Locates a host for a given device node
88 * @node: device-tree node of the interrupt controller
89 */
Grant Likelybae1d8f2012-02-14 14:06:50 -070090extern struct irq_domain *irq_find_host(struct device_node *node);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100091
92
Michael Ellerman40681b92006-08-02 11:13:50 +100093/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100094 * irq_set_default_host - Set a "default" host
95 * @host: default host pointer
96 *
97 * For convenience, it's possible to set a "default" host that will be used
98 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
99 * platforms that want to manipulate a few hard coded interrupt numbers that
100 * aren't properly represented in the device-tree.
101 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700102extern void irq_set_default_host(struct irq_domain *host);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000103
104
Michael Ellerman40681b92006-08-02 11:13:50 +1000105/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000106 * irq_set_virq_count - Set the maximum number of virt irqs
107 * @count: number of linux virtual irqs, capped with NR_IRQS
108 *
109 * This is mainly for use by platforms like iSeries who want to program
110 * the virtual irq number in the controller to avoid the reverse mapping
111 */
112extern void irq_set_virq_count(unsigned int count);
113
114
Michael Ellerman40681b92006-08-02 11:13:50 +1000115/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000116 * irq_create_mapping - Map a hardware interrupt into linux virq space
117 * @host: host owning this hardware interrupt or NULL for default host
118 * @hwirq: hardware irq number in that host space
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000119 *
120 * Only one mapping per hardware interrupt is permitted. Returns a linux
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700121 * virq number.
122 * If the sense/trigger is to be specified, set_irq_type() should be called
123 * on the number returned from that call.
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000124 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700125extern unsigned int irq_create_mapping(struct irq_domain *host,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700126 irq_hw_number_t hwirq);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000127
128
Michael Ellerman40681b92006-08-02 11:13:50 +1000129/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000130 * irq_dispose_mapping - Unmap an interrupt
131 * @virq: linux virq number of the interrupt to unmap
132 */
133extern void irq_dispose_mapping(unsigned int virq);
134
Michael Ellerman40681b92006-08-02 11:13:50 +1000135/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000136 * irq_find_mapping - Find a linux virq from an hw irq number.
137 * @host: host owning this hardware interrupt
138 * @hwirq: hardware irq number in that host space
139 *
140 * This is a slow path, for use by generic code. It's expected that an
141 * irq controller implementation directly calls the appropriate low level
142 * mapping function.
143 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700144extern unsigned int irq_find_mapping(struct irq_domain *host,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000145 irq_hw_number_t hwirq);
146
Michael Ellermanee51de52007-06-04 23:00:00 +1000147/**
148 * irq_create_direct_mapping - Allocate a virq for direct mapping
149 * @host: host to allocate the virq for or NULL for default host
150 *
151 * This routine is used for irq controllers which can choose the hardware
152 * interrupt numbers they generate. In such a case it's simplest to use
153 * the linux virq as the hardware interrupt number.
154 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700155extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000156
Michael Ellerman40681b92006-08-02 11:13:50 +1000157/**
Sebastien Dugue967e0122008-09-04 22:37:07 +1000158 * irq_radix_revmap_insert - Insert a hw irq to linux virq number mapping.
159 * @host: host owning this hardware interrupt
160 * @virq: linux irq number
161 * @hwirq: hardware irq number in that host space
162 *
163 * This is for use by irq controllers that use a radix tree reverse
164 * mapping for fast lookup.
165 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700166extern void irq_radix_revmap_insert(struct irq_domain *host, unsigned int virq,
Sebastien Dugue967e0122008-09-04 22:37:07 +1000167 irq_hw_number_t hwirq);
168
169/**
170 * irq_radix_revmap_lookup - Find a linux virq from a hw irq number.
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000171 * @host: host owning this hardware interrupt
172 * @hwirq: hardware irq number in that host space
173 *
174 * This is a fast path, for use by irq controller code that uses radix tree
175 * revmaps
176 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700177extern unsigned int irq_radix_revmap_lookup(struct irq_domain *host,
Sebastien Dugue967e0122008-09-04 22:37:07 +1000178 irq_hw_number_t hwirq);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000179
Michael Ellerman40681b92006-08-02 11:13:50 +1000180/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000181 * irq_linear_revmap - Find a linux virq from a hw irq number.
182 * @host: host owning this hardware interrupt
183 * @hwirq: hardware irq number in that host space
184 *
185 * This is a fast path, for use by irq controller code that uses linear
186 * revmaps. It does fallback to the slow path if the revmap doesn't exist
187 * yet and will create the revmap entry with appropriate locking
188 */
189
Grant Likelybae1d8f2012-02-14 14:06:50 -0700190extern unsigned int irq_linear_revmap(struct irq_domain *host,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000191 irq_hw_number_t hwirq);
192
193
194
Michael Ellerman40681b92006-08-02 11:13:50 +1000195/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000196 * irq_alloc_virt - Allocate virtual irq numbers
197 * @host: host owning these new virtual irqs
198 * @count: number of consecutive numbers to allocate
199 * @hint: pass a hint number, the allocator will try to use a 1:1 mapping
200 *
201 * This is a low level function that is used internally by irq_create_mapping()
202 * and that can be used by some irq controllers implementations for things
203 * like allocating ranges of numbers for MSIs. The revmaps are left untouched.
204 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700205extern unsigned int irq_alloc_virt(struct irq_domain *host,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000206 unsigned int count,
207 unsigned int hint);
208
Michael Ellerman40681b92006-08-02 11:13:50 +1000209/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000210 * irq_free_virt - Free virtual irq numbers
211 * @virq: virtual irq number of the first interrupt to free
212 * @count: number of interrupts to free
213 *
214 * This function is the opposite of irq_alloc_virt. It will not clear reverse
215 * maps, this should be done previously by unmap'ing the interrupt. In fact,
216 * all interrupts covered by the range being freed should have been unmapped
217 * prior to calling this.
218 */
219extern void irq_free_virt(unsigned int virq, unsigned int count);
220
Michael Ellerman40681b92006-08-02 11:13:50 +1000221/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000222 * irq_early_init - Init irq remapping subsystem
223 */
224extern void irq_early_init(void);
225
226static __inline__ int irq_canonicalize(int irq)
227{
228 return irq;
229}
230
Paul Mackerras1b923132005-10-10 22:54:57 +1000231extern int distribute_irqs;
232
233struct irqaction;
234struct pt_regs;
235
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100236#define __ARCH_HAS_DO_SOFTIRQ
237
Kumar Galabcf0b082008-04-30 03:49:55 -0500238#if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
239/*
240 * Per-cpu stacks for handling critical, debug and machine check
241 * level interrupts.
242 */
243extern struct thread_info *critirq_ctx[NR_CPUS];
244extern struct thread_info *dbgirq_ctx[NR_CPUS];
245extern struct thread_info *mcheckirq_ctx[NR_CPUS];
246extern void exc_lvl_ctx_init(void);
247#else
248#define exc_lvl_ctx_init()
249#endif
250
Paul Mackerras1b923132005-10-10 22:54:57 +1000251/*
252 * Per-cpu stacks for handling hard and soft interrupts.
253 */
254extern struct thread_info *hardirq_ctx[NR_CPUS];
255extern struct thread_info *softirq_ctx[NR_CPUS];
256
257extern void irq_ctx_init(void);
258extern void call_do_softirq(struct thread_info *tp);
David Howells7d12e782006-10-05 14:55:46 +0100259extern int call_handle_irq(int irq, void *p1,
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000260 struct thread_info *tp, void *func);
Paul Mackerrasf2783c12005-10-20 09:23:26 +1000261extern void do_IRQ(struct pt_regs *regs);
262
Stuart Yoder6ec36b52011-05-19 08:54:26 -0500263int irq_choose_cpu(const struct cpumask *mask);
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#endif /* _ASM_IRQ_H */
266#endif /* __KERNEL__ */