smp.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 ps3_smp_message_pass(int cpu, 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, cpu)[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__, cpu, msg, result);
  48. }
  49. static void __init ps3_smp_probe(void)
  50. {
  51. int cpu;
  52. for (cpu = 0; cpu < 2; cpu++) {
  53. int result;
  54. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  55. int i;
  56. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  57. /*
  58. * Check assumptions on ps3_ipi_virqs[] indexing. If this
  59. * check fails, then a different mapping of PPC_MSG_
  60. * to index needs to be setup.
  61. */
  62. BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
  63. BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
  64. BUILD_BUG_ON(PPC_MSG_TICK_BROADCAST != 2);
  65. BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
  66. for (i = 0; i < MSG_COUNT; i++) {
  67. result = ps3_event_receive_port_setup(cpu, &virqs[i]);
  68. if (result)
  69. continue;
  70. DBG("%s:%d: (%d, %d) => virq %u\n",
  71. __func__, __LINE__, cpu, i, virqs[i]);
  72. result = smp_request_message_ipi(virqs[i], i);
  73. if (result)
  74. virqs[i] = 0;
  75. else
  76. ps3_register_ipi_irq(cpu, virqs[i]);
  77. }
  78. ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
  79. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  80. }
  81. }
  82. void ps3_smp_cleanup_cpu(int cpu)
  83. {
  84. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  85. int i;
  86. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  87. for (i = 0; i < MSG_COUNT; i++) {
  88. /* Can't call free_irq from interrupt context. */
  89. ps3_event_receive_port_destroy(virqs[i]);
  90. virqs[i] = 0;
  91. }
  92. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  93. }
  94. static struct smp_ops_t ps3_smp_ops = {
  95. .probe = ps3_smp_probe,
  96. .message_pass = ps3_smp_message_pass,
  97. .kick_cpu = smp_generic_kick_cpu,
  98. };
  99. void smp_init_ps3(void)
  100. {
  101. DBG(" -> %s\n", __func__);
  102. smp_ops = &ps3_smp_ops;
  103. DBG(" <- %s\n", __func__);
  104. }