1 // SPDX-License-Identifier: GPL-2.0 2 3 #define pr_fmt(fmt) "irq: " fmt 4 5 #include <linux/acpi.h> 6 #include <linux/debugfs.h> 7 #include <linux/hardirq.h> 8 #include <linux/interrupt.h> 9 #include <linux/irq.h> 10 #include <linux/irqdesc.h> 11 #include <linux/irqdomain.h> 12 #include <linux/module.h> 13 #include <linux/mutex.h> 14 #include <linux/of.h> 15 #include <linux/of_address.h> 16 #include <linux/of_irq.h> 17 #include <linux/topology.h> 18 #include <linux/seq_file.h> 19 #include <linux/slab.h> 20 #include <linux/smp.h> 21 #include <linux/fs.h> 22 23 static LIST_HEAD(irq_domain_list); 24 static DEFINE_MUTEX(irq_domain_mutex); 25 26 static struct irq_domain *irq_default_domain; 27 28 static int irq_domain_alloc_irqs_locked(struct irq_domain *domain, int irq_base, 29 unsigned int nr_irqs, int node, void *arg, 30 bool realloc, const struct irq_affinity_desc *affinity); 31 static void irq_domain_check_hierarchy(struct irq_domain *domain); 32 33 struct irqchip_fwid { 34 struct fwnode_handle fwnode; 35 unsigned int type; 36 char *name; 37 phys_addr_t *pa; 38 }; 39 40 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS 41 static void debugfs_add_domain_dir(struct irq_domain *d); 42 static void debugfs_remove_domain_dir(struct irq_domain *d); 43 #else 44 static inline void debugfs_add_domain_dir(struct irq_domain *d) { } 45 static inline void debugfs_remove_domain_dir(struct irq_domain *d) { } 46 #endif 47 48 static const char *irqchip_fwnode_get_name(const struct fwnode_handle *fwnode) 49 { 50 struct irqchip_fwid *fwid = container_of(fwnode, struct irqchip_fwid, fwnode); 51 52 return fwid->name; 53 } 54 55 const struct fwnode_operations irqchip_fwnode_ops = { 56 .get_name = irqchip_fwnode_get_name, 57 }; 58 EXPORT_SYMBOL_GPL(irqchip_fwnode_ops); 59 60 /** 61 * __irq_domain_alloc_fwnode - Allocate a fwnode_handle suitable for 62 * identifying an irq domain 63 * @type: Type of irqchip_fwnode. See linux/irqdomain.h 64 * @id: Optional user provided id if name != NULL 65 * @name: Optional user provided domain name 66 * @pa: Optional user-provided physical address 67 * 68 * Allocate a struct irqchip_fwid, and return a pointer to the embedded 69 * fwnode_handle (or NULL on failure). 70 * 71 * Note: The types IRQCHIP_FWNODE_NAMED and IRQCHIP_FWNODE_NAMED_ID are 72 * solely to transport name information to irqdomain creation code. The 73 * node is not stored. For other types the pointer is kept in the irq 74 * domain struct. 75 */ 76 struct fwnode_handle *__irq_domain_alloc_fwnode(unsigned int type, int id, 77 const char *name, 78 phys_addr_t *pa) 79 { 80 struct irqchip_fwid *fwid; 81 char *n; 82 83 fwid = kzalloc(sizeof(*fwid), GFP_KERNEL); 84 85 switch (type) { 86 case IRQCHIP_FWNODE_NAMED: 87 n = kasprintf(GFP_KERNEL, "%s", name); 88 break; 89 case IRQCHIP_FWNODE_NAMED_ID: 90 n = kasprintf(GFP_KERNEL, "%s-%d", name, id); 91 break; 92 default: 93 n = kasprintf(GFP_KERNEL, "irqchip@%pa", pa); 94 break; 95 } 96 97 if (!fwid || !n) { 98 kfree(fwid); 99 kfree(n); 100 return NULL; 101 } 102 103 fwid->type = type; 104 fwid->name = n; 105 fwid->pa = pa; 106 fwnode_init(&fwid->fwnode, &irqchip_fwnode_ops); 107 return &fwid->fwnode; 108 } 109 EXPORT_SYMBOL_GPL(__irq_domain_alloc_fwnode); 110 111 /** 112 * irq_domain_free_fwnode - Free a non-OF-backed fwnode_handle 113 * 114 * Free a fwnode_handle allocated with irq_domain_alloc_fwnode. 115 */ 116 void irq_domain_free_fwnode(struct fwnode_handle *fwnode) 117 { 118 struct irqchip_fwid *fwid; 119 120 if (!fwnode || WARN_ON(!is_fwnode_irqchip(fwnode))) 121 return; 122 123 fwid = container_of(fwnode, struct irqchip_fwid, fwnode); 124 kfree(fwid->name); 125 kfree(fwid); 126 } 127 EXPORT_SYMBOL_GPL(irq_domain_free_fwnode); 128 129 static struct irq_domain *__irq_domain_create(struct fwnode_handle *fwnode, 130 unsigned int size, 131 irq_hw_number_t hwirq_max, 132 int direct_max, 133 const struct irq_domain_ops *ops, 134 void *host_data) 135 { 136 struct irqchip_fwid *fwid; 137 struct irq_domain *domain; 138 139 static atomic_t unknown_domains; 140 141 if (WARN_ON((size && direct_max) || 142 (!IS_ENABLED(CONFIG_IRQ_DOMAIN_NOMAP) && direct_max) || 143 (direct_max && (direct_max != hwirq_max)))) 144 return NULL; 145 146 domain = kzalloc_node(struct_size(domain, revmap, size), 147 GFP_KERNEL, of_node_to_nid(to_of_node(fwnode))); 148 if (!domain) 149 return NULL; 150 151 if (is_fwnode_irqchip(fwnode)) { 152 fwid = container_of(fwnode, struct irqchip_fwid, fwnode); 153 154 switch (fwid->type) { 155 case IRQCHIP_FWNODE_NAMED: 156 case IRQCHIP_FWNODE_NAMED_ID: 157 domain->fwnode = fwnode; 158 domain->name = kstrdup(fwid->name, GFP_KERNEL); 159 if (!domain->name) { 160 kfree(domain); 161 return NULL; 162 } 163 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; 164 break; 165 default: 166 domain->fwnode = fwnode; 167 domain->name = fwid->name; 168 break; 169 } 170 } else if (is_of_node(fwnode) || is_acpi_device_node(fwnode) || 171 is_software_node(fwnode)) { 172 char *name; 173 174 /* 175 * fwnode paths contain '/', which debugfs is legitimately 176 * unhappy about. Replace them with ':', which does 177 * the trick and is not as offensive as '\'... 178 */ 179 name = kasprintf(GFP_KERNEL, "%pfw", fwnode); 180 if (!name) { 181 kfree(domain); 182 return NULL; 183 } 184 185 strreplace(name, '/', ':'); 186 187 domain->name = name; 188 domain->fwnode = fwnode; 189 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; 190 } 191 192 if (!domain->name) { 193 if (fwnode) 194 pr_err("Invalid fwnode type for irqdomain\n"); 195 domain->name = kasprintf(GFP_KERNEL, "unknown-%d", 196 atomic_inc_return(&unknown_domains)); 197 if (!domain->name) { 198 kfree(domain); 199 return NULL; 200 } 201 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; 202 } 203 204 fwnode_handle_get(fwnode); 205 fwnode_dev_initialized(fwnode, true); 206 207 /* Fill structure */ 208 INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL); 209 domain->ops = ops; 210 domain->host_data = host_data; 211 domain->hwirq_max = hwirq_max; 212 213 if (direct_max) 214 domain->flags |= IRQ_DOMAIN_FLAG_NO_MAP; 215 216 domain->revmap_size = size; 217 218 /* 219 * Hierarchical domains use the domain lock of the root domain 220 * (innermost domain). 221 * 222 * For non-hierarchical domains (as for root domains), the root 223 * pointer is set to the domain itself so that &domain->root->mutex 224 * always points to the right lock. 225 */ 226 mutex_init(&domain->mutex); 227 domain->root = domain; 228 229 irq_domain_check_hierarchy(domain); 230 231 return domain; 232 } 233 234 static void __irq_domain_publish(struct irq_domain *domain) 235 { 236 mutex_lock(&irq_domain_mutex); 237 debugfs_add_domain_dir(domain); 238 list_add(&domain->link, &irq_domain_list); 239 mutex_unlock(&irq_domain_mutex); 240 241 pr_debug("Added domain %s\n", domain->name); 242 } 243 244 /** 245 * __irq_domain_add() - Allocate a new irq_domain data structure 246 * @fwnode: firmware node for the interrupt controller 247 * @size: Size of linear map; 0 for radix mapping only 248 * @hwirq_max: Maximum number of interrupts supported by controller 249 * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no 250 * direct mapping 251 * @ops: domain callbacks 252 * @host_data: Controller private data pointer 253 * 254 * Allocates and initializes an irq_domain structure. 255 * Returns pointer to IRQ domain, or NULL on failure. 256 */ 257 struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int size, 258 irq_hw_number_t hwirq_max, int direct_max, 259 const struct irq_domain_ops *ops, 260 void *host_data) 261 { 262 struct irq_domain *domain; 263 264 domain = __irq_domain_create(fwnode, size, hwirq_max, direct_max, 265 ops, host_data); 266 if (domain) 267 __irq_domain_publish(domain); 268 269 return domain; 270 } 271 EXPORT_SYMBOL_GPL(__irq_domain_add); 272 273 /** 274 * irq_domain_remove() - Remove an irq domain. 275 * @domain: domain to remove 276 * 277 * This routine is used to remove an irq domain. The caller must ensure 278 * that all mappings within the domain have been disposed of prior to 279 * use, depending on the revmap type. 280 */ 281 void irq_domain_remove(struct irq_domain *domain) 282 { 283 mutex_lock(&irq_domain_mutex); 284 debugfs_remove_domain_dir(domain); 285 286 WARN_ON(!radix_tree_empty(&domain->revmap_tree)); 287 288 list_del(&domain->link); 289 290 /* 291 * If the going away domain is the default one, reset it. 292 */ 293 if (unlikely(irq_default_domain == domain)) 294 irq_set_default_host(NULL); 295 296 mutex_unlock(&irq_domain_mutex); 297 298 pr_debug("Removed domain %s\n", domain->name); 299 300 fwnode_dev_initialized(domain->fwnode, false); 301 fwnode_handle_put(domain->fwnode); 302 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED) 303 kfree(domain->name); 304 kfree(domain); 305 } 306 EXPORT_SYMBOL_GPL(irq_domain_remove); 307 308 void irq_domain_update_bus_token(struct irq_domain *domain, 309 enum irq_domain_bus_token bus_token) 310 { 311 char *name; 312 313 if (domain->bus_token == bus_token) 314 return; 315 316 mutex_lock(&irq_domain_mutex); 317 318 domain->bus_token = bus_token; 319 320 name = kasprintf(GFP_KERNEL, "%s-%d", domain->name, bus_token); 321 if (!name) { 322 mutex_unlock(&irq_domain_mutex); 323 return; 324 } 325 326 debugfs_remove_domain_dir(domain); 327 328 if (domain->flags & IRQ_DOMAIN_NAME_ALLOCATED) 329 kfree(domain->name); 330 else 331 domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED; 332 333 domain->name = name; 334 debugfs_add_domain_dir(domain); 335 336 mutex_unlock(&irq_domain_mutex); 337 } 338 EXPORT_SYMBOL_GPL(irq_domain_update_bus_token); 339 340 /** 341 * irq_domain_create_simple() - Register an irq_domain and optionally map a range of irqs 342 * @fwnode: firmware node for the interrupt controller 343 * @size: total number of irqs in mapping 344 * @first_irq: first number of irq block assigned to the domain, 345 * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then 346 * pre-map all of the irqs in the domain to virqs starting at first_irq. 347 * @ops: domain callbacks 348 * @host_data: Controller private data pointer 349 * 350 * Allocates an irq_domain, and optionally if first_irq is positive then also 351 * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq. 352 * 353 * This is intended to implement the expected behaviour for most 354 * interrupt controllers. If device tree is used, then first_irq will be 0 and 355 * irqs get mapped dynamically on the fly. However, if the controller requires 356 * static virq assignments (non-DT boot) then it will set that up correctly. 357 */ 358 struct irq_domain *irq_domain_create_simple(struct fwnode_handle *fwnode, 359 unsigned int size, 360 unsigned int first_irq, 361 const struct irq_domain_ops *ops, 362 void *host_data) 363 { 364 struct irq_domain *domain; 365 366 domain = __irq_domain_add(fwnode, size, size, 0, ops, host_data); 367 if (!domain) 368 return NULL; 369 370 if (first_irq > 0) { 371 if (IS_ENABLED(CONFIG_SPARSE_IRQ)) { 372 /* attempt to allocated irq_descs */ 373 int rc = irq_alloc_descs(first_irq, first_irq, size, 374 of_node_to_nid(to_of_node(fwnode))); 375 if (rc < 0) 376 pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n", 377 first_irq); 378 } 379 irq_domain_associate_many(domain, first_irq, 0, size); 380 } 381 382 return domain; 383 } 384 EXPORT_SYMBOL_GPL(irq_domain_create_simple); 385 386 /** 387 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain. 388 * @of_node: pointer to interrupt controller's device tree node. 389 * @size: total number of irqs in legacy mapping 390 * @first_irq: first number of irq block assigned to the domain 391 * @first_hwirq: first hwirq number to use for the translation. Should normally 392 * be '0', but a positive integer can be used if the effective 393 * hwirqs numbering does not begin at zero. 394 * @ops: map/unmap domain callbacks 395 * @host_data: Controller private data pointer 396 * 397 * Note: the map() callback will be called before this function returns 398 * for all legacy interrupts except 0 (which is always the invalid irq for 399 * a legacy controller). 400 */ 401 struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, 402 unsigned int size, 403 unsigned int first_irq, 404 irq_hw_number_t first_hwirq, 405 const struct irq_domain_ops *ops, 406 void *host_data) 407 { 408 return irq_domain_create_legacy(of_node_to_fwnode(of_node), size, 409 first_irq, first_hwirq, ops, host_data); 410 } 411 EXPORT_SYMBOL_GPL(irq_domain_add_legacy); 412 413 struct irq_domain *irq_domain_create_legacy(struct fwnode_handle *fwnode, 414 unsigned int size, 415 unsigned int first_irq, 416 irq_hw_number_t first_hwirq, 417 const struct irq_domain_ops *ops, 418 void *host_data) 419 { 420 struct irq_domain *domain; 421 422 domain = __irq_domain_add(fwnode, first_hwirq + size, first_hwirq + size, 0, ops, host_data); 423 if (domain) 424 irq_domain_associate_many(domain, first_irq, first_hwirq, size); 425 426 return domain; 427 } 428 EXPORT_SYMBOL_GPL(irq_domain_create_legacy); 429 430 /** 431 * irq_find_matching_fwspec() - Locates a domain for a given fwspec 432 * @fwspec: FW specifier for an interrupt 433 * @bus_token: domain-specific data 434 */ 435 struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec, 436 enum irq_domain_bus_token bus_token) 437 { 438 struct irq_domain *h, *found = NULL; 439 struct fwnode_handle *fwnode = fwspec->fwnode; 440 int rc; 441 442 /* We might want to match the legacy controller last since 443 * it might potentially be set to match all interrupts in 444 * the absence of a device node. This isn't a problem so far 445 * yet though... 446 * 447 * bus_token == DOMAIN_BUS_ANY matches any domain, any other 448 * values must generate an exact match for the domain to be 449 * selected. 450 */ 451 mutex_lock(&irq_domain_mutex); 452 list_for_each_entry(h, &irq_domain_list, link) { 453 if (h->ops->select && fwspec->param_count) 454 rc = h->ops->select(h, fwspec, bus_token); 455 else if (h->ops->match) 456 rc = h->ops->match(h, to_of_node(fwnode), bus_token); 457 else 458 rc = ((fwnode != NULL) && (h->fwnode == fwnode) && 459 ((bus_token == DOMAIN_BUS_ANY) || 460 (h->bus_token == bus_token))); 461 462 if (rc) { 463 found = h; 464 break; 465 } 466 } 467 mutex_unlock(&irq_domain_mutex); 468 return found; 469 } 470 EXPORT_SYMBOL_GPL(irq_find_matching_fwspec); 471 472 /** 473 * irq_domain_check_msi_remap - Check whether all MSI irq domains implement 474 * IRQ remapping 475 * 476 * Return: false if any MSI irq domain does not support IRQ remapping, 477 * true otherwise (including if there is no MSI irq domain) 478 */ 479 bool irq_domain_check_msi_remap(void) 480 { 481 struct irq_domain *h; 482 bool ret = true; 483 484 mutex_lock(&irq_domain_mutex); 485 list_for_each_entry(h, &irq_domain_list, link) { 486 if (irq_domain_is_msi(h) && 487 !irq_domain_hierarchical_is_msi_remap(h)) { 488 ret = false; 489 break; 490 } 491 } 492 mutex_unlock(&irq_domain_mutex); 493 return ret; 494 } 495 EXPORT_SYMBOL_GPL(irq_domain_check_msi_remap); 496 497 /** 498 * irq_set_default_host() - Set a "default" irq domain 499 * @domain: default domain pointer 500 * 501 * For convenience, it's possible to set a "default" domain that will be used 502 * whenever NULL is passed to irq_create_mapping(). It makes life easier for 503 * platforms that want to manipulate a few hard coded interrupt numbers that 504 * aren't properly represented in the device-tree. 505 */ 506 void irq_set_default_host(struct irq_domain *domain) 507 { 508 pr_debug("Default domain set to @0x%p\n", domain); 509 510 irq_default_domain = domain; 511 } 512 EXPORT_SYMBOL_GPL(irq_set_default_host); 513 514 /** 515 * irq_get_default_host() - Retrieve the "default" irq domain 516 * 517 * Returns: the default domain, if any. 518 * 519 * Modern code should never use this. This should only be used on 520 * systems that cannot implement a firmware->fwnode mapping (which 521 * both DT and ACPI provide). 522 */ 523 struct irq_domain *irq_get_default_host(void) 524 { 525 return irq_default_domain; 526 } 527 EXPORT_SYMBOL_GPL(irq_get_default_host); 528 529 static bool irq_domain_is_nomap(struct irq_domain *domain) 530 { 531 return IS_ENABLED(CONFIG_IRQ_DOMAIN_NOMAP) && 532 (domain->flags & IRQ_DOMAIN_FLAG_NO_MAP); 533 } 534 535 static void irq_domain_clear_mapping(struct irq_domain *domain, 536 irq_hw_number_t hwirq) 537 { 538 lockdep_assert_held(&domain->root->mutex); 539 540 if (irq_domain_is_nomap(domain)) 541 return; 542 543 if (hwirq < domain->revmap_size) 544 rcu_assign_pointer(domain->revmap[hwirq], NULL); 545 else 546 radix_tree_delete(&domain->revmap_tree, hwirq); 547 } 548 549 static void irq_domain_set_mapping(struct irq_domain *domain, 550 irq_hw_number_t hwirq, 551 struct irq_data *irq_data) 552 { 553 /* 554 * This also makes sure that all domains point to the same root when 555 * called from irq_domain_insert_irq() for each domain in a hierarchy. 556 */ 557 lockdep_assert_held(&domain->root->mutex); 558 559 if (irq_domain_is_nomap(domain)) 560 return; 561 562 if (hwirq < domain->revmap_size) 563 rcu_assign_pointer(domain->revmap[hwirq], irq_data); 564 else 565 radix_tree_insert(&domain->revmap_tree, hwirq, irq_data); 566 } 567 568 static void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq) 569 { 570 struct irq_data *irq_data = irq_get_irq_data(irq); 571 irq_hw_number_t hwirq; 572 573 if (WARN(!irq_data || irq_data->domain != domain, 574 "virq%i doesn't exist; cannot disassociate\n", irq)) 575 return; 576 577 hwirq = irq_data->hwirq; 578 579 mutex_lock(&domain->root->mutex); 580 581 irq_set_status_flags(irq, IRQ_NOREQUEST); 582 583 /* remove chip and handler */ 584 irq_set_chip_and_handler(irq, NULL, NULL); 585 586 /* Make sure it's completed */ 587 synchronize_irq(irq); 588 589 /* Tell the PIC about it */ 590 if (domain->ops->unmap) 591 domain->ops->unmap(domain, irq); 592 smp_mb(); 593 594 irq_data->domain = NULL; 595 irq_data->hwirq = 0; 596 domain->mapcount--; 597 598 /* Clear reverse map for this hwirq */ 599 irq_domain_clear_mapping(domain, hwirq); 600 601 mutex_unlock(&domain->root->mutex); 602 } 603 604 static int irq_domain_associate_locked(struct irq_domain *domain, unsigned int virq, 605 irq_hw_number_t hwirq) 606 { 607 struct irq_data *irq_data = irq_get_irq_data(virq); 608 int ret; 609 610 if (WARN(hwirq >= domain->hwirq_max, 611 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name)) 612 return -EINVAL; 613 if (WARN(!irq_data, "error: virq%i is not allocated", virq)) 614 return -EINVAL; 615 if (WARN(irq_data->domain, "error: virq%i is already associated", virq)) 616 return -EINVAL; 617 618 irq_data->hwirq = hwirq; 619 irq_data->domain = domain; 620 if (domain->ops->map) { 621 ret = domain->ops->map(domain, virq, hwirq); 622 if (ret != 0) { 623 /* 624 * If map() returns -EPERM, this interrupt is protected 625 * by the firmware or some other service and shall not 626 * be mapped. Don't bother telling the user about it. 627 */ 628 if (ret != -EPERM) { 629 pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n", 630 domain->name, hwirq, virq, ret); 631 } 632 irq_data->domain = NULL; 633 irq_data->hwirq = 0; 634 return ret; 635 } 636 } 637 638 domain->mapcount++; 639 irq_domain_set_mapping(domain, hwirq, irq_data); 640 641 irq_clear_status_flags(virq, IRQ_NOREQUEST); 642 643 return 0; 644 } 645 646 int irq_domain_associate(struct irq_domain *domain, unsigned int virq, 647 irq_hw_number_t hwirq) 648 { 649 int ret; 650 651 mutex_lock(&domain->root->mutex); 652 ret = irq_domain_associate_locked(domain, virq, hwirq); 653 mutex_unlock(&domain->root->mutex); 654 655 return ret; 656 } 657 EXPORT_SYMBOL_GPL(irq_domain_associate); 658 659 void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base, 660 irq_hw_number_t hwirq_base, int count) 661 { 662 struct device_node *of_node; 663 int i; 664 665 of_node = irq_domain_get_of_node(domain); 666 pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__, 667 of_node_full_name(of_node), irq_base, (int)hwirq_base, count); 668 669 for (i = 0; i < count; i++) 670 irq_domain_associate(domain, irq_base + i, hwirq_base + i); 671 } 672 EXPORT_SYMBOL_GPL(irq_domain_associate_many); 673 674 #ifdef CONFIG_IRQ_DOMAIN_NOMAP 675 /** 676 * irq_create_direct_mapping() - Allocate an irq for direct mapping 677 * @domain: domain to allocate the irq for or NULL for default domain 678 * 679 * This routine is used for irq controllers which can choose the hardware 680 * interrupt numbers they generate. In such a case it's simplest to use 681 * the linux irq as the hardware interrupt number. It still uses the linear 682 * or radix tree to store the mapping, but the irq controller can optimize 683 * the revmap path by using the hwirq directly. 684 */ 685 unsigned int irq_create_direct_mapping(struct irq_domain *domain) 686 { 687 struct device_node *of_node; 688 unsigned int virq; 689 690 if (domain == NULL) 691 domain = irq_default_domain; 692 693 of_node = irq_domain_get_of_node(domain); 694 virq = irq_alloc_desc_from(1, of_node_to_nid(of_node)); 695 if (!virq) { 696 pr_debug("create_direct virq allocation failed\n"); 697 return 0; 698 } 699 if (virq >= domain->hwirq_max) { 700 pr_err("ERROR: no free irqs available below %lu maximum\n", 701 domain->hwirq_max); 702 irq_free_desc(virq); 703 return 0; 704 } 705 pr_debug("create_direct obtained virq %d\n", virq); 706 707 if (irq_domain_associate(domain, virq, virq)) { 708 irq_free_desc(virq); 709 return 0; 710 } 711 712 return virq; 713 } 714 EXPORT_SYMBOL_GPL(irq_create_direct_mapping); 715 #endif 716 717 static unsigned int irq_create_mapping_affinity_locked(struct irq_domain *domain, 718 irq_hw_number_t hwirq, 719 const struct irq_affinity_desc *affinity) 720 { 721 struct device_node *of_node = irq_domain_get_of_node(domain); 722 int virq; 723 724 pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); 725 726 /* Allocate a virtual interrupt number */ 727 virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(of_node), 728 affinity); 729 if (virq <= 0) { 730 pr_debug("-> virq allocation failed\n"); 731 return 0; 732 } 733 734 if (irq_domain_associate_locked(domain, virq, hwirq)) { 735 irq_free_desc(virq); 736 return 0; 737 } 738 739 pr_debug("irq %lu on domain %s mapped to virtual irq %u\n", 740 hwirq, of_node_full_name(of_node), virq); 741 742 return virq; 743 } 744 745 /** 746 * irq_create_mapping_affinity() - Map a hardware interrupt into linux irq space 747 * @domain: domain owning this hardware interrupt or NULL for default domain 748 * @hwirq: hardware irq number in that domain space 749 * @affinity: irq affinity 750 * 751 * Only one mapping per hardware interrupt is permitted. Returns a linux 752 * irq number. 753 * If the sense/trigger is to be specified, set_irq_type() should be called 754 * on the number returned from that call. 755 */ 756 unsigned int irq_create_mapping_affinity(struct irq_domain *domain, 757 irq_hw_number_t hwirq, 758 const struct irq_affinity_desc *affinity) 759 { 760 int virq; 761 762 /* Look for default domain if necessary */ 763 if (domain == NULL) 764 domain = irq_default_domain; 765 if (domain == NULL) { 766 WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq); 767 return 0; 768 } 769 770 mutex_lock(&domain->root->mutex); 771 772 /* Check if mapping already exists */ 773 virq = irq_find_mapping(domain, hwirq); 774 if (virq) { 775 pr_debug("existing mapping on virq %d\n", virq); 776 goto out; 777 } 778 779 virq = irq_create_mapping_affinity_locked(domain, hwirq, affinity); 780 out: 781 mutex_unlock(&domain->root->mutex); 782 783 return virq; 784 } 785 EXPORT_SYMBOL_GPL(irq_create_mapping_affinity); 786 787 static int irq_domain_translate(struct irq_domain *d, 788 struct irq_fwspec *fwspec, 789 irq_hw_number_t *hwirq, unsigned int *type) 790 { 791 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 792 if (d->ops->translate) 793 return d->ops->translate(d, fwspec, hwirq, type); 794 #endif 795 if (d->ops->xlate) 796 return d->ops->xlate(d, to_of_node(fwspec->fwnode), 797 fwspec->param, fwspec->param_count, 798 hwirq, type); 799 800 /* If domain has no translation, then we assume interrupt line */ 801 *hwirq = fwspec->param[0]; 802 return 0; 803 } 804 805 void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args, 806 unsigned int count, struct irq_fwspec *fwspec) 807 { 808 int i; 809 810 fwspec->fwnode = of_node_to_fwnode(np); 811 fwspec->param_count = count; 812 813 for (i = 0; i < count; i++) 814 fwspec->param[i] = args[i]; 815 } 816 EXPORT_SYMBOL_GPL(of_phandle_args_to_fwspec); 817 818 unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec) 819 { 820 struct irq_domain *domain; 821 struct irq_data *irq_data; 822 irq_hw_number_t hwirq; 823 unsigned int type = IRQ_TYPE_NONE; 824 int virq; 825 826 if (fwspec->fwnode) { 827 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_WIRED); 828 if (!domain) 829 domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_ANY); 830 } else { 831 domain = irq_default_domain; 832 } 833 834 if (!domain) { 835 pr_warn("no irq domain found for %s !\n", 836 of_node_full_name(to_of_node(fwspec->fwnode))); 837 return 0; 838 } 839 840 if (irq_domain_translate(domain, fwspec, &hwirq, &type)) 841 return 0; 842 843 /* 844 * WARN if the irqchip returns a type with bits 845 * outside the sense mask set and clear these bits. 846 */ 847 if (WARN_ON(type & ~IRQ_TYPE_SENSE_MASK)) 848 type &= IRQ_TYPE_SENSE_MASK; 849 850 mutex_lock(&domain->root->mutex); 851 852 /* 853 * If we've already configured this interrupt, 854 * don't do it again, or hell will break loose. 855 */ 856 virq = irq_find_mapping(domain, hwirq); 857 if (virq) { 858 /* 859 * If the trigger type is not specified or matches the 860 * current trigger type then we are done so return the 861 * interrupt number. 862 */ 863 if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq)) 864 goto out; 865 866 /* 867 * If the trigger type has not been set yet, then set 868 * it now and return the interrupt number. 869 */ 870 if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) { 871 irq_data = irq_get_irq_data(virq); 872 if (!irq_data) { 873 virq = 0; 874 goto out; 875 } 876 877 irqd_set_trigger_type(irq_data, type); 878 goto out; 879 } 880 881 pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n", 882 hwirq, of_node_full_name(to_of_node(fwspec->fwnode))); 883 virq = 0; 884 goto out; 885 } 886 887 if (irq_domain_is_hierarchy(domain)) { 888 virq = irq_domain_alloc_irqs_locked(domain, -1, 1, NUMA_NO_NODE, 889 fwspec, false, NULL); 890 if (virq <= 0) { 891 virq = 0; 892 goto out; 893 } 894 } else { 895 /* Create mapping */ 896 virq = irq_create_mapping_affinity_locked(domain, hwirq, NULL); 897 if (!virq) 898 goto out; 899 } 900 901 irq_data = irq_get_irq_data(virq); 902 if (WARN_ON(!irq_data)) { 903 virq = 0; 904 goto out; 905 } 906 907 /* Store trigger type */ 908 irqd_set_trigger_type(irq_data, type); 909 out: 910 mutex_unlock(&domain->root->mutex); 911 912 return virq; 913 } 914 EXPORT_SYMBOL_GPL(irq_create_fwspec_mapping); 915 916 unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data) 917 { 918 struct irq_fwspec fwspec; 919 920 of_phandle_args_to_fwspec(irq_data->np, irq_data->args, 921 irq_data->args_count, &fwspec); 922 923 return irq_create_fwspec_mapping(&fwspec); 924 } 925 EXPORT_SYMBOL_GPL(irq_create_of_mapping); 926 927 /** 928 * irq_dispose_mapping() - Unmap an interrupt 929 * @virq: linux irq number of the interrupt to unmap 930 */ 931 void irq_dispose_mapping(unsigned int virq) 932 { 933 struct irq_data *irq_data = irq_get_irq_data(virq); 934 struct irq_domain *domain; 935 936 if (!virq || !irq_data) 937 return; 938 939 domain = irq_data->domain; 940 if (WARN_ON(domain == NULL)) 941 return; 942 943 if (irq_domain_is_hierarchy(domain)) { 944 irq_domain_free_irqs(virq, 1); 945 } else { 946 irq_domain_disassociate(domain, virq); 947 irq_free_desc(virq); 948 } 949 } 950 EXPORT_SYMBOL_GPL(irq_dispose_mapping); 951 952 /** 953 * __irq_resolve_mapping() - Find a linux irq from a hw irq number. 954 * @domain: domain owning this hardware interrupt 955 * @hwirq: hardware irq number in that domain space 956 * @irq: optional pointer to return the Linux irq if required 957 * 958 * Returns the interrupt descriptor. 959 */ 960 struct irq_desc *__irq_resolve_mapping(struct irq_domain *domain, 961 irq_hw_number_t hwirq, 962 unsigned int *irq) 963 { 964 struct irq_desc *desc = NULL; 965 struct irq_data *data; 966 967 /* Look for default domain if necessary */ 968 if (domain == NULL) 969 domain = irq_default_domain; 970 if (domain == NULL) 971 return desc; 972 973 if (irq_domain_is_nomap(domain)) { 974 if (hwirq < domain->hwirq_max) { 975 data = irq_domain_get_irq_data(domain, hwirq); 976 if (data && data->hwirq == hwirq) 977 desc = irq_data_to_desc(data); 978 if (irq && desc) 979 *irq = hwirq; 980 } 981 982 return desc; 983 } 984 985 rcu_read_lock(); 986 /* Check if the hwirq is in the linear revmap. */ 987 if (hwirq < domain->revmap_size) 988 data = rcu_dereference(domain->revmap[hwirq]); 989 else 990 data = radix_tree_lookup(&domain->revmap_tree, hwirq); 991 992 if (likely(data)) { 993 desc = irq_data_to_desc(data); 994 if (irq) 995 *irq = data->irq; 996 } 997 998 rcu_read_unlock(); 999 return desc; 1000 } 1001 EXPORT_SYMBOL_GPL(__irq_resolve_mapping); 1002 1003 /** 1004 * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings 1005 * 1006 * Device Tree IRQ specifier translation function which works with one cell 1007 * bindings where the cell value maps directly to the hwirq number. 1008 */ 1009 int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr, 1010 const u32 *intspec, unsigned int intsize, 1011 unsigned long *out_hwirq, unsigned int *out_type) 1012 { 1013 if (WARN_ON(intsize < 1)) 1014 return -EINVAL; 1015 *out_hwirq = intspec[0]; 1016 *out_type = IRQ_TYPE_NONE; 1017 return 0; 1018 } 1019 EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell); 1020 1021 /** 1022 * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings 1023 * 1024 * Device Tree IRQ specifier translation function which works with two cell 1025 * bindings where the cell values map directly to the hwirq number 1026 * and linux irq flags. 1027 */ 1028 int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr, 1029 const u32 *intspec, unsigned int intsize, 1030 irq_hw_number_t *out_hwirq, unsigned int *out_type) 1031 { 1032 struct irq_fwspec fwspec; 1033 1034 of_phandle_args_to_fwspec(ctrlr, intspec, intsize, &fwspec); 1035 return irq_domain_translate_twocell(d, &fwspec, out_hwirq, out_type); 1036 } 1037 EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell); 1038 1039 /** 1040 * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings 1041 * 1042 * Device Tree IRQ specifier translation function which works with either one 1043 * or two cell bindings where the cell values map directly to the hwirq number 1044 * and linux irq flags. 1045 * 1046 * Note: don't use this function unless your interrupt controller explicitly 1047 * supports both one and two cell bindings. For the majority of controllers 1048 * the _onecell() or _twocell() variants above should be used. 1049 */ 1050 int irq_domain_xlate_onetwocell(struct irq_domain *d, 1051 struct device_node *ctrlr, 1052 const u32 *intspec, unsigned int intsize, 1053 unsigned long *out_hwirq, unsigned int *out_type) 1054 { 1055 if (WARN_ON(intsize < 1)) 1056 return -EINVAL; 1057 *out_hwirq = intspec[0]; 1058 if (intsize > 1) 1059 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; 1060 else 1061 *out_type = IRQ_TYPE_NONE; 1062 return 0; 1063 } 1064 EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell); 1065 1066 const struct irq_domain_ops irq_domain_simple_ops = { 1067 .xlate = irq_domain_xlate_onetwocell, 1068 }; 1069 EXPORT_SYMBOL_GPL(irq_domain_simple_ops); 1070 1071 /** 1072 * irq_domain_translate_onecell() - Generic translate for direct one cell 1073 * bindings 1074 */ 1075 int irq_domain_translate_onecell(struct irq_domain *d, 1076 struct irq_fwspec *fwspec, 1077 unsigned long *out_hwirq, 1078 unsigned int *out_type) 1079 { 1080 if (WARN_ON(fwspec->param_count < 1)) 1081 return -EINVAL; 1082 *out_hwirq = fwspec->param[0]; 1083 *out_type = IRQ_TYPE_NONE; 1084 return 0; 1085 } 1086 EXPORT_SYMBOL_GPL(irq_domain_translate_onecell); 1087 1088 /** 1089 * irq_domain_translate_twocell() - Generic translate for direct two cell 1090 * bindings 1091 * 1092 * Device Tree IRQ specifier translation function which works with two cell 1093 * bindings where the cell values map directly to the hwirq number 1094 * and linux irq flags. 1095 */ 1096 int irq_domain_translate_twocell(struct irq_domain *d, 1097 struct irq_fwspec *fwspec, 1098 unsigned long *out_hwirq, 1099 unsigned int *out_type) 1100 { 1101 if (WARN_ON(fwspec->param_count < 2)) 1102 return -EINVAL; 1103 *out_hwirq = fwspec->param[0]; 1104 *out_type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK; 1105 return 0; 1106 } 1107 EXPORT_SYMBOL_GPL(irq_domain_translate_twocell); 1108 1109 int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq, 1110 int node, const struct irq_affinity_desc *affinity) 1111 { 1112 unsigned int hint; 1113 1114 if (virq >= 0) { 1115 virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE, 1116 affinity); 1117 } else { 1118 hint = hwirq % nr_irqs; 1119 if (hint == 0) 1120 hint++; 1121 virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE, 1122 affinity); 1123 if (virq <= 0 && hint > 1) { 1124 virq = __irq_alloc_descs(-1, 1, cnt, node, THIS_MODULE, 1125 affinity); 1126 } 1127 } 1128 1129 return virq; 1130 } 1131 1132 /** 1133 * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data 1134 * @irq_data: The pointer to irq_data 1135 */ 1136 void irq_domain_reset_irq_data(struct irq_data *irq_data) 1137 { 1138 irq_data->hwirq = 0; 1139 irq_data->chip = &no_irq_chip; 1140 irq_data->chip_data = NULL; 1141 } 1142 EXPORT_SYMBOL_GPL(irq_domain_reset_irq_data); 1143 1144 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 1145 /** 1146 * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy 1147 * @parent: Parent irq domain to associate with the new domain 1148 * @flags: Irq domain flags associated to the domain 1149 * @size: Size of the domain. See below 1150 * @fwnode: Optional fwnode of the interrupt controller 1151 * @ops: Pointer to the interrupt domain callbacks 1152 * @host_data: Controller private data pointer 1153 * 1154 * If @size is 0 a tree domain is created, otherwise a linear domain. 1155 * 1156 * If successful the parent is associated to the new domain and the 1157 * domain flags are set. 1158 * Returns pointer to IRQ domain, or NULL on failure. 1159 */ 1160 struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent, 1161 unsigned int flags, 1162 unsigned int size, 1163 struct fwnode_handle *fwnode, 1164 const struct irq_domain_ops *ops, 1165 void *host_data) 1166 { 1167 struct irq_domain *domain; 1168 1169 if (size) 1170 domain = __irq_domain_create(fwnode, size, size, 0, ops, host_data); 1171 else 1172 domain = __irq_domain_create(fwnode, 0, ~0, 0, ops, host_data); 1173 1174 if (domain) { 1175 domain->root = parent->root; 1176 domain->parent = parent; 1177 domain->flags |= flags; 1178 1179 __irq_domain_publish(domain); 1180 } 1181 1182 return domain; 1183 } 1184 EXPORT_SYMBOL_GPL(irq_domain_create_hierarchy); 1185 1186 static void irq_domain_insert_irq(int virq) 1187 { 1188 struct irq_data *data; 1189 1190 for (data = irq_get_irq_data(virq); data; data = data->parent_data) { 1191 struct irq_domain *domain = data->domain; 1192 1193 domain->mapcount++; 1194 irq_domain_set_mapping(domain, data->hwirq, data); 1195 } 1196 1197 irq_clear_status_flags(virq, IRQ_NOREQUEST); 1198 } 1199 1200 static void irq_domain_remove_irq(int virq) 1201 { 1202 struct irq_data *data; 1203 1204 irq_set_status_flags(virq, IRQ_NOREQUEST); 1205 irq_set_chip_and_handler(virq, NULL, NULL); 1206 synchronize_irq(virq); 1207 smp_mb(); 1208 1209 for (data = irq_get_irq_data(virq); data; data = data->parent_data) { 1210 struct irq_domain *domain = data->domain; 1211 irq_hw_number_t hwirq = data->hwirq; 1212 1213 domain->mapcount--; 1214 irq_domain_clear_mapping(domain, hwirq); 1215 } 1216 } 1217 1218 static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain, 1219 struct irq_data *child) 1220 { 1221 struct irq_data *irq_data; 1222 1223 irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL, 1224 irq_data_get_node(child)); 1225 if (irq_data) { 1226 child->parent_data = irq_data; 1227 irq_data->irq = child->irq; 1228 irq_data->common = child->common; 1229 irq_data->domain = domain; 1230 } 1231 1232 return irq_data; 1233 } 1234 1235 static void __irq_domain_free_hierarchy(struct irq_data *irq_data) 1236 { 1237 struct irq_data *tmp; 1238 1239 while (irq_data) { 1240 tmp = irq_data; 1241 irq_data = irq_data->parent_data; 1242 kfree(tmp); 1243 } 1244 } 1245 1246 static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs) 1247 { 1248 struct irq_data *irq_data, *tmp; 1249 int i; 1250 1251 for (i = 0; i < nr_irqs; i++) { 1252 irq_data = irq_get_irq_data(virq + i); 1253 tmp = irq_data->parent_data; 1254 irq_data->parent_data = NULL; 1255 irq_data->domain = NULL; 1256 1257 __irq_domain_free_hierarchy(tmp); 1258 } 1259 } 1260 1261 /** 1262 * irq_domain_disconnect_hierarchy - Mark the first unused level of a hierarchy 1263 * @domain: IRQ domain from which the hierarchy is to be disconnected 1264 * @virq: IRQ number where the hierarchy is to be trimmed 1265 * 1266 * Marks the @virq level belonging to @domain as disconnected. 1267 * Returns -EINVAL if @virq doesn't have a valid irq_data pointing 1268 * to @domain. 1269 * 1270 * Its only use is to be able to trim levels of hierarchy that do not 1271 * have any real meaning for this interrupt, and that the driver marks 1272 * as such from its .alloc() callback. 1273 */ 1274 int irq_domain_disconnect_hierarchy(struct irq_domain *domain, 1275 unsigned int virq) 1276 { 1277 struct irq_data *irqd; 1278 1279 irqd = irq_domain_get_irq_data(domain, virq); 1280 if (!irqd) 1281 return -EINVAL; 1282 1283 irqd->chip = ERR_PTR(-ENOTCONN); 1284 return 0; 1285 } 1286 EXPORT_SYMBOL_GPL(irq_domain_disconnect_hierarchy); 1287 1288 static int irq_domain_trim_hierarchy(unsigned int virq) 1289 { 1290 struct irq_data *tail, *irqd, *irq_data; 1291 1292 irq_data = irq_get_irq_data(virq); 1293 tail = NULL; 1294 1295 /* The first entry must have a valid irqchip */ 1296 if (!irq_data->chip || IS_ERR(irq_data->chip)) 1297 return -EINVAL; 1298 1299 /* 1300 * Validate that the irq_data chain is sane in the presence of 1301 * a hierarchy trimming marker. 1302 */ 1303 for (irqd = irq_data->parent_data; irqd; irq_data = irqd, irqd = irqd->parent_data) { 1304 /* Can't have a valid irqchip after a trim marker */ 1305 if (irqd->chip && tail) 1306 return -EINVAL; 1307 1308 /* Can't have an empty irqchip before a trim marker */ 1309 if (!irqd->chip && !tail) 1310 return -EINVAL; 1311 1312 if (IS_ERR(irqd->chip)) { 1313 /* Only -ENOTCONN is a valid trim marker */ 1314 if (PTR_ERR(irqd->chip) != -ENOTCONN) 1315 return -EINVAL; 1316 1317 tail = irq_data; 1318 } 1319 } 1320 1321 /* No trim marker, nothing to do */ 1322 if (!tail) 1323 return 0; 1324 1325 pr_info("IRQ%d: trimming hierarchy from %s\n", 1326 virq, tail->parent_data->domain->name); 1327 1328 /* Sever the inner part of the hierarchy... */ 1329 irqd = tail; 1330 tail = tail->parent_data; 1331 irqd->parent_data = NULL; 1332 __irq_domain_free_hierarchy(tail); 1333 1334 return 0; 1335 } 1336 1337 static int irq_domain_alloc_irq_data(struct irq_domain *domain, 1338 unsigned int virq, unsigned int nr_irqs) 1339 { 1340 struct irq_data *irq_data; 1341 struct irq_domain *parent; 1342 int i; 1343 1344 /* The outermost irq_data is embedded in struct irq_desc */ 1345 for (i = 0; i < nr_irqs; i++) { 1346 irq_data = irq_get_irq_data(virq + i); 1347 irq_data->domain = domain; 1348 1349 for (parent = domain->parent; parent; parent = parent->parent) { 1350 irq_data = irq_domain_insert_irq_data(parent, irq_data); 1351 if (!irq_data) { 1352 irq_domain_free_irq_data(virq, i + 1); 1353 return -ENOMEM; 1354 } 1355 } 1356 } 1357 1358 return 0; 1359 } 1360 1361 /** 1362 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain 1363 * @domain: domain to match 1364 * @virq: IRQ number to get irq_data 1365 */ 1366 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, 1367 unsigned int virq) 1368 { 1369 struct irq_data *irq_data; 1370 1371 for (irq_data = irq_get_irq_data(virq); irq_data; 1372 irq_data = irq_data->parent_data) 1373 if (irq_data->domain == domain) 1374 return irq_data; 1375 1376 return NULL; 1377 } 1378 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data); 1379 1380 /** 1381 * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain 1382 * @domain: Interrupt domain to match 1383 * @virq: IRQ number 1384 * @hwirq: The hwirq number 1385 * @chip: The associated interrupt chip 1386 * @chip_data: The associated chip data 1387 */ 1388 int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq, 1389 irq_hw_number_t hwirq, 1390 const struct irq_chip *chip, 1391 void *chip_data) 1392 { 1393 struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq); 1394 1395 if (!irq_data) 1396 return -ENOENT; 1397 1398 irq_data->hwirq = hwirq; 1399 irq_data->chip = (struct irq_chip *)(chip ? chip : &no_irq_chip); 1400 irq_data->chip_data = chip_data; 1401 1402 return 0; 1403 } 1404 EXPORT_SYMBOL_GPL(irq_domain_set_hwirq_and_chip); 1405 1406 /** 1407 * irq_domain_set_info - Set the complete data for a @virq in @domain 1408 * @domain: Interrupt domain to match 1409 * @virq: IRQ number 1410 * @hwirq: The hardware interrupt number 1411 * @chip: The associated interrupt chip 1412 * @chip_data: The associated interrupt chip data 1413 * @handler: The interrupt flow handler 1414 * @handler_data: The interrupt flow handler data 1415 * @handler_name: The interrupt handler name 1416 */ 1417 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq, 1418 irq_hw_number_t hwirq, const struct irq_chip *chip, 1419 void *chip_data, irq_flow_handler_t handler, 1420 void *handler_data, const char *handler_name) 1421 { 1422 irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data); 1423 __irq_set_handler(virq, handler, 0, handler_name); 1424 irq_set_handler_data(virq, handler_data); 1425 } 1426 EXPORT_SYMBOL(irq_domain_set_info); 1427 1428 /** 1429 * irq_domain_free_irqs_common - Clear irq_data and free the parent 1430 * @domain: Interrupt domain to match 1431 * @virq: IRQ number to start with 1432 * @nr_irqs: The number of irqs to free 1433 */ 1434 void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq, 1435 unsigned int nr_irqs) 1436 { 1437 struct irq_data *irq_data; 1438 int i; 1439 1440 for (i = 0; i < nr_irqs; i++) { 1441 irq_data = irq_domain_get_irq_data(domain, virq + i); 1442 if (irq_data) 1443 irq_domain_reset_irq_data(irq_data); 1444 } 1445 irq_domain_free_irqs_parent(domain, virq, nr_irqs); 1446 } 1447 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_common); 1448 1449 /** 1450 * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent 1451 * @domain: Interrupt domain to match 1452 * @virq: IRQ number to start with 1453 * @nr_irqs: The number of irqs to free 1454 */ 1455 void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq, 1456 unsigned int nr_irqs) 1457 { 1458 int i; 1459 1460 for (i = 0; i < nr_irqs; i++) { 1461 irq_set_handler_data(virq + i, NULL); 1462 irq_set_handler(virq + i, NULL); 1463 } 1464 irq_domain_free_irqs_common(domain, virq, nr_irqs); 1465 } 1466 1467 static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain, 1468 unsigned int irq_base, 1469 unsigned int nr_irqs) 1470 { 1471 unsigned int i; 1472 1473 if (!domain->ops->free) 1474 return; 1475 1476 for (i = 0; i < nr_irqs; i++) { 1477 if (irq_domain_get_irq_data(domain, irq_base + i)) 1478 domain->ops->free(domain, irq_base + i, 1); 1479 } 1480 } 1481 1482 int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain, 1483 unsigned int irq_base, 1484 unsigned int nr_irqs, void *arg) 1485 { 1486 if (!domain->ops->alloc) { 1487 pr_debug("domain->ops->alloc() is NULL\n"); 1488 return -ENOSYS; 1489 } 1490 1491 return domain->ops->alloc(domain, irq_base, nr_irqs, arg); 1492 } 1493 1494 static int irq_domain_alloc_irqs_locked(struct irq_domain *domain, int irq_base, 1495 unsigned int nr_irqs, int node, void *arg, 1496 bool realloc, const struct irq_affinity_desc *affinity) 1497 { 1498 int i, ret, virq; 1499 1500 if (realloc && irq_base >= 0) { 1501 virq = irq_base; 1502 } else { 1503 virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node, 1504 affinity); 1505 if (virq < 0) { 1506 pr_debug("cannot allocate IRQ(base %d, count %d)\n", 1507 irq_base, nr_irqs); 1508 return virq; 1509 } 1510 } 1511 1512 if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) { 1513 pr_debug("cannot allocate memory for IRQ%d\n", virq); 1514 ret = -ENOMEM; 1515 goto out_free_desc; 1516 } 1517 1518 ret = irq_domain_alloc_irqs_hierarchy(domain, virq, nr_irqs, arg); 1519 if (ret < 0) 1520 goto out_free_irq_data; 1521 1522 for (i = 0; i < nr_irqs; i++) { 1523 ret = irq_domain_trim_hierarchy(virq + i); 1524 if (ret) 1525 goto out_free_irq_data; 1526 } 1527 1528 for (i = 0; i < nr_irqs; i++) 1529 irq_domain_insert_irq(virq + i); 1530 1531 return virq; 1532 1533 out_free_irq_data: 1534 irq_domain_free_irq_data(virq, nr_irqs); 1535 out_free_desc: 1536 irq_free_descs(virq, nr_irqs); 1537 return ret; 1538 } 1539 1540 /** 1541 * __irq_domain_alloc_irqs - Allocate IRQs from domain 1542 * @domain: domain to allocate from 1543 * @irq_base: allocate specified IRQ number if irq_base >= 0 1544 * @nr_irqs: number of IRQs to allocate 1545 * @node: NUMA node id for memory allocation 1546 * @arg: domain specific argument 1547 * @realloc: IRQ descriptors have already been allocated if true 1548 * @affinity: Optional irq affinity mask for multiqueue devices 1549 * 1550 * Allocate IRQ numbers and initialized all data structures to support 1551 * hierarchy IRQ domains. 1552 * Parameter @realloc is mainly to support legacy IRQs. 1553 * Returns error code or allocated IRQ number 1554 * 1555 * The whole process to setup an IRQ has been split into two steps. 1556 * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ 1557 * descriptor and required hardware resources. The second step, 1558 * irq_domain_activate_irq(), is to program the hardware with preallocated 1559 * resources. In this way, it's easier to rollback when failing to 1560 * allocate resources. 1561 */ 1562 int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, 1563 unsigned int nr_irqs, int node, void *arg, 1564 bool realloc, const struct irq_affinity_desc *affinity) 1565 { 1566 int ret; 1567 1568 if (domain == NULL) { 1569 domain = irq_default_domain; 1570 if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n")) 1571 return -EINVAL; 1572 } 1573 1574 mutex_lock(&domain->root->mutex); 1575 ret = irq_domain_alloc_irqs_locked(domain, irq_base, nr_irqs, node, arg, 1576 realloc, affinity); 1577 mutex_unlock(&domain->root->mutex); 1578 1579 return ret; 1580 } 1581 EXPORT_SYMBOL_GPL(__irq_domain_alloc_irqs); 1582 1583 /* The irq_data was moved, fix the revmap to refer to the new location */ 1584 static void irq_domain_fix_revmap(struct irq_data *d) 1585 { 1586 void __rcu **slot; 1587 1588 lockdep_assert_held(&d->domain->root->mutex); 1589 1590 if (irq_domain_is_nomap(d->domain)) 1591 return; 1592 1593 /* Fix up the revmap. */ 1594 if (d->hwirq < d->domain->revmap_size) { 1595 /* Not using radix tree */ 1596 rcu_assign_pointer(d->domain->revmap[d->hwirq], d); 1597 } else { 1598 slot = radix_tree_lookup_slot(&d->domain->revmap_tree, d->hwirq); 1599 if (slot) 1600 radix_tree_replace_slot(&d->domain->revmap_tree, slot, d); 1601 } 1602 } 1603 1604 /** 1605 * irq_domain_push_irq() - Push a domain in to the top of a hierarchy. 1606 * @domain: Domain to push. 1607 * @virq: Irq to push the domain in to. 1608 * @arg: Passed to the irq_domain_ops alloc() function. 1609 * 1610 * For an already existing irqdomain hierarchy, as might be obtained 1611 * via a call to pci_enable_msix(), add an additional domain to the 1612 * head of the processing chain. Must be called before request_irq() 1613 * has been called. 1614 */ 1615 int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg) 1616 { 1617 struct irq_data *irq_data = irq_get_irq_data(virq); 1618 struct irq_data *parent_irq_data; 1619 struct irq_desc *desc; 1620 int rv = 0; 1621 1622 /* 1623 * Check that no action has been set, which indicates the virq 1624 * is in a state where this function doesn't have to deal with 1625 * races between interrupt handling and maintaining the 1626 * hierarchy. This will catch gross misuse. Attempting to 1627 * make the check race free would require holding locks across 1628 * calls to struct irq_domain_ops->alloc(), which could lead 1629 * to deadlock, so we just do a simple check before starting. 1630 */ 1631 desc = irq_to_desc(virq); 1632 if (!desc) 1633 return -EINVAL; 1634 if (WARN_ON(desc->action)) 1635 return -EBUSY; 1636 1637 if (domain == NULL) 1638 return -EINVAL; 1639 1640 if (WARN_ON(!irq_domain_is_hierarchy(domain))) 1641 return -EINVAL; 1642 1643 if (!irq_data) 1644 return -EINVAL; 1645 1646 if (domain->parent != irq_data->domain) 1647 return -EINVAL; 1648 1649 parent_irq_data = kzalloc_node(sizeof(*parent_irq_data), GFP_KERNEL, 1650 irq_data_get_node(irq_data)); 1651 if (!parent_irq_data) 1652 return -ENOMEM; 1653 1654 mutex_lock(&domain->root->mutex); 1655 1656 /* Copy the original irq_data. */ 1657 *parent_irq_data = *irq_data; 1658 1659 /* 1660 * Overwrite the irq_data, which is embedded in struct irq_desc, with 1661 * values for this domain. 1662 */ 1663 irq_data->parent_data = parent_irq_data; 1664 irq_data->domain = domain; 1665 irq_data->mask = 0; 1666 irq_data->hwirq = 0; 1667 irq_data->chip = NULL; 1668 irq_data->chip_data = NULL; 1669 1670 /* May (probably does) set hwirq, chip, etc. */ 1671 rv = irq_domain_alloc_irqs_hierarchy(domain, virq, 1, arg); 1672 if (rv) { 1673 /* Restore the original irq_data. */ 1674 *irq_data = *parent_irq_data; 1675 kfree(parent_irq_data); 1676 goto error; 1677 } 1678 1679 irq_domain_fix_revmap(parent_irq_data); 1680 irq_domain_set_mapping(domain, irq_data->hwirq, irq_data); 1681 error: 1682 mutex_unlock(&domain->root->mutex); 1683 1684 return rv; 1685 } 1686 EXPORT_SYMBOL_GPL(irq_domain_push_irq); 1687 1688 /** 1689 * irq_domain_pop_irq() - Remove a domain from the top of a hierarchy. 1690 * @domain: Domain to remove. 1691 * @virq: Irq to remove the domain from. 1692 * 1693 * Undo the effects of a call to irq_domain_push_irq(). Must be 1694 * called either before request_irq() or after free_irq(). 1695 */ 1696 int irq_domain_pop_irq(struct irq_domain *domain, int virq) 1697 { 1698 struct irq_data *irq_data = irq_get_irq_data(virq); 1699 struct irq_data *parent_irq_data; 1700 struct irq_data *tmp_irq_data; 1701 struct irq_desc *desc; 1702 1703 /* 1704 * Check that no action is set, which indicates the virq is in 1705 * a state where this function doesn't have to deal with races 1706 * between interrupt handling and maintaining the hierarchy. 1707 * This will catch gross misuse. Attempting to make the check 1708 * race free would require holding locks across calls to 1709 * struct irq_domain_ops->free(), which could lead to 1710 * deadlock, so we just do a simple check before starting. 1711 */ 1712 desc = irq_to_desc(virq); 1713 if (!desc) 1714 return -EINVAL; 1715 if (WARN_ON(desc->action)) 1716 return -EBUSY; 1717 1718 if (domain == NULL) 1719 return -EINVAL; 1720 1721 if (!irq_data) 1722 return -EINVAL; 1723 1724 tmp_irq_data = irq_domain_get_irq_data(domain, virq); 1725 1726 /* We can only "pop" if this domain is at the top of the list */ 1727 if (WARN_ON(irq_data != tmp_irq_data)) 1728 return -EINVAL; 1729 1730 if (WARN_ON(irq_data->domain != domain)) 1731 return -EINVAL; 1732 1733 parent_irq_data = irq_data->parent_data; 1734 if (WARN_ON(!parent_irq_data)) 1735 return -EINVAL; 1736 1737 mutex_lock(&domain->root->mutex); 1738 1739 irq_data->parent_data = NULL; 1740 1741 irq_domain_clear_mapping(domain, irq_data->hwirq); 1742 irq_domain_free_irqs_hierarchy(domain, virq, 1); 1743 1744 /* Restore the original irq_data. */ 1745 *irq_data = *parent_irq_data; 1746 1747 irq_domain_fix_revmap(irq_data); 1748 1749 mutex_unlock(&domain->root->mutex); 1750 1751 kfree(parent_irq_data); 1752 1753 return 0; 1754 } 1755 EXPORT_SYMBOL_GPL(irq_domain_pop_irq); 1756 1757 /** 1758 * irq_domain_free_irqs - Free IRQ number and associated data structures 1759 * @virq: base IRQ number 1760 * @nr_irqs: number of IRQs to free 1761 */ 1762 void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs) 1763 { 1764 struct irq_data *data = irq_get_irq_data(virq); 1765 struct irq_domain *domain; 1766 int i; 1767 1768 if (WARN(!data || !data->domain || !data->domain->ops->free, 1769 "NULL pointer, cannot free irq\n")) 1770 return; 1771 1772 domain = data->domain; 1773 1774 mutex_lock(&domain->root->mutex); 1775 for (i = 0; i < nr_irqs; i++) 1776 irq_domain_remove_irq(virq + i); 1777 irq_domain_free_irqs_hierarchy(domain, virq, nr_irqs); 1778 mutex_unlock(&domain->root->mutex); 1779 1780 irq_domain_free_irq_data(virq, nr_irqs); 1781 irq_free_descs(virq, nr_irqs); 1782 } 1783 1784 /** 1785 * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain 1786 * @domain: Domain below which interrupts must be allocated 1787 * @irq_base: Base IRQ number 1788 * @nr_irqs: Number of IRQs to allocate 1789 * @arg: Allocation data (arch/domain specific) 1790 */ 1791 int irq_domain_alloc_irqs_parent(struct irq_domain *domain, 1792 unsigned int irq_base, unsigned int nr_irqs, 1793 void *arg) 1794 { 1795 if (!domain->parent) 1796 return -ENOSYS; 1797 1798 return irq_domain_alloc_irqs_hierarchy(domain->parent, irq_base, 1799 nr_irqs, arg); 1800 } 1801 EXPORT_SYMBOL_GPL(irq_domain_alloc_irqs_parent); 1802 1803 /** 1804 * irq_domain_free_irqs_parent - Free interrupts from parent domain 1805 * @domain: Domain below which interrupts must be freed 1806 * @irq_base: Base IRQ number 1807 * @nr_irqs: Number of IRQs to free 1808 */ 1809 void irq_domain_free_irqs_parent(struct irq_domain *domain, 1810 unsigned int irq_base, unsigned int nr_irqs) 1811 { 1812 if (!domain->parent) 1813 return; 1814 1815 irq_domain_free_irqs_hierarchy(domain->parent, irq_base, nr_irqs); 1816 } 1817 EXPORT_SYMBOL_GPL(irq_domain_free_irqs_parent); 1818 1819 static void __irq_domain_deactivate_irq(struct irq_data *irq_data) 1820 { 1821 if (irq_data && irq_data->domain) { 1822 struct irq_domain *domain = irq_data->domain; 1823 1824 if (domain->ops->deactivate) 1825 domain->ops->deactivate(domain, irq_data); 1826 if (irq_data->parent_data) 1827 __irq_domain_deactivate_irq(irq_data->parent_data); 1828 } 1829 } 1830 1831 static int __irq_domain_activate_irq(struct irq_data *irqd, bool reserve) 1832 { 1833 int ret = 0; 1834 1835 if (irqd && irqd->domain) { 1836 struct irq_domain *domain = irqd->domain; 1837 1838 if (irqd->parent_data) 1839 ret = __irq_domain_activate_irq(irqd->parent_data, 1840 reserve); 1841 if (!ret && domain->ops->activate) { 1842 ret = domain->ops->activate(domain, irqd, reserve); 1843 /* Rollback in case of error */ 1844 if (ret && irqd->parent_data) 1845 __irq_domain_deactivate_irq(irqd->parent_data); 1846 } 1847 } 1848 return ret; 1849 } 1850 1851 /** 1852 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate 1853 * interrupt 1854 * @irq_data: Outermost irq_data associated with interrupt 1855 * @reserve: If set only reserve an interrupt vector instead of assigning one 1856 * 1857 * This is the second step to call domain_ops->activate to program interrupt 1858 * controllers, so the interrupt could actually get delivered. 1859 */ 1860 int irq_domain_activate_irq(struct irq_data *irq_data, bool reserve) 1861 { 1862 int ret = 0; 1863 1864 if (!irqd_is_activated(irq_data)) 1865 ret = __irq_domain_activate_irq(irq_data, reserve); 1866 if (!ret) 1867 irqd_set_activated(irq_data); 1868 return ret; 1869 } 1870 1871 /** 1872 * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to 1873 * deactivate interrupt 1874 * @irq_data: outermost irq_data associated with interrupt 1875 * 1876 * It calls domain_ops->deactivate to program interrupt controllers to disable 1877 * interrupt delivery. 1878 */ 1879 void irq_domain_deactivate_irq(struct irq_data *irq_data) 1880 { 1881 if (irqd_is_activated(irq_data)) { 1882 __irq_domain_deactivate_irq(irq_data); 1883 irqd_clr_activated(irq_data); 1884 } 1885 } 1886 1887 static void irq_domain_check_hierarchy(struct irq_domain *domain) 1888 { 1889 /* Hierarchy irq_domains must implement callback alloc() */ 1890 if (domain->ops->alloc) 1891 domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY; 1892 } 1893 1894 /** 1895 * irq_domain_hierarchical_is_msi_remap - Check if the domain or any 1896 * parent has MSI remapping support 1897 * @domain: domain pointer 1898 */ 1899 bool irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain) 1900 { 1901 for (; domain; domain = domain->parent) { 1902 if (irq_domain_is_msi_remap(domain)) 1903 return true; 1904 } 1905 return false; 1906 } 1907 #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */ 1908 /** 1909 * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain 1910 * @domain: domain to match 1911 * @virq: IRQ number to get irq_data 1912 */ 1913 struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain, 1914 unsigned int virq) 1915 { 1916 struct irq_data *irq_data = irq_get_irq_data(virq); 1917 1918 return (irq_data && irq_data->domain == domain) ? irq_data : NULL; 1919 } 1920 EXPORT_SYMBOL_GPL(irq_domain_get_irq_data); 1921 1922 /** 1923 * irq_domain_set_info - Set the complete data for a @virq in @domain 1924 * @domain: Interrupt domain to match 1925 * @virq: IRQ number 1926 * @hwirq: The hardware interrupt number 1927 * @chip: The associated interrupt chip 1928 * @chip_data: The associated interrupt chip data 1929 * @handler: The interrupt flow handler 1930 * @handler_data: The interrupt flow handler data 1931 * @handler_name: The interrupt handler name 1932 */ 1933 void irq_domain_set_info(struct irq_domain *domain, unsigned int virq, 1934 irq_hw_number_t hwirq, const struct irq_chip *chip, 1935 void *chip_data, irq_flow_handler_t handler, 1936 void *handler_data, const char *handler_name) 1937 { 1938 irq_set_chip_and_handler_name(virq, chip, handler, handler_name); 1939 irq_set_chip_data(virq, chip_data); 1940 irq_set_handler_data(virq, handler_data); 1941 } 1942 1943 static int irq_domain_alloc_irqs_locked(struct irq_domain *domain, int irq_base, 1944 unsigned int nr_irqs, int node, void *arg, 1945 bool realloc, const struct irq_affinity_desc *affinity) 1946 { 1947 return -EINVAL; 1948 } 1949 1950 static void irq_domain_check_hierarchy(struct irq_domain *domain) 1951 { 1952 } 1953 #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ 1954 1955 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS 1956 static struct dentry *domain_dir; 1957 1958 static void 1959 irq_domain_debug_show_one(struct seq_file *m, struct irq_domain *d, int ind) 1960 { 1961 seq_printf(m, "%*sname: %s\n", ind, "", d->name); 1962 seq_printf(m, "%*ssize: %u\n", ind + 1, "", d->revmap_size); 1963 seq_printf(m, "%*smapped: %u\n", ind + 1, "", d->mapcount); 1964 seq_printf(m, "%*sflags: 0x%08x\n", ind +1 , "", d->flags); 1965 if (d->ops && d->ops->debug_show) 1966 d->ops->debug_show(m, d, NULL, ind + 1); 1967 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 1968 if (!d->parent) 1969 return; 1970 seq_printf(m, "%*sparent: %s\n", ind + 1, "", d->parent->name); 1971 irq_domain_debug_show_one(m, d->parent, ind + 4); 1972 #endif 1973 } 1974 1975 static int irq_domain_debug_show(struct seq_file *m, void *p) 1976 { 1977 struct irq_domain *d = m->private; 1978 1979 /* Default domain? Might be NULL */ 1980 if (!d) { 1981 if (!irq_default_domain) 1982 return 0; 1983 d = irq_default_domain; 1984 } 1985 irq_domain_debug_show_one(m, d, 0); 1986 return 0; 1987 } 1988 DEFINE_SHOW_ATTRIBUTE(irq_domain_debug); 1989 1990 static void debugfs_add_domain_dir(struct irq_domain *d) 1991 { 1992 if (!d->name || !domain_dir) 1993 return; 1994 debugfs_create_file(d->name, 0444, domain_dir, d, 1995 &irq_domain_debug_fops); 1996 } 1997 1998 static void debugfs_remove_domain_dir(struct irq_domain *d) 1999 { 2000 debugfs_lookup_and_remove(d->name, domain_dir); 2001 } 2002 2003 void __init irq_domain_debugfs_init(struct dentry *root) 2004 { 2005 struct irq_domain *d; 2006 2007 domain_dir = debugfs_create_dir("domains", root); 2008 2009 debugfs_create_file("default", 0444, domain_dir, NULL, 2010 &irq_domain_debug_fops); 2011 mutex_lock(&irq_domain_mutex); 2012 list_for_each_entry(d, &irq_domain_list, link) 2013 debugfs_add_domain_dir(d); 2014 mutex_unlock(&irq_domain_mutex); 2015 } 2016 #endif 2017