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