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

📄 pci_fixup.c

📁 pcmcia source code
💻 C
📖 第 1 页 / 共 2 页
字号:
/*======================================================================    Kernel fixups for PCI device support        pci_fixup.c 1.31 2002/07/02 07:54:47        PCI bus fixups: various bits of code that don't really belong in    the PCMCIA subsystem, but may or may not be available from the    kernel, depending on kernel version.  The basic idea is to make    2.0.* and 2.2.* kernels look like they have the 2.3.* features.======================================================================*/#define __NO_VERSION__#include <linux/module.h>#include <linux/kernel.h>#include <linux/slab.h>#include <linux/pci.h>#include <asm/io.h>/* We use these for setting up CardBus bridges */#include "yenta.h"#include "i82365.h"#if (LINUX_VERSION_CODE < VERSION(2,3,24))/* Default memory base addresses for CardBus controllers */static u_int cb_mem_base[] = { 0x0, 0x68000000, 0xf8000000 };MODULE_PARM(cb_mem_base, "i");/* PCI bus number overrides for CardBus controllers */#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")INT_MODULE_PARM(cb_bus_base, 0);INT_MODULE_PARM(cb_bus_step, 2);INT_MODULE_PARM(cb_pci_irq, 0);#endif/* (exported) mask of interrupts reserved for PCI devices */u32 pci_irq_mask = 0;/*======================================================================    Basic PCI services missing from older kernels: device lookup, etc======================================================================*/#if (LINUX_VERSION_CODE < VERSION(2,1,0))struct pci_dev *pci_devices = NULL;struct pci_bus pci_root = {    parent:	NULL,    children:	NULL,    next:	NULL,    self:	NULL,    devices:	NULL,    number:	0};#endif#if (LINUX_VERSION_CODE < VERSION(2,1,93))struct pci_dev *pci_find_slot(u_int bus, u_int devfn){    struct pci_dev *dev;    for (dev = pci_devices; dev; dev = dev->next)	if ((dev->devfn == devfn) && (bus == dev->bus->number))	    return dev;#if (LINUX_VERSION_CODE > VERSION(2,1,0))    return NULL;#else    {	struct pci_bus *b;	u8 hdr;	u32 id, class;	if (pcibios_read_config_byte(bus, devfn & ~7, PCI_HEADER_TYPE, &hdr))	    return NULL;	if (PCI_FUNC(devfn) && !(hdr & 0x80))	    return NULL;	pcibios_read_config_dword(bus, devfn, PCI_VENDOR_ID, &id);	if ((id == 0) || (id == 0xffffffff))	    return NULL;	dev = kmalloc(sizeof *dev, GFP_ATOMIC);	if (!dev)	    return NULL;	memset(dev, 0, sizeof *dev);	dev->devfn = devfn;	pcibios_read_config_byte(bus, devfn, PCI_INTERRUPT_LINE, &dev->irq);	dev->vendor = id & 0xffff;	dev->device = id >> 16;	pcibios_read_config_dword(bus, devfn, PCI_CLASS_REVISION, &class);	if (dev->irq == 255)	    dev->irq = 0;	dev->class = class >> 8;	for (b = &pci_root; b; b = b->next)	    if (b->number == bus) break;	if (!b) {	    b = kmalloc(sizeof *b, GFP_ATOMIC);	    if (!b) {		kfree(dev);		return NULL;	    }	    memset(b, 0, sizeof *b);	    b->number = bus;	    b->next = pci_root.next;	    pci_root.next = b;	}	dev->bus = b;	return dev;    }#endif}struct pci_dev *pci_find_class(u_int class, struct pci_dev *from){    static u16 index = 0;    u8 bus, devfn;    if (from == NULL)	index = 0;    if (pcibios_find_class(class, index++, &bus, &devfn) == 0)	return pci_find_slot(bus, devfn);    else	return NULL;}#endif /* (LINUX_VERSION_CODE < VERSION(2,1,93)) *//*======================================================================    PCI Interrupt Routing Table parser    This only needs to be done once per boot: we scan the BIOS for    the routing table, and then look for devices that have interrupt    assignments that the kernel doesn't know about.  If we find any,    we update their pci_dev structures and write the PCI interrupt    line registers.    ======================================================================*/#if (LINUX_VERSION_CODE < VERSION(2,3,24)) && defined(__i386__)#pragma pack(1)struct slot_entry {    u8		bus, devfn;    struct pirq_pin {	u8	link;	u16	irq_map;    } pin[4];    u8		slot;    u8		reserved;};struct routing_table {    u32		signature;    u8		minor, major;    u16		size;    u8		bus, devfn;    u16		pci_mask;    u32		compat;    u32		miniport;    u8		reserved[11];    u8		checksum;    struct slot_entry entry[0];};#pragma pack()/*  The meaning of the link bytes in the routing table is vendor  specific.  We need code to get and set the routing information.*/static u8 pIIx_link(struct pci_dev *router, u8 link){    u8 pirq;    /* link should be 0x60, 0x61, 0x62, 0x63 */    pci_read_config_byte(router, link, &pirq);    return (pirq < 16) ? pirq : 0;}static void pIIx_init(struct pci_dev *router, u8 link, u8 irq){    pci_write_config_byte(router, link, irq);}static u8 via_link(struct pci_dev *router, u8 link){    u8 pirq = 0;    /* link should be 1, 2, 3, 5 */    if (link < 6)	pci_read_config_byte(router, 0x55 + (link>>1), &pirq);    return (link & 1) ? (pirq >> 4) : (pirq & 15);}static void via_init(struct pci_dev *router, u8 link, u8 irq){    u8 pirq;    pci_read_config_byte(router, 0x55 + (link>>1), &pirq);    pirq &= (link & 1) ? 0x0f : 0xf0;    pirq |= (link & 1) ? (irq << 4) : (irq & 15);    pci_write_config_byte(router, 0x55 + (link>>1), pirq);}static u8 opti_link(struct pci_dev *router, u8 link){    u8 pirq = 0;    /* link should be 0x02, 0x12, 0x22, 0x32 */    if ((link & 0xcf) == 0x02)	pci_read_config_byte(router, 0xb8 + (link >> 5), &pirq);    return (link & 0x10) ? (pirq >> 4) : (pirq & 15);}static void opti_init(struct pci_dev *router, u8 link, u8 irq){    u8 pirq;    pci_read_config_byte(router, 0xb8 + (link >> 5), &pirq);    pirq &= (link & 0x10) ? 0x0f : 0xf0;    pirq |= (link & 0x10) ? (irq << 4) : (irq & 15);    pci_write_config_byte(router, 0xb8 + (link >> 5), pirq);}static u8 ali_link(struct pci_dev *router, u8 link){    /* No, you're not dreaming */    static const u8 map[] =    { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };    u8 pirq;    /* link should be 0x01..0x08 */    pci_read_config_byte(router, 0x48 + ((link-1)>>1), &pirq);    return (link & 1) ? map[pirq&15] : map[pirq>>4];}static void ali_init(struct pci_dev *router, u8 link, u8 irq){    /* Inverse of map in ali_link */    static const u8 map[] =    { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };    u8 pirq;    pci_read_config_byte(router, 0x48 + ((link-1)>>1), &pirq);    pirq &= (link & 1) ? 0x0f : 0xf0;    pirq |= (link & 1) ? (map[irq] << 4) : (map[irq] & 15);    pci_write_config_byte(router, 0x48 + ((link-1)>>1), pirq);}static u8 cyrix_link(struct pci_dev *router, u8 link){    u8 pirq;    /* link should be 1, 2, 3, 4 */    link--;    pci_read_config_byte(router, 0x5c + (link>>1), &pirq);    return ((link & 1) ? pirq >> 4 : pirq & 15);}static void cyrix_init(struct pci_dev *router, u8 link, u8 irq){    u8 pirq;    link--;    pci_read_config_byte(router, 0x5c + (link>>1), &pirq);    pirq &= (link & 1) ? 0x0f : 0xf0;    pirq |= (link & 1) ? (irq << 4) : (irq & 15);    pci_write_config_byte(router, 0x5c + (link>>1), pirq);}/*  A table of all the PCI interrupt routers for which we know how to  interpret the link bytes.*/#ifndef PCI_DEVICE_ID_INTEL_82371FB_0#define PCI_DEVICE_ID_INTEL_82371FB_0 0x122e#endif#ifndef PCI_DEVICE_ID_INTEL_82371SB_0#define PCI_DEVICE_ID_INTEL_82371SB_0 0x7000#endif#ifndef PCI_DEVICE_ID_INTEL_82371AB_0#define PCI_DEVICE_ID_INTEL_82371AB_0 0x7110#endif#ifndef PCI_DEVICE_ID_INTEL_82443MX_1#define PCI_DEVICE_ID_INTEL_82443MX_1 0x7198#endif#ifndef PCI_DEVICE_ID_INTEL_82443MX_1#define PCI_DEVICE_ID_INTEL_82443MX_1 0x7198#endif#ifndef PCI_DEVICE_ID_INTEL_82801AA_0#define PCI_DEVICE_ID_INTEL_82801AA_0 0x2410#endif#ifndef PCI_DEVICE_ID_INTEL_82801AB_0#define PCI_DEVICE_ID_INTEL_82801AB_0 0x2420#endif#ifndef PCI_DEVICE_ID_INTEL_82801BA_0#define PCI_DEVICE_ID_INTEL_82801BA_0 0x2440#endif#ifndef PCI_DEVICE_ID_INTEL_82801BAM_0#define PCI_DEVICE_ID_INTEL_82801BAM_0 0x244c#endif#ifndef PCI_DEVICE_ID_VIA_82C586_0#define PCI_DEVICE_ID_VIA_82C586_0 0x0586#endif#ifndef PCI_DEVICE_ID_VIA_82C596#define PCI_DEVICE_ID_VIA_82C596 0x0596#endif#ifndef PCI_DEVICE_ID_VIA_82C686#define PCI_DEVICE_ID_VIA_82C686 0x0686#endif#ifndef PCI_DEVICE_ID_SI#define PCI_DEVICE_ID_SI 0x1039#endif#ifndef PCI_DEVICE_ID_SI_503#define PCI_DEVICE_ID_SI_503 0x0008#endif#ifndef PCI_DEVICE_ID_SI_496#define PCI_DEVICE_ID_SI_496 0x0496#endif#define ID(a,b) PCI_VENDOR_ID_##a,PCI_DEVICE_ID_##a##_##bstruct router {    u16 vendor, device;    u8 (*xlate)(struct pci_dev *, u8);    void (*init)(struct pci_dev *, u8, u8);} router_table[] = {    { ID(INTEL, 82371FB_0),	&pIIx_link,	&pIIx_init },    { ID(INTEL, 82371SB_0),	&pIIx_link,	&pIIx_init },    { ID(INTEL, 82371AB_0),	&pIIx_link,	&pIIx_init },    { ID(INTEL, 82443MX_1),	&pIIx_link,	&pIIx_init },    { ID(INTEL, 82801AA_0),	&pIIx_link,	&pIIx_init },    { ID(INTEL, 82801AB_0),	&pIIx_link,	&pIIx_init },    { ID(INTEL, 82801BA_0),	&pIIx_link,	&pIIx_init },    { ID(INTEL, 82801BAM_0),	&pIIx_link,	&pIIx_init },    { ID(VIA, 82C586_0),	&via_link,	&via_init },    { ID(VIA, 82C596),		&via_link,	&via_init },    { ID(VIA, 82C686),		&via_link,	&via_init },    { ID(OPTI, 82C700),		&opti_link,	&opti_init },    { ID(AL, M1533),		&ali_link,	&ali_init },    { ID(SI, 503),		&pIIx_link,	&pIIx_init },    { ID(SI, 496),		&pIIx_link,	&pIIx_init },    { ID(CYRIX, 5530_LEGACY),	&cyrix_link,	&cyrix_init }

⌨️ 快捷键说明

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