Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Support for the interrupt controllers found on Power Macintosh, |
| 3 | * currently Apple's "Grand Central" interrupt controller in all |
| 4 | * it's incarnations. OpenPIC support used on newer machines is |
| 5 | * in a separate file |
| 6 | * |
| 7 | * Copyright (C) 1997 Paul Mackerras (paulus@samba.org) |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 8 | * Copyright (C) 2005 Benjamin Herrenschmidt (benh@kernel.crashing.org) |
| 9 | * IBM, Corp. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version |
| 14 | * 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/config.h> |
| 19 | #include <linux/stddef.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/signal.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/sysdev.h> |
| 26 | #include <linux/adb.h> |
| 27 | #include <linux/pmu.h> |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 28 | #include <linux/module.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 29 | |
| 30 | #include <asm/sections.h> |
| 31 | #include <asm/io.h> |
| 32 | #include <asm/smp.h> |
| 33 | #include <asm/prom.h> |
| 34 | #include <asm/pci-bridge.h> |
| 35 | #include <asm/time.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 36 | #include <asm/pmac_feature.h> |
| 37 | #include <asm/mpic.h> |
| 38 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 39 | #include "pmac.h" |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * XXX this should be in xmon.h, but putting it there means xmon.h |
| 43 | * has to include <linux/interrupt.h> (to get irqreturn_t), which |
| 44 | * causes all sorts of problems. -- paulus |
| 45 | */ |
| 46 | extern irqreturn_t xmon_irq(int, void *, struct pt_regs *); |
| 47 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 48 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 49 | struct pmac_irq_hw { |
| 50 | unsigned int event; |
| 51 | unsigned int enable; |
| 52 | unsigned int ack; |
| 53 | unsigned int level; |
| 54 | }; |
| 55 | |
| 56 | /* Default addresses */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 57 | static volatile struct pmac_irq_hw __iomem *pmac_irq_hw[4]; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 58 | |
| 59 | #define GC_LEVEL_MASK 0x3ff00000 |
| 60 | #define OHARE_LEVEL_MASK 0x1ff00000 |
| 61 | #define HEATHROW_LEVEL_MASK 0x1ff00000 |
| 62 | |
| 63 | static int max_irqs; |
| 64 | static int max_real_irqs; |
| 65 | static u32 level_mask[4]; |
| 66 | |
| 67 | static DEFINE_SPINLOCK(pmac_pic_lock); |
| 68 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 69 | #define GATWICK_IRQ_POOL_SIZE 10 |
| 70 | static struct interrupt_info gatwick_int_pool[GATWICK_IRQ_POOL_SIZE]; |
| 71 | |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 72 | #define NR_MASK_WORDS ((NR_IRQS + 31) / 32) |
| 73 | static unsigned long ppc_lost_interrupts[NR_MASK_WORDS]; |
| 74 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 75 | /* |
| 76 | * Mark an irq as "lost". This is only used on the pmac |
| 77 | * since it can lose interrupts (see pmac_set_irq_mask). |
| 78 | * -- Cort |
| 79 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 80 | void __set_lost(unsigned long irq_nr, int nokick) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 81 | { |
| 82 | if (!test_and_set_bit(irq_nr, ppc_lost_interrupts)) { |
| 83 | atomic_inc(&ppc_n_lost_interrupts); |
| 84 | if (!nokick) |
| 85 | set_dec(1); |
| 86 | } |
| 87 | } |
| 88 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 89 | static void pmac_mask_and_ack_irq(unsigned int irq_nr) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 90 | { |
| 91 | unsigned long bit = 1UL << (irq_nr & 0x1f); |
| 92 | int i = irq_nr >> 5; |
| 93 | unsigned long flags; |
| 94 | |
| 95 | if ((unsigned)irq_nr >= max_irqs) |
| 96 | return; |
| 97 | |
| 98 | clear_bit(irq_nr, ppc_cached_irq_mask); |
| 99 | if (test_and_clear_bit(irq_nr, ppc_lost_interrupts)) |
| 100 | atomic_dec(&ppc_n_lost_interrupts); |
| 101 | spin_lock_irqsave(&pmac_pic_lock, flags); |
| 102 | out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]); |
| 103 | out_le32(&pmac_irq_hw[i]->ack, bit); |
| 104 | do { |
| 105 | /* make sure ack gets to controller before we enable |
| 106 | interrupts */ |
| 107 | mb(); |
| 108 | } while((in_le32(&pmac_irq_hw[i]->enable) & bit) |
| 109 | != (ppc_cached_irq_mask[i] & bit)); |
| 110 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
| 111 | } |
| 112 | |
| 113 | static void pmac_set_irq_mask(unsigned int irq_nr, int nokicklost) |
| 114 | { |
| 115 | unsigned long bit = 1UL << (irq_nr & 0x1f); |
| 116 | int i = irq_nr >> 5; |
| 117 | unsigned long flags; |
| 118 | |
| 119 | if ((unsigned)irq_nr >= max_irqs) |
| 120 | return; |
| 121 | |
| 122 | spin_lock_irqsave(&pmac_pic_lock, flags); |
| 123 | /* enable unmasked interrupts */ |
| 124 | out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]); |
| 125 | |
| 126 | do { |
| 127 | /* make sure mask gets to controller before we |
| 128 | return to user */ |
| 129 | mb(); |
| 130 | } while((in_le32(&pmac_irq_hw[i]->enable) & bit) |
| 131 | != (ppc_cached_irq_mask[i] & bit)); |
| 132 | |
| 133 | /* |
| 134 | * Unfortunately, setting the bit in the enable register |
| 135 | * when the device interrupt is already on *doesn't* set |
| 136 | * the bit in the flag register or request another interrupt. |
| 137 | */ |
| 138 | if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level)) |
| 139 | __set_lost((ulong)irq_nr, nokicklost); |
| 140 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
| 141 | } |
| 142 | |
| 143 | /* When an irq gets requested for the first client, if it's an |
| 144 | * edge interrupt, we clear any previous one on the controller |
| 145 | */ |
| 146 | static unsigned int pmac_startup_irq(unsigned int irq_nr) |
| 147 | { |
| 148 | unsigned long bit = 1UL << (irq_nr & 0x1f); |
| 149 | int i = irq_nr >> 5; |
| 150 | |
| 151 | if ((irq_desc[irq_nr].status & IRQ_LEVEL) == 0) |
| 152 | out_le32(&pmac_irq_hw[i]->ack, bit); |
| 153 | set_bit(irq_nr, ppc_cached_irq_mask); |
| 154 | pmac_set_irq_mask(irq_nr, 0); |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static void pmac_mask_irq(unsigned int irq_nr) |
| 160 | { |
| 161 | clear_bit(irq_nr, ppc_cached_irq_mask); |
| 162 | pmac_set_irq_mask(irq_nr, 0); |
| 163 | mb(); |
| 164 | } |
| 165 | |
| 166 | static void pmac_unmask_irq(unsigned int irq_nr) |
| 167 | { |
| 168 | set_bit(irq_nr, ppc_cached_irq_mask); |
| 169 | pmac_set_irq_mask(irq_nr, 0); |
| 170 | } |
| 171 | |
| 172 | static void pmac_end_irq(unsigned int irq_nr) |
| 173 | { |
| 174 | if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS)) |
| 175 | && irq_desc[irq_nr].action) { |
| 176 | set_bit(irq_nr, ppc_cached_irq_mask); |
| 177 | pmac_set_irq_mask(irq_nr, 1); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | |
| 182 | struct hw_interrupt_type pmac_pic = { |
| 183 | .typename = " PMAC-PIC ", |
| 184 | .startup = pmac_startup_irq, |
| 185 | .enable = pmac_unmask_irq, |
| 186 | .disable = pmac_mask_irq, |
| 187 | .ack = pmac_mask_and_ack_irq, |
| 188 | .end = pmac_end_irq, |
| 189 | }; |
| 190 | |
| 191 | struct hw_interrupt_type gatwick_pic = { |
| 192 | .typename = " GATWICK ", |
| 193 | .startup = pmac_startup_irq, |
| 194 | .enable = pmac_unmask_irq, |
| 195 | .disable = pmac_mask_irq, |
| 196 | .ack = pmac_mask_and_ack_irq, |
| 197 | .end = pmac_end_irq, |
| 198 | }; |
| 199 | |
| 200 | static irqreturn_t gatwick_action(int cpl, void *dev_id, struct pt_regs *regs) |
| 201 | { |
| 202 | int irq, bits; |
| 203 | |
| 204 | for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) { |
| 205 | int i = irq >> 5; |
| 206 | bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i]; |
| 207 | /* We must read level interrupts from the level register */ |
| 208 | bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]); |
| 209 | bits &= ppc_cached_irq_mask[i]; |
| 210 | if (bits == 0) |
| 211 | continue; |
| 212 | irq += __ilog2(bits); |
| 213 | __do_IRQ(irq, regs); |
| 214 | return IRQ_HANDLED; |
| 215 | } |
| 216 | printk("gatwick irq not from gatwick pic\n"); |
| 217 | return IRQ_NONE; |
| 218 | } |
| 219 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 220 | static int pmac_get_irq(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 221 | { |
| 222 | int irq; |
| 223 | unsigned long bits = 0; |
| 224 | |
| 225 | #ifdef CONFIG_SMP |
| 226 | void psurge_smp_message_recv(struct pt_regs *); |
| 227 | |
| 228 | /* IPI's are a hack on the powersurge -- Cort */ |
| 229 | if ( smp_processor_id() != 0 ) { |
| 230 | psurge_smp_message_recv(regs); |
| 231 | return -2; /* ignore, already handled */ |
| 232 | } |
| 233 | #endif /* CONFIG_SMP */ |
| 234 | for (irq = max_real_irqs; (irq -= 32) >= 0; ) { |
| 235 | int i = irq >> 5; |
| 236 | bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i]; |
| 237 | /* We must read level interrupts from the level register */ |
| 238 | bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]); |
| 239 | bits &= ppc_cached_irq_mask[i]; |
| 240 | if (bits == 0) |
| 241 | continue; |
| 242 | irq += __ilog2(bits); |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | return irq; |
| 247 | } |
| 248 | |
| 249 | /* This routine will fix some missing interrupt values in the device tree |
| 250 | * on the gatwick mac-io controller used by some PowerBooks |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 251 | * |
| 252 | * Walking of OF nodes could use a bit more fixing up here, but it's not |
| 253 | * very important as this is all boot time code on static portions of the |
| 254 | * device-tree. |
| 255 | * |
| 256 | * However, the modifications done to "intrs" will have to be removed and |
| 257 | * replaced with proper updates of the "interrupts" properties or |
| 258 | * AAPL,interrupts, yet to be decided, once the dynamic parsing is there. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 259 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 260 | static void __init pmac_fix_gatwick_interrupts(struct device_node *gw, |
| 261 | int irq_base) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 262 | { |
| 263 | struct device_node *node; |
| 264 | int count; |
| 265 | |
| 266 | memset(gatwick_int_pool, 0, sizeof(gatwick_int_pool)); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 267 | count = 0; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 268 | for (node = NULL; (node = of_get_next_child(gw, node)) != NULL;) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 269 | /* Fix SCC */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 270 | if ((strcasecmp(node->name, "escc") == 0) && node->child) { |
| 271 | if (node->child->n_intrs < 3) { |
| 272 | node->child->intrs = &gatwick_int_pool[count]; |
| 273 | count += 3; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 274 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 275 | node->child->n_intrs = 3; |
| 276 | node->child->intrs[0].line = 15+irq_base; |
| 277 | node->child->intrs[1].line = 4+irq_base; |
| 278 | node->child->intrs[2].line = 5+irq_base; |
| 279 | printk(KERN_INFO "irq: fixed SCC on gatwick" |
| 280 | " (%d,%d,%d)\n", |
| 281 | node->child->intrs[0].line, |
| 282 | node->child->intrs[1].line, |
| 283 | node->child->intrs[2].line); |
| 284 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 285 | /* Fix media-bay & left SWIM */ |
| 286 | if (strcasecmp(node->name, "media-bay") == 0) { |
| 287 | struct device_node* ya_node; |
| 288 | |
| 289 | if (node->n_intrs == 0) |
| 290 | node->intrs = &gatwick_int_pool[count++]; |
| 291 | node->n_intrs = 1; |
| 292 | node->intrs[0].line = 29+irq_base; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 293 | printk(KERN_INFO "irq: fixed media-bay on gatwick" |
| 294 | " (%d)\n", node->intrs[0].line); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 295 | |
| 296 | ya_node = node->child; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 297 | while(ya_node) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 298 | if (strcasecmp(ya_node->name, "floppy") == 0) { |
| 299 | if (ya_node->n_intrs < 2) { |
| 300 | ya_node->intrs = &gatwick_int_pool[count]; |
| 301 | count += 2; |
| 302 | } |
| 303 | ya_node->n_intrs = 2; |
| 304 | ya_node->intrs[0].line = 19+irq_base; |
| 305 | ya_node->intrs[1].line = 1+irq_base; |
| 306 | printk(KERN_INFO "irq: fixed floppy on second controller (%d,%d)\n", |
| 307 | ya_node->intrs[0].line, ya_node->intrs[1].line); |
| 308 | } |
| 309 | if (strcasecmp(ya_node->name, "ata4") == 0) { |
| 310 | if (ya_node->n_intrs < 2) { |
| 311 | ya_node->intrs = &gatwick_int_pool[count]; |
| 312 | count += 2; |
| 313 | } |
| 314 | ya_node->n_intrs = 2; |
| 315 | ya_node->intrs[0].line = 14+irq_base; |
| 316 | ya_node->intrs[1].line = 3+irq_base; |
| 317 | printk(KERN_INFO "irq: fixed ide on second controller (%d,%d)\n", |
| 318 | ya_node->intrs[0].line, ya_node->intrs[1].line); |
| 319 | } |
| 320 | ya_node = ya_node->sibling; |
| 321 | } |
| 322 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 323 | } |
| 324 | if (count > 10) { |
| 325 | printk("WARNING !! Gatwick interrupt pool overflow\n"); |
| 326 | printk(" GATWICK_IRQ_POOL_SIZE = %d\n", GATWICK_IRQ_POOL_SIZE); |
| 327 | printk(" requested = %d\n", count); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * The PowerBook 3400/2400/3500 can have a combo ethernet/modem |
| 333 | * card which includes an ohare chip that acts as a second interrupt |
| 334 | * controller. If we find this second ohare, set it up and fix the |
| 335 | * interrupt value in the device tree for the ethernet chip. |
| 336 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 337 | static void __init enable_second_ohare(struct device_node *np) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 338 | { |
| 339 | unsigned char bus, devfn; |
| 340 | unsigned short cmd; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 341 | struct device_node *ether; |
| 342 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 343 | /* This code doesn't strictly belong here, it could be part of |
| 344 | * either the PCI initialisation or the feature code. It's kept |
| 345 | * here for historical reasons. |
| 346 | */ |
| 347 | if (pci_device_from_OF_node(np, &bus, &devfn) == 0) { |
| 348 | struct pci_controller* hose = |
| 349 | pci_find_hose_for_OF_device(np); |
| 350 | if (!hose) { |
| 351 | printk(KERN_ERR "Can't find PCI hose for OHare2 !\n"); |
| 352 | return; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 353 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 354 | early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd); |
| 355 | cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
| 356 | cmd &= ~PCI_COMMAND_IO; |
| 357 | early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /* Fix interrupt for the modem/ethernet combo controller. The number |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 361 | * in the device tree (27) is bogus (correct for the ethernet-only |
| 362 | * board but not the combo ethernet/modem board). |
| 363 | * The real interrupt is 28 on the second controller -> 28+32 = 60. |
| 364 | */ |
| 365 | ether = of_find_node_by_name(NULL, "pci1011,14"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 366 | if (ether && ether->n_intrs > 0) { |
| 367 | ether->intrs[0].line = 60; |
| 368 | printk(KERN_INFO "irq: Fixed ethernet IRQ to %d\n", |
| 369 | ether->intrs[0].line); |
| 370 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 371 | of_node_put(ether); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 372 | } |
| 373 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 374 | #ifdef CONFIG_XMON |
| 375 | static struct irqaction xmon_action = { |
| 376 | .handler = xmon_irq, |
| 377 | .flags = 0, |
| 378 | .mask = CPU_MASK_NONE, |
| 379 | .name = "NMI - XMON" |
| 380 | }; |
| 381 | #endif |
| 382 | |
| 383 | static struct irqaction gatwick_cascade_action = { |
| 384 | .handler = gatwick_action, |
| 385 | .flags = SA_INTERRUPT, |
| 386 | .mask = CPU_MASK_NONE, |
| 387 | .name = "cascade", |
| 388 | }; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 389 | |
| 390 | static void __init pmac_pic_probe_oldstyle(void) |
| 391 | { |
| 392 | int i; |
| 393 | int irq_cascade = -1; |
| 394 | struct device_node *master = NULL; |
| 395 | struct device_node *slave = NULL; |
| 396 | u8 __iomem *addr; |
| 397 | struct resource r; |
| 398 | |
| 399 | /* Set our get_irq function */ |
| 400 | ppc_md.get_irq = pmac_get_irq; |
| 401 | |
| 402 | /* |
| 403 | * Find the interrupt controller type & node |
| 404 | */ |
| 405 | |
| 406 | if ((master = of_find_node_by_name(NULL, "gc")) != NULL) { |
| 407 | max_irqs = max_real_irqs = 32; |
| 408 | level_mask[0] = GC_LEVEL_MASK; |
| 409 | } else if ((master = of_find_node_by_name(NULL, "ohare")) != NULL) { |
| 410 | max_irqs = max_real_irqs = 32; |
| 411 | level_mask[0] = OHARE_LEVEL_MASK; |
| 412 | |
| 413 | /* We might have a second cascaded ohare */ |
| 414 | slave = of_find_node_by_name(NULL, "pci106b,7"); |
| 415 | if (slave) { |
| 416 | max_irqs = 64; |
| 417 | level_mask[1] = OHARE_LEVEL_MASK; |
| 418 | enable_second_ohare(slave); |
| 419 | } |
| 420 | } else if ((master = of_find_node_by_name(NULL, "mac-io")) != NULL) { |
| 421 | max_irqs = max_real_irqs = 64; |
| 422 | level_mask[0] = HEATHROW_LEVEL_MASK; |
| 423 | level_mask[1] = 0; |
| 424 | |
| 425 | /* We might have a second cascaded heathrow */ |
| 426 | slave = of_find_node_by_name(master, "mac-io"); |
| 427 | |
| 428 | /* Check ordering of master & slave */ |
| 429 | if (device_is_compatible(master, "gatwick")) { |
| 430 | struct device_node *tmp; |
| 431 | BUG_ON(slave == NULL); |
| 432 | tmp = master; |
| 433 | master = slave; |
| 434 | slave = tmp; |
| 435 | } |
| 436 | |
| 437 | /* We found a slave */ |
| 438 | if (slave) { |
| 439 | max_irqs = 128; |
| 440 | level_mask[2] = HEATHROW_LEVEL_MASK; |
| 441 | level_mask[3] = 0; |
| 442 | pmac_fix_gatwick_interrupts(slave, max_real_irqs); |
| 443 | } |
| 444 | } |
| 445 | BUG_ON(master == NULL); |
| 446 | |
| 447 | /* Set the handler for the main PIC */ |
| 448 | for ( i = 0; i < max_real_irqs ; i++ ) |
| 449 | irq_desc[i].handler = &pmac_pic; |
| 450 | |
| 451 | /* Get addresses of first controller if we have a node for it */ |
| 452 | BUG_ON(of_address_to_resource(master, 0, &r)); |
| 453 | |
| 454 | /* Map interrupts of primary controller */ |
| 455 | addr = (u8 __iomem *) ioremap(r.start, 0x40); |
| 456 | i = 0; |
| 457 | pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *) |
| 458 | (addr + 0x20); |
| 459 | if (max_real_irqs > 32) |
| 460 | pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *) |
| 461 | (addr + 0x10); |
| 462 | of_node_put(master); |
| 463 | |
| 464 | printk(KERN_INFO "irq: Found primary Apple PIC %s for %d irqs\n", |
| 465 | master->full_name, max_real_irqs); |
| 466 | |
| 467 | /* Map interrupts of cascaded controller */ |
| 468 | if (slave && !of_address_to_resource(slave, 0, &r)) { |
| 469 | addr = (u8 __iomem *)ioremap(r.start, 0x40); |
| 470 | pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *) |
| 471 | (addr + 0x20); |
| 472 | if (max_irqs > 64) |
| 473 | pmac_irq_hw[i++] = |
| 474 | (volatile struct pmac_irq_hw __iomem *) |
| 475 | (addr + 0x10); |
| 476 | irq_cascade = slave->intrs[0].line; |
| 477 | |
| 478 | printk(KERN_INFO "irq: Found slave Apple PIC %s for %d irqs" |
| 479 | " cascade: %d\n", slave->full_name, |
| 480 | max_irqs - max_real_irqs, irq_cascade); |
| 481 | } |
| 482 | of_node_put(slave); |
| 483 | |
| 484 | /* disable all interrupts in all controllers */ |
| 485 | for (i = 0; i * 32 < max_irqs; ++i) |
| 486 | out_le32(&pmac_irq_hw[i]->enable, 0); |
| 487 | |
| 488 | /* mark level interrupts */ |
| 489 | for (i = 0; i < max_irqs; i++) |
| 490 | if (level_mask[i >> 5] & (1UL << (i & 0x1f))) |
| 491 | irq_desc[i].status = IRQ_LEVEL; |
| 492 | |
| 493 | /* Setup handlers for secondary controller and hook cascade irq*/ |
| 494 | if (slave) { |
| 495 | for ( i = max_real_irqs ; i < max_irqs ; i++ ) |
| 496 | irq_desc[i].handler = &gatwick_pic; |
| 497 | setup_irq(irq_cascade, &gatwick_cascade_action); |
| 498 | } |
| 499 | printk(KERN_INFO "irq: System has %d possible interrupts\n", max_irqs); |
| 500 | #ifdef CONFIG_XMON |
| 501 | setup_irq(20, &xmon_action); |
| 502 | #endif |
| 503 | } |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 504 | #endif /* CONFIG_PPC32 */ |
| 505 | |
| 506 | static int pmac_u3_cascade(struct pt_regs *regs, void *data) |
| 507 | { |
| 508 | return mpic_get_one_irq((struct mpic *)data, regs); |
| 509 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 510 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 511 | static void __init pmac_pic_setup_mpic_nmi(struct mpic *mpic) |
| 512 | { |
| 513 | #if defined(CONFIG_XMON) && defined(CONFIG_PPC32) |
| 514 | struct device_node* pswitch; |
| 515 | int nmi_irq; |
| 516 | |
| 517 | pswitch = of_find_node_by_name(NULL, "programmer-switch"); |
| 518 | if (pswitch && pswitch->n_intrs) { |
| 519 | nmi_irq = pswitch->intrs[0].line; |
| 520 | mpic_irq_set_priority(nmi_irq, 9); |
| 521 | setup_irq(nmi_irq, &xmon_action); |
| 522 | } |
| 523 | of_node_put(pswitch); |
| 524 | #endif /* defined(CONFIG_XMON) && defined(CONFIG_PPC32) */ |
| 525 | } |
| 526 | |
| 527 | static int __init pmac_pic_probe_mpic(void) |
| 528 | { |
| 529 | struct mpic *mpic1, *mpic2; |
| 530 | struct device_node *np, *master = NULL, *slave = NULL; |
| 531 | unsigned char senses[128]; |
| 532 | struct resource r; |
| 533 | |
| 534 | /* We can have up to 2 MPICs cascaded */ |
| 535 | for (np = NULL; (np = of_find_node_by_type(np, "open-pic")) |
| 536 | != NULL;) { |
| 537 | if (master == NULL && |
| 538 | get_property(np, "interrupt-parent", NULL) != NULL) |
| 539 | master = of_node_get(np); |
| 540 | else if (slave == NULL) |
| 541 | slave = of_node_get(np); |
| 542 | if (master && slave) |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | /* Check for bogus setups */ |
| 547 | if (master == NULL && slave != NULL) { |
| 548 | master = slave; |
| 549 | slave = NULL; |
| 550 | } |
| 551 | |
| 552 | /* Not found, default to good old pmac pic */ |
| 553 | if (master == NULL) |
| 554 | return -ENODEV; |
| 555 | |
| 556 | /* Set master handler */ |
| 557 | ppc_md.get_irq = mpic_get_irq; |
| 558 | |
| 559 | /* Setup master */ |
| 560 | BUG_ON(of_address_to_resource(master, 0, &r)); |
| 561 | pmac_call_feature(PMAC_FTR_ENABLE_MPIC, master, 0, 0); |
| 562 | prom_get_irq_senses(senses, 0, 128); |
| 563 | mpic1 = mpic_alloc(r.start, MPIC_PRIMARY | MPIC_WANTS_RESET, |
| 564 | 0, 0, 128, 252, senses, 128, " OpenPIC "); |
| 565 | BUG_ON(mpic1 == NULL); |
| 566 | mpic_init(mpic1); |
| 567 | |
| 568 | /* Install NMI if any */ |
| 569 | pmac_pic_setup_mpic_nmi(mpic1); |
| 570 | |
| 571 | of_node_put(master); |
| 572 | |
| 573 | /* No slave, let's go out */ |
| 574 | if (slave == NULL || slave->n_intrs < 1) |
| 575 | return 0; |
| 576 | |
| 577 | /* Setup slave, failures are non-fatal */ |
| 578 | if (of_address_to_resource(slave, 0, &r)) { |
| 579 | printk(KERN_ERR "Can't get address of MPIC %s\n", |
| 580 | slave->full_name); |
| 581 | return 0; |
| 582 | } |
| 583 | pmac_call_feature(PMAC_FTR_ENABLE_MPIC, slave, 0, 0); |
| 584 | prom_get_irq_senses(senses, 128, 128 + 124); |
| 585 | |
| 586 | /* We don't need to set MPIC_BROKEN_U3 here since we don't have |
| 587 | * hypertransport interrupts routed to it, at least not on currently |
| 588 | * supported machines, that may change. |
| 589 | */ |
| 590 | mpic2 = mpic_alloc(r.start, MPIC_BIG_ENDIAN | MPIC_WANTS_RESET, |
| 591 | 0, 128, 124, 0, senses, 124, " U3-MPIC "); |
| 592 | if (mpic2 == NULL) { |
| 593 | printk(KERN_ERR "Can't create slave MPIC %s\n", |
| 594 | slave->full_name); |
| 595 | return 0; |
| 596 | } |
| 597 | mpic_init(mpic2); |
| 598 | mpic_setup_cascade(slave->intrs[0].line, pmac_u3_cascade, mpic2); |
| 599 | |
| 600 | of_node_put(slave); |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 605 | void __init pmac_pic_init(void) |
| 606 | { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 607 | /* We first try to detect Apple's new Core99 chipset, since mac-io |
| 608 | * is quite different on those machines and contains an IBM MPIC2. |
| 609 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 610 | if (pmac_pic_probe_mpic() == 0) |
Paul Mackerras | 20c8c21 | 2005-09-28 20:28:14 +1000 | [diff] [blame] | 611 | return; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 612 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 613 | #ifdef CONFIG_PPC32 |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame^] | 614 | pmac_pic_probe_oldstyle(); |
| 615 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 616 | } |
| 617 | |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 618 | #if defined(CONFIG_PM) && defined(CONFIG_PPC32) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 619 | /* |
| 620 | * These procedures are used in implementing sleep on the powerbooks. |
| 621 | * sleep_save_intrs() saves the states of all interrupt enables |
| 622 | * and disables all interrupts except for the nominated one. |
| 623 | * sleep_restore_intrs() restores the states of all interrupt enables. |
| 624 | */ |
| 625 | unsigned long sleep_save_mask[2]; |
| 626 | |
| 627 | /* This used to be passed by the PMU driver but that link got |
| 628 | * broken with the new driver model. We use this tweak for now... |
| 629 | */ |
| 630 | static int pmacpic_find_viaint(void) |
| 631 | { |
| 632 | int viaint = -1; |
| 633 | |
| 634 | #ifdef CONFIG_ADB_PMU |
| 635 | struct device_node *np; |
| 636 | |
| 637 | if (pmu_get_model() != PMU_OHARE_BASED) |
| 638 | goto not_found; |
| 639 | np = of_find_node_by_name(NULL, "via-pmu"); |
| 640 | if (np == NULL) |
| 641 | goto not_found; |
| 642 | viaint = np->intrs[0].line; |
| 643 | #endif /* CONFIG_ADB_PMU */ |
| 644 | |
| 645 | not_found: |
| 646 | return viaint; |
| 647 | } |
| 648 | |
| 649 | static int pmacpic_suspend(struct sys_device *sysdev, pm_message_t state) |
| 650 | { |
| 651 | int viaint = pmacpic_find_viaint(); |
| 652 | |
| 653 | sleep_save_mask[0] = ppc_cached_irq_mask[0]; |
| 654 | sleep_save_mask[1] = ppc_cached_irq_mask[1]; |
| 655 | ppc_cached_irq_mask[0] = 0; |
| 656 | ppc_cached_irq_mask[1] = 0; |
| 657 | if (viaint > 0) |
| 658 | set_bit(viaint, ppc_cached_irq_mask); |
| 659 | out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]); |
| 660 | if (max_real_irqs > 32) |
| 661 | out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]); |
| 662 | (void)in_le32(&pmac_irq_hw[0]->event); |
| 663 | /* make sure mask gets to controller before we return to caller */ |
| 664 | mb(); |
| 665 | (void)in_le32(&pmac_irq_hw[0]->enable); |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | static int pmacpic_resume(struct sys_device *sysdev) |
| 671 | { |
| 672 | int i; |
| 673 | |
| 674 | out_le32(&pmac_irq_hw[0]->enable, 0); |
| 675 | if (max_real_irqs > 32) |
| 676 | out_le32(&pmac_irq_hw[1]->enable, 0); |
| 677 | mb(); |
| 678 | for (i = 0; i < max_real_irqs; ++i) |
| 679 | if (test_bit(i, sleep_save_mask)) |
| 680 | pmac_unmask_irq(i); |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 685 | #endif /* CONFIG_PM && CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 686 | |
| 687 | static struct sysdev_class pmacpic_sysclass = { |
| 688 | set_kset_name("pmac_pic"), |
| 689 | }; |
| 690 | |
| 691 | static struct sys_device device_pmacpic = { |
| 692 | .id = 0, |
| 693 | .cls = &pmacpic_sysclass, |
| 694 | }; |
| 695 | |
| 696 | static struct sysdev_driver driver_pmacpic = { |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 697 | #if defined(CONFIG_PM) && defined(CONFIG_PPC32) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 698 | .suspend = &pmacpic_suspend, |
| 699 | .resume = &pmacpic_resume, |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 700 | #endif /* CONFIG_PM && CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | static int __init init_pmacpic_sysfs(void) |
| 704 | { |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 705 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 706 | if (max_irqs == 0) |
| 707 | return -ENODEV; |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 708 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 709 | printk(KERN_DEBUG "Registering pmac pic with sysfs...\n"); |
| 710 | sysdev_class_register(&pmacpic_sysclass); |
| 711 | sysdev_register(&device_pmacpic); |
| 712 | sysdev_driver_register(&pmacpic_sysclass, &driver_pmacpic); |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | subsys_initcall(init_pmacpic_sysfs); |
| 717 | |