1 #define pr_fmt(fmt) "irq: " fmt
9 #include <linux/module.h>
15 #include <linux/slab.h>
19 #define IRQ_DOMAIN_MAP_LEGACY 0
21 #define IRQ_DOMAIN_MAP_NOMAP 1
22 #define IRQ_DOMAIN_MAP_LINEAR 2
23 #define IRQ_DOMAIN_MAP_TREE 3
49 domain = kzalloc_node(
sizeof(*domain),
GFP_KERNEL,
58 domain->
of_node = of_node_get(of_node);
63 static void irq_domain_free(
struct irq_domain *domain)
69 static void irq_domain_add(
struct irq_domain *domain)
72 list_add(&domain->
link, &irq_domain_list);
74 pr_debug(
"Allocated domain of type %d @0x%p\n",
119 if (
unlikely(irq_default_domain == domain))
124 pr_debug(
"Removed domain of type %d @0x%p\n",
127 irq_domain_free(domain);
131 static unsigned int irq_domain_legacy_revmap(
struct irq_domain *domain,
137 if (
WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
177 irq_base = irq_alloc_descs(first_irq, first_irq, size,
180 WARN(1,
"Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
212 unsigned int first_irq,
230 for (i = 0; i <
size; i++) {
231 int irq = first_irq +
i;
236 irq_domain_free(domain);
242 for (i = 0; i <
size; i++) {
244 irq_data->
hwirq = first_hwirq +
i;
249 for (i = 0; i <
size; i++) {
250 int irq = first_irq +
i;
251 int hwirq = first_hwirq +
i;
262 ops->
map(domain, irq, hwirq);
268 irq_domain_add(domain);
288 revmap = kzalloc_node(
sizeof(*revmap) * size,
GFP_KERNEL,
300 irq_domain_add(domain);
310 struct irq_domain *domain = irq_domain_alloc(of_node,
314 irq_domain_add(domain);
332 struct irq_domain *domain = irq_domain_alloc(of_node,
336 irq_domain_add(domain);
359 rc = h->
ops->match(h, node);
384 pr_debug(
"Default domain set to @0x%p\n", domain);
386 irq_default_domain = domain;
390 static void irq_domain_disassociate_many(
struct irq_domain *domain,
391 unsigned int irq_base,
int count)
398 int irq = irq_base +
count;
408 irq_set_chip_and_handler(irq,
NULL,
NULL);
414 if (domain->
ops->unmap)
415 domain->
ops->unmap(domain, irq);
424 if (hwirq < domain->revmap_data.linear.size)
439 unsigned int virq = irq_base;
443 pr_debug(
"%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
444 of_node_full_name(domain->
of_node), irq_base, (
int)hwirq_base, count);
446 for (i = 0; i <
count; i++) {
449 if (
WARN(!irq_data,
"error: irq_desc not allocated; "
450 "irq=%i hwirq=0x%x\n", virq + i, (
int)hwirq + i))
452 if (
WARN(irq_data->
domain,
"error: irq_desc already associated; "
453 "irq=%i hwirq=0x%x\n", virq + i, (
int)hwirq + i))
457 for (i = 0; i <
count; i++, virq++, hwirq++) {
462 if (domain->
ops->map) {
463 ret = domain->
ops->map(domain, virq, hwirq);
465 pr_err(
"irq-%i==>hwirq-0x%lx mapping failed: %d\n",
476 if (hwirq < domain->revmap_data.linear.size)
492 irq_domain_disassociate_many(domain, irq_base, i);
510 domain = irq_default_domain;
517 pr_debug(
"create_direct virq allocation failed\n");
521 pr_err(
"ERROR: no free irqs available below %i maximum\n",
526 pr_debug(
"create_direct obtained virq %d\n", virq);
528 if (irq_domain_associate(domain, virq, virq)) {
553 pr_debug(
"irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
557 domain = irq_default_domain;
558 if (domain ==
NULL) {
560 " NULL domain, hwirq=%lx\n", hwirq);
564 pr_debug(
"-> using domain @%p\n", domain);
569 pr_debug(
"-> existing mapping on virq %d\n", virq);
575 return irq_domain_legacy_revmap(domain, hwirq);
585 pr_debug(
"-> virq allocation failed\n");
589 if (irq_domain_associate(domain, virq, hwirq)) {
594 pr_debug(
"irq %lu on domain %s mapped to virtual irq %u\n",
595 hwirq, of_node_full_name(domain->
of_node), virq);
624 ret = irq_alloc_descs(irq_base, irq_base, count,
640 const u32 *intspec,
unsigned int intsize)
647 domain = controller ?
irq_find_host(controller) : irq_default_domain;
662 of_node_full_name(controller));
667 if (domain->
ops->xlate ==
NULL)
670 if (domain->
ops->xlate(domain, controller, intspec, intsize,
697 if (!virq || !irq_data)
700 domain = irq_data->
domain;
708 irq_domain_disassociate_many(domain, virq, 1);
721 struct irq_data *
data;
725 domain = irq_default_domain;
731 return irq_domain_legacy_revmap(domain, hwirq);
743 if (data && (data->
domain == domain) && (data->
hwirq == hwirq))
773 #ifdef CONFIG_IRQ_DOMAIN_DEBUG
774 static int virq_debug_show(
struct seq_file *
m,
void *
private)
779 static const char none[] =
"none";
783 seq_printf(m,
"%-5s %-7s %-15s %-*s %s\n",
"irq",
"hwirq",
784 "chip name", (
int)(2 *
sizeof(
void *) + 2),
"chip data",
787 for (i = 1; i <
nr_irqs; i++) {
800 chip = irq_desc_get_chip(desc);
801 if (chip && chip->
name)
807 data = irq_desc_get_chip_data(desc);
811 p = of_node_full_name(desc->
irq_data.domain->of_node);
829 .
open = virq_debug_open,
835 static int __init irq_debugfs_init(
void)
853 const u32 *intspec,
unsigned int intsize,
854 unsigned long *out_hwirq,
unsigned int *out_type)
858 *out_hwirq = intspec[0];
872 const u32 *intspec,
unsigned int intsize,
877 *out_hwirq = intspec[0];
896 const u32 *intspec,
unsigned int intsize,
897 unsigned long *out_hwirq,
unsigned int *out_type)
901 *out_hwirq = intspec[0];
914 u64 phys_base,
unsigned int irq_start)
917 pr_debug(
"looking for phys_base=%llx, irq_start=%i\n",
918 (
unsigned long long) phys_base, (
int) irq_start);
922 &irq_domain_simple_ops,
NULL);