sun4m_smp.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. /* At each hardware IRQ, we get this called to forward IRQ reception
  121. * to the next processor. The caller must disable the IRQ level being
  122. * serviced globally so that there are no double interrupts received.
  123. *
  124. * XXX See sparc64 irq.c.
  125. */
  126. void smp4m_irq_rotate(int cpu)
  127. {
  128. int next = cpu_data(cpu).next;
  129. if (next != cpu)
  130. set_irq_udt(next);
  131. }
  132. static struct smp_funcall {
  133. smpfunc_t func;
  134. unsigned long arg1;
  135. unsigned long arg2;
  136. unsigned long arg3;
  137. unsigned long arg4;
  138. unsigned long arg5;
  139. unsigned long processors_in[SUN4M_NCPUS]; /* Set when ipi entered. */
  140. unsigned long processors_out[SUN4M_NCPUS]; /* Set when ipi exited. */
  141. } ccall_info;
  142. static DEFINE_SPINLOCK(cross_call_lock);
  143. /* Cross calls must be serialized, at least currently. */
  144. static void smp4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
  145. unsigned long arg2, unsigned long arg3,
  146. unsigned long arg4)
  147. {
  148. register int ncpus = SUN4M_NCPUS;
  149. unsigned long flags;
  150. spin_lock_irqsave(&cross_call_lock, flags);
  151. /* Init function glue. */
  152. ccall_info.func = func;
  153. ccall_info.arg1 = arg1;
  154. ccall_info.arg2 = arg2;
  155. ccall_info.arg3 = arg3;
  156. ccall_info.arg4 = arg4;
  157. ccall_info.arg5 = 0;
  158. /* Init receive/complete mapping, plus fire the IPI's off. */
  159. {
  160. register int i;
  161. cpu_clear(smp_processor_id(), mask);
  162. cpus_and(mask, cpu_online_map, mask);
  163. for (i = 0; i < ncpus; i++) {
  164. if (cpu_isset(i, mask)) {
  165. ccall_info.processors_in[i] = 0;
  166. ccall_info.processors_out[i] = 0;
  167. set_cpu_int(i, IRQ_CROSS_CALL);
  168. } else {
  169. ccall_info.processors_in[i] = 1;
  170. ccall_info.processors_out[i] = 1;
  171. }
  172. }
  173. }
  174. {
  175. register int i;
  176. i = 0;
  177. do {
  178. if (!cpu_isset(i, mask))
  179. continue;
  180. while (!ccall_info.processors_in[i])
  181. barrier();
  182. } while (++i < ncpus);
  183. i = 0;
  184. do {
  185. if (!cpu_isset(i, mask))
  186. continue;
  187. while (!ccall_info.processors_out[i])
  188. barrier();
  189. } while (++i < ncpus);
  190. }
  191. spin_unlock_irqrestore(&cross_call_lock, flags);
  192. }
  193. /* Running cross calls. */
  194. void smp4m_cross_call_irq(void)
  195. {
  196. int i = smp_processor_id();
  197. ccall_info.processors_in[i] = 1;
  198. ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
  199. ccall_info.arg4, ccall_info.arg5);
  200. ccall_info.processors_out[i] = 1;
  201. }
  202. void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
  203. {
  204. struct pt_regs *old_regs;
  205. int cpu = smp_processor_id();
  206. old_regs = set_irq_regs(regs);
  207. sun4m_clear_profile_irq(cpu);
  208. profile_tick(CPU_PROFILING);
  209. if (!--prof_counter(cpu)) {
  210. int user = user_mode(regs);
  211. irq_enter();
  212. update_process_times(user);
  213. irq_exit();
  214. prof_counter(cpu) = prof_multiplier(cpu);
  215. }
  216. set_irq_regs(old_regs);
  217. }
  218. static void __cpuinit smp_setup_percpu_timer(void)
  219. {
  220. int cpu = smp_processor_id();
  221. prof_counter(cpu) = prof_multiplier(cpu) = 1;
  222. load_profile_irq(cpu, lvl14_resolution);
  223. if (cpu == boot_cpu_id)
  224. enable_pil_irq(14);
  225. }
  226. static void __init smp4m_blackbox_id(unsigned *addr)
  227. {
  228. int rd = *addr & 0x3e000000;
  229. int rs1 = rd >> 11;
  230. addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
  231. addr[1] = 0x8130200c | rd | rs1; /* srl reg, 0xc, reg */
  232. addr[2] = 0x80082003 | rd | rs1; /* and reg, 3, reg */
  233. }
  234. static void __init smp4m_blackbox_current(unsigned *addr)
  235. {
  236. int rd = *addr & 0x3e000000;
  237. int rs1 = rd >> 11;
  238. addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
  239. addr[2] = 0x8130200a | rd | rs1; /* srl reg, 0xa, reg */
  240. addr[4] = 0x8008200c | rd | rs1; /* and reg, 0xc, reg */
  241. }
  242. void __init sun4m_init_smp(void)
  243. {
  244. BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4m_blackbox_id);
  245. BTFIXUPSET_BLACKBOX(load_current, smp4m_blackbox_current);
  246. BTFIXUPSET_CALL(smp_cross_call, smp4m_cross_call, BTFIXUPCALL_NORM);
  247. BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4m_processor_id, BTFIXUPCALL_NORM);
  248. }