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 void irq_domain_check_hierarchy(struct irq_domain *domain); |
| 27 | |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 28 | struct irqchip_fwid { |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 29 | struct fwnode_handle fwnode; |
| 30 | unsigned int type; |
| 31 | char *name; |
| 32 | void *data; |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | /** |
| 36 | * irq_domain_alloc_fwnode - Allocate a fwnode_handle suitable for |
| 37 | * identifying an irq domain |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 38 | * @type: Type of irqchip_fwnode. See linux/irqdomain.h |
| 39 | * @name: Optional user provided domain name |
| 40 | * @id: Optional user provided id if name != NULL |
| 41 | * @data: Optional user-provided data |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 42 | * |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 43 | * Allocate a struct irqchip_fwid, and return a poiner to the embedded |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 44 | * fwnode_handle (or NULL on failure). |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 45 | * |
| 46 | * Note: The types IRQCHIP_FWNODE_NAMED and IRQCHIP_FWNODE_NAMED_ID are |
| 47 | * solely to transport name information to irqdomain creation code. The |
| 48 | * node is not stored. For other types the pointer is kept in the irq |
| 49 | * domain struct. |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 50 | */ |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 51 | struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, |
| 52 | const char *name, void *data) |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 53 | { |
| 54 | struct irqchip_fwid *fwid; |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 55 | char *n; |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 56 | |
| 57 | fwid = kzalloc(sizeof(*fwid), GFP_KERNEL); |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 58 | |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 59 | switch (type) { |
| 60 | case IRQCHIP_FWNODE_NAMED: |
| 61 | n = kasprintf(GFP_KERNEL, "%s", name); |
| 62 | break; |
| 63 | case IRQCHIP_FWNODE_NAMED_ID: |
| 64 | n = kasprintf(GFP_KERNEL, "%s-%d", name, id); |
| 65 | break; |
| 66 | default: |
| 67 | n = kasprintf(GFP_KERNEL, "irqchip@%p", data); |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | if (!fwid || !n) { |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 72 | kfree(fwid); |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 73 | kfree(n); |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 74 | return NULL; |
| 75 | } |
| 76 | |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 77 | fwid->type = type; |
| 78 | fwid->name = n; |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 79 | fwid->data = data; |
| 80 | fwid->fwnode.type = FWNODE_IRQCHIP; |
| 81 | return &fwid->fwnode; |
| 82 | } |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(__irq_domain_alloc_fwnode); |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * irq_domain_free_fwnode - Free a non-OF-backed fwnode_handle |
| 87 | * |
| 88 | * Free a fwnode_handle allocated with irq_domain_alloc_fwnode. |
| 89 | */ |
| 90 | void irq_domain_free_fwnode(struct fwnode_handle *fwnode) |
| 91 | { |
| 92 | struct irqchip_fwid *fwid; |
| 93 | |
Suravee Suthikulpanit | 75aba7b | 2015-12-10 08:55:28 -0800 | [diff] [blame] | 94 | if (WARN_ON(!is_fwnode_irqchip(fwnode))) |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 95 | return; |
| 96 | |
| 97 | fwid = container_of(fwnode, struct irqchip_fwid, fwnode); |
| 98 | kfree(fwid->name); |
| 99 | kfree(fwid); |
| 100 | } |
Jake Oshins | a4289dc | 2015-12-10 17:52:59 +0000 | [diff] [blame] | 101 | EXPORT_SYMBOL_GPL(irq_domain_free_fwnode); |
Marc Zyngier | b145dcc | 2015-10-13 12:51:36 +0100 | [diff] [blame] | 102 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 103 | /** |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 104 | * __irq_domain_add() - Allocate a new irq_domain data structure |
Punit Agrawal | 545d5d6 | 2016-05-31 13:56:48 +0100 | [diff] [blame] | 105 | * @fwnode: firmware node for the interrupt controller |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 106 | * @size: Size of linear map; 0 for radix mapping only |
Jiang Liu | a257954 | 2014-05-27 16:07:37 +0800 | [diff] [blame] | 107 | * @hwirq_max: Maximum number of interrupts supported by controller |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 108 | * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no |
| 109 | * direct mapping |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 110 | * @ops: domain callbacks |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 111 | * @host_data: Controller private data pointer |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 112 | * |
Jiang Liu | a257954 | 2014-05-27 16:07:37 +0800 | [diff] [blame] | 113 | * Allocates and initialize and irq_domain structure. |
| 114 | * Returns pointer to IRQ domain, or NULL on failure. |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 115 | */ |
Marc Zyngier | 1bf4ddc | 2015-10-13 12:51:35 +0100 | [diff] [blame] | 116 | struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, int size, |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 117 | irq_hw_number_t hwirq_max, int direct_max, |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 118 | const struct irq_domain_ops *ops, |
| 119 | void *host_data) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 120 | { |
Punit Agrawal | 545d5d6 | 2016-05-31 13:56:48 +0100 | [diff] [blame] | 121 | struct device_node *of_node = to_of_node(fwnode); |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 122 | struct irqchip_fwid *fwid; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 123 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 124 | |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 125 | static atomic_t unknown_domains; |
| 126 | |
Grant Likely | cef5075 | 2012-07-11 17:24:31 +0100 | [diff] [blame] | 127 | domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size), |
| 128 | GFP_KERNEL, of_node_to_nid(of_node)); |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 129 | if (WARN_ON(!domain)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 130 | return NULL; |
| 131 | |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 132 | if (fwnode && is_fwnode_irqchip(fwnode)) { |
| 133 | fwid = container_of(fwnode, struct irqchip_fwid, fwnode); |
| 134 | |
| 135 | switch (fwid->type) { |
| 136 | case IRQCHIP_FWNODE_NAMED: |
| 137 | case IRQCHIP_FWNODE_NAMED_ID: |
| 138 | domain->name = kstrdup(fwid->name, GFP_KERNEL); |
| 139 | if (!domain->name) { |
| 140 | kfree(domain); |
| 141 | return NULL; |
| 142 | } |
| 143 | domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; |
| 144 | break; |
| 145 | default: |
| 146 | domain->fwnode = fwnode; |
| 147 | domain->name = fwid->name; |
| 148 | break; |
| 149 | } |
| 150 | } else if (of_node) { |
| 151 | char *name; |
| 152 | |
| 153 | /* |
| 154 | * DT paths contain '/', which debugfs is legitimately |
| 155 | * unhappy about. Replace them with ':', which does |
| 156 | * the trick and is not as offensive as '\'... |
| 157 | */ |
| 158 | name = kstrdup(of_node_full_name(of_node), GFP_KERNEL); |
| 159 | if (!name) { |
| 160 | kfree(domain); |
| 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | strreplace(name, '/', ':'); |
| 165 | |
| 166 | domain->name = name; |
| 167 | domain->fwnode = fwnode; |
| 168 | domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; |
| 169 | } |
| 170 | |
| 171 | if (!domain->name) { |
| 172 | if (fwnode) { |
| 173 | pr_err("Invalid fwnode type (%d) for irqdomain\n", |
| 174 | fwnode->type); |
| 175 | } |
| 176 | domain->name = kasprintf(GFP_KERNEL, "unknown-%d", |
| 177 | atomic_inc_return(&unknown_domains)); |
| 178 | if (!domain->name) { |
| 179 | kfree(domain); |
| 180 | return NULL; |
| 181 | } |
| 182 | domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; |
| 183 | } |
| 184 | |
Marc Zyngier | f110711 | 2015-10-13 12:51:30 +0100 | [diff] [blame] | 185 | of_node_get(of_node); |
Marc Zyngier | f110711 | 2015-10-13 12:51:30 +0100 | [diff] [blame] | 186 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 187 | /* Fill structure */ |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 188 | INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 189 | domain->ops = ops; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 190 | domain->host_data = host_data; |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 191 | domain->hwirq_max = hwirq_max; |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 192 | domain->revmap_size = size; |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 193 | domain->revmap_direct_max_irq = direct_max; |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 194 | irq_domain_check_hierarchy(domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 195 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 196 | mutex_lock(&irq_domain_mutex); |
| 197 | list_add(&domain->link, &irq_domain_list); |
| 198 | mutex_unlock(&irq_domain_mutex); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 199 | |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 200 | pr_debug("Added domain %s\n", domain->name); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 201 | return domain; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 202 | } |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 203 | EXPORT_SYMBOL_GPL(__irq_domain_add); |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 204 | |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 205 | /** |
| 206 | * irq_domain_remove() - Remove an irq domain. |
| 207 | * @domain: domain to remove |
| 208 | * |
| 209 | * This routine is used to remove an irq domain. The caller must ensure |
| 210 | * that all mappings within the domain have been disposed of prior to |
| 211 | * use, depending on the revmap type. |
| 212 | */ |
| 213 | void irq_domain_remove(struct irq_domain *domain) |
| 214 | { |
| 215 | mutex_lock(&irq_domain_mutex); |
| 216 | |
Matthew Wilcox | e9256ef | 2016-05-20 17:01:33 -0700 | [diff] [blame] | 217 | WARN_ON(!radix_tree_empty(&domain->revmap_tree)); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 218 | |
| 219 | list_del(&domain->link); |
| 220 | |
| 221 | /* |
| 222 | * If the going away domain is the default one, reset it. |
| 223 | */ |
| 224 | if (unlikely(irq_default_domain == domain)) |
| 225 | irq_set_default_host(NULL); |
| 226 | |
| 227 | mutex_unlock(&irq_domain_mutex); |
| 228 | |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 229 | pr_debug("Removed domain %s\n", domain->name); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 230 | |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 231 | of_node_put(irq_domain_get_of_node(domain)); |
Thomas Gleixner | d59f661 | 2017-06-20 01:37:05 +0200 | [diff] [blame] | 232 | if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED) |
| 233 | kfree(domain->name); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 234 | kfree(domain); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 235 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 236 | EXPORT_SYMBOL_GPL(irq_domain_remove); |
Paul Mundt | 58ee99a | 2012-05-19 15:11:41 +0900 | [diff] [blame] | 237 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 238 | /** |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 239 | * 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] | 240 | * @of_node: pointer to interrupt controller's device tree node. |
| 241 | * @size: total number of irqs in mapping |
Linus Walleij | 94a63da | 2013-06-06 12:10:23 +0100 | [diff] [blame] | 242 | * @first_irq: first number of irq block assigned to the domain, |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 243 | * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then |
| 244 | * 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] | 245 | * @ops: domain callbacks |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 246 | * @host_data: Controller private data pointer |
| 247 | * |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 248 | * Allocates an irq_domain, and optionally if first_irq is positive then also |
| 249 | * 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] | 250 | * |
| 251 | * This is intended to implement the expected behaviour for most |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 252 | * interrupt controllers. If device tree is used, then first_irq will be 0 and |
| 253 | * irqs get mapped dynamically on the fly. However, if the controller requires |
| 254 | * 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] | 255 | */ |
| 256 | struct irq_domain *irq_domain_add_simple(struct device_node *of_node, |
| 257 | unsigned int size, |
| 258 | unsigned int first_irq, |
| 259 | const struct irq_domain_ops *ops, |
| 260 | void *host_data) |
| 261 | { |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 262 | struct irq_domain *domain; |
Linus Walleij | 2854d16 | 2012-09-27 14:59:39 +0200 | [diff] [blame] | 263 | |
Marc Zyngier | 1bf4ddc | 2015-10-13 12:51:35 +0100 | [diff] [blame] | 264 | domain = __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 265 | if (!domain) |
| 266 | return NULL; |
| 267 | |
| 268 | if (first_irq > 0) { |
Linus Walleij | 2854d16 | 2012-09-27 14:59:39 +0200 | [diff] [blame] | 269 | if (IS_ENABLED(CONFIG_SPARSE_IRQ)) { |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 270 | /* attempt to allocated irq_descs */ |
| 271 | int rc = irq_alloc_descs(first_irq, first_irq, size, |
| 272 | of_node_to_nid(of_node)); |
| 273 | if (rc < 0) |
Linus Walleij | d202b7b | 2012-11-27 01:20:32 +0100 | [diff] [blame] | 274 | pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n", |
| 275 | first_irq); |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 276 | } |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 277 | irq_domain_associate_many(domain, first_irq, 0, size); |
Linus Walleij | 2854d16 | 2012-09-27 14:59:39 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Grant Likely | fa40f37 | 2013-06-08 12:57:40 +0100 | [diff] [blame] | 280 | return domain; |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 281 | } |
Arnd Bergmann | 346dbb7 | 2013-04-25 19:28:54 +0200 | [diff] [blame] | 282 | EXPORT_SYMBOL_GPL(irq_domain_add_simple); |
Mark Brown | 781d0f4 | 2012-07-05 12:19:19 +0100 | [diff] [blame] | 283 | |
| 284 | /** |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 285 | * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain. |
| 286 | * @of_node: pointer to interrupt controller's device tree node. |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 287 | * @size: total number of irqs in legacy mapping |
| 288 | * @first_irq: first number of irq block assigned to the domain |
| 289 | * @first_hwirq: first hwirq number to use for the translation. Should normally |
| 290 | * be '0', but a positive integer can be used if the effective |
| 291 | * hwirqs numbering does not begin at zero. |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 292 | * @ops: map/unmap domain callbacks |
| 293 | * @host_data: Controller private data pointer |
| 294 | * |
| 295 | * Note: the map() callback will be called before this function returns |
| 296 | * for all legacy interrupts except 0 (which is always the invalid irq for |
| 297 | * a legacy controller). |
| 298 | */ |
| 299 | struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 300 | unsigned int size, |
| 301 | unsigned int first_irq, |
| 302 | irq_hw_number_t first_hwirq, |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 303 | const struct irq_domain_ops *ops, |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 304 | void *host_data) |
| 305 | { |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 306 | struct irq_domain *domain; |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 307 | |
Marc Zyngier | 1bf4ddc | 2015-10-13 12:51:35 +0100 | [diff] [blame] | 308 | domain = __irq_domain_add(of_node_to_fwnode(of_node), first_hwirq + size, |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 309 | first_hwirq + size, 0, ops, host_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 310 | if (domain) |
| 311 | irq_domain_associate_many(domain, first_irq, first_hwirq, size); |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 312 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 313 | return domain; |
| 314 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 315 | EXPORT_SYMBOL_GPL(irq_domain_add_legacy); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 316 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 317 | /** |
Marc Zyngier | 651e8b5 | 2016-04-11 09:57:51 +0100 | [diff] [blame] | 318 | * irq_find_matching_fwspec() - Locates a domain for a given fwspec |
| 319 | * @fwspec: FW specifier for an interrupt |
Marc Zyngier | ad3aedf | 2015-07-28 14:46:08 +0100 | [diff] [blame] | 320 | * @bus_token: domain-specific data |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 321 | */ |
Marc Zyngier | 651e8b5 | 2016-04-11 09:57:51 +0100 | [diff] [blame] | 322 | struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec, |
Marc Zyngier | 130b8c6 | 2015-10-13 12:51:31 +0100 | [diff] [blame] | 323 | enum irq_domain_bus_token bus_token) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 324 | { |
| 325 | struct irq_domain *h, *found = NULL; |
Marc Zyngier | 651e8b5 | 2016-04-11 09:57:51 +0100 | [diff] [blame] | 326 | struct fwnode_handle *fwnode = fwspec->fwnode; |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 327 | int rc; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 328 | |
| 329 | /* We might want to match the legacy controller last since |
| 330 | * it might potentially be set to match all interrupts in |
| 331 | * the absence of a device node. This isn't a problem so far |
| 332 | * yet though... |
Marc Zyngier | ad3aedf | 2015-07-28 14:46:08 +0100 | [diff] [blame] | 333 | * |
| 334 | * bus_token == DOMAIN_BUS_ANY matches any domain, any other |
| 335 | * values must generate an exact match for the domain to be |
| 336 | * selected. |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 337 | */ |
| 338 | mutex_lock(&irq_domain_mutex); |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 339 | list_for_each_entry(h, &irq_domain_list, link) { |
Marc Zyngier | 651e8b5 | 2016-04-11 09:57:51 +0100 | [diff] [blame] | 340 | if (h->ops->select && fwspec->param_count) |
| 341 | rc = h->ops->select(h, fwspec, bus_token); |
| 342 | else if (h->ops->match) |
Marc Zyngier | 130b8c6 | 2015-10-13 12:51:31 +0100 | [diff] [blame] | 343 | rc = h->ops->match(h, to_of_node(fwnode), bus_token); |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 344 | else |
Marc Zyngier | 130b8c6 | 2015-10-13 12:51:31 +0100 | [diff] [blame] | 345 | rc = ((fwnode != NULL) && (h->fwnode == fwnode) && |
Marc Zyngier | ad3aedf | 2015-07-28 14:46:08 +0100 | [diff] [blame] | 346 | ((bus_token == DOMAIN_BUS_ANY) || |
| 347 | (h->bus_token == bus_token))); |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 348 | |
| 349 | if (rc) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 350 | found = h; |
| 351 | break; |
| 352 | } |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 353 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 354 | mutex_unlock(&irq_domain_mutex); |
| 355 | return found; |
| 356 | } |
Marc Zyngier | 651e8b5 | 2016-04-11 09:57:51 +0100 | [diff] [blame] | 357 | EXPORT_SYMBOL_GPL(irq_find_matching_fwspec); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 358 | |
| 359 | /** |
Eric Auger | c7b41f0 | 2017-01-19 20:57:59 +0000 | [diff] [blame] | 360 | * irq_domain_check_msi_remap - Check whether all MSI irq domains implement |
| 361 | * IRQ remapping |
| 362 | * |
| 363 | * Return: false if any MSI irq domain does not support IRQ remapping, |
| 364 | * true otherwise (including if there is no MSI irq domain) |
| 365 | */ |
| 366 | bool irq_domain_check_msi_remap(void) |
| 367 | { |
| 368 | struct irq_domain *h; |
| 369 | bool ret = true; |
| 370 | |
| 371 | mutex_lock(&irq_domain_mutex); |
| 372 | list_for_each_entry(h, &irq_domain_list, link) { |
| 373 | if (irq_domain_is_msi(h) && |
| 374 | !irq_domain_hierarchical_is_msi_remap(h)) { |
| 375 | ret = false; |
| 376 | break; |
| 377 | } |
| 378 | } |
| 379 | mutex_unlock(&irq_domain_mutex); |
| 380 | return ret; |
| 381 | } |
| 382 | EXPORT_SYMBOL_GPL(irq_domain_check_msi_remap); |
| 383 | |
| 384 | /** |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 385 | * irq_set_default_host() - Set a "default" irq domain |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 386 | * @domain: default domain pointer |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 387 | * |
| 388 | * For convenience, it's possible to set a "default" domain that will be used |
| 389 | * whenever NULL is passed to irq_create_mapping(). It makes life easier for |
| 390 | * platforms that want to manipulate a few hard coded interrupt numbers that |
| 391 | * aren't properly represented in the device-tree. |
| 392 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 393 | void irq_set_default_host(struct irq_domain *domain) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 394 | { |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 395 | pr_debug("Default domain set to @0x%p\n", domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 396 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 397 | irq_default_domain = domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 398 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 399 | EXPORT_SYMBOL_GPL(irq_set_default_host); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 400 | |
Jiang Liu | 43a7759 | 2014-06-09 16:20:05 +0800 | [diff] [blame] | 401 | void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq) |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 402 | { |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 403 | struct irq_data *irq_data = irq_get_irq_data(irq); |
| 404 | irq_hw_number_t hwirq; |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 405 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 406 | if (WARN(!irq_data || irq_data->domain != domain, |
| 407 | "virq%i doesn't exist; cannot disassociate\n", irq)) |
| 408 | return; |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 409 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 410 | hwirq = irq_data->hwirq; |
| 411 | irq_set_status_flags(irq, IRQ_NOREQUEST); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 412 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 413 | /* remove chip and handler */ |
| 414 | irq_set_chip_and_handler(irq, NULL, NULL); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 415 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 416 | /* Make sure it's completed */ |
| 417 | synchronize_irq(irq); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 418 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 419 | /* Tell the PIC about it */ |
| 420 | if (domain->ops->unmap) |
| 421 | domain->ops->unmap(domain, irq); |
| 422 | smp_mb(); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 423 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 424 | irq_data->domain = NULL; |
| 425 | irq_data->hwirq = 0; |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 426 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 427 | /* Clear reverse map for this hwirq */ |
| 428 | if (hwirq < domain->revmap_size) { |
| 429 | domain->linear_revmap[hwirq] = 0; |
| 430 | } else { |
| 431 | mutex_lock(&revmap_trees_mutex); |
| 432 | radix_tree_delete(&domain->revmap_tree, hwirq); |
| 433 | mutex_unlock(&revmap_trees_mutex); |
Grant Likely | 913af20 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 437 | int irq_domain_associate(struct irq_domain *domain, unsigned int virq, |
| 438 | irq_hw_number_t hwirq) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 439 | { |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 440 | struct irq_data *irq_data = irq_get_irq_data(virq); |
| 441 | int ret; |
| 442 | |
| 443 | if (WARN(hwirq >= domain->hwirq_max, |
| 444 | "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name)) |
| 445 | return -EINVAL; |
| 446 | if (WARN(!irq_data, "error: virq%i is not allocated", virq)) |
| 447 | return -EINVAL; |
| 448 | if (WARN(irq_data->domain, "error: virq%i is already associated", virq)) |
| 449 | return -EINVAL; |
| 450 | |
| 451 | mutex_lock(&irq_domain_mutex); |
| 452 | irq_data->hwirq = hwirq; |
| 453 | irq_data->domain = domain; |
| 454 | if (domain->ops->map) { |
| 455 | ret = domain->ops->map(domain, virq, hwirq); |
| 456 | if (ret != 0) { |
| 457 | /* |
| 458 | * If map() returns -EPERM, this interrupt is protected |
| 459 | * by the firmware or some other service and shall not |
| 460 | * be mapped. Don't bother telling the user about it. |
| 461 | */ |
| 462 | if (ret != -EPERM) { |
| 463 | pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n", |
| 464 | domain->name, hwirq, virq, ret); |
| 465 | } |
| 466 | irq_data->domain = NULL; |
| 467 | irq_data->hwirq = 0; |
| 468 | mutex_unlock(&irq_domain_mutex); |
| 469 | return ret; |
| 470 | } |
| 471 | |
| 472 | /* If not already assigned, give the domain the chip's name */ |
| 473 | if (!domain->name && irq_data->chip) |
| 474 | domain->name = irq_data->chip->name; |
| 475 | } |
| 476 | |
| 477 | if (hwirq < domain->revmap_size) { |
| 478 | domain->linear_revmap[hwirq] = virq; |
| 479 | } else { |
| 480 | mutex_lock(&revmap_trees_mutex); |
| 481 | radix_tree_insert(&domain->revmap_tree, hwirq, irq_data); |
| 482 | mutex_unlock(&revmap_trees_mutex); |
| 483 | } |
| 484 | mutex_unlock(&irq_domain_mutex); |
| 485 | |
| 486 | irq_clear_status_flags(virq, IRQ_NOREQUEST); |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | EXPORT_SYMBOL_GPL(irq_domain_associate); |
| 491 | |
| 492 | void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base, |
| 493 | irq_hw_number_t hwirq_base, int count) |
| 494 | { |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 495 | struct device_node *of_node; |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 496 | int i; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 497 | |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 498 | of_node = irq_domain_get_of_node(domain); |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 499 | pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__, |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 500 | of_node_full_name(of_node), irq_base, (int)hwirq_base, count); |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 501 | |
| 502 | for (i = 0; i < count; i++) { |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 503 | irq_domain_associate(domain, irq_base + i, hwirq_base + i); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 504 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 505 | } |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 506 | EXPORT_SYMBOL_GPL(irq_domain_associate_many); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 507 | |
| 508 | /** |
| 509 | * irq_create_direct_mapping() - Allocate an irq for direct mapping |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 510 | * @domain: domain to allocate the irq for or NULL for default domain |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 511 | * |
| 512 | * This routine is used for irq controllers which can choose the hardware |
| 513 | * 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] | 514 | * the linux irq as the hardware interrupt number. It still uses the linear |
| 515 | * or radix tree to store the mapping, but the irq controller can optimize |
| 516 | * the revmap path by using the hwirq directly. |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 517 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 518 | unsigned int irq_create_direct_mapping(struct irq_domain *domain) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 519 | { |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 520 | struct device_node *of_node; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 521 | unsigned int virq; |
| 522 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 523 | if (domain == NULL) |
| 524 | domain = irq_default_domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 525 | |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 526 | of_node = irq_domain_get_of_node(domain); |
| 527 | virq = irq_alloc_desc_from(1, of_node_to_nid(of_node)); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 528 | if (!virq) { |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 529 | pr_debug("create_direct virq allocation failed\n"); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 530 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 531 | } |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 532 | if (virq >= domain->revmap_direct_max_irq) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 533 | pr_err("ERROR: no free irqs available below %i maximum\n", |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 534 | domain->revmap_direct_max_irq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 535 | irq_free_desc(virq); |
| 536 | return 0; |
| 537 | } |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 538 | pr_debug("create_direct obtained virq %d\n", virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 539 | |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 540 | if (irq_domain_associate(domain, virq, virq)) { |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 541 | irq_free_desc(virq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 542 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | return virq; |
| 546 | } |
Paul Mundt | ecd84eb | 2012-05-19 15:11:42 +0900 | [diff] [blame] | 547 | EXPORT_SYMBOL_GPL(irq_create_direct_mapping); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 548 | |
| 549 | /** |
| 550 | * irq_create_mapping() - Map a hardware interrupt into linux irq space |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 551 | * @domain: domain owning this hardware interrupt or NULL for default domain |
| 552 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 553 | * |
| 554 | * Only one mapping per hardware interrupt is permitted. Returns a linux |
| 555 | * irq number. |
| 556 | * If the sense/trigger is to be specified, set_irq_type() should be called |
| 557 | * on the number returned from that call. |
| 558 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 559 | unsigned int irq_create_mapping(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 560 | irq_hw_number_t hwirq) |
| 561 | { |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 562 | struct device_node *of_node; |
David Daney | 5b7526e | 2012-04-05 16:52:13 -0700 | [diff] [blame] | 563 | int virq; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 564 | |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 565 | pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 566 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 567 | /* Look for default domain if nececssary */ |
| 568 | if (domain == NULL) |
| 569 | domain = irq_default_domain; |
| 570 | if (domain == NULL) { |
Kefeng Wang | 798f0fd | 2013-06-06 19:20:27 +0800 | [diff] [blame] | 571 | WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 572 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 573 | } |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 574 | pr_debug("-> using domain @%p\n", domain); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 575 | |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 576 | of_node = irq_domain_get_of_node(domain); |
| 577 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 578 | /* Check if mapping already exists */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 579 | virq = irq_find_mapping(domain, hwirq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 580 | if (virq) { |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 581 | pr_debug("-> existing mapping on virq %d\n", virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 582 | return virq; |
| 583 | } |
| 584 | |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 585 | /* Allocate a virtual interrupt number */ |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 586 | virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(of_node), NULL); |
David Daney | 5b7526e | 2012-04-05 16:52:13 -0700 | [diff] [blame] | 587 | if (virq <= 0) { |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 588 | pr_debug("-> virq allocation failed\n"); |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 589 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 592 | if (irq_domain_associate(domain, virq, hwirq)) { |
Grant Likely | 7325570 | 2012-06-03 22:04:35 -0700 | [diff] [blame] | 593 | irq_free_desc(virq); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 594 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Paul Mundt | 54a9058 | 2012-05-19 15:11:47 +0900 | [diff] [blame] | 597 | pr_debug("irq %lu on domain %s mapped to virtual irq %u\n", |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 598 | hwirq, of_node_full_name(of_node), virq); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 599 | |
| 600 | return virq; |
| 601 | } |
| 602 | EXPORT_SYMBOL_GPL(irq_create_mapping); |
| 603 | |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 604 | /** |
| 605 | * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs |
| 606 | * @domain: domain owning the interrupt range |
| 607 | * @irq_base: beginning of linux IRQ range |
| 608 | * @hwirq_base: beginning of hardware IRQ range |
| 609 | * @count: Number of interrupts to map |
| 610 | * |
| 611 | * This routine is used for allocating and mapping a range of hardware |
| 612 | * irqs to linux irqs where the linux irq numbers are at pre-defined |
| 613 | * locations. For use by controllers that already have static mappings |
| 614 | * to insert in to the domain. |
| 615 | * |
| 616 | * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time |
| 617 | * domain insertion. |
| 618 | * |
| 619 | * 0 is returned upon success, while any failure to establish a static |
| 620 | * mapping is treated as an error. |
| 621 | */ |
| 622 | int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base, |
| 623 | irq_hw_number_t hwirq_base, int count) |
| 624 | { |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 625 | struct device_node *of_node; |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 626 | int ret; |
| 627 | |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 628 | of_node = irq_domain_get_of_node(domain); |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 629 | ret = irq_alloc_descs(irq_base, irq_base, count, |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 630 | of_node_to_nid(of_node)); |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 631 | if (unlikely(ret < 0)) |
| 632 | return ret; |
| 633 | |
Grant Likely | ddaf144 | 2013-06-10 01:06:02 +0100 | [diff] [blame] | 634 | irq_domain_associate_many(domain, irq_base, hwirq_base, count); |
Grant Likely | 98aa468 | 2012-06-17 16:17:04 -0600 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | EXPORT_SYMBOL_GPL(irq_create_strict_mappings); |
| 638 | |
Marc Zyngier | 11e4438e | 2015-10-13 12:51:32 +0100 | [diff] [blame] | 639 | static int irq_domain_translate(struct irq_domain *d, |
| 640 | struct irq_fwspec *fwspec, |
| 641 | irq_hw_number_t *hwirq, unsigned int *type) |
| 642 | { |
| 643 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 644 | if (d->ops->translate) |
| 645 | return d->ops->translate(d, fwspec, hwirq, type); |
| 646 | #endif |
| 647 | if (d->ops->xlate) |
| 648 | return d->ops->xlate(d, to_of_node(fwspec->fwnode), |
| 649 | fwspec->param, fwspec->param_count, |
| 650 | hwirq, type); |
| 651 | |
| 652 | /* If domain has no translation, then we assume interrupt line */ |
| 653 | *hwirq = fwspec->param[0]; |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static void of_phandle_args_to_fwspec(struct of_phandle_args *irq_data, |
| 658 | struct irq_fwspec *fwspec) |
| 659 | { |
| 660 | int i; |
| 661 | |
| 662 | fwspec->fwnode = irq_data->np ? &irq_data->np->fwnode : NULL; |
| 663 | fwspec->param_count = irq_data->args_count; |
| 664 | |
| 665 | for (i = 0; i < irq_data->args_count; i++) |
| 666 | fwspec->param[i] = irq_data->args[i]; |
| 667 | } |
| 668 | |
Marc Zyngier | c0131f0 | 2015-10-13 12:51:34 +0100 | [diff] [blame] | 669 | unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 670 | { |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 671 | struct irq_domain *domain; |
Jon Hunter | 1e2a7d7 | 2016-06-07 16:12:28 +0100 | [diff] [blame] | 672 | struct irq_data *irq_data; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 673 | irq_hw_number_t hwirq; |
| 674 | unsigned int type = IRQ_TYPE_NONE; |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 675 | int virq; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 676 | |
Marc Zyngier | 530cbe1 | 2016-01-26 13:52:25 +0000 | [diff] [blame] | 677 | if (fwspec->fwnode) { |
Marc Zyngier | 651e8b5 | 2016-04-11 09:57:51 +0100 | [diff] [blame] | 678 | domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_WIRED); |
Marc Zyngier | 530cbe1 | 2016-01-26 13:52:25 +0000 | [diff] [blame] | 679 | if (!domain) |
Marc Zyngier | 651e8b5 | 2016-04-11 09:57:51 +0100 | [diff] [blame] | 680 | domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_ANY); |
Marc Zyngier | 530cbe1 | 2016-01-26 13:52:25 +0000 | [diff] [blame] | 681 | } else { |
Marc Zyngier | 11e4438e | 2015-10-13 12:51:32 +0100 | [diff] [blame] | 682 | domain = irq_default_domain; |
Marc Zyngier | 530cbe1 | 2016-01-26 13:52:25 +0000 | [diff] [blame] | 683 | } |
Marc Zyngier | 11e4438e | 2015-10-13 12:51:32 +0100 | [diff] [blame] | 684 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 685 | if (!domain) { |
Kefeng Wang | 798f0fd | 2013-06-06 19:20:27 +0800 | [diff] [blame] | 686 | pr_warn("no irq domain found for %s !\n", |
Marc Zyngier | c0131f0 | 2015-10-13 12:51:34 +0100 | [diff] [blame] | 687 | of_node_full_name(to_of_node(fwspec->fwnode))); |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 688 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Marc Zyngier | c0131f0 | 2015-10-13 12:51:34 +0100 | [diff] [blame] | 691 | if (irq_domain_translate(domain, fwspec, &hwirq, &type)) |
Marc Zyngier | 11e4438e | 2015-10-13 12:51:32 +0100 | [diff] [blame] | 692 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 693 | |
Jon Hunter | b62b2cf | 2016-06-07 16:12:26 +0100 | [diff] [blame] | 694 | /* |
| 695 | * WARN if the irqchip returns a type with bits |
| 696 | * outside the sense mask set and clear these bits. |
| 697 | */ |
| 698 | if (WARN_ON(type & ~IRQ_TYPE_SENSE_MASK)) |
| 699 | type &= IRQ_TYPE_SENSE_MASK; |
| 700 | |
| 701 | /* |
| 702 | * If we've already configured this interrupt, |
| 703 | * don't do it again, or hell will break loose. |
| 704 | */ |
| 705 | virq = irq_find_mapping(domain, hwirq); |
| 706 | if (virq) { |
Yingjoe Chen | 0cc01ab | 2014-11-06 22:20:15 +0800 | [diff] [blame] | 707 | /* |
Jon Hunter | b62b2cf | 2016-06-07 16:12:26 +0100 | [diff] [blame] | 708 | * If the trigger type is not specified or matches the |
| 709 | * current trigger type then we are done so return the |
| 710 | * interrupt number. |
Yingjoe Chen | 0cc01ab | 2014-11-06 22:20:15 +0800 | [diff] [blame] | 711 | */ |
Jon Hunter | b62b2cf | 2016-06-07 16:12:26 +0100 | [diff] [blame] | 712 | if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq)) |
Yingjoe Chen | 0cc01ab | 2014-11-06 22:20:15 +0800 | [diff] [blame] | 713 | return virq; |
| 714 | |
Jon Hunter | b62b2cf | 2016-06-07 16:12:26 +0100 | [diff] [blame] | 715 | /* |
| 716 | * If the trigger type has not been set yet, then set |
| 717 | * it now and return the interrupt number. |
| 718 | */ |
| 719 | if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) { |
Jon Hunter | 1e2a7d7 | 2016-06-07 16:12:28 +0100 | [diff] [blame] | 720 | irq_data = irq_get_irq_data(virq); |
| 721 | if (!irq_data) |
| 722 | return 0; |
| 723 | |
| 724 | irqd_set_trigger_type(irq_data, type); |
Jon Hunter | b62b2cf | 2016-06-07 16:12:26 +0100 | [diff] [blame] | 725 | return virq; |
| 726 | } |
| 727 | |
| 728 | pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n", |
| 729 | hwirq, of_node_full_name(to_of_node(fwspec->fwnode))); |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | if (irq_domain_is_hierarchy(domain)) { |
Marc Zyngier | c0131f0 | 2015-10-13 12:51:34 +0100 | [diff] [blame] | 734 | virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, fwspec); |
Yingjoe Chen | 0cc01ab | 2014-11-06 22:20:15 +0800 | [diff] [blame] | 735 | if (virq <= 0) |
| 736 | return 0; |
| 737 | } else { |
| 738 | /* Create mapping */ |
| 739 | virq = irq_create_mapping(domain, hwirq); |
| 740 | if (!virq) |
| 741 | return virq; |
| 742 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 743 | |
Jon Hunter | 1e2a7d7 | 2016-06-07 16:12:28 +0100 | [diff] [blame] | 744 | irq_data = irq_get_irq_data(virq); |
| 745 | if (!irq_data) { |
| 746 | if (irq_domain_is_hierarchy(domain)) |
| 747 | irq_domain_free_irqs(virq, 1); |
| 748 | else |
| 749 | irq_dispose_mapping(virq); |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | /* Store trigger type */ |
| 754 | irqd_set_trigger_type(irq_data, type); |
| 755 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 756 | return virq; |
| 757 | } |
Marc Zyngier | c0131f0 | 2015-10-13 12:51:34 +0100 | [diff] [blame] | 758 | EXPORT_SYMBOL_GPL(irq_create_fwspec_mapping); |
| 759 | |
| 760 | unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data) |
| 761 | { |
| 762 | struct irq_fwspec fwspec; |
| 763 | |
| 764 | of_phandle_args_to_fwspec(irq_data, &fwspec); |
| 765 | return irq_create_fwspec_mapping(&fwspec); |
| 766 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 767 | EXPORT_SYMBOL_GPL(irq_create_of_mapping); |
| 768 | |
| 769 | /** |
| 770 | * irq_dispose_mapping() - Unmap an interrupt |
| 771 | * @virq: linux irq number of the interrupt to unmap |
| 772 | */ |
| 773 | void irq_dispose_mapping(unsigned int virq) |
| 774 | { |
| 775 | struct irq_data *irq_data = irq_get_irq_data(virq); |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 776 | struct irq_domain *domain; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 777 | |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 778 | if (!virq || !irq_data) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 779 | return; |
| 780 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 781 | domain = irq_data->domain; |
| 782 | if (WARN_ON(domain == NULL)) |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 783 | return; |
| 784 | |
Jon Hunter | d16dcd3d | 2016-06-21 10:23:22 +0100 | [diff] [blame] | 785 | if (irq_domain_is_hierarchy(domain)) { |
| 786 | irq_domain_free_irqs(virq, 1); |
| 787 | } else { |
| 788 | irq_domain_disassociate(domain, virq); |
| 789 | irq_free_desc(virq); |
| 790 | } |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 791 | } |
| 792 | EXPORT_SYMBOL_GPL(irq_dispose_mapping); |
| 793 | |
| 794 | /** |
| 795 | * irq_find_mapping() - Find a linux irq from an hw irq number. |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 796 | * @domain: domain owning this hardware interrupt |
| 797 | * @hwirq: hardware irq number in that domain space |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 798 | */ |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 799 | unsigned int irq_find_mapping(struct irq_domain *domain, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 800 | irq_hw_number_t hwirq) |
| 801 | { |
Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 802 | struct irq_data *data; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 803 | |
Grant Likely | 6870065 | 2012-02-14 14:06:53 -0700 | [diff] [blame] | 804 | /* Look for default domain if nececssary */ |
| 805 | if (domain == NULL) |
| 806 | domain = irq_default_domain; |
| 807 | if (domain == NULL) |
Grant Likely | 0384837 | 2012-02-14 14:06:52 -0700 | [diff] [blame] | 808 | return 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 809 | |
Grant Likely | 1aa0dd9 | 2013-06-08 12:03:59 +0100 | [diff] [blame] | 810 | if (hwirq < domain->revmap_direct_max_irq) { |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 811 | data = irq_domain_get_irq_data(domain, hwirq); |
| 812 | if (data && data->hwirq == hwirq) |
Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 813 | return hwirq; |
Grant Likely | 4c0946c | 2012-06-03 22:04:39 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Grant Likely | d3dcb43 | 2013-06-10 12:19:17 +0100 | [diff] [blame] | 816 | /* Check if the hwirq is in the linear revmap. */ |
| 817 | if (hwirq < domain->revmap_size) |
| 818 | return domain->linear_revmap[hwirq]; |
| 819 | |
| 820 | rcu_read_lock(); |
| 821 | data = radix_tree_lookup(&domain->revmap_tree, hwirq); |
| 822 | rcu_read_unlock(); |
| 823 | return data ? data->irq : 0; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 824 | } |
| 825 | EXPORT_SYMBOL_GPL(irq_find_mapping); |
| 826 | |
Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 827 | #ifdef CONFIG_IRQ_DOMAIN_DEBUG |
Marc Zyngier | fe17a42 | 2017-05-12 12:55:35 +0100 | [diff] [blame] | 828 | static void virq_debug_show_one(struct seq_file *m, struct irq_desc *desc) |
| 829 | { |
| 830 | struct irq_domain *domain; |
| 831 | struct irq_data *data; |
| 832 | |
| 833 | domain = desc->irq_data.domain; |
| 834 | data = &desc->irq_data; |
| 835 | |
| 836 | while (domain) { |
| 837 | unsigned int irq = data->irq; |
| 838 | unsigned long hwirq = data->hwirq; |
| 839 | struct irq_chip *chip; |
| 840 | bool direct; |
| 841 | |
| 842 | if (data == &desc->irq_data) |
| 843 | seq_printf(m, "%5d ", irq); |
| 844 | else |
| 845 | seq_printf(m, "%5d+ ", irq); |
| 846 | seq_printf(m, "0x%05lx ", hwirq); |
| 847 | |
| 848 | chip = irq_data_get_irq_chip(data); |
| 849 | seq_printf(m, "%-15s ", (chip && chip->name) ? chip->name : "none"); |
| 850 | |
| 851 | seq_printf(m, data ? "0x%p " : " %p ", |
| 852 | irq_data_get_irq_chip_data(data)); |
| 853 | |
| 854 | seq_printf(m, " %c ", (desc->action && desc->action->handler) ? '*' : ' '); |
| 855 | direct = (irq == hwirq) && (irq < domain->revmap_direct_max_irq); |
| 856 | seq_printf(m, "%6s%-8s ", |
| 857 | (hwirq < domain->revmap_size) ? "LINEAR" : "RADIX", |
| 858 | direct ? "(DIRECT)" : ""); |
| 859 | seq_printf(m, "%s\n", domain->name); |
| 860 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 861 | domain = domain->parent; |
| 862 | data = data->parent_data; |
| 863 | #else |
| 864 | domain = NULL; |
| 865 | #endif |
| 866 | } |
| 867 | } |
| 868 | |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 869 | static int virq_debug_show(struct seq_file *m, void *private) |
| 870 | { |
| 871 | unsigned long flags; |
| 872 | struct irq_desc *desc; |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 873 | struct irq_domain *domain; |
| 874 | struct radix_tree_iter iter; |
Marc Zyngier | fe17a42 | 2017-05-12 12:55:35 +0100 | [diff] [blame] | 875 | void **slot; |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 876 | int i; |
| 877 | |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 878 | seq_printf(m, " %-16s %-6s %-10s %-10s %s\n", |
| 879 | "name", "mapped", "linear-max", "direct-max", "devtree-node"); |
| 880 | mutex_lock(&irq_domain_mutex); |
| 881 | list_for_each_entry(domain, &irq_domain_list, link) { |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 882 | struct device_node *of_node; |
Marc Zyngier | 2370c00 | 2017-05-12 12:55:36 +0100 | [diff] [blame] | 883 | const char *name; |
| 884 | |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 885 | int count = 0; |
Marc Zyngier | 2370c00 | 2017-05-12 12:55:36 +0100 | [diff] [blame] | 886 | |
Marc Zyngier | 5d4c9bc | 2015-10-13 12:51:29 +0100 | [diff] [blame] | 887 | of_node = irq_domain_get_of_node(domain); |
Marc Zyngier | 2370c00 | 2017-05-12 12:55:36 +0100 | [diff] [blame] | 888 | if (of_node) |
| 889 | name = of_node_full_name(of_node); |
| 890 | else if (is_fwnode_irqchip(domain->fwnode)) |
| 891 | name = container_of(domain->fwnode, struct irqchip_fwid, |
| 892 | fwnode)->name; |
| 893 | else |
| 894 | name = ""; |
| 895 | |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 896 | radix_tree_for_each_slot(slot, &domain->revmap_tree, &iter, 0) |
| 897 | count++; |
| 898 | seq_printf(m, "%c%-16s %6u %10u %10u %s\n", |
| 899 | domain == irq_default_domain ? '*' : ' ', domain->name, |
| 900 | domain->revmap_size + count, domain->revmap_size, |
| 901 | domain->revmap_direct_max_irq, |
Marc Zyngier | 2370c00 | 2017-05-12 12:55:36 +0100 | [diff] [blame] | 902 | name); |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 903 | } |
| 904 | mutex_unlock(&irq_domain_mutex); |
| 905 | |
| 906 | 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] | 907 | "chip name", (int)(2 * sizeof(void *) + 2), "chip data", |
Grant Likely | 1400ea8 | 2013-06-06 22:20:44 +0100 | [diff] [blame] | 908 | "active", "type", "domain"); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 909 | |
| 910 | for (i = 1; i < nr_irqs; i++) { |
| 911 | desc = irq_to_desc(i); |
| 912 | if (!desc) |
| 913 | continue; |
| 914 | |
| 915 | raw_spin_lock_irqsave(&desc->lock, flags); |
Marc Zyngier | fe17a42 | 2017-05-12 12:55:35 +0100 | [diff] [blame] | 916 | virq_debug_show_one(m, desc); |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 917 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 918 | } |
| 919 | |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | static int virq_debug_open(struct inode *inode, struct file *file) |
| 924 | { |
| 925 | return single_open(file, virq_debug_show, inode->i_private); |
| 926 | } |
| 927 | |
| 928 | static const struct file_operations virq_debug_fops = { |
| 929 | .open = virq_debug_open, |
| 930 | .read = seq_read, |
| 931 | .llseek = seq_lseek, |
| 932 | .release = single_release, |
| 933 | }; |
| 934 | |
| 935 | static int __init irq_debugfs_init(void) |
| 936 | { |
Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 937 | if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL, |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 938 | NULL, &virq_debug_fops) == NULL) |
| 939 | return -ENOMEM; |
| 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | __initcall(irq_debugfs_init); |
Grant Likely | 092b2fb | 2012-03-29 14:10:30 -0600 | [diff] [blame] | 944 | #endif /* CONFIG_IRQ_DOMAIN_DEBUG */ |
Grant Likely | cc79ca6 | 2012-02-16 01:37:49 -0700 | [diff] [blame] | 945 | |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 946 | /** |
| 947 | * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings |
| 948 | * |
| 949 | * Device Tree IRQ specifier translation function which works with one cell |
| 950 | * bindings where the cell value maps directly to the hwirq number. |
| 951 | */ |
| 952 | int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr, |
| 953 | const u32 *intspec, unsigned int intsize, |
| 954 | unsigned long *out_hwirq, unsigned int *out_type) |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 955 | { |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 956 | if (WARN_ON(intsize < 1)) |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 957 | return -EINVAL; |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 958 | *out_hwirq = intspec[0]; |
| 959 | *out_type = IRQ_TYPE_NONE; |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 960 | return 0; |
| 961 | } |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 962 | EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell); |
| 963 | |
| 964 | /** |
| 965 | * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings |
| 966 | * |
| 967 | * Device Tree IRQ specifier translation function which works with two cell |
| 968 | * bindings where the cell values map directly to the hwirq number |
| 969 | * and linux irq flags. |
| 970 | */ |
| 971 | int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr, |
| 972 | const u32 *intspec, unsigned int intsize, |
| 973 | irq_hw_number_t *out_hwirq, unsigned int *out_type) |
| 974 | { |
| 975 | if (WARN_ON(intsize < 2)) |
| 976 | return -EINVAL; |
| 977 | *out_hwirq = intspec[0]; |
| 978 | *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; |
| 979 | return 0; |
| 980 | } |
| 981 | EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell); |
| 982 | |
| 983 | /** |
| 984 | * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings |
| 985 | * |
| 986 | * Device Tree IRQ specifier translation function which works with either one |
| 987 | * or two cell bindings where the cell values map directly to the hwirq number |
| 988 | * and linux irq flags. |
| 989 | * |
| 990 | * Note: don't use this function unless your interrupt controller explicitly |
| 991 | * supports both one and two cell bindings. For the majority of controllers |
| 992 | * the _onecell() or _twocell() variants above should be used. |
| 993 | */ |
| 994 | int irq_domain_xlate_onetwocell(struct irq_domain *d, |
| 995 | struct device_node *ctrlr, |
| 996 | const u32 *intspec, unsigned int intsize, |
| 997 | unsigned long *out_hwirq, unsigned int *out_type) |
| 998 | { |
| 999 | if (WARN_ON(intsize < 1)) |
| 1000 | return -EINVAL; |
| 1001 | *out_hwirq = intspec[0]; |
Sebastian Frias | 0c22891 | 2016-08-02 10:52:45 +0200 | [diff] [blame] | 1002 | if (intsize > 1) |
| 1003 | *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; |
| 1004 | else |
| 1005 | *out_type = IRQ_TYPE_NONE; |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 1006 | return 0; |
| 1007 | } |
| 1008 | EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell); |
Grant Likely | 7e71330 | 2011-07-26 03:19:06 -0600 | [diff] [blame] | 1009 | |
Grant Likely | a18dc81 | 2012-01-26 12:12:14 -0700 | [diff] [blame] | 1010 | const struct irq_domain_ops irq_domain_simple_ops = { |
Grant Likely | 16b2e6e | 2012-01-26 11:26:52 -0700 | [diff] [blame] | 1011 | .xlate = irq_domain_xlate_onetwocell, |
Grant Likely | 7529495 | 2012-02-14 14:06:57 -0700 | [diff] [blame] | 1012 | }; |
| 1013 | EXPORT_SYMBOL_GPL(irq_domain_simple_ops); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1014 | |
Qais Yousef | ac0a0cd | 2015-12-08 13:20:18 +0000 | [diff] [blame] | 1015 | int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq, |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 1016 | int node, const struct cpumask *affinity) |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1017 | { |
| 1018 | unsigned int hint; |
| 1019 | |
| 1020 | if (virq >= 0) { |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 1021 | virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE, |
| 1022 | affinity); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1023 | } else { |
| 1024 | hint = hwirq % nr_irqs; |
| 1025 | if (hint == 0) |
| 1026 | hint++; |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 1027 | virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE, |
| 1028 | affinity); |
| 1029 | if (virq <= 0 && hint > 1) { |
| 1030 | virq = __irq_alloc_descs(-1, 1, cnt, node, THIS_MODULE, |
| 1031 | affinity); |
| 1032 | } |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | return virq; |
| 1036 | } |
| 1037 | |
| 1038 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1039 | /** |
Marc Zyngier | 2a5e9a0 | 2015-10-13 12:51:43 +0100 | [diff] [blame] | 1040 | * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1041 | * @parent: Parent irq domain to associate with the new domain |
| 1042 | * @flags: Irq domain flags associated to the domain |
| 1043 | * @size: Size of the domain. See below |
Marc Zyngier | 2a5e9a0 | 2015-10-13 12:51:43 +0100 | [diff] [blame] | 1044 | * @fwnode: Optional fwnode of the interrupt controller |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1045 | * @ops: Pointer to the interrupt domain callbacks |
| 1046 | * @host_data: Controller private data pointer |
| 1047 | * |
| 1048 | * If @size is 0 a tree domain is created, otherwise a linear domain. |
| 1049 | * |
| 1050 | * If successful the parent is associated to the new domain and the |
| 1051 | * domain flags are set. |
| 1052 | * Returns pointer to IRQ domain, or NULL on failure. |
| 1053 | */ |
Marc Zyngier | 2a5e9a0 | 2015-10-13 12:51:43 +0100 | [diff] [blame] | 1054 | struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent, |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1055 | unsigned int flags, |
| 1056 | unsigned int size, |
Marc Zyngier | 2a5e9a0 | 2015-10-13 12:51:43 +0100 | [diff] [blame] | 1057 | struct fwnode_handle *fwnode, |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1058 | const struct irq_domain_ops *ops, |
| 1059 | void *host_data) |
| 1060 | { |
| 1061 | struct irq_domain *domain; |
| 1062 | |
| 1063 | if (size) |
Marc Zyngier | 2a5e9a0 | 2015-10-13 12:51:43 +0100 | [diff] [blame] | 1064 | domain = irq_domain_create_linear(fwnode, size, ops, host_data); |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1065 | else |
Marc Zyngier | 2a5e9a0 | 2015-10-13 12:51:43 +0100 | [diff] [blame] | 1066 | domain = irq_domain_create_tree(fwnode, ops, host_data); |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1067 | if (domain) { |
| 1068 | domain->parent = parent; |
| 1069 | domain->flags |= flags; |
| 1070 | } |
| 1071 | |
| 1072 | return domain; |
| 1073 | } |
Quan Nguyen | 52b2a05 | 2016-03-03 21:56:52 +0700 | [diff] [blame] | 1074 | EXPORT_SYMBOL_GPL(irq_domain_create_hierarchy); |
Jiang Liu | afb7da8 | 2014-11-15 22:24:02 +0800 | [diff] [blame] | 1075 | |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1076 | static void irq_domain_insert_irq(int virq) |
| 1077 | { |
| 1078 | struct irq_data *data; |
| 1079 | |
| 1080 | for (data = irq_get_irq_data(virq); data; data = data->parent_data) { |
| 1081 | struct irq_domain *domain = data->domain; |
| 1082 | irq_hw_number_t hwirq = data->hwirq; |
| 1083 | |
| 1084 | if (hwirq < domain->revmap_size) { |
| 1085 | domain->linear_revmap[hwirq] = virq; |
| 1086 | } else { |
| 1087 | mutex_lock(&revmap_trees_mutex); |
| 1088 | radix_tree_insert(&domain->revmap_tree, hwirq, data); |
| 1089 | mutex_unlock(&revmap_trees_mutex); |
| 1090 | } |
| 1091 | |
| 1092 | /* If not already assigned, give the domain the chip's name */ |
| 1093 | if (!domain->name && data->chip) |
| 1094 | domain->name = data->chip->name; |
| 1095 | } |
| 1096 | |
| 1097 | irq_clear_status_flags(virq, IRQ_NOREQUEST); |
| 1098 | } |
| 1099 | |
| 1100 | static void irq_domain_remove_irq(int virq) |
| 1101 | { |
| 1102 | struct irq_data *data; |
| 1103 | |
| 1104 | irq_set_status_flags(virq, IRQ_NOREQUEST); |
| 1105 | irq_set_chip_and_handler(virq, NULL, NULL); |
| 1106 | synchronize_irq(virq); |
| 1107 | smp_mb(); |
| 1108 | |
| 1109 | for (data = irq_get_irq_data(virq); data; data = data->parent_data) { |
| 1110 | struct irq_domain *domain = data->domain; |
| 1111 | irq_hw_number_t hwirq = data->hwirq; |
| 1112 | |
| 1113 | if (hwirq < domain->revmap_size) { |
| 1114 | domain->linear_revmap[hwirq] = 0; |
| 1115 | } else { |
| 1116 | mutex_lock(&revmap_trees_mutex); |
| 1117 | radix_tree_delete(&domain->revmap_tree, hwirq); |
| 1118 | mutex_unlock(&revmap_trees_mutex); |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain, |
| 1124 | struct irq_data *child) |
| 1125 | { |
| 1126 | struct irq_data *irq_data; |
| 1127 | |
Jiang Liu | 6783011 | 2015-06-01 16:05:13 +0800 | [diff] [blame] | 1128 | irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL, |
| 1129 | irq_data_get_node(child)); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1130 | if (irq_data) { |
| 1131 | child->parent_data = irq_data; |
| 1132 | irq_data->irq = child->irq; |
Jiang Liu | 0d0b4c8 | 2015-06-01 16:05:12 +0800 | [diff] [blame] | 1133 | irq_data->common = child->common; |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1134 | irq_data->domain = domain; |
| 1135 | } |
| 1136 | |
| 1137 | return irq_data; |
| 1138 | } |
| 1139 | |
| 1140 | static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs) |
| 1141 | { |
| 1142 | struct irq_data *irq_data, *tmp; |
| 1143 | int i; |
| 1144 | |
| 1145 | for (i = 0; i < nr_irqs; i++) { |
| 1146 | irq_data = irq_get_irq_data(virq + i); |
| 1147 | tmp = irq_data->parent_data; |
| 1148 | irq_data->parent_data = NULL; |
| 1149 | irq_data->domain = NULL; |
| 1150 | |
| 1151 | while (tmp) { |
| 1152 | irq_data = tmp; |
| 1153 | tmp = tmp->parent_data; |
| 1154 | kfree(irq_data); |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | static int irq_domain_alloc_irq_data(struct irq_domain *domain, |
| 1160 | unsigned int virq, unsigned int nr_irqs) |
| 1161 | { |
| 1162 | struct irq_data *irq_data; |
| 1163 | struct irq_domain *parent; |
| 1164 | int i; |
| 1165 | |
| 1166 | /* The outermost irq_data is embedded in struct irq_desc */ |
| 1167 | for (i = 0; i < nr_irqs; i++) { |
| 1168 | irq_data = irq_get_irq_data(virq + i); |
| 1169 | irq_data->domain = domain; |
| 1170 | |
| 1171 | for (parent = domain->parent; parent; parent = parent->parent) { |
| 1172 | irq_data = irq_domain_insert_irq_data(parent, irq_data); |
| 1173 | if (!irq_data) { |
| 1174 | irq_domain_free_irq_data(virq, i + 1); |
| 1175 | return -ENOMEM; |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | /** |
| 1184 | * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain |
| 1185 | * @domain: domain to match |
| 1186 | * @virq: IRQ number to get irq_data |
| 1187 | */ |
| 1188 | struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, |
| 1189 | unsigned int virq) |
| 1190 | { |
| 1191 | struct irq_data *irq_data; |
| 1192 | |
| 1193 | for (irq_data = irq_get_irq_data(virq); irq_data; |
| 1194 | irq_data = irq_data->parent_data) |
| 1195 | if (irq_data->domain == domain) |
| 1196 | return irq_data; |
| 1197 | |
| 1198 | return NULL; |
| 1199 | } |
Jake Oshins | a4289dc | 2015-12-10 17:52:59 +0000 | [diff] [blame] | 1200 | EXPORT_SYMBOL_GPL(irq_domain_get_irq_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1201 | |
| 1202 | /** |
| 1203 | * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain |
| 1204 | * @domain: Interrupt domain to match |
| 1205 | * @virq: IRQ number |
| 1206 | * @hwirq: The hwirq number |
| 1207 | * @chip: The associated interrupt chip |
| 1208 | * @chip_data: The associated chip data |
| 1209 | */ |
| 1210 | int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq, |
| 1211 | irq_hw_number_t hwirq, struct irq_chip *chip, |
| 1212 | void *chip_data) |
| 1213 | { |
| 1214 | struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq); |
| 1215 | |
| 1216 | if (!irq_data) |
| 1217 | return -ENOENT; |
| 1218 | |
| 1219 | irq_data->hwirq = hwirq; |
| 1220 | irq_data->chip = chip ? chip : &no_irq_chip; |
| 1221 | irq_data->chip_data = chip_data; |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
Quan Nguyen | 52b2a05 | 2016-03-03 21:56:52 +0700 | [diff] [blame] | 1225 | EXPORT_SYMBOL_GPL(irq_domain_set_hwirq_and_chip); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1226 | |
| 1227 | /** |
Jiang Liu | 1b53770 | 2014-11-09 23:10:24 +0800 | [diff] [blame] | 1228 | * irq_domain_set_info - Set the complete data for a @virq in @domain |
| 1229 | * @domain: Interrupt domain to match |
| 1230 | * @virq: IRQ number |
| 1231 | * @hwirq: The hardware interrupt number |
| 1232 | * @chip: The associated interrupt chip |
| 1233 | * @chip_data: The associated interrupt chip data |
| 1234 | * @handler: The interrupt flow handler |
| 1235 | * @handler_data: The interrupt flow handler data |
| 1236 | * @handler_name: The interrupt handler name |
| 1237 | */ |
| 1238 | void irq_domain_set_info(struct irq_domain *domain, unsigned int virq, |
| 1239 | irq_hw_number_t hwirq, struct irq_chip *chip, |
| 1240 | void *chip_data, irq_flow_handler_t handler, |
| 1241 | void *handler_data, const char *handler_name) |
| 1242 | { |
| 1243 | irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data); |
| 1244 | __irq_set_handler(virq, handler, 0, handler_name); |
| 1245 | irq_set_handler_data(virq, handler_data); |
| 1246 | } |
Keith Busch | 64bce3e | 2016-01-12 13:18:07 -0700 | [diff] [blame] | 1247 | EXPORT_SYMBOL(irq_domain_set_info); |
Jiang Liu | 1b53770 | 2014-11-09 23:10:24 +0800 | [diff] [blame] | 1248 | |
| 1249 | /** |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1250 | * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data |
| 1251 | * @irq_data: The pointer to irq_data |
| 1252 | */ |
| 1253 | void irq_domain_reset_irq_data(struct irq_data *irq_data) |
| 1254 | { |
| 1255 | irq_data->hwirq = 0; |
| 1256 | irq_data->chip = &no_irq_chip; |
| 1257 | irq_data->chip_data = NULL; |
| 1258 | } |
Quan Nguyen | 52b2a05 | 2016-03-03 21:56:52 +0700 | [diff] [blame] | 1259 | EXPORT_SYMBOL_GPL(irq_domain_reset_irq_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1260 | |
| 1261 | /** |
| 1262 | * irq_domain_free_irqs_common - Clear irq_data and free the parent |
| 1263 | * @domain: Interrupt domain to match |
| 1264 | * @virq: IRQ number to start with |
| 1265 | * @nr_irqs: The number of irqs to free |
| 1266 | */ |
| 1267 | void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq, |
| 1268 | unsigned int nr_irqs) |
| 1269 | { |
| 1270 | struct irq_data *irq_data; |
| 1271 | int i; |
| 1272 | |
| 1273 | for (i = 0; i < nr_irqs; i++) { |
| 1274 | irq_data = irq_domain_get_irq_data(domain, virq + i); |
| 1275 | if (irq_data) |
| 1276 | irq_domain_reset_irq_data(irq_data); |
| 1277 | } |
| 1278 | irq_domain_free_irqs_parent(domain, virq, nr_irqs); |
| 1279 | } |
Axel Lin | 63cc787 | 2016-03-17 12:00:31 +0800 | [diff] [blame] | 1280 | EXPORT_SYMBOL_GPL(irq_domain_free_irqs_common); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1281 | |
| 1282 | /** |
| 1283 | * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent |
| 1284 | * @domain: Interrupt domain to match |
| 1285 | * @virq: IRQ number to start with |
| 1286 | * @nr_irqs: The number of irqs to free |
| 1287 | */ |
| 1288 | void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq, |
| 1289 | unsigned int nr_irqs) |
| 1290 | { |
| 1291 | int i; |
| 1292 | |
| 1293 | for (i = 0; i < nr_irqs; i++) { |
| 1294 | irq_set_handler_data(virq + i, NULL); |
| 1295 | irq_set_handler(virq + i, NULL); |
| 1296 | } |
| 1297 | irq_domain_free_irqs_common(domain, virq, nr_irqs); |
| 1298 | } |
| 1299 | |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1300 | static bool irq_domain_is_auto_recursive(struct irq_domain *domain) |
| 1301 | { |
| 1302 | return domain->flags & IRQ_DOMAIN_FLAG_AUTO_RECURSIVE; |
| 1303 | } |
| 1304 | |
| 1305 | static void irq_domain_free_irqs_recursive(struct irq_domain *domain, |
| 1306 | unsigned int irq_base, |
| 1307 | unsigned int nr_irqs) |
| 1308 | { |
| 1309 | domain->ops->free(domain, irq_base, nr_irqs); |
| 1310 | if (irq_domain_is_auto_recursive(domain)) { |
| 1311 | BUG_ON(!domain->parent); |
| 1312 | irq_domain_free_irqs_recursive(domain->parent, irq_base, |
| 1313 | nr_irqs); |
| 1314 | } |
| 1315 | } |
| 1316 | |
Marc Zyngier | c466595 | 2015-11-23 08:26:04 +0000 | [diff] [blame] | 1317 | int irq_domain_alloc_irqs_recursive(struct irq_domain *domain, |
| 1318 | unsigned int irq_base, |
| 1319 | unsigned int nr_irqs, void *arg) |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1320 | { |
| 1321 | int ret = 0; |
| 1322 | struct irq_domain *parent = domain->parent; |
| 1323 | bool recursive = irq_domain_is_auto_recursive(domain); |
| 1324 | |
| 1325 | BUG_ON(recursive && !parent); |
| 1326 | if (recursive) |
| 1327 | ret = irq_domain_alloc_irqs_recursive(parent, irq_base, |
| 1328 | nr_irqs, arg); |
Alexander Popov | a1b7b1a | 2016-07-03 03:24:08 +0300 | [diff] [blame] | 1329 | if (ret < 0) |
| 1330 | return ret; |
| 1331 | |
| 1332 | ret = domain->ops->alloc(domain, irq_base, nr_irqs, arg); |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1333 | if (ret < 0 && recursive) |
| 1334 | irq_domain_free_irqs_recursive(parent, irq_base, nr_irqs); |
| 1335 | |
| 1336 | return ret; |
| 1337 | } |
| 1338 | |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1339 | /** |
| 1340 | * __irq_domain_alloc_irqs - Allocate IRQs from domain |
| 1341 | * @domain: domain to allocate from |
| 1342 | * @irq_base: allocate specified IRQ nubmer if irq_base >= 0 |
| 1343 | * @nr_irqs: number of IRQs to allocate |
| 1344 | * @node: NUMA node id for memory allocation |
| 1345 | * @arg: domain specific argument |
| 1346 | * @realloc: IRQ descriptors have already been allocated if true |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 1347 | * @affinity: Optional irq affinity mask for multiqueue devices |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1348 | * |
| 1349 | * Allocate IRQ numbers and initialized all data structures to support |
| 1350 | * hierarchy IRQ domains. |
| 1351 | * Parameter @realloc is mainly to support legacy IRQs. |
| 1352 | * Returns error code or allocated IRQ number |
| 1353 | * |
| 1354 | * The whole process to setup an IRQ has been split into two steps. |
| 1355 | * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ |
| 1356 | * descriptor and required hardware resources. The second step, |
| 1357 | * irq_domain_activate_irq(), is to program hardwares with preallocated |
| 1358 | * resources. In this way, it's easier to rollback when failing to |
| 1359 | * allocate resources. |
| 1360 | */ |
| 1361 | int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, |
| 1362 | unsigned int nr_irqs, int node, void *arg, |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 1363 | bool realloc, const struct cpumask *affinity) |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1364 | { |
| 1365 | int i, ret, virq; |
| 1366 | |
| 1367 | if (domain == NULL) { |
| 1368 | domain = irq_default_domain; |
| 1369 | if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n")) |
| 1370 | return -EINVAL; |
| 1371 | } |
| 1372 | |
| 1373 | if (!domain->ops->alloc) { |
| 1374 | pr_debug("domain->ops->alloc() is NULL\n"); |
| 1375 | return -ENOSYS; |
| 1376 | } |
| 1377 | |
| 1378 | if (realloc && irq_base >= 0) { |
| 1379 | virq = irq_base; |
| 1380 | } else { |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 1381 | virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node, |
| 1382 | affinity); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1383 | if (virq < 0) { |
| 1384 | pr_debug("cannot allocate IRQ(base %d, count %d)\n", |
| 1385 | irq_base, nr_irqs); |
| 1386 | return virq; |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) { |
| 1391 | pr_debug("cannot allocate memory for IRQ%d\n", virq); |
| 1392 | ret = -ENOMEM; |
| 1393 | goto out_free_desc; |
| 1394 | } |
| 1395 | |
| 1396 | mutex_lock(&irq_domain_mutex); |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1397 | ret = irq_domain_alloc_irqs_recursive(domain, virq, nr_irqs, arg); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1398 | if (ret < 0) { |
| 1399 | mutex_unlock(&irq_domain_mutex); |
| 1400 | goto out_free_irq_data; |
| 1401 | } |
| 1402 | for (i = 0; i < nr_irqs; i++) |
| 1403 | irq_domain_insert_irq(virq + i); |
| 1404 | mutex_unlock(&irq_domain_mutex); |
| 1405 | |
| 1406 | return virq; |
| 1407 | |
| 1408 | out_free_irq_data: |
| 1409 | irq_domain_free_irq_data(virq, nr_irqs); |
| 1410 | out_free_desc: |
| 1411 | irq_free_descs(virq, nr_irqs); |
| 1412 | return ret; |
| 1413 | } |
| 1414 | |
| 1415 | /** |
| 1416 | * irq_domain_free_irqs - Free IRQ number and associated data structures |
| 1417 | * @virq: base IRQ number |
| 1418 | * @nr_irqs: number of IRQs to free |
| 1419 | */ |
| 1420 | void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs) |
| 1421 | { |
| 1422 | struct irq_data *data = irq_get_irq_data(virq); |
| 1423 | int i; |
| 1424 | |
| 1425 | if (WARN(!data || !data->domain || !data->domain->ops->free, |
| 1426 | "NULL pointer, cannot free irq\n")) |
| 1427 | return; |
| 1428 | |
| 1429 | mutex_lock(&irq_domain_mutex); |
| 1430 | for (i = 0; i < nr_irqs; i++) |
| 1431 | irq_domain_remove_irq(virq + i); |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1432 | irq_domain_free_irqs_recursive(data->domain, virq, nr_irqs); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1433 | mutex_unlock(&irq_domain_mutex); |
| 1434 | |
| 1435 | irq_domain_free_irq_data(virq, nr_irqs); |
| 1436 | irq_free_descs(virq, nr_irqs); |
| 1437 | } |
| 1438 | |
| 1439 | /** |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1440 | * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain |
| 1441 | * @irq_base: Base IRQ number |
| 1442 | * @nr_irqs: Number of IRQs to allocate |
| 1443 | * @arg: Allocation data (arch/domain specific) |
| 1444 | * |
| 1445 | * Check whether the domain has been setup recursive. If not allocate |
| 1446 | * through the parent domain. |
| 1447 | */ |
| 1448 | int irq_domain_alloc_irqs_parent(struct irq_domain *domain, |
| 1449 | unsigned int irq_base, unsigned int nr_irqs, |
| 1450 | void *arg) |
| 1451 | { |
| 1452 | /* irq_domain_alloc_irqs_recursive() has called parent's alloc() */ |
| 1453 | if (irq_domain_is_auto_recursive(domain)) |
| 1454 | return 0; |
| 1455 | |
| 1456 | domain = domain->parent; |
| 1457 | if (domain) |
| 1458 | return irq_domain_alloc_irqs_recursive(domain, irq_base, |
| 1459 | nr_irqs, arg); |
| 1460 | return -ENOSYS; |
| 1461 | } |
Quan Nguyen | 52b2a05 | 2016-03-03 21:56:52 +0700 | [diff] [blame] | 1462 | EXPORT_SYMBOL_GPL(irq_domain_alloc_irqs_parent); |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1463 | |
| 1464 | /** |
| 1465 | * irq_domain_free_irqs_parent - Free interrupts from parent domain |
| 1466 | * @irq_base: Base IRQ number |
| 1467 | * @nr_irqs: Number of IRQs to free |
| 1468 | * |
| 1469 | * Check whether the domain has been setup recursive. If not free |
| 1470 | * through the parent domain. |
| 1471 | */ |
| 1472 | void irq_domain_free_irqs_parent(struct irq_domain *domain, |
| 1473 | unsigned int irq_base, unsigned int nr_irqs) |
| 1474 | { |
| 1475 | /* irq_domain_free_irqs_recursive() will call parent's free */ |
| 1476 | if (!irq_domain_is_auto_recursive(domain) && domain->parent) |
| 1477 | irq_domain_free_irqs_recursive(domain->parent, irq_base, |
| 1478 | nr_irqs); |
| 1479 | } |
Quan Nguyen | 52b2a05 | 2016-03-03 21:56:52 +0700 | [diff] [blame] | 1480 | EXPORT_SYMBOL_GPL(irq_domain_free_irqs_parent); |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1481 | |
Marc Zyngier | 08d85f3 | 2017-01-17 16:00:48 +0000 | [diff] [blame] | 1482 | static void __irq_domain_activate_irq(struct irq_data *irq_data) |
| 1483 | { |
| 1484 | if (irq_data && irq_data->domain) { |
| 1485 | struct irq_domain *domain = irq_data->domain; |
| 1486 | |
| 1487 | if (irq_data->parent_data) |
| 1488 | __irq_domain_activate_irq(irq_data->parent_data); |
| 1489 | if (domain->ops->activate) |
| 1490 | domain->ops->activate(domain, irq_data); |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | static void __irq_domain_deactivate_irq(struct irq_data *irq_data) |
| 1495 | { |
| 1496 | if (irq_data && irq_data->domain) { |
| 1497 | struct irq_domain *domain = irq_data->domain; |
| 1498 | |
| 1499 | if (domain->ops->deactivate) |
| 1500 | domain->ops->deactivate(domain, irq_data); |
| 1501 | if (irq_data->parent_data) |
| 1502 | __irq_domain_deactivate_irq(irq_data->parent_data); |
| 1503 | } |
| 1504 | } |
| 1505 | |
Jiang Liu | 36d7273 | 2014-11-15 22:24:01 +0800 | [diff] [blame] | 1506 | /** |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1507 | * irq_domain_activate_irq - Call domain_ops->activate recursively to activate |
| 1508 | * interrupt |
| 1509 | * @irq_data: outermost irq_data associated with interrupt |
| 1510 | * |
| 1511 | * This is the second step to call domain_ops->activate to program interrupt |
| 1512 | * controllers, so the interrupt could actually get delivered. |
| 1513 | */ |
| 1514 | void irq_domain_activate_irq(struct irq_data *irq_data) |
| 1515 | { |
Marc Zyngier | 08d85f3 | 2017-01-17 16:00:48 +0000 | [diff] [blame] | 1516 | if (!irqd_is_activated(irq_data)) { |
| 1517 | __irq_domain_activate_irq(irq_data); |
| 1518 | irqd_set_activated(irq_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | /** |
| 1523 | * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to |
| 1524 | * deactivate interrupt |
| 1525 | * @irq_data: outermost irq_data associated with interrupt |
| 1526 | * |
| 1527 | * It calls domain_ops->deactivate to program interrupt controllers to disable |
| 1528 | * interrupt delivery. |
| 1529 | */ |
| 1530 | void irq_domain_deactivate_irq(struct irq_data *irq_data) |
| 1531 | { |
Marc Zyngier | 08d85f3 | 2017-01-17 16:00:48 +0000 | [diff] [blame] | 1532 | if (irqd_is_activated(irq_data)) { |
| 1533 | __irq_domain_deactivate_irq(irq_data); |
| 1534 | irqd_clr_activated(irq_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | static void irq_domain_check_hierarchy(struct irq_domain *domain) |
| 1539 | { |
| 1540 | /* Hierarchy irq_domains must implement callback alloc() */ |
| 1541 | if (domain->ops->alloc) |
| 1542 | domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY; |
| 1543 | } |
Eric Auger | 631a963 | 2017-01-19 20:57:57 +0000 | [diff] [blame] | 1544 | |
| 1545 | /** |
| 1546 | * irq_domain_hierarchical_is_msi_remap - Check if the domain or any |
| 1547 | * parent has MSI remapping support |
| 1548 | * @domain: domain pointer |
| 1549 | */ |
| 1550 | bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain) |
| 1551 | { |
| 1552 | for (; domain; domain = domain->parent) { |
| 1553 | if (irq_domain_is_msi_remap(domain)) |
| 1554 | return true; |
| 1555 | } |
| 1556 | return false; |
| 1557 | } |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1558 | #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ |
| 1559 | /** |
| 1560 | * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain |
| 1561 | * @domain: domain to match |
| 1562 | * @virq: IRQ number to get irq_data |
| 1563 | */ |
| 1564 | struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, |
| 1565 | unsigned int virq) |
| 1566 | { |
| 1567 | struct irq_data *irq_data = irq_get_irq_data(virq); |
| 1568 | |
| 1569 | return (irq_data && irq_data->domain == domain) ? irq_data : NULL; |
| 1570 | } |
Jake Oshins | a4289dc | 2015-12-10 17:52:59 +0000 | [diff] [blame] | 1571 | EXPORT_SYMBOL_GPL(irq_domain_get_irq_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1572 | |
Stefan Agner | 5f22f5c | 2015-05-16 11:44:13 +0200 | [diff] [blame] | 1573 | /** |
| 1574 | * irq_domain_set_info - Set the complete data for a @virq in @domain |
| 1575 | * @domain: Interrupt domain to match |
| 1576 | * @virq: IRQ number |
| 1577 | * @hwirq: The hardware interrupt number |
| 1578 | * @chip: The associated interrupt chip |
| 1579 | * @chip_data: The associated interrupt chip data |
| 1580 | * @handler: The interrupt flow handler |
| 1581 | * @handler_data: The interrupt flow handler data |
| 1582 | * @handler_name: The interrupt handler name |
| 1583 | */ |
| 1584 | void irq_domain_set_info(struct irq_domain *domain, unsigned int virq, |
| 1585 | irq_hw_number_t hwirq, struct irq_chip *chip, |
| 1586 | void *chip_data, irq_flow_handler_t handler, |
| 1587 | void *handler_data, const char *handler_name) |
| 1588 | { |
| 1589 | irq_set_chip_and_handler_name(virq, chip, handler, handler_name); |
| 1590 | irq_set_chip_data(virq, chip_data); |
| 1591 | irq_set_handler_data(virq, handler_data); |
| 1592 | } |
| 1593 | |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 1594 | static void irq_domain_check_hierarchy(struct irq_domain *domain) |
| 1595 | { |
| 1596 | } |
| 1597 | #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ |