| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 1 | /* | 
|  | 2 | * arch/powerpc/sysdev/uic.c | 
|  | 3 | * | 
|  | 4 | * IBM PowerPC 4xx Universal Interrupt Controller | 
|  | 5 | * | 
|  | 6 | * Copyright 2007 David Gibson <dwg@au1.ibm.com>, IBM Corporation. | 
|  | 7 | * | 
|  | 8 | * This program is free software; you can redistribute  it and/or modify it | 
|  | 9 | * under  the terms of  the GNU General  Public License as published by the | 
|  | 10 | * Free Software Foundation;  either version 2 of the  License, or (at your | 
|  | 11 | * option) any later version. | 
|  | 12 | */ | 
|  | 13 | #include <linux/kernel.h> | 
|  | 14 | #include <linux/init.h> | 
|  | 15 | #include <linux/errno.h> | 
|  | 16 | #include <linux/reboot.h> | 
|  | 17 | #include <linux/slab.h> | 
|  | 18 | #include <linux/stddef.h> | 
|  | 19 | #include <linux/sched.h> | 
|  | 20 | #include <linux/signal.h> | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 21 | #include <linux/device.h> | 
|  | 22 | #include <linux/bootmem.h> | 
|  | 23 | #include <linux/spinlock.h> | 
|  | 24 | #include <linux/irq.h> | 
|  | 25 | #include <linux/interrupt.h> | 
| David Gibson | 868afce | 2007-08-14 13:52:42 +1000 | [diff] [blame] | 26 | #include <linux/kernel_stat.h> | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 27 | #include <asm/irq.h> | 
|  | 28 | #include <asm/io.h> | 
|  | 29 | #include <asm/prom.h> | 
|  | 30 | #include <asm/dcr.h> | 
|  | 31 |  | 
|  | 32 | #define NR_UIC_INTS	32 | 
|  | 33 |  | 
|  | 34 | #define UIC_SR		0x0 | 
|  | 35 | #define UIC_ER		0x2 | 
|  | 36 | #define UIC_CR		0x3 | 
|  | 37 | #define UIC_PR		0x4 | 
|  | 38 | #define UIC_TR		0x5 | 
|  | 39 | #define UIC_MSR		0x6 | 
|  | 40 | #define UIC_VR		0x7 | 
|  | 41 | #define UIC_VCR		0x8 | 
|  | 42 |  | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 43 | struct uic *primary_uic; | 
|  | 44 |  | 
|  | 45 | struct uic { | 
|  | 46 | int index; | 
|  | 47 | int dcrbase; | 
|  | 48 |  | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 49 | raw_spinlock_t lock; | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 50 |  | 
|  | 51 | /* The remapper for this UIC */ | 
|  | 52 | struct irq_host	*irqhost; | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 53 | }; | 
|  | 54 |  | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 55 | static void uic_unmask_irq(struct irq_data *d) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 56 | { | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 57 | struct uic *uic = irq_data_get_irq_chip_data(d); | 
| Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 58 | unsigned int src = irqd_to_hwirq(d); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 59 | unsigned long flags; | 
| Valentine Barshak | c809056 | 2007-11-15 01:00:52 +1100 | [diff] [blame] | 60 | u32 er, sr; | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 61 |  | 
| Valentine Barshak | c809056 | 2007-11-15 01:00:52 +1100 | [diff] [blame] | 62 | sr = 1 << (31-src); | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 63 | raw_spin_lock_irqsave(&uic->lock, flags); | 
| Valentine Barshak | c809056 | 2007-11-15 01:00:52 +1100 | [diff] [blame] | 64 | /* ack level-triggered interrupts here */ | 
| Thomas Gleixner | 1ac06cd | 2011-03-25 16:23:57 +0100 | [diff] [blame] | 65 | if (irqd_is_level_type(d)) | 
| Valentine Barshak | c809056 | 2007-11-15 01:00:52 +1100 | [diff] [blame] | 66 | mtdcr(uic->dcrbase + UIC_SR, sr); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 67 | er = mfdcr(uic->dcrbase + UIC_ER); | 
| Valentine Barshak | c809056 | 2007-11-15 01:00:52 +1100 | [diff] [blame] | 68 | er |= sr; | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 69 | mtdcr(uic->dcrbase + UIC_ER, er); | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 70 | raw_spin_unlock_irqrestore(&uic->lock, flags); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 73 | static void uic_mask_irq(struct irq_data *d) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 74 | { | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 75 | struct uic *uic = irq_data_get_irq_chip_data(d); | 
| Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 76 | unsigned int src = irqd_to_hwirq(d); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 77 | unsigned long flags; | 
|  | 78 | u32 er; | 
|  | 79 |  | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 80 | raw_spin_lock_irqsave(&uic->lock, flags); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 81 | er = mfdcr(uic->dcrbase + UIC_ER); | 
|  | 82 | er &= ~(1 << (31 - src)); | 
|  | 83 | mtdcr(uic->dcrbase + UIC_ER, er); | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 84 | raw_spin_unlock_irqrestore(&uic->lock, flags); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 85 | } | 
|  | 86 |  | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 87 | static void uic_ack_irq(struct irq_data *d) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 88 | { | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 89 | struct uic *uic = irq_data_get_irq_chip_data(d); | 
| Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 90 | unsigned int src = irqd_to_hwirq(d); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 91 | unsigned long flags; | 
|  | 92 |  | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 93 | raw_spin_lock_irqsave(&uic->lock, flags); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 94 | mtdcr(uic->dcrbase + UIC_SR, 1 << (31-src)); | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 95 | raw_spin_unlock_irqrestore(&uic->lock, flags); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 98 | static void uic_mask_ack_irq(struct irq_data *d) | 
| Valentine Barshak | b8b799a | 2007-11-14 07:25:21 +1100 | [diff] [blame] | 99 | { | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 100 | struct uic *uic = irq_data_get_irq_chip_data(d); | 
| Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 101 | unsigned int src = irqd_to_hwirq(d); | 
| Valentine Barshak | b8b799a | 2007-11-14 07:25:21 +1100 | [diff] [blame] | 102 | unsigned long flags; | 
|  | 103 | u32 er, sr; | 
|  | 104 |  | 
|  | 105 | sr = 1 << (31-src); | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 106 | raw_spin_lock_irqsave(&uic->lock, flags); | 
| Valentine Barshak | b8b799a | 2007-11-14 07:25:21 +1100 | [diff] [blame] | 107 | er = mfdcr(uic->dcrbase + UIC_ER); | 
|  | 108 | er &= ~sr; | 
|  | 109 | mtdcr(uic->dcrbase + UIC_ER, er); | 
| Valentine Barshak | c809056 | 2007-11-15 01:00:52 +1100 | [diff] [blame] | 110 | /* On the UIC, acking (i.e. clearing the SR bit) | 
|  | 111 | * a level irq will have no effect if the interrupt | 
|  | 112 | * is still asserted by the device, even if | 
|  | 113 | * the interrupt is already masked. Therefore | 
|  | 114 | * we only ack the egde interrupts here, while | 
|  | 115 | * level interrupts are ack'ed after the actual | 
|  | 116 | * isr call in the uic_unmask_irq() | 
|  | 117 | */ | 
| Thomas Gleixner | 1ac06cd | 2011-03-25 16:23:57 +0100 | [diff] [blame] | 118 | if (!irqd_is_level_type(d)) | 
| Valentine Barshak | c809056 | 2007-11-15 01:00:52 +1100 | [diff] [blame] | 119 | mtdcr(uic->dcrbase + UIC_SR, sr); | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 120 | raw_spin_unlock_irqrestore(&uic->lock, flags); | 
| Valentine Barshak | b8b799a | 2007-11-14 07:25:21 +1100 | [diff] [blame] | 121 | } | 
|  | 122 |  | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 123 | static int uic_set_irq_type(struct irq_data *d, unsigned int flow_type) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 124 | { | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 125 | struct uic *uic = irq_data_get_irq_chip_data(d); | 
| Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 126 | unsigned int src = irqd_to_hwirq(d); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 127 | unsigned long flags; | 
|  | 128 | int trigger, polarity; | 
|  | 129 | u32 tr, pr, mask; | 
|  | 130 |  | 
|  | 131 | switch (flow_type & IRQ_TYPE_SENSE_MASK) { | 
|  | 132 | case IRQ_TYPE_NONE: | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 133 | uic_mask_irq(d); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 134 | return 0; | 
|  | 135 |  | 
|  | 136 | case IRQ_TYPE_EDGE_RISING: | 
|  | 137 | trigger = 1; polarity = 1; | 
|  | 138 | break; | 
|  | 139 | case IRQ_TYPE_EDGE_FALLING: | 
|  | 140 | trigger = 1; polarity = 0; | 
|  | 141 | break; | 
|  | 142 | case IRQ_TYPE_LEVEL_HIGH: | 
|  | 143 | trigger = 0; polarity = 1; | 
|  | 144 | break; | 
|  | 145 | case IRQ_TYPE_LEVEL_LOW: | 
|  | 146 | trigger = 0; polarity = 0; | 
|  | 147 | break; | 
|  | 148 | default: | 
|  | 149 | return -EINVAL; | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | mask = ~(1 << (31 - src)); | 
|  | 153 |  | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 154 | raw_spin_lock_irqsave(&uic->lock, flags); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 155 | tr = mfdcr(uic->dcrbase + UIC_TR); | 
|  | 156 | pr = mfdcr(uic->dcrbase + UIC_PR); | 
|  | 157 | tr = (tr & mask) | (trigger << (31-src)); | 
|  | 158 | pr = (pr & mask) | (polarity << (31-src)); | 
|  | 159 |  | 
|  | 160 | mtdcr(uic->dcrbase + UIC_PR, pr); | 
|  | 161 | mtdcr(uic->dcrbase + UIC_TR, tr); | 
|  | 162 |  | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 163 | raw_spin_unlock_irqrestore(&uic->lock, flags); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 164 |  | 
|  | 165 | return 0; | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 | static struct irq_chip uic_irq_chip = { | 
| Anton Blanchard | fc380c0 | 2010-01-31 20:33:41 +0000 | [diff] [blame] | 169 | .name		= "UIC", | 
| Lennert Buytenhek | 42a07ae | 2011-03-08 22:27:02 +0000 | [diff] [blame] | 170 | .irq_unmask	= uic_unmask_irq, | 
|  | 171 | .irq_mask	= uic_mask_irq, | 
|  | 172 | .irq_mask_ack	= uic_mask_ack_irq, | 
|  | 173 | .irq_ack	= uic_ack_irq, | 
|  | 174 | .irq_set_type	= uic_set_irq_type, | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 175 | }; | 
|  | 176 |  | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 177 | static int uic_host_map(struct irq_host *h, unsigned int virq, | 
|  | 178 | irq_hw_number_t hw) | 
|  | 179 | { | 
|  | 180 | struct uic *uic = h->host_data; | 
|  | 181 |  | 
| Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 182 | irq_set_chip_data(virq, uic); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 183 | /* Despite the name, handle_level_irq() works for both level | 
|  | 184 | * and edge irqs on UIC.  FIXME: check this is correct */ | 
| Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 185 | irq_set_chip_and_handler(virq, &uic_irq_chip, handle_level_irq); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 186 |  | 
|  | 187 | /* Set default irq type */ | 
| Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 188 | irq_set_irq_type(virq, IRQ_TYPE_NONE); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 189 |  | 
|  | 190 | return 0; | 
|  | 191 | } | 
|  | 192 |  | 
|  | 193 | static int uic_host_xlate(struct irq_host *h, struct device_node *ct, | 
| Roman Fietze | 40d50cf | 2009-12-08 02:39:50 +0000 | [diff] [blame] | 194 | const u32 *intspec, unsigned int intsize, | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 195 | irq_hw_number_t *out_hwirq, unsigned int *out_type) | 
|  | 196 |  | 
|  | 197 | { | 
|  | 198 | /* UIC intspecs must have 2 cells */ | 
|  | 199 | BUG_ON(intsize != 2); | 
|  | 200 | *out_hwirq = intspec[0]; | 
|  | 201 | *out_type = intspec[1]; | 
|  | 202 | return 0; | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | static struct irq_host_ops uic_host_ops = { | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 206 | .map	= uic_host_map, | 
|  | 207 | .xlate	= uic_host_xlate, | 
|  | 208 | }; | 
|  | 209 |  | 
| Valentine Barshak | 5aac48d | 2007-12-07 00:48:26 +1100 | [diff] [blame] | 210 | void uic_irq_cascade(unsigned int virq, struct irq_desc *desc) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 211 | { | 
| Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 212 | struct irq_chip *chip = irq_desc_get_chip(desc); | 
| Thomas Gleixner | 1ac06cd | 2011-03-25 16:23:57 +0100 | [diff] [blame] | 213 | struct irq_data *idata = irq_desc_get_irq_data(desc); | 
| Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 214 | struct uic *uic = irq_get_handler_data(virq); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 215 | u32 msr; | 
|  | 216 | int src; | 
|  | 217 | int subvirq; | 
|  | 218 |  | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 219 | raw_spin_lock(&desc->lock); | 
| Thomas Gleixner | 1ac06cd | 2011-03-25 16:23:57 +0100 | [diff] [blame] | 220 | if (irqd_is_level_type(idata)) | 
|  | 221 | chip->irq_mask(idata); | 
| Valentine Barshak | 5aac48d | 2007-12-07 00:48:26 +1100 | [diff] [blame] | 222 | else | 
| Thomas Gleixner | 1ac06cd | 2011-03-25 16:23:57 +0100 | [diff] [blame] | 223 | chip->irq_mask_ack(idata); | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 224 | raw_spin_unlock(&desc->lock); | 
| Valentine Barshak | 5aac48d | 2007-12-07 00:48:26 +1100 | [diff] [blame] | 225 |  | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 226 | msr = mfdcr(uic->dcrbase + UIC_MSR); | 
| David Gibson | 553fdff | 2007-08-14 13:52:42 +1000 | [diff] [blame] | 227 | if (!msr) /* spurious interrupt */ | 
| Valentine Barshak | 5aac48d | 2007-12-07 00:48:26 +1100 | [diff] [blame] | 228 | goto uic_irq_ret; | 
| David Gibson | 553fdff | 2007-08-14 13:52:42 +1000 | [diff] [blame] | 229 |  | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 230 | src = 32 - ffs(msr); | 
|  | 231 |  | 
|  | 232 | subvirq = irq_linear_revmap(uic->irqhost, src); | 
|  | 233 | generic_handle_irq(subvirq); | 
|  | 234 |  | 
| Valentine Barshak | 5aac48d | 2007-12-07 00:48:26 +1100 | [diff] [blame] | 235 | uic_irq_ret: | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 236 | raw_spin_lock(&desc->lock); | 
| Thomas Gleixner | 1ac06cd | 2011-03-25 16:23:57 +0100 | [diff] [blame] | 237 | if (irqd_is_level_type(idata)) | 
|  | 238 | chip->irq_ack(idata); | 
|  | 239 | if (!irqd_irq_disabled(idata) && chip->irq_unmask) | 
|  | 240 | chip->irq_unmask(idata); | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 241 | raw_spin_unlock(&desc->lock); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
|  | 244 | static struct uic * __init uic_init_one(struct device_node *node) | 
|  | 245 | { | 
|  | 246 | struct uic *uic; | 
|  | 247 | const u32 *indexp, *dcrreg; | 
|  | 248 | int len; | 
|  | 249 |  | 
| Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 250 | BUG_ON(! of_device_is_compatible(node, "ibm,uic")); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 251 |  | 
| Anton Vorontsov | ea96025 | 2009-07-01 10:59:57 +0000 | [diff] [blame] | 252 | uic = kzalloc(sizeof(*uic), GFP_KERNEL); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 253 | if (! uic) | 
|  | 254 | return NULL; /* FIXME: panic? */ | 
|  | 255 |  | 
| Thomas Gleixner | bccc2f7 | 2010-04-06 09:44:10 +0200 | [diff] [blame] | 256 | raw_spin_lock_init(&uic->lock); | 
| Stephen Rothwell | 12d371a | 2007-04-29 16:29:08 +1000 | [diff] [blame] | 257 | indexp = of_get_property(node, "cell-index", &len); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 258 | if (!indexp || (len != sizeof(u32))) { | 
|  | 259 | printk(KERN_ERR "uic: Device node %s has missing or invalid " | 
|  | 260 | "cell-index property\n", node->full_name); | 
|  | 261 | return NULL; | 
|  | 262 | } | 
|  | 263 | uic->index = *indexp; | 
|  | 264 |  | 
| Stephen Rothwell | 12d371a | 2007-04-29 16:29:08 +1000 | [diff] [blame] | 265 | dcrreg = of_get_property(node, "dcr-reg", &len); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 266 | if (!dcrreg || (len != 2*sizeof(u32))) { | 
|  | 267 | printk(KERN_ERR "uic: Device node %s has missing or invalid " | 
|  | 268 | "dcr-reg property\n", node->full_name); | 
|  | 269 | return NULL; | 
|  | 270 | } | 
|  | 271 | uic->dcrbase = *dcrreg; | 
|  | 272 |  | 
| Michael Ellerman | 19fc65b | 2008-05-26 12:12:32 +1000 | [diff] [blame] | 273 | uic->irqhost = irq_alloc_host(node, IRQ_HOST_MAP_LINEAR, | 
| Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 274 | NR_UIC_INTS, &uic_host_ops, -1); | 
| Michael Ellerman | 19fc65b | 2008-05-26 12:12:32 +1000 | [diff] [blame] | 275 | if (! uic->irqhost) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 276 | return NULL; /* FIXME: panic? */ | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 277 |  | 
|  | 278 | uic->irqhost->host_data = uic; | 
|  | 279 |  | 
|  | 280 | /* Start with all interrupts disabled, level and non-critical */ | 
|  | 281 | mtdcr(uic->dcrbase + UIC_ER, 0); | 
|  | 282 | mtdcr(uic->dcrbase + UIC_CR, 0); | 
|  | 283 | mtdcr(uic->dcrbase + UIC_TR, 0); | 
|  | 284 | /* Clear any pending interrupts, in case the firmware left some */ | 
|  | 285 | mtdcr(uic->dcrbase + UIC_SR, 0xffffffff); | 
|  | 286 |  | 
|  | 287 | printk ("UIC%d (%d IRQ sources) at DCR 0x%x\n", uic->index, | 
|  | 288 | NR_UIC_INTS, uic->dcrbase); | 
|  | 289 |  | 
|  | 290 | return uic; | 
|  | 291 | } | 
|  | 292 |  | 
|  | 293 | void __init uic_init_tree(void) | 
|  | 294 | { | 
|  | 295 | struct device_node *np; | 
|  | 296 | struct uic *uic; | 
|  | 297 | const u32 *interrupts; | 
|  | 298 |  | 
|  | 299 | /* First locate and initialize the top-level UIC */ | 
| Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 300 | for_each_compatible_node(np, NULL, "ibm,uic") { | 
| Stephen Rothwell | 12d371a | 2007-04-29 16:29:08 +1000 | [diff] [blame] | 301 | interrupts = of_get_property(np, "interrupts", NULL); | 
| Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 302 | if (!interrupts) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 303 | break; | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 304 | } | 
|  | 305 |  | 
|  | 306 | BUG_ON(!np); /* uic_init_tree() assumes there's a UIC as the | 
|  | 307 | * top-level interrupt controller */ | 
|  | 308 | primary_uic = uic_init_one(np); | 
| Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 309 | if (!primary_uic) | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 310 | panic("Unable to initialize primary UIC %s\n", np->full_name); | 
|  | 311 |  | 
|  | 312 | irq_set_default_host(primary_uic->irqhost); | 
|  | 313 | of_node_put(np); | 
|  | 314 |  | 
|  | 315 | /* The scan again for cascaded UICs */ | 
| Cyrill Gorcunov | 26cb7d8 | 2007-11-30 06:44:36 +1100 | [diff] [blame] | 316 | for_each_compatible_node(np, NULL, "ibm,uic") { | 
| Stephen Rothwell | 12d371a | 2007-04-29 16:29:08 +1000 | [diff] [blame] | 317 | interrupts = of_get_property(np, "interrupts", NULL); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 318 | if (interrupts) { | 
|  | 319 | /* Secondary UIC */ | 
|  | 320 | int cascade_virq; | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 321 |  | 
|  | 322 | uic = uic_init_one(np); | 
|  | 323 | if (! uic) | 
|  | 324 | panic("Unable to initialize a secondary UIC %s\n", | 
|  | 325 | np->full_name); | 
|  | 326 |  | 
|  | 327 | cascade_virq = irq_of_parse_and_map(np, 0); | 
|  | 328 |  | 
| Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 329 | irq_set_handler_data(cascade_virq, uic); | 
|  | 330 | irq_set_chained_handler(cascade_virq, uic_irq_cascade); | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 331 |  | 
|  | 332 | /* FIXME: setup critical cascade?? */ | 
|  | 333 | } | 
| David Gibson | e58923e | 2007-04-18 16:36:26 +1000 | [diff] [blame] | 334 | } | 
|  | 335 | } | 
|  | 336 |  | 
|  | 337 | /* Return an interrupt vector or NO_IRQ if no interrupt is pending. */ | 
|  | 338 | unsigned int uic_get_irq(void) | 
|  | 339 | { | 
|  | 340 | u32 msr; | 
|  | 341 | int src; | 
|  | 342 |  | 
|  | 343 | BUG_ON(! primary_uic); | 
|  | 344 |  | 
|  | 345 | msr = mfdcr(primary_uic->dcrbase + UIC_MSR); | 
|  | 346 | src = 32 - ffs(msr); | 
|  | 347 |  | 
|  | 348 | return irq_linear_revmap(primary_uic->irqhost, src); | 
|  | 349 | } |