irq_domain: Remove irq_domain_add_simple()
[firefly-linux-kernel-4.4.55.git] / kernel / irq / irqdomain.c
1 #include <linux/debugfs.h>
2 #include <linux/hardirq.h>
3 #include <linux/interrupt.h>
4 #include <linux/irq.h>
5 #include <linux/irqdesc.h>
6 #include <linux/irqdomain.h>
7 #include <linux/module.h>
8 #include <linux/mutex.h>
9 #include <linux/of.h>
10 #include <linux/of_address.h>
11 #include <linux/seq_file.h>
12 #include <linux/slab.h>
13 #include <linux/smp.h>
14 #include <linux/fs.h>
15
16 #define IRQ_DOMAIN_MAP_LEGACY 0 /* driver allocated fixed range of irqs.
17                                  * ie. legacy 8259, gets irqs 1..15 */
18 #define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */
19 #define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */
20 #define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */
21
22 static LIST_HEAD(irq_domain_list);
23 static DEFINE_MUTEX(irq_domain_mutex);
24
25 static DEFINE_MUTEX(revmap_trees_mutex);
26 static unsigned int irq_virq_count = NR_IRQS;
27 static struct irq_domain *irq_default_domain;
28
29 static int default_irq_domain_match(struct irq_domain *d, struct device_node *np)
30 {
31         return d->of_node != NULL && d->of_node == np;
32 }
33
34 /**
35  * irq_domain_alloc() - Allocate a new irq_domain data structure
36  * @of_node: optional device-tree node of the interrupt controller
37  * @revmap_type: type of reverse mapping to use
38  * @ops: map/unmap domain callbacks
39  * @host_data: Controller private data pointer
40  *
41  * Allocates and initialize and irq_domain structure.  Caller is expected to
42  * register allocated irq_domain with irq_domain_register().  Returns pointer
43  * to IRQ domain, or NULL on failure.
44  */
45 static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
46                                            unsigned int revmap_type,
47                                            struct irq_domain_ops *ops,
48                                            void *host_data)
49 {
50         struct irq_domain *domain;
51
52         domain = kzalloc(sizeof(*domain), GFP_KERNEL);
53         if (WARN_ON(!domain))
54                 return NULL;
55
56         /* Fill structure */
57         domain->revmap_type = revmap_type;
58         domain->ops = ops;
59         domain->host_data = host_data;
60         domain->of_node = of_node_get(of_node);
61
62         if (domain->ops->match == NULL)
63                 domain->ops->match = default_irq_domain_match;
64
65         return domain;
66 }
67
68 static void irq_domain_add(struct irq_domain *domain)
69 {
70         mutex_lock(&irq_domain_mutex);
71         list_add(&domain->link, &irq_domain_list);
72         mutex_unlock(&irq_domain_mutex);
73         pr_debug("irq: Allocated domain of type %d @0x%p\n",
74                  domain->revmap_type, domain);
75 }
76
77 static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
78                                              irq_hw_number_t hwirq)
79 {
80         irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq;
81         int size = domain->revmap_data.legacy.size;
82
83         if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
84                 return 0;
85         return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq;
86 }
87
88 /**
89  * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
90  * @of_node: pointer to interrupt controller's device tree node.
91  * @size: total number of irqs in legacy mapping
92  * @first_irq: first number of irq block assigned to the domain
93  * @first_hwirq: first hwirq number to use for the translation. Should normally
94  *               be '0', but a positive integer can be used if the effective
95  *               hwirqs numbering does not begin at zero.
96  * @ops: map/unmap domain callbacks
97  * @host_data: Controller private data pointer
98  *
99  * Note: the map() callback will be called before this function returns
100  * for all legacy interrupts except 0 (which is always the invalid irq for
101  * a legacy controller).
102  */
103 struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
104                                          unsigned int size,
105                                          unsigned int first_irq,
106                                          irq_hw_number_t first_hwirq,
107                                          struct irq_domain_ops *ops,
108                                          void *host_data)
109 {
110         struct irq_domain *domain;
111         unsigned int i;
112
113         domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
114         if (!domain)
115                 return NULL;
116
117         domain->revmap_data.legacy.first_irq = first_irq;
118         domain->revmap_data.legacy.first_hwirq = first_hwirq;
119         domain->revmap_data.legacy.size = size;
120
121         mutex_lock(&irq_domain_mutex);
122         /* Verify that all the irqs are available */
123         for (i = 0; i < size; i++) {
124                 int irq = first_irq + i;
125                 struct irq_data *irq_data = irq_get_irq_data(irq);
126
127                 if (WARN_ON(!irq_data || irq_data->domain)) {
128                         mutex_unlock(&irq_domain_mutex);
129                         of_node_put(domain->of_node);
130                         kfree(domain);
131                         return NULL;
132                 }
133         }
134
135         /* Claim all of the irqs before registering a legacy domain */
136         for (i = 0; i < size; i++) {
137                 struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
138                 irq_data->hwirq = first_hwirq + i;
139                 irq_data->domain = domain;
140         }
141         mutex_unlock(&irq_domain_mutex);
142
143         for (i = 0; i < size; i++) {
144                 int irq = first_irq + i;
145                 int hwirq = first_hwirq + i;
146
147                 /* IRQ0 gets ignored */
148                 if (!irq)
149                         continue;
150
151                 /* Legacy flags are left to default at this point,
152                  * one can then use irq_create_mapping() to
153                  * explicitly change them
154                  */
155                 ops->map(domain, irq, hwirq);
156
157                 /* Clear norequest flags */
158                 irq_clear_status_flags(irq, IRQ_NOREQUEST);
159         }
160
161         irq_domain_add(domain);
162         return domain;
163 }
164
165 /**
166  * irq_domain_add_linear() - Allocate and register a legacy revmap irq_domain.
167  * @of_node: pointer to interrupt controller's device tree node.
168  * @ops: map/unmap domain callbacks
169  * @host_data: Controller private data pointer
170  */
171 struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
172                                          unsigned int size,
173                                          struct irq_domain_ops *ops,
174                                          void *host_data)
175 {
176         struct irq_domain *domain;
177         unsigned int *revmap;
178
179         revmap = kzalloc(sizeof(*revmap) * size, GFP_KERNEL);
180         if (WARN_ON(!revmap))
181                 return NULL;
182
183         domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
184         if (!domain) {
185                 kfree(revmap);
186                 return NULL;
187         }
188         domain->revmap_data.linear.size = size;
189         domain->revmap_data.linear.revmap = revmap;
190         irq_domain_add(domain);
191         return domain;
192 }
193
194 struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
195                                          struct irq_domain_ops *ops,
196                                          void *host_data)
197 {
198         struct irq_domain *domain = irq_domain_alloc(of_node,
199                                         IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
200         if (domain)
201                 irq_domain_add(domain);
202         return domain;
203 }
204
205 /**
206  * irq_domain_add_tree()
207  * @of_node: pointer to interrupt controller's device tree node.
208  * @ops: map/unmap domain callbacks
209  *
210  * Note: The radix tree will be allocated later during boot automatically
211  * (the reverse mapping will use the slow path until that happens).
212  */
213 struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
214                                          struct irq_domain_ops *ops,
215                                          void *host_data)
216 {
217         struct irq_domain *domain = irq_domain_alloc(of_node,
218                                         IRQ_DOMAIN_MAP_TREE, ops, host_data);
219         if (domain) {
220                 INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
221                 irq_domain_add(domain);
222         }
223         return domain;
224 }
225
226 /**
227  * irq_find_host() - Locates a domain for a given device node
228  * @node: device-tree node of the interrupt controller
229  */
230 struct irq_domain *irq_find_host(struct device_node *node)
231 {
232         struct irq_domain *h, *found = NULL;
233
234         /* We might want to match the legacy controller last since
235          * it might potentially be set to match all interrupts in
236          * the absence of a device node. This isn't a problem so far
237          * yet though...
238          */
239         mutex_lock(&irq_domain_mutex);
240         list_for_each_entry(h, &irq_domain_list, link)
241                 if (h->ops->match(h, node)) {
242                         found = h;
243                         break;
244                 }
245         mutex_unlock(&irq_domain_mutex);
246         return found;
247 }
248 EXPORT_SYMBOL_GPL(irq_find_host);
249
250 /**
251  * irq_set_default_host() - Set a "default" irq domain
252  * @domain: default domain pointer
253  *
254  * For convenience, it's possible to set a "default" domain that will be used
255  * whenever NULL is passed to irq_create_mapping(). It makes life easier for
256  * platforms that want to manipulate a few hard coded interrupt numbers that
257  * aren't properly represented in the device-tree.
258  */
259 void irq_set_default_host(struct irq_domain *domain)
260 {
261         pr_debug("irq: Default domain set to @0x%p\n", domain);
262
263         irq_default_domain = domain;
264 }
265
266 /**
267  * irq_set_virq_count() - Set the maximum number of linux irqs
268  * @count: number of linux irqs, capped with NR_IRQS
269  *
270  * This is mainly for use by platforms like iSeries who want to program
271  * the virtual irq number in the controller to avoid the reverse mapping
272  */
273 void irq_set_virq_count(unsigned int count)
274 {
275         pr_debug("irq: Trying to set virq count to %d\n", count);
276
277         BUG_ON(count < NUM_ISA_INTERRUPTS);
278         if (count < NR_IRQS)
279                 irq_virq_count = count;
280 }
281
282 static int irq_setup_virq(struct irq_domain *domain, unsigned int virq,
283                             irq_hw_number_t hwirq)
284 {
285         struct irq_data *irq_data = irq_get_irq_data(virq);
286
287         irq_data->hwirq = hwirq;
288         irq_data->domain = domain;
289         if (domain->ops->map(domain, virq, hwirq)) {
290                 pr_debug("irq: -> mapping failed, freeing\n");
291                 irq_data->domain = NULL;
292                 irq_data->hwirq = 0;
293                 return -1;
294         }
295
296         irq_clear_status_flags(virq, IRQ_NOREQUEST);
297
298         return 0;
299 }
300
301 /**
302  * irq_create_direct_mapping() - Allocate an irq for direct mapping
303  * @domain: domain to allocate the irq for or NULL for default domain
304  *
305  * This routine is used for irq controllers which can choose the hardware
306  * interrupt numbers they generate. In such a case it's simplest to use
307  * the linux irq as the hardware interrupt number.
308  */
309 unsigned int irq_create_direct_mapping(struct irq_domain *domain)
310 {
311         unsigned int virq;
312
313         if (domain == NULL)
314                 domain = irq_default_domain;
315
316         BUG_ON(domain == NULL);
317         WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP);
318
319         virq = irq_alloc_desc_from(1, 0);
320         if (!virq) {
321                 pr_debug("irq: create_direct virq allocation failed\n");
322                 return 0;
323         }
324         if (virq >= irq_virq_count) {
325                 pr_err("ERROR: no free irqs available below %i maximum\n",
326                         irq_virq_count);
327                 irq_free_desc(virq);
328                 return 0;
329         }
330
331         pr_debug("irq: create_direct obtained virq %d\n", virq);
332
333         if (irq_setup_virq(domain, virq, virq)) {
334                 irq_free_desc(virq);
335                 return 0;
336         }
337
338         return virq;
339 }
340
341 /**
342  * irq_create_mapping() - Map a hardware interrupt into linux irq space
343  * @domain: domain owning this hardware interrupt or NULL for default domain
344  * @hwirq: hardware irq number in that domain space
345  *
346  * Only one mapping per hardware interrupt is permitted. Returns a linux
347  * irq number.
348  * If the sense/trigger is to be specified, set_irq_type() should be called
349  * on the number returned from that call.
350  */
351 unsigned int irq_create_mapping(struct irq_domain *domain,
352                                 irq_hw_number_t hwirq)
353 {
354         unsigned int virq, hint;
355
356         pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
357
358         /* Look for default domain if nececssary */
359         if (domain == NULL)
360                 domain = irq_default_domain;
361         if (domain == NULL) {
362                 printk(KERN_WARNING "irq_create_mapping called for"
363                        " NULL domain, hwirq=%lx\n", hwirq);
364                 WARN_ON(1);
365                 return 0;
366         }
367         pr_debug("irq: -> using domain @%p\n", domain);
368
369         /* Check if mapping already exists */
370         virq = irq_find_mapping(domain, hwirq);
371         if (virq) {
372                 pr_debug("irq: -> existing mapping on virq %d\n", virq);
373                 return virq;
374         }
375
376         /* Get a virtual interrupt number */
377         if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
378                 return irq_domain_legacy_revmap(domain, hwirq);
379
380         /* Allocate a virtual interrupt number */
381         hint = hwirq % irq_virq_count;
382         if (hint == 0)
383                 hint++;
384         virq = irq_alloc_desc_from(hint, 0);
385         if (!virq)
386                 virq = irq_alloc_desc_from(1, 0);
387         if (!virq) {
388                 pr_debug("irq: -> virq allocation failed\n");
389                 return 0;
390         }
391
392         if (irq_setup_virq(domain, virq, hwirq)) {
393                 if (domain->revmap_type != IRQ_DOMAIN_MAP_LEGACY)
394                         irq_free_desc(virq);
395                 return 0;
396         }
397
398         pr_debug("irq: irq %lu on domain %s mapped to virtual irq %u\n",
399                 hwirq, domain->of_node ? domain->of_node->full_name : "null", virq);
400
401         return virq;
402 }
403 EXPORT_SYMBOL_GPL(irq_create_mapping);
404
405 unsigned int irq_create_of_mapping(struct device_node *controller,
406                                    const u32 *intspec, unsigned int intsize)
407 {
408         struct irq_domain *domain;
409         irq_hw_number_t hwirq;
410         unsigned int type = IRQ_TYPE_NONE;
411         unsigned int virq;
412
413         domain = controller ? irq_find_host(controller) : irq_default_domain;
414         if (!domain) {
415                 printk(KERN_WARNING "irq: no irq domain found for %s !\n",
416                        controller->full_name);
417                 return 0;
418         }
419
420         /* If domain has no translation, then we assume interrupt line */
421         if (domain->ops->xlate == NULL)
422                 hwirq = intspec[0];
423         else {
424                 if (domain->ops->xlate(domain, controller, intspec, intsize,
425                                      &hwirq, &type))
426                         return 0;
427         }
428
429         /* Create mapping */
430         virq = irq_create_mapping(domain, hwirq);
431         if (!virq)
432                 return virq;
433
434         /* Set type if specified and different than the current one */
435         if (type != IRQ_TYPE_NONE &&
436             type != (irqd_get_trigger_type(irq_get_irq_data(virq))))
437                 irq_set_irq_type(virq, type);
438         return virq;
439 }
440 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
441
442 /**
443  * irq_dispose_mapping() - Unmap an interrupt
444  * @virq: linux irq number of the interrupt to unmap
445  */
446 void irq_dispose_mapping(unsigned int virq)
447 {
448         struct irq_data *irq_data = irq_get_irq_data(virq);
449         struct irq_domain *domain;
450         irq_hw_number_t hwirq;
451
452         if (!virq || !irq_data)
453                 return;
454
455         domain = irq_data->domain;
456         if (WARN_ON(domain == NULL))
457                 return;
458
459         /* Never unmap legacy interrupts */
460         if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
461                 return;
462
463         irq_set_status_flags(virq, IRQ_NOREQUEST);
464
465         /* remove chip and handler */
466         irq_set_chip_and_handler(virq, NULL, NULL);
467
468         /* Make sure it's completed */
469         synchronize_irq(virq);
470
471         /* Tell the PIC about it */
472         if (domain->ops->unmap)
473                 domain->ops->unmap(domain, virq);
474         smp_mb();
475
476         /* Clear reverse map */
477         hwirq = irq_data->hwirq;
478         switch(domain->revmap_type) {
479         case IRQ_DOMAIN_MAP_LINEAR:
480                 if (hwirq < domain->revmap_data.linear.size)
481                         domain->revmap_data.linear.revmap[hwirq] = 0;
482                 break;
483         case IRQ_DOMAIN_MAP_TREE:
484                 mutex_lock(&revmap_trees_mutex);
485                 radix_tree_delete(&domain->revmap_data.tree, hwirq);
486                 mutex_unlock(&revmap_trees_mutex);
487                 break;
488         }
489
490         irq_free_desc(virq);
491 }
492 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
493
494 /**
495  * irq_find_mapping() - Find a linux irq from an hw irq number.
496  * @domain: domain owning this hardware interrupt
497  * @hwirq: hardware irq number in that domain space
498  *
499  * This is a slow path, for use by generic code. It's expected that an
500  * irq controller implementation directly calls the appropriate low level
501  * mapping function.
502  */
503 unsigned int irq_find_mapping(struct irq_domain *domain,
504                               irq_hw_number_t hwirq)
505 {
506         unsigned int i;
507         unsigned int hint = hwirq % irq_virq_count;
508
509         /* Look for default domain if nececssary */
510         if (domain == NULL)
511                 domain = irq_default_domain;
512         if (domain == NULL)
513                 return 0;
514
515         /* legacy -> bail early */
516         if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
517                 return irq_domain_legacy_revmap(domain, hwirq);
518
519         /* Slow path does a linear search of the map */
520         if (hint == 0)
521                 hint = 1;
522         i = hint;
523         do {
524                 struct irq_data *data = irq_get_irq_data(i);
525                 if (data && (data->domain == domain) && (data->hwirq == hwirq))
526                         return i;
527                 i++;
528                 if (i >= irq_virq_count)
529                         i = 1;
530         } while(i != hint);
531         return 0;
532 }
533 EXPORT_SYMBOL_GPL(irq_find_mapping);
534
535 /**
536  * irq_radix_revmap_lookup() - Find a linux irq from a hw irq number.
537  * @domain: domain owning this hardware interrupt
538  * @hwirq: hardware irq number in that domain space
539  *
540  * This is a fast path, for use by irq controller code that uses radix tree
541  * revmaps
542  */
543 unsigned int irq_radix_revmap_lookup(struct irq_domain *domain,
544                                      irq_hw_number_t hwirq)
545 {
546         struct irq_data *irq_data;
547
548         if (WARN_ON_ONCE(domain->revmap_type != IRQ_DOMAIN_MAP_TREE))
549                 return irq_find_mapping(domain, hwirq);
550
551         /*
552          * Freeing an irq can delete nodes along the path to
553          * do the lookup via call_rcu.
554          */
555         rcu_read_lock();
556         irq_data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
557         rcu_read_unlock();
558
559         /*
560          * If found in radix tree, then fine.
561          * Else fallback to linear lookup - this should not happen in practice
562          * as it means that we failed to insert the node in the radix tree.
563          */
564         return irq_data ? irq_data->irq : irq_find_mapping(domain, hwirq);
565 }
566
567 /**
568  * irq_radix_revmap_insert() - Insert a hw irq to linux irq number mapping.
569  * @domain: domain owning this hardware interrupt
570  * @virq: linux irq number
571  * @hwirq: hardware irq number in that domain space
572  *
573  * This is for use by irq controllers that use a radix tree reverse
574  * mapping for fast lookup.
575  */
576 void irq_radix_revmap_insert(struct irq_domain *domain, unsigned int virq,
577                              irq_hw_number_t hwirq)
578 {
579         struct irq_data *irq_data = irq_get_irq_data(virq);
580
581         if (WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_TREE))
582                 return;
583
584         if (virq) {
585                 mutex_lock(&revmap_trees_mutex);
586                 radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
587                 mutex_unlock(&revmap_trees_mutex);
588         }
589 }
590
591 /**
592  * irq_linear_revmap() - Find a linux irq from a hw irq number.
593  * @domain: domain owning this hardware interrupt
594  * @hwirq: hardware irq number in that domain space
595  *
596  * This is a fast path, for use by irq controller code that uses linear
597  * revmaps. It does fallback to the slow path if the revmap doesn't exist
598  * yet and will create the revmap entry with appropriate locking
599  */
600 unsigned int irq_linear_revmap(struct irq_domain *domain,
601                                irq_hw_number_t hwirq)
602 {
603         unsigned int *revmap;
604
605         if (WARN_ON_ONCE(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR))
606                 return irq_find_mapping(domain, hwirq);
607
608         /* Check revmap bounds */
609         if (unlikely(hwirq >= domain->revmap_data.linear.size))
610                 return irq_find_mapping(domain, hwirq);
611
612         /* Check if revmap was allocated */
613         revmap = domain->revmap_data.linear.revmap;
614         if (unlikely(revmap == NULL))
615                 return irq_find_mapping(domain, hwirq);
616
617         /* Fill up revmap with slow path if no mapping found */
618         if (unlikely(!revmap[hwirq]))
619                 revmap[hwirq] = irq_find_mapping(domain, hwirq);
620
621         return revmap[hwirq];
622 }
623
624 #ifdef CONFIG_VIRQ_DEBUG
625 static int virq_debug_show(struct seq_file *m, void *private)
626 {
627         unsigned long flags;
628         struct irq_desc *desc;
629         const char *p;
630         static const char none[] = "none";
631         void *data;
632         int i;
633
634         seq_printf(m, "%-5s  %-7s  %-15s  %-18s  %s\n", "virq", "hwirq",
635                       "chip name", "chip data", "domain name");
636
637         for (i = 1; i < nr_irqs; i++) {
638                 desc = irq_to_desc(i);
639                 if (!desc)
640                         continue;
641
642                 raw_spin_lock_irqsave(&desc->lock, flags);
643
644                 if (desc->action && desc->action->handler) {
645                         struct irq_chip *chip;
646
647                         seq_printf(m, "%5d  ", i);
648                         seq_printf(m, "0x%05lx  ", desc->irq_data.hwirq);
649
650                         chip = irq_desc_get_chip(desc);
651                         if (chip && chip->name)
652                                 p = chip->name;
653                         else
654                                 p = none;
655                         seq_printf(m, "%-15s  ", p);
656
657                         data = irq_desc_get_chip_data(desc);
658                         seq_printf(m, "0x%16p  ", data);
659
660                         if (desc->irq_data.domain->of_node)
661                                 p = desc->irq_data.domain->of_node->full_name;
662                         else
663                                 p = none;
664                         seq_printf(m, "%s\n", p);
665                 }
666
667                 raw_spin_unlock_irqrestore(&desc->lock, flags);
668         }
669
670         return 0;
671 }
672
673 static int virq_debug_open(struct inode *inode, struct file *file)
674 {
675         return single_open(file, virq_debug_show, inode->i_private);
676 }
677
678 static const struct file_operations virq_debug_fops = {
679         .open = virq_debug_open,
680         .read = seq_read,
681         .llseek = seq_lseek,
682         .release = single_release,
683 };
684
685 static int __init irq_debugfs_init(void)
686 {
687         if (debugfs_create_file("virq_mapping", S_IRUGO, powerpc_debugfs_root,
688                                  NULL, &virq_debug_fops) == NULL)
689                 return -ENOMEM;
690
691         return 0;
692 }
693 __initcall(irq_debugfs_init);
694 #endif /* CONFIG_VIRQ_DEBUG */
695
696 int irq_domain_simple_map(struct irq_domain *d, unsigned int irq,
697                           irq_hw_number_t hwirq)
698 {
699         return 0;
700 }
701
702 int irq_domain_simple_xlate(struct irq_domain *d,
703                             struct device_node *controller,
704                             const u32 *intspec, unsigned int intsize,
705                             unsigned long *out_hwirq, unsigned int *out_type)
706 {
707         if (d->of_node != controller)
708                 return -EINVAL;
709         if (intsize < 1)
710                 return -EINVAL;
711         *out_hwirq = intspec[0];
712         *out_type = IRQ_TYPE_NONE;
713         if (intsize > 1)
714                 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
715         return 0;
716 }
717
718 struct irq_domain_ops irq_domain_simple_ops = {
719         .map = irq_domain_simple_map,
720         .xlate = irq_domain_simple_xlate,
721 };
722 EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
723
724 #ifdef CONFIG_OF_IRQ
725 void irq_domain_generate_simple(const struct of_device_id *match,
726                                 u64 phys_base, unsigned int irq_start)
727 {
728         struct device_node *node;
729         pr_debug("looking for phys_base=%llx, irq_start=%i\n",
730                 (unsigned long long) phys_base, (int) irq_start);
731         node = of_find_matching_node_by_address(NULL, match, phys_base);
732         if (node)
733                 irq_domain_add_legacy(node, 32, irq_start, 0,
734                                       &irq_domain_simple_ops, NULL);
735 }
736 EXPORT_SYMBOL_GPL(irq_domain_generate_simple);
737 #endif