📄 open_pic.c
字号:
/* * BK Id: SCCS/s.open_pic.c 1.33 12/19/01 09:45:54 trini *//* * arch/ppc/kernel/open_pic.c -- OpenPIC Interrupt Handling * * Copyright (C) 1997 Geert Uytterhoeven * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. */#include <linux/config.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/init.h>#include <linux/irq.h>#include <linux/init.h>#include <asm/ptrace.h>#include <asm/signal.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/prom.h>#include <asm/sections.h>#include "local_irq.h"#include "open_pic.h"#include "open_pic_defs.h"#include "i8259.h"void* OpenPIC_Addr;static volatile struct OpenPIC *OpenPIC = NULL;u_int OpenPIC_NumInitSenses __initdata = 0;u_char *OpenPIC_InitSenses __initdata = NULL;extern int use_of_interrupt_tree;void find_ISUs(void);static u_int NumProcessors;static u_int NumSources;#ifdef CONFIG_POWER3static int NumISUs;#endifstatic int open_pic_irq_offset;static volatile unsigned char* chrp_int_ack_special;OpenPIC_SourcePtr ISU[OPENPIC_MAX_ISU];/* Global Operations */static void openpic_disable_8259_pass_through(void);static void openpic_set_priority(u_int pri);static void openpic_set_spurious(u_int vector);#ifdef CONFIG_SMP/* Interprocessor Interrupts */static void openpic_initipi(u_int ipi, u_int pri, u_int vector);static void openpic_ipi_action(int cpl, void *dev_id, struct pt_regs *regs);#endif/* Timer Interrupts */static void openpic_inittimer(u_int timer, u_int pri, u_int vector);static void openpic_maptimer(u_int timer, u_int cpumask);/* Interrupt Sources */static void openpic_enable_irq(u_int irq);static void openpic_disable_irq(u_int irq);static void openpic_initirq(u_int irq, u_int pri, u_int vector, int polarity, int is_level);static void openpic_mapirq(u_int irq, u_int cpumask);/* * These functions are not used but the code is kept here * for completeness and future reference. */static void openpic_reset(void);#ifdef notusedstatic void openpic_enable_8259_pass_through(void);static u_int openpic_get_priority(void);static u_int openpic_get_spurious(void);static void openpic_set_sense(u_int irq, int sense);#endif /* notused *//* * Description of the openpic for the higher-level irq code */static void openpic_end_irq(unsigned int irq_nr);static void openpic_ack_irq(unsigned int irq_nr);static void openpic_set_affinity(unsigned int irq_nr, unsigned long cpumask);struct hw_interrupt_type open_pic = { " OpenPIC ", NULL, NULL, openpic_enable_irq, openpic_disable_irq, openpic_ack_irq, openpic_end_irq, openpic_set_affinity};#ifdef CONFIG_SMPstatic void openpic_end_ipi(unsigned int irq_nr);static void openpic_ack_ipi(unsigned int irq_nr);static void openpic_enable_ipi(unsigned int irq_nr);static void openpic_disable_ipi(unsigned int irq_nr);struct hw_interrupt_type open_pic_ipi = { " OpenPIC ", NULL, NULL, openpic_enable_ipi, openpic_disable_ipi, openpic_ack_ipi, openpic_end_ipi, 0};#endif /* CONFIG_SMP *//* * Accesses to the current processor's openpic registers */#ifdef CONFIG_SMP#define THIS_CPU Processor[cpu]#define DECL_THIS_CPU int cpu = smp_hw_index[smp_processor_id()]#define CHECK_THIS_CPU check_arg_cpu(cpu)#else#define THIS_CPU Processor[0]#define DECL_THIS_CPU#define CHECK_THIS_CPU#endif /* CONFIG_SMP */#if 1#define check_arg_ipi(ipi) \ if (ipi < 0 || ipi >= OPENPIC_NUM_IPI) \ printk("open_pic.c:%d: illegal ipi %d\n", __LINE__, ipi);#define check_arg_timer(timer) \ if (timer < 0 || timer >= OPENPIC_NUM_TIMERS) \ printk("open_pic.c:%d: illegal timer %d\n", __LINE__, timer);#define check_arg_vec(vec) \ if (vec < 0 || vec >= OPENPIC_NUM_VECTORS) \ printk("open_pic.c:%d: illegal vector %d\n", __LINE__, vec);#define check_arg_pri(pri) \ if (pri < 0 || pri >= OPENPIC_NUM_PRI) \ printk("open_pic.c:%d: illegal priority %d\n", __LINE__, pri);/* * Print out a backtrace if it's out of range, since if it's larger than NR_IRQ's * data has probably been corrupted and we're going to panic or deadlock later * anyway --Troy */extern unsigned long* _get_SP(void);#define check_arg_irq(irq) \ if (irq < open_pic_irq_offset || irq >= (NumSources+open_pic_irq_offset)){ \ printk("open_pic.c:%d: illegal irq %d\n", __LINE__, irq); \ print_backtrace(_get_SP()); }#define check_arg_cpu(cpu) \ if (cpu < 0 || cpu >= NumProcessors){ \ printk("open_pic.c:%d: illegal cpu %d\n", __LINE__, cpu); \ print_backtrace(_get_SP()); }#else#define check_arg_ipi(ipi) do {} while (0)#define check_arg_timer(timer) do {} while (0)#define check_arg_vec(vec) do {} while (0)#define check_arg_pri(pri) do {} while (0)#define check_arg_irq(irq) do {} while (0)#define check_arg_cpu(cpu) do {} while (0)#endif#ifdef CONFIG_POWER3 #define GET_ISU(source) ISU[(source) >> 4][(source) & 0xf]#else #define GET_ISU(source) ISU[0][(source)]#endifu_int openpic_read(volatile u_int *addr){ u_int val; val = in_le32(addr); return val;}static inline void openpic_write(volatile u_int *addr, u_int val){ out_le32(addr, val);}static inline u_int openpic_readfield(volatile u_int *addr, u_int mask){ u_int val = openpic_read(addr); return val & mask;}inline void openpic_writefield(volatile u_int *addr, u_int mask, u_int field){ u_int val = openpic_read(addr); openpic_write(addr, (val & ~mask) | (field & mask));}static inline void openpic_clearfield(volatile u_int *addr, u_int mask){ openpic_writefield(addr, mask, 0);}static inline void openpic_setfield(volatile u_int *addr, u_int mask){ openpic_writefield(addr, mask, mask);}static void openpic_safe_writefield(volatile u_int *addr, u_int mask, u_int field){ openpic_setfield(addr, OPENPIC_MASK); while (openpic_read(addr) & OPENPIC_ACTIVITY); openpic_writefield(addr, mask | OPENPIC_MASK, field | OPENPIC_MASK);}#ifdef CONFIG_SMP/* yes this is right ... bug, feature, you decide! -- tgall */u_int openpic_read_IPI(volatile u_int* addr){ u_int val = 0;#ifdef CONFIG_POWER3 val = in_be32(addr);#else val = in_le32(addr);#endif return val;}/* because of the power3 be / le above, this is needed */inline void openpic_writefield_IPI(volatile u_int* addr, u_int mask, u_int field){ u_int val = openpic_read_IPI(addr); openpic_write(addr, (val & ~mask) | (field & mask));}static inline void openpic_clearfield_IPI(volatile u_int *addr, u_int mask){ openpic_writefield_IPI(addr, mask, 0);}static inline void openpic_setfield_IPI(volatile u_int *addr, u_int mask){ openpic_writefield_IPI(addr, mask, mask);}static void openpic_safe_writefield_IPI(volatile u_int *addr, u_int mask, u_int field){ openpic_setfield_IPI(addr, OPENPIC_MASK); /* wait until it's not in use */ /* BenH: Is this code really enough ? I would rather check the result * and eventually retry ... */ while(openpic_read_IPI(addr) & OPENPIC_ACTIVITY); openpic_writefield_IPI(addr, mask | OPENPIC_MASK, field | OPENPIC_MASK);}#endif /* CONFIG_SMP */void __init openpic_init(int main_pic, int offset, unsigned char* chrp_ack, int programmer_switch_irq){ u_int t, i; u_int timerfreq; const char *version; if (!OpenPIC_Addr) { printk("No OpenPIC found !\n"); return; } OpenPIC = (volatile struct OpenPIC *)OpenPIC_Addr; if ( ppc_md.progress ) ppc_md.progress("openpic enter",0x122); t = openpic_read(&OpenPIC->Global.Feature_Reporting0); switch (t & OPENPIC_FEATURE_VERSION_MASK) { case 1: version = "1.0"; break; case 2: version = "1.2"; break; case 3: version = "1.3"; break; default: version = "?"; break; } NumProcessors = ((t & OPENPIC_FEATURE_LAST_PROCESSOR_MASK) >> OPENPIC_FEATURE_LAST_PROCESSOR_SHIFT) + 1; NumSources = ((t & OPENPIC_FEATURE_LAST_SOURCE_MASK) >> OPENPIC_FEATURE_LAST_SOURCE_SHIFT) + 1; printk("OpenPIC Version %s (%d CPUs and %d IRQ sources) at %p\n", version, NumProcessors, NumSources, OpenPIC); timerfreq = openpic_read(&OpenPIC->Global.Timer_Frequency); if (timerfreq) printk("OpenPIC timer frequency is %d.%06d MHz\n", timerfreq / 1000000, timerfreq % 1000000); if (!main_pic) return; open_pic_irq_offset = offset; chrp_int_ack_special = (volatile unsigned char*)chrp_ack; /* Initialize timer interrupts */ if ( ppc_md.progress ) ppc_md.progress("openpic timer",0x3ba); for (i = 0; i < OPENPIC_NUM_TIMERS; i++) { /* Disabled, Priority 0 */ openpic_inittimer(i, 0, OPENPIC_VEC_TIMER+i+offset); /* No processor */ openpic_maptimer(i, 0); }#ifdef CONFIG_SMP /* Initialize IPI interrupts */ if ( ppc_md.progress ) ppc_md.progress("openpic ipi",0x3bb); for (i = 0; i < OPENPIC_NUM_IPI; i++) { /* Disabled, Priority 10..13 */ openpic_initipi(i, 10+i, OPENPIC_VEC_IPI+i+offset); /* IPIs are per-CPU */ irq_desc[OPENPIC_VEC_IPI+i+offset].status |= IRQ_PER_CPU; irq_desc[OPENPIC_VEC_IPI+i+offset].handler = &open_pic_ipi; }#endif find_ISUs(); /* Initialize external interrupts */ if (ppc_md.progress) ppc_md.progress("openpic ext",0x3bc); openpic_set_priority(0xf); /* SIOint (8259 cascade) is special */ if (offset) { openpic_initirq(0, 8, offset, 1, 1); openpic_mapirq(0, 1<<0); } /* Init all external sources */ for (i = 1; i < NumSources; i++) { int pri, sense; /* the bootloader may have left it enabled (bad !) */ openpic_disable_irq(i+offset); pri = (i == programmer_switch_irq)? 9: 8; sense = (i < OpenPIC_NumInitSenses)? OpenPIC_InitSenses[i]: 1; if (sense) irq_desc[i+offset].status = IRQ_LEVEL; /* Enabled, Priority 8 or 9 */ openpic_initirq(i, pri, i+offset, !sense, sense); /* Processor 0 */ openpic_mapirq(i, 1<<0); } /* Init descriptors */ for (i = offset; i < NumSources + offset; i++) irq_desc[i].handler = &open_pic; /* Initialize the spurious interrupt */ if (ppc_md.progress) ppc_md.progress("openpic spurious",0x3bd); openpic_set_spurious(OPENPIC_VEC_SPURIOUS+offset); /* Initialize the cascade */ if (offset) { if (request_irq(offset, no_action, SA_INTERRUPT, "82c59 cascade", NULL)) printk("Unable to get OpenPIC IRQ 0 for cascade\n"); } openpic_set_priority(0); openpic_disable_8259_pass_through(); if (ppc_md.progress) ppc_md.progress("openpic exit",0x222);}#ifdef CONFIG_POWER3void openpic_setup_ISU(int isu_num, unsigned long addr){ if (isu_num >= OPENPIC_MAX_ISU) return; ISU[isu_num] = (OpenPIC_SourcePtr) ioremap(addr, 0x400); if (isu_num >= NumISUs) NumISUs = isu_num + 1;}#endifvoid find_ISUs(void){#ifdef CONFIG_POWER3 /* Use /interrupt-controller/reg and * /interrupt-controller/interrupt-ranges from OF device tree * the ISU array is setup in chrp_pci.c in ibm_add_bridges * as a result * -- tgall */ /* basically each ISU is a bus, and this assumes that * open_pic_isu_count interrupts per bus are possible * ISU == Interrupt Source */ NumSources = NumISUs * 0x10;#else /* for non-distributed OpenPIC implementations it's in the IDU -- Cort */ ISU[0] = (OpenPIC_Source *)OpenPIC->Source;#endif}static void openpic_reset(void){ openpic_setfield(&OpenPIC->Global.Global_Configuration0, OPENPIC_CONFIG_RESET); while (openpic_readfield(&OpenPIC->Global.Global_Configuration0, OPENPIC_CONFIG_RESET)) mb();}#ifdef notusedstatic void openpic_enable_8259_pass_through(void){ openpic_clearfield(&OpenPIC->Global.Global_Configuration0, OPENPIC_CONFIG_8259_PASSTHROUGH_DISABLE);}#endif /* notused */static void openpic_disable_8259_pass_through(void){ openpic_setfield(&OpenPIC->Global.Global_Configuration0, OPENPIC_CONFIG_8259_PASSTHROUGH_DISABLE);}/* * Find out the current interrupt */u_int openpic_irq(void){ u_int vec; DECL_THIS_CPU;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -