1 #define pr_fmt(fmt) "irq: " fmt
3 #include <linux/acpi.h>
4 #include <linux/debugfs.h>
5 #include <linux/hardirq.h>
6 #include <linux/interrupt.h>
8 #include <linux/irqdesc.h>
9 #include <linux/irqdomain.h>
10 #include <linux/module.h>
11 #include <linux/mutex.h>
13 #include <linux/of_address.h>
14 #include <linux/of_irq.h>
15 #include <linux/topology.h>
16 #include <linux/seq_file.h>
17 #include <linux/slab.h>
18 #include <linux/smp.h>
21 static LIST_HEAD(irq_domain_list);
22 static DEFINE_MUTEX(irq_domain_mutex);
24 static DEFINE_MUTEX(revmap_trees_mutex);
25 static struct irq_domain *irq_default_domain;
27 static void irq_domain_check_hierarchy(struct irq_domain *domain);
30 struct fwnode_handle fwnode;
36 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
37 static void debugfs_add_domain_dir(struct irq_domain *d);
38 static void debugfs_remove_domain_dir(struct irq_domain *d);
40 static inline void debugfs_add_domain_dir(struct irq_domain *d) { }
41 static inline void debugfs_remove_domain_dir(struct irq_domain *d) { }
45 * irq_domain_alloc_fwnode - Allocate a fwnode_handle suitable for
46 * identifying an irq domain
47 * @type: Type of irqchip_fwnode. See linux/irqdomain.h
48 * @name: Optional user provided domain name
49 * @id: Optional user provided id if name != NULL
50 * @data: Optional user-provided data
52 * Allocate a struct irqchip_fwid, and return a poiner to the embedded
53 * fwnode_handle (or NULL on failure).
55 * Note: The types IRQCHIP_FWNODE_NAMED and IRQCHIP_FWNODE_NAMED_ID are
56 * solely to transport name information to irqdomain creation code. The
57 * node is not stored. For other types the pointer is kept in the irq
60 struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
61 const char *name, void *data)
63 struct irqchip_fwid *fwid;
66 fwid = kzalloc(sizeof(*fwid), GFP_KERNEL);
69 case IRQCHIP_FWNODE_NAMED:
70 n = kasprintf(GFP_KERNEL, "%s", name);
72 case IRQCHIP_FWNODE_NAMED_ID:
73 n = kasprintf(GFP_KERNEL, "%s-%d", name, id);
76 n = kasprintf(GFP_KERNEL, "irqchip@%p", data);
89 fwid->fwnode.type = FWNODE_IRQCHIP;
92 EXPORT_SYMBOL_GPL(__irq_domain_alloc_fwnode);
95 * irq_domain_free_fwnode - Free a non-OF-backed fwnode_handle
97 * Free a fwnode_handle allocated with irq_domain_alloc_fwnode.
99 void irq_domain_free_fwnode(struct fwnode_handle *fwnode)
101 struct irqchip_fwid *fwid;
103 if (WARN_ON(!is_fwnode_irqchip(fwnode)))
106 fwid = container_of(fwnode, struct irqchip_fwid, fwnode);
110 EXPORT_SYMBOL_GPL(irq_domain_free_fwnode);
113 * __irq_domain_add() - Allocate a new irq_domain data structure
114 * @fwnode: firmware node for the interrupt controller
115 * @size: Size of linear map; 0 for radix mapping only
116 * @hwirq_max: Maximum number of interrupts supported by controller
117 * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
119 * @ops: domain callbacks
120 * @host_data: Controller private data pointer
122 * Allocates and initialize and irq_domain structure.
123 * Returns pointer to IRQ domain, or NULL on failure.
125 struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, int size,
126 irq_hw_number_t hwirq_max, int direct_max,
127 const struct irq_domain_ops *ops,
130 struct device_node *of_node = to_of_node(fwnode);
131 struct irqchip_fwid *fwid;
132 struct irq_domain *domain;
134 static atomic_t unknown_domains;
136 domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
137 GFP_KERNEL, of_node_to_nid(of_node));
138 if (WARN_ON(!domain))
141 if (fwnode && is_fwnode_irqchip(fwnode)) {
142 fwid = container_of(fwnode, struct irqchip_fwid, fwnode);
144 switch (fwid->type) {
145 case IRQCHIP_FWNODE_NAMED:
146 case IRQCHIP_FWNODE_NAMED_ID:
147 domain->name = kstrdup(fwid->name, GFP_KERNEL);
152 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
155 domain->fwnode = fwnode;
156 domain->name = fwid->name;
160 } else if (is_acpi_device_node(fwnode)) {
161 struct acpi_buffer buf = {
162 .length = ACPI_ALLOCATE_BUFFER,
166 handle = acpi_device_handle(to_acpi_device_node(fwnode));
167 if (acpi_get_name(handle, ACPI_FULL_PATHNAME, &buf) == AE_OK) {
168 domain->name = buf.pointer;
169 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
172 domain->fwnode = fwnode;
174 } else if (of_node) {
178 * DT paths contain '/', which debugfs is legitimately
179 * unhappy about. Replace them with ':', which does
180 * the trick and is not as offensive as '\'...
182 name = kstrdup(of_node_full_name(of_node), GFP_KERNEL);
188 strreplace(name, '/', ':');
191 domain->fwnode = fwnode;
192 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
197 pr_err("Invalid fwnode type (%d) for irqdomain\n",
200 domain->name = kasprintf(GFP_KERNEL, "unknown-%d",
201 atomic_inc_return(&unknown_domains));
206 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
209 of_node_get(of_node);
212 INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
214 domain->host_data = host_data;
215 domain->hwirq_max = hwirq_max;
216 domain->revmap_size = size;
217 domain->revmap_direct_max_irq = direct_max;
218 irq_domain_check_hierarchy(domain);
220 mutex_lock(&irq_domain_mutex);
221 debugfs_add_domain_dir(domain);
222 list_add(&domain->link, &irq_domain_list);
223 mutex_unlock(&irq_domain_mutex);
225 pr_debug("Added domain %s\n", domain->name);
228 EXPORT_SYMBOL_GPL(__irq_domain_add);
231 * irq_domain_remove() - Remove an irq domain.
232 * @domain: domain to remove
234 * This routine is used to remove an irq domain. The caller must ensure
235 * that all mappings within the domain have been disposed of prior to
236 * use, depending on the revmap type.
238 void irq_domain_remove(struct irq_domain *domain)
240 mutex_lock(&irq_domain_mutex);
241 debugfs_remove_domain_dir(domain);
243 WARN_ON(!radix_tree_empty(&domain->revmap_tree));
245 list_del(&domain->link);
248 * If the going away domain is the default one, reset it.
250 if (unlikely(irq_default_domain == domain))
251 irq_set_default_host(NULL);
253 mutex_unlock(&irq_domain_mutex);
255 pr_debug("Removed domain %s\n", domain->name);
257 of_node_put(irq_domain_get_of_node(domain));
258 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED)
262 EXPORT_SYMBOL_GPL(irq_domain_remove);
264 void irq_domain_update_bus_token(struct irq_domain *domain,
265 enum irq_domain_bus_token bus_token)
269 if (domain->bus_token == bus_token)
272 mutex_lock(&irq_domain_mutex);
274 domain->bus_token = bus_token;
276 name = kasprintf(GFP_KERNEL, "%s-%d", domain->name, bus_token);
278 mutex_unlock(&irq_domain_mutex);
282 debugfs_remove_domain_dir(domain);
284 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED)
287 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
290 debugfs_add_domain_dir(domain);
292 mutex_unlock(&irq_domain_mutex);
296 * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
297 * @of_node: pointer to interrupt controller's device tree node.
298 * @size: total number of irqs in mapping
299 * @first_irq: first number of irq block assigned to the domain,
300 * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
301 * pre-map all of the irqs in the domain to virqs starting at first_irq.
302 * @ops: domain callbacks
303 * @host_data: Controller private data pointer
305 * Allocates an irq_domain, and optionally if first_irq is positive then also
306 * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
308 * This is intended to implement the expected behaviour for most
309 * interrupt controllers. If device tree is used, then first_irq will be 0 and
310 * irqs get mapped dynamically on the fly. However, if the controller requires
311 * static virq assignments (non-DT boot) then it will set that up correctly.
313 struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
315 unsigned int first_irq,
316 const struct irq_domain_ops *ops,
319 struct irq_domain *domain;
321 domain = __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data);
326 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
327 /* attempt to allocated irq_descs */
328 int rc = irq_alloc_descs(first_irq, first_irq, size,
329 of_node_to_nid(of_node));
331 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
334 irq_domain_associate_many(domain, first_irq, 0, size);
339 EXPORT_SYMBOL_GPL(irq_domain_add_simple);
342 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
343 * @of_node: pointer to interrupt controller's device tree node.
344 * @size: total number of irqs in legacy mapping
345 * @first_irq: first number of irq block assigned to the domain
346 * @first_hwirq: first hwirq number to use for the translation. Should normally
347 * be '0', but a positive integer can be used if the effective
348 * hwirqs numbering does not begin at zero.
349 * @ops: map/unmap domain callbacks
350 * @host_data: Controller private data pointer
352 * Note: the map() callback will be called before this function returns
353 * for all legacy interrupts except 0 (which is always the invalid irq for
354 * a legacy controller).
356 struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
358 unsigned int first_irq,
359 irq_hw_number_t first_hwirq,
360 const struct irq_domain_ops *ops,
363 struct irq_domain *domain;
365 domain = __irq_domain_add(of_node_to_fwnode(of_node), first_hwirq + size,
366 first_hwirq + size, 0, ops, host_data);
368 irq_domain_associate_many(domain, first_irq, first_hwirq, size);
372 EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
375 * irq_find_matching_fwspec() - Locates a domain for a given fwspec
376 * @fwspec: FW specifier for an interrupt
377 * @bus_token: domain-specific data
379 struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
380 enum irq_domain_bus_token bus_token)
382 struct irq_domain *h, *found = NULL;
383 struct fwnode_handle *fwnode = fwspec->fwnode;
386 /* We might want to match the legacy controller last since
387 * it might potentially be set to match all interrupts in
388 * the absence of a device node. This isn't a problem so far
391 * bus_token == DOMAIN_BUS_ANY matches any domain, any other
392 * values must generate an exact match for the domain to be
395 mutex_lock(&irq_domain_mutex);
396 list_for_each_entry(h, &irq_domain_list, link) {
397 if (h->ops->select && fwspec->param_count)
398 rc = h->ops->select(h, fwspec, bus_token);
399 else if (h->ops->match)
400 rc = h->ops->match(h, to_of_node(fwnode), bus_token);
402 rc = ((fwnode != NULL) && (h->fwnode == fwnode) &&
403 ((bus_token == DOMAIN_BUS_ANY) ||
404 (h->bus_token == bus_token)));
411 mutex_unlock(&irq_domain_mutex);
414 EXPORT_SYMBOL_GPL(irq_find_matching_fwspec);
417 * irq_domain_check_msi_remap - Check whether all MSI irq domains implement
420 * Return: false if any MSI irq domain does not support IRQ remapping,
421 * true otherwise (including if there is no MSI irq domain)
423 bool irq_domain_check_msi_remap(void)
425 struct irq_domain *h;
428 mutex_lock(&irq_domain_mutex);
429 list_for_each_entry(h, &irq_domain_list, link) {
430 if (irq_domain_is_msi(h) &&
431 !irq_domain_hierarchical_is_msi_remap(h)) {
436 mutex_unlock(&irq_domain_mutex);
439 EXPORT_SYMBOL_GPL(irq_domain_check_msi_remap);
442 * irq_set_default_host() - Set a "default" irq domain
443 * @domain: default domain pointer
445 * For convenience, it's possible to set a "default" domain that will be used
446 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
447 * platforms that want to manipulate a few hard coded interrupt numbers that
448 * aren't properly represented in the device-tree.
450 void irq_set_default_host(struct irq_domain *domain)
452 pr_debug("Default domain set to @0x%p\n", domain);
454 irq_default_domain = domain;
456 EXPORT_SYMBOL_GPL(irq_set_default_host);
458 void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
460 struct irq_data *irq_data = irq_get_irq_data(irq);
461 irq_hw_number_t hwirq;
463 if (WARN(!irq_data || irq_data->domain != domain,
464 "virq%i doesn't exist; cannot disassociate\n", irq))
467 hwirq = irq_data->hwirq;
468 irq_set_status_flags(irq, IRQ_NOREQUEST);
470 /* remove chip and handler */
471 irq_set_chip_and_handler(irq, NULL, NULL);
473 /* Make sure it's completed */
474 synchronize_irq(irq);
476 /* Tell the PIC about it */
477 if (domain->ops->unmap)
478 domain->ops->unmap(domain, irq);
481 irq_data->domain = NULL;
485 /* Clear reverse map for this hwirq */
486 if (hwirq < domain->revmap_size) {
487 domain->linear_revmap[hwirq] = 0;
489 mutex_lock(&revmap_trees_mutex);
490 radix_tree_delete(&domain->revmap_tree, hwirq);
491 mutex_unlock(&revmap_trees_mutex);
495 int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
496 irq_hw_number_t hwirq)
498 struct irq_data *irq_data = irq_get_irq_data(virq);
501 if (WARN(hwirq >= domain->hwirq_max,
502 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
504 if (WARN(!irq_data, "error: virq%i is not allocated", virq))
506 if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
509 mutex_lock(&irq_domain_mutex);
510 irq_data->hwirq = hwirq;
511 irq_data->domain = domain;
512 if (domain->ops->map) {
513 ret = domain->ops->map(domain, virq, hwirq);
516 * If map() returns -EPERM, this interrupt is protected
517 * by the firmware or some other service and shall not
518 * be mapped. Don't bother telling the user about it.
521 pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
522 domain->name, hwirq, virq, ret);
524 irq_data->domain = NULL;
526 mutex_unlock(&irq_domain_mutex);
530 /* If not already assigned, give the domain the chip's name */
531 if (!domain->name && irq_data->chip)
532 domain->name = irq_data->chip->name;
536 if (hwirq < domain->revmap_size) {
537 domain->linear_revmap[hwirq] = virq;
539 mutex_lock(&revmap_trees_mutex);
540 radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
541 mutex_unlock(&revmap_trees_mutex);
543 mutex_unlock(&irq_domain_mutex);
545 irq_clear_status_flags(virq, IRQ_NOREQUEST);
549 EXPORT_SYMBOL_GPL(irq_domain_associate);
551 void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
552 irq_hw_number_t hwirq_base, int count)
554 struct device_node *of_node;
557 of_node = irq_domain_get_of_node(domain);
558 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
559 of_node_full_name(of_node), irq_base, (int)hwirq_base, count);
561 for (i = 0; i < count; i++) {
562 irq_domain_associate(domain, irq_base + i, hwirq_base + i);
565 EXPORT_SYMBOL_GPL(irq_domain_associate_many);
568 * irq_create_direct_mapping() - Allocate an irq for direct mapping
569 * @domain: domain to allocate the irq for or NULL for default domain
571 * This routine is used for irq controllers which can choose the hardware
572 * interrupt numbers they generate. In such a case it's simplest to use
573 * the linux irq as the hardware interrupt number. It still uses the linear
574 * or radix tree to store the mapping, but the irq controller can optimize
575 * the revmap path by using the hwirq directly.
577 unsigned int irq_create_direct_mapping(struct irq_domain *domain)
579 struct device_node *of_node;
583 domain = irq_default_domain;
585 of_node = irq_domain_get_of_node(domain);
586 virq = irq_alloc_desc_from(1, of_node_to_nid(of_node));
588 pr_debug("create_direct virq allocation failed\n");
591 if (virq >= domain->revmap_direct_max_irq) {
592 pr_err("ERROR: no free irqs available below %i maximum\n",
593 domain->revmap_direct_max_irq);
597 pr_debug("create_direct obtained virq %d\n", virq);
599 if (irq_domain_associate(domain, virq, virq)) {
606 EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
609 * irq_create_mapping() - Map a hardware interrupt into linux irq space
610 * @domain: domain owning this hardware interrupt or NULL for default domain
611 * @hwirq: hardware irq number in that domain space
613 * Only one mapping per hardware interrupt is permitted. Returns a linux
615 * If the sense/trigger is to be specified, set_irq_type() should be called
616 * on the number returned from that call.
618 unsigned int irq_create_mapping(struct irq_domain *domain,
619 irq_hw_number_t hwirq)
621 struct device_node *of_node;
624 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
626 /* Look for default domain if nececssary */
628 domain = irq_default_domain;
629 if (domain == NULL) {
630 WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
633 pr_debug("-> using domain @%p\n", domain);
635 of_node = irq_domain_get_of_node(domain);
637 /* Check if mapping already exists */
638 virq = irq_find_mapping(domain, hwirq);
640 pr_debug("-> existing mapping on virq %d\n", virq);
644 /* Allocate a virtual interrupt number */
645 virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(of_node), NULL);
647 pr_debug("-> virq allocation failed\n");
651 if (irq_domain_associate(domain, virq, hwirq)) {
656 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
657 hwirq, of_node_full_name(of_node), virq);
661 EXPORT_SYMBOL_GPL(irq_create_mapping);
664 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
665 * @domain: domain owning the interrupt range
666 * @irq_base: beginning of linux IRQ range
667 * @hwirq_base: beginning of hardware IRQ range
668 * @count: Number of interrupts to map
670 * This routine is used for allocating and mapping a range of hardware
671 * irqs to linux irqs where the linux irq numbers are at pre-defined
672 * locations. For use by controllers that already have static mappings
673 * to insert in to the domain.
675 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
678 * 0 is returned upon success, while any failure to establish a static
679 * mapping is treated as an error.
681 int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
682 irq_hw_number_t hwirq_base, int count)
684 struct device_node *of_node;
687 of_node = irq_domain_get_of_node(domain);
688 ret = irq_alloc_descs(irq_base, irq_base, count,
689 of_node_to_nid(of_node));
690 if (unlikely(ret < 0))
693 irq_domain_associate_many(domain, irq_base, hwirq_base, count);
696 EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
698 static int irq_domain_translate(struct irq_domain *d,
699 struct irq_fwspec *fwspec,
700 irq_hw_number_t *hwirq, unsigned int *type)
702 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
703 if (d->ops->translate)
704 return d->ops->translate(d, fwspec, hwirq, type);
707 return d->ops->xlate(d, to_of_node(fwspec->fwnode),
708 fwspec->param, fwspec->param_count,
711 /* If domain has no translation, then we assume interrupt line */
712 *hwirq = fwspec->param[0];
716 static void of_phandle_args_to_fwspec(struct of_phandle_args *irq_data,
717 struct irq_fwspec *fwspec)
721 fwspec->fwnode = irq_data->np ? &irq_data->np->fwnode : NULL;
722 fwspec->param_count = irq_data->args_count;
724 for (i = 0; i < irq_data->args_count; i++)
725 fwspec->param[i] = irq_data->args[i];
728 unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
730 struct irq_domain *domain;
731 struct irq_data *irq_data;
732 irq_hw_number_t hwirq;
733 unsigned int type = IRQ_TYPE_NONE;
736 if (fwspec->fwnode) {
737 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_WIRED);
739 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_ANY);
741 domain = irq_default_domain;
745 pr_warn("no irq domain found for %s !\n",
746 of_node_full_name(to_of_node(fwspec->fwnode)));
750 if (irq_domain_translate(domain, fwspec, &hwirq, &type))
754 * WARN if the irqchip returns a type with bits
755 * outside the sense mask set and clear these bits.
757 if (WARN_ON(type & ~IRQ_TYPE_SENSE_MASK))
758 type &= IRQ_TYPE_SENSE_MASK;
761 * If we've already configured this interrupt,
762 * don't do it again, or hell will break loose.
764 virq = irq_find_mapping(domain, hwirq);
767 * If the trigger type is not specified or matches the
768 * current trigger type then we are done so return the
771 if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq))
775 * If the trigger type has not been set yet, then set
776 * it now and return the interrupt number.
778 if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) {
779 irq_data = irq_get_irq_data(virq);
783 irqd_set_trigger_type(irq_data, type);
787 pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n",
788 hwirq, of_node_full_name(to_of_node(fwspec->fwnode)));
792 if (irq_domain_is_hierarchy(domain)) {
793 virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, fwspec);
798 virq = irq_create_mapping(domain, hwirq);
803 irq_data = irq_get_irq_data(virq);
805 if (irq_domain_is_hierarchy(domain))
806 irq_domain_free_irqs(virq, 1);
808 irq_dispose_mapping(virq);
812 /* Store trigger type */
813 irqd_set_trigger_type(irq_data, type);
817 EXPORT_SYMBOL_GPL(irq_create_fwspec_mapping);
819 unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
821 struct irq_fwspec fwspec;
823 of_phandle_args_to_fwspec(irq_data, &fwspec);
824 return irq_create_fwspec_mapping(&fwspec);
826 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
829 * irq_dispose_mapping() - Unmap an interrupt
830 * @virq: linux irq number of the interrupt to unmap
832 void irq_dispose_mapping(unsigned int virq)
834 struct irq_data *irq_data = irq_get_irq_data(virq);
835 struct irq_domain *domain;
837 if (!virq || !irq_data)
840 domain = irq_data->domain;
841 if (WARN_ON(domain == NULL))
844 if (irq_domain_is_hierarchy(domain)) {
845 irq_domain_free_irqs(virq, 1);
847 irq_domain_disassociate(domain, virq);
851 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
854 * irq_find_mapping() - Find a linux irq from an hw irq number.
855 * @domain: domain owning this hardware interrupt
856 * @hwirq: hardware irq number in that domain space
858 unsigned int irq_find_mapping(struct irq_domain *domain,
859 irq_hw_number_t hwirq)
861 struct irq_data *data;
863 /* Look for default domain if nececssary */
865 domain = irq_default_domain;
869 if (hwirq < domain->revmap_direct_max_irq) {
870 data = irq_domain_get_irq_data(domain, hwirq);
871 if (data && data->hwirq == hwirq)
875 /* Check if the hwirq is in the linear revmap. */
876 if (hwirq < domain->revmap_size)
877 return domain->linear_revmap[hwirq];
880 data = radix_tree_lookup(&domain->revmap_tree, hwirq);
882 return data ? data->irq : 0;
884 EXPORT_SYMBOL_GPL(irq_find_mapping);
886 #ifdef CONFIG_IRQ_DOMAIN_DEBUG
887 static void virq_debug_show_one(struct seq_file *m, struct irq_desc *desc)
889 struct irq_domain *domain;
890 struct irq_data *data;
892 domain = desc->irq_data.domain;
893 data = &desc->irq_data;
896 unsigned int irq = data->irq;
897 unsigned long hwirq = data->hwirq;
898 struct irq_chip *chip;
901 if (data == &desc->irq_data)
902 seq_printf(m, "%5d ", irq);
904 seq_printf(m, "%5d+ ", irq);
905 seq_printf(m, "0x%05lx ", hwirq);
907 chip = irq_data_get_irq_chip(data);
908 seq_printf(m, "%-15s ", (chip && chip->name) ? chip->name : "none");
910 seq_printf(m, data ? "0x%p " : " %p ",
911 irq_data_get_irq_chip_data(data));
913 seq_printf(m, " %c ", (desc->action && desc->action->handler) ? '*' : ' ');
914 direct = (irq == hwirq) && (irq < domain->revmap_direct_max_irq);
915 seq_printf(m, "%6s%-8s ",
916 (hwirq < domain->revmap_size) ? "LINEAR" : "RADIX",
917 direct ? "(DIRECT)" : "");
918 seq_printf(m, "%s\n", domain->name);
919 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
920 domain = domain->parent;
921 data = data->parent_data;
928 static int virq_debug_show(struct seq_file *m, void *private)
931 struct irq_desc *desc;
932 struct irq_domain *domain;
933 struct radix_tree_iter iter;
937 seq_printf(m, " %-16s %-6s %-10s %-10s %s\n",
938 "name", "mapped", "linear-max", "direct-max", "devtree-node");
939 mutex_lock(&irq_domain_mutex);
940 list_for_each_entry(domain, &irq_domain_list, link) {
941 struct device_node *of_node;
946 of_node = irq_domain_get_of_node(domain);
948 name = of_node_full_name(of_node);
949 else if (is_fwnode_irqchip(domain->fwnode))
950 name = container_of(domain->fwnode, struct irqchip_fwid,
955 radix_tree_for_each_slot(slot, &domain->revmap_tree, &iter, 0)
957 seq_printf(m, "%c%-16s %6u %10u %10u %s\n",
958 domain == irq_default_domain ? '*' : ' ', domain->name,
959 domain->revmap_size + count, domain->revmap_size,
960 domain->revmap_direct_max_irq,
963 mutex_unlock(&irq_domain_mutex);
965 seq_printf(m, "%-5s %-7s %-15s %-*s %6s %-14s %s\n", "irq", "hwirq",
966 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
967 "active", "type", "domain");
969 for (i = 1; i < nr_irqs; i++) {
970 desc = irq_to_desc(i);
974 raw_spin_lock_irqsave(&desc->lock, flags);
975 virq_debug_show_one(m, desc);
976 raw_spin_unlock_irqrestore(&desc->lock, flags);
982 static int virq_debug_open(struct inode *inode, struct file *file)
984 return single_open(file, virq_debug_show, inode->i_private);
987 static const struct file_operations virq_debug_fops = {
988 .open = virq_debug_open,
991 .release = single_release,
994 static int __init irq_debugfs_init(void)
996 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
997 NULL, &virq_debug_fops) == NULL)
1002 __initcall(irq_debugfs_init);
1003 #endif /* CONFIG_IRQ_DOMAIN_DEBUG */
1006 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
1008 * Device Tree IRQ specifier translation function which works with one cell
1009 * bindings where the cell value maps directly to the hwirq number.
1011 int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
1012 const u32 *intspec, unsigned int intsize,
1013 unsigned long *out_hwirq, unsigned int *out_type)
1015 if (WARN_ON(intsize < 1))
1017 *out_hwirq = intspec[0];
1018 *out_type = IRQ_TYPE_NONE;
1021 EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
1024 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
1026 * Device Tree IRQ specifier translation function which works with two cell
1027 * bindings where the cell values map directly to the hwirq number
1028 * and linux irq flags.
1030 int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
1031 const u32 *intspec, unsigned int intsize,
1032 irq_hw_number_t *out_hwirq, unsigned int *out_type)
1034 if (WARN_ON(intsize < 2))
1036 *out_hwirq = intspec[0];
1037 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
1040 EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
1043 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
1045 * Device Tree IRQ specifier translation function which works with either one
1046 * or two cell bindings where the cell values map directly to the hwirq number
1047 * and linux irq flags.
1049 * Note: don't use this function unless your interrupt controller explicitly
1050 * supports both one and two cell bindings. For the majority of controllers
1051 * the _onecell() or _twocell() variants above should be used.
1053 int irq_domain_xlate_onetwocell(struct irq_domain *d,
1054 struct device_node *ctrlr,
1055 const u32 *intspec, unsigned int intsize,
1056 unsigned long *out_hwirq, unsigned int *out_type)
1058 if (WARN_ON(intsize < 1))
1060 *out_hwirq = intspec[0];
1062 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
1064 *out_type = IRQ_TYPE_NONE;
1067 EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
1069 const struct irq_domain_ops irq_domain_simple_ops = {
1070 .xlate = irq_domain_xlate_onetwocell,
1072 EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
1074 int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq,
1075 int node, const struct cpumask *affinity)
1080 virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE,
1083 hint = hwirq % nr_irqs;
1086 virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE,
1088 if (virq <= 0 && hint > 1) {
1089 virq = __irq_alloc_descs(-1, 1, cnt, node, THIS_MODULE,
1097 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1099 * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy
1100 * @parent: Parent irq domain to associate with the new domain
1101 * @flags: Irq domain flags associated to the domain
1102 * @size: Size of the domain. See below
1103 * @fwnode: Optional fwnode of the interrupt controller
1104 * @ops: Pointer to the interrupt domain callbacks
1105 * @host_data: Controller private data pointer
1107 * If @size is 0 a tree domain is created, otherwise a linear domain.
1109 * If successful the parent is associated to the new domain and the
1110 * domain flags are set.
1111 * Returns pointer to IRQ domain, or NULL on failure.
1113 struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
1116 struct fwnode_handle *fwnode,
1117 const struct irq_domain_ops *ops,
1120 struct irq_domain *domain;
1123 domain = irq_domain_create_linear(fwnode, size, ops, host_data);
1125 domain = irq_domain_create_tree(fwnode, ops, host_data);
1127 domain->parent = parent;
1128 domain->flags |= flags;
1133 EXPORT_SYMBOL_GPL(irq_domain_create_hierarchy);
1135 static void irq_domain_insert_irq(int virq)
1137 struct irq_data *data;
1139 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
1140 struct irq_domain *domain = data->domain;
1141 irq_hw_number_t hwirq = data->hwirq;
1144 if (hwirq < domain->revmap_size) {
1145 domain->linear_revmap[hwirq] = virq;
1147 mutex_lock(&revmap_trees_mutex);
1148 radix_tree_insert(&domain->revmap_tree, hwirq, data);
1149 mutex_unlock(&revmap_trees_mutex);
1152 /* If not already assigned, give the domain the chip's name */
1153 if (!domain->name && data->chip)
1154 domain->name = data->chip->name;
1157 irq_clear_status_flags(virq, IRQ_NOREQUEST);
1160 static void irq_domain_remove_irq(int virq)
1162 struct irq_data *data;
1164 irq_set_status_flags(virq, IRQ_NOREQUEST);
1165 irq_set_chip_and_handler(virq, NULL, NULL);
1166 synchronize_irq(virq);
1169 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
1170 struct irq_domain *domain = data->domain;
1171 irq_hw_number_t hwirq = data->hwirq;
1174 if (hwirq < domain->revmap_size) {
1175 domain->linear_revmap[hwirq] = 0;
1177 mutex_lock(&revmap_trees_mutex);
1178 radix_tree_delete(&domain->revmap_tree, hwirq);
1179 mutex_unlock(&revmap_trees_mutex);
1184 static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain,
1185 struct irq_data *child)
1187 struct irq_data *irq_data;
1189 irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL,
1190 irq_data_get_node(child));
1192 child->parent_data = irq_data;
1193 irq_data->irq = child->irq;
1194 irq_data->common = child->common;
1195 irq_data->domain = domain;
1201 static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs)
1203 struct irq_data *irq_data, *tmp;
1206 for (i = 0; i < nr_irqs; i++) {
1207 irq_data = irq_get_irq_data(virq + i);
1208 tmp = irq_data->parent_data;
1209 irq_data->parent_data = NULL;
1210 irq_data->domain = NULL;
1214 tmp = tmp->parent_data;
1220 static int irq_domain_alloc_irq_data(struct irq_domain *domain,
1221 unsigned int virq, unsigned int nr_irqs)
1223 struct irq_data *irq_data;
1224 struct irq_domain *parent;
1227 /* The outermost irq_data is embedded in struct irq_desc */
1228 for (i = 0; i < nr_irqs; i++) {
1229 irq_data = irq_get_irq_data(virq + i);
1230 irq_data->domain = domain;
1232 for (parent = domain->parent; parent; parent = parent->parent) {
1233 irq_data = irq_domain_insert_irq_data(parent, irq_data);
1235 irq_domain_free_irq_data(virq, i + 1);
1245 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
1246 * @domain: domain to match
1247 * @virq: IRQ number to get irq_data
1249 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
1252 struct irq_data *irq_data;
1254 for (irq_data = irq_get_irq_data(virq); irq_data;
1255 irq_data = irq_data->parent_data)
1256 if (irq_data->domain == domain)
1261 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
1264 * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain
1265 * @domain: Interrupt domain to match
1267 * @hwirq: The hwirq number
1268 * @chip: The associated interrupt chip
1269 * @chip_data: The associated chip data
1271 int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
1272 irq_hw_number_t hwirq, struct irq_chip *chip,
1275 struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
1280 irq_data->hwirq = hwirq;
1281 irq_data->chip = chip ? chip : &no_irq_chip;
1282 irq_data->chip_data = chip_data;
1286 EXPORT_SYMBOL_GPL(irq_domain_set_hwirq_and_chip);
1289 * irq_domain_set_info - Set the complete data for a @virq in @domain
1290 * @domain: Interrupt domain to match
1292 * @hwirq: The hardware interrupt number
1293 * @chip: The associated interrupt chip
1294 * @chip_data: The associated interrupt chip data
1295 * @handler: The interrupt flow handler
1296 * @handler_data: The interrupt flow handler data
1297 * @handler_name: The interrupt handler name
1299 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
1300 irq_hw_number_t hwirq, struct irq_chip *chip,
1301 void *chip_data, irq_flow_handler_t handler,
1302 void *handler_data, const char *handler_name)
1304 irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data);
1305 __irq_set_handler(virq, handler, 0, handler_name);
1306 irq_set_handler_data(virq, handler_data);
1308 EXPORT_SYMBOL(irq_domain_set_info);
1311 * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data
1312 * @irq_data: The pointer to irq_data
1314 void irq_domain_reset_irq_data(struct irq_data *irq_data)
1316 irq_data->hwirq = 0;
1317 irq_data->chip = &no_irq_chip;
1318 irq_data->chip_data = NULL;
1320 EXPORT_SYMBOL_GPL(irq_domain_reset_irq_data);
1323 * irq_domain_free_irqs_common - Clear irq_data and free the parent
1324 * @domain: Interrupt domain to match
1325 * @virq: IRQ number to start with
1326 * @nr_irqs: The number of irqs to free
1328 void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq,
1329 unsigned int nr_irqs)
1331 struct irq_data *irq_data;
1334 for (i = 0; i < nr_irqs; i++) {
1335 irq_data = irq_domain_get_irq_data(domain, virq + i);
1337 irq_domain_reset_irq_data(irq_data);
1339 irq_domain_free_irqs_parent(domain, virq, nr_irqs);
1341 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_common);
1344 * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent
1345 * @domain: Interrupt domain to match
1346 * @virq: IRQ number to start with
1347 * @nr_irqs: The number of irqs to free
1349 void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq,
1350 unsigned int nr_irqs)
1354 for (i = 0; i < nr_irqs; i++) {
1355 irq_set_handler_data(virq + i, NULL);
1356 irq_set_handler(virq + i, NULL);
1358 irq_domain_free_irqs_common(domain, virq, nr_irqs);
1361 static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain,
1362 unsigned int irq_base,
1363 unsigned int nr_irqs)
1365 domain->ops->free(domain, irq_base, nr_irqs);
1368 int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
1369 unsigned int irq_base,
1370 unsigned int nr_irqs, void *arg)
1372 return domain->ops->alloc(domain, irq_base, nr_irqs, arg);
1376 * __irq_domain_alloc_irqs - Allocate IRQs from domain
1377 * @domain: domain to allocate from
1378 * @irq_base: allocate specified IRQ nubmer if irq_base >= 0
1379 * @nr_irqs: number of IRQs to allocate
1380 * @node: NUMA node id for memory allocation
1381 * @arg: domain specific argument
1382 * @realloc: IRQ descriptors have already been allocated if true
1383 * @affinity: Optional irq affinity mask for multiqueue devices
1385 * Allocate IRQ numbers and initialized all data structures to support
1386 * hierarchy IRQ domains.
1387 * Parameter @realloc is mainly to support legacy IRQs.
1388 * Returns error code or allocated IRQ number
1390 * The whole process to setup an IRQ has been split into two steps.
1391 * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
1392 * descriptor and required hardware resources. The second step,
1393 * irq_domain_activate_irq(), is to program hardwares with preallocated
1394 * resources. In this way, it's easier to rollback when failing to
1395 * allocate resources.
1397 int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
1398 unsigned int nr_irqs, int node, void *arg,
1399 bool realloc, const struct cpumask *affinity)
1403 if (domain == NULL) {
1404 domain = irq_default_domain;
1405 if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
1409 if (!domain->ops->alloc) {
1410 pr_debug("domain->ops->alloc() is NULL\n");
1414 if (realloc && irq_base >= 0) {
1417 virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node,
1420 pr_debug("cannot allocate IRQ(base %d, count %d)\n",
1426 if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) {
1427 pr_debug("cannot allocate memory for IRQ%d\n", virq);
1432 mutex_lock(&irq_domain_mutex);
1433 ret = irq_domain_alloc_irqs_hierarchy(domain, virq, nr_irqs, arg);
1435 mutex_unlock(&irq_domain_mutex);
1436 goto out_free_irq_data;
1438 for (i = 0; i < nr_irqs; i++)
1439 irq_domain_insert_irq(virq + i);
1440 mutex_unlock(&irq_domain_mutex);
1445 irq_domain_free_irq_data(virq, nr_irqs);
1447 irq_free_descs(virq, nr_irqs);
1452 * irq_domain_free_irqs - Free IRQ number and associated data structures
1453 * @virq: base IRQ number
1454 * @nr_irqs: number of IRQs to free
1456 void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs)
1458 struct irq_data *data = irq_get_irq_data(virq);
1461 if (WARN(!data || !data->domain || !data->domain->ops->free,
1462 "NULL pointer, cannot free irq\n"))
1465 mutex_lock(&irq_domain_mutex);
1466 for (i = 0; i < nr_irqs; i++)
1467 irq_domain_remove_irq(virq + i);
1468 irq_domain_free_irqs_hierarchy(data->domain, virq, nr_irqs);
1469 mutex_unlock(&irq_domain_mutex);
1471 irq_domain_free_irq_data(virq, nr_irqs);
1472 irq_free_descs(virq, nr_irqs);
1476 * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain
1477 * @irq_base: Base IRQ number
1478 * @nr_irqs: Number of IRQs to allocate
1479 * @arg: Allocation data (arch/domain specific)
1481 * Check whether the domain has been setup recursive. If not allocate
1482 * through the parent domain.
1484 int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
1485 unsigned int irq_base, unsigned int nr_irqs,
1488 if (!domain->parent)
1491 return irq_domain_alloc_irqs_hierarchy(domain->parent, irq_base,
1494 EXPORT_SYMBOL_GPL(irq_domain_alloc_irqs_parent);
1497 * irq_domain_free_irqs_parent - Free interrupts from parent domain
1498 * @irq_base: Base IRQ number
1499 * @nr_irqs: Number of IRQs to free
1501 * Check whether the domain has been setup recursive. If not free
1502 * through the parent domain.
1504 void irq_domain_free_irqs_parent(struct irq_domain *domain,
1505 unsigned int irq_base, unsigned int nr_irqs)
1507 if (!domain->parent)
1510 irq_domain_free_irqs_hierarchy(domain->parent, irq_base, nr_irqs);
1512 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_parent);
1514 static void __irq_domain_activate_irq(struct irq_data *irq_data)
1516 if (irq_data && irq_data->domain) {
1517 struct irq_domain *domain = irq_data->domain;
1519 if (irq_data->parent_data)
1520 __irq_domain_activate_irq(irq_data->parent_data);
1521 if (domain->ops->activate)
1522 domain->ops->activate(domain, irq_data);
1526 static void __irq_domain_deactivate_irq(struct irq_data *irq_data)
1528 if (irq_data && irq_data->domain) {
1529 struct irq_domain *domain = irq_data->domain;
1531 if (domain->ops->deactivate)
1532 domain->ops->deactivate(domain, irq_data);
1533 if (irq_data->parent_data)
1534 __irq_domain_deactivate_irq(irq_data->parent_data);
1539 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
1541 * @irq_data: outermost irq_data associated with interrupt
1543 * This is the second step to call domain_ops->activate to program interrupt
1544 * controllers, so the interrupt could actually get delivered.
1546 void irq_domain_activate_irq(struct irq_data *irq_data)
1548 if (!irqd_is_activated(irq_data)) {
1549 __irq_domain_activate_irq(irq_data);
1550 irqd_set_activated(irq_data);
1555 * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to
1556 * deactivate interrupt
1557 * @irq_data: outermost irq_data associated with interrupt
1559 * It calls domain_ops->deactivate to program interrupt controllers to disable
1560 * interrupt delivery.
1562 void irq_domain_deactivate_irq(struct irq_data *irq_data)
1564 if (irqd_is_activated(irq_data)) {
1565 __irq_domain_deactivate_irq(irq_data);
1566 irqd_clr_activated(irq_data);
1570 static void irq_domain_check_hierarchy(struct irq_domain *domain)
1572 /* Hierarchy irq_domains must implement callback alloc() */
1573 if (domain->ops->alloc)
1574 domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
1578 * irq_domain_hierarchical_is_msi_remap - Check if the domain or any
1579 * parent has MSI remapping support
1580 * @domain: domain pointer
1582 bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain)
1584 for (; domain; domain = domain->parent) {
1585 if (irq_domain_is_msi_remap(domain))
1590 #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
1592 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
1593 * @domain: domain to match
1594 * @virq: IRQ number to get irq_data
1596 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
1599 struct irq_data *irq_data = irq_get_irq_data(virq);
1601 return (irq_data && irq_data->domain == domain) ? irq_data : NULL;
1603 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
1606 * irq_domain_set_info - Set the complete data for a @virq in @domain
1607 * @domain: Interrupt domain to match
1609 * @hwirq: The hardware interrupt number
1610 * @chip: The associated interrupt chip
1611 * @chip_data: The associated interrupt chip data
1612 * @handler: The interrupt flow handler
1613 * @handler_data: The interrupt flow handler data
1614 * @handler_name: The interrupt handler name
1616 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
1617 irq_hw_number_t hwirq, struct irq_chip *chip,
1618 void *chip_data, irq_flow_handler_t handler,
1619 void *handler_data, const char *handler_name)
1621 irq_set_chip_and_handler_name(virq, chip, handler, handler_name);
1622 irq_set_chip_data(virq, chip_data);
1623 irq_set_handler_data(virq, handler_data);
1626 static void irq_domain_check_hierarchy(struct irq_domain *domain)
1629 #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */
1631 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
1632 static struct dentry *domain_dir;
1635 irq_domain_debug_show_one(struct seq_file *m, struct irq_domain *d, int ind)
1637 seq_printf(m, "%*sname: %s\n", ind, "", d->name);
1638 seq_printf(m, "%*ssize: %u\n", ind + 1, "",
1639 d->revmap_size + d->revmap_direct_max_irq);
1640 seq_printf(m, "%*smapped: %u\n", ind + 1, "", d->mapcount);
1641 seq_printf(m, "%*sflags: 0x%08x\n", ind +1 , "", d->flags);
1642 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1645 seq_printf(m, "%*sparent: %s\n", ind + 1, "", d->parent->name);
1646 irq_domain_debug_show_one(m, d->parent, ind + 4);
1650 static int irq_domain_debug_show(struct seq_file *m, void *p)
1652 struct irq_domain *d = m->private;
1654 /* Default domain? Might be NULL */
1656 if (!irq_default_domain)
1658 d = irq_default_domain;
1660 irq_domain_debug_show_one(m, d, 0);
1664 static int irq_domain_debug_open(struct inode *inode, struct file *file)
1666 return single_open(file, irq_domain_debug_show, inode->i_private);
1669 static const struct file_operations dfs_domain_ops = {
1670 .open = irq_domain_debug_open,
1672 .llseek = seq_lseek,
1673 .release = single_release,
1676 static void debugfs_add_domain_dir(struct irq_domain *d)
1678 if (!d->name || !domain_dir || d->debugfs_file)
1680 d->debugfs_file = debugfs_create_file(d->name, 0444, domain_dir, d,
1684 static void debugfs_remove_domain_dir(struct irq_domain *d)
1686 debugfs_remove(d->debugfs_file);
1689 void __init irq_domain_debugfs_init(struct dentry *root)
1691 struct irq_domain *d;
1693 domain_dir = debugfs_create_dir("domains", root);
1697 debugfs_create_file("default", 0444, domain_dir, NULL, &dfs_domain_ops);
1698 mutex_lock(&irq_domain_mutex);
1699 list_for_each_entry(d, &irq_domain_list, link)
1700 debugfs_add_domain_dir(d);
1701 mutex_unlock(&irq_domain_mutex);