📄 pmac_pic.c
字号:
/* * BK Id: SCCS/s.pmac_pic.c 1.24 12/19/01 10:53:01 paulus */#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 <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 "pmac_pic.h"#include "open_pic.h"struct 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] __pmacdata = { (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 __pmacdata;static int max_real_irqs __pmacdata;static u32 level_mask[4] __pmacdata;static spinlock_t pmac_pic_lock __pmacdata = SPIN_LOCK_UNLOCKED;#define GATWICK_IRQ_POOL_SIZE 10static struct interrupt_info gatwick_int_pool[GATWICK_IRQ_POOL_SIZE] __pmacdata;/* * Mark an irq as "lost". This is only used on the pmac * since it can lose interrupts (see pmac_set_irq_mask). * -- Cort */void __pmac__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 void __pmacpmac_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 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);}static void __pmac 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 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 pmac_end_irq(unsigned int irq_nr){ if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))) { set_bit(irq_nr, ppc_cached_irq_mask); pmac_set_irq_mask(irq_nr, 1); }}struct hw_interrupt_type pmac_pic = { " PMAC-PIC ", NULL, NULL, pmac_unmask_irq, pmac_mask_irq, pmac_mask_and_ack_irq, pmac_end_irq, NULL};struct hw_interrupt_type gatwick_pic = { " GATWICK ", NULL, NULL, pmac_unmask_irq, pmac_mask_irq, pmac_mask_and_ack_irq, pmac_end_irq, NULL};static void 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); break; } /* The previous version of this code allowed for this case, we * don't. Put this here to check for it. * -- Cort */ if ( irq_desc[irq].handler != &gatwick_pic ) printk("gatwick irq not from gatwick pic\n"); else ppc_irq_dispatch_handler( regs, irq );}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];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -