smp.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * PS3 SMP routines.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006 Sony Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/smp.h>
  22. #include <asm/machdep.h>
  23. #include <asm/udbg.h>
  24. #include "platform.h"
  25. #if defined(DEBUG)
  26. #define DBG udbg_printf
  27. #else
  28. #define DBG pr_debug
  29. #endif
  30. static irqreturn_t ipi_function_handler(int irq, void *msg)
  31. {
  32. smp_message_recv((int)(long)msg);
  33. return IRQ_HANDLED;
  34. }
  35. /**
  36. * ps3_ipi_virqs - a per cpu array of virqs for ipi use
  37. */
  38. #define MSG_COUNT 4
  39. static DEFINE_PER_CPU(unsigned int, ps3_ipi_virqs[MSG_COUNT]);
  40. static const char *names[MSG_COUNT] = {
  41. "ipi call",
  42. "ipi reschedule",
  43. "ipi migrate",
  44. "ipi debug brk"
  45. };
  46. static void do_message_pass(int target, int msg)
  47. {
  48. int result;
  49. unsigned int virq;
  50. if (msg >= MSG_COUNT) {
  51. DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
  52. return;
  53. }
  54. virq = per_cpu(ps3_ipi_virqs, target)[msg];
  55. result = ps3_send_event_locally(virq);
  56. if (result)
  57. DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
  58. " (%d)\n", __func__, __LINE__, target, msg, result);
  59. }
  60. static void ps3_smp_message_pass(int target, int msg)
  61. {
  62. int cpu;
  63. if (target < NR_CPUS)
  64. do_message_pass(target, msg);
  65. else if (target == MSG_ALL_BUT_SELF) {
  66. for_each_online_cpu(cpu)
  67. if (cpu != smp_processor_id())
  68. do_message_pass(cpu, msg);
  69. } else {
  70. for_each_online_cpu(cpu)
  71. do_message_pass(cpu, msg);
  72. }
  73. }
  74. static int ps3_smp_probe(void)
  75. {
  76. return 2;
  77. }
  78. static void __init ps3_smp_setup_cpu(int cpu)
  79. {
  80. int result;
  81. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  82. int i;
  83. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  84. /*
  85. * Check assumptions on ps3_ipi_virqs[] indexing. If this
  86. * check fails, then a different mapping of PPC_MSG_
  87. * to index needs to be setup.
  88. */
  89. BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
  90. BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
  91. BUILD_BUG_ON(PPC_MSG_CALL_FUNC_SINGLE != 2);
  92. BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
  93. for (i = 0; i < MSG_COUNT; i++) {
  94. result = ps3_event_receive_port_setup(cpu, &virqs[i]);
  95. if (result)
  96. continue;
  97. DBG("%s:%d: (%d, %d) => virq %u\n",
  98. __func__, __LINE__, cpu, i, virqs[i]);
  99. result = request_irq(virqs[i], ipi_function_handler,
  100. IRQF_DISABLED, names[i], (void*)(long)i);
  101. if (result)
  102. virqs[i] = NO_IRQ;
  103. }
  104. ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
  105. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  106. }
  107. void ps3_smp_cleanup_cpu(int cpu)
  108. {
  109. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  110. int i;
  111. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  112. for (i = 0; i < MSG_COUNT; i++) {
  113. /* Can't call free_irq from interrupt context. */
  114. ps3_event_receive_port_destroy(virqs[i]);
  115. virqs[i] = NO_IRQ;
  116. }
  117. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  118. }
  119. static struct smp_ops_t ps3_smp_ops = {
  120. .probe = ps3_smp_probe,
  121. .message_pass = ps3_smp_message_pass,
  122. .kick_cpu = smp_generic_kick_cpu,
  123. .setup_cpu = ps3_smp_setup_cpu,
  124. };
  125. void smp_init_ps3(void)
  126. {
  127. DBG(" -> %s\n", __func__);
  128. smp_ops = &ps3_smp_ops;
  129. DBG(" <- %s\n", __func__);
  130. }