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

📄 io_apic.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
{	int irq = vector_to_irq(vector);	move_native_irq(vector);	ack_edge_ioapic_irq(irq);}static unsigned int startup_level_ioapic_vector (unsigned int vector){	int irq = vector_to_irq(vector);	return startup_level_ioapic_irq (irq);}static void end_level_ioapic_vector (unsigned int vector){	int irq = vector_to_irq(vector);	move_native_irq(vector);	end_level_ioapic_irq(irq);}static void mask_IO_APIC_vector (unsigned int vector){	int irq = vector_to_irq(vector);	mask_IO_APIC_irq(irq);}static void unmask_IO_APIC_vector (unsigned int vector){	int irq = vector_to_irq(vector);	unmask_IO_APIC_irq(irq);}#ifdef CONFIG_SMPstatic void set_ioapic_affinity_vector (unsigned int vector,					cpumask_t cpu_mask){	int irq = vector_to_irq(vector);	set_native_irq_info(vector, cpu_mask);	set_ioapic_affinity_irq(irq, cpu_mask);}#endif#endif/* * Level and edge triggered IO-APIC interrupts need different handling, * so we use two separate IRQ descriptors. Edge triggered IRQs can be * handled with the level-triggered descriptor, but that one has slightly * more overhead. Level-triggered interrupts cannot be handled with the * edge-triggered handler, without risking IRQ storms and other ugly * races. */static struct hw_interrupt_type ioapic_edge_type __read_mostly = {	.typename 	= "IO-APIC-edge",	.startup 	= startup_edge_ioapic,	.shutdown 	= shutdown_edge_ioapic,	.enable 	= enable_edge_ioapic,	.disable 	= disable_edge_ioapic,	.ack 		= ack_edge_ioapic,	.end 		= end_edge_ioapic,#ifdef CONFIG_SMP	.set_affinity 	= set_ioapic_affinity,#endif};static struct hw_interrupt_type ioapic_level_type __read_mostly = {	.typename 	= "IO-APIC-level",	.startup 	= startup_level_ioapic,	.shutdown 	= shutdown_level_ioapic,	.enable 	= enable_level_ioapic,	.disable 	= disable_level_ioapic,	.ack 		= mask_and_ack_level_ioapic,	.end 		= end_level_ioapic,#ifdef CONFIG_SMP	.set_affinity 	= set_ioapic_affinity,#endif};static inline void init_IO_APIC_traps(void){	int irq;	/*	 * NOTE! The local APIC isn't very good at handling	 * multiple interrupts at the same interrupt level.	 * As the interrupt level is determined by taking the	 * vector number and shifting that right by 4, we	 * want to spread these out a bit so that they don't	 * all fall in the same interrupt level.	 *	 * Also, we've got to be careful not to trash gate	 * 0x80, because int 0x80 is hm, kind of importantish. ;)	 */	for (irq = 0; irq < NR_IRQS ; irq++) {		int tmp = irq;		if (use_pci_vector()) {			if (!platform_legacy_irq(tmp))				if ((tmp = vector_to_irq(tmp)) == -1)					continue;		}		if (IO_APIC_IRQ(tmp) && !IO_APIC_VECTOR(tmp)) {			/*			 * Hmm.. We don't have an entry for this,			 * so default to an old-fashioned 8259			 * interrupt if we can..			 */			if (irq < 16)				make_8259A_irq(irq);			else				/* Strange. Oh, well.. */				irq_desc[irq].handler = &no_irq_type;		}	}}static void enable_lapic_irq (unsigned int irq){	unsigned long v;	v = apic_read(APIC_LVT0);	apic_write_around(APIC_LVT0, v & ~APIC_LVT_MASKED);}static void disable_lapic_irq (unsigned int irq){	unsigned long v;	v = apic_read(APIC_LVT0);	apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);}static void ack_lapic_irq (unsigned int irq){	ack_APIC_irq();}static void end_lapic_irq (unsigned int i) { /* nothing */ }static struct hw_interrupt_type lapic_irq_type __read_mostly = {	.typename 	= "local-APIC-edge",	.startup 	= NULL, /* startup_irq() not used for IRQ0 */	.shutdown 	= NULL, /* shutdown_irq() not used for IRQ0 */	.enable 	= enable_lapic_irq,	.disable 	= disable_lapic_irq,	.ack 		= ack_lapic_irq,	.end 		= end_lapic_irq};static void setup_nmi (void){	/* 	 * Dirty trick to enable the NMI watchdog ...	 * We put the 8259A master into AEOI mode and	 * unmask on all local APICs LVT0 as NMI.	 *	 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')	 * is from Maciej W. Rozycki - so we do not have to EOI from	 * the NMI handler or the timer interrupt.	 */ 	apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");	on_each_cpu(enable_NMI_through_LVT0, NULL, 1, 1);	apic_printk(APIC_VERBOSE, " done.\n");}/* * This looks a bit hackish but it's about the only one way of sending * a few INTA cycles to 8259As and any associated glue logic.  ICR does * not support the ExtINT mode, unfortunately.  We need to send these * cycles as some i82489DX-based boards have glue logic that keeps the * 8259A interrupt line asserted until INTA.  --macro */static inline void unlock_ExtINT_logic(void){	int apic, pin, i;	struct IO_APIC_route_entry entry0, entry1;	unsigned char save_control, save_freq_select;	unsigned long flags;	pin  = find_isa_irq_pin(8, mp_INT);	apic = find_isa_irq_apic(8, mp_INT);	if (pin == -1)		return;	spin_lock_irqsave(&ioapic_lock, flags);	*(((int *)&entry0) + 1) = io_apic_read(apic, 0x11 + 2 * pin);	*(((int *)&entry0) + 0) = io_apic_read(apic, 0x10 + 2 * pin);	spin_unlock_irqrestore(&ioapic_lock, flags);	clear_IO_APIC_pin(apic, pin);	memset(&entry1, 0, sizeof(entry1));	entry1.dest_mode = 0;			/* physical delivery */	entry1.mask = 0;			/* unmask IRQ now */	entry1.dest.physical.physical_dest = hard_smp_processor_id();	entry1.delivery_mode = dest_ExtINT;	entry1.polarity = entry0.polarity;	entry1.trigger = 0;	entry1.vector = 0;	spin_lock_irqsave(&ioapic_lock, flags);	io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&entry1) + 1));	io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&entry1) + 0));	spin_unlock_irqrestore(&ioapic_lock, flags);	save_control = CMOS_READ(RTC_CONTROL);	save_freq_select = CMOS_READ(RTC_FREQ_SELECT);	CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,		   RTC_FREQ_SELECT);	CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);	i = 100;	while (i-- > 0) {		mdelay(10);		if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)			i -= 10;	}	CMOS_WRITE(save_control, RTC_CONTROL);	CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);	clear_IO_APIC_pin(apic, pin);	spin_lock_irqsave(&ioapic_lock, flags);	io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&entry0) + 1));	io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&entry0) + 0));	spin_unlock_irqrestore(&ioapic_lock, flags);}/* * This code may look a bit paranoid, but it's supposed to cooperate with * a wide range of boards and BIOS bugs.  Fortunately only the timer IRQ * is so screwy.  Thanks to Brian Perkins for testing/hacking this beast * fanatically on his truly buggy board. */static inline void check_timer(void){	int apic1, pin1, apic2, pin2;	int vector;	/*	 * get/set the timer IRQ vector:	 */	disable_8259A_irq(0);	vector = assign_irq_vector(0);	set_intr_gate(vector, interrupt[0]);	/*	 * Subtle, code in do_timer_interrupt() expects an AEOI	 * mode for the 8259A whenever interrupts are routed	 * through I/O APICs.  Also IRQ0 has to be enabled in	 * the 8259A which implies the virtual wire has to be	 * disabled in the local APIC.	 */	apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);	init_8259A(1);	timer_ack = 1;	enable_8259A_irq(0);	pin1  = find_isa_irq_pin(0, mp_INT);	apic1 = find_isa_irq_apic(0, mp_INT);	pin2  = ioapic_i8259.pin;	apic2 = ioapic_i8259.apic;	printk(KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n",		vector, apic1, pin1, apic2, pin2);	if (pin1 != -1) {		/*		 * Ok, does IRQ0 through the IOAPIC work?		 */		unmask_IO_APIC_irq(0);		if (timer_irq_works()) {			if (nmi_watchdog == NMI_IO_APIC) {				disable_8259A_irq(0);				setup_nmi();				enable_8259A_irq(0);			}			if (disable_timer_pin_1 > 0)				clear_IO_APIC_pin(0, pin1);			return;		}		clear_IO_APIC_pin(apic1, pin1);		printk(KERN_ERR "..MP-BIOS bug: 8254 timer not connected to "				"IO-APIC\n");	}	printk(KERN_INFO "...trying to set up timer (IRQ0) through the 8259A ... ");	if (pin2 != -1) {		printk("\n..... (found pin %d) ...", pin2);		/*		 * legacy devices should be connected to IO APIC #0		 */		setup_ExtINT_IRQ0_pin(apic2, pin2, vector);		if (timer_irq_works()) {			printk("works.\n");			if (pin1 != -1)				replace_pin_at_irq(0, apic1, pin1, apic2, pin2);			else				add_pin_to_irq(0, apic2, pin2);			if (nmi_watchdog == NMI_IO_APIC) {				setup_nmi();			}			return;		}		/*		 * Cleanup, just in case ...		 */		clear_IO_APIC_pin(apic2, pin2);	}	printk(" failed.\n");	if (nmi_watchdog == NMI_IO_APIC) {		printk(KERN_WARNING "timer doesn't work through the IO-APIC - disabling NMI Watchdog!\n");		nmi_watchdog = 0;	}	printk(KERN_INFO "...trying to set up timer as Virtual Wire IRQ...");	disable_8259A_irq(0);	irq_desc[0].handler = &lapic_irq_type;	apic_write_around(APIC_LVT0, APIC_DM_FIXED | vector);	/* Fixed mode */	enable_8259A_irq(0);	if (timer_irq_works()) {		printk(" works.\n");		return;	}	apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);	printk(" failed.\n");	printk(KERN_INFO "...trying to set up timer as ExtINT IRQ...");	timer_ack = 0;	init_8259A(0);	make_8259A_irq(0);	apic_write_around(APIC_LVT0, APIC_DM_EXTINT);	unlock_ExtINT_logic();	if (timer_irq_works()) {		printk(" works.\n");		return;	}	printk(" failed :(.\n");	panic("IO-APIC + timer doesn't work!  Boot with apic=debug and send a "		"report.  Then try booting with the 'noapic' option");}/* * * IRQ's that are handled by the PIC in the MPS IOAPIC case. * - IRQ2 is the cascade IRQ, and cannot be a io-apic IRQ. *   Linux doesn't really care, as it's not actually used *   for any interrupt handling anyway. */#define PIC_IRQS	(1 << PIC_CASCADE_IR)void __init setup_IO_APIC(void){	enable_IO_APIC();	if (acpi_ioapic)		io_apic_irqs = ~0;	/* all IRQs go through IOAPIC */	else		io_apic_irqs = ~PIC_IRQS;	printk("ENABLING IO-APIC IRQs\n");	/*	 * Set up IO-APIC IRQ routing.	 */	if (!acpi_ioapic)		setup_ioapic_ids_from_mpc();	sync_Arb_IDs();	setup_IO_APIC_irqs();	init_IO_APIC_traps();	check_timer();	if (!acpi_ioapic)		print_IO_APIC();}/* *	Called after all the initialization is done. If we didnt find any *	APIC bugs then we can allow the modify fast path */ static int __init io_apic_bug_finalize(void){	if(sis_apic_bug == -1)		sis_apic_bug = 0;	return 0;}late_initcall(io_apic_bug_finalize);struct sysfs_ioapic_data {	struct sys_device dev;	struct IO_APIC_route_entry entry[0];};static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];static int ioapic_suspend(struct sys_device *dev, pm_message_t state){	struct IO_APIC_route_entry *entry;	struct sysfs_ioapic_data *data;	unsigned long flags;	int i;		data = container_of(dev, struct sysfs_ioapic_data, dev);	entry = data->entry;	spin_lock_irqsave(&ioapic_lock, flags);	for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ ) {		*(((int *)entry) + 1) = io_apic_read(dev->id, 0x11 + 2 * i);		*(((int *)entry) + 0) = io_apic_read(dev->id, 0x10 + 2 * i);	}	spin_unlock_irqrestore(&ioapic_lock, flags);	return 0;}static int ioapic_resume(struct sys_device *dev){	struct IO_APIC_route_entry *entry;	struct sysfs_ioapic_data *data;	unsigned long flags;	union IO_APIC_reg_00 reg_00;	int i;		data = container_of(dev, struct sysfs_ioapic_data, dev);	entry = data->entry;	spin_lock_irqsave(&ioapic_lock, flags);	reg_00.raw = io_apic_read(dev->id, 0);	if (reg_00.bits.ID != mp_ioapics[dev->id].mpc_apicid) {		reg_00.bits.ID = mp_ioapics[dev->id].mpc_apicid;		io_apic_write(dev->id, 0, reg_00.raw);	}	for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ ) {		io_apic_write(dev->id, 0x11+2*i, *(((int *)entry)+1));		io_apic_write(dev->id, 0x10+2*i, *(((int *)entry)+0));	}	spin_unlock_irqrestore(&ioapic_lock, flags);	return 0;}static struct sysdev_class ioapic_sysdev_class = {	set_kset_name("ioapic"),	.suspend = ioapic_suspend,	.resume = ioapic_resume,};static int __init ioapic_init_sysfs(void){	struct sys_device * dev;	int i, size, error = 0;	error = sysdev_class_register(&ioapic_sysdev_class);	if (error)		return error;	for (i = 0; i < nr_ioapics; i++ ) {		size = sizeof(struct sys_device) + nr_ioapic_registers[i] 			* sizeof(struct IO_APIC_route_entry);		mp_ioapic_data[i] = kmalloc(size, GFP_KERNEL);		if (!mp_ioapic_data[i]) {			printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);			continue;		}		memset(mp_ioapic_data[i], 0, size);		dev = &mp_ioapic_data[i]->dev;		dev->id = i; 		dev->cls = &ioapic_sysdev_class;		error = sysdev_register(dev);		if (error) {			kfree(mp_ioapic_data[i]);			mp_ioapic_data[i] = NULL;			printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);			continue;		}	}	return 0;}device_initcall(ioapic_init_sysfs);/* --------------------------------------------------------------------------                          ACPI-based IOAPIC Configuration   -------------------------------------------------------------------------- */#ifdef CONFIG_ACPIint __init io_apic_get_unique_id (int ioapic, int apic_id){	union

⌨️ 快捷键说明

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