2 * Derived from "arch/powerpc/platforms/pseries/pci_dlpar.c"
4 * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
5 * Copyright (C) 2005 International Business Machines
7 * Updates, 2005, John Rose <johnrose@austin.ibm.com>
8 * Updates, 2005, Linas Vepstas <linas@austin.ibm.com>
9 * Updates, 2013, Gavin Shan <shangw@linux.vnet.ibm.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/pci.h>
18 #include <linux/export.h>
19 #include <asm/pci-bridge.h>
20 #include <asm/ppc-pci.h>
21 #include <asm/firmware.h>
25 * __pcibios_remove_pci_devices - remove all devices under this bus
26 * @bus: the indicated PCI bus
27 * @purge_pe: destroy the PE on removal of PCI devices
29 * Remove all of the PCI devices under this bus both from the
30 * linux pci device tree, and from the powerpc EEH address cache.
31 * By default, the corresponding PE will be destroied during the
32 * normal PCI hotplug path. For PCI hotplug during EEH recovery,
33 * the corresponding PE won't be destroied and deallocated.
35 void __pcibios_remove_pci_devices(struct pci_bus
*bus
, int purge_pe
)
37 struct pci_dev
*dev
, *tmp
;
38 struct pci_bus
*child_bus
;
40 /* First go down child busses */
41 list_for_each_entry(child_bus
, &bus
->children
, node
)
42 __pcibios_remove_pci_devices(child_bus
, purge_pe
);
44 pr_debug("PCI: Removing devices on bus %04x:%02x\n",
45 pci_domain_nr(bus
), bus
->number
);
46 list_for_each_entry_safe(dev
, tmp
, &bus
->devices
, bus_list
) {
47 pr_debug(" * Removing %s...\n", pci_name(dev
));
48 eeh_remove_bus_device(dev
, purge_pe
);
49 pci_stop_and_remove_bus_device(dev
);
54 * pcibios_remove_pci_devices - remove all devices under this bus
55 * @bus: the indicated PCI bus
57 * Remove all of the PCI devices under this bus both from the
58 * linux pci device tree, and from the powerpc EEH address cache.
60 void pcibios_remove_pci_devices(struct pci_bus
*bus
)
62 __pcibios_remove_pci_devices(bus
, 1);
64 EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices
);
67 * pcibios_add_pci_devices - adds new pci devices to bus
68 * @bus: the indicated PCI bus
70 * This routine will find and fixup new pci devices under
71 * the indicated bus. This routine presumes that there
72 * might already be some devices under this bridge, so
73 * it carefully tries to add only new devices. (And that
74 * is how this routine differs from other, similar pcibios
77 void pcibios_add_pci_devices(struct pci_bus
* bus
)
79 int slotno
, num
, mode
, pass
, max
;
81 struct device_node
*dn
= pci_bus_to_OF_node(bus
);
83 eeh_add_device_tree_early(dn
);
85 mode
= PCI_PROBE_NORMAL
;
86 if (ppc_md
.pci_probe_mode
)
87 mode
= ppc_md
.pci_probe_mode(bus
);
89 if (mode
== PCI_PROBE_DEVTREE
) {
90 /* use ofdt-based probe */
91 of_rescan_bus(dn
, bus
);
92 } else if (mode
== PCI_PROBE_NORMAL
) {
93 /* use legacy probe */
94 slotno
= PCI_SLOT(PCI_DN(dn
->child
)->devfn
);
95 num
= pci_scan_slot(bus
, PCI_DEVFN(slotno
, 0));
98 pcibios_setup_bus_devices(bus
);
99 max
= bus
->busn_res
.start
;
100 for (pass
= 0; pass
< 2; pass
++) {
101 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
102 if (dev
->hdr_type
== PCI_HEADER_TYPE_BRIDGE
||
103 dev
->hdr_type
== PCI_HEADER_TYPE_CARDBUS
)
104 max
= pci_scan_bridge(bus
, dev
,
109 pcibios_finish_adding_to_bus(bus
);
111 EXPORT_SYMBOL_GPL(pcibios_add_pci_devices
);