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

📄 io_apic_64.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
	printk(KERN_DEBUG "\nprinting PIC contents\n");	spin_lock_irqsave(&i8259A_lock, flags);	v = inb(0xa1) << 8 | inb(0x21);	printk(KERN_DEBUG "... PIC  IMR: %04x\n", v);	v = inb(0xa0) << 8 | inb(0x20);	printk(KERN_DEBUG "... PIC  IRR: %04x\n", v);	outb(0x0b,0xa0);	outb(0x0b,0x20);	v = inb(0xa0) << 8 | inb(0x20);	outb(0x0a,0xa0);	outb(0x0a,0x20);	spin_unlock_irqrestore(&i8259A_lock, flags);	printk(KERN_DEBUG "... PIC  ISR: %04x\n", v);	v = inb(0x4d1) << 8 | inb(0x4d0);	printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);}#endif  /*  0  */static void __init enable_IO_APIC(void){	union IO_APIC_reg_01 reg_01;	int i8259_apic, i8259_pin;	int i, apic;	unsigned long flags;	for (i = 0; i < PIN_MAP_SIZE; i++) {		irq_2_pin[i].pin = -1;		irq_2_pin[i].next = 0;	}	/*	 * The number of IO-APIC IRQ registers (== #pins):	 */	for (apic = 0; apic < nr_ioapics; apic++) {		spin_lock_irqsave(&ioapic_lock, flags);		reg_01.raw = io_apic_read(apic, 1);		spin_unlock_irqrestore(&ioapic_lock, flags);		nr_ioapic_registers[apic] = reg_01.bits.entries+1;	}	for(apic = 0; apic < nr_ioapics; apic++) {		int pin;		/* See if any of the pins is in ExtINT mode */		for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {			struct IO_APIC_route_entry entry;			entry = ioapic_read_entry(apic, pin);			/* If the interrupt line is enabled and in ExtInt mode			 * I have found the pin where the i8259 is connected.			 */			if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {				ioapic_i8259.apic = apic;				ioapic_i8259.pin  = pin;				goto found_i8259;			}		}	} found_i8259:	/* Look to see what if the MP table has reported the ExtINT */	i8259_pin  = find_isa_irq_pin(0, mp_ExtINT);	i8259_apic = find_isa_irq_apic(0, mp_ExtINT);	/* Trust the MP table if nothing is setup in the hardware */	if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {		printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");		ioapic_i8259.pin  = i8259_pin;		ioapic_i8259.apic = i8259_apic;	}	/* Complain if the MP table and the hardware disagree */	if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&		(i8259_pin >= 0) && (ioapic_i8259.pin >= 0))	{		printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");	}	/*	 * Do not trust the IO-APIC being empty at bootup	 */	clear_IO_APIC();}/* * Not an __init, needed by the reboot code */void disable_IO_APIC(void){	/*	 * Clear the IO-APIC before rebooting:	 */	clear_IO_APIC();	/*	 * If the i8259 is routed through an IOAPIC	 * Put that IOAPIC in virtual wire mode	 * so legacy interrupts can be delivered.	 */	if (ioapic_i8259.pin != -1) {		struct IO_APIC_route_entry entry;		memset(&entry, 0, sizeof(entry));		entry.mask            = 0; /* Enabled */		entry.trigger         = 0; /* Edge */		entry.irr             = 0;		entry.polarity        = 0; /* High */		entry.delivery_status = 0;		entry.dest_mode       = 0; /* Physical */		entry.delivery_mode   = dest_ExtINT; /* ExtInt */		entry.vector          = 0;		entry.dest          = GET_APIC_ID(apic_read(APIC_ID));		/*		 * Add it to the IO-APIC irq-routing table:		 */		ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);	}	disconnect_bsp_APIC(ioapic_i8259.pin != -1);}/* * There is a nasty bug in some older SMP boards, their mptable lies * about the timer IRQ. We do the following to work around the situation: * *	- timer IRQ defaults to IO-APIC IRQ *	- if this function detects that timer IRQs are defunct, then we fall *	  back to ISA timer IRQs */static int __init timer_irq_works(void){	unsigned long t1 = jiffies;	unsigned long flags;	local_save_flags(flags);	local_irq_enable();	/* Let ten ticks pass... */	mdelay((10 * 1000) / HZ);	local_irq_restore(flags);	/*	 * Expect a few ticks at least, to be sure some possible	 * glue logic does not lock up after one or two first	 * ticks in a non-ExtINT mode.  Also the local APIC	 * might have cached one ExtINT interrupt.  Finally, at	 * least one tick may be lost due to delays.	 */	/* jiffies wrap? */	if (jiffies - t1 > 4)		return 1;	return 0;}/* * In the SMP+IOAPIC case it might happen that there are an unspecified * number of pending IRQ events unhandled. These cases are very rare, * so we 'resend' these IRQs via IPIs, to the same CPU. It's much * better to do it this way as thus we do not have to be aware of * 'pending' interrupts in the IRQ path, except at this point. *//* * Edge triggered needs to resend any interrupt * that was delayed but this is now handled in the device * independent code. *//* * Starting up a edge-triggered IO-APIC interrupt is * nasty - we need to make sure that we get the edge. * If it is already asserted for some reason, we need * return 1 to indicate that is was pending. * * This is not complete - we should be able to fake * an edge even if it isn't on the 8259A... */static unsigned int startup_ioapic_irq(unsigned int irq){	int was_pending = 0;	unsigned long flags;	spin_lock_irqsave(&ioapic_lock, flags);	if (irq < 16) {		disable_8259A_irq(irq);		if (i8259A_irq_pending(irq))			was_pending = 1;	}	__unmask_IO_APIC_irq(irq);	spin_unlock_irqrestore(&ioapic_lock, flags);	return was_pending;}static int ioapic_retrigger_irq(unsigned int irq){	struct irq_cfg *cfg = &irq_cfg[irq];	cpumask_t mask;	unsigned long flags;	spin_lock_irqsave(&vector_lock, flags);	cpus_clear(mask);	cpu_set(first_cpu(cfg->domain), mask);	send_IPI_mask(mask, cfg->vector);	spin_unlock_irqrestore(&vector_lock, flags);	return 1;}/* * 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. */#ifdef CONFIG_SMPasmlinkage void smp_irq_move_cleanup_interrupt(void){	unsigned vector, me;	ack_APIC_irq();	exit_idle();	irq_enter();	me = smp_processor_id();	for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {		unsigned int irq;		struct irq_desc *desc;		struct irq_cfg *cfg;		irq = __get_cpu_var(vector_irq)[vector];		if (irq >= NR_IRQS)			continue;		desc = irq_desc + irq;		cfg = irq_cfg + irq;		spin_lock(&desc->lock);		if (!cfg->move_cleanup_count)			goto unlock;		if ((vector == cfg->vector) && cpu_isset(me, cfg->domain))			goto unlock;		__get_cpu_var(vector_irq)[vector] = -1;		cfg->move_cleanup_count--;unlock:		spin_unlock(&desc->lock);	}	irq_exit();}static void irq_complete_move(unsigned int irq){	struct irq_cfg *cfg = irq_cfg + irq;	unsigned vector, me;	if (likely(!cfg->move_in_progress))		return;	vector = ~get_irq_regs()->orig_rax;	me = smp_processor_id();	if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) {		cpumask_t cleanup_mask;		cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map);		cfg->move_cleanup_count = cpus_weight(cleanup_mask);		send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);		cfg->move_in_progress = 0;	}}#elsestatic inline void irq_complete_move(unsigned int irq) {}#endifstatic void ack_apic_edge(unsigned int irq){	irq_complete_move(irq);	move_native_irq(irq);	ack_APIC_irq();}static void ack_apic_level(unsigned int irq){	int do_unmask_irq = 0;	irq_complete_move(irq);#if defined(CONFIG_GENERIC_PENDING_IRQ) || defined(CONFIG_IRQBALANCE)	/* If we are moving the irq we need to mask it */	if (unlikely(irq_desc[irq].status & IRQ_MOVE_PENDING)) {		do_unmask_irq = 1;		mask_IO_APIC_irq(irq);	}#endif	/*	 * We must acknowledge the irq before we move it or the acknowledge will	 * not propagate properly.	 */	ack_APIC_irq();	/* Now we can move and renable the irq */	if (unlikely(do_unmask_irq)) {		/* Only migrate the irq if the ack has been received.		 *		 * On rare occasions the broadcast level triggered ack gets		 * delayed going to ioapics, and if we reprogram the		 * vector while Remote IRR is still set the irq will never		 * fire again.		 *		 * To prevent this scenario we read the Remote IRR bit		 * of the ioapic.  This has two effects.		 * - On any sane system the read of the ioapic will		 *   flush writes (and acks) going to the ioapic from		 *   this cpu.		 * - We get to see if the ACK has actually been delivered.		 *		 * Based on failed experiments of reprogramming the		 * ioapic entry from outside of irq context starting		 * with masking the ioapic entry and then polling until		 * Remote IRR was clear before reprogramming the		 * ioapic I don't trust the Remote IRR bit to be		 * completey accurate.		 *		 * However there appears to be no other way to plug		 * this race, so if the Remote IRR bit is not		 * accurate and is causing problems then it is a hardware bug		 * and you can go talk to the chipset vendor about it.		 */		if (!io_apic_level_ack_pending(irq))			move_masked_irq(irq);		unmask_IO_APIC_irq(irq);	}}static struct irq_chip ioapic_chip __read_mostly = {	.name 		= "IO-APIC",	.startup 	= startup_ioapic_irq,	.mask	 	= mask_IO_APIC_irq,	.unmask	 	= unmask_IO_APIC_irq,	.ack 		= ack_apic_edge,	.eoi 		= ack_apic_level,#ifdef CONFIG_SMP	.set_affinity 	= set_ioapic_affinity_irq,#endif	.retrigger	= ioapic_retrigger_irq,};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 (IO_APIC_IRQ(tmp) && !irq_cfg[tmp].vector) {			/*			 * 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].chip = &no_irq_chip;		}	}}static void enable_lapic_irq (unsigned int irq){	unsigned long v;	v = apic_read(APIC_LVT0);	apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);}static void disable_lapic_irq (unsigned int irq){	unsigned long v;	v = apic_read(APIC_LVT0);	apic_write(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 = {	.name = "local-APIC",	.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 ...");	enable_NMI_through_LVT0(NULL);	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 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 = 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. * * FIXME: really need to revamp this for modern platforms only. */static inline void check_timer(void){	struct irq_cfg *cfg = irq_cfg + 0;	int apic1, pin1, apic2, pin2;	unsigned long flags;	local_irq_save(flags);	/*	 * get/set the timer IRQ vector:	 */	disable_8259A_irq(0);	assign_irq_vector(0, TARGET_CPUS);	/*	 * 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(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);	init_8259A(1);	if (timer_over_8254 > 0)		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;	apic_printk(APIC_VERBOSE,KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n",		cfg->vector, apic1, pin1, apic2, pin2);	if (pin1 != -1) {		/*		 * Ok, does IRQ0 through the IOAPIC work?		 */		unmask_IO_APIC_irq(0);		if (!no_timer_check && timer_irq_works()) {			nmi_watchdog_default();			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);			goto out;		}		clear_IO_APIC_pin(apic1, pin1);		apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: 8254 timer not "				"connected to IO-APIC\n");	}	apic_printk(APIC_VERBOSE,KERN_INFO "...trying to set up timer (IRQ0) "				"through the 8259A ... ");	if (pin2 != -1) {		apic_printk(APIC_VERBOSE,"\n..... (found apic %d pin %d) ...",			apic2, pin2);		/*		 * legacy devices should be connected to IO APIC #0		 */

⌨️ 快捷键说明

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