Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Library implementing the most common irq chip callback functions |
| 3 | * |
| 4 | * Copyright (C) 2011, Thomas Gleixner |
| 5 | */ |
| 6 | #include <linux/io.h> |
| 7 | #include <linux/irq.h> |
| 8 | #include <linux/slab.h> |
Paul Gortmaker | 6e5fdee | 2011-05-26 16:00:52 -0400 | [diff] [blame] | 9 | #include <linux/export.h> |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 10 | #include <linux/irqdomain.h> |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/kernel_stat.h> |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 13 | #include <linux/syscore_ops.h> |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 14 | |
| 15 | #include "internals.h" |
| 16 | |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 17 | static LIST_HEAD(gc_list); |
| 18 | static DEFINE_RAW_SPINLOCK(gc_lock); |
| 19 | |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 20 | /** |
| 21 | * irq_gc_noop - NOOP function |
| 22 | * @d: irq_data |
| 23 | */ |
| 24 | void irq_gc_noop(struct irq_data *d) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * irq_gc_mask_disable_reg - Mask chip via disable register |
| 30 | * @d: irq_data |
| 31 | * |
| 32 | * Chip has separate enable/disable registers instead of a single mask |
| 33 | * register. |
| 34 | */ |
| 35 | void irq_gc_mask_disable_reg(struct irq_data *d) |
| 36 | { |
| 37 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 38 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 39 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 40 | |
| 41 | irq_gc_lock(gc); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 42 | irq_reg_writel(mask, gc->reg_base + ct->regs.disable); |
Gerlando Falauto | 899f0e6 | 2013-05-06 14:30:19 +0000 | [diff] [blame] | 43 | *ct->mask_cache &= ~mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 44 | irq_gc_unlock(gc); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * irq_gc_mask_set_mask_bit - Mask chip via setting bit in mask register |
| 49 | * @d: irq_data |
| 50 | * |
| 51 | * Chip has a single mask register. Values of this register are cached |
| 52 | * and protected by gc->lock |
| 53 | */ |
| 54 | void irq_gc_mask_set_bit(struct irq_data *d) |
| 55 | { |
| 56 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 57 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 58 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 59 | |
| 60 | irq_gc_lock(gc); |
Gerlando Falauto | 899f0e6 | 2013-05-06 14:30:19 +0000 | [diff] [blame] | 61 | *ct->mask_cache |= mask; |
| 62 | irq_reg_writel(*ct->mask_cache, gc->reg_base + ct->regs.mask); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 63 | irq_gc_unlock(gc); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * irq_gc_mask_set_mask_bit - Mask chip via clearing bit in mask register |
| 68 | * @d: irq_data |
| 69 | * |
| 70 | * Chip has a single mask register. Values of this register are cached |
| 71 | * and protected by gc->lock |
| 72 | */ |
| 73 | void irq_gc_mask_clr_bit(struct irq_data *d) |
| 74 | { |
| 75 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 76 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 77 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 78 | |
| 79 | irq_gc_lock(gc); |
Gerlando Falauto | 899f0e6 | 2013-05-06 14:30:19 +0000 | [diff] [blame] | 80 | *ct->mask_cache &= ~mask; |
| 81 | irq_reg_writel(*ct->mask_cache, gc->reg_base + ct->regs.mask); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 82 | irq_gc_unlock(gc); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * irq_gc_unmask_enable_reg - Unmask chip via enable register |
| 87 | * @d: irq_data |
| 88 | * |
| 89 | * Chip has separate enable/disable registers instead of a single mask |
| 90 | * register. |
| 91 | */ |
| 92 | void irq_gc_unmask_enable_reg(struct irq_data *d) |
| 93 | { |
| 94 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 95 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 96 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 97 | |
| 98 | irq_gc_lock(gc); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 99 | irq_reg_writel(mask, gc->reg_base + ct->regs.enable); |
Gerlando Falauto | 899f0e6 | 2013-05-06 14:30:19 +0000 | [diff] [blame] | 100 | *ct->mask_cache |= mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 101 | irq_gc_unlock(gc); |
| 102 | } |
| 103 | |
| 104 | /** |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 105 | * irq_gc_ack_set_bit - Ack pending interrupt via setting bit |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 106 | * @d: irq_data |
| 107 | */ |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 108 | void irq_gc_ack_set_bit(struct irq_data *d) |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 109 | { |
| 110 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 111 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 112 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 113 | |
| 114 | irq_gc_lock(gc); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 115 | irq_reg_writel(mask, gc->reg_base + ct->regs.ack); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 116 | irq_gc_unlock(gc); |
| 117 | } |
| 118 | |
| 119 | /** |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 120 | * irq_gc_ack_clr_bit - Ack pending interrupt via clearing bit |
| 121 | * @d: irq_data |
| 122 | */ |
| 123 | void irq_gc_ack_clr_bit(struct irq_data *d) |
| 124 | { |
| 125 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 126 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 127 | u32 mask = ~d->mask; |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 128 | |
| 129 | irq_gc_lock(gc); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 130 | irq_reg_writel(mask, gc->reg_base + ct->regs.ack); |
Simon Guinot | 659fb32 | 2011-07-06 12:41:31 -0400 | [diff] [blame] | 131 | irq_gc_unlock(gc); |
| 132 | } |
| 133 | |
| 134 | /** |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 135 | * irq_gc_mask_disable_reg_and_ack- Mask and ack pending interrupt |
| 136 | * @d: irq_data |
| 137 | */ |
| 138 | void irq_gc_mask_disable_reg_and_ack(struct irq_data *d) |
| 139 | { |
| 140 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 141 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 142 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 143 | |
| 144 | irq_gc_lock(gc); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 145 | irq_reg_writel(mask, gc->reg_base + ct->regs.mask); |
| 146 | irq_reg_writel(mask, gc->reg_base + ct->regs.ack); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 147 | irq_gc_unlock(gc); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * irq_gc_eoi - EOI interrupt |
| 152 | * @d: irq_data |
| 153 | */ |
| 154 | void irq_gc_eoi(struct irq_data *d) |
| 155 | { |
| 156 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 157 | struct irq_chip_type *ct = irq_data_get_chip_type(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 158 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 159 | |
| 160 | irq_gc_lock(gc); |
Gerlando Falauto | cfeaa93 | 2013-05-06 14:30:17 +0000 | [diff] [blame] | 161 | irq_reg_writel(mask, gc->reg_base + ct->regs.eoi); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 162 | irq_gc_unlock(gc); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * irq_gc_set_wake - Set/clr wake bit for an interrupt |
| 167 | * @d: irq_data |
| 168 | * |
| 169 | * For chips where the wake from suspend functionality is not |
| 170 | * configured in a separate register and the wakeup active state is |
| 171 | * just stored in a bitmask. |
| 172 | */ |
| 173 | int irq_gc_set_wake(struct irq_data *d, unsigned int on) |
| 174 | { |
| 175 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 176 | u32 mask = d->mask; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 177 | |
| 178 | if (!(mask & gc->wake_enabled)) |
| 179 | return -EINVAL; |
| 180 | |
| 181 | irq_gc_lock(gc); |
| 182 | if (on) |
| 183 | gc->wake_active |= mask; |
| 184 | else |
| 185 | gc->wake_active &= ~mask; |
| 186 | irq_gc_unlock(gc); |
| 187 | return 0; |
| 188 | } |
| 189 | |
Thomas Gleixner | 3528d82 | 2013-05-06 14:30:25 +0000 | [diff] [blame] | 190 | static void |
| 191 | irq_init_generic_chip(struct irq_chip_generic *gc, const char *name, |
| 192 | int num_ct, unsigned int irq_base, |
| 193 | void __iomem *reg_base, irq_flow_handler_t handler) |
| 194 | { |
| 195 | raw_spin_lock_init(&gc->lock); |
| 196 | gc->num_ct = num_ct; |
| 197 | gc->irq_base = irq_base; |
| 198 | gc->reg_base = reg_base; |
| 199 | gc->chip_types->chip.name = name; |
| 200 | gc->chip_types->handler = handler; |
| 201 | } |
| 202 | |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 203 | /** |
| 204 | * irq_alloc_generic_chip - Allocate a generic chip and initialize it |
| 205 | * @name: Name of the irq chip |
| 206 | * @num_ct: Number of irq_chip_type instances associated with this |
| 207 | * @irq_base: Interrupt base nr for this chip |
| 208 | * @reg_base: Register base address (virtual) |
| 209 | * @handler: Default flow handler associated with this chip |
| 210 | * |
| 211 | * Returns an initialized irq_chip_generic structure. The chip defaults |
| 212 | * to the primary (index 0) irq_chip_type and @handler |
| 213 | */ |
| 214 | struct irq_chip_generic * |
| 215 | irq_alloc_generic_chip(const char *name, int num_ct, unsigned int irq_base, |
| 216 | void __iomem *reg_base, irq_flow_handler_t handler) |
| 217 | { |
| 218 | struct irq_chip_generic *gc; |
| 219 | unsigned long sz = sizeof(*gc) + num_ct * sizeof(struct irq_chip_type); |
| 220 | |
| 221 | gc = kzalloc(sz, GFP_KERNEL); |
| 222 | if (gc) { |
Thomas Gleixner | 3528d82 | 2013-05-06 14:30:25 +0000 | [diff] [blame] | 223 | irq_init_generic_chip(gc, name, num_ct, irq_base, reg_base, |
| 224 | handler); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 225 | } |
| 226 | return gc; |
| 227 | } |
Nobuhiro Iwamatsu | 825de2e | 2011-10-17 11:08:46 +0900 | [diff] [blame] | 228 | EXPORT_SYMBOL_GPL(irq_alloc_generic_chip); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 229 | |
Thomas Gleixner | 3528d82 | 2013-05-06 14:30:25 +0000 | [diff] [blame] | 230 | static void |
| 231 | irq_gc_init_mask_cache(struct irq_chip_generic *gc, enum irq_gc_flags flags) |
| 232 | { |
| 233 | struct irq_chip_type *ct = gc->chip_types; |
| 234 | u32 *mskptr = &gc->mask_cache, mskreg = ct->regs.mask; |
| 235 | int i; |
| 236 | |
| 237 | for (i = 0; i < gc->num_ct; i++) { |
| 238 | if (flags & IRQ_GC_MASK_CACHE_PER_TYPE) { |
| 239 | mskptr = &ct[i].mask_cache_priv; |
| 240 | mskreg = ct[i].regs.mask; |
| 241 | } |
| 242 | ct[i].mask_cache = mskptr; |
| 243 | if (flags & IRQ_GC_INIT_MASK_CACHE) |
| 244 | *mskptr = irq_reg_readl(gc->reg_base + mskreg); |
| 245 | } |
| 246 | } |
| 247 | |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 248 | /** |
| 249 | * irq_alloc_domain_generic_chip - Allocate generic chips for an irq domain |
| 250 | * @d: irq domain for which to allocate chips |
| 251 | * @irqs_per_chip: Number of interrupts each chip handles |
| 252 | * @num_ct: Number of irq_chip_type instances associated with this |
| 253 | * @name: Name of the irq chip |
| 254 | * @handler: Default flow handler associated with these chips |
| 255 | * @clr: IRQ_* bits to clear in the mapping function |
| 256 | * @set: IRQ_* bits to set in the mapping function |
| 257 | */ |
| 258 | int irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip, |
| 259 | int num_ct, const char *name, |
| 260 | irq_flow_handler_t handler, |
| 261 | unsigned int clr, unsigned int set, |
| 262 | enum irq_gc_flags gcflags) |
| 263 | { |
| 264 | struct irq_domain_chip_generic *dgc; |
| 265 | struct irq_chip_generic *gc; |
| 266 | int numchips, sz, i; |
| 267 | unsigned long flags; |
| 268 | void *tmp; |
| 269 | |
| 270 | if (d->gc) |
| 271 | return -EBUSY; |
| 272 | |
| 273 | if (d->revmap_type != IRQ_DOMAIN_MAP_LINEAR) |
| 274 | return -EINVAL; |
| 275 | |
| 276 | numchips = d->revmap_data.linear.size / irqs_per_chip; |
| 277 | if (!numchips) |
| 278 | return -EINVAL; |
| 279 | |
| 280 | /* Allocate a pointer, generic chip and chiptypes for each chip */ |
| 281 | sz = sizeof(*dgc) + numchips * sizeof(gc); |
| 282 | sz += numchips * (sizeof(*gc) + num_ct * sizeof(struct irq_chip_type)); |
| 283 | |
| 284 | tmp = dgc = kzalloc(sz, GFP_KERNEL); |
| 285 | if (!dgc) |
| 286 | return -ENOMEM; |
| 287 | dgc->irqs_per_chip = irqs_per_chip; |
| 288 | dgc->num_chips = numchips; |
| 289 | dgc->irq_flags_to_set = set; |
| 290 | dgc->irq_flags_to_clear = clr; |
| 291 | dgc->gc_flags = gcflags; |
| 292 | d->gc = dgc; |
| 293 | |
| 294 | /* Calc pointer to the first generic chip */ |
| 295 | tmp += sizeof(*dgc) + numchips * sizeof(gc); |
| 296 | for (i = 0; i < numchips; i++) { |
| 297 | /* Store the pointer to the generic chip */ |
| 298 | dgc->gc[i] = gc = tmp; |
| 299 | irq_init_generic_chip(gc, name, num_ct, i * irqs_per_chip, |
| 300 | NULL, handler); |
| 301 | gc->domain = d; |
| 302 | raw_spin_lock_irqsave(&gc_lock, flags); |
| 303 | list_add_tail(&gc->list, &gc_list); |
| 304 | raw_spin_unlock_irqrestore(&gc_lock, flags); |
| 305 | /* Calc pointer to the next generic chip */ |
| 306 | tmp += sizeof(*gc) + num_ct * sizeof(struct irq_chip_type); |
| 307 | } |
| 308 | return 0; |
| 309 | } |
| 310 | EXPORT_SYMBOL_GPL(irq_alloc_domain_generic_chips); |
| 311 | |
| 312 | /** |
| 313 | * irq_get_domain_generic_chip - Get a pointer to the generic chip of a hw_irq |
| 314 | * @d: irq domain pointer |
| 315 | * @hw_irq: Hardware interrupt number |
| 316 | */ |
| 317 | struct irq_chip_generic * |
| 318 | irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq) |
| 319 | { |
| 320 | struct irq_domain_chip_generic *dgc = d->gc; |
| 321 | int idx; |
| 322 | |
| 323 | if (!dgc) |
| 324 | return NULL; |
| 325 | idx = hw_irq / dgc->irqs_per_chip; |
| 326 | if (idx >= dgc->num_chips) |
| 327 | return NULL; |
| 328 | return dgc->gc[idx]; |
| 329 | } |
| 330 | EXPORT_SYMBOL_GPL(irq_get_domain_generic_chip); |
| 331 | |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 332 | /* |
| 333 | * Separate lockdep class for interrupt chip which can nest irq_desc |
| 334 | * lock. |
| 335 | */ |
| 336 | static struct lock_class_key irq_nested_lock_class; |
| 337 | |
| 338 | /** |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 339 | * irq_map_generic_chip - Map a generic chip for an irq domain |
| 340 | */ |
| 341 | static int irq_map_generic_chip(struct irq_domain *d, unsigned int virq, |
| 342 | irq_hw_number_t hw_irq) |
| 343 | { |
| 344 | struct irq_data *data = irq_get_irq_data(virq); |
| 345 | struct irq_domain_chip_generic *dgc = d->gc; |
| 346 | struct irq_chip_generic *gc; |
| 347 | struct irq_chip_type *ct; |
| 348 | struct irq_chip *chip; |
| 349 | unsigned long flags; |
| 350 | int idx; |
| 351 | |
| 352 | if (!d->gc) |
| 353 | return -ENODEV; |
| 354 | |
| 355 | idx = hw_irq / dgc->irqs_per_chip; |
| 356 | if (idx >= dgc->num_chips) |
| 357 | return -EINVAL; |
| 358 | gc = dgc->gc[idx]; |
| 359 | |
| 360 | idx = hw_irq % dgc->irqs_per_chip; |
| 361 | |
Grant Likely | e8bd834 | 2013-05-29 03:10:52 +0100 | [diff] [blame^] | 362 | if (test_bit(idx, &gc->unused)) |
| 363 | return -ENOTSUPP; |
| 364 | |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 365 | if (test_bit(idx, &gc->installed)) |
| 366 | return -EBUSY; |
| 367 | |
| 368 | ct = gc->chip_types; |
| 369 | chip = &ct->chip; |
| 370 | |
| 371 | /* We only init the cache for the first mapping of a generic chip */ |
| 372 | if (!gc->installed) { |
| 373 | raw_spin_lock_irqsave(&gc->lock, flags); |
| 374 | irq_gc_init_mask_cache(gc, dgc->gc_flags); |
| 375 | raw_spin_unlock_irqrestore(&gc->lock, flags); |
| 376 | } |
| 377 | |
| 378 | /* Mark the interrupt as installed */ |
| 379 | set_bit(idx, &gc->installed); |
| 380 | |
| 381 | if (dgc->gc_flags & IRQ_GC_INIT_NESTED_LOCK) |
| 382 | irq_set_lockdep_class(virq, &irq_nested_lock_class); |
| 383 | |
| 384 | if (chip->irq_calc_mask) |
| 385 | chip->irq_calc_mask(data); |
| 386 | else |
| 387 | data->mask = 1 << idx; |
| 388 | |
| 389 | irq_set_chip_and_handler(virq, chip, ct->handler); |
| 390 | irq_set_chip_data(virq, gc); |
| 391 | irq_modify_status(virq, dgc->irq_flags_to_clear, dgc->irq_flags_to_set); |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | struct irq_domain_ops irq_generic_chip_ops = { |
| 396 | .map = irq_map_generic_chip, |
| 397 | .xlate = irq_domain_xlate_onetwocell, |
| 398 | }; |
| 399 | EXPORT_SYMBOL_GPL(irq_generic_chip_ops); |
| 400 | |
| 401 | /** |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 402 | * irq_setup_generic_chip - Setup a range of interrupts with a generic chip |
| 403 | * @gc: Generic irq chip holding all data |
| 404 | * @msk: Bitmask holding the irqs to initialize relative to gc->irq_base |
| 405 | * @flags: Flags for initialization |
| 406 | * @clr: IRQ_* bits to clear |
| 407 | * @set: IRQ_* bits to set |
| 408 | * |
| 409 | * Set up max. 32 interrupts starting from gc->irq_base. Note, this |
| 410 | * initializes all interrupts to the primary irq_chip_type and its |
| 411 | * associated handler. |
| 412 | */ |
| 413 | void irq_setup_generic_chip(struct irq_chip_generic *gc, u32 msk, |
| 414 | enum irq_gc_flags flags, unsigned int clr, |
| 415 | unsigned int set) |
| 416 | { |
| 417 | struct irq_chip_type *ct = gc->chip_types; |
Thomas Gleixner | d005181 | 2013-05-06 14:30:24 +0000 | [diff] [blame] | 418 | struct irq_chip *chip = &ct->chip; |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 419 | unsigned int i; |
| 420 | |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 421 | raw_spin_lock(&gc_lock); |
| 422 | list_add_tail(&gc->list, &gc_list); |
| 423 | raw_spin_unlock(&gc_lock); |
| 424 | |
Thomas Gleixner | 3528d82 | 2013-05-06 14:30:25 +0000 | [diff] [blame] | 425 | irq_gc_init_mask_cache(gc, flags); |
Gerlando Falauto | 899f0e6 | 2013-05-06 14:30:19 +0000 | [diff] [blame] | 426 | |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 427 | for (i = gc->irq_base; msk; msk >>= 1, i++) { |
jhbird.choi@samsung.com | 1dd75f9 | 2011-07-21 15:29:14 +0900 | [diff] [blame] | 428 | if (!(msk & 0x01)) |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 429 | continue; |
| 430 | |
| 431 | if (flags & IRQ_GC_INIT_NESTED_LOCK) |
| 432 | irq_set_lockdep_class(i, &irq_nested_lock_class); |
| 433 | |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 434 | if (!(flags & IRQ_GC_NO_MASK)) { |
| 435 | struct irq_data *d = irq_get_irq_data(i); |
| 436 | |
Thomas Gleixner | d005181 | 2013-05-06 14:30:24 +0000 | [diff] [blame] | 437 | if (chip->irq_calc_mask) |
| 438 | chip->irq_calc_mask(d); |
| 439 | else |
| 440 | d->mask = 1 << (i - gc->irq_base); |
Thomas Gleixner | 966dc73 | 2013-05-06 14:30:22 +0000 | [diff] [blame] | 441 | } |
Thomas Gleixner | d005181 | 2013-05-06 14:30:24 +0000 | [diff] [blame] | 442 | irq_set_chip_and_handler(i, chip, ct->handler); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 443 | irq_set_chip_data(i, gc); |
| 444 | irq_modify_status(i, clr, set); |
| 445 | } |
| 446 | gc->irq_cnt = i - gc->irq_base; |
| 447 | } |
Nobuhiro Iwamatsu | 825de2e | 2011-10-17 11:08:46 +0900 | [diff] [blame] | 448 | EXPORT_SYMBOL_GPL(irq_setup_generic_chip); |
Thomas Gleixner | 7d82806 | 2011-04-03 11:42:53 +0200 | [diff] [blame] | 449 | |
| 450 | /** |
| 451 | * irq_setup_alt_chip - Switch to alternative chip |
| 452 | * @d: irq_data for this interrupt |
| 453 | * @type Flow type to be initialized |
| 454 | * |
| 455 | * Only to be called from chip->irq_set_type() callbacks. |
| 456 | */ |
| 457 | int irq_setup_alt_chip(struct irq_data *d, unsigned int type) |
| 458 | { |
| 459 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
| 460 | struct irq_chip_type *ct = gc->chip_types; |
| 461 | unsigned int i; |
| 462 | |
| 463 | for (i = 0; i < gc->num_ct; i++, ct++) { |
| 464 | if (ct->type & type) { |
| 465 | d->chip = &ct->chip; |
| 466 | irq_data_to_desc(d)->handle_irq = ct->handler; |
| 467 | return 0; |
| 468 | } |
| 469 | } |
| 470 | return -EINVAL; |
| 471 | } |
Nobuhiro Iwamatsu | 825de2e | 2011-10-17 11:08:46 +0900 | [diff] [blame] | 472 | EXPORT_SYMBOL_GPL(irq_setup_alt_chip); |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 473 | |
| 474 | /** |
| 475 | * irq_remove_generic_chip - Remove a chip |
| 476 | * @gc: Generic irq chip holding all data |
| 477 | * @msk: Bitmask holding the irqs to initialize relative to gc->irq_base |
| 478 | * @clr: IRQ_* bits to clear |
| 479 | * @set: IRQ_* bits to set |
| 480 | * |
| 481 | * Remove up to 32 interrupts starting from gc->irq_base. |
| 482 | */ |
| 483 | void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk, |
| 484 | unsigned int clr, unsigned int set) |
| 485 | { |
| 486 | unsigned int i = gc->irq_base; |
| 487 | |
| 488 | raw_spin_lock(&gc_lock); |
| 489 | list_del(&gc->list); |
| 490 | raw_spin_unlock(&gc_lock); |
| 491 | |
| 492 | for (; msk; msk >>= 1, i++) { |
jhbird.choi@samsung.com | 1dd75f9 | 2011-07-21 15:29:14 +0900 | [diff] [blame] | 493 | if (!(msk & 0x01)) |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 494 | continue; |
| 495 | |
| 496 | /* Remove handler first. That will mask the irq line */ |
| 497 | irq_set_handler(i, NULL); |
| 498 | irq_set_chip(i, &no_irq_chip); |
| 499 | irq_set_chip_data(i, NULL); |
| 500 | irq_modify_status(i, clr, set); |
| 501 | } |
| 502 | } |
Nobuhiro Iwamatsu | 825de2e | 2011-10-17 11:08:46 +0900 | [diff] [blame] | 503 | EXPORT_SYMBOL_GPL(irq_remove_generic_chip); |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 504 | |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 505 | static struct irq_data *irq_gc_get_irq_data(struct irq_chip_generic *gc) |
| 506 | { |
| 507 | unsigned int virq; |
| 508 | |
| 509 | if (!gc->domain) |
| 510 | return irq_get_irq_data(gc->irq_base); |
| 511 | |
| 512 | /* |
| 513 | * We don't know which of the irqs has been actually |
| 514 | * installed. Use the first one. |
| 515 | */ |
| 516 | if (!gc->installed) |
| 517 | return NULL; |
| 518 | |
| 519 | virq = irq_find_mapping(gc->domain, gc->irq_base + __ffs(gc->installed)); |
| 520 | return virq ? irq_get_irq_data(virq) : NULL; |
| 521 | } |
| 522 | |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 523 | #ifdef CONFIG_PM |
| 524 | static int irq_gc_suspend(void) |
| 525 | { |
| 526 | struct irq_chip_generic *gc; |
| 527 | |
| 528 | list_for_each_entry(gc, &gc_list, list) { |
| 529 | struct irq_chip_type *ct = gc->chip_types; |
| 530 | |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 531 | if (ct->chip.irq_suspend) { |
| 532 | struct irq_data *data = irq_gc_get_irq_data(gc); |
| 533 | |
| 534 | if (data) |
| 535 | ct->chip.irq_suspend(data); |
| 536 | } |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 537 | } |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | static void irq_gc_resume(void) |
| 542 | { |
| 543 | struct irq_chip_generic *gc; |
| 544 | |
| 545 | list_for_each_entry(gc, &gc_list, list) { |
| 546 | struct irq_chip_type *ct = gc->chip_types; |
| 547 | |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 548 | if (ct->chip.irq_resume) { |
| 549 | struct irq_data *data = irq_gc_get_irq_data(gc); |
| 550 | |
| 551 | if (data) |
| 552 | ct->chip.irq_resume(data); |
| 553 | } |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | #else |
| 557 | #define irq_gc_suspend NULL |
| 558 | #define irq_gc_resume NULL |
| 559 | #endif |
| 560 | |
| 561 | static void irq_gc_shutdown(void) |
| 562 | { |
| 563 | struct irq_chip_generic *gc; |
| 564 | |
| 565 | list_for_each_entry(gc, &gc_list, list) { |
| 566 | struct irq_chip_type *ct = gc->chip_types; |
| 567 | |
Thomas Gleixner | 088f40b | 2013-05-06 14:30:27 +0000 | [diff] [blame] | 568 | if (ct->chip.irq_pm_shutdown) { |
| 569 | struct irq_data *data = irq_gc_get_irq_data(gc); |
| 570 | |
| 571 | if (data) |
| 572 | ct->chip.irq_pm_shutdown(data); |
| 573 | } |
Thomas Gleixner | cfefd21 | 2011-04-15 22:36:08 +0200 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | static struct syscore_ops irq_gc_syscore_ops = { |
| 578 | .suspend = irq_gc_suspend, |
| 579 | .resume = irq_gc_resume, |
| 580 | .shutdown = irq_gc_shutdown, |
| 581 | }; |
| 582 | |
| 583 | static int __init irq_gc_init_ops(void) |
| 584 | { |
| 585 | register_syscore_ops(&irq_gc_syscore_ops); |
| 586 | return 0; |
| 587 | } |
| 588 | device_initcall(irq_gc_init_ops); |