1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#ifndef _LINUX_IRQDOMAIN_H
31#define _LINUX_IRQDOMAIN_H
32
33#include <linux/types.h>
34#include <linux/irqhandler.h>
35#include <linux/of.h>
36#include <linux/mutex.h>
37#include <linux/radix-tree.h>
38
39struct device_node;
40struct fwnode_handle;
41struct irq_domain;
42struct irq_chip;
43struct irq_data;
44struct irq_desc;
45struct cpumask;
46struct seq_file;
47struct irq_affinity_desc;
48
49#define IRQ_DOMAIN_IRQ_SPEC_PARAMS 16
50
51
52
53
54
55
56
57
58
59
60
61struct irq_fwspec {
62 struct fwnode_handle *fwnode;
63 int param_count;
64 u32 param[IRQ_DOMAIN_IRQ_SPEC_PARAMS];
65};
66
67
68void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
69 unsigned int count, struct irq_fwspec *fwspec);
70
71
72
73
74
75
76
77
78enum irq_domain_bus_token {
79 DOMAIN_BUS_ANY = 0,
80 DOMAIN_BUS_WIRED,
81 DOMAIN_BUS_GENERIC_MSI,
82 DOMAIN_BUS_PCI_MSI,
83 DOMAIN_BUS_PLATFORM_MSI,
84 DOMAIN_BUS_NEXUS,
85 DOMAIN_BUS_IPI,
86 DOMAIN_BUS_FSL_MC_MSI,
87 DOMAIN_BUS_TI_SCI_INTA_MSI,
88 DOMAIN_BUS_WAKEUP,
89 DOMAIN_BUS_VMD_MSI,
90};
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107struct irq_domain_ops {
108 int (*match)(struct irq_domain *d, struct device_node *node,
109 enum irq_domain_bus_token bus_token);
110 int (*select)(struct irq_domain *d, struct irq_fwspec *fwspec,
111 enum irq_domain_bus_token bus_token);
112 int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw);
113 void (*unmap)(struct irq_domain *d, unsigned int virq);
114 int (*xlate)(struct irq_domain *d, struct device_node *node,
115 const u32 *intspec, unsigned int intsize,
116 unsigned long *out_hwirq, unsigned int *out_type);
117#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
118
119 int (*alloc)(struct irq_domain *d, unsigned int virq,
120 unsigned int nr_irqs, void *arg);
121 void (*free)(struct irq_domain *d, unsigned int virq,
122 unsigned int nr_irqs);
123 int (*activate)(struct irq_domain *d, struct irq_data *irqd, bool reserve);
124 void (*deactivate)(struct irq_domain *d, struct irq_data *irq_data);
125 int (*translate)(struct irq_domain *d, struct irq_fwspec *fwspec,
126 unsigned long *out_hwirq, unsigned int *out_type);
127#endif
128#ifdef CONFIG_GENERIC_IRQ_DEBUGFS
129 void (*debug_show)(struct seq_file *m, struct irq_domain *d,
130 struct irq_data *irqd, int ind);
131#endif
132};
133
134extern const struct irq_domain_ops irq_generic_chip_ops;
135
136struct irq_domain_chip_generic;
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162struct irq_domain {
163 struct list_head link;
164 const char *name;
165 const struct irq_domain_ops *ops;
166 void *host_data;
167 unsigned int flags;
168 unsigned int mapcount;
169
170
171 struct fwnode_handle *fwnode;
172 enum irq_domain_bus_token bus_token;
173 struct irq_domain_chip_generic *gc;
174#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
175 struct irq_domain *parent;
176#endif
177
178
179 irq_hw_number_t hwirq_max;
180 unsigned int revmap_size;
181 struct radix_tree_root revmap_tree;
182 struct mutex revmap_mutex;
183 struct irq_data __rcu *revmap[];
184};
185
186
187enum {
188
189 IRQ_DOMAIN_FLAG_HIERARCHY = (1 << 0),
190
191
192 IRQ_DOMAIN_NAME_ALLOCATED = (1 << 1),
193
194
195 IRQ_DOMAIN_FLAG_IPI_PER_CPU = (1 << 2),
196
197
198 IRQ_DOMAIN_FLAG_IPI_SINGLE = (1 << 3),
199
200
201 IRQ_DOMAIN_FLAG_MSI = (1 << 4),
202
203
204 IRQ_DOMAIN_FLAG_MSI_REMAP = (1 << 5),
205
206
207
208
209
210
211 IRQ_DOMAIN_MSI_NOMASK_QUIRK = (1 << 6),
212
213
214 IRQ_DOMAIN_FLAG_NO_MAP = (1 << 7),
215
216
217
218
219
220
221 IRQ_DOMAIN_FLAG_NONCORE = (1 << 16),
222};
223
224static inline struct device_node *irq_domain_get_of_node(struct irq_domain *d)
225{
226 return to_of_node(d->fwnode);
227}
228
229#ifdef CONFIG_IRQ_DOMAIN
230struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
231 const char *name, phys_addr_t *pa);
232
233enum {
234 IRQCHIP_FWNODE_REAL,
235 IRQCHIP_FWNODE_NAMED,
236 IRQCHIP_FWNODE_NAMED_ID,
237};
238
239static inline
240struct fwnode_handle *irq_domain_alloc_named_fwnode(const char *name)
241{
242 return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED, 0, name, NULL);
243}
244
245static inline
246struct fwnode_handle *irq_domain_alloc_named_id_fwnode(const char *name, int id)
247{
248 return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED_ID, id, name,
249 NULL);
250}
251
252static inline struct fwnode_handle *irq_domain_alloc_fwnode(phys_addr_t *pa)
253{
254 return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_REAL, 0, NULL, pa);
255}
256
257void irq_domain_free_fwnode(struct fwnode_handle *fwnode);
258struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int size,
259 irq_hw_number_t hwirq_max, int direct_max,
260 const struct irq_domain_ops *ops,
261 void *host_data);
262struct irq_domain *irq_domain_create_simple(struct fwnode_handle *fwnode,
263 unsigned int size,
264 unsigned int first_irq,
265 const struct irq_domain_ops *ops,
266 void *host_data);
267struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
268 unsigned int size,
269 unsigned int first_irq,
270 irq_hw_number_t first_hwirq,
271 const struct irq_domain_ops *ops,
272 void *host_data);
273struct irq_domain *irq_domain_create_legacy(struct fwnode_handle *fwnode,
274 unsigned int size,
275 unsigned int first_irq,
276 irq_hw_number_t first_hwirq,
277 const struct irq_domain_ops *ops,
278 void *host_data);
279extern struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
280 enum irq_domain_bus_token bus_token);
281extern bool irq_domain_check_msi_remap(void);
282extern void irq_set_default_host(struct irq_domain *host);
283extern struct irq_domain *irq_get_default_host(void);
284extern int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
285 irq_hw_number_t hwirq, int node,
286 const struct irq_affinity_desc *affinity);
287
288static inline struct fwnode_handle *of_node_to_fwnode(struct device_node *node)
289{
290 return node ? &node->fwnode : NULL;
291}
292
293extern const struct fwnode_operations irqchip_fwnode_ops;
294
295static inline bool is_fwnode_irqchip(struct fwnode_handle *fwnode)
296{
297 return fwnode && fwnode->ops == &irqchip_fwnode_ops;
298}
299
300extern void irq_domain_update_bus_token(struct irq_domain *domain,
301 enum irq_domain_bus_token bus_token);
302
303static inline
304struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode,
305 enum irq_domain_bus_token bus_token)
306{
307 struct irq_fwspec fwspec = {
308 .fwnode = fwnode,
309 };
310
311 return irq_find_matching_fwspec(&fwspec, bus_token);
312}
313
314static inline struct irq_domain *irq_find_matching_host(struct device_node *node,
315 enum irq_domain_bus_token bus_token)
316{
317 return irq_find_matching_fwnode(of_node_to_fwnode(node), bus_token);
318}
319
320static inline struct irq_domain *irq_find_host(struct device_node *node)
321{
322 struct irq_domain *d;
323
324 d = irq_find_matching_host(node, DOMAIN_BUS_WIRED);
325 if (!d)
326 d = irq_find_matching_host(node, DOMAIN_BUS_ANY);
327
328 return d;
329}
330
331static inline struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
332 unsigned int size,
333 unsigned int first_irq,
334 const struct irq_domain_ops *ops,
335 void *host_data)
336{
337 return irq_domain_create_simple(of_node_to_fwnode(of_node), size, first_irq, ops, host_data);
338}
339
340
341
342
343
344
345
346
347static inline struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
348 unsigned int size,
349 const struct irq_domain_ops *ops,
350 void *host_data)
351{
352 return __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data);
353}
354
355#ifdef CONFIG_IRQ_DOMAIN_NOMAP
356static inline struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
357 unsigned int max_irq,
358 const struct irq_domain_ops *ops,
359 void *host_data)
360{
361 return __irq_domain_add(of_node_to_fwnode(of_node), 0, max_irq, max_irq, ops, host_data);
362}
363
364extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
365#endif
366
367static inline struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
368 const struct irq_domain_ops *ops,
369 void *host_data)
370{
371 return __irq_domain_add(of_node_to_fwnode(of_node), 0, ~0, 0, ops, host_data);
372}
373
374static inline struct irq_domain *irq_domain_create_linear(struct fwnode_handle *fwnode,
375 unsigned int size,
376 const struct irq_domain_ops *ops,
377 void *host_data)
378{
379 return __irq_domain_add(fwnode, size, size, 0, ops, host_data);
380}
381
382static inline struct irq_domain *irq_domain_create_tree(struct fwnode_handle *fwnode,
383 const struct irq_domain_ops *ops,
384 void *host_data)
385{
386 return __irq_domain_add(fwnode, 0, ~0, 0, ops, host_data);
387}
388
389extern void irq_domain_remove(struct irq_domain *host);
390
391extern int irq_domain_associate(struct irq_domain *domain, unsigned int irq,
392 irq_hw_number_t hwirq);
393extern void irq_domain_associate_many(struct irq_domain *domain,
394 unsigned int irq_base,
395 irq_hw_number_t hwirq_base, int count);
396
397extern unsigned int irq_create_mapping_affinity(struct irq_domain *host,
398 irq_hw_number_t hwirq,
399 const struct irq_affinity_desc *affinity);
400extern unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec);
401extern void irq_dispose_mapping(unsigned int virq);
402
403static inline unsigned int irq_create_mapping(struct irq_domain *host,
404 irq_hw_number_t hwirq)
405{
406 return irq_create_mapping_affinity(host, hwirq, NULL);
407}
408
409extern struct irq_desc *__irq_resolve_mapping(struct irq_domain *domain,
410 irq_hw_number_t hwirq,
411 unsigned int *irq);
412
413static inline struct irq_desc *irq_resolve_mapping(struct irq_domain *domain,
414 irq_hw_number_t hwirq)
415{
416 return __irq_resolve_mapping(domain, hwirq, NULL);
417}
418
419
420
421
422
423
424static inline unsigned int irq_find_mapping(struct irq_domain *domain,
425 irq_hw_number_t hwirq)
426{
427 unsigned int irq;
428
429 if (__irq_resolve_mapping(domain, hwirq, &irq))
430 return irq;
431
432 return 0;
433}
434
435static inline unsigned int irq_linear_revmap(struct irq_domain *domain,
436 irq_hw_number_t hwirq)
437{
438 return irq_find_mapping(domain, hwirq);
439}
440
441extern const struct irq_domain_ops irq_domain_simple_ops;
442
443
444int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
445 const u32 *intspec, unsigned int intsize,
446 irq_hw_number_t *out_hwirq, unsigned int *out_type);
447int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
448 const u32 *intspec, unsigned int intsize,
449 irq_hw_number_t *out_hwirq, unsigned int *out_type);
450int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr,
451 const u32 *intspec, unsigned int intsize,
452 irq_hw_number_t *out_hwirq, unsigned int *out_type);
453
454int irq_domain_translate_twocell(struct irq_domain *d,
455 struct irq_fwspec *fwspec,
456 unsigned long *out_hwirq,
457 unsigned int *out_type);
458
459int irq_domain_translate_onecell(struct irq_domain *d,
460 struct irq_fwspec *fwspec,
461 unsigned long *out_hwirq,
462 unsigned int *out_type);
463
464
465int irq_reserve_ipi(struct irq_domain *domain, const struct cpumask *dest);
466int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest);
467
468
469extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
470 unsigned int virq);
471extern void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
472 irq_hw_number_t hwirq, struct irq_chip *chip,
473 void *chip_data, irq_flow_handler_t handler,
474 void *handler_data, const char *handler_name);
475extern void irq_domain_reset_irq_data(struct irq_data *irq_data);
476#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
477extern struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
478 unsigned int flags, unsigned int size,
479 struct fwnode_handle *fwnode,
480 const struct irq_domain_ops *ops, void *host_data);
481
482static inline struct irq_domain *irq_domain_add_hierarchy(struct irq_domain *parent,
483 unsigned int flags,
484 unsigned int size,
485 struct device_node *node,
486 const struct irq_domain_ops *ops,
487 void *host_data)
488{
489 return irq_domain_create_hierarchy(parent, flags, size,
490 of_node_to_fwnode(node),
491 ops, host_data);
492}
493
494extern int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
495 unsigned int nr_irqs, int node, void *arg,
496 bool realloc,
497 const struct irq_affinity_desc *affinity);
498extern void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs);
499extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early);
500extern void irq_domain_deactivate_irq(struct irq_data *irq_data);
501
502static inline int irq_domain_alloc_irqs(struct irq_domain *domain,
503 unsigned int nr_irqs, int node, void *arg)
504{
505 return __irq_domain_alloc_irqs(domain, -1, nr_irqs, node, arg, false,
506 NULL);
507}
508
509extern int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
510 unsigned int irq_base,
511 unsigned int nr_irqs, void *arg);
512extern int irq_domain_set_hwirq_and_chip(struct irq_domain *domain,
513 unsigned int virq,
514 irq_hw_number_t hwirq,
515 struct irq_chip *chip,
516 void *chip_data);
517extern void irq_domain_free_irqs_common(struct irq_domain *domain,
518 unsigned int virq,
519 unsigned int nr_irqs);
520extern void irq_domain_free_irqs_top(struct irq_domain *domain,
521 unsigned int virq, unsigned int nr_irqs);
522
523extern int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg);
524extern int irq_domain_pop_irq(struct irq_domain *domain, int virq);
525
526extern int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
527 unsigned int irq_base,
528 unsigned int nr_irqs, void *arg);
529
530extern void irq_domain_free_irqs_parent(struct irq_domain *domain,
531 unsigned int irq_base,
532 unsigned int nr_irqs);
533
534extern int irq_domain_disconnect_hierarchy(struct irq_domain *domain,
535 unsigned int virq);
536
537static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
538{
539 return domain->flags & IRQ_DOMAIN_FLAG_HIERARCHY;
540}
541
542static inline bool irq_domain_is_ipi(struct irq_domain *domain)
543{
544 return domain->flags &
545 (IRQ_DOMAIN_FLAG_IPI_PER_CPU | IRQ_DOMAIN_FLAG_IPI_SINGLE);
546}
547
548static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
549{
550 return domain->flags & IRQ_DOMAIN_FLAG_IPI_PER_CPU;
551}
552
553static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
554{
555 return domain->flags & IRQ_DOMAIN_FLAG_IPI_SINGLE;
556}
557
558static inline bool irq_domain_is_msi(struct irq_domain *domain)
559{
560 return domain->flags & IRQ_DOMAIN_FLAG_MSI;
561}
562
563static inline bool irq_domain_is_msi_remap(struct irq_domain *domain)
564{
565 return domain->flags & IRQ_DOMAIN_FLAG_MSI_REMAP;
566}
567
568extern bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain);
569
570#else
571static inline int irq_domain_alloc_irqs(struct irq_domain *domain,
572 unsigned int nr_irqs, int node, void *arg)
573{
574 return -1;
575}
576
577static inline void irq_domain_free_irqs(unsigned int virq,
578 unsigned int nr_irqs) { }
579
580static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
581{
582 return false;
583}
584
585static inline bool irq_domain_is_ipi(struct irq_domain *domain)
586{
587 return false;
588}
589
590static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
591{
592 return false;
593}
594
595static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
596{
597 return false;
598}
599
600static inline bool irq_domain_is_msi(struct irq_domain *domain)
601{
602 return false;
603}
604
605static inline bool irq_domain_is_msi_remap(struct irq_domain *domain)
606{
607 return false;
608}
609
610static inline bool
611irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain)
612{
613 return false;
614}
615#endif
616
617#else
618static inline void irq_dispose_mapping(unsigned int virq) { }
619static inline struct irq_domain *irq_find_matching_fwnode(
620 struct fwnode_handle *fwnode, enum irq_domain_bus_token bus_token)
621{
622 return NULL;
623}
624static inline bool irq_domain_check_msi_remap(void)
625{
626 return false;
627}
628#endif
629
630#endif
631