1 // SPDX-License-Identifier: GPL-2.0
3 #define pr_fmt(fmt) "irq: " fmt
5 #include <linux/acpi.h>
6 #include <linux/debugfs.h>
7 #include <linux/hardirq.h>
8 #include <linux/interrupt.h>
10 #include <linux/irqdesc.h>
11 #include <linux/irqdomain.h>
12 #include <linux/module.h>
13 #include <linux/mutex.h>
15 #include <linux/of_address.h>
16 #include <linux/of_irq.h>
17 #include <linux/topology.h>
18 #include <linux/seq_file.h>
19 #include <linux/slab.h>
20 #include <linux/smp.h>
23 static LIST_HEAD(irq_domain_list);
24 static DEFINE_MUTEX(irq_domain_mutex);
26 static struct irq_domain *irq_default_domain;
28 static void irq_domain_check_hierarchy(struct irq_domain *domain);
31 struct fwnode_handle fwnode;
37 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
38 static void debugfs_add_domain_dir(struct irq_domain *d);
39 static void debugfs_remove_domain_dir(struct irq_domain *d);
41 static inline void debugfs_add_domain_dir(struct irq_domain *d) { }
42 static inline void debugfs_remove_domain_dir(struct irq_domain *d) { }
45 const struct fwnode_operations irqchip_fwnode_ops;
46 EXPORT_SYMBOL_GPL(irqchip_fwnode_ops);
49 * irq_domain_alloc_fwnode - Allocate a fwnode_handle suitable for
50 * identifying an irq domain
51 * @type: Type of irqchip_fwnode. See linux/irqdomain.h
52 * @name: Optional user provided domain name
53 * @id: Optional user provided id if name != NULL
54 * @data: Optional user-provided data
56 * Allocate a struct irqchip_fwid, and return a poiner to the embedded
57 * fwnode_handle (or NULL on failure).
59 * Note: The types IRQCHIP_FWNODE_NAMED and IRQCHIP_FWNODE_NAMED_ID are
60 * solely to transport name information to irqdomain creation code. The
61 * node is not stored. For other types the pointer is kept in the irq
64 struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
65 const char *name, void *data)
67 struct irqchip_fwid *fwid;
70 fwid = kzalloc(sizeof(*fwid), GFP_KERNEL);
73 case IRQCHIP_FWNODE_NAMED:
74 n = kasprintf(GFP_KERNEL, "%s", name);
76 case IRQCHIP_FWNODE_NAMED_ID:
77 n = kasprintf(GFP_KERNEL, "%s-%d", name, id);
80 n = kasprintf(GFP_KERNEL, "irqchip@%p", data);
93 fwid->fwnode.ops = &irqchip_fwnode_ops;
96 EXPORT_SYMBOL_GPL(__irq_domain_alloc_fwnode);
99 * irq_domain_free_fwnode - Free a non-OF-backed fwnode_handle
101 * Free a fwnode_handle allocated with irq_domain_alloc_fwnode.
103 void irq_domain_free_fwnode(struct fwnode_handle *fwnode)
105 struct irqchip_fwid *fwid;
107 if (WARN_ON(!is_fwnode_irqchip(fwnode)))
110 fwid = container_of(fwnode, struct irqchip_fwid, fwnode);
114 EXPORT_SYMBOL_GPL(irq_domain_free_fwnode);
117 * __irq_domain_add() - Allocate a new irq_domain data structure
118 * @fwnode: firmware node for the interrupt controller
119 * @size: Size of linear map; 0 for radix mapping only
120 * @hwirq_max: Maximum number of interrupts supported by controller
121 * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
123 * @ops: domain callbacks
124 * @host_data: Controller private data pointer
126 * Allocates and initialize and irq_domain structure.
127 * Returns pointer to IRQ domain, or NULL on failure.
129 struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, int size,
130 irq_hw_number_t hwirq_max, int direct_max,
131 const struct irq_domain_ops *ops,
134 struct device_node *of_node = to_of_node(fwnode);
135 struct irqchip_fwid *fwid;
136 struct irq_domain *domain;
138 static atomic_t unknown_domains;
140 domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
141 GFP_KERNEL, of_node_to_nid(of_node));
142 if (WARN_ON(!domain))
145 if (fwnode && is_fwnode_irqchip(fwnode)) {
146 fwid = container_of(fwnode, struct irqchip_fwid, fwnode);
148 switch (fwid->type) {
149 case IRQCHIP_FWNODE_NAMED:
150 case IRQCHIP_FWNODE_NAMED_ID:
151 domain->fwnode = fwnode;
152 domain->name = kstrdup(fwid->name, GFP_KERNEL);
157 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
160 domain->fwnode = fwnode;
161 domain->name = fwid->name;
165 } else if (is_acpi_device_node(fwnode)) {
166 struct acpi_buffer buf = {
167 .length = ACPI_ALLOCATE_BUFFER,
171 handle = acpi_device_handle(to_acpi_device_node(fwnode));
172 if (acpi_get_name(handle, ACPI_FULL_PATHNAME, &buf) == AE_OK) {
173 domain->name = buf.pointer;
174 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
177 domain->fwnode = fwnode;
179 } else if (of_node) {
183 * DT paths contain '/', which debugfs is legitimately
184 * unhappy about. Replace them with ':', which does
185 * the trick and is not as offensive as '\'...
187 name = kasprintf(GFP_KERNEL, "%pOF", of_node);
193 strreplace(name, '/', ':');
196 domain->fwnode = fwnode;
197 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
202 pr_err("Invalid fwnode type for irqdomain\n");
203 domain->name = kasprintf(GFP_KERNEL, "unknown-%d",
204 atomic_inc_return(&unknown_domains));
209 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
212 of_node_get(of_node);
215 INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
216 mutex_init(&domain->revmap_tree_mutex);
218 domain->host_data = host_data;
219 domain->hwirq_max = hwirq_max;
220 domain->revmap_size = size;
221 domain->revmap_direct_max_irq = direct_max;
222 irq_domain_check_hierarchy(domain);
224 mutex_lock(&irq_domain_mutex);
225 debugfs_add_domain_dir(domain);
226 list_add(&domain->link, &irq_domain_list);
227 mutex_unlock(&irq_domain_mutex);
229 pr_debug("Added domain %s\n", domain->name);
232 EXPORT_SYMBOL_GPL(__irq_domain_add);
235 * irq_domain_remove() - Remove an irq domain.
236 * @domain: domain to remove
238 * This routine is used to remove an irq domain. The caller must ensure
239 * that all mappings within the domain have been disposed of prior to
240 * use, depending on the revmap type.
242 void irq_domain_remove(struct irq_domain *domain)
244 mutex_lock(&irq_domain_mutex);
245 debugfs_remove_domain_dir(domain);
247 WARN_ON(!radix_tree_empty(&domain->revmap_tree));
249 list_del(&domain->link);
252 * If the going away domain is the default one, reset it.
254 if (unlikely(irq_default_domain == domain))
255 irq_set_default_host(NULL);
257 mutex_unlock(&irq_domain_mutex);
259 pr_debug("Removed domain %s\n", domain->name);
261 of_node_put(irq_domain_get_of_node(domain));
262 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED)
266 EXPORT_SYMBOL_GPL(irq_domain_remove);
268 void irq_domain_update_bus_token(struct irq_domain *domain,
269 enum irq_domain_bus_token bus_token)
273 if (domain->bus_token == bus_token)
276 mutex_lock(&irq_domain_mutex);
278 domain->bus_token = bus_token;
280 name = kasprintf(GFP_KERNEL, "%s-%d", domain->name, bus_token);
282 mutex_unlock(&irq_domain_mutex);
286 debugfs_remove_domain_dir(domain);
288 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED)
291 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
294 debugfs_add_domain_dir(domain);
296 mutex_unlock(&irq_domain_mutex);
300 * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
301 * @of_node: pointer to interrupt controller's device tree node.
302 * @size: total number of irqs in mapping
303 * @first_irq: first number of irq block assigned to the domain,
304 * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
305 * pre-map all of the irqs in the domain to virqs starting at first_irq.
306 * @ops: domain callbacks
307 * @host_data: Controller private data pointer
309 * Allocates an irq_domain, and optionally if first_irq is positive then also
310 * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
312 * This is intended to implement the expected behaviour for most
313 * interrupt controllers. If device tree is used, then first_irq will be 0 and
314 * irqs get mapped dynamically on the fly. However, if the controller requires
315 * static virq assignments (non-DT boot) then it will set that up correctly.
317 struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
319 unsigned int first_irq,
320 const struct irq_domain_ops *ops,
323 struct irq_domain *domain;
325 domain = __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data);
330 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
331 /* attempt to allocated irq_descs */
332 int rc = irq_alloc_descs(first_irq, first_irq, size,
333 of_node_to_nid(of_node));
335 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
338 irq_domain_associate_many(domain, first_irq, 0, size);
343 EXPORT_SYMBOL_GPL(irq_domain_add_simple);
346 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
347 * @of_node: pointer to interrupt controller's device tree node.
348 * @size: total number of irqs in legacy mapping
349 * @first_irq: first number of irq block assigned to the domain
350 * @first_hwirq: first hwirq number to use for the translation. Should normally
351 * be '0', but a positive integer can be used if the effective
352 * hwirqs numbering does not begin at zero.
353 * @ops: map/unmap domain callbacks
354 * @host_data: Controller private data pointer
356 * Note: the map() callback will be called before this function returns
357 * for all legacy interrupts except 0 (which is always the invalid irq for
358 * a legacy controller).
360 struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
362 unsigned int first_irq,
363 irq_hw_number_t first_hwirq,
364 const struct irq_domain_ops *ops,
367 struct irq_domain *domain;
369 domain = __irq_domain_add(of_node_to_fwnode(of_node), first_hwirq + size,
370 first_hwirq + size, 0, ops, host_data);
372 irq_domain_associate_many(domain, first_irq, first_hwirq, size);
376 EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
379 * irq_find_matching_fwspec() - Locates a domain for a given fwspec
380 * @fwspec: FW specifier for an interrupt
381 * @bus_token: domain-specific data
383 struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
384 enum irq_domain_bus_token bus_token)
386 struct irq_domain *h, *found = NULL;
387 struct fwnode_handle *fwnode = fwspec->fwnode;
390 /* We might want to match the legacy controller last since
391 * it might potentially be set to match all interrupts in
392 * the absence of a device node. This isn't a problem so far
395 * bus_token == DOMAIN_BUS_ANY matches any domain, any other
396 * values must generate an exact match for the domain to be
399 mutex_lock(&irq_domain_mutex);
400 list_for_each_entry(h, &irq_domain_list, link) {
401 if (h->ops->select && fwspec->param_count)
402 rc = h->ops->select(h, fwspec, bus_token);
403 else if (h->ops->match)
404 rc = h->ops->match(h, to_of_node(fwnode), bus_token);
406 rc = ((fwnode != NULL) && (h->fwnode == fwnode) &&
407 ((bus_token == DOMAIN_BUS_ANY) ||
408 (h->bus_token == bus_token)));
415 mutex_unlock(&irq_domain_mutex);
418 EXPORT_SYMBOL_GPL(irq_find_matching_fwspec);
421 * irq_domain_check_msi_remap - Check whether all MSI irq domains implement
424 * Return: false if any MSI irq domain does not support IRQ remapping,
425 * true otherwise (including if there is no MSI irq domain)
427 bool irq_domain_check_msi_remap(void)
429 struct irq_domain *h;
432 mutex_lock(&irq_domain_mutex);
433 list_for_each_entry(h, &irq_domain_list, link) {
434 if (irq_domain_is_msi(h) &&
435 !irq_domain_hierarchical_is_msi_remap(h)) {
440 mutex_unlock(&irq_domain_mutex);
443 EXPORT_SYMBOL_GPL(irq_domain_check_msi_remap);
446 * irq_set_default_host() - Set a "default" irq domain
447 * @domain: default domain pointer
449 * For convenience, it's possible to set a "default" domain that will be used
450 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
451 * platforms that want to manipulate a few hard coded interrupt numbers that
452 * aren't properly represented in the device-tree.
454 void irq_set_default_host(struct irq_domain *domain)
456 pr_debug("Default domain set to @0x%p\n", domain);
458 irq_default_domain = domain;
460 EXPORT_SYMBOL_GPL(irq_set_default_host);
462 static void irq_domain_clear_mapping(struct irq_domain *domain,
463 irq_hw_number_t hwirq)
465 if (hwirq < domain->revmap_size) {
466 domain->linear_revmap[hwirq] = 0;
468 mutex_lock(&domain->revmap_tree_mutex);
469 radix_tree_delete(&domain->revmap_tree, hwirq);
470 mutex_unlock(&domain->revmap_tree_mutex);
474 static void irq_domain_set_mapping(struct irq_domain *domain,
475 irq_hw_number_t hwirq,
476 struct irq_data *irq_data)
478 if (hwirq < domain->revmap_size) {
479 domain->linear_revmap[hwirq] = irq_data->irq;
481 mutex_lock(&domain->revmap_tree_mutex);
482 radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
483 mutex_unlock(&domain->revmap_tree_mutex);
487 void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
489 struct irq_data *irq_data = irq_get_irq_data(irq);
490 irq_hw_number_t hwirq;
492 if (WARN(!irq_data || irq_data->domain != domain,
493 "virq%i doesn't exist; cannot disassociate\n", irq))
496 hwirq = irq_data->hwirq;
497 irq_set_status_flags(irq, IRQ_NOREQUEST);
499 /* remove chip and handler */
500 irq_set_chip_and_handler(irq, NULL, NULL);
502 /* Make sure it's completed */
503 synchronize_irq(irq);
505 /* Tell the PIC about it */
506 if (domain->ops->unmap)
507 domain->ops->unmap(domain, irq);
510 irq_data->domain = NULL;
514 /* Clear reverse map for this hwirq */
515 irq_domain_clear_mapping(domain, hwirq);
518 int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
519 irq_hw_number_t hwirq)
521 struct irq_data *irq_data = irq_get_irq_data(virq);
524 if (WARN(hwirq >= domain->hwirq_max,
525 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
527 if (WARN(!irq_data, "error: virq%i is not allocated", virq))
529 if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
532 mutex_lock(&irq_domain_mutex);
533 irq_data->hwirq = hwirq;
534 irq_data->domain = domain;
535 if (domain->ops->map) {
536 ret = domain->ops->map(domain, virq, hwirq);
539 * If map() returns -EPERM, this interrupt is protected
540 * by the firmware or some other service and shall not
541 * be mapped. Don't bother telling the user about it.
544 pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
545 domain->name, hwirq, virq, ret);
547 irq_data->domain = NULL;
549 mutex_unlock(&irq_domain_mutex);
553 /* If not already assigned, give the domain the chip's name */
554 if (!domain->name && irq_data->chip)
555 domain->name = irq_data->chip->name;
559 irq_domain_set_mapping(domain, hwirq, irq_data);
560 mutex_unlock(&irq_domain_mutex);
562 irq_clear_status_flags(virq, IRQ_NOREQUEST);
566 EXPORT_SYMBOL_GPL(irq_domain_associate);
568 void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
569 irq_hw_number_t hwirq_base, int count)
571 struct device_node *of_node;
574 of_node = irq_domain_get_of_node(domain);
575 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
576 of_node_full_name(of_node), irq_base, (int)hwirq_base, count);
578 for (i = 0; i < count; i++) {
579 irq_domain_associate(domain, irq_base + i, hwirq_base + i);
582 EXPORT_SYMBOL_GPL(irq_domain_associate_many);
585 * irq_create_direct_mapping() - Allocate an irq for direct mapping
586 * @domain: domain to allocate the irq for or NULL for default domain
588 * This routine is used for irq controllers which can choose the hardware
589 * interrupt numbers they generate. In such a case it's simplest to use
590 * the linux irq as the hardware interrupt number. It still uses the linear
591 * or radix tree to store the mapping, but the irq controller can optimize
592 * the revmap path by using the hwirq directly.
594 unsigned int irq_create_direct_mapping(struct irq_domain *domain)
596 struct device_node *of_node;
600 domain = irq_default_domain;
602 of_node = irq_domain_get_of_node(domain);
603 virq = irq_alloc_desc_from(1, of_node_to_nid(of_node));
605 pr_debug("create_direct virq allocation failed\n");
608 if (virq >= domain->revmap_direct_max_irq) {
609 pr_err("ERROR: no free irqs available below %i maximum\n",
610 domain->revmap_direct_max_irq);
614 pr_debug("create_direct obtained virq %d\n", virq);
616 if (irq_domain_associate(domain, virq, virq)) {
623 EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
626 * irq_create_mapping() - Map a hardware interrupt into linux irq space
627 * @domain: domain owning this hardware interrupt or NULL for default domain
628 * @hwirq: hardware irq number in that domain space
630 * Only one mapping per hardware interrupt is permitted. Returns a linux
632 * If the sense/trigger is to be specified, set_irq_type() should be called
633 * on the number returned from that call.
635 unsigned int irq_create_mapping(struct irq_domain *domain,
636 irq_hw_number_t hwirq)
638 struct device_node *of_node;
641 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
643 /* Look for default domain if nececssary */
645 domain = irq_default_domain;
646 if (domain == NULL) {
647 WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
650 pr_debug("-> using domain @%p\n", domain);
652 of_node = irq_domain_get_of_node(domain);
654 /* Check if mapping already exists */
655 virq = irq_find_mapping(domain, hwirq);
657 pr_debug("-> existing mapping on virq %d\n", virq);
661 /* Allocate a virtual interrupt number */
662 virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(of_node), NULL);
664 pr_debug("-> virq allocation failed\n");
668 if (irq_domain_associate(domain, virq, hwirq)) {
673 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
674 hwirq, of_node_full_name(of_node), virq);
678 EXPORT_SYMBOL_GPL(irq_create_mapping);
681 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
682 * @domain: domain owning the interrupt range
683 * @irq_base: beginning of linux IRQ range
684 * @hwirq_base: beginning of hardware IRQ range
685 * @count: Number of interrupts to map
687 * This routine is used for allocating and mapping a range of hardware
688 * irqs to linux irqs where the linux irq numbers are at pre-defined
689 * locations. For use by controllers that already have static mappings
690 * to insert in to the domain.
692 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
695 * 0 is returned upon success, while any failure to establish a static
696 * mapping is treated as an error.
698 int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
699 irq_hw_number_t hwirq_base, int count)
701 struct device_node *of_node;
704 of_node = irq_domain_get_of_node(domain);
705 ret = irq_alloc_descs(irq_base, irq_base, count,
706 of_node_to_nid(of_node));
707 if (unlikely(ret < 0))
710 irq_domain_associate_many(domain, irq_base, hwirq_base, count);
713 EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
715 static int irq_domain_translate(struct irq_domain *d,
716 struct irq_fwspec *fwspec,
717 irq_hw_number_t *hwirq, unsigned int *type)
719 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
720 if (d->ops->translate)
721 return d->ops->translate(d, fwspec, hwirq, type);
724 return d->ops->xlate(d, to_of_node(fwspec->fwnode),
725 fwspec->param, fwspec->param_count,
728 /* If domain has no translation, then we assume interrupt line */
729 *hwirq = fwspec->param[0];
733 static void of_phandle_args_to_fwspec(struct of_phandle_args *irq_data,
734 struct irq_fwspec *fwspec)
738 fwspec->fwnode = irq_data->np ? &irq_data->np->fwnode : NULL;
739 fwspec->param_count = irq_data->args_count;
741 for (i = 0; i < irq_data->args_count; i++)
742 fwspec->param[i] = irq_data->args[i];
745 unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
747 struct irq_domain *domain;
748 struct irq_data *irq_data;
749 irq_hw_number_t hwirq;
750 unsigned int type = IRQ_TYPE_NONE;
753 if (fwspec->fwnode) {
754 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_WIRED);
756 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_ANY);
758 domain = irq_default_domain;
762 pr_warn("no irq domain found for %s !\n",
763 of_node_full_name(to_of_node(fwspec->fwnode)));
767 if (irq_domain_translate(domain, fwspec, &hwirq, &type))
771 * WARN if the irqchip returns a type with bits
772 * outside the sense mask set and clear these bits.
774 if (WARN_ON(type & ~IRQ_TYPE_SENSE_MASK))
775 type &= IRQ_TYPE_SENSE_MASK;
778 * If we've already configured this interrupt,
779 * don't do it again, or hell will break loose.
781 virq = irq_find_mapping(domain, hwirq);
784 * If the trigger type is not specified or matches the
785 * current trigger type then we are done so return the
788 if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq))
792 * If the trigger type has not been set yet, then set
793 * it now and return the interrupt number.
795 if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) {
796 irq_data = irq_get_irq_data(virq);
800 irqd_set_trigger_type(irq_data, type);
804 pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n",
805 hwirq, of_node_full_name(to_of_node(fwspec->fwnode)));
809 if (irq_domain_is_hierarchy(domain)) {
810 virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, fwspec);
815 virq = irq_create_mapping(domain, hwirq);
820 irq_data = irq_get_irq_data(virq);
822 if (irq_domain_is_hierarchy(domain))
823 irq_domain_free_irqs(virq, 1);
825 irq_dispose_mapping(virq);
829 /* Store trigger type */
830 irqd_set_trigger_type(irq_data, type);
834 EXPORT_SYMBOL_GPL(irq_create_fwspec_mapping);
836 unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
838 struct irq_fwspec fwspec;
840 of_phandle_args_to_fwspec(irq_data, &fwspec);
841 return irq_create_fwspec_mapping(&fwspec);
843 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
846 * irq_dispose_mapping() - Unmap an interrupt
847 * @virq: linux irq number of the interrupt to unmap
849 void irq_dispose_mapping(unsigned int virq)
851 struct irq_data *irq_data = irq_get_irq_data(virq);
852 struct irq_domain *domain;
854 if (!virq || !irq_data)
857 domain = irq_data->domain;
858 if (WARN_ON(domain == NULL))
861 if (irq_domain_is_hierarchy(domain)) {
862 irq_domain_free_irqs(virq, 1);
864 irq_domain_disassociate(domain, virq);
868 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
871 * irq_find_mapping() - Find a linux irq from an hw irq number.
872 * @domain: domain owning this hardware interrupt
873 * @hwirq: hardware irq number in that domain space
875 unsigned int irq_find_mapping(struct irq_domain *domain,
876 irq_hw_number_t hwirq)
878 struct irq_data *data;
880 /* Look for default domain if nececssary */
882 domain = irq_default_domain;
886 if (hwirq < domain->revmap_direct_max_irq) {
887 data = irq_domain_get_irq_data(domain, hwirq);
888 if (data && data->hwirq == hwirq)
892 /* Check if the hwirq is in the linear revmap. */
893 if (hwirq < domain->revmap_size)
894 return domain->linear_revmap[hwirq];
897 data = radix_tree_lookup(&domain->revmap_tree, hwirq);
899 return data ? data->irq : 0;
901 EXPORT_SYMBOL_GPL(irq_find_mapping);
904 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
906 * Device Tree IRQ specifier translation function which works with one cell
907 * bindings where the cell value maps directly to the hwirq number.
909 int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
910 const u32 *intspec, unsigned int intsize,
911 unsigned long *out_hwirq, unsigned int *out_type)
913 if (WARN_ON(intsize < 1))
915 *out_hwirq = intspec[0];
916 *out_type = IRQ_TYPE_NONE;
919 EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
922 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
924 * Device Tree IRQ specifier translation function which works with two cell
925 * bindings where the cell values map directly to the hwirq number
926 * and linux irq flags.
928 int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
929 const u32 *intspec, unsigned int intsize,
930 irq_hw_number_t *out_hwirq, unsigned int *out_type)
932 if (WARN_ON(intsize < 2))
934 *out_hwirq = intspec[0];
935 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
938 EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
941 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
943 * Device Tree IRQ specifier translation function which works with either one
944 * or two cell bindings where the cell values map directly to the hwirq number
945 * and linux irq flags.
947 * Note: don't use this function unless your interrupt controller explicitly
948 * supports both one and two cell bindings. For the majority of controllers
949 * the _onecell() or _twocell() variants above should be used.
951 int irq_domain_xlate_onetwocell(struct irq_domain *d,
952 struct device_node *ctrlr,
953 const u32 *intspec, unsigned int intsize,
954 unsigned long *out_hwirq, unsigned int *out_type)
956 if (WARN_ON(intsize < 1))
958 *out_hwirq = intspec[0];
960 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
962 *out_type = IRQ_TYPE_NONE;
965 EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
967 const struct irq_domain_ops irq_domain_simple_ops = {
968 .xlate = irq_domain_xlate_onetwocell,
970 EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
972 int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq,
973 int node, const struct cpumask *affinity)
978 virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE,
981 hint = hwirq % nr_irqs;
984 virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE,
986 if (virq <= 0 && hint > 1) {
987 virq = __irq_alloc_descs(-1, 1, cnt, node, THIS_MODULE,
995 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
997 * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy
998 * @parent: Parent irq domain to associate with the new domain
999 * @flags: Irq domain flags associated to the domain
1000 * @size: Size of the domain. See below
1001 * @fwnode: Optional fwnode of the interrupt controller
1002 * @ops: Pointer to the interrupt domain callbacks
1003 * @host_data: Controller private data pointer
1005 * If @size is 0 a tree domain is created, otherwise a linear domain.
1007 * If successful the parent is associated to the new domain and the
1008 * domain flags are set.
1009 * Returns pointer to IRQ domain, or NULL on failure.
1011 struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
1014 struct fwnode_handle *fwnode,
1015 const struct irq_domain_ops *ops,
1018 struct irq_domain *domain;
1021 domain = irq_domain_create_linear(fwnode, size, ops, host_data);
1023 domain = irq_domain_create_tree(fwnode, ops, host_data);
1025 domain->parent = parent;
1026 domain->flags |= flags;
1031 EXPORT_SYMBOL_GPL(irq_domain_create_hierarchy);
1033 static void irq_domain_insert_irq(int virq)
1035 struct irq_data *data;
1037 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
1038 struct irq_domain *domain = data->domain;
1041 irq_domain_set_mapping(domain, data->hwirq, data);
1043 /* If not already assigned, give the domain the chip's name */
1044 if (!domain->name && data->chip)
1045 domain->name = data->chip->name;
1048 irq_clear_status_flags(virq, IRQ_NOREQUEST);
1051 static void irq_domain_remove_irq(int virq)
1053 struct irq_data *data;
1055 irq_set_status_flags(virq, IRQ_NOREQUEST);
1056 irq_set_chip_and_handler(virq, NULL, NULL);
1057 synchronize_irq(virq);
1060 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
1061 struct irq_domain *domain = data->domain;
1062 irq_hw_number_t hwirq = data->hwirq;
1065 irq_domain_clear_mapping(domain, hwirq);
1069 static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain,
1070 struct irq_data *child)
1072 struct irq_data *irq_data;
1074 irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL,
1075 irq_data_get_node(child));
1077 child->parent_data = irq_data;
1078 irq_data->irq = child->irq;
1079 irq_data->common = child->common;
1080 irq_data->domain = domain;
1086 static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs)
1088 struct irq_data *irq_data, *tmp;
1091 for (i = 0; i < nr_irqs; i++) {
1092 irq_data = irq_get_irq_data(virq + i);
1093 tmp = irq_data->parent_data;
1094 irq_data->parent_data = NULL;
1095 irq_data->domain = NULL;
1099 tmp = tmp->parent_data;
1105 static int irq_domain_alloc_irq_data(struct irq_domain *domain,
1106 unsigned int virq, unsigned int nr_irqs)
1108 struct irq_data *irq_data;
1109 struct irq_domain *parent;
1112 /* The outermost irq_data is embedded in struct irq_desc */
1113 for (i = 0; i < nr_irqs; i++) {
1114 irq_data = irq_get_irq_data(virq + i);
1115 irq_data->domain = domain;
1117 for (parent = domain->parent; parent; parent = parent->parent) {
1118 irq_data = irq_domain_insert_irq_data(parent, irq_data);
1120 irq_domain_free_irq_data(virq, i + 1);
1130 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
1131 * @domain: domain to match
1132 * @virq: IRQ number to get irq_data
1134 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
1137 struct irq_data *irq_data;
1139 for (irq_data = irq_get_irq_data(virq); irq_data;
1140 irq_data = irq_data->parent_data)
1141 if (irq_data->domain == domain)
1146 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
1149 * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain
1150 * @domain: Interrupt domain to match
1152 * @hwirq: The hwirq number
1153 * @chip: The associated interrupt chip
1154 * @chip_data: The associated chip data
1156 int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
1157 irq_hw_number_t hwirq, struct irq_chip *chip,
1160 struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
1165 irq_data->hwirq = hwirq;
1166 irq_data->chip = chip ? chip : &no_irq_chip;
1167 irq_data->chip_data = chip_data;
1171 EXPORT_SYMBOL_GPL(irq_domain_set_hwirq_and_chip);
1174 * irq_domain_set_info - Set the complete data for a @virq in @domain
1175 * @domain: Interrupt domain to match
1177 * @hwirq: The hardware interrupt number
1178 * @chip: The associated interrupt chip
1179 * @chip_data: The associated interrupt chip data
1180 * @handler: The interrupt flow handler
1181 * @handler_data: The interrupt flow handler data
1182 * @handler_name: The interrupt handler name
1184 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
1185 irq_hw_number_t hwirq, struct irq_chip *chip,
1186 void *chip_data, irq_flow_handler_t handler,
1187 void *handler_data, const char *handler_name)
1189 irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data);
1190 __irq_set_handler(virq, handler, 0, handler_name);
1191 irq_set_handler_data(virq, handler_data);
1193 EXPORT_SYMBOL(irq_domain_set_info);
1196 * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data
1197 * @irq_data: The pointer to irq_data
1199 void irq_domain_reset_irq_data(struct irq_data *irq_data)
1201 irq_data->hwirq = 0;
1202 irq_data->chip = &no_irq_chip;
1203 irq_data->chip_data = NULL;
1205 EXPORT_SYMBOL_GPL(irq_domain_reset_irq_data);
1208 * irq_domain_free_irqs_common - Clear irq_data and free the parent
1209 * @domain: Interrupt domain to match
1210 * @virq: IRQ number to start with
1211 * @nr_irqs: The number of irqs to free
1213 void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq,
1214 unsigned int nr_irqs)
1216 struct irq_data *irq_data;
1219 for (i = 0; i < nr_irqs; i++) {
1220 irq_data = irq_domain_get_irq_data(domain, virq + i);
1222 irq_domain_reset_irq_data(irq_data);
1224 irq_domain_free_irqs_parent(domain, virq, nr_irqs);
1226 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_common);
1229 * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent
1230 * @domain: Interrupt domain to match
1231 * @virq: IRQ number to start with
1232 * @nr_irqs: The number of irqs to free
1234 void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq,
1235 unsigned int nr_irqs)
1239 for (i = 0; i < nr_irqs; i++) {
1240 irq_set_handler_data(virq + i, NULL);
1241 irq_set_handler(virq + i, NULL);
1243 irq_domain_free_irqs_common(domain, virq, nr_irqs);
1246 static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain,
1247 unsigned int irq_base,
1248 unsigned int nr_irqs)
1252 if (!domain->ops->free)
1255 for (i = 0; i < nr_irqs; i++) {
1256 if (irq_domain_get_irq_data(domain, irq_base + i))
1257 domain->ops->free(domain, irq_base + i, 1);
1261 int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
1262 unsigned int irq_base,
1263 unsigned int nr_irqs, void *arg)
1265 if (!domain->ops->alloc) {
1266 pr_debug("domain->ops->alloc() is NULL\n");
1270 return domain->ops->alloc(domain, irq_base, nr_irqs, arg);
1274 * __irq_domain_alloc_irqs - Allocate IRQs from domain
1275 * @domain: domain to allocate from
1276 * @irq_base: allocate specified IRQ nubmer if irq_base >= 0
1277 * @nr_irqs: number of IRQs to allocate
1278 * @node: NUMA node id for memory allocation
1279 * @arg: domain specific argument
1280 * @realloc: IRQ descriptors have already been allocated if true
1281 * @affinity: Optional irq affinity mask for multiqueue devices
1283 * Allocate IRQ numbers and initialized all data structures to support
1284 * hierarchy IRQ domains.
1285 * Parameter @realloc is mainly to support legacy IRQs.
1286 * Returns error code or allocated IRQ number
1288 * The whole process to setup an IRQ has been split into two steps.
1289 * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
1290 * descriptor and required hardware resources. The second step,
1291 * irq_domain_activate_irq(), is to program hardwares with preallocated
1292 * resources. In this way, it's easier to rollback when failing to
1293 * allocate resources.
1295 int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
1296 unsigned int nr_irqs, int node, void *arg,
1297 bool realloc, const struct cpumask *affinity)
1301 if (domain == NULL) {
1302 domain = irq_default_domain;
1303 if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
1307 if (realloc && irq_base >= 0) {
1310 virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node,
1313 pr_debug("cannot allocate IRQ(base %d, count %d)\n",
1319 if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) {
1320 pr_debug("cannot allocate memory for IRQ%d\n", virq);
1325 mutex_lock(&irq_domain_mutex);
1326 ret = irq_domain_alloc_irqs_hierarchy(domain, virq, nr_irqs, arg);
1328 mutex_unlock(&irq_domain_mutex);
1329 goto out_free_irq_data;
1331 for (i = 0; i < nr_irqs; i++)
1332 irq_domain_insert_irq(virq + i);
1333 mutex_unlock(&irq_domain_mutex);
1338 irq_domain_free_irq_data(virq, nr_irqs);
1340 irq_free_descs(virq, nr_irqs);
1344 /* The irq_data was moved, fix the revmap to refer to the new location */
1345 static void irq_domain_fix_revmap(struct irq_data *d)
1349 if (d->hwirq < d->domain->revmap_size)
1350 return; /* Not using radix tree. */
1352 /* Fix up the revmap. */
1353 mutex_lock(&d->domain->revmap_tree_mutex);
1354 slot = radix_tree_lookup_slot(&d->domain->revmap_tree, d->hwirq);
1356 radix_tree_replace_slot(&d->domain->revmap_tree, slot, d);
1357 mutex_unlock(&d->domain->revmap_tree_mutex);
1361 * irq_domain_push_irq() - Push a domain in to the top of a hierarchy.
1362 * @domain: Domain to push.
1363 * @virq: Irq to push the domain in to.
1364 * @arg: Passed to the irq_domain_ops alloc() function.
1366 * For an already existing irqdomain hierarchy, as might be obtained
1367 * via a call to pci_enable_msix(), add an additional domain to the
1368 * head of the processing chain. Must be called before request_irq()
1371 int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg)
1373 struct irq_data *child_irq_data;
1374 struct irq_data *root_irq_data = irq_get_irq_data(virq);
1375 struct irq_desc *desc;
1379 * Check that no action has been set, which indicates the virq
1380 * is in a state where this function doesn't have to deal with
1381 * races between interrupt handling and maintaining the
1382 * hierarchy. This will catch gross misuse. Attempting to
1383 * make the check race free would require holding locks across
1384 * calls to struct irq_domain_ops->alloc(), which could lead
1385 * to deadlock, so we just do a simple check before starting.
1387 desc = irq_to_desc(virq);
1390 if (WARN_ON(desc->action))
1396 if (WARN_ON(!irq_domain_is_hierarchy(domain)))
1402 if (domain->parent != root_irq_data->domain)
1405 child_irq_data = kzalloc_node(sizeof(*child_irq_data), GFP_KERNEL,
1406 irq_data_get_node(root_irq_data));
1407 if (!child_irq_data)
1410 mutex_lock(&irq_domain_mutex);
1412 /* Copy the original irq_data. */
1413 *child_irq_data = *root_irq_data;
1416 * Overwrite the root_irq_data, which is embedded in struct
1417 * irq_desc, with values for this domain.
1419 root_irq_data->parent_data = child_irq_data;
1420 root_irq_data->domain = domain;
1421 root_irq_data->mask = 0;
1422 root_irq_data->hwirq = 0;
1423 root_irq_data->chip = NULL;
1424 root_irq_data->chip_data = NULL;
1426 /* May (probably does) set hwirq, chip, etc. */
1427 rv = irq_domain_alloc_irqs_hierarchy(domain, virq, 1, arg);
1429 /* Restore the original irq_data. */
1430 *root_irq_data = *child_irq_data;
1431 kfree(child_irq_data);
1435 irq_domain_fix_revmap(child_irq_data);
1436 irq_domain_set_mapping(domain, root_irq_data->hwirq, root_irq_data);
1439 mutex_unlock(&irq_domain_mutex);
1443 EXPORT_SYMBOL_GPL(irq_domain_push_irq);
1446 * irq_domain_pop_irq() - Remove a domain from the top of a hierarchy.
1447 * @domain: Domain to remove.
1448 * @virq: Irq to remove the domain from.
1450 * Undo the effects of a call to irq_domain_push_irq(). Must be
1451 * called either before request_irq() or after free_irq().
1453 int irq_domain_pop_irq(struct irq_domain *domain, int virq)
1455 struct irq_data *root_irq_data = irq_get_irq_data(virq);
1456 struct irq_data *child_irq_data;
1457 struct irq_data *tmp_irq_data;
1458 struct irq_desc *desc;
1461 * Check that no action is set, which indicates the virq is in
1462 * a state where this function doesn't have to deal with races
1463 * between interrupt handling and maintaining the hierarchy.
1464 * This will catch gross misuse. Attempting to make the check
1465 * race free would require holding locks across calls to
1466 * struct irq_domain_ops->free(), which could lead to
1467 * deadlock, so we just do a simple check before starting.
1469 desc = irq_to_desc(virq);
1472 if (WARN_ON(desc->action))
1481 tmp_irq_data = irq_domain_get_irq_data(domain, virq);
1483 /* We can only "pop" if this domain is at the top of the list */
1484 if (WARN_ON(root_irq_data != tmp_irq_data))
1487 if (WARN_ON(root_irq_data->domain != domain))
1490 child_irq_data = root_irq_data->parent_data;
1491 if (WARN_ON(!child_irq_data))
1494 mutex_lock(&irq_domain_mutex);
1496 root_irq_data->parent_data = NULL;
1498 irq_domain_clear_mapping(domain, root_irq_data->hwirq);
1499 irq_domain_free_irqs_hierarchy(domain, virq, 1);
1501 /* Restore the original irq_data. */
1502 *root_irq_data = *child_irq_data;
1504 irq_domain_fix_revmap(root_irq_data);
1506 mutex_unlock(&irq_domain_mutex);
1508 kfree(child_irq_data);
1512 EXPORT_SYMBOL_GPL(irq_domain_pop_irq);
1515 * irq_domain_free_irqs - Free IRQ number and associated data structures
1516 * @virq: base IRQ number
1517 * @nr_irqs: number of IRQs to free
1519 void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs)
1521 struct irq_data *data = irq_get_irq_data(virq);
1524 if (WARN(!data || !data->domain || !data->domain->ops->free,
1525 "NULL pointer, cannot free irq\n"))
1528 mutex_lock(&irq_domain_mutex);
1529 for (i = 0; i < nr_irqs; i++)
1530 irq_domain_remove_irq(virq + i);
1531 irq_domain_free_irqs_hierarchy(data->domain, virq, nr_irqs);
1532 mutex_unlock(&irq_domain_mutex);
1534 irq_domain_free_irq_data(virq, nr_irqs);
1535 irq_free_descs(virq, nr_irqs);
1539 * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain
1540 * @irq_base: Base IRQ number
1541 * @nr_irqs: Number of IRQs to allocate
1542 * @arg: Allocation data (arch/domain specific)
1544 * Check whether the domain has been setup recursive. If not allocate
1545 * through the parent domain.
1547 int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
1548 unsigned int irq_base, unsigned int nr_irqs,
1551 if (!domain->parent)
1554 return irq_domain_alloc_irqs_hierarchy(domain->parent, irq_base,
1557 EXPORT_SYMBOL_GPL(irq_domain_alloc_irqs_parent);
1560 * irq_domain_free_irqs_parent - Free interrupts from parent domain
1561 * @irq_base: Base IRQ number
1562 * @nr_irqs: Number of IRQs to free
1564 * Check whether the domain has been setup recursive. If not free
1565 * through the parent domain.
1567 void irq_domain_free_irqs_parent(struct irq_domain *domain,
1568 unsigned int irq_base, unsigned int nr_irqs)
1570 if (!domain->parent)
1573 irq_domain_free_irqs_hierarchy(domain->parent, irq_base, nr_irqs);
1575 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_parent);
1577 static void __irq_domain_deactivate_irq(struct irq_data *irq_data)
1579 if (irq_data && irq_data->domain) {
1580 struct irq_domain *domain = irq_data->domain;
1582 if (domain->ops->deactivate)
1583 domain->ops->deactivate(domain, irq_data);
1584 if (irq_data->parent_data)
1585 __irq_domain_deactivate_irq(irq_data->parent_data);
1589 static int __irq_domain_activate_irq(struct irq_data *irqd, bool reserve)
1593 if (irqd && irqd->domain) {
1594 struct irq_domain *domain = irqd->domain;
1596 if (irqd->parent_data)
1597 ret = __irq_domain_activate_irq(irqd->parent_data,
1599 if (!ret && domain->ops->activate) {
1600 ret = domain->ops->activate(domain, irqd, reserve);
1601 /* Rollback in case of error */
1602 if (ret && irqd->parent_data)
1603 __irq_domain_deactivate_irq(irqd->parent_data);
1610 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
1612 * @irq_data: Outermost irq_data associated with interrupt
1613 * @reserve: If set only reserve an interrupt vector instead of assigning one
1615 * This is the second step to call domain_ops->activate to program interrupt
1616 * controllers, so the interrupt could actually get delivered.
1618 int irq_domain_activate_irq(struct irq_data *irq_data, bool reserve)
1622 if (!irqd_is_activated(irq_data))
1623 ret = __irq_domain_activate_irq(irq_data, reserve);
1625 irqd_set_activated(irq_data);
1630 * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to
1631 * deactivate interrupt
1632 * @irq_data: outermost irq_data associated with interrupt
1634 * It calls domain_ops->deactivate to program interrupt controllers to disable
1635 * interrupt delivery.
1637 void irq_domain_deactivate_irq(struct irq_data *irq_data)
1639 if (irqd_is_activated(irq_data)) {
1640 __irq_domain_deactivate_irq(irq_data);
1641 irqd_clr_activated(irq_data);
1645 static void irq_domain_check_hierarchy(struct irq_domain *domain)
1647 /* Hierarchy irq_domains must implement callback alloc() */
1648 if (domain->ops->alloc)
1649 domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
1653 * irq_domain_hierarchical_is_msi_remap - Check if the domain or any
1654 * parent has MSI remapping support
1655 * @domain: domain pointer
1657 bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain)
1659 for (; domain; domain = domain->parent) {
1660 if (irq_domain_is_msi_remap(domain))
1665 #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
1667 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
1668 * @domain: domain to match
1669 * @virq: IRQ number to get irq_data
1671 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
1674 struct irq_data *irq_data = irq_get_irq_data(virq);
1676 return (irq_data && irq_data->domain == domain) ? irq_data : NULL;
1678 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
1681 * irq_domain_set_info - Set the complete data for a @virq in @domain
1682 * @domain: Interrupt domain to match
1684 * @hwirq: The hardware interrupt number
1685 * @chip: The associated interrupt chip
1686 * @chip_data: The associated interrupt chip data
1687 * @handler: The interrupt flow handler
1688 * @handler_data: The interrupt flow handler data
1689 * @handler_name: The interrupt handler name
1691 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
1692 irq_hw_number_t hwirq, struct irq_chip *chip,
1693 void *chip_data, irq_flow_handler_t handler,
1694 void *handler_data, const char *handler_name)
1696 irq_set_chip_and_handler_name(virq, chip, handler, handler_name);
1697 irq_set_chip_data(virq, chip_data);
1698 irq_set_handler_data(virq, handler_data);
1701 static void irq_domain_check_hierarchy(struct irq_domain *domain)
1704 #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */
1706 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
1707 static struct dentry *domain_dir;
1710 irq_domain_debug_show_one(struct seq_file *m, struct irq_domain *d, int ind)
1712 seq_printf(m, "%*sname: %s\n", ind, "", d->name);
1713 seq_printf(m, "%*ssize: %u\n", ind + 1, "",
1714 d->revmap_size + d->revmap_direct_max_irq);
1715 seq_printf(m, "%*smapped: %u\n", ind + 1, "", d->mapcount);
1716 seq_printf(m, "%*sflags: 0x%08x\n", ind +1 , "", d->flags);
1717 if (d->ops && d->ops->debug_show)
1718 d->ops->debug_show(m, d, NULL, ind + 1);
1719 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1722 seq_printf(m, "%*sparent: %s\n", ind + 1, "", d->parent->name);
1723 irq_domain_debug_show_one(m, d->parent, ind + 4);
1727 static int irq_domain_debug_show(struct seq_file *m, void *p)
1729 struct irq_domain *d = m->private;
1731 /* Default domain? Might be NULL */
1733 if (!irq_default_domain)
1735 d = irq_default_domain;
1737 irq_domain_debug_show_one(m, d, 0);
1740 DEFINE_SHOW_ATTRIBUTE(irq_domain_debug);
1742 static void debugfs_add_domain_dir(struct irq_domain *d)
1744 if (!d->name || !domain_dir || d->debugfs_file)
1746 d->debugfs_file = debugfs_create_file(d->name, 0444, domain_dir, d,
1747 &irq_domain_debug_fops);
1750 static void debugfs_remove_domain_dir(struct irq_domain *d)
1752 debugfs_remove(d->debugfs_file);
1755 void __init irq_domain_debugfs_init(struct dentry *root)
1757 struct irq_domain *d;
1759 domain_dir = debugfs_create_dir("domains", root);
1763 debugfs_create_file("default", 0444, domain_dir, NULL,
1764 &irq_domain_debug_fops);
1765 mutex_lock(&irq_domain_mutex);
1766 list_for_each_entry(d, &irq_domain_list, link)
1767 debugfs_add_domain_dir(d);
1768 mutex_unlock(&irq_domain_mutex);