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

📄 pci.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * Common pmac/prep/chrp pci routines. -- Cort */#include <linux/config.h>#include <linux/kernel.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/string.h>#include <linux/init.h>#include <linux/capability.h>#include <linux/sched.h>#include <linux/errno.h>#include <linux/bootmem.h>#include <asm/processor.h>#include <asm/io.h>#include <asm/prom.h>#include <asm/sections.h>#include <asm/pci-bridge.h>#include <asm/byteorder.h>#include <asm/irq.h>#include <asm/uaccess.h>#undef DEBUG#ifdef DEBUG#define DBG(x...) printk(x)#else#define DBG(x...)#endifunsigned long isa_io_base     = 0;unsigned long isa_mem_base    = 0;unsigned long pci_dram_offset = 0;void pcibios_make_OF_bus_map(void);static int pci_relocate_bridge_resource(struct pci_bus *bus, int i);static int probe_resource(struct pci_bus *parent, struct resource *pr,			  struct resource *res, struct resource **conflict);static void update_bridge_base(struct pci_bus *bus, int i);static void pcibios_fixup_resources(struct pci_dev* dev);static void fixup_broken_pcnet32(struct pci_dev* dev);static int reparent_resources(struct resource *parent, struct resource *res);static void fixup_rev1_53c810(struct pci_dev* dev);static void fixup_cpc710_pci64(struct pci_dev* dev);#ifdef CONFIG_PPC_PMACextern void pmac_pci_fixup_cardbus(struct pci_dev* dev);extern void pmac_pci_fixup_pciata(struct pci_dev* dev);extern void pmac_pci_fixup_k2_sata(struct pci_dev* dev);#endif#ifdef CONFIG_PPC_OFstatic u8* pci_to_OF_bus_map;#endif/* By default, we don't re-assign bus numbers. We do this only on * some pmacs */int pci_assign_all_busses;struct pci_controller* hose_head;struct pci_controller** hose_tail = &hose_head;static int pci_bus_count;struct pci_fixup pcibios_fixups[] = {	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_TRIDENT,	PCI_ANY_ID,			fixup_broken_pcnet32 },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_NCR,	PCI_DEVICE_ID_NCR_53C810,	fixup_rev1_53c810 },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_IBM,	PCI_DEVICE_ID_IBM_CPC710_PCI64,	fixup_cpc710_pci64},	{ PCI_FIXUP_HEADER,	PCI_ANY_ID,		PCI_ANY_ID,			pcibios_fixup_resources },#ifdef CONFIG_PPC_PMAC	/* We should add per-machine fixup support in xxx_setup.c or xxx_pci.c */	{ PCI_FIXUP_FINAL,	PCI_VENDOR_ID_TI,	PCI_ANY_ID,			pmac_pci_fixup_cardbus },	{ PCI_FIXUP_FINAL,	PCI_ANY_ID,		PCI_ANY_ID,			pmac_pci_fixup_pciata },	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_SERVERWORKS, 0x0240,			pmac_pci_fixup_k2_sata },#endif /* CONFIG_PPC_PMAC */ 	{ 0 }};static voidfixup_rev1_53c810(struct pci_dev* dev){	/* rev 1 ncr53c810 chips don't set the class at all which means	 * they don't get their resources remapped. Fix that here.	 */	if ((dev->class == PCI_CLASS_NOT_DEFINED)) {		printk("NCR 53c810 rev 1 detected, setting PCI class.\n");		dev->class = PCI_CLASS_STORAGE_SCSI;	}}static voidfixup_broken_pcnet32(struct pci_dev* dev){	if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {		dev->vendor = PCI_VENDOR_ID_AMD;		pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);		pci_name_device(dev);	}}static voidfixup_cpc710_pci64(struct pci_dev* dev){	/* Hide the PCI64 BARs from the kernel as their content doesn't	 * fit well in the resource management	 */	dev->resource[0].start = dev->resource[0].end = 0;	dev->resource[0].flags = 0;	dev->resource[1].start = dev->resource[1].end = 0;	dev->resource[1].flags = 0;}static voidpcibios_fixup_resources(struct pci_dev *dev){	struct pci_controller* hose = (struct pci_controller *)dev->sysdata;	int i;	unsigned long offset;	if (!hose) {		printk(KERN_ERR "No hose for PCI dev %s!\n", pci_name(dev));		return;	}	for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {		struct resource *res = dev->resource + i;		if (!res->flags)			continue;		if (res->end == 0xffffffff) {			DBG("PCI:%s Resource %d [%08lx-%08lx] is unassigned\n",			    pci_name(dev), i, res->start, res->end);			res->end -= res->start;			res->start = 0;			res->flags |= IORESOURCE_UNSET;			continue;		}		offset = 0;		if (res->flags & IORESOURCE_MEM) {			offset = hose->pci_mem_offset;		} else if (res->flags & IORESOURCE_IO) {			offset = (unsigned long) hose->io_base_virt				- isa_io_base;		}		if (offset != 0) {			res->start += offset;			res->end += offset;#ifdef DEBUG			printk("Fixup res %d (%lx) of dev %s: %lx -> %lx\n",			       i, res->flags, pci_name(dev),			       res->start - offset, res->start);#endif		}	}	/* Call machine specific resource fixup */	if (ppc_md.pcibios_fixup_resources)		ppc_md.pcibios_fixup_resources(dev);}voidpcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,			struct resource *res){	unsigned long offset = 0;	struct pci_controller *hose = dev->sysdata;	if (hose && res->flags & IORESOURCE_IO)		offset = (unsigned long)hose->io_base_virt - isa_io_base;	else if (hose && res->flags & IORESOURCE_MEM)		offset = hose->pci_mem_offset;	region->start = res->start - offset;	region->end = res->end - offset;}/* * We need to avoid collisions with `mirrored' VGA ports * and other strange ISA hardware, so we always want the * addresses to be allocated in the 0x000-0x0ff region * modulo 0x400. * * Why? Because some silly external IO cards only decode * the low 10 bits of the IO address. The 0x00-0xff region * is reserved for motherboard devices that decode all 16 * bits, so it's ok to allocate at, say, 0x2800-0x28ff, * but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */voidpcibios_align_resource(void *data, struct resource *res, unsigned long size,		       unsigned long align){	struct pci_dev *dev = data;	if (res->flags & IORESOURCE_IO) {		unsigned long start = res->start;		if (size > 0x100) {			printk(KERN_ERR "PCI: I/O Region %s/%d too large"			       " (%ld bytes)\n", pci_name(dev),			       dev->resource - res, size);		}		if (start & 0x300) {			start = (start + 0x3ff) & ~0x3ff;			res->start = start;		}	}}/* *  Handle resources of PCI devices.  If the world were perfect, we could *  just allocate all the resource regions and do nothing more.  It isn't. *  On the other hand, we cannot just re-allocate all devices, as it would *  require us to know lots of host bridge internals.  So we attempt to *  keep as much of the original configuration as possible, but tweak it *  when it's found to be wrong. * *  Known BIOS problems we have to work around: *	- I/O or memory regions not configured *	- regions configured, but not enabled in the command register *	- bogus I/O addresses above 64K used *	- expansion ROMs left enabled (this may sound harmless, but given *	  the fact the PCI specs explicitly allow address decoders to be *	  shared between expansion ROMs and other resource regions, it's *	  at least dangerous) * *  Our solution: *	(1) Allocate resources for all buses behind PCI-to-PCI bridges. *	    This gives us fixed barriers on where we can allocate. *	(2) Allocate resources for all enabled devices.  If there is *	    a collision, just mark the resource as unallocated. Also *	    disable expansion ROMs during this step. *	(3) Try to allocate resources for disabled devices.  If the *	    resources were assigned correctly, everything goes well, *	    if they weren't, they won't disturb allocation of other *	    resources. *	(4) Assign new addresses to resources which were either *	    not configured at all or misconfigured.  If explicitly *	    requested by the user, configure expansion ROM address *	    as well. */static void __initpcibios_allocate_bus_resources(struct list_head *bus_list){	struct list_head *ln;	struct pci_bus *bus;	int i;	struct resource *res, *pr;	/* Depth-First Search on bus tree */	for (ln = bus_list->next; ln != bus_list; ln=ln->next) {		bus = pci_bus_b(ln);		for (i = 0; i < 4; ++i) {			if ((res = bus->resource[i]) == NULL || !res->flags			    || res->start > res->end)				continue;			if (bus->parent == NULL)				pr = (res->flags & IORESOURCE_IO)?					&ioport_resource: &iomem_resource;			else {				pr = pci_find_parent_resource(bus->self, res);				if (pr == res) {					/* this happens when the generic PCI					 * code (wrongly) decides that this					 * bridge is transparent  -- paulus					 */					continue;				}			}			DBG("PCI: bridge rsrc %lx..%lx (%lx), parent %p\n",			    res->start, res->end, res->flags, pr);			if (pr) {				if (request_resource(pr, res) == 0)					continue;				/*				 * Must be a conflict with an existing entry.				 * Move that entry (or entries) under the				 * bridge resource and try again.				 */				if (reparent_resources(pr, res) == 0)					continue;			}			printk(KERN_ERR "PCI: Cannot allocate resource region "			       "%d of PCI bridge %d\n", i, bus->number);			if (pci_relocate_bridge_resource(bus, i))				bus->resource[i] = NULL;		}		pcibios_allocate_bus_resources(&bus->children);	}}/* * Reparent resource children of pr that conflict with res * under res, and make res replace those children. */static int __initreparent_resources(struct resource *parent, struct resource *res){	struct resource *p, **pp;	struct resource **firstpp = NULL;	for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) {		if (p->end < res->start)			continue;		if (res->end < p->start)			break;		if (p->start < res->start || p->end > res->end)			return -1;	/* not completely contained */		if (firstpp == NULL)			firstpp = pp;	}	if (firstpp == NULL)		return -1;	/* didn't find any conflicting entries? */	res->parent = parent;	res->child = *firstpp;	res->sibling = *pp;	*firstpp = res;	*pp = NULL;	for (p = res->child; p != NULL; p = p->sibling) {		p->parent = res;		DBG(KERN_INFO "PCI: reparented %s [%lx..%lx] under %s\n",		    p->name, p->start, p->end, res->name);	}	return 0;}/* * A bridge has been allocated a range which is outside the range * of its parent bridge, so it needs to be moved. */static int __initpci_relocate_bridge_resource(struct pci_bus *bus, int i){	struct resource *res, *pr, *conflict;	unsigned long try, size;	int j;	struct pci_bus *parent = bus->parent;	if (parent == NULL) {		/* shouldn't ever happen */		printk(KERN_ERR "PCI: can't move host bridge resource\n");		return -1;	}	res = bus->resource[i];	if (res == NULL)		return -1;	pr = NULL;	for (j = 0; j < 4; j++) {		struct resource *r = parent->resource[j];		if (!r)			continue;		if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))			continue;		if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) {			pr = r;			break;		}		if (res->flags & IORESOURCE_PREFETCH)			pr = r;	}	if (pr == NULL)		return -1;	size = res->end - res->start;	if (pr->start > pr->end || size > pr->end - pr->start)		return -1;	try = pr->end;	for (;;) {		res->start = try - size;		res->end = try;		if (probe_resource(bus->parent, pr, res, &conflict) == 0)			break;		if (conflict->start <= pr->start + size)			return -1;		try = conflict->start - 1;	}	if (request_resource(pr, res)) {		DBG(KERN_ERR "PCI: huh? couldn't move to %lx..%lx\n",		    res->start, res->end);		return -1;		/* "can't happen" */	}	update_bridge_base(bus, i);	printk(KERN_INFO "PCI: bridge %d resource %d moved to %lx..%lx\n",	       bus->number, i, res->start, res->end);	return 0;}static int __initprobe_resource(struct pci_bus *parent, struct resource *pr,	       struct resource *res, struct resource **conflict){	struct pci_bus *bus;	struct pci_dev *dev;	struct resource *r;	struct list_head *ln;	int i;	for (r = pr->child; r != NULL; r = r->sibling) {		if (r->end >= res->start && res->end >= r->start) {			*conflict = r;			return 1;		}	}	for (ln = parent->children.next; ln != &parent->children;	     ln = ln->next) {		bus = pci_bus_b(ln);		for (i = 0; i < 4; ++i) {			if ((r = bus->resource[i]) == NULL)				continue;			if (!r->flags || r->start > r->end || r == res)				continue;			if (pci_find_parent_resource(bus->self, r) != pr)				continue;			if (r->end >= res->start && res->end >= r->start) {				*conflict = r;				return 1;			}		}	}	for (ln = parent->devices.next; ln != &parent->devices; ln=ln->next) {		dev = pci_dev_b(ln);		for (i = 0; i < 6; ++i) {			r = &dev->resource[i];			if (!r->flags || (r->flags & IORESOURCE_UNSET))				continue;			if (pci_find_parent_resource(bus->self, r) != pr)				continue;			if (r->end >= res->start && res->end >= r->start) {				*conflict = r;				return 1;			}		}	}	return 0;}static void __initupdate_bridge_base(struct pci_bus *bus, int i){	struct resource *res = bus->resource[i];	u8 io_base_lo, io_limit_lo;	u16 mem_base, mem_limit;	u16 cmd;	unsigned long start, end, off;

⌨️ 快捷键说明

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