sun4m_smp.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * sun4m SMP support.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <linux/interrupt.h>
  7. #include <linux/profile.h>
  8. #include <linux/delay.h>
  9. #include <linux/cpu.h>
  10. #include <asm/cacheflush.h>
  11. #include <asm/tlbflush.h>
  12. #include "irq.h"
  13. #include "kernel.h"
  14. #define IRQ_CROSS_CALL 15
  15. static inline unsigned long
  16. swap_ulong(volatile unsigned long *ptr, unsigned long val)
  17. {
  18. __asm__ __volatile__("swap [%1], %0\n\t" :
  19. "=&r" (val), "=&r" (ptr) :
  20. "0" (val), "1" (ptr));
  21. return val;
  22. }
  23. static void smp_setup_percpu_timer(void);
  24. void __cpuinit smp4m_callin(void)
  25. {
  26. int cpuid = hard_smp_processor_id();
  27. local_flush_cache_all();
  28. local_flush_tlb_all();
  29. notify_cpu_starting(cpuid);
  30. /* Get our local ticker going. */
  31. smp_setup_percpu_timer();
  32. calibrate_delay();
  33. smp_store_cpu_info(cpuid);
  34. local_flush_cache_all();
  35. local_flush_tlb_all();
  36. /*
  37. * Unblock the master CPU _only_ when the scheduler state
  38. * of all secondary CPUs will be up-to-date, so after
  39. * the SMP initialization the master will be just allowed
  40. * to call the scheduler code.
  41. */
  42. /* Allow master to continue. */
  43. swap_ulong(&cpu_callin_map[cpuid], 1);
  44. /* XXX: What's up with all the flushes? */
  45. local_flush_cache_all();
  46. local_flush_tlb_all();
  47. cpu_probe();
  48. /* Fix idle thread fields. */
  49. __asm__ __volatile__("ld [%0], %%g6\n\t"
  50. : : "r" (&current_set[cpuid])
  51. : "memory" /* paranoid */);
  52. /* Attach to the address space of init_task. */
  53. atomic_inc(&init_mm.mm_count);
  54. current->active_mm = &init_mm;
  55. while (!cpu_isset(cpuid, smp_commenced_mask))
  56. mb();
  57. local_irq_enable();
  58. set_cpu_online(cpuid, true);
  59. }
  60. /*
  61. * Cycle through the processors asking the PROM to start each one.
  62. */
  63. void __init smp4m_boot_cpus(void)
  64. {
  65. smp_setup_percpu_timer();
  66. local_flush_cache_all();
  67. }
  68. int __cpuinit smp4m_boot_one_cpu(int i)
  69. {
  70. unsigned long *entry = &sun4m_cpu_startup;
  71. struct task_struct *p;
  72. int timeout;
  73. int cpu_node;
  74. cpu_find_by_mid(i, &cpu_node);
  75. /* Cook up an idler for this guy. */
  76. p = fork_idle(i);
  77. current_set[i] = task_thread_info(p);
  78. /* See trampoline.S for details... */
  79. entry += ((i - 1) * 3);
  80. /*
  81. * Initialize the contexts table
  82. * Since the call to prom_startcpu() trashes the structure,
  83. * we need to re-initialize it for each cpu
  84. */
  85. smp_penguin_ctable.which_io = 0;
  86. smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
  87. smp_penguin_ctable.reg_size = 0;
  88. /* whirrr, whirrr, whirrrrrrrrr... */
  89. printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
  90. local_flush_cache_all();
  91. prom_startcpu(cpu_node, &smp_penguin_ctable, 0, (char *)entry);
  92. /* wheee... it's going... */
  93. for (timeout = 0; timeout < 10000; timeout++) {
  94. if (cpu_callin_map[i])
  95. break;
  96. udelay(200);
  97. }
  98. if (!(cpu_callin_map[i])) {
  99. printk(KERN_ERR "Processor %d is stuck.\n", i);
  100. return -ENODEV;
  101. }
  102. local_flush_cache_all();
  103. return 0;
  104. }
  105. void __init smp4m_smp_done(void)
  106. {
  107. int i, first;
  108. int *prev;
  109. /* setup cpu list for irq rotation */
  110. first = 0;
  111. prev = &first;
  112. for_each_online_cpu(i) {
  113. *prev = i;
  114. prev = &cpu_data(i).next;
  115. }
  116. *prev = first;
  117. local_flush_cache_all();
  118. /* Ok, they are spinning and ready to go. */
  119. }
  120. static struct smp_funcall {
  121. smpfunc_t func;
  122. unsigned long arg1;
  123. unsigned long arg2;
  124. unsigned long arg3;
  125. unsigned long arg4;
  126. unsigned long arg5;
  127. unsigned long processors_in[SUN4M_NCPUS]; /* Set when ipi entered. */
  128. unsigned long processors_out[SUN4M_NCPUS]; /* Set when ipi exited. */
  129. } ccall_info;
  130. static DEFINE_SPINLOCK(cross_call_lock);
  131. /* Cross calls must be serialized, at least currently. */
  132. static void smp4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
  133. unsigned long arg2, unsigned long arg3,
  134. unsigned long arg4)
  135. {
  136. register int ncpus = SUN4M_NCPUS;
  137. unsigned long flags;
  138. spin_lock_irqsave(&cross_call_lock, flags);
  139. /* Init function glue. */
  140. ccall_info.func = func;
  141. ccall_info.arg1 = arg1;
  142. ccall_info.arg2 = arg2;
  143. ccall_info.arg3 = arg3;
  144. ccall_info.arg4 = arg4;
  145. ccall_info.arg5 = 0;
  146. /* Init receive/complete mapping, plus fire the IPI's off. */
  147. {
  148. register int i;
  149. cpu_clear(smp_processor_id(), mask);
  150. cpus_and(mask, cpu_online_map, mask);
  151. for (i = 0; i < ncpus; i++) {
  152. if (cpu_isset(i, mask)) {
  153. ccall_info.processors_in[i] = 0;
  154. ccall_info.processors_out[i] = 0;
  155. set_cpu_int(i, IRQ_CROSS_CALL);
  156. } else {
  157. ccall_info.processors_in[i] = 1;
  158. ccall_info.processors_out[i] = 1;
  159. }
  160. }
  161. }
  162. {
  163. register int i;
  164. i = 0;
  165. do {
  166. if (!cpu_isset(i, mask))
  167. continue;
  168. while (!ccall_info.processors_in[i])
  169. barrier();
  170. } while (++i < ncpus);
  171. i = 0;
  172. do {
  173. if (!cpu_isset(i, mask))
  174. continue;
  175. while (!ccall_info.processors_out[i])
  176. barrier();
  177. } while (++i < ncpus);
  178. }
  179. spin_unlock_irqrestore(&cross_call_lock, flags);
  180. }
  181. /* Running cross calls. */
  182. void smp4m_cross_call_irq(void)
  183. {
  184. int i = smp_processor_id();
  185. ccall_info.processors_in[i] = 1;
  186. ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
  187. ccall_info.arg4, ccall_info.arg5);
  188. ccall_info.processors_out[i] = 1;
  189. }
  190. void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
  191. {
  192. struct pt_regs *old_regs;
  193. int cpu = smp_processor_id();
  194. old_regs = set_irq_regs(regs);
  195. sun4m_clear_profile_irq(cpu);
  196. profile_tick(CPU_PROFILING);
  197. if (!--prof_counter(cpu)) {
  198. int user = user_mode(regs);
  199. irq_enter();
  200. update_process_times(user);
  201. irq_exit();
  202. prof_counter(cpu) = prof_multiplier(cpu);
  203. }
  204. set_irq_regs(old_regs);
  205. }
  206. static void __cpuinit smp_setup_percpu_timer(void)
  207. {
  208. int cpu = smp_processor_id();
  209. prof_counter(cpu) = prof_multiplier(cpu) = 1;
  210. load_profile_irq(cpu, lvl14_resolution);
  211. if (cpu == boot_cpu_id)
  212. sun4m_unmask_profile_irq();
  213. }
  214. static void __init smp4m_blackbox_id(unsigned *addr)
  215. {
  216. int rd = *addr & 0x3e000000;
  217. int rs1 = rd >> 11;
  218. addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
  219. addr[1] = 0x8130200c | rd | rs1; /* srl reg, 0xc, reg */
  220. addr[2] = 0x80082003 | rd | rs1; /* and reg, 3, reg */
  221. }
  222. static void __init smp4m_blackbox_current(unsigned *addr)
  223. {
  224. int rd = *addr & 0x3e000000;
  225. int rs1 = rd >> 11;
  226. addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
  227. addr[2] = 0x8130200a | rd | rs1; /* srl reg, 0xa, reg */
  228. addr[4] = 0x8008200c | rd | rs1; /* and reg, 0xc, reg */
  229. }
  230. void __init sun4m_init_smp(void)
  231. {
  232. BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4m_blackbox_id);
  233. BTFIXUPSET_BLACKBOX(load_current, smp4m_blackbox_current);
  234. BTFIXUPSET_CALL(smp_cross_call, smp4m_cross_call, BTFIXUPCALL_NORM);
  235. BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4m_processor_id, BTFIXUPCALL_NORM);
  236. }