📄 pic.c
字号:
/* * Support for the interrupt controllers found on Power Macintosh, * currently Apple's "Grand Central" interrupt controller in all * it's incarnations. OpenPIC support used on newer machines is * in a separate file * * Copyright (C) 1997 Paul Mackerras (paulus@samba.org) * * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * */#include <linux/config.h>#include <linux/stddef.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/signal.h>#include <linux/pci.h>#include <linux/interrupt.h>#include <linux/sysdev.h>#include <linux/adb.h>#include <linux/pmu.h>#include <linux/module.h>#include <asm/sections.h>#include <asm/io.h>#include <asm/smp.h>#include <asm/prom.h>#include <asm/pci-bridge.h>#include <asm/time.h>#include <asm/pmac_feature.h>#include <asm/mpic.h>#include "pmac.h"/* * XXX this should be in xmon.h, but putting it there means xmon.h * has to include <linux/interrupt.h> (to get irqreturn_t), which * causes all sorts of problems. -- paulus */extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);#ifdef CONFIG_PPC32struct pmac_irq_hw { unsigned int event; unsigned int enable; unsigned int ack; unsigned int level;};/* Default addresses */static volatile struct pmac_irq_hw *pmac_irq_hw[4] = { (struct pmac_irq_hw *) 0xf3000020, (struct pmac_irq_hw *) 0xf3000010, (struct pmac_irq_hw *) 0xf4000020, (struct pmac_irq_hw *) 0xf4000010,};#define GC_LEVEL_MASK 0x3ff00000#define OHARE_LEVEL_MASK 0x1ff00000#define HEATHROW_LEVEL_MASK 0x1ff00000static int max_irqs;static int max_real_irqs;static u32 level_mask[4];static DEFINE_SPINLOCK(pmac_pic_lock);#define GATWICK_IRQ_POOL_SIZE 10static struct interrupt_info gatwick_int_pool[GATWICK_IRQ_POOL_SIZE];#define NR_MASK_WORDS ((NR_IRQS + 31) / 32)static unsigned long ppc_lost_interrupts[NR_MASK_WORDS];/* * Mark an irq as "lost". This is only used on the pmac * since it can lose interrupts (see pmac_set_irq_mask). * -- Cort */void__set_lost(unsigned long irq_nr, int nokick){ if (!test_and_set_bit(irq_nr, ppc_lost_interrupts)) { atomic_inc(&ppc_n_lost_interrupts); if (!nokick) set_dec(1); }}static voidpmac_mask_and_ack_irq(unsigned int irq_nr){ unsigned long bit = 1UL << (irq_nr & 0x1f); int i = irq_nr >> 5; unsigned long flags; if ((unsigned)irq_nr >= max_irqs) return; clear_bit(irq_nr, ppc_cached_irq_mask); if (test_and_clear_bit(irq_nr, ppc_lost_interrupts)) atomic_dec(&ppc_n_lost_interrupts); spin_lock_irqsave(&pmac_pic_lock, flags); out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]); out_le32(&pmac_irq_hw[i]->ack, bit); do { /* make sure ack gets to controller before we enable interrupts */ mb(); } while((in_le32(&pmac_irq_hw[i]->enable) & bit) != (ppc_cached_irq_mask[i] & bit)); spin_unlock_irqrestore(&pmac_pic_lock, flags);}static void pmac_set_irq_mask(unsigned int irq_nr, int nokicklost){ unsigned long bit = 1UL << (irq_nr & 0x1f); int i = irq_nr >> 5; unsigned long flags; if ((unsigned)irq_nr >= max_irqs) return; spin_lock_irqsave(&pmac_pic_lock, flags); /* enable unmasked interrupts */ out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]); do { /* make sure mask gets to controller before we return to user */ mb(); } while((in_le32(&pmac_irq_hw[i]->enable) & bit) != (ppc_cached_irq_mask[i] & bit)); /* * Unfortunately, setting the bit in the enable register * when the device interrupt is already on *doesn't* set * the bit in the flag register or request another interrupt. */ if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level)) __set_lost((ulong)irq_nr, nokicklost); spin_unlock_irqrestore(&pmac_pic_lock, flags);}/* When an irq gets requested for the first client, if it's an * edge interrupt, we clear any previous one on the controller */static unsigned int pmac_startup_irq(unsigned int irq_nr){ unsigned long bit = 1UL << (irq_nr & 0x1f); int i = irq_nr >> 5; if ((irq_desc[irq_nr].status & IRQ_LEVEL) == 0) out_le32(&pmac_irq_hw[i]->ack, bit); set_bit(irq_nr, ppc_cached_irq_mask); pmac_set_irq_mask(irq_nr, 0); return 0;}static void pmac_mask_irq(unsigned int irq_nr){ clear_bit(irq_nr, ppc_cached_irq_mask); pmac_set_irq_mask(irq_nr, 0); mb();}static void pmac_unmask_irq(unsigned int irq_nr){ set_bit(irq_nr, ppc_cached_irq_mask); pmac_set_irq_mask(irq_nr, 0);}static void pmac_end_irq(unsigned int irq_nr){ if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS)) && irq_desc[irq_nr].action) { set_bit(irq_nr, ppc_cached_irq_mask); pmac_set_irq_mask(irq_nr, 1); }}struct hw_interrupt_type pmac_pic = { .typename = " PMAC-PIC ", .startup = pmac_startup_irq, .enable = pmac_unmask_irq, .disable = pmac_mask_irq, .ack = pmac_mask_and_ack_irq, .end = pmac_end_irq,};struct hw_interrupt_type gatwick_pic = { .typename = " GATWICK ", .startup = pmac_startup_irq, .enable = pmac_unmask_irq, .disable = pmac_mask_irq, .ack = pmac_mask_and_ack_irq, .end = pmac_end_irq,};static irqreturn_t gatwick_action(int cpl, void *dev_id, struct pt_regs *regs){ int irq, bits; for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) { int i = irq >> 5; bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i]; /* We must read level interrupts from the level register */ bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]); bits &= ppc_cached_irq_mask[i]; if (bits == 0) continue; irq += __ilog2(bits); __do_IRQ(irq, regs); return IRQ_HANDLED; } printk("gatwick irq not from gatwick pic\n"); return IRQ_NONE;}intpmac_get_irq(struct pt_regs *regs){ int irq; unsigned long bits = 0;#ifdef CONFIG_SMP void psurge_smp_message_recv(struct pt_regs *); /* IPI's are a hack on the powersurge -- Cort */ if ( smp_processor_id() != 0 ) { psurge_smp_message_recv(regs); return -2; /* ignore, already handled */ }#endif /* CONFIG_SMP */ for (irq = max_real_irqs; (irq -= 32) >= 0; ) { int i = irq >> 5; bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i]; /* We must read level interrupts from the level register */ bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]); bits &= ppc_cached_irq_mask[i]; if (bits == 0) continue; irq += __ilog2(bits); break; } return irq;}/* This routine will fix some missing interrupt values in the device tree * on the gatwick mac-io controller used by some PowerBooks */static void __initpmac_fix_gatwick_interrupts(struct device_node *gw, int irq_base){ struct device_node *node; int count; memset(gatwick_int_pool, 0, sizeof(gatwick_int_pool)); node = gw->child; count = 0; while(node) { /* Fix SCC */ if (strcasecmp(node->name, "escc") == 0) if (node->child) { if (node->child->n_intrs < 3) { node->child->intrs = &gatwick_int_pool[count]; count += 3; } node->child->n_intrs = 3; node->child->intrs[0].line = 15+irq_base; node->child->intrs[1].line = 4+irq_base; node->child->intrs[2].line = 5+irq_base; printk(KERN_INFO "irq: fixed SCC on second controller (%d,%d,%d)\n", node->child->intrs[0].line, node->child->intrs[1].line, node->child->intrs[2].line); } /* Fix media-bay & left SWIM */ if (strcasecmp(node->name, "media-bay") == 0) { struct device_node* ya_node; if (node->n_intrs == 0) node->intrs = &gatwick_int_pool[count++]; node->n_intrs = 1; node->intrs[0].line = 29+irq_base; printk(KERN_INFO "irq: fixed media-bay on second controller (%d)\n", node->intrs[0].line); ya_node = node->child; while(ya_node) { if (strcasecmp(ya_node->name, "floppy") == 0) { if (ya_node->n_intrs < 2) { ya_node->intrs = &gatwick_int_pool[count]; count += 2; } ya_node->n_intrs = 2; ya_node->intrs[0].line = 19+irq_base; ya_node->intrs[1].line = 1+irq_base; printk(KERN_INFO "irq: fixed floppy on second controller (%d,%d)\n", ya_node->intrs[0].line, ya_node->intrs[1].line); } if (strcasecmp(ya_node->name, "ata4") == 0) { if (ya_node->n_intrs < 2) { ya_node->intrs = &gatwick_int_pool[count]; count += 2; } ya_node->n_intrs = 2; ya_node->intrs[0].line = 14+irq_base; ya_node->intrs[1].line = 3+irq_base; printk(KERN_INFO "irq: fixed ide on second controller (%d,%d)\n", ya_node->intrs[0].line, ya_node->intrs[1].line); } ya_node = ya_node->sibling; } } node = node->sibling; } if (count > 10) { printk("WARNING !! Gatwick interrupt pool overflow\n"); printk(" GATWICK_IRQ_POOL_SIZE = %d\n", GATWICK_IRQ_POOL_SIZE); printk(" requested = %d\n", count); }}/* * The PowerBook 3400/2400/3500 can have a combo ethernet/modem * card which includes an ohare chip that acts as a second interrupt * controller. If we find this second ohare, set it up and fix the * interrupt value in the device tree for the ethernet chip. */static int __init enable_second_ohare(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -