| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 1 | #define pr_fmt(fmt)  "irq: " fmt | 
|  | 2 |  | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 3 | #include <linux/debugfs.h> | 
|  | 4 | #include <linux/hardirq.h> | 
|  | 5 | #include <linux/interrupt.h> | 
| Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 6 | #include <linux/irq.h> | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 7 | #include <linux/irqdesc.h> | 
| Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 8 | #include <linux/irqdomain.h> | 
|  | 9 | #include <linux/module.h> | 
|  | 10 | #include <linux/mutex.h> | 
|  | 11 | #include <linux/of.h> | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 12 | #include <linux/of_address.h> | 
| Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 13 | #include <linux/topology.h> | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 14 | #include <linux/seq_file.h> | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 15 | #include <linux/slab.h> | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 16 | #include <linux/smp.h> | 
|  | 17 | #include <linux/fs.h> | 
| Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 18 |  | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 19 | #define IRQ_DOMAIN_MAP_LEGACY 0 /* driver allocated fixed range of irqs. | 
|  | 20 | * ie. legacy 8259, gets irqs 1..15 */ | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 21 | #define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */ | 
|  | 22 | #define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */ | 
|  | 23 | #define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */ | 
|  | 24 |  | 
| Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 25 | static LIST_HEAD(irq_domain_list); | 
|  | 26 | static DEFINE_MUTEX(irq_domain_mutex); | 
|  | 27 |  | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 28 | static DEFINE_MUTEX(revmap_trees_mutex); | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 29 | static struct irq_domain *irq_default_domain; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 30 |  | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 31 | /** | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 32 | * irq_domain_alloc() - Allocate a new irq_domain data structure | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 33 | * @of_node: optional device-tree node of the interrupt controller | 
|  | 34 | * @revmap_type: type of reverse mapping to use | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 35 | * @ops: map/unmap domain callbacks | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 36 | * @host_data: Controller private data pointer | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 37 | * | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 38 | * Allocates and initialize and irq_domain structure.  Caller is expected to | 
|  | 39 | * register allocated irq_domain with irq_domain_register().  Returns pointer | 
|  | 40 | * to IRQ domain, or NULL on failure. | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 41 | */ | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 42 | static struct irq_domain *irq_domain_alloc(struct device_node *of_node, | 
|  | 43 | unsigned int revmap_type, | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 44 | const struct irq_domain_ops *ops, | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 45 | void *host_data) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 46 | { | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 47 | struct irq_domain *domain; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 48 |  | 
| Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 49 | domain = kzalloc_node(sizeof(*domain), GFP_KERNEL, | 
|  | 50 | of_node_to_nid(of_node)); | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 51 | if (WARN_ON(!domain)) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 52 | return NULL; | 
|  | 53 |  | 
|  | 54 | /* Fill structure */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 55 | domain->revmap_type = revmap_type; | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 56 | domain->ops = ops; | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 57 | domain->host_data = host_data; | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 58 | domain->of_node = of_node_get(of_node); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 59 |  | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 60 | return domain; | 
|  | 61 | } | 
|  | 62 |  | 
| Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 63 | static void irq_domain_free(struct irq_domain *domain) | 
|  | 64 | { | 
|  | 65 | of_node_put(domain->of_node); | 
|  | 66 | kfree(domain); | 
|  | 67 | } | 
|  | 68 |  | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 69 | static void irq_domain_add(struct irq_domain *domain) | 
|  | 70 | { | 
|  | 71 | mutex_lock(&irq_domain_mutex); | 
|  | 72 | list_add(&domain->link, &irq_domain_list); | 
|  | 73 | mutex_unlock(&irq_domain_mutex); | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 74 | pr_debug("Allocated domain of type %d @0x%p\n", | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 75 | domain->revmap_type, domain); | 
|  | 76 | } | 
|  | 77 |  | 
| Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 78 | /** | 
|  | 79 | * irq_domain_remove() - Remove an irq domain. | 
|  | 80 | * @domain: domain to remove | 
|  | 81 | * | 
|  | 82 | * This routine is used to remove an irq domain. The caller must ensure | 
|  | 83 | * that all mappings within the domain have been disposed of prior to | 
|  | 84 | * use, depending on the revmap type. | 
|  | 85 | */ | 
|  | 86 | void irq_domain_remove(struct irq_domain *domain) | 
|  | 87 | { | 
|  | 88 | mutex_lock(&irq_domain_mutex); | 
|  | 89 |  | 
|  | 90 | switch (domain->revmap_type) { | 
|  | 91 | case IRQ_DOMAIN_MAP_LEGACY: | 
|  | 92 | /* | 
|  | 93 | * Legacy domains don't manage their own irq_desc | 
|  | 94 | * allocations, we expect the caller to handle irq_desc | 
|  | 95 | * freeing on their own. | 
|  | 96 | */ | 
|  | 97 | break; | 
|  | 98 | case IRQ_DOMAIN_MAP_TREE: | 
|  | 99 | /* | 
|  | 100 | * radix_tree_delete() takes care of destroying the root | 
|  | 101 | * node when all entries are removed. Shout if there are | 
|  | 102 | * any mappings left. | 
|  | 103 | */ | 
|  | 104 | WARN_ON(domain->revmap_data.tree.height); | 
|  | 105 | break; | 
|  | 106 | case IRQ_DOMAIN_MAP_LINEAR: | 
|  | 107 | kfree(domain->revmap_data.linear.revmap); | 
|  | 108 | domain->revmap_data.linear.size = 0; | 
|  | 109 | break; | 
|  | 110 | case IRQ_DOMAIN_MAP_NOMAP: | 
|  | 111 | break; | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | list_del(&domain->link); | 
|  | 115 |  | 
|  | 116 | /* | 
|  | 117 | * If the going away domain is the default one, reset it. | 
|  | 118 | */ | 
|  | 119 | if (unlikely(irq_default_domain == domain)) | 
|  | 120 | irq_set_default_host(NULL); | 
|  | 121 |  | 
|  | 122 | mutex_unlock(&irq_domain_mutex); | 
|  | 123 |  | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 124 | pr_debug("Removed domain of type %d @0x%p\n", | 
| Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 125 | domain->revmap_type, domain); | 
|  | 126 |  | 
|  | 127 | irq_domain_free(domain); | 
|  | 128 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 129 | EXPORT_SYMBOL_GPL(irq_domain_remove); | 
| Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 130 |  | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 131 | static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain, | 
|  | 132 | irq_hw_number_t hwirq) | 
|  | 133 | { | 
|  | 134 | irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq; | 
|  | 135 | int size = domain->revmap_data.legacy.size; | 
|  | 136 |  | 
|  | 137 | if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size)) | 
|  | 138 | return 0; | 
|  | 139 | return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq; | 
|  | 140 | } | 
|  | 141 |  | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 142 | /** | 
| Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 143 | * irq_domain_add_simple() - Allocate and register a simple irq_domain. | 
|  | 144 | * @of_node: pointer to interrupt controller's device tree node. | 
|  | 145 | * @size: total number of irqs in mapping | 
|  | 146 | * @first_irq: first number of irq block assigned to the domain | 
|  | 147 | * @ops: map/unmap domain callbacks | 
|  | 148 | * @host_data: Controller private data pointer | 
|  | 149 | * | 
|  | 150 | * Allocates a legacy irq_domain if irq_base is positive or a linear | 
|  | 151 | * domain otherwise. | 
|  | 152 | * | 
|  | 153 | * This is intended to implement the expected behaviour for most | 
|  | 154 | * interrupt controllers which is that a linear mapping should | 
|  | 155 | * normally be used unless the system requires a legacy mapping in | 
|  | 156 | * order to support supplying interrupt numbers during non-DT | 
|  | 157 | * registration of devices. | 
|  | 158 | */ | 
|  | 159 | struct irq_domain *irq_domain_add_simple(struct device_node *of_node, | 
|  | 160 | unsigned int size, | 
|  | 161 | unsigned int first_irq, | 
|  | 162 | const struct irq_domain_ops *ops, | 
|  | 163 | void *host_data) | 
|  | 164 | { | 
|  | 165 | if (first_irq > 0) | 
|  | 166 | return irq_domain_add_legacy(of_node, size, first_irq, 0, | 
|  | 167 | ops, host_data); | 
|  | 168 | else | 
|  | 169 | return irq_domain_add_linear(of_node, size, ops, host_data); | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | /** | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 173 | * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain. | 
|  | 174 | * @of_node: pointer to interrupt controller's device tree node. | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 175 | * @size: total number of irqs in legacy mapping | 
|  | 176 | * @first_irq: first number of irq block assigned to the domain | 
|  | 177 | * @first_hwirq: first hwirq number to use for the translation. Should normally | 
|  | 178 | *               be '0', but a positive integer can be used if the effective | 
|  | 179 | *               hwirqs numbering does not begin at zero. | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 180 | * @ops: map/unmap domain callbacks | 
|  | 181 | * @host_data: Controller private data pointer | 
|  | 182 | * | 
|  | 183 | * Note: the map() callback will be called before this function returns | 
|  | 184 | * for all legacy interrupts except 0 (which is always the invalid irq for | 
|  | 185 | * a legacy controller). | 
|  | 186 | */ | 
|  | 187 | struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 188 | unsigned int size, | 
|  | 189 | unsigned int first_irq, | 
|  | 190 | irq_hw_number_t first_hwirq, | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 191 | const struct irq_domain_ops *ops, | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 192 | void *host_data) | 
|  | 193 | { | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 194 | struct irq_domain *domain; | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 195 | unsigned int i; | 
|  | 196 |  | 
|  | 197 | domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data); | 
|  | 198 | if (!domain) | 
|  | 199 | return NULL; | 
|  | 200 |  | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 201 | domain->revmap_data.legacy.first_irq = first_irq; | 
|  | 202 | domain->revmap_data.legacy.first_hwirq = first_hwirq; | 
|  | 203 | domain->revmap_data.legacy.size = size; | 
|  | 204 |  | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 205 | mutex_lock(&irq_domain_mutex); | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 206 | /* Verify that all the irqs are available */ | 
|  | 207 | for (i = 0; i < size; i++) { | 
|  | 208 | int irq = first_irq + i; | 
|  | 209 | struct irq_data *irq_data = irq_get_irq_data(irq); | 
|  | 210 |  | 
|  | 211 | if (WARN_ON(!irq_data || irq_data->domain)) { | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 212 | mutex_unlock(&irq_domain_mutex); | 
| Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 213 | irq_domain_free(domain); | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 214 | return NULL; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 215 | } | 
|  | 216 | } | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 217 |  | 
|  | 218 | /* Claim all of the irqs before registering a legacy domain */ | 
|  | 219 | for (i = 0; i < size; i++) { | 
|  | 220 | struct irq_data *irq_data = irq_get_irq_data(first_irq + i); | 
|  | 221 | irq_data->hwirq = first_hwirq + i; | 
|  | 222 | irq_data->domain = domain; | 
|  | 223 | } | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 224 | mutex_unlock(&irq_domain_mutex); | 
|  | 225 |  | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 226 | for (i = 0; i < size; i++) { | 
|  | 227 | int irq = first_irq + i; | 
|  | 228 | int hwirq = first_hwirq + i; | 
|  | 229 |  | 
|  | 230 | /* IRQ0 gets ignored */ | 
|  | 231 | if (!irq) | 
|  | 232 | continue; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 233 |  | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 234 | /* Legacy flags are left to default at this point, | 
|  | 235 | * one can then use irq_create_mapping() to | 
|  | 236 | * explicitly change them | 
|  | 237 | */ | 
| Grant Likely | aed9804 | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 238 | if (ops->map) | 
|  | 239 | ops->map(domain, irq, hwirq); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 240 |  | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 241 | /* Clear norequest flags */ | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 242 | irq_clear_status_flags(irq, IRQ_NOREQUEST); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 243 | } | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 244 |  | 
|  | 245 | irq_domain_add(domain); | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 246 | return domain; | 
|  | 247 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 248 | EXPORT_SYMBOL_GPL(irq_domain_add_legacy); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 249 |  | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 250 | /** | 
| Dong Aisheng | 22076c7 | 2012-06-20 17:00:30 +0800 | [diff] [blame] | 251 | * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain. | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 252 | * @of_node: pointer to interrupt controller's device tree node. | 
| Mark Brown | a87487e | 2012-05-19 12:15:35 +0100 | [diff] [blame] | 253 | * @size: Number of interrupts in the domain. | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 254 | * @ops: map/unmap domain callbacks | 
|  | 255 | * @host_data: Controller private data pointer | 
|  | 256 | */ | 
|  | 257 | struct irq_domain *irq_domain_add_linear(struct device_node *of_node, | 
|  | 258 | unsigned int size, | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 259 | const struct irq_domain_ops *ops, | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 260 | void *host_data) | 
|  | 261 | { | 
|  | 262 | struct irq_domain *domain; | 
|  | 263 | unsigned int *revmap; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 264 |  | 
| Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 265 | revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL, | 
|  | 266 | of_node_to_nid(of_node)); | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 267 | if (WARN_ON(!revmap)) | 
|  | 268 | return NULL; | 
|  | 269 |  | 
|  | 270 | domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data); | 
|  | 271 | if (!domain) { | 
|  | 272 | kfree(revmap); | 
|  | 273 | return NULL; | 
|  | 274 | } | 
|  | 275 | domain->revmap_data.linear.size = size; | 
|  | 276 | domain->revmap_data.linear.revmap = revmap; | 
|  | 277 | irq_domain_add(domain); | 
|  | 278 | return domain; | 
|  | 279 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 280 | EXPORT_SYMBOL_GPL(irq_domain_add_linear); | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 281 |  | 
|  | 282 | struct irq_domain *irq_domain_add_nomap(struct device_node *of_node, | 
| Grant Likely | 6fa6c8e2 | 2012-02-15 15:06:08 -0700 | [diff] [blame] | 283 | unsigned int max_irq, | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 284 | const struct irq_domain_ops *ops, | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 285 | void *host_data) | 
|  | 286 | { | 
|  | 287 | struct irq_domain *domain = irq_domain_alloc(of_node, | 
|  | 288 | IRQ_DOMAIN_MAP_NOMAP, ops, host_data); | 
| Grant Likely | 6fa6c8e2 | 2012-02-15 15:06:08 -0700 | [diff] [blame] | 289 | if (domain) { | 
|  | 290 | domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0; | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 291 | irq_domain_add(domain); | 
| Grant Likely | 6fa6c8e2 | 2012-02-15 15:06:08 -0700 | [diff] [blame] | 292 | } | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 293 | return domain; | 
|  | 294 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 295 | EXPORT_SYMBOL_GPL(irq_domain_add_nomap); | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 296 |  | 
|  | 297 | /** | 
|  | 298 | * irq_domain_add_tree() | 
|  | 299 | * @of_node: pointer to interrupt controller's device tree node. | 
|  | 300 | * @ops: map/unmap domain callbacks | 
|  | 301 | * | 
|  | 302 | * Note: The radix tree will be allocated later during boot automatically | 
|  | 303 | * (the reverse mapping will use the slow path until that happens). | 
|  | 304 | */ | 
|  | 305 | struct irq_domain *irq_domain_add_tree(struct device_node *of_node, | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 306 | const struct irq_domain_ops *ops, | 
| Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 307 | void *host_data) | 
|  | 308 | { | 
|  | 309 | struct irq_domain *domain = irq_domain_alloc(of_node, | 
|  | 310 | IRQ_DOMAIN_MAP_TREE, ops, host_data); | 
|  | 311 | if (domain) { | 
|  | 312 | INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL); | 
|  | 313 | irq_domain_add(domain); | 
|  | 314 | } | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 315 | return domain; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 316 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 317 | EXPORT_SYMBOL_GPL(irq_domain_add_tree); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 318 |  | 
|  | 319 | /** | 
|  | 320 | * irq_find_host() - Locates a domain for a given device node | 
|  | 321 | * @node: device-tree node of the interrupt controller | 
|  | 322 | */ | 
|  | 323 | struct irq_domain *irq_find_host(struct device_node *node) | 
|  | 324 | { | 
|  | 325 | struct irq_domain *h, *found = NULL; | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 326 | int rc; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 327 |  | 
|  | 328 | /* We might want to match the legacy controller last since | 
|  | 329 | * it might potentially be set to match all interrupts in | 
|  | 330 | * the absence of a device node. This isn't a problem so far | 
|  | 331 | * yet though... | 
|  | 332 | */ | 
|  | 333 | mutex_lock(&irq_domain_mutex); | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 334 | list_for_each_entry(h, &irq_domain_list, link) { | 
|  | 335 | if (h->ops->match) | 
|  | 336 | rc = h->ops->match(h, node); | 
|  | 337 | else | 
|  | 338 | rc = (h->of_node != NULL) && (h->of_node == node); | 
|  | 339 |  | 
|  | 340 | if (rc) { | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 341 | found = h; | 
|  | 342 | break; | 
|  | 343 | } | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 344 | } | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 345 | mutex_unlock(&irq_domain_mutex); | 
|  | 346 | return found; | 
|  | 347 | } | 
|  | 348 | EXPORT_SYMBOL_GPL(irq_find_host); | 
|  | 349 |  | 
|  | 350 | /** | 
|  | 351 | * irq_set_default_host() - Set a "default" irq domain | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 352 | * @domain: default domain pointer | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 353 | * | 
|  | 354 | * For convenience, it's possible to set a "default" domain that will be used | 
|  | 355 | * whenever NULL is passed to irq_create_mapping(). It makes life easier for | 
|  | 356 | * platforms that want to manipulate a few hard coded interrupt numbers that | 
|  | 357 | * aren't properly represented in the device-tree. | 
|  | 358 | */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 359 | void irq_set_default_host(struct irq_domain *domain) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 360 | { | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 361 | pr_debug("Default domain set to @0x%p\n", domain); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 362 |  | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 363 | irq_default_domain = domain; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 364 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 365 | EXPORT_SYMBOL_GPL(irq_set_default_host); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 366 |  | 
| Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 367 | static void irq_domain_disassociate_many(struct irq_domain *domain, | 
|  | 368 | unsigned int irq_base, int count) | 
|  | 369 | { | 
|  | 370 | /* | 
|  | 371 | * disassociate in reverse order; | 
|  | 372 | * not strictly necessary, but nice for unwinding | 
|  | 373 | */ | 
|  | 374 | while (count--) { | 
|  | 375 | int irq = irq_base + count; | 
|  | 376 | struct irq_data *irq_data = irq_get_irq_data(irq); | 
|  | 377 | irq_hw_number_t hwirq = irq_data->hwirq; | 
|  | 378 |  | 
|  | 379 | if (WARN_ON(!irq_data || irq_data->domain != domain)) | 
|  | 380 | continue; | 
|  | 381 |  | 
|  | 382 | irq_set_status_flags(irq, IRQ_NOREQUEST); | 
|  | 383 |  | 
|  | 384 | /* remove chip and handler */ | 
|  | 385 | irq_set_chip_and_handler(irq, NULL, NULL); | 
|  | 386 |  | 
|  | 387 | /* Make sure it's completed */ | 
|  | 388 | synchronize_irq(irq); | 
|  | 389 |  | 
|  | 390 | /* Tell the PIC about it */ | 
|  | 391 | if (domain->ops->unmap) | 
|  | 392 | domain->ops->unmap(domain, irq); | 
|  | 393 | smp_mb(); | 
|  | 394 |  | 
|  | 395 | irq_data->domain = NULL; | 
|  | 396 | irq_data->hwirq = 0; | 
|  | 397 |  | 
|  | 398 | /* Clear reverse map */ | 
|  | 399 | switch(domain->revmap_type) { | 
|  | 400 | case IRQ_DOMAIN_MAP_LINEAR: | 
|  | 401 | if (hwirq < domain->revmap_data.linear.size) | 
|  | 402 | domain->revmap_data.linear.revmap[hwirq] = 0; | 
|  | 403 | break; | 
|  | 404 | case IRQ_DOMAIN_MAP_TREE: | 
|  | 405 | mutex_lock(&revmap_trees_mutex); | 
|  | 406 | radix_tree_delete(&domain->revmap_data.tree, hwirq); | 
|  | 407 | mutex_unlock(&revmap_trees_mutex); | 
|  | 408 | break; | 
|  | 409 | } | 
|  | 410 | } | 
|  | 411 | } | 
|  | 412 |  | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 413 | int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base, | 
|  | 414 | irq_hw_number_t hwirq_base, int count) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 415 | { | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 416 | unsigned int virq = irq_base; | 
|  | 417 | irq_hw_number_t hwirq = hwirq_base; | 
| Mark Brown | f5a1ad0 | 2012-07-20 10:33:19 +0100 | [diff] [blame] | 418 | int i, ret; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 419 |  | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 420 | pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__, | 
|  | 421 | of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count); | 
|  | 422 |  | 
|  | 423 | for (i = 0; i < count; i++) { | 
|  | 424 | struct irq_data *irq_data = irq_get_irq_data(virq + i); | 
|  | 425 |  | 
|  | 426 | if (WARN(!irq_data, "error: irq_desc not allocated; " | 
|  | 427 | "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i)) | 
|  | 428 | return -EINVAL; | 
|  | 429 | if (WARN(irq_data->domain, "error: irq_desc already associated; " | 
|  | 430 | "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i)) | 
|  | 431 | return -EINVAL; | 
|  | 432 | }; | 
|  | 433 |  | 
|  | 434 | for (i = 0; i < count; i++, virq++, hwirq++) { | 
|  | 435 | struct irq_data *irq_data = irq_get_irq_data(virq); | 
|  | 436 |  | 
|  | 437 | irq_data->hwirq = hwirq; | 
|  | 438 | irq_data->domain = domain; | 
| Mark Brown | f5a1ad0 | 2012-07-20 10:33:19 +0100 | [diff] [blame] | 439 | if (domain->ops->map) { | 
|  | 440 | ret = domain->ops->map(domain, virq, hwirq); | 
|  | 441 | if (ret != 0) { | 
|  | 442 | pr_err("irq-%i==>hwirq-0x%lx mapping failed: %d\n", | 
|  | 443 | virq, hwirq, ret); | 
|  | 444 | WARN_ON(1); | 
|  | 445 | irq_data->domain = NULL; | 
|  | 446 | irq_data->hwirq = 0; | 
|  | 447 | goto err_unmap; | 
|  | 448 | } | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 449 | } | 
|  | 450 |  | 
|  | 451 | switch (domain->revmap_type) { | 
|  | 452 | case IRQ_DOMAIN_MAP_LINEAR: | 
|  | 453 | if (hwirq < domain->revmap_data.linear.size) | 
|  | 454 | domain->revmap_data.linear.revmap[hwirq] = virq; | 
|  | 455 | break; | 
|  | 456 | case IRQ_DOMAIN_MAP_TREE: | 
|  | 457 | mutex_lock(&revmap_trees_mutex); | 
| Grant Likely | d6b0d1f | 2012-06-03 22:04:37 -0700 | [diff] [blame] | 458 | radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data); | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 459 | mutex_unlock(&revmap_trees_mutex); | 
|  | 460 | break; | 
|  | 461 | } | 
|  | 462 |  | 
|  | 463 | irq_clear_status_flags(virq, IRQ_NOREQUEST); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 464 | } | 
|  | 465 |  | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 466 | return 0; | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 467 |  | 
|  | 468 | err_unmap: | 
|  | 469 | irq_domain_disassociate_many(domain, irq_base, i); | 
|  | 470 | return -EINVAL; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 471 | } | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 472 | EXPORT_SYMBOL_GPL(irq_domain_associate_many); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 473 |  | 
|  | 474 | /** | 
|  | 475 | * irq_create_direct_mapping() - Allocate an irq for direct mapping | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 476 | * @domain: domain to allocate the irq for or NULL for default domain | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 477 | * | 
|  | 478 | * This routine is used for irq controllers which can choose the hardware | 
|  | 479 | * interrupt numbers they generate. In such a case it's simplest to use | 
|  | 480 | * the linux irq as the hardware interrupt number. | 
|  | 481 | */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 482 | unsigned int irq_create_direct_mapping(struct irq_domain *domain) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 483 | { | 
|  | 484 | unsigned int virq; | 
|  | 485 |  | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 486 | if (domain == NULL) | 
|  | 487 | domain = irq_default_domain; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 488 |  | 
| Grant Likely | 9844a55 | 2012-06-03 22:04:38 -0700 | [diff] [blame] | 489 | if (WARN_ON(!domain || domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP)) | 
|  | 490 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 491 |  | 
| Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 492 | virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node)); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 493 | if (!virq) { | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 494 | pr_debug("create_direct virq allocation failed\n"); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 495 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 496 | } | 
| Grant Likely | 6fa6c8e2 | 2012-02-15 15:06:08 -0700 | [diff] [blame] | 497 | if (virq >= domain->revmap_data.nomap.max_irq) { | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 498 | pr_err("ERROR: no free irqs available below %i maximum\n", | 
| Grant Likely | 6fa6c8e2 | 2012-02-15 15:06:08 -0700 | [diff] [blame] | 499 | domain->revmap_data.nomap.max_irq); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 500 | irq_free_desc(virq); | 
|  | 501 | return 0; | 
|  | 502 | } | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 503 | pr_debug("create_direct obtained virq %d\n", virq); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 504 |  | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 505 | if (irq_domain_associate(domain, virq, virq)) { | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 506 | irq_free_desc(virq); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 507 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 508 | } | 
|  | 509 |  | 
|  | 510 | return virq; | 
|  | 511 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 512 | EXPORT_SYMBOL_GPL(irq_create_direct_mapping); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 513 |  | 
|  | 514 | /** | 
|  | 515 | * irq_create_mapping() - Map a hardware interrupt into linux irq space | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 516 | * @domain: domain owning this hardware interrupt or NULL for default domain | 
|  | 517 | * @hwirq: hardware irq number in that domain space | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 518 | * | 
|  | 519 | * Only one mapping per hardware interrupt is permitted. Returns a linux | 
|  | 520 | * irq number. | 
|  | 521 | * If the sense/trigger is to be specified, set_irq_type() should be called | 
|  | 522 | * on the number returned from that call. | 
|  | 523 | */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 524 | unsigned int irq_create_mapping(struct irq_domain *domain, | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 525 | irq_hw_number_t hwirq) | 
|  | 526 | { | 
| David Daney | 5b7526e | 2012-04-05 16:52:13 -0700 | [diff] [blame] | 527 | unsigned int hint; | 
|  | 528 | int virq; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 529 |  | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 530 | pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 531 |  | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 532 | /* Look for default domain if nececssary */ | 
|  | 533 | if (domain == NULL) | 
|  | 534 | domain = irq_default_domain; | 
|  | 535 | if (domain == NULL) { | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 536 | pr_warning("irq_create_mapping called for" | 
|  | 537 | " NULL domain, hwirq=%lx\n", hwirq); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 538 | WARN_ON(1); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 539 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 540 | } | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 541 | pr_debug("-> using domain @%p\n", domain); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 542 |  | 
|  | 543 | /* Check if mapping already exists */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 544 | virq = irq_find_mapping(domain, hwirq); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 545 | if (virq) { | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 546 | pr_debug("-> existing mapping on virq %d\n", virq); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 547 | return virq; | 
|  | 548 | } | 
|  | 549 |  | 
|  | 550 | /* Get a virtual interrupt number */ | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 551 | if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY) | 
|  | 552 | return irq_domain_legacy_revmap(domain, hwirq); | 
|  | 553 |  | 
|  | 554 | /* Allocate a virtual interrupt number */ | 
| Grant Likely | 6fa6c8e2 | 2012-02-15 15:06:08 -0700 | [diff] [blame] | 555 | hint = hwirq % nr_irqs; | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 556 | if (hint == 0) | 
|  | 557 | hint++; | 
| Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 558 | virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node)); | 
| David Daney | 5b7526e | 2012-04-05 16:52:13 -0700 | [diff] [blame] | 559 | if (virq <= 0) | 
| Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 560 | virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node)); | 
| David Daney | 5b7526e | 2012-04-05 16:52:13 -0700 | [diff] [blame] | 561 | if (virq <= 0) { | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 562 | pr_debug("-> virq allocation failed\n"); | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 563 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 564 | } | 
|  | 565 |  | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 566 | if (irq_domain_associate(domain, virq, hwirq)) { | 
| Grant Likely | 7325570 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 567 | irq_free_desc(virq); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 568 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 569 | } | 
|  | 570 |  | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 571 | pr_debug("irq %lu on domain %s mapped to virtual irq %u\n", | 
| Grant Likely | efd68e7 | 2012-06-03 22:04:33 -0700 | [diff] [blame] | 572 | hwirq, of_node_full_name(domain->of_node), virq); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 573 |  | 
|  | 574 | return virq; | 
|  | 575 | } | 
|  | 576 | EXPORT_SYMBOL_GPL(irq_create_mapping); | 
|  | 577 |  | 
| Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 578 | /** | 
|  | 579 | * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs | 
|  | 580 | * @domain: domain owning the interrupt range | 
|  | 581 | * @irq_base: beginning of linux IRQ range | 
|  | 582 | * @hwirq_base: beginning of hardware IRQ range | 
|  | 583 | * @count: Number of interrupts to map | 
|  | 584 | * | 
|  | 585 | * This routine is used for allocating and mapping a range of hardware | 
|  | 586 | * irqs to linux irqs where the linux irq numbers are at pre-defined | 
|  | 587 | * locations. For use by controllers that already have static mappings | 
|  | 588 | * to insert in to the domain. | 
|  | 589 | * | 
|  | 590 | * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time | 
|  | 591 | * domain insertion. | 
|  | 592 | * | 
|  | 593 | * 0 is returned upon success, while any failure to establish a static | 
|  | 594 | * mapping is treated as an error. | 
|  | 595 | */ | 
|  | 596 | int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base, | 
|  | 597 | irq_hw_number_t hwirq_base, int count) | 
|  | 598 | { | 
|  | 599 | int ret; | 
|  | 600 |  | 
|  | 601 | ret = irq_alloc_descs(irq_base, irq_base, count, | 
|  | 602 | of_node_to_nid(domain->of_node)); | 
|  | 603 | if (unlikely(ret < 0)) | 
|  | 604 | return ret; | 
|  | 605 |  | 
|  | 606 | ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count); | 
|  | 607 | if (unlikely(ret < 0)) { | 
|  | 608 | irq_free_descs(irq_base, count); | 
|  | 609 | return ret; | 
|  | 610 | } | 
|  | 611 |  | 
|  | 612 | return 0; | 
|  | 613 | } | 
|  | 614 | EXPORT_SYMBOL_GPL(irq_create_strict_mappings); | 
|  | 615 |  | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 616 | unsigned int irq_create_of_mapping(struct device_node *controller, | 
|  | 617 | const u32 *intspec, unsigned int intsize) | 
|  | 618 | { | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 619 | struct irq_domain *domain; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 620 | irq_hw_number_t hwirq; | 
|  | 621 | unsigned int type = IRQ_TYPE_NONE; | 
|  | 622 | unsigned int virq; | 
|  | 623 |  | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 624 | domain = controller ? irq_find_host(controller) : irq_default_domain; | 
|  | 625 | if (!domain) { | 
| Grant Likely | abd2363 | 2012-02-24 08:07:06 -0700 | [diff] [blame] | 626 | #ifdef CONFIG_MIPS | 
|  | 627 | /* | 
|  | 628 | * Workaround to avoid breaking interrupt controller drivers | 
|  | 629 | * that don't yet register an irq_domain.  This is temporary | 
|  | 630 | * code. ~~~gcl, Feb 24, 2012 | 
|  | 631 | * | 
|  | 632 | * Scheduled for removal in Linux v3.6.  That should be enough | 
|  | 633 | * time. | 
|  | 634 | */ | 
|  | 635 | if (intsize > 0) | 
|  | 636 | return intspec[0]; | 
|  | 637 | #endif | 
| Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 638 | pr_warning("no irq domain found for %s !\n", | 
| Grant Likely | efd68e7 | 2012-06-03 22:04:33 -0700 | [diff] [blame] | 639 | of_node_full_name(controller)); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 640 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 641 | } | 
|  | 642 |  | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 643 | /* If domain has no translation, then we assume interrupt line */ | 
|  | 644 | if (domain->ops->xlate == NULL) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 645 | hwirq = intspec[0]; | 
|  | 646 | else { | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 647 | if (domain->ops->xlate(domain, controller, intspec, intsize, | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 648 | &hwirq, &type)) | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 649 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 650 | } | 
|  | 651 |  | 
|  | 652 | /* Create mapping */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 653 | virq = irq_create_mapping(domain, hwirq); | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 654 | if (!virq) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 655 | return virq; | 
|  | 656 |  | 
|  | 657 | /* Set type if specified and different than the current one */ | 
|  | 658 | if (type != IRQ_TYPE_NONE && | 
|  | 659 | type != (irqd_get_trigger_type(irq_get_irq_data(virq)))) | 
|  | 660 | irq_set_irq_type(virq, type); | 
|  | 661 | return virq; | 
|  | 662 | } | 
|  | 663 | EXPORT_SYMBOL_GPL(irq_create_of_mapping); | 
|  | 664 |  | 
|  | 665 | /** | 
|  | 666 | * irq_dispose_mapping() - Unmap an interrupt | 
|  | 667 | * @virq: linux irq number of the interrupt to unmap | 
|  | 668 | */ | 
|  | 669 | void irq_dispose_mapping(unsigned int virq) | 
|  | 670 | { | 
|  | 671 | struct irq_data *irq_data = irq_get_irq_data(virq); | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 672 | struct irq_domain *domain; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 673 |  | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 674 | if (!virq || !irq_data) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 675 | return; | 
|  | 676 |  | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 677 | domain = irq_data->domain; | 
|  | 678 | if (WARN_ON(domain == NULL)) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 679 | return; | 
|  | 680 |  | 
|  | 681 | /* Never unmap legacy interrupts */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 682 | if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY) | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 683 | return; | 
|  | 684 |  | 
| Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 685 | irq_domain_disassociate_many(domain, virq, 1); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 686 | irq_free_desc(virq); | 
|  | 687 | } | 
|  | 688 | EXPORT_SYMBOL_GPL(irq_dispose_mapping); | 
|  | 689 |  | 
|  | 690 | /** | 
|  | 691 | * irq_find_mapping() - Find a linux irq from an hw irq number. | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 692 | * @domain: domain owning this hardware interrupt | 
|  | 693 | * @hwirq: hardware irq number in that domain space | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 694 | */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 695 | unsigned int irq_find_mapping(struct irq_domain *domain, | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 696 | irq_hw_number_t hwirq) | 
|  | 697 | { | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 698 | struct irq_data *data; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 699 |  | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 700 | /* Look for default domain if nececssary */ | 
|  | 701 | if (domain == NULL) | 
|  | 702 | domain = irq_default_domain; | 
|  | 703 | if (domain == NULL) | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 704 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 705 |  | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 706 | switch (domain->revmap_type) { | 
|  | 707 | case IRQ_DOMAIN_MAP_LEGACY: | 
| Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 708 | return irq_domain_legacy_revmap(domain, hwirq); | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 709 | case IRQ_DOMAIN_MAP_LINEAR: | 
|  | 710 | return irq_linear_revmap(domain, hwirq); | 
|  | 711 | case IRQ_DOMAIN_MAP_TREE: | 
|  | 712 | rcu_read_lock(); | 
|  | 713 | data = radix_tree_lookup(&domain->revmap_data.tree, hwirq); | 
|  | 714 | rcu_read_unlock(); | 
|  | 715 | if (data) | 
|  | 716 | return data->irq; | 
|  | 717 | break; | 
|  | 718 | case IRQ_DOMAIN_MAP_NOMAP: | 
|  | 719 | data = irq_get_irq_data(hwirq); | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 720 | if (data && (data->domain == domain) && (data->hwirq == hwirq)) | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 721 | return hwirq; | 
|  | 722 | break; | 
|  | 723 | } | 
|  | 724 |  | 
| Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 725 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 726 | } | 
|  | 727 | EXPORT_SYMBOL_GPL(irq_find_mapping); | 
|  | 728 |  | 
|  | 729 | /** | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 730 | * irq_linear_revmap() - Find a linux irq from a hw irq number. | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 731 | * @domain: domain owning this hardware interrupt | 
|  | 732 | * @hwirq: hardware irq number in that domain space | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 733 | * | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 734 | * This is a fast path that can be called directly by irq controller code to | 
|  | 735 | * save a handful of instructions. | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 736 | */ | 
| Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 737 | unsigned int irq_linear_revmap(struct irq_domain *domain, | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 738 | irq_hw_number_t hwirq) | 
|  | 739 | { | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 740 | BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 741 |  | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 742 | /* Check revmap bounds; complain if exceeded */ | 
|  | 743 | if (WARN_ON(hwirq >= domain->revmap_data.linear.size)) | 
|  | 744 | return 0; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 745 |  | 
| Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 746 | return domain->revmap_data.linear.revmap[hwirq]; | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 747 | } | 
| Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 748 | EXPORT_SYMBOL_GPL(irq_linear_revmap); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 749 |  | 
| Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 750 | #ifdef CONFIG_IRQ_DOMAIN_DEBUG | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 751 | static int virq_debug_show(struct seq_file *m, void *private) | 
|  | 752 | { | 
|  | 753 | unsigned long flags; | 
|  | 754 | struct irq_desc *desc; | 
|  | 755 | const char *p; | 
|  | 756 | static const char none[] = "none"; | 
|  | 757 | void *data; | 
|  | 758 | int i; | 
|  | 759 |  | 
| Grant Likely | 15e06bf | 2012-04-11 00:26:25 -0600 | [diff] [blame] | 760 | seq_printf(m, "%-5s  %-7s  %-15s  %-*s  %s\n", "irq", "hwirq", | 
| Grant Likely | 5269a9a | 2012-04-12 14:42:15 -0600 | [diff] [blame] | 761 | "chip name", (int)(2 * sizeof(void *) + 2), "chip data", | 
|  | 762 | "domain name"); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 763 |  | 
|  | 764 | for (i = 1; i < nr_irqs; i++) { | 
|  | 765 | desc = irq_to_desc(i); | 
|  | 766 | if (!desc) | 
|  | 767 | continue; | 
|  | 768 |  | 
|  | 769 | raw_spin_lock_irqsave(&desc->lock, flags); | 
|  | 770 |  | 
|  | 771 | if (desc->action && desc->action->handler) { | 
|  | 772 | struct irq_chip *chip; | 
|  | 773 |  | 
|  | 774 | seq_printf(m, "%5d  ", i); | 
|  | 775 | seq_printf(m, "0x%05lx  ", desc->irq_data.hwirq); | 
|  | 776 |  | 
|  | 777 | chip = irq_desc_get_chip(desc); | 
|  | 778 | if (chip && chip->name) | 
|  | 779 | p = chip->name; | 
|  | 780 | else | 
|  | 781 | p = none; | 
|  | 782 | seq_printf(m, "%-15s  ", p); | 
|  | 783 |  | 
|  | 784 | data = irq_desc_get_chip_data(desc); | 
| Grant Likely | 15e06bf | 2012-04-11 00:26:25 -0600 | [diff] [blame] | 785 | seq_printf(m, data ? "0x%p  " : "  %p  ", data); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 786 |  | 
| Grant Likely | efd68e7 | 2012-06-03 22:04:33 -0700 | [diff] [blame] | 787 | if (desc->irq_data.domain) | 
|  | 788 | p = of_node_full_name(desc->irq_data.domain->of_node); | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 789 | else | 
|  | 790 | p = none; | 
|  | 791 | seq_printf(m, "%s\n", p); | 
|  | 792 | } | 
|  | 793 |  | 
|  | 794 | raw_spin_unlock_irqrestore(&desc->lock, flags); | 
|  | 795 | } | 
|  | 796 |  | 
|  | 797 | return 0; | 
|  | 798 | } | 
|  | 799 |  | 
|  | 800 | static int virq_debug_open(struct inode *inode, struct file *file) | 
|  | 801 | { | 
|  | 802 | return single_open(file, virq_debug_show, inode->i_private); | 
|  | 803 | } | 
|  | 804 |  | 
|  | 805 | static const struct file_operations virq_debug_fops = { | 
|  | 806 | .open = virq_debug_open, | 
|  | 807 | .read = seq_read, | 
|  | 808 | .llseek = seq_lseek, | 
|  | 809 | .release = single_release, | 
|  | 810 | }; | 
|  | 811 |  | 
|  | 812 | static int __init irq_debugfs_init(void) | 
|  | 813 | { | 
| Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 814 | if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL, | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 815 | NULL, &virq_debug_fops) == NULL) | 
|  | 816 | return -ENOMEM; | 
|  | 817 |  | 
|  | 818 | return 0; | 
|  | 819 | } | 
|  | 820 | __initcall(irq_debugfs_init); | 
| Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 821 | #endif /* CONFIG_IRQ_DOMAIN_DEBUG */ | 
| Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 822 |  | 
| Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 823 | /** | 
|  | 824 | * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings | 
|  | 825 | * | 
|  | 826 | * Device Tree IRQ specifier translation function which works with one cell | 
|  | 827 | * bindings where the cell value maps directly to the hwirq number. | 
|  | 828 | */ | 
|  | 829 | int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr, | 
|  | 830 | const u32 *intspec, unsigned int intsize, | 
|  | 831 | unsigned long *out_hwirq, unsigned int *out_type) | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 832 | { | 
| Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 833 | if (WARN_ON(intsize < 1)) | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 834 | return -EINVAL; | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 835 | *out_hwirq = intspec[0]; | 
|  | 836 | *out_type = IRQ_TYPE_NONE; | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 837 | return 0; | 
|  | 838 | } | 
| Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 839 | EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell); | 
|  | 840 |  | 
|  | 841 | /** | 
|  | 842 | * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings | 
|  | 843 | * | 
|  | 844 | * Device Tree IRQ specifier translation function which works with two cell | 
|  | 845 | * bindings where the cell values map directly to the hwirq number | 
|  | 846 | * and linux irq flags. | 
|  | 847 | */ | 
|  | 848 | int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr, | 
|  | 849 | const u32 *intspec, unsigned int intsize, | 
|  | 850 | irq_hw_number_t *out_hwirq, unsigned int *out_type) | 
|  | 851 | { | 
|  | 852 | if (WARN_ON(intsize < 2)) | 
|  | 853 | return -EINVAL; | 
|  | 854 | *out_hwirq = intspec[0]; | 
|  | 855 | *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; | 
|  | 856 | return 0; | 
|  | 857 | } | 
|  | 858 | EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell); | 
|  | 859 |  | 
|  | 860 | /** | 
|  | 861 | * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings | 
|  | 862 | * | 
|  | 863 | * Device Tree IRQ specifier translation function which works with either one | 
|  | 864 | * or two cell bindings where the cell values map directly to the hwirq number | 
|  | 865 | * and linux irq flags. | 
|  | 866 | * | 
|  | 867 | * Note: don't use this function unless your interrupt controller explicitly | 
|  | 868 | * supports both one and two cell bindings.  For the majority of controllers | 
|  | 869 | * the _onecell() or _twocell() variants above should be used. | 
|  | 870 | */ | 
|  | 871 | int irq_domain_xlate_onetwocell(struct irq_domain *d, | 
|  | 872 | struct device_node *ctrlr, | 
|  | 873 | const u32 *intspec, unsigned int intsize, | 
|  | 874 | unsigned long *out_hwirq, unsigned int *out_type) | 
|  | 875 | { | 
|  | 876 | if (WARN_ON(intsize < 1)) | 
|  | 877 | return -EINVAL; | 
|  | 878 | *out_hwirq = intspec[0]; | 
|  | 879 | *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE; | 
|  | 880 | return 0; | 
|  | 881 | } | 
|  | 882 | EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell); | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 883 |  | 
| Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 884 | const struct irq_domain_ops irq_domain_simple_ops = { | 
| Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 885 | .xlate = irq_domain_xlate_onetwocell, | 
| Grant Likely | 7529495 | 2012-02-14 14:06:57 -0700 | [diff] [blame] | 886 | }; | 
|  | 887 | EXPORT_SYMBOL_GPL(irq_domain_simple_ops); | 
|  | 888 |  | 
|  | 889 | #ifdef CONFIG_OF_IRQ | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 890 | void irq_domain_generate_simple(const struct of_device_id *match, | 
|  | 891 | u64 phys_base, unsigned int irq_start) | 
|  | 892 | { | 
|  | 893 | struct device_node *node; | 
| Grant Likely | e1964c5 | 2012-02-14 14:06:48 -0700 | [diff] [blame] | 894 | pr_debug("looking for phys_base=%llx, irq_start=%i\n", | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 895 | (unsigned long long) phys_base, (int) irq_start); | 
|  | 896 | node = of_find_matching_node_by_address(NULL, match, phys_base); | 
|  | 897 | if (node) | 
| Grant Likely | 6b783f7 | 2012-01-10 17:09:30 -0700 | [diff] [blame] | 898 | irq_domain_add_legacy(node, 32, irq_start, 0, | 
|  | 899 | &irq_domain_simple_ops, NULL); | 
| Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 900 | } | 
|  | 901 | EXPORT_SYMBOL_GPL(irq_domain_generate_simple); | 
| Grant Likely | 7529495 | 2012-02-14 14:06:57 -0700 | [diff] [blame] | 902 | #endif |