pci-hotplug.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include <linux/pci.h>
  17. #include <linux/export.h>
  18. #include <asm/pci-bridge.h>
  19. #include <asm/ppc-pci.h>
  20. #include <asm/firmware.h>
  21. #include <asm/eeh.h>
  22. /**
  23. * __pcibios_remove_pci_devices - remove all devices under this bus
  24. * @bus: the indicated PCI bus
  25. * @purge_pe: destroy the PE on removal of PCI devices
  26. *
  27. * Remove all of the PCI devices under this bus both from the
  28. * linux pci device tree, and from the powerpc EEH address cache.
  29. * By default, the corresponding PE will be destroied during the
  30. * normal PCI hotplug path. For PCI hotplug during EEH recovery,
  31. * the corresponding PE won't be destroied and deallocated.
  32. */
  33. void __pcibios_remove_pci_devices(struct pci_bus *bus, int purge_pe)
  34. {
  35. struct pci_dev *dev, *tmp;
  36. struct pci_bus *child_bus;
  37. /* First go down child busses */
  38. list_for_each_entry(child_bus, &bus->children, node)
  39. __pcibios_remove_pci_devices(child_bus, purge_pe);
  40. pr_debug("PCI: Removing devices on bus %04x:%02x\n",
  41. pci_domain_nr(bus), bus->number);
  42. list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
  43. pr_debug(" * Removing %s...\n", pci_name(dev));
  44. eeh_remove_bus_device(dev, purge_pe);
  45. pci_stop_and_remove_bus_device(dev);
  46. }
  47. }
  48. /**
  49. * pcibios_remove_pci_devices - remove all devices under this bus
  50. * @bus: the indicated PCI bus
  51. *
  52. * Remove all of the PCI devices under this bus both from the
  53. * linux pci device tree, and from the powerpc EEH address cache.
  54. */
  55. void pcibios_remove_pci_devices(struct pci_bus *bus)
  56. {
  57. __pcibios_remove_pci_devices(bus, 1);
  58. }
  59. EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices);
  60. /**
  61. * pcibios_add_pci_devices - adds new pci devices to bus
  62. * @bus: the indicated PCI bus
  63. *
  64. * This routine will find and fixup new pci devices under
  65. * the indicated bus. This routine presumes that there
  66. * might already be some devices under this bridge, so
  67. * it carefully tries to add only new devices. (And that
  68. * is how this routine differs from other, similar pcibios
  69. * routines.)
  70. */
  71. void pcibios_add_pci_devices(struct pci_bus * bus)
  72. {
  73. int slotno, num, mode, pass, max;
  74. struct pci_dev *dev;
  75. struct device_node *dn = pci_bus_to_OF_node(bus);
  76. eeh_add_device_tree_early(dn);
  77. mode = PCI_PROBE_NORMAL;
  78. if (ppc_md.pci_probe_mode)
  79. mode = ppc_md.pci_probe_mode(bus);
  80. if (mode == PCI_PROBE_DEVTREE) {
  81. /* use ofdt-based probe */
  82. of_rescan_bus(dn, bus);
  83. } else if (mode == PCI_PROBE_NORMAL) {
  84. /* use legacy probe */
  85. slotno = PCI_SLOT(PCI_DN(dn->child)->devfn);
  86. num = pci_scan_slot(bus, PCI_DEVFN(slotno, 0));
  87. if (!num)
  88. return;
  89. pcibios_setup_bus_devices(bus);
  90. max = bus->busn_res.start;
  91. for (pass = 0; pass < 2; pass++) {
  92. list_for_each_entry(dev, &bus->devices, bus_list) {
  93. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  94. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  95. max = pci_scan_bridge(bus, dev,
  96. max, pass);
  97. }
  98. }
  99. }
  100. pcibios_finish_adding_to_bus(bus);
  101. }
  102. EXPORT_SYMBOL_GPL(pcibios_add_pci_devices);