blob: d1adaedb435f7d0dcc1589fdedba3c390efb34dc [file] [log] [blame]
Paul Mundt54a90582012-05-19 15:11:47 +09001#define pr_fmt(fmt) "irq: " fmt
2
Grant Likelycc79ca62012-02-16 01:37:49 -07003#include <linux/debugfs.h>
4#include <linux/hardirq.h>
5#include <linux/interrupt.h>
Grant Likely08a543a2011-07-26 03:19:06 -06006#include <linux/irq.h>
Grant Likelycc79ca62012-02-16 01:37:49 -07007#include <linux/irqdesc.h>
Grant Likely08a543a2011-07-26 03:19:06 -06008#include <linux/irqdomain.h>
9#include <linux/module.h>
10#include <linux/mutex.h>
11#include <linux/of.h>
Grant Likely7e713302011-07-26 03:19:06 -060012#include <linux/of_address.h>
Paul Mundt5ca4db62012-06-03 22:04:34 -070013#include <linux/topology.h>
Grant Likelycc79ca62012-02-16 01:37:49 -070014#include <linux/seq_file.h>
Grant Likely7e713302011-07-26 03:19:06 -060015#include <linux/slab.h>
Grant Likelycc79ca62012-02-16 01:37:49 -070016#include <linux/smp.h>
17#include <linux/fs.h>
Grant Likely08a543a2011-07-26 03:19:06 -060018
Grant Likely1bc04f22012-02-14 14:06:55 -070019#define IRQ_DOMAIN_MAP_LEGACY 0 /* driver allocated fixed range of irqs.
20 * ie. legacy 8259, gets irqs 1..15 */
Grant Likelya8db8cf2012-02-14 14:06:54 -070021#define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */
22#define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */
23#define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */
24
Grant Likely08a543a2011-07-26 03:19:06 -060025static LIST_HEAD(irq_domain_list);
26static DEFINE_MUTEX(irq_domain_mutex);
27
Grant Likelycc79ca62012-02-16 01:37:49 -070028static DEFINE_MUTEX(revmap_trees_mutex);
Grant Likely68700652012-02-14 14:06:53 -070029static struct irq_domain *irq_default_domain;
Grant Likelycc79ca62012-02-16 01:37:49 -070030
Grant Likelycc79ca62012-02-16 01:37:49 -070031/**
Grant Likelya8db8cf2012-02-14 14:06:54 -070032 * irq_domain_alloc() - Allocate a new irq_domain data structure
Grant Likelycc79ca62012-02-16 01:37:49 -070033 * @of_node: optional device-tree node of the interrupt controller
34 * @revmap_type: type of reverse mapping to use
Grant Likely68700652012-02-14 14:06:53 -070035 * @ops: map/unmap domain callbacks
Grant Likelya8db8cf2012-02-14 14:06:54 -070036 * @host_data: Controller private data pointer
Grant Likelycc79ca62012-02-16 01:37:49 -070037 *
Grant Likelya8db8cf2012-02-14 14:06:54 -070038 * Allocates and initialize and irq_domain structure. Caller is expected to
39 * register allocated irq_domain with irq_domain_register(). Returns pointer
40 * to IRQ domain, or NULL on failure.
Grant Likelycc79ca62012-02-16 01:37:49 -070041 */
Grant Likelya8db8cf2012-02-14 14:06:54 -070042static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
43 unsigned int revmap_type,
Grant Likelya18dc812012-01-26 12:12:14 -070044 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -070045 void *host_data)
Grant Likelycc79ca62012-02-16 01:37:49 -070046{
Grant Likelya8db8cf2012-02-14 14:06:54 -070047 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -070048
Paul Mundt5ca4db62012-06-03 22:04:34 -070049 domain = kzalloc_node(sizeof(*domain), GFP_KERNEL,
50 of_node_to_nid(of_node));
Grant Likelya8db8cf2012-02-14 14:06:54 -070051 if (WARN_ON(!domain))
Grant Likelycc79ca62012-02-16 01:37:49 -070052 return NULL;
53
54 /* Fill structure */
Grant Likely68700652012-02-14 14:06:53 -070055 domain->revmap_type = revmap_type;
Grant Likely68700652012-02-14 14:06:53 -070056 domain->ops = ops;
Grant Likelya8db8cf2012-02-14 14:06:54 -070057 domain->host_data = host_data;
Grant Likely68700652012-02-14 14:06:53 -070058 domain->of_node = of_node_get(of_node);
Grant Likelycc79ca62012-02-16 01:37:49 -070059
Grant Likelya8db8cf2012-02-14 14:06:54 -070060 return domain;
61}
62
Paul Mundt58ee99a2012-05-19 15:11:41 +090063static void irq_domain_free(struct irq_domain *domain)
64{
65 of_node_put(domain->of_node);
66 kfree(domain);
67}
68
Grant Likelya8db8cf2012-02-14 14:06:54 -070069static void irq_domain_add(struct irq_domain *domain)
70{
71 mutex_lock(&irq_domain_mutex);
72 list_add(&domain->link, &irq_domain_list);
73 mutex_unlock(&irq_domain_mutex);
Paul Mundt54a90582012-05-19 15:11:47 +090074 pr_debug("Allocated domain of type %d @0x%p\n",
Grant Likelya8db8cf2012-02-14 14:06:54 -070075 domain->revmap_type, domain);
76}
77
Paul Mundt58ee99a2012-05-19 15:11:41 +090078/**
79 * irq_domain_remove() - Remove an irq domain.
80 * @domain: domain to remove
81 *
82 * This routine is used to remove an irq domain. The caller must ensure
83 * that all mappings within the domain have been disposed of prior to
84 * use, depending on the revmap type.
85 */
86void irq_domain_remove(struct irq_domain *domain)
87{
88 mutex_lock(&irq_domain_mutex);
89
90 switch (domain->revmap_type) {
91 case IRQ_DOMAIN_MAP_LEGACY:
92 /*
93 * Legacy domains don't manage their own irq_desc
94 * allocations, we expect the caller to handle irq_desc
95 * freeing on their own.
96 */
97 break;
98 case IRQ_DOMAIN_MAP_TREE:
99 /*
100 * radix_tree_delete() takes care of destroying the root
101 * node when all entries are removed. Shout if there are
102 * any mappings left.
103 */
104 WARN_ON(domain->revmap_data.tree.height);
105 break;
106 case IRQ_DOMAIN_MAP_LINEAR:
107 kfree(domain->revmap_data.linear.revmap);
108 domain->revmap_data.linear.size = 0;
109 break;
110 case IRQ_DOMAIN_MAP_NOMAP:
111 break;
112 }
113
114 list_del(&domain->link);
115
116 /*
117 * If the going away domain is the default one, reset it.
118 */
119 if (unlikely(irq_default_domain == domain))
120 irq_set_default_host(NULL);
121
122 mutex_unlock(&irq_domain_mutex);
123
Paul Mundt54a90582012-05-19 15:11:47 +0900124 pr_debug("Removed domain of type %d @0x%p\n",
Paul Mundt58ee99a2012-05-19 15:11:41 +0900125 domain->revmap_type, domain);
126
127 irq_domain_free(domain);
128}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900129EXPORT_SYMBOL_GPL(irq_domain_remove);
Paul Mundt58ee99a2012-05-19 15:11:41 +0900130
Grant Likely1bc04f22012-02-14 14:06:55 -0700131static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
132 irq_hw_number_t hwirq)
133{
134 irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq;
135 int size = domain->revmap_data.legacy.size;
136
137 if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
138 return 0;
139 return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq;
140}
141
Grant Likelya8db8cf2012-02-14 14:06:54 -0700142/**
Mark Brown781d0f42012-07-05 12:19:19 +0100143 * irq_domain_add_simple() - Allocate and register a simple irq_domain.
144 * @of_node: pointer to interrupt controller's device tree node.
145 * @size: total number of irqs in mapping
146 * @first_irq: first number of irq block assigned to the domain
147 * @ops: map/unmap domain callbacks
148 * @host_data: Controller private data pointer
149 *
150 * Allocates a legacy irq_domain if irq_base is positive or a linear
Linus Walleij2854d162012-09-27 14:59:39 +0200151 * domain otherwise. For the legacy domain, IRQ descriptors will also
152 * be allocated.
Mark Brown781d0f42012-07-05 12:19:19 +0100153 *
154 * This is intended to implement the expected behaviour for most
155 * interrupt controllers which is that a linear mapping should
156 * normally be used unless the system requires a legacy mapping in
157 * order to support supplying interrupt numbers during non-DT
158 * registration of devices.
159 */
160struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
161 unsigned int size,
162 unsigned int first_irq,
163 const struct irq_domain_ops *ops,
164 void *host_data)
165{
Linus Walleij2854d162012-09-27 14:59:39 +0200166 if (first_irq > 0) {
167 int irq_base;
168
169 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
170 /*
171 * Set the descriptor allocator to search for a
172 * 1-to-1 mapping, such as irq_alloc_desc_at().
173 * Use of_node_to_nid() which is defined to
174 * numa_node_id() on platforms that have no custom
175 * implementation.
176 */
177 irq_base = irq_alloc_descs(first_irq, first_irq, size,
178 of_node_to_nid(of_node));
179 if (irq_base < 0) {
Linus Walleijd202b7b2012-11-27 01:20:32 +0100180 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
181 first_irq);
Linus Walleij2854d162012-09-27 14:59:39 +0200182 irq_base = first_irq;
183 }
184 } else
185 irq_base = first_irq;
186
187 return irq_domain_add_legacy(of_node, size, irq_base, 0,
Mark Brown781d0f42012-07-05 12:19:19 +0100188 ops, host_data);
Linus Walleij2854d162012-09-27 14:59:39 +0200189 }
190
191 /* A linear domain is the default */
192 return irq_domain_add_linear(of_node, size, ops, host_data);
Mark Brown781d0f42012-07-05 12:19:19 +0100193}
Arnd Bergmann346dbb72013-04-25 19:28:54 +0200194EXPORT_SYMBOL_GPL(irq_domain_add_simple);
Mark Brown781d0f42012-07-05 12:19:19 +0100195
196/**
Grant Likelya8db8cf2012-02-14 14:06:54 -0700197 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
198 * @of_node: pointer to interrupt controller's device tree node.
Grant Likely1bc04f22012-02-14 14:06:55 -0700199 * @size: total number of irqs in legacy mapping
200 * @first_irq: first number of irq block assigned to the domain
201 * @first_hwirq: first hwirq number to use for the translation. Should normally
202 * be '0', but a positive integer can be used if the effective
203 * hwirqs numbering does not begin at zero.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700204 * @ops: map/unmap domain callbacks
205 * @host_data: Controller private data pointer
206 *
207 * Note: the map() callback will be called before this function returns
208 * for all legacy interrupts except 0 (which is always the invalid irq for
209 * a legacy controller).
210 */
211struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
Grant Likely1bc04f22012-02-14 14:06:55 -0700212 unsigned int size,
213 unsigned int first_irq,
214 irq_hw_number_t first_hwirq,
Grant Likelya18dc812012-01-26 12:12:14 -0700215 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700216 void *host_data)
217{
Grant Likely1bc04f22012-02-14 14:06:55 -0700218 struct irq_domain *domain;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700219 unsigned int i;
220
221 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
222 if (!domain)
223 return NULL;
224
Grant Likely1bc04f22012-02-14 14:06:55 -0700225 domain->revmap_data.legacy.first_irq = first_irq;
226 domain->revmap_data.legacy.first_hwirq = first_hwirq;
227 domain->revmap_data.legacy.size = size;
228
Grant Likelycc79ca62012-02-16 01:37:49 -0700229 mutex_lock(&irq_domain_mutex);
Grant Likely1bc04f22012-02-14 14:06:55 -0700230 /* Verify that all the irqs are available */
231 for (i = 0; i < size; i++) {
232 int irq = first_irq + i;
233 struct irq_data *irq_data = irq_get_irq_data(irq);
234
235 if (WARN_ON(!irq_data || irq_data->domain)) {
Grant Likelya8db8cf2012-02-14 14:06:54 -0700236 mutex_unlock(&irq_domain_mutex);
Paul Mundt58ee99a2012-05-19 15:11:41 +0900237 irq_domain_free(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700238 return NULL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700239 }
240 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700241
242 /* Claim all of the irqs before registering a legacy domain */
243 for (i = 0; i < size; i++) {
244 struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
245 irq_data->hwirq = first_hwirq + i;
246 irq_data->domain = domain;
247 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700248 mutex_unlock(&irq_domain_mutex);
249
Grant Likely1bc04f22012-02-14 14:06:55 -0700250 for (i = 0; i < size; i++) {
251 int irq = first_irq + i;
252 int hwirq = first_hwirq + i;
253
254 /* IRQ0 gets ignored */
255 if (!irq)
256 continue;
Grant Likelycc79ca62012-02-16 01:37:49 -0700257
Grant Likelya8db8cf2012-02-14 14:06:54 -0700258 /* Legacy flags are left to default at this point,
259 * one can then use irq_create_mapping() to
260 * explicitly change them
261 */
Grant Likelyaed98042012-06-03 22:04:39 -0700262 if (ops->map)
263 ops->map(domain, irq, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700264
Grant Likelya8db8cf2012-02-14 14:06:54 -0700265 /* Clear norequest flags */
Grant Likely1bc04f22012-02-14 14:06:55 -0700266 irq_clear_status_flags(irq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700267 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700268
269 irq_domain_add(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700270 return domain;
271}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900272EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
Grant Likelycc79ca62012-02-16 01:37:49 -0700273
Grant Likelya8db8cf2012-02-14 14:06:54 -0700274/**
Dong Aisheng22076c72012-06-20 17:00:30 +0800275 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700276 * @of_node: pointer to interrupt controller's device tree node.
Mark Browna87487e2012-05-19 12:15:35 +0100277 * @size: Number of interrupts in the domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700278 * @ops: map/unmap domain callbacks
279 * @host_data: Controller private data pointer
280 */
281struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
282 unsigned int size,
Grant Likelya18dc812012-01-26 12:12:14 -0700283 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700284 void *host_data)
285{
286 struct irq_domain *domain;
287 unsigned int *revmap;
Grant Likelycc79ca62012-02-16 01:37:49 -0700288
Paul Mundt5ca4db62012-06-03 22:04:34 -0700289 revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
290 of_node_to_nid(of_node));
Grant Likelya8db8cf2012-02-14 14:06:54 -0700291 if (WARN_ON(!revmap))
292 return NULL;
293
294 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
295 if (!domain) {
296 kfree(revmap);
297 return NULL;
298 }
299 domain->revmap_data.linear.size = size;
300 domain->revmap_data.linear.revmap = revmap;
301 irq_domain_add(domain);
302 return domain;
303}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900304EXPORT_SYMBOL_GPL(irq_domain_add_linear);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700305
306struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700307 unsigned int max_irq,
Grant Likelya18dc812012-01-26 12:12:14 -0700308 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700309 void *host_data)
310{
311 struct irq_domain *domain = irq_domain_alloc(of_node,
312 IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700313 if (domain) {
314 domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700315 irq_domain_add(domain);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700316 }
Grant Likelya8db8cf2012-02-14 14:06:54 -0700317 return domain;
318}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900319EXPORT_SYMBOL_GPL(irq_domain_add_nomap);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700320
321/**
322 * irq_domain_add_tree()
323 * @of_node: pointer to interrupt controller's device tree node.
324 * @ops: map/unmap domain callbacks
325 *
326 * Note: The radix tree will be allocated later during boot automatically
327 * (the reverse mapping will use the slow path until that happens).
328 */
329struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
Grant Likelya18dc812012-01-26 12:12:14 -0700330 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700331 void *host_data)
332{
333 struct irq_domain *domain = irq_domain_alloc(of_node,
334 IRQ_DOMAIN_MAP_TREE, ops, host_data);
335 if (domain) {
336 INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
337 irq_domain_add(domain);
338 }
Grant Likely68700652012-02-14 14:06:53 -0700339 return domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700340}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900341EXPORT_SYMBOL_GPL(irq_domain_add_tree);
Grant Likelycc79ca62012-02-16 01:37:49 -0700342
343/**
344 * irq_find_host() - Locates a domain for a given device node
345 * @node: device-tree node of the interrupt controller
346 */
347struct irq_domain *irq_find_host(struct device_node *node)
348{
349 struct irq_domain *h, *found = NULL;
Grant Likelya18dc812012-01-26 12:12:14 -0700350 int rc;
Grant Likelycc79ca62012-02-16 01:37:49 -0700351
352 /* We might want to match the legacy controller last since
353 * it might potentially be set to match all interrupts in
354 * the absence of a device node. This isn't a problem so far
355 * yet though...
356 */
357 mutex_lock(&irq_domain_mutex);
Grant Likelya18dc812012-01-26 12:12:14 -0700358 list_for_each_entry(h, &irq_domain_list, link) {
359 if (h->ops->match)
360 rc = h->ops->match(h, node);
361 else
362 rc = (h->of_node != NULL) && (h->of_node == node);
363
364 if (rc) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700365 found = h;
366 break;
367 }
Grant Likelya18dc812012-01-26 12:12:14 -0700368 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700369 mutex_unlock(&irq_domain_mutex);
370 return found;
371}
372EXPORT_SYMBOL_GPL(irq_find_host);
373
374/**
375 * irq_set_default_host() - Set a "default" irq domain
Grant Likely68700652012-02-14 14:06:53 -0700376 * @domain: default domain pointer
Grant Likelycc79ca62012-02-16 01:37:49 -0700377 *
378 * For convenience, it's possible to set a "default" domain that will be used
379 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
380 * platforms that want to manipulate a few hard coded interrupt numbers that
381 * aren't properly represented in the device-tree.
382 */
Grant Likely68700652012-02-14 14:06:53 -0700383void irq_set_default_host(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700384{
Paul Mundt54a90582012-05-19 15:11:47 +0900385 pr_debug("Default domain set to @0x%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700386
Grant Likely68700652012-02-14 14:06:53 -0700387 irq_default_domain = domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700388}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900389EXPORT_SYMBOL_GPL(irq_set_default_host);
Grant Likelycc79ca62012-02-16 01:37:49 -0700390
Grant Likely913af202012-06-03 22:04:35 -0700391static void irq_domain_disassociate_many(struct irq_domain *domain,
392 unsigned int irq_base, int count)
393{
394 /*
395 * disassociate in reverse order;
396 * not strictly necessary, but nice for unwinding
397 */
398 while (count--) {
399 int irq = irq_base + count;
400 struct irq_data *irq_data = irq_get_irq_data(irq);
401 irq_hw_number_t hwirq = irq_data->hwirq;
402
403 if (WARN_ON(!irq_data || irq_data->domain != domain))
404 continue;
405
406 irq_set_status_flags(irq, IRQ_NOREQUEST);
407
408 /* remove chip and handler */
409 irq_set_chip_and_handler(irq, NULL, NULL);
410
411 /* Make sure it's completed */
412 synchronize_irq(irq);
413
414 /* Tell the PIC about it */
415 if (domain->ops->unmap)
416 domain->ops->unmap(domain, irq);
417 smp_mb();
418
419 irq_data->domain = NULL;
420 irq_data->hwirq = 0;
421
422 /* Clear reverse map */
423 switch(domain->revmap_type) {
424 case IRQ_DOMAIN_MAP_LINEAR:
425 if (hwirq < domain->revmap_data.linear.size)
426 domain->revmap_data.linear.revmap[hwirq] = 0;
427 break;
428 case IRQ_DOMAIN_MAP_TREE:
429 mutex_lock(&revmap_trees_mutex);
430 radix_tree_delete(&domain->revmap_data.tree, hwirq);
431 mutex_unlock(&revmap_trees_mutex);
432 break;
433 }
434 }
435}
436
Grant Likely98aa4682012-06-17 16:17:04 -0600437int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
438 irq_hw_number_t hwirq_base, int count)
Grant Likelycc79ca62012-02-16 01:37:49 -0700439{
Grant Likely98aa4682012-06-17 16:17:04 -0600440 unsigned int virq = irq_base;
441 irq_hw_number_t hwirq = hwirq_base;
Mark Brownf5a1ad02012-07-20 10:33:19 +0100442 int i, ret;
Grant Likelycc79ca62012-02-16 01:37:49 -0700443
Grant Likely98aa4682012-06-17 16:17:04 -0600444 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
445 of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
446
447 for (i = 0; i < count; i++) {
448 struct irq_data *irq_data = irq_get_irq_data(virq + i);
449
450 if (WARN(!irq_data, "error: irq_desc not allocated; "
451 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
452 return -EINVAL;
453 if (WARN(irq_data->domain, "error: irq_desc already associated; "
454 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
455 return -EINVAL;
456 };
457
458 for (i = 0; i < count; i++, virq++, hwirq++) {
459 struct irq_data *irq_data = irq_get_irq_data(virq);
460
461 irq_data->hwirq = hwirq;
462 irq_data->domain = domain;
Mark Brownf5a1ad02012-07-20 10:33:19 +0100463 if (domain->ops->map) {
464 ret = domain->ops->map(domain, virq, hwirq);
465 if (ret != 0) {
Benjamin Herrenschmidt5fe0c1f2013-05-06 11:37:43 +1000466 /*
467 * If map() returns -EPERM, this interrupt is protected
468 * by the firmware or some other service and shall not
469 * be mapped.
470 *
471 * Since on some platforms we blindly try to map everything
472 * we end up with a log full of backtraces.
473 *
474 * So instead, we silently fail on -EPERM, it is the
475 * responsibility of the PIC driver to display a relevant
476 * message if needed.
477 */
478 if (ret != -EPERM) {
479 pr_err("irq-%i==>hwirq-0x%lx mapping failed: %d\n",
480 virq, hwirq, ret);
481 WARN_ON(1);
482 }
Mark Brownf5a1ad02012-07-20 10:33:19 +0100483 irq_data->domain = NULL;
484 irq_data->hwirq = 0;
485 goto err_unmap;
486 }
Grant Likely98aa4682012-06-17 16:17:04 -0600487 }
488
489 switch (domain->revmap_type) {
490 case IRQ_DOMAIN_MAP_LINEAR:
491 if (hwirq < domain->revmap_data.linear.size)
492 domain->revmap_data.linear.revmap[hwirq] = virq;
493 break;
494 case IRQ_DOMAIN_MAP_TREE:
495 mutex_lock(&revmap_trees_mutex);
Grant Likelyd6b0d1f2012-06-03 22:04:37 -0700496 radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
Grant Likely98aa4682012-06-17 16:17:04 -0600497 mutex_unlock(&revmap_trees_mutex);
498 break;
499 }
500
501 irq_clear_status_flags(virq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700502 }
503
Grant Likelycc79ca62012-02-16 01:37:49 -0700504 return 0;
Grant Likely98aa4682012-06-17 16:17:04 -0600505
506 err_unmap:
507 irq_domain_disassociate_many(domain, irq_base, i);
508 return -EINVAL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700509}
Grant Likely98aa4682012-06-17 16:17:04 -0600510EXPORT_SYMBOL_GPL(irq_domain_associate_many);
Grant Likelycc79ca62012-02-16 01:37:49 -0700511
512/**
513 * irq_create_direct_mapping() - Allocate an irq for direct mapping
Grant Likely68700652012-02-14 14:06:53 -0700514 * @domain: domain to allocate the irq for or NULL for default domain
Grant Likelycc79ca62012-02-16 01:37:49 -0700515 *
516 * This routine is used for irq controllers which can choose the hardware
517 * interrupt numbers they generate. In such a case it's simplest to use
518 * the linux irq as the hardware interrupt number.
519 */
Grant Likely68700652012-02-14 14:06:53 -0700520unsigned int irq_create_direct_mapping(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700521{
522 unsigned int virq;
523
Grant Likely68700652012-02-14 14:06:53 -0700524 if (domain == NULL)
525 domain = irq_default_domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700526
Grant Likely9844a552012-06-03 22:04:38 -0700527 if (WARN_ON(!domain || domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP))
528 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700529
Paul Mundt5ca4db62012-06-03 22:04:34 -0700530 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
Grant Likely03848372012-02-14 14:06:52 -0700531 if (!virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900532 pr_debug("create_direct virq allocation failed\n");
Grant Likely03848372012-02-14 14:06:52 -0700533 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700534 }
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700535 if (virq >= domain->revmap_data.nomap.max_irq) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700536 pr_err("ERROR: no free irqs available below %i maximum\n",
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700537 domain->revmap_data.nomap.max_irq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700538 irq_free_desc(virq);
539 return 0;
540 }
Paul Mundt54a90582012-05-19 15:11:47 +0900541 pr_debug("create_direct obtained virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700542
Grant Likely98aa4682012-06-17 16:17:04 -0600543 if (irq_domain_associate(domain, virq, virq)) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700544 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700545 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700546 }
547
548 return virq;
549}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900550EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
Grant Likelycc79ca62012-02-16 01:37:49 -0700551
552/**
553 * irq_create_mapping() - Map a hardware interrupt into linux irq space
Grant Likely68700652012-02-14 14:06:53 -0700554 * @domain: domain owning this hardware interrupt or NULL for default domain
555 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700556 *
557 * Only one mapping per hardware interrupt is permitted. Returns a linux
558 * irq number.
559 * If the sense/trigger is to be specified, set_irq_type() should be called
560 * on the number returned from that call.
561 */
Grant Likely68700652012-02-14 14:06:53 -0700562unsigned int irq_create_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700563 irq_hw_number_t hwirq)
564{
David Daney5b7526e2012-04-05 16:52:13 -0700565 unsigned int hint;
566 int virq;
Grant Likelycc79ca62012-02-16 01:37:49 -0700567
Paul Mundt54a90582012-05-19 15:11:47 +0900568 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700569
Grant Likely68700652012-02-14 14:06:53 -0700570 /* Look for default domain if nececssary */
571 if (domain == NULL)
572 domain = irq_default_domain;
573 if (domain == NULL) {
Paul Mundt54a90582012-05-19 15:11:47 +0900574 pr_warning("irq_create_mapping called for"
575 " NULL domain, hwirq=%lx\n", hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700576 WARN_ON(1);
Grant Likely03848372012-02-14 14:06:52 -0700577 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700578 }
Paul Mundt54a90582012-05-19 15:11:47 +0900579 pr_debug("-> using domain @%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700580
581 /* Check if mapping already exists */
Grant Likely68700652012-02-14 14:06:53 -0700582 virq = irq_find_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700583 if (virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900584 pr_debug("-> existing mapping on virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700585 return virq;
586 }
587
588 /* Get a virtual interrupt number */
Grant Likely1bc04f22012-02-14 14:06:55 -0700589 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
590 return irq_domain_legacy_revmap(domain, hwirq);
591
592 /* Allocate a virtual interrupt number */
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700593 hint = hwirq % nr_irqs;
Grant Likely1bc04f22012-02-14 14:06:55 -0700594 if (hint == 0)
595 hint++;
Paul Mundt5ca4db62012-06-03 22:04:34 -0700596 virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700597 if (virq <= 0)
Paul Mundt5ca4db62012-06-03 22:04:34 -0700598 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700599 if (virq <= 0) {
Paul Mundt54a90582012-05-19 15:11:47 +0900600 pr_debug("-> virq allocation failed\n");
Grant Likely1bc04f22012-02-14 14:06:55 -0700601 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700602 }
603
Grant Likely98aa4682012-06-17 16:17:04 -0600604 if (irq_domain_associate(domain, virq, hwirq)) {
Grant Likely73255702012-06-03 22:04:35 -0700605 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700606 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700607 }
608
Paul Mundt54a90582012-05-19 15:11:47 +0900609 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700610 hwirq, of_node_full_name(domain->of_node), virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700611
612 return virq;
613}
614EXPORT_SYMBOL_GPL(irq_create_mapping);
615
Grant Likely98aa4682012-06-17 16:17:04 -0600616/**
617 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
618 * @domain: domain owning the interrupt range
619 * @irq_base: beginning of linux IRQ range
620 * @hwirq_base: beginning of hardware IRQ range
621 * @count: Number of interrupts to map
622 *
623 * This routine is used for allocating and mapping a range of hardware
624 * irqs to linux irqs where the linux irq numbers are at pre-defined
625 * locations. For use by controllers that already have static mappings
626 * to insert in to the domain.
627 *
628 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
629 * domain insertion.
630 *
631 * 0 is returned upon success, while any failure to establish a static
632 * mapping is treated as an error.
633 */
634int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
635 irq_hw_number_t hwirq_base, int count)
636{
637 int ret;
638
639 ret = irq_alloc_descs(irq_base, irq_base, count,
640 of_node_to_nid(domain->of_node));
641 if (unlikely(ret < 0))
642 return ret;
643
644 ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
645 if (unlikely(ret < 0)) {
646 irq_free_descs(irq_base, count);
647 return ret;
648 }
649
650 return 0;
651}
652EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
653
Grant Likelycc79ca62012-02-16 01:37:49 -0700654unsigned int irq_create_of_mapping(struct device_node *controller,
655 const u32 *intspec, unsigned int intsize)
656{
Grant Likely68700652012-02-14 14:06:53 -0700657 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700658 irq_hw_number_t hwirq;
659 unsigned int type = IRQ_TYPE_NONE;
660 unsigned int virq;
661
Grant Likely68700652012-02-14 14:06:53 -0700662 domain = controller ? irq_find_host(controller) : irq_default_domain;
663 if (!domain) {
Grant Likelyabd23632012-02-24 08:07:06 -0700664#ifdef CONFIG_MIPS
665 /*
666 * Workaround to avoid breaking interrupt controller drivers
667 * that don't yet register an irq_domain. This is temporary
668 * code. ~~~gcl, Feb 24, 2012
669 *
670 * Scheduled for removal in Linux v3.6. That should be enough
671 * time.
672 */
673 if (intsize > 0)
674 return intspec[0];
675#endif
Paul Mundt54a90582012-05-19 15:11:47 +0900676 pr_warning("no irq domain found for %s !\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700677 of_node_full_name(controller));
Grant Likely03848372012-02-14 14:06:52 -0700678 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700679 }
680
Grant Likely68700652012-02-14 14:06:53 -0700681 /* If domain has no translation, then we assume interrupt line */
682 if (domain->ops->xlate == NULL)
Grant Likelycc79ca62012-02-16 01:37:49 -0700683 hwirq = intspec[0];
684 else {
Grant Likely68700652012-02-14 14:06:53 -0700685 if (domain->ops->xlate(domain, controller, intspec, intsize,
Grant Likelycc79ca62012-02-16 01:37:49 -0700686 &hwirq, &type))
Grant Likely03848372012-02-14 14:06:52 -0700687 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700688 }
689
690 /* Create mapping */
Grant Likely68700652012-02-14 14:06:53 -0700691 virq = irq_create_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700692 if (!virq)
Grant Likelycc79ca62012-02-16 01:37:49 -0700693 return virq;
694
695 /* Set type if specified and different than the current one */
696 if (type != IRQ_TYPE_NONE &&
697 type != (irqd_get_trigger_type(irq_get_irq_data(virq))))
698 irq_set_irq_type(virq, type);
699 return virq;
700}
701EXPORT_SYMBOL_GPL(irq_create_of_mapping);
702
703/**
704 * irq_dispose_mapping() - Unmap an interrupt
705 * @virq: linux irq number of the interrupt to unmap
706 */
707void irq_dispose_mapping(unsigned int virq)
708{
709 struct irq_data *irq_data = irq_get_irq_data(virq);
Grant Likely68700652012-02-14 14:06:53 -0700710 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700711
Grant Likely03848372012-02-14 14:06:52 -0700712 if (!virq || !irq_data)
Grant Likelycc79ca62012-02-16 01:37:49 -0700713 return;
714
Grant Likely68700652012-02-14 14:06:53 -0700715 domain = irq_data->domain;
716 if (WARN_ON(domain == NULL))
Grant Likelycc79ca62012-02-16 01:37:49 -0700717 return;
718
719 /* Never unmap legacy interrupts */
Grant Likely68700652012-02-14 14:06:53 -0700720 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
Grant Likelycc79ca62012-02-16 01:37:49 -0700721 return;
722
Grant Likely913af202012-06-03 22:04:35 -0700723 irq_domain_disassociate_many(domain, virq, 1);
Grant Likelycc79ca62012-02-16 01:37:49 -0700724 irq_free_desc(virq);
725}
726EXPORT_SYMBOL_GPL(irq_dispose_mapping);
727
728/**
729 * irq_find_mapping() - Find a linux irq from an hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700730 * @domain: domain owning this hardware interrupt
731 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700732 */
Grant Likely68700652012-02-14 14:06:53 -0700733unsigned int irq_find_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700734 irq_hw_number_t hwirq)
735{
Grant Likely4c0946c2012-06-03 22:04:39 -0700736 struct irq_data *data;
Grant Likelycc79ca62012-02-16 01:37:49 -0700737
Grant Likely68700652012-02-14 14:06:53 -0700738 /* Look for default domain if nececssary */
739 if (domain == NULL)
740 domain = irq_default_domain;
741 if (domain == NULL)
Grant Likely03848372012-02-14 14:06:52 -0700742 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700743
Grant Likely4c0946c2012-06-03 22:04:39 -0700744 switch (domain->revmap_type) {
745 case IRQ_DOMAIN_MAP_LEGACY:
Grant Likely1bc04f22012-02-14 14:06:55 -0700746 return irq_domain_legacy_revmap(domain, hwirq);
Grant Likely4c0946c2012-06-03 22:04:39 -0700747 case IRQ_DOMAIN_MAP_LINEAR:
748 return irq_linear_revmap(domain, hwirq);
749 case IRQ_DOMAIN_MAP_TREE:
750 rcu_read_lock();
751 data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
752 rcu_read_unlock();
753 if (data)
754 return data->irq;
755 break;
756 case IRQ_DOMAIN_MAP_NOMAP:
757 data = irq_get_irq_data(hwirq);
Grant Likely68700652012-02-14 14:06:53 -0700758 if (data && (data->domain == domain) && (data->hwirq == hwirq))
Grant Likely4c0946c2012-06-03 22:04:39 -0700759 return hwirq;
760 break;
761 }
762
Grant Likely03848372012-02-14 14:06:52 -0700763 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700764}
765EXPORT_SYMBOL_GPL(irq_find_mapping);
766
767/**
Grant Likelycc79ca62012-02-16 01:37:49 -0700768 * irq_linear_revmap() - Find a linux irq from a hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700769 * @domain: domain owning this hardware interrupt
770 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700771 *
Grant Likely4c0946c2012-06-03 22:04:39 -0700772 * This is a fast path that can be called directly by irq controller code to
773 * save a handful of instructions.
Grant Likelycc79ca62012-02-16 01:37:49 -0700774 */
Grant Likely68700652012-02-14 14:06:53 -0700775unsigned int irq_linear_revmap(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700776 irq_hw_number_t hwirq)
777{
Grant Likely4c0946c2012-06-03 22:04:39 -0700778 BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
Grant Likelycc79ca62012-02-16 01:37:49 -0700779
Grant Likely4c0946c2012-06-03 22:04:39 -0700780 /* Check revmap bounds; complain if exceeded */
781 if (WARN_ON(hwirq >= domain->revmap_data.linear.size))
782 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700783
Grant Likely4c0946c2012-06-03 22:04:39 -0700784 return domain->revmap_data.linear.revmap[hwirq];
Grant Likelycc79ca62012-02-16 01:37:49 -0700785}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900786EXPORT_SYMBOL_GPL(irq_linear_revmap);
Grant Likelycc79ca62012-02-16 01:37:49 -0700787
Grant Likely092b2fb2012-03-29 14:10:30 -0600788#ifdef CONFIG_IRQ_DOMAIN_DEBUG
Grant Likelycc79ca62012-02-16 01:37:49 -0700789static int virq_debug_show(struct seq_file *m, void *private)
790{
791 unsigned long flags;
792 struct irq_desc *desc;
793 const char *p;
794 static const char none[] = "none";
795 void *data;
796 int i;
797
Grant Likely15e06bf2012-04-11 00:26:25 -0600798 seq_printf(m, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
Grant Likely5269a9a2012-04-12 14:42:15 -0600799 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
800 "domain name");
Grant Likelycc79ca62012-02-16 01:37:49 -0700801
802 for (i = 1; i < nr_irqs; i++) {
803 desc = irq_to_desc(i);
804 if (!desc)
805 continue;
806
807 raw_spin_lock_irqsave(&desc->lock, flags);
808
809 if (desc->action && desc->action->handler) {
810 struct irq_chip *chip;
811
812 seq_printf(m, "%5d ", i);
813 seq_printf(m, "0x%05lx ", desc->irq_data.hwirq);
814
815 chip = irq_desc_get_chip(desc);
816 if (chip && chip->name)
817 p = chip->name;
818 else
819 p = none;
820 seq_printf(m, "%-15s ", p);
821
822 data = irq_desc_get_chip_data(desc);
Grant Likely15e06bf2012-04-11 00:26:25 -0600823 seq_printf(m, data ? "0x%p " : " %p ", data);
Grant Likelycc79ca62012-02-16 01:37:49 -0700824
Grant Likelyefd68e72012-06-03 22:04:33 -0700825 if (desc->irq_data.domain)
826 p = of_node_full_name(desc->irq_data.domain->of_node);
Grant Likelycc79ca62012-02-16 01:37:49 -0700827 else
828 p = none;
829 seq_printf(m, "%s\n", p);
830 }
831
832 raw_spin_unlock_irqrestore(&desc->lock, flags);
833 }
834
835 return 0;
836}
837
838static int virq_debug_open(struct inode *inode, struct file *file)
839{
840 return single_open(file, virq_debug_show, inode->i_private);
841}
842
843static const struct file_operations virq_debug_fops = {
844 .open = virq_debug_open,
845 .read = seq_read,
846 .llseek = seq_lseek,
847 .release = single_release,
848};
849
850static int __init irq_debugfs_init(void)
851{
Grant Likely092b2fb2012-03-29 14:10:30 -0600852 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
Grant Likelycc79ca62012-02-16 01:37:49 -0700853 NULL, &virq_debug_fops) == NULL)
854 return -ENOMEM;
855
856 return 0;
857}
858__initcall(irq_debugfs_init);
Grant Likely092b2fb2012-03-29 14:10:30 -0600859#endif /* CONFIG_IRQ_DOMAIN_DEBUG */
Grant Likelycc79ca62012-02-16 01:37:49 -0700860
Grant Likely16b2e6e2012-01-26 11:26:52 -0700861/**
862 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
863 *
864 * Device Tree IRQ specifier translation function which works with one cell
865 * bindings where the cell value maps directly to the hwirq number.
866 */
867int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
868 const u32 *intspec, unsigned int intsize,
869 unsigned long *out_hwirq, unsigned int *out_type)
Grant Likely7e713302011-07-26 03:19:06 -0600870{
Grant Likely16b2e6e2012-01-26 11:26:52 -0700871 if (WARN_ON(intsize < 1))
Grant Likely7e713302011-07-26 03:19:06 -0600872 return -EINVAL;
Grant Likely7e713302011-07-26 03:19:06 -0600873 *out_hwirq = intspec[0];
874 *out_type = IRQ_TYPE_NONE;
Grant Likely7e713302011-07-26 03:19:06 -0600875 return 0;
876}
Grant Likely16b2e6e2012-01-26 11:26:52 -0700877EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
878
879/**
880 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
881 *
882 * Device Tree IRQ specifier translation function which works with two cell
883 * bindings where the cell values map directly to the hwirq number
884 * and linux irq flags.
885 */
886int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
887 const u32 *intspec, unsigned int intsize,
888 irq_hw_number_t *out_hwirq, unsigned int *out_type)
889{
890 if (WARN_ON(intsize < 2))
891 return -EINVAL;
892 *out_hwirq = intspec[0];
893 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
894 return 0;
895}
896EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
897
898/**
899 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
900 *
901 * Device Tree IRQ specifier translation function which works with either one
902 * or two cell bindings where the cell values map directly to the hwirq number
903 * and linux irq flags.
904 *
905 * Note: don't use this function unless your interrupt controller explicitly
906 * supports both one and two cell bindings. For the majority of controllers
907 * the _onecell() or _twocell() variants above should be used.
908 */
909int irq_domain_xlate_onetwocell(struct irq_domain *d,
910 struct device_node *ctrlr,
911 const u32 *intspec, unsigned int intsize,
912 unsigned long *out_hwirq, unsigned int *out_type)
913{
914 if (WARN_ON(intsize < 1))
915 return -EINVAL;
916 *out_hwirq = intspec[0];
917 *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
918 return 0;
919}
920EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
Grant Likely7e713302011-07-26 03:19:06 -0600921
Grant Likelya18dc812012-01-26 12:12:14 -0700922const struct irq_domain_ops irq_domain_simple_ops = {
Grant Likely16b2e6e2012-01-26 11:26:52 -0700923 .xlate = irq_domain_xlate_onetwocell,
Grant Likely75294952012-02-14 14:06:57 -0700924};
925EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
926
927#ifdef CONFIG_OF_IRQ
Grant Likely7e713302011-07-26 03:19:06 -0600928void irq_domain_generate_simple(const struct of_device_id *match,
929 u64 phys_base, unsigned int irq_start)
930{
931 struct device_node *node;
Grant Likelye1964c52012-02-14 14:06:48 -0700932 pr_debug("looking for phys_base=%llx, irq_start=%i\n",
Grant Likely7e713302011-07-26 03:19:06 -0600933 (unsigned long long) phys_base, (int) irq_start);
934 node = of_find_matching_node_by_address(NULL, match, phys_base);
935 if (node)
Grant Likely6b783f72012-01-10 17:09:30 -0700936 irq_domain_add_legacy(node, 32, irq_start, 0,
937 &irq_domain_simple_ops, NULL);
Grant Likely7e713302011-07-26 03:19:06 -0600938}
939EXPORT_SYMBOL_GPL(irq_domain_generate_simple);
Grant Likely75294952012-02-14 14:06:57 -0700940#endif