smp.c 3.1 KB

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