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

📄 pci-pc.c

📁 ARM 嵌入式 系统 设计与实例开发 实验教材 二源码
💻 C
📖 第 1 页 / 共 3 页
字号:
struct irq_routing_table * __devinit pcibios_get_irq_routing_table(void){	struct irq_routing_options opt;	struct irq_routing_table *rt = NULL;	int ret, map;	unsigned long page;	if (!pci_bios_present)		return NULL;	page = __get_free_page(GFP_KERNEL);	if (!page)		return NULL;	opt.table = (struct irq_info *) page;	opt.size = PAGE_SIZE;	opt.segment = __KERNEL_DS;	DBG("PCI: Fetching IRQ routing table... ");	__asm__("push %%es\n\t"		"push %%ds\n\t"		"pop  %%es\n\t"		"lcall (%%esi); cld\n\t"		"pop %%es\n\t"		"jc 1f\n\t"		"xor %%ah, %%ah\n"		"1:"		: "=a" (ret),		  "=b" (map)		: "0" (PCIBIOS_GET_ROUTING_OPTIONS),		  "1" (0),		  "D" ((long) &opt),		  "S" (&pci_indirect));	DBG("OK  ret=%d, size=%d, map=%x\n", ret, opt.size, map);	if (ret & 0xff00)		printk(KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n", (ret >> 8) & 0xff);	else if (opt.size) {		rt = kmalloc(sizeof(struct irq_routing_table) + opt.size, GFP_KERNEL);		if (rt) {			memset(rt, 0, sizeof(struct irq_routing_table));			rt->size = opt.size + sizeof(struct irq_routing_table);			rt->exclusive_irqs = map;			memcpy(rt->slots, (void *) page, opt.size);			printk("PCI: Using BIOS Interrupt Routing Table\n");		}	}	free_page(page);	return rt;}int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq){	int ret;	__asm__("lcall (%%esi); cld\n\t"		"jc 1f\n\t"		"xor %%ah, %%ah\n"		"1:"		: "=a" (ret)		: "0" (PCIBIOS_SET_PCI_HW_INT),		  "b" ((dev->bus->number << 8) | dev->devfn),		  "c" ((irq << 8) | (pin + 10)),		  "S" (&pci_indirect));	return !(ret & 0xff00);}#endif/* * Several buggy motherboards address only 16 devices and mirror * them to next 16 IDs. We try to detect this `feature' on all * primary buses (those containing host bridges as they are * expected to be unique) and remove the ghost devices. */static void __devinit pcibios_fixup_ghosts(struct pci_bus *b){	struct list_head *ln, *mn;	struct pci_dev *d, *e;	int mirror = PCI_DEVFN(16,0);	int seen_host_bridge = 0;	int i;	DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);	for (ln=b->devices.next; ln != &b->devices; ln=ln->next) {		d = pci_dev_b(ln);		if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)			seen_host_bridge++;		for (mn=ln->next; mn != &b->devices; mn=mn->next) {			e = pci_dev_b(mn);			if (e->devfn != d->devfn + mirror ||			    e->vendor != d->vendor ||			    e->device != d->device ||			    e->class != d->class)				continue;			for(i=0; i<PCI_NUM_RESOURCES; i++)				if (e->resource[i].start != d->resource[i].start ||				    e->resource[i].end != d->resource[i].end ||				    e->resource[i].flags != d->resource[i].flags)					continue;			break;		}		if (mn == &b->devices)			return;	}	if (!seen_host_bridge)		return;	printk("PCI: Ignoring ghost devices on bus %02x\n", b->number);	ln = &b->devices;	while (ln->next != &b->devices) {		d = pci_dev_b(ln->next);		if (d->devfn >= mirror) {			list_del(&d->global_list);			list_del(&d->bus_list);			kfree(d);		} else			ln = ln->next;	}}/* * Discover remaining PCI buses in case there are peer host bridges. * We use the number of last PCI bus provided by the PCI BIOS. */static void __devinit pcibios_fixup_peer_bridges(void){	int n;	struct pci_bus bus;	struct pci_dev dev;	u16 l;	if (pcibios_last_bus <= 0 || pcibios_last_bus >= 0xff)		return;	DBG("PCI: Peer bridge fixup\n");	for (n=0; n <= pcibios_last_bus; n++) {		if (pci_bus_exists(&pci_root_buses, n))			continue;		bus.number = n;		bus.ops = pci_root_ops;		dev.bus = &bus;		for(dev.devfn=0; dev.devfn<256; dev.devfn += 8)			if (!pci_read_config_word(&dev, PCI_VENDOR_ID, &l) &&			    l != 0x0000 && l != 0xffff) {				DBG("Found device at %02x:%02x [%04x]\n", n, dev.devfn, l);				printk("PCI: Discovered peer bus %02x\n", n);				pci_scan_bus(n, pci_root_ops, NULL);				break;			}	}}/* * Exceptions for specific devices. Usually work-arounds for fatal design flaws. */static void __devinit pci_fixup_i450nx(struct pci_dev *d){	/*	 * i450NX -- Find and scan all secondary buses on all PXB's.	 */	int pxb, reg;	u8 busno, suba, subb;	printk("PCI: Searching for i450NX host bridges on %s\n", d->slot_name);	reg = 0xd0;	for(pxb=0; pxb<2; pxb++) {		pci_read_config_byte(d, reg++, &busno);		pci_read_config_byte(d, reg++, &suba);		pci_read_config_byte(d, reg++, &subb);		DBG("i450NX PXB %d: %02x/%02x/%02x\n", pxb, busno, suba, subb);		if (busno)			pci_scan_bus(busno, pci_root_ops, NULL);	/* Bus A */		if (suba < subb)			pci_scan_bus(suba+1, pci_root_ops, NULL);	/* Bus B */	}	pcibios_last_bus = -1;}static void __devinit pci_fixup_i450gx(struct pci_dev *d){	/*	 * i450GX and i450KX -- Find and scan all secondary buses.	 * (called separately for each PCI bridge found)	 */	u8 busno;	pci_read_config_byte(d, 0x4a, &busno);	printk("PCI: i440KX/GX host bridge %s: secondary bus %02x\n", d->slot_name, busno);	pci_scan_bus(busno, pci_root_ops, NULL);	pcibios_last_bus = -1;}static void __devinit  pci_fixup_umc_ide(struct pci_dev *d){	/*	 * UM8886BF IDE controller sets region type bits incorrectly,	 * therefore they look like memory despite of them being I/O.	 */	int i;	printk("PCI: Fixing base address flags for device %s\n", d->slot_name);	for(i=0; i<4; i++)		d->resource[i].flags |= PCI_BASE_ADDRESS_SPACE_IO;}static void __devinit pci_fixup_ide_bases(struct pci_dev *d){	int i;	/*	 * PCI IDE controllers use non-standard I/O port decoding, respect it.	 */	if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)		return;	DBG("PCI: IDE base address fixup for %s\n", d->slot_name);	for(i=0; i<4; i++) {		struct resource *r = &d->resource[i];		if ((r->start & ~0x80) == 0x374) {			r->start |= 2;			r->end = r->start;		}	}}static void __devinit  pci_fixup_ide_trash(struct pci_dev *d){	int i;	/*	 * There exist PCI IDE controllers which have utter garbage	 * in first four base registers. Ignore that.	 */	DBG("PCI: IDE base address trash cleared for %s\n", d->slot_name);	for(i=0; i<4; i++)		d->resource[i].start = d->resource[i].end = d->resource[i].flags = 0;}static void __devinit  pci_fixup_latency(struct pci_dev *d){	/*	 *  SiS 5597 and 5598 chipsets require latency timer set to	 *  at most 32 to avoid lockups.	 */	DBG("PCI: Setting max latency to 32\n");	pcibios_max_latency = 32;}static void __devinit pci_fixup_piix4_acpi(struct pci_dev *d){	/*	 * PIIX4 ACPI device: hardwired IRQ9	 */	d->irq = 9;}/* * Addresses issues with problems in the memory write queue timer in * certain VIA Northbridges.  This bugfix is per VIA's specifications. * * VIA 8363,8622,8361 Northbridges: *  - bits  5, 6, 7 at offset 0x55 need to be turned off * VIA 8367 (KT266x) Northbridges: *  - bits  5, 6, 7 at offset 0x95 need to be turned off */static void __init pci_fixup_via_northbridge_bug(struct pci_dev *d){	u8 v;	int where = 0x55;	if (d->device == PCI_DEVICE_ID_VIA_8367_0) {		where = 0x95; /* the memory write queue timer register is 				 different for the kt266x's: 0x95 not 0x55 */	}	pci_read_config_byte(d, where, &v);	if (v & 0xe0) {		printk("Disabling VIA memory write queue: [%02x] %02x->%02x\n", where, v, v & 0x1f);		v &= 0x1f; /* clear bits 5, 6, 7 */		pci_write_config_byte(d, where, v);	}}struct pci_fixup pcibios_fixups[] = {	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_82451NX,	pci_fixup_i450nx },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_82454GX,	pci_fixup_i450gx },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_UMC,	PCI_DEVICE_ID_UMC_UM8886BF,	pci_fixup_umc_ide },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_SI,	PCI_DEVICE_ID_SI_5513,		pci_fixup_ide_trash },	{ PCI_FIXUP_HEADER,	PCI_ANY_ID,		PCI_ANY_ID,			pci_fixup_ide_bases },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_SI,	PCI_DEVICE_ID_SI_5597,		pci_fixup_latency },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_SI,	PCI_DEVICE_ID_SI_5598,		pci_fixup_latency }, 	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_82371AB_3,	pci_fixup_piix4_acpi },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_8363_0,	pci_fixup_via_northbridge_bug },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_8622,	        pci_fixup_via_northbridge_bug },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_8361,	        pci_fixup_via_northbridge_bug },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_8367_0,	pci_fixup_via_northbridge_bug },	{ 0 }};/* *  Called after each bus is probed, but before its children *  are examined. */void __devinit  pcibios_fixup_bus(struct pci_bus *b){	pcibios_fixup_ghosts(b);	pci_read_bridge_bases(b);}void __devinit pcibios_config_init(void){	/*	 * Try all known PCI access methods. Note that we support using 	 * both PCI BIOS and direct access, with a preference for direct.	 */#ifdef CONFIG_PCI_BIOS	if ((pci_probe & PCI_PROBE_BIOS) 		&& ((pci_root_ops = pci_find_bios()))) {		pci_probe |= PCI_BIOS_SORT;		pci_bios_present = 1;		pci_config_read = pci_bios_read;		pci_config_write = pci_bios_write;	}#endif#ifdef CONFIG_PCI_DIRECT	if ((pci_probe & (PCI_PROBE_CONF1 | PCI_PROBE_CONF2)) 		&& (pci_root_ops = pci_check_direct())) {		if (pci_root_ops == &pci_direct_conf1) {			pci_config_read = pci_conf1_read;			pci_config_write = pci_conf1_write;		}		else {			pci_config_read = pci_conf2_read;			pci_config_write = pci_conf2_write;		}	}#endif	return;}void __init pcibios_init(void){	if (!pci_root_ops)		pcibios_config_init();	if (!pci_root_ops) {		printk("PCI: System does not support PCI\n");		return;	}	printk("PCI: Probing PCI hardware\n");	pci_root_bus = pci_scan_bus(0, pci_root_ops, NULL);	pcibios_irq_init();	pcibios_fixup_peer_bridges();	pcibios_fixup_irqs();	pcibios_resource_survey();#ifdef CONFIG_PCI_BIOS	if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))		pcibios_sort();#endif}char * __devinit  pcibios_setup(char *str){	if (!strcmp(str, "off")) {		pci_probe = 0;		return NULL;	}#ifdef CONFIG_PCI_BIOS	else if (!strcmp(str, "bios")) {		pci_probe = PCI_PROBE_BIOS;		return NULL;	} else if (!strcmp(str, "nobios")) {		pci_probe &= ~PCI_PROBE_BIOS;		return NULL;	} else if (!strcmp(str, "nosort")) {		pci_probe |= PCI_NO_SORT;		return NULL;	} else if (!strcmp(str, "biosirq")) {		pci_probe |= PCI_BIOS_IRQ_SCAN;		return NULL;	}#endif#ifdef CONFIG_PCI_DIRECT	else if (!strcmp(str, "conf1")) {		pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;		return NULL;	}	else if (!strcmp(str, "conf2")) {		pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;		return NULL;	}#endif	else if (!strcmp(str, "rom")) {		pci_probe |= PCI_ASSIGN_ROMS;		return NULL;	} else if (!strcmp(str, "assign-busses")) {		pci_probe |= PCI_ASSIGN_ALL_BUSSES;		return NULL;	} else if (!strncmp(str, "irqmask=", 8)) {		pcibios_irq_mask = simple_strtol(str+8, NULL, 0);		return NULL;	} else if (!strncmp(str, "lastbus=", 8)) {		pcibios_last_bus = simple_strtol(str+8, NULL, 0);		return NULL;	}	return str;}unsigned int pcibios_assign_all_busses(void){	return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;}int pcibios_enable_device(struct pci_dev *dev){	int err;	if ((err = pcibios_enable_resources(dev)) < 0)		return err;	pcibios_enable_irq(dev);	return 0;}

⌨️ 快捷键说明

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