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/topology.h>
14 #include <linux/seq_file.h>
15 #include <linux/slab.h>
16 #include <linux/smp.h>
19 static LIST_HEAD(irq_domain_list);
20 static DEFINE_MUTEX(irq_domain_mutex);
22 static DEFINE_MUTEX(revmap_trees_mutex);
23 static struct irq_domain *irq_default_domain;
26 * irq_domain_alloc() - Allocate a new irq_domain data structure
27 * @of_node: optional device-tree node of the interrupt controller
28 * @revmap_type: type of reverse mapping to use
29 * @ops: map/unmap domain callbacks
30 * @host_data: Controller private data pointer
32 * Allocates and initialize and irq_domain structure. Caller is expected to
33 * register allocated irq_domain with irq_domain_register(). Returns pointer
34 * to IRQ domain, or NULL on failure.
36 static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
37 unsigned int revmap_type,
38 const struct irq_domain_ops *ops,
41 struct irq_domain *domain;
43 domain = kzalloc_node(sizeof(*domain), GFP_KERNEL,
44 of_node_to_nid(of_node));
49 domain->revmap_type = revmap_type;
51 domain->host_data = host_data;
52 domain->of_node = of_node_get(of_node);
57 static void irq_domain_free(struct irq_domain *domain)
59 of_node_put(domain->of_node);
63 static void irq_domain_add(struct irq_domain *domain)
65 mutex_lock(&irq_domain_mutex);
66 list_add(&domain->link, &irq_domain_list);
67 mutex_unlock(&irq_domain_mutex);
68 pr_debug("Allocated domain of type %d @0x%p\n",
69 domain->revmap_type, domain);
73 * irq_domain_remove() - Remove an irq domain.
74 * @domain: domain to remove
76 * This routine is used to remove an irq domain. The caller must ensure
77 * that all mappings within the domain have been disposed of prior to
78 * use, depending on the revmap type.
80 void irq_domain_remove(struct irq_domain *domain)
82 mutex_lock(&irq_domain_mutex);
84 switch (domain->revmap_type) {
85 case IRQ_DOMAIN_MAP_LEGACY:
87 * Legacy domains don't manage their own irq_desc
88 * allocations, we expect the caller to handle irq_desc
89 * freeing on their own.
92 case IRQ_DOMAIN_MAP_TREE:
94 * radix_tree_delete() takes care of destroying the root
95 * node when all entries are removed. Shout if there are
98 WARN_ON(domain->revmap_data.tree.height);
100 case IRQ_DOMAIN_MAP_LINEAR:
101 kfree(domain->revmap_data.linear.revmap);
102 domain->revmap_data.linear.size = 0;
104 case IRQ_DOMAIN_MAP_NOMAP:
108 list_del(&domain->link);
111 * If the going away domain is the default one, reset it.
113 if (unlikely(irq_default_domain == domain))
114 irq_set_default_host(NULL);
116 mutex_unlock(&irq_domain_mutex);
118 pr_debug("Removed domain of type %d @0x%p\n",
119 domain->revmap_type, domain);
121 irq_domain_free(domain);
123 EXPORT_SYMBOL_GPL(irq_domain_remove);
125 static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
126 irq_hw_number_t hwirq)
128 irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq;
129 int size = domain->revmap_data.legacy.size;
131 if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
133 return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq;
137 * irq_domain_add_simple() - Allocate and register a simple irq_domain.
138 * @of_node: pointer to interrupt controller's device tree node.
139 * @size: total number of irqs in mapping
140 * @first_irq: first number of irq block assigned to the domain
141 * @ops: map/unmap domain callbacks
142 * @host_data: Controller private data pointer
144 * Allocates a legacy irq_domain if irq_base is positive or a linear
145 * domain otherwise. For the legacy domain, IRQ descriptors will also
148 * This is intended to implement the expected behaviour for most
149 * interrupt controllers which is that a linear mapping should
150 * normally be used unless the system requires a legacy mapping in
151 * order to support supplying interrupt numbers during non-DT
152 * registration of devices.
154 struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
156 unsigned int first_irq,
157 const struct irq_domain_ops *ops,
163 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
165 * Set the descriptor allocator to search for a
166 * 1-to-1 mapping, such as irq_alloc_desc_at().
167 * Use of_node_to_nid() which is defined to
168 * numa_node_id() on platforms that have no custom
171 irq_base = irq_alloc_descs(first_irq, first_irq, size,
172 of_node_to_nid(of_node));
174 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
176 irq_base = first_irq;
179 irq_base = first_irq;
181 return irq_domain_add_legacy(of_node, size, irq_base, 0,
185 /* A linear domain is the default */
186 return irq_domain_add_linear(of_node, size, ops, host_data);
190 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
191 * @of_node: pointer to interrupt controller's device tree node.
192 * @size: total number of irqs in legacy mapping
193 * @first_irq: first number of irq block assigned to the domain
194 * @first_hwirq: first hwirq number to use for the translation. Should normally
195 * be '0', but a positive integer can be used if the effective
196 * hwirqs numbering does not begin at zero.
197 * @ops: map/unmap domain callbacks
198 * @host_data: Controller private data pointer
200 * Note: the map() callback will be called before this function returns
201 * for all legacy interrupts except 0 (which is always the invalid irq for
202 * a legacy controller).
204 struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
206 unsigned int first_irq,
207 irq_hw_number_t first_hwirq,
208 const struct irq_domain_ops *ops,
211 struct irq_domain *domain;
214 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
218 domain->revmap_data.legacy.first_irq = first_irq;
219 domain->revmap_data.legacy.first_hwirq = first_hwirq;
220 domain->revmap_data.legacy.size = size;
222 mutex_lock(&irq_domain_mutex);
223 /* Verify that all the irqs are available */
224 for (i = 0; i < size; i++) {
225 int irq = first_irq + i;
226 struct irq_data *irq_data = irq_get_irq_data(irq);
228 if (WARN_ON(!irq_data || irq_data->domain)) {
229 mutex_unlock(&irq_domain_mutex);
230 irq_domain_free(domain);
235 /* Claim all of the irqs before registering a legacy domain */
236 for (i = 0; i < size; i++) {
237 struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
238 irq_data->hwirq = first_hwirq + i;
239 irq_data->domain = domain;
241 mutex_unlock(&irq_domain_mutex);
243 for (i = 0; i < size; i++) {
244 int irq = first_irq + i;
245 int hwirq = first_hwirq + i;
247 /* IRQ0 gets ignored */
251 /* Legacy flags are left to default at this point,
252 * one can then use irq_create_mapping() to
253 * explicitly change them
256 ops->map(domain, irq, hwirq);
258 /* Clear norequest flags */
259 irq_clear_status_flags(irq, IRQ_NOREQUEST);
262 irq_domain_add(domain);
265 EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
268 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
269 * @of_node: pointer to interrupt controller's device tree node.
270 * @size: Number of interrupts in the domain.
271 * @ops: map/unmap domain callbacks
272 * @host_data: Controller private data pointer
274 struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
276 const struct irq_domain_ops *ops,
279 struct irq_domain *domain;
280 unsigned int *revmap;
282 revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
283 of_node_to_nid(of_node));
284 if (WARN_ON(!revmap))
287 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
292 domain->revmap_data.linear.size = size;
293 domain->revmap_data.linear.revmap = revmap;
294 irq_domain_add(domain);
297 EXPORT_SYMBOL_GPL(irq_domain_add_linear);
299 struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
300 unsigned int max_irq,
301 const struct irq_domain_ops *ops,
304 struct irq_domain *domain = irq_domain_alloc(of_node,
305 IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
307 domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
308 irq_domain_add(domain);
312 EXPORT_SYMBOL_GPL(irq_domain_add_nomap);
315 * irq_domain_add_tree()
316 * @of_node: pointer to interrupt controller's device tree node.
317 * @ops: map/unmap domain callbacks
319 * Note: The radix tree will be allocated later during boot automatically
320 * (the reverse mapping will use the slow path until that happens).
322 struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
323 const struct irq_domain_ops *ops,
326 struct irq_domain *domain = irq_domain_alloc(of_node,
327 IRQ_DOMAIN_MAP_TREE, ops, host_data);
329 INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
330 irq_domain_add(domain);
334 EXPORT_SYMBOL_GPL(irq_domain_add_tree);
337 * irq_find_host() - Locates a domain for a given device node
338 * @node: device-tree node of the interrupt controller
340 struct irq_domain *irq_find_host(struct device_node *node)
342 struct irq_domain *h, *found = NULL;
345 /* We might want to match the legacy controller last since
346 * it might potentially be set to match all interrupts in
347 * the absence of a device node. This isn't a problem so far
350 mutex_lock(&irq_domain_mutex);
351 list_for_each_entry(h, &irq_domain_list, link) {
353 rc = h->ops->match(h, node);
355 rc = (h->of_node != NULL) && (h->of_node == node);
362 mutex_unlock(&irq_domain_mutex);
365 EXPORT_SYMBOL_GPL(irq_find_host);
368 * irq_set_default_host() - Set a "default" irq domain
369 * @domain: default domain pointer
371 * For convenience, it's possible to set a "default" domain that will be used
372 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
373 * platforms that want to manipulate a few hard coded interrupt numbers that
374 * aren't properly represented in the device-tree.
376 void irq_set_default_host(struct irq_domain *domain)
378 pr_debug("Default domain set to @0x%p\n", domain);
380 irq_default_domain = domain;
382 EXPORT_SYMBOL_GPL(irq_set_default_host);
384 static void irq_domain_disassociate_many(struct irq_domain *domain,
385 unsigned int irq_base, int count)
388 * disassociate in reverse order;
389 * not strictly necessary, but nice for unwinding
392 int irq = irq_base + count;
393 struct irq_data *irq_data = irq_get_irq_data(irq);
394 irq_hw_number_t hwirq = irq_data->hwirq;
396 if (WARN_ON(!irq_data || irq_data->domain != domain))
399 irq_set_status_flags(irq, IRQ_NOREQUEST);
401 /* remove chip and handler */
402 irq_set_chip_and_handler(irq, NULL, NULL);
404 /* Make sure it's completed */
405 synchronize_irq(irq);
407 /* Tell the PIC about it */
408 if (domain->ops->unmap)
409 domain->ops->unmap(domain, irq);
412 irq_data->domain = NULL;
415 /* Clear reverse map */
416 switch(domain->revmap_type) {
417 case IRQ_DOMAIN_MAP_LINEAR:
418 if (hwirq < domain->revmap_data.linear.size)
419 domain->revmap_data.linear.revmap[hwirq] = 0;
421 case IRQ_DOMAIN_MAP_TREE:
422 mutex_lock(&revmap_trees_mutex);
423 radix_tree_delete(&domain->revmap_data.tree, hwirq);
424 mutex_unlock(&revmap_trees_mutex);
430 int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
431 irq_hw_number_t hwirq_base, int count)
433 unsigned int virq = irq_base;
434 irq_hw_number_t hwirq = hwirq_base;
437 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
438 of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
440 for (i = 0; i < count; i++) {
441 struct irq_data *irq_data = irq_get_irq_data(virq + i);
443 if (WARN(!irq_data, "error: irq_desc not allocated; "
444 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
446 if (WARN(irq_data->domain, "error: irq_desc already associated; "
447 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
451 for (i = 0; i < count; i++, virq++, hwirq++) {
452 struct irq_data *irq_data = irq_get_irq_data(virq);
454 irq_data->hwirq = hwirq;
455 irq_data->domain = domain;
456 if (domain->ops->map) {
457 ret = domain->ops->map(domain, virq, hwirq);
460 * If map() returns -EPERM, this interrupt is protected
461 * by the firmware or some other service and shall not
464 * Since on some platforms we blindly try to map everything
465 * we end up with a log full of backtraces.
467 * So instead, we silently fail on -EPERM, it is the
468 * responsibility of the PIC driver to display a relevant
472 pr_err("irq-%i==>hwirq-0x%lx mapping failed: %d\n",
476 irq_data->domain = NULL;
482 switch (domain->revmap_type) {
483 case IRQ_DOMAIN_MAP_LINEAR:
484 if (hwirq < domain->revmap_data.linear.size)
485 domain->revmap_data.linear.revmap[hwirq] = virq;
487 case IRQ_DOMAIN_MAP_TREE:
488 mutex_lock(&revmap_trees_mutex);
489 radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
490 mutex_unlock(&revmap_trees_mutex);
494 irq_clear_status_flags(virq, IRQ_NOREQUEST);
500 irq_domain_disassociate_many(domain, irq_base, i);
503 EXPORT_SYMBOL_GPL(irq_domain_associate_many);
506 * irq_create_direct_mapping() - Allocate an irq for direct mapping
507 * @domain: domain to allocate the irq for or NULL for default domain
509 * This routine is used for irq controllers which can choose the hardware
510 * interrupt numbers they generate. In such a case it's simplest to use
511 * the linux irq as the hardware interrupt number.
513 unsigned int irq_create_direct_mapping(struct irq_domain *domain)
518 domain = irq_default_domain;
520 if (WARN_ON(!domain || domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP))
523 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
525 pr_debug("create_direct virq allocation failed\n");
528 if (virq >= domain->revmap_data.nomap.max_irq) {
529 pr_err("ERROR: no free irqs available below %i maximum\n",
530 domain->revmap_data.nomap.max_irq);
534 pr_debug("create_direct obtained virq %d\n", virq);
536 if (irq_domain_associate(domain, virq, virq)) {
543 EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
546 * irq_create_mapping() - Map a hardware interrupt into linux irq space
547 * @domain: domain owning this hardware interrupt or NULL for default domain
548 * @hwirq: hardware irq number in that domain space
550 * Only one mapping per hardware interrupt is permitted. Returns a linux
552 * If the sense/trigger is to be specified, set_irq_type() should be called
553 * on the number returned from that call.
555 unsigned int irq_create_mapping(struct irq_domain *domain,
556 irq_hw_number_t hwirq)
561 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
563 /* Look for default domain if nececssary */
565 domain = irq_default_domain;
566 if (domain == NULL) {
567 pr_warning("irq_create_mapping called for"
568 " NULL domain, hwirq=%lx\n", hwirq);
572 pr_debug("-> using domain @%p\n", domain);
574 /* Check if mapping already exists */
575 virq = irq_find_mapping(domain, hwirq);
577 pr_debug("-> existing mapping on virq %d\n", virq);
581 /* Get a virtual interrupt number */
582 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
583 return irq_domain_legacy_revmap(domain, hwirq);
585 /* Allocate a virtual interrupt number */
586 hint = hwirq % nr_irqs;
589 virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
591 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
593 pr_debug("-> virq allocation failed\n");
597 if (irq_domain_associate(domain, virq, hwirq)) {
602 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
603 hwirq, of_node_full_name(domain->of_node), virq);
607 EXPORT_SYMBOL_GPL(irq_create_mapping);
610 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
611 * @domain: domain owning the interrupt range
612 * @irq_base: beginning of linux IRQ range
613 * @hwirq_base: beginning of hardware IRQ range
614 * @count: Number of interrupts to map
616 * This routine is used for allocating and mapping a range of hardware
617 * irqs to linux irqs where the linux irq numbers are at pre-defined
618 * locations. For use by controllers that already have static mappings
619 * to insert in to the domain.
621 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
624 * 0 is returned upon success, while any failure to establish a static
625 * mapping is treated as an error.
627 int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
628 irq_hw_number_t hwirq_base, int count)
632 ret = irq_alloc_descs(irq_base, irq_base, count,
633 of_node_to_nid(domain->of_node));
634 if (unlikely(ret < 0))
637 ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
638 if (unlikely(ret < 0)) {
639 irq_free_descs(irq_base, count);
645 EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
647 unsigned int irq_create_of_mapping(struct device_node *controller,
648 const u32 *intspec, unsigned int intsize)
650 struct irq_domain *domain;
651 irq_hw_number_t hwirq;
652 unsigned int type = IRQ_TYPE_NONE;
655 domain = controller ? irq_find_host(controller) : irq_default_domain;
659 * Workaround to avoid breaking interrupt controller drivers
660 * that don't yet register an irq_domain. This is temporary
661 * code. ~~~gcl, Feb 24, 2012
663 * Scheduled for removal in Linux v3.6. That should be enough
669 pr_warning("no irq domain found for %s !\n",
670 of_node_full_name(controller));
674 /* If domain has no translation, then we assume interrupt line */
675 if (domain->ops->xlate == NULL)
678 if (domain->ops->xlate(domain, controller, intspec, intsize,
684 virq = irq_create_mapping(domain, hwirq);
688 /* Set type if specified and different than the current one */
689 if (type != IRQ_TYPE_NONE &&
690 type != irq_get_trigger_type(virq))
691 irq_set_irq_type(virq, type);
694 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
697 * irq_dispose_mapping() - Unmap an interrupt
698 * @virq: linux irq number of the interrupt to unmap
700 void irq_dispose_mapping(unsigned int virq)
702 struct irq_data *irq_data = irq_get_irq_data(virq);
703 struct irq_domain *domain;
705 if (!virq || !irq_data)
708 domain = irq_data->domain;
709 if (WARN_ON(domain == NULL))
712 /* Never unmap legacy interrupts */
713 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
716 irq_domain_disassociate_many(domain, virq, 1);
719 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
722 * irq_find_mapping() - Find a linux irq from an hw irq number.
723 * @domain: domain owning this hardware interrupt
724 * @hwirq: hardware irq number in that domain space
726 unsigned int irq_find_mapping(struct irq_domain *domain,
727 irq_hw_number_t hwirq)
729 struct irq_data *data;
731 /* Look for default domain if nececssary */
733 domain = irq_default_domain;
737 switch (domain->revmap_type) {
738 case IRQ_DOMAIN_MAP_LEGACY:
739 return irq_domain_legacy_revmap(domain, hwirq);
740 case IRQ_DOMAIN_MAP_LINEAR:
741 return irq_linear_revmap(domain, hwirq);
742 case IRQ_DOMAIN_MAP_TREE:
744 data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
749 case IRQ_DOMAIN_MAP_NOMAP:
750 data = irq_get_irq_data(hwirq);
751 if (data && (data->domain == domain) && (data->hwirq == hwirq))
758 EXPORT_SYMBOL_GPL(irq_find_mapping);
761 * irq_linear_revmap() - Find a linux irq from a hw irq number.
762 * @domain: domain owning this hardware interrupt
763 * @hwirq: hardware irq number in that domain space
765 * This is a fast path that can be called directly by irq controller code to
766 * save a handful of instructions.
768 unsigned int irq_linear_revmap(struct irq_domain *domain,
769 irq_hw_number_t hwirq)
771 BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
773 /* Check revmap bounds; complain if exceeded */
774 if (WARN_ON(hwirq >= domain->revmap_data.linear.size))
777 return domain->revmap_data.linear.revmap[hwirq];
779 EXPORT_SYMBOL_GPL(irq_linear_revmap);
781 #ifdef CONFIG_IRQ_DOMAIN_DEBUG
782 static int virq_debug_show(struct seq_file *m, void *private)
785 struct irq_desc *desc;
787 static const char none[] = "none";
791 seq_printf(m, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
792 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
795 for (i = 1; i < nr_irqs; i++) {
796 desc = irq_to_desc(i);
800 raw_spin_lock_irqsave(&desc->lock, flags);
802 if (desc->action && desc->action->handler) {
803 struct irq_chip *chip;
805 seq_printf(m, "%5d ", i);
806 seq_printf(m, "0x%05lx ", desc->irq_data.hwirq);
808 chip = irq_desc_get_chip(desc);
809 if (chip && chip->name)
813 seq_printf(m, "%-15s ", p);
815 data = irq_desc_get_chip_data(desc);
816 seq_printf(m, data ? "0x%p " : " %p ", data);
818 if (desc->irq_data.domain)
819 p = of_node_full_name(desc->irq_data.domain->of_node);
822 seq_printf(m, "%s\n", p);
825 raw_spin_unlock_irqrestore(&desc->lock, flags);
831 static int virq_debug_open(struct inode *inode, struct file *file)
833 return single_open(file, virq_debug_show, inode->i_private);
836 static const struct file_operations virq_debug_fops = {
837 .open = virq_debug_open,
840 .release = single_release,
843 static int __init irq_debugfs_init(void)
845 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
846 NULL, &virq_debug_fops) == NULL)
851 __initcall(irq_debugfs_init);
852 #endif /* CONFIG_IRQ_DOMAIN_DEBUG */
855 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
857 * Device Tree IRQ specifier translation function which works with one cell
858 * bindings where the cell value maps directly to the hwirq number.
860 int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
861 const u32 *intspec, unsigned int intsize,
862 unsigned long *out_hwirq, unsigned int *out_type)
864 if (WARN_ON(intsize < 1))
866 *out_hwirq = intspec[0];
867 *out_type = IRQ_TYPE_NONE;
870 EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
873 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
875 * Device Tree IRQ specifier translation function which works with two cell
876 * bindings where the cell values map directly to the hwirq number
877 * and linux irq flags.
879 int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
880 const u32 *intspec, unsigned int intsize,
881 irq_hw_number_t *out_hwirq, unsigned int *out_type)
883 if (WARN_ON(intsize < 2))
885 *out_hwirq = intspec[0];
886 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
889 EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
892 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
894 * Device Tree IRQ specifier translation function which works with either one
895 * or two cell bindings where the cell values map directly to the hwirq number
896 * and linux irq flags.
898 * Note: don't use this function unless your interrupt controller explicitly
899 * supports both one and two cell bindings. For the majority of controllers
900 * the _onecell() or _twocell() variants above should be used.
902 int irq_domain_xlate_onetwocell(struct irq_domain *d,
903 struct device_node *ctrlr,
904 const u32 *intspec, unsigned int intsize,
905 unsigned long *out_hwirq, unsigned int *out_type)
907 if (WARN_ON(intsize < 1))
909 *out_hwirq = intspec[0];
910 *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
913 EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
915 const struct irq_domain_ops irq_domain_simple_ops = {
916 .xlate = irq_domain_xlate_onetwocell,
918 EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
921 void irq_domain_generate_simple(const struct of_device_id *match,
922 u64 phys_base, unsigned int irq_start)
924 struct device_node *node;
925 pr_debug("looking for phys_base=%llx, irq_start=%i\n",
926 (unsigned long long) phys_base, (int) irq_start);
927 node = of_find_matching_node_by_address(NULL, match, phys_base);
929 irq_domain_add_legacy(node, 32, irq_start, 0,
930 &irq_domain_simple_ops, NULL);
932 EXPORT_SYMBOL_GPL(irq_domain_generate_simple);