1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * irq_domain - IRQ translation domains
4 *
5 * Translation infrastructure between hw and linux irq numbers. This is
6 * helpful for interrupt controllers to implement mapping between hardware
7 * irq numbers and the Linux irq number space.
8 *
9 * irq_domains also have hooks for translating device tree or other
10 * firmware interrupt representations into a hardware irq number that
11 * can be mapped back to a Linux irq number without any extra platform
12 * support code.
13 *
14 * Interrupt controller "domain" data structure. This could be defined as a
15 * irq domain controller. That is, it handles the mapping between hardware
16 * and virtual interrupt numbers for a given interrupt domain. The domain
17 * structure is generally created by the PIC code for a given PIC instance
18 * (though a domain can cover more than one PIC if they have a flat number
19 * model). It's the domain callbacks that are responsible for setting the
20 * irq_chip on a given irq_desc after it's been mapped.
21 *
22 * The host code and data structures use a fwnode_handle pointer to
23 * identify the domain. In some cases, and in order to preserve source
24 * code compatibility, this fwnode pointer is "upgraded" to a DT
25 * device_node. For those firmware infrastructures that do not provide
26 * a unique identifier for an interrupt controller, the irq_domain
27 * code offers a fwnode allocator.
28 */
29
30 #ifndef _LINUX_IRQDOMAIN_H
31 #define _LINUX_IRQDOMAIN_H
32
33 #include <linux/types.h>
34 #include <linux/irqdomain_defs.h>
35 #include <linux/irqhandler.h>
36 #include <linux/of.h>
37 #include <linux/mutex.h>
38 #include <linux/radix-tree.h>
39 #include <linux/android_kabi.h>
40
41 struct device_node;
42 struct fwnode_handle;
43 struct irq_domain;
44 struct irq_chip;
45 struct irq_data;
46 struct irq_desc;
47 struct cpumask;
48 struct seq_file;
49 struct irq_affinity_desc;
50 struct msi_parent_ops;
51
52 #define IRQ_DOMAIN_IRQ_SPEC_PARAMS 16
53
54 /**
55 * struct irq_fwspec - generic IRQ specifier structure
56 *
57 * @fwnode: Pointer to a firmware-specific descriptor
58 * @param_count: Number of device-specific parameters
59 * @param: Device-specific parameters
60 *
61 * This structure, directly modeled after of_phandle_args, is used to
62 * pass a device-specific description of an interrupt.
63 */
64 struct irq_fwspec {
65 struct fwnode_handle *fwnode;
66 int param_count;
67 u32 param[IRQ_DOMAIN_IRQ_SPEC_PARAMS];
68 };
69
70 /* Conversion function from of_phandle_args fields to fwspec */
71 void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
72 unsigned int count, struct irq_fwspec *fwspec);
73
74 /**
75 * struct irq_domain_ops - Methods for irq_domain objects
76 * @match: Match an interrupt controller device node to a host, returns
77 * 1 on a match
78 * @select: Match an interrupt controller fw specification. It is more generic
79 * than @match as it receives a complete struct irq_fwspec. Therefore,
80 * @select is preferred if provided. Returns 1 on a match.
81 * @map: Create or update a mapping between a virtual irq number and a hw
82 * irq number. This is called only once for a given mapping.
83 * @unmap: Dispose of such a mapping
84 * @xlate: Given a device tree node and interrupt specifier, decode
85 * the hardware irq number and linux irq type value.
86 * @alloc: Allocate @nr_irqs interrupts starting from @virq.
87 * @free: Free @nr_irqs interrupts starting from @virq.
88 * @activate: Activate one interrupt in HW (@irqd). If @reserve is set, only
89 * reserve the vector. If unset, assign the vector (called from
90 * request_irq()).
91 * @deactivate: Disarm one interrupt (@irqd).
92 * @translate: Given @fwspec, decode the hardware irq number (@out_hwirq) and
93 * linux irq type value (@out_type). This is a generalised @xlate
94 * (over struct irq_fwspec) and is preferred if provided.
95 * @debug_show: For domains to show specific data for an interrupt in debugfs.
96 *
97 * Functions below are provided by the driver and called whenever a new mapping
98 * is created or an old mapping is disposed. The driver can then proceed to
99 * whatever internal data structures management is required. It also needs
100 * to setup the irq_desc when returning from map().
101 */
102 struct irq_domain_ops {
103 int (*match)(struct irq_domain *d, struct device_node *node,
104 enum irq_domain_bus_token bus_token);
105 int (*select)(struct irq_domain *d, struct irq_fwspec *fwspec,
106 enum irq_domain_bus_token bus_token);
107 int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw);
108 void (*unmap)(struct irq_domain *d, unsigned int virq);
109 int (*xlate)(struct irq_domain *d, struct device_node *node,
110 const u32 *intspec, unsigned int intsize,
111 unsigned long *out_hwirq, unsigned int *out_type);
112 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
113 /* extended V2 interfaces to support hierarchy irq_domains */
114 int (*alloc)(struct irq_domain *d, unsigned int virq,
115 unsigned int nr_irqs, void *arg);
116 void (*free)(struct irq_domain *d, unsigned int virq,
117 unsigned int nr_irqs);
118 int (*activate)(struct irq_domain *d, struct irq_data *irqd, bool reserve);
119 void (*deactivate)(struct irq_domain *d, struct irq_data *irq_data);
120 int (*translate)(struct irq_domain *d, struct irq_fwspec *fwspec,
121 unsigned long *out_hwirq, unsigned int *out_type);
122 #endif
123 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
124 void (*debug_show)(struct seq_file *m, struct irq_domain *d,
125 struct irq_data *irqd, int ind);
126 #endif
127 };
128
129 extern const struct irq_domain_ops irq_generic_chip_ops;
130
131 struct irq_domain_chip_generic;
132
133 /**
134 * struct irq_domain - Hardware interrupt number translation object
135 * @link: Element in global irq_domain list.
136 * @name: Name of interrupt domain
137 * @ops: Pointer to irq_domain methods
138 * @host_data: Private data pointer for use by owner. Not touched by irq_domain
139 * core code.
140 * @flags: Per irq_domain flags
141 * @mapcount: The number of mapped interrupts
142 * @mutex: Domain lock, hierarchical domains use root domain's lock
143 * @root: Pointer to root domain, or containing structure if non-hierarchical
144 *
145 * Optional elements:
146 * @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy
147 * to swap it for the of_node via the irq_domain_get_of_node accessor
148 * @bus_token: @fwnode's device_node might be used for several irq domains. But
149 * in connection with @bus_token, the pair shall be unique in a
150 * system.
151 * @gc: Pointer to a list of generic chips. There is a helper function for
152 * setting up one or more generic chips for interrupt controllers
153 * drivers using the generic chip library which uses this pointer.
154 * @dev: Pointer to the device which instantiated the irqdomain
155 * With per device irq domains this is not necessarily the same
156 * as @pm_dev.
157 * @pm_dev: Pointer to a device that can be utilized for power management
158 * purposes related to the irq domain.
159 * @parent: Pointer to parent irq_domain to support hierarchy irq_domains
160 * @msi_parent_ops: Pointer to MSI parent domain methods for per device domain init
161 * @exit: Function called when the domain is destroyed
162 *
163 * Revmap data, used internally by the irq domain code:
164 * @hwirq_max: Top limit for the HW irq number. Especially to avoid
165 * conflicts/failures with reserved HW irqs. Can be ~0.
166 * @revmap_size: Size of the linear map table @revmap
167 * @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map
168 * @revmap: Linear table of irq_data pointers
169 */
170 struct irq_domain {
171 struct list_head link;
172 const char *name;
173 const struct irq_domain_ops *ops;
174 void *host_data;
175 unsigned int flags;
176 unsigned int mapcount;
177 struct mutex mutex;
178 struct irq_domain *root;
179
180 /* Optional data */
181 struct fwnode_handle *fwnode;
182 enum irq_domain_bus_token bus_token;
183 struct irq_domain_chip_generic *gc;
184 struct device *dev;
185 struct device *pm_dev;
186 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
187 struct irq_domain *parent;
188 #endif
189 #ifdef CONFIG_GENERIC_MSI_IRQ
190 const struct msi_parent_ops *msi_parent_ops;
191 #endif
192 void (*exit)(struct irq_domain *d);
193
194 ANDROID_KABI_RESERVE(1);
195 ANDROID_KABI_RESERVE(2);
196 ANDROID_KABI_RESERVE(3);
197 ANDROID_KABI_RESERVE(4);
198
199 /* reverse map data. The linear map gets appended to the irq_domain */
200 irq_hw_number_t hwirq_max;
201 unsigned int revmap_size;
202 struct radix_tree_root revmap_tree;
203 struct irq_data __rcu *revmap[] __counted_by(revmap_size);
204 };
205
206 /* Irq domain flags */
207 enum {
208 /* Irq domain is hierarchical */
209 IRQ_DOMAIN_FLAG_HIERARCHY = (1 << 0),
210
211 /* Irq domain name was allocated internally */
212 IRQ_DOMAIN_NAME_ALLOCATED = (1 << 1),
213
214 /* Irq domain is an IPI domain with virq per cpu */
215 IRQ_DOMAIN_FLAG_IPI_PER_CPU = (1 << 2),
216
217 /* Irq domain is an IPI domain with single virq */
218 IRQ_DOMAIN_FLAG_IPI_SINGLE = (1 << 3),
219
220 /* Irq domain implements MSIs */
221 IRQ_DOMAIN_FLAG_MSI = (1 << 4),
222
223 /*
224 * Irq domain implements isolated MSI, see msi_device_has_isolated_msi()
225 */
226 IRQ_DOMAIN_FLAG_ISOLATED_MSI = (1 << 5),
227
228 /* Irq domain doesn't translate anything */
229 IRQ_DOMAIN_FLAG_NO_MAP = (1 << 6),
230
231 /* Irq domain is a MSI parent domain */
232 IRQ_DOMAIN_FLAG_MSI_PARENT = (1 << 8),
233
234 /* Irq domain is a MSI device domain */
235 IRQ_DOMAIN_FLAG_MSI_DEVICE = (1 << 9),
236
237 /* Irq domain must destroy generic chips when removed */
238 IRQ_DOMAIN_FLAG_DESTROY_GC = (1 << 10),
239
240 /*
241 * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved
242 * for implementation specific purposes and ignored by the
243 * core code.
244 */
245 IRQ_DOMAIN_FLAG_NONCORE = (1 << 16),
246 };
247
irq_domain_get_of_node(struct irq_domain * d)248 static inline struct device_node *irq_domain_get_of_node(struct irq_domain *d)
249 {
250 return to_of_node(d->fwnode);
251 }
252
irq_domain_set_pm_device(struct irq_domain * d,struct device * dev)253 static inline void irq_domain_set_pm_device(struct irq_domain *d,
254 struct device *dev)
255 {
256 if (d)
257 d->pm_dev = dev;
258 }
259
260 #ifdef CONFIG_IRQ_DOMAIN
261 struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id,
262 const char *name, phys_addr_t *pa);
263
264 enum {
265 IRQCHIP_FWNODE_REAL,
266 IRQCHIP_FWNODE_NAMED,
267 IRQCHIP_FWNODE_NAMED_ID,
268 };
269
270 static inline
irq_domain_alloc_named_fwnode(const char * name)271 struct fwnode_handle *irq_domain_alloc_named_fwnode(const char *name)
272 {
273 return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED, 0, name, NULL);
274 }
275
276 static inline
irq_domain_alloc_named_id_fwnode(const char * name,int id)277 struct fwnode_handle *irq_domain_alloc_named_id_fwnode(const char *name, int id)
278 {
279 return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_NAMED_ID, id, name,
280 NULL);
281 }
282
irq_domain_alloc_fwnode(phys_addr_t * pa)283 static inline struct fwnode_handle *irq_domain_alloc_fwnode(phys_addr_t *pa)
284 {
285 return __irq_domain_alloc_fwnode(IRQCHIP_FWNODE_REAL, 0, NULL, pa);
286 }
287
288 void irq_domain_free_fwnode(struct fwnode_handle *fwnode);
289
290 struct irq_domain_chip_generic_info;
291
292 /**
293 * struct irq_domain_info - Domain information structure
294 * @fwnode: firmware node for the interrupt controller
295 * @domain_flags: Additional flags to add to the domain flags
296 * @size: Size of linear map; 0 for radix mapping only
297 * @hwirq_max: Maximum number of interrupts supported by controller
298 * @direct_max: Maximum value of direct maps;
299 * Use ~0 for no limit; 0 for no direct mapping
300 * @hwirq_base: The first hardware interrupt number (legacy domains only)
301 * @virq_base: The first Linux interrupt number for legacy domains to
302 * immediately associate the interrupts after domain creation
303 * @bus_token: Domain bus token
304 * @name_suffix: Optional name suffix to avoid collisions when multiple
305 * domains are added using same fwnode
306 * @ops: Domain operation callbacks
307 * @host_data: Controller private data pointer
308 * @dgc_info: Geneneric chip information structure pointer used to
309 * create generic chips for the domain if not NULL.
310 * @init: Function called when the domain is created.
311 * Allow to do some additional domain initialisation.
312 * @exit: Function called when the domain is destroyed.
313 * Allow to do some additional cleanup operation.
314 */
315 struct irq_domain_info {
316 struct fwnode_handle *fwnode;
317 unsigned int domain_flags;
318 unsigned int size;
319 irq_hw_number_t hwirq_max;
320 int direct_max;
321 unsigned int hwirq_base;
322 unsigned int virq_base;
323 enum irq_domain_bus_token bus_token;
324 const char *name_suffix;
325 const struct irq_domain_ops *ops;
326 void *host_data;
327 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
328 /**
329 * @parent: Pointer to the parent irq domain used in a hierarchy domain
330 */
331 struct irq_domain *parent;
332 #endif
333 struct irq_domain_chip_generic_info *dgc_info;
334 int (*init)(struct irq_domain *d);
335 void (*exit)(struct irq_domain *d);
336 };
337
338 struct irq_domain *irq_domain_instantiate(const struct irq_domain_info *info);
339 struct irq_domain *devm_irq_domain_instantiate(struct device *dev,
340 const struct irq_domain_info *info);
341
342 struct irq_domain *irq_domain_create_simple(struct fwnode_handle *fwnode,
343 unsigned int size,
344 unsigned int first_irq,
345 const struct irq_domain_ops *ops,
346 void *host_data);
347 struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
348 unsigned int size,
349 unsigned int first_irq,
350 irq_hw_number_t first_hwirq,
351 const struct irq_domain_ops *ops,
352 void *host_data);
353 struct irq_domain *irq_domain_create_legacy(struct fwnode_handle *fwnode,
354 unsigned int size,
355 unsigned int first_irq,
356 irq_hw_number_t first_hwirq,
357 const struct irq_domain_ops *ops,
358 void *host_data);
359 extern struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
360 enum irq_domain_bus_token bus_token);
361 extern void irq_set_default_host(struct irq_domain *host);
362 extern struct irq_domain *irq_get_default_host(void);
363 extern int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
364 irq_hw_number_t hwirq, int node,
365 const struct irq_affinity_desc *affinity);
366
of_node_to_fwnode(struct device_node * node)367 static inline struct fwnode_handle *of_node_to_fwnode(struct device_node *node)
368 {
369 return node ? &node->fwnode : NULL;
370 }
371
372 extern const struct fwnode_operations irqchip_fwnode_ops;
373
is_fwnode_irqchip(const struct fwnode_handle * fwnode)374 static inline bool is_fwnode_irqchip(const struct fwnode_handle *fwnode)
375 {
376 return fwnode && fwnode->ops == &irqchip_fwnode_ops;
377 }
378
379 extern void irq_domain_update_bus_token(struct irq_domain *domain,
380 enum irq_domain_bus_token bus_token);
381
382 static inline
irq_find_matching_fwnode(struct fwnode_handle * fwnode,enum irq_domain_bus_token bus_token)383 struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode,
384 enum irq_domain_bus_token bus_token)
385 {
386 struct irq_fwspec fwspec = {
387 .fwnode = fwnode,
388 };
389
390 return irq_find_matching_fwspec(&fwspec, bus_token);
391 }
392
irq_find_matching_host(struct device_node * node,enum irq_domain_bus_token bus_token)393 static inline struct irq_domain *irq_find_matching_host(struct device_node *node,
394 enum irq_domain_bus_token bus_token)
395 {
396 return irq_find_matching_fwnode(of_node_to_fwnode(node), bus_token);
397 }
398
irq_find_host(struct device_node * node)399 static inline struct irq_domain *irq_find_host(struct device_node *node)
400 {
401 struct irq_domain *d;
402
403 d = irq_find_matching_host(node, DOMAIN_BUS_WIRED);
404 if (!d)
405 d = irq_find_matching_host(node, DOMAIN_BUS_ANY);
406
407 return d;
408 }
409
irq_domain_add_simple(struct device_node * of_node,unsigned int size,unsigned int first_irq,const struct irq_domain_ops * ops,void * host_data)410 static inline struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
411 unsigned int size,
412 unsigned int first_irq,
413 const struct irq_domain_ops *ops,
414 void *host_data)
415 {
416 return irq_domain_create_simple(of_node_to_fwnode(of_node), size, first_irq, ops, host_data);
417 }
418
419 /**
420 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
421 * @of_node: pointer to interrupt controller's device tree node.
422 * @size: Number of interrupts in the domain.
423 * @ops: map/unmap domain callbacks
424 * @host_data: Controller private data pointer
425 */
irq_domain_add_linear(struct device_node * of_node,unsigned int size,const struct irq_domain_ops * ops,void * host_data)426 static inline struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
427 unsigned int size,
428 const struct irq_domain_ops *ops,
429 void *host_data)
430 {
431 struct irq_domain_info info = {
432 .fwnode = of_node_to_fwnode(of_node),
433 .size = size,
434 .hwirq_max = size,
435 .ops = ops,
436 .host_data = host_data,
437 };
438 struct irq_domain *d;
439
440 d = irq_domain_instantiate(&info);
441 return IS_ERR(d) ? NULL : d;
442 }
443
444 #ifdef CONFIG_IRQ_DOMAIN_NOMAP
irq_domain_add_nomap(struct device_node * of_node,unsigned int max_irq,const struct irq_domain_ops * ops,void * host_data)445 static inline struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
446 unsigned int max_irq,
447 const struct irq_domain_ops *ops,
448 void *host_data)
449 {
450 struct irq_domain_info info = {
451 .fwnode = of_node_to_fwnode(of_node),
452 .hwirq_max = max_irq,
453 .direct_max = max_irq,
454 .ops = ops,
455 .host_data = host_data,
456 };
457 struct irq_domain *d;
458
459 d = irq_domain_instantiate(&info);
460 return IS_ERR(d) ? NULL : d;
461 }
462
463 extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
464 #endif
465
irq_domain_add_tree(struct device_node * of_node,const struct irq_domain_ops * ops,void * host_data)466 static inline struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
467 const struct irq_domain_ops *ops,
468 void *host_data)
469 {
470 struct irq_domain_info info = {
471 .fwnode = of_node_to_fwnode(of_node),
472 .hwirq_max = ~0U,
473 .ops = ops,
474 .host_data = host_data,
475 };
476 struct irq_domain *d;
477
478 d = irq_domain_instantiate(&info);
479 return IS_ERR(d) ? NULL : d;
480 }
481
irq_domain_create_linear(struct fwnode_handle * fwnode,unsigned int size,const struct irq_domain_ops * ops,void * host_data)482 static inline struct irq_domain *irq_domain_create_linear(struct fwnode_handle *fwnode,
483 unsigned int size,
484 const struct irq_domain_ops *ops,
485 void *host_data)
486 {
487 struct irq_domain_info info = {
488 .fwnode = fwnode,
489 .size = size,
490 .hwirq_max = size,
491 .ops = ops,
492 .host_data = host_data,
493 };
494 struct irq_domain *d;
495
496 d = irq_domain_instantiate(&info);
497 return IS_ERR(d) ? NULL : d;
498 }
499
irq_domain_create_tree(struct fwnode_handle * fwnode,const struct irq_domain_ops * ops,void * host_data)500 static inline struct irq_domain *irq_domain_create_tree(struct fwnode_handle *fwnode,
501 const struct irq_domain_ops *ops,
502 void *host_data)
503 {
504 struct irq_domain_info info = {
505 .fwnode = fwnode,
506 .hwirq_max = ~0,
507 .ops = ops,
508 .host_data = host_data,
509 };
510 struct irq_domain *d;
511
512 d = irq_domain_instantiate(&info);
513 return IS_ERR(d) ? NULL : d;
514 }
515
516 extern void irq_domain_remove(struct irq_domain *host);
517
518 extern int irq_domain_associate(struct irq_domain *domain, unsigned int irq,
519 irq_hw_number_t hwirq);
520 extern void irq_domain_associate_many(struct irq_domain *domain,
521 unsigned int irq_base,
522 irq_hw_number_t hwirq_base, int count);
523
524 extern unsigned int irq_create_mapping_affinity(struct irq_domain *host,
525 irq_hw_number_t hwirq,
526 const struct irq_affinity_desc *affinity);
527 extern unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec);
528 extern void irq_dispose_mapping(unsigned int virq);
529
irq_create_mapping(struct irq_domain * host,irq_hw_number_t hwirq)530 static inline unsigned int irq_create_mapping(struct irq_domain *host,
531 irq_hw_number_t hwirq)
532 {
533 return irq_create_mapping_affinity(host, hwirq, NULL);
534 }
535
536 extern struct irq_desc *__irq_resolve_mapping(struct irq_domain *domain,
537 irq_hw_number_t hwirq,
538 unsigned int *irq);
539
irq_resolve_mapping(struct irq_domain * domain,irq_hw_number_t hwirq)540 static inline struct irq_desc *irq_resolve_mapping(struct irq_domain *domain,
541 irq_hw_number_t hwirq)
542 {
543 return __irq_resolve_mapping(domain, hwirq, NULL);
544 }
545
546 /**
547 * irq_find_mapping() - Find a linux irq from a hw irq number.
548 * @domain: domain owning this hardware interrupt
549 * @hwirq: hardware irq number in that domain space
550 */
irq_find_mapping(struct irq_domain * domain,irq_hw_number_t hwirq)551 static inline unsigned int irq_find_mapping(struct irq_domain *domain,
552 irq_hw_number_t hwirq)
553 {
554 unsigned int irq;
555
556 if (__irq_resolve_mapping(domain, hwirq, &irq))
557 return irq;
558
559 return 0;
560 }
561
irq_linear_revmap(struct irq_domain * domain,irq_hw_number_t hwirq)562 static inline unsigned int irq_linear_revmap(struct irq_domain *domain,
563 irq_hw_number_t hwirq)
564 {
565 return irq_find_mapping(domain, hwirq);
566 }
567
568 extern const struct irq_domain_ops irq_domain_simple_ops;
569
570 /* stock xlate functions */
571 int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
572 const u32 *intspec, unsigned int intsize,
573 irq_hw_number_t *out_hwirq, unsigned int *out_type);
574 int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
575 const u32 *intspec, unsigned int intsize,
576 irq_hw_number_t *out_hwirq, unsigned int *out_type);
577 int irq_domain_xlate_onetwocell(struct irq_domain *d, struct device_node *ctrlr,
578 const u32 *intspec, unsigned int intsize,
579 irq_hw_number_t *out_hwirq, unsigned int *out_type);
580
581 int irq_domain_translate_twocell(struct irq_domain *d,
582 struct irq_fwspec *fwspec,
583 unsigned long *out_hwirq,
584 unsigned int *out_type);
585
586 int irq_domain_translate_onecell(struct irq_domain *d,
587 struct irq_fwspec *fwspec,
588 unsigned long *out_hwirq,
589 unsigned int *out_type);
590
591 /* IPI functions */
592 int irq_reserve_ipi(struct irq_domain *domain, const struct cpumask *dest);
593 int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest);
594
595 /* V2 interfaces to support hierarchy IRQ domains. */
596 extern struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
597 unsigned int virq);
598 extern void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
599 irq_hw_number_t hwirq,
600 const struct irq_chip *chip,
601 void *chip_data, irq_flow_handler_t handler,
602 void *handler_data, const char *handler_name);
603 extern void irq_domain_reset_irq_data(struct irq_data *irq_data);
604 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
605 extern struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
606 unsigned int flags, unsigned int size,
607 struct fwnode_handle *fwnode,
608 const struct irq_domain_ops *ops, void *host_data);
609
irq_domain_add_hierarchy(struct irq_domain * parent,unsigned int flags,unsigned int size,struct device_node * node,const struct irq_domain_ops * ops,void * host_data)610 static inline struct irq_domain *irq_domain_add_hierarchy(struct irq_domain *parent,
611 unsigned int flags,
612 unsigned int size,
613 struct device_node *node,
614 const struct irq_domain_ops *ops,
615 void *host_data)
616 {
617 return irq_domain_create_hierarchy(parent, flags, size,
618 of_node_to_fwnode(node),
619 ops, host_data);
620 }
621
622 extern int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
623 unsigned int nr_irqs, int node, void *arg,
624 bool realloc,
625 const struct irq_affinity_desc *affinity);
626 extern void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs);
627 extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early);
628 extern void irq_domain_deactivate_irq(struct irq_data *irq_data);
629
irq_domain_alloc_irqs(struct irq_domain * domain,unsigned int nr_irqs,int node,void * arg)630 static inline int irq_domain_alloc_irqs(struct irq_domain *domain,
631 unsigned int nr_irqs, int node, void *arg)
632 {
633 return __irq_domain_alloc_irqs(domain, -1, nr_irqs, node, arg, false,
634 NULL);
635 }
636
637 extern int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
638 unsigned int irq_base,
639 unsigned int nr_irqs, void *arg);
640 extern int irq_domain_set_hwirq_and_chip(struct irq_domain *domain,
641 unsigned int virq,
642 irq_hw_number_t hwirq,
643 const struct irq_chip *chip,
644 void *chip_data);
645 extern void irq_domain_free_irqs_common(struct irq_domain *domain,
646 unsigned int virq,
647 unsigned int nr_irqs);
648 extern void irq_domain_free_irqs_top(struct irq_domain *domain,
649 unsigned int virq, unsigned int nr_irqs);
650
651 extern int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg);
652 extern int irq_domain_pop_irq(struct irq_domain *domain, int virq);
653
654 extern int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
655 unsigned int irq_base,
656 unsigned int nr_irqs, void *arg);
657
658 extern void irq_domain_free_irqs_parent(struct irq_domain *domain,
659 unsigned int irq_base,
660 unsigned int nr_irqs);
661
662 extern int irq_domain_disconnect_hierarchy(struct irq_domain *domain,
663 unsigned int virq);
664
irq_domain_is_hierarchy(struct irq_domain * domain)665 static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
666 {
667 return domain->flags & IRQ_DOMAIN_FLAG_HIERARCHY;
668 }
669
irq_domain_is_ipi(struct irq_domain * domain)670 static inline bool irq_domain_is_ipi(struct irq_domain *domain)
671 {
672 return domain->flags &
673 (IRQ_DOMAIN_FLAG_IPI_PER_CPU | IRQ_DOMAIN_FLAG_IPI_SINGLE);
674 }
675
irq_domain_is_ipi_per_cpu(struct irq_domain * domain)676 static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
677 {
678 return domain->flags & IRQ_DOMAIN_FLAG_IPI_PER_CPU;
679 }
680
irq_domain_is_ipi_single(struct irq_domain * domain)681 static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
682 {
683 return domain->flags & IRQ_DOMAIN_FLAG_IPI_SINGLE;
684 }
685
irq_domain_is_msi(struct irq_domain * domain)686 static inline bool irq_domain_is_msi(struct irq_domain *domain)
687 {
688 return domain->flags & IRQ_DOMAIN_FLAG_MSI;
689 }
690
irq_domain_is_msi_parent(struct irq_domain * domain)691 static inline bool irq_domain_is_msi_parent(struct irq_domain *domain)
692 {
693 return domain->flags & IRQ_DOMAIN_FLAG_MSI_PARENT;
694 }
695
irq_domain_is_msi_device(struct irq_domain * domain)696 static inline bool irq_domain_is_msi_device(struct irq_domain *domain)
697 {
698 return domain->flags & IRQ_DOMAIN_FLAG_MSI_DEVICE;
699 }
700
701 #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
irq_domain_alloc_irqs(struct irq_domain * domain,unsigned int nr_irqs,int node,void * arg)702 static inline int irq_domain_alloc_irqs(struct irq_domain *domain,
703 unsigned int nr_irqs, int node, void *arg)
704 {
705 return -1;
706 }
707
irq_domain_free_irqs(unsigned int virq,unsigned int nr_irqs)708 static inline void irq_domain_free_irqs(unsigned int virq,
709 unsigned int nr_irqs) { }
710
irq_domain_is_hierarchy(struct irq_domain * domain)711 static inline bool irq_domain_is_hierarchy(struct irq_domain *domain)
712 {
713 return false;
714 }
715
irq_domain_is_ipi(struct irq_domain * domain)716 static inline bool irq_domain_is_ipi(struct irq_domain *domain)
717 {
718 return false;
719 }
720
irq_domain_is_ipi_per_cpu(struct irq_domain * domain)721 static inline bool irq_domain_is_ipi_per_cpu(struct irq_domain *domain)
722 {
723 return false;
724 }
725
irq_domain_is_ipi_single(struct irq_domain * domain)726 static inline bool irq_domain_is_ipi_single(struct irq_domain *domain)
727 {
728 return false;
729 }
730
irq_domain_is_msi(struct irq_domain * domain)731 static inline bool irq_domain_is_msi(struct irq_domain *domain)
732 {
733 return false;
734 }
735
irq_domain_is_msi_parent(struct irq_domain * domain)736 static inline bool irq_domain_is_msi_parent(struct irq_domain *domain)
737 {
738 return false;
739 }
740
irq_domain_is_msi_device(struct irq_domain * domain)741 static inline bool irq_domain_is_msi_device(struct irq_domain *domain)
742 {
743 return false;
744 }
745
746 #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */
747
748 #ifdef CONFIG_GENERIC_MSI_IRQ
749 int msi_device_domain_alloc_wired(struct irq_domain *domain, unsigned int hwirq,
750 unsigned int type);
751 void msi_device_domain_free_wired(struct irq_domain *domain, unsigned int virq);
752 #else
msi_device_domain_alloc_wired(struct irq_domain * domain,unsigned int hwirq,unsigned int type)753 static inline int msi_device_domain_alloc_wired(struct irq_domain *domain, unsigned int hwirq,
754 unsigned int type)
755 {
756 WARN_ON_ONCE(1);
757 return -EINVAL;
758 }
msi_device_domain_free_wired(struct irq_domain * domain,unsigned int virq)759 static inline void msi_device_domain_free_wired(struct irq_domain *domain, unsigned int virq)
760 {
761 WARN_ON_ONCE(1);
762 }
763 #endif
764
765 #else /* CONFIG_IRQ_DOMAIN */
irq_dispose_mapping(unsigned int virq)766 static inline void irq_dispose_mapping(unsigned int virq) { }
irq_find_matching_fwnode(struct fwnode_handle * fwnode,enum irq_domain_bus_token bus_token)767 static inline struct irq_domain *irq_find_matching_fwnode(
768 struct fwnode_handle *fwnode, enum irq_domain_bus_token bus_token)
769 {
770 return NULL;
771 }
772 #endif /* !CONFIG_IRQ_DOMAIN */
773
774 #endif /* _LINUX_IRQDOMAIN_H */
775