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