irq-gic-v3-its-platform-msi.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) 2013-2015 ARM Limited, All Rights Reserved.
  3. * Author: Marc Zyngier <marc.zyngier@arm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <linux/acpi_iort.h>
  18. #include <linux/device.h>
  19. #include <linux/msi.h>
  20. #include <linux/of.h>
  21. #include <linux/of_irq.h>
  22. static struct irq_chip its_pmsi_irq_chip = {
  23. .name = "ITS-pMSI",
  24. };
  25. static int of_pmsi_get_dev_id(struct irq_domain *domain, struct device *dev,
  26. u32 *dev_id)
  27. {
  28. int ret, index = 0;
  29. /* Suck the DeviceID out of the msi-parent property */
  30. do {
  31. struct of_phandle_args args;
  32. ret = of_parse_phandle_with_args(dev->of_node,
  33. "msi-parent", "#msi-cells",
  34. index, &args);
  35. if (args.np == irq_domain_get_of_node(domain)) {
  36. if (WARN_ON(args.args_count != 1))
  37. return -EINVAL;
  38. *dev_id = args.args[0];
  39. break;
  40. }
  41. index++;
  42. } while (!ret);
  43. return ret;
  44. }
  45. int __weak iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id)
  46. {
  47. return -1;
  48. }
  49. static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
  50. int nvec, msi_alloc_info_t *info)
  51. {
  52. struct msi_domain_info *msi_info;
  53. u32 dev_id;
  54. int ret;
  55. msi_info = msi_get_domain_info(domain->parent);
  56. if (dev->of_node)
  57. ret = of_pmsi_get_dev_id(domain, dev, &dev_id);
  58. else
  59. ret = iort_pmsi_get_dev_id(dev, &dev_id);
  60. if (ret)
  61. return ret;
  62. /* ITS specific DeviceID, as the core ITS ignores dev. */
  63. info->scratchpad[0].ul = dev_id;
  64. return msi_info->ops->msi_prepare(domain->parent,
  65. dev, nvec, info);
  66. }
  67. static struct msi_domain_ops its_pmsi_ops = {
  68. .msi_prepare = its_pmsi_prepare,
  69. };
  70. static struct msi_domain_info its_pmsi_domain_info = {
  71. .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
  72. .ops = &its_pmsi_ops,
  73. .chip = &its_pmsi_irq_chip,
  74. };
  75. static const struct of_device_id its_device_id[] = {
  76. { .compatible = "arm,gic-v3-its", },
  77. {},
  78. };
  79. static int __init its_pmsi_init_one(struct fwnode_handle *fwnode,
  80. const char *name)
  81. {
  82. struct irq_domain *parent;
  83. parent = irq_find_matching_fwnode(fwnode, DOMAIN_BUS_NEXUS);
  84. if (!parent || !msi_get_domain_info(parent)) {
  85. pr_err("%s: unable to locate ITS domain\n", name);
  86. return -ENXIO;
  87. }
  88. if (!platform_msi_create_irq_domain(fwnode, &its_pmsi_domain_info,
  89. parent)) {
  90. pr_err("%s: unable to create platform domain\n", name);
  91. return -ENXIO;
  92. }
  93. pr_info("Platform MSI: %s domain created\n", name);
  94. return 0;
  95. }
  96. #ifdef CONFIG_ACPI
  97. static int __init
  98. its_pmsi_parse_madt(struct acpi_subtable_header *header,
  99. const unsigned long end)
  100. {
  101. struct acpi_madt_generic_translator *its_entry;
  102. struct fwnode_handle *domain_handle;
  103. const char *node_name;
  104. int err = -ENXIO;
  105. its_entry = (struct acpi_madt_generic_translator *)header;
  106. node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
  107. (long)its_entry->base_address);
  108. domain_handle = iort_find_domain_token(its_entry->translation_id);
  109. if (!domain_handle) {
  110. pr_err("%s: Unable to locate ITS domain handle\n", node_name);
  111. goto out;
  112. }
  113. err = its_pmsi_init_one(domain_handle, node_name);
  114. out:
  115. kfree(node_name);
  116. return err;
  117. }
  118. static void __init its_pmsi_acpi_init(void)
  119. {
  120. acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
  121. its_pmsi_parse_madt, 0);
  122. }
  123. #else
  124. static inline void its_pmsi_acpi_init(void) { }
  125. #endif
  126. static void __init its_pmsi_of_init(void)
  127. {
  128. struct device_node *np;
  129. for (np = of_find_matching_node(NULL, its_device_id); np;
  130. np = of_find_matching_node(np, its_device_id)) {
  131. if (!of_device_is_available(np))
  132. continue;
  133. if (!of_property_read_bool(np, "msi-controller"))
  134. continue;
  135. its_pmsi_init_one(of_node_to_fwnode(np), np->full_name);
  136. }
  137. }
  138. static int __init its_pmsi_init(void)
  139. {
  140. its_pmsi_of_init();
  141. its_pmsi_acpi_init();
  142. return 0;
  143. }
  144. early_initcall(its_pmsi_init);