pci-hotplug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_release_device - release PCI device
  24. * @dev: PCI device
  25. *
  26. * The function is called before releasing the indicated PCI device.
  27. */
  28. void pcibios_release_device(struct pci_dev *dev)
  29. {
  30. eeh_remove_device(dev);
  31. }
  32. /**
  33. * pcibios_remove_pci_devices - remove all devices under this bus
  34. * @bus: the indicated PCI bus
  35. *
  36. * Remove all of the PCI devices under this bus both from the
  37. * linux pci device tree, and from the powerpc EEH address cache.
  38. */
  39. void pcibios_remove_pci_devices(struct pci_bus *bus)
  40. {
  41. struct pci_dev *dev, *tmp;
  42. struct pci_bus *child_bus;
  43. /* First go down child busses */
  44. list_for_each_entry(child_bus, &bus->children, node)
  45. pcibios_remove_pci_devices(child_bus);
  46. pr_debug("PCI: Removing devices on bus %04x:%02x\n",
  47. pci_domain_nr(bus), bus->number);
  48. list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
  49. pr_debug(" Removing %s...\n", pci_name(dev));
  50. pci_stop_and_remove_bus_device(dev);
  51. }
  52. }
  53. EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices);
  54. /**
  55. * pcibios_add_pci_devices - adds new pci devices to bus
  56. * @bus: the indicated PCI bus
  57. *
  58. * This routine will find and fixup new pci devices under
  59. * the indicated bus. This routine presumes that there
  60. * might already be some devices under this bridge, so
  61. * it carefully tries to add only new devices. (And that
  62. * is how this routine differs from other, similar pcibios
  63. * routines.)
  64. */
  65. void pcibios_add_pci_devices(struct pci_bus * bus)
  66. {
  67. int slotno, mode, pass, max;
  68. struct pci_dev *dev;
  69. struct device_node *dn = pci_bus_to_OF_node(bus);
  70. eeh_add_device_tree_early(dn);
  71. mode = PCI_PROBE_NORMAL;
  72. if (ppc_md.pci_probe_mode)
  73. mode = ppc_md.pci_probe_mode(bus);
  74. if (mode == PCI_PROBE_DEVTREE) {
  75. /* use ofdt-based probe */
  76. of_rescan_bus(dn, bus);
  77. } else if (mode == PCI_PROBE_NORMAL) {
  78. /*
  79. * Use legacy probe. In the partial hotplug case, we
  80. * probably have grandchildren devices unplugged. So
  81. * we don't check the return value from pci_scan_slot() in
  82. * order for fully rescan all the way down to pick them up.
  83. * They can have been removed during partial hotplug.
  84. */
  85. slotno = PCI_SLOT(PCI_DN(dn->child)->devfn);
  86. pci_scan_slot(bus, PCI_DEVFN(slotno, 0));
  87. pcibios_setup_bus_devices(bus);
  88. max = bus->busn_res.start;
  89. for (pass = 0; pass < 2; pass++) {
  90. list_for_each_entry(dev, &bus->devices, bus_list) {
  91. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  92. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  93. max = pci_scan_bridge(bus, dev,
  94. max, pass);
  95. }
  96. }
  97. }
  98. pcibios_finish_adding_to_bus(bus);
  99. }
  100. EXPORT_SYMBOL_GPL(pcibios_add_pci_devices);