eeh_dev.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * The file intends to implement dynamic creation of EEH device, which will
  3. * be bound with OF node and PCI device simutaneously. The EEH devices would
  4. * be foundamental information for EEH core components to work proerly. Besides,
  5. * We have to support multiple situations where dynamic creation of EEH device
  6. * is required:
  7. *
  8. * 1) Before PCI emunation starts, we need create EEH devices according to the
  9. * PCI sensitive OF nodes.
  10. * 2) When PCI emunation is done, we need do the binding between PCI device and
  11. * the associated EEH device.
  12. * 3) DR (Dynamic Reconfiguration) would create PCI sensitive OF node. EEH device
  13. * will be created while PCI sensitive OF node is detected from DR.
  14. * 4) PCI hotplug needs redoing the binding between PCI device and EEH device. If
  15. * PHB is newly inserted, we also need create EEH devices accordingly.
  16. *
  17. * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2012.
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  32. */
  33. #include <linux/export.h>
  34. #include <linux/gfp.h>
  35. #include <linux/init.h>
  36. #include <linux/kernel.h>
  37. #include <linux/pci.h>
  38. #include <linux/string.h>
  39. #include <asm/pci-bridge.h>
  40. #include <asm/ppc-pci.h>
  41. /**
  42. * eeh_dev_init - Create EEH device according to OF node
  43. * @pdn: PCI device node
  44. * @data: PHB
  45. *
  46. * It will create EEH device according to the given OF node. The function
  47. * might be called by PCI emunation, DR, PHB hotplug.
  48. */
  49. void *eeh_dev_init(struct pci_dn *pdn, void *data)
  50. {
  51. struct pci_controller *phb = data;
  52. struct eeh_dev *edev;
  53. /* Allocate EEH device */
  54. edev = kzalloc(sizeof(*edev), GFP_KERNEL);
  55. if (!edev) {
  56. pr_warn("%s: out of memory\n",
  57. __func__);
  58. return NULL;
  59. }
  60. /* Associate EEH device with OF node */
  61. pdn->edev = edev;
  62. edev->pdn = pdn;
  63. edev->phb = phb;
  64. INIT_LIST_HEAD(&edev->list);
  65. return NULL;
  66. }
  67. /**
  68. * eeh_dev_phb_init_dynamic - Create EEH devices for devices included in PHB
  69. * @phb: PHB
  70. *
  71. * Scan the PHB OF node and its child association, then create the
  72. * EEH devices accordingly
  73. */
  74. void eeh_dev_phb_init_dynamic(struct pci_controller *phb)
  75. {
  76. struct pci_dn *root = phb->pci_data;
  77. /* EEH PE for PHB */
  78. eeh_phb_pe_create(phb);
  79. /* EEH device for PHB */
  80. eeh_dev_init(root, phb);
  81. /* EEH devices for children OF nodes */
  82. traverse_pci_dn(root, eeh_dev_init, phb);
  83. }
  84. /**
  85. * eeh_dev_phb_init - Create EEH devices for devices included in existing PHBs
  86. *
  87. * Scan all the existing PHBs and create EEH devices for their OF
  88. * nodes and their children OF nodes
  89. */
  90. static int __init eeh_dev_phb_init(void)
  91. {
  92. struct pci_controller *phb, *tmp;
  93. list_for_each_entry_safe(phb, tmp, &hose_list, list_node)
  94. eeh_dev_phb_init_dynamic(phb);
  95. pr_info("EEH: devices created\n");
  96. return 0;
  97. }
  98. core_initcall(eeh_dev_phb_init);