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

📄 irq.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *	Low-Level PCI Support for PC -- Routing of Interrupts * *	(c) 1999--2000 Martin Mares <mj@ucw.cz> */#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/dmi.h>#include <asm/io.h>#include <asm/smp.h>#include <asm/io_apic.h>#include <linux/irq.h>#include <linux/acpi.h>#include "pci.h"#define PIRQ_SIGNATURE	(('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))#define PIRQ_VERSION 0x0100static int broken_hp_bios_irq9;static int acer_tm360_irqrouting;static struct irq_routing_table *pirq_table;static int pirq_enable_irq(struct pci_dev *dev);/* * 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);};int (*pcibios_enable_irq)(struct pci_dev *dev) = NULL;void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;/* *  Check passed address for the PCI IRQ Routing Table signature *  and perform checksum verification. */static inline struct irq_routing_table * pirq_check_routing_table(u8 *addr){	struct irq_routing_table *rt;	int i;	u8 sum;	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))		return NULL;	sum = 0;	for (i=0; i < rt->size; i++)		sum += addr[i];	if (!sum) {		DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%p\n", rt);		return rt;	}	return NULL;}/* *  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;	if (pirq_table_addr) {		rt = pirq_check_routing_table((u8 *) __va(pirq_table_addr));		if (rt)			return rt;		printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n");	}	for(addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) {		rt = pirq_check_routing_table(addr);		if (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(KERN_DEBUG "%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++) {		if (!busmap[i] || pci_find_bus(0, i))			continue;		if (pci_scan_bus_with_sysdata(i))			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;	static u16 eisa_irq_mask;	if (irq >= 16 || (1 << irq) & eisa_irq_mask)		return;	eisa_irq_mask |= (1 << irq);	printk(KERN_DEBUG "PCI: setting IRQ %u as level-triggered\n", irq);	val = inb(port);	if (!(val & mask)) {		DBG(KERN_DEBUG " -> edge");		outb(val | mask, port);	}}/* * Common IRQ routing practice: nibbles 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 const 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 const 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 4 bits. */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;}/* * The VIA pirq rules are nibble-based, like ALI, * but without the ugly irq number munging. * However, for 82C586, nibble map is different . */static int pirq_via586_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };	return read_config_nybble(router, 0x55, pirqmap[pirq-1]);}static int pirq_via586_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };	write_config_nybble(router, 0x55, pirqmap[pirq-1], 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 const 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 const 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;}/* * Cyrix: nibble offset 0x5C * 0x5C bits 7:4 is INTB bits 3:0 is INTA  * 0x5D bits 7:4 is INTD bits 3:0 is INTC */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	0x40static int pirq_sis_get(struct pci_dev *router, struct pci_dev *dev, int pirq){	u8 x;	int reg;	reg = pirq;	if (reg >= 0x01 && reg <= 0x04)		reg += 0x40;	pci_read_config_byte(router, reg, &x);	return (x & PIRQ_SIS_IRQ_DISABLE) ? 0 : (x & PIRQ_SIS_IRQ_MASK);}static int pirq_sis_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq){	u8 x;	int reg;	reg = pirq;	if (reg >= 0x01 && reg <= 0x04)		reg += 0x40;	pci_read_config_byte(router, reg, &x);	x &= ~(PIRQ_SIS_IRQ_MASK | PIRQ_SIS_IRQ_DISABLE);

⌨️ 快捷键说明

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