Merge remote-tracking branches 'spi/topic/s3c64xx', 'spi/topic/ti-qspi' and 'spi...
[deliverable/linux.git] / kernel / irq / irqdomain.c
CommitLineData
54a90588
PM
1#define pr_fmt(fmt) "irq: " fmt
2
cc79ca69
GL
3#include <linux/debugfs.h>
4#include <linux/hardirq.h>
5#include <linux/interrupt.h>
08a543ad 6#include <linux/irq.h>
cc79ca69 7#include <linux/irqdesc.h>
08a543ad
GL
8#include <linux/irqdomain.h>
9#include <linux/module.h>
10#include <linux/mutex.h>
11#include <linux/of.h>
7e713301 12#include <linux/of_address.h>
64be38ab 13#include <linux/of_irq.h>
5ca4db61 14#include <linux/topology.h>
cc79ca69 15#include <linux/seq_file.h>
7e713301 16#include <linux/slab.h>
cc79ca69
GL
17#include <linux/smp.h>
18#include <linux/fs.h>
08a543ad
GL
19
20static LIST_HEAD(irq_domain_list);
21static DEFINE_MUTEX(irq_domain_mutex);
22
cc79ca69 23static DEFINE_MUTEX(revmap_trees_mutex);
68700650 24static struct irq_domain *irq_default_domain;
cc79ca69 25
f8264e34
JL
26static int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
27 irq_hw_number_t hwirq, int node);
28static void irq_domain_check_hierarchy(struct irq_domain *domain);
29
cc79ca69 30/**
fa40f377 31 * __irq_domain_add() - Allocate a new irq_domain data structure
cc79ca69 32 * @of_node: optional device-tree node of the interrupt controller
fa40f377 33 * @size: Size of linear map; 0 for radix mapping only
a257954b 34 * @hwirq_max: Maximum number of interrupts supported by controller
fa40f377
GL
35 * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
36 * direct mapping
f8264e34 37 * @ops: domain callbacks
a8db8cf0 38 * @host_data: Controller private data pointer
cc79ca69 39 *
a257954b
JL
40 * Allocates and initialize and irq_domain structure.
41 * Returns pointer to IRQ domain, or NULL on failure.
cc79ca69 42 */
ddaf144c
GL
43struct irq_domain *__irq_domain_add(struct device_node *of_node, int size,
44 irq_hw_number_t hwirq_max, int direct_max,
fa40f377
GL
45 const struct irq_domain_ops *ops,
46 void *host_data)
cc79ca69 47{
a8db8cf0 48 struct irq_domain *domain;
cc79ca69 49
cef5075c
GL
50 domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
51 GFP_KERNEL, of_node_to_nid(of_node));
a8db8cf0 52 if (WARN_ON(!domain))
cc79ca69
GL
53 return NULL;
54
55 /* Fill structure */
1aa0dd94 56 INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
68700650 57 domain->ops = ops;
a8db8cf0 58 domain->host_data = host_data;
68700650 59 domain->of_node = of_node_get(of_node);
ddaf144c 60 domain->hwirq_max = hwirq_max;
1aa0dd94 61 domain->revmap_size = size;
fa40f377 62 domain->revmap_direct_max_irq = direct_max;
f8264e34 63 irq_domain_check_hierarchy(domain);
cc79ca69 64
a8db8cf0
GL
65 mutex_lock(&irq_domain_mutex);
66 list_add(&domain->link, &irq_domain_list);
67 mutex_unlock(&irq_domain_mutex);
fa40f377 68
1aa0dd94 69 pr_debug("Added domain %s\n", domain->name);
fa40f377 70 return domain;
a8db8cf0 71}
fa40f377 72EXPORT_SYMBOL_GPL(__irq_domain_add);
a8db8cf0 73
58ee99ad
PM
74/**
75 * irq_domain_remove() - Remove an irq domain.
76 * @domain: domain to remove
77 *
78 * This routine is used to remove an irq domain. The caller must ensure
79 * that all mappings within the domain have been disposed of prior to
80 * use, depending on the revmap type.
81 */
82void irq_domain_remove(struct irq_domain *domain)
83{
84 mutex_lock(&irq_domain_mutex);
85
cef5075c
GL
86 /*
87 * radix_tree_delete() takes care of destroying the root
88 * node when all entries are removed. Shout if there are
89 * any mappings left.
90 */
1aa0dd94 91 WARN_ON(domain->revmap_tree.height);
58ee99ad
PM
92
93 list_del(&domain->link);
94
95 /*
96 * If the going away domain is the default one, reset it.
97 */
98 if (unlikely(irq_default_domain == domain))
99 irq_set_default_host(NULL);
100
101 mutex_unlock(&irq_domain_mutex);
102
1aa0dd94 103 pr_debug("Removed domain %s\n", domain->name);
58ee99ad 104
fa40f377
GL
105 of_node_put(domain->of_node);
106 kfree(domain);
58ee99ad 107}
ecd84eb2 108EXPORT_SYMBOL_GPL(irq_domain_remove);
58ee99ad 109
781d0f46 110/**
fa40f377 111 * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
781d0f46
MB
112 * @of_node: pointer to interrupt controller's device tree node.
113 * @size: total number of irqs in mapping
94a63da0 114 * @first_irq: first number of irq block assigned to the domain,
fa40f377
GL
115 * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
116 * pre-map all of the irqs in the domain to virqs starting at first_irq.
f8264e34 117 * @ops: domain callbacks
781d0f46
MB
118 * @host_data: Controller private data pointer
119 *
fa40f377
GL
120 * Allocates an irq_domain, and optionally if first_irq is positive then also
121 * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
781d0f46
MB
122 *
123 * This is intended to implement the expected behaviour for most
fa40f377
GL
124 * interrupt controllers. If device tree is used, then first_irq will be 0 and
125 * irqs get mapped dynamically on the fly. However, if the controller requires
126 * static virq assignments (non-DT boot) then it will set that up correctly.
781d0f46
MB
127 */
128struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
129 unsigned int size,
130 unsigned int first_irq,
131 const struct irq_domain_ops *ops,
132 void *host_data)
133{
fa40f377
GL
134 struct irq_domain *domain;
135
ddaf144c 136 domain = __irq_domain_add(of_node, size, size, 0, ops, host_data);
fa40f377
GL
137 if (!domain)
138 return NULL;
2854d167 139
fa40f377 140 if (first_irq > 0) {
2854d167 141 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
fa40f377
GL
142 /* attempt to allocated irq_descs */
143 int rc = irq_alloc_descs(first_irq, first_irq, size,
144 of_node_to_nid(of_node));
145 if (rc < 0)
d202b7b9
LW
146 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
147 first_irq);
fa40f377 148 }
ddaf144c 149 irq_domain_associate_many(domain, first_irq, 0, size);
2854d167
LW
150 }
151
fa40f377 152 return domain;
781d0f46 153}
346dbb79 154EXPORT_SYMBOL_GPL(irq_domain_add_simple);
781d0f46 155
a8db8cf0
GL
156/**
157 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
158 * @of_node: pointer to interrupt controller's device tree node.
1bc04f2c
GL
159 * @size: total number of irqs in legacy mapping
160 * @first_irq: first number of irq block assigned to the domain
161 * @first_hwirq: first hwirq number to use for the translation. Should normally
162 * be '0', but a positive integer can be used if the effective
163 * hwirqs numbering does not begin at zero.
a8db8cf0
GL
164 * @ops: map/unmap domain callbacks
165 * @host_data: Controller private data pointer
166 *
167 * Note: the map() callback will be called before this function returns
168 * for all legacy interrupts except 0 (which is always the invalid irq for
169 * a legacy controller).
170 */
171struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
1bc04f2c
GL
172 unsigned int size,
173 unsigned int first_irq,
174 irq_hw_number_t first_hwirq,
a18dc81b 175 const struct irq_domain_ops *ops,
a8db8cf0
GL
176 void *host_data)
177{
1bc04f2c 178 struct irq_domain *domain;
a8db8cf0 179
ddaf144c
GL
180 domain = __irq_domain_add(of_node, first_hwirq + size,
181 first_hwirq + size, 0, ops, host_data);
f8264e34
JL
182 if (domain)
183 irq_domain_associate_many(domain, first_irq, first_hwirq, size);
1bc04f2c 184
a8db8cf0
GL
185 return domain;
186}
ecd84eb2 187EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
a8db8cf0 188
cc79ca69 189/**
ad3aedfb 190 * irq_find_matching_host() - Locates a domain for a given device node
cc79ca69 191 * @node: device-tree node of the interrupt controller
ad3aedfb 192 * @bus_token: domain-specific data
cc79ca69 193 */
ad3aedfb
MZ
194struct irq_domain *irq_find_matching_host(struct device_node *node,
195 enum irq_domain_bus_token bus_token)
cc79ca69
GL
196{
197 struct irq_domain *h, *found = NULL;
a18dc81b 198 int rc;
cc79ca69
GL
199
200 /* We might want to match the legacy controller last since
201 * it might potentially be set to match all interrupts in
202 * the absence of a device node. This isn't a problem so far
203 * yet though...
ad3aedfb
MZ
204 *
205 * bus_token == DOMAIN_BUS_ANY matches any domain, any other
206 * values must generate an exact match for the domain to be
207 * selected.
cc79ca69
GL
208 */
209 mutex_lock(&irq_domain_mutex);
a18dc81b
GL
210 list_for_each_entry(h, &irq_domain_list, link) {
211 if (h->ops->match)
ad3aedfb 212 rc = h->ops->match(h, node, bus_token);
a18dc81b 213 else
ad3aedfb
MZ
214 rc = ((h->of_node != NULL) && (h->of_node == node) &&
215 ((bus_token == DOMAIN_BUS_ANY) ||
216 (h->bus_token == bus_token)));
a18dc81b
GL
217
218 if (rc) {
cc79ca69
GL
219 found = h;
220 break;
221 }
a18dc81b 222 }
cc79ca69
GL
223 mutex_unlock(&irq_domain_mutex);
224 return found;
225}
ad3aedfb 226EXPORT_SYMBOL_GPL(irq_find_matching_host);
cc79ca69
GL
227
228/**
229 * irq_set_default_host() - Set a "default" irq domain
68700650 230 * @domain: default domain pointer
cc79ca69
GL
231 *
232 * For convenience, it's possible to set a "default" domain that will be used
233 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
234 * platforms that want to manipulate a few hard coded interrupt numbers that
235 * aren't properly represented in the device-tree.
236 */
68700650 237void irq_set_default_host(struct irq_domain *domain)
cc79ca69 238{
54a90588 239 pr_debug("Default domain set to @0x%p\n", domain);
cc79ca69 240
68700650 241 irq_default_domain = domain;
cc79ca69 242}
ecd84eb2 243EXPORT_SYMBOL_GPL(irq_set_default_host);
cc79ca69 244
43a77591 245void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
913af207 246{
ddaf144c
GL
247 struct irq_data *irq_data = irq_get_irq_data(irq);
248 irq_hw_number_t hwirq;
913af207 249
ddaf144c
GL
250 if (WARN(!irq_data || irq_data->domain != domain,
251 "virq%i doesn't exist; cannot disassociate\n", irq))
252 return;
913af207 253
ddaf144c
GL
254 hwirq = irq_data->hwirq;
255 irq_set_status_flags(irq, IRQ_NOREQUEST);
913af207 256
ddaf144c
GL
257 /* remove chip and handler */
258 irq_set_chip_and_handler(irq, NULL, NULL);
913af207 259
ddaf144c
GL
260 /* Make sure it's completed */
261 synchronize_irq(irq);
913af207 262
ddaf144c
GL
263 /* Tell the PIC about it */
264 if (domain->ops->unmap)
265 domain->ops->unmap(domain, irq);
266 smp_mb();
913af207 267
ddaf144c
GL
268 irq_data->domain = NULL;
269 irq_data->hwirq = 0;
913af207 270
ddaf144c
GL
271 /* Clear reverse map for this hwirq */
272 if (hwirq < domain->revmap_size) {
273 domain->linear_revmap[hwirq] = 0;
274 } else {
275 mutex_lock(&revmap_trees_mutex);
276 radix_tree_delete(&domain->revmap_tree, hwirq);
277 mutex_unlock(&revmap_trees_mutex);
913af207
GL
278 }
279}
280
ddaf144c
GL
281int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
282 irq_hw_number_t hwirq)
cc79ca69 283{
ddaf144c
GL
284 struct irq_data *irq_data = irq_get_irq_data(virq);
285 int ret;
cc79ca69 286
ddaf144c
GL
287 if (WARN(hwirq >= domain->hwirq_max,
288 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
289 return -EINVAL;
290 if (WARN(!irq_data, "error: virq%i is not allocated", virq))
291 return -EINVAL;
292 if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
293 return -EINVAL;
cc79ca69 294
ddaf144c
GL
295 mutex_lock(&irq_domain_mutex);
296 irq_data->hwirq = hwirq;
297 irq_data->domain = domain;
298 if (domain->ops->map) {
299 ret = domain->ops->map(domain, virq, hwirq);
300 if (ret != 0) {
301 /*
302 * If map() returns -EPERM, this interrupt is protected
303 * by the firmware or some other service and shall not
304 * be mapped. Don't bother telling the user about it.
305 */
306 if (ret != -EPERM) {
307 pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
308 domain->name, hwirq, virq, ret);
f5a1ad05 309 }
ddaf144c
GL
310 irq_data->domain = NULL;
311 irq_data->hwirq = 0;
312 mutex_unlock(&irq_domain_mutex);
313 return ret;
98aa468e
GL
314 }
315
ddaf144c
GL
316 /* If not already assigned, give the domain the chip's name */
317 if (!domain->name && irq_data->chip)
318 domain->name = irq_data->chip->name;
319 }
2a71a1a9 320
ddaf144c
GL
321 if (hwirq < domain->revmap_size) {
322 domain->linear_revmap[hwirq] = virq;
323 } else {
324 mutex_lock(&revmap_trees_mutex);
325 radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
326 mutex_unlock(&revmap_trees_mutex);
98aa468e 327 }
ddaf144c
GL
328 mutex_unlock(&irq_domain_mutex);
329
330 irq_clear_status_flags(virq, IRQ_NOREQUEST);
cc79ca69
GL
331
332 return 0;
333}
ddaf144c 334EXPORT_SYMBOL_GPL(irq_domain_associate);
98aa468e 335
ddaf144c
GL
336void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
337 irq_hw_number_t hwirq_base, int count)
338{
339 int i;
340
341 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
342 of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
343
344 for (i = 0; i < count; i++) {
345 irq_domain_associate(domain, irq_base + i, hwirq_base + i);
346 }
cc79ca69 347}
98aa468e 348EXPORT_SYMBOL_GPL(irq_domain_associate_many);
cc79ca69
GL
349
350/**
351 * irq_create_direct_mapping() - Allocate an irq for direct mapping
68700650 352 * @domain: domain to allocate the irq for or NULL for default domain
cc79ca69
GL
353 *
354 * This routine is used for irq controllers which can choose the hardware
355 * interrupt numbers they generate. In such a case it's simplest to use
1aa0dd94
GL
356 * the linux irq as the hardware interrupt number. It still uses the linear
357 * or radix tree to store the mapping, but the irq controller can optimize
358 * the revmap path by using the hwirq directly.
cc79ca69 359 */
68700650 360unsigned int irq_create_direct_mapping(struct irq_domain *domain)
cc79ca69
GL
361{
362 unsigned int virq;
363
68700650
GL
364 if (domain == NULL)
365 domain = irq_default_domain;
cc79ca69 366
5ca4db61 367 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
03848373 368 if (!virq) {
54a90588 369 pr_debug("create_direct virq allocation failed\n");
03848373 370 return 0;
cc79ca69 371 }
1aa0dd94 372 if (virq >= domain->revmap_direct_max_irq) {
cc79ca69 373 pr_err("ERROR: no free irqs available below %i maximum\n",
1aa0dd94 374 domain->revmap_direct_max_irq);
cc79ca69
GL
375 irq_free_desc(virq);
376 return 0;
377 }
54a90588 378 pr_debug("create_direct obtained virq %d\n", virq);
cc79ca69 379
98aa468e 380 if (irq_domain_associate(domain, virq, virq)) {
cc79ca69 381 irq_free_desc(virq);
03848373 382 return 0;
cc79ca69
GL
383 }
384
385 return virq;
386}
ecd84eb2 387EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
cc79ca69
GL
388
389/**
390 * irq_create_mapping() - Map a hardware interrupt into linux irq space
68700650
GL
391 * @domain: domain owning this hardware interrupt or NULL for default domain
392 * @hwirq: hardware irq number in that domain space
cc79ca69
GL
393 *
394 * Only one mapping per hardware interrupt is permitted. Returns a linux
395 * irq number.
396 * If the sense/trigger is to be specified, set_irq_type() should be called
397 * on the number returned from that call.
398 */
68700650 399unsigned int irq_create_mapping(struct irq_domain *domain,
cc79ca69
GL
400 irq_hw_number_t hwirq)
401{
5b7526e3 402 int virq;
cc79ca69 403
54a90588 404 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
cc79ca69 405
68700650
GL
406 /* Look for default domain if nececssary */
407 if (domain == NULL)
408 domain = irq_default_domain;
409 if (domain == NULL) {
798f0fd1 410 WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
03848373 411 return 0;
cc79ca69 412 }
54a90588 413 pr_debug("-> using domain @%p\n", domain);
cc79ca69
GL
414
415 /* Check if mapping already exists */
68700650 416 virq = irq_find_mapping(domain, hwirq);
03848373 417 if (virq) {
54a90588 418 pr_debug("-> existing mapping on virq %d\n", virq);
cc79ca69
GL
419 return virq;
420 }
421
1bc04f2c 422 /* Allocate a virtual interrupt number */
f8264e34
JL
423 virq = irq_domain_alloc_descs(-1, 1, hwirq,
424 of_node_to_nid(domain->of_node));
5b7526e3 425 if (virq <= 0) {
54a90588 426 pr_debug("-> virq allocation failed\n");
1bc04f2c 427 return 0;
cc79ca69
GL
428 }
429
98aa468e 430 if (irq_domain_associate(domain, virq, hwirq)) {
73255704 431 irq_free_desc(virq);
03848373 432 return 0;
cc79ca69
GL
433 }
434
54a90588 435 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
efd68e72 436 hwirq, of_node_full_name(domain->of_node), virq);
cc79ca69
GL
437
438 return virq;
439}
440EXPORT_SYMBOL_GPL(irq_create_mapping);
441
98aa468e
GL
442/**
443 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
444 * @domain: domain owning the interrupt range
445 * @irq_base: beginning of linux IRQ range
446 * @hwirq_base: beginning of hardware IRQ range
447 * @count: Number of interrupts to map
448 *
449 * This routine is used for allocating and mapping a range of hardware
450 * irqs to linux irqs where the linux irq numbers are at pre-defined
451 * locations. For use by controllers that already have static mappings
452 * to insert in to the domain.
453 *
454 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
455 * domain insertion.
456 *
457 * 0 is returned upon success, while any failure to establish a static
458 * mapping is treated as an error.
459 */
460int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
461 irq_hw_number_t hwirq_base, int count)
462{
463 int ret;
464
465 ret = irq_alloc_descs(irq_base, irq_base, count,
466 of_node_to_nid(domain->of_node));
467 if (unlikely(ret < 0))
468 return ret;
469
ddaf144c 470 irq_domain_associate_many(domain, irq_base, hwirq_base, count);
98aa468e
GL
471 return 0;
472}
473EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
474
e6d30ab1 475unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
cc79ca69 476{
68700650 477 struct irq_domain *domain;
cc79ca69
GL
478 irq_hw_number_t hwirq;
479 unsigned int type = IRQ_TYPE_NONE;
f8264e34 480 int virq;
cc79ca69 481
e6d30ab1 482 domain = irq_data->np ? irq_find_host(irq_data->np) : irq_default_domain;
68700650 483 if (!domain) {
798f0fd1 484 pr_warn("no irq domain found for %s !\n",
e6d30ab1 485 of_node_full_name(irq_data->np));
03848373 486 return 0;
cc79ca69
GL
487 }
488
68700650
GL
489 /* If domain has no translation, then we assume interrupt line */
490 if (domain->ops->xlate == NULL)
e6d30ab1 491 hwirq = irq_data->args[0];
cc79ca69 492 else {
e6d30ab1
GL
493 if (domain->ops->xlate(domain, irq_data->np, irq_data->args,
494 irq_data->args_count, &hwirq, &type))
03848373 495 return 0;
cc79ca69
GL
496 }
497
0cc01aba
YC
498 if (irq_domain_is_hierarchy(domain)) {
499 /*
500 * If we've already configured this interrupt,
501 * don't do it again, or hell will break loose.
502 */
503 virq = irq_find_mapping(domain, hwirq);
504 if (virq)
505 return virq;
506
507 virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, irq_data);
508 if (virq <= 0)
509 return 0;
510 } else {
511 /* Create mapping */
512 virq = irq_create_mapping(domain, hwirq);
513 if (!virq)
514 return virq;
515 }
cc79ca69
GL
516
517 /* Set type if specified and different than the current one */
518 if (type != IRQ_TYPE_NONE &&
fbab62c5 519 type != irq_get_trigger_type(virq))
cc79ca69
GL
520 irq_set_irq_type(virq, type);
521 return virq;
522}
523EXPORT_SYMBOL_GPL(irq_create_of_mapping);
524
525/**
526 * irq_dispose_mapping() - Unmap an interrupt
527 * @virq: linux irq number of the interrupt to unmap
528 */
529void irq_dispose_mapping(unsigned int virq)
530{
531 struct irq_data *irq_data = irq_get_irq_data(virq);
68700650 532 struct irq_domain *domain;
cc79ca69 533
03848373 534 if (!virq || !irq_data)
cc79ca69
GL
535 return;
536
68700650
GL
537 domain = irq_data->domain;
538 if (WARN_ON(domain == NULL))
cc79ca69
GL
539 return;
540
ddaf144c 541 irq_domain_disassociate(domain, virq);
cc79ca69
GL
542 irq_free_desc(virq);
543}
544EXPORT_SYMBOL_GPL(irq_dispose_mapping);
545
546/**
547 * irq_find_mapping() - Find a linux irq from an hw irq number.
68700650
GL
548 * @domain: domain owning this hardware interrupt
549 * @hwirq: hardware irq number in that domain space
cc79ca69 550 */
68700650 551unsigned int irq_find_mapping(struct irq_domain *domain,
cc79ca69
GL
552 irq_hw_number_t hwirq)
553{
4c0946c4 554 struct irq_data *data;
cc79ca69 555
68700650
GL
556 /* Look for default domain if nececssary */
557 if (domain == NULL)
558 domain = irq_default_domain;
559 if (domain == NULL)
03848373 560 return 0;
cc79ca69 561
1aa0dd94 562 if (hwirq < domain->revmap_direct_max_irq) {
f8264e34
JL
563 data = irq_domain_get_irq_data(domain, hwirq);
564 if (data && data->hwirq == hwirq)
4c0946c4 565 return hwirq;
4c0946c4
GL
566 }
567
d3dcb436
GL
568 /* Check if the hwirq is in the linear revmap. */
569 if (hwirq < domain->revmap_size)
570 return domain->linear_revmap[hwirq];
cc79ca69 571
d3dcb436
GL
572 rcu_read_lock();
573 data = radix_tree_lookup(&domain->revmap_tree, hwirq);
574 rcu_read_unlock();
575 return data ? data->irq : 0;
cc79ca69 576}
cc79ca69 577EXPORT_SYMBOL_GPL(irq_find_mapping);
cc79ca69 578
092b2fb0 579#ifdef CONFIG_IRQ_DOMAIN_DEBUG
cc79ca69
GL
580static int virq_debug_show(struct seq_file *m, void *private)
581{
582 unsigned long flags;
583 struct irq_desc *desc;
1400ea86
GL
584 struct irq_domain *domain;
585 struct radix_tree_iter iter;
586 void *data, **slot;
cc79ca69
GL
587 int i;
588
1400ea86
GL
589 seq_printf(m, " %-16s %-6s %-10s %-10s %s\n",
590 "name", "mapped", "linear-max", "direct-max", "devtree-node");
591 mutex_lock(&irq_domain_mutex);
592 list_for_each_entry(domain, &irq_domain_list, link) {
593 int count = 0;
594 radix_tree_for_each_slot(slot, &domain->revmap_tree, &iter, 0)
595 count++;
596 seq_printf(m, "%c%-16s %6u %10u %10u %s\n",
597 domain == irq_default_domain ? '*' : ' ', domain->name,
598 domain->revmap_size + count, domain->revmap_size,
599 domain->revmap_direct_max_irq,
600 domain->of_node ? of_node_full_name(domain->of_node) : "");
601 }
602 mutex_unlock(&irq_domain_mutex);
603
604 seq_printf(m, "%-5s %-7s %-15s %-*s %6s %-14s %s\n", "irq", "hwirq",
5269a9ab 605 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
1400ea86 606 "active", "type", "domain");
cc79ca69
GL
607
608 for (i = 1; i < nr_irqs; i++) {
609 desc = irq_to_desc(i);
610 if (!desc)
611 continue;
612
613 raw_spin_lock_irqsave(&desc->lock, flags);
1400ea86 614 domain = desc->irq_data.domain;
cc79ca69 615
1400ea86 616 if (domain) {
cc79ca69 617 struct irq_chip *chip;
1400ea86
GL
618 int hwirq = desc->irq_data.hwirq;
619 bool direct;
cc79ca69
GL
620
621 seq_printf(m, "%5d ", i);
1400ea86 622 seq_printf(m, "0x%05x ", hwirq);
cc79ca69
GL
623
624 chip = irq_desc_get_chip(desc);
0bb4afb4 625 seq_printf(m, "%-15s ", (chip && chip->name) ? chip->name : "none");
cc79ca69
GL
626
627 data = irq_desc_get_chip_data(desc);
15e06bf6 628 seq_printf(m, data ? "0x%p " : " %p ", data);
cc79ca69 629
1400ea86
GL
630 seq_printf(m, " %c ", (desc->action && desc->action->handler) ? '*' : ' ');
631 direct = (i == hwirq) && (i < domain->revmap_direct_max_irq);
632 seq_printf(m, "%6s%-8s ",
633 (hwirq < domain->revmap_size) ? "LINEAR" : "RADIX",
634 direct ? "(DIRECT)" : "");
0bb4afb4 635 seq_printf(m, "%s\n", desc->irq_data.domain->name);
cc79ca69
GL
636 }
637
638 raw_spin_unlock_irqrestore(&desc->lock, flags);
639 }
640
641 return 0;
642}
643
644static int virq_debug_open(struct inode *inode, struct file *file)
645{
646 return single_open(file, virq_debug_show, inode->i_private);
647}
648
649static const struct file_operations virq_debug_fops = {
650 .open = virq_debug_open,
651 .read = seq_read,
652 .llseek = seq_lseek,
653 .release = single_release,
654};
655
656static int __init irq_debugfs_init(void)
657{
092b2fb0 658 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
cc79ca69
GL
659 NULL, &virq_debug_fops) == NULL)
660 return -ENOMEM;
661
662 return 0;
663}
664__initcall(irq_debugfs_init);
092b2fb0 665#endif /* CONFIG_IRQ_DOMAIN_DEBUG */
cc79ca69 666
16b2e6e2
GL
667/**
668 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
669 *
670 * Device Tree IRQ specifier translation function which works with one cell
671 * bindings where the cell value maps directly to the hwirq number.
672 */
673int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
674 const u32 *intspec, unsigned int intsize,
675 unsigned long *out_hwirq, unsigned int *out_type)
7e713301 676{
16b2e6e2 677 if (WARN_ON(intsize < 1))
7e713301 678 return -EINVAL;
7e713301
GL
679 *out_hwirq = intspec[0];
680 *out_type = IRQ_TYPE_NONE;
7e713301
GL
681 return 0;
682}
16b2e6e2
GL
683EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
684
685/**
686 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
687 *
688 * Device Tree IRQ specifier translation function which works with two cell
689 * bindings where the cell values map directly to the hwirq number
690 * and linux irq flags.
691 */
692int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
693 const u32 *intspec, unsigned int intsize,
694 irq_hw_number_t *out_hwirq, unsigned int *out_type)
695{
696 if (WARN_ON(intsize < 2))
697 return -EINVAL;
698 *out_hwirq = intspec[0];
699 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
700 return 0;
701}
702EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
703
704/**
705 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
706 *
707 * Device Tree IRQ specifier translation function which works with either one
708 * or two cell bindings where the cell values map directly to the hwirq number
709 * and linux irq flags.
710 *
711 * Note: don't use this function unless your interrupt controller explicitly
712 * supports both one and two cell bindings. For the majority of controllers
713 * the _onecell() or _twocell() variants above should be used.
714 */
715int irq_domain_xlate_onetwocell(struct irq_domain *d,
716 struct device_node *ctrlr,
717 const u32 *intspec, unsigned int intsize,
718 unsigned long *out_hwirq, unsigned int *out_type)
719{
720 if (WARN_ON(intsize < 1))
721 return -EINVAL;
722 *out_hwirq = intspec[0];
723 *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
724 return 0;
725}
726EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
7e713301 727
a18dc81b 728const struct irq_domain_ops irq_domain_simple_ops = {
16b2e6e2 729 .xlate = irq_domain_xlate_onetwocell,
75294957
GL
730};
731EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
f8264e34
JL
732
733static int irq_domain_alloc_descs(int virq, unsigned int cnt,
734 irq_hw_number_t hwirq, int node)
735{
736 unsigned int hint;
737
738 if (virq >= 0) {
739 virq = irq_alloc_descs(virq, virq, cnt, node);
740 } else {
741 hint = hwirq % nr_irqs;
742 if (hint == 0)
743 hint++;
744 virq = irq_alloc_descs_from(hint, cnt, node);
745 if (virq <= 0 && hint > 1)
746 virq = irq_alloc_descs_from(1, cnt, node);
747 }
748
749 return virq;
750}
751
752#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
afb7da83
JL
753/**
754 * irq_domain_add_hierarchy - Add a irqdomain into the hierarchy
755 * @parent: Parent irq domain to associate with the new domain
756 * @flags: Irq domain flags associated to the domain
757 * @size: Size of the domain. See below
758 * @node: Optional device-tree node of the interrupt controller
759 * @ops: Pointer to the interrupt domain callbacks
760 * @host_data: Controller private data pointer
761 *
762 * If @size is 0 a tree domain is created, otherwise a linear domain.
763 *
764 * If successful the parent is associated to the new domain and the
765 * domain flags are set.
766 * Returns pointer to IRQ domain, or NULL on failure.
767 */
768struct irq_domain *irq_domain_add_hierarchy(struct irq_domain *parent,
769 unsigned int flags,
770 unsigned int size,
771 struct device_node *node,
772 const struct irq_domain_ops *ops,
773 void *host_data)
774{
775 struct irq_domain *domain;
776
777 if (size)
778 domain = irq_domain_add_linear(node, size, ops, host_data);
779 else
780 domain = irq_domain_add_tree(node, ops, host_data);
781 if (domain) {
782 domain->parent = parent;
783 domain->flags |= flags;
784 }
785
786 return domain;
787}
788
f8264e34
JL
789static void irq_domain_insert_irq(int virq)
790{
791 struct irq_data *data;
792
793 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
794 struct irq_domain *domain = data->domain;
795 irq_hw_number_t hwirq = data->hwirq;
796
797 if (hwirq < domain->revmap_size) {
798 domain->linear_revmap[hwirq] = virq;
799 } else {
800 mutex_lock(&revmap_trees_mutex);
801 radix_tree_insert(&domain->revmap_tree, hwirq, data);
802 mutex_unlock(&revmap_trees_mutex);
803 }
804
805 /* If not already assigned, give the domain the chip's name */
806 if (!domain->name && data->chip)
807 domain->name = data->chip->name;
808 }
809
810 irq_clear_status_flags(virq, IRQ_NOREQUEST);
811}
812
813static void irq_domain_remove_irq(int virq)
814{
815 struct irq_data *data;
816
817 irq_set_status_flags(virq, IRQ_NOREQUEST);
818 irq_set_chip_and_handler(virq, NULL, NULL);
819 synchronize_irq(virq);
820 smp_mb();
821
822 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
823 struct irq_domain *domain = data->domain;
824 irq_hw_number_t hwirq = data->hwirq;
825
826 if (hwirq < domain->revmap_size) {
827 domain->linear_revmap[hwirq] = 0;
828 } else {
829 mutex_lock(&revmap_trees_mutex);
830 radix_tree_delete(&domain->revmap_tree, hwirq);
831 mutex_unlock(&revmap_trees_mutex);
832 }
833 }
834}
835
836static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain,
837 struct irq_data *child)
838{
839 struct irq_data *irq_data;
840
6783011b
JL
841 irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL,
842 irq_data_get_node(child));
f8264e34
JL
843 if (irq_data) {
844 child->parent_data = irq_data;
845 irq_data->irq = child->irq;
0d0b4c86 846 irq_data->common = child->common;
f8264e34
JL
847 irq_data->domain = domain;
848 }
849
850 return irq_data;
851}
852
853static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs)
854{
855 struct irq_data *irq_data, *tmp;
856 int i;
857
858 for (i = 0; i < nr_irqs; i++) {
859 irq_data = irq_get_irq_data(virq + i);
860 tmp = irq_data->parent_data;
861 irq_data->parent_data = NULL;
862 irq_data->domain = NULL;
863
864 while (tmp) {
865 irq_data = tmp;
866 tmp = tmp->parent_data;
867 kfree(irq_data);
868 }
869 }
870}
871
872static int irq_domain_alloc_irq_data(struct irq_domain *domain,
873 unsigned int virq, unsigned int nr_irqs)
874{
875 struct irq_data *irq_data;
876 struct irq_domain *parent;
877 int i;
878
879 /* The outermost irq_data is embedded in struct irq_desc */
880 for (i = 0; i < nr_irqs; i++) {
881 irq_data = irq_get_irq_data(virq + i);
882 irq_data->domain = domain;
883
884 for (parent = domain->parent; parent; parent = parent->parent) {
885 irq_data = irq_domain_insert_irq_data(parent, irq_data);
886 if (!irq_data) {
887 irq_domain_free_irq_data(virq, i + 1);
888 return -ENOMEM;
889 }
890 }
891 }
892
893 return 0;
894}
895
896/**
897 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
898 * @domain: domain to match
899 * @virq: IRQ number to get irq_data
900 */
901struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
902 unsigned int virq)
903{
904 struct irq_data *irq_data;
905
906 for (irq_data = irq_get_irq_data(virq); irq_data;
907 irq_data = irq_data->parent_data)
908 if (irq_data->domain == domain)
909 return irq_data;
910
911 return NULL;
912}
913
914/**
915 * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain
916 * @domain: Interrupt domain to match
917 * @virq: IRQ number
918 * @hwirq: The hwirq number
919 * @chip: The associated interrupt chip
920 * @chip_data: The associated chip data
921 */
922int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
923 irq_hw_number_t hwirq, struct irq_chip *chip,
924 void *chip_data)
925{
926 struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
927
928 if (!irq_data)
929 return -ENOENT;
930
931 irq_data->hwirq = hwirq;
932 irq_data->chip = chip ? chip : &no_irq_chip;
933 irq_data->chip_data = chip_data;
934
935 return 0;
936}
937
1b537708
JL
938/**
939 * irq_domain_set_info - Set the complete data for a @virq in @domain
940 * @domain: Interrupt domain to match
941 * @virq: IRQ number
942 * @hwirq: The hardware interrupt number
943 * @chip: The associated interrupt chip
944 * @chip_data: The associated interrupt chip data
945 * @handler: The interrupt flow handler
946 * @handler_data: The interrupt flow handler data
947 * @handler_name: The interrupt handler name
948 */
949void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
950 irq_hw_number_t hwirq, struct irq_chip *chip,
951 void *chip_data, irq_flow_handler_t handler,
952 void *handler_data, const char *handler_name)
953{
954 irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data);
955 __irq_set_handler(virq, handler, 0, handler_name);
956 irq_set_handler_data(virq, handler_data);
957}
958
f8264e34
JL
959/**
960 * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data
961 * @irq_data: The pointer to irq_data
962 */
963void irq_domain_reset_irq_data(struct irq_data *irq_data)
964{
965 irq_data->hwirq = 0;
966 irq_data->chip = &no_irq_chip;
967 irq_data->chip_data = NULL;
968}
969
970/**
971 * irq_domain_free_irqs_common - Clear irq_data and free the parent
972 * @domain: Interrupt domain to match
973 * @virq: IRQ number to start with
974 * @nr_irqs: The number of irqs to free
975 */
976void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq,
977 unsigned int nr_irqs)
978{
979 struct irq_data *irq_data;
980 int i;
981
982 for (i = 0; i < nr_irqs; i++) {
983 irq_data = irq_domain_get_irq_data(domain, virq + i);
984 if (irq_data)
985 irq_domain_reset_irq_data(irq_data);
986 }
987 irq_domain_free_irqs_parent(domain, virq, nr_irqs);
988}
989
990/**
991 * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent
992 * @domain: Interrupt domain to match
993 * @virq: IRQ number to start with
994 * @nr_irqs: The number of irqs to free
995 */
996void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq,
997 unsigned int nr_irqs)
998{
999 int i;
1000
1001 for (i = 0; i < nr_irqs; i++) {
1002 irq_set_handler_data(virq + i, NULL);
1003 irq_set_handler(virq + i, NULL);
1004 }
1005 irq_domain_free_irqs_common(domain, virq, nr_irqs);
1006}
1007
36d72731
JL
1008static bool irq_domain_is_auto_recursive(struct irq_domain *domain)
1009{
1010 return domain->flags & IRQ_DOMAIN_FLAG_AUTO_RECURSIVE;
1011}
1012
1013static void irq_domain_free_irqs_recursive(struct irq_domain *domain,
1014 unsigned int irq_base,
1015 unsigned int nr_irqs)
1016{
1017 domain->ops->free(domain, irq_base, nr_irqs);
1018 if (irq_domain_is_auto_recursive(domain)) {
1019 BUG_ON(!domain->parent);
1020 irq_domain_free_irqs_recursive(domain->parent, irq_base,
1021 nr_irqs);
1022 }
1023}
1024
1025static int irq_domain_alloc_irqs_recursive(struct irq_domain *domain,
1026 unsigned int irq_base,
1027 unsigned int nr_irqs, void *arg)
1028{
1029 int ret = 0;
1030 struct irq_domain *parent = domain->parent;
1031 bool recursive = irq_domain_is_auto_recursive(domain);
1032
1033 BUG_ON(recursive && !parent);
1034 if (recursive)
1035 ret = irq_domain_alloc_irqs_recursive(parent, irq_base,
1036 nr_irqs, arg);
1037 if (ret >= 0)
1038 ret = domain->ops->alloc(domain, irq_base, nr_irqs, arg);
1039 if (ret < 0 && recursive)
1040 irq_domain_free_irqs_recursive(parent, irq_base, nr_irqs);
1041
1042 return ret;
1043}
1044
f8264e34
JL
1045/**
1046 * __irq_domain_alloc_irqs - Allocate IRQs from domain
1047 * @domain: domain to allocate from
1048 * @irq_base: allocate specified IRQ nubmer if irq_base >= 0
1049 * @nr_irqs: number of IRQs to allocate
1050 * @node: NUMA node id for memory allocation
1051 * @arg: domain specific argument
1052 * @realloc: IRQ descriptors have already been allocated if true
1053 *
1054 * Allocate IRQ numbers and initialized all data structures to support
1055 * hierarchy IRQ domains.
1056 * Parameter @realloc is mainly to support legacy IRQs.
1057 * Returns error code or allocated IRQ number
1058 *
1059 * The whole process to setup an IRQ has been split into two steps.
1060 * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
1061 * descriptor and required hardware resources. The second step,
1062 * irq_domain_activate_irq(), is to program hardwares with preallocated
1063 * resources. In this way, it's easier to rollback when failing to
1064 * allocate resources.
1065 */
1066int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
1067 unsigned int nr_irqs, int node, void *arg,
1068 bool realloc)
1069{
1070 int i, ret, virq;
1071
1072 if (domain == NULL) {
1073 domain = irq_default_domain;
1074 if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
1075 return -EINVAL;
1076 }
1077
1078 if (!domain->ops->alloc) {
1079 pr_debug("domain->ops->alloc() is NULL\n");
1080 return -ENOSYS;
1081 }
1082
1083 if (realloc && irq_base >= 0) {
1084 virq = irq_base;
1085 } else {
1086 virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node);
1087 if (virq < 0) {
1088 pr_debug("cannot allocate IRQ(base %d, count %d)\n",
1089 irq_base, nr_irqs);
1090 return virq;
1091 }
1092 }
1093
1094 if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) {
1095 pr_debug("cannot allocate memory for IRQ%d\n", virq);
1096 ret = -ENOMEM;
1097 goto out_free_desc;
1098 }
1099
1100 mutex_lock(&irq_domain_mutex);
36d72731 1101 ret = irq_domain_alloc_irqs_recursive(domain, virq, nr_irqs, arg);
f8264e34
JL
1102 if (ret < 0) {
1103 mutex_unlock(&irq_domain_mutex);
1104 goto out_free_irq_data;
1105 }
1106 for (i = 0; i < nr_irqs; i++)
1107 irq_domain_insert_irq(virq + i);
1108 mutex_unlock(&irq_domain_mutex);
1109
1110 return virq;
1111
1112out_free_irq_data:
1113 irq_domain_free_irq_data(virq, nr_irqs);
1114out_free_desc:
1115 irq_free_descs(virq, nr_irqs);
1116 return ret;
1117}
1118
1119/**
1120 * irq_domain_free_irqs - Free IRQ number and associated data structures
1121 * @virq: base IRQ number
1122 * @nr_irqs: number of IRQs to free
1123 */
1124void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs)
1125{
1126 struct irq_data *data = irq_get_irq_data(virq);
1127 int i;
1128
1129 if (WARN(!data || !data->domain || !data->domain->ops->free,
1130 "NULL pointer, cannot free irq\n"))
1131 return;
1132
1133 mutex_lock(&irq_domain_mutex);
1134 for (i = 0; i < nr_irqs; i++)
1135 irq_domain_remove_irq(virq + i);
36d72731 1136 irq_domain_free_irqs_recursive(data->domain, virq, nr_irqs);
f8264e34
JL
1137 mutex_unlock(&irq_domain_mutex);
1138
1139 irq_domain_free_irq_data(virq, nr_irqs);
1140 irq_free_descs(virq, nr_irqs);
1141}
1142
36d72731
JL
1143/**
1144 * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain
1145 * @irq_base: Base IRQ number
1146 * @nr_irqs: Number of IRQs to allocate
1147 * @arg: Allocation data (arch/domain specific)
1148 *
1149 * Check whether the domain has been setup recursive. If not allocate
1150 * through the parent domain.
1151 */
1152int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
1153 unsigned int irq_base, unsigned int nr_irqs,
1154 void *arg)
1155{
1156 /* irq_domain_alloc_irqs_recursive() has called parent's alloc() */
1157 if (irq_domain_is_auto_recursive(domain))
1158 return 0;
1159
1160 domain = domain->parent;
1161 if (domain)
1162 return irq_domain_alloc_irqs_recursive(domain, irq_base,
1163 nr_irqs, arg);
1164 return -ENOSYS;
1165}
1166
1167/**
1168 * irq_domain_free_irqs_parent - Free interrupts from parent domain
1169 * @irq_base: Base IRQ number
1170 * @nr_irqs: Number of IRQs to free
1171 *
1172 * Check whether the domain has been setup recursive. If not free
1173 * through the parent domain.
1174 */
1175void irq_domain_free_irqs_parent(struct irq_domain *domain,
1176 unsigned int irq_base, unsigned int nr_irqs)
1177{
1178 /* irq_domain_free_irqs_recursive() will call parent's free */
1179 if (!irq_domain_is_auto_recursive(domain) && domain->parent)
1180 irq_domain_free_irqs_recursive(domain->parent, irq_base,
1181 nr_irqs);
1182}
1183
f8264e34
JL
1184/**
1185 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
1186 * interrupt
1187 * @irq_data: outermost irq_data associated with interrupt
1188 *
1189 * This is the second step to call domain_ops->activate to program interrupt
1190 * controllers, so the interrupt could actually get delivered.
1191 */
1192void irq_domain_activate_irq(struct irq_data *irq_data)
1193{
1194 if (irq_data && irq_data->domain) {
1195 struct irq_domain *domain = irq_data->domain;
1196
1197 if (irq_data->parent_data)
1198 irq_domain_activate_irq(irq_data->parent_data);
1199 if (domain->ops->activate)
1200 domain->ops->activate(domain, irq_data);
1201 }
1202}
1203
1204/**
1205 * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to
1206 * deactivate interrupt
1207 * @irq_data: outermost irq_data associated with interrupt
1208 *
1209 * It calls domain_ops->deactivate to program interrupt controllers to disable
1210 * interrupt delivery.
1211 */
1212void irq_domain_deactivate_irq(struct irq_data *irq_data)
1213{
1214 if (irq_data && irq_data->domain) {
1215 struct irq_domain *domain = irq_data->domain;
1216
1217 if (domain->ops->deactivate)
1218 domain->ops->deactivate(domain, irq_data);
1219 if (irq_data->parent_data)
1220 irq_domain_deactivate_irq(irq_data->parent_data);
1221 }
1222}
1223
1224static void irq_domain_check_hierarchy(struct irq_domain *domain)
1225{
1226 /* Hierarchy irq_domains must implement callback alloc() */
1227 if (domain->ops->alloc)
1228 domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
1229}
1230#else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
1231/**
1232 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
1233 * @domain: domain to match
1234 * @virq: IRQ number to get irq_data
1235 */
1236struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
1237 unsigned int virq)
1238{
1239 struct irq_data *irq_data = irq_get_irq_data(virq);
1240
1241 return (irq_data && irq_data->domain == domain) ? irq_data : NULL;
1242}
1243
5f22f5c6
SA
1244/**
1245 * irq_domain_set_info - Set the complete data for a @virq in @domain
1246 * @domain: Interrupt domain to match
1247 * @virq: IRQ number
1248 * @hwirq: The hardware interrupt number
1249 * @chip: The associated interrupt chip
1250 * @chip_data: The associated interrupt chip data
1251 * @handler: The interrupt flow handler
1252 * @handler_data: The interrupt flow handler data
1253 * @handler_name: The interrupt handler name
1254 */
1255void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
1256 irq_hw_number_t hwirq, struct irq_chip *chip,
1257 void *chip_data, irq_flow_handler_t handler,
1258 void *handler_data, const char *handler_name)
1259{
1260 irq_set_chip_and_handler_name(virq, chip, handler, handler_name);
1261 irq_set_chip_data(virq, chip_data);
1262 irq_set_handler_data(virq, handler_data);
1263}
1264
f8264e34
JL
1265static void irq_domain_check_hierarchy(struct irq_domain *domain)
1266{
1267}
1268#endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */
This page took 0.232847 seconds and 5 git commands to generate.