smp.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <asm/ps3.h>
  25. #include "platform.h"
  26. #if defined(DEBUG)
  27. #define DBG(fmt...) udbg_printf(fmt)
  28. #else
  29. #define DBG(fmt...) do{if(0)printk(fmt);}while(0)
  30. #endif
  31. static irqreturn_t ipi_function_handler(int irq, void *msg)
  32. {
  33. smp_message_recv((int)(long)msg);
  34. return IRQ_HANDLED;
  35. }
  36. /**
  37. * virqs - a per cpu array of virqs for ipi use
  38. */
  39. #define MSG_COUNT 4
  40. static DEFINE_PER_CPU(unsigned int, virqs[MSG_COUNT]);
  41. static const char *names[MSG_COUNT] = {
  42. "ipi call",
  43. "ipi reschedule",
  44. "ipi migrate",
  45. "ipi debug brk"
  46. };
  47. static void do_message_pass(int target, int msg)
  48. {
  49. int result;
  50. unsigned int virq;
  51. if (msg >= MSG_COUNT) {
  52. DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
  53. return;
  54. }
  55. virq = per_cpu(virqs, target)[msg];
  56. result = ps3_send_event_locally(virq);
  57. if (result)
  58. DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
  59. " (%d)\n", __func__, __LINE__, target, msg, result);
  60. }
  61. static void ps3_smp_message_pass(int target, int msg)
  62. {
  63. int cpu;
  64. if (target < NR_CPUS)
  65. do_message_pass(target, msg);
  66. else if (target == MSG_ALL_BUT_SELF) {
  67. for_each_online_cpu(cpu)
  68. if (cpu != smp_processor_id())
  69. do_message_pass(cpu, msg);
  70. } else {
  71. for_each_online_cpu(cpu)
  72. do_message_pass(cpu, msg);
  73. }
  74. }
  75. static int ps3_smp_probe(void)
  76. {
  77. return 2;
  78. }
  79. static void __init ps3_smp_setup_cpu(int cpu)
  80. {
  81. int result;
  82. unsigned int *virqs = per_cpu(virqs, cpu);
  83. int i;
  84. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  85. /*
  86. * Check assumptions on virqs[] indexing. If this
  87. * check fails, then a different mapping of PPC_MSG_
  88. * to index needs to be setup.
  89. */
  90. BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
  91. BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
  92. BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
  93. for (i = 0; i < MSG_COUNT; i++) {
  94. result = ps3_alloc_event_irq(&virqs[i]);
  95. if (result)
  96. continue;
  97. DBG("%s:%d: (%d, %d) => virq %u\n",
  98. __func__, __LINE__, cpu, i, virqs[i]);
  99. request_irq(virqs[i], ipi_function_handler, IRQF_DISABLED,
  100. names[i], (void*)(long)i);
  101. }
  102. ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
  103. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  104. }
  105. void ps3_smp_cleanup_cpu(int cpu)
  106. {
  107. unsigned int *virqs = per_cpu(virqs, cpu);
  108. int i;
  109. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  110. for (i = 0; i < MSG_COUNT; i++) {
  111. ps3_free_event_irq(virqs[i]);
  112. free_irq(virqs[i], (void*)(long)i);
  113. virqs[i] = NO_IRQ;
  114. }
  115. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  116. }
  117. static struct smp_ops_t ps3_smp_ops = {
  118. .probe = ps3_smp_probe,
  119. .message_pass = ps3_smp_message_pass,
  120. .kick_cpu = smp_generic_kick_cpu,
  121. .setup_cpu = ps3_smp_setup_cpu,
  122. };
  123. void smp_init_ps3(void)
  124. {
  125. DBG(" -> %s\n", __func__);
  126. smp_ops = &ps3_smp_ops;
  127. DBG(" <- %s\n", __func__);
  128. }