smp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /**
  31. * ps3_ipi_virqs - a per cpu array of virqs for ipi use
  32. */
  33. #define MSG_COUNT 4
  34. static DEFINE_PER_CPU(unsigned int [MSG_COUNT], ps3_ipi_virqs);
  35. static void do_message_pass(int target, int msg)
  36. {
  37. int result;
  38. unsigned int virq;
  39. if (msg >= MSG_COUNT) {
  40. DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
  41. return;
  42. }
  43. virq = per_cpu(ps3_ipi_virqs, target)[msg];
  44. result = ps3_send_event_locally(virq);
  45. if (result)
  46. DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
  47. " (%d)\n", __func__, __LINE__, target, msg, result);
  48. }
  49. static void ps3_smp_message_pass(int target, int msg)
  50. {
  51. int cpu;
  52. if (target < NR_CPUS)
  53. do_message_pass(target, msg);
  54. else if (target == MSG_ALL_BUT_SELF) {
  55. for_each_online_cpu(cpu)
  56. if (cpu != smp_processor_id())
  57. do_message_pass(cpu, msg);
  58. } else {
  59. for_each_online_cpu(cpu)
  60. do_message_pass(cpu, msg);
  61. }
  62. }
  63. static int ps3_smp_probe(void)
  64. {
  65. return 2;
  66. }
  67. static void __init ps3_smp_setup_cpu(int cpu)
  68. {
  69. int result;
  70. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  71. int i;
  72. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  73. /*
  74. * Check assumptions on ps3_ipi_virqs[] indexing. If this
  75. * check fails, then a different mapping of PPC_MSG_
  76. * to index needs to be setup.
  77. */
  78. BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
  79. BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
  80. BUILD_BUG_ON(PPC_MSG_CALL_FUNC_SINGLE != 2);
  81. BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
  82. for (i = 0; i < MSG_COUNT; i++) {
  83. result = ps3_event_receive_port_setup(cpu, &virqs[i]);
  84. if (result)
  85. continue;
  86. DBG("%s:%d: (%d, %d) => virq %u\n",
  87. __func__, __LINE__, cpu, i, virqs[i]);
  88. result = smp_request_message_ipi(virqs[i], i);
  89. if (result)
  90. virqs[i] = NO_IRQ;
  91. }
  92. ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
  93. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  94. }
  95. void ps3_smp_cleanup_cpu(int cpu)
  96. {
  97. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  98. int i;
  99. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  100. for (i = 0; i < MSG_COUNT; i++) {
  101. /* Can't call free_irq from interrupt context. */
  102. ps3_event_receive_port_destroy(virqs[i]);
  103. virqs[i] = NO_IRQ;
  104. }
  105. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  106. }
  107. static struct smp_ops_t ps3_smp_ops = {
  108. .probe = ps3_smp_probe,
  109. .message_pass = ps3_smp_message_pass,
  110. .kick_cpu = smp_generic_kick_cpu,
  111. .setup_cpu = ps3_smp_setup_cpu,
  112. };
  113. void smp_init_ps3(void)
  114. {
  115. DBG(" -> %s\n", __func__);
  116. smp_ops = &ps3_smp_ops;
  117. DBG(" <- %s\n", __func__);
  118. }