⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 open_pic.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
	check_arg_ipi(ipi);	check_arg_pri(pri);	check_arg_vec(vec);	openpic_safe_writefield_IPI(&OpenPIC->Global.IPI_Vector_Priority(ipi),				OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK,				(pri << OPENPIC_PRIORITY_SHIFT) | vec);}/* *  Send an IPI to one or more CPUs * *  Externally called, however, it takes an IPI number (0...OPENPIC_NUM_IPI) *  and not a system-wide interrupt number */void openpic_cause_IPI(u_int ipi, cpumask_t cpumask){	DECL_THIS_CPU;	CHECK_THIS_CPU;	check_arg_ipi(ipi);	openpic_write(&OpenPIC->THIS_CPU.IPI_Dispatch(ipi),		      cpus_addr(physmask(cpumask))[0]);}void openpic_request_IPIs(void){	int i;	/*	 * Make sure this matches what is defined in smp.c for	 * smp_message_{pass|recv}() or what shows up in	 * /proc/interrupts will be wrong!!! --Troy */	if (OpenPIC == NULL)		return;	/* IPIs are marked SA_INTERRUPT as they must run with irqs disabled */	request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset,		    openpic_ipi_action, SA_INTERRUPT,		    "IPI0 (call function)", NULL);	request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset+1,		    openpic_ipi_action, SA_INTERRUPT,		    "IPI1 (reschedule)", NULL);	request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset+2,		    openpic_ipi_action, SA_INTERRUPT,		    "IPI2 (invalidate tlb)", NULL);	request_irq(OPENPIC_VEC_IPI+open_pic_irq_offset+3,		    openpic_ipi_action, SA_INTERRUPT,		    "IPI3 (xmon break)", NULL);	for ( i = 0; i < OPENPIC_NUM_IPI ; i++ )		openpic_enable_ipi(OPENPIC_VEC_IPI+open_pic_irq_offset+i);}/* * Do per-cpu setup for SMP systems. * * Get IPI's working and start taking interrupts. *   -- Cort */void __devinit do_openpic_setup_cpu(void){#ifdef CONFIG_IRQ_ALL_CPUS 	int i;	cpumask_t msk = CPU_MASK_NONE;#endif	spin_lock(&openpic_setup_lock);#ifdef CONFIG_IRQ_ALL_CPUS	cpu_set(smp_hw_index[smp_processor_id()], msk); 	/* let the openpic know we want intrs. default affinity 	 * is 0xffffffff until changed via /proc 	 * That's how it's done on x86. If we want it differently, then 	 * we should make sure we also change the default values of irq_affinity 	 * in irq.c. 	 */ 	for (i = 0; i < NumSources; i++)		openpic_mapirq(i, msk, CPU_MASK_ALL);#endif /* CONFIG_IRQ_ALL_CPUS */ 	openpic_set_priority(0);	spin_unlock(&openpic_setup_lock);}#endif /* CONFIG_SMP *//* *  Initialize a timer interrupt (and disable it) * *  timer: OpenPIC timer number *  pri: interrupt source priority *  vec: the vector it will produce */static void __init openpic_inittimer(u_int timer, u_int pri, u_int vec){	check_arg_timer(timer);	check_arg_pri(pri);	check_arg_vec(vec);	openpic_safe_writefield(&OpenPIC->Global.Timer[timer].Vector_Priority,				OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK,				(pri << OPENPIC_PRIORITY_SHIFT) | vec);}/* *  Map a timer interrupt to one or more CPUs */static void __init openpic_maptimer(u_int timer, cpumask_t cpumask){	cpumask_t phys = physmask(cpumask);	check_arg_timer(timer);	openpic_write(&OpenPIC->Global.Timer[timer].Destination,		      cpus_addr(phys)[0]);}/* * Change the priority of an interrupt */void __initopenpic_set_irq_priority(u_int irq, u_int pri){	check_arg_irq(irq);	openpic_safe_writefield(&ISR[irq - open_pic_irq_offset]->Vector_Priority,				OPENPIC_PRIORITY_MASK,				pri << OPENPIC_PRIORITY_SHIFT);}/* * Initalize the interrupt source which will generate an NMI. * This raises the interrupt's priority from 8 to 9. * * irq: The logical IRQ which generates an NMI. */void __initopenpic_init_nmi_irq(u_int irq){	check_arg_irq(irq);	openpic_set_irq_priority(irq, OPENPIC_PRIORITY_NMI);}/* * * All functions below take an offset'ed irq argument * *//* * Hookup a cascade to the OpenPIC. */static struct irqaction openpic_cascade_irqaction = {	.handler = no_action,	.flags = SA_INTERRUPT,	.mask = CPU_MASK_NONE,};void __initopenpic_hookup_cascade(u_int irq, char *name,	int (*cascade_fn)(struct pt_regs *)){	openpic_cascade_irq = irq;	openpic_cascade_fn = cascade_fn;	if (setup_irq(irq, &openpic_cascade_irqaction))		printk("Unable to get OpenPIC IRQ %d for cascade\n",				irq - open_pic_irq_offset);}/* *  Enable/disable an external interrupt source * *  Externally called, irq is an offseted system-wide interrupt number */static void openpic_enable_irq(u_int irq){	volatile u_int __iomem *vpp;	check_arg_irq(irq);	vpp = &ISR[irq - open_pic_irq_offset]->Vector_Priority;	openpic_clearfield(vpp, OPENPIC_MASK);	/* make sure mask gets to controller before we return to user */	do {		mb(); /* sync is probably useless here */	} while (openpic_readfield(vpp, OPENPIC_MASK));}static void openpic_disable_irq(u_int irq){	volatile u_int __iomem *vpp;	u32 vp;	check_arg_irq(irq);	vpp = &ISR[irq - open_pic_irq_offset]->Vector_Priority;	openpic_setfield(vpp, OPENPIC_MASK);	/* make sure mask gets to controller before we return to user */	do {		mb();  /* sync is probably useless here */		vp = openpic_readfield(vpp, OPENPIC_MASK | OPENPIC_ACTIVITY);	} while((vp & OPENPIC_ACTIVITY) && !(vp & OPENPIC_MASK));}#ifdef CONFIG_SMP/* *  Enable/disable an IPI interrupt source * *  Externally called, irq is an offseted system-wide interrupt number */void openpic_enable_ipi(u_int irq){	irq -= (OPENPIC_VEC_IPI+open_pic_irq_offset);	check_arg_ipi(irq);	openpic_clearfield_IPI(&OpenPIC->Global.IPI_Vector_Priority(irq), OPENPIC_MASK);}void openpic_disable_ipi(u_int irq){	irq -= (OPENPIC_VEC_IPI+open_pic_irq_offset);	check_arg_ipi(irq);	openpic_setfield_IPI(&OpenPIC->Global.IPI_Vector_Priority(irq), OPENPIC_MASK);}#endif/* *  Initialize an interrupt source (and disable it!) * *  irq: OpenPIC interrupt number *  pri: interrupt source priority *  vec: the vector it will produce *  pol: polarity (1 for positive, 0 for negative) *  sense: 1 for level, 0 for edge */static void __initopenpic_initirq(u_int irq, u_int pri, u_int vec, int pol, int sense){	openpic_safe_writefield(&ISR[irq]->Vector_Priority,				OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK |				OPENPIC_SENSE_MASK | OPENPIC_POLARITY_MASK,				(pri << OPENPIC_PRIORITY_SHIFT) | vec |				(pol ? OPENPIC_POLARITY_POSITIVE :			    		OPENPIC_POLARITY_NEGATIVE) |				(sense ? OPENPIC_SENSE_LEVEL : OPENPIC_SENSE_EDGE));}/* *  Map an interrupt source to one or more CPUs */static void openpic_mapirq(u_int irq, cpumask_t physmask, cpumask_t keepmask){	if (ISR[irq] == 0)		return;	if (!cpus_empty(keepmask)) {		cpumask_t irqdest = { .bits[0] = openpic_read(&ISR[irq]->Destination) };		cpus_and(irqdest, irqdest, keepmask);		cpus_or(physmask, physmask, irqdest);	}	openpic_write(&ISR[irq]->Destination, cpus_addr(physmask)[0]);}#ifdef notused/* *  Set the sense for an interrupt source (and disable it!) * *  sense: 1 for level, 0 for edge */static void openpic_set_sense(u_int irq, int sense){	if (ISR[irq] != 0)		openpic_safe_writefield(&ISR[irq]->Vector_Priority,					OPENPIC_SENSE_LEVEL,					(sense ? OPENPIC_SENSE_LEVEL : 0));}#endif /* notused *//* No spinlocks, should not be necessary with the OpenPIC * (1 register = 1 interrupt and we have the desc lock). */static void openpic_ack_irq(unsigned int irq_nr){#ifdef __SLOW_VERSION__	openpic_disable_irq(irq_nr);	openpic_eoi();#else	if ((irq_desc[irq_nr].status & IRQ_LEVEL) == 0)		openpic_eoi();#endif}static void openpic_end_irq(unsigned int irq_nr){#ifdef __SLOW_VERSION__	if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))	    && irq_desc[irq_nr].action)		openpic_enable_irq(irq_nr);#else	if ((irq_desc[irq_nr].status & IRQ_LEVEL) != 0)		openpic_eoi();#endif}static void openpic_set_affinity(unsigned int irq_nr, cpumask_t cpumask){	openpic_mapirq(irq_nr - open_pic_irq_offset, physmask(cpumask), CPU_MASK_NONE);}#ifdef CONFIG_SMPstatic void openpic_ack_ipi(unsigned int irq_nr){	openpic_eoi();}static void openpic_end_ipi(unsigned int irq_nr){}static irqreturn_t openpic_ipi_action(int cpl, void *dev_id, struct pt_regs *regs){	smp_message_recv(cpl-OPENPIC_VEC_IPI-open_pic_irq_offset, regs);	return IRQ_HANDLED;}#endif /* CONFIG_SMP */intopenpic_get_irq(struct pt_regs *regs){	int irq = openpic_irq();	/*	 * Check for the cascade interrupt and call the cascaded	 * interrupt controller function (usually i8259_irq) if so.	 * This should move to irq.c eventually.  -- paulus	 */	if (irq == openpic_cascade_irq && openpic_cascade_fn != NULL) {		int cirq = openpic_cascade_fn(regs);		/* Allow for the cascade being shared with other devices */		if (cirq != -1) {			irq = cirq;			openpic_eoi();		}	} else if (irq == OPENPIC_VEC_SPURIOUS)		irq = -1;	return irq;}#ifdef CONFIG_SMPvoidsmp_openpic_message_pass(int target, int msg){	cpumask_t mask = CPU_MASK_ALL;	/* make sure we're sending something that translates to an IPI */	if (msg > 0x3) {		printk("SMP %d: smp_message_pass: unknown msg %d\n",		       smp_processor_id(), msg);		return;	}	switch (target) {	case MSG_ALL:		openpic_cause_IPI(msg, mask);		break;	case MSG_ALL_BUT_SELF:		cpu_clear(smp_processor_id(), mask);		openpic_cause_IPI(msg, mask);		break;	default:		openpic_cause_IPI(msg, cpumask_of_cpu(target));		break;	}}#endif /* CONFIG_SMP */#ifdef CONFIG_PM/* * We implement the IRQ controller as a sysdev and put it * to sleep at powerdown stage (the callback is named suspend, * but it's old semantics, for the Device Model, it's really * powerdown). The possible problem is that another sysdev that * happens to be suspend after this one will have interrupts off, * that may be an issue... For now, this isn't an issue on pmac * though... */static u32 save_ipi_vp[OPENPIC_NUM_IPI];static u32 save_irq_src_vp[OPENPIC_MAX_SOURCES];static u32 save_irq_src_dest[OPENPIC_MAX_SOURCES];static u32 save_cpu_task_pri[OPENPIC_MAX_PROCESSORS];static int openpic_suspend_count;static void openpic_cached_enable_irq(u_int irq){	check_arg_irq(irq);	save_irq_src_vp[irq - open_pic_irq_offset] &= ~OPENPIC_MASK;}static void openpic_cached_disable_irq(u_int irq){	check_arg_irq(irq);	save_irq_src_vp[irq - open_pic_irq_offset] |= OPENPIC_MASK;}/* WARNING: Can be called directly by the cpufreq code with NULL parameter, * we need something better to deal with that... Maybe switch to S1 for * cpufreq changes */int openpic_suspend(struct sys_device *sysdev, pm_message_t state){	int	i;	unsigned long flags;	spin_lock_irqsave(&openpic_setup_lock, flags);	if (openpic_suspend_count++ > 0) {		spin_unlock_irqrestore(&openpic_setup_lock, flags);		return 0;	} 	openpic_set_priority(0xf);	open_pic.enable = openpic_cached_enable_irq;	open_pic.disable = openpic_cached_disable_irq;	for (i=0; i<NumProcessors; i++) {		save_cpu_task_pri[i] = openpic_read(&OpenPIC->Processor[i].Current_Task_Priority);		openpic_writefield(&OpenPIC->Processor[i].Current_Task_Priority,				   OPENPIC_CURRENT_TASK_PRIORITY_MASK, 0xf);	}	for (i=0; i<OPENPIC_NUM_IPI; i++)		save_ipi_vp[i] = openpic_read(&OpenPIC->Global.IPI_Vector_Priority(i));	for (i=0; i<NumSources; i++) {		if (ISR[i] == 0)			continue;		save_irq_src_vp[i] = openpic_read(&ISR[i]->Vector_Priority) & ~OPENPIC_ACTIVITY;		save_irq_src_dest[i] = openpic_read(&ISR[i]->Destination);	}	spin_unlock_irqrestore(&openpic_setup_lock, flags);	return 0;}/* WARNING: Can be called directly by the cpufreq code with NULL parameter, * we need something better to deal with that... Maybe switch to S1 for * cpufreq changes */int openpic_resume(struct sys_device *sysdev){	int		i;	unsigned long	flags;	u32		vppmask =	OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK |					OPENPIC_SENSE_MASK | OPENPIC_POLARITY_MASK |					OPENPIC_MASK;	spin_lock_irqsave(&openpic_setup_lock, flags);	if ((--openpic_suspend_count) > 0) {		spin_unlock_irqrestore(&openpic_setup_lock, flags);		return 0;	}	/* OpenPIC sometimes seem to need some time to be fully back up... */	do {		openpic_set_spurious(OPENPIC_VEC_SPURIOUS);	} while(openpic_readfield(&OpenPIC->Global.Spurious_Vector, OPENPIC_VECTOR_MASK)			!= OPENPIC_VEC_SPURIOUS);		openpic_disable_8259_pass_through();	for (i=0; i<OPENPIC_NUM_IPI; i++)		openpic_write(&OpenPIC->Global.IPI_Vector_Priority(i),			      save_ipi_vp[i]);	for (i=0; i<NumSources; i++) {		if (ISR[i] == 0)			continue;		openpic_write(&ISR[i]->Destination, save_irq_src_dest[i]);		openpic_write(&ISR[i]->Vector_Priority, save_irq_src_vp[i]);		/* make sure mask gets to controller before we return to user */		do {			openpic_write(&ISR[i]->Vector_Priority, save_irq_src_vp[i]);		} while (openpic_readfield(&ISR[i]->Vector_Priority, vppmask)			 != (save_irq_src_vp[i] & vppmask));	}	for (i=0; i<NumProcessors; i++)		openpic_write(&OpenPIC->Processor[i].Current_Task_Priority,			      save_cpu_task_pri[i]);	open_pic.enable = openpic_enable_irq;	open_pic.disable = openpic_disable_irq; 	openpic_set_priority(0);	spin_unlock_irqrestore(&openpic_setup_lock, flags);	return 0;}#endif /* CONFIG_PM */static struct sysdev_class openpic_sysclass = {	set_kset_name("openpic"),};static struct sys_device device_openpic = {	.id		= 0,	.cls		= &openpic_sysclass,};static struct sysdev_driver driver_openpic = {#ifdef CONFIG_PM	.suspend	= &openpic_suspend,	.resume		= &openpic_resume,#endif /* CONFIG_PM */};static int __init init_openpic_sysfs(void){	int rc;	if (!OpenPIC_Addr)		return -ENODEV;	printk(KERN_DEBUG "Registering openpic with sysfs...\n");	rc = sysdev_class_register(&openpic_sysclass);	if (rc) {		printk(KERN_ERR "Failed registering openpic sys class\n");		return -ENODEV;	}	rc = sysdev_register(&device_openpic);	if (rc) {		printk(KERN_ERR "Failed registering openpic sys device\n");		return -ENODEV;	}	rc = sysdev_driver_register(&openpic_sysclass, &driver_openpic);	if (rc) {		printk(KERN_ERR "Failed registering openpic sys driver\n");		return -ENODEV;	}	return 0;}subsys_initcall(init_openpic_sysfs);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -