blob: 61d6d3c80feec3aad05dd86dab1a732167e2644c [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
19static LIST_HEAD(irq_domain_list);
20static DEFINE_MUTEX(irq_domain_mutex);
21
Grant Likelycc79ca62012-02-16 01:37:49 -070022static DEFINE_MUTEX(revmap_trees_mutex);
Grant Likely68700652012-02-14 14:06:53 -070023static struct irq_domain *irq_default_domain;
Grant Likelycc79ca62012-02-16 01:37:49 -070024
Grant Likelycc79ca62012-02-16 01:37:49 -070025/**
Grant Likelya8db8cf2012-02-14 14:06:54 -070026 * irq_domain_alloc() - Allocate a new irq_domain data structure
Grant Likelycc79ca62012-02-16 01:37:49 -070027 * @of_node: optional device-tree node of the interrupt controller
28 * @revmap_type: type of reverse mapping to use
Grant Likely68700652012-02-14 14:06:53 -070029 * @ops: map/unmap domain callbacks
Grant Likelya8db8cf2012-02-14 14:06:54 -070030 * @host_data: Controller private data pointer
Grant Likelycc79ca62012-02-16 01:37:49 -070031 *
Grant Likelya8db8cf2012-02-14 14:06:54 -070032 * Allocates and initialize and irq_domain structure. Caller is expected to
33 * register allocated irq_domain with irq_domain_register(). Returns pointer
34 * to IRQ domain, or NULL on failure.
Grant Likelycc79ca62012-02-16 01:37:49 -070035 */
Grant Likelya8db8cf2012-02-14 14:06:54 -070036static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
37 unsigned int revmap_type,
Grant Likelya18dc812012-01-26 12:12:14 -070038 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -070039 void *host_data)
Grant Likelycc79ca62012-02-16 01:37:49 -070040{
Grant Likelya8db8cf2012-02-14 14:06:54 -070041 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -070042
Paul Mundt5ca4db62012-06-03 22:04:34 -070043 domain = kzalloc_node(sizeof(*domain), GFP_KERNEL,
44 of_node_to_nid(of_node));
Grant Likelya8db8cf2012-02-14 14:06:54 -070045 if (WARN_ON(!domain))
Grant Likelycc79ca62012-02-16 01:37:49 -070046 return NULL;
47
48 /* Fill structure */
Grant Likely68700652012-02-14 14:06:53 -070049 domain->revmap_type = revmap_type;
Grant Likely68700652012-02-14 14:06:53 -070050 domain->ops = ops;
Grant Likelya8db8cf2012-02-14 14:06:54 -070051 domain->host_data = host_data;
Grant Likely68700652012-02-14 14:06:53 -070052 domain->of_node = of_node_get(of_node);
Grant Likelycc79ca62012-02-16 01:37:49 -070053
Grant Likelya8db8cf2012-02-14 14:06:54 -070054 return domain;
55}
56
Paul Mundt58ee99a2012-05-19 15:11:41 +090057static void irq_domain_free(struct irq_domain *domain)
58{
59 of_node_put(domain->of_node);
60 kfree(domain);
61}
62
Grant Likelya8db8cf2012-02-14 14:06:54 -070063static void irq_domain_add(struct irq_domain *domain)
64{
65 mutex_lock(&irq_domain_mutex);
66 list_add(&domain->link, &irq_domain_list);
67 mutex_unlock(&irq_domain_mutex);
Paul Mundt54a90582012-05-19 15:11:47 +090068 pr_debug("Allocated domain of type %d @0x%p\n",
Grant Likelya8db8cf2012-02-14 14:06:54 -070069 domain->revmap_type, domain);
70}
71
Paul Mundt58ee99a2012-05-19 15:11:41 +090072/**
73 * irq_domain_remove() - Remove an irq domain.
74 * @domain: domain to remove
75 *
76 * This routine is used to remove an irq domain. The caller must ensure
77 * that all mappings within the domain have been disposed of prior to
78 * use, depending on the revmap type.
79 */
80void irq_domain_remove(struct irq_domain *domain)
81{
82 mutex_lock(&irq_domain_mutex);
83
84 switch (domain->revmap_type) {
85 case IRQ_DOMAIN_MAP_LEGACY:
86 /*
87 * Legacy domains don't manage their own irq_desc
88 * allocations, we expect the caller to handle irq_desc
89 * freeing on their own.
90 */
91 break;
92 case IRQ_DOMAIN_MAP_TREE:
93 /*
94 * radix_tree_delete() takes care of destroying the root
95 * node when all entries are removed. Shout if there are
96 * any mappings left.
97 */
98 WARN_ON(domain->revmap_data.tree.height);
99 break;
100 case IRQ_DOMAIN_MAP_LINEAR:
101 kfree(domain->revmap_data.linear.revmap);
102 domain->revmap_data.linear.size = 0;
103 break;
104 case IRQ_DOMAIN_MAP_NOMAP:
105 break;
106 }
107
108 list_del(&domain->link);
109
110 /*
111 * If the going away domain is the default one, reset it.
112 */
113 if (unlikely(irq_default_domain == domain))
114 irq_set_default_host(NULL);
115
116 mutex_unlock(&irq_domain_mutex);
117
Paul Mundt54a90582012-05-19 15:11:47 +0900118 pr_debug("Removed domain of type %d @0x%p\n",
Paul Mundt58ee99a2012-05-19 15:11:41 +0900119 domain->revmap_type, domain);
120
121 irq_domain_free(domain);
122}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900123EXPORT_SYMBOL_GPL(irq_domain_remove);
Paul Mundt58ee99a2012-05-19 15:11:41 +0900124
Grant Likely1bc04f22012-02-14 14:06:55 -0700125static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
126 irq_hw_number_t hwirq)
127{
128 irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq;
129 int size = domain->revmap_data.legacy.size;
130
131 if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
132 return 0;
133 return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq;
134}
135
Grant Likelya8db8cf2012-02-14 14:06:54 -0700136/**
Mark Brown781d0f42012-07-05 12:19:19 +0100137 * irq_domain_add_simple() - Allocate and register a simple irq_domain.
138 * @of_node: pointer to interrupt controller's device tree node.
139 * @size: total number of irqs in mapping
Linus Walleij94a63da2013-06-06 12:10:23 +0100140 * @first_irq: first number of irq block assigned to the domain,
141 * pass zero to assign irqs on-the-fly. This will result in a
142 * linear IRQ domain so it is important to use irq_create_mapping()
143 * for each used IRQ, especially when SPARSE_IRQ is enabled.
Mark Brown781d0f42012-07-05 12:19:19 +0100144 * @ops: map/unmap domain callbacks
145 * @host_data: Controller private data pointer
146 *
147 * Allocates a legacy irq_domain if irq_base is positive or a linear
Linus Walleij2854d162012-09-27 14:59:39 +0200148 * domain otherwise. For the legacy domain, IRQ descriptors will also
149 * be allocated.
Mark Brown781d0f42012-07-05 12:19:19 +0100150 *
151 * This is intended to implement the expected behaviour for most
152 * interrupt controllers which is that a linear mapping should
153 * normally be used unless the system requires a legacy mapping in
154 * order to support supplying interrupt numbers during non-DT
155 * registration of devices.
156 */
157struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
158 unsigned int size,
159 unsigned int first_irq,
160 const struct irq_domain_ops *ops,
161 void *host_data)
162{
Linus Walleij2854d162012-09-27 14:59:39 +0200163 if (first_irq > 0) {
164 int irq_base;
165
166 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
167 /*
168 * Set the descriptor allocator to search for a
169 * 1-to-1 mapping, such as irq_alloc_desc_at().
170 * Use of_node_to_nid() which is defined to
171 * numa_node_id() on platforms that have no custom
172 * implementation.
173 */
174 irq_base = irq_alloc_descs(first_irq, first_irq, size,
175 of_node_to_nid(of_node));
176 if (irq_base < 0) {
Linus Walleijd202b7b2012-11-27 01:20:32 +0100177 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
178 first_irq);
Linus Walleij2854d162012-09-27 14:59:39 +0200179 irq_base = first_irq;
180 }
181 } else
182 irq_base = first_irq;
183
184 return irq_domain_add_legacy(of_node, size, irq_base, 0,
Mark Brown781d0f42012-07-05 12:19:19 +0100185 ops, host_data);
Linus Walleij2854d162012-09-27 14:59:39 +0200186 }
187
188 /* A linear domain is the default */
189 return irq_domain_add_linear(of_node, size, ops, host_data);
Mark Brown781d0f42012-07-05 12:19:19 +0100190}
Arnd Bergmann346dbb72013-04-25 19:28:54 +0200191EXPORT_SYMBOL_GPL(irq_domain_add_simple);
Mark Brown781d0f42012-07-05 12:19:19 +0100192
193/**
Grant Likelya8db8cf2012-02-14 14:06:54 -0700194 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
195 * @of_node: pointer to interrupt controller's device tree node.
Grant Likely1bc04f22012-02-14 14:06:55 -0700196 * @size: total number of irqs in legacy mapping
197 * @first_irq: first number of irq block assigned to the domain
198 * @first_hwirq: first hwirq number to use for the translation. Should normally
199 * be '0', but a positive integer can be used if the effective
200 * hwirqs numbering does not begin at zero.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700201 * @ops: map/unmap domain callbacks
202 * @host_data: Controller private data pointer
203 *
204 * Note: the map() callback will be called before this function returns
205 * for all legacy interrupts except 0 (which is always the invalid irq for
206 * a legacy controller).
207 */
208struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
Grant Likely1bc04f22012-02-14 14:06:55 -0700209 unsigned int size,
210 unsigned int first_irq,
211 irq_hw_number_t first_hwirq,
Grant Likelya18dc812012-01-26 12:12:14 -0700212 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700213 void *host_data)
214{
Grant Likely1bc04f22012-02-14 14:06:55 -0700215 struct irq_domain *domain;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700216 unsigned int i;
217
218 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
219 if (!domain)
220 return NULL;
221
Grant Likely1bc04f22012-02-14 14:06:55 -0700222 domain->revmap_data.legacy.first_irq = first_irq;
223 domain->revmap_data.legacy.first_hwirq = first_hwirq;
224 domain->revmap_data.legacy.size = size;
225
Grant Likelycc79ca62012-02-16 01:37:49 -0700226 mutex_lock(&irq_domain_mutex);
Grant Likely1bc04f22012-02-14 14:06:55 -0700227 /* Verify that all the irqs are available */
228 for (i = 0; i < size; i++) {
229 int irq = first_irq + i;
230 struct irq_data *irq_data = irq_get_irq_data(irq);
231
232 if (WARN_ON(!irq_data || irq_data->domain)) {
Grant Likelya8db8cf2012-02-14 14:06:54 -0700233 mutex_unlock(&irq_domain_mutex);
Paul Mundt58ee99a2012-05-19 15:11:41 +0900234 irq_domain_free(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700235 return NULL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700236 }
237 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700238
239 /* Claim all of the irqs before registering a legacy domain */
240 for (i = 0; i < size; i++) {
241 struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
242 irq_data->hwirq = first_hwirq + i;
243 irq_data->domain = domain;
244 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700245 mutex_unlock(&irq_domain_mutex);
246
Grant Likely1bc04f22012-02-14 14:06:55 -0700247 for (i = 0; i < size; i++) {
248 int irq = first_irq + i;
249 int hwirq = first_hwirq + i;
250
251 /* IRQ0 gets ignored */
252 if (!irq)
253 continue;
Grant Likelycc79ca62012-02-16 01:37:49 -0700254
Grant Likelya8db8cf2012-02-14 14:06:54 -0700255 /* Legacy flags are left to default at this point,
256 * one can then use irq_create_mapping() to
257 * explicitly change them
258 */
Grant Likelyaed98042012-06-03 22:04:39 -0700259 if (ops->map)
260 ops->map(domain, irq, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700261
Grant Likelya8db8cf2012-02-14 14:06:54 -0700262 /* Clear norequest flags */
Grant Likely1bc04f22012-02-14 14:06:55 -0700263 irq_clear_status_flags(irq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700264 }
Grant Likely1bc04f22012-02-14 14:06:55 -0700265
266 irq_domain_add(domain);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700267 return domain;
268}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900269EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
Grant Likelycc79ca62012-02-16 01:37:49 -0700270
Grant Likelya8db8cf2012-02-14 14:06:54 -0700271/**
Dong Aisheng22076c72012-06-20 17:00:30 +0800272 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700273 * @of_node: pointer to interrupt controller's device tree node.
Mark Browna87487e2012-05-19 12:15:35 +0100274 * @size: Number of interrupts in the domain.
Grant Likelya8db8cf2012-02-14 14:06:54 -0700275 * @ops: map/unmap domain callbacks
276 * @host_data: Controller private data pointer
277 */
278struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
279 unsigned int size,
Grant Likelya18dc812012-01-26 12:12:14 -0700280 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700281 void *host_data)
282{
283 struct irq_domain *domain;
284 unsigned int *revmap;
Grant Likelycc79ca62012-02-16 01:37:49 -0700285
Paul Mundt5ca4db62012-06-03 22:04:34 -0700286 revmap = kzalloc_node(sizeof(*revmap) * size, GFP_KERNEL,
287 of_node_to_nid(of_node));
Grant Likelya8db8cf2012-02-14 14:06:54 -0700288 if (WARN_ON(!revmap))
289 return NULL;
290
291 domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
292 if (!domain) {
293 kfree(revmap);
294 return NULL;
295 }
296 domain->revmap_data.linear.size = size;
297 domain->revmap_data.linear.revmap = revmap;
298 irq_domain_add(domain);
299 return domain;
300}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900301EXPORT_SYMBOL_GPL(irq_domain_add_linear);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700302
303struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700304 unsigned int max_irq,
Grant Likelya18dc812012-01-26 12:12:14 -0700305 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700306 void *host_data)
307{
308 struct irq_domain *domain = irq_domain_alloc(of_node,
309 IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700310 if (domain) {
311 domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
Grant Likelya8db8cf2012-02-14 14:06:54 -0700312 irq_domain_add(domain);
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700313 }
Grant Likelya8db8cf2012-02-14 14:06:54 -0700314 return domain;
315}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900316EXPORT_SYMBOL_GPL(irq_domain_add_nomap);
Grant Likelya8db8cf2012-02-14 14:06:54 -0700317
318/**
319 * irq_domain_add_tree()
320 * @of_node: pointer to interrupt controller's device tree node.
321 * @ops: map/unmap domain callbacks
322 *
323 * Note: The radix tree will be allocated later during boot automatically
324 * (the reverse mapping will use the slow path until that happens).
325 */
326struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
Grant Likelya18dc812012-01-26 12:12:14 -0700327 const struct irq_domain_ops *ops,
Grant Likelya8db8cf2012-02-14 14:06:54 -0700328 void *host_data)
329{
330 struct irq_domain *domain = irq_domain_alloc(of_node,
331 IRQ_DOMAIN_MAP_TREE, ops, host_data);
332 if (domain) {
333 INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
334 irq_domain_add(domain);
335 }
Grant Likely68700652012-02-14 14:06:53 -0700336 return domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700337}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900338EXPORT_SYMBOL_GPL(irq_domain_add_tree);
Grant Likelycc79ca62012-02-16 01:37:49 -0700339
340/**
341 * irq_find_host() - Locates a domain for a given device node
342 * @node: device-tree node of the interrupt controller
343 */
344struct irq_domain *irq_find_host(struct device_node *node)
345{
346 struct irq_domain *h, *found = NULL;
Grant Likelya18dc812012-01-26 12:12:14 -0700347 int rc;
Grant Likelycc79ca62012-02-16 01:37:49 -0700348
349 /* We might want to match the legacy controller last since
350 * it might potentially be set to match all interrupts in
351 * the absence of a device node. This isn't a problem so far
352 * yet though...
353 */
354 mutex_lock(&irq_domain_mutex);
Grant Likelya18dc812012-01-26 12:12:14 -0700355 list_for_each_entry(h, &irq_domain_list, link) {
356 if (h->ops->match)
357 rc = h->ops->match(h, node);
358 else
359 rc = (h->of_node != NULL) && (h->of_node == node);
360
361 if (rc) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700362 found = h;
363 break;
364 }
Grant Likelya18dc812012-01-26 12:12:14 -0700365 }
Grant Likelycc79ca62012-02-16 01:37:49 -0700366 mutex_unlock(&irq_domain_mutex);
367 return found;
368}
369EXPORT_SYMBOL_GPL(irq_find_host);
370
371/**
372 * irq_set_default_host() - Set a "default" irq domain
Grant Likely68700652012-02-14 14:06:53 -0700373 * @domain: default domain pointer
Grant Likelycc79ca62012-02-16 01:37:49 -0700374 *
375 * For convenience, it's possible to set a "default" domain that will be used
376 * whenever NULL is passed to irq_create_mapping(). It makes life easier for
377 * platforms that want to manipulate a few hard coded interrupt numbers that
378 * aren't properly represented in the device-tree.
379 */
Grant Likely68700652012-02-14 14:06:53 -0700380void irq_set_default_host(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700381{
Paul Mundt54a90582012-05-19 15:11:47 +0900382 pr_debug("Default domain set to @0x%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700383
Grant Likely68700652012-02-14 14:06:53 -0700384 irq_default_domain = domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700385}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900386EXPORT_SYMBOL_GPL(irq_set_default_host);
Grant Likelycc79ca62012-02-16 01:37:49 -0700387
Grant Likely913af202012-06-03 22:04:35 -0700388static void irq_domain_disassociate_many(struct irq_domain *domain,
389 unsigned int irq_base, int count)
390{
391 /*
392 * disassociate in reverse order;
393 * not strictly necessary, but nice for unwinding
394 */
395 while (count--) {
396 int irq = irq_base + count;
397 struct irq_data *irq_data = irq_get_irq_data(irq);
Chen Gang275e31b2013-05-14 19:02:45 +0800398 irq_hw_number_t hwirq;
Grant Likely913af202012-06-03 22:04:35 -0700399
400 if (WARN_ON(!irq_data || irq_data->domain != domain))
401 continue;
402
Chen Gang275e31b2013-05-14 19:02:45 +0800403 hwirq = irq_data->hwirq;
Grant Likely913af202012-06-03 22:04:35 -0700404 irq_set_status_flags(irq, IRQ_NOREQUEST);
405
406 /* remove chip and handler */
407 irq_set_chip_and_handler(irq, NULL, NULL);
408
409 /* Make sure it's completed */
410 synchronize_irq(irq);
411
412 /* Tell the PIC about it */
413 if (domain->ops->unmap)
414 domain->ops->unmap(domain, irq);
415 smp_mb();
416
417 irq_data->domain = NULL;
418 irq_data->hwirq = 0;
419
420 /* Clear reverse map */
421 switch(domain->revmap_type) {
422 case IRQ_DOMAIN_MAP_LINEAR:
423 if (hwirq < domain->revmap_data.linear.size)
424 domain->revmap_data.linear.revmap[hwirq] = 0;
425 break;
426 case IRQ_DOMAIN_MAP_TREE:
427 mutex_lock(&revmap_trees_mutex);
428 radix_tree_delete(&domain->revmap_data.tree, hwirq);
429 mutex_unlock(&revmap_trees_mutex);
430 break;
431 }
432 }
433}
434
Grant Likely98aa4682012-06-17 16:17:04 -0600435int irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
436 irq_hw_number_t hwirq_base, int count)
Grant Likelycc79ca62012-02-16 01:37:49 -0700437{
Grant Likely98aa4682012-06-17 16:17:04 -0600438 unsigned int virq = irq_base;
439 irq_hw_number_t hwirq = hwirq_base;
Mark Brownf5a1ad02012-07-20 10:33:19 +0100440 int i, ret;
Grant Likelycc79ca62012-02-16 01:37:49 -0700441
Grant Likely98aa4682012-06-17 16:17:04 -0600442 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
443 of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
444
445 for (i = 0; i < count; i++) {
446 struct irq_data *irq_data = irq_get_irq_data(virq + i);
447
448 if (WARN(!irq_data, "error: irq_desc not allocated; "
449 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
450 return -EINVAL;
451 if (WARN(irq_data->domain, "error: irq_desc already associated; "
452 "irq=%i hwirq=0x%x\n", virq + i, (int)hwirq + i))
453 return -EINVAL;
454 };
455
456 for (i = 0; i < count; i++, virq++, hwirq++) {
457 struct irq_data *irq_data = irq_get_irq_data(virq);
458
459 irq_data->hwirq = hwirq;
460 irq_data->domain = domain;
Mark Brownf5a1ad02012-07-20 10:33:19 +0100461 if (domain->ops->map) {
462 ret = domain->ops->map(domain, virq, hwirq);
463 if (ret != 0) {
Benjamin Herrenschmidt5fe0c1f2013-05-06 11:37:43 +1000464 /*
465 * If map() returns -EPERM, this interrupt is protected
466 * by the firmware or some other service and shall not
Grant Likely5e1cda52013-05-29 03:10:53 +0100467 * be mapped. Don't bother telling the user about it.
Benjamin Herrenschmidt5fe0c1f2013-05-06 11:37:43 +1000468 */
469 if (ret != -EPERM) {
Grant Likely5e1cda52013-05-29 03:10:53 +0100470 pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
471 of_node_full_name(domain->of_node), hwirq, virq, ret);
Benjamin Herrenschmidt5fe0c1f2013-05-06 11:37:43 +1000472 }
Mark Brownf5a1ad02012-07-20 10:33:19 +0100473 irq_data->domain = NULL;
474 irq_data->hwirq = 0;
Grant Likely5e1cda52013-05-29 03:10:53 +0100475 continue;
Mark Brownf5a1ad02012-07-20 10:33:19 +0100476 }
Grant Likely98aa4682012-06-17 16:17:04 -0600477 }
478
479 switch (domain->revmap_type) {
480 case IRQ_DOMAIN_MAP_LINEAR:
481 if (hwirq < domain->revmap_data.linear.size)
482 domain->revmap_data.linear.revmap[hwirq] = virq;
483 break;
484 case IRQ_DOMAIN_MAP_TREE:
485 mutex_lock(&revmap_trees_mutex);
Grant Likelyd6b0d1f2012-06-03 22:04:37 -0700486 radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
Grant Likely98aa4682012-06-17 16:17:04 -0600487 mutex_unlock(&revmap_trees_mutex);
488 break;
489 }
490
491 irq_clear_status_flags(virq, IRQ_NOREQUEST);
Grant Likelycc79ca62012-02-16 01:37:49 -0700492 }
493
Grant Likelycc79ca62012-02-16 01:37:49 -0700494 return 0;
Grant Likely98aa4682012-06-17 16:17:04 -0600495
496 err_unmap:
497 irq_domain_disassociate_many(domain, irq_base, i);
498 return -EINVAL;
Grant Likelycc79ca62012-02-16 01:37:49 -0700499}
Grant Likely98aa4682012-06-17 16:17:04 -0600500EXPORT_SYMBOL_GPL(irq_domain_associate_many);
Grant Likelycc79ca62012-02-16 01:37:49 -0700501
502/**
503 * irq_create_direct_mapping() - Allocate an irq for direct mapping
Grant Likely68700652012-02-14 14:06:53 -0700504 * @domain: domain to allocate the irq for or NULL for default domain
Grant Likelycc79ca62012-02-16 01:37:49 -0700505 *
506 * This routine is used for irq controllers which can choose the hardware
507 * interrupt numbers they generate. In such a case it's simplest to use
508 * the linux irq as the hardware interrupt number.
509 */
Grant Likely68700652012-02-14 14:06:53 -0700510unsigned int irq_create_direct_mapping(struct irq_domain *domain)
Grant Likelycc79ca62012-02-16 01:37:49 -0700511{
512 unsigned int virq;
513
Grant Likely68700652012-02-14 14:06:53 -0700514 if (domain == NULL)
515 domain = irq_default_domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700516
Grant Likely9844a552012-06-03 22:04:38 -0700517 if (WARN_ON(!domain || domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP))
518 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700519
Paul Mundt5ca4db62012-06-03 22:04:34 -0700520 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
Grant Likely03848372012-02-14 14:06:52 -0700521 if (!virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900522 pr_debug("create_direct virq allocation failed\n");
Grant Likely03848372012-02-14 14:06:52 -0700523 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700524 }
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700525 if (virq >= domain->revmap_data.nomap.max_irq) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700526 pr_err("ERROR: no free irqs available below %i maximum\n",
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700527 domain->revmap_data.nomap.max_irq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700528 irq_free_desc(virq);
529 return 0;
530 }
Paul Mundt54a90582012-05-19 15:11:47 +0900531 pr_debug("create_direct obtained virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700532
Grant Likely98aa4682012-06-17 16:17:04 -0600533 if (irq_domain_associate(domain, virq, virq)) {
Grant Likelycc79ca62012-02-16 01:37:49 -0700534 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700535 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700536 }
537
538 return virq;
539}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900540EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
Grant Likelycc79ca62012-02-16 01:37:49 -0700541
542/**
543 * irq_create_mapping() - Map a hardware interrupt into linux irq space
Grant Likely68700652012-02-14 14:06:53 -0700544 * @domain: domain owning this hardware interrupt or NULL for default domain
545 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700546 *
547 * Only one mapping per hardware interrupt is permitted. Returns a linux
548 * irq number.
549 * If the sense/trigger is to be specified, set_irq_type() should be called
550 * on the number returned from that call.
551 */
Grant Likely68700652012-02-14 14:06:53 -0700552unsigned int irq_create_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700553 irq_hw_number_t hwirq)
554{
David Daney5b7526e2012-04-05 16:52:13 -0700555 unsigned int hint;
556 int virq;
Grant Likelycc79ca62012-02-16 01:37:49 -0700557
Paul Mundt54a90582012-05-19 15:11:47 +0900558 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700559
Grant Likely68700652012-02-14 14:06:53 -0700560 /* Look for default domain if nececssary */
561 if (domain == NULL)
562 domain = irq_default_domain;
563 if (domain == NULL) {
Paul Mundt54a90582012-05-19 15:11:47 +0900564 pr_warning("irq_create_mapping called for"
565 " NULL domain, hwirq=%lx\n", hwirq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700566 WARN_ON(1);
Grant Likely03848372012-02-14 14:06:52 -0700567 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700568 }
Paul Mundt54a90582012-05-19 15:11:47 +0900569 pr_debug("-> using domain @%p\n", domain);
Grant Likelycc79ca62012-02-16 01:37:49 -0700570
571 /* Check if mapping already exists */
Grant Likely68700652012-02-14 14:06:53 -0700572 virq = irq_find_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700573 if (virq) {
Paul Mundt54a90582012-05-19 15:11:47 +0900574 pr_debug("-> existing mapping on virq %d\n", virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700575 return virq;
576 }
577
578 /* Get a virtual interrupt number */
Grant Likely1bc04f22012-02-14 14:06:55 -0700579 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
580 return irq_domain_legacy_revmap(domain, hwirq);
581
582 /* Allocate a virtual interrupt number */
Grant Likely6fa6c8e22012-02-15 15:06:08 -0700583 hint = hwirq % nr_irqs;
Grant Likely1bc04f22012-02-14 14:06:55 -0700584 if (hint == 0)
585 hint++;
Paul Mundt5ca4db62012-06-03 22:04:34 -0700586 virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700587 if (virq <= 0)
Paul Mundt5ca4db62012-06-03 22:04:34 -0700588 virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
David Daney5b7526e2012-04-05 16:52:13 -0700589 if (virq <= 0) {
Paul Mundt54a90582012-05-19 15:11:47 +0900590 pr_debug("-> virq allocation failed\n");
Grant Likely1bc04f22012-02-14 14:06:55 -0700591 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700592 }
593
Grant Likely98aa4682012-06-17 16:17:04 -0600594 if (irq_domain_associate(domain, virq, hwirq)) {
Grant Likely73255702012-06-03 22:04:35 -0700595 irq_free_desc(virq);
Grant Likely03848372012-02-14 14:06:52 -0700596 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700597 }
598
Paul Mundt54a90582012-05-19 15:11:47 +0900599 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700600 hwirq, of_node_full_name(domain->of_node), virq);
Grant Likelycc79ca62012-02-16 01:37:49 -0700601
602 return virq;
603}
604EXPORT_SYMBOL_GPL(irq_create_mapping);
605
Grant Likely98aa4682012-06-17 16:17:04 -0600606/**
607 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
608 * @domain: domain owning the interrupt range
609 * @irq_base: beginning of linux IRQ range
610 * @hwirq_base: beginning of hardware IRQ range
611 * @count: Number of interrupts to map
612 *
613 * This routine is used for allocating and mapping a range of hardware
614 * irqs to linux irqs where the linux irq numbers are at pre-defined
615 * locations. For use by controllers that already have static mappings
616 * to insert in to the domain.
617 *
618 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
619 * domain insertion.
620 *
621 * 0 is returned upon success, while any failure to establish a static
622 * mapping is treated as an error.
623 */
624int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
625 irq_hw_number_t hwirq_base, int count)
626{
627 int ret;
628
629 ret = irq_alloc_descs(irq_base, irq_base, count,
630 of_node_to_nid(domain->of_node));
631 if (unlikely(ret < 0))
632 return ret;
633
634 ret = irq_domain_associate_many(domain, irq_base, hwirq_base, count);
635 if (unlikely(ret < 0)) {
636 irq_free_descs(irq_base, count);
637 return ret;
638 }
639
640 return 0;
641}
642EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
643
Grant Likelycc79ca62012-02-16 01:37:49 -0700644unsigned int irq_create_of_mapping(struct device_node *controller,
645 const u32 *intspec, unsigned int intsize)
646{
Grant Likely68700652012-02-14 14:06:53 -0700647 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700648 irq_hw_number_t hwirq;
649 unsigned int type = IRQ_TYPE_NONE;
650 unsigned int virq;
651
Grant Likely68700652012-02-14 14:06:53 -0700652 domain = controller ? irq_find_host(controller) : irq_default_domain;
653 if (!domain) {
Grant Likelyabd23632012-02-24 08:07:06 -0700654#ifdef CONFIG_MIPS
655 /*
656 * Workaround to avoid breaking interrupt controller drivers
657 * that don't yet register an irq_domain. This is temporary
658 * code. ~~~gcl, Feb 24, 2012
659 *
660 * Scheduled for removal in Linux v3.6. That should be enough
661 * time.
662 */
663 if (intsize > 0)
664 return intspec[0];
665#endif
Paul Mundt54a90582012-05-19 15:11:47 +0900666 pr_warning("no irq domain found for %s !\n",
Grant Likelyefd68e72012-06-03 22:04:33 -0700667 of_node_full_name(controller));
Grant Likely03848372012-02-14 14:06:52 -0700668 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700669 }
670
Grant Likely68700652012-02-14 14:06:53 -0700671 /* If domain has no translation, then we assume interrupt line */
672 if (domain->ops->xlate == NULL)
Grant Likelycc79ca62012-02-16 01:37:49 -0700673 hwirq = intspec[0];
674 else {
Grant Likely68700652012-02-14 14:06:53 -0700675 if (domain->ops->xlate(domain, controller, intspec, intsize,
Grant Likelycc79ca62012-02-16 01:37:49 -0700676 &hwirq, &type))
Grant Likely03848372012-02-14 14:06:52 -0700677 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700678 }
679
680 /* Create mapping */
Grant Likely68700652012-02-14 14:06:53 -0700681 virq = irq_create_mapping(domain, hwirq);
Grant Likely03848372012-02-14 14:06:52 -0700682 if (!virq)
Grant Likelycc79ca62012-02-16 01:37:49 -0700683 return virq;
684
685 /* Set type if specified and different than the current one */
686 if (type != IRQ_TYPE_NONE &&
687 type != (irqd_get_trigger_type(irq_get_irq_data(virq))))
688 irq_set_irq_type(virq, type);
689 return virq;
690}
691EXPORT_SYMBOL_GPL(irq_create_of_mapping);
692
693/**
694 * irq_dispose_mapping() - Unmap an interrupt
695 * @virq: linux irq number of the interrupt to unmap
696 */
697void irq_dispose_mapping(unsigned int virq)
698{
699 struct irq_data *irq_data = irq_get_irq_data(virq);
Grant Likely68700652012-02-14 14:06:53 -0700700 struct irq_domain *domain;
Grant Likelycc79ca62012-02-16 01:37:49 -0700701
Grant Likely03848372012-02-14 14:06:52 -0700702 if (!virq || !irq_data)
Grant Likelycc79ca62012-02-16 01:37:49 -0700703 return;
704
Grant Likely68700652012-02-14 14:06:53 -0700705 domain = irq_data->domain;
706 if (WARN_ON(domain == NULL))
Grant Likelycc79ca62012-02-16 01:37:49 -0700707 return;
708
709 /* Never unmap legacy interrupts */
Grant Likely68700652012-02-14 14:06:53 -0700710 if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
Grant Likelycc79ca62012-02-16 01:37:49 -0700711 return;
712
Grant Likely913af202012-06-03 22:04:35 -0700713 irq_domain_disassociate_many(domain, virq, 1);
Grant Likelycc79ca62012-02-16 01:37:49 -0700714 irq_free_desc(virq);
715}
716EXPORT_SYMBOL_GPL(irq_dispose_mapping);
717
718/**
719 * irq_find_mapping() - Find a linux irq from an hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700720 * @domain: domain owning this hardware interrupt
721 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700722 */
Grant Likely68700652012-02-14 14:06:53 -0700723unsigned int irq_find_mapping(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700724 irq_hw_number_t hwirq)
725{
Grant Likely4c0946c2012-06-03 22:04:39 -0700726 struct irq_data *data;
Grant Likelycc79ca62012-02-16 01:37:49 -0700727
Grant Likely68700652012-02-14 14:06:53 -0700728 /* Look for default domain if nececssary */
729 if (domain == NULL)
730 domain = irq_default_domain;
731 if (domain == NULL)
Grant Likely03848372012-02-14 14:06:52 -0700732 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700733
Grant Likely4c0946c2012-06-03 22:04:39 -0700734 switch (domain->revmap_type) {
735 case IRQ_DOMAIN_MAP_LEGACY:
Grant Likely1bc04f22012-02-14 14:06:55 -0700736 return irq_domain_legacy_revmap(domain, hwirq);
Grant Likely4c0946c2012-06-03 22:04:39 -0700737 case IRQ_DOMAIN_MAP_LINEAR:
738 return irq_linear_revmap(domain, hwirq);
739 case IRQ_DOMAIN_MAP_TREE:
740 rcu_read_lock();
741 data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
742 rcu_read_unlock();
743 if (data)
744 return data->irq;
745 break;
746 case IRQ_DOMAIN_MAP_NOMAP:
747 data = irq_get_irq_data(hwirq);
Grant Likely68700652012-02-14 14:06:53 -0700748 if (data && (data->domain == domain) && (data->hwirq == hwirq))
Grant Likely4c0946c2012-06-03 22:04:39 -0700749 return hwirq;
750 break;
751 }
752
Grant Likely03848372012-02-14 14:06:52 -0700753 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700754}
755EXPORT_SYMBOL_GPL(irq_find_mapping);
756
757/**
Grant Likelycc79ca62012-02-16 01:37:49 -0700758 * irq_linear_revmap() - Find a linux irq from a hw irq number.
Grant Likely68700652012-02-14 14:06:53 -0700759 * @domain: domain owning this hardware interrupt
760 * @hwirq: hardware irq number in that domain space
Grant Likelycc79ca62012-02-16 01:37:49 -0700761 *
Grant Likely4c0946c2012-06-03 22:04:39 -0700762 * This is a fast path that can be called directly by irq controller code to
763 * save a handful of instructions.
Grant Likelycc79ca62012-02-16 01:37:49 -0700764 */
Grant Likely68700652012-02-14 14:06:53 -0700765unsigned int irq_linear_revmap(struct irq_domain *domain,
Grant Likelycc79ca62012-02-16 01:37:49 -0700766 irq_hw_number_t hwirq)
767{
Grant Likely4c0946c2012-06-03 22:04:39 -0700768 BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
Grant Likelycc79ca62012-02-16 01:37:49 -0700769
Grant Likely4c0946c2012-06-03 22:04:39 -0700770 /* Check revmap bounds; complain if exceeded */
771 if (WARN_ON(hwirq >= domain->revmap_data.linear.size))
772 return 0;
Grant Likelycc79ca62012-02-16 01:37:49 -0700773
Grant Likely4c0946c2012-06-03 22:04:39 -0700774 return domain->revmap_data.linear.revmap[hwirq];
Grant Likelycc79ca62012-02-16 01:37:49 -0700775}
Paul Mundtecd84eb2012-05-19 15:11:42 +0900776EXPORT_SYMBOL_GPL(irq_linear_revmap);
Grant Likelycc79ca62012-02-16 01:37:49 -0700777
Grant Likely092b2fb2012-03-29 14:10:30 -0600778#ifdef CONFIG_IRQ_DOMAIN_DEBUG
Grant Likelycc79ca62012-02-16 01:37:49 -0700779static int virq_debug_show(struct seq_file *m, void *private)
780{
781 unsigned long flags;
782 struct irq_desc *desc;
783 const char *p;
784 static const char none[] = "none";
785 void *data;
786 int i;
787
Grant Likely15e06bf2012-04-11 00:26:25 -0600788 seq_printf(m, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
Grant Likely5269a9a2012-04-12 14:42:15 -0600789 "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
790 "domain name");
Grant Likelycc79ca62012-02-16 01:37:49 -0700791
792 for (i = 1; i < nr_irqs; i++) {
793 desc = irq_to_desc(i);
794 if (!desc)
795 continue;
796
797 raw_spin_lock_irqsave(&desc->lock, flags);
798
799 if (desc->action && desc->action->handler) {
800 struct irq_chip *chip;
801
802 seq_printf(m, "%5d ", i);
803 seq_printf(m, "0x%05lx ", desc->irq_data.hwirq);
804
805 chip = irq_desc_get_chip(desc);
806 if (chip && chip->name)
807 p = chip->name;
808 else
809 p = none;
810 seq_printf(m, "%-15s ", p);
811
812 data = irq_desc_get_chip_data(desc);
Grant Likely15e06bf2012-04-11 00:26:25 -0600813 seq_printf(m, data ? "0x%p " : " %p ", data);
Grant Likelycc79ca62012-02-16 01:37:49 -0700814
Grant Likelyefd68e72012-06-03 22:04:33 -0700815 if (desc->irq_data.domain)
816 p = of_node_full_name(desc->irq_data.domain->of_node);
Grant Likelycc79ca62012-02-16 01:37:49 -0700817 else
818 p = none;
819 seq_printf(m, "%s\n", p);
820 }
821
822 raw_spin_unlock_irqrestore(&desc->lock, flags);
823 }
824
825 return 0;
826}
827
828static int virq_debug_open(struct inode *inode, struct file *file)
829{
830 return single_open(file, virq_debug_show, inode->i_private);
831}
832
833static const struct file_operations virq_debug_fops = {
834 .open = virq_debug_open,
835 .read = seq_read,
836 .llseek = seq_lseek,
837 .release = single_release,
838};
839
840static int __init irq_debugfs_init(void)
841{
Grant Likely092b2fb2012-03-29 14:10:30 -0600842 if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
Grant Likelycc79ca62012-02-16 01:37:49 -0700843 NULL, &virq_debug_fops) == NULL)
844 return -ENOMEM;
845
846 return 0;
847}
848__initcall(irq_debugfs_init);
Grant Likely092b2fb2012-03-29 14:10:30 -0600849#endif /* CONFIG_IRQ_DOMAIN_DEBUG */
Grant Likelycc79ca62012-02-16 01:37:49 -0700850
Grant Likely16b2e6e2012-01-26 11:26:52 -0700851/**
852 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
853 *
854 * Device Tree IRQ specifier translation function which works with one cell
855 * bindings where the cell value maps directly to the hwirq number.
856 */
857int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
858 const u32 *intspec, unsigned int intsize,
859 unsigned long *out_hwirq, unsigned int *out_type)
Grant Likely7e713302011-07-26 03:19:06 -0600860{
Grant Likely16b2e6e2012-01-26 11:26:52 -0700861 if (WARN_ON(intsize < 1))
Grant Likely7e713302011-07-26 03:19:06 -0600862 return -EINVAL;
Grant Likely7e713302011-07-26 03:19:06 -0600863 *out_hwirq = intspec[0];
864 *out_type = IRQ_TYPE_NONE;
Grant Likely7e713302011-07-26 03:19:06 -0600865 return 0;
866}
Grant Likely16b2e6e2012-01-26 11:26:52 -0700867EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
868
869/**
870 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
871 *
872 * Device Tree IRQ specifier translation function which works with two cell
873 * bindings where the cell values map directly to the hwirq number
874 * and linux irq flags.
875 */
876int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
877 const u32 *intspec, unsigned int intsize,
878 irq_hw_number_t *out_hwirq, unsigned int *out_type)
879{
880 if (WARN_ON(intsize < 2))
881 return -EINVAL;
882 *out_hwirq = intspec[0];
883 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
884 return 0;
885}
886EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
887
888/**
889 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
890 *
891 * Device Tree IRQ specifier translation function which works with either one
892 * or two cell bindings where the cell values map directly to the hwirq number
893 * and linux irq flags.
894 *
895 * Note: don't use this function unless your interrupt controller explicitly
896 * supports both one and two cell bindings. For the majority of controllers
897 * the _onecell() or _twocell() variants above should be used.
898 */
899int irq_domain_xlate_onetwocell(struct irq_domain *d,
900 struct device_node *ctrlr,
901 const u32 *intspec, unsigned int intsize,
902 unsigned long *out_hwirq, unsigned int *out_type)
903{
904 if (WARN_ON(intsize < 1))
905 return -EINVAL;
906 *out_hwirq = intspec[0];
907 *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
908 return 0;
909}
910EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
Grant Likely7e713302011-07-26 03:19:06 -0600911
Grant Likelya18dc812012-01-26 12:12:14 -0700912const struct irq_domain_ops irq_domain_simple_ops = {
Grant Likely16b2e6e2012-01-26 11:26:52 -0700913 .xlate = irq_domain_xlate_onetwocell,
Grant Likely75294952012-02-14 14:06:57 -0700914};
915EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
916
917#ifdef CONFIG_OF_IRQ
Grant Likely7e713302011-07-26 03:19:06 -0600918void irq_domain_generate_simple(const struct of_device_id *match,
919 u64 phys_base, unsigned int irq_start)
920{
921 struct device_node *node;
Grant Likelye1964c52012-02-14 14:06:48 -0700922 pr_debug("looking for phys_base=%llx, irq_start=%i\n",
Grant Likely7e713302011-07-26 03:19:06 -0600923 (unsigned long long) phys_base, (int) irq_start);
924 node = of_find_matching_node_by_address(NULL, match, phys_base);
925 if (node)
Grant Likely6b783f72012-01-10 17:09:30 -0700926 irq_domain_add_legacy(node, 32, irq_start, 0,
927 &irq_domain_simple_ops, NULL);
Grant Likely7e713302011-07-26 03:19:06 -0600928}
929EXPORT_SYMBOL_GPL(irq_domain_generate_simple);
Grant Likely75294952012-02-14 14:06:57 -0700930#endif