icp-opal.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2016 IBM Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/irq.h>
  12. #include <linux/smp.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/cpu.h>
  15. #include <linux/of.h>
  16. #include <asm/smp.h>
  17. #include <asm/irq.h>
  18. #include <asm/errno.h>
  19. #include <asm/xics.h>
  20. #include <asm/io.h>
  21. #include <asm/opal.h>
  22. static void icp_opal_teardown_cpu(void)
  23. {
  24. int hw_cpu = hard_smp_processor_id();
  25. /* Clear any pending IPI */
  26. opal_int_set_mfrr(hw_cpu, 0xff);
  27. }
  28. static void icp_opal_flush_ipi(void)
  29. {
  30. /*
  31. * We take the ipi irq but and never return so we need to EOI the IPI,
  32. * but want to leave our priority 0.
  33. *
  34. * Should we check all the other interrupts too?
  35. * Should we be flagging idle loop instead?
  36. * Or creating some task to be scheduled?
  37. */
  38. opal_int_eoi((0x00 << 24) | XICS_IPI);
  39. }
  40. static unsigned int icp_opal_get_irq(void)
  41. {
  42. unsigned int xirr;
  43. unsigned int vec;
  44. unsigned int irq;
  45. int64_t rc;
  46. rc = opal_int_get_xirr(&xirr, false);
  47. if (rc < 0)
  48. return 0;
  49. xirr = be32_to_cpu(xirr);
  50. vec = xirr & 0x00ffffff;
  51. if (vec == XICS_IRQ_SPURIOUS)
  52. return 0;
  53. irq = irq_find_mapping(xics_host, vec);
  54. if (likely(irq)) {
  55. xics_push_cppr(vec);
  56. return irq;
  57. }
  58. /* We don't have a linux mapping, so have rtas mask it. */
  59. xics_mask_unknown_vec(vec);
  60. /* We might learn about it later, so EOI it */
  61. opal_int_eoi(xirr);
  62. return 0;
  63. }
  64. static void icp_opal_set_cpu_priority(unsigned char cppr)
  65. {
  66. xics_set_base_cppr(cppr);
  67. opal_int_set_cppr(cppr);
  68. iosync();
  69. }
  70. static void icp_opal_eoi(struct irq_data *d)
  71. {
  72. unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
  73. int64_t rc;
  74. iosync();
  75. rc = opal_int_eoi((xics_pop_cppr() << 24) | hw_irq);
  76. /*
  77. * EOI tells us whether there are more interrupts to fetch.
  78. *
  79. * Some HW implementations might not be able to send us another
  80. * external interrupt in that case, so we force a replay.
  81. */
  82. if (rc > 0)
  83. force_external_irq_replay();
  84. }
  85. #ifdef CONFIG_SMP
  86. static void icp_opal_cause_ipi(int cpu, unsigned long data)
  87. {
  88. int hw_cpu = get_hard_smp_processor_id(cpu);
  89. opal_int_set_mfrr(hw_cpu, IPI_PRIORITY);
  90. }
  91. static irqreturn_t icp_opal_ipi_action(int irq, void *dev_id)
  92. {
  93. int hw_cpu = hard_smp_processor_id();
  94. opal_int_set_mfrr(hw_cpu, 0xff);
  95. return smp_ipi_demux();
  96. }
  97. #endif /* CONFIG_SMP */
  98. static const struct icp_ops icp_opal_ops = {
  99. .get_irq = icp_opal_get_irq,
  100. .eoi = icp_opal_eoi,
  101. .set_priority = icp_opal_set_cpu_priority,
  102. .teardown_cpu = icp_opal_teardown_cpu,
  103. .flush_ipi = icp_opal_flush_ipi,
  104. #ifdef CONFIG_SMP
  105. .ipi_action = icp_opal_ipi_action,
  106. .cause_ipi = icp_opal_cause_ipi,
  107. #endif
  108. };
  109. int icp_opal_init(void)
  110. {
  111. struct device_node *np;
  112. np = of_find_compatible_node(NULL, NULL, "ibm,opal-intc");
  113. if (!np)
  114. return -ENODEV;
  115. icp_ops = &icp_opal_ops;
  116. printk("XICS: Using OPAL ICP fallbacks\n");
  117. return 0;
  118. }