📄 pci.c
字号:
/* * * * Port for PPC64 David Engebretsen, IBM Corp. * Contains common pci routines for ppc64 platform, pSeries and iSeries brands. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#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/pci-bridge.h>#include <asm/byteorder.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <asm/flight_recorder.h>#include <asm/ppcdebug.h>#include <asm/naca.h>#include <asm/pci_dma.h>#include <asm/machdep.h>#include <asm/eeh.h>#include "pci.h"/* pci_io_base -- the base address from which io bars are offsets. * This is the lowest I/O base address (so bar values are always positive), * and it *must* be the start of ISA space if an ISA bus exists because * ISA drivers use hard coded offsets. If no ISA bus exists a dummy * page is mapped and isa_io_limit prevents access to it. */unsigned long isa_io_base = 0; /* NULL if no ISA bus */unsigned long pci_io_base = 0;unsigned long isa_mem_base = 0;unsigned long pci_dram_offset = 0;/****************************************************************** * Forward declare of prototypes ******************************************************************/static void pcibios_fixup_resources(struct pci_dev* dev);static void fixup_broken_pcnet32(struct pci_dev* dev);static void fixup_windbond_82c105(struct pci_dev* dev);void fixup_resources(struct pci_dev* dev);void iSeries_pcibios_init(void);void pSeries_pcibios_init(void);int pci_assign_all_busses = 0;struct pci_controller* hose_head;struct pci_controller** hose_tail = &hose_head;LIST_HEAD(iSeries_Global_Device_List);/******************************************************************* * Counters and control flags. *******************************************************************/long Pci_Io_Read_Count = 0;long Pci_Io_Write_Count = 0;long Pci_Cfg_Read_Count = 0;long Pci_Cfg_Write_Count= 0;long Pci_Error_Count = 0;int Pci_Retry_Max = 7; /* Retry set to 7 times */ int Pci_Error_Flag = 1; /* Set Retry Error on. */int Pci_Trace_Flag = 0;/****************************************************************** * ******************************************************************/int global_phb_number = 0; /* Global phb counter */int Pci_Large_Bus_System = 0;int Pci_Set_IOA_Address = 0;int Pci_Manage_Phb_Space = 0;struct pci_controller *phbtab[PCI_MAX_PHB];static int pci_bus_count;/* Cached ISA bridge dev. */struct pci_dev *ppc64_isabridge_dev = NULL;struct pci_fixup pcibios_fixups[] = { { PCI_FIXUP_HEADER, PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32 }, { PCI_FIXUP_HEADER, PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105, fixup_windbond_82c105 }, { PCI_FIXUP_HEADER, PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources }, { 0 }};static void fixup_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 void fixup_windbond_82c105(struct pci_dev* dev){ /* Assume the windbond 82c105 is the IDE controller on a * p610. We should probably be more careful in case * someone tries to plug in a similar adapter. */ unsigned int reg; printk("Using INTC for W82c105 IDE controller.\n"); pci_read_config_dword(dev, 0x40, ®); /* Enable LEGIRQ to use INTC instead of ISA interrupts */ pci_write_config_dword(dev, 0x40, reg | (1<<11));}void pcibios_fixup_pbus_ranges(struct pci_bus *pbus, struct pbus_set_ranges_data *pranges){}voidpcibios_update_resource(struct pci_dev *dev, struct resource *root, struct resource *res, int resource){ u32 new, check; int reg; struct pci_controller* hose = PCI_GET_PHB_PTR(dev); new = res->start; if (hose && res->flags & IORESOURCE_MEM) new -= hose->pci_mem_offset; new |= (res->flags & PCI_REGION_FLAG_MASK); if (resource < 6) { reg = PCI_BASE_ADDRESS_0 + 4*resource; } else if (resource == PCI_ROM_RESOURCE) { res->flags |= PCI_ROM_ADDRESS_ENABLE; reg = dev->rom_base_reg; } else { /* Somebody might have asked allocation of a non-standard resource */ return; } pci_write_config_dword(dev, reg, new); pci_read_config_dword(dev, reg, &check); if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) { printk(KERN_ERR "PCI: Error while updating region " "%s/%d (%08x != %08x)\n", dev->slot_name, resource, new, check); }}static voidpcibios_fixup_resources(struct pci_dev* dev){ fixup_resources(dev);}/* * 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: Can not align I/O Region %s %s because size %ld is too large.\n", dev->slot_name, res->name, 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) 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) continue; /* transparent bus or undefined */ if (pr && request_resource(pr, res) == 0) continue; printk(KERN_ERR "PCI: Cannot allocate resource region " "%d of PCI bridge %x\n", i, bus->number); printk(KERN_ERR "PCI: resource is %lx..%lx (%lx), parent %p\n", res->start, res->end, res->flags, pr); } pcibios_allocate_bus_resources(&bus->children); }}static void __initpcibios_allocate_resources(int pass){ struct pci_dev *dev; int idx, disabled; u16 command; struct resource *r, *pr; pci_for_each_dev(dev) { pci_read_config_word(dev, PCI_COMMAND, &command); for(idx = 0; idx < 6; idx++) { r = &dev->resource[idx]; if (r->parent) /* Already allocated */ continue; if (!r->start) /* Address not assigned at all */ continue; if (r->flags & IORESOURCE_IO) disabled = !(command & PCI_COMMAND_IO); else disabled = !(command & PCI_COMMAND_MEMORY); if (pass == disabled) { PPCDBG(PPCDBG_PHBINIT, "PCI: Resource %08lx-%08lx (f=%lx, d=%d, p=%d)\n", r->start, r->end, r->flags, disabled, pass); pr = pci_find_parent_resource(dev, r); if (!pr || request_resource(pr, r) < 0) { PPCDBG(PPCDBG_PHBINIT, "PCI: Cannot allocate resource region %d of device %s, pr = 0x%lx\n", idx, dev->slot_name, pr); if(pr) { PPCDBG(PPCDBG_PHBINIT, "PCI: Cannot allocate resource 0x%lx\n", request_resource(pr,r)); } /* We'll assign a new address later */ r->end -= r->start; r->start = 0; } } } if (!pass) { r = &dev->resource[PCI_ROM_RESOURCE]; if (r->flags & PCI_ROM_ADDRESS_ENABLE) { /* Turn the ROM off, leave the resource region, but keep it unregistered. */ u32 reg; r->flags &= ~PCI_ROM_ADDRESS_ENABLE; pci_read_config_dword(dev, dev->rom_base_reg, ®); pci_write_config_dword(dev, dev->rom_base_reg, reg & ~PCI_ROM_ADDRESS_ENABLE); } } }}static void __initpcibios_assign_resources(void){ struct pci_dev *dev; int idx; struct resource *r; pci_for_each_dev(dev) { int class = dev->class >> 8; /* Don't touch classless devices and host bridges */ if (!class || class == PCI_CLASS_BRIDGE_HOST) continue; for(idx=0; idx<6; idx++) { r = &dev->resource[idx]; /* * Don't touch IDE controllers and I/O ports of video cards! */ if ((class == PCI_CLASS_STORAGE_IDE && idx < 4) || (class == PCI_CLASS_DISPLAY_VGA && (r->flags & IORESOURCE_IO))) continue; /* * We shall assign a new address to this resource, either because * the BIOS forgot to do so or because we have decided the old * address was unusable for some reason. */ if (!r->start && r->end && ppc_md.pcibios_enable_device_hook && !ppc_md.pcibios_enable_device_hook(dev, 1)) pci_assign_resource(dev, idx); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -