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 | { | |
10e79630 MN |
32 | struct pci_controller *phb = pci_bus_to_host(dev->bus); |
33 | ||
807a827d | 34 | eeh_remove_device(dev); |
10e79630 MN |
35 | |
36 | if (phb->controller_ops.release_device) | |
37 | phb->controller_ops.release_device(dev); | |
008a4938 GS |
38 | } |
39 | ||
317f06de | 40 | /** |
807a827d | 41 | * pcibios_remove_pci_devices - remove all devices under this bus |
317f06de | 42 | * @bus: the indicated PCI bus |
317f06de GS |
43 | * |
44 | * Remove all of the PCI devices under this bus both from the | |
45 | * linux pci device tree, and from the powerpc EEH address cache. | |
317f06de | 46 | */ |
807a827d | 47 | void pcibios_remove_pci_devices(struct pci_bus *bus) |
317f06de GS |
48 | { |
49 | struct pci_dev *dev, *tmp; | |
50 | struct pci_bus *child_bus; | |
51 | ||
52 | /* First go down child busses */ | |
53 | list_for_each_entry(child_bus, &bus->children, node) | |
807a827d | 54 | pcibios_remove_pci_devices(child_bus); |
317f06de GS |
55 | |
56 | pr_debug("PCI: Removing devices on bus %04x:%02x\n", | |
57 | pci_domain_nr(bus), bus->number); | |
971427f5 | 58 | list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) { |
807a827d | 59 | pr_debug(" Removing %s...\n", pci_name(dev)); |
317f06de GS |
60 | pci_stop_and_remove_bus_device(dev); |
61 | } | |
62 | } | |
63 | ||
317f06de GS |
64 | EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices); |
65 | ||
66 | /** | |
67 | * pcibios_add_pci_devices - adds new pci devices to bus | |
68 | * @bus: the indicated PCI bus | |
69 | * | |
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 | |
75 | * routines.) | |
76 | */ | |
77 | void pcibios_add_pci_devices(struct pci_bus * bus) | |
78 | { | |
ab444ec9 | 79 | int slotno, mode, pass, max; |
317f06de | 80 | struct pci_dev *dev; |
467efc2e | 81 | struct pci_controller *phb; |
317f06de GS |
82 | struct device_node *dn = pci_bus_to_OF_node(bus); |
83 | ||
ff57b454 | 84 | eeh_add_device_tree_early(PCI_DN(dn)); |
317f06de | 85 | |
467efc2e DA |
86 | phb = pci_bus_to_host(bus); |
87 | ||
317f06de | 88 | mode = PCI_PROBE_NORMAL; |
467efc2e DA |
89 | if (phb->controller_ops.probe_mode) |
90 | mode = phb->controller_ops.probe_mode(bus); | |
317f06de GS |
91 | |
92 | if (mode == PCI_PROBE_DEVTREE) { | |
93 | /* use ofdt-based probe */ | |
94 | of_rescan_bus(dn, bus); | |
95 | } else if (mode == PCI_PROBE_NORMAL) { | |
ab444ec9 GS |
96 | /* |
97 | * Use legacy probe. In the partial hotplug case, we | |
98 | * probably have grandchildren devices unplugged. So | |
99 | * we don't check the return value from pci_scan_slot() in | |
100 | * order for fully rescan all the way down to pick them up. | |
101 | * They can have been removed during partial hotplug. | |
102 | */ | |
317f06de | 103 | slotno = PCI_SLOT(PCI_DN(dn->child)->devfn); |
ab444ec9 | 104 | pci_scan_slot(bus, PCI_DEVFN(slotno, 0)); |
317f06de GS |
105 | pcibios_setup_bus_devices(bus); |
106 | max = bus->busn_res.start; | |
107 | for (pass = 0; pass < 2; pass++) { | |
108 | list_for_each_entry(dev, &bus->devices, bus_list) { | |
c888770e | 109 | if (pci_is_bridge(dev)) |
317f06de GS |
110 | max = pci_scan_bridge(bus, dev, |
111 | max, pass); | |
112 | } | |
113 | } | |
114 | } | |
115 | pcibios_finish_adding_to_bus(bus); | |
116 | } | |
117 | EXPORT_SYMBOL_GPL(pcibios_add_pci_devices); |