of_platform.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
  3. * <benh@kernel.crashing.org>
  4. * and Arnd Bergmann, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. */
  12. #undef DEBUG
  13. #include <linux/string.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/mod_devicetable.h>
  18. #include <linux/pci.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/of_platform.h>
  22. #include <asm/errno.h>
  23. #include <asm/topology.h>
  24. #include <asm/pci-bridge.h>
  25. #include <asm/ppc-pci.h>
  26. #include <asm/atomic.h>
  27. /*
  28. * The list of OF IDs below is used for matching bus types in the
  29. * system whose devices are to be exposed as of_platform_devices.
  30. *
  31. * This is the default list valid for most platforms. This file provides
  32. * functions who can take an explicit list if necessary though
  33. *
  34. * The search is always performed recursively looking for children of
  35. * the provided device_node and recursively if such a children matches
  36. * a bus type in the list
  37. */
  38. const struct of_device_id of_default_bus_ids[] = {
  39. { .type = "soc", },
  40. { .compatible = "soc", },
  41. { .type = "spider", },
  42. { .type = "axon", },
  43. { .type = "plb5", },
  44. { .type = "plb4", },
  45. { .type = "opb", },
  46. { .type = "ebc", },
  47. {},
  48. };
  49. static int of_dev_node_match(struct device *dev, void *data)
  50. {
  51. return to_of_device(dev)->dev.of_node == data;
  52. }
  53. struct of_device *of_find_device_by_node(struct device_node *np)
  54. {
  55. struct device *dev;
  56. dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
  57. if (dev)
  58. return to_of_device(dev);
  59. return NULL;
  60. }
  61. EXPORT_SYMBOL(of_find_device_by_node);
  62. #ifdef CONFIG_PPC_OF_PLATFORM_PCI
  63. /* The probing of PCI controllers from of_platform is currently
  64. * 64 bits only, mostly due to gratuitous differences between
  65. * the 32 and 64 bits PCI code on PowerPC and the 32 bits one
  66. * lacking some bits needed here.
  67. */
  68. static int __devinit of_pci_phb_probe(struct of_device *dev,
  69. const struct of_device_id *match)
  70. {
  71. struct pci_controller *phb;
  72. /* Check if we can do that ... */
  73. if (ppc_md.pci_setup_phb == NULL)
  74. return -ENODEV;
  75. pr_info("Setting up PCI bus %s\n", dev->dev.of_node->full_name);
  76. /* Alloc and setup PHB data structure */
  77. phb = pcibios_alloc_controller(dev->dev.of_node);
  78. if (!phb)
  79. return -ENODEV;
  80. /* Setup parent in sysfs */
  81. phb->parent = &dev->dev;
  82. /* Setup the PHB using arch provided callback */
  83. if (ppc_md.pci_setup_phb(phb)) {
  84. pcibios_free_controller(phb);
  85. return -ENODEV;
  86. }
  87. /* Process "ranges" property */
  88. pci_process_bridge_OF_ranges(phb, dev->dev.of_node, 0);
  89. /* Init pci_dn data structures */
  90. pci_devs_phb_init_dynamic(phb);
  91. /* Register devices with EEH */
  92. #ifdef CONFIG_EEH
  93. if (dev->dev.of_node->child)
  94. eeh_add_device_tree_early(dev->dev.of_node);
  95. #endif /* CONFIG_EEH */
  96. /* Scan the bus */
  97. pcibios_scan_phb(phb, dev->dev.of_node);
  98. if (phb->bus == NULL)
  99. return -ENXIO;
  100. /* Claim resources. This might need some rework as well depending
  101. * wether we are doing probe-only or not, like assigning unassigned
  102. * resources etc...
  103. */
  104. pcibios_claim_one_bus(phb->bus);
  105. /* Finish EEH setup */
  106. #ifdef CONFIG_EEH
  107. eeh_add_device_tree_late(phb->bus);
  108. #endif
  109. /* Add probed PCI devices to the device model */
  110. pci_bus_add_devices(phb->bus);
  111. return 0;
  112. }
  113. static struct of_device_id of_pci_phb_ids[] = {
  114. { .type = "pci", },
  115. { .type = "pcix", },
  116. { .type = "pcie", },
  117. { .type = "pciex", },
  118. { .type = "ht", },
  119. {}
  120. };
  121. static struct of_platform_driver of_pci_phb_driver = {
  122. .probe = of_pci_phb_probe,
  123. .driver = {
  124. .name = "of-pci",
  125. .owner = THIS_MODULE,
  126. .of_match_table = of_pci_phb_ids,
  127. },
  128. };
  129. static __init int of_pci_phb_init(void)
  130. {
  131. return of_register_platform_driver(&of_pci_phb_driver);
  132. }
  133. device_initcall(of_pci_phb_init);
  134. #endif /* CONFIG_PPC_OF_PLATFORM_PCI */