sun4d_smp.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /* Sparc SS1000/SC2000 SMP support.
  2. *
  3. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  4. *
  5. * Based on sun4m's smp.c, which is:
  6. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  7. */
  8. #include <linux/interrupt.h>
  9. #include <linux/profile.h>
  10. #include <linux/delay.h>
  11. #include <linux/cpu.h>
  12. #include <asm/sbi.h>
  13. #include <asm/mmu.h>
  14. #include <asm/tlbflush.h>
  15. #include <asm/cacheflush.h>
  16. #include "kernel.h"
  17. #include "irq.h"
  18. #define IRQ_CROSS_CALL 15
  19. static volatile int smp_processors_ready;
  20. static int smp_highest_cpu;
  21. static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned long val)
  22. {
  23. __asm__ __volatile__("swap [%1], %0\n\t" :
  24. "=&r" (val), "=&r" (ptr) :
  25. "0" (val), "1" (ptr));
  26. return val;
  27. }
  28. static void smp_setup_percpu_timer(void);
  29. static unsigned char cpu_leds[32];
  30. static inline void show_leds(int cpuid)
  31. {
  32. cpuid &= 0x1e;
  33. __asm__ __volatile__ ("stba %0, [%1] %2" : :
  34. "r" ((cpu_leds[cpuid] << 4) | cpu_leds[cpuid+1]),
  35. "r" (ECSR_BASE(cpuid) | BB_LEDS),
  36. "i" (ASI_M_CTL));
  37. }
  38. void __cpuinit smp4d_callin(void)
  39. {
  40. int cpuid = hard_smp4d_processor_id();
  41. unsigned long flags;
  42. /* Show we are alive */
  43. cpu_leds[cpuid] = 0x6;
  44. show_leds(cpuid);
  45. /* Enable level15 interrupt, disable level14 interrupt for now */
  46. cc_set_imsk((cc_get_imsk() & ~0x8000) | 0x4000);
  47. local_flush_cache_all();
  48. local_flush_tlb_all();
  49. notify_cpu_starting(cpuid);
  50. /*
  51. * Unblock the master CPU _only_ when the scheduler state
  52. * of all secondary CPUs will be up-to-date, so after
  53. * the SMP initialization the master will be just allowed
  54. * to call the scheduler code.
  55. */
  56. /* Get our local ticker going. */
  57. smp_setup_percpu_timer();
  58. calibrate_delay();
  59. smp_store_cpu_info(cpuid);
  60. local_flush_cache_all();
  61. local_flush_tlb_all();
  62. /* Allow master to continue. */
  63. sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1);
  64. local_flush_cache_all();
  65. local_flush_tlb_all();
  66. cpu_probe();
  67. while ((unsigned long)current_set[cpuid] < PAGE_OFFSET)
  68. barrier();
  69. while (current_set[cpuid]->cpu != cpuid)
  70. barrier();
  71. /* Fix idle thread fields. */
  72. __asm__ __volatile__("ld [%0], %%g6\n\t"
  73. : : "r" (&current_set[cpuid])
  74. : "memory" /* paranoid */);
  75. cpu_leds[cpuid] = 0x9;
  76. show_leds(cpuid);
  77. /* Attach to the address space of init_task. */
  78. atomic_inc(&init_mm.mm_count);
  79. current->active_mm = &init_mm;
  80. local_flush_cache_all();
  81. local_flush_tlb_all();
  82. local_irq_enable(); /* We don't allow PIL 14 yet */
  83. while (!cpu_isset(cpuid, smp_commenced_mask))
  84. barrier();
  85. spin_lock_irqsave(&sun4d_imsk_lock, flags);
  86. cc_set_imsk(cc_get_imsk() & ~0x4000); /* Allow PIL 14 as well */
  87. spin_unlock_irqrestore(&sun4d_imsk_lock, flags);
  88. set_cpu_online(cpuid, true);
  89. }
  90. /*
  91. * Cycle through the processors asking the PROM to start each one.
  92. */
  93. void __init smp4d_boot_cpus(void)
  94. {
  95. if (boot_cpu_id)
  96. current_set[0] = NULL;
  97. smp_setup_percpu_timer();
  98. local_flush_cache_all();
  99. }
  100. int __cpuinit smp4d_boot_one_cpu(int i)
  101. {
  102. unsigned long *entry = &sun4d_cpu_startup;
  103. struct task_struct *p;
  104. int timeout;
  105. int cpu_node;
  106. cpu_find_by_instance(i, &cpu_node, NULL);
  107. /* Cook up an idler for this guy. */
  108. p = fork_idle(i);
  109. current_set[i] = task_thread_info(p);
  110. /*
  111. * Initialize the contexts table
  112. * Since the call to prom_startcpu() trashes the structure,
  113. * we need to re-initialize it for each cpu
  114. */
  115. smp_penguin_ctable.which_io = 0;
  116. smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
  117. smp_penguin_ctable.reg_size = 0;
  118. /* whirrr, whirrr, whirrrrrrrrr... */
  119. printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
  120. local_flush_cache_all();
  121. prom_startcpu(cpu_node,
  122. &smp_penguin_ctable, 0, (char *)entry);
  123. printk(KERN_INFO "prom_startcpu returned :)\n");
  124. /* wheee... it's going... */
  125. for (timeout = 0; timeout < 10000; timeout++) {
  126. if (cpu_callin_map[i])
  127. break;
  128. udelay(200);
  129. }
  130. if (!(cpu_callin_map[i])) {
  131. printk(KERN_ERR "Processor %d is stuck.\n", i);
  132. return -ENODEV;
  133. }
  134. local_flush_cache_all();
  135. return 0;
  136. }
  137. void __init smp4d_smp_done(void)
  138. {
  139. int i, first;
  140. int *prev;
  141. /* setup cpu list for irq rotation */
  142. first = 0;
  143. prev = &first;
  144. for_each_online_cpu(i) {
  145. *prev = i;
  146. prev = &cpu_data(i).next;
  147. }
  148. *prev = first;
  149. local_flush_cache_all();
  150. /* Ok, they are spinning and ready to go. */
  151. smp_processors_ready = 1;
  152. sun4d_distribute_irqs();
  153. }
  154. static struct smp_funcall {
  155. smpfunc_t func;
  156. unsigned long arg1;
  157. unsigned long arg2;
  158. unsigned long arg3;
  159. unsigned long arg4;
  160. unsigned long arg5;
  161. unsigned char processors_in[NR_CPUS]; /* Set when ipi entered. */
  162. unsigned char processors_out[NR_CPUS]; /* Set when ipi exited. */
  163. } ccall_info __attribute__((aligned(8)));
  164. static DEFINE_SPINLOCK(cross_call_lock);
  165. /* Cross calls must be serialized, at least currently. */
  166. static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
  167. unsigned long arg2, unsigned long arg3,
  168. unsigned long arg4)
  169. {
  170. if (smp_processors_ready) {
  171. register int high = smp_highest_cpu;
  172. unsigned long flags;
  173. spin_lock_irqsave(&cross_call_lock, flags);
  174. {
  175. /*
  176. * If you make changes here, make sure
  177. * gcc generates proper code...
  178. */
  179. register smpfunc_t f asm("i0") = func;
  180. register unsigned long a1 asm("i1") = arg1;
  181. register unsigned long a2 asm("i2") = arg2;
  182. register unsigned long a3 asm("i3") = arg3;
  183. register unsigned long a4 asm("i4") = arg4;
  184. register unsigned long a5 asm("i5") = 0;
  185. __asm__ __volatile__(
  186. "std %0, [%6]\n\t"
  187. "std %2, [%6 + 8]\n\t"
  188. "std %4, [%6 + 16]\n\t" : :
  189. "r"(f), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5),
  190. "r" (&ccall_info.func));
  191. }
  192. /* Init receive/complete mapping, plus fire the IPI's off. */
  193. {
  194. register int i;
  195. cpu_clear(smp_processor_id(), mask);
  196. cpus_and(mask, cpu_online_map, mask);
  197. for (i = 0; i <= high; i++) {
  198. if (cpu_isset(i, mask)) {
  199. ccall_info.processors_in[i] = 0;
  200. ccall_info.processors_out[i] = 0;
  201. sun4d_send_ipi(i, IRQ_CROSS_CALL);
  202. }
  203. }
  204. }
  205. {
  206. register int i;
  207. i = 0;
  208. do {
  209. if (!cpu_isset(i, mask))
  210. continue;
  211. while (!ccall_info.processors_in[i])
  212. barrier();
  213. } while (++i <= high);
  214. i = 0;
  215. do {
  216. if (!cpu_isset(i, mask))
  217. continue;
  218. while (!ccall_info.processors_out[i])
  219. barrier();
  220. } while (++i <= high);
  221. }
  222. spin_unlock_irqrestore(&cross_call_lock, flags);
  223. }
  224. }
  225. /* Running cross calls. */
  226. void smp4d_cross_call_irq(void)
  227. {
  228. int i = hard_smp4d_processor_id();
  229. ccall_info.processors_in[i] = 1;
  230. ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
  231. ccall_info.arg4, ccall_info.arg5);
  232. ccall_info.processors_out[i] = 1;
  233. }
  234. void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
  235. {
  236. struct pt_regs *old_regs;
  237. int cpu = hard_smp4d_processor_id();
  238. static int cpu_tick[NR_CPUS];
  239. static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd };
  240. old_regs = set_irq_regs(regs);
  241. bw_get_prof_limit(cpu);
  242. bw_clear_intr_mask(0, 1); /* INTR_TABLE[0] & 1 is Profile IRQ */
  243. cpu_tick[cpu]++;
  244. if (!(cpu_tick[cpu] & 15)) {
  245. if (cpu_tick[cpu] == 0x60)
  246. cpu_tick[cpu] = 0;
  247. cpu_leds[cpu] = led_mask[cpu_tick[cpu] >> 4];
  248. show_leds(cpu);
  249. }
  250. profile_tick(CPU_PROFILING);
  251. if (!--prof_counter(cpu)) {
  252. int user = user_mode(regs);
  253. irq_enter();
  254. update_process_times(user);
  255. irq_exit();
  256. prof_counter(cpu) = prof_multiplier(cpu);
  257. }
  258. set_irq_regs(old_regs);
  259. }
  260. static void __cpuinit smp_setup_percpu_timer(void)
  261. {
  262. int cpu = hard_smp4d_processor_id();
  263. prof_counter(cpu) = prof_multiplier(cpu) = 1;
  264. load_profile_irq(cpu, lvl14_resolution);
  265. }
  266. void __init smp4d_blackbox_id(unsigned *addr)
  267. {
  268. int rd = *addr & 0x3e000000;
  269. addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
  270. addr[1] = 0x01000000; /* nop */
  271. addr[2] = 0x01000000; /* nop */
  272. }
  273. void __init smp4d_blackbox_current(unsigned *addr)
  274. {
  275. int rd = *addr & 0x3e000000;
  276. addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
  277. addr[2] = 0x81282002 | rd | (rd >> 11); /* sll reg, 2, reg */
  278. addr[4] = 0x01000000; /* nop */
  279. }
  280. void __init sun4d_init_smp(void)
  281. {
  282. int i;
  283. /* Patch ipi15 trap table */
  284. t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m);
  285. /* And set btfixup... */
  286. BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id);
  287. BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current);
  288. BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM);
  289. BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM);
  290. for (i = 0; i < NR_CPUS; i++) {
  291. ccall_info.processors_in[i] = 1;
  292. ccall_info.processors_out[i] = 1;
  293. }
  294. }