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> |
Rashika Kheria | 64be38a | 2014-02-27 17:10:12 +0530 | [diff] [blame] | 13 | #include <linux/of_irq.h> |
Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 14 | #include <linux/topology.h> |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 15 | #include <linux/seq_file.h> |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 16 | #include <linux/slab.h> |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 17 | #include <linux/smp.h> |
| 18 | #include <linux/fs.h> |
Grant Likely | 08a543a | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 19 | |
| 20 | static LIST_HEAD(irq_domain_list); |
| 21 | static DEFINE_MUTEX(irq_domain_mutex); |
| 22 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 23 | static DEFINE_MUTEX(revmap_trees_mutex); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 24 | static struct irq_domain *irq_default_domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 25 | |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 26 | static int irq_domain_alloc_descs(int virq, unsigned int nr_irqs, |
| 27 | irq_hw_number_t hwirq, int node); |
| 28 | static void irq_domain_check_hierarchy(struct irq_domain *domain); |
| 29 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 30 | /** |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 31 | * __irq_domain_add() - Allocate a new irq_domain data structure |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 32 | * @of_node: optional device-tree node of the interrupt controller |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 33 | * @size: Size of linear map; 0 for radix mapping only |
Jiang Liu | a257954 | 2014-05-27 16:07:37 +0800 | [diff] [blame] | 34 | * @hwirq_max: Maximum number of interrupts supported by controller |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 35 | * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no |
| 36 | * direct mapping |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 37 | * @ops: domain callbacks |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 38 | * @host_data: Controller private data pointer |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 39 | * |
Jiang Liu | a257954 | 2014-05-27 16:07:37 +0800 | [diff] [blame] | 40 | * Allocates and initialize and irq_domain structure. |
| 41 | * Returns pointer to IRQ domain, or NULL on failure. |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 42 | */ |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 43 | struct irq_domain *__irq_domain_add(struct device_node *of_node, int size, |
| 44 | irq_hw_number_t hwirq_max, int direct_max, |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 45 | const struct irq_domain_ops *ops, |
| 46 | void *host_data) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 47 | { |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 48 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 49 | |
Grant Likely | cef5075 | 2012-07-11 17:24:31 +0100 | [diff] [blame] | 50 | domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size), |
| 51 | GFP_KERNEL, of_node_to_nid(of_node)); |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 52 | if (WARN_ON(!domain)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 53 | return NULL; |
| 54 | |
| 55 | /* Fill structure */ |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 56 | INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 57 | domain->ops = ops; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 58 | domain->host_data = host_data; |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 59 | domain->of_node = of_node_get(of_node); |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 60 | domain->hwirq_max = hwirq_max; |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 61 | domain->revmap_size = size; |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 62 | domain->revmap_direct_max_irq = direct_max; |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 63 | irq_domain_check_hierarchy(domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 64 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 65 | mutex_lock(&irq_domain_mutex); |
| 66 | list_add(&domain->link, &irq_domain_list); |
| 67 | mutex_unlock(&irq_domain_mutex); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 68 | |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 69 | pr_debug("Added domain %s\n", domain->name); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 70 | return domain; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 71 | } |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 72 | EXPORT_SYMBOL_GPL(__irq_domain_add); |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 73 | |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 74 | /** |
| 75 | * irq_domain_remove() - Remove an irq domain. |
| 76 | * @domain: domain to remove |
| 77 | * |
| 78 | * This routine is used to remove an irq domain. The caller must ensure |
| 79 | * that all mappings within the domain have been disposed of prior to |
| 80 | * use, depending on the revmap type. |
| 81 | */ |
| 82 | void irq_domain_remove(struct irq_domain *domain) |
| 83 | { |
| 84 | mutex_lock(&irq_domain_mutex); |
| 85 | |
Grant Likely | cef5075 | 2012-07-11 17:24:31 +0100 | [diff] [blame] | 86 | /* |
| 87 | * radix_tree_delete() takes care of destroying the root |
| 88 | * node when all entries are removed. Shout if there are |
| 89 | * any mappings left. |
| 90 | */ |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 91 | WARN_ON(domain->revmap_tree.height); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 92 | |
| 93 | list_del(&domain->link); |
| 94 | |
| 95 | /* |
| 96 | * If the going away domain is the default one, reset it. |
| 97 | */ |
| 98 | if (unlikely(irq_default_domain == domain)) |
| 99 | irq_set_default_host(NULL); |
| 100 | |
| 101 | mutex_unlock(&irq_domain_mutex); |
| 102 | |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 103 | pr_debug("Removed domain %s\n", domain->name); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 104 | |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 105 | of_node_put(domain->of_node); |
| 106 | kfree(domain); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 107 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 108 | EXPORT_SYMBOL_GPL(irq_domain_remove); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 109 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 110 | /** |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 111 | * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 112 | * @of_node: pointer to interrupt controller's device tree node. |
| 113 | * @size: total number of irqs in mapping |
Linus Walleij | 94a63da | 2013-06-06 12:10:23 +0100 | [diff] [blame] | 114 | * @first_irq: first number of irq block assigned to the domain, |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 115 | * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then |
| 116 | * pre-map all of the irqs in the domain to virqs starting at first_irq. |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 117 | * @ops: domain callbacks |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 118 | * @host_data: Controller private data pointer |
| 119 | * |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 120 | * Allocates an irq_domain, and optionally if first_irq is positive then also |
| 121 | * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq. |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 122 | * |
| 123 | * This is intended to implement the expected behaviour for most |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 124 | * interrupt controllers. If device tree is used, then first_irq will be 0 and |
| 125 | * irqs get mapped dynamically on the fly. However, if the controller requires |
| 126 | * static virq assignments (non-DT boot) then it will set that up correctly. |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 127 | */ |
| 128 | struct irq_domain *irq_domain_add_simple(struct device_node *of_node, |
| 129 | unsigned int size, |
| 130 | unsigned int first_irq, |
| 131 | const struct irq_domain_ops *ops, |
| 132 | void *host_data) |
| 133 | { |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 134 | struct irq_domain *domain; |
Linus Walleij | 2854d16 | 2012-09-27 14:59:39 +0200 | [diff] [blame] | 135 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 136 | domain = __irq_domain_add(of_node, size, size, 0, ops, host_data); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 137 | if (!domain) |
| 138 | return NULL; |
| 139 | |
| 140 | if (first_irq > 0) { |
Linus Walleij | 2854d16 | 2012-09-27 14:59:39 +0200 | [diff] [blame] | 141 | if (IS_ENABLED(CONFIG_SPARSE_IRQ)) { |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 142 | /* attempt to allocated irq_descs */ |
| 143 | int rc = irq_alloc_descs(first_irq, first_irq, size, |
| 144 | of_node_to_nid(of_node)); |
| 145 | if (rc < 0) |
Linus Walleij | d202b7b | 2012-11-27 01:20:32 +0100 | [diff] [blame] | 146 | pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n", |
| 147 | first_irq); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 148 | } |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 149 | irq_domain_associate_many(domain, first_irq, 0, size); |
Linus Walleij | 2854d16 | 2012-09-27 14:59:39 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 152 | return domain; |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 153 | } |
Arnd Bergmann | 346dbb7 | 2013-04-25 19:28:54 +0200 | [diff] [blame] | 154 | EXPORT_SYMBOL_GPL(irq_domain_add_simple); |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 155 | |
| 156 | /** |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 157 | * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain. |
| 158 | * @of_node: pointer to interrupt controller's device tree node. |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 159 | * @size: total number of irqs in legacy mapping |
| 160 | * @first_irq: first number of irq block assigned to the domain |
| 161 | * @first_hwirq: first hwirq number to use for the translation. Should normally |
| 162 | * be '0', but a positive integer can be used if the effective |
| 163 | * hwirqs numbering does not begin at zero. |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 164 | * @ops: map/unmap domain callbacks |
| 165 | * @host_data: Controller private data pointer |
| 166 | * |
| 167 | * Note: the map() callback will be called before this function returns |
| 168 | * for all legacy interrupts except 0 (which is always the invalid irq for |
| 169 | * a legacy controller). |
| 170 | */ |
| 171 | struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 172 | unsigned int size, |
| 173 | unsigned int first_irq, |
| 174 | irq_hw_number_t first_hwirq, |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 175 | const struct irq_domain_ops *ops, |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 176 | void *host_data) |
| 177 | { |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 178 | struct irq_domain *domain; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 179 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 180 | domain = __irq_domain_add(of_node, first_hwirq + size, |
| 181 | first_hwirq + size, 0, ops, host_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 182 | if (domain) |
| 183 | irq_domain_associate_many(domain, first_irq, first_hwirq, size); |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 184 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 185 | return domain; |
| 186 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 187 | EXPORT_SYMBOL_GPL(irq_domain_add_legacy); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 188 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 189 | /** |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 190 | * irq_find_host() - Locates a domain for a given device node |
| 191 | * @node: device-tree node of the interrupt controller |
| 192 | */ |
| 193 | struct irq_domain *irq_find_host(struct device_node *node) |
| 194 | { |
| 195 | struct irq_domain *h, *found = NULL; |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 196 | int rc; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 197 | |
| 198 | /* We might want to match the legacy controller last since |
| 199 | * it might potentially be set to match all interrupts in |
| 200 | * the absence of a device node. This isn't a problem so far |
| 201 | * yet though... |
| 202 | */ |
| 203 | mutex_lock(&irq_domain_mutex); |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 204 | list_for_each_entry(h, &irq_domain_list, link) { |
| 205 | if (h->ops->match) |
| 206 | rc = h->ops->match(h, node); |
| 207 | else |
| 208 | rc = (h->of_node != NULL) && (h->of_node == node); |
| 209 | |
| 210 | if (rc) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 211 | found = h; |
| 212 | break; |
| 213 | } |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 214 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 215 | mutex_unlock(&irq_domain_mutex); |
| 216 | return found; |
| 217 | } |
| 218 | EXPORT_SYMBOL_GPL(irq_find_host); |
| 219 | |
| 220 | /** |
| 221 | * irq_set_default_host() - Set a "default" irq domain |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 222 | * @domain: default domain pointer |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 223 | * |
| 224 | * For convenience, it's possible to set a "default" domain that will be used |
| 225 | * whenever NULL is passed to irq_create_mapping(). It makes life easier for |
| 226 | * platforms that want to manipulate a few hard coded interrupt numbers that |
| 227 | * aren't properly represented in the device-tree. |
| 228 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 229 | void irq_set_default_host(struct irq_domain *domain) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 230 | { |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 231 | pr_debug("Default domain set to @0x%p\n", domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 232 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 233 | irq_default_domain = domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 234 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 235 | EXPORT_SYMBOL_GPL(irq_set_default_host); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 236 | |
Jiang Liu | 43a7759 | 2014-06-09 16:20:05 +0800 | [diff] [blame] | 237 | void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq) |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 238 | { |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 239 | struct irq_data *irq_data = irq_get_irq_data(irq); |
| 240 | irq_hw_number_t hwirq; |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 241 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 242 | if (WARN(!irq_data || irq_data->domain != domain, |
| 243 | "virq%i doesn't exist; cannot disassociate\n", irq)) |
| 244 | return; |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 245 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 246 | hwirq = irq_data->hwirq; |
| 247 | irq_set_status_flags(irq, IRQ_NOREQUEST); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 248 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 249 | /* remove chip and handler */ |
| 250 | irq_set_chip_and_handler(irq, NULL, NULL); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 251 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 252 | /* Make sure it's completed */ |
| 253 | synchronize_irq(irq); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 254 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 255 | /* Tell the PIC about it */ |
| 256 | if (domain->ops->unmap) |
| 257 | domain->ops->unmap(domain, irq); |
| 258 | smp_mb(); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 259 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 260 | irq_data->domain = NULL; |
| 261 | irq_data->hwirq = 0; |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 262 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 263 | /* Clear reverse map for this hwirq */ |
| 264 | if (hwirq < domain->revmap_size) { |
| 265 | domain->linear_revmap[hwirq] = 0; |
| 266 | } else { |
| 267 | mutex_lock(&revmap_trees_mutex); |
| 268 | radix_tree_delete(&domain->revmap_tree, hwirq); |
| 269 | mutex_unlock(&revmap_trees_mutex); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 273 | int irq_domain_associate(struct irq_domain *domain, unsigned int virq, |
| 274 | irq_hw_number_t hwirq) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 275 | { |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 276 | struct irq_data *irq_data = irq_get_irq_data(virq); |
| 277 | int ret; |
| 278 | |
| 279 | if (WARN(hwirq >= domain->hwirq_max, |
| 280 | "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name)) |
| 281 | return -EINVAL; |
| 282 | if (WARN(!irq_data, "error: virq%i is not allocated", virq)) |
| 283 | return -EINVAL; |
| 284 | if (WARN(irq_data->domain, "error: virq%i is already associated", virq)) |
| 285 | return -EINVAL; |
| 286 | |
| 287 | mutex_lock(&irq_domain_mutex); |
| 288 | irq_data->hwirq = hwirq; |
| 289 | irq_data->domain = domain; |
| 290 | if (domain->ops->map) { |
| 291 | ret = domain->ops->map(domain, virq, hwirq); |
| 292 | if (ret != 0) { |
| 293 | /* |
| 294 | * If map() returns -EPERM, this interrupt is protected |
| 295 | * by the firmware or some other service and shall not |
| 296 | * be mapped. Don't bother telling the user about it. |
| 297 | */ |
| 298 | if (ret != -EPERM) { |
| 299 | pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n", |
| 300 | domain->name, hwirq, virq, ret); |
| 301 | } |
| 302 | irq_data->domain = NULL; |
| 303 | irq_data->hwirq = 0; |
| 304 | mutex_unlock(&irq_domain_mutex); |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | /* If not already assigned, give the domain the chip's name */ |
| 309 | if (!domain->name && irq_data->chip) |
| 310 | domain->name = irq_data->chip->name; |
| 311 | } |
| 312 | |
| 313 | if (hwirq < domain->revmap_size) { |
| 314 | domain->linear_revmap[hwirq] = virq; |
| 315 | } else { |
| 316 | mutex_lock(&revmap_trees_mutex); |
| 317 | radix_tree_insert(&domain->revmap_tree, hwirq, irq_data); |
| 318 | mutex_unlock(&revmap_trees_mutex); |
| 319 | } |
| 320 | mutex_unlock(&irq_domain_mutex); |
| 321 | |
| 322 | irq_clear_status_flags(virq, IRQ_NOREQUEST); |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | EXPORT_SYMBOL_GPL(irq_domain_associate); |
| 327 | |
| 328 | void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base, |
| 329 | irq_hw_number_t hwirq_base, int count) |
| 330 | { |
| 331 | int i; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 332 | |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 333 | pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__, |
| 334 | of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count); |
| 335 | |
| 336 | for (i = 0; i < count; i++) { |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 337 | irq_domain_associate(domain, irq_base + i, hwirq_base + i); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 338 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 339 | } |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 340 | EXPORT_SYMBOL_GPL(irq_domain_associate_many); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 341 | |
| 342 | /** |
| 343 | * irq_create_direct_mapping() - Allocate an irq for direct mapping |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 344 | * @domain: domain to allocate the irq for or NULL for default domain |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 345 | * |
| 346 | * This routine is used for irq controllers which can choose the hardware |
| 347 | * 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] | 348 | * the linux irq as the hardware interrupt number. It still uses the linear |
| 349 | * or radix tree to store the mapping, but the irq controller can optimize |
| 350 | * the revmap path by using the hwirq directly. |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 351 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 352 | unsigned int irq_create_direct_mapping(struct irq_domain *domain) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 353 | { |
| 354 | unsigned int virq; |
| 355 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 356 | if (domain == NULL) |
| 357 | domain = irq_default_domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 358 | |
Paul Mundt | 5ca4db6 | 2012-06-03 22:04:34 -0700 | [diff] [blame] | 359 | 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] | 360 | if (!virq) { |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 361 | pr_debug("create_direct virq allocation failed\n"); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 362 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 363 | } |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 364 | if (virq >= domain->revmap_direct_max_irq) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 365 | pr_err("ERROR: no free irqs available below %i maximum\n", |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 366 | domain->revmap_direct_max_irq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 367 | irq_free_desc(virq); |
| 368 | return 0; |
| 369 | } |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 370 | pr_debug("create_direct obtained virq %d\n", virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 371 | |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 372 | if (irq_domain_associate(domain, virq, virq)) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 373 | irq_free_desc(virq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 374 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | return virq; |
| 378 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 379 | EXPORT_SYMBOL_GPL(irq_create_direct_mapping); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 380 | |
| 381 | /** |
| 382 | * irq_create_mapping() - Map a hardware interrupt into linux irq space |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 383 | * @domain: domain owning this hardware interrupt or NULL for default domain |
| 384 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 385 | * |
| 386 | * Only one mapping per hardware interrupt is permitted. Returns a linux |
| 387 | * irq number. |
| 388 | * If the sense/trigger is to be specified, set_irq_type() should be called |
| 389 | * on the number returned from that call. |
| 390 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 391 | unsigned int irq_create_mapping(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 392 | irq_hw_number_t hwirq) |
| 393 | { |
David Daney | 5b7526e | 2012-04-05 16:52:13 -0700 | [diff] [blame] | 394 | int virq; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 395 | |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 396 | pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 397 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 398 | /* Look for default domain if nececssary */ |
| 399 | if (domain == NULL) |
| 400 | domain = irq_default_domain; |
| 401 | if (domain == NULL) { |
Kefeng Wang | 798f0fd | 2013-06-06 19:20:27 +0800 | [diff] [blame] | 402 | WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 403 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 404 | } |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 405 | pr_debug("-> using domain @%p\n", domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 406 | |
| 407 | /* Check if mapping already exists */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 408 | virq = irq_find_mapping(domain, hwirq); |
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("-> existing mapping on virq %d\n", virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 411 | return virq; |
| 412 | } |
| 413 | |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 414 | /* Allocate a virtual interrupt number */ |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 415 | virq = irq_domain_alloc_descs(-1, 1, hwirq, |
| 416 | of_node_to_nid(domain->of_node)); |
David Daney | 5b7526e | 2012-04-05 16:52:13 -0700 | [diff] [blame] | 417 | if (virq <= 0) { |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 418 | pr_debug("-> virq allocation failed\n"); |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 419 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 422 | if (irq_domain_associate(domain, virq, hwirq)) { |
Grant Likely | 7325570 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 423 | irq_free_desc(virq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 424 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 427 | 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] | 428 | hwirq, of_node_full_name(domain->of_node), virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 429 | |
| 430 | return virq; |
| 431 | } |
| 432 | EXPORT_SYMBOL_GPL(irq_create_mapping); |
| 433 | |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 434 | /** |
| 435 | * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs |
| 436 | * @domain: domain owning the interrupt range |
| 437 | * @irq_base: beginning of linux IRQ range |
| 438 | * @hwirq_base: beginning of hardware IRQ range |
| 439 | * @count: Number of interrupts to map |
| 440 | * |
| 441 | * This routine is used for allocating and mapping a range of hardware |
| 442 | * irqs to linux irqs where the linux irq numbers are at pre-defined |
| 443 | * locations. For use by controllers that already have static mappings |
| 444 | * to insert in to the domain. |
| 445 | * |
| 446 | * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time |
| 447 | * domain insertion. |
| 448 | * |
| 449 | * 0 is returned upon success, while any failure to establish a static |
| 450 | * mapping is treated as an error. |
| 451 | */ |
| 452 | int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base, |
| 453 | irq_hw_number_t hwirq_base, int count) |
| 454 | { |
| 455 | int ret; |
| 456 | |
| 457 | ret = irq_alloc_descs(irq_base, irq_base, count, |
| 458 | of_node_to_nid(domain->of_node)); |
| 459 | if (unlikely(ret < 0)) |
| 460 | return ret; |
| 461 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 462 | irq_domain_associate_many(domain, irq_base, hwirq_base, count); |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | EXPORT_SYMBOL_GPL(irq_create_strict_mappings); |
| 466 | |
Grant Likely | e6d30ab | 2013-09-15 16:55:53 +0100 | [diff] [blame] | 467 | unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 468 | { |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 469 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 470 | irq_hw_number_t hwirq; |
| 471 | unsigned int type = IRQ_TYPE_NONE; |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 472 | int virq; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 473 | |
Grant Likely | e6d30ab | 2013-09-15 16:55:53 +0100 | [diff] [blame] | 474 | domain = irq_data->np ? irq_find_host(irq_data->np) : irq_default_domain; |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 475 | if (!domain) { |
Kefeng Wang | 798f0fd | 2013-06-06 19:20:27 +0800 | [diff] [blame] | 476 | pr_warn("no irq domain found for %s !\n", |
Grant Likely | e6d30ab | 2013-09-15 16:55:53 +0100 | [diff] [blame] | 477 | of_node_full_name(irq_data->np)); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 478 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 481 | if (irq_domain_is_hierarchy(domain)) { |
| 482 | virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, irq_data); |
| 483 | return virq <= 0 ? 0 : virq; |
| 484 | } |
| 485 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 486 | /* If domain has no translation, then we assume interrupt line */ |
| 487 | if (domain->ops->xlate == NULL) |
Grant Likely | e6d30ab | 2013-09-15 16:55:53 +0100 | [diff] [blame] | 488 | hwirq = irq_data->args[0]; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 489 | else { |
Grant Likely | e6d30ab | 2013-09-15 16:55:53 +0100 | [diff] [blame] | 490 | if (domain->ops->xlate(domain, irq_data->np, irq_data->args, |
| 491 | irq_data->args_count, &hwirq, &type)) |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 492 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /* Create mapping */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 496 | virq = irq_create_mapping(domain, hwirq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 497 | if (!virq) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 498 | return virq; |
| 499 | |
| 500 | /* Set type if specified and different than the current one */ |
| 501 | if (type != IRQ_TYPE_NONE && |
Javier Martinez Canillas | fbab62c5 | 2013-06-14 18:40:49 +0200 | [diff] [blame] | 502 | type != irq_get_trigger_type(virq)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 503 | irq_set_irq_type(virq, type); |
| 504 | return virq; |
| 505 | } |
| 506 | EXPORT_SYMBOL_GPL(irq_create_of_mapping); |
| 507 | |
| 508 | /** |
| 509 | * irq_dispose_mapping() - Unmap an interrupt |
| 510 | * @virq: linux irq number of the interrupt to unmap |
| 511 | */ |
| 512 | void irq_dispose_mapping(unsigned int virq) |
| 513 | { |
| 514 | struct irq_data *irq_data = irq_get_irq_data(virq); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 515 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 516 | |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 517 | if (!virq || !irq_data) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 518 | return; |
| 519 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 520 | domain = irq_data->domain; |
| 521 | if (WARN_ON(domain == NULL)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 522 | return; |
| 523 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 524 | irq_domain_disassociate(domain, virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 525 | irq_free_desc(virq); |
| 526 | } |
| 527 | EXPORT_SYMBOL_GPL(irq_dispose_mapping); |
| 528 | |
| 529 | /** |
| 530 | * irq_find_mapping() - Find a linux irq from an hw irq number. |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 531 | * @domain: domain owning this hardware interrupt |
| 532 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 533 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 534 | unsigned int irq_find_mapping(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 535 | irq_hw_number_t hwirq) |
| 536 | { |
Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 537 | struct irq_data *data; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 538 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 539 | /* Look for default domain if nececssary */ |
| 540 | if (domain == NULL) |
| 541 | domain = irq_default_domain; |
| 542 | if (domain == NULL) |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 543 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 544 | |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 545 | if (hwirq < domain->revmap_direct_max_irq) { |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 546 | data = irq_domain_get_irq_data(domain, hwirq); |
| 547 | if (data && data->hwirq == hwirq) |
Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 548 | return hwirq; |
Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Grant Likely | d3dcb43 | 2013-06-10 12:19:17 +0100 | [diff] [blame] | 551 | /* Check if the hwirq is in the linear revmap. */ |
| 552 | if (hwirq < domain->revmap_size) |
| 553 | return domain->linear_revmap[hwirq]; |
| 554 | |
| 555 | rcu_read_lock(); |
| 556 | data = radix_tree_lookup(&domain->revmap_tree, hwirq); |
| 557 | rcu_read_unlock(); |
| 558 | return data ? data->irq : 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 559 | } |
| 560 | EXPORT_SYMBOL_GPL(irq_find_mapping); |
| 561 | |
Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 562 | #ifdef CONFIG_IRQ_DOMAIN_DEBUG |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 563 | static int virq_debug_show(struct seq_file *m, void *private) |
| 564 | { |
| 565 | unsigned long flags; |
| 566 | struct irq_desc *desc; |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 567 | struct irq_domain *domain; |
| 568 | struct radix_tree_iter iter; |
| 569 | void *data, **slot; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 570 | int i; |
| 571 | |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 572 | seq_printf(m, " %-16s %-6s %-10s %-10s %s\n", |
| 573 | "name", "mapped", "linear-max", "direct-max", "devtree-node"); |
| 574 | mutex_lock(&irq_domain_mutex); |
| 575 | list_for_each_entry(domain, &irq_domain_list, link) { |
| 576 | int count = 0; |
| 577 | radix_tree_for_each_slot(slot, &domain->revmap_tree, &iter, 0) |
| 578 | count++; |
| 579 | seq_printf(m, "%c%-16s %6u %10u %10u %s\n", |
| 580 | domain == irq_default_domain ? '*' : ' ', domain->name, |
| 581 | domain->revmap_size + count, domain->revmap_size, |
| 582 | domain->revmap_direct_max_irq, |
| 583 | domain->of_node ? of_node_full_name(domain->of_node) : ""); |
| 584 | } |
| 585 | mutex_unlock(&irq_domain_mutex); |
| 586 | |
| 587 | seq_printf(m, "%-5s %-7s %-15s %-*s %6s %-14s %s\n", "irq", "hwirq", |
Grant Likely | 5269a9a | 2012-04-12 14:42:15 -0600 | [diff] [blame] | 588 | "chip name", (int)(2 * sizeof(void *) + 2), "chip data", |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 589 | "active", "type", "domain"); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 590 | |
| 591 | for (i = 1; i < nr_irqs; i++) { |
| 592 | desc = irq_to_desc(i); |
| 593 | if (!desc) |
| 594 | continue; |
| 595 | |
| 596 | raw_spin_lock_irqsave(&desc->lock, flags); |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 597 | domain = desc->irq_data.domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 598 | |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 599 | if (domain) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 600 | struct irq_chip *chip; |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 601 | int hwirq = desc->irq_data.hwirq; |
| 602 | bool direct; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 603 | |
| 604 | seq_printf(m, "%5d ", i); |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 605 | seq_printf(m, "0x%05x ", hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 606 | |
| 607 | chip = irq_desc_get_chip(desc); |
Grant Likely | 0bb4afb | 2013-06-06 14:23:30 +0100 | [diff] [blame] | 608 | seq_printf(m, "%-15s ", (chip && chip->name) ? chip->name : "none"); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 609 | |
| 610 | data = irq_desc_get_chip_data(desc); |
Grant Likely | 15e06bf | 2012-04-11 00:26:25 -0600 | [diff] [blame] | 611 | seq_printf(m, data ? "0x%p " : " %p ", data); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 612 | |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 613 | seq_printf(m, " %c ", (desc->action && desc->action->handler) ? '*' : ' '); |
| 614 | direct = (i == hwirq) && (i < domain->revmap_direct_max_irq); |
| 615 | seq_printf(m, "%6s%-8s ", |
| 616 | (hwirq < domain->revmap_size) ? "LINEAR" : "RADIX", |
| 617 | direct ? "(DIRECT)" : ""); |
Grant Likely | 0bb4afb | 2013-06-06 14:23:30 +0100 | [diff] [blame] | 618 | seq_printf(m, "%s\n", desc->irq_data.domain->name); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 622 | } |
| 623 | |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | static int virq_debug_open(struct inode *inode, struct file *file) |
| 628 | { |
| 629 | return single_open(file, virq_debug_show, inode->i_private); |
| 630 | } |
| 631 | |
| 632 | static const struct file_operations virq_debug_fops = { |
| 633 | .open = virq_debug_open, |
| 634 | .read = seq_read, |
| 635 | .llseek = seq_lseek, |
| 636 | .release = single_release, |
| 637 | }; |
| 638 | |
| 639 | static int __init irq_debugfs_init(void) |
| 640 | { |
Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 641 | if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 642 | NULL, &virq_debug_fops) == NULL) |
| 643 | return -ENOMEM; |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | __initcall(irq_debugfs_init); |
Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 648 | #endif /* CONFIG_IRQ_DOMAIN_DEBUG */ |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 649 | |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 650 | /** |
| 651 | * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings |
| 652 | * |
| 653 | * Device Tree IRQ specifier translation function which works with one cell |
| 654 | * bindings where the cell value maps directly to the hwirq number. |
| 655 | */ |
| 656 | int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr, |
| 657 | const u32 *intspec, unsigned int intsize, |
| 658 | unsigned long *out_hwirq, unsigned int *out_type) |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 659 | { |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 660 | if (WARN_ON(intsize < 1)) |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 661 | return -EINVAL; |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 662 | *out_hwirq = intspec[0]; |
| 663 | *out_type = IRQ_TYPE_NONE; |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 664 | return 0; |
| 665 | } |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 666 | EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell); |
| 667 | |
| 668 | /** |
| 669 | * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings |
| 670 | * |
| 671 | * Device Tree IRQ specifier translation function which works with two cell |
| 672 | * bindings where the cell values map directly to the hwirq number |
| 673 | * and linux irq flags. |
| 674 | */ |
| 675 | int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr, |
| 676 | const u32 *intspec, unsigned int intsize, |
| 677 | irq_hw_number_t *out_hwirq, unsigned int *out_type) |
| 678 | { |
| 679 | if (WARN_ON(intsize < 2)) |
| 680 | return -EINVAL; |
| 681 | *out_hwirq = intspec[0]; |
| 682 | *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; |
| 683 | return 0; |
| 684 | } |
| 685 | EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell); |
| 686 | |
| 687 | /** |
| 688 | * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings |
| 689 | * |
| 690 | * Device Tree IRQ specifier translation function which works with either one |
| 691 | * or two cell bindings where the cell values map directly to the hwirq number |
| 692 | * and linux irq flags. |
| 693 | * |
| 694 | * Note: don't use this function unless your interrupt controller explicitly |
| 695 | * supports both one and two cell bindings. For the majority of controllers |
| 696 | * the _onecell() or _twocell() variants above should be used. |
| 697 | */ |
| 698 | int irq_domain_xlate_onetwocell(struct irq_domain *d, |
| 699 | struct device_node *ctrlr, |
| 700 | const u32 *intspec, unsigned int intsize, |
| 701 | unsigned long *out_hwirq, unsigned int *out_type) |
| 702 | { |
| 703 | if (WARN_ON(intsize < 1)) |
| 704 | return -EINVAL; |
| 705 | *out_hwirq = intspec[0]; |
| 706 | *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE; |
| 707 | return 0; |
| 708 | } |
| 709 | EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell); |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 710 | |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 711 | const struct irq_domain_ops irq_domain_simple_ops = { |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 712 | .xlate = irq_domain_xlate_onetwocell, |
Grant Likely | 7529495 | 2012-02-14 14:06:57 -0700 | [diff] [blame] | 713 | }; |
| 714 | EXPORT_SYMBOL_GPL(irq_domain_simple_ops); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame^] | 715 | |
| 716 | static int irq_domain_alloc_descs(int virq, unsigned int cnt, |
| 717 | irq_hw_number_t hwirq, int node) |
| 718 | { |
| 719 | unsigned int hint; |
| 720 | |
| 721 | if (virq >= 0) { |
| 722 | virq = irq_alloc_descs(virq, virq, cnt, node); |
| 723 | } else { |
| 724 | hint = hwirq % nr_irqs; |
| 725 | if (hint == 0) |
| 726 | hint++; |
| 727 | virq = irq_alloc_descs_from(hint, cnt, node); |
| 728 | if (virq <= 0 && hint > 1) |
| 729 | virq = irq_alloc_descs_from(1, cnt, node); |
| 730 | } |
| 731 | |
| 732 | return virq; |
| 733 | } |
| 734 | |
| 735 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 736 | static void irq_domain_insert_irq(int virq) |
| 737 | { |
| 738 | struct irq_data *data; |
| 739 | |
| 740 | for (data = irq_get_irq_data(virq); data; data = data->parent_data) { |
| 741 | struct irq_domain *domain = data->domain; |
| 742 | irq_hw_number_t hwirq = data->hwirq; |
| 743 | |
| 744 | if (hwirq < domain->revmap_size) { |
| 745 | domain->linear_revmap[hwirq] = virq; |
| 746 | } else { |
| 747 | mutex_lock(&revmap_trees_mutex); |
| 748 | radix_tree_insert(&domain->revmap_tree, hwirq, data); |
| 749 | mutex_unlock(&revmap_trees_mutex); |
| 750 | } |
| 751 | |
| 752 | /* If not already assigned, give the domain the chip's name */ |
| 753 | if (!domain->name && data->chip) |
| 754 | domain->name = data->chip->name; |
| 755 | } |
| 756 | |
| 757 | irq_clear_status_flags(virq, IRQ_NOREQUEST); |
| 758 | } |
| 759 | |
| 760 | static void irq_domain_remove_irq(int virq) |
| 761 | { |
| 762 | struct irq_data *data; |
| 763 | |
| 764 | irq_set_status_flags(virq, IRQ_NOREQUEST); |
| 765 | irq_set_chip_and_handler(virq, NULL, NULL); |
| 766 | synchronize_irq(virq); |
| 767 | smp_mb(); |
| 768 | |
| 769 | for (data = irq_get_irq_data(virq); data; data = data->parent_data) { |
| 770 | struct irq_domain *domain = data->domain; |
| 771 | irq_hw_number_t hwirq = data->hwirq; |
| 772 | |
| 773 | if (hwirq < domain->revmap_size) { |
| 774 | domain->linear_revmap[hwirq] = 0; |
| 775 | } else { |
| 776 | mutex_lock(&revmap_trees_mutex); |
| 777 | radix_tree_delete(&domain->revmap_tree, hwirq); |
| 778 | mutex_unlock(&revmap_trees_mutex); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain, |
| 784 | struct irq_data *child) |
| 785 | { |
| 786 | struct irq_data *irq_data; |
| 787 | |
| 788 | irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL, child->node); |
| 789 | if (irq_data) { |
| 790 | child->parent_data = irq_data; |
| 791 | irq_data->irq = child->irq; |
| 792 | irq_data->node = child->node; |
| 793 | irq_data->domain = domain; |
| 794 | } |
| 795 | |
| 796 | return irq_data; |
| 797 | } |
| 798 | |
| 799 | static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs) |
| 800 | { |
| 801 | struct irq_data *irq_data, *tmp; |
| 802 | int i; |
| 803 | |
| 804 | for (i = 0; i < nr_irqs; i++) { |
| 805 | irq_data = irq_get_irq_data(virq + i); |
| 806 | tmp = irq_data->parent_data; |
| 807 | irq_data->parent_data = NULL; |
| 808 | irq_data->domain = NULL; |
| 809 | |
| 810 | while (tmp) { |
| 811 | irq_data = tmp; |
| 812 | tmp = tmp->parent_data; |
| 813 | kfree(irq_data); |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | static int irq_domain_alloc_irq_data(struct irq_domain *domain, |
| 819 | unsigned int virq, unsigned int nr_irqs) |
| 820 | { |
| 821 | struct irq_data *irq_data; |
| 822 | struct irq_domain *parent; |
| 823 | int i; |
| 824 | |
| 825 | /* The outermost irq_data is embedded in struct irq_desc */ |
| 826 | for (i = 0; i < nr_irqs; i++) { |
| 827 | irq_data = irq_get_irq_data(virq + i); |
| 828 | irq_data->domain = domain; |
| 829 | |
| 830 | for (parent = domain->parent; parent; parent = parent->parent) { |
| 831 | irq_data = irq_domain_insert_irq_data(parent, irq_data); |
| 832 | if (!irq_data) { |
| 833 | irq_domain_free_irq_data(virq, i + 1); |
| 834 | return -ENOMEM; |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain |
| 844 | * @domain: domain to match |
| 845 | * @virq: IRQ number to get irq_data |
| 846 | */ |
| 847 | struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, |
| 848 | unsigned int virq) |
| 849 | { |
| 850 | struct irq_data *irq_data; |
| 851 | |
| 852 | for (irq_data = irq_get_irq_data(virq); irq_data; |
| 853 | irq_data = irq_data->parent_data) |
| 854 | if (irq_data->domain == domain) |
| 855 | return irq_data; |
| 856 | |
| 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | /** |
| 861 | * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain |
| 862 | * @domain: Interrupt domain to match |
| 863 | * @virq: IRQ number |
| 864 | * @hwirq: The hwirq number |
| 865 | * @chip: The associated interrupt chip |
| 866 | * @chip_data: The associated chip data |
| 867 | */ |
| 868 | int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq, |
| 869 | irq_hw_number_t hwirq, struct irq_chip *chip, |
| 870 | void *chip_data) |
| 871 | { |
| 872 | struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq); |
| 873 | |
| 874 | if (!irq_data) |
| 875 | return -ENOENT; |
| 876 | |
| 877 | irq_data->hwirq = hwirq; |
| 878 | irq_data->chip = chip ? chip : &no_irq_chip; |
| 879 | irq_data->chip_data = chip_data; |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data |
| 886 | * @irq_data: The pointer to irq_data |
| 887 | */ |
| 888 | void irq_domain_reset_irq_data(struct irq_data *irq_data) |
| 889 | { |
| 890 | irq_data->hwirq = 0; |
| 891 | irq_data->chip = &no_irq_chip; |
| 892 | irq_data->chip_data = NULL; |
| 893 | } |
| 894 | |
| 895 | /** |
| 896 | * irq_domain_free_irqs_common - Clear irq_data and free the parent |
| 897 | * @domain: Interrupt domain to match |
| 898 | * @virq: IRQ number to start with |
| 899 | * @nr_irqs: The number of irqs to free |
| 900 | */ |
| 901 | void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq, |
| 902 | unsigned int nr_irqs) |
| 903 | { |
| 904 | struct irq_data *irq_data; |
| 905 | int i; |
| 906 | |
| 907 | for (i = 0; i < nr_irqs; i++) { |
| 908 | irq_data = irq_domain_get_irq_data(domain, virq + i); |
| 909 | if (irq_data) |
| 910 | irq_domain_reset_irq_data(irq_data); |
| 911 | } |
| 912 | irq_domain_free_irqs_parent(domain, virq, nr_irqs); |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent |
| 917 | * @domain: Interrupt domain to match |
| 918 | * @virq: IRQ number to start with |
| 919 | * @nr_irqs: The number of irqs to free |
| 920 | */ |
| 921 | void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq, |
| 922 | unsigned int nr_irqs) |
| 923 | { |
| 924 | int i; |
| 925 | |
| 926 | for (i = 0; i < nr_irqs; i++) { |
| 927 | irq_set_handler_data(virq + i, NULL); |
| 928 | irq_set_handler(virq + i, NULL); |
| 929 | } |
| 930 | irq_domain_free_irqs_common(domain, virq, nr_irqs); |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * __irq_domain_alloc_irqs - Allocate IRQs from domain |
| 935 | * @domain: domain to allocate from |
| 936 | * @irq_base: allocate specified IRQ nubmer if irq_base >= 0 |
| 937 | * @nr_irqs: number of IRQs to allocate |
| 938 | * @node: NUMA node id for memory allocation |
| 939 | * @arg: domain specific argument |
| 940 | * @realloc: IRQ descriptors have already been allocated if true |
| 941 | * |
| 942 | * Allocate IRQ numbers and initialized all data structures to support |
| 943 | * hierarchy IRQ domains. |
| 944 | * Parameter @realloc is mainly to support legacy IRQs. |
| 945 | * Returns error code or allocated IRQ number |
| 946 | * |
| 947 | * The whole process to setup an IRQ has been split into two steps. |
| 948 | * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ |
| 949 | * descriptor and required hardware resources. The second step, |
| 950 | * irq_domain_activate_irq(), is to program hardwares with preallocated |
| 951 | * resources. In this way, it's easier to rollback when failing to |
| 952 | * allocate resources. |
| 953 | */ |
| 954 | int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, |
| 955 | unsigned int nr_irqs, int node, void *arg, |
| 956 | bool realloc) |
| 957 | { |
| 958 | int i, ret, virq; |
| 959 | |
| 960 | if (domain == NULL) { |
| 961 | domain = irq_default_domain; |
| 962 | if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n")) |
| 963 | return -EINVAL; |
| 964 | } |
| 965 | |
| 966 | if (!domain->ops->alloc) { |
| 967 | pr_debug("domain->ops->alloc() is NULL\n"); |
| 968 | return -ENOSYS; |
| 969 | } |
| 970 | |
| 971 | if (realloc && irq_base >= 0) { |
| 972 | virq = irq_base; |
| 973 | } else { |
| 974 | virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node); |
| 975 | if (virq < 0) { |
| 976 | pr_debug("cannot allocate IRQ(base %d, count %d)\n", |
| 977 | irq_base, nr_irqs); |
| 978 | return virq; |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) { |
| 983 | pr_debug("cannot allocate memory for IRQ%d\n", virq); |
| 984 | ret = -ENOMEM; |
| 985 | goto out_free_desc; |
| 986 | } |
| 987 | |
| 988 | mutex_lock(&irq_domain_mutex); |
| 989 | ret = domain->ops->alloc(domain, virq, nr_irqs, arg); |
| 990 | if (ret < 0) { |
| 991 | mutex_unlock(&irq_domain_mutex); |
| 992 | goto out_free_irq_data; |
| 993 | } |
| 994 | for (i = 0; i < nr_irqs; i++) |
| 995 | irq_domain_insert_irq(virq + i); |
| 996 | mutex_unlock(&irq_domain_mutex); |
| 997 | |
| 998 | return virq; |
| 999 | |
| 1000 | out_free_irq_data: |
| 1001 | irq_domain_free_irq_data(virq, nr_irqs); |
| 1002 | out_free_desc: |
| 1003 | irq_free_descs(virq, nr_irqs); |
| 1004 | return ret; |
| 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * irq_domain_free_irqs - Free IRQ number and associated data structures |
| 1009 | * @virq: base IRQ number |
| 1010 | * @nr_irqs: number of IRQs to free |
| 1011 | */ |
| 1012 | void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs) |
| 1013 | { |
| 1014 | struct irq_data *data = irq_get_irq_data(virq); |
| 1015 | int i; |
| 1016 | |
| 1017 | if (WARN(!data || !data->domain || !data->domain->ops->free, |
| 1018 | "NULL pointer, cannot free irq\n")) |
| 1019 | return; |
| 1020 | |
| 1021 | mutex_lock(&irq_domain_mutex); |
| 1022 | for (i = 0; i < nr_irqs; i++) |
| 1023 | irq_domain_remove_irq(virq + i); |
| 1024 | data->domain->ops->free(data->domain, virq, nr_irqs); |
| 1025 | mutex_unlock(&irq_domain_mutex); |
| 1026 | |
| 1027 | irq_domain_free_irq_data(virq, nr_irqs); |
| 1028 | irq_free_descs(virq, nr_irqs); |
| 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * irq_domain_activate_irq - Call domain_ops->activate recursively to activate |
| 1033 | * interrupt |
| 1034 | * @irq_data: outermost irq_data associated with interrupt |
| 1035 | * |
| 1036 | * This is the second step to call domain_ops->activate to program interrupt |
| 1037 | * controllers, so the interrupt could actually get delivered. |
| 1038 | */ |
| 1039 | void irq_domain_activate_irq(struct irq_data *irq_data) |
| 1040 | { |
| 1041 | if (irq_data && irq_data->domain) { |
| 1042 | struct irq_domain *domain = irq_data->domain; |
| 1043 | |
| 1044 | if (irq_data->parent_data) |
| 1045 | irq_domain_activate_irq(irq_data->parent_data); |
| 1046 | if (domain->ops->activate) |
| 1047 | domain->ops->activate(domain, irq_data); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to |
| 1053 | * deactivate interrupt |
| 1054 | * @irq_data: outermost irq_data associated with interrupt |
| 1055 | * |
| 1056 | * It calls domain_ops->deactivate to program interrupt controllers to disable |
| 1057 | * interrupt delivery. |
| 1058 | */ |
| 1059 | void irq_domain_deactivate_irq(struct irq_data *irq_data) |
| 1060 | { |
| 1061 | if (irq_data && irq_data->domain) { |
| 1062 | struct irq_domain *domain = irq_data->domain; |
| 1063 | |
| 1064 | if (domain->ops->deactivate) |
| 1065 | domain->ops->deactivate(domain, irq_data); |
| 1066 | if (irq_data->parent_data) |
| 1067 | irq_domain_deactivate_irq(irq_data->parent_data); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | static void irq_domain_check_hierarchy(struct irq_domain *domain) |
| 1072 | { |
| 1073 | /* Hierarchy irq_domains must implement callback alloc() */ |
| 1074 | if (domain->ops->alloc) |
| 1075 | domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY; |
| 1076 | } |
| 1077 | #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ |
| 1078 | /** |
| 1079 | * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain |
| 1080 | * @domain: domain to match |
| 1081 | * @virq: IRQ number to get irq_data |
| 1082 | */ |
| 1083 | struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, |
| 1084 | unsigned int virq) |
| 1085 | { |
| 1086 | struct irq_data *irq_data = irq_get_irq_data(virq); |
| 1087 | |
| 1088 | return (irq_data && irq_data->domain == domain) ? irq_data : NULL; |
| 1089 | } |
| 1090 | |
| 1091 | static void irq_domain_check_hierarchy(struct irq_domain *domain) |
| 1092 | { |
| 1093 | } |
| 1094 | #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ |