of.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * PCI <-> OF mapping helpers
  3. *
  4. * Copyright 2011 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. #include <linux/irqdomain.h>
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/of.h>
  15. #include <linux/of_irq.h>
  16. #include <linux/of_pci.h>
  17. #include "pci.h"
  18. void pci_set_of_node(struct pci_dev *dev)
  19. {
  20. if (!dev->bus->dev.of_node)
  21. return;
  22. dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
  23. dev->devfn);
  24. }
  25. void pci_release_of_node(struct pci_dev *dev)
  26. {
  27. of_node_put(dev->dev.of_node);
  28. dev->dev.of_node = NULL;
  29. }
  30. void pci_set_bus_of_node(struct pci_bus *bus)
  31. {
  32. if (bus->self == NULL)
  33. bus->dev.of_node = pcibios_get_phb_of_node(bus);
  34. else
  35. bus->dev.of_node = of_node_get(bus->self->dev.of_node);
  36. }
  37. void pci_release_bus_of_node(struct pci_bus *bus)
  38. {
  39. of_node_put(bus->dev.of_node);
  40. bus->dev.of_node = NULL;
  41. }
  42. struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
  43. {
  44. /* This should only be called for PHBs */
  45. if (WARN_ON(bus->self || bus->parent))
  46. return NULL;
  47. /* Look for a node pointer in either the intermediary device we
  48. * create above the root bus or it's own parent. Normally only
  49. * the later is populated.
  50. */
  51. if (bus->bridge->of_node)
  52. return of_node_get(bus->bridge->of_node);
  53. if (bus->bridge->parent && bus->bridge->parent->of_node)
  54. return of_node_get(bus->bridge->parent->of_node);
  55. return NULL;
  56. }
  57. struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus)
  58. {
  59. #ifdef CONFIG_IRQ_DOMAIN
  60. struct irq_domain *d;
  61. if (!bus->dev.of_node)
  62. return NULL;
  63. /* Start looking for a phandle to an MSI controller. */
  64. d = of_msi_get_domain(&bus->dev, bus->dev.of_node, DOMAIN_BUS_PCI_MSI);
  65. if (d)
  66. return d;
  67. /*
  68. * If we don't have an msi-parent property, look for a domain
  69. * directly attached to the host bridge.
  70. */
  71. d = irq_find_matching_host(bus->dev.of_node, DOMAIN_BUS_PCI_MSI);
  72. if (d)
  73. return d;
  74. return irq_find_host(bus->dev.of_node);
  75. #else
  76. return NULL;
  77. #endif
  78. }