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