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

📄 io_apic.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	.shutdown 	= shutdown_level_ioapic,	.enable 	= enable_level_ioapic,	.disable 	= disable_level_ioapic,	.ack 		= mask_and_ack_level_ioapic,	.end 		= end_level_ioapic,	.set_affinity 	= set_ioapic_affinity,};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 = {	.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.	 */ 	printk(KERN_INFO "activating NMI Watchdog ...");	on_each_cpu(enable_NMI_through_LVT0, NULL, 1, 1);	printk(" 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 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);	if (pin == -1)		return;	spin_lock_irqsave(&ioapic_lock, flags);	*(((int *)&entry0) + 1) = io_apic_read(0, 0x11 + 2 * pin);	*(((int *)&entry0) + 0) = io_apic_read(0, 0x10 + 2 * pin);	spin_unlock_irqrestore(&ioapic_lock, flags);	clear_IO_APIC_pin(0, 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(0, 0x11 + 2 * pin, *(((int *)&entry1) + 1));	io_apic_write(0, 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(0, pin);	spin_lock_irqsave(&ioapic_lock, flags);	io_apic_write(0, 0x11 + 2 * pin, *(((int *)&entry0) + 1));	io_apic_write(0, 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 pin1, 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);	pin2 = find_isa_irq_pin(0, mp_ExtINT);	printk(KERN_INFO "..TIMER: vector=0x%02X pin1=%d pin2=%d\n", vector, pin1, 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);				check_nmi_watchdog();			}			return;		}		clear_IO_APIC_pin(0, 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(pin2, vector);		if (timer_irq_works()) {			printk("works.\n");			if (pin1 != -1)				replace_pin_at_irq(0, 0, pin1, 0, pin2);			else				add_pin_to_irq(0, 0, pin2);			if (nmi_watchdog == NMI_IO_APIC) {				setup_nmi();				check_nmi_watchdog();			}			return;		}		/*		 * Cleanup, just in case ...		 */		clear_IO_APIC_pin(0, 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! Try using the 'noapic' kernel parameter\n");}/* * * 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);/* --------------------------------------------------------------------------                          ACPI-based IOAPIC Configuration   -------------------------------------------------------------------------- */#ifdef CONFIG_ACPI_BOOTint __init io_apic_get_unique_id (int ioapic, int apic_id){	union IO_APIC_reg_00 reg_00;	static physid_mask_t apic_id_map = PHYSID_MASK_NONE;	physid_mask_t tmp;	unsigned long flags;	int i = 0;	/*	 * The P4 platform supports up to 256 APIC IDs on two separate APIC 	 * buses (one for LAPICs, one for IOAPICs), where predecessors only 	 * supports up to 16 on one shared APIC bus.	 * 	 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full	 *      advantage of new APIC bus architecture.	 */	if (physids_empty(apic_id_map))		apic_id_map = ioapic_phys_id_map(phys_cpu_present_map);	spin_lock_irqsave(&ioapic_lock, flags);	reg_00.raw = io_apic_read(ioapic, 0);	spin_unlock_irqrestore(&ioapic_lock, flags);	if (apic_id >= get_physical_broadcast()) {		printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "			"%d\n", ioapic, apic_id, reg_00.bits.ID);		apic_id = reg_00.bits.ID;	}	/*	 * Every APIC in a system must have a unique ID or we get lots of nice 	 * 'stuck on smp_invalidate_needed IPI wait' messages.	 */	if (check_apicid_used(apic_id_map, apic_id)) {		for (i = 0; i < get_physical_broadcast(); i++) {			if (!check_apicid_used(apic_id_map, i))				break;		}		if (i == get_physical_broadcast())			panic("Max apic_id exceeded!\n");		printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "			"trying %d\n", ioapic, apic_id, i);		apic_id = i;	} 	tmp = apicid_to_cpu_present(apic_id);	physids_or(apic_id_map, apic_id_map, tmp);	if (reg_00.bits.ID != apic_id) {		reg_00.bits.ID = apic_id;		spin_lock_irqsave(&ioapic_lock, flags);		io_apic_write(ioapic, 0, reg_00.raw);		reg_00.raw = io_apic_read(ioapic, 0);		spin_unlock_irqrestore(&ioapic_lock, flags);		/* Sanity check */		if (reg_00.bits.ID != apic_id)			panic("IOAPIC[%d]: Unable change apic_id!\n", ioapic);	}	printk(KERN_INFO "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);	return apic_id;}int __init io_apic_get_version (int ioapic){	union IO_APIC_reg_01	reg_01;	unsigned long flags;	spin_lock_irqsave(&ioapic_lock, flags);	reg_01.raw = io_apic_read(ioapic, 1);	spin_unlock_irqrestore(&ioapic_lock, flags);	return reg_01.bits.version;}int __init io_apic_get_redir_entries (int ioapic){	union IO_APIC_reg_01	reg_01;	unsigned long flags;	spin_lock_irqsave(&ioapic_lock, flags);	reg_01.raw = io_apic_read(ioapic, 1);	spin_unlock_irqrestore(&ioapic_lock, flags);	return reg_01.bits.entries;}int io_apic_set_pci_routing (int ioapic, int pin, int irq, int edge_level, int active_high_low){	struct IO_APIC_route_entry entry;	unsigned long flags;	if (!IO_APIC_IRQ(irq)) {		printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",			ioapic);		return -EINVAL;	}	/*	 * Generate a PCI IRQ routing entry and program the IOAPIC accordingly.	 * Note that we mask (disable) IRQs now -- these get enabled when the	 * corresponding device driver registers for this IRQ.	 */	memset(&entry,0,sizeof(entry));	entry.delivery_mode = INT_DELIVERY_MODE;	entry.dest_mode = INT_DEST_MODE;	entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);	entry.trigger = edge_level;	entry.polarity = active_high_low;	entry.mask  = 1;	/*	 * IRQs < 16 are already in the irq_2_pin[] map	 */	if (irq >= 16)		add_pin_to_irq(irq, ioapic, pin);	entry.vector = assign_irq_vector(irq);	Dprintk(KERN_DEBUG "IOAPIC[%d]: Set PCI routing entry (%d-%d -> 0x%x -> "		"IRQ %d Mode:%i Active:%i)\n", ioapic, 		mp_ioapics[ioapic].mpc_apicid, pin, entry.vector, irq, edge_level, active_high_low); 	if (use_pci_vector() && !platform_legacy_irq(irq))		irq = IO_APIC_VECTOR(irq);	if (edge_level) {		irq_desc[irq].handler = &ioapic_level_type;	} else {		irq_desc[irq].handler = &ioapic_edge_type;	}	set_intr_gate(entry.vector, interrupt[irq]);	if (!ioapic && (irq < 16))		disable_8259A_irq(irq);	spin_lock_irqsave(&ioapic_lock, flags);	io_apic_write(ioapic, 0x11+2*pin, *(((int *)&entry)+1));	io_apic_write(ioapic, 0x10+2*pin, *(((int *)&entry)+0));	spin_unlock_irqrestore(&ioapic_lock, flags);	return 0;}#endif /*CONFIG_ACPI_BOOT*/

⌨️ 快捷键说明

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