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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. } while (!ret);
  42. return ret;
  43. }
  44. int __weak iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id)
  45. {
  46. return -1;
  47. }
  48. static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
  49. int nvec, msi_alloc_info_t *info)
  50. {
  51. struct msi_domain_info *msi_info;
  52. u32 dev_id;
  53. int ret;
  54. msi_info = msi_get_domain_info(domain->parent);
  55. if (dev->of_node)
  56. ret = of_pmsi_get_dev_id(domain, dev, &dev_id);
  57. else
  58. ret = iort_pmsi_get_dev_id(dev, &dev_id);
  59. if (ret)
  60. return ret;
  61. /* ITS specific DeviceID, as the core ITS ignores dev. */
  62. info->scratchpad[0].ul = dev_id;
  63. return msi_info->ops->msi_prepare(domain->parent,
  64. dev, nvec, info);
  65. }
  66. static struct msi_domain_ops its_pmsi_ops = {
  67. .msi_prepare = its_pmsi_prepare,
  68. };
  69. static struct msi_domain_info its_pmsi_domain_info = {
  70. .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
  71. .ops = &its_pmsi_ops,
  72. .chip = &its_pmsi_irq_chip,
  73. };
  74. static struct of_device_id its_device_id[] = {
  75. { .compatible = "arm,gic-v3-its", },
  76. {},
  77. };
  78. static int __init its_pmsi_init_one(struct fwnode_handle *fwnode,
  79. const char *name)
  80. {
  81. struct irq_domain *parent;
  82. parent = irq_find_matching_fwnode(fwnode, DOMAIN_BUS_NEXUS);
  83. if (!parent || !msi_get_domain_info(parent)) {
  84. pr_err("%s: unable to locate ITS domain\n", name);
  85. return -ENXIO;
  86. }
  87. if (!platform_msi_create_irq_domain(fwnode, &its_pmsi_domain_info,
  88. parent)) {
  89. pr_err("%s: unable to create platform domain\n", name);
  90. return -ENXIO;
  91. }
  92. pr_info("Platform MSI: %s domain created\n", name);
  93. return 0;
  94. }
  95. #ifdef CONFIG_ACPI
  96. static int __init
  97. its_pmsi_parse_madt(struct acpi_subtable_header *header,
  98. const unsigned long end)
  99. {
  100. struct acpi_madt_generic_translator *its_entry;
  101. struct fwnode_handle *domain_handle;
  102. const char *node_name;
  103. int err = -ENXIO;
  104. its_entry = (struct acpi_madt_generic_translator *)header;
  105. node_name = kasprintf(GFP_KERNEL, "ITS@0x%lx",
  106. (long)its_entry->base_address);
  107. domain_handle = iort_find_domain_token(its_entry->translation_id);
  108. if (!domain_handle) {
  109. pr_err("%s: Unable to locate ITS domain handle\n", node_name);
  110. goto out;
  111. }
  112. err = its_pmsi_init_one(domain_handle, node_name);
  113. out:
  114. kfree(node_name);
  115. return err;
  116. }
  117. static void __init its_pmsi_acpi_init(void)
  118. {
  119. acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
  120. its_pmsi_parse_madt, 0);
  121. }
  122. #else
  123. static inline void its_pmsi_acpi_init(void) { }
  124. #endif
  125. static void __init its_pmsi_of_init(void)
  126. {
  127. struct device_node *np;
  128. for (np = of_find_matching_node(NULL, its_device_id); np;
  129. np = of_find_matching_node(np, its_device_id)) {
  130. if (!of_property_read_bool(np, "msi-controller"))
  131. continue;
  132. its_pmsi_init_one(of_node_to_fwnode(np), np->full_name);
  133. }
  134. }
  135. static int __init its_pmsi_init(void)
  136. {
  137. its_pmsi_of_init();
  138. its_pmsi_acpi_init();
  139. return 0;
  140. }
  141. early_initcall(its_pmsi_init);