smp.c 3.8 KB

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