smp.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * PS3 SMP routines.
  4. *
  5. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  6. * Copyright 2006 Sony Corp.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/smp.h>
  10. #include <asm/machdep.h>
  11. #include <asm/udbg.h>
  12. #include "platform.h"
  13. #if defined(DEBUG)
  14. #define DBG udbg_printf
  15. #else
  16. #define DBG pr_debug
  17. #endif
  18. /**
  19. * ps3_ipi_virqs - a per cpu array of virqs for ipi use
  20. */
  21. #define MSG_COUNT 4
  22. static DEFINE_PER_CPU(unsigned int [MSG_COUNT], ps3_ipi_virqs);
  23. static void ps3_smp_message_pass(int cpu, int msg)
  24. {
  25. int result;
  26. unsigned int virq;
  27. if (msg >= MSG_COUNT) {
  28. DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
  29. return;
  30. }
  31. virq = per_cpu(ps3_ipi_virqs, cpu)[msg];
  32. result = ps3_send_event_locally(virq);
  33. if (result)
  34. DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
  35. " (%d)\n", __func__, __LINE__, cpu, msg, result);
  36. }
  37. static void __init ps3_smp_probe(void)
  38. {
  39. int cpu;
  40. for (cpu = 0; cpu < 2; cpu++) {
  41. int result;
  42. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  43. int i;
  44. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  45. /*
  46. * Check assumptions on ps3_ipi_virqs[] indexing. If this
  47. * check fails, then a different mapping of PPC_MSG_
  48. * to index needs to be setup.
  49. */
  50. BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
  51. BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
  52. BUILD_BUG_ON(PPC_MSG_TICK_BROADCAST != 2);
  53. BUILD_BUG_ON(PPC_MSG_NMI_IPI != 3);
  54. for (i = 0; i < MSG_COUNT; i++) {
  55. result = ps3_event_receive_port_setup(cpu, &virqs[i]);
  56. if (result)
  57. continue;
  58. DBG("%s:%d: (%d, %d) => virq %u\n",
  59. __func__, __LINE__, cpu, i, virqs[i]);
  60. result = smp_request_message_ipi(virqs[i], i);
  61. if (result)
  62. virqs[i] = 0;
  63. else
  64. ps3_register_ipi_irq(cpu, virqs[i]);
  65. }
  66. ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_NMI_IPI]);
  67. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  68. }
  69. }
  70. void ps3_smp_cleanup_cpu(int cpu)
  71. {
  72. unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
  73. int i;
  74. DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
  75. for (i = 0; i < MSG_COUNT; i++) {
  76. /* Can't call free_irq from interrupt context. */
  77. ps3_event_receive_port_destroy(virqs[i]);
  78. virqs[i] = 0;
  79. }
  80. DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
  81. }
  82. static struct smp_ops_t ps3_smp_ops = {
  83. .probe = ps3_smp_probe,
  84. .message_pass = ps3_smp_message_pass,
  85. .kick_cpu = smp_generic_kick_cpu,
  86. };
  87. void __init smp_init_ps3(void)
  88. {
  89. DBG(" -> %s\n", __func__);
  90. smp_ops = &ps3_smp_ops;
  91. DBG(" <- %s\n", __func__);
  92. }