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