blob: 489921e6242a982ea7543a2e63f441c1e3450b40 [file] [log] [blame]
Paul Mundt54a90582012-05-19 15:11:47 +09001#define pr_fmt(fmt) "irq: " fmt
2
Grant Likelycc79ca62012-02-16 01:37:49 -07003#include <linux/debugfs.h>
4#include <linux/hardirq.h>
5#include <linux/interrupt.h>
Grant Likely08a543a2011-07-26 03:19:06 -06006#include <linux/irq.h>
Grant Likelycc79ca62012-02-16 01:37:49 -07007#include <linux/irqdesc.h>
Grant Likely08a543a2011-07-26 03:19:06 -06008#include <linux/irqdomain.h>
9#include <linux/module.h>
10#include <linux/mutex.h>
11#include <linux/of.h>
Grant Likely7e713302011-07-26 03:19:06 -060012#include <linux/of_address.h>
Paul Mundt5ca4db62012-06-03 22:04:34 -070013#include <linux/topology.h>
Grant Likelycc79ca62012-02-16 01:37:49 -070014#include <linux/seq_file.h>
Grant Likely7e713302011-07-26 03:19:06 -060015#include <linux/slab.h>
Grant Likelycc79ca62012-02-16 01:37:49 -070016#include <linux/smp.h>
17#include <linux/fs.h>
Grant Likely08a543a2011-07-26 03:19:06 -060018
19static LIST_HEAD(irq_domain_list);
20static DEFINE_MUTEX(irq_domain_mutex);
21
Grant Likelycc79ca62012-02-16 01:37:49 -070022static DEFINE_MUTEX(revmap_trees_mutex);
Grant Likely68700652012-02-14 14:06:53 -070023static struct irq_domain *irq_default_domain;
Grant Likelycc79ca62012-02-16 01:37:49 -070024
Grant Likelycc79ca62012-02-16 01:37:49 -070025/**
Grant Likelya8db8cf2012-02-14 14:06:54 -070026 * irq_domain_alloc() - Allocate a new irq_domain data structure
Grant Likelycc79ca62012-02-16 01:37:49 -070027 * @of_node: optional device-tree node of the interrupt controller
28 * @revmap_type: type of reverse mapping to use
Grant Likely68700652012-02-14 14:06:53 -070029 * @ops: map/unmap domain callbacks
Grant Likelya8db8cf2012-02-14 14:06:54 -070030 * @host_data: Controller private data pointer
Grant Likelycc79ca62012-02-16 01:37:49 -070031 *
Grant Likelya8db8cf2012-02-14 14:06:54 -070032 * Allocates and initialize and irq_domain structure. Caller is expected to
33 * register allocated irq_domain with irq_domain_register(). Returns pointer
34 * to IRQ domain, or NULL on failure.
Grant Likelycc79ca62012-02-16 01:37:49 -070035 */
Grant Likelya8db8cf2012-02-14 14:06:54 -070036static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
37 unsigned int revmap_type,
Grant Likelya18dc812012-01-26 12:12:14 -070038 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -070039 void *host_data)
Grant Likelycc79ca62012-02-16 01:37:49 -070040{
Grant Likelya8db8cf2012-02-14 14:06:54 -070041 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -070042
Paul Mundt5ca4db62012-06-03 22:04:34 -070043 domain = kzalloc_node(sizeof(*domain), GFP_KERNEL,
44 of_node_to_nid(of_node));
Grant Likelya8db8cf2012-02-14 14:06:54 -070045 if (WARN_ON(!domain))
Grant Likelycc79ca62012-02-16 01:37:49 -070046 return NULL;
47
48 /* Fill structure */
Grant Likely68700652012-02-14 14:06:53 -070049 domain->revmap_type = revmap_type;
Grant Likely68700652012-02-14 14:06:53 -070050 domain->ops = ops;
Grant Likelya8db8cf2012-02-14 14:06:54 -070051 domain->host_data = host_data;
Grant Likely68700652012-02-14 14:06:53 -070052 domain->of_node = of_node_get(of_node);
Grant Likelycc79ca62012-02-16 01:37:49 -070053
Grant Likelya8db8cf2012-02-14 14:06:54 -070054 return domain;
55}
56
Paul Mundt58ee99a2012-05-19 15:11:41 +090057static void irq_domain_free(struct irq_domain *domain)
58{
59 of_node_put(domain->of_node);
60 kfree(domain);
61}
62
Grant Likelya8db8cf2012-02-14 14:06:54 -070063static void irq_domain_add(struct irq_domain *domain)
64{
65 mutex_lock(&irq_domain_mutex);
66 list_add(&domain->link, &irq_domain_list);
67 mutex_unlock(&irq_domain_mutex);
Paul Mundt54a90582012-05-19 15:11:47 +090068 pr_debug("Allocated domain of type %d @0x%p\n",
Grant Likelya8db8cf2012-02-14 14:06:54 -070069 domain->revmap_type, domain);
70}
71
Paul Mundt58ee99a2012-05-19 15:11:41 +090072/**
73 * irq_domain_remove() - Remove an irq domain.
74 * @domain: domain to remove
75 *
76 * This routine is used to remove an irq domain. The caller must ensure
77 * that all mappings within the domain have been disposed of prior to
78 * use, depending on the revmap type.
79 */
80void irq_domain_remove(struct irq_domain *domain)
81{
82 mutex_lock(&irq_domain_mutex);
83
84 switch (domain->revmap_type) {
85 case IRQ_DOMAIN_MAP_LEGACY:
86 /*
87 * Legacy domains don't manage their own irq_desc
88 * allocations, we expect the caller to handle irq_desc
89 * freeing on their own.
90 */
91 break;
92 case IRQ_DOMAIN_MAP_TREE:
93 /*
94 * radix_tree_delete() takes care of destroying the root
95 * node when all entries are removed. Shout if there are
96 * any mappings left.
97 */
98 WARN_ON(domain->revmap_data.tree.height);
99 break;
100 case IRQ_DOMAIN_MAP_LINEAR:
101 kfree(domain->revmap_data.linear.revmap);
102 domain->revmap_data.linear.size = 0;
103 break;
104 case IRQ_DOMAIN_MAP_NOMAP:
105 break;
106 }
107
108 list_del(&domain->link);
109
110 /*
111 * If the going away domain is the default one, reset it.
112 */
113 if (unlikely(irq_default_domain == domain))
114 irq_set_default_host(NULL);
115
116 mutex_unlock(&irq_domain_mutex);
117
Paul Mundt54a90582012-05-19 15:11:47 +0900118 pr_debug("Removed domain of type %d @0x%p\n",
Paul Mundt58ee99a2012-05-19 15:11:41 +0900119 domain->revmap_type, domain);
120
121 irq_domain_free(domain);
122}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900123EXPORT_SYMBOL_GPL(irq_domain_remove);
Paul Mundt58ee99a2012-05-19 15:11:41 +0900124
Grant Likely1bc04f22012-02-14 14:06:55 -0700125static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
126 irq_hw_number_t hwirq)
127{
128 irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq;
129 int size = domain->revmap_data.legacy.size;
130
131 if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
132 return 0;
133 return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq;
134}
135
Grant Likelya8db8cf2012-02-14 14:06:54 -0700136/**
Mark Brown781d0f42012-07-05 12:19:19 +0100137 * irq_domain_add_simple() - Allocate and register a simple irq_domain.
138 * @of_node: pointer to interrupt controller's device tree node.
139 * @size: total number of irqs in mapping
140 * @first_irq: first number of irq block assigned to the domain
141 * @ops: map/unmap domain callbacks
142 * @host_data: Controller private data pointer
143 *
144 * Allocates a legacy irq_domain if irq_base is positive or a linear
Linus Walleij2854d162012-09-27 14:59:39 +0200145 * domain otherwise. For the legacy domain, IRQ descriptors will also
146 * be allocated.
Mark Brown781d0f42012-07-05 12:19:19 +0100147 *
148 * This is intended to implement the expected behaviour for most
149 * interrupt controllers which is that a linear mapping should
150 * normally be used unless the system requires a legacy mapping in
151 * order to support supplying interrupt numbers during non-DT
152 * registration of devices.
153 */
154struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
155 unsigned int size,
156 unsigned int first_irq,
157 const struct irq_domain_ops *ops,
158 void *host_data)
159{
Linus Walleij2854d162012-09-27 14:59:39 +0200160 if (first_irq > 0) {
161 int irq_base;
162
163 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
164 /*
165 * Set the descriptor allocator to search for a
166 * 1-to-1 mapping, such as irq_alloc_desc_at().
167 * Use of_node_to_nid() which is defined to
168 * numa_node_id() on platforms that have no custom
169 * implementation.
170 */
171 irq_base = irq_alloc_descs(first_irq, first_irq, size,
172 of_node_to_nid(of_node));
173 if (irq_base < 0) {
Linus Walleijd202b7b2012-11-27 01:20:32 +0100174 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
175 first_irq);
Linus Walleij2854d162012-09-27 14:59:39 +0200176 irq_base = first_irq;
177 }
178 } else
179 irq_base = first_irq;
180
181 return irq_domain_add_legacy(of_node, size, irq_base, 0,
Mark Brown781d0f42012-07-05 12:19:19 +0100182 ops, host_data);
Linus Walleij2854d162012-09-27 14:59:39 +0200183 }
184
185 /* A linear domain is the default */
186 return irq_domain_add_linear(of_node, size, ops, host_data);
Mark Brown781d0f42012-07-05 12:19:19 +0100187}
188
189/**
Grant Likelya8db8cf2012-02-14 14:06:54 -0700190 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
191 * @of_node: pointer to interrupt controller's device tree node.
Grant Likely1bc04f22012-02-14 14:06:55 -0700192 * @size: total number of irqs in legacy mapping
193 * @first_irq: first number of irq block assigned to the domain
194 * @first_hwirq: first hwirq number to use for the translation. Should normally
195 * be '0', but a positive integer can be used if the effective
196 * hwirqs numbering does not begin at zero.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700197 * @ops: map/unmap domain callbacks
198 * @host_data: Controller private data pointer
199 *
200 * Note: the map() callback will be called before this function returns
201 * for all legacy interrupts except 0 (which is always the invalid irq for
202 * a legacy controller).
203 */
204struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
Grant Likely1bc04f22012-02-14 14:06:55 -0700205 unsigned int size,
206 unsigned int first_irq,
207 irq_hw_number_t first_hwirq,
Grant Likelya18dc812012-01-26 12:12:14 -0700208 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700209 void *host_data)
210{
Grant Likely1bc04f22012-02-14 14:06:55 -0700211 struct irq_domain *domain;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700212 unsigned int i;
213
214 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
215 if (!domain)
216 return NULL;
217
Grant Likely1bc04f22012-02-14 14:06:55 -0700218 domain->revmap_data.legacy.first_irq = first_irq;
219 domain->revmap_data.legacy.first_hwirq = first_hwirq;
220 domain->revmap_data.legacy.size = size;
221
Grant Likelycc79ca62012-02-16 01:37:49 -0700222 mutex_lock(&irq_domain_mutex);
Grant Likely1bc04f22012-02-14 14:06:55 -0700223 /* Verify that all the irqs are available */
224 for (i = 0; i < size; i++) {
225 int irq = first_irq + i;
226 struct irq_data *irq_data = irq_get_irq_data(irq);
227
228 if (WARN_ON(!irq_data || irq_data->domain)) {
Grant Likelya8db8cf2012-02-14 14:06:54 -0700229 mutex_unlock(&irq_domain_mutex);
Paul Mundt58ee99a2012-05-19 15:11:41 +0900230 irq_domain_free(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700231 return NULL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700232 }
233 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700234
235 /* Claim all of the irqs before registering a legacy domain */
236 for (i = 0; i < size; i++) {
237 struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
238 irq_data->hwirq = first_hwirq + i;
239 irq_data->domain = domain;
240 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700241 mutex_unlock(&irq_domain_mutex);
242
Grant Likely1bc04f22012-02-14 14:06:55 -0700243 for (i = 0; i < size; i++) {
244 int irq = first_irq + i;
245 int hwirq = first_hwirq + i;
246
247 /* IRQ0 gets ignored */
248 if (!irq)
249 continue;
Grant Likelycc79ca62012-02-16 01:37:49 -0700250
Grant Likelya8db8cf2012-02-14 14:06:54 -0700251 /* Legacy flags are left to default at this point,
252 * one can then use irq_create_mapping() to
253 * explicitly change them
254 */
Grant Likelyaed98042012-06-03 22:04:39 -0700255 if (ops->map)
256 ops->map(domain, irq, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700257
Grant Likelya8db8cf2012-02-14 14:06:54 -0700258 /* Clear norequest flags */
Grant Likely1bc04f22012-02-14 14:06:55 -0700259 irq_clear_status_flags(irq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700260 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700261
262 irq_domain_add(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700263 return domain;
264}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900265EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
Grant Likelycc79ca62012-02-16 01:37:49 -0700266
Grant Likelya8db8cf2012-02-14 14:06:54 -0700267/**
Dong Aisheng22076c72012-06-20 17:00:30 +0800268 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700269 * @of_node: pointer to interrupt controller's device tree node.
Mark Browna87487e2012-05-19 12:15:35 +0100270 * @size: Number of interrupts in the domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700271 * @ops: map/unmap domain callbacks
272 * @host_data: Controller private data pointer
273 */
274struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
275 unsigned int size,
Grant Likelya18dc812012-01-26 12:12:14 -0700276 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700277 void *host_data)
278{
279 struct irq_domain *domain;
280 unsigned int *revmap;
Grant Likelycc79ca62012-02-16 01:37:49 -0700281
Paul Mundt5ca4db62012-06-03 22:04:34 -0700282 revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
283 of_node_to_nid(of_node));
Grant Likelya8db8cf2012-02-14 14:06:54 -0700284 if (WARN_ON(!revmap))
285 return NULL;
286
287 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
288 if (!domain) {
289 kfree(revmap);
290 return NULL;
291 }
292 domain->revmap_data.linear.size = size;
293 domain->revmap_data.linear.revmap = revmap;
294 irq_domain_add(domain);
295 return domain;
296}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900297EXPORT_SYMBOL_GPL(irq_domain_add_linear);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700298
299struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700300 unsigned int max_irq,
Grant Likelya18dc812012-01-26 12:12:14 -0700301 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700302 void *host_data)
303{
304 struct irq_domain *domain = irq_domain_alloc(of_node,
305 IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700306 if (domain) {
307 domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700308 irq_domain_add(domain);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700309 }
Grant Likelya8db8cf2012-02-14 14:06:54 -0700310 return domain;
311}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900312EXPORT_SYMBOL_GPL(irq_domain_add_nomap);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700313
314/**
315 * irq_domain_add_tree()
316 * @of_node: pointer to interrupt controller's device tree node.
317 * @ops: map/unmap domain callbacks
318 *
319 * Note: The radix tree will be allocated later during boot automatically
320 * (the reverse mapping will use the slow path until that happens).
321 */
322struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
Grant Likelya18dc812012-01-26 12:12:14 -0700323 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700324 void *host_data)
325{
326 struct irq_domain *domain = irq_domain_alloc(of_node,
327 IRQ_DOMAIN_MAP_TREE, ops, host_data);
328 if (domain) {
329 INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
330 irq_domain_add(domain);
331 }
Grant Likely68700652012-02-14 14:06:53 -0700332 return domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700333}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900334EXPORT_SYMBOL_GPL(irq_domain_add_tree);
Grant Likelycc79ca62012-02-16 01:37:49 -0700335
336/**
337 * irq_find_host() - Locates a domain for a given device node
338 * @node: device-tree node of the interrupt controller
339 */
340struct irq_domain *irq_find_host(struct device_node *node)
341{
342 struct irq_domain *h, *found = NULL;
Grant Likelya18dc812012-01-26 12:12:14 -0700343 int rc;
Grant Likelycc79ca62012-02-16 01:37:49 -0700344
345 /* We might want to match the legacy controller last since
346 * it might potentially be set to match all interrupts in
347 * the absence of a device node. This isn't a problem so far
348 * yet though...
349 */
350 mutex_lock(&irq_domain_mutex);
Grant Likelya18dc812012-01-26 12:12:14 -0700351 list_for_each_entry(h, &irq_domain_list, link) {
352 if (h->ops->match)
353 rc = h->ops->match(h, node);
354 else
355 rc = (h->of_node != NULL) && (h->of_node == node);
356
357 if (rc) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700358 found = h;
359 break;
360 }
Grant Likelya18dc812012-01-26 12:12:14 -0700361 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700362 mutex_unlock(&irq_domain_mutex);
363 return found;
364}
365EXPORT_SYMBOL_GPL(irq_find_host);
366
367/**
368 * irq_set_default_host() - Set a "default" irq domain
Grant Likely68700652012-02-14 14:06:53 -0700369 * @domain: default domain pointer
Grant Likelycc79ca62012-02-16 01:37:49 -0700370 *
371 * For convenience, it's possible to set a "default" domain that will be used
372 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
373 * platforms that want to manipulate a few hard coded interrupt numbers that
374 * aren't properly represented in the device-tree.
375 */
Grant Likely68700652012-02-14 14:06:53 -0700376void irq_set_default_host(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700377{
Paul Mundt54a90582012-05-19 15:11:47 +0900378 pr_debug("Default domain set to @0x%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700379
Grant Likely68700652012-02-14 14:06:53 -0700380 irq_default_domain = domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700381}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900382EXPORT_SYMBOL_GPL(irq_set_default_host);
Grant Likelycc79ca62012-02-16 01:37:49 -0700383
Grant Likely913af202012-06-03 22:04:35 -0700384static void irq_domain_disassociate_many(struct irq_domain *domain,
385 unsigned int irq_base, int count)
386{
387 /*
388 * disassociate in reverse order;
389 * not strictly necessary, but nice for unwinding
390 */
391 while (count--) {
392 int irq = irq_base + count;
393 struct irq_data *irq_data = irq_get_irq_data(irq);
394 irq_hw_number_t hwirq = irq_data->hwirq;
395
396 if (WARN_ON(!irq_data || irq_data->domain != domain))
397 continue;
398
399 irq_set_status_flags(irq, IRQ_NOREQUEST);
400
401 /* remove chip and handler */
402 irq_set_chip_and_handler(irq, NULL, NULL);
403
404 /* Make sure it's completed */
405 synchronize_irq(irq);
406
407 /* Tell the PIC about it */
408 if (domain->ops->unmap)
409 domain->ops->unmap(domain, irq);
410 smp_mb();
411
412 irq_data->domain = NULL;
413 irq_data->hwirq = 0;
414
415 /* Clear reverse map */
416 switch(domain->revmap_type) {
417 case IRQ_DOMAIN_MAP_LINEAR:
418 if (hwirq < domain->revmap_data.linear.size)
419 domain->revmap_data.linear.revmap[hwirq] = 0;
420 break;
421 case IRQ_DOMAIN_MAP_TREE:
422 mutex_lock(&revmap_trees_mutex);
423 radix_tree_delete(&domain->revmap_data.tree, hwirq);
424 mutex_unlock(&revmap_trees_mutex);
425 break;
426 }
427 }
428}
429
Grant Likely98aa4682012-06-17 16:17:04 -0600430int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
431 irq_hw_number_t hwirq_base, int count)
Grant Likelycc79ca62012-02-16 01:37:49 -0700432{
Grant Likely98aa4682012-06-17 16:17:04 -0600433 unsigned int virq = irq_base;
434 irq_hw_number_t hwirq = hwirq_base;
Mark Brownf5a1ad02012-07-20 10:33:19 +0100435 int i, ret;
Grant Likelycc79ca62012-02-16 01:37:49 -0700436
Grant Likely98aa4682012-06-17 16:17:04 -0600437 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
438 of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
439
440 for (i = 0; i < count; i++) {
441 struct irq_data *irq_data = irq_get_irq_data(virq + i);
442
443 if (WARN(!irq_data, "error: irq_desc not allocated; "
444 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
445 return -EINVAL;
446 if (WARN(irq_data->domain, "error: irq_desc already associated; "
447 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
448 return -EINVAL;
449 };
450
451 for (i = 0; i < count; i++, virq++, hwirq++) {
452 struct irq_data *irq_data = irq_get_irq_data(virq);
453
454 irq_data->hwirq = hwirq;
455 irq_data->domain = domain;
Mark Brownf5a1ad02012-07-20 10:33:19 +0100456 if (domain->ops->map) {
457 ret = domain->ops->map(domain, virq, hwirq);
458 if (ret != 0) {
Benjamin Herrenschmidt5fe0c1f2013-05-06 11:37:43 +1000459 /*
460 * If map() returns -EPERM, this interrupt is protected
461 * by the firmware or some other service and shall not
462 * be mapped.
463 *
464 * Since on some platforms we blindly try to map everything
465 * we end up with a log full of backtraces.
466 *
467 * So instead, we silently fail on -EPERM, it is the
468 * responsibility of the PIC driver to display a relevant
469 * message if needed.
470 */
471 if (ret != -EPERM) {
472 pr_err("irq-%i==>hwirq-0x%lx mapping failed: %d\n",
473 virq, hwirq, ret);
474 WARN_ON(1);
475 }
Mark Brownf5a1ad02012-07-20 10:33:19 +0100476 irq_data->domain = NULL;
477 irq_data->hwirq = 0;
478 goto err_unmap;
479 }
Grant Likely98aa4682012-06-17 16:17:04 -0600480 }
481
482 switch (domain->revmap_type) {
483 case IRQ_DOMAIN_MAP_LINEAR:
484 if (hwirq < domain->revmap_data.linear.size)
485 domain->revmap_data.linear.revmap[hwirq] = virq;
486 break;
487 case IRQ_DOMAIN_MAP_TREE:
488 mutex_lock(&revmap_trees_mutex);
Grant Likelyd6b0d1f2012-06-03 22:04:37 -0700489 radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
Grant Likely98aa4682012-06-17 16:17:04 -0600490 mutex_unlock(&revmap_trees_mutex);
491 break;
492 }
493
494 irq_clear_status_flags(virq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700495 }
496
Grant Likelycc79ca62012-02-16 01:37:49 -0700497 return 0;
Grant Likely98aa4682012-06-17 16:17:04 -0600498
499 err_unmap:
500 irq_domain_disassociate_many(domain, irq_base, i);
501 return -EINVAL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700502}
Grant Likely98aa4682012-06-17 16:17:04 -0600503EXPORT_SYMBOL_GPL(irq_domain_associate_many);
Grant Likelycc79ca62012-02-16 01:37:49 -0700504
505/**
506 * irq_create_direct_mapping() - Allocate an irq for direct mapping
Grant Likely68700652012-02-14 14:06:53 -0700507 * @domain: domain to allocate the irq for or NULL for default domain
Grant Likelycc79ca62012-02-16 01:37:49 -0700508 *
509 * This routine is used for irq controllers which can choose the hardware
510 * interrupt numbers they generate. In such a case it's simplest to use
511 * the linux irq as the hardware interrupt number.
512 */
Grant Likely68700652012-02-14 14:06:53 -0700513unsigned int irq_create_direct_mapping(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700514{
515 unsigned int virq;
516
Grant Likely68700652012-02-14 14:06:53 -0700517 if (domain == NULL)
518 domain = irq_default_domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700519
Grant Likely9844a552012-06-03 22:04:38 -0700520 if (WARN_ON(!domain || domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP))
521 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700522
Paul Mundt5ca4db62012-06-03 22:04:34 -0700523 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
Grant Likely03848372012-02-14 14:06:52 -0700524 if (!virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900525 pr_debug("create_direct virq allocation failed\n");
Grant Likely03848372012-02-14 14:06:52 -0700526 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700527 }
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700528 if (virq >= domain->revmap_data.nomap.max_irq) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700529 pr_err("ERROR: no free irqs available below %i maximum\n",
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700530 domain->revmap_data.nomap.max_irq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700531 irq_free_desc(virq);
532 return 0;
533 }
Paul Mundt54a90582012-05-19 15:11:47 +0900534 pr_debug("create_direct obtained virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700535
Grant Likely98aa4682012-06-17 16:17:04 -0600536 if (irq_domain_associate(domain, virq, virq)) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700537 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700538 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700539 }
540
541 return virq;
542}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900543EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
Grant Likelycc79ca62012-02-16 01:37:49 -0700544
545/**
546 * irq_create_mapping() - Map a hardware interrupt into linux irq space
Grant Likely68700652012-02-14 14:06:53 -0700547 * @domain: domain owning this hardware interrupt or NULL for default domain
548 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700549 *
550 * Only one mapping per hardware interrupt is permitted. Returns a linux
551 * irq number.
552 * If the sense/trigger is to be specified, set_irq_type() should be called
553 * on the number returned from that call.
554 */
Grant Likely68700652012-02-14 14:06:53 -0700555unsigned int irq_create_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700556 irq_hw_number_t hwirq)
557{
David Daney5b7526e2012-04-05 16:52:13 -0700558 unsigned int hint;
559 int virq;
Grant Likelycc79ca62012-02-16 01:37:49 -0700560
Paul Mundt54a90582012-05-19 15:11:47 +0900561 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700562
Grant Likely68700652012-02-14 14:06:53 -0700563 /* Look for default domain if nececssary */
564 if (domain == NULL)
565 domain = irq_default_domain;
566 if (domain == NULL) {
Paul Mundt54a90582012-05-19 15:11:47 +0900567 pr_warning("irq_create_mapping called for"
568 " NULL domain, hwirq=%lx\n", hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700569 WARN_ON(1);
Grant Likely03848372012-02-14 14:06:52 -0700570 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700571 }
Paul Mundt54a90582012-05-19 15:11:47 +0900572 pr_debug("-> using domain @%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700573
574 /* Check if mapping already exists */
Grant Likely68700652012-02-14 14:06:53 -0700575 virq = irq_find_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700576 if (virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900577 pr_debug("-> existing mapping on virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700578 return virq;
579 }
580
581 /* Get a virtual interrupt number */
Grant Likely1bc04f22012-02-14 14:06:55 -0700582 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
583 return irq_domain_legacy_revmap(domain, hwirq);
584
585 /* Allocate a virtual interrupt number */
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700586 hint = hwirq % nr_irqs;
Grant Likely1bc04f22012-02-14 14:06:55 -0700587 if (hint == 0)
588 hint++;
Paul Mundt5ca4db62012-06-03 22:04:34 -0700589 virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700590 if (virq <= 0)
Paul Mundt5ca4db62012-06-03 22:04:34 -0700591 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700592 if (virq <= 0) {
Paul Mundt54a90582012-05-19 15:11:47 +0900593 pr_debug("-> virq allocation failed\n");
Grant Likely1bc04f22012-02-14 14:06:55 -0700594 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700595 }
596
Grant Likely98aa4682012-06-17 16:17:04 -0600597 if (irq_domain_associate(domain, virq, hwirq)) {
Grant Likely73255702012-06-03 22:04:35 -0700598 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700599 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700600 }
601
Paul Mundt54a90582012-05-19 15:11:47 +0900602 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700603 hwirq, of_node_full_name(domain->of_node), virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700604
605 return virq;
606}
607EXPORT_SYMBOL_GPL(irq_create_mapping);
608
Grant Likely98aa4682012-06-17 16:17:04 -0600609/**
610 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
611 * @domain: domain owning the interrupt range
612 * @irq_base: beginning of linux IRQ range
613 * @hwirq_base: beginning of hardware IRQ range
614 * @count: Number of interrupts to map
615 *
616 * This routine is used for allocating and mapping a range of hardware
617 * irqs to linux irqs where the linux irq numbers are at pre-defined
618 * locations. For use by controllers that already have static mappings
619 * to insert in to the domain.
620 *
621 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
622 * domain insertion.
623 *
624 * 0 is returned upon success, while any failure to establish a static
625 * mapping is treated as an error.
626 */
627int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
628 irq_hw_number_t hwirq_base, int count)
629{
630 int ret;
631
632 ret = irq_alloc_descs(irq_base, irq_base, count,
633 of_node_to_nid(domain->of_node));
634 if (unlikely(ret < 0))
635 return ret;
636
637 ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
638 if (unlikely(ret < 0)) {
639 irq_free_descs(irq_base, count);
640 return ret;
641 }
642
643 return 0;
644}
645EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
646
Grant Likelycc79ca62012-02-16 01:37:49 -0700647unsigned int irq_create_of_mapping(struct device_node *controller,
648 const u32 *intspec, unsigned int intsize)
649{
Grant Likely68700652012-02-14 14:06:53 -0700650 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700651 irq_hw_number_t hwirq;
652 unsigned int type = IRQ_TYPE_NONE;
653 unsigned int virq;
654
Grant Likely68700652012-02-14 14:06:53 -0700655 domain = controller ? irq_find_host(controller) : irq_default_domain;
656 if (!domain) {
Grant Likelyabd23632012-02-24 08:07:06 -0700657#ifdef CONFIG_MIPS
658 /*
659 * Workaround to avoid breaking interrupt controller drivers
660 * that don't yet register an irq_domain. This is temporary
661 * code. ~~~gcl, Feb 24, 2012
662 *
663 * Scheduled for removal in Linux v3.6. That should be enough
664 * time.
665 */
666 if (intsize > 0)
667 return intspec[0];
668#endif
Paul Mundt54a90582012-05-19 15:11:47 +0900669 pr_warning("no irq domain found for %s !\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700670 of_node_full_name(controller));
Grant Likely03848372012-02-14 14:06:52 -0700671 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700672 }
673
Grant Likely68700652012-02-14 14:06:53 -0700674 /* If domain has no translation, then we assume interrupt line */
675 if (domain->ops->xlate == NULL)
Grant Likelycc79ca62012-02-16 01:37:49 -0700676 hwirq = intspec[0];
677 else {
Grant Likely68700652012-02-14 14:06:53 -0700678 if (domain->ops->xlate(domain, controller, intspec, intsize,
Grant Likelycc79ca62012-02-16 01:37:49 -0700679 &hwirq, &type))
Grant Likely03848372012-02-14 14:06:52 -0700680 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700681 }
682
683 /* Create mapping */
Grant Likely68700652012-02-14 14:06:53 -0700684 virq = irq_create_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700685 if (!virq)
Grant Likelycc79ca62012-02-16 01:37:49 -0700686 return virq;
687
688 /* Set type if specified and different than the current one */
689 if (type != IRQ_TYPE_NONE &&
Javier Martinez Canillasfbab62c52013-06-14 18:40:49 +0200690 type != irq_get_trigger_type(virq))
Grant Likelycc79ca62012-02-16 01:37:49 -0700691 irq_set_irq_type(virq, type);
692 return virq;
693}
694EXPORT_SYMBOL_GPL(irq_create_of_mapping);
695
696/**
697 * irq_dispose_mapping() - Unmap an interrupt
698 * @virq: linux irq number of the interrupt to unmap
699 */
700void irq_dispose_mapping(unsigned int virq)
701{
702 struct irq_data *irq_data = irq_get_irq_data(virq);
Grant Likely68700652012-02-14 14:06:53 -0700703 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700704
Grant Likely03848372012-02-14 14:06:52 -0700705 if (!virq || !irq_data)
Grant Likelycc79ca62012-02-16 01:37:49 -0700706 return;
707
Grant Likely68700652012-02-14 14:06:53 -0700708 domain = irq_data->domain;
709 if (WARN_ON(domain == NULL))
Grant Likelycc79ca62012-02-16 01:37:49 -0700710 return;
711
712 /* Never unmap legacy interrupts */
Grant Likely68700652012-02-14 14:06:53 -0700713 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
Grant Likelycc79ca62012-02-16 01:37:49 -0700714 return;
715
Grant Likely913af202012-06-03 22:04:35 -0700716 irq_domain_disassociate_many(domain, virq, 1);
Grant Likelycc79ca62012-02-16 01:37:49 -0700717 irq_free_desc(virq);
718}
719EXPORT_SYMBOL_GPL(irq_dispose_mapping);
720
721/**
722 * irq_find_mapping() - Find a linux irq from an hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700723 * @domain: domain owning this hardware interrupt
724 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700725 */
Grant Likely68700652012-02-14 14:06:53 -0700726unsigned int irq_find_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700727 irq_hw_number_t hwirq)
728{
Grant Likely4c0946c2012-06-03 22:04:39 -0700729 struct irq_data *data;
Grant Likelycc79ca62012-02-16 01:37:49 -0700730
Grant Likely68700652012-02-14 14:06:53 -0700731 /* Look for default domain if nececssary */
732 if (domain == NULL)
733 domain = irq_default_domain;
734 if (domain == NULL)
Grant Likely03848372012-02-14 14:06:52 -0700735 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700736
Grant Likely4c0946c2012-06-03 22:04:39 -0700737 switch (domain->revmap_type) {
738 case IRQ_DOMAIN_MAP_LEGACY:
Grant Likely1bc04f22012-02-14 14:06:55 -0700739 return irq_domain_legacy_revmap(domain, hwirq);
Grant Likely4c0946c2012-06-03 22:04:39 -0700740 case IRQ_DOMAIN_MAP_LINEAR:
741 return irq_linear_revmap(domain, hwirq);
742 case IRQ_DOMAIN_MAP_TREE:
743 rcu_read_lock();
744 data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
745 rcu_read_unlock();
746 if (data)
747 return data->irq;
748 break;
749 case IRQ_DOMAIN_MAP_NOMAP:
750 data = irq_get_irq_data(hwirq);
Grant Likely68700652012-02-14 14:06:53 -0700751 if (data && (data->domain == domain) && (data->hwirq == hwirq))
Grant Likely4c0946c2012-06-03 22:04:39 -0700752 return hwirq;
753 break;
754 }
755
Grant Likely03848372012-02-14 14:06:52 -0700756 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700757}
758EXPORT_SYMBOL_GPL(irq_find_mapping);
759
760/**
Grant Likelycc79ca62012-02-16 01:37:49 -0700761 * irq_linear_revmap() - Find a linux irq from a hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700762 * @domain: domain owning this hardware interrupt
763 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700764 *
Grant Likely4c0946c2012-06-03 22:04:39 -0700765 * This is a fast path that can be called directly by irq controller code to
766 * save a handful of instructions.
Grant Likelycc79ca62012-02-16 01:37:49 -0700767 */
Grant Likely68700652012-02-14 14:06:53 -0700768unsigned int irq_linear_revmap(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700769 irq_hw_number_t hwirq)
770{
Grant Likely4c0946c2012-06-03 22:04:39 -0700771 BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
Grant Likelycc79ca62012-02-16 01:37:49 -0700772
Grant Likely4c0946c2012-06-03 22:04:39 -0700773 /* Check revmap bounds; complain if exceeded */
774 if (WARN_ON(hwirq >= domain->revmap_data.linear.size))
775 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700776
Grant Likely4c0946c2012-06-03 22:04:39 -0700777 return domain->revmap_data.linear.revmap[hwirq];
Grant Likelycc79ca62012-02-16 01:37:49 -0700778}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900779EXPORT_SYMBOL_GPL(irq_linear_revmap);
Grant Likelycc79ca62012-02-16 01:37:49 -0700780
Grant Likely092b2fb2012-03-29 14:10:30 -0600781#ifdef CONFIG_IRQ_DOMAIN_DEBUG
Grant Likelycc79ca62012-02-16 01:37:49 -0700782static int virq_debug_show(struct seq_file *m, void *private)
783{
784 unsigned long flags;
785 struct irq_desc *desc;
786 const char *p;
787 static const char none[] = "none";
788 void *data;
789 int i;
790
Grant Likely15e06bf2012-04-11 00:26:25 -0600791 seq_printf(m, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
Grant Likely5269a9a2012-04-12 14:42:15 -0600792 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
793 "domain name");
Grant Likelycc79ca62012-02-16 01:37:49 -0700794
795 for (i = 1; i < nr_irqs; i++) {
796 desc = irq_to_desc(i);
797 if (!desc)
798 continue;
799
800 raw_spin_lock_irqsave(&desc->lock, flags);
801
802 if (desc->action && desc->action->handler) {
803 struct irq_chip *chip;
804
805 seq_printf(m, "%5d ", i);
806 seq_printf(m, "0x%05lx ", desc->irq_data.hwirq);
807
808 chip = irq_desc_get_chip(desc);
809 if (chip && chip->name)
810 p = chip->name;
811 else
812 p = none;
813 seq_printf(m, "%-15s ", p);
814
815 data = irq_desc_get_chip_data(desc);
Grant Likely15e06bf2012-04-11 00:26:25 -0600816 seq_printf(m, data ? "0x%p " : " %p ", data);
Grant Likelycc79ca62012-02-16 01:37:49 -0700817
Grant Likelyefd68e72012-06-03 22:04:33 -0700818 if (desc->irq_data.domain)
819 p = of_node_full_name(desc->irq_data.domain->of_node);
Grant Likelycc79ca62012-02-16 01:37:49 -0700820 else
821 p = none;
822 seq_printf(m, "%s\n", p);
823 }
824
825 raw_spin_unlock_irqrestore(&desc->lock, flags);
826 }
827
828 return 0;
829}
830
831static int virq_debug_open(struct inode *inode, struct file *file)
832{
833 return single_open(file, virq_debug_show, inode->i_private);
834}
835
836static const struct file_operations virq_debug_fops = {
837 .open = virq_debug_open,
838 .read = seq_read,
839 .llseek = seq_lseek,
840 .release = single_release,
841};
842
843static int __init irq_debugfs_init(void)
844{
Grant Likely092b2fb2012-03-29 14:10:30 -0600845 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
Grant Likelycc79ca62012-02-16 01:37:49 -0700846 NULL, &virq_debug_fops) == NULL)
847 return -ENOMEM;
848
849 return 0;
850}
851__initcall(irq_debugfs_init);
Grant Likely092b2fb2012-03-29 14:10:30 -0600852#endif /* CONFIG_IRQ_DOMAIN_DEBUG */
Grant Likelycc79ca62012-02-16 01:37:49 -0700853
Grant Likely16b2e6e2012-01-26 11:26:52 -0700854/**
855 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
856 *
857 * Device Tree IRQ specifier translation function which works with one cell
858 * bindings where the cell value maps directly to the hwirq number.
859 */
860int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
861 const u32 *intspec, unsigned int intsize,
862 unsigned long *out_hwirq, unsigned int *out_type)
Grant Likely7e713302011-07-26 03:19:06 -0600863{
Grant Likely16b2e6e2012-01-26 11:26:52 -0700864 if (WARN_ON(intsize < 1))
Grant Likely7e713302011-07-26 03:19:06 -0600865 return -EINVAL;
Grant Likely7e713302011-07-26 03:19:06 -0600866 *out_hwirq = intspec[0];
867 *out_type = IRQ_TYPE_NONE;
Grant Likely7e713302011-07-26 03:19:06 -0600868 return 0;
869}
Grant Likely16b2e6e2012-01-26 11:26:52 -0700870EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
871
872/**
873 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
874 *
875 * Device Tree IRQ specifier translation function which works with two cell
876 * bindings where the cell values map directly to the hwirq number
877 * and linux irq flags.
878 */
879int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
880 const u32 *intspec, unsigned int intsize,
881 irq_hw_number_t *out_hwirq, unsigned int *out_type)
882{
883 if (WARN_ON(intsize < 2))
884 return -EINVAL;
885 *out_hwirq = intspec[0];
886 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
887 return 0;
888}
889EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
890
891/**
892 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
893 *
894 * Device Tree IRQ specifier translation function which works with either one
895 * or two cell bindings where the cell values map directly to the hwirq number
896 * and linux irq flags.
897 *
898 * Note: don't use this function unless your interrupt controller explicitly
899 * supports both one and two cell bindings. For the majority of controllers
900 * the _onecell() or _twocell() variants above should be used.
901 */
902int irq_domain_xlate_onetwocell(struct irq_domain *d,
903 struct device_node *ctrlr,
904 const u32 *intspec, unsigned int intsize,
905 unsigned long *out_hwirq, unsigned int *out_type)
906{
907 if (WARN_ON(intsize < 1))
908 return -EINVAL;
909 *out_hwirq = intspec[0];
910 *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
911 return 0;
912}
913EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
Grant Likely7e713302011-07-26 03:19:06 -0600914
Grant Likelya18dc812012-01-26 12:12:14 -0700915const struct irq_domain_ops irq_domain_simple_ops = {
Grant Likely16b2e6e2012-01-26 11:26:52 -0700916 .xlate = irq_domain_xlate_onetwocell,
Grant Likely75294952012-02-14 14:06:57 -0700917};
918EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
919
920#ifdef CONFIG_OF_IRQ
Grant Likely7e713302011-07-26 03:19:06 -0600921void irq_domain_generate_simple(const struct of_device_id *match,
922 u64 phys_base, unsigned int irq_start)
923{
924 struct device_node *node;
Grant Likelye1964c52012-02-14 14:06:48 -0700925 pr_debug("looking for phys_base=%llx, irq_start=%i\n",
Grant Likely7e713302011-07-26 03:19:06 -0600926 (unsigned long long) phys_base, (int) irq_start);
927 node = of_find_matching_node_by_address(NULL, match, phys_base);
928 if (node)
Grant Likely6b783f72012-01-10 17:09:30 -0700929 irq_domain_add_legacy(node, 32, irq_start, 0,
930 &irq_domain_simple_ops, NULL);
Grant Likely7e713302011-07-26 03:19:06 -0600931}
932EXPORT_SYMBOL_GPL(irq_domain_generate_simple);
Grant Likely75294952012-02-14 14:06:57 -0700933#endif