sun4m_smp.c 7.2 KB

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