1 #define pr_fmt(fmt) "irq: " fmt
3 #include <linux/debugfs.h>
4 #include <linux/hardirq.h>
5 #include <linux/interrupt.h>
7 #include <linux/irqdesc.h>
8 #include <linux/irqdomain.h>
9 #include <linux/module.h>
10 #include <linux/mutex.h>
12 #include <linux/of_address.h>
13 #include <linux/of_irq.h>
14 #include <linux/topology.h>
15 #include <linux/seq_file.h>
16 #include <linux/slab.h>
17 #include <linux/smp.h>
20 static LIST_HEAD(irq_domain_list);
21 static DEFINE_MUTEX(irq_domain_mutex);
23 static DEFINE_MUTEX(revmap_trees_mutex);
24 static struct irq_domain *irq_default_domain;
26 static void irq_domain_check_hierarchy(struct irq_domain *domain);
29 struct fwnode_handle fwnode;
35 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
36 static void debugfs_add_domain_dir(struct irq_domain *d);
37 static void debugfs_remove_domain_dir(struct irq_domain *d);
39 static inline void debugfs_add_domain_dir(struct irq_domain *d) { }
40 static inline void debugfs_remove_domain_dir(struct irq_domain *d) { }
44 * irq_domain_alloc_fwnode - Allocate a fwnode_handle suitable for
45 * identifying an irq domain
46 * @type: Type of irqchip_fwnode. See linux/irqdomain.h
47 * @name: Optional user provided domain name
48 * @id: Optional user provided id if name != NULL
49 * @data: Optional user-provided data
51 * Allocate a struct irqchip_fwid, and return a poiner to the embedded
52 * fwnode_handle (or NULL on failure).
54 * Note: The types IRQCHIP_FWNODE_NAMED and IRQCHIP_FWNODE_NAMED_ID are
55 * solely to transport name information to irqdomain creation code. The
56 * node is not stored. For other types the pointer is kept in the irq
59 struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
60 const char *name, void *data)
62 struct irqchip_fwid *fwid;
65 fwid = kzalloc(sizeof(*fwid), GFP_KERNEL);
68 case IRQCHIP_FWNODE_NAMED:
69 n = kasprintf(GFP_KERNEL, "%s", name);
71 case IRQCHIP_FWNODE_NAMED_ID:
72 n = kasprintf(GFP_KERNEL, "%s-%d", name, id);
75 n = kasprintf(GFP_KERNEL, "irqchip@%p", data);
88 fwid->fwnode.type = FWNODE_IRQCHIP;
91 EXPORT_SYMBOL_GPL(__irq_domain_alloc_fwnode);
94 * irq_domain_free_fwnode - Free a non-OF-backed fwnode_handle
96 * Free a fwnode_handle allocated with irq_domain_alloc_fwnode.
98 void irq_domain_free_fwnode(struct fwnode_handle *fwnode)
100 struct irqchip_fwid *fwid;
102 if (WARN_ON(!is_fwnode_irqchip(fwnode)))
105 fwid = container_of(fwnode, struct irqchip_fwid, fwnode);
109 EXPORT_SYMBOL_GPL(irq_domain_free_fwnode);
112 * __irq_domain_add() - Allocate a new irq_domain data structure
113 * @fwnode: firmware node for the interrupt controller
114 * @size: Size of linear map; 0 for radix mapping only
115 * @hwirq_max: Maximum number of interrupts supported by controller
116 * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
118 * @ops: domain callbacks
119 * @host_data: Controller private data pointer
121 * Allocates and initialize and irq_domain structure.
122 * Returns pointer to IRQ domain, or NULL on failure.
124 struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, int size,
125 irq_hw_number_t hwirq_max, int direct_max,
126 const struct irq_domain_ops *ops,
129 struct device_node *of_node = to_of_node(fwnode);
130 struct irqchip_fwid *fwid;
131 struct irq_domain *domain;
133 static atomic_t unknown_domains;
135 domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
136 GFP_KERNEL, of_node_to_nid(of_node));
137 if (WARN_ON(!domain))
140 if (fwnode && is_fwnode_irqchip(fwnode)) {
141 fwid = container_of(fwnode, struct irqchip_fwid, fwnode);
143 switch (fwid->type) {
144 case IRQCHIP_FWNODE_NAMED:
145 case IRQCHIP_FWNODE_NAMED_ID:
146 domain->name = kstrdup(fwid->name, GFP_KERNEL);
151 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
154 domain->fwnode = fwnode;
155 domain->name = fwid->name;
158 } else if (of_node) {
162 * DT paths contain '/', which debugfs is legitimately
163 * unhappy about. Replace them with ':', which does
164 * the trick and is not as offensive as '\'...
166 name = kstrdup(of_node_full_name(of_node), GFP_KERNEL);
172 strreplace(name, '/', ':');
175 domain->fwnode = fwnode;
176 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
181 pr_err("Invalid fwnode type (%d) for irqdomain\n",
184 domain->name = kasprintf(GFP_KERNEL, "unknown-%d",
185 atomic_inc_return(&unknown_domains));
190 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
193 of_node_get(of_node);
196 INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
198 domain->host_data = host_data;
199 domain->hwirq_max = hwirq_max;
200 domain->revmap_size = size;
201 domain->revmap_direct_max_irq = direct_max;
202 irq_domain_check_hierarchy(domain);
204 mutex_lock(&irq_domain_mutex);
205 debugfs_add_domain_dir(domain);
206 list_add(&domain->link, &irq_domain_list);
207 mutex_unlock(&irq_domain_mutex);
209 pr_debug("Added domain %s\n", domain->name);
212 EXPORT_SYMBOL_GPL(__irq_domain_add);
215 * irq_domain_remove() - Remove an irq domain.
216 * @domain: domain to remove
218 * This routine is used to remove an irq domain. The caller must ensure
219 * that all mappings within the domain have been disposed of prior to
220 * use, depending on the revmap type.
222 void irq_domain_remove(struct irq_domain *domain)
224 mutex_lock(&irq_domain_mutex);
225 debugfs_remove_domain_dir(domain);
227 WARN_ON(!radix_tree_empty(&domain->revmap_tree));
229 list_del(&domain->link);
232 * If the going away domain is the default one, reset it.
234 if (unlikely(irq_default_domain == domain))
235 irq_set_default_host(NULL);
237 mutex_unlock(&irq_domain_mutex);
239 pr_debug("Removed domain %s\n", domain->name);
241 of_node_put(irq_domain_get_of_node(domain));
242 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED)
246 EXPORT_SYMBOL_GPL(irq_domain_remove);
248 void irq_domain_update_bus_token(struct irq_domain *domain,
249 enum irq_domain_bus_token bus_token)
253 if (domain->bus_token == bus_token)
256 mutex_lock(&irq_domain_mutex);
258 domain->bus_token = bus_token;
260 name = kasprintf(GFP_KERNEL, "%s-%d", domain->name, bus_token);
262 mutex_unlock(&irq_domain_mutex);
266 debugfs_remove_domain_dir(domain);
268 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED)
271 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
274 debugfs_add_domain_dir(domain);
276 mutex_unlock(&irq_domain_mutex);
280 * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
281 * @of_node: pointer to interrupt controller's device tree node.
282 * @size: total number of irqs in mapping
283 * @first_irq: first number of irq block assigned to the domain,
284 * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
285 * pre-map all of the irqs in the domain to virqs starting at first_irq.
286 * @ops: domain callbacks
287 * @host_data: Controller private data pointer
289 * Allocates an irq_domain, and optionally if first_irq is positive then also
290 * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
292 * This is intended to implement the expected behaviour for most
293 * interrupt controllers. If device tree is used, then first_irq will be 0 and
294 * irqs get mapped dynamically on the fly. However, if the controller requires
295 * static virq assignments (non-DT boot) then it will set that up correctly.
297 struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
299 unsigned int first_irq,
300 const struct irq_domain_ops *ops,
303 struct irq_domain *domain;
305 domain = __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data);
310 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
311 /* attempt to allocated irq_descs */
312 int rc = irq_alloc_descs(first_irq, first_irq, size,
313 of_node_to_nid(of_node));
315 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
318 irq_domain_associate_many(domain, first_irq, 0, size);
323 EXPORT_SYMBOL_GPL(irq_domain_add_simple);
326 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
327 * @of_node: pointer to interrupt controller's device tree node.
328 * @size: total number of irqs in legacy mapping
329 * @first_irq: first number of irq block assigned to the domain
330 * @first_hwirq: first hwirq number to use for the translation. Should normally
331 * be '0', but a positive integer can be used if the effective
332 * hwirqs numbering does not begin at zero.
333 * @ops: map/unmap domain callbacks
334 * @host_data: Controller private data pointer
336 * Note: the map() callback will be called before this function returns
337 * for all legacy interrupts except 0 (which is always the invalid irq for
338 * a legacy controller).
340 struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
342 unsigned int first_irq,
343 irq_hw_number_t first_hwirq,
344 const struct irq_domain_ops *ops,
347 struct irq_domain *domain;
349 domain = __irq_domain_add(of_node_to_fwnode(of_node), first_hwirq + size,
350 first_hwirq + size, 0, ops, host_data);
352 irq_domain_associate_many(domain, first_irq, first_hwirq, size);
356 EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
359 * irq_find_matching_fwspec() - Locates a domain for a given fwspec
360 * @fwspec: FW specifier for an interrupt
361 * @bus_token: domain-specific data
363 struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
364 enum irq_domain_bus_token bus_token)
366 struct irq_domain *h, *found = NULL;
367 struct fwnode_handle *fwnode = fwspec->fwnode;
370 /* We might want to match the legacy controller last since
371 * it might potentially be set to match all interrupts in
372 * the absence of a device node. This isn't a problem so far
375 * bus_token == DOMAIN_BUS_ANY matches any domain, any other
376 * values must generate an exact match for the domain to be
379 mutex_lock(&irq_domain_mutex);
380 list_for_each_entry(h, &irq_domain_list, link) {
381 if (h->ops->select && fwspec->param_count)
382 rc = h->ops->select(h, fwspec, bus_token);
383 else if (h->ops->match)
384 rc = h->ops->match(h, to_of_node(fwnode), bus_token);
386 rc = ((fwnode != NULL) && (h->fwnode == fwnode) &&
387 ((bus_token == DOMAIN_BUS_ANY) ||
388 (h->bus_token == bus_token)));
395 mutex_unlock(&irq_domain_mutex);
398 EXPORT_SYMBOL_GPL(irq_find_matching_fwspec);
401 * irq_domain_check_msi_remap - Check whether all MSI irq domains implement
404 * Return: false if any MSI irq domain does not support IRQ remapping,
405 * true otherwise (including if there is no MSI irq domain)
407 bool irq_domain_check_msi_remap(void)
409 struct irq_domain *h;
412 mutex_lock(&irq_domain_mutex);
413 list_for_each_entry(h, &irq_domain_list, link) {
414 if (irq_domain_is_msi(h) &&
415 !irq_domain_hierarchical_is_msi_remap(h)) {
420 mutex_unlock(&irq_domain_mutex);
423 EXPORT_SYMBOL_GPL(irq_domain_check_msi_remap);
426 * irq_set_default_host() - Set a "default" irq domain
427 * @domain: default domain pointer
429 * For convenience, it's possible to set a "default" domain that will be used
430 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
431 * platforms that want to manipulate a few hard coded interrupt numbers that
432 * aren't properly represented in the device-tree.
434 void irq_set_default_host(struct irq_domain *domain)
436 pr_debug("Default domain set to @0x%p\n", domain);
438 irq_default_domain = domain;
440 EXPORT_SYMBOL_GPL(irq_set_default_host);
442 void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
444 struct irq_data *irq_data = irq_get_irq_data(irq);
445 irq_hw_number_t hwirq;
447 if (WARN(!irq_data || irq_data->domain != domain,
448 "virq%i doesn't exist; cannot disassociate\n", irq))
451 hwirq = irq_data->hwirq;
452 irq_set_status_flags(irq, IRQ_NOREQUEST);
454 /* remove chip and handler */
455 irq_set_chip_and_handler(irq, NULL, NULL);
457 /* Make sure it's completed */
458 synchronize_irq(irq);
460 /* Tell the PIC about it */
461 if (domain->ops->unmap)
462 domain->ops->unmap(domain, irq);
465 irq_data->domain = NULL;
469 /* Clear reverse map for this hwirq */
470 if (hwirq < domain->revmap_size) {
471 domain->linear_revmap[hwirq] = 0;
473 mutex_lock(&revmap_trees_mutex);
474 radix_tree_delete(&domain->revmap_tree, hwirq);
475 mutex_unlock(&revmap_trees_mutex);
479 int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
480 irq_hw_number_t hwirq)
482 struct irq_data *irq_data = irq_get_irq_data(virq);
485 if (WARN(hwirq >= domain->hwirq_max,
486 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
488 if (WARN(!irq_data, "error: virq%i is not allocated", virq))
490 if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
493 mutex_lock(&irq_domain_mutex);
494 irq_data->hwirq = hwirq;
495 irq_data->domain = domain;
496 if (domain->ops->map) {
497 ret = domain->ops->map(domain, virq, hwirq);
500 * If map() returns -EPERM, this interrupt is protected
501 * by the firmware or some other service and shall not
502 * be mapped. Don't bother telling the user about it.
505 pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
506 domain->name, hwirq, virq, ret);
508 irq_data->domain = NULL;
510 mutex_unlock(&irq_domain_mutex);
514 /* If not already assigned, give the domain the chip's name */
515 if (!domain->name && irq_data->chip)
516 domain->name = irq_data->chip->name;
520 if (hwirq < domain->revmap_size) {
521 domain->linear_revmap[hwirq] = virq;
523 mutex_lock(&revmap_trees_mutex);
524 radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
525 mutex_unlock(&revmap_trees_mutex);
527 mutex_unlock(&irq_domain_mutex);
529 irq_clear_status_flags(virq, IRQ_NOREQUEST);
533 EXPORT_SYMBOL_GPL(irq_domain_associate);
535 void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
536 irq_hw_number_t hwirq_base, int count)
538 struct device_node *of_node;
541 of_node = irq_domain_get_of_node(domain);
542 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
543 of_node_full_name(of_node), irq_base, (int)hwirq_base, count);
545 for (i = 0; i < count; i++) {
546 irq_domain_associate(domain, irq_base + i, hwirq_base + i);
549 EXPORT_SYMBOL_GPL(irq_domain_associate_many);
552 * irq_create_direct_mapping() - Allocate an irq for direct mapping
553 * @domain: domain to allocate the irq for or NULL for default domain
555 * This routine is used for irq controllers which can choose the hardware
556 * interrupt numbers they generate. In such a case it's simplest to use
557 * the linux irq as the hardware interrupt number. It still uses the linear
558 * or radix tree to store the mapping, but the irq controller can optimize
559 * the revmap path by using the hwirq directly.
561 unsigned int irq_create_direct_mapping(struct irq_domain *domain)
563 struct device_node *of_node;
567 domain = irq_default_domain;
569 of_node = irq_domain_get_of_node(domain);
570 virq = irq_alloc_desc_from(1, of_node_to_nid(of_node));
572 pr_debug("create_direct virq allocation failed\n");
575 if (virq >= domain->revmap_direct_max_irq) {
576 pr_err("ERROR: no free irqs available below %i maximum\n",
577 domain->revmap_direct_max_irq);
581 pr_debug("create_direct obtained virq %d\n", virq);
583 if (irq_domain_associate(domain, virq, virq)) {
590 EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
593 * irq_create_mapping() - Map a hardware interrupt into linux irq space
594 * @domain: domain owning this hardware interrupt or NULL for default domain
595 * @hwirq: hardware irq number in that domain space
597 * Only one mapping per hardware interrupt is permitted. Returns a linux
599 * If the sense/trigger is to be specified, set_irq_type() should be called
600 * on the number returned from that call.
602 unsigned int irq_create_mapping(struct irq_domain *domain,
603 irq_hw_number_t hwirq)
605 struct device_node *of_node;
608 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
610 /* Look for default domain if nececssary */
612 domain = irq_default_domain;
613 if (domain == NULL) {
614 WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
617 pr_debug("-> using domain @%p\n", domain);
619 of_node = irq_domain_get_of_node(domain);
621 /* Check if mapping already exists */
622 virq = irq_find_mapping(domain, hwirq);
624 pr_debug("-> existing mapping on virq %d\n", virq);
628 /* Allocate a virtual interrupt number */
629 virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(of_node), NULL);
631 pr_debug("-> virq allocation failed\n");
635 if (irq_domain_associate(domain, virq, hwirq)) {
640 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
641 hwirq, of_node_full_name(of_node), virq);
645 EXPORT_SYMBOL_GPL(irq_create_mapping);
648 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
649 * @domain: domain owning the interrupt range
650 * @irq_base: beginning of linux IRQ range
651 * @hwirq_base: beginning of hardware IRQ range
652 * @count: Number of interrupts to map
654 * This routine is used for allocating and mapping a range of hardware
655 * irqs to linux irqs where the linux irq numbers are at pre-defined
656 * locations. For use by controllers that already have static mappings
657 * to insert in to the domain.
659 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
662 * 0 is returned upon success, while any failure to establish a static
663 * mapping is treated as an error.
665 int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
666 irq_hw_number_t hwirq_base, int count)
668 struct device_node *of_node;
671 of_node = irq_domain_get_of_node(domain);
672 ret = irq_alloc_descs(irq_base, irq_base, count,
673 of_node_to_nid(of_node));
674 if (unlikely(ret < 0))
677 irq_domain_associate_many(domain, irq_base, hwirq_base, count);
680 EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
682 static int irq_domain_translate(struct irq_domain *d,
683 struct irq_fwspec *fwspec,
684 irq_hw_number_t *hwirq, unsigned int *type)
686 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
687 if (d->ops->translate)
688 return d->ops->translate(d, fwspec, hwirq, type);
691 return d->ops->xlate(d, to_of_node(fwspec->fwnode),
692 fwspec->param, fwspec->param_count,
695 /* If domain has no translation, then we assume interrupt line */
696 *hwirq = fwspec->param[0];
700 static void of_phandle_args_to_fwspec(struct of_phandle_args *irq_data,
701 struct irq_fwspec *fwspec)
705 fwspec->fwnode = irq_data->np ? &irq_data->np->fwnode : NULL;
706 fwspec->param_count = irq_data->args_count;
708 for (i = 0; i < irq_data->args_count; i++)
709 fwspec->param[i] = irq_data->args[i];
712 unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
714 struct irq_domain *domain;
715 struct irq_data *irq_data;
716 irq_hw_number_t hwirq;
717 unsigned int type = IRQ_TYPE_NONE;
720 if (fwspec->fwnode) {
721 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_WIRED);
723 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_ANY);
725 domain = irq_default_domain;
729 pr_warn("no irq domain found for %s !\n",
730 of_node_full_name(to_of_node(fwspec->fwnode)));
734 if (irq_domain_translate(domain, fwspec, &hwirq, &type))
738 * WARN if the irqchip returns a type with bits
739 * outside the sense mask set and clear these bits.
741 if (WARN_ON(type & ~IRQ_TYPE_SENSE_MASK))
742 type &= IRQ_TYPE_SENSE_MASK;
745 * If we've already configured this interrupt,
746 * don't do it again, or hell will break loose.
748 virq = irq_find_mapping(domain, hwirq);
751 * If the trigger type is not specified or matches the
752 * current trigger type then we are done so return the
755 if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq))
759 * If the trigger type has not been set yet, then set
760 * it now and return the interrupt number.
762 if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) {
763 irq_data = irq_get_irq_data(virq);
767 irqd_set_trigger_type(irq_data, type);
771 pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n",
772 hwirq, of_node_full_name(to_of_node(fwspec->fwnode)));
776 if (irq_domain_is_hierarchy(domain)) {
777 virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, fwspec);
782 virq = irq_create_mapping(domain, hwirq);
787 irq_data = irq_get_irq_data(virq);
789 if (irq_domain_is_hierarchy(domain))
790 irq_domain_free_irqs(virq, 1);
792 irq_dispose_mapping(virq);
796 /* Store trigger type */
797 irqd_set_trigger_type(irq_data, type);
801 EXPORT_SYMBOL_GPL(irq_create_fwspec_mapping);
803 unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
805 struct irq_fwspec fwspec;
807 of_phandle_args_to_fwspec(irq_data, &fwspec);
808 return irq_create_fwspec_mapping(&fwspec);
810 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
813 * irq_dispose_mapping() - Unmap an interrupt
814 * @virq: linux irq number of the interrupt to unmap
816 void irq_dispose_mapping(unsigned int virq)
818 struct irq_data *irq_data = irq_get_irq_data(virq);
819 struct irq_domain *domain;
821 if (!virq || !irq_data)
824 domain = irq_data->domain;
825 if (WARN_ON(domain == NULL))
828 if (irq_domain_is_hierarchy(domain)) {
829 irq_domain_free_irqs(virq, 1);
831 irq_domain_disassociate(domain, virq);
835 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
838 * irq_find_mapping() - Find a linux irq from an hw irq number.
839 * @domain: domain owning this hardware interrupt
840 * @hwirq: hardware irq number in that domain space
842 unsigned int irq_find_mapping(struct irq_domain *domain,
843 irq_hw_number_t hwirq)
845 struct irq_data *data;
847 /* Look for default domain if nececssary */
849 domain = irq_default_domain;
853 if (hwirq < domain->revmap_direct_max_irq) {
854 data = irq_domain_get_irq_data(domain, hwirq);
855 if (data && data->hwirq == hwirq)
859 /* Check if the hwirq is in the linear revmap. */
860 if (hwirq < domain->revmap_size)
861 return domain->linear_revmap[hwirq];
864 data = radix_tree_lookup(&domain->revmap_tree, hwirq);
866 return data ? data->irq : 0;
868 EXPORT_SYMBOL_GPL(irq_find_mapping);
870 #ifdef CONFIG_IRQ_DOMAIN_DEBUG
871 static void virq_debug_show_one(struct seq_file *m, struct irq_desc *desc)
873 struct irq_domain *domain;
874 struct irq_data *data;
876 domain = desc->irq_data.domain;
877 data = &desc->irq_data;
880 unsigned int irq = data->irq;
881 unsigned long hwirq = data->hwirq;
882 struct irq_chip *chip;
885 if (data == &desc->irq_data)
886 seq_printf(m, "%5d ", irq);
888 seq_printf(m, "%5d+ ", irq);
889 seq_printf(m, "0x%05lx ", hwirq);
891 chip = irq_data_get_irq_chip(data);
892 seq_printf(m, "%-15s ", (chip && chip->name) ? chip->name : "none");
894 seq_printf(m, data ? "0x%p " : " %p ",
895 irq_data_get_irq_chip_data(data));
897 seq_printf(m, " %c ", (desc->action && desc->action->handler) ? '*' : ' ');
898 direct = (irq == hwirq) && (irq < domain->revmap_direct_max_irq);
899 seq_printf(m, "%6s%-8s ",
900 (hwirq < domain->revmap_size) ? "LINEAR" : "RADIX",
901 direct ? "(DIRECT)" : "");
902 seq_printf(m, "%s\n", domain->name);
903 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
904 domain = domain->parent;
905 data = data->parent_data;
912 static int virq_debug_show(struct seq_file *m, void *private)
915 struct irq_desc *desc;
916 struct irq_domain *domain;
917 struct radix_tree_iter iter;
921 seq_printf(m, " %-16s %-6s %-10s %-10s %s\n",
922 "name", "mapped", "linear-max", "direct-max", "devtree-node");
923 mutex_lock(&irq_domain_mutex);
924 list_for_each_entry(domain, &irq_domain_list, link) {
925 struct device_node *of_node;
930 of_node = irq_domain_get_of_node(domain);
932 name = of_node_full_name(of_node);
933 else if (is_fwnode_irqchip(domain->fwnode))
934 name = container_of(domain->fwnode, struct irqchip_fwid,
939 radix_tree_for_each_slot(slot, &domain->revmap_tree, &iter, 0)
941 seq_printf(m, "%c%-16s %6u %10u %10u %s\n",
942 domain == irq_default_domain ? '*' : ' ', domain->name,
943 domain->revmap_size + count, domain->revmap_size,
944 domain->revmap_direct_max_irq,
947 mutex_unlock(&irq_domain_mutex);
949 seq_printf(m, "%-5s %-7s %-15s %-*s %6s %-14s %s\n", "irq", "hwirq",
950 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
951 "active", "type", "domain");
953 for (i = 1; i < nr_irqs; i++) {
954 desc = irq_to_desc(i);
958 raw_spin_lock_irqsave(&desc->lock, flags);
959 virq_debug_show_one(m, desc);
960 raw_spin_unlock_irqrestore(&desc->lock, flags);
966 static int virq_debug_open(struct inode *inode, struct file *file)
968 return single_open(file, virq_debug_show, inode->i_private);
971 static const struct file_operations virq_debug_fops = {
972 .open = virq_debug_open,
975 .release = single_release,
978 static int __init irq_debugfs_init(void)
980 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
981 NULL, &virq_debug_fops) == NULL)
986 __initcall(irq_debugfs_init);
987 #endif /* CONFIG_IRQ_DOMAIN_DEBUG */
990 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
992 * Device Tree IRQ specifier translation function which works with one cell
993 * bindings where the cell value maps directly to the hwirq number.
995 int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
996 const u32 *intspec, unsigned int intsize,
997 unsigned long *out_hwirq, unsigned int *out_type)
999 if (WARN_ON(intsize < 1))
1001 *out_hwirq = intspec[0];
1002 *out_type = IRQ_TYPE_NONE;
1005 EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
1008 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
1010 * Device Tree IRQ specifier translation function which works with two cell
1011 * bindings where the cell values map directly to the hwirq number
1012 * and linux irq flags.
1014 int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
1015 const u32 *intspec, unsigned int intsize,
1016 irq_hw_number_t *out_hwirq, unsigned int *out_type)
1018 if (WARN_ON(intsize < 2))
1020 *out_hwirq = intspec[0];
1021 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
1024 EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
1027 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
1029 * Device Tree IRQ specifier translation function which works with either one
1030 * or two cell bindings where the cell values map directly to the hwirq number
1031 * and linux irq flags.
1033 * Note: don't use this function unless your interrupt controller explicitly
1034 * supports both one and two cell bindings. For the majority of controllers
1035 * the _onecell() or _twocell() variants above should be used.
1037 int irq_domain_xlate_onetwocell(struct irq_domain *d,
1038 struct device_node *ctrlr,
1039 const u32 *intspec, unsigned int intsize,
1040 unsigned long *out_hwirq, unsigned int *out_type)
1042 if (WARN_ON(intsize < 1))
1044 *out_hwirq = intspec[0];
1046 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
1048 *out_type = IRQ_TYPE_NONE;
1051 EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
1053 const struct irq_domain_ops irq_domain_simple_ops = {
1054 .xlate = irq_domain_xlate_onetwocell,
1056 EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
1058 int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq,
1059 int node, const struct cpumask *affinity)
1064 virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE,
1067 hint = hwirq % nr_irqs;
1070 virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE,
1072 if (virq <= 0 && hint > 1) {
1073 virq = __irq_alloc_descs(-1, 1, cnt, node, THIS_MODULE,
1081 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1083 * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy
1084 * @parent: Parent irq domain to associate with the new domain
1085 * @flags: Irq domain flags associated to the domain
1086 * @size: Size of the domain. See below
1087 * @fwnode: Optional fwnode of the interrupt controller
1088 * @ops: Pointer to the interrupt domain callbacks
1089 * @host_data: Controller private data pointer
1091 * If @size is 0 a tree domain is created, otherwise a linear domain.
1093 * If successful the parent is associated to the new domain and the
1094 * domain flags are set.
1095 * Returns pointer to IRQ domain, or NULL on failure.
1097 struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
1100 struct fwnode_handle *fwnode,
1101 const struct irq_domain_ops *ops,
1104 struct irq_domain *domain;
1107 domain = irq_domain_create_linear(fwnode, size, ops, host_data);
1109 domain = irq_domain_create_tree(fwnode, ops, host_data);
1111 domain->parent = parent;
1112 domain->flags |= flags;
1117 EXPORT_SYMBOL_GPL(irq_domain_create_hierarchy);
1119 static void irq_domain_insert_irq(int virq)
1121 struct irq_data *data;
1123 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
1124 struct irq_domain *domain = data->domain;
1125 irq_hw_number_t hwirq = data->hwirq;
1128 if (hwirq < domain->revmap_size) {
1129 domain->linear_revmap[hwirq] = virq;
1131 mutex_lock(&revmap_trees_mutex);
1132 radix_tree_insert(&domain->revmap_tree, hwirq, data);
1133 mutex_unlock(&revmap_trees_mutex);
1136 /* If not already assigned, give the domain the chip's name */
1137 if (!domain->name && data->chip)
1138 domain->name = data->chip->name;
1141 irq_clear_status_flags(virq, IRQ_NOREQUEST);
1144 static void irq_domain_remove_irq(int virq)
1146 struct irq_data *data;
1148 irq_set_status_flags(virq, IRQ_NOREQUEST);
1149 irq_set_chip_and_handler(virq, NULL, NULL);
1150 synchronize_irq(virq);
1153 for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
1154 struct irq_domain *domain = data->domain;
1155 irq_hw_number_t hwirq = data->hwirq;
1158 if (hwirq < domain->revmap_size) {
1159 domain->linear_revmap[hwirq] = 0;
1161 mutex_lock(&revmap_trees_mutex);
1162 radix_tree_delete(&domain->revmap_tree, hwirq);
1163 mutex_unlock(&revmap_trees_mutex);
1168 static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain,
1169 struct irq_data *child)
1171 struct irq_data *irq_data;
1173 irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL,
1174 irq_data_get_node(child));
1176 child->parent_data = irq_data;
1177 irq_data->irq = child->irq;
1178 irq_data->common = child->common;
1179 irq_data->domain = domain;
1185 static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs)
1187 struct irq_data *irq_data, *tmp;
1190 for (i = 0; i < nr_irqs; i++) {
1191 irq_data = irq_get_irq_data(virq + i);
1192 tmp = irq_data->parent_data;
1193 irq_data->parent_data = NULL;
1194 irq_data->domain = NULL;
1198 tmp = tmp->parent_data;
1204 static int irq_domain_alloc_irq_data(struct irq_domain *domain,
1205 unsigned int virq, unsigned int nr_irqs)
1207 struct irq_data *irq_data;
1208 struct irq_domain *parent;
1211 /* The outermost irq_data is embedded in struct irq_desc */
1212 for (i = 0; i < nr_irqs; i++) {
1213 irq_data = irq_get_irq_data(virq + i);
1214 irq_data->domain = domain;
1216 for (parent = domain->parent; parent; parent = parent->parent) {
1217 irq_data = irq_domain_insert_irq_data(parent, irq_data);
1219 irq_domain_free_irq_data(virq, i + 1);
1229 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
1230 * @domain: domain to match
1231 * @virq: IRQ number to get irq_data
1233 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
1236 struct irq_data *irq_data;
1238 for (irq_data = irq_get_irq_data(virq); irq_data;
1239 irq_data = irq_data->parent_data)
1240 if (irq_data->domain == domain)
1245 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
1248 * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain
1249 * @domain: Interrupt domain to match
1251 * @hwirq: The hwirq number
1252 * @chip: The associated interrupt chip
1253 * @chip_data: The associated chip data
1255 int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
1256 irq_hw_number_t hwirq, struct irq_chip *chip,
1259 struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
1264 irq_data->hwirq = hwirq;
1265 irq_data->chip = chip ? chip : &no_irq_chip;
1266 irq_data->chip_data = chip_data;
1270 EXPORT_SYMBOL_GPL(irq_domain_set_hwirq_and_chip);
1273 * irq_domain_set_info - Set the complete data for a @virq in @domain
1274 * @domain: Interrupt domain to match
1276 * @hwirq: The hardware interrupt number
1277 * @chip: The associated interrupt chip
1278 * @chip_data: The associated interrupt chip data
1279 * @handler: The interrupt flow handler
1280 * @handler_data: The interrupt flow handler data
1281 * @handler_name: The interrupt handler name
1283 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
1284 irq_hw_number_t hwirq, struct irq_chip *chip,
1285 void *chip_data, irq_flow_handler_t handler,
1286 void *handler_data, const char *handler_name)
1288 irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data);
1289 __irq_set_handler(virq, handler, 0, handler_name);
1290 irq_set_handler_data(virq, handler_data);
1292 EXPORT_SYMBOL(irq_domain_set_info);
1295 * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data
1296 * @irq_data: The pointer to irq_data
1298 void irq_domain_reset_irq_data(struct irq_data *irq_data)
1300 irq_data->hwirq = 0;
1301 irq_data->chip = &no_irq_chip;
1302 irq_data->chip_data = NULL;
1304 EXPORT_SYMBOL_GPL(irq_domain_reset_irq_data);
1307 * irq_domain_free_irqs_common - Clear irq_data and free the parent
1308 * @domain: Interrupt domain to match
1309 * @virq: IRQ number to start with
1310 * @nr_irqs: The number of irqs to free
1312 void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq,
1313 unsigned int nr_irqs)
1315 struct irq_data *irq_data;
1318 for (i = 0; i < nr_irqs; i++) {
1319 irq_data = irq_domain_get_irq_data(domain, virq + i);
1321 irq_domain_reset_irq_data(irq_data);
1323 irq_domain_free_irqs_parent(domain, virq, nr_irqs);
1325 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_common);
1328 * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent
1329 * @domain: Interrupt domain to match
1330 * @virq: IRQ number to start with
1331 * @nr_irqs: The number of irqs to free
1333 void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq,
1334 unsigned int nr_irqs)
1338 for (i = 0; i < nr_irqs; i++) {
1339 irq_set_handler_data(virq + i, NULL);
1340 irq_set_handler(virq + i, NULL);
1342 irq_domain_free_irqs_common(domain, virq, nr_irqs);
1345 static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain,
1346 unsigned int irq_base,
1347 unsigned int nr_irqs)
1349 domain->ops->free(domain, irq_base, nr_irqs);
1352 int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
1353 unsigned int irq_base,
1354 unsigned int nr_irqs, void *arg)
1356 return domain->ops->alloc(domain, irq_base, nr_irqs, arg);
1360 * __irq_domain_alloc_irqs - Allocate IRQs from domain
1361 * @domain: domain to allocate from
1362 * @irq_base: allocate specified IRQ nubmer if irq_base >= 0
1363 * @nr_irqs: number of IRQs to allocate
1364 * @node: NUMA node id for memory allocation
1365 * @arg: domain specific argument
1366 * @realloc: IRQ descriptors have already been allocated if true
1367 * @affinity: Optional irq affinity mask for multiqueue devices
1369 * Allocate IRQ numbers and initialized all data structures to support
1370 * hierarchy IRQ domains.
1371 * Parameter @realloc is mainly to support legacy IRQs.
1372 * Returns error code or allocated IRQ number
1374 * The whole process to setup an IRQ has been split into two steps.
1375 * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
1376 * descriptor and required hardware resources. The second step,
1377 * irq_domain_activate_irq(), is to program hardwares with preallocated
1378 * resources. In this way, it's easier to rollback when failing to
1379 * allocate resources.
1381 int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
1382 unsigned int nr_irqs, int node, void *arg,
1383 bool realloc, const struct cpumask *affinity)
1387 if (domain == NULL) {
1388 domain = irq_default_domain;
1389 if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
1393 if (!domain->ops->alloc) {
1394 pr_debug("domain->ops->alloc() is NULL\n");
1398 if (realloc && irq_base >= 0) {
1401 virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node,
1404 pr_debug("cannot allocate IRQ(base %d, count %d)\n",
1410 if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) {
1411 pr_debug("cannot allocate memory for IRQ%d\n", virq);
1416 mutex_lock(&irq_domain_mutex);
1417 ret = irq_domain_alloc_irqs_hierarchy(domain, virq, nr_irqs, arg);
1419 mutex_unlock(&irq_domain_mutex);
1420 goto out_free_irq_data;
1422 for (i = 0; i < nr_irqs; i++)
1423 irq_domain_insert_irq(virq + i);
1424 mutex_unlock(&irq_domain_mutex);
1429 irq_domain_free_irq_data(virq, nr_irqs);
1431 irq_free_descs(virq, nr_irqs);
1436 * irq_domain_free_irqs - Free IRQ number and associated data structures
1437 * @virq: base IRQ number
1438 * @nr_irqs: number of IRQs to free
1440 void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs)
1442 struct irq_data *data = irq_get_irq_data(virq);
1445 if (WARN(!data || !data->domain || !data->domain->ops->free,
1446 "NULL pointer, cannot free irq\n"))
1449 mutex_lock(&irq_domain_mutex);
1450 for (i = 0; i < nr_irqs; i++)
1451 irq_domain_remove_irq(virq + i);
1452 irq_domain_free_irqs_hierarchy(data->domain, virq, nr_irqs);
1453 mutex_unlock(&irq_domain_mutex);
1455 irq_domain_free_irq_data(virq, nr_irqs);
1456 irq_free_descs(virq, nr_irqs);
1460 * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain
1461 * @irq_base: Base IRQ number
1462 * @nr_irqs: Number of IRQs to allocate
1463 * @arg: Allocation data (arch/domain specific)
1465 * Check whether the domain has been setup recursive. If not allocate
1466 * through the parent domain.
1468 int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
1469 unsigned int irq_base, unsigned int nr_irqs,
1472 if (!domain->parent)
1475 return irq_domain_alloc_irqs_hierarchy(domain->parent, irq_base,
1478 EXPORT_SYMBOL_GPL(irq_domain_alloc_irqs_parent);
1481 * irq_domain_free_irqs_parent - Free interrupts from parent domain
1482 * @irq_base: Base IRQ number
1483 * @nr_irqs: Number of IRQs to free
1485 * Check whether the domain has been setup recursive. If not free
1486 * through the parent domain.
1488 void irq_domain_free_irqs_parent(struct irq_domain *domain,
1489 unsigned int irq_base, unsigned int nr_irqs)
1491 if (!domain->parent)
1494 irq_domain_free_irqs_hierarchy(domain->parent, irq_base, nr_irqs);
1496 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_parent);
1498 static void __irq_domain_activate_irq(struct irq_data *irq_data)
1500 if (irq_data && irq_data->domain) {
1501 struct irq_domain *domain = irq_data->domain;
1503 if (irq_data->parent_data)
1504 __irq_domain_activate_irq(irq_data->parent_data);
1505 if (domain->ops->activate)
1506 domain->ops->activate(domain, irq_data);
1510 static void __irq_domain_deactivate_irq(struct irq_data *irq_data)
1512 if (irq_data && irq_data->domain) {
1513 struct irq_domain *domain = irq_data->domain;
1515 if (domain->ops->deactivate)
1516 domain->ops->deactivate(domain, irq_data);
1517 if (irq_data->parent_data)
1518 __irq_domain_deactivate_irq(irq_data->parent_data);
1523 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
1525 * @irq_data: outermost irq_data associated with interrupt
1527 * This is the second step to call domain_ops->activate to program interrupt
1528 * controllers, so the interrupt could actually get delivered.
1530 void irq_domain_activate_irq(struct irq_data *irq_data)
1532 if (!irqd_is_activated(irq_data)) {
1533 __irq_domain_activate_irq(irq_data);
1534 irqd_set_activated(irq_data);
1539 * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to
1540 * deactivate interrupt
1541 * @irq_data: outermost irq_data associated with interrupt
1543 * It calls domain_ops->deactivate to program interrupt controllers to disable
1544 * interrupt delivery.
1546 void irq_domain_deactivate_irq(struct irq_data *irq_data)
1548 if (irqd_is_activated(irq_data)) {
1549 __irq_domain_deactivate_irq(irq_data);
1550 irqd_clr_activated(irq_data);
1554 static void irq_domain_check_hierarchy(struct irq_domain *domain)
1556 /* Hierarchy irq_domains must implement callback alloc() */
1557 if (domain->ops->alloc)
1558 domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
1562 * irq_domain_hierarchical_is_msi_remap - Check if the domain or any
1563 * parent has MSI remapping support
1564 * @domain: domain pointer
1566 bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain)
1568 for (; domain; domain = domain->parent) {
1569 if (irq_domain_is_msi_remap(domain))
1574 #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
1576 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
1577 * @domain: domain to match
1578 * @virq: IRQ number to get irq_data
1580 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
1583 struct irq_data *irq_data = irq_get_irq_data(virq);
1585 return (irq_data && irq_data->domain == domain) ? irq_data : NULL;
1587 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data);
1590 * irq_domain_set_info - Set the complete data for a @virq in @domain
1591 * @domain: Interrupt domain to match
1593 * @hwirq: The hardware interrupt number
1594 * @chip: The associated interrupt chip
1595 * @chip_data: The associated interrupt chip data
1596 * @handler: The interrupt flow handler
1597 * @handler_data: The interrupt flow handler data
1598 * @handler_name: The interrupt handler name
1600 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
1601 irq_hw_number_t hwirq, struct irq_chip *chip,
1602 void *chip_data, irq_flow_handler_t handler,
1603 void *handler_data, const char *handler_name)
1605 irq_set_chip_and_handler_name(virq, chip, handler, handler_name);
1606 irq_set_chip_data(virq, chip_data);
1607 irq_set_handler_data(virq, handler_data);
1610 static void irq_domain_check_hierarchy(struct irq_domain *domain)
1613 #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */
1615 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
1616 static struct dentry *domain_dir;
1619 irq_domain_debug_show_one(struct seq_file *m, struct irq_domain *d, int ind)
1621 seq_printf(m, "%*sname: %s\n", ind, "", d->name);
1622 seq_printf(m, "%*ssize: %u\n", ind + 1, "",
1623 d->revmap_size + d->revmap_direct_max_irq);
1624 seq_printf(m, "%*smapped: %u\n", ind + 1, "", d->mapcount);
1625 seq_printf(m, "%*sflags: 0x%08x\n", ind +1 , "", d->flags);
1626 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1629 seq_printf(m, "%*sparent: %s\n", ind + 1, "", d->parent->name);
1630 irq_domain_debug_show_one(m, d->parent, ind + 4);
1634 static int irq_domain_debug_show(struct seq_file *m, void *p)
1636 struct irq_domain *d = m->private;
1638 /* Default domain? Might be NULL */
1640 if (!irq_default_domain)
1642 d = irq_default_domain;
1644 irq_domain_debug_show_one(m, d, 0);
1648 static int irq_domain_debug_open(struct inode *inode, struct file *file)
1650 return single_open(file, irq_domain_debug_show, inode->i_private);
1653 static const struct file_operations dfs_domain_ops = {
1654 .open = irq_domain_debug_open,
1656 .llseek = seq_lseek,
1657 .release = single_release,
1660 static void debugfs_add_domain_dir(struct irq_domain *d)
1662 if (!d->name || !domain_dir || d->debugfs_file)
1664 d->debugfs_file = debugfs_create_file(d->name, 0444, domain_dir, d,
1668 static void debugfs_remove_domain_dir(struct irq_domain *d)
1670 if (d->debugfs_file)
1671 debugfs_remove(d->debugfs_file);
1674 void __init irq_domain_debugfs_init(struct dentry *root)
1676 struct irq_domain *d;
1678 domain_dir = debugfs_create_dir("domains", root);
1682 debugfs_create_file("default", 0444, domain_dir, NULL, &dfs_domain_ops);
1683 mutex_lock(&irq_domain_mutex);
1684 list_for_each_entry(d, &irq_domain_list, link)
1685 debugfs_add_domain_dir(d);
1686 mutex_unlock(&irq_domain_mutex);