Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/irq/chip.c |
| 3 | * |
| 4 | * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar |
| 5 | * Copyright (C) 2005-2006, Thomas Gleixner, Russell King |
| 6 | * |
| 7 | * This file contains the core interrupt handling code, for irq-chip |
| 8 | * based architectures. |
| 9 | * |
| 10 | * Detailed information is available in Documentation/DocBook/genericirq |
| 11 | */ |
| 12 | |
| 13 | #include <linux/irq.h> |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 14 | #include <linux/msi.h> |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/kernel_stat.h> |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 18 | #include <linux/irqdomain.h> |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 19 | |
Steven Rostedt | f069686 | 2012-01-25 20:18:55 -0500 | [diff] [blame] | 20 | #include <trace/events/irq.h> |
| 21 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 22 | #include "internals.h" |
| 23 | |
Eric W. Biederman | 3a16d71 | 2006-10-04 02:16:37 -0700 | [diff] [blame] | 24 | /** |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 25 | * irq_set_chip - set the irq chip for an irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 26 | * @irq: irq number |
| 27 | * @chip: pointer to irq chip description structure |
| 28 | */ |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 29 | int irq_set_chip(unsigned int irq, struct irq_chip *chip) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 30 | { |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 31 | unsigned long flags; |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 32 | struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 33 | |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 34 | if (!desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 35 | return -EINVAL; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 36 | |
| 37 | if (!chip) |
| 38 | chip = &no_irq_chip; |
| 39 | |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 40 | desc->irq_data.chip = chip; |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 41 | irq_put_desc_unlock(desc, flags); |
David Daney | d72274e | 2011-03-25 12:38:48 -0700 | [diff] [blame] | 42 | /* |
| 43 | * For !CONFIG_SPARSE_IRQ make the irq show up in |
Thomas Gleixner | f63b6a0 | 2014-05-07 15:44:21 +0000 | [diff] [blame] | 44 | * allocated_irqs. |
David Daney | d72274e | 2011-03-25 12:38:48 -0700 | [diff] [blame] | 45 | */ |
Thomas Gleixner | f63b6a0 | 2014-05-07 15:44:21 +0000 | [diff] [blame] | 46 | irq_mark_irq(irq); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 47 | return 0; |
| 48 | } |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 49 | EXPORT_SYMBOL(irq_set_chip); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 52 | * irq_set_type - set the irq trigger type for an irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 53 | * @irq: irq number |
David Brownell | 0c5d1eb | 2008-10-01 14:46:18 -0700 | [diff] [blame] | 54 | * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 55 | */ |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 56 | int irq_set_irq_type(unsigned int irq, unsigned int type) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 57 | { |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 58 | unsigned long flags; |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 59 | struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL); |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 60 | int ret = 0; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 61 | |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 62 | if (!desc) |
| 63 | return -EINVAL; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 64 | |
David Brownell | f2b662d | 2008-12-01 14:31:38 -0800 | [diff] [blame] | 65 | type &= IRQ_TYPE_SENSE_MASK; |
Russell King | a09b659 | 2012-03-05 15:07:25 -0800 | [diff] [blame] | 66 | ret = __irq_set_trigger(desc, irq, type); |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 67 | irq_put_desc_busunlock(desc, flags); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 68 | return ret; |
| 69 | } |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 70 | EXPORT_SYMBOL(irq_set_irq_type); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 73 | * irq_set_handler_data - set irq handler data for an irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 74 | * @irq: Interrupt number |
| 75 | * @data: Pointer to interrupt specific data |
| 76 | * |
| 77 | * Set the hardware irq controller data for an irq |
| 78 | */ |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 79 | int irq_set_handler_data(unsigned int irq, void *data) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 80 | { |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 81 | unsigned long flags; |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 82 | struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 83 | |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 84 | if (!desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 85 | return -EINVAL; |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 86 | desc->irq_data.handler_data = data; |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 87 | irq_put_desc_unlock(desc, flags); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 90 | EXPORT_SYMBOL(irq_set_handler_data); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Alexander Gordeev | 51906e7 | 2012-11-19 16:01:29 +0100 | [diff] [blame] | 93 | * irq_set_msi_desc_off - set MSI descriptor data for an irq at offset |
| 94 | * @irq_base: Interrupt number base |
| 95 | * @irq_offset: Interrupt number offset |
| 96 | * @entry: Pointer to MSI descriptor data |
| 97 | * |
| 98 | * Set the MSI descriptor entry for an irq at offset |
| 99 | */ |
| 100 | int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset, |
| 101 | struct msi_desc *entry) |
| 102 | { |
| 103 | unsigned long flags; |
| 104 | struct irq_desc *desc = irq_get_desc_lock(irq_base + irq_offset, &flags, IRQ_GET_DESC_CHECK_GLOBAL); |
| 105 | |
| 106 | if (!desc) |
| 107 | return -EINVAL; |
| 108 | desc->irq_data.msi_desc = entry; |
| 109 | if (entry && !irq_offset) |
| 110 | entry->irq = irq_base; |
| 111 | irq_put_desc_unlock(desc, flags); |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /** |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 116 | * irq_set_msi_desc - set MSI descriptor data for an irq |
Eric W. Biederman | 5b912c1 | 2007-01-28 12:52:03 -0700 | [diff] [blame] | 117 | * @irq: Interrupt number |
Randy Dunlap | 472900b | 2007-02-16 01:28:25 -0800 | [diff] [blame] | 118 | * @entry: Pointer to MSI descriptor data |
Eric W. Biederman | 5b912c1 | 2007-01-28 12:52:03 -0700 | [diff] [blame] | 119 | * |
Liuweni | 24b26d4 | 2009-11-04 20:11:05 +0800 | [diff] [blame] | 120 | * Set the MSI descriptor entry for an irq |
Eric W. Biederman | 5b912c1 | 2007-01-28 12:52:03 -0700 | [diff] [blame] | 121 | */ |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 122 | int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry) |
Eric W. Biederman | 5b912c1 | 2007-01-28 12:52:03 -0700 | [diff] [blame] | 123 | { |
Alexander Gordeev | 51906e7 | 2012-11-19 16:01:29 +0100 | [diff] [blame] | 124 | return irq_set_msi_desc_off(irq, 0, entry); |
Eric W. Biederman | 5b912c1 | 2007-01-28 12:52:03 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 128 | * irq_set_chip_data - set irq chip data for an irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 129 | * @irq: Interrupt number |
| 130 | * @data: Pointer to chip specific data |
| 131 | * |
| 132 | * Set the hardware irq chip data for an irq |
| 133 | */ |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 134 | int irq_set_chip_data(unsigned int irq, void *data) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 135 | { |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 136 | unsigned long flags; |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 137 | struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 138 | |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 139 | if (!desc) |
Yinghai Lu | 7d94f7c | 2008-08-19 20:50:14 -0700 | [diff] [blame] | 140 | return -EINVAL; |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 141 | desc->irq_data.chip_data = data; |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 142 | irq_put_desc_unlock(desc, flags); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 143 | return 0; |
| 144 | } |
Thomas Gleixner | a0cd9ca | 2011-02-10 11:36:33 +0100 | [diff] [blame] | 145 | EXPORT_SYMBOL(irq_set_chip_data); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 146 | |
Thomas Gleixner | f303a6d | 2010-09-28 17:34:01 +0200 | [diff] [blame] | 147 | struct irq_data *irq_get_irq_data(unsigned int irq) |
| 148 | { |
| 149 | struct irq_desc *desc = irq_to_desc(irq); |
| 150 | |
| 151 | return desc ? &desc->irq_data : NULL; |
| 152 | } |
| 153 | EXPORT_SYMBOL_GPL(irq_get_irq_data); |
| 154 | |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 155 | static void irq_state_clr_disabled(struct irq_desc *desc) |
| 156 | { |
Thomas Gleixner | 801a0e9 | 2011-03-27 11:02:49 +0200 | [diff] [blame] | 157 | irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED); |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static void irq_state_set_disabled(struct irq_desc *desc) |
| 161 | { |
Thomas Gleixner | 801a0e9 | 2011-03-27 11:02:49 +0200 | [diff] [blame] | 162 | irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED); |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 165 | static void irq_state_clr_masked(struct irq_desc *desc) |
| 166 | { |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 167 | irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED); |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static void irq_state_set_masked(struct irq_desc *desc) |
| 171 | { |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 172 | irqd_set(&desc->irq_data, IRQD_IRQ_MASKED); |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Thomas Gleixner | b4bc724 | 2012-02-08 11:57:52 +0100 | [diff] [blame] | 175 | int irq_startup(struct irq_desc *desc, bool resend) |
Thomas Gleixner | 4699923 | 2011-02-02 21:41:14 +0000 | [diff] [blame] | 176 | { |
Thomas Gleixner | b4bc724 | 2012-02-08 11:57:52 +0100 | [diff] [blame] | 177 | int ret = 0; |
| 178 | |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 179 | irq_state_clr_disabled(desc); |
Thomas Gleixner | 4699923 | 2011-02-02 21:41:14 +0000 | [diff] [blame] | 180 | desc->depth = 0; |
| 181 | |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 182 | irq_domain_activate_irq(&desc->irq_data); |
Thomas Gleixner | 3aae994 | 2011-02-04 10:17:52 +0100 | [diff] [blame] | 183 | if (desc->irq_data.chip->irq_startup) { |
Thomas Gleixner | b4bc724 | 2012-02-08 11:57:52 +0100 | [diff] [blame] | 184 | ret = desc->irq_data.chip->irq_startup(&desc->irq_data); |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 185 | irq_state_clr_masked(desc); |
Thomas Gleixner | b4bc724 | 2012-02-08 11:57:52 +0100 | [diff] [blame] | 186 | } else { |
| 187 | irq_enable(desc); |
Thomas Gleixner | 3aae994 | 2011-02-04 10:17:52 +0100 | [diff] [blame] | 188 | } |
Thomas Gleixner | b4bc724 | 2012-02-08 11:57:52 +0100 | [diff] [blame] | 189 | if (resend) |
| 190 | check_irq_resend(desc, desc->irq_data.irq); |
| 191 | return ret; |
Thomas Gleixner | 4699923 | 2011-02-02 21:41:14 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void irq_shutdown(struct irq_desc *desc) |
| 195 | { |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 196 | irq_state_set_disabled(desc); |
Thomas Gleixner | 4699923 | 2011-02-02 21:41:14 +0000 | [diff] [blame] | 197 | desc->depth = 1; |
Thomas Gleixner | 50f7c03 | 2011-02-03 13:23:54 +0100 | [diff] [blame] | 198 | if (desc->irq_data.chip->irq_shutdown) |
| 199 | desc->irq_data.chip->irq_shutdown(&desc->irq_data); |
Geert Uytterhoeven | ed585a6 | 2011-09-11 13:59:27 +0200 | [diff] [blame] | 200 | else if (desc->irq_data.chip->irq_disable) |
Thomas Gleixner | 50f7c03 | 2011-02-03 13:23:54 +0100 | [diff] [blame] | 201 | desc->irq_data.chip->irq_disable(&desc->irq_data); |
| 202 | else |
| 203 | desc->irq_data.chip->irq_mask(&desc->irq_data); |
Jiang Liu | f8264e3 | 2014-11-06 22:20:14 +0800 | [diff] [blame] | 204 | irq_domain_deactivate_irq(&desc->irq_data); |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 205 | irq_state_set_masked(desc); |
Thomas Gleixner | 4699923 | 2011-02-02 21:41:14 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Thomas Gleixner | 8792347 | 2011-02-03 12:27:44 +0100 | [diff] [blame] | 208 | void irq_enable(struct irq_desc *desc) |
| 209 | { |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 210 | irq_state_clr_disabled(desc); |
Thomas Gleixner | 50f7c03 | 2011-02-03 13:23:54 +0100 | [diff] [blame] | 211 | if (desc->irq_data.chip->irq_enable) |
| 212 | desc->irq_data.chip->irq_enable(&desc->irq_data); |
| 213 | else |
| 214 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 215 | irq_state_clr_masked(desc); |
Thomas Gleixner | 8792347 | 2011-02-03 12:27:44 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Andreas Fenkart | d671a60 | 2013-05-10 12:21:30 +0200 | [diff] [blame] | 218 | /** |
Xie XiuQi | f788e7b | 2013-10-18 09:12:04 +0800 | [diff] [blame] | 219 | * irq_disable - Mark interrupt disabled |
Andreas Fenkart | d671a60 | 2013-05-10 12:21:30 +0200 | [diff] [blame] | 220 | * @desc: irq descriptor which should be disabled |
| 221 | * |
| 222 | * If the chip does not implement the irq_disable callback, we |
| 223 | * use a lazy disable approach. That means we mark the interrupt |
| 224 | * disabled, but leave the hardware unmasked. That's an |
| 225 | * optimization because we avoid the hardware access for the |
| 226 | * common case where no interrupt happens after we marked it |
| 227 | * disabled. If an interrupt happens, then the interrupt flow |
| 228 | * handler masks the line at the hardware level and marks it |
| 229 | * pending. |
| 230 | */ |
Thomas Gleixner | 8792347 | 2011-02-03 12:27:44 +0100 | [diff] [blame] | 231 | void irq_disable(struct irq_desc *desc) |
| 232 | { |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 233 | irq_state_set_disabled(desc); |
Thomas Gleixner | 50f7c03 | 2011-02-03 13:23:54 +0100 | [diff] [blame] | 234 | if (desc->irq_data.chip->irq_disable) { |
| 235 | desc->irq_data.chip->irq_disable(&desc->irq_data); |
Thomas Gleixner | a61d825 | 2011-02-21 12:54:34 +0100 | [diff] [blame] | 236 | irq_state_set_masked(desc); |
Thomas Gleixner | 50f7c03 | 2011-02-03 13:23:54 +0100 | [diff] [blame] | 237 | } |
Thomas Gleixner | 89d694b | 2008-02-18 18:25:17 +0100 | [diff] [blame] | 238 | } |
| 239 | |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 240 | void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu) |
| 241 | { |
| 242 | if (desc->irq_data.chip->irq_enable) |
| 243 | desc->irq_data.chip->irq_enable(&desc->irq_data); |
| 244 | else |
| 245 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
| 246 | cpumask_set_cpu(cpu, desc->percpu_enabled); |
| 247 | } |
| 248 | |
| 249 | void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu) |
| 250 | { |
| 251 | if (desc->irq_data.chip->irq_disable) |
| 252 | desc->irq_data.chip->irq_disable(&desc->irq_data); |
| 253 | else |
| 254 | desc->irq_data.chip->irq_mask(&desc->irq_data); |
| 255 | cpumask_clear_cpu(cpu, desc->percpu_enabled); |
| 256 | } |
| 257 | |
Thomas Gleixner | 9205e31 | 2010-09-27 12:44:50 +0000 | [diff] [blame] | 258 | static inline void mask_ack_irq(struct irq_desc *desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 259 | { |
Thomas Gleixner | 9205e31 | 2010-09-27 12:44:50 +0000 | [diff] [blame] | 260 | if (desc->irq_data.chip->irq_mask_ack) |
| 261 | desc->irq_data.chip->irq_mask_ack(&desc->irq_data); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 262 | else { |
Thomas Gleixner | e2c0f8f | 2010-09-27 12:44:42 +0000 | [diff] [blame] | 263 | desc->irq_data.chip->irq_mask(&desc->irq_data); |
Thomas Gleixner | 22a4916 | 2010-09-27 12:44:47 +0000 | [diff] [blame] | 264 | if (desc->irq_data.chip->irq_ack) |
| 265 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 266 | } |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 267 | irq_state_set_masked(desc); |
Thomas Gleixner | 0b1adaa | 2010-03-09 19:45:54 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Thomas Gleixner | d4d5e08 | 2011-02-10 13:16:14 +0100 | [diff] [blame] | 270 | void mask_irq(struct irq_desc *desc) |
Thomas Gleixner | 0b1adaa | 2010-03-09 19:45:54 +0100 | [diff] [blame] | 271 | { |
Thomas Gleixner | e2c0f8f | 2010-09-27 12:44:42 +0000 | [diff] [blame] | 272 | if (desc->irq_data.chip->irq_mask) { |
| 273 | desc->irq_data.chip->irq_mask(&desc->irq_data); |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 274 | irq_state_set_masked(desc); |
Thomas Gleixner | 0b1adaa | 2010-03-09 19:45:54 +0100 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Thomas Gleixner | d4d5e08 | 2011-02-10 13:16:14 +0100 | [diff] [blame] | 278 | void unmask_irq(struct irq_desc *desc) |
Thomas Gleixner | 0b1adaa | 2010-03-09 19:45:54 +0100 | [diff] [blame] | 279 | { |
Thomas Gleixner | 0eda58b | 2010-09-27 12:44:44 +0000 | [diff] [blame] | 280 | if (desc->irq_data.chip->irq_unmask) { |
| 281 | desc->irq_data.chip->irq_unmask(&desc->irq_data); |
Thomas Gleixner | 6e40262 | 2011-02-08 12:36:06 +0100 | [diff] [blame] | 282 | irq_state_clr_masked(desc); |
Thomas Gleixner | 0b1adaa | 2010-03-09 19:45:54 +0100 | [diff] [blame] | 283 | } |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Thomas Gleixner | 328a497 | 2014-03-13 19:03:51 +0100 | [diff] [blame] | 286 | void unmask_threaded_irq(struct irq_desc *desc) |
| 287 | { |
| 288 | struct irq_chip *chip = desc->irq_data.chip; |
| 289 | |
| 290 | if (chip->flags & IRQCHIP_EOI_THREADED) |
| 291 | chip->irq_eoi(&desc->irq_data); |
| 292 | |
| 293 | if (chip->irq_unmask) { |
| 294 | chip->irq_unmask(&desc->irq_data); |
| 295 | irq_state_clr_masked(desc); |
| 296 | } |
| 297 | } |
| 298 | |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 299 | /* |
| 300 | * handle_nested_irq - Handle a nested irq from a irq thread |
| 301 | * @irq: the interrupt number |
| 302 | * |
| 303 | * Handle interrupts which are nested into a threaded interrupt |
| 304 | * handler. The handler function is called inside the calling |
| 305 | * threads context. |
| 306 | */ |
| 307 | void handle_nested_irq(unsigned int irq) |
| 308 | { |
| 309 | struct irq_desc *desc = irq_to_desc(irq); |
| 310 | struct irqaction *action; |
| 311 | irqreturn_t action_ret; |
| 312 | |
| 313 | might_sleep(); |
| 314 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 315 | raw_spin_lock_irq(&desc->lock); |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 316 | |
Thomas Gleixner | 293a7a0 | 2012-10-16 15:07:49 -0700 | [diff] [blame] | 317 | desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING); |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 318 | kstat_incr_irqs_this_cpu(irq, desc); |
| 319 | |
| 320 | action = desc->action; |
Ning Jiang | 23812b9 | 2012-05-22 00:19:20 +0800 | [diff] [blame] | 321 | if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) { |
| 322 | desc->istate |= IRQS_PENDING; |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 323 | goto out_unlock; |
Ning Jiang | 23812b9 | 2012-05-22 00:19:20 +0800 | [diff] [blame] | 324 | } |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 325 | |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 326 | irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS); |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 327 | raw_spin_unlock_irq(&desc->lock); |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 328 | |
| 329 | action_ret = action->thread_fn(action->irq, action->dev_id); |
| 330 | if (!noirqdebug) |
| 331 | note_interrupt(irq, desc, action_ret); |
| 332 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 333 | raw_spin_lock_irq(&desc->lock); |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 334 | irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 335 | |
| 336 | out_unlock: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 337 | raw_spin_unlock_irq(&desc->lock); |
Thomas Gleixner | 399b5da | 2009-08-13 13:21:38 +0200 | [diff] [blame] | 338 | } |
| 339 | EXPORT_SYMBOL_GPL(handle_nested_irq); |
| 340 | |
Thomas Gleixner | fe200ae | 2011-02-07 10:34:30 +0100 | [diff] [blame] | 341 | static bool irq_check_poll(struct irq_desc *desc) |
| 342 | { |
Thomas Gleixner | 6954b75 | 2011-02-07 20:55:35 +0100 | [diff] [blame] | 343 | if (!(desc->istate & IRQS_POLL_INPROGRESS)) |
Thomas Gleixner | fe200ae | 2011-02-07 10:34:30 +0100 | [diff] [blame] | 344 | return false; |
| 345 | return irq_wait_for_poll(desc); |
| 346 | } |
| 347 | |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 348 | static bool irq_may_run(struct irq_desc *desc) |
| 349 | { |
Thomas Gleixner | 9ce7a25 | 2014-08-29 14:00:16 +0200 | [diff] [blame] | 350 | unsigned int mask = IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED; |
| 351 | |
| 352 | /* |
| 353 | * If the interrupt is not in progress and is not an armed |
| 354 | * wakeup interrupt, proceed. |
| 355 | */ |
| 356 | if (!irqd_has_set(&desc->irq_data, mask)) |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 357 | return true; |
Thomas Gleixner | 9ce7a25 | 2014-08-29 14:00:16 +0200 | [diff] [blame] | 358 | |
| 359 | /* |
| 360 | * If the interrupt is an armed wakeup source, mark it pending |
| 361 | * and suspended, disable it and notify the pm core about the |
| 362 | * event. |
| 363 | */ |
| 364 | if (irq_pm_check_wakeup(desc)) |
| 365 | return false; |
| 366 | |
| 367 | /* |
| 368 | * Handle a potential concurrent poll on a different core. |
| 369 | */ |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 370 | return irq_check_poll(desc); |
| 371 | } |
| 372 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 373 | /** |
| 374 | * handle_simple_irq - Simple and software-decoded IRQs. |
| 375 | * @irq: the interrupt number |
| 376 | * @desc: the interrupt description structure for this irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 377 | * |
| 378 | * Simple interrupts are either sent from a demultiplexing interrupt |
| 379 | * handler or come from hardware, where no interrupt hardware control |
| 380 | * is necessary. |
| 381 | * |
| 382 | * Note: The caller is expected to handle the ack, clear, mask and |
| 383 | * unmask issues if necessary. |
| 384 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 385 | void |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 386 | handle_simple_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 387 | { |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 388 | raw_spin_lock(&desc->lock); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 389 | |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 390 | if (!irq_may_run(desc)) |
| 391 | goto out_unlock; |
Thomas Gleixner | fe200ae | 2011-02-07 10:34:30 +0100 | [diff] [blame] | 392 | |
Thomas Gleixner | 163ef30 | 2011-02-08 11:39:15 +0100 | [diff] [blame] | 393 | desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 394 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 395 | |
Ning Jiang | 23812b9 | 2012-05-22 00:19:20 +0800 | [diff] [blame] | 396 | if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) { |
| 397 | desc->istate |= IRQS_PENDING; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 398 | goto out_unlock; |
Ning Jiang | 23812b9 | 2012-05-22 00:19:20 +0800 | [diff] [blame] | 399 | } |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 400 | |
Thomas Gleixner | 107781e | 2011-02-07 01:21:02 +0100 | [diff] [blame] | 401 | handle_irq_event(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 402 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 403 | out_unlock: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 404 | raw_spin_unlock(&desc->lock); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 405 | } |
Jonathan Cameron | edf76f8 | 2011-05-18 10:39:04 +0100 | [diff] [blame] | 406 | EXPORT_SYMBOL_GPL(handle_simple_irq); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 407 | |
Thomas Gleixner | ac56376 | 2012-02-07 17:58:03 +0100 | [diff] [blame] | 408 | /* |
| 409 | * Called unconditionally from handle_level_irq() and only for oneshot |
| 410 | * interrupts from handle_fasteoi_irq() |
| 411 | */ |
| 412 | static void cond_unmask_irq(struct irq_desc *desc) |
| 413 | { |
| 414 | /* |
| 415 | * We need to unmask in the following cases: |
| 416 | * - Standard level irq (IRQF_ONESHOT is not set) |
| 417 | * - Oneshot irq which did not wake the thread (caused by a |
| 418 | * spurious interrupt or a primary handler handling it |
| 419 | * completely). |
| 420 | */ |
| 421 | if (!irqd_irq_disabled(&desc->irq_data) && |
| 422 | irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) |
| 423 | unmask_irq(desc); |
| 424 | } |
| 425 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 426 | /** |
| 427 | * handle_level_irq - Level type irq handler |
| 428 | * @irq: the interrupt number |
| 429 | * @desc: the interrupt description structure for this irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 430 | * |
| 431 | * Level type interrupts are active as long as the hardware line has |
| 432 | * the active level. This may require to mask the interrupt and unmask |
| 433 | * it after the associated handler has acknowledged the device, so the |
| 434 | * interrupt line is back to inactive. |
| 435 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 436 | void |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 437 | handle_level_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 438 | { |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 439 | raw_spin_lock(&desc->lock); |
Thomas Gleixner | 9205e31 | 2010-09-27 12:44:50 +0000 | [diff] [blame] | 440 | mask_ack_irq(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 441 | |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 442 | if (!irq_may_run(desc)) |
| 443 | goto out_unlock; |
Thomas Gleixner | fe200ae | 2011-02-07 10:34:30 +0100 | [diff] [blame] | 444 | |
Thomas Gleixner | 163ef30 | 2011-02-08 11:39:15 +0100 | [diff] [blame] | 445 | desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 446 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 447 | |
| 448 | /* |
| 449 | * If its disabled or no action available |
| 450 | * keep it masked and get out of here |
| 451 | */ |
Thomas Gleixner | d4dc0f9 | 2012-04-25 12:54:54 +0200 | [diff] [blame] | 452 | if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) { |
| 453 | desc->istate |= IRQS_PENDING; |
Ingo Molnar | 86998aa | 2006-09-19 11:14:34 +0200 | [diff] [blame] | 454 | goto out_unlock; |
Thomas Gleixner | d4dc0f9 | 2012-04-25 12:54:54 +0200 | [diff] [blame] | 455 | } |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 456 | |
Thomas Gleixner | 1529866 | 2011-02-07 01:22:17 +0100 | [diff] [blame] | 457 | handle_irq_event(desc); |
Thomas Gleixner | b25c340 | 2009-08-13 12:17:22 +0200 | [diff] [blame] | 458 | |
Thomas Gleixner | ac56376 | 2012-02-07 17:58:03 +0100 | [diff] [blame] | 459 | cond_unmask_irq(desc); |
| 460 | |
Ingo Molnar | 86998aa | 2006-09-19 11:14:34 +0200 | [diff] [blame] | 461 | out_unlock: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 462 | raw_spin_unlock(&desc->lock); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 463 | } |
Ingo Molnar | 14819ea | 2009-01-14 12:34:21 +0100 | [diff] [blame] | 464 | EXPORT_SYMBOL_GPL(handle_level_irq); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 465 | |
Thomas Gleixner | 7812957 | 2011-02-10 15:14:20 +0100 | [diff] [blame] | 466 | #ifdef CONFIG_IRQ_PREFLOW_FASTEOI |
| 467 | static inline void preflow_handler(struct irq_desc *desc) |
| 468 | { |
| 469 | if (desc->preflow_handler) |
| 470 | desc->preflow_handler(&desc->irq_data); |
| 471 | } |
| 472 | #else |
| 473 | static inline void preflow_handler(struct irq_desc *desc) { } |
| 474 | #endif |
| 475 | |
Thomas Gleixner | 328a497 | 2014-03-13 19:03:51 +0100 | [diff] [blame] | 476 | static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip) |
| 477 | { |
| 478 | if (!(desc->istate & IRQS_ONESHOT)) { |
| 479 | chip->irq_eoi(&desc->irq_data); |
| 480 | return; |
| 481 | } |
| 482 | /* |
| 483 | * We need to unmask in the following cases: |
| 484 | * - Oneshot irq which did not wake the thread (caused by a |
| 485 | * spurious interrupt or a primary handler handling it |
| 486 | * completely). |
| 487 | */ |
| 488 | if (!irqd_irq_disabled(&desc->irq_data) && |
| 489 | irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) { |
| 490 | chip->irq_eoi(&desc->irq_data); |
| 491 | unmask_irq(desc); |
| 492 | } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) { |
| 493 | chip->irq_eoi(&desc->irq_data); |
| 494 | } |
| 495 | } |
| 496 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 497 | /** |
Ingo Molnar | 47c2a3a | 2006-06-29 02:25:03 -0700 | [diff] [blame] | 498 | * handle_fasteoi_irq - irq handler for transparent controllers |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 499 | * @irq: the interrupt number |
| 500 | * @desc: the interrupt description structure for this irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 501 | * |
Ingo Molnar | 47c2a3a | 2006-06-29 02:25:03 -0700 | [diff] [blame] | 502 | * Only a single callback will be issued to the chip: an ->eoi() |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 503 | * call when the interrupt has been serviced. This enables support |
| 504 | * for modern forms of interrupt handlers, which handle the flow |
| 505 | * details in hardware, transparently. |
| 506 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 507 | void |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 508 | handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 509 | { |
Thomas Gleixner | 328a497 | 2014-03-13 19:03:51 +0100 | [diff] [blame] | 510 | struct irq_chip *chip = desc->irq_data.chip; |
| 511 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 512 | raw_spin_lock(&desc->lock); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 513 | |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 514 | if (!irq_may_run(desc)) |
| 515 | goto out; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 516 | |
Thomas Gleixner | 163ef30 | 2011-02-08 11:39:15 +0100 | [diff] [blame] | 517 | desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 518 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 519 | |
| 520 | /* |
| 521 | * If its disabled or no action available |
Ingo Molnar | 76d2160 | 2007-02-16 01:28:24 -0800 | [diff] [blame] | 522 | * then mask it and get out of here: |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 523 | */ |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 524 | if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) { |
Thomas Gleixner | 2a0d6fb | 2011-02-08 12:17:57 +0100 | [diff] [blame] | 525 | desc->istate |= IRQS_PENDING; |
Thomas Gleixner | e2c0f8f | 2010-09-27 12:44:42 +0000 | [diff] [blame] | 526 | mask_irq(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 527 | goto out; |
Benjamin Herrenschmidt | 98bb244 | 2006-06-29 02:25:01 -0700 | [diff] [blame] | 528 | } |
Thomas Gleixner | c69e375 | 2011-03-02 11:49:21 +0100 | [diff] [blame] | 529 | |
| 530 | if (desc->istate & IRQS_ONESHOT) |
| 531 | mask_irq(desc); |
| 532 | |
Thomas Gleixner | 7812957 | 2011-02-10 15:14:20 +0100 | [diff] [blame] | 533 | preflow_handler(desc); |
Thomas Gleixner | a7ae4de | 2011-02-07 01:23:07 +0100 | [diff] [blame] | 534 | handle_irq_event(desc); |
Thomas Gleixner | 77694b4 | 2011-02-15 10:33:57 +0100 | [diff] [blame] | 535 | |
Thomas Gleixner | 328a497 | 2014-03-13 19:03:51 +0100 | [diff] [blame] | 536 | cond_unmask_eoi_irq(desc, chip); |
Thomas Gleixner | ac56376 | 2012-02-07 17:58:03 +0100 | [diff] [blame] | 537 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 538 | raw_spin_unlock(&desc->lock); |
Thomas Gleixner | 77694b4 | 2011-02-15 10:33:57 +0100 | [diff] [blame] | 539 | return; |
| 540 | out: |
Thomas Gleixner | 328a497 | 2014-03-13 19:03:51 +0100 | [diff] [blame] | 541 | if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED)) |
| 542 | chip->irq_eoi(&desc->irq_data); |
| 543 | raw_spin_unlock(&desc->lock); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 544 | } |
Vincent Stehlé | 7cad45e | 2014-08-22 01:31:20 +0200 | [diff] [blame] | 545 | EXPORT_SYMBOL_GPL(handle_fasteoi_irq); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 546 | |
| 547 | /** |
| 548 | * handle_edge_irq - edge type IRQ handler |
| 549 | * @irq: the interrupt number |
| 550 | * @desc: the interrupt description structure for this irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 551 | * |
| 552 | * Interrupt occures on the falling and/or rising edge of a hardware |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 553 | * signal. The occurrence is latched into the irq controller hardware |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 554 | * and must be acked in order to be reenabled. After the ack another |
| 555 | * interrupt can happen on the same source even before the first one |
Uwe Kleine-König | dfff061 | 2010-02-12 21:58:11 +0100 | [diff] [blame] | 556 | * is handled by the associated event handler. If this happens it |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 557 | * might be necessary to disable (mask) the interrupt depending on the |
| 558 | * controller hardware. This requires to reenable the interrupt inside |
| 559 | * of the loop which handles the interrupts which have arrived while |
| 560 | * the handler was running. If all pending interrupts are handled, the |
| 561 | * loop is left. |
| 562 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 563 | void |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 564 | handle_edge_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 565 | { |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 566 | raw_spin_lock(&desc->lock); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 567 | |
Thomas Gleixner | 163ef30 | 2011-02-08 11:39:15 +0100 | [diff] [blame] | 568 | desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING); |
Thomas Gleixner | c3d7acd | 2014-08-29 13:46:08 +0200 | [diff] [blame] | 569 | |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 570 | if (!irq_may_run(desc)) { |
| 571 | desc->istate |= IRQS_PENDING; |
| 572 | mask_ack_irq(desc); |
| 573 | goto out_unlock; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 574 | } |
Thomas Gleixner | c3d7acd | 2014-08-29 13:46:08 +0200 | [diff] [blame] | 575 | |
| 576 | /* |
| 577 | * If its disabled or no action available then mask it and get |
| 578 | * out of here. |
| 579 | */ |
| 580 | if (irqd_irq_disabled(&desc->irq_data) || !desc->action) { |
| 581 | desc->istate |= IRQS_PENDING; |
| 582 | mask_ack_irq(desc); |
| 583 | goto out_unlock; |
| 584 | } |
| 585 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 586 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 587 | |
| 588 | /* Start handling the irq */ |
Thomas Gleixner | 22a4916 | 2010-09-27 12:44:47 +0000 | [diff] [blame] | 589 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 590 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 591 | do { |
Thomas Gleixner | a60a5dc | 2011-02-07 01:24:07 +0100 | [diff] [blame] | 592 | if (unlikely(!desc->action)) { |
Thomas Gleixner | e2c0f8f | 2010-09-27 12:44:42 +0000 | [diff] [blame] | 593 | mask_irq(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 594 | goto out_unlock; |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * When another irq arrived while we were handling |
| 599 | * one, we could have masked the irq. |
| 600 | * Renable it, if it was not disabled in meantime. |
| 601 | */ |
Thomas Gleixner | 2a0d6fb | 2011-02-08 12:17:57 +0100 | [diff] [blame] | 602 | if (unlikely(desc->istate & IRQS_PENDING)) { |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 603 | if (!irqd_irq_disabled(&desc->irq_data) && |
| 604 | irqd_irq_masked(&desc->irq_data)) |
Thomas Gleixner | c1594b7 | 2011-02-07 22:11:30 +0100 | [diff] [blame] | 605 | unmask_irq(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Thomas Gleixner | a60a5dc | 2011-02-07 01:24:07 +0100 | [diff] [blame] | 608 | handle_irq_event(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 609 | |
Thomas Gleixner | 2a0d6fb | 2011-02-08 12:17:57 +0100 | [diff] [blame] | 610 | } while ((desc->istate & IRQS_PENDING) && |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 611 | !irqd_irq_disabled(&desc->irq_data)); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 612 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 613 | out_unlock: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 614 | raw_spin_unlock(&desc->lock); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 615 | } |
Jiri Kosina | 3911ff3 | 2012-05-13 12:13:15 +0200 | [diff] [blame] | 616 | EXPORT_SYMBOL(handle_edge_irq); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 617 | |
Thomas Gleixner | 0521c8f | 2011-03-28 16:13:24 +0200 | [diff] [blame] | 618 | #ifdef CONFIG_IRQ_EDGE_EOI_HANDLER |
| 619 | /** |
| 620 | * handle_edge_eoi_irq - edge eoi type IRQ handler |
| 621 | * @irq: the interrupt number |
| 622 | * @desc: the interrupt description structure for this irq |
| 623 | * |
| 624 | * Similar as the above handle_edge_irq, but using eoi and w/o the |
| 625 | * mask/unmask logic. |
| 626 | */ |
| 627 | void handle_edge_eoi_irq(unsigned int irq, struct irq_desc *desc) |
| 628 | { |
| 629 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 630 | |
| 631 | raw_spin_lock(&desc->lock); |
| 632 | |
| 633 | desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING); |
Thomas Gleixner | c3d7acd | 2014-08-29 13:46:08 +0200 | [diff] [blame] | 634 | |
Thomas Gleixner | c7bd3ec0 | 2014-08-29 13:39:37 +0200 | [diff] [blame] | 635 | if (!irq_may_run(desc)) { |
| 636 | desc->istate |= IRQS_PENDING; |
| 637 | goto out_eoi; |
Thomas Gleixner | 0521c8f | 2011-03-28 16:13:24 +0200 | [diff] [blame] | 638 | } |
Thomas Gleixner | c3d7acd | 2014-08-29 13:46:08 +0200 | [diff] [blame] | 639 | |
| 640 | /* |
| 641 | * If its disabled or no action available then mask it and get |
| 642 | * out of here. |
| 643 | */ |
| 644 | if (irqd_irq_disabled(&desc->irq_data) || !desc->action) { |
| 645 | desc->istate |= IRQS_PENDING; |
| 646 | goto out_eoi; |
| 647 | } |
| 648 | |
Thomas Gleixner | 0521c8f | 2011-03-28 16:13:24 +0200 | [diff] [blame] | 649 | kstat_incr_irqs_this_cpu(irq, desc); |
| 650 | |
| 651 | do { |
| 652 | if (unlikely(!desc->action)) |
| 653 | goto out_eoi; |
| 654 | |
| 655 | handle_irq_event(desc); |
| 656 | |
| 657 | } while ((desc->istate & IRQS_PENDING) && |
| 658 | !irqd_irq_disabled(&desc->irq_data)); |
| 659 | |
Stephen Rothwell | ac0e044 | 2011-03-30 10:55:12 +1100 | [diff] [blame] | 660 | out_eoi: |
Thomas Gleixner | 0521c8f | 2011-03-28 16:13:24 +0200 | [diff] [blame] | 661 | chip->irq_eoi(&desc->irq_data); |
| 662 | raw_spin_unlock(&desc->lock); |
| 663 | } |
| 664 | #endif |
| 665 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 666 | /** |
Liuweni | 24b26d4 | 2009-11-04 20:11:05 +0800 | [diff] [blame] | 667 | * handle_percpu_irq - Per CPU local irq handler |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 668 | * @irq: the interrupt number |
| 669 | * @desc: the interrupt description structure for this irq |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 670 | * |
| 671 | * Per CPU interrupts on SMP machines without locking requirements |
| 672 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 673 | void |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 674 | handle_percpu_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 675 | { |
Thomas Gleixner | 35e857c | 2011-02-10 12:20:23 +0100 | [diff] [blame] | 676 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 677 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 678 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 679 | |
Thomas Gleixner | 849f061 | 2011-02-07 01:25:41 +0100 | [diff] [blame] | 680 | if (chip->irq_ack) |
| 681 | chip->irq_ack(&desc->irq_data); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 682 | |
Thomas Gleixner | 849f061 | 2011-02-07 01:25:41 +0100 | [diff] [blame] | 683 | handle_irq_event_percpu(desc, desc->action); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 684 | |
Thomas Gleixner | 849f061 | 2011-02-07 01:25:41 +0100 | [diff] [blame] | 685 | if (chip->irq_eoi) |
| 686 | chip->irq_eoi(&desc->irq_data); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 689 | /** |
| 690 | * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids |
| 691 | * @irq: the interrupt number |
| 692 | * @desc: the interrupt description structure for this irq |
| 693 | * |
| 694 | * Per CPU interrupts on SMP machines without locking requirements. Same as |
| 695 | * handle_percpu_irq() above but with the following extras: |
| 696 | * |
| 697 | * action->percpu_dev_id is a pointer to percpu variables which |
| 698 | * contain the real device id for the cpu on which this handler is |
| 699 | * called |
| 700 | */ |
| 701 | void handle_percpu_devid_irq(unsigned int irq, struct irq_desc *desc) |
| 702 | { |
| 703 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 704 | struct irqaction *action = desc->action; |
Christoph Lameter | 532d0d0 | 2014-08-17 12:30:39 -0500 | [diff] [blame] | 705 | void *dev_id = raw_cpu_ptr(action->percpu_dev_id); |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 706 | irqreturn_t res; |
| 707 | |
| 708 | kstat_incr_irqs_this_cpu(irq, desc); |
| 709 | |
| 710 | if (chip->irq_ack) |
| 711 | chip->irq_ack(&desc->irq_data); |
| 712 | |
| 713 | trace_irq_handler_entry(irq, action); |
| 714 | res = action->handler(irq, dev_id); |
| 715 | trace_irq_handler_exit(irq, action, res); |
| 716 | |
| 717 | if (chip->irq_eoi) |
| 718 | chip->irq_eoi(&desc->irq_data); |
| 719 | } |
| 720 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 721 | void |
Thomas Gleixner | 3836ca0 | 2011-02-14 20:09:19 +0100 | [diff] [blame] | 722 | __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained, |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 723 | const char *name) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 724 | { |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 725 | unsigned long flags; |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 726 | struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 727 | |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 728 | if (!desc) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 729 | return; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 730 | |
Thomas Gleixner | 091738a | 2011-02-14 20:16:43 +0100 | [diff] [blame] | 731 | if (!handle) { |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 732 | handle = handle_bad_irq; |
Thomas Gleixner | 091738a | 2011-02-14 20:16:43 +0100 | [diff] [blame] | 733 | } else { |
Marc Zyngier | f86eff2 | 2014-11-15 10:49:13 +0000 | [diff] [blame] | 734 | struct irq_data *irq_data = &desc->irq_data; |
| 735 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 736 | /* |
| 737 | * With hierarchical domains we might run into a |
| 738 | * situation where the outermost chip is not yet set |
| 739 | * up, but the inner chips are there. Instead of |
| 740 | * bailing we install the handler, but obviously we |
| 741 | * cannot enable/startup the interrupt at this point. |
| 742 | */ |
| 743 | while (irq_data) { |
| 744 | if (irq_data->chip != &no_irq_chip) |
| 745 | break; |
| 746 | /* |
| 747 | * Bail out if the outer chip is not set up |
| 748 | * and the interrrupt supposed to be started |
| 749 | * right away. |
| 750 | */ |
| 751 | if (WARN_ON(is_chained)) |
| 752 | goto out; |
| 753 | /* Try the parent */ |
| 754 | irq_data = irq_data->parent_data; |
| 755 | } |
| 756 | #endif |
| 757 | if (WARN_ON(!irq_data || irq_data->chip == &no_irq_chip)) |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 758 | goto out; |
Thomas Gleixner | f8b5473 | 2006-07-01 22:30:08 +0100 | [diff] [blame] | 759 | } |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 760 | |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 761 | /* Uninstall? */ |
| 762 | if (handle == handle_bad_irq) { |
Thomas Gleixner | 6b8ff31 | 2010-10-01 12:58:38 +0200 | [diff] [blame] | 763 | if (desc->irq_data.chip != &no_irq_chip) |
Thomas Gleixner | 9205e31 | 2010-09-27 12:44:50 +0000 | [diff] [blame] | 764 | mask_ack_irq(desc); |
Thomas Gleixner | 801a0e9 | 2011-03-27 11:02:49 +0200 | [diff] [blame] | 765 | irq_state_set_disabled(desc); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 766 | desc->depth = 1; |
| 767 | } |
| 768 | desc->handle_irq = handle; |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 769 | desc->name = name; |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 770 | |
| 771 | if (handle != handle_bad_irq && is_chained) { |
Thomas Gleixner | 1ccb4e6 | 2011-02-09 14:44:17 +0100 | [diff] [blame] | 772 | irq_settings_set_noprobe(desc); |
| 773 | irq_settings_set_norequest(desc); |
Paul Mundt | 7f1b124 | 2011-04-07 06:01:44 +0900 | [diff] [blame] | 774 | irq_settings_set_nothread(desc); |
Thomas Gleixner | b4bc724 | 2012-02-08 11:57:52 +0100 | [diff] [blame] | 775 | irq_startup(desc, true); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 776 | } |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 777 | out: |
| 778 | irq_put_desc_busunlock(desc, flags); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 779 | } |
Thomas Gleixner | 3836ca0 | 2011-02-14 20:09:19 +0100 | [diff] [blame] | 780 | EXPORT_SYMBOL_GPL(__irq_set_handler); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 781 | |
| 782 | void |
Thomas Gleixner | 3836ca0 | 2011-02-14 20:09:19 +0100 | [diff] [blame] | 783 | irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip, |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 784 | irq_flow_handler_t handle, const char *name) |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 785 | { |
Thomas Gleixner | 35e857c | 2011-02-10 12:20:23 +0100 | [diff] [blame] | 786 | irq_set_chip(irq, chip); |
Thomas Gleixner | 3836ca0 | 2011-02-14 20:09:19 +0100 | [diff] [blame] | 787 | __irq_set_handler(irq, handle, 0, name); |
Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 788 | } |
Kuninori Morimoto | b3ae66f | 2012-07-30 22:39:06 -0700 | [diff] [blame] | 789 | EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name); |
Ralf Baechle | 46f4f8f | 2008-02-08 04:22:01 -0800 | [diff] [blame] | 790 | |
Thomas Gleixner | 4424718 | 2010-09-28 10:40:18 +0200 | [diff] [blame] | 791 | void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set) |
Ralf Baechle | 46f4f8f | 2008-02-08 04:22:01 -0800 | [diff] [blame] | 792 | { |
Ralf Baechle | 46f4f8f | 2008-02-08 04:22:01 -0800 | [diff] [blame] | 793 | unsigned long flags; |
Marc Zyngier | 31d9d9b | 2011-09-23 17:03:06 +0100 | [diff] [blame] | 794 | struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0); |
Ralf Baechle | 46f4f8f | 2008-02-08 04:22:01 -0800 | [diff] [blame] | 795 | |
Thomas Gleixner | 4424718 | 2010-09-28 10:40:18 +0200 | [diff] [blame] | 796 | if (!desc) |
Ralf Baechle | 46f4f8f | 2008-02-08 04:22:01 -0800 | [diff] [blame] | 797 | return; |
Thomas Gleixner | a005677 | 2011-02-08 17:11:03 +0100 | [diff] [blame] | 798 | irq_settings_clr_and_set(desc, clr, set); |
| 799 | |
Thomas Gleixner | 876dbd4 | 2011-02-08 17:28:12 +0100 | [diff] [blame] | 800 | irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU | |
Thomas Gleixner | e1ef824 | 2011-02-10 22:25:31 +0100 | [diff] [blame] | 801 | IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT); |
Thomas Gleixner | a005677 | 2011-02-08 17:11:03 +0100 | [diff] [blame] | 802 | if (irq_settings_has_no_balance_set(desc)) |
| 803 | irqd_set(&desc->irq_data, IRQD_NO_BALANCING); |
| 804 | if (irq_settings_is_per_cpu(desc)) |
| 805 | irqd_set(&desc->irq_data, IRQD_PER_CPU); |
Thomas Gleixner | e1ef824 | 2011-02-10 22:25:31 +0100 | [diff] [blame] | 806 | if (irq_settings_can_move_pcntxt(desc)) |
| 807 | irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT); |
Thomas Gleixner | 0ef5ca1 | 2011-03-28 21:59:37 +0200 | [diff] [blame] | 808 | if (irq_settings_is_level(desc)) |
| 809 | irqd_set(&desc->irq_data, IRQD_LEVEL); |
Thomas Gleixner | a005677 | 2011-02-08 17:11:03 +0100 | [diff] [blame] | 810 | |
Thomas Gleixner | 876dbd4 | 2011-02-08 17:28:12 +0100 | [diff] [blame] | 811 | irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc)); |
| 812 | |
Thomas Gleixner | 02725e7 | 2011-02-12 10:37:36 +0100 | [diff] [blame] | 813 | irq_put_desc_unlock(desc, flags); |
Ralf Baechle | 46f4f8f | 2008-02-08 04:22:01 -0800 | [diff] [blame] | 814 | } |
Jonathan Cameron | edf76f8 | 2011-05-18 10:39:04 +0100 | [diff] [blame] | 815 | EXPORT_SYMBOL_GPL(irq_modify_status); |
David Daney | 0fdb4b2 | 2011-03-25 12:38:49 -0700 | [diff] [blame] | 816 | |
| 817 | /** |
| 818 | * irq_cpu_online - Invoke all irq_cpu_online functions. |
| 819 | * |
| 820 | * Iterate through all irqs and invoke the chip.irq_cpu_online() |
| 821 | * for each. |
| 822 | */ |
| 823 | void irq_cpu_online(void) |
| 824 | { |
| 825 | struct irq_desc *desc; |
| 826 | struct irq_chip *chip; |
| 827 | unsigned long flags; |
| 828 | unsigned int irq; |
| 829 | |
| 830 | for_each_active_irq(irq) { |
| 831 | desc = irq_to_desc(irq); |
| 832 | if (!desc) |
| 833 | continue; |
| 834 | |
| 835 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 836 | |
| 837 | chip = irq_data_get_irq_chip(&desc->irq_data); |
Thomas Gleixner | b3d4223 | 2011-03-27 16:05:36 +0200 | [diff] [blame] | 838 | if (chip && chip->irq_cpu_online && |
| 839 | (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) || |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 840 | !irqd_irq_disabled(&desc->irq_data))) |
David Daney | 0fdb4b2 | 2011-03-25 12:38:49 -0700 | [diff] [blame] | 841 | chip->irq_cpu_online(&desc->irq_data); |
| 842 | |
| 843 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | /** |
| 848 | * irq_cpu_offline - Invoke all irq_cpu_offline functions. |
| 849 | * |
| 850 | * Iterate through all irqs and invoke the chip.irq_cpu_offline() |
| 851 | * for each. |
| 852 | */ |
| 853 | void irq_cpu_offline(void) |
| 854 | { |
| 855 | struct irq_desc *desc; |
| 856 | struct irq_chip *chip; |
| 857 | unsigned long flags; |
| 858 | unsigned int irq; |
| 859 | |
| 860 | for_each_active_irq(irq) { |
| 861 | desc = irq_to_desc(irq); |
| 862 | if (!desc) |
| 863 | continue; |
| 864 | |
| 865 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 866 | |
| 867 | chip = irq_data_get_irq_chip(&desc->irq_data); |
Thomas Gleixner | b3d4223 | 2011-03-27 16:05:36 +0200 | [diff] [blame] | 868 | if (chip && chip->irq_cpu_offline && |
| 869 | (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) || |
Thomas Gleixner | 32f4125 | 2011-03-28 14:10:52 +0200 | [diff] [blame] | 870 | !irqd_irq_disabled(&desc->irq_data))) |
David Daney | 0fdb4b2 | 2011-03-25 12:38:49 -0700 | [diff] [blame] | 871 | chip->irq_cpu_offline(&desc->irq_data); |
| 872 | |
| 873 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
| 874 | } |
| 875 | } |
Jiang Liu | 85f08c1 | 2014-11-06 22:20:16 +0800 | [diff] [blame] | 876 | |
| 877 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 878 | /** |
Stefan Agner | 3cfeffc | 2015-05-16 11:44:14 +0200 | [diff] [blame^] | 879 | * irq_chip_enable_parent - Enable the parent interrupt (defaults to unmask if |
| 880 | * NULL) |
| 881 | * @data: Pointer to interrupt specific data |
| 882 | */ |
| 883 | void irq_chip_enable_parent(struct irq_data *data) |
| 884 | { |
| 885 | data = data->parent_data; |
| 886 | if (data->chip->irq_enable) |
| 887 | data->chip->irq_enable(data); |
| 888 | else |
| 889 | data->chip->irq_unmask(data); |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * irq_chip_disable_parent - Disable the parent interrupt (defaults to mask if |
| 894 | * NULL) |
| 895 | * @data: Pointer to interrupt specific data |
| 896 | */ |
| 897 | void irq_chip_disable_parent(struct irq_data *data) |
| 898 | { |
| 899 | data = data->parent_data; |
| 900 | if (data->chip->irq_disable) |
| 901 | data->chip->irq_disable(data); |
| 902 | else |
| 903 | data->chip->irq_mask(data); |
| 904 | } |
| 905 | |
| 906 | /** |
Jiang Liu | 85f08c1 | 2014-11-06 22:20:16 +0800 | [diff] [blame] | 907 | * irq_chip_ack_parent - Acknowledge the parent interrupt |
| 908 | * @data: Pointer to interrupt specific data |
| 909 | */ |
| 910 | void irq_chip_ack_parent(struct irq_data *data) |
| 911 | { |
| 912 | data = data->parent_data; |
| 913 | data->chip->irq_ack(data); |
| 914 | } |
| 915 | |
| 916 | /** |
Yingjoe Chen | 56e8aba | 2014-11-13 23:37:05 +0800 | [diff] [blame] | 917 | * irq_chip_mask_parent - Mask the parent interrupt |
| 918 | * @data: Pointer to interrupt specific data |
| 919 | */ |
| 920 | void irq_chip_mask_parent(struct irq_data *data) |
| 921 | { |
| 922 | data = data->parent_data; |
| 923 | data->chip->irq_mask(data); |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * irq_chip_unmask_parent - Unmask the parent interrupt |
| 928 | * @data: Pointer to interrupt specific data |
| 929 | */ |
| 930 | void irq_chip_unmask_parent(struct irq_data *data) |
| 931 | { |
| 932 | data = data->parent_data; |
| 933 | data->chip->irq_unmask(data); |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * irq_chip_eoi_parent - Invoke EOI on the parent interrupt |
| 938 | * @data: Pointer to interrupt specific data |
| 939 | */ |
| 940 | void irq_chip_eoi_parent(struct irq_data *data) |
| 941 | { |
| 942 | data = data->parent_data; |
| 943 | data->chip->irq_eoi(data); |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * irq_chip_set_affinity_parent - Set affinity on the parent interrupt |
| 948 | * @data: Pointer to interrupt specific data |
| 949 | * @dest: The affinity mask to set |
| 950 | * @force: Flag to enforce setting (disable online checks) |
| 951 | * |
| 952 | * Conditinal, as the underlying parent chip might not implement it. |
| 953 | */ |
| 954 | int irq_chip_set_affinity_parent(struct irq_data *data, |
| 955 | const struct cpumask *dest, bool force) |
| 956 | { |
| 957 | data = data->parent_data; |
| 958 | if (data->chip->irq_set_affinity) |
| 959 | return data->chip->irq_set_affinity(data, dest, force); |
| 960 | |
| 961 | return -ENOSYS; |
| 962 | } |
| 963 | |
| 964 | /** |
Jiang Liu | 85f08c1 | 2014-11-06 22:20:16 +0800 | [diff] [blame] | 965 | * irq_chip_retrigger_hierarchy - Retrigger an interrupt in hardware |
| 966 | * @data: Pointer to interrupt specific data |
| 967 | * |
| 968 | * Iterate through the domain hierarchy of the interrupt and check |
| 969 | * whether a hw retrigger function exists. If yes, invoke it. |
| 970 | */ |
| 971 | int irq_chip_retrigger_hierarchy(struct irq_data *data) |
| 972 | { |
| 973 | for (data = data->parent_data; data; data = data->parent_data) |
| 974 | if (data->chip && data->chip->irq_retrigger) |
| 975 | return data->chip->irq_retrigger(data); |
| 976 | |
| 977 | return -ENOSYS; |
| 978 | } |
Marc Zyngier | 08b55e2 | 2015-03-11 15:43:43 +0000 | [diff] [blame] | 979 | |
| 980 | /** |
| 981 | * irq_chip_set_wake_parent - Set/reset wake-up on the parent interrupt |
| 982 | * @data: Pointer to interrupt specific data |
| 983 | * @on: Whether to set or reset the wake-up capability of this irq |
| 984 | * |
| 985 | * Conditional, as the underlying parent chip might not implement it. |
| 986 | */ |
| 987 | int irq_chip_set_wake_parent(struct irq_data *data, unsigned int on) |
| 988 | { |
| 989 | data = data->parent_data; |
| 990 | if (data->chip->irq_set_wake) |
| 991 | return data->chip->irq_set_wake(data, on); |
| 992 | |
| 993 | return -ENOSYS; |
| 994 | } |
Jiang Liu | 85f08c1 | 2014-11-06 22:20:16 +0800 | [diff] [blame] | 995 | #endif |
Jiang Liu | 515085e | 2014-11-06 22:20:17 +0800 | [diff] [blame] | 996 | |
| 997 | /** |
| 998 | * irq_chip_compose_msi_msg - Componse msi message for a irq chip |
| 999 | * @data: Pointer to interrupt specific data |
| 1000 | * @msg: Pointer to the MSI message |
| 1001 | * |
| 1002 | * For hierarchical domains we find the first chip in the hierarchy |
| 1003 | * which implements the irq_compose_msi_msg callback. For non |
| 1004 | * hierarchical we use the top level chip. |
| 1005 | */ |
| 1006 | int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) |
| 1007 | { |
| 1008 | struct irq_data *pos = NULL; |
| 1009 | |
| 1010 | #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY |
| 1011 | for (; data; data = data->parent_data) |
| 1012 | #endif |
| 1013 | if (data->chip && data->chip->irq_compose_msi_msg) |
| 1014 | pos = data; |
| 1015 | if (!pos) |
| 1016 | return -ENOSYS; |
| 1017 | |
| 1018 | pos->chip->irq_compose_msi_msg(pos, msg); |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |