of_platform.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
  4. * <benh@kernel.crashing.org>
  5. * and Arnd Bergmann, IBM Corp.
  6. */
  7. #undef DEBUG
  8. #include <linux/string.h>
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/export.h>
  12. #include <linux/mod_devicetable.h>
  13. #include <linux/pci.h>
  14. #include <linux/of.h>
  15. #include <linux/of_device.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/atomic.h>
  18. #include <asm/errno.h>
  19. #include <asm/topology.h>
  20. #include <asm/pci-bridge.h>
  21. #include <asm/ppc-pci.h>
  22. #include <asm/eeh.h>
  23. #ifdef CONFIG_PPC_OF_PLATFORM_PCI
  24. /* The probing of PCI controllers from of_platform is currently
  25. * 64 bits only, mostly due to gratuitous differences between
  26. * the 32 and 64 bits PCI code on PowerPC and the 32 bits one
  27. * lacking some bits needed here.
  28. */
  29. static int of_pci_phb_probe(struct platform_device *dev)
  30. {
  31. struct pci_controller *phb;
  32. /* Check if we can do that ... */
  33. if (ppc_md.pci_setup_phb == NULL)
  34. return -ENODEV;
  35. pr_info("Setting up PCI bus %pOF\n", dev->dev.of_node);
  36. /* Alloc and setup PHB data structure */
  37. phb = pcibios_alloc_controller(dev->dev.of_node);
  38. if (!phb)
  39. return -ENODEV;
  40. /* Setup parent in sysfs */
  41. phb->parent = &dev->dev;
  42. /* Setup the PHB using arch provided callback */
  43. if (ppc_md.pci_setup_phb(phb)) {
  44. pcibios_free_controller(phb);
  45. return -ENODEV;
  46. }
  47. /* Process "ranges" property */
  48. pci_process_bridge_OF_ranges(phb, dev->dev.of_node, 0);
  49. /* Init pci_dn data structures */
  50. pci_devs_phb_init_dynamic(phb);
  51. /* Create EEH PE for the PHB */
  52. eeh_phb_pe_create(phb);
  53. /* Scan the bus */
  54. pcibios_scan_phb(phb);
  55. if (phb->bus == NULL)
  56. return -ENXIO;
  57. /* Claim resources. This might need some rework as well depending
  58. * whether we are doing probe-only or not, like assigning unassigned
  59. * resources etc...
  60. */
  61. pcibios_claim_one_bus(phb->bus);
  62. /* Add probed PCI devices to the device model */
  63. pci_bus_add_devices(phb->bus);
  64. return 0;
  65. }
  66. static const struct of_device_id of_pci_phb_ids[] = {
  67. { .type = "pci", },
  68. { .type = "pcix", },
  69. { .type = "pcie", },
  70. { .type = "pciex", },
  71. { .type = "ht", },
  72. {}
  73. };
  74. static struct platform_driver of_pci_phb_driver = {
  75. .probe = of_pci_phb_probe,
  76. .driver = {
  77. .name = "of-pci",
  78. .of_match_table = of_pci_phb_ids,
  79. },
  80. };
  81. builtin_platform_driver(of_pci_phb_driver);
  82. #endif /* CONFIG_PPC_OF_PLATFORM_PCI */