1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar 4 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King 5 * 6 * This file contains the core interrupt handling code, for irq-chip based 7 * architectures. Detailed information is available in 8 * Documentation/core-api/genericirq.rst 9 */ 10 11 #include <linux/irq.h> 12 #include <linux/msi.h> 13 #include <linux/module.h> 14 #include <linux/interrupt.h> 15 #include <linux/kernel_stat.h> 16 #include <linux/irqdomain.h> 17 18 #include <trace/events/irq.h> 19 20 #include "internals.h" 21 22 static irqreturn_t bad_chained_irq(int irq, void *dev_id) 23 { 24 WARN_ONCE(1, "Chained irq %d should not call an action\n", irq); 25 return IRQ_NONE; 26 } 27 28 /* 29 * Chained handlers should never call action on their IRQ. This default 30 * action will emit warning if such thing happens. 31 */ 32 struct irqaction chained_action = { 33 .handler = bad_chained_irq, 34 }; 35 36 /** 37 * irq_set_chip - set the irq chip for an irq 38 * @irq: irq number 39 * @chip: pointer to irq chip description structure 40 */ 41 int irq_set_chip(unsigned int irq, const struct irq_chip *chip) 42 { 43 int ret = -EINVAL; 44 45 scoped_irqdesc_get_and_lock(irq, 0) { 46 scoped_irqdesc->irq_data.chip = (struct irq_chip *)(chip ?: &no_irq_chip); 47 ret = 0; 48 } 49 /* For !CONFIG_SPARSE_IRQ make the irq show up in allocated_irqs. */ 50 if (!ret) 51 irq_mark_irq(irq); 52 return ret; 53 } 54 EXPORT_SYMBOL(irq_set_chip); 55 56 /** 57 * irq_set_irq_type - set the irq trigger type for an irq 58 * @irq: irq number 59 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h 60 */ 61 int irq_set_irq_type(unsigned int irq, unsigned int type) 62 { 63 scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) 64 return __irq_set_trigger(scoped_irqdesc, type); 65 return -EINVAL; 66 } 67 EXPORT_SYMBOL(irq_set_irq_type); 68 69 /** 70 * irq_set_handler_data - set irq handler data for an irq 71 * @irq: Interrupt number 72 * @data: Pointer to interrupt specific data 73 * 74 * Set the hardware irq controller data for an irq 75 */ 76 int irq_set_handler_data(unsigned int irq, void *data) 77 { 78 scoped_irqdesc_get_and_lock(irq, 0) { 79 scoped_irqdesc->irq_common_data.handler_data = data; 80 return 0; 81 } 82 return -EINVAL; 83 } 84 EXPORT_SYMBOL(irq_set_handler_data); 85 86 /** 87 * irq_set_msi_desc_off - set MSI descriptor data for an irq at offset 88 * @irq_base: Interrupt number base 89 * @irq_offset: Interrupt number offset 90 * @entry: Pointer to MSI descriptor data 91 * 92 * Set the MSI descriptor entry for an irq at offset 93 */ 94 int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset, struct msi_desc *entry) 95 { 96 scoped_irqdesc_get_and_lock(irq_base + irq_offset, IRQ_GET_DESC_CHECK_GLOBAL) { 97 scoped_irqdesc->irq_common_data.msi_desc = entry; 98 if (entry && !irq_offset) 99 entry->irq = irq_base; 100 return 0; 101 } 102 return -EINVAL; 103 } 104 105 /** 106 * irq_set_msi_desc - set MSI descriptor data for an irq 107 * @irq: Interrupt number 108 * @entry: Pointer to MSI descriptor data 109 * 110 * Set the MSI descriptor entry for an irq 111 */ 112 int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry) 113 { 114 return irq_set_msi_desc_off(irq, 0, entry); 115 } 116 117 /** 118 * irq_set_chip_data - set irq chip data for an irq 119 * @irq: Interrupt number 120 * @data: Pointer to chip specific data 121 * 122 * Set the hardware irq chip data for an irq 123 */ 124 int irq_set_chip_data(unsigned int irq, void *data) 125 { 126 scoped_irqdesc_get_and_lock(irq, 0) { 127 scoped_irqdesc->irq_data.chip_data = data; 128 return 0; 129 } 130 return -EINVAL; 131 } 132 EXPORT_SYMBOL(irq_set_chip_data); 133 134 struct irq_data *irq_get_irq_data(unsigned int irq) 135 { 136 struct irq_desc *desc = irq_to_desc(irq); 137 138 return desc ? &desc->irq_data : NULL; 139 } 140 EXPORT_SYMBOL_GPL(irq_get_irq_data); 141 142 static void irq_state_clr_disabled(struct irq_desc *desc) 143 { 144 irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED); 145 } 146 147 static void irq_state_clr_masked(struct irq_desc *desc) 148 { 149 irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED); 150 } 151 152 static void irq_state_clr_started(struct irq_desc *desc) 153 { 154 irqd_clear(&desc->irq_data, IRQD_IRQ_STARTED); 155 } 156 157 static void irq_state_set_started(struct irq_desc *desc) 158 { 159 irqd_set(&desc->irq_data, IRQD_IRQ_STARTED); 160 } 161 162 enum { 163 IRQ_STARTUP_NORMAL, 164 IRQ_STARTUP_MANAGED, 165 IRQ_STARTUP_ABORT, 166 }; 167 168 #ifdef CONFIG_SMP 169 static int 170 __irq_startup_managed(struct irq_desc *desc, const struct cpumask *aff, 171 bool force) 172 { 173 struct irq_data *d = irq_desc_get_irq_data(desc); 174 175 if (!irqd_affinity_is_managed(d)) 176 return IRQ_STARTUP_NORMAL; 177 178 irqd_clr_managed_shutdown(d); 179 180 if (!cpumask_intersects(aff, cpu_online_mask)) { 181 /* 182 * Catch code which fiddles with enable_irq() on a managed 183 * and potentially shutdown IRQ. Chained interrupt 184 * installment or irq auto probing should not happen on 185 * managed irqs either. 186 */ 187 if (WARN_ON_ONCE(force)) 188 return IRQ_STARTUP_ABORT; 189 /* 190 * The interrupt was requested, but there is no online CPU 191 * in it's affinity mask. Put it into managed shutdown 192 * state and let the cpu hotplug mechanism start it up once 193 * a CPU in the mask becomes available. 194 */ 195 return IRQ_STARTUP_ABORT; 196 } 197 /* 198 * Managed interrupts have reserved resources, so this should not 199 * happen. 200 */ 201 if (WARN_ON(irq_domain_activate_irq(d, false))) 202 return IRQ_STARTUP_ABORT; 203 return IRQ_STARTUP_MANAGED; 204 } 205 206 void irq_startup_managed(struct irq_desc *desc) 207 { 208 struct irq_data *d = irq_desc_get_irq_data(desc); 209 210 /* 211 * Clear managed-shutdown flag, so we don't repeat managed-startup for 212 * multiple hotplugs, and cause imbalanced disable depth. 213 */ 214 irqd_clr_managed_shutdown(d); 215 216 /* 217 * Only start it up when the disable depth is 1, so that a disable, 218 * hotunplug, hotplug sequence does not end up enabling it during 219 * hotplug unconditionally. 220 */ 221 desc->depth--; 222 if (!desc->depth) 223 irq_startup(desc, IRQ_RESEND, IRQ_START_COND); 224 } 225 226 #else 227 static __always_inline int 228 __irq_startup_managed(struct irq_desc *desc, const struct cpumask *aff, 229 bool force) 230 { 231 return IRQ_STARTUP_NORMAL; 232 } 233 #endif 234 235 static void irq_enable(struct irq_desc *desc) 236 { 237 if (!irqd_irq_disabled(&desc->irq_data)) { 238 unmask_irq(desc); 239 } else { 240 irq_state_clr_disabled(desc); 241 if (desc->irq_data.chip->irq_enable) { 242 desc->irq_data.chip->irq_enable(&desc->irq_data); 243 irq_state_clr_masked(desc); 244 } else { 245 unmask_irq(desc); 246 } 247 } 248 } 249 250 static int __irq_startup(struct irq_desc *desc) 251 { 252 struct irq_data *d = irq_desc_get_irq_data(desc); 253 int ret = 0; 254 255 /* Warn if this interrupt is not activated but try nevertheless */ 256 WARN_ON_ONCE(!irqd_is_activated(d)); 257 258 if (d->chip->irq_startup) { 259 ret = d->chip->irq_startup(d); 260 irq_state_clr_disabled(desc); 261 irq_state_clr_masked(desc); 262 } else { 263 irq_enable(desc); 264 } 265 irq_state_set_started(desc); 266 return ret; 267 } 268 269 int irq_startup(struct irq_desc *desc, bool resend, bool force) 270 { 271 struct irq_data *d = irq_desc_get_irq_data(desc); 272 const struct cpumask *aff = irq_data_get_affinity_mask(d); 273 int ret = 0; 274 275 desc->depth = 0; 276 277 if (irqd_is_started(d)) { 278 irq_enable(desc); 279 } else { 280 switch (__irq_startup_managed(desc, aff, force)) { 281 case IRQ_STARTUP_NORMAL: 282 if (d->chip->flags & IRQCHIP_AFFINITY_PRE_STARTUP) 283 irq_setup_affinity(desc); 284 ret = __irq_startup(desc); 285 if (!(d->chip->flags & IRQCHIP_AFFINITY_PRE_STARTUP)) 286 irq_setup_affinity(desc); 287 break; 288 case IRQ_STARTUP_MANAGED: 289 irq_do_set_affinity(d, aff, false); 290 ret = __irq_startup(desc); 291 break; 292 case IRQ_STARTUP_ABORT: 293 desc->depth = 1; 294 irqd_set_managed_shutdown(d); 295 return 0; 296 } 297 } 298 if (resend) 299 check_irq_resend(desc, false); 300 301 return ret; 302 } 303 304 int irq_activate(struct irq_desc *desc) 305 { 306 struct irq_data *d = irq_desc_get_irq_data(desc); 307 308 if (!irqd_affinity_is_managed(d)) 309 return irq_domain_activate_irq(d, false); 310 return 0; 311 } 312 313 int irq_activate_and_startup(struct irq_desc *desc, bool resend) 314 { 315 if (WARN_ON(irq_activate(desc))) 316 return 0; 317 return irq_startup(desc, resend, IRQ_START_FORCE); 318 } 319 320 static void __irq_disable(struct irq_desc *desc, bool mask); 321 322 void irq_shutdown(struct irq_desc *desc) 323 { 324 if (irqd_is_started(&desc->irq_data)) { 325 clear_irq_resend(desc); 326 /* 327 * Increment disable depth, so that a managed shutdown on 328 * CPU hotunplug preserves the actual disabled state when the 329 * CPU comes back online. See irq_startup_managed(). 330 */ 331 desc->depth++; 332 333 if (desc->irq_data.chip->irq_shutdown) { 334 desc->irq_data.chip->irq_shutdown(&desc->irq_data); 335 irq_state_set_disabled(desc); 336 irq_state_set_masked(desc); 337 } else { 338 __irq_disable(desc, true); 339 } 340 irq_state_clr_started(desc); 341 } 342 } 343 344 345 void irq_shutdown_and_deactivate(struct irq_desc *desc) 346 { 347 irq_shutdown(desc); 348 /* 349 * This must be called even if the interrupt was never started up, 350 * because the activation can happen before the interrupt is 351 * available for request/startup. It has it's own state tracking so 352 * it's safe to call it unconditionally. 353 */ 354 irq_domain_deactivate_irq(&desc->irq_data); 355 } 356 357 static void __irq_disable(struct irq_desc *desc, bool mask) 358 { 359 if (irqd_irq_disabled(&desc->irq_data)) { 360 if (mask) 361 mask_irq(desc); 362 } else { 363 irq_state_set_disabled(desc); 364 if (desc->irq_data.chip->irq_disable) { 365 desc->irq_data.chip->irq_disable(&desc->irq_data); 366 irq_state_set_masked(desc); 367 } else if (mask) { 368 mask_irq(desc); 369 } 370 } 371 } 372 373 /** 374 * irq_disable - Mark interrupt disabled 375 * @desc: irq descriptor which should be disabled 376 * 377 * If the chip does not implement the irq_disable callback, we 378 * use a lazy disable approach. That means we mark the interrupt 379 * disabled, but leave the hardware unmasked. That's an 380 * optimization because we avoid the hardware access for the 381 * common case where no interrupt happens after we marked it 382 * disabled. If an interrupt happens, then the interrupt flow 383 * handler masks the line at the hardware level and marks it 384 * pending. 385 * 386 * If the interrupt chip does not implement the irq_disable callback, 387 * a driver can disable the lazy approach for a particular irq line by 388 * calling 'irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY)'. This can 389 * be used for devices which cannot disable the interrupt at the 390 * device level under certain circumstances and have to use 391 * disable_irq[_nosync] instead. 392 */ 393 void irq_disable(struct irq_desc *desc) 394 { 395 __irq_disable(desc, irq_settings_disable_unlazy(desc)); 396 } 397 398 void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu) 399 { 400 if (desc->irq_data.chip->irq_enable) 401 desc->irq_data.chip->irq_enable(&desc->irq_data); 402 else 403 desc->irq_data.chip->irq_unmask(&desc->irq_data); 404 cpumask_set_cpu(cpu, desc->percpu_enabled); 405 } 406 407 void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu) 408 { 409 if (desc->irq_data.chip->irq_disable) 410 desc->irq_data.chip->irq_disable(&desc->irq_data); 411 else 412 desc->irq_data.chip->irq_mask(&desc->irq_data); 413 cpumask_clear_cpu(cpu, desc->percpu_enabled); 414 } 415 416 static inline void mask_ack_irq(struct irq_desc *desc) 417 { 418 if (desc->irq_data.chip->irq_mask_ack) { 419 desc->irq_data.chip->irq_mask_ack(&desc->irq_data); 420 irq_state_set_masked(desc); 421 } else { 422 mask_irq(desc); 423 if (desc->irq_data.chip->irq_ack) 424 desc->irq_data.chip->irq_ack(&desc->irq_data); 425 } 426 } 427 428 void mask_irq(struct irq_desc *desc) 429 { 430 if (irqd_irq_masked(&desc->irq_data)) 431 return; 432 433 if (desc->irq_data.chip->irq_mask) { 434 desc->irq_data.chip->irq_mask(&desc->irq_data); 435 irq_state_set_masked(desc); 436 } 437 } 438 439 void unmask_irq(struct irq_desc *desc) 440 { 441 if (!irqd_irq_masked(&desc->irq_data)) 442 return; 443 444 if (desc->irq_data.chip->irq_unmask) { 445 desc->irq_data.chip->irq_unmask(&desc->irq_data); 446 irq_state_clr_masked(desc); 447 } 448 } 449 450 void unmask_threaded_irq(struct irq_desc *desc) 451 { 452 struct irq_chip *chip = desc->irq_data.chip; 453 454 if (chip->flags & IRQCHIP_EOI_THREADED) 455 chip->irq_eoi(&desc->irq_data); 456 457 unmask_irq(desc); 458 } 459 460 static bool irq_check_poll(struct irq_desc *desc) 461 { 462 if (!(desc->istate & IRQS_POLL_INPROGRESS)) 463 return false; 464 return irq_wait_for_poll(desc); 465 } 466 467 static bool irq_can_handle_pm(struct irq_desc *desc) 468 { 469 unsigned int mask = IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED; 470 471 /* 472 * If the interrupt is not in progress and is not an armed 473 * wakeup interrupt, proceed. 474 */ 475 if (!irqd_has_set(&desc->irq_data, mask)) 476 return true; 477 478 /* 479 * If the interrupt is an armed wakeup source, mark it pending 480 * and suspended, disable it and notify the pm core about the 481 * event. 482 */ 483 if (irq_pm_check_wakeup(desc)) 484 return false; 485 486 /* 487 * Handle a potential concurrent poll on a different core. 488 */ 489 return irq_check_poll(desc); 490 } 491 492 static inline bool irq_can_handle_actions(struct irq_desc *desc) 493 { 494 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING); 495 496 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) { 497 desc->istate |= IRQS_PENDING; 498 return false; 499 } 500 return true; 501 } 502 503 static inline bool irq_can_handle(struct irq_desc *desc) 504 { 505 if (!irq_can_handle_pm(desc)) 506 return false; 507 508 return irq_can_handle_actions(desc); 509 } 510 511 /** 512 * handle_nested_irq - Handle a nested irq from a irq thread 513 * @irq: the interrupt number 514 * 515 * Handle interrupts which are nested into a threaded interrupt 516 * handler. The handler function is called inside the calling threads 517 * context. 518 */ 519 void handle_nested_irq(unsigned int irq) 520 { 521 struct irq_desc *desc = irq_to_desc(irq); 522 struct irqaction *action; 523 irqreturn_t action_ret; 524 525 might_sleep(); 526 527 scoped_guard(raw_spinlock_irq, &desc->lock) { 528 if (!irq_can_handle_actions(desc)) 529 return; 530 531 action = desc->action; 532 kstat_incr_irqs_this_cpu(desc); 533 atomic_inc(&desc->threads_active); 534 } 535 536 action_ret = IRQ_NONE; 537 for_each_action_of_desc(desc, action) 538 action_ret |= action->thread_fn(action->irq, action->dev_id); 539 540 if (!irq_settings_no_debug(desc)) 541 note_interrupt(desc, action_ret); 542 543 wake_threads_waitq(desc); 544 } 545 EXPORT_SYMBOL_GPL(handle_nested_irq); 546 547 /** 548 * handle_simple_irq - Simple and software-decoded IRQs. 549 * @desc: the interrupt description structure for this irq 550 * 551 * Simple interrupts are either sent from a demultiplexing interrupt 552 * handler or come from hardware, where no interrupt hardware control is 553 * necessary. 554 * 555 * Note: The caller is expected to handle the ack, clear, mask and unmask 556 * issues if necessary. 557 */ 558 void handle_simple_irq(struct irq_desc *desc) 559 { 560 guard(raw_spinlock)(&desc->lock); 561 562 if (!irq_can_handle(desc)) 563 return; 564 565 kstat_incr_irqs_this_cpu(desc); 566 handle_irq_event(desc); 567 } 568 EXPORT_SYMBOL_GPL(handle_simple_irq); 569 570 /** 571 * handle_untracked_irq - Simple and software-decoded IRQs. 572 * @desc: the interrupt description structure for this irq 573 * 574 * Untracked interrupts are sent from a demultiplexing interrupt handler 575 * when the demultiplexer does not know which device it its multiplexed irq 576 * domain generated the interrupt. IRQ's handled through here are not 577 * subjected to stats tracking, randomness, or spurious interrupt 578 * detection. 579 * 580 * Note: Like handle_simple_irq, the caller is expected to handle the ack, 581 * clear, mask and unmask issues if necessary. 582 */ 583 void handle_untracked_irq(struct irq_desc *desc) 584 { 585 scoped_guard(raw_spinlock, &desc->lock) { 586 if (!irq_can_handle(desc)) 587 return; 588 589 desc->istate &= ~IRQS_PENDING; 590 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS); 591 } 592 593 __handle_irq_event_percpu(desc); 594 595 scoped_guard(raw_spinlock, &desc->lock) 596 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); 597 } 598 EXPORT_SYMBOL_GPL(handle_untracked_irq); 599 600 /* 601 * Called unconditionally from handle_level_irq() and only for oneshot 602 * interrupts from handle_fasteoi_irq() 603 */ 604 static void cond_unmask_irq(struct irq_desc *desc) 605 { 606 /* 607 * We need to unmask in the following cases: 608 * - Standard level irq (IRQF_ONESHOT is not set) 609 * - Oneshot irq which did not wake the thread (caused by a 610 * spurious interrupt or a primary handler handling it 611 * completely). 612 */ 613 if (!irqd_irq_disabled(&desc->irq_data) && 614 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) 615 unmask_irq(desc); 616 } 617 618 /** 619 * handle_level_irq - Level type irq handler 620 * @desc: the interrupt description structure for this irq 621 * 622 * Level type interrupts are active as long as the hardware line has the 623 * active level. This may require to mask the interrupt and unmask it after 624 * the associated handler has acknowledged the device, so the interrupt 625 * line is back to inactive. 626 */ 627 void handle_level_irq(struct irq_desc *desc) 628 { 629 guard(raw_spinlock)(&desc->lock); 630 mask_ack_irq(desc); 631 632 if (!irq_can_handle(desc)) 633 return; 634 635 kstat_incr_irqs_this_cpu(desc); 636 handle_irq_event(desc); 637 638 cond_unmask_irq(desc); 639 } 640 EXPORT_SYMBOL_GPL(handle_level_irq); 641 642 static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip) 643 { 644 if (!(desc->istate & IRQS_ONESHOT)) { 645 chip->irq_eoi(&desc->irq_data); 646 return; 647 } 648 /* 649 * We need to unmask in the following cases: 650 * - Oneshot irq which did not wake the thread (caused by a 651 * spurious interrupt or a primary handler handling it 652 * completely). 653 */ 654 if (!irqd_irq_disabled(&desc->irq_data) && 655 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) { 656 chip->irq_eoi(&desc->irq_data); 657 unmask_irq(desc); 658 } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) { 659 chip->irq_eoi(&desc->irq_data); 660 } 661 } 662 663 static inline void cond_eoi_irq(struct irq_chip *chip, struct irq_data *data) 664 { 665 if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED)) 666 chip->irq_eoi(data); 667 } 668 669 /** 670 * handle_fasteoi_irq - irq handler for transparent controllers 671 * @desc: the interrupt description structure for this irq 672 * 673 * Only a single callback will be issued to the chip: an ->eoi() call when 674 * the interrupt has been serviced. This enables support for modern forms 675 * of interrupt handlers, which handle the flow details in hardware, 676 * transparently. 677 */ 678 void handle_fasteoi_irq(struct irq_desc *desc) 679 { 680 struct irq_chip *chip = desc->irq_data.chip; 681 682 guard(raw_spinlock)(&desc->lock); 683 684 /* 685 * When an affinity change races with IRQ handling, the next interrupt 686 * can arrive on the new CPU before the original CPU has completed 687 * handling the previous one - it may need to be resent. 688 */ 689 if (!irq_can_handle_pm(desc)) { 690 if (irqd_needs_resend_when_in_progress(&desc->irq_data)) 691 desc->istate |= IRQS_PENDING; 692 cond_eoi_irq(chip, &desc->irq_data); 693 return; 694 } 695 696 if (!irq_can_handle_actions(desc)) { 697 mask_irq(desc); 698 cond_eoi_irq(chip, &desc->irq_data); 699 return; 700 } 701 702 kstat_incr_irqs_this_cpu(desc); 703 if (desc->istate & IRQS_ONESHOT) 704 mask_irq(desc); 705 706 handle_irq_event(desc); 707 708 cond_unmask_eoi_irq(desc, chip); 709 710 /* 711 * When the race described above happens this will resend the interrupt. 712 */ 713 if (unlikely(desc->istate & IRQS_PENDING)) 714 check_irq_resend(desc, false); 715 } 716 EXPORT_SYMBOL_GPL(handle_fasteoi_irq); 717 718 /** 719 * handle_fasteoi_nmi - irq handler for NMI interrupt lines 720 * @desc: the interrupt description structure for this irq 721 * 722 * A simple NMI-safe handler, considering the restrictions 723 * from request_nmi. 724 * 725 * Only a single callback will be issued to the chip: an ->eoi() 726 * call when the interrupt has been serviced. This enables support 727 * for modern forms of interrupt handlers, which handle the flow 728 * details in hardware, transparently. 729 */ 730 void handle_fasteoi_nmi(struct irq_desc *desc) 731 { 732 struct irq_chip *chip = irq_desc_get_chip(desc); 733 struct irqaction *action = desc->action; 734 unsigned int irq = irq_desc_get_irq(desc); 735 irqreturn_t res; 736 737 __kstat_incr_irqs_this_cpu(desc); 738 739 trace_irq_handler_entry(irq, action); 740 /* 741 * NMIs cannot be shared, there is only one action. 742 */ 743 res = action->handler(irq, action->dev_id); 744 trace_irq_handler_exit(irq, action, res); 745 746 if (chip->irq_eoi) 747 chip->irq_eoi(&desc->irq_data); 748 } 749 EXPORT_SYMBOL_GPL(handle_fasteoi_nmi); 750 751 /** 752 * handle_edge_irq - edge type IRQ handler 753 * @desc: the interrupt description structure for this irq 754 * 755 * Interrupt occurs on the falling and/or rising edge of a hardware 756 * signal. The occurrence is latched into the irq controller hardware and 757 * must be acked in order to be reenabled. After the ack another interrupt 758 * can happen on the same source even before the first one is handled by 759 * the associated event handler. If this happens it might be necessary to 760 * disable (mask) the interrupt depending on the controller hardware. This 761 * requires to reenable the interrupt inside of the loop which handles the 762 * interrupts which have arrived while the handler was running. If all 763 * pending interrupts are handled, the loop is left. 764 */ 765 void handle_edge_irq(struct irq_desc *desc) 766 { 767 guard(raw_spinlock)(&desc->lock); 768 769 if (!irq_can_handle(desc)) { 770 desc->istate |= IRQS_PENDING; 771 mask_ack_irq(desc); 772 return; 773 } 774 775 kstat_incr_irqs_this_cpu(desc); 776 777 /* Start handling the irq */ 778 desc->irq_data.chip->irq_ack(&desc->irq_data); 779 780 do { 781 if (unlikely(!desc->action)) { 782 mask_irq(desc); 783 return; 784 } 785 786 /* 787 * When another irq arrived while we were handling 788 * one, we could have masked the irq. 789 * Reenable it, if it was not disabled in meantime. 790 */ 791 if (unlikely(desc->istate & IRQS_PENDING)) { 792 if (!irqd_irq_disabled(&desc->irq_data) && 793 irqd_irq_masked(&desc->irq_data)) 794 unmask_irq(desc); 795 } 796 797 handle_irq_event(desc); 798 799 } while ((desc->istate & IRQS_PENDING) && !irqd_irq_disabled(&desc->irq_data)); 800 } 801 EXPORT_SYMBOL(handle_edge_irq); 802 803 /** 804 * handle_percpu_irq - Per CPU local irq handler 805 * @desc: the interrupt description structure for this irq 806 * 807 * Per CPU interrupts on SMP machines without locking requirements 808 */ 809 void handle_percpu_irq(struct irq_desc *desc) 810 { 811 struct irq_chip *chip = irq_desc_get_chip(desc); 812 813 /* 814 * PER CPU interrupts are not serialized. Do not touch 815 * desc->tot_count. 816 */ 817 __kstat_incr_irqs_this_cpu(desc); 818 819 if (chip->irq_ack) 820 chip->irq_ack(&desc->irq_data); 821 822 handle_irq_event_percpu(desc); 823 824 if (chip->irq_eoi) 825 chip->irq_eoi(&desc->irq_data); 826 } 827 828 /** 829 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids 830 * @desc: the interrupt description structure for this irq 831 * 832 * Per CPU interrupts on SMP machines without locking requirements. Same as 833 * handle_percpu_irq() above but with the following extras: 834 * 835 * action->percpu_dev_id is a pointer to percpu variables which 836 * contain the real device id for the cpu on which this handler is 837 * called 838 */ 839 void handle_percpu_devid_irq(struct irq_desc *desc) 840 { 841 struct irq_chip *chip = irq_desc_get_chip(desc); 842 struct irqaction *action = desc->action; 843 unsigned int irq = irq_desc_get_irq(desc); 844 irqreturn_t res; 845 846 /* 847 * PER CPU interrupts are not serialized. Do not touch 848 * desc->tot_count. 849 */ 850 __kstat_incr_irqs_this_cpu(desc); 851 852 if (chip->irq_ack) 853 chip->irq_ack(&desc->irq_data); 854 855 if (likely(action)) { 856 trace_irq_handler_entry(irq, action); 857 res = action->handler(irq, raw_cpu_ptr(action->percpu_dev_id)); 858 trace_irq_handler_exit(irq, action, res); 859 } else { 860 unsigned int cpu = smp_processor_id(); 861 bool enabled = cpumask_test_cpu(cpu, desc->percpu_enabled); 862 863 if (enabled) 864 irq_percpu_disable(desc, cpu); 865 866 pr_err_once("Spurious%s percpu IRQ%u on CPU%u\n", 867 enabled ? " and unmasked" : "", irq, cpu); 868 } 869 870 if (chip->irq_eoi) 871 chip->irq_eoi(&desc->irq_data); 872 } 873 874 /** 875 * handle_percpu_devid_fasteoi_nmi - Per CPU local NMI handler with per cpu 876 * dev ids 877 * @desc: the interrupt description structure for this irq 878 * 879 * Similar to handle_fasteoi_nmi, but handling the dev_id cookie 880 * as a percpu pointer. 881 */ 882 void handle_percpu_devid_fasteoi_nmi(struct irq_desc *desc) 883 { 884 struct irq_chip *chip = irq_desc_get_chip(desc); 885 struct irqaction *action = desc->action; 886 unsigned int irq = irq_desc_get_irq(desc); 887 irqreturn_t res; 888 889 __kstat_incr_irqs_this_cpu(desc); 890 891 trace_irq_handler_entry(irq, action); 892 res = action->handler(irq, raw_cpu_ptr(action->percpu_dev_id)); 893 trace_irq_handler_exit(irq, action, res); 894 895 if (chip->irq_eoi) 896 chip->irq_eoi(&desc->irq_data); 897 } 898 899 static void 900 __irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle, 901 int is_chained, const char *name) 902 { 903 if (!handle) { 904 handle = handle_bad_irq; 905 } else { 906 struct irq_data *irq_data = &desc->irq_data; 907 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 908 /* 909 * With hierarchical domains we might run into a 910 * situation where the outermost chip is not yet set 911 * up, but the inner chips are there. Instead of 912 * bailing we install the handler, but obviously we 913 * cannot enable/startup the interrupt at this point. 914 */ 915 while (irq_data) { 916 if (irq_data->chip != &no_irq_chip) 917 break; 918 /* 919 * Bail out if the outer chip is not set up 920 * and the interrupt supposed to be started 921 * right away. 922 */ 923 if (WARN_ON(is_chained)) 924 return; 925 /* Try the parent */ 926 irq_data = irq_data->parent_data; 927 } 928 #endif 929 if (WARN_ON(!irq_data || irq_data->chip == &no_irq_chip)) 930 return; 931 } 932 933 /* Uninstall? */ 934 if (handle == handle_bad_irq) { 935 if (desc->irq_data.chip != &no_irq_chip) 936 mask_ack_irq(desc); 937 irq_state_set_disabled(desc); 938 if (is_chained) { 939 desc->action = NULL; 940 WARN_ON(irq_chip_pm_put(irq_desc_get_irq_data(desc))); 941 } 942 desc->depth = 1; 943 } 944 desc->handle_irq = handle; 945 desc->name = name; 946 947 if (handle != handle_bad_irq && is_chained) { 948 unsigned int type = irqd_get_trigger_type(&desc->irq_data); 949 950 /* 951 * We're about to start this interrupt immediately, 952 * hence the need to set the trigger configuration. 953 * But the .set_type callback may have overridden the 954 * flow handler, ignoring that we're dealing with a 955 * chained interrupt. Reset it immediately because we 956 * do know better. 957 */ 958 if (type != IRQ_TYPE_NONE) { 959 __irq_set_trigger(desc, type); 960 desc->handle_irq = handle; 961 } 962 963 irq_settings_set_noprobe(desc); 964 irq_settings_set_norequest(desc); 965 irq_settings_set_nothread(desc); 966 desc->action = &chained_action; 967 WARN_ON(irq_chip_pm_get(irq_desc_get_irq_data(desc))); 968 irq_activate_and_startup(desc, IRQ_RESEND); 969 } 970 } 971 972 void __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained, 973 const char *name) 974 { 975 scoped_irqdesc_get_and_lock(irq, 0) 976 __irq_do_set_handler(scoped_irqdesc, handle, is_chained, name); 977 } 978 EXPORT_SYMBOL_GPL(__irq_set_handler); 979 980 void irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle, 981 void *data) 982 { 983 scoped_irqdesc_get_and_buslock(irq, 0) { 984 struct irq_desc *desc = scoped_irqdesc; 985 986 desc->irq_common_data.handler_data = data; 987 __irq_do_set_handler(desc, handle, 1, NULL); 988 } 989 } 990 EXPORT_SYMBOL_GPL(irq_set_chained_handler_and_data); 991 992 void 993 irq_set_chip_and_handler_name(unsigned int irq, const struct irq_chip *chip, 994 irq_flow_handler_t handle, const char *name) 995 { 996 irq_set_chip(irq, chip); 997 __irq_set_handler(irq, handle, 0, name); 998 } 999 EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name); 1000 1001 void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set) 1002 { 1003 scoped_irqdesc_get_and_lock(irq, 0) { 1004 struct irq_desc *desc = scoped_irqdesc; 1005 unsigned long trigger, tmp; 1006 /* 1007 * Warn when a driver sets the no autoenable flag on an already 1008 * active interrupt. 1009 */ 1010 WARN_ON_ONCE(!desc->depth && (set & _IRQ_NOAUTOEN)); 1011 1012 irq_settings_clr_and_set(desc, clr, set); 1013 1014 trigger = irqd_get_trigger_type(&desc->irq_data); 1015 1016 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU | 1017 IRQD_TRIGGER_MASK | IRQD_LEVEL); 1018 if (irq_settings_has_no_balance_set(desc)) 1019 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); 1020 if (irq_settings_is_per_cpu(desc)) 1021 irqd_set(&desc->irq_data, IRQD_PER_CPU); 1022 if (irq_settings_is_level(desc)) 1023 irqd_set(&desc->irq_data, IRQD_LEVEL); 1024 1025 tmp = irq_settings_get_trigger_mask(desc); 1026 if (tmp != IRQ_TYPE_NONE) 1027 trigger = tmp; 1028 1029 irqd_set(&desc->irq_data, trigger); 1030 } 1031 } 1032 EXPORT_SYMBOL_GPL(irq_modify_status); 1033 1034 #ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE 1035 /** 1036 * irq_cpu_online - Invoke all irq_cpu_online functions. 1037 * 1038 * Iterate through all irqs and invoke the chip.irq_cpu_online() 1039 * for each. 1040 */ 1041 void irq_cpu_online(void) 1042 { 1043 unsigned int irq; 1044 1045 for_each_active_irq(irq) { 1046 struct irq_desc *desc = irq_to_desc(irq); 1047 struct irq_chip *chip; 1048 1049 if (!desc) 1050 continue; 1051 1052 guard(raw_spinlock_irqsave)(&desc->lock); 1053 chip = irq_data_get_irq_chip(&desc->irq_data); 1054 if (chip && chip->irq_cpu_online && 1055 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) || 1056 !irqd_irq_disabled(&desc->irq_data))) 1057 chip->irq_cpu_online(&desc->irq_data); 1058 } 1059 } 1060 1061 /** 1062 * irq_cpu_offline - Invoke all irq_cpu_offline functions. 1063 * 1064 * Iterate through all irqs and invoke the chip.irq_cpu_offline() 1065 * for each. 1066 */ 1067 void irq_cpu_offline(void) 1068 { 1069 unsigned int irq; 1070 1071 for_each_active_irq(irq) { 1072 struct irq_desc *desc = irq_to_desc(irq); 1073 struct irq_chip *chip; 1074 1075 if (!desc) 1076 continue; 1077 1078 guard(raw_spinlock_irqsave)(&desc->lock); 1079 chip = irq_data_get_irq_chip(&desc->irq_data); 1080 if (chip && chip->irq_cpu_offline && 1081 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) || 1082 !irqd_irq_disabled(&desc->irq_data))) 1083 chip->irq_cpu_offline(&desc->irq_data); 1084 } 1085 } 1086 #endif 1087 1088 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 1089 1090 #ifdef CONFIG_IRQ_FASTEOI_HIERARCHY_HANDLERS 1091 /** 1092 * handle_fasteoi_ack_irq - irq handler for edge hierarchy stacked on 1093 * transparent controllers 1094 * 1095 * @desc: the interrupt description structure for this irq 1096 * 1097 * Like handle_fasteoi_irq(), but for use with hierarchy where the irq_chip 1098 * also needs to have its ->irq_ack() function called. 1099 */ 1100 void handle_fasteoi_ack_irq(struct irq_desc *desc) 1101 { 1102 struct irq_chip *chip = desc->irq_data.chip; 1103 1104 guard(raw_spinlock)(&desc->lock); 1105 1106 if (!irq_can_handle_pm(desc)) { 1107 cond_eoi_irq(chip, &desc->irq_data); 1108 return; 1109 } 1110 1111 if (unlikely(!irq_can_handle_actions(desc))) { 1112 mask_irq(desc); 1113 cond_eoi_irq(chip, &desc->irq_data); 1114 return; 1115 } 1116 1117 kstat_incr_irqs_this_cpu(desc); 1118 if (desc->istate & IRQS_ONESHOT) 1119 mask_irq(desc); 1120 1121 desc->irq_data.chip->irq_ack(&desc->irq_data); 1122 1123 handle_irq_event(desc); 1124 1125 cond_unmask_eoi_irq(desc, chip); 1126 } 1127 EXPORT_SYMBOL_GPL(handle_fasteoi_ack_irq); 1128 1129 /** 1130 * handle_fasteoi_mask_irq - irq handler for level hierarchy stacked on 1131 * transparent controllers 1132 * 1133 * @desc: the interrupt description structure for this irq 1134 * 1135 * Like handle_fasteoi_irq(), but for use with hierarchy where the irq_chip 1136 * also needs to have its ->irq_mask_ack() function called. 1137 */ 1138 void handle_fasteoi_mask_irq(struct irq_desc *desc) 1139 { 1140 struct irq_chip *chip = desc->irq_data.chip; 1141 1142 guard(raw_spinlock)(&desc->lock); 1143 mask_ack_irq(desc); 1144 1145 if (!irq_can_handle(desc)) { 1146 cond_eoi_irq(chip, &desc->irq_data); 1147 return; 1148 } 1149 1150 kstat_incr_irqs_this_cpu(desc); 1151 1152 handle_irq_event(desc); 1153 1154 cond_unmask_eoi_irq(desc, chip); 1155 } 1156 EXPORT_SYMBOL_GPL(handle_fasteoi_mask_irq); 1157 1158 #endif /* CONFIG_IRQ_FASTEOI_HIERARCHY_HANDLERS */ 1159 1160 /** 1161 * irq_chip_set_parent_state - set the state of a parent interrupt. 1162 * 1163 * @data: Pointer to interrupt specific data 1164 * @which: State to be restored (one of IRQCHIP_STATE_*) 1165 * @val: Value corresponding to @which 1166 * 1167 * Conditional success, if the underlying irqchip does not implement it. 1168 */ 1169 int irq_chip_set_parent_state(struct irq_data *data, 1170 enum irqchip_irq_state which, 1171 bool val) 1172 { 1173 data = data->parent_data; 1174 1175 if (!data || !data->chip->irq_set_irqchip_state) 1176 return 0; 1177 1178 return data->chip->irq_set_irqchip_state(data, which, val); 1179 } 1180 EXPORT_SYMBOL_GPL(irq_chip_set_parent_state); 1181 1182 /** 1183 * irq_chip_get_parent_state - get the state of a parent interrupt. 1184 * 1185 * @data: Pointer to interrupt specific data 1186 * @which: one of IRQCHIP_STATE_* the caller wants to know 1187 * @state: a pointer to a boolean where the state is to be stored 1188 * 1189 * Conditional success, if the underlying irqchip does not implement it. 1190 */ 1191 int irq_chip_get_parent_state(struct irq_data *data, 1192 enum irqchip_irq_state which, 1193 bool *state) 1194 { 1195 data = data->parent_data; 1196 1197 if (!data || !data->chip->irq_get_irqchip_state) 1198 return 0; 1199 1200 return data->chip->irq_get_irqchip_state(data, which, state); 1201 } 1202 EXPORT_SYMBOL_GPL(irq_chip_get_parent_state); 1203 1204 /** 1205 * irq_chip_enable_parent - Enable the parent interrupt (defaults to unmask if 1206 * NULL) 1207 * @data: Pointer to interrupt specific data 1208 */ 1209 void irq_chip_enable_parent(struct irq_data *data) 1210 { 1211 data = data->parent_data; 1212 if (data->chip->irq_enable) 1213 data->chip->irq_enable(data); 1214 else 1215 data->chip->irq_unmask(data); 1216 } 1217 EXPORT_SYMBOL_GPL(irq_chip_enable_parent); 1218 1219 /** 1220 * irq_chip_disable_parent - Disable the parent interrupt (defaults to mask if 1221 * NULL) 1222 * @data: Pointer to interrupt specific data 1223 */ 1224 void irq_chip_disable_parent(struct irq_data *data) 1225 { 1226 data = data->parent_data; 1227 if (data->chip->irq_disable) 1228 data->chip->irq_disable(data); 1229 else 1230 data->chip->irq_mask(data); 1231 } 1232 EXPORT_SYMBOL_GPL(irq_chip_disable_parent); 1233 1234 /** 1235 * irq_chip_ack_parent - Acknowledge the parent interrupt 1236 * @data: Pointer to interrupt specific data 1237 */ 1238 void irq_chip_ack_parent(struct irq_data *data) 1239 { 1240 data = data->parent_data; 1241 data->chip->irq_ack(data); 1242 } 1243 EXPORT_SYMBOL_GPL(irq_chip_ack_parent); 1244 1245 /** 1246 * irq_chip_mask_parent - Mask the parent interrupt 1247 * @data: Pointer to interrupt specific data 1248 */ 1249 void irq_chip_mask_parent(struct irq_data *data) 1250 { 1251 data = data->parent_data; 1252 data->chip->irq_mask(data); 1253 } 1254 EXPORT_SYMBOL_GPL(irq_chip_mask_parent); 1255 1256 /** 1257 * irq_chip_mask_ack_parent - Mask and acknowledge the parent interrupt 1258 * @data: Pointer to interrupt specific data 1259 */ 1260 void irq_chip_mask_ack_parent(struct irq_data *data) 1261 { 1262 data = data->parent_data; 1263 data->chip->irq_mask_ack(data); 1264 } 1265 EXPORT_SYMBOL_GPL(irq_chip_mask_ack_parent); 1266 1267 /** 1268 * irq_chip_unmask_parent - Unmask the parent interrupt 1269 * @data: Pointer to interrupt specific data 1270 */ 1271 void irq_chip_unmask_parent(struct irq_data *data) 1272 { 1273 data = data->parent_data; 1274 data->chip->irq_unmask(data); 1275 } 1276 EXPORT_SYMBOL_GPL(irq_chip_unmask_parent); 1277 1278 /** 1279 * irq_chip_eoi_parent - Invoke EOI on the parent interrupt 1280 * @data: Pointer to interrupt specific data 1281 */ 1282 void irq_chip_eoi_parent(struct irq_data *data) 1283 { 1284 data = data->parent_data; 1285 data->chip->irq_eoi(data); 1286 } 1287 EXPORT_SYMBOL_GPL(irq_chip_eoi_parent); 1288 1289 /** 1290 * irq_chip_set_affinity_parent - Set affinity on the parent interrupt 1291 * @data: Pointer to interrupt specific data 1292 * @dest: The affinity mask to set 1293 * @force: Flag to enforce setting (disable online checks) 1294 * 1295 * Conditional, as the underlying parent chip might not implement it. 1296 */ 1297 int irq_chip_set_affinity_parent(struct irq_data *data, 1298 const struct cpumask *dest, bool force) 1299 { 1300 data = data->parent_data; 1301 if (data->chip->irq_set_affinity) 1302 return data->chip->irq_set_affinity(data, dest, force); 1303 1304 return -ENOSYS; 1305 } 1306 EXPORT_SYMBOL_GPL(irq_chip_set_affinity_parent); 1307 1308 /** 1309 * irq_chip_set_type_parent - Set IRQ type on the parent interrupt 1310 * @data: Pointer to interrupt specific data 1311 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h 1312 * 1313 * Conditional, as the underlying parent chip might not implement it. 1314 */ 1315 int irq_chip_set_type_parent(struct irq_data *data, unsigned int type) 1316 { 1317 data = data->parent_data; 1318 1319 if (data->chip->irq_set_type) 1320 return data->chip->irq_set_type(data, type); 1321 1322 return -ENOSYS; 1323 } 1324 EXPORT_SYMBOL_GPL(irq_chip_set_type_parent); 1325 1326 /** 1327 * irq_chip_retrigger_hierarchy - Retrigger an interrupt in hardware 1328 * @data: Pointer to interrupt specific data 1329 * 1330 * Iterate through the domain hierarchy of the interrupt and check 1331 * whether a hw retrigger function exists. If yes, invoke it. 1332 */ 1333 int irq_chip_retrigger_hierarchy(struct irq_data *data) 1334 { 1335 for (data = data->parent_data; data; data = data->parent_data) 1336 if (data->chip && data->chip->irq_retrigger) 1337 return data->chip->irq_retrigger(data); 1338 1339 return 0; 1340 } 1341 EXPORT_SYMBOL_GPL(irq_chip_retrigger_hierarchy); 1342 1343 /** 1344 * irq_chip_set_vcpu_affinity_parent - Set vcpu affinity on the parent interrupt 1345 * @data: Pointer to interrupt specific data 1346 * @vcpu_info: The vcpu affinity information 1347 */ 1348 int irq_chip_set_vcpu_affinity_parent(struct irq_data *data, void *vcpu_info) 1349 { 1350 data = data->parent_data; 1351 if (data->chip->irq_set_vcpu_affinity) 1352 return data->chip->irq_set_vcpu_affinity(data, vcpu_info); 1353 1354 return -ENOSYS; 1355 } 1356 EXPORT_SYMBOL_GPL(irq_chip_set_vcpu_affinity_parent); 1357 /** 1358 * irq_chip_set_wake_parent - Set/reset wake-up on the parent interrupt 1359 * @data: Pointer to interrupt specific data 1360 * @on: Whether to set or reset the wake-up capability of this irq 1361 * 1362 * Conditional, as the underlying parent chip might not implement it. 1363 */ 1364 int irq_chip_set_wake_parent(struct irq_data *data, unsigned int on) 1365 { 1366 data = data->parent_data; 1367 1368 if (data->chip->flags & IRQCHIP_SKIP_SET_WAKE) 1369 return 0; 1370 1371 if (data->chip->irq_set_wake) 1372 return data->chip->irq_set_wake(data, on); 1373 1374 return -ENOSYS; 1375 } 1376 EXPORT_SYMBOL_GPL(irq_chip_set_wake_parent); 1377 1378 /** 1379 * irq_chip_request_resources_parent - Request resources on the parent interrupt 1380 * @data: Pointer to interrupt specific data 1381 */ 1382 int irq_chip_request_resources_parent(struct irq_data *data) 1383 { 1384 data = data->parent_data; 1385 1386 if (data->chip->irq_request_resources) 1387 return data->chip->irq_request_resources(data); 1388 1389 /* no error on missing optional irq_chip::irq_request_resources */ 1390 return 0; 1391 } 1392 EXPORT_SYMBOL_GPL(irq_chip_request_resources_parent); 1393 1394 /** 1395 * irq_chip_release_resources_parent - Release resources on the parent interrupt 1396 * @data: Pointer to interrupt specific data 1397 */ 1398 void irq_chip_release_resources_parent(struct irq_data *data) 1399 { 1400 data = data->parent_data; 1401 if (data->chip->irq_release_resources) 1402 data->chip->irq_release_resources(data); 1403 } 1404 EXPORT_SYMBOL_GPL(irq_chip_release_resources_parent); 1405 #endif 1406 1407 /** 1408 * irq_chip_compose_msi_msg - Compose msi message for a irq chip 1409 * @data: Pointer to interrupt specific data 1410 * @msg: Pointer to the MSI message 1411 * 1412 * For hierarchical domains we find the first chip in the hierarchy 1413 * which implements the irq_compose_msi_msg callback. For non 1414 * hierarchical we use the top level chip. 1415 */ 1416 int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) 1417 { 1418 struct irq_data *pos; 1419 1420 for (pos = NULL; !pos && data; data = irqd_get_parent_data(data)) { 1421 if (data->chip && data->chip->irq_compose_msi_msg) 1422 pos = data; 1423 } 1424 1425 if (!pos) 1426 return -ENOSYS; 1427 1428 pos->chip->irq_compose_msi_msg(pos, msg); 1429 return 0; 1430 } 1431 1432 static struct device *irq_get_pm_device(struct irq_data *data) 1433 { 1434 if (data->domain) 1435 return data->domain->pm_dev; 1436 1437 return NULL; 1438 } 1439 1440 /** 1441 * irq_chip_pm_get - Enable power for an IRQ chip 1442 * @data: Pointer to interrupt specific data 1443 * 1444 * Enable the power to the IRQ chip referenced by the interrupt data 1445 * structure. 1446 */ 1447 int irq_chip_pm_get(struct irq_data *data) 1448 { 1449 struct device *dev = irq_get_pm_device(data); 1450 int retval = 0; 1451 1452 if (IS_ENABLED(CONFIG_PM) && dev) 1453 retval = pm_runtime_resume_and_get(dev); 1454 1455 return retval; 1456 } 1457 1458 /** 1459 * irq_chip_pm_put - Disable power for an IRQ chip 1460 * @data: Pointer to interrupt specific data 1461 * 1462 * Disable the power to the IRQ chip referenced by the interrupt data 1463 * structure, belongs. Note that power will only be disabled, once this 1464 * function has been called for all IRQs that have called irq_chip_pm_get(). 1465 */ 1466 int irq_chip_pm_put(struct irq_data *data) 1467 { 1468 struct device *dev = irq_get_pm_device(data); 1469 int retval = 0; 1470 1471 if (IS_ENABLED(CONFIG_PM) && dev) 1472 retval = pm_runtime_put(dev); 1473 1474 return (retval < 0) ? retval : 0; 1475 } 1476