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_TREE
:
87 * radix_tree_delete() takes care of destroying the root
88 * node when all entries are removed. Shout if there are
91 WARN_ON(domain
->revmap_data
.tree
.height
);
93 case IRQ_DOMAIN_MAP_LINEAR
:
94 kfree(domain
->revmap_data
.linear
.revmap
);
95 domain
->revmap_data
.linear
.size
= 0;
97 case IRQ_DOMAIN_MAP_NOMAP
:
101 list_del(&domain
->link
);
104 * If the going away domain is the default one, reset it.
106 if (unlikely(irq_default_domain
== domain
))
107 irq_set_default_host(NULL
);
109 mutex_unlock(&irq_domain_mutex
);
111 pr_debug("Removed domain of type %d @0x%p\n",
112 domain
->revmap_type
, domain
);
114 irq_domain_free(domain
);
116 EXPORT_SYMBOL_GPL(irq_domain_remove
);
119 * irq_domain_add_simple() - Allocate and register a simple irq_domain.
120 * @of_node: pointer to interrupt controller's device tree node.
121 * @size: total number of irqs in mapping
122 * @first_irq: first number of irq block assigned to the domain,
123 * pass zero to assign irqs on-the-fly. This will result in a
124 * linear IRQ domain so it is important to use irq_create_mapping()
125 * for each used IRQ, especially when SPARSE_IRQ is enabled.
126 * @ops: map/unmap domain callbacks
127 * @host_data: Controller private data pointer
129 * Allocates a legacy irq_domain if irq_base is positive or a linear
130 * domain otherwise. For the legacy domain, IRQ descriptors will also
133 * This is intended to implement the expected behaviour for most
134 * interrupt controllers which is that a linear mapping should
135 * normally be used unless the system requires a legacy mapping in
136 * order to support supplying interrupt numbers during non-DT
137 * registration of devices.
139 struct irq_domain
*irq_domain_add_simple(struct device_node
*of_node
,
141 unsigned int first_irq
,
142 const struct irq_domain_ops
*ops
,
148 if (IS_ENABLED(CONFIG_SPARSE_IRQ
)) {
150 * Set the descriptor allocator to search for a
151 * 1-to-1 mapping, such as irq_alloc_desc_at().
152 * Use of_node_to_nid() which is defined to
153 * numa_node_id() on platforms that have no custom
156 irq_base
= irq_alloc_descs(first_irq
, first_irq
, size
,
157 of_node_to_nid(of_node
));
159 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
161 irq_base
= first_irq
;
164 irq_base
= first_irq
;
166 return irq_domain_add_legacy(of_node
, size
, irq_base
, 0,
170 /* A linear domain is the default */
171 return irq_domain_add_linear(of_node
, size
, ops
, host_data
);
173 EXPORT_SYMBOL_GPL(irq_domain_add_simple
);
176 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
177 * @of_node: pointer to interrupt controller's device tree node.
178 * @size: total number of irqs in legacy mapping
179 * @first_irq: first number of irq block assigned to the domain
180 * @first_hwirq: first hwirq number to use for the translation. Should normally
181 * be '0', but a positive integer can be used if the effective
182 * hwirqs numbering does not begin at zero.
183 * @ops: map/unmap domain callbacks
184 * @host_data: Controller private data pointer
186 * Note: the map() callback will be called before this function returns
187 * for all legacy interrupts except 0 (which is always the invalid irq for
188 * a legacy controller).
190 struct irq_domain
*irq_domain_add_legacy(struct device_node
*of_node
,
192 unsigned int first_irq
,
193 irq_hw_number_t first_hwirq
,
194 const struct irq_domain_ops
*ops
,
197 struct irq_domain
*domain
;
199 pr_debug("Setting up legacy domain virq[%i:%i] ==> hwirq[%i:%i]\n",
200 first_irq
, first_irq
+ size
- 1,
201 (int)first_hwirq
, (int)first_hwirq
+ size
-1);
203 domain
= irq_domain_add_linear(of_node
, first_hwirq
+ size
, ops
, host_data
);
207 WARN_ON(irq_domain_associate_many(domain
, first_irq
, first_hwirq
, size
));
211 EXPORT_SYMBOL_GPL(irq_domain_add_legacy
);
214 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
215 * @of_node: pointer to interrupt controller's device tree node.
216 * @size: Number of interrupts in the domain.
217 * @ops: map/unmap domain callbacks
218 * @host_data: Controller private data pointer
220 struct irq_domain
*irq_domain_add_linear(struct device_node
*of_node
,
222 const struct irq_domain_ops
*ops
,
225 struct irq_domain
*domain
;
226 unsigned int *revmap
;
228 revmap
= kzalloc_node(sizeof(*revmap
) * size
, GFP_KERNEL
,
229 of_node_to_nid(of_node
));
230 if (WARN_ON(!revmap
))
233 domain
= irq_domain_alloc(of_node
, IRQ_DOMAIN_MAP_LINEAR
, ops
, host_data
);
238 domain
->revmap_data
.linear
.size
= size
;
239 domain
->revmap_data
.linear
.revmap
= revmap
;
240 irq_domain_add(domain
);
243 EXPORT_SYMBOL_GPL(irq_domain_add_linear
);
245 struct irq_domain
*irq_domain_add_nomap(struct device_node
*of_node
,
246 unsigned int max_irq
,
247 const struct irq_domain_ops
*ops
,
250 struct irq_domain
*domain
= irq_domain_alloc(of_node
,
251 IRQ_DOMAIN_MAP_NOMAP
, ops
, host_data
);
253 domain
->revmap_data
.nomap
.max_irq
= max_irq
? max_irq
: ~0;
254 irq_domain_add(domain
);
258 EXPORT_SYMBOL_GPL(irq_domain_add_nomap
);
261 * irq_domain_add_tree()
262 * @of_node: pointer to interrupt controller's device tree node.
263 * @ops: map/unmap domain callbacks
265 * Note: The radix tree will be allocated later during boot automatically
266 * (the reverse mapping will use the slow path until that happens).
268 struct irq_domain
*irq_domain_add_tree(struct device_node
*of_node
,
269 const struct irq_domain_ops
*ops
,
272 struct irq_domain
*domain
= irq_domain_alloc(of_node
,
273 IRQ_DOMAIN_MAP_TREE
, ops
, host_data
);
275 INIT_RADIX_TREE(&domain
->revmap_data
.tree
, GFP_KERNEL
);
276 irq_domain_add(domain
);
280 EXPORT_SYMBOL_GPL(irq_domain_add_tree
);
283 * irq_find_host() - Locates a domain for a given device node
284 * @node: device-tree node of the interrupt controller
286 struct irq_domain
*irq_find_host(struct device_node
*node
)
288 struct irq_domain
*h
, *found
= NULL
;
291 /* We might want to match the legacy controller last since
292 * it might potentially be set to match all interrupts in
293 * the absence of a device node. This isn't a problem so far
296 mutex_lock(&irq_domain_mutex
);
297 list_for_each_entry(h
, &irq_domain_list
, link
) {
299 rc
= h
->ops
->match(h
, node
);
301 rc
= (h
->of_node
!= NULL
) && (h
->of_node
== node
);
308 mutex_unlock(&irq_domain_mutex
);
311 EXPORT_SYMBOL_GPL(irq_find_host
);
314 * irq_set_default_host() - Set a "default" irq domain
315 * @domain: default domain pointer
317 * For convenience, it's possible to set a "default" domain that will be used
318 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
319 * platforms that want to manipulate a few hard coded interrupt numbers that
320 * aren't properly represented in the device-tree.
322 void irq_set_default_host(struct irq_domain
*domain
)
324 pr_debug("Default domain set to @0x%p\n", domain
);
326 irq_default_domain
= domain
;
328 EXPORT_SYMBOL_GPL(irq_set_default_host
);
330 static void irq_domain_disassociate_many(struct irq_domain
*domain
,
331 unsigned int irq_base
, int count
)
334 * disassociate in reverse order;
335 * not strictly necessary, but nice for unwinding
338 int irq
= irq_base
+ count
;
339 struct irq_data
*irq_data
= irq_get_irq_data(irq
);
340 irq_hw_number_t hwirq
;
342 if (WARN_ON(!irq_data
|| irq_data
->domain
!= domain
))
345 hwirq
= irq_data
->hwirq
;
346 irq_set_status_flags(irq
, IRQ_NOREQUEST
);
348 /* remove chip and handler */
349 irq_set_chip_and_handler(irq
, NULL
, NULL
);
351 /* Make sure it's completed */
352 synchronize_irq(irq
);
354 /* Tell the PIC about it */
355 if (domain
->ops
->unmap
)
356 domain
->ops
->unmap(domain
, irq
);
359 irq_data
->domain
= NULL
;
362 /* Clear reverse map */
363 switch(domain
->revmap_type
) {
364 case IRQ_DOMAIN_MAP_LINEAR
:
365 if (hwirq
< domain
->revmap_data
.linear
.size
)
366 domain
->revmap_data
.linear
.revmap
[hwirq
] = 0;
368 case IRQ_DOMAIN_MAP_TREE
:
369 mutex_lock(&revmap_trees_mutex
);
370 radix_tree_delete(&domain
->revmap_data
.tree
, hwirq
);
371 mutex_unlock(&revmap_trees_mutex
);
377 int irq_domain_associate_many(struct irq_domain
*domain
, unsigned int irq_base
,
378 irq_hw_number_t hwirq_base
, int count
)
380 unsigned int virq
= irq_base
;
381 irq_hw_number_t hwirq
= hwirq_base
;
384 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__
,
385 of_node_full_name(domain
->of_node
), irq_base
, (int)hwirq_base
, count
);
387 for (i
= 0; i
< count
; i
++) {
388 struct irq_data
*irq_data
= irq_get_irq_data(virq
+ i
);
390 if (WARN(!irq_data
, "error: irq_desc not allocated; "
391 "irq=%i hwirq=0x%x\n", virq
+ i
, (int)hwirq
+ i
))
393 if (WARN(irq_data
->domain
, "error: irq_desc already associated; "
394 "irq=%i hwirq=0x%x\n", virq
+ i
, (int)hwirq
+ i
))
398 for (i
= 0; i
< count
; i
++, virq
++, hwirq
++) {
399 struct irq_data
*irq_data
= irq_get_irq_data(virq
);
401 irq_data
->hwirq
= hwirq
;
402 irq_data
->domain
= domain
;
403 if (domain
->ops
->map
) {
404 ret
= domain
->ops
->map(domain
, virq
, hwirq
);
407 * If map() returns -EPERM, this interrupt is protected
408 * by the firmware or some other service and shall not
409 * be mapped. Don't bother telling the user about it.
412 pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
413 of_node_full_name(domain
->of_node
), hwirq
, virq
, ret
);
415 irq_data
->domain
= NULL
;
421 switch (domain
->revmap_type
) {
422 case IRQ_DOMAIN_MAP_LINEAR
:
423 if (hwirq
< domain
->revmap_data
.linear
.size
)
424 domain
->revmap_data
.linear
.revmap
[hwirq
] = virq
;
426 case IRQ_DOMAIN_MAP_TREE
:
427 mutex_lock(&revmap_trees_mutex
);
428 radix_tree_insert(&domain
->revmap_data
.tree
, hwirq
, irq_data
);
429 mutex_unlock(&revmap_trees_mutex
);
433 irq_clear_status_flags(virq
, IRQ_NOREQUEST
);
438 EXPORT_SYMBOL_GPL(irq_domain_associate_many
);
441 * irq_create_direct_mapping() - Allocate an irq for direct mapping
442 * @domain: domain to allocate the irq for or NULL for default domain
444 * This routine is used for irq controllers which can choose the hardware
445 * interrupt numbers they generate. In such a case it's simplest to use
446 * the linux irq as the hardware interrupt number.
448 unsigned int irq_create_direct_mapping(struct irq_domain
*domain
)
453 domain
= irq_default_domain
;
455 if (WARN_ON(!domain
|| domain
->revmap_type
!= IRQ_DOMAIN_MAP_NOMAP
))
458 virq
= irq_alloc_desc_from(1, of_node_to_nid(domain
->of_node
));
460 pr_debug("create_direct virq allocation failed\n");
463 if (virq
>= domain
->revmap_data
.nomap
.max_irq
) {
464 pr_err("ERROR: no free irqs available below %i maximum\n",
465 domain
->revmap_data
.nomap
.max_irq
);
469 pr_debug("create_direct obtained virq %d\n", virq
);
471 if (irq_domain_associate(domain
, virq
, virq
)) {
478 EXPORT_SYMBOL_GPL(irq_create_direct_mapping
);
481 * irq_create_mapping() - Map a hardware interrupt into linux irq space
482 * @domain: domain owning this hardware interrupt or NULL for default domain
483 * @hwirq: hardware irq number in that domain space
485 * Only one mapping per hardware interrupt is permitted. Returns a linux
487 * If the sense/trigger is to be specified, set_irq_type() should be called
488 * on the number returned from that call.
490 unsigned int irq_create_mapping(struct irq_domain
*domain
,
491 irq_hw_number_t hwirq
)
496 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain
, hwirq
);
498 /* Look for default domain if nececssary */
500 domain
= irq_default_domain
;
501 if (domain
== NULL
) {
502 pr_warning("irq_create_mapping called for"
503 " NULL domain, hwirq=%lx\n", hwirq
);
507 pr_debug("-> using domain @%p\n", domain
);
509 /* Check if mapping already exists */
510 virq
= irq_find_mapping(domain
, hwirq
);
512 pr_debug("-> existing mapping on virq %d\n", virq
);
516 /* Allocate a virtual interrupt number */
517 hint
= hwirq
% nr_irqs
;
520 virq
= irq_alloc_desc_from(hint
, of_node_to_nid(domain
->of_node
));
522 virq
= irq_alloc_desc_from(1, of_node_to_nid(domain
->of_node
));
524 pr_debug("-> virq allocation failed\n");
528 if (irq_domain_associate(domain
, virq
, hwirq
)) {
533 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
534 hwirq
, of_node_full_name(domain
->of_node
), virq
);
538 EXPORT_SYMBOL_GPL(irq_create_mapping
);
541 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
542 * @domain: domain owning the interrupt range
543 * @irq_base: beginning of linux IRQ range
544 * @hwirq_base: beginning of hardware IRQ range
545 * @count: Number of interrupts to map
547 * This routine is used for allocating and mapping a range of hardware
548 * irqs to linux irqs where the linux irq numbers are at pre-defined
549 * locations. For use by controllers that already have static mappings
550 * to insert in to the domain.
552 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
555 * 0 is returned upon success, while any failure to establish a static
556 * mapping is treated as an error.
558 int irq_create_strict_mappings(struct irq_domain
*domain
, unsigned int irq_base
,
559 irq_hw_number_t hwirq_base
, int count
)
563 ret
= irq_alloc_descs(irq_base
, irq_base
, count
,
564 of_node_to_nid(domain
->of_node
));
565 if (unlikely(ret
< 0))
568 ret
= irq_domain_associate_many(domain
, irq_base
, hwirq_base
, count
);
569 if (unlikely(ret
< 0)) {
570 irq_free_descs(irq_base
, count
);
576 EXPORT_SYMBOL_GPL(irq_create_strict_mappings
);
578 unsigned int irq_create_of_mapping(struct device_node
*controller
,
579 const u32
*intspec
, unsigned int intsize
)
581 struct irq_domain
*domain
;
582 irq_hw_number_t hwirq
;
583 unsigned int type
= IRQ_TYPE_NONE
;
586 domain
= controller
? irq_find_host(controller
) : irq_default_domain
;
590 * Workaround to avoid breaking interrupt controller drivers
591 * that don't yet register an irq_domain. This is temporary
592 * code. ~~~gcl, Feb 24, 2012
594 * Scheduled for removal in Linux v3.6. That should be enough
600 pr_warning("no irq domain found for %s !\n",
601 of_node_full_name(controller
));
605 /* If domain has no translation, then we assume interrupt line */
606 if (domain
->ops
->xlate
== NULL
)
609 if (domain
->ops
->xlate(domain
, controller
, intspec
, intsize
,
615 virq
= irq_create_mapping(domain
, hwirq
);
619 /* Set type if specified and different than the current one */
620 if (type
!= IRQ_TYPE_NONE
&&
621 type
!= (irqd_get_trigger_type(irq_get_irq_data(virq
))))
622 irq_set_irq_type(virq
, type
);
625 EXPORT_SYMBOL_GPL(irq_create_of_mapping
);
628 * irq_dispose_mapping() - Unmap an interrupt
629 * @virq: linux irq number of the interrupt to unmap
631 void irq_dispose_mapping(unsigned int virq
)
633 struct irq_data
*irq_data
= irq_get_irq_data(virq
);
634 struct irq_domain
*domain
;
636 if (!virq
|| !irq_data
)
639 domain
= irq_data
->domain
;
640 if (WARN_ON(domain
== NULL
))
643 irq_domain_disassociate_many(domain
, virq
, 1);
646 EXPORT_SYMBOL_GPL(irq_dispose_mapping
);
649 * irq_find_mapping() - Find a linux irq from an hw irq number.
650 * @domain: domain owning this hardware interrupt
651 * @hwirq: hardware irq number in that domain space
653 unsigned int irq_find_mapping(struct irq_domain
*domain
,
654 irq_hw_number_t hwirq
)
656 struct irq_data
*data
;
658 /* Look for default domain if nececssary */
660 domain
= irq_default_domain
;
664 switch (domain
->revmap_type
) {
665 case IRQ_DOMAIN_MAP_LINEAR
:
666 return irq_linear_revmap(domain
, hwirq
);
667 case IRQ_DOMAIN_MAP_TREE
:
669 data
= radix_tree_lookup(&domain
->revmap_data
.tree
, hwirq
);
674 case IRQ_DOMAIN_MAP_NOMAP
:
675 data
= irq_get_irq_data(hwirq
);
676 if (data
&& (data
->domain
== domain
) && (data
->hwirq
== hwirq
))
683 EXPORT_SYMBOL_GPL(irq_find_mapping
);
686 * irq_linear_revmap() - Find a linux irq from a hw irq number.
687 * @domain: domain owning this hardware interrupt
688 * @hwirq: hardware irq number in that domain space
690 * This is a fast path that can be called directly by irq controller code to
691 * save a handful of instructions.
693 unsigned int irq_linear_revmap(struct irq_domain
*domain
,
694 irq_hw_number_t hwirq
)
696 BUG_ON(domain
->revmap_type
!= IRQ_DOMAIN_MAP_LINEAR
);
698 /* Check revmap bounds; complain if exceeded */
699 if (WARN_ON(hwirq
>= domain
->revmap_data
.linear
.size
))
702 return domain
->revmap_data
.linear
.revmap
[hwirq
];
704 EXPORT_SYMBOL_GPL(irq_linear_revmap
);
706 #ifdef CONFIG_IRQ_DOMAIN_DEBUG
707 static int virq_debug_show(struct seq_file
*m
, void *private)
710 struct irq_desc
*desc
;
712 static const char none
[] = "none";
716 seq_printf(m
, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
717 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
720 for (i
= 1; i
< nr_irqs
; i
++) {
721 desc
= irq_to_desc(i
);
725 raw_spin_lock_irqsave(&desc
->lock
, flags
);
727 if (desc
->action
&& desc
->action
->handler
) {
728 struct irq_chip
*chip
;
730 seq_printf(m
, "%5d ", i
);
731 seq_printf(m
, "0x%05lx ", desc
->irq_data
.hwirq
);
733 chip
= irq_desc_get_chip(desc
);
734 if (chip
&& chip
->name
)
738 seq_printf(m
, "%-15s ", p
);
740 data
= irq_desc_get_chip_data(desc
);
741 seq_printf(m
, data
? "0x%p " : " %p ", data
);
743 if (desc
->irq_data
.domain
)
744 p
= of_node_full_name(desc
->irq_data
.domain
->of_node
);
747 seq_printf(m
, "%s\n", p
);
750 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
756 static int virq_debug_open(struct inode
*inode
, struct file
*file
)
758 return single_open(file
, virq_debug_show
, inode
->i_private
);
761 static const struct file_operations virq_debug_fops
= {
762 .open
= virq_debug_open
,
765 .release
= single_release
,
768 static int __init
irq_debugfs_init(void)
770 if (debugfs_create_file("irq_domain_mapping", S_IRUGO
, NULL
,
771 NULL
, &virq_debug_fops
) == NULL
)
776 __initcall(irq_debugfs_init
);
777 #endif /* CONFIG_IRQ_DOMAIN_DEBUG */
780 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
782 * Device Tree IRQ specifier translation function which works with one cell
783 * bindings where the cell value maps directly to the hwirq number.
785 int irq_domain_xlate_onecell(struct irq_domain
*d
, struct device_node
*ctrlr
,
786 const u32
*intspec
, unsigned int intsize
,
787 unsigned long *out_hwirq
, unsigned int *out_type
)
789 if (WARN_ON(intsize
< 1))
791 *out_hwirq
= intspec
[0];
792 *out_type
= IRQ_TYPE_NONE
;
795 EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell
);
798 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
800 * Device Tree IRQ specifier translation function which works with two cell
801 * bindings where the cell values map directly to the hwirq number
802 * and linux irq flags.
804 int irq_domain_xlate_twocell(struct irq_domain
*d
, struct device_node
*ctrlr
,
805 const u32
*intspec
, unsigned int intsize
,
806 irq_hw_number_t
*out_hwirq
, unsigned int *out_type
)
808 if (WARN_ON(intsize
< 2))
810 *out_hwirq
= intspec
[0];
811 *out_type
= intspec
[1] & IRQ_TYPE_SENSE_MASK
;
814 EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell
);
817 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
819 * Device Tree IRQ specifier translation function which works with either one
820 * or two cell bindings where the cell values map directly to the hwirq number
821 * and linux irq flags.
823 * Note: don't use this function unless your interrupt controller explicitly
824 * supports both one and two cell bindings. For the majority of controllers
825 * the _onecell() or _twocell() variants above should be used.
827 int irq_domain_xlate_onetwocell(struct irq_domain
*d
,
828 struct device_node
*ctrlr
,
829 const u32
*intspec
, unsigned int intsize
,
830 unsigned long *out_hwirq
, unsigned int *out_type
)
832 if (WARN_ON(intsize
< 1))
834 *out_hwirq
= intspec
[0];
835 *out_type
= (intsize
> 1) ? intspec
[1] : IRQ_TYPE_NONE
;
838 EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell
);
840 const struct irq_domain_ops irq_domain_simple_ops
= {
841 .xlate
= irq_domain_xlate_onetwocell
,
843 EXPORT_SYMBOL_GPL(irq_domain_simple_ops
);
846 void irq_domain_generate_simple(const struct of_device_id
*match
,
847 u64 phys_base
, unsigned int irq_start
)
849 struct device_node
*node
;
850 pr_debug("looking for phys_base=%llx, irq_start=%i\n",
851 (unsigned long long) phys_base
, (int) irq_start
);
852 node
= of_find_matching_node_by_address(NULL
, match
, phys_base
);
854 irq_domain_add_legacy(node
, 32, irq_start
, 0,
855 &irq_domain_simple_ops
, NULL
);
857 EXPORT_SYMBOL_GPL(irq_domain_generate_simple
);