blob: f80f262e05970a692fc458515422750a531c7620 [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 Sharma60063492011-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 Johansson35923f12007-06-04 14:47:04 +100060extern irq_hw_number_t virq_to_hw(unsigned int virq);
Benjamin Herrenschmidt0b05ac62011-04-04 13:46:58 +100061
Michael Ellerman40681b92006-08-02 11:13:50 +100062/**
Grant Likelybae1d8f2012-02-14 14:06:50 -070063 * irq_alloc_host - Allocate a new irq_domain data structure
Michael Ellerman52964f82007-08-28 18:47:54 +100064 * @of_node: optional device-tree node of the interrupt controller
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100065 * @revmap_type: type of reverse mapping to use
Grant Likelybae1d8f2012-02-14 14:06:50 -070066 * @revmap_arg: for IRQ_DOMAIN_MAP_LINEAR linear only: size of the map
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100067 * @ops: map/unmap host callbacks
68 * @inval_irq: provide a hw number in that host space that is always invalid
69 *
Grant Likelybae1d8f2012-02-14 14:06:50 -070070 * Allocates and initialize and irq_domain structure. Note that in the case of
71 * IRQ_DOMAIN_MAP_LEGACY, the map() callback will be called before this returns
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100072 * for all legacy interrupts except 0 (which is always the invalid irq for
Grant Likelybae1d8f2012-02-14 14:06:50 -070073 * a legacy controller). For a IRQ_DOMAIN_MAP_LINEAR, the map is allocated by
74 * this call as well. For a IRQ_DOMAIN_MAP_TREE, the radix tree will be allocated
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100075 * later during boot automatically (the reverse mapping will use the slow path
76 * until that happens).
77 */
Grant Likelybae1d8f2012-02-14 14:06:50 -070078extern struct irq_domain *irq_alloc_host(struct device_node *of_node,
Michael Ellerman52964f82007-08-28 18:47:54 +100079 unsigned int revmap_type,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100080 unsigned int revmap_arg,
Grant Likelybae1d8f2012-02-14 14:06:50 -070081 struct irq_domain_ops *ops,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100082 irq_hw_number_t inval_irq);
83
84
Michael Ellerman40681b92006-08-02 11:13:50 +100085/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100086 * irq_find_host - Locates a host for a given device node
87 * @node: device-tree node of the interrupt controller
88 */
Grant Likelybae1d8f2012-02-14 14:06:50 -070089extern struct irq_domain *irq_find_host(struct device_node *node);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100090
91
Michael Ellerman40681b92006-08-02 11:13:50 +100092/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +100093 * irq_set_default_host - Set a "default" host
94 * @host: default host pointer
95 *
96 * For convenience, it's possible to set a "default" host that will be used
97 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
98 * platforms that want to manipulate a few hard coded interrupt numbers that
99 * aren't properly represented in the device-tree.
100 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700101extern void irq_set_default_host(struct irq_domain *host);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000102
103
Michael Ellerman40681b92006-08-02 11:13:50 +1000104/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000105 * irq_set_virq_count - Set the maximum number of virt irqs
106 * @count: number of linux virtual irqs, capped with NR_IRQS
107 *
108 * This is mainly for use by platforms like iSeries who want to program
109 * the virtual irq number in the controller to avoid the reverse mapping
110 */
111extern void irq_set_virq_count(unsigned int count);
112
113
Michael Ellerman40681b92006-08-02 11:13:50 +1000114/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000115 * irq_create_mapping - Map a hardware interrupt into linux virq space
116 * @host: host owning this hardware interrupt or NULL for default host
117 * @hwirq: hardware irq number in that host space
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000118 *
119 * Only one mapping per hardware interrupt is permitted. Returns a linux
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700120 * virq number.
121 * If the sense/trigger is to be specified, set_irq_type() should be called
122 * on the number returned from that call.
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000123 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700124extern unsigned int irq_create_mapping(struct irq_domain *host,
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -0700125 irq_hw_number_t hwirq);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000126
127
Michael Ellerman40681b92006-08-02 11:13:50 +1000128/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000129 * irq_dispose_mapping - Unmap an interrupt
130 * @virq: linux virq number of the interrupt to unmap
131 */
132extern void irq_dispose_mapping(unsigned int virq);
133
Michael Ellerman40681b92006-08-02 11:13:50 +1000134/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000135 * irq_find_mapping - Find a linux virq from an hw irq number.
136 * @host: host owning this hardware interrupt
137 * @hwirq: hardware irq number in that host space
138 *
139 * This is a slow path, for use by generic code. It's expected that an
140 * irq controller implementation directly calls the appropriate low level
141 * mapping function.
142 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700143extern unsigned int irq_find_mapping(struct irq_domain *host,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000144 irq_hw_number_t hwirq);
145
Michael Ellermanee51de52007-06-04 23:00:00 +1000146/**
147 * irq_create_direct_mapping - Allocate a virq for direct mapping
148 * @host: host to allocate the virq for or NULL for default host
149 *
150 * This routine is used for irq controllers which can choose the hardware
151 * interrupt numbers they generate. In such a case it's simplest to use
152 * the linux virq as the hardware interrupt number.
153 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700154extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000155
Michael Ellerman40681b92006-08-02 11:13:50 +1000156/**
Sebastien Dugue967e0122008-09-04 22:37:07 +1000157 * irq_radix_revmap_insert - Insert a hw irq to linux virq number mapping.
158 * @host: host owning this hardware interrupt
159 * @virq: linux irq number
160 * @hwirq: hardware irq number in that host space
161 *
162 * This is for use by irq controllers that use a radix tree reverse
163 * mapping for fast lookup.
164 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700165extern void irq_radix_revmap_insert(struct irq_domain *host, unsigned int virq,
Sebastien Dugue967e0122008-09-04 22:37:07 +1000166 irq_hw_number_t hwirq);
167
168/**
169 * irq_radix_revmap_lookup - Find a linux virq from a hw irq number.
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000170 * @host: host owning this hardware interrupt
171 * @hwirq: hardware irq number in that host space
172 *
173 * This is a fast path, for use by irq controller code that uses radix tree
174 * revmaps
175 */
Grant Likelybae1d8f2012-02-14 14:06:50 -0700176extern unsigned int irq_radix_revmap_lookup(struct irq_domain *host,
Sebastien Dugue967e0122008-09-04 22:37:07 +1000177 irq_hw_number_t hwirq);
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000178
Michael Ellerman40681b92006-08-02 11:13:50 +1000179/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000180 * irq_linear_revmap - Find a linux virq from a hw irq number.
181 * @host: host owning this hardware interrupt
182 * @hwirq: hardware irq number in that host space
183 *
184 * This is a fast path, for use by irq controller code that uses linear
185 * revmaps. It does fallback to the slow path if the revmap doesn't exist
186 * yet and will create the revmap entry with appropriate locking
187 */
188
Grant Likelybae1d8f2012-02-14 14:06:50 -0700189extern unsigned int irq_linear_revmap(struct irq_domain *host,
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000190 irq_hw_number_t hwirq);
191
192
Michael Ellerman40681b92006-08-02 11:13:50 +1000193/**
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000194 * irq_early_init - Init irq remapping subsystem
195 */
196extern void irq_early_init(void);
197
198static __inline__ int irq_canonicalize(int irq)
199{
200 return irq;
201}
202
Paul Mackerras1b923132005-10-10 22:54:57 +1000203extern int distribute_irqs;
204
205struct irqaction;
206struct pt_regs;
207
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100208#define __ARCH_HAS_DO_SOFTIRQ
209
Kumar Galabcf0b082008-04-30 03:49:55 -0500210#if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
211/*
212 * Per-cpu stacks for handling critical, debug and machine check
213 * level interrupts.
214 */
215extern struct thread_info *critirq_ctx[NR_CPUS];
216extern struct thread_info *dbgirq_ctx[NR_CPUS];
217extern struct thread_info *mcheckirq_ctx[NR_CPUS];
218extern void exc_lvl_ctx_init(void);
219#else
220#define exc_lvl_ctx_init()
221#endif
222
Paul Mackerras1b923132005-10-10 22:54:57 +1000223/*
224 * Per-cpu stacks for handling hard and soft interrupts.
225 */
226extern struct thread_info *hardirq_ctx[NR_CPUS];
227extern struct thread_info *softirq_ctx[NR_CPUS];
228
229extern void irq_ctx_init(void);
230extern void call_do_softirq(struct thread_info *tp);
David Howells7d12e782006-10-05 14:55:46 +0100231extern int call_handle_irq(int irq, void *p1,
Benjamin Herrenschmidtb9e5b4e2006-07-03 19:32:51 +1000232 struct thread_info *tp, void *func);
Paul Mackerrasf2783c12005-10-20 09:23:26 +1000233extern void do_IRQ(struct pt_regs *regs);
234
Stuart Yoder6ec36b52011-05-19 08:54:26 -0500235int irq_choose_cpu(const struct cpumask *mask);
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237#endif /* _ASM_IRQ_H */
238#endif /* __KERNEL__ */