Commit | Line | Data |
---|---|---|
317f06de GS |
1 | /* |
2 | * Derived from "arch/powerpc/platforms/pseries/pci_dlpar.c" | |
3 | * | |
4 | * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com> | |
5 | * Copyright (C) 2005 International Business Machines | |
6 | * | |
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> | |
10 | * | |
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. | |
15 | */ | |
16 | ||
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> | |
22 | #include <asm/eeh.h> | |
23 | ||
008a4938 GS |
24 | /** |
25 | * pcibios_release_device - release PCI device | |
26 | * @dev: PCI device | |
27 | * | |
28 | * The function is called before releasing the indicated PCI device. | |
29 | */ | |
30 | void pcibios_release_device(struct pci_dev *dev) | |
31 | { | |
32 | eeh_remove_device(dev, 1); | |
33 | } | |
34 | ||
317f06de GS |
35 | /** |
36 | * __pcibios_remove_pci_devices - remove all devices under this bus | |
37 | * @bus: the indicated PCI bus | |
38 | * @purge_pe: destroy the PE on removal of PCI devices | |
39 | * | |
40 | * Remove all of the PCI devices under this bus both from the | |
41 | * linux pci device tree, and from the powerpc EEH address cache. | |
42 | * By default, the corresponding PE will be destroied during the | |
43 | * normal PCI hotplug path. For PCI hotplug during EEH recovery, | |
44 | * the corresponding PE won't be destroied and deallocated. | |
45 | */ | |
46 | void __pcibios_remove_pci_devices(struct pci_bus *bus, int purge_pe) | |
47 | { | |
48 | struct pci_dev *dev, *tmp; | |
49 | struct pci_bus *child_bus; | |
50 | ||
51 | /* First go down child busses */ | |
52 | list_for_each_entry(child_bus, &bus->children, node) | |
53 | __pcibios_remove_pci_devices(child_bus, purge_pe); | |
54 | ||
55 | pr_debug("PCI: Removing devices on bus %04x:%02x\n", | |
56 | pci_domain_nr(bus), bus->number); | |
57 | list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) { | |
58 | pr_debug(" * Removing %s...\n", pci_name(dev)); | |
59 | eeh_remove_bus_device(dev, purge_pe); | |
60 | pci_stop_and_remove_bus_device(dev); | |
61 | } | |
62 | } | |
63 | ||
64 | /** | |
65 | * pcibios_remove_pci_devices - remove all devices under this bus | |
66 | * @bus: the indicated PCI bus | |
67 | * | |
68 | * Remove all of the PCI devices under this bus both from the | |
69 | * linux pci device tree, and from the powerpc EEH address cache. | |
70 | */ | |
71 | void pcibios_remove_pci_devices(struct pci_bus *bus) | |
72 | { | |
73 | __pcibios_remove_pci_devices(bus, 1); | |
74 | } | |
75 | EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices); | |
76 | ||
77 | /** | |
78 | * pcibios_add_pci_devices - adds new pci devices to bus | |
79 | * @bus: the indicated PCI bus | |
80 | * | |
81 | * This routine will find and fixup new pci devices under | |
82 | * the indicated bus. This routine presumes that there | |
83 | * might already be some devices under this bridge, so | |
84 | * it carefully tries to add only new devices. (And that | |
85 | * is how this routine differs from other, similar pcibios | |
86 | * routines.) | |
87 | */ | |
88 | void pcibios_add_pci_devices(struct pci_bus * bus) | |
89 | { | |
90 | int slotno, num, mode, pass, max; | |
91 | struct pci_dev *dev; | |
92 | struct device_node *dn = pci_bus_to_OF_node(bus); | |
93 | ||
94 | eeh_add_device_tree_early(dn); | |
95 | ||
96 | mode = PCI_PROBE_NORMAL; | |
97 | if (ppc_md.pci_probe_mode) | |
98 | mode = ppc_md.pci_probe_mode(bus); | |
99 | ||
100 | if (mode == PCI_PROBE_DEVTREE) { | |
101 | /* use ofdt-based probe */ | |
102 | of_rescan_bus(dn, bus); | |
103 | } else if (mode == PCI_PROBE_NORMAL) { | |
104 | /* use legacy probe */ | |
105 | slotno = PCI_SLOT(PCI_DN(dn->child)->devfn); | |
106 | num = pci_scan_slot(bus, PCI_DEVFN(slotno, 0)); | |
107 | if (!num) | |
108 | return; | |
109 | pcibios_setup_bus_devices(bus); | |
110 | max = bus->busn_res.start; | |
111 | for (pass = 0; pass < 2; pass++) { | |
112 | list_for_each_entry(dev, &bus->devices, bus_list) { | |
113 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || | |
114 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) | |
115 | max = pci_scan_bridge(bus, dev, | |
116 | max, pass); | |
117 | } | |
118 | } | |
119 | } | |
120 | pcibios_finish_adding_to_bus(bus); | |
121 | } | |
122 | EXPORT_SYMBOL_GPL(pcibios_add_pci_devices); |