0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <linux/pci.h>
0014 #include <linux/export.h>
0015 #include <linux/of.h>
0016 #include <asm/pci-bridge.h>
0017 #include <asm/ppc-pci.h>
0018 #include <asm/firmware.h>
0019 #include <asm/eeh.h>
0020
0021 static struct pci_bus *find_bus_among_children(struct pci_bus *bus,
0022 struct device_node *dn)
0023 {
0024 struct pci_bus *child = NULL;
0025 struct pci_bus *tmp;
0026
0027 if (pci_bus_to_OF_node(bus) == dn)
0028 return bus;
0029
0030 list_for_each_entry(tmp, &bus->children, node) {
0031 child = find_bus_among_children(tmp, dn);
0032 if (child)
0033 break;
0034 }
0035
0036 return child;
0037 }
0038
0039 struct pci_bus *pci_find_bus_by_node(struct device_node *dn)
0040 {
0041 struct pci_dn *pdn = PCI_DN(dn);
0042
0043 if (!pdn || !pdn->phb || !pdn->phb->bus)
0044 return NULL;
0045
0046 return find_bus_among_children(pdn->phb->bus, dn);
0047 }
0048 EXPORT_SYMBOL_GPL(pci_find_bus_by_node);
0049
0050
0051
0052
0053
0054
0055
0056 void pcibios_release_device(struct pci_dev *dev)
0057 {
0058 struct pci_controller *phb = pci_bus_to_host(dev->bus);
0059 struct pci_dn *pdn = pci_get_pdn(dev);
0060
0061 if (phb->controller_ops.release_device)
0062 phb->controller_ops.release_device(dev);
0063
0064
0065 if (pdn && (pdn->flags & PCI_DN_FLAG_DEAD)) {
0066 pci_dbg(dev, "freeing dead pdn\n");
0067 kfree(pdn);
0068 }
0069 }
0070
0071
0072
0073
0074
0075
0076
0077
0078 void pci_hp_remove_devices(struct pci_bus *bus)
0079 {
0080 struct pci_dev *dev, *tmp;
0081 struct pci_bus *child_bus;
0082
0083
0084 list_for_each_entry(child_bus, &bus->children, node)
0085 pci_hp_remove_devices(child_bus);
0086
0087 pr_debug("PCI: Removing devices on bus %04x:%02x\n",
0088 pci_domain_nr(bus), bus->number);
0089 list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
0090 pr_debug(" Removing %s...\n", pci_name(dev));
0091 pci_stop_and_remove_bus_device(dev);
0092 }
0093 }
0094 EXPORT_SYMBOL_GPL(pci_hp_remove_devices);
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 void pci_hp_add_devices(struct pci_bus *bus)
0108 {
0109 int slotno, mode, max;
0110 struct pci_dev *dev;
0111 struct pci_controller *phb;
0112 struct device_node *dn = pci_bus_to_OF_node(bus);
0113
0114 phb = pci_bus_to_host(bus);
0115
0116 mode = PCI_PROBE_NORMAL;
0117 if (phb->controller_ops.probe_mode)
0118 mode = phb->controller_ops.probe_mode(bus);
0119
0120 if (mode == PCI_PROBE_DEVTREE) {
0121
0122 of_rescan_bus(dn, bus);
0123 } else if (mode == PCI_PROBE_NORMAL &&
0124 dn->child && PCI_DN(dn->child)) {
0125
0126
0127
0128
0129
0130
0131
0132 slotno = PCI_SLOT(PCI_DN(dn->child)->devfn);
0133 pci_scan_slot(bus, PCI_DEVFN(slotno, 0));
0134 max = bus->busn_res.start;
0135
0136
0137
0138
0139
0140 for_each_pci_bridge(dev, bus)
0141 max = pci_scan_bridge(bus, dev, max, 0);
0142
0143
0144 for_each_pci_bridge(dev, bus)
0145 max = pci_scan_bridge(bus, dev, max, 1);
0146 }
0147 pcibios_finish_adding_to_bus(bus);
0148 }
0149 EXPORT_SYMBOL_GPL(pci_hp_add_devices);