of_platform.c 2.3 KB

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