icp-hv.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright 2011 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. */
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/irq.h>
  13. #include <linux/smp.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/init.h>
  16. #include <linux/cpu.h>
  17. #include <linux/of.h>
  18. #include <asm/smp.h>
  19. #include <asm/irq.h>
  20. #include <asm/errno.h>
  21. #include <asm/xics.h>
  22. #include <asm/io.h>
  23. #include <asm/hvcall.h>
  24. static inline unsigned int icp_hv_get_xirr(unsigned char cppr)
  25. {
  26. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  27. long rc;
  28. rc = plpar_hcall(H_XIRR, retbuf, cppr);
  29. if (rc != H_SUCCESS)
  30. panic(" bad return code xirr - rc = %lx\n", rc);
  31. return (unsigned int)retbuf[0];
  32. }
  33. static inline void icp_hv_set_xirr(unsigned int value)
  34. {
  35. long rc = plpar_hcall_norets(H_EOI, value);
  36. if (rc != H_SUCCESS)
  37. panic("bad return code EOI - rc = %ld, value=%x\n", rc, value);
  38. }
  39. static inline void icp_hv_set_cppr(u8 value)
  40. {
  41. long rc = plpar_hcall_norets(H_CPPR, value);
  42. if (rc != H_SUCCESS)
  43. panic("bad return code cppr - rc = %lx\n", rc);
  44. }
  45. static inline void icp_hv_set_qirr(int n_cpu , u8 value)
  46. {
  47. long rc = plpar_hcall_norets(H_IPI, get_hard_smp_processor_id(n_cpu),
  48. value);
  49. if (rc != H_SUCCESS)
  50. panic("bad return code qirr - rc = %lx\n", rc);
  51. }
  52. static void icp_hv_eoi(struct irq_data *d)
  53. {
  54. unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
  55. iosync();
  56. icp_hv_set_xirr((xics_pop_cppr() << 24) | hw_irq);
  57. }
  58. static void icp_hv_teardown_cpu(void)
  59. {
  60. int cpu = smp_processor_id();
  61. /* Clear any pending IPI */
  62. icp_hv_set_qirr(cpu, 0xff);
  63. }
  64. static void icp_hv_flush_ipi(void)
  65. {
  66. /* We take the ipi irq but and never return so we
  67. * need to EOI the IPI, but want to leave our priority 0
  68. *
  69. * should we check all the other interrupts too?
  70. * should we be flagging idle loop instead?
  71. * or creating some task to be scheduled?
  72. */
  73. icp_hv_set_xirr((0x00 << 24) | XICS_IPI);
  74. }
  75. static unsigned int icp_hv_get_irq(void)
  76. {
  77. unsigned int xirr = icp_hv_get_xirr(xics_cppr_top());
  78. unsigned int vec = xirr & 0x00ffffff;
  79. unsigned int irq;
  80. if (vec == XICS_IRQ_SPURIOUS)
  81. return NO_IRQ;
  82. irq = irq_radix_revmap_lookup(xics_host, vec);
  83. if (likely(irq != NO_IRQ)) {
  84. xics_push_cppr(vec);
  85. return irq;
  86. }
  87. /* We don't have a linux mapping, so have rtas mask it. */
  88. xics_mask_unknown_vec(vec);
  89. /* We might learn about it later, so EOI it */
  90. icp_hv_set_xirr(xirr);
  91. return NO_IRQ;
  92. }
  93. static void icp_hv_set_cpu_priority(unsigned char cppr)
  94. {
  95. xics_set_base_cppr(cppr);
  96. icp_hv_set_cppr(cppr);
  97. iosync();
  98. }
  99. #ifdef CONFIG_SMP
  100. static inline void icp_hv_do_message(int cpu, int msg)
  101. {
  102. unsigned long *tgt = &per_cpu(xics_ipi_message, cpu);
  103. set_bit(msg, tgt);
  104. mb();
  105. icp_hv_set_qirr(cpu, IPI_PRIORITY);
  106. }
  107. static void icp_hv_message_pass(int target, int msg)
  108. {
  109. unsigned int i;
  110. if (target < NR_CPUS) {
  111. icp_hv_do_message(target, msg);
  112. } else {
  113. for_each_online_cpu(i) {
  114. if (target == MSG_ALL_BUT_SELF
  115. && i == smp_processor_id())
  116. continue;
  117. icp_hv_do_message(i, msg);
  118. }
  119. }
  120. }
  121. static irqreturn_t icp_hv_ipi_action(int irq, void *dev_id)
  122. {
  123. int cpu = smp_processor_id();
  124. icp_hv_set_qirr(cpu, 0xff);
  125. return xics_ipi_dispatch(cpu);
  126. }
  127. #endif /* CONFIG_SMP */
  128. static const struct icp_ops icp_hv_ops = {
  129. .get_irq = icp_hv_get_irq,
  130. .eoi = icp_hv_eoi,
  131. .set_priority = icp_hv_set_cpu_priority,
  132. .teardown_cpu = icp_hv_teardown_cpu,
  133. .flush_ipi = icp_hv_flush_ipi,
  134. #ifdef CONFIG_SMP
  135. .ipi_action = icp_hv_ipi_action,
  136. .message_pass = icp_hv_message_pass,
  137. #endif
  138. };
  139. int icp_hv_init(void)
  140. {
  141. struct device_node *np;
  142. np = of_find_compatible_node(NULL, NULL, "ibm,ppc-xicp");
  143. if (!np)
  144. np = of_find_node_by_type(NULL,
  145. "PowerPC-External-Interrupt-Presentation");
  146. if (!np)
  147. return -ENODEV;
  148. icp_ops = &icp_hv_ops;
  149. return 0;
  150. }