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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/device.h>
  18. #include <linux/msi.h>
  19. #include <linux/of.h>
  20. #include <linux/of_irq.h>
  21. static struct irq_chip its_pmsi_irq_chip = {
  22. .name = "ITS-pMSI",
  23. };
  24. static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev,
  25. int nvec, msi_alloc_info_t *info)
  26. {
  27. struct msi_domain_info *msi_info;
  28. u32 dev_id;
  29. int ret, index = 0;
  30. msi_info = msi_get_domain_info(domain->parent);
  31. /* Suck the DeviceID out of the msi-parent property */
  32. do {
  33. struct of_phandle_args args;
  34. ret = of_parse_phandle_with_args(dev->of_node,
  35. "msi-parent", "#msi-cells",
  36. index, &args);
  37. if (args.np == irq_domain_get_of_node(domain)) {
  38. if (WARN_ON(args.args_count != 1))
  39. return -EINVAL;
  40. dev_id = args.args[0];
  41. break;
  42. }
  43. } while (!ret);
  44. if (ret)
  45. return ret;
  46. /* ITS specific DeviceID, as the core ITS ignores dev. */
  47. info->scratchpad[0].ul = dev_id;
  48. return msi_info->ops->msi_prepare(domain->parent,
  49. dev, nvec, info);
  50. }
  51. static struct msi_domain_ops its_pmsi_ops = {
  52. .msi_prepare = its_pmsi_prepare,
  53. };
  54. static struct msi_domain_info its_pmsi_domain_info = {
  55. .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
  56. .ops = &its_pmsi_ops,
  57. .chip = &its_pmsi_irq_chip,
  58. };
  59. static struct of_device_id its_device_id[] = {
  60. { .compatible = "arm,gic-v3-its", },
  61. {},
  62. };
  63. static int __init its_pmsi_init(void)
  64. {
  65. struct device_node *np;
  66. struct irq_domain *parent;
  67. for (np = of_find_matching_node(NULL, its_device_id); np;
  68. np = of_find_matching_node(np, its_device_id)) {
  69. if (!of_property_read_bool(np, "msi-controller"))
  70. continue;
  71. parent = irq_find_matching_host(np, DOMAIN_BUS_NEXUS);
  72. if (!parent || !msi_get_domain_info(parent)) {
  73. pr_err("%s: unable to locate ITS domain\n",
  74. np->full_name);
  75. continue;
  76. }
  77. if (!platform_msi_create_irq_domain(of_node_to_fwnode(np),
  78. &its_pmsi_domain_info,
  79. parent)) {
  80. pr_err("%s: unable to create platform domain\n",
  81. np->full_name);
  82. continue;
  83. }
  84. pr_info("Platform MSI: %s domain created\n", np->full_name);
  85. }
  86. return 0;
  87. }
  88. early_initcall(its_pmsi_init);