of_platform.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <linux/atomic.h>
  27. #ifdef CONFIG_PPC_OF_PLATFORM_PCI
  28. /* The probing of PCI controllers from of_platform is currently
  29. * 64 bits only, mostly due to gratuitous differences between
  30. * the 32 and 64 bits PCI code on PowerPC and the 32 bits one
  31. * lacking some bits needed here.
  32. */
  33. static int __devinit of_pci_phb_probe(struct platform_device *dev)
  34. {
  35. struct pci_controller *phb;
  36. /* Check if we can do that ... */
  37. if (ppc_md.pci_setup_phb == NULL)
  38. return -ENODEV;
  39. pr_info("Setting up PCI bus %s\n", dev->dev.of_node->full_name);
  40. /* Alloc and setup PHB data structure */
  41. phb = pcibios_alloc_controller(dev->dev.of_node);
  42. if (!phb)
  43. return -ENODEV;
  44. /* Setup parent in sysfs */
  45. phb->parent = &dev->dev;
  46. /* Setup the PHB using arch provided callback */
  47. if (ppc_md.pci_setup_phb(phb)) {
  48. pcibios_free_controller(phb);
  49. return -ENODEV;
  50. }
  51. /* Process "ranges" property */
  52. pci_process_bridge_OF_ranges(phb, dev->dev.of_node, 0);
  53. /* Init pci_dn data structures */
  54. pci_devs_phb_init_dynamic(phb);
  55. /* Register devices with EEH */
  56. #ifdef CONFIG_EEH
  57. if (dev->dev.of_node->child)
  58. eeh_add_device_tree_early(dev->dev.of_node);
  59. #endif /* CONFIG_EEH */
  60. /* Scan the bus */
  61. pcibios_scan_phb(phb);
  62. if (phb->bus == NULL)
  63. return -ENXIO;
  64. /* Claim resources. This might need some rework as well depending
  65. * wether we are doing probe-only or not, like assigning unassigned
  66. * resources etc...
  67. */
  68. pcibios_claim_one_bus(phb->bus);
  69. /* Finish EEH setup */
  70. #ifdef CONFIG_EEH
  71. eeh_add_device_tree_late(phb->bus);
  72. #endif
  73. /* Add probed PCI devices to the device model */
  74. pci_bus_add_devices(phb->bus);
  75. return 0;
  76. }
  77. static struct of_device_id of_pci_phb_ids[] = {
  78. { .type = "pci", },
  79. { .type = "pcix", },
  80. { .type = "pcie", },
  81. { .type = "pciex", },
  82. { .type = "ht", },
  83. {}
  84. };
  85. static struct platform_driver of_pci_phb_driver = {
  86. .probe = of_pci_phb_probe,
  87. .driver = {
  88. .name = "of-pci",
  89. .owner = THIS_MODULE,
  90. .of_match_table = of_pci_phb_ids,
  91. },
  92. };
  93. static __init int of_pci_phb_init(void)
  94. {
  95. return platform_driver_register(&of_pci_phb_driver);
  96. }
  97. device_initcall(of_pci_phb_init);
  98. #endif /* CONFIG_PPC_OF_PLATFORM_PCI */