sun4m_smp.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * sun4m SMP support.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <linux/clockchips.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/profile.h>
  9. #include <linux/delay.h>
  10. #include <linux/sched.h>
  11. #include <linux/cpu.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/switch_to.h>
  14. #include <asm/tlbflush.h>
  15. #include <asm/timer.h>
  16. #include <asm/oplib.h>
  17. #include "irq.h"
  18. #include "kernel.h"
  19. #define IRQ_IPI_SINGLE 12
  20. #define IRQ_IPI_MASK 13
  21. #define IRQ_IPI_RESCHED 14
  22. #define IRQ_CROSS_CALL 15
  23. static inline unsigned long
  24. swap_ulong(volatile unsigned long *ptr, unsigned long val)
  25. {
  26. __asm__ __volatile__("swap [%1], %0\n\t" :
  27. "=&r" (val), "=&r" (ptr) :
  28. "0" (val), "1" (ptr));
  29. return val;
  30. }
  31. void sun4m_cpu_pre_starting(void *arg)
  32. {
  33. }
  34. void sun4m_cpu_pre_online(void *arg)
  35. {
  36. int cpuid = hard_smp_processor_id();
  37. /* Allow master to continue. The master will then give us the
  38. * go-ahead by setting the smp_commenced_mask and will wait without
  39. * timeouts until our setup is completed fully (signified by
  40. * our bit being set in the cpu_online_mask).
  41. */
  42. swap_ulong(&cpu_callin_map[cpuid], 1);
  43. /* XXX: What's up with all the flushes? */
  44. local_ops->cache_all();
  45. local_ops->tlb_all();
  46. /* Fix idle thread fields. */
  47. __asm__ __volatile__("ld [%0], %%g6\n\t"
  48. : : "r" (&current_set[cpuid])
  49. : "memory" /* paranoid */);
  50. /* Attach to the address space of init_task. */
  51. atomic_inc(&init_mm.mm_count);
  52. current->active_mm = &init_mm;
  53. while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
  54. mb();
  55. }
  56. /*
  57. * Cycle through the processors asking the PROM to start each one.
  58. */
  59. void __init smp4m_boot_cpus(void)
  60. {
  61. sun4m_unmask_profile_irq();
  62. local_ops->cache_all();
  63. }
  64. int smp4m_boot_one_cpu(int i, struct task_struct *idle)
  65. {
  66. unsigned long *entry = &sun4m_cpu_startup;
  67. int timeout;
  68. int cpu_node;
  69. cpu_find_by_mid(i, &cpu_node);
  70. current_set[i] = task_thread_info(idle);
  71. /* See trampoline.S for details... */
  72. entry += ((i - 1) * 3);
  73. /*
  74. * Initialize the contexts table
  75. * Since the call to prom_startcpu() trashes the structure,
  76. * we need to re-initialize it for each cpu
  77. */
  78. smp_penguin_ctable.which_io = 0;
  79. smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
  80. smp_penguin_ctable.reg_size = 0;
  81. /* whirrr, whirrr, whirrrrrrrrr... */
  82. printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
  83. local_ops->cache_all();
  84. prom_startcpu(cpu_node, &smp_penguin_ctable, 0, (char *)entry);
  85. /* wheee... it's going... */
  86. for (timeout = 0; timeout < 10000; timeout++) {
  87. if (cpu_callin_map[i])
  88. break;
  89. udelay(200);
  90. }
  91. if (!(cpu_callin_map[i])) {
  92. printk(KERN_ERR "Processor %d is stuck.\n", i);
  93. return -ENODEV;
  94. }
  95. local_ops->cache_all();
  96. return 0;
  97. }
  98. void __init smp4m_smp_done(void)
  99. {
  100. int i, first;
  101. int *prev;
  102. /* setup cpu list for irq rotation */
  103. first = 0;
  104. prev = &first;
  105. for_each_online_cpu(i) {
  106. *prev = i;
  107. prev = &cpu_data(i).next;
  108. }
  109. *prev = first;
  110. local_ops->cache_all();
  111. /* Ok, they are spinning and ready to go. */
  112. }
  113. static void sun4m_send_ipi(int cpu, int level)
  114. {
  115. sbus_writel(SUN4M_SOFT_INT(level), &sun4m_irq_percpu[cpu]->set);
  116. }
  117. static void sun4m_ipi_resched(int cpu)
  118. {
  119. sun4m_send_ipi(cpu, IRQ_IPI_RESCHED);
  120. }
  121. static void sun4m_ipi_single(int cpu)
  122. {
  123. sun4m_send_ipi(cpu, IRQ_IPI_SINGLE);
  124. }
  125. static void sun4m_ipi_mask_one(int cpu)
  126. {
  127. sun4m_send_ipi(cpu, IRQ_IPI_MASK);
  128. }
  129. static struct smp_funcall {
  130. smpfunc_t func;
  131. unsigned long arg1;
  132. unsigned long arg2;
  133. unsigned long arg3;
  134. unsigned long arg4;
  135. unsigned long arg5;
  136. unsigned long processors_in[SUN4M_NCPUS]; /* Set when ipi entered. */
  137. unsigned long processors_out[SUN4M_NCPUS]; /* Set when ipi exited. */
  138. } ccall_info;
  139. static DEFINE_SPINLOCK(cross_call_lock);
  140. /* Cross calls must be serialized, at least currently. */
  141. static void sun4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
  142. unsigned long arg2, unsigned long arg3,
  143. unsigned long arg4)
  144. {
  145. register int ncpus = SUN4M_NCPUS;
  146. unsigned long flags;
  147. spin_lock_irqsave(&cross_call_lock, flags);
  148. /* Init function glue. */
  149. ccall_info.func = func;
  150. ccall_info.arg1 = arg1;
  151. ccall_info.arg2 = arg2;
  152. ccall_info.arg3 = arg3;
  153. ccall_info.arg4 = arg4;
  154. ccall_info.arg5 = 0;
  155. /* Init receive/complete mapping, plus fire the IPI's off. */
  156. {
  157. register int i;
  158. cpumask_clear_cpu(smp_processor_id(), &mask);
  159. cpumask_and(&mask, cpu_online_mask, &mask);
  160. for (i = 0; i < ncpus; i++) {
  161. if (cpumask_test_cpu(i, &mask)) {
  162. ccall_info.processors_in[i] = 0;
  163. ccall_info.processors_out[i] = 0;
  164. sun4m_send_ipi(i, IRQ_CROSS_CALL);
  165. } else {
  166. ccall_info.processors_in[i] = 1;
  167. ccall_info.processors_out[i] = 1;
  168. }
  169. }
  170. }
  171. {
  172. register int i;
  173. i = 0;
  174. do {
  175. if (!cpumask_test_cpu(i, &mask))
  176. continue;
  177. while (!ccall_info.processors_in[i])
  178. barrier();
  179. } while (++i < ncpus);
  180. i = 0;
  181. do {
  182. if (!cpumask_test_cpu(i, &mask))
  183. continue;
  184. while (!ccall_info.processors_out[i])
  185. barrier();
  186. } while (++i < ncpus);
  187. }
  188. spin_unlock_irqrestore(&cross_call_lock, flags);
  189. }
  190. /* Running cross calls. */
  191. void smp4m_cross_call_irq(void)
  192. {
  193. int i = smp_processor_id();
  194. ccall_info.processors_in[i] = 1;
  195. ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
  196. ccall_info.arg4, ccall_info.arg5);
  197. ccall_info.processors_out[i] = 1;
  198. }
  199. void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
  200. {
  201. struct pt_regs *old_regs;
  202. struct clock_event_device *ce;
  203. int cpu = smp_processor_id();
  204. old_regs = set_irq_regs(regs);
  205. ce = &per_cpu(sparc32_clockevent, cpu);
  206. if (clockevent_state_periodic(ce))
  207. sun4m_clear_profile_irq(cpu);
  208. else
  209. sparc_config.load_profile_irq(cpu, 0); /* Is this needless? */
  210. irq_enter();
  211. ce->event_handler(ce);
  212. irq_exit();
  213. set_irq_regs(old_regs);
  214. }
  215. static const struct sparc32_ipi_ops sun4m_ipi_ops = {
  216. .cross_call = sun4m_cross_call,
  217. .resched = sun4m_ipi_resched,
  218. .single = sun4m_ipi_single,
  219. .mask_one = sun4m_ipi_mask_one,
  220. };
  221. void __init sun4m_init_smp(void)
  222. {
  223. sparc32_ipi_ops = &sun4m_ipi_ops;
  224. }