1 #include <linux/config.h>
2 #include <linux/stddef.h>
3 #include <linux/init.h>
4 #include <linux/sched.h>
5 #include <linux/signal.h>
8 #include <asm/sections.h>
12 #include <asm/pci-bridge.h>
14 #include <asm/open_pic.h>
25 /* Default addresses */
26 static volatile struct pmac_irq_hw *pmac_irq_hw[4] __pmacdata = {
27 (struct pmac_irq_hw *) 0xf3000020,
28 (struct pmac_irq_hw *) 0xf3000010,
29 (struct pmac_irq_hw *) 0xf4000020,
30 (struct pmac_irq_hw *) 0xf4000010,
33 #define GC_LEVEL_MASK 0x3ff00000
34 #define OHARE_LEVEL_MASK 0x1ff00000
35 #define HEATHROW_LEVEL_MASK 0x1ff00000
37 static int max_irqs __pmacdata;
38 static int max_real_irqs __pmacdata;
39 static u32 level_mask[4] __pmacdata;
41 static spinlock_t pmac_pic_lock __pmacdata = SPIN_LOCK_UNLOCKED;
44 #define GATWICK_IRQ_POOL_SIZE 10
45 static struct interrupt_info gatwick_int_pool[GATWICK_IRQ_POOL_SIZE] __pmacdata;
48 * Mark an irq as "lost". This is only used on the pmac
49 * since it can lose interrupts (see pmac_set_irq_mask).
53 __set_lost(unsigned long irq_nr, int nokick)
55 if (!test_and_set_bit(irq_nr, ppc_lost_interrupts)) {
56 atomic_inc(&ppc_n_lost_interrupts);
63 pmac_mask_and_ack_irq(unsigned int irq_nr)
65 unsigned long bit = 1UL << (irq_nr & 0x1f);
69 if ((unsigned)irq_nr >= max_irqs)
72 clear_bit(irq_nr, ppc_cached_irq_mask);
73 if (test_and_clear_bit(irq_nr, ppc_lost_interrupts))
74 atomic_dec(&ppc_n_lost_interrupts);
75 spin_lock_irqsave(&pmac_pic_lock, flags);
76 out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
77 out_le32(&pmac_irq_hw[i]->ack, bit);
79 /* make sure ack gets to controller before we enable
82 } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
83 != (ppc_cached_irq_mask[i] & bit));
84 spin_unlock_irqrestore(&pmac_pic_lock, flags);
87 static void __pmac pmac_set_irq_mask(unsigned int irq_nr, int nokicklost)
89 unsigned long bit = 1UL << (irq_nr & 0x1f);
93 if ((unsigned)irq_nr >= max_irqs)
96 spin_lock_irqsave(&pmac_pic_lock, flags);
97 /* enable unmasked interrupts */
98 out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
101 /* make sure mask gets to controller before we
104 } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
105 != (ppc_cached_irq_mask[i] & bit));
108 * Unfortunately, setting the bit in the enable register
109 * when the device interrupt is already on *doesn't* set
110 * the bit in the flag register or request another interrupt.
112 if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level))
113 __set_lost((ulong)irq_nr, nokicklost);
114 spin_unlock_irqrestore(&pmac_pic_lock, flags);
117 static void __pmac pmac_mask_irq(unsigned int irq_nr)
119 clear_bit(irq_nr, ppc_cached_irq_mask);
120 pmac_set_irq_mask(irq_nr, 0);
124 static void __pmac pmac_unmask_irq(unsigned int irq_nr)
126 set_bit(irq_nr, ppc_cached_irq_mask);
127 pmac_set_irq_mask(irq_nr, 0);
130 static void __pmac pmac_end_irq(unsigned int irq_nr)
132 if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))) {
133 set_bit(irq_nr, ppc_cached_irq_mask);
134 pmac_set_irq_mask(irq_nr, 1);
139 struct hw_interrupt_type pmac_pic = {
145 pmac_mask_and_ack_irq,
150 struct hw_interrupt_type gatwick_pic = {
156 pmac_mask_and_ack_irq,
161 static void gatwick_action(int cpl, void *dev_id, struct pt_regs *regs)
165 for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) {
167 bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
168 /* We must read level interrupts from the level register */
169 bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
170 bits &= ppc_cached_irq_mask[i];
173 irq += __ilog2(bits);
176 /* The previous version of this code allowed for this case, we
177 * don't. Put this here to check for it.
180 if ( irq_desc[irq].handler != &gatwick_pic )
181 printk("gatwick irq not from gatwick pic\n");
183 ppc_irq_dispatch_handler( regs, irq );
187 pmac_get_irq(struct pt_regs *regs)
190 unsigned long bits = 0;
193 void psurge_smp_message_recv(struct pt_regs *);
195 /* IPI's are a hack on the powersurge -- Cort */
196 if ( smp_processor_id() != 0 ) {
197 psurge_smp_message_recv(regs);
198 return -2; /* ignore, already handled */
200 #endif /* CONFIG_SMP */
201 for (irq = max_real_irqs; (irq -= 32) >= 0; ) {
203 bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
204 /* We must read level interrupts from the level register */
205 bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
206 bits &= ppc_cached_irq_mask[i];
209 irq += __ilog2(bits);
216 /* This routine will fix some missing interrupt values in the device tree
217 * on the gatwick mac-io controller used by some PowerBooks
220 pmac_fix_gatwick_interrupts(struct device_node *gw, int irq_base)
222 struct device_node *node;
225 memset(gatwick_int_pool, 0, sizeof(gatwick_int_pool));
231 if (strcasecmp(node->name, "escc") == 0)
233 if (node->child->n_intrs < 3) {
234 node->child->intrs = &gatwick_int_pool[count];
237 node->child->n_intrs = 3;
238 node->child->intrs[0].line = 15+irq_base;
239 node->child->intrs[1].line = 4+irq_base;
240 node->child->intrs[2].line = 5+irq_base;
241 printk(KERN_INFO "irq: fixed SCC on second controller (%d,%d,%d)\n",
242 node->child->intrs[0].line,
243 node->child->intrs[1].line,
244 node->child->intrs[2].line);
246 /* Fix media-bay & left SWIM */
247 if (strcasecmp(node->name, "media-bay") == 0) {
248 struct device_node* ya_node;
250 if (node->n_intrs == 0)
251 node->intrs = &gatwick_int_pool[count++];
253 node->intrs[0].line = 29+irq_base;
254 printk(KERN_INFO "irq: fixed media-bay on second controller (%d)\n",
255 node->intrs[0].line);
257 ya_node = node->child;
260 if (strcasecmp(ya_node->name, "floppy") == 0) {
261 if (ya_node->n_intrs < 2) {
262 ya_node->intrs = &gatwick_int_pool[count];
265 ya_node->n_intrs = 2;
266 ya_node->intrs[0].line = 19+irq_base;
267 ya_node->intrs[1].line = 1+irq_base;
268 printk(KERN_INFO "irq: fixed floppy on second controller (%d,%d)\n",
269 ya_node->intrs[0].line, ya_node->intrs[1].line);
271 if (strcasecmp(ya_node->name, "ata4") == 0) {
272 if (ya_node->n_intrs < 2) {
273 ya_node->intrs = &gatwick_int_pool[count];
276 ya_node->n_intrs = 2;
277 ya_node->intrs[0].line = 14+irq_base;
278 ya_node->intrs[1].line = 3+irq_base;
279 printk(KERN_INFO "irq: fixed ide on second controller (%d,%d)\n",
280 ya_node->intrs[0].line, ya_node->intrs[1].line);
282 ya_node = ya_node->sibling;
285 node = node->sibling;
288 printk("WARNING !! Gatwick interrupt pool overflow\n");
289 printk(" GATWICK_IRQ_POOL_SIZE = %d\n", GATWICK_IRQ_POOL_SIZE);
290 printk(" requested = %d\n", count);
295 * The PowerBook 3400/2400/3500 can have a combo ethernet/modem
296 * card which includes an ohare chip that acts as a second interrupt
297 * controller. If we find this second ohare, set it up and fix the
298 * interrupt value in the device tree for the ethernet chip.
300 static int __init enable_second_ohare(void)
302 unsigned char bus, devfn;
305 struct device_node *irqctrler = find_devices("pci106b,7");
306 struct device_node *ether;
308 if (irqctrler == NULL || irqctrler->n_addrs <= 0)
310 addr = (unsigned long) ioremap(irqctrler->addrs[0].address, 0x40);
311 pmac_irq_hw[1] = (volatile struct pmac_irq_hw *)(addr + 0x20);
313 if (pci_device_from_OF_node(irqctrler, &bus, &devfn) == 0) {
314 struct pci_controller* hose = pci_find_hose_for_OF_device(irqctrler);
316 printk(KERN_ERR "Can't find PCI hose for OHare2 !\n");
318 early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd);
319 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
320 cmd &= ~PCI_COMMAND_IO;
321 early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd);
325 /* Fix interrupt for the modem/ethernet combo controller. The number
326 in the device tree (27) is bogus (correct for the ethernet-only
327 board but not the combo ethernet/modem board).
328 The real interrupt is 28 on the second controller -> 28+32 = 60.
330 ether = find_devices("pci1011,14");
331 if (ether && ether->n_intrs > 0) {
332 ether->intrs[0].line = 60;
333 printk(KERN_INFO "irq: Fixed ethernet IRQ to %d\n",
334 ether->intrs[0].line);
337 /* Return the interrupt number of the cascade */
338 return irqctrler->intrs[0].line;
345 struct device_node *irqctrler;
347 int irq_cascade = -1;
349 /* We first try to detect Apple's new Core99 chipset, since mac-io
350 * is quite different on those machines and contains an IBM MPIC2.
352 irqctrler = find_type_devices("open-pic");
353 if (irqctrler != NULL)
355 printk("PowerMac using OpenPIC irq controller\n");
356 if (irqctrler->n_addrs > 0)
358 unsigned char senses[NR_IRQS];
360 prom_get_irq_senses(senses, 0, NR_IRQS);
361 OpenPIC_InitSenses = senses;
362 OpenPIC_NumInitSenses = NR_IRQS;
363 ppc_md.get_irq = openpic_get_irq;
364 OpenPIC_Addr = ioremap(irqctrler->addrs[0].address,
365 irqctrler->addrs[0].size);
369 struct device_node* pswitch;
372 pswitch = find_devices("programmer-switch");
373 if (pswitch && pswitch->n_intrs) {
374 nmi_irq = pswitch->intrs[0].line;
375 openpic_init_nmi_irq(nmi_irq);
376 request_irq(nmi_irq, xmon_irq, 0,
380 #endif /* CONFIG_XMON */
386 /* Get the level/edge settings, assume if it's not
387 * a Grand Central nor an OHare, then it's an Heathrow
390 if (find_devices("gc"))
391 level_mask[0] = GC_LEVEL_MASK;
392 else if (find_devices("ohare")) {
393 level_mask[0] = OHARE_LEVEL_MASK;
394 /* We might have a second cascaded ohare */
395 level_mask[1] = OHARE_LEVEL_MASK;
397 level_mask[0] = HEATHROW_LEVEL_MASK;
399 /* We might have a second cascaded heathrow */
400 level_mask[2] = HEATHROW_LEVEL_MASK;
405 * G3 powermacs and 1999 G3 PowerBooks have 64 interrupts,
406 * 1998 G3 Series PowerBooks have 128,
407 * other powermacs have 32.
408 * The combo ethernet/modem card for the Powerstar powerbooks
409 * (2400/3400/3500, ohare based) has a second ohare chip
410 * effectively making a total of 64.
412 max_irqs = max_real_irqs = 32;
413 irqctrler = find_devices("mac-io");
422 for ( i = 0; i < max_real_irqs ; i++ )
423 irq_desc[i].handler = &pmac_pic;
425 /* get addresses of first controller */
427 if (irqctrler->n_addrs > 0) {
428 addr = (unsigned long)
429 ioremap(irqctrler->addrs[0].address, 0x40);
430 for (i = 0; i < 2; ++i)
431 pmac_irq_hw[i] = (volatile struct pmac_irq_hw*)
432 (addr + (2 - i) * 0x10);
435 /* get addresses of second controller */
436 irqctrler = irqctrler->next;
437 if (irqctrler && irqctrler->n_addrs > 0) {
438 addr = (unsigned long)
439 ioremap(irqctrler->addrs[0].address, 0x40);
440 for (i = 2; i < 4; ++i)
441 pmac_irq_hw[i] = (volatile struct pmac_irq_hw*)
442 (addr + (4 - i) * 0x10);
443 irq_cascade = irqctrler->intrs[0].line;
444 if (device_is_compatible(irqctrler, "gatwick"))
445 pmac_fix_gatwick_interrupts(irqctrler, max_real_irqs);
448 /* older powermacs have a GC (grand central) or ohare at
449 f3000000, with interrupt control registers at f3000020. */
450 addr = (unsigned long) ioremap(0xf3000000, 0x40);
451 pmac_irq_hw[0] = (volatile struct pmac_irq_hw *) (addr + 0x20);
454 /* PowerBooks 3400 and 3500 can have a second controller in a second
455 ohare chip, on the combo ethernet/modem card */
456 if (machine_is_compatible("AAPL,3400/2400")
457 || machine_is_compatible("AAPL,3500"))
458 irq_cascade = enable_second_ohare();
460 /* disable all interrupts in all controllers */
461 for (i = 0; i * 32 < max_irqs; ++i)
462 out_le32(&pmac_irq_hw[i]->enable, 0);
463 /* mark level interrupts */
464 for (i = 0; i < max_irqs; i++)
465 if (level_mask[i >> 5] & (1UL << (i & 0x1f)))
466 irq_desc[i].status = IRQ_LEVEL;
468 /* get interrupt line of secondary interrupt controller */
469 if (irq_cascade >= 0) {
470 printk(KERN_INFO "irq: secondary controller on irq %d\n",
472 for ( i = max_real_irqs ; i < max_irqs ; i++ )
473 irq_desc[i].handler = &gatwick_pic;
474 request_irq( irq_cascade, gatwick_action, SA_INTERRUPT,
477 printk("System has %d possible interrupts\n", max_irqs);
478 if (max_irqs != max_real_irqs)
479 printk(KERN_DEBUG "%d interrupts on main controller\n",
483 request_irq(20, xmon_irq, 0, "NMI - XMON", 0);
484 #endif /* CONFIG_XMON */
487 #ifdef CONFIG_PMAC_PBOOK
489 * These procedures are used in implementing sleep on the powerbooks.
490 * sleep_save_intrs() saves the states of all interrupt enables
491 * and disables all interrupts except for the nominated one.
492 * sleep_restore_intrs() restores the states of all interrupt enables.
494 unsigned int sleep_save_mask[2];
497 pmac_sleep_save_intrs(int viaint)
499 sleep_save_mask[0] = ppc_cached_irq_mask[0];
500 sleep_save_mask[1] = ppc_cached_irq_mask[1];
501 ppc_cached_irq_mask[0] = 0;
502 ppc_cached_irq_mask[1] = 0;
504 set_bit(viaint, ppc_cached_irq_mask);
505 out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]);
506 if (max_real_irqs > 32)
507 out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]);
508 (void)in_le32(&pmac_irq_hw[0]->event);
509 /* make sure mask gets to controller before we return to caller */
511 (void)in_le32(&pmac_irq_hw[0]->enable);
515 pmac_sleep_restore_intrs(void)
519 out_le32(&pmac_irq_hw[0]->enable, 0);
520 if (max_real_irqs > 32)
521 out_le32(&pmac_irq_hw[1]->enable, 0);
523 for (i = 0; i < max_real_irqs; ++i)
524 if (test_bit(i, sleep_save_mask))
527 #endif /* CONFIG_PMAC_PBOOK */