diff options
Diffstat (limited to 'kernel/irq')
| -rw-r--r-- | kernel/irq/chip.c | 54 | ||||
| -rw-r--r-- | kernel/irq/debugfs.c | 6 | ||||
| -rw-r--r-- | kernel/irq/internals.h | 2 | ||||
| -rw-r--r-- | kernel/irq/irqdesc.c | 35 | ||||
| -rw-r--r-- | kernel/irq/irqdomain.c | 14 | ||||
| -rw-r--r-- | kernel/irq/manage.c | 405 |
6 files changed, 513 insertions, 3 deletions
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index e960c4f46ee0..99b7dd6982a4 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c | |||
| @@ -730,6 +730,37 @@ out: | |||
| 730 | EXPORT_SYMBOL_GPL(handle_fasteoi_irq); | 730 | EXPORT_SYMBOL_GPL(handle_fasteoi_irq); |
| 731 | 731 | ||
| 732 | /** | 732 | /** |
| 733 | * handle_fasteoi_nmi - irq handler for NMI interrupt lines | ||
| 734 | * @desc: the interrupt description structure for this irq | ||
| 735 | * | ||
| 736 | * A simple NMI-safe handler, considering the restrictions | ||
| 737 | * from request_nmi. | ||
| 738 | * | ||
| 739 | * Only a single callback will be issued to the chip: an ->eoi() | ||
| 740 | * call when the interrupt has been serviced. This enables support | ||
| 741 | * for modern forms of interrupt handlers, which handle the flow | ||
| 742 | * details in hardware, transparently. | ||
| 743 | */ | ||
| 744 | void handle_fasteoi_nmi(struct irq_desc *desc) | ||
| 745 | { | ||
| 746 | struct irq_chip *chip = irq_desc_get_chip(desc); | ||
| 747 | struct irqaction *action = desc->action; | ||
| 748 | unsigned int irq = irq_desc_get_irq(desc); | ||
| 749 | irqreturn_t res; | ||
| 750 | |||
| 751 | trace_irq_handler_entry(irq, action); | ||
| 752 | /* | ||
| 753 | * NMIs cannot be shared, there is only one action. | ||
| 754 | */ | ||
| 755 | res = action->handler(irq, action->dev_id); | ||
| 756 | trace_irq_handler_exit(irq, action, res); | ||
| 757 | |||
| 758 | if (chip->irq_eoi) | ||
| 759 | chip->irq_eoi(&desc->irq_data); | ||
| 760 | } | ||
| 761 | EXPORT_SYMBOL_GPL(handle_fasteoi_nmi); | ||
| 762 | |||
| 763 | /** | ||
| 733 | * handle_edge_irq - edge type IRQ handler | 764 | * handle_edge_irq - edge type IRQ handler |
| 734 | * @desc: the interrupt description structure for this irq | 765 | * @desc: the interrupt description structure for this irq |
| 735 | * | 766 | * |
| @@ -916,6 +947,29 @@ void handle_percpu_devid_irq(struct irq_desc *desc) | |||
| 916 | chip->irq_eoi(&desc->irq_data); | 947 | chip->irq_eoi(&desc->irq_data); |
| 917 | } | 948 | } |
| 918 | 949 | ||
| 950 | /** | ||
| 951 | * handle_percpu_devid_fasteoi_nmi - Per CPU local NMI handler with per cpu | ||
| 952 | * dev ids | ||
| 953 | * @desc: the interrupt description structure for this irq | ||
| 954 | * | ||
| 955 | * Similar to handle_fasteoi_nmi, but handling the dev_id cookie | ||
| 956 | * as a percpu pointer. | ||
| 957 | */ | ||
| 958 | void handle_percpu_devid_fasteoi_nmi(struct irq_desc *desc) | ||
| 959 | { | ||
| 960 | struct irq_chip *chip = irq_desc_get_chip(desc); | ||
| 961 | struct irqaction *action = desc->action; | ||
| 962 | unsigned int irq = irq_desc_get_irq(desc); | ||
| 963 | irqreturn_t res; | ||
| 964 | |||
| 965 | trace_irq_handler_entry(irq, action); | ||
| 966 | res = action->handler(irq, raw_cpu_ptr(action->percpu_dev_id)); | ||
| 967 | trace_irq_handler_exit(irq, action, res); | ||
| 968 | |||
| 969 | if (chip->irq_eoi) | ||
| 970 | chip->irq_eoi(&desc->irq_data); | ||
| 971 | } | ||
| 972 | |||
| 919 | static void | 973 | static void |
| 920 | __irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle, | 974 | __irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle, |
| 921 | int is_chained, const char *name) | 975 | int is_chained, const char *name) |
diff --git a/kernel/irq/debugfs.c b/kernel/irq/debugfs.c index bbd783a83409..516c00a5e867 100644 --- a/kernel/irq/debugfs.c +++ b/kernel/irq/debugfs.c | |||
| @@ -56,6 +56,7 @@ static const struct irq_bit_descr irqchip_flags[] = { | |||
| 56 | BIT_MASK_DESCR(IRQCHIP_ONESHOT_SAFE), | 56 | BIT_MASK_DESCR(IRQCHIP_ONESHOT_SAFE), |
| 57 | BIT_MASK_DESCR(IRQCHIP_EOI_THREADED), | 57 | BIT_MASK_DESCR(IRQCHIP_EOI_THREADED), |
| 58 | BIT_MASK_DESCR(IRQCHIP_SUPPORTS_LEVEL_MSI), | 58 | BIT_MASK_DESCR(IRQCHIP_SUPPORTS_LEVEL_MSI), |
| 59 | BIT_MASK_DESCR(IRQCHIP_SUPPORTS_NMI), | ||
| 59 | }; | 60 | }; |
| 60 | 61 | ||
| 61 | static void | 62 | static void |
| @@ -140,6 +141,7 @@ static const struct irq_bit_descr irqdesc_istates[] = { | |||
| 140 | BIT_MASK_DESCR(IRQS_WAITING), | 141 | BIT_MASK_DESCR(IRQS_WAITING), |
| 141 | BIT_MASK_DESCR(IRQS_PENDING), | 142 | BIT_MASK_DESCR(IRQS_PENDING), |
| 142 | BIT_MASK_DESCR(IRQS_SUSPENDED), | 143 | BIT_MASK_DESCR(IRQS_SUSPENDED), |
| 144 | BIT_MASK_DESCR(IRQS_NMI), | ||
| 143 | }; | 145 | }; |
| 144 | 146 | ||
| 145 | 147 | ||
| @@ -203,8 +205,8 @@ static ssize_t irq_debug_write(struct file *file, const char __user *user_buf, | |||
| 203 | chip_bus_lock(desc); | 205 | chip_bus_lock(desc); |
| 204 | raw_spin_lock_irqsave(&desc->lock, flags); | 206 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 205 | 207 | ||
| 206 | if (irq_settings_is_level(desc)) { | 208 | if (irq_settings_is_level(desc) || desc->istate & IRQS_NMI) { |
| 207 | /* Can't do level, sorry */ | 209 | /* Can't do level nor NMIs, sorry */ |
| 208 | err = -EINVAL; | 210 | err = -EINVAL; |
| 209 | } else { | 211 | } else { |
| 210 | desc->istate |= IRQS_PENDING; | 212 | desc->istate |= IRQS_PENDING; |
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index e74e7eea76cf..70c3053bc1f6 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h | |||
| @@ -49,6 +49,7 @@ enum { | |||
| 49 | * IRQS_WAITING - irq is waiting | 49 | * IRQS_WAITING - irq is waiting |
| 50 | * IRQS_PENDING - irq is pending and replayed later | 50 | * IRQS_PENDING - irq is pending and replayed later |
| 51 | * IRQS_SUSPENDED - irq is suspended | 51 | * IRQS_SUSPENDED - irq is suspended |
| 52 | * IRQS_NMI - irq line is used to deliver NMIs | ||
| 52 | */ | 53 | */ |
| 53 | enum { | 54 | enum { |
| 54 | IRQS_AUTODETECT = 0x00000001, | 55 | IRQS_AUTODETECT = 0x00000001, |
| @@ -60,6 +61,7 @@ enum { | |||
| 60 | IRQS_PENDING = 0x00000200, | 61 | IRQS_PENDING = 0x00000200, |
| 61 | IRQS_SUSPENDED = 0x00000800, | 62 | IRQS_SUSPENDED = 0x00000800, |
| 62 | IRQS_TIMINGS = 0x00001000, | 63 | IRQS_TIMINGS = 0x00001000, |
| 64 | IRQS_NMI = 0x00002000, | ||
| 63 | }; | 65 | }; |
| 64 | 66 | ||
| 65 | #include "debug.h" | 67 | #include "debug.h" |
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 84fa255d0329..13539e12cd80 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c | |||
| @@ -670,6 +670,41 @@ int __handle_domain_irq(struct irq_domain *domain, unsigned int hwirq, | |||
| 670 | set_irq_regs(old_regs); | 670 | set_irq_regs(old_regs); |
| 671 | return ret; | 671 | return ret; |
| 672 | } | 672 | } |
| 673 | |||
| 674 | #ifdef CONFIG_IRQ_DOMAIN | ||
| 675 | /** | ||
| 676 | * handle_domain_nmi - Invoke the handler for a HW irq belonging to a domain | ||
| 677 | * @domain: The domain where to perform the lookup | ||
| 678 | * @hwirq: The HW irq number to convert to a logical one | ||
| 679 | * @regs: Register file coming from the low-level handling code | ||
| 680 | * | ||
| 681 | * Returns: 0 on success, or -EINVAL if conversion has failed | ||
| 682 | */ | ||
| 683 | int handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq, | ||
| 684 | struct pt_regs *regs) | ||
| 685 | { | ||
| 686 | struct pt_regs *old_regs = set_irq_regs(regs); | ||
| 687 | unsigned int irq; | ||
| 688 | int ret = 0; | ||
| 689 | |||
| 690 | nmi_enter(); | ||
| 691 | |||
| 692 | irq = irq_find_mapping(domain, hwirq); | ||
| 693 | |||
| 694 | /* | ||
| 695 | * ack_bad_irq is not NMI-safe, just report | ||
| 696 | * an invalid interrupt. | ||
| 697 | */ | ||
| 698 | if (likely(irq)) | ||
| 699 | generic_handle_irq(irq); | ||
| 700 | else | ||
| 701 | ret = -EINVAL; | ||
| 702 | |||
| 703 | nmi_exit(); | ||
| 704 | set_irq_regs(old_regs); | ||
| 705 | return ret; | ||
| 706 | } | ||
| 707 | #endif | ||
| 673 | #endif | 708 | #endif |
| 674 | 709 | ||
| 675 | /* Dynamic interrupt handling */ | 710 | /* Dynamic interrupt handling */ |
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 45c74373c7a4..3bf9793d8825 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c | |||
| @@ -458,6 +458,20 @@ void irq_set_default_host(struct irq_domain *domain) | |||
| 458 | } | 458 | } |
| 459 | EXPORT_SYMBOL_GPL(irq_set_default_host); | 459 | EXPORT_SYMBOL_GPL(irq_set_default_host); |
| 460 | 460 | ||
| 461 | /** | ||
| 462 | * irq_get_default_host() - Retrieve the "default" irq domain | ||
| 463 | * | ||
| 464 | * Returns: the default domain, if any. | ||
| 465 | * | ||
| 466 | * Modern code should never use this. This should only be used on | ||
| 467 | * systems that cannot implement a firmware->fwnode mapping (which | ||
| 468 | * both DT and ACPI provide). | ||
| 469 | */ | ||
| 470 | struct irq_domain *irq_get_default_host(void) | ||
| 471 | { | ||
| 472 | return irq_default_domain; | ||
| 473 | } | ||
| 474 | |||
| 461 | static void irq_domain_clear_mapping(struct irq_domain *domain, | 475 | static void irq_domain_clear_mapping(struct irq_domain *domain, |
| 462 | irq_hw_number_t hwirq) | 476 | irq_hw_number_t hwirq) |
| 463 | { | 477 | { |
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 3f8a8ebda484..9ec34a2a6638 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c | |||
| @@ -341,7 +341,7 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) | |||
| 341 | /* The release function is promised process context */ | 341 | /* The release function is promised process context */ |
| 342 | might_sleep(); | 342 | might_sleep(); |
| 343 | 343 | ||
| 344 | if (!desc) | 344 | if (!desc || desc->istate & IRQS_NMI) |
| 345 | return -EINVAL; | 345 | return -EINVAL; |
| 346 | 346 | ||
| 347 | /* Complete initialisation of *notify */ | 347 | /* Complete initialisation of *notify */ |
| @@ -553,6 +553,21 @@ bool disable_hardirq(unsigned int irq) | |||
| 553 | } | 553 | } |
| 554 | EXPORT_SYMBOL_GPL(disable_hardirq); | 554 | EXPORT_SYMBOL_GPL(disable_hardirq); |
| 555 | 555 | ||
| 556 | /** | ||
| 557 | * disable_nmi_nosync - disable an nmi without waiting | ||
| 558 | * @irq: Interrupt to disable | ||
| 559 | * | ||
| 560 | * Disable the selected interrupt line. Disables and enables are | ||
| 561 | * nested. | ||
| 562 | * The interrupt to disable must have been requested through request_nmi. | ||
| 563 | * Unlike disable_nmi(), this function does not ensure existing | ||
| 564 | * instances of the IRQ handler have completed before returning. | ||
| 565 | */ | ||
| 566 | void disable_nmi_nosync(unsigned int irq) | ||
| 567 | { | ||
| 568 | disable_irq_nosync(irq); | ||
| 569 | } | ||
| 570 | |||
| 556 | void __enable_irq(struct irq_desc *desc) | 571 | void __enable_irq(struct irq_desc *desc) |
| 557 | { | 572 | { |
| 558 | switch (desc->depth) { | 573 | switch (desc->depth) { |
| @@ -609,6 +624,20 @@ out: | |||
| 609 | } | 624 | } |
| 610 | EXPORT_SYMBOL(enable_irq); | 625 | EXPORT_SYMBOL(enable_irq); |
| 611 | 626 | ||
| 627 | /** | ||
| 628 | * enable_nmi - enable handling of an nmi | ||
| 629 | * @irq: Interrupt to enable | ||
| 630 | * | ||
| 631 | * The interrupt to enable must have been requested through request_nmi. | ||
| 632 | * Undoes the effect of one call to disable_nmi(). If this | ||
| 633 | * matches the last disable, processing of interrupts on this | ||
| 634 | * IRQ line is re-enabled. | ||
| 635 | */ | ||
| 636 | void enable_nmi(unsigned int irq) | ||
| 637 | { | ||
| 638 | enable_irq(irq); | ||
| 639 | } | ||
| 640 | |||
| 612 | static int set_irq_wake_real(unsigned int irq, unsigned int on) | 641 | static int set_irq_wake_real(unsigned int irq, unsigned int on) |
| 613 | { | 642 | { |
| 614 | struct irq_desc *desc = irq_to_desc(irq); | 643 | struct irq_desc *desc = irq_to_desc(irq); |
| @@ -644,6 +673,12 @@ int irq_set_irq_wake(unsigned int irq, unsigned int on) | |||
| 644 | if (!desc) | 673 | if (!desc) |
| 645 | return -EINVAL; | 674 | return -EINVAL; |
| 646 | 675 | ||
| 676 | /* Don't use NMIs as wake up interrupts please */ | ||
| 677 | if (desc->istate & IRQS_NMI) { | ||
| 678 | ret = -EINVAL; | ||
| 679 | goto out_unlock; | ||
| 680 | } | ||
| 681 | |||
| 647 | /* wakeup-capable irqs can be shared between drivers that | 682 | /* wakeup-capable irqs can be shared between drivers that |
| 648 | * don't need to have the same sleep mode behaviors. | 683 | * don't need to have the same sleep mode behaviors. |
| 649 | */ | 684 | */ |
| @@ -666,6 +701,8 @@ int irq_set_irq_wake(unsigned int irq, unsigned int on) | |||
| 666 | irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); | 701 | irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); |
| 667 | } | 702 | } |
| 668 | } | 703 | } |
| 704 | |||
| 705 | out_unlock: | ||
| 669 | irq_put_desc_busunlock(desc, flags); | 706 | irq_put_desc_busunlock(desc, flags); |
| 670 | return ret; | 707 | return ret; |
| 671 | } | 708 | } |
| @@ -1129,6 +1166,39 @@ static void irq_release_resources(struct irq_desc *desc) | |||
| 1129 | c->irq_release_resources(d); | 1166 | c->irq_release_resources(d); |
| 1130 | } | 1167 | } |
| 1131 | 1168 | ||
| 1169 | static bool irq_supports_nmi(struct irq_desc *desc) | ||
| 1170 | { | ||
| 1171 | struct irq_data *d = irq_desc_get_irq_data(desc); | ||
| 1172 | |||
| 1173 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY | ||
| 1174 | /* Only IRQs directly managed by the root irqchip can be set as NMI */ | ||
| 1175 | if (d->parent_data) | ||
| 1176 | return false; | ||
| 1177 | #endif | ||
| 1178 | /* Don't support NMIs for chips behind a slow bus */ | ||
| 1179 | if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) | ||
| 1180 | return false; | ||
| 1181 | |||
| 1182 | return d->chip->flags & IRQCHIP_SUPPORTS_NMI; | ||
| 1183 | } | ||
| 1184 | |||
| 1185 | static int irq_nmi_setup(struct irq_desc *desc) | ||
| 1186 | { | ||
| 1187 | struct irq_data *d = irq_desc_get_irq_data(desc); | ||
| 1188 | struct irq_chip *c = d->chip; | ||
| 1189 | |||
| 1190 | return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; | ||
| 1191 | } | ||
| 1192 | |||
| 1193 | static void irq_nmi_teardown(struct irq_desc *desc) | ||
| 1194 | { | ||
| 1195 | struct irq_data *d = irq_desc_get_irq_data(desc); | ||
| 1196 | struct irq_chip *c = d->chip; | ||
| 1197 | |||
| 1198 | if (c->irq_nmi_teardown) | ||
| 1199 | c->irq_nmi_teardown(d); | ||
| 1200 | } | ||
| 1201 | |||
| 1132 | static int | 1202 | static int |
| 1133 | setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary) | 1203 | setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary) |
| 1134 | { | 1204 | { |
| @@ -1303,9 +1373,17 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) | |||
| 1303 | * fields must have IRQF_SHARED set and the bits which | 1373 | * fields must have IRQF_SHARED set and the bits which |
| 1304 | * set the trigger type must match. Also all must | 1374 | * set the trigger type must match. Also all must |
| 1305 | * agree on ONESHOT. | 1375 | * agree on ONESHOT. |
| 1376 | * Interrupt lines used for NMIs cannot be shared. | ||
| 1306 | */ | 1377 | */ |
| 1307 | unsigned int oldtype; | 1378 | unsigned int oldtype; |
| 1308 | 1379 | ||
| 1380 | if (desc->istate & IRQS_NMI) { | ||
| 1381 | pr_err("Invalid attempt to share NMI for %s (irq %d) on irqchip %s.\n", | ||
| 1382 | new->name, irq, desc->irq_data.chip->name); | ||
| 1383 | ret = -EINVAL; | ||
| 1384 | goto out_unlock; | ||
| 1385 | } | ||
| 1386 | |||
| 1309 | /* | 1387 | /* |
| 1310 | * If nobody did set the configuration before, inherit | 1388 | * If nobody did set the configuration before, inherit |
| 1311 | * the one provided by the requester. | 1389 | * the one provided by the requester. |
| @@ -1757,6 +1835,59 @@ const void *free_irq(unsigned int irq, void *dev_id) | |||
| 1757 | } | 1835 | } |
| 1758 | EXPORT_SYMBOL(free_irq); | 1836 | EXPORT_SYMBOL(free_irq); |
| 1759 | 1837 | ||
| 1838 | /* This function must be called with desc->lock held */ | ||
| 1839 | static const void *__cleanup_nmi(unsigned int irq, struct irq_desc *desc) | ||
| 1840 | { | ||
| 1841 | const char *devname = NULL; | ||
| 1842 | |||
| 1843 | desc->istate &= ~IRQS_NMI; | ||
| 1844 | |||
| 1845 | if (!WARN_ON(desc->action == NULL)) { | ||
| 1846 | irq_pm_remove_action(desc, desc->action); | ||
| 1847 | devname = desc->action->name; | ||
| 1848 | unregister_handler_proc(irq, desc->action); | ||
| 1849 | |||
| 1850 | kfree(desc->action); | ||
| 1851 | desc->action = NULL; | ||
| 1852 | } | ||
| 1853 | |||
| 1854 | irq_settings_clr_disable_unlazy(desc); | ||
| 1855 | irq_shutdown(desc); | ||
| 1856 | |||
| 1857 | irq_release_resources(desc); | ||
| 1858 | |||
| 1859 | irq_chip_pm_put(&desc->irq_data); | ||
| 1860 | module_put(desc->owner); | ||
| 1861 | |||
| 1862 | return devname; | ||
| 1863 | } | ||
| 1864 | |||
| 1865 | const void *free_nmi(unsigned int irq, void *dev_id) | ||
| 1866 | { | ||
| 1867 | struct irq_desc *desc = irq_to_desc(irq); | ||
| 1868 | unsigned long flags; | ||
| 1869 | const void *devname; | ||
| 1870 | |||
| 1871 | if (!desc || WARN_ON(!(desc->istate & IRQS_NMI))) | ||
| 1872 | return NULL; | ||
| 1873 | |||
| 1874 | if (WARN_ON(irq_settings_is_per_cpu_devid(desc))) | ||
| 1875 | return NULL; | ||
| 1876 | |||
| 1877 | /* NMI still enabled */ | ||
| 1878 | if (WARN_ON(desc->depth == 0)) | ||
| 1879 | disable_nmi_nosync(irq); | ||
| 1880 | |||
| 1881 | raw_spin_lock_irqsave(&desc->lock, flags); | ||
| 1882 | |||
| 1883 | irq_nmi_teardown(desc); | ||
| 1884 | devname = __cleanup_nmi(irq, desc); | ||
| 1885 | |||
| 1886 | raw_spin_unlock_irqrestore(&desc->lock, flags); | ||
| 1887 | |||
| 1888 | return devname; | ||
| 1889 | } | ||
| 1890 | |||
| 1760 | /** | 1891 | /** |
| 1761 | * request_threaded_irq - allocate an interrupt line | 1892 | * request_threaded_irq - allocate an interrupt line |
| 1762 | * @irq: Interrupt line to allocate | 1893 | * @irq: Interrupt line to allocate |
| @@ -1926,6 +2057,101 @@ int request_any_context_irq(unsigned int irq, irq_handler_t handler, | |||
| 1926 | } | 2057 | } |
| 1927 | EXPORT_SYMBOL_GPL(request_any_context_irq); | 2058 | EXPORT_SYMBOL_GPL(request_any_context_irq); |
| 1928 | 2059 | ||
| 2060 | /** | ||
| 2061 | * request_nmi - allocate an interrupt line for NMI delivery | ||
| 2062 | * @irq: Interrupt line to allocate | ||
| 2063 | * @handler: Function to be called when the IRQ occurs. | ||
| 2064 | * Threaded handler for threaded interrupts. | ||
| 2065 | * @irqflags: Interrupt type flags | ||
| 2066 | * @name: An ascii name for the claiming device | ||
| 2067 | * @dev_id: A cookie passed back to the handler function | ||
| 2068 | * | ||
| 2069 | * This call allocates interrupt resources and enables the | ||
| 2070 | * interrupt line and IRQ handling. It sets up the IRQ line | ||
| 2071 | * to be handled as an NMI. | ||
| 2072 | * | ||
| 2073 | * An interrupt line delivering NMIs cannot be shared and IRQ handling | ||
| 2074 | * cannot be threaded. | ||
| 2075 | * | ||
| 2076 | * Interrupt lines requested for NMI delivering must produce per cpu | ||
| 2077 | * interrupts and have auto enabling setting disabled. | ||
| 2078 | * | ||
| 2079 | * Dev_id must be globally unique. Normally the address of the | ||
| 2080 | * device data structure is used as the cookie. Since the handler | ||
| 2081 | * receives this value it makes sense to use it. | ||
| 2082 | * | ||
| 2083 | * If the interrupt line cannot be used to deliver NMIs, function | ||
| 2084 | * will fail and return a negative value. | ||
| 2085 | */ | ||
| 2086 | int request_nmi(unsigned int irq, irq_handler_t handler, | ||
| 2087 | unsigned long irqflags, const char *name, void *dev_id) | ||
| 2088 | { | ||
| 2089 | struct irqaction *action; | ||
| 2090 | struct irq_desc *desc; | ||
| 2091 | unsigned long flags; | ||
| 2092 | int retval; | ||
| 2093 | |||
| 2094 | if (irq == IRQ_NOTCONNECTED) | ||
| 2095 | return -ENOTCONN; | ||
| 2096 | |||
| 2097 | /* NMI cannot be shared, used for Polling */ | ||
| 2098 | if (irqflags & (IRQF_SHARED | IRQF_COND_SUSPEND | IRQF_IRQPOLL)) | ||
| 2099 | return -EINVAL; | ||
| 2100 | |||
| 2101 | if (!(irqflags & IRQF_PERCPU)) | ||
| 2102 | return -EINVAL; | ||
| 2103 | |||
| 2104 | if (!handler) | ||
| 2105 | return -EINVAL; | ||
| 2106 | |||
| 2107 | desc = irq_to_desc(irq); | ||
| 2108 | |||
| 2109 | if (!desc || irq_settings_can_autoenable(desc) || | ||
| 2110 | !irq_settings_can_request(desc) || | ||
| 2111 | WARN_ON(irq_settings_is_per_cpu_devid(desc)) || | ||
| 2112 | !irq_supports_nmi(desc)) | ||
| 2113 | return -EINVAL; | ||
| 2114 | |||
| 2115 | action = kzalloc(sizeof(struct irqaction), GFP_KERNEL); | ||
| 2116 | if (!action) | ||
| 2117 | return -ENOMEM; | ||
| 2118 | |||
| 2119 | action->handler = handler; | ||
| 2120 | action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; | ||
| 2121 | action->name = name; | ||
| 2122 | action->dev_id = dev_id; | ||
| 2123 | |||
| 2124 | retval = irq_chip_pm_get(&desc->irq_data); | ||
| 2125 | if (retval < 0) | ||
| 2126 | goto err_out; | ||
| 2127 | |||
| 2128 | retval = __setup_irq(irq, desc, action); | ||
| 2129 | if (retval) | ||
| 2130 | goto err_irq_setup; | ||
| 2131 | |||
| 2132 | raw_spin_lock_irqsave(&desc->lock, flags); | ||
| 2133 | |||
| 2134 | /* Setup NMI state */ | ||
| 2135 | desc->istate |= IRQS_NMI; | ||
| 2136 | retval = irq_nmi_setup(desc); | ||
| 2137 | if (retval) { | ||
| 2138 | __cleanup_nmi(irq, desc); | ||
| 2139 | raw_spin_unlock_irqrestore(&desc->lock, flags); | ||
| 2140 | return -EINVAL; | ||
| 2141 | } | ||
| 2142 | |||
| 2143 | raw_spin_unlock_irqrestore(&desc->lock, flags); | ||
| 2144 | |||
| 2145 | return 0; | ||
| 2146 | |||
| 2147 | err_irq_setup: | ||
| 2148 | irq_chip_pm_put(&desc->irq_data); | ||
| 2149 | err_out: | ||
| 2150 | kfree(action); | ||
| 2151 | |||
| 2152 | return retval; | ||
| 2153 | } | ||
| 2154 | |||
| 1929 | void enable_percpu_irq(unsigned int irq, unsigned int type) | 2155 | void enable_percpu_irq(unsigned int irq, unsigned int type) |
| 1930 | { | 2156 | { |
| 1931 | unsigned int cpu = smp_processor_id(); | 2157 | unsigned int cpu = smp_processor_id(); |
| @@ -1960,6 +2186,11 @@ out: | |||
| 1960 | } | 2186 | } |
| 1961 | EXPORT_SYMBOL_GPL(enable_percpu_irq); | 2187 | EXPORT_SYMBOL_GPL(enable_percpu_irq); |
| 1962 | 2188 | ||
| 2189 | void enable_percpu_nmi(unsigned int irq, unsigned int type) | ||
| 2190 | { | ||
| 2191 | enable_percpu_irq(irq, type); | ||
| 2192 | } | ||
| 2193 | |||
| 1963 | /** | 2194 | /** |
| 1964 | * irq_percpu_is_enabled - Check whether the per cpu irq is enabled | 2195 | * irq_percpu_is_enabled - Check whether the per cpu irq is enabled |
| 1965 | * @irq: Linux irq number to check for | 2196 | * @irq: Linux irq number to check for |
| @@ -1999,6 +2230,11 @@ void disable_percpu_irq(unsigned int irq) | |||
| 1999 | } | 2230 | } |
| 2000 | EXPORT_SYMBOL_GPL(disable_percpu_irq); | 2231 | EXPORT_SYMBOL_GPL(disable_percpu_irq); |
| 2001 | 2232 | ||
| 2233 | void disable_percpu_nmi(unsigned int irq) | ||
| 2234 | { | ||
| 2235 | disable_percpu_irq(irq); | ||
| 2236 | } | ||
| 2237 | |||
| 2002 | /* | 2238 | /* |
| 2003 | * Internal function to unregister a percpu irqaction. | 2239 | * Internal function to unregister a percpu irqaction. |
| 2004 | */ | 2240 | */ |
| @@ -2030,6 +2266,8 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_ | |||
| 2030 | /* Found it - now remove it from the list of entries: */ | 2266 | /* Found it - now remove it from the list of entries: */ |
| 2031 | desc->action = NULL; | 2267 | desc->action = NULL; |
| 2032 | 2268 | ||
| 2269 | desc->istate &= ~IRQS_NMI; | ||
| 2270 | |||
| 2033 | raw_spin_unlock_irqrestore(&desc->lock, flags); | 2271 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 2034 | 2272 | ||
| 2035 | unregister_handler_proc(irq, action); | 2273 | unregister_handler_proc(irq, action); |
| @@ -2083,6 +2321,19 @@ void free_percpu_irq(unsigned int irq, void __percpu *dev_id) | |||
| 2083 | } | 2321 | } |
| 2084 | EXPORT_SYMBOL_GPL(free_percpu_irq); | 2322 | EXPORT_SYMBOL_GPL(free_percpu_irq); |
| 2085 | 2323 | ||
| 2324 | void free_percpu_nmi(unsigned int irq, void __percpu *dev_id) | ||
| 2325 | { | ||
| 2326 | struct irq_desc *desc = irq_to_desc(irq); | ||
| 2327 | |||
| 2328 | if (!desc || !irq_settings_is_per_cpu_devid(desc)) | ||
| 2329 | return; | ||
| 2330 | |||
| 2331 | if (WARN_ON(!(desc->istate & IRQS_NMI))) | ||
| 2332 | return; | ||
| 2333 | |||
| 2334 | kfree(__free_percpu_irq(irq, dev_id)); | ||
| 2335 | } | ||
| 2336 | |||
| 2086 | /** | 2337 | /** |
| 2087 | * setup_percpu_irq - setup a per-cpu interrupt | 2338 | * setup_percpu_irq - setup a per-cpu interrupt |
| 2088 | * @irq: Interrupt line to setup | 2339 | * @irq: Interrupt line to setup |
| @@ -2173,6 +2424,158 @@ int __request_percpu_irq(unsigned int irq, irq_handler_t handler, | |||
| 2173 | EXPORT_SYMBOL_GPL(__request_percpu_irq); | 2424 | EXPORT_SYMBOL_GPL(__request_percpu_irq); |
| 2174 | 2425 | ||
| 2175 | /** | 2426 | /** |
| 2427 | * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery | ||
| 2428 | * @irq: Interrupt line to allocate | ||
| 2429 | * @handler: Function to be called when the IRQ occurs. | ||
| 2430 | * @name: An ascii name for the claiming device | ||
| 2431 | * @dev_id: A percpu cookie passed back to the handler function | ||
| 2432 | * | ||
| 2433 | * This call allocates interrupt resources for a per CPU NMI. Per CPU NMIs | ||
| 2434 | * have to be setup on each CPU by calling prepare_percpu_nmi() before | ||
| 2435 | * being enabled on the same CPU by using enable_percpu_nmi(). | ||
| 2436 | * | ||
| 2437 | * Dev_id must be globally unique. It is a per-cpu variable, and | ||
| 2438 | * the handler gets called with the interrupted CPU's instance of | ||
| 2439 | * that variable. | ||
| 2440 | * | ||
| 2441 | * Interrupt lines requested for NMI delivering should have auto enabling | ||
| 2442 | * setting disabled. | ||
| 2443 | * | ||
| 2444 | * If the interrupt line cannot be used to deliver NMIs, function | ||
| 2445 | * will fail returning a negative value. | ||
| 2446 | */ | ||
| 2447 | int request_percpu_nmi(unsigned int irq, irq_handler_t handler, | ||
| 2448 | const char *name, void __percpu *dev_id) | ||
| 2449 | { | ||
| 2450 | struct irqaction *action; | ||
| 2451 | struct irq_desc *desc; | ||
| 2452 | unsigned long flags; | ||
| 2453 | int retval; | ||
| 2454 | |||
| 2455 | if (!handler) | ||
| 2456 | return -EINVAL; | ||
| 2457 | |||
| 2458 | desc = irq_to_desc(irq); | ||
| 2459 | |||
| 2460 | if (!desc || !irq_settings_can_request(desc) || | ||
| 2461 | !irq_settings_is_per_cpu_devid(desc) || | ||
| 2462 | irq_settings_can_autoenable(desc) || | ||
| 2463 | !irq_supports_nmi(desc)) | ||
| 2464 | return -EINVAL; | ||
| 2465 | |||
| 2466 | /* The line cannot already be NMI */ | ||
| 2467 | if (desc->istate & IRQS_NMI) | ||
| 2468 | return -EINVAL; | ||
| 2469 | |||
| 2470 | action = kzalloc(sizeof(struct irqaction), GFP_KERNEL); | ||
| 2471 | if (!action) | ||
| 2472 | return -ENOMEM; | ||
| 2473 | |||
| 2474 | action->handler = handler; | ||
| 2475 | action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD | ||
| 2476 | | IRQF_NOBALANCING; | ||
| 2477 | action->name = name; | ||
| 2478 | action->percpu_dev_id = dev_id; | ||
| 2479 | |||
| 2480 | retval = irq_chip_pm_get(&desc->irq_data); | ||
| 2481 | if (retval < 0) | ||
| 2482 | goto err_out; | ||
| 2483 | |||
| 2484 | retval = __setup_irq(irq, desc, action); | ||
| 2485 | if (retval) | ||
| 2486 | goto err_irq_setup; | ||
| 2487 | |||
| 2488 | raw_spin_lock_irqsave(&desc->lock, flags); | ||
| 2489 | desc->istate |= IRQS_NMI; | ||
| 2490 | raw_spin_unlock_irqrestore(&desc->lock, flags); | ||
| 2491 | |||
| 2492 | return 0; | ||
| 2493 | |||
| 2494 | err_irq_setup: | ||
| 2495 | irq_chip_pm_put(&desc->irq_data); | ||
| 2496 | err_out: | ||
| 2497 | kfree(action); | ||
| 2498 | |||
| 2499 | return retval; | ||
| 2500 | } | ||
| 2501 | |||
| 2502 | /** | ||
| 2503 | * prepare_percpu_nmi - performs CPU local setup for NMI delivery | ||
| 2504 | * @irq: Interrupt line to prepare for NMI delivery | ||
| 2505 | * | ||
| 2506 | * This call prepares an interrupt line to deliver NMI on the current CPU, | ||
| 2507 | * before that interrupt line gets enabled with enable_percpu_nmi(). | ||
| 2508 | * | ||
| 2509 | * As a CPU local operation, this should be called from non-preemptible | ||
| 2510 | * context. | ||
| 2511 | * | ||
| 2512 | * If the interrupt line cannot be used to deliver NMIs, function | ||
| 2513 | * will fail returning a negative value. | ||
| 2514 | */ | ||
| 2515 | int prepare_percpu_nmi(unsigned int irq) | ||
| 2516 | { | ||
| 2517 | unsigned long flags; | ||
| 2518 | struct irq_desc *desc; | ||
| 2519 | int ret = 0; | ||
| 2520 | |||
| 2521 | WARN_ON(preemptible()); | ||
| 2522 | |||
| 2523 | desc = irq_get_desc_lock(irq, &flags, | ||
| 2524 | IRQ_GET_DESC_CHECK_PERCPU); | ||
| 2525 | if (!desc) | ||
| 2526 | return -EINVAL; | ||
| 2527 | |||
| 2528 | if (WARN(!(desc->istate & IRQS_NMI), | ||
| 2529 | KERN_ERR "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", | ||
| 2530 | irq)) { | ||
| 2531 | ret = -EINVAL; | ||
| 2532 | goto out; | ||
| 2533 | } | ||
| 2534 | |||
| 2535 | ret = irq_nmi_setup(desc); | ||
| 2536 | if (ret) { | ||
| 2537 | pr_err("Failed to setup NMI delivery: irq %u\n", irq); | ||
| 2538 | goto out; | ||
| 2539 | } | ||
| 2540 | |||
| 2541 | out: | ||
| 2542 | irq_put_desc_unlock(desc, flags); | ||
| 2543 | return ret; | ||
| 2544 | } | ||
| 2545 | |||
| 2546 | /** | ||
| 2547 | * teardown_percpu_nmi - undoes NMI setup of IRQ line | ||
| 2548 | * @irq: Interrupt line from which CPU local NMI configuration should be | ||
| 2549 | * removed | ||
| 2550 | * | ||
| 2551 | * This call undoes the setup done by prepare_percpu_nmi(). | ||
| 2552 | * | ||
| 2553 | * IRQ line should not be enabled for the current CPU. | ||
| 2554 | * | ||
| 2555 | * As a CPU local operation, this should be called from non-preemptible | ||
| 2556 | * context. | ||
| 2557 | */ | ||
| 2558 | void teardown_percpu_nmi(unsigned int irq) | ||
| 2559 | { | ||
| 2560 | unsigned long flags; | ||
| 2561 | struct irq_desc *desc; | ||
| 2562 | |||
| 2563 | WARN_ON(preemptible()); | ||
| 2564 | |||
| 2565 | desc = irq_get_desc_lock(irq, &flags, | ||
| 2566 | IRQ_GET_DESC_CHECK_PERCPU); | ||
| 2567 | if (!desc) | ||
| 2568 | return; | ||
| 2569 | |||
| 2570 | if (WARN_ON(!(desc->istate & IRQS_NMI))) | ||
| 2571 | goto out; | ||
| 2572 | |||
| 2573 | irq_nmi_teardown(desc); | ||
| 2574 | out: | ||
| 2575 | irq_put_desc_unlock(desc, flags); | ||
| 2576 | } | ||
| 2577 | |||
| 2578 | /** | ||
| 2176 | * irq_get_irqchip_state - returns the irqchip state of a interrupt. | 2579 | * irq_get_irqchip_state - returns the irqchip state of a interrupt. |
| 2177 | * @irq: Interrupt line that is forwarded to a VM | 2580 | * @irq: Interrupt line that is forwarded to a VM |
| 2178 | * @which: One of IRQCHIP_STATE_* the caller wants to know about | 2581 | * @which: One of IRQCHIP_STATE_* the caller wants to know about |
