of_platform.c 2.9 KB

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