blob: c0e638ba9c2a5849694bba229472cb75f268e76b [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
151 * domain otherwise.
152 *
153 * This is intended to implement the expected behaviour for most
154 * interrupt controllers which is that a linear mapping should
155 * normally be used unless the system requires a legacy mapping in
156 * order to support supplying interrupt numbers during non-DT
157 * registration of devices.
158 */
159struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
160 unsigned int size,
161 unsigned int first_irq,
162 const struct irq_domain_ops *ops,
163 void *host_data)
164{
165 if (first_irq > 0)
166 return irq_domain_add_legacy(of_node, size, first_irq, 0,
167 ops, host_data);
168 else
169 return irq_domain_add_linear(of_node, size, ops, host_data);
170}
171
172/**
Grant Likelya8db8cf2012-02-14 14:06:54 -0700173 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
174 * @of_node: pointer to interrupt controller's device tree node.
Grant Likely1bc04f22012-02-14 14:06:55 -0700175 * @size: total number of irqs in legacy mapping
176 * @first_irq: first number of irq block assigned to the domain
177 * @first_hwirq: first hwirq number to use for the translation. Should normally
178 * be '0', but a positive integer can be used if the effective
179 * hwirqs numbering does not begin at zero.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700180 * @ops: map/unmap domain callbacks
181 * @host_data: Controller private data pointer
182 *
183 * Note: the map() callback will be called before this function returns
184 * for all legacy interrupts except 0 (which is always the invalid irq for
185 * a legacy controller).
186 */
187struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
Grant Likely1bc04f22012-02-14 14:06:55 -0700188 unsigned int size,
189 unsigned int first_irq,
190 irq_hw_number_t first_hwirq,
Grant Likelya18dc812012-01-26 12:12:14 -0700191 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700192 void *host_data)
193{
Grant Likely1bc04f22012-02-14 14:06:55 -0700194 struct irq_domain *domain;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700195 unsigned int i;
196
197 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
198 if (!domain)
199 return NULL;
200
Grant Likely1bc04f22012-02-14 14:06:55 -0700201 domain->revmap_data.legacy.first_irq = first_irq;
202 domain->revmap_data.legacy.first_hwirq = first_hwirq;
203 domain->revmap_data.legacy.size = size;
204
Grant Likelycc79ca62012-02-16 01:37:49 -0700205 mutex_lock(&irq_domain_mutex);
Grant Likely1bc04f22012-02-14 14:06:55 -0700206 /* Verify that all the irqs are available */
207 for (i = 0; i < size; i++) {
208 int irq = first_irq + i;
209 struct irq_data *irq_data = irq_get_irq_data(irq);
210
211 if (WARN_ON(!irq_data || irq_data->domain)) {
Grant Likelya8db8cf2012-02-14 14:06:54 -0700212 mutex_unlock(&irq_domain_mutex);
Paul Mundt58ee99a2012-05-19 15:11:41 +0900213 irq_domain_free(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700214 return NULL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700215 }
216 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700217
218 /* Claim all of the irqs before registering a legacy domain */
219 for (i = 0; i < size; i++) {
220 struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
221 irq_data->hwirq = first_hwirq + i;
222 irq_data->domain = domain;
223 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700224 mutex_unlock(&irq_domain_mutex);
225
Grant Likely1bc04f22012-02-14 14:06:55 -0700226 for (i = 0; i < size; i++) {
227 int irq = first_irq + i;
228 int hwirq = first_hwirq + i;
229
230 /* IRQ0 gets ignored */
231 if (!irq)
232 continue;
Grant Likelycc79ca62012-02-16 01:37:49 -0700233
Grant Likelya8db8cf2012-02-14 14:06:54 -0700234 /* Legacy flags are left to default at this point,
235 * one can then use irq_create_mapping() to
236 * explicitly change them
237 */
Grant Likelyaed98042012-06-03 22:04:39 -0700238 if (ops->map)
239 ops->map(domain, irq, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700240
Grant Likelya8db8cf2012-02-14 14:06:54 -0700241 /* Clear norequest flags */
Grant Likely1bc04f22012-02-14 14:06:55 -0700242 irq_clear_status_flags(irq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700243 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700244
245 irq_domain_add(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700246 return domain;
247}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900248EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
Grant Likelycc79ca62012-02-16 01:37:49 -0700249
Grant Likelya8db8cf2012-02-14 14:06:54 -0700250/**
Dong Aisheng22076c72012-06-20 17:00:30 +0800251 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700252 * @of_node: pointer to interrupt controller's device tree node.
Mark Browna87487e2012-05-19 12:15:35 +0100253 * @size: Number of interrupts in the domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700254 * @ops: map/unmap domain callbacks
255 * @host_data: Controller private data pointer
256 */
257struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
258 unsigned int size,
Grant Likelya18dc812012-01-26 12:12:14 -0700259 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700260 void *host_data)
261{
262 struct irq_domain *domain;
263 unsigned int *revmap;
Grant Likelycc79ca62012-02-16 01:37:49 -0700264
Paul Mundt5ca4db62012-06-03 22:04:34 -0700265 revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
266 of_node_to_nid(of_node));
Grant Likelya8db8cf2012-02-14 14:06:54 -0700267 if (WARN_ON(!revmap))
268 return NULL;
269
270 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
271 if (!domain) {
272 kfree(revmap);
273 return NULL;
274 }
275 domain->revmap_data.linear.size = size;
276 domain->revmap_data.linear.revmap = revmap;
277 irq_domain_add(domain);
278 return domain;
279}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900280EXPORT_SYMBOL_GPL(irq_domain_add_linear);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700281
282struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700283 unsigned int max_irq,
Grant Likelya18dc812012-01-26 12:12:14 -0700284 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700285 void *host_data)
286{
287 struct irq_domain *domain = irq_domain_alloc(of_node,
288 IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700289 if (domain) {
290 domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700291 irq_domain_add(domain);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700292 }
Grant Likelya8db8cf2012-02-14 14:06:54 -0700293 return domain;
294}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900295EXPORT_SYMBOL_GPL(irq_domain_add_nomap);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700296
297/**
298 * irq_domain_add_tree()
299 * @of_node: pointer to interrupt controller's device tree node.
300 * @ops: map/unmap domain callbacks
301 *
302 * Note: The radix tree will be allocated later during boot automatically
303 * (the reverse mapping will use the slow path until that happens).
304 */
305struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
Grant Likelya18dc812012-01-26 12:12:14 -0700306 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700307 void *host_data)
308{
309 struct irq_domain *domain = irq_domain_alloc(of_node,
310 IRQ_DOMAIN_MAP_TREE, ops, host_data);
311 if (domain) {
312 INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
313 irq_domain_add(domain);
314 }
Grant Likely68700652012-02-14 14:06:53 -0700315 return domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700316}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900317EXPORT_SYMBOL_GPL(irq_domain_add_tree);
Grant Likelycc79ca62012-02-16 01:37:49 -0700318
319/**
320 * irq_find_host() - Locates a domain for a given device node
321 * @node: device-tree node of the interrupt controller
322 */
323struct irq_domain *irq_find_host(struct device_node *node)
324{
325 struct irq_domain *h, *found = NULL;
Grant Likelya18dc812012-01-26 12:12:14 -0700326 int rc;
Grant Likelycc79ca62012-02-16 01:37:49 -0700327
328 /* We might want to match the legacy controller last since
329 * it might potentially be set to match all interrupts in
330 * the absence of a device node. This isn't a problem so far
331 * yet though...
332 */
333 mutex_lock(&irq_domain_mutex);
Grant Likelya18dc812012-01-26 12:12:14 -0700334 list_for_each_entry(h, &irq_domain_list, link) {
335 if (h->ops->match)
336 rc = h->ops->match(h, node);
337 else
338 rc = (h->of_node != NULL) && (h->of_node == node);
339
340 if (rc) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700341 found = h;
342 break;
343 }
Grant Likelya18dc812012-01-26 12:12:14 -0700344 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700345 mutex_unlock(&irq_domain_mutex);
346 return found;
347}
348EXPORT_SYMBOL_GPL(irq_find_host);
349
350/**
351 * irq_set_default_host() - Set a "default" irq domain
Grant Likely68700652012-02-14 14:06:53 -0700352 * @domain: default domain pointer
Grant Likelycc79ca62012-02-16 01:37:49 -0700353 *
354 * For convenience, it's possible to set a "default" domain that will be used
355 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
356 * platforms that want to manipulate a few hard coded interrupt numbers that
357 * aren't properly represented in the device-tree.
358 */
Grant Likely68700652012-02-14 14:06:53 -0700359void irq_set_default_host(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700360{
Paul Mundt54a90582012-05-19 15:11:47 +0900361 pr_debug("Default domain set to @0x%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700362
Grant Likely68700652012-02-14 14:06:53 -0700363 irq_default_domain = domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700364}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900365EXPORT_SYMBOL_GPL(irq_set_default_host);
Grant Likelycc79ca62012-02-16 01:37:49 -0700366
Grant Likely913af202012-06-03 22:04:35 -0700367static void irq_domain_disassociate_many(struct irq_domain *domain,
368 unsigned int irq_base, int count)
369{
370 /*
371 * disassociate in reverse order;
372 * not strictly necessary, but nice for unwinding
373 */
374 while (count--) {
375 int irq = irq_base + count;
376 struct irq_data *irq_data = irq_get_irq_data(irq);
377 irq_hw_number_t hwirq = irq_data->hwirq;
378
379 if (WARN_ON(!irq_data || irq_data->domain != domain))
380 continue;
381
382 irq_set_status_flags(irq, IRQ_NOREQUEST);
383
384 /* remove chip and handler */
385 irq_set_chip_and_handler(irq, NULL, NULL);
386
387 /* Make sure it's completed */
388 synchronize_irq(irq);
389
390 /* Tell the PIC about it */
391 if (domain->ops->unmap)
392 domain->ops->unmap(domain, irq);
393 smp_mb();
394
395 irq_data->domain = NULL;
396 irq_data->hwirq = 0;
397
398 /* Clear reverse map */
399 switch(domain->revmap_type) {
400 case IRQ_DOMAIN_MAP_LINEAR:
401 if (hwirq < domain->revmap_data.linear.size)
402 domain->revmap_data.linear.revmap[hwirq] = 0;
403 break;
404 case IRQ_DOMAIN_MAP_TREE:
405 mutex_lock(&revmap_trees_mutex);
406 radix_tree_delete(&domain->revmap_data.tree, hwirq);
407 mutex_unlock(&revmap_trees_mutex);
408 break;
409 }
410 }
411}
412
Grant Likely98aa4682012-06-17 16:17:04 -0600413int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
414 irq_hw_number_t hwirq_base, int count)
Grant Likelycc79ca62012-02-16 01:37:49 -0700415{
Grant Likely98aa4682012-06-17 16:17:04 -0600416 unsigned int virq = irq_base;
417 irq_hw_number_t hwirq = hwirq_base;
418 int i;
Grant Likelycc79ca62012-02-16 01:37:49 -0700419
Grant Likely98aa4682012-06-17 16:17:04 -0600420 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
421 of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
422
423 for (i = 0; i < count; i++) {
424 struct irq_data *irq_data = irq_get_irq_data(virq + i);
425
426 if (WARN(!irq_data, "error: irq_desc not allocated; "
427 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
428 return -EINVAL;
429 if (WARN(irq_data->domain, "error: irq_desc already associated; "
430 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
431 return -EINVAL;
432 };
433
434 for (i = 0; i < count; i++, virq++, hwirq++) {
435 struct irq_data *irq_data = irq_get_irq_data(virq);
436
437 irq_data->hwirq = hwirq;
438 irq_data->domain = domain;
439 if (domain->ops->map && domain->ops->map(domain, virq, hwirq)) {
440 pr_err("irq-%i==>hwirq-0x%lx mapping failed\n", virq, hwirq);
441 irq_data->domain = NULL;
442 irq_data->hwirq = 0;
443 goto err_unmap;
444 }
445
446 switch (domain->revmap_type) {
447 case IRQ_DOMAIN_MAP_LINEAR:
448 if (hwirq < domain->revmap_data.linear.size)
449 domain->revmap_data.linear.revmap[hwirq] = virq;
450 break;
451 case IRQ_DOMAIN_MAP_TREE:
452 mutex_lock(&revmap_trees_mutex);
Grant Likelyd6b0d1f2012-06-03 22:04:37 -0700453 radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
Grant Likely98aa4682012-06-17 16:17:04 -0600454 mutex_unlock(&revmap_trees_mutex);
455 break;
456 }
457
458 irq_clear_status_flags(virq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700459 }
460
Grant Likelycc79ca62012-02-16 01:37:49 -0700461 return 0;
Grant Likely98aa4682012-06-17 16:17:04 -0600462
463 err_unmap:
464 irq_domain_disassociate_many(domain, irq_base, i);
465 return -EINVAL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700466}
Grant Likely98aa4682012-06-17 16:17:04 -0600467EXPORT_SYMBOL_GPL(irq_domain_associate_many);
Grant Likelycc79ca62012-02-16 01:37:49 -0700468
469/**
470 * irq_create_direct_mapping() - Allocate an irq for direct mapping
Grant Likely68700652012-02-14 14:06:53 -0700471 * @domain: domain to allocate the irq for or NULL for default domain
Grant Likelycc79ca62012-02-16 01:37:49 -0700472 *
473 * This routine is used for irq controllers which can choose the hardware
474 * interrupt numbers they generate. In such a case it's simplest to use
475 * the linux irq as the hardware interrupt number.
476 */
Grant Likely68700652012-02-14 14:06:53 -0700477unsigned int irq_create_direct_mapping(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700478{
479 unsigned int virq;
480
Grant Likely68700652012-02-14 14:06:53 -0700481 if (domain == NULL)
482 domain = irq_default_domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700483
Grant Likely9844a552012-06-03 22:04:38 -0700484 if (WARN_ON(!domain || domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP))
485 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700486
Paul Mundt5ca4db62012-06-03 22:04:34 -0700487 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
Grant Likely03848372012-02-14 14:06:52 -0700488 if (!virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900489 pr_debug("create_direct virq allocation failed\n");
Grant Likely03848372012-02-14 14:06:52 -0700490 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700491 }
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700492 if (virq >= domain->revmap_data.nomap.max_irq) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700493 pr_err("ERROR: no free irqs available below %i maximum\n",
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700494 domain->revmap_data.nomap.max_irq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700495 irq_free_desc(virq);
496 return 0;
497 }
Paul Mundt54a90582012-05-19 15:11:47 +0900498 pr_debug("create_direct obtained virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700499
Grant Likely98aa4682012-06-17 16:17:04 -0600500 if (irq_domain_associate(domain, virq, virq)) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700501 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700502 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700503 }
504
505 return virq;
506}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900507EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
Grant Likelycc79ca62012-02-16 01:37:49 -0700508
509/**
510 * irq_create_mapping() - Map a hardware interrupt into linux irq space
Grant Likely68700652012-02-14 14:06:53 -0700511 * @domain: domain owning this hardware interrupt or NULL for default domain
512 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700513 *
514 * Only one mapping per hardware interrupt is permitted. Returns a linux
515 * irq number.
516 * If the sense/trigger is to be specified, set_irq_type() should be called
517 * on the number returned from that call.
518 */
Grant Likely68700652012-02-14 14:06:53 -0700519unsigned int irq_create_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700520 irq_hw_number_t hwirq)
521{
David Daney5b7526e2012-04-05 16:52:13 -0700522 unsigned int hint;
523 int virq;
Grant Likelycc79ca62012-02-16 01:37:49 -0700524
Paul Mundt54a90582012-05-19 15:11:47 +0900525 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700526
Grant Likely68700652012-02-14 14:06:53 -0700527 /* Look for default domain if nececssary */
528 if (domain == NULL)
529 domain = irq_default_domain;
530 if (domain == NULL) {
Paul Mundt54a90582012-05-19 15:11:47 +0900531 pr_warning("irq_create_mapping called for"
532 " NULL domain, hwirq=%lx\n", hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700533 WARN_ON(1);
Grant Likely03848372012-02-14 14:06:52 -0700534 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700535 }
Paul Mundt54a90582012-05-19 15:11:47 +0900536 pr_debug("-> using domain @%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700537
538 /* Check if mapping already exists */
Grant Likely68700652012-02-14 14:06:53 -0700539 virq = irq_find_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700540 if (virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900541 pr_debug("-> existing mapping on virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700542 return virq;
543 }
544
545 /* Get a virtual interrupt number */
Grant Likely1bc04f22012-02-14 14:06:55 -0700546 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
547 return irq_domain_legacy_revmap(domain, hwirq);
548
549 /* Allocate a virtual interrupt number */
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700550 hint = hwirq % nr_irqs;
Grant Likely1bc04f22012-02-14 14:06:55 -0700551 if (hint == 0)
552 hint++;
Paul Mundt5ca4db62012-06-03 22:04:34 -0700553 virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700554 if (virq <= 0)
Paul Mundt5ca4db62012-06-03 22:04:34 -0700555 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700556 if (virq <= 0) {
Paul Mundt54a90582012-05-19 15:11:47 +0900557 pr_debug("-> virq allocation failed\n");
Grant Likely1bc04f22012-02-14 14:06:55 -0700558 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700559 }
560
Grant Likely98aa4682012-06-17 16:17:04 -0600561 if (irq_domain_associate(domain, virq, hwirq)) {
Grant Likely73255702012-06-03 22:04:35 -0700562 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700563 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700564 }
565
Paul Mundt54a90582012-05-19 15:11:47 +0900566 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700567 hwirq, of_node_full_name(domain->of_node), virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700568
569 return virq;
570}
571EXPORT_SYMBOL_GPL(irq_create_mapping);
572
Grant Likely98aa4682012-06-17 16:17:04 -0600573/**
574 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
575 * @domain: domain owning the interrupt range
576 * @irq_base: beginning of linux IRQ range
577 * @hwirq_base: beginning of hardware IRQ range
578 * @count: Number of interrupts to map
579 *
580 * This routine is used for allocating and mapping a range of hardware
581 * irqs to linux irqs where the linux irq numbers are at pre-defined
582 * locations. For use by controllers that already have static mappings
583 * to insert in to the domain.
584 *
585 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
586 * domain insertion.
587 *
588 * 0 is returned upon success, while any failure to establish a static
589 * mapping is treated as an error.
590 */
591int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
592 irq_hw_number_t hwirq_base, int count)
593{
594 int ret;
595
596 ret = irq_alloc_descs(irq_base, irq_base, count,
597 of_node_to_nid(domain->of_node));
598 if (unlikely(ret < 0))
599 return ret;
600
601 ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
602 if (unlikely(ret < 0)) {
603 irq_free_descs(irq_base, count);
604 return ret;
605 }
606
607 return 0;
608}
609EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
610
Grant Likelycc79ca62012-02-16 01:37:49 -0700611unsigned int irq_create_of_mapping(struct device_node *controller,
612 const u32 *intspec, unsigned int intsize)
613{
Grant Likely68700652012-02-14 14:06:53 -0700614 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700615 irq_hw_number_t hwirq;
616 unsigned int type = IRQ_TYPE_NONE;
617 unsigned int virq;
618
Grant Likely68700652012-02-14 14:06:53 -0700619 domain = controller ? irq_find_host(controller) : irq_default_domain;
620 if (!domain) {
Grant Likelyabd23632012-02-24 08:07:06 -0700621#ifdef CONFIG_MIPS
622 /*
623 * Workaround to avoid breaking interrupt controller drivers
624 * that don't yet register an irq_domain. This is temporary
625 * code. ~~~gcl, Feb 24, 2012
626 *
627 * Scheduled for removal in Linux v3.6. That should be enough
628 * time.
629 */
630 if (intsize > 0)
631 return intspec[0];
632#endif
Paul Mundt54a90582012-05-19 15:11:47 +0900633 pr_warning("no irq domain found for %s !\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700634 of_node_full_name(controller));
Grant Likely03848372012-02-14 14:06:52 -0700635 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700636 }
637
Grant Likely68700652012-02-14 14:06:53 -0700638 /* If domain has no translation, then we assume interrupt line */
639 if (domain->ops->xlate == NULL)
Grant Likelycc79ca62012-02-16 01:37:49 -0700640 hwirq = intspec[0];
641 else {
Grant Likely68700652012-02-14 14:06:53 -0700642 if (domain->ops->xlate(domain, controller, intspec, intsize,
Grant Likelycc79ca62012-02-16 01:37:49 -0700643 &hwirq, &type))
Grant Likely03848372012-02-14 14:06:52 -0700644 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700645 }
646
647 /* Create mapping */
Grant Likely68700652012-02-14 14:06:53 -0700648 virq = irq_create_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700649 if (!virq)
Grant Likelycc79ca62012-02-16 01:37:49 -0700650 return virq;
651
652 /* Set type if specified and different than the current one */
653 if (type != IRQ_TYPE_NONE &&
654 type != (irqd_get_trigger_type(irq_get_irq_data(virq))))
655 irq_set_irq_type(virq, type);
656 return virq;
657}
658EXPORT_SYMBOL_GPL(irq_create_of_mapping);
659
660/**
661 * irq_dispose_mapping() - Unmap an interrupt
662 * @virq: linux irq number of the interrupt to unmap
663 */
664void irq_dispose_mapping(unsigned int virq)
665{
666 struct irq_data *irq_data = irq_get_irq_data(virq);
Grant Likely68700652012-02-14 14:06:53 -0700667 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700668
Grant Likely03848372012-02-14 14:06:52 -0700669 if (!virq || !irq_data)
Grant Likelycc79ca62012-02-16 01:37:49 -0700670 return;
671
Grant Likely68700652012-02-14 14:06:53 -0700672 domain = irq_data->domain;
673 if (WARN_ON(domain == NULL))
Grant Likelycc79ca62012-02-16 01:37:49 -0700674 return;
675
676 /* Never unmap legacy interrupts */
Grant Likely68700652012-02-14 14:06:53 -0700677 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
Grant Likelycc79ca62012-02-16 01:37:49 -0700678 return;
679
Grant Likely913af202012-06-03 22:04:35 -0700680 irq_domain_disassociate_many(domain, virq, 1);
Grant Likelycc79ca62012-02-16 01:37:49 -0700681 irq_free_desc(virq);
682}
683EXPORT_SYMBOL_GPL(irq_dispose_mapping);
684
685/**
686 * irq_find_mapping() - Find a linux irq from an hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700687 * @domain: domain owning this hardware interrupt
688 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700689 *
690 * This is a slow path, for use by generic code. It's expected that an
691 * irq controller implementation directly calls the appropriate low level
692 * mapping function.
693 */
Grant Likely68700652012-02-14 14:06:53 -0700694unsigned int irq_find_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700695 irq_hw_number_t hwirq)
696{
697 unsigned int i;
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700698 unsigned int hint = hwirq % nr_irqs;
Grant Likelycc79ca62012-02-16 01:37:49 -0700699
Grant Likely68700652012-02-14 14:06:53 -0700700 /* Look for default domain if nececssary */
701 if (domain == NULL)
702 domain = irq_default_domain;
703 if (domain == NULL)
Grant Likely03848372012-02-14 14:06:52 -0700704 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700705
706 /* legacy -> bail early */
Grant Likely68700652012-02-14 14:06:53 -0700707 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
Grant Likely1bc04f22012-02-14 14:06:55 -0700708 return irq_domain_legacy_revmap(domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700709
710 /* Slow path does a linear search of the map */
711 if (hint == 0)
712 hint = 1;
713 i = hint;
714 do {
715 struct irq_data *data = irq_get_irq_data(i);
Grant Likely68700652012-02-14 14:06:53 -0700716 if (data && (data->domain == domain) && (data->hwirq == hwirq))
Grant Likelycc79ca62012-02-16 01:37:49 -0700717 return i;
718 i++;
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700719 if (i >= nr_irqs)
Grant Likelycc79ca62012-02-16 01:37:49 -0700720 i = 1;
721 } while(i != hint);
Grant Likely03848372012-02-14 14:06:52 -0700722 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700723}
724EXPORT_SYMBOL_GPL(irq_find_mapping);
725
726/**
Grant Likelycc79ca62012-02-16 01:37:49 -0700727 * irq_linear_revmap() - Find a linux irq from a hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700728 * @domain: domain owning this hardware interrupt
729 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700730 *
731 * This is a fast path, for use by irq controller code that uses linear
732 * revmaps. It does fallback to the slow path if the revmap doesn't exist
733 * yet and will create the revmap entry with appropriate locking
734 */
Grant Likely68700652012-02-14 14:06:53 -0700735unsigned int irq_linear_revmap(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700736 irq_hw_number_t hwirq)
737{
738 unsigned int *revmap;
739
Grant Likely68700652012-02-14 14:06:53 -0700740 if (WARN_ON_ONCE(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR))
741 return irq_find_mapping(domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700742
743 /* Check revmap bounds */
Grant Likely68700652012-02-14 14:06:53 -0700744 if (unlikely(hwirq >= domain->revmap_data.linear.size))
745 return irq_find_mapping(domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700746
747 /* Check if revmap was allocated */
Grant Likely68700652012-02-14 14:06:53 -0700748 revmap = domain->revmap_data.linear.revmap;
Grant Likelycc79ca62012-02-16 01:37:49 -0700749 if (unlikely(revmap == NULL))
Grant Likely68700652012-02-14 14:06:53 -0700750 return irq_find_mapping(domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700751
752 /* Fill up revmap with slow path if no mapping found */
Grant Likely03848372012-02-14 14:06:52 -0700753 if (unlikely(!revmap[hwirq]))
Grant Likely68700652012-02-14 14:06:53 -0700754 revmap[hwirq] = irq_find_mapping(domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700755
756 return revmap[hwirq];
757}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900758EXPORT_SYMBOL_GPL(irq_linear_revmap);
Grant Likelycc79ca62012-02-16 01:37:49 -0700759
Grant Likely092b2fb2012-03-29 14:10:30 -0600760#ifdef CONFIG_IRQ_DOMAIN_DEBUG
Grant Likelycc79ca62012-02-16 01:37:49 -0700761static int virq_debug_show(struct seq_file *m, void *private)
762{
763 unsigned long flags;
764 struct irq_desc *desc;
765 const char *p;
766 static const char none[] = "none";
767 void *data;
768 int i;
769
Grant Likely15e06bf2012-04-11 00:26:25 -0600770 seq_printf(m, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
Grant Likely5269a9a2012-04-12 14:42:15 -0600771 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
772 "domain name");
Grant Likelycc79ca62012-02-16 01:37:49 -0700773
774 for (i = 1; i < nr_irqs; i++) {
775 desc = irq_to_desc(i);
776 if (!desc)
777 continue;
778
779 raw_spin_lock_irqsave(&desc->lock, flags);
780
781 if (desc->action && desc->action->handler) {
782 struct irq_chip *chip;
783
784 seq_printf(m, "%5d ", i);
785 seq_printf(m, "0x%05lx ", desc->irq_data.hwirq);
786
787 chip = irq_desc_get_chip(desc);
788 if (chip && chip->name)
789 p = chip->name;
790 else
791 p = none;
792 seq_printf(m, "%-15s ", p);
793
794 data = irq_desc_get_chip_data(desc);
Grant Likely15e06bf2012-04-11 00:26:25 -0600795 seq_printf(m, data ? "0x%p " : " %p ", data);
Grant Likelycc79ca62012-02-16 01:37:49 -0700796
Grant Likelyefd68e72012-06-03 22:04:33 -0700797 if (desc->irq_data.domain)
798 p = of_node_full_name(desc->irq_data.domain->of_node);
Grant Likelycc79ca62012-02-16 01:37:49 -0700799 else
800 p = none;
801 seq_printf(m, "%s\n", p);
802 }
803
804 raw_spin_unlock_irqrestore(&desc->lock, flags);
805 }
806
807 return 0;
808}
809
810static int virq_debug_open(struct inode *inode, struct file *file)
811{
812 return single_open(file, virq_debug_show, inode->i_private);
813}
814
815static const struct file_operations virq_debug_fops = {
816 .open = virq_debug_open,
817 .read = seq_read,
818 .llseek = seq_lseek,
819 .release = single_release,
820};
821
822static int __init irq_debugfs_init(void)
823{
Grant Likely092b2fb2012-03-29 14:10:30 -0600824 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
Grant Likelycc79ca62012-02-16 01:37:49 -0700825 NULL, &virq_debug_fops) == NULL)
826 return -ENOMEM;
827
828 return 0;
829}
830__initcall(irq_debugfs_init);
Grant Likely092b2fb2012-03-29 14:10:30 -0600831#endif /* CONFIG_IRQ_DOMAIN_DEBUG */
Grant Likelycc79ca62012-02-16 01:37:49 -0700832
Grant Likely16b2e6e2012-01-26 11:26:52 -0700833/**
834 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
835 *
836 * Device Tree IRQ specifier translation function which works with one cell
837 * bindings where the cell value maps directly to the hwirq number.
838 */
839int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
840 const u32 *intspec, unsigned int intsize,
841 unsigned long *out_hwirq, unsigned int *out_type)
Grant Likely7e713302011-07-26 03:19:06 -0600842{
Grant Likely16b2e6e2012-01-26 11:26:52 -0700843 if (WARN_ON(intsize < 1))
Grant Likely7e713302011-07-26 03:19:06 -0600844 return -EINVAL;
Grant Likely7e713302011-07-26 03:19:06 -0600845 *out_hwirq = intspec[0];
846 *out_type = IRQ_TYPE_NONE;
Grant Likely7e713302011-07-26 03:19:06 -0600847 return 0;
848}
Grant Likely16b2e6e2012-01-26 11:26:52 -0700849EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
850
851/**
852 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
853 *
854 * Device Tree IRQ specifier translation function which works with two cell
855 * bindings where the cell values map directly to the hwirq number
856 * and linux irq flags.
857 */
858int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
859 const u32 *intspec, unsigned int intsize,
860 irq_hw_number_t *out_hwirq, unsigned int *out_type)
861{
862 if (WARN_ON(intsize < 2))
863 return -EINVAL;
864 *out_hwirq = intspec[0];
865 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
866 return 0;
867}
868EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
869
870/**
871 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
872 *
873 * Device Tree IRQ specifier translation function which works with either one
874 * or two cell bindings where the cell values map directly to the hwirq number
875 * and linux irq flags.
876 *
877 * Note: don't use this function unless your interrupt controller explicitly
878 * supports both one and two cell bindings. For the majority of controllers
879 * the _onecell() or _twocell() variants above should be used.
880 */
881int irq_domain_xlate_onetwocell(struct irq_domain *d,
882 struct device_node *ctrlr,
883 const u32 *intspec, unsigned int intsize,
884 unsigned long *out_hwirq, unsigned int *out_type)
885{
886 if (WARN_ON(intsize < 1))
887 return -EINVAL;
888 *out_hwirq = intspec[0];
889 *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
890 return 0;
891}
892EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
Grant Likely7e713302011-07-26 03:19:06 -0600893
Grant Likelya18dc812012-01-26 12:12:14 -0700894const struct irq_domain_ops irq_domain_simple_ops = {
Grant Likely16b2e6e2012-01-26 11:26:52 -0700895 .xlate = irq_domain_xlate_onetwocell,
Grant Likely75294952012-02-14 14:06:57 -0700896};
897EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
898
899#ifdef CONFIG_OF_IRQ
Grant Likely7e713302011-07-26 03:19:06 -0600900void irq_domain_generate_simple(const struct of_device_id *match,
901 u64 phys_base, unsigned int irq_start)
902{
903 struct device_node *node;
Grant Likelye1964c52012-02-14 14:06:48 -0700904 pr_debug("looking for phys_base=%llx, irq_start=%i\n",
Grant Likely7e713302011-07-26 03:19:06 -0600905 (unsigned long long) phys_base, (int) irq_start);
906 node = of_find_matching_node_by_address(NULL, match, phys_base);
907 if (node)
Grant Likely6b783f72012-01-10 17:09:30 -0700908 irq_domain_add_legacy(node, 32, irq_start, 0,
909 &irq_domain_simple_ops, NULL);
Grant Likely7e713302011-07-26 03:19:06 -0600910}
911EXPORT_SYMBOL_GPL(irq_domain_generate_simple);
Grant Likely75294952012-02-14 14:06:57 -0700912#endif