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 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 18 | #include <linux/stddef.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/signal.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/sysdev.h> |
| 25 | #include <linux/adb.h> |
| 26 | #include <linux/pmu.h> |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 27 | #include <linux/module.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 28 | |
| 29 | #include <asm/sections.h> |
| 30 | #include <asm/io.h> |
| 31 | #include <asm/smp.h> |
| 32 | #include <asm/prom.h> |
| 33 | #include <asm/pci-bridge.h> |
| 34 | #include <asm/time.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 35 | #include <asm/pmac_feature.h> |
| 36 | #include <asm/mpic.h> |
Michael Ellerman | af3b74d | 2008-05-08 14:27:15 +1000 | [diff] [blame] | 37 | #include <asm/xmon.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 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 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 41 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 42 | struct pmac_irq_hw { |
| 43 | unsigned int event; |
| 44 | unsigned int enable; |
| 45 | unsigned int ack; |
| 46 | unsigned int level; |
| 47 | }; |
| 48 | |
| 49 | /* Default addresses */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 50 | static volatile struct pmac_irq_hw __iomem *pmac_irq_hw[4]; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 51 | |
| 52 | #define GC_LEVEL_MASK 0x3ff00000 |
| 53 | #define OHARE_LEVEL_MASK 0x1ff00000 |
| 54 | #define HEATHROW_LEVEL_MASK 0x1ff00000 |
| 55 | |
| 56 | static int max_irqs; |
| 57 | static int max_real_irqs; |
| 58 | static u32 level_mask[4]; |
| 59 | |
| 60 | static DEFINE_SPINLOCK(pmac_pic_lock); |
| 61 | |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 62 | #define NR_MASK_WORDS ((NR_IRQS + 31) / 32) |
| 63 | static unsigned long ppc_lost_interrupts[NR_MASK_WORDS]; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 64 | static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS]; |
| 65 | static int pmac_irq_cascade = -1; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 66 | static struct irq_host *pmac_pic_host; |
Stephen Rothwell | 756e710 | 2005-11-09 18:07:45 +1100 | [diff] [blame] | 67 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 68 | static void __pmac_retrigger(unsigned int irq_nr) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 69 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 70 | if (irq_nr >= max_real_irqs && pmac_irq_cascade > 0) { |
| 71 | __set_bit(irq_nr, ppc_lost_interrupts); |
| 72 | irq_nr = pmac_irq_cascade; |
| 73 | mb(); |
| 74 | } |
| 75 | if (!__test_and_set_bit(irq_nr, ppc_lost_interrupts)) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 76 | atomic_inc(&ppc_n_lost_interrupts); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 77 | set_dec(1); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 81 | static void pmac_mask_and_ack_irq(unsigned int virq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 82 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 83 | unsigned int src = irq_map[virq].hwirq; |
Benjamin Herrenschmidt | ca72945 | 2006-08-31 21:27:50 -0700 | [diff] [blame] | 84 | unsigned long bit = 1UL << (src & 0x1f); |
| 85 | int i = src >> 5; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 86 | unsigned long flags; |
| 87 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 88 | spin_lock_irqsave(&pmac_pic_lock, flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 89 | __clear_bit(src, ppc_cached_irq_mask); |
| 90 | if (__test_and_clear_bit(src, ppc_lost_interrupts)) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 91 | atomic_dec(&ppc_n_lost_interrupts); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 92 | out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]); |
| 93 | out_le32(&pmac_irq_hw[i]->ack, bit); |
| 94 | do { |
| 95 | /* make sure ack gets to controller before we enable |
| 96 | interrupts */ |
| 97 | mb(); |
| 98 | } while((in_le32(&pmac_irq_hw[i]->enable) & bit) |
| 99 | != (ppc_cached_irq_mask[i] & bit)); |
| 100 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
| 101 | } |
| 102 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 103 | static void pmac_ack_irq(unsigned int virq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 104 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 105 | unsigned int src = irq_map[virq].hwirq; |
| 106 | unsigned long bit = 1UL << (src & 0x1f); |
| 107 | int i = src >> 5; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 108 | unsigned long flags; |
| 109 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 110 | spin_lock_irqsave(&pmac_pic_lock, flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 111 | if (__test_and_clear_bit(src, ppc_lost_interrupts)) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 112 | atomic_dec(&ppc_n_lost_interrupts); |
| 113 | out_le32(&pmac_irq_hw[i]->ack, bit); |
| 114 | (void)in_le32(&pmac_irq_hw[i]->ack); |
| 115 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
| 116 | } |
| 117 | |
| 118 | static void __pmac_set_irq_mask(unsigned int irq_nr, int nokicklost) |
| 119 | { |
| 120 | unsigned long bit = 1UL << (irq_nr & 0x1f); |
| 121 | int i = irq_nr >> 5; |
| 122 | |
| 123 | if ((unsigned)irq_nr >= max_irqs) |
| 124 | return; |
| 125 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 126 | /* enable unmasked interrupts */ |
| 127 | out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]); |
| 128 | |
| 129 | do { |
| 130 | /* make sure mask gets to controller before we |
| 131 | return to user */ |
| 132 | mb(); |
| 133 | } while((in_le32(&pmac_irq_hw[i]->enable) & bit) |
| 134 | != (ppc_cached_irq_mask[i] & bit)); |
| 135 | |
| 136 | /* |
| 137 | * Unfortunately, setting the bit in the enable register |
| 138 | * when the device interrupt is already on *doesn't* set |
| 139 | * the bit in the flag register or request another interrupt. |
| 140 | */ |
| 141 | if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level)) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 142 | __pmac_retrigger(irq_nr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* When an irq gets requested for the first client, if it's an |
| 146 | * edge interrupt, we clear any previous one on the controller |
| 147 | */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 148 | static unsigned int pmac_startup_irq(unsigned int virq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 149 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 150 | unsigned long flags; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 151 | unsigned int src = irq_map[virq].hwirq; |
| 152 | unsigned long bit = 1UL << (src & 0x1f); |
| 153 | int i = src >> 5; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 154 | |
Michael Ellerman | 6cff46f | 2009-10-13 19:44:51 +0000 | [diff] [blame] | 155 | spin_lock_irqsave(&pmac_pic_lock, flags); |
| 156 | if ((irq_to_desc(virq)->status & IRQ_LEVEL) == 0) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 157 | out_le32(&pmac_irq_hw[i]->ack, bit); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 158 | __set_bit(src, ppc_cached_irq_mask); |
| 159 | __pmac_set_irq_mask(src, 0); |
Michael Ellerman | 6cff46f | 2009-10-13 19:44:51 +0000 | [diff] [blame] | 160 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 165 | static void pmac_mask_irq(unsigned int virq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 166 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 167 | unsigned long flags; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 168 | unsigned int src = irq_map[virq].hwirq; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 169 | |
| 170 | spin_lock_irqsave(&pmac_pic_lock, flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 171 | __clear_bit(src, ppc_cached_irq_mask); |
Benjamin Herrenschmidt | ca72945 | 2006-08-31 21:27:50 -0700 | [diff] [blame] | 172 | __pmac_set_irq_mask(src, 1); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 173 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 174 | } |
| 175 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 176 | static void pmac_unmask_irq(unsigned int virq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 177 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 178 | unsigned long flags; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 179 | unsigned int src = irq_map[virq].hwirq; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 180 | |
| 181 | spin_lock_irqsave(&pmac_pic_lock, flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 182 | __set_bit(src, ppc_cached_irq_mask); |
| 183 | __pmac_set_irq_mask(src, 0); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 184 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 185 | } |
| 186 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 187 | static int pmac_retrigger(unsigned int virq) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 188 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 189 | unsigned long flags; |
| 190 | |
| 191 | spin_lock_irqsave(&pmac_pic_lock, flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 192 | __pmac_retrigger(irq_map[virq].hwirq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 193 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
| 194 | return 1; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 195 | } |
| 196 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 197 | static struct irq_chip pmac_pic = { |
Thomas Gleixner | b27df67 | 2009-11-18 23:44:21 +0000 | [diff] [blame] | 198 | .name = " PMAC-PIC ", |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 199 | .startup = pmac_startup_irq, |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 200 | .mask = pmac_mask_irq, |
| 201 | .ack = pmac_ack_irq, |
| 202 | .mask_ack = pmac_mask_and_ack_irq, |
| 203 | .unmask = pmac_unmask_irq, |
| 204 | .retrigger = pmac_retrigger, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 205 | }; |
| 206 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 207 | static irqreturn_t gatwick_action(int cpl, void *dev_id) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 208 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 209 | unsigned long flags; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 210 | int irq, bits; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 211 | int rc = IRQ_NONE; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 212 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 213 | spin_lock_irqsave(&pmac_pic_lock, flags); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 214 | for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) { |
| 215 | int i = irq >> 5; |
| 216 | bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i]; |
| 217 | /* We must read level interrupts from the level register */ |
| 218 | bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]); |
| 219 | bits &= ppc_cached_irq_mask[i]; |
| 220 | if (bits == 0) |
| 221 | continue; |
| 222 | irq += __ilog2(bits); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 223 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
Michael Ellerman | f11f76d | 2009-04-22 15:31:44 +0000 | [diff] [blame] | 224 | generic_handle_irq(irq); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 225 | spin_lock_irqsave(&pmac_pic_lock, flags); |
| 226 | rc = IRQ_HANDLED; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 227 | } |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 228 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
| 229 | return rc; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 230 | } |
| 231 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 232 | static unsigned int pmac_pic_get_irq(void) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 233 | { |
| 234 | int irq; |
| 235 | unsigned long bits = 0; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 236 | unsigned long flags; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 237 | |
| 238 | #ifdef CONFIG_SMP |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 239 | void psurge_smp_message_recv(void); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 240 | |
| 241 | /* IPI's are a hack on the powersurge -- Cort */ |
| 242 | if ( smp_processor_id() != 0 ) { |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 243 | psurge_smp_message_recv(); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 244 | return NO_IRQ_IGNORE; /* ignore, already handled */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 245 | } |
| 246 | #endif /* CONFIG_SMP */ |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 247 | spin_lock_irqsave(&pmac_pic_lock, flags); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 248 | for (irq = max_real_irqs; (irq -= 32) >= 0; ) { |
| 249 | int i = irq >> 5; |
| 250 | bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i]; |
| 251 | /* We must read level interrupts from the level register */ |
| 252 | bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]); |
| 253 | bits &= ppc_cached_irq_mask[i]; |
| 254 | if (bits == 0) |
| 255 | continue; |
| 256 | irq += __ilog2(bits); |
| 257 | break; |
| 258 | } |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 259 | spin_unlock_irqrestore(&pmac_pic_lock, flags); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 260 | if (unlikely(irq < 0)) |
| 261 | return NO_IRQ; |
| 262 | return irq_linear_revmap(pmac_pic_host, irq); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 263 | } |
| 264 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 265 | #ifdef CONFIG_XMON |
| 266 | static struct irqaction xmon_action = { |
| 267 | .handler = xmon_irq, |
| 268 | .flags = 0, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 269 | .name = "NMI - XMON" |
| 270 | }; |
| 271 | #endif |
| 272 | |
| 273 | static struct irqaction gatwick_cascade_action = { |
| 274 | .handler = gatwick_action, |
Thomas Gleixner | 6714465 | 2006-07-01 19:29:22 -0700 | [diff] [blame] | 275 | .flags = IRQF_DISABLED, |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 276 | .name = "cascade", |
| 277 | }; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 278 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 279 | static int pmac_pic_host_match(struct irq_host *h, struct device_node *node) |
| 280 | { |
| 281 | /* We match all, we don't always have a node anyway */ |
| 282 | return 1; |
| 283 | } |
| 284 | |
| 285 | static int pmac_pic_host_map(struct irq_host *h, unsigned int virq, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 286 | irq_hw_number_t hw) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 287 | { |
Michael Ellerman | 6cff46f | 2009-10-13 19:44:51 +0000 | [diff] [blame] | 288 | struct irq_desc *desc = irq_to_desc(virq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 289 | int level; |
| 290 | |
| 291 | if (hw >= max_irqs) |
| 292 | return -EINVAL; |
| 293 | |
| 294 | /* Mark level interrupts, set delayed disable for edge ones and set |
| 295 | * handlers |
| 296 | */ |
| 297 | level = !!(level_mask[hw >> 5] & (1UL << (hw & 0x1f))); |
| 298 | if (level) |
| 299 | desc->status |= IRQ_LEVEL; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 300 | set_irq_chip_and_handler(virq, &pmac_pic, level ? |
| 301 | handle_level_irq : handle_edge_irq); |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static int pmac_pic_host_xlate(struct irq_host *h, struct device_node *ct, |
Roman Fietze | 40d50cf | 2009-12-08 02:39:50 +0000 | [diff] [blame] | 306 | const u32 *intspec, unsigned int intsize, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 307 | irq_hw_number_t *out_hwirq, |
| 308 | unsigned int *out_flags) |
| 309 | |
| 310 | { |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 311 | *out_flags = IRQ_TYPE_NONE; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 312 | *out_hwirq = *intspec; |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static struct irq_host_ops pmac_pic_host_ops = { |
| 317 | .match = pmac_pic_host_match, |
| 318 | .map = pmac_pic_host_map, |
| 319 | .xlate = pmac_pic_host_xlate, |
| 320 | }; |
| 321 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 322 | static void __init pmac_pic_probe_oldstyle(void) |
| 323 | { |
| 324 | int i; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 325 | struct device_node *master = NULL; |
| 326 | struct device_node *slave = NULL; |
| 327 | u8 __iomem *addr; |
| 328 | struct resource r; |
| 329 | |
| 330 | /* Set our get_irq function */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 331 | ppc_md.get_irq = pmac_pic_get_irq; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 332 | |
| 333 | /* |
| 334 | * Find the interrupt controller type & node |
| 335 | */ |
| 336 | |
| 337 | if ((master = of_find_node_by_name(NULL, "gc")) != NULL) { |
| 338 | max_irqs = max_real_irqs = 32; |
| 339 | level_mask[0] = GC_LEVEL_MASK; |
| 340 | } else if ((master = of_find_node_by_name(NULL, "ohare")) != NULL) { |
| 341 | max_irqs = max_real_irqs = 32; |
| 342 | level_mask[0] = OHARE_LEVEL_MASK; |
| 343 | |
| 344 | /* We might have a second cascaded ohare */ |
| 345 | slave = of_find_node_by_name(NULL, "pci106b,7"); |
| 346 | if (slave) { |
| 347 | max_irqs = 64; |
| 348 | level_mask[1] = OHARE_LEVEL_MASK; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 349 | } |
| 350 | } else if ((master = of_find_node_by_name(NULL, "mac-io")) != NULL) { |
| 351 | max_irqs = max_real_irqs = 64; |
| 352 | level_mask[0] = HEATHROW_LEVEL_MASK; |
| 353 | level_mask[1] = 0; |
| 354 | |
| 355 | /* We might have a second cascaded heathrow */ |
| 356 | slave = of_find_node_by_name(master, "mac-io"); |
| 357 | |
| 358 | /* Check ordering of master & slave */ |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 359 | if (of_device_is_compatible(master, "gatwick")) { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 360 | struct device_node *tmp; |
| 361 | BUG_ON(slave == NULL); |
| 362 | tmp = master; |
| 363 | master = slave; |
| 364 | slave = tmp; |
| 365 | } |
| 366 | |
| 367 | /* We found a slave */ |
| 368 | if (slave) { |
| 369 | max_irqs = 128; |
| 370 | level_mask[2] = HEATHROW_LEVEL_MASK; |
| 371 | level_mask[3] = 0; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | BUG_ON(master == NULL); |
| 375 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 376 | /* |
| 377 | * Allocate an irq host |
| 378 | */ |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 379 | pmac_pic_host = irq_alloc_host(master, IRQ_HOST_MAP_LINEAR, max_irqs, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 380 | &pmac_pic_host_ops, |
| 381 | max_irqs); |
| 382 | BUG_ON(pmac_pic_host == NULL); |
| 383 | irq_set_default_host(pmac_pic_host); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 384 | |
| 385 | /* Get addresses of first controller if we have a node for it */ |
| 386 | BUG_ON(of_address_to_resource(master, 0, &r)); |
| 387 | |
| 388 | /* Map interrupts of primary controller */ |
| 389 | addr = (u8 __iomem *) ioremap(r.start, 0x40); |
| 390 | i = 0; |
| 391 | pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *) |
| 392 | (addr + 0x20); |
| 393 | if (max_real_irqs > 32) |
| 394 | pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *) |
| 395 | (addr + 0x10); |
| 396 | of_node_put(master); |
| 397 | |
| 398 | printk(KERN_INFO "irq: Found primary Apple PIC %s for %d irqs\n", |
| 399 | master->full_name, max_real_irqs); |
| 400 | |
| 401 | /* Map interrupts of cascaded controller */ |
| 402 | if (slave && !of_address_to_resource(slave, 0, &r)) { |
| 403 | addr = (u8 __iomem *)ioremap(r.start, 0x40); |
| 404 | pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *) |
| 405 | (addr + 0x20); |
| 406 | if (max_irqs > 64) |
| 407 | pmac_irq_hw[i++] = |
| 408 | (volatile struct pmac_irq_hw __iomem *) |
| 409 | (addr + 0x10); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 410 | pmac_irq_cascade = irq_of_parse_and_map(slave, 0); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 411 | |
| 412 | printk(KERN_INFO "irq: Found slave Apple PIC %s for %d irqs" |
| 413 | " cascade: %d\n", slave->full_name, |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 414 | max_irqs - max_real_irqs, pmac_irq_cascade); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 415 | } |
| 416 | of_node_put(slave); |
| 417 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 418 | /* Disable all interrupts in all controllers */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 419 | for (i = 0; i * 32 < max_irqs; ++i) |
| 420 | out_le32(&pmac_irq_hw[i]->enable, 0); |
| 421 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 422 | /* Hookup cascade irq */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 423 | if (slave && pmac_irq_cascade != NO_IRQ) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 424 | setup_irq(pmac_irq_cascade, &gatwick_cascade_action); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 425 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 426 | printk(KERN_INFO "irq: System has %d possible interrupts\n", max_irqs); |
| 427 | #ifdef CONFIG_XMON |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 428 | setup_irq(irq_create_mapping(NULL, 20), &xmon_action); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 429 | #endif |
| 430 | } |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 431 | #endif /* CONFIG_PPC32 */ |
| 432 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 433 | static void pmac_u3_cascade(unsigned int irq, struct irq_desc *desc) |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 434 | { |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 435 | struct mpic *mpic = desc->handler_data; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 436 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 437 | unsigned int cascade_irq = mpic_get_one_irq(mpic); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 438 | if (cascade_irq != NO_IRQ) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 439 | generic_handle_irq(cascade_irq); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 440 | desc->chip->eoi(irq); |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 441 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 442 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 443 | static void __init pmac_pic_setup_mpic_nmi(struct mpic *mpic) |
| 444 | { |
| 445 | #if defined(CONFIG_XMON) && defined(CONFIG_PPC32) |
| 446 | struct device_node* pswitch; |
| 447 | int nmi_irq; |
| 448 | |
| 449 | pswitch = of_find_node_by_name(NULL, "programmer-switch"); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 450 | if (pswitch) { |
| 451 | nmi_irq = irq_of_parse_and_map(pswitch, 0); |
| 452 | if (nmi_irq != NO_IRQ) { |
| 453 | mpic_irq_set_priority(nmi_irq, 9); |
| 454 | setup_irq(nmi_irq, &xmon_action); |
| 455 | } |
| 456 | of_node_put(pswitch); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 457 | } |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 458 | #endif /* defined(CONFIG_XMON) && defined(CONFIG_PPC32) */ |
| 459 | } |
| 460 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 461 | static struct mpic * __init pmac_setup_one_mpic(struct device_node *np, |
| 462 | int master) |
| 463 | { |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 464 | const char *name = master ? " MPIC 1 " : " MPIC 2 "; |
| 465 | struct resource r; |
| 466 | struct mpic *mpic; |
| 467 | unsigned int flags = master ? MPIC_PRIMARY : 0; |
| 468 | int rc; |
| 469 | |
| 470 | rc = of_address_to_resource(np, 0, &r); |
| 471 | if (rc) |
| 472 | return NULL; |
| 473 | |
| 474 | pmac_call_feature(PMAC_FTR_ENABLE_MPIC, np, 0, 0); |
| 475 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 476 | flags |= MPIC_WANTS_RESET; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 477 | if (of_get_property(np, "big-endian", NULL)) |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 478 | flags |= MPIC_BIG_ENDIAN; |
| 479 | |
| 480 | /* Primary Big Endian means HT interrupts. This is quite dodgy |
| 481 | * but works until I find a better way |
| 482 | */ |
| 483 | if (master && (flags & MPIC_BIG_ENDIAN)) |
Michael Ellerman | 6cfef5b | 2007-04-23 18:47:08 +1000 | [diff] [blame] | 484 | flags |= MPIC_U3_HT_IRQS; |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 485 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 486 | mpic = mpic_alloc(np, r.start, flags, 0, 0, name); |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 487 | if (mpic == NULL) |
| 488 | return NULL; |
| 489 | |
| 490 | mpic_init(mpic); |
| 491 | |
| 492 | return mpic; |
| 493 | } |
| 494 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 495 | static int __init pmac_pic_probe_mpic(void) |
| 496 | { |
| 497 | struct mpic *mpic1, *mpic2; |
| 498 | struct device_node *np, *master = NULL, *slave = NULL; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 499 | unsigned int cascade; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 500 | |
| 501 | /* We can have up to 2 MPICs cascaded */ |
| 502 | for (np = NULL; (np = of_find_node_by_type(np, "open-pic")) |
| 503 | != NULL;) { |
| 504 | if (master == NULL && |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 505 | of_get_property(np, "interrupts", NULL) == NULL) |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 506 | master = of_node_get(np); |
| 507 | else if (slave == NULL) |
| 508 | slave = of_node_get(np); |
| 509 | if (master && slave) |
| 510 | break; |
| 511 | } |
| 512 | |
| 513 | /* Check for bogus setups */ |
| 514 | if (master == NULL && slave != NULL) { |
| 515 | master = slave; |
| 516 | slave = NULL; |
| 517 | } |
| 518 | |
| 519 | /* Not found, default to good old pmac pic */ |
| 520 | if (master == NULL) |
| 521 | return -ENODEV; |
| 522 | |
| 523 | /* Set master handler */ |
| 524 | ppc_md.get_irq = mpic_get_irq; |
| 525 | |
| 526 | /* Setup master */ |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 527 | mpic1 = pmac_setup_one_mpic(master, 1); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 528 | BUG_ON(mpic1 == NULL); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 529 | |
| 530 | /* Install NMI if any */ |
| 531 | pmac_pic_setup_mpic_nmi(mpic1); |
| 532 | |
| 533 | of_node_put(master); |
| 534 | |
| 535 | /* No slave, let's go out */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 536 | if (slave == NULL) |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 537 | return 0; |
| 538 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 539 | /* Get/Map slave interrupt */ |
| 540 | cascade = irq_of_parse_and_map(slave, 0); |
| 541 | if (cascade == NO_IRQ) { |
| 542 | printk(KERN_ERR "Failed to map cascade IRQ\n"); |
| 543 | return 0; |
| 544 | } |
| 545 | |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 546 | mpic2 = pmac_setup_one_mpic(slave, 0); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 547 | if (mpic2 == NULL) { |
Benjamin Herrenschmidt | 1beb6a7 | 2005-12-14 13:10:10 +1100 | [diff] [blame] | 548 | printk(KERN_ERR "Failed to setup slave MPIC\n"); |
| 549 | of_node_put(slave); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 550 | return 0; |
| 551 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 552 | set_irq_data(cascade, mpic2); |
| 553 | set_irq_chained_handler(cascade, pmac_u3_cascade); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 554 | |
| 555 | of_node_put(slave); |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 560 | void __init pmac_pic_init(void) |
| 561 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 562 | unsigned int flags = 0; |
| 563 | |
| 564 | /* We configure the OF parsing based on our oldworld vs. newworld |
| 565 | * platform type and wether we were booted by BootX. |
| 566 | */ |
| 567 | #ifdef CONFIG_PPC32 |
| 568 | if (!pmac_newworld) |
| 569 | flags |= OF_IMAP_OLDWORLD_MAC; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 570 | if (of_get_property(of_chosen, "linux,bootx", NULL) != NULL) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 571 | flags |= OF_IMAP_NO_PHANDLE; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 572 | #endif /* CONFIG_PPC_32 */ |
| 573 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 574 | of_irq_map_init(flags); |
| 575 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 576 | /* We first try to detect Apple's new Core99 chipset, since mac-io |
| 577 | * is quite different on those machines and contains an IBM MPIC2. |
| 578 | */ |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 579 | if (pmac_pic_probe_mpic() == 0) |
Paul Mackerras | 20c8c21 | 2005-09-28 20:28:14 +1000 | [diff] [blame] | 580 | return; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 581 | |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 582 | #ifdef CONFIG_PPC32 |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 583 | pmac_pic_probe_oldstyle(); |
| 584 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 585 | } |
| 586 | |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 587 | #if defined(CONFIG_PM) && defined(CONFIG_PPC32) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 588 | /* |
| 589 | * These procedures are used in implementing sleep on the powerbooks. |
| 590 | * sleep_save_intrs() saves the states of all interrupt enables |
| 591 | * and disables all interrupts except for the nominated one. |
| 592 | * sleep_restore_intrs() restores the states of all interrupt enables. |
| 593 | */ |
| 594 | unsigned long sleep_save_mask[2]; |
| 595 | |
| 596 | /* This used to be passed by the PMU driver but that link got |
| 597 | * broken with the new driver model. We use this tweak for now... |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 598 | * We really want to do things differently though... |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 599 | */ |
| 600 | static int pmacpic_find_viaint(void) |
| 601 | { |
| 602 | int viaint = -1; |
| 603 | |
| 604 | #ifdef CONFIG_ADB_PMU |
| 605 | struct device_node *np; |
| 606 | |
| 607 | if (pmu_get_model() != PMU_OHARE_BASED) |
| 608 | goto not_found; |
| 609 | np = of_find_node_by_name(NULL, "via-pmu"); |
| 610 | if (np == NULL) |
| 611 | goto not_found; |
Joe Perches | d258e64 | 2009-06-28 06:26:10 +0000 | [diff] [blame] | 612 | viaint = irq_of_parse_and_map(np, 0); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 613 | |
| 614 | not_found: |
Tony Breeds | 98cddbf | 2008-03-12 10:48:48 +1100 | [diff] [blame] | 615 | #endif /* CONFIG_ADB_PMU */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 616 | return viaint; |
| 617 | } |
| 618 | |
| 619 | static int pmacpic_suspend(struct sys_device *sysdev, pm_message_t state) |
| 620 | { |
| 621 | int viaint = pmacpic_find_viaint(); |
| 622 | |
| 623 | sleep_save_mask[0] = ppc_cached_irq_mask[0]; |
| 624 | sleep_save_mask[1] = ppc_cached_irq_mask[1]; |
| 625 | ppc_cached_irq_mask[0] = 0; |
| 626 | ppc_cached_irq_mask[1] = 0; |
| 627 | if (viaint > 0) |
| 628 | set_bit(viaint, ppc_cached_irq_mask); |
| 629 | out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]); |
| 630 | if (max_real_irqs > 32) |
| 631 | out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]); |
| 632 | (void)in_le32(&pmac_irq_hw[0]->event); |
| 633 | /* make sure mask gets to controller before we return to caller */ |
| 634 | mb(); |
| 635 | (void)in_le32(&pmac_irq_hw[0]->enable); |
| 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | static int pmacpic_resume(struct sys_device *sysdev) |
| 641 | { |
| 642 | int i; |
| 643 | |
| 644 | out_le32(&pmac_irq_hw[0]->enable, 0); |
| 645 | if (max_real_irqs > 32) |
| 646 | out_le32(&pmac_irq_hw[1]->enable, 0); |
| 647 | mb(); |
| 648 | for (i = 0; i < max_real_irqs; ++i) |
| 649 | if (test_bit(i, sleep_save_mask)) |
| 650 | pmac_unmask_irq(i); |
| 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 655 | #endif /* CONFIG_PM && CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 656 | |
| 657 | static struct sysdev_class pmacpic_sysclass = { |
Kay Sievers | af5ca3f4 | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 658 | .name = "pmac_pic", |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 659 | }; |
| 660 | |
| 661 | static struct sys_device device_pmacpic = { |
| 662 | .id = 0, |
| 663 | .cls = &pmacpic_sysclass, |
| 664 | }; |
| 665 | |
| 666 | static struct sysdev_driver driver_pmacpic = { |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 667 | #if defined(CONFIG_PM) && defined(CONFIG_PPC32) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 668 | .suspend = &pmacpic_suspend, |
| 669 | .resume = &pmacpic_resume, |
Paul Mackerras | a000503 | 2005-11-02 15:08:17 +1100 | [diff] [blame] | 670 | #endif /* CONFIG_PM && CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 671 | }; |
| 672 | |
| 673 | static int __init init_pmacpic_sysfs(void) |
| 674 | { |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 675 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 676 | if (max_irqs == 0) |
| 677 | return -ENODEV; |
Paul Mackerras | 3c3f42d | 2005-10-10 22:58:41 +1000 | [diff] [blame] | 678 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 679 | printk(KERN_DEBUG "Registering pmac pic with sysfs...\n"); |
| 680 | sysdev_class_register(&pmacpic_sysclass); |
| 681 | sysdev_register(&device_pmacpic); |
| 682 | sysdev_driver_register(&pmacpic_sysclass, &driver_pmacpic); |
| 683 | return 0; |
| 684 | } |
Grant Likely | d518b71 | 2008-01-03 06:14:28 +1100 | [diff] [blame] | 685 | machine_subsys_initcall(powermac, init_pmacpic_sysfs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 686 | |