/* Clear bit of phb_bitmap to allow reuse of this PHB number. */ if (phb->global_number < MAX_PHBS)
clear_bit(phb->global_number, phb_bitmap);
of_node_put(phb->dn);
list_del(&phb->list_node);
spin_unlock(&hose_spinlock);
if (phb->is_dynamic)
kfree(phb);
}
EXPORT_SYMBOL_GPL(pcibios_free_controller);
/* This routine is meant to be used early during boot, when the *PCIbusnumbershavenotyetbeenassigned,andyouneedto *issuePCIconfigcyclestoanOFdevice. *Itcouldalsobeusedto"fix"RTASconfigcyclesifyouwant *tosetpci_assign_all_busesto1andstilluseRTASforPCI *configcycles.
*/ struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node)
{ while(node) { struct pci_controller *hose, *tmp;
list_for_each_entry_safe(hose, tmp, &hose_list, list_node) if (hose->dn == node) return hose;
node = node->parent;
} return NULL;
}
/* Preallocate vi as rewind is complex if this fails after mapping */
vi = kzalloc(sizeof(struct pci_intx_virq), GFP_KERNEL); if (!vi) return -1;
pr_debug("PCI: Try to map irq for %s...\n", pci_name(pci_dev));
/* Try to get a mapping from the device-tree */
virq = of_irq_parse_and_map_pci(pci_dev, 0, 0); if (virq <= 0) {
u8 line, pin;
/* If that fails, lets fallback to what is in the config *spaceandmapthatthroughthedefaultcontroller.We *alsosetthetypetolevellowsincethat'swhatPCI *interruptsare.Ifyourplatformdoesdifferently,then *eitherprovideaproperinterrupttreeordon'tusethis *function.
*/ if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &pin)) goto error_exit; if (pin == 0) goto error_exit; if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_LINE, &line) ||
line == 0xff || line == 0) { goto error_exit;
}
pr_debug(" No map ! Using line %d (pin %d) from PCI config\n",
line, pin);
virq = irq_create_mapping(NULL, line); if (virq)
irq_set_irq_type(virq, IRQ_TYPE_LEVEL_LOW);
}
if (!virq) {
pr_debug(" Failed to map !\n"); goto error_exit;
}
pr_debug(" Mapped to linux irq %d\n", virq);
pci_dev->irq = virq;
mutex_lock(&intx_mutex);
list_for_each_entry(vitmp, &intx_list, list_node) { if (vitmp->virq == virq) {
kref_get(&vitmp->kref);
kfree(vi);
vi = NULL; break;
}
} if (vi) {
vi->virq = virq;
kref_init(&vi->kref);
list_add_tail(&vi->list_node, &intx_list);
}
mutex_unlock(&intx_mutex);
return0;
error_exit:
kfree(vi); return -1;
}
/* *Platformsupportfor/proc/bus/pci/X/Ymmap()s. *--paulus.
*/ int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma)
{ struct pci_controller *hose = pci_bus_to_host(pdev->bus);
resource_size_t ioaddr = pci_resource_start(pdev, bar);
if (!hose) return -EINVAL;
/* Convert to an offset within this PCI controller */
ioaddr -= (unsignedlong)hose->io_base_virt - _IO_BASE;
prot = pgprot_noncached(prot);
for_each_pci_dev(pdev) { for (i = 0; i <= PCI_ROM_RESOURCE; i++) { struct resource *rp = &pdev->resource[i]; int flags = rp->flags;
/* Active and same type? */ if ((flags & IORESOURCE_MEM) == 0) continue; /* In the range of this resource? */ if (offset < (rp->start & PAGE_MASK) ||
offset > rp->end) continue;
found = rp; break;
} if (found) break;
} if (found) { if (found->flags & IORESOURCE_PREFETCH)
prot = pgprot_noncached_wc(prot);
pci_dev_put(pdev);
}
pr_debug("PCI: Non-PCI map for %llx, prot: %lx\n",
(unsignedlonglong)offset, pgprot_val(prot));
return prot;
}
/* This provides legacy IO read access on a bus */ int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val, size_t size)
{ unsignedlong offset; struct pci_controller *hose = pci_bus_to_host(bus); struct resource *rp = &hose->io_resource; void __iomem *addr;
/* Check if port can be supported by that bus. We only check *therangesofthePHBthough,notthebusitselfastherules *forforwardinglegacycyclesdownbridgesarenotourproblem *here.Soifthehostbridgesupportsit,wedoit.
*/
offset = (unsignedlong)hose->io_base_virt - _IO_BASE;
offset += port;
/* This provides legacy IO write access on a bus */ int pci_legacy_write(struct pci_bus *bus, loff_t port, u32 val, size_t size)
{ unsignedlong offset; struct pci_controller *hose = pci_bus_to_host(bus); struct resource *rp = &hose->io_resource; void __iomem *addr;
/* Check if port can be supported by that bus. We only check *therangesofthePHBthough,notthebusitselfastherules *forforwardinglegacycyclesdownbridgesarenotourproblem *here.Soifthehostbridgesupportsit,wedoit.
*/
offset = (unsignedlong)hose->io_base_virt - _IO_BASE;
offset += port;
/* We pass a CPU physical address to userland for MMIO instead of a *BARvaluebecauseXislameandexpectstobeabletousethat *topassto/dev/mem! * *Thatmeanswemayhave64-bitvalueswheresomeappsonlyexpect *32(likeXitselfsinceitthinksonlySparchas64-bitMMIO).
*/
*start = rsrc->start;
*end = rsrc->end;
}
/* Check for ranges property */ if (of_pci_range_parser_init(&parser, dev)) return;
/* Parse it */
for_each_of_pci_range(&parser, &range) { /* If we failed translation or got a zero-sized region *(someFWtrytofeeduswithnonsensicalzerosizedregions *suchaspower3whichlooklikesomekindofattemptatexposing *theVGAmemoryhole)
*/ if (range.cpu_addr == OF_BAD_ADDR || range.size == 0) continue;
/* Act based on address space type */
res = NULL; switch (range.flags & IORESOURCE_TYPE_BITS) { case IORESOURCE_IO:
printk(KERN_INFO " IO 0x%016llx..0x%016llx -> 0x%016llx\n",
range.cpu_addr, range.cpu_addr + range.size - 1,
range.pci_addr);
/* We support only one IO range */ if (hose->pci_io_size) {
printk(KERN_INFO " \\--> Skipped (too many) !\n"); continue;
} #ifdef CONFIG_PPC32 /* On 32 bits, limit I/O space to 16MB */ if (range.size > 0x01000000)
range.size = 0x01000000;
/* 32 bits needs to map IOs here */
hose->io_base_virt = ioremap(range.cpu_addr,
range.size);
/* Expect trouble if pci_addr is not 0 */ if (primary)
isa_io_base =
(unsignedlong)hose->io_base_virt; #endif/* CONFIG_PPC32 */ /* pci_io_size and io_base_phys always represent IO *spacestartingat0sowefactorinpci_addr
*/
hose->pci_io_size = range.pci_addr + range.size;
hose->io_base_phys = range.cpu_addr - range.pci_addr;
/* Decide whether to display the domain number in /proc */ int pci_proc_domain(struct pci_bus *bus)
{ struct pci_controller *hose = pci_bus_to_host(bus);
if (!pci_has_flag(PCI_ENABLE_PROC_DOMAINS)) return0; if (pci_has_flag(PCI_COMPAT_DOMAIN_0)) return hose->global_number != 0; return1;
}
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
{ if (ppc_md.pcibios_root_bridge_prepare) return ppc_md.pcibios_root_bridge_prepare(bridge);
return0;
}
/* This header fixup will do the resource fixup for all devices as they are *probed,butnotforbridgeranges
*/ staticvoid pcibios_fixup_resources(struct pci_dev *dev)
{ struct pci_controller *hose = pci_bus_to_host(dev->bus); struct resource *res; int i;
if (!hose) {
printk(KERN_ERR "No host bridge for PCI dev %s !\n",
pci_name(dev)); return;
}
/* If we're going to re-assign everything, we mark all resources *asunset(and0-basethem).Inaddition,wemarkBARsstarting *at0asunsetaswell,exceptifPCI_PROBE_ONLYisalsoset *sinceinthatcase,wedon'twanttore-assignanything
*/
pcibios_resource_to_bus(dev->bus, ®, res); if (pci_has_flag(PCI_REASSIGN_ALL_RSRC) ||
(reg.start == 0 && !pci_has_flag(PCI_PROBE_ONLY))) { /* Only print message if not re-assigning */ if (!pci_has_flag(PCI_REASSIGN_ALL_RSRC))
pr_debug("PCI:%s Resource %d %pR is unassigned\n",
pci_name(dev), i, res);
res->end -= res->start;
res->start = 0;
res->flags |= IORESOURCE_UNSET; continue;
}
pr_debug("PCI:%s Resource %d %pR\n", pci_name(dev), i, res);
}
/* Call machine specific resource fixup */ if (ppc_md.pcibios_fixup_resources)
ppc_md.pcibios_fixup_resources(dev);
}
DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources);
/* This function tries to figure out if a bridge resource has been initialized *bythefirmwareornot.Itdoesn'thavetobeabsolutelybulletproof,but *thingsgomoresmoothlywhenitgetsitright.Itshouldcoverscasessuch *asApple"closed"bridgeresourcesandbare-metalpSeriesunassignedbridges
*/ staticint pcibios_uninitialized_bridge_resource(struct pci_bus *bus, struct resource *res)
{ struct pci_controller *hose = pci_bus_to_host(bus); struct pci_dev *dev = bus->self;
resource_size_t offset; struct pci_bus_region region;
u16 command; int i;
/* We don't do anything if PCI_PROBE_ONLY is set */ if (pci_has_flag(PCI_PROBE_ONLY)) return0;
/* Job is a bit different between memory and IO */ if (res->flags & IORESOURCE_MEM) {
pcibios_resource_to_bus(dev->bus, ®ion, res);
/* If the BAR is non-0 then it's probably been initialized */ if (region.start != 0) return0;
/* The BAR is 0, let's check if memory decoding is enabled on *thebridge.Ifnot,weconsideritunassigned
*/
pci_read_config_word(dev, PCI_COMMAND, &command); if ((command & PCI_COMMAND_MEMORY) == 0) return1;
/* Memory decoding is enabled and the BAR is 0. If any of the bridge *resourcescoversthatstartingaddress(0thenit'sgoodenoughfor *usformemoryspace)
*/ for (i = 0; i < 3; i++) { if ((hose->mem_resources[i].flags & IORESOURCE_MEM) &&
hose->mem_resources[i].start == hose->mem_offset[i]) return0;
}
/* Well, it starts at 0 and we know it will collide so we may as *wellconsideritasunassigned.ThatcoverstheApplecase.
*/ return1;
} else { /* If the BAR is non-0, then we consider it assigned */
offset = (unsignedlong)hose->io_base_virt - _IO_BASE; if (((res->start - offset) & 0xfffffffful) != 0) return0;
/* Here, we are a bit different than memory as typically IO space *startingatlowaddresses-is-valid.Whatwedoinsteadifthat *weconsiderasunassignedanythingthatdoesn'thaveIOenabled *inthePCIcommandregister,andthat'sit.
*/
pci_read_config_word(dev, PCI_COMMAND, &command); if (command & PCI_COMMAND_IO) return0;
/* It's starting at 0 and IO is disabled in the bridge, consider *itunassigned
*/ return1;
}
}
/* Fixup resources of a PCI<->PCI bridge */ staticvoid pcibios_fixup_bridge(struct pci_bus *bus)
{ struct resource *res; int i;
struct pci_dev *dev = bus->self;
pci_bus_for_each_resource(bus, res, i) { if (!res || !res->flags) continue; if (i >= 3 && bus->self->transparent) continue;
/* If we're going to reassign everything, we can *shrinktheP2Presourcetohavesizeasbeing *of0inordertosavespace.
*/ if (pci_has_flag(PCI_REASSIGN_ALL_RSRC)) {
res->flags |= IORESOURCE_UNSET;
res->start = 0;
res->end = -1; continue;
}
pr_debug("PCI:%s Bus rsrc %d %pR\n", pci_name(dev), i, res);
/* Fix up the bus resources for P2P bridges */ if (bus->self != NULL)
pcibios_fixup_bridge(bus);
/* Platform specific bus fixups. This is currently only used *byfsl_pciandI'mhopingtogetridofitatsomepoint
*/ if (ppc_md.pcibios_fixup_bus)
ppc_md.pcibios_fixup_bus(bus);
/* Setup bus DMA mappings */
phb = pci_bus_to_host(bus); if (phb->controller_ops.dma_bus_setup)
phb->controller_ops.dma_bus_setup(bus);
}
void pcibios_bus_add_device(struct pci_dev *dev)
{ struct pci_controller *phb; /* Fixup NUMA node as it may not be setup yet by the generic *codeandisneededbytheDMAinit
*/
set_dev_node(&dev->dev, pcibus_to_node(dev->bus));
/* Read default IRQs and fixup if necessary */
pci_read_irq_line(dev); if (ppc_md.pci_irq_fixup)
ppc_md.pci_irq_fixup(dev);
if (ppc_md.pcibios_bus_add_device)
ppc_md.pcibios_bus_add_device(dev);
}
int pcibios_device_add(struct pci_dev *dev)
{ struct irq_domain *d;
#ifdef CONFIG_PCI_IOV if (ppc_md.pcibios_fixup_sriov)
ppc_md.pcibios_fixup_sriov(dev); #endif/* CONFIG_PCI_IOV */
d = dev_get_msi_domain(&dev->bus->dev); if (d)
dev_set_msi_domain(&dev->dev, d); return0;
}
void pcibios_set_master(struct pci_dev *dev)
{ /* No special bus mastering setup handling */
}
void pcibios_fixup_bus(struct pci_bus *bus)
{ /* When called from the generic PCI probe, read PCI<->PCI bridge *bases.Thisis-not-calledwhengeneratingthePCItreefrom *theOFdevice-tree.
*/
pci_read_bridge_bases(bus);
/* Now fixup the bus */
pcibios_setup_bus_self(bus);
}
EXPORT_SYMBOL(pcibios_fixup_bus);
if (request_resource(pr, res) == 0) continue; /* *Mustbeaconflictwithanexistingentry. *Movethatentry(orentries)underthe *bridgeresourceandtryagain.
*/ if (reparent_resources(pr, res) == 0) continue;
if (dev && i < PCI_BRIDGE_RESOURCE_NUM &&
pci_claim_bridge_resource(dev,
i + PCI_BRIDGE_RESOURCES) == 0) continue;
}
pr_warn("PCI: Cannot allocate resource region %d of PCI bridge %d, will remap\n",
i, bus->number);
clear_resource: /* The resource might be figured out when doing *reassignmentbasedontheresourcesrequired *bythedownstreamPCIdevices.Hereweset *thesizeoftheresourcetobe0inorderto *savemorespace.
*/
res->start = 0;
res->end = -1;
res->flags = 0;
}
for_each_pci_dev(dev) {
pci_read_config_word(dev, PCI_COMMAND, &command); for (idx = 0; idx <= PCI_ROM_RESOURCE; idx++) {
r = &dev->resource[idx]; if (r->parent) /* Already allocated */ continue; if (!r->flags || (r->flags & IORESOURCE_UNSET)) continue; /* Not assigned at all */ /* We only allocate ROMs on pass 1 just in case they *havebeenscrewedupbyfirmware
*/ if (idx == PCI_ROM_RESOURCE )
disabled = 1; if (r->flags & IORESOURCE_IO)
disabled = !(command & PCI_COMMAND_IO); else
disabled = !(command & PCI_COMMAND_MEMORY); if (pass == disabled)
alloc_resource(dev, idx);
} if (pass) continue;
r = &dev->resource[PCI_ROM_RESOURCE]; if (r->flags) { /* Turn the ROM off, leave the resource region, *butkeepitunregistered.
*/
u32 reg;
pci_read_config_dword(dev, dev->rom_base_reg, ®); if (reg & PCI_ROM_ADDRESS_ENABLE) {
pr_debug("PCI: Switching off ROM of %s\n",
pci_name(dev));
r->flags &= ~IORESOURCE_ROM_ENABLE;
pci_write_config_dword(dev, dev->rom_base_reg,
reg & ~PCI_ROM_ADDRESS_ENABLE);
}
}
}
}
/* Allocate and assign resources */
list_for_each_entry(b, &pci_root_buses, node)
pcibios_allocate_bus_resources(b); if (!pci_has_flag(PCI_REASSIGN_ALL_RSRC)) {
pcibios_allocate_resources(0);
pcibios_allocate_resources(1);
}
/* Before we start assigning unassigned resource, we try to reserve *thelowIOareaandtheVGAmemoryareaiftheyintersectthe *busavailableresourcestoavoidallocatingthingsontopofthem
*/ if (!pci_has_flag(PCI_PROBE_ONLY)) {
list_for_each_entry(b, &pci_root_buses, node)
pcibios_reserve_legacy_regions(b);
}
/* Now, if the platform didn't decide to blindly trust the firmware, *weproceedtoassigningthingsthatwereleftunassigned
*/ if (!pci_has_flag(PCI_PROBE_ONLY)) {
pr_debug("PCI: Assigning unassigned resources...\n");
pci_assign_unassigned_resources();
}
}
/* This is used by the PCI hotplug driver to allocate resource *ofnewlypluggedbusses.Wecantrytoconsolidatewiththe *restofthecodelater,fornow,keepitas-isasourmain *resourceallocationfunctiondoesn'tdealwithsub-treesyet.
*/ void pcibios_claim_one_bus(struct pci_bus *bus)
{ struct pci_dev *dev; struct pci_bus *child_bus;
list_for_each_entry(dev, &bus->devices, bus_list) { struct resource *r; int i;
/* Allocate bus and devices resources */
pcibios_allocate_bus_resources(bus);
pcibios_claim_one_bus(bus); if (!pci_has_flag(PCI_PROBE_ONLY)) { if (bus->self)
pci_assign_unassigned_bridge_resources(bus->self); else
pci_assign_unassigned_bus_resources(bus);
}
/* Add new devices to global lists. Register in proc, sysfs. */
pci_bus_add_devices(bus);
}
EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus);
int pcibios_enable_device(struct pci_dev *dev, int mask)
{ struct pci_controller *phb = pci_bus_to_host(dev->bus);
if (phb->controller_ops.enable_device_hook) if (!phb->controller_ops.enable_device_hook(dev)) return -EINVAL;
int early_find_capability(struct pci_controller *hose, int bus, int devfn, int cap)
{ return pci_bus_find_capability(fake_pci_bus(hose, bus), devfn, cap);
}
/* Create an empty bus for the toplevel */
bus = pci_create_root_bus(hose->parent, hose->first_busno,
hose->ops, hose, &resources); if (bus == NULL) {
pr_err("Failed to create bus for PCI domain %04x\n",
hose->global_number);
pci_free_resource_list(&resources); return;
}
hose->bus = bus;
/* Get probe mode and perform scan */
mode = PCI_PROBE_NORMAL; if (node && hose->controller_ops.probe_mode)
mode = hose->controller_ops.probe_mode(bus);
pr_debug(" probe mode: %d\n", mode); if (mode == PCI_PROBE_DEVTREE)
of_scan_bus(node, bus);
/* Platform gets a chance to do some global fixups before *weproceedtoresourceallocation
*/ if (ppc_md.pcibios_fixup_phb)
ppc_md.pcibios_fixup_phb(hose);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.