smp.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 __initdata DEFINE_SPINLOCK(launch_lock);
  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. void __init plat_smp_setup(void)
  42. {
  43. int i;
  44. cpus_clear(phys_cpu_present_map);
  45. for (i = 0; i < 2; i++) {
  46. cpu_set(i, phys_cpu_present_map);
  47. __cpu_number_map[i] = i;
  48. __cpu_logical_map[i] = i;
  49. }
  50. }
  51. void __init plat_prepare_cpus(unsigned int max_cpus)
  52. {
  53. /*
  54. * Be paranoid. Enable the IPI only if we're really about to go SMP.
  55. */
  56. if (cpus_weight(cpu_possible_map))
  57. set_c0_status(STATUSF_IP5);
  58. }
  59. /*
  60. * Firmware CPU startup hook
  61. * Complicated by PMON's weird interface which tries to minimic the UNIX fork.
  62. * It launches the next * available CPU and copies some information on the
  63. * stack so the first thing we do is throw away that stuff and load useful
  64. * values into the registers ...
  65. */
  66. void prom_boot_secondary(int cpu, struct task_struct *idle)
  67. {
  68. unsigned long gp = (unsigned long) task_thread_info(idle);
  69. unsigned long sp = __KSTK_TOS(idle);
  70. secondary_sp = sp;
  71. secondary_gp = gp;
  72. spin_unlock(&launch_lock);
  73. }
  74. /* Hook for after all CPUs are online */
  75. void prom_cpus_done(void)
  76. {
  77. }
  78. /*
  79. * After we've done initial boot, this function is called to allow the
  80. * board code to clean up state, if needed
  81. */
  82. void prom_init_secondary(void)
  83. {
  84. mips_hpt_init(mips_hpt_read());
  85. set_c0_status(ST0_CO | ST0_IE | ST0_IM);
  86. }
  87. void prom_smp_finish(void)
  88. {
  89. }
  90. asmlinkage void titan_mailbox_irq(struct pt_regs *regs)
  91. {
  92. int cpu = smp_processor_id();
  93. unsigned long status;
  94. if (cpu == 0) {
  95. status = OCD_READ(RM9000x2_OCD_INTP0STATUS3);
  96. OCD_WRITE(RM9000x2_OCD_INTP0CLEAR3, status);
  97. }
  98. if (cpu == 1) {
  99. status = OCD_READ(RM9000x2_OCD_INTP1STATUS3);
  100. OCD_WRITE(RM9000x2_OCD_INTP1CLEAR3, status);
  101. }
  102. if (status & 0x2)
  103. smp_call_function_interrupt();
  104. }
  105. /*
  106. * Send inter-processor interrupt
  107. */
  108. void core_send_ipi(int cpu, unsigned int action)
  109. {
  110. /*
  111. * Generate an INTMSG so that it can be sent over to the
  112. * destination CPU. The INTMSG will put the STATUS bits
  113. * based on the action desired. An alternative strategy
  114. * is to write to the Interrupt Set register, read the
  115. * Interrupt Status register and clear the Interrupt
  116. * Clear register. The latter is preffered.
  117. */
  118. switch (action) {
  119. case SMP_RESCHEDULE_YOURSELF:
  120. if (cpu == 1)
  121. OCD_WRITE(RM9000x2_OCD_INTP1SET3, 4);
  122. else
  123. OCD_WRITE(RM9000x2_OCD_INTP0SET3, 4);
  124. break;
  125. case SMP_CALL_FUNCTION:
  126. if (cpu == 1)
  127. OCD_WRITE(RM9000x2_OCD_INTP1SET3, 2);
  128. else
  129. OCD_WRITE(RM9000x2_OCD_INTP0SET3, 2);
  130. break;
  131. }
  132. }