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