smp.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include <linux/linkage.h>
  2. #include <linux/sched.h>
  3. #include <asm/pmon.h>
  4. #include <asm/titan_dep.h>
  5. #include <asm/time.h>
  6. #define LAUNCHSTACK_SIZE 256
  7. static __initdata DEFINE_SPINLOCK(launch_lock);
  8. static unsigned long secondary_sp __initdata;
  9. static unsigned long secondary_gp __initdata;
  10. static unsigned char launchstack[LAUNCHSTACK_SIZE] __initdata
  11. __attribute__((aligned(2 * sizeof(long))));
  12. static void __init prom_smp_bootstrap(void)
  13. {
  14. local_irq_disable();
  15. while (spin_is_locked(&launch_lock));
  16. __asm__ __volatile__(
  17. " move $sp, %0 \n"
  18. " move $gp, %1 \n"
  19. " j smp_bootstrap \n"
  20. :
  21. : "r" (secondary_sp), "r" (secondary_gp));
  22. }
  23. /*
  24. * PMON is a fragile beast. It'll blow up once the mappings it's littering
  25. * right into the middle of KSEG3 are blown away so we have to grab the slave
  26. * core early and keep it in a waiting loop.
  27. */
  28. void __init prom_grab_secondary(void)
  29. {
  30. spin_lock(&launch_lock);
  31. pmon_cpustart(1, &prom_smp_bootstrap,
  32. launchstack + LAUNCHSTACK_SIZE, 0);
  33. }
  34. /*
  35. * Detect available CPUs, populate phys_cpu_present_map before smp_init
  36. *
  37. * We don't want to start the secondary CPU yet nor do we have a nice probing
  38. * feature in PMON so we just assume presence of the secondary core.
  39. */
  40. void __init plat_smp_setup(void)
  41. {
  42. int i;
  43. cpus_clear(phys_cpu_present_map);
  44. for (i = 0; i < 2; i++) {
  45. cpu_set(i, phys_cpu_present_map);
  46. __cpu_number_map[i] = i;
  47. __cpu_logical_map[i] = i;
  48. }
  49. }
  50. void __init plat_prepare_cpus(unsigned int max_cpus)
  51. {
  52. /*
  53. * Be paranoid. Enable the IPI only if we're really about to go SMP.
  54. */
  55. if (cpus_weight(cpu_possible_map))
  56. set_c0_status(STATUSF_IP5);
  57. }
  58. /*
  59. * Firmware CPU startup hook
  60. * Complicated by PMON's weird interface which tries to minimic the UNIX fork.
  61. * It launches the next * available CPU and copies some information on the
  62. * stack so the first thing we do is throw away that stuff and load useful
  63. * values into the registers ...
  64. */
  65. void prom_boot_secondary(int cpu, struct task_struct *idle)
  66. {
  67. unsigned long gp = (unsigned long) task_thread_info(idle);
  68. unsigned long sp = __KSTK_TOS(idle);
  69. secondary_sp = sp;
  70. secondary_gp = gp;
  71. spin_unlock(&launch_lock);
  72. }
  73. /* Hook for after all CPUs are online */
  74. void prom_cpus_done(void)
  75. {
  76. }
  77. /*
  78. * After we've done initial boot, this function is called to allow the
  79. * board code to clean up state, if needed
  80. */
  81. void prom_init_secondary(void)
  82. {
  83. set_c0_status(ST0_CO | ST0_IE | ST0_IM);
  84. }
  85. void prom_smp_finish(void)
  86. {
  87. }
  88. asmlinkage void titan_mailbox_irq(void)
  89. {
  90. int cpu = smp_processor_id();
  91. unsigned long status;
  92. if (cpu == 0) {
  93. status = OCD_READ(RM9000x2_OCD_INTP0STATUS3);
  94. OCD_WRITE(RM9000x2_OCD_INTP0CLEAR3, status);
  95. }
  96. if (cpu == 1) {
  97. status = OCD_READ(RM9000x2_OCD_INTP1STATUS3);
  98. OCD_WRITE(RM9000x2_OCD_INTP1CLEAR3, status);
  99. }
  100. if (status & 0x2)
  101. smp_call_function_interrupt();
  102. }
  103. /*
  104. * Send inter-processor interrupt
  105. */
  106. void core_send_ipi(int cpu, unsigned int action)
  107. {
  108. /*
  109. * Generate an INTMSG so that it can be sent over to the
  110. * destination CPU. The INTMSG will put the STATUS bits
  111. * based on the action desired. An alternative strategy
  112. * is to write to the Interrupt Set register, read the
  113. * Interrupt Status register and clear the Interrupt
  114. * Clear register. The latter is preffered.
  115. */
  116. switch (action) {
  117. case SMP_RESCHEDULE_YOURSELF:
  118. if (cpu == 1)
  119. OCD_WRITE(RM9000x2_OCD_INTP1SET3, 4);
  120. else
  121. OCD_WRITE(RM9000x2_OCD_INTP0SET3, 4);
  122. break;
  123. case SMP_CALL_FUNCTION:
  124. if (cpu == 1)
  125. OCD_WRITE(RM9000x2_OCD_INTP1SET3, 2);
  126. else
  127. OCD_WRITE(RM9000x2_OCD_INTP0SET3, 2);
  128. break;
  129. }
  130. }