pci-irq.c

来自「linux-2.4.29操作系统的源码」· C语言 代码 · 共 1,180 行 · 第 1/3 页

C
1,180
字号
/* *	Low-Level PCI Support for PC -- Routing of Interrupts * *	(c) 1999--2000 Martin Mares <mj@ucw.cz> */#include <linux/config.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/pci.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/irq.h>#include <asm/io.h>#include <asm/smp.h>#include <asm/io_apic.h>#include "pci-i386.h"#define PIRQ_SIGNATURE	(('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))#define PIRQ_VERSION 0x0100int broken_hp_bios_irq9;int acer_tm360_irqrouting;static struct irq_routing_table *pirq_table;/* * Never use: 0, 1, 2 (timer, keyboard, and cascade) * Avoid using: 13, 14 and 15 (FP error and IDE). * Penalize: 3, 4, 6, 7, 12 (known ISA uses: serial, floppy, parallel and mouse) */unsigned int pcibios_irq_mask = 0xfff8;static int pirq_penalty[16] = {	1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000,	0, 0, 0, 0, 1000, 100000, 100000, 100000};struct irq_router {	char *name;	u16 vendor, device;	int (*get)(struct pci_dev *router, struct pci_dev *dev, int pirq);	int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq, int new);};struct irq_router_handler {	u16 vendor;	int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);};/* *  Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table. */static struct irq_routing_table * __init pirq_find_routing_table(void){	u8 *addr;	struct irq_routing_table *rt;	int i;	u8 sum;	for(addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) {		rt = (struct irq_routing_table *) addr;		if (rt->signature != PIRQ_SIGNATURE ||		    rt->version != PIRQ_VERSION ||		    rt->size % 16 ||		    rt->size < sizeof(struct irq_routing_table))			continue;		sum = 0;		for(i=0; i<rt->size; i++)			sum += addr[i];		if (!sum) {			DBG("PCI: Interrupt Routing Table found at 0x%p\n", rt);			return rt;		}	}	return NULL;}/* *  If we have a IRQ routing table, use it to search for peer host *  bridges.  It's a gross hack, but since there are no other known *  ways how to get a list of buses, we have to go this way. */static void __init pirq_peer_trick(void){	struct irq_routing_table *rt = pirq_table;	u8 busmap[256];	int i;	struct irq_info *e;	memset(busmap, 0, sizeof(busmap));	for(i=0; i < (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); i++) {		e = &rt->slots[i];#ifdef DEBUG		{			int j;			DBG("%02x:%02x slot=%02x", e->bus, e->devfn/8, e->slot);			for(j=0; j<4; j++)				DBG(" %d:%02x/%04x", j, e->irq[j].link, e->irq[j].bitmap);			DBG("\n");		}#endif		busmap[e->bus] = 1;	}	for(i=1; i<256; i++)		/*		 *  It might be a secondary bus, but in this case its parent is already		 *  known (ascending bus order) and therefore pci_scan_bus returns immediately.		 */		if (busmap[i] && pci_scan_bus(i, pci_root_bus->ops, NULL))			printk(KERN_INFO "PCI: Discovered primary peer bus %02x [IRQ]\n", i);	pcibios_last_bus = -1;}/* *  Code for querying and setting of IRQ routes on various interrupt routers. */void eisa_set_level_irq(unsigned int irq){	unsigned char mask = 1 << (irq & 7);	unsigned int port = 0x4d0 + (irq >> 3);	unsigned char val = inb(port);	if (!(val & mask)) {		DBG(" -> edge");		outb(val | mask, port);	}}/* * Common IRQ routing practice: nybbles in config space, * offset by some magic constant. */static unsigned int read_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr){	u8 x;	unsigned reg = offset + (nr >> 1);	pci_read_config_byte(router, reg, &x);	return (nr & 1) ? (x >> 4) : (x & 0xf);}static void write_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr, unsigned int val){	u8 x;	unsigned reg = offset + (nr >> 1);	pci_read_config_byte(router, reg, &x);	x = (nr & 1) ? ((x & 0x0f) | (val << 4)) : ((x & 0xf0) | val);	pci_write_config_byte(router, reg, x);}/* * ALI pirq entries are damn ugly, and completely undocumented. * This has been figured out from pirq tables, and it's not a pretty * picture. */static int pirq_ali_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	static unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };	return irqmap[read_config_nybble(router, 0x48, pirq-1)];}static int pirq_ali_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	static unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };	unsigned int val = irqmap[irq];			if (val) {		write_config_nybble(router, 0x48, pirq-1, val);		return 1;	}	return 0;}/* * The Intel PIIX4 pirq rules are fairly simple: "pirq" is * just a pointer to the config space. */static int pirq_piix_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	u8 x;	pci_read_config_byte(router, pirq, &x);	return (x < 16) ? x : 0;}static int pirq_piix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	pci_write_config_byte(router, pirq, irq);	return 1;}/* * The VIA pirq rules are nibble-based, like ALI, * but without the ugly irq number munging. * However, PIRQD is in the upper instead of lower nibble. */static int pirq_via_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	return read_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq);}static int pirq_via_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	write_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq, irq);	return 1;}/* * ITE 8330G pirq rules are nibble-based * FIXME: pirqmap may be { 1, 0, 3, 2 }, * 	  2+3 are both mapped to irq 9 on my system */static int pirq_ite_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	static unsigned char pirqmap[4] = { 1, 0, 2, 3 };	return read_config_nybble(router,0x43, pirqmap[pirq-1]);}static int pirq_ite_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	static unsigned char pirqmap[4] = { 1, 0, 2, 3 };	write_config_nybble(router, 0x43, pirqmap[pirq-1], irq);	return 1;}/* * OPTI: high four bits are nibble pointer.. * I wonder what the low bits do? */static int pirq_opti_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	return read_config_nybble(router, 0xb8, pirq >> 4);}static int pirq_opti_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	write_config_nybble(router, 0xb8, pirq >> 4, irq);	return 1;}/* * OPTI Viper-M/N+: Bit field with 3 bits per entry. * Due to the lack of a specification the information about this chipset * was taken from the NetBSD source code. */static int pirq_viper_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	static const int viper_irq_decode[] = { 0, 5, 9, 10, 11, 12, 14, 15 };	u32 irq;	pci_read_config_dword(router, 0x40, &irq);	irq >>= (pirq-1)*3;	irq &= 7;	return viper_irq_decode[irq];}static int pirq_viper_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	static const int viper_irq_map[] = { -1, -1, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, -1, 6, 7 };	int newval = viper_irq_map[irq];	u32 val;	u32 mask = 7 << (3*(pirq-1));#if 0	mask |= 0x10000UL << (pirq-1);	/* edge triggered */#endif	if ( newval == -1 )		return 0;		pci_read_config_dword(router, 0x40, &val);	val &= ~mask;	val |= newval << (3*(pirq-1));	pci_write_config_dword(router, 0x40, val);	return 1;}/* * Cyrix: nibble offset 0x5C */static int pirq_cyrix_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	return read_config_nybble(router, 0x5C, (pirq-1)^1);}static int pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	write_config_nybble(router, 0x5C, (pirq-1)^1, irq);	return 1;}/* *	PIRQ routing for SiS 85C503 router used in several SiS chipsets. *	We have to deal with the following issues here: *	- vendors have different ideas about the meaning of link values *	- some onboard devices (integrated in the chipset) have special *	  links and are thus routed differently (i.e. not via PCI INTA-INTD) *	- different revision of the router have a different layout for *	  the routing registers, particularly for the onchip devices * *	For all routing registers the common thing is we have one byte *	per routeable link which is defined as: *		 bit 7      IRQ mapping enabled (0) or disabled (1) *		 bits [6:4] reserved (sometimes used for onchip devices) *		 bits [3:0] IRQ to map to *		     allowed: 3-7, 9-12, 14-15 *		     reserved: 0, 1, 2, 8, 13 * *	The config-space registers located at 0x41/0x42/0x43/0x44 are *	always used to route the normal PCI INT A/B/C/D respectively. *	Apparently there are systems implementing PCI routing table using *	link values 0x01-0x04 and others using 0x41-0x44 for PCI INTA..D. *	We try our best to handle both link mappings. *	 *	Currently (2003-05-21) it appears most SiS chipsets follow the *	definition of routing registers from the SiS-5595 southbridge. *	According to the SiS 5595 datasheets the revision id's of the *	router (ISA-bridge) should be 0x01 or 0xb0. * *	Furthermore we've also seen lspci dumps with revision 0x00 and 0xb1. *	Looks like these are used in a number of SiS 5xx/6xx/7xx chipsets. *	They seem to work with the current routing code. However there is *	some concern because of the two USB-OHCI HCs (original SiS 5595 *	had only one). YMMV. * *	Onchip routing for router rev-id 0x01/0xb0 and probably 0x00/0xb1: * *	0x61:	IDEIRQ: *		bits [6:5] must be written 01 *		bit 4 channel-select primary (0), secondary (1) * *	0x62:	USBIRQ: *		bit 6 OHCI function disabled (0), enabled (1) *	 *	0x6a:	ACPI/SCI IRQ: bits 4-6 reserved * *	0x7e:	Data Acq. Module IRQ - bits 4-6 reserved * *	We support USBIRQ (in addition to INTA-INTD) and keep the *	IDE, ACPI and DAQ routing untouched as set by the BIOS. * *	Currently the only reported exception is the new SiS 65x chipset *	which includes the SiS 69x southbridge. Here we have the 85C503 *	router revision 0x04 and there are changes in the register layout *	mostly related to the different USB HCs with USB 2.0 support. * *	Onchip routing for router rev-id 0x04 (try-and-error observation) * *	0x60/0x61/0x62/0x63:	1xEHCI and 3xOHCI (companion) USB-HCs *				bit 6-4 are probably unused, not like 5595 */#define PIRQ_SIS_IRQ_MASK	0x0f#define PIRQ_SIS_IRQ_DISABLE	0x80#define PIRQ_SIS_USB_ENABLE	0x40#define PIRQ_SIS_DETECT_REGISTER 0x40/* return value: * -1 on error * 0 for PCI INTA-INTD * 0 or enable bit mask to check or set for onchip functions */static inline int pirq_sis5595_onchip(int pirq, int *reg){	int ret = -1;	*reg = pirq;	switch(pirq) {	case 0x01:	case 0x02:	case 0x03:	case 0x04:		*reg += 0x40;	case 0x41:	case 0x42:	case 0x43:	case 0x44:		ret = 0;		break;	case 0x62:		ret = PIRQ_SIS_USB_ENABLE;	/* documented for 5595 */		break;

⌨️ 快捷键说明

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