| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 1 | /* | 
|  | 2 | * Dynamic IRQ management | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2010  Paul Mundt | 
|  | 5 | * | 
|  | 6 | * Modelled after arch/x86/kernel/apic/io_apic.c | 
|  | 7 | * | 
|  | 8 | * This file is subject to the terms and conditions of the GNU General Public | 
|  | 9 | * License.  See the file "COPYING" in the main directory of this archive | 
|  | 10 | * for more details. | 
|  | 11 | */ | 
|  | 12 | #define pr_fmt(fmt) "intc: " fmt | 
|  | 13 |  | 
|  | 14 | #include <linux/irq.h> | 
|  | 15 | #include <linux/bitmap.h> | 
|  | 16 | #include <linux/spinlock.h> | 
| Paul Gortmaker | db4e839 | 2011-07-31 19:18:02 -0400 | [diff] [blame] | 17 | #include <linux/module.h> | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 18 | #include "internals.h" /* only for activate_irq() damage.. */ | 
|  | 19 |  | 
|  | 20 | /* | 
| Paul Mundt | 38ab134 | 2010-10-26 16:05:08 +0900 | [diff] [blame] | 21 | * The IRQ bitmap provides a global map of bound IRQ vectors for a | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 22 | * given platform. Allocation of IRQs are either static through the CPU | 
|  | 23 | * vector map, or dynamic in the case of board mux vectors or MSI. | 
|  | 24 | * | 
|  | 25 | * As this is a central point for all IRQ controllers on the system, | 
|  | 26 | * each of the available sources are mapped out here. This combined with | 
|  | 27 | * sparseirq makes it quite trivial to keep the vector map tightly packed | 
|  | 28 | * when dynamically creating IRQs, as well as tying in to otherwise | 
|  | 29 | * unused irq_desc positions in the sparse array. | 
|  | 30 | */ | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 31 |  | 
|  | 32 | /* | 
|  | 33 | * Dynamic IRQ allocation and deallocation | 
|  | 34 | */ | 
|  | 35 | unsigned int create_irq_nr(unsigned int irq_want, int node) | 
|  | 36 | { | 
| Paul Mundt | 38ab134 | 2010-10-26 16:05:08 +0900 | [diff] [blame] | 37 | int irq = irq_alloc_desc_at(irq_want, node); | 
|  | 38 | if (irq < 0) | 
| Thomas Gleixner | c4318ba | 2010-10-12 02:03:09 +0900 | [diff] [blame] | 39 | return 0; | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 40 |  | 
| Thomas Gleixner | c4318ba | 2010-10-12 02:03:09 +0900 | [diff] [blame] | 41 | activate_irq(irq); | 
| Paul Mundt | 38ab134 | 2010-10-26 16:05:08 +0900 | [diff] [blame] | 42 | return irq; | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 43 | } | 
|  | 44 |  | 
|  | 45 | int create_irq(void) | 
|  | 46 | { | 
| Paul Mundt | 38ab134 | 2010-10-26 16:05:08 +0900 | [diff] [blame] | 47 | int irq = irq_alloc_desc(numa_node_id()); | 
|  | 48 | if (irq >= 0) | 
|  | 49 | activate_irq(irq); | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 50 |  | 
|  | 51 | return irq; | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | void destroy_irq(unsigned int irq) | 
|  | 55 | { | 
| Thomas Gleixner | c4318ba | 2010-10-12 02:03:09 +0900 | [diff] [blame] | 56 | irq_free_desc(irq); | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 57 | } | 
|  | 58 |  | 
|  | 59 | void reserve_intc_vectors(struct intc_vect *vectors, unsigned int nr_vecs) | 
|  | 60 | { | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 61 | int i; | 
|  | 62 |  | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 63 | for (i = 0; i < nr_vecs; i++) | 
| Paul Mundt | 20f95e0 | 2010-11-01 16:10:48 -0400 | [diff] [blame] | 64 | irq_reserve_irq(evt2irq(vectors[i].vect)); | 
| Paul Mundt | 2be6bb0 | 2010-10-05 22:10:30 +0900 | [diff] [blame] | 65 | } |