sun4d_smp.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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/clockchips.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/profile.h>
  11. #include <linux/delay.h>
  12. #include <linux/sched.h>
  13. #include <linux/cpu.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/switch_to.h>
  16. #include <asm/tlbflush.h>
  17. #include <asm/timer.h>
  18. #include <asm/oplib.h>
  19. #include <asm/sbi.h>
  20. #include <asm/mmu.h>
  21. #include "kernel.h"
  22. #include "irq.h"
  23. #define IRQ_CROSS_CALL 15
  24. static volatile int smp_processors_ready;
  25. static int smp_highest_cpu;
  26. static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned long val)
  27. {
  28. __asm__ __volatile__("swap [%1], %0\n\t" :
  29. "=&r" (val), "=&r" (ptr) :
  30. "0" (val), "1" (ptr));
  31. return val;
  32. }
  33. static void smp4d_ipi_init(void);
  34. static unsigned char cpu_leds[32];
  35. static inline void show_leds(int cpuid)
  36. {
  37. cpuid &= 0x1e;
  38. __asm__ __volatile__ ("stba %0, [%1] %2" : :
  39. "r" ((cpu_leds[cpuid] << 4) | cpu_leds[cpuid+1]),
  40. "r" (ECSR_BASE(cpuid) | BB_LEDS),
  41. "i" (ASI_M_CTL));
  42. }
  43. void __cpuinit smp4d_callin(void)
  44. {
  45. int cpuid = hard_smp_processor_id();
  46. unsigned long flags;
  47. /* Show we are alive */
  48. cpu_leds[cpuid] = 0x6;
  49. show_leds(cpuid);
  50. /* Enable level15 interrupt, disable level14 interrupt for now */
  51. cc_set_imsk((cc_get_imsk() & ~0x8000) | 0x4000);
  52. local_ops->cache_all();
  53. local_ops->tlb_all();
  54. notify_cpu_starting(cpuid);
  55. /*
  56. * Unblock the master CPU _only_ when the scheduler state
  57. * of all secondary CPUs will be up-to-date, so after
  58. * the SMP initialization the master will be just allowed
  59. * to call the scheduler code.
  60. */
  61. /* Get our local ticker going. */
  62. register_percpu_ce(cpuid);
  63. calibrate_delay();
  64. smp_store_cpu_info(cpuid);
  65. local_ops->cache_all();
  66. local_ops->tlb_all();
  67. /* Allow master to continue. */
  68. sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1);
  69. local_ops->cache_all();
  70. local_ops->tlb_all();
  71. while ((unsigned long)current_set[cpuid] < PAGE_OFFSET)
  72. barrier();
  73. while (current_set[cpuid]->cpu != cpuid)
  74. barrier();
  75. /* Fix idle thread fields. */
  76. __asm__ __volatile__("ld [%0], %%g6\n\t"
  77. : : "r" (&current_set[cpuid])
  78. : "memory" /* paranoid */);
  79. cpu_leds[cpuid] = 0x9;
  80. show_leds(cpuid);
  81. /* Attach to the address space of init_task. */
  82. atomic_inc(&init_mm.mm_count);
  83. current->active_mm = &init_mm;
  84. local_ops->cache_all();
  85. local_ops->tlb_all();
  86. local_irq_enable(); /* We don't allow PIL 14 yet */
  87. while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
  88. barrier();
  89. spin_lock_irqsave(&sun4d_imsk_lock, flags);
  90. cc_set_imsk(cc_get_imsk() & ~0x4000); /* Allow PIL 14 as well */
  91. spin_unlock_irqrestore(&sun4d_imsk_lock, flags);
  92. set_cpu_online(cpuid, true);
  93. }
  94. /*
  95. * Cycle through the processors asking the PROM to start each one.
  96. */
  97. void __init smp4d_boot_cpus(void)
  98. {
  99. smp4d_ipi_init();
  100. if (boot_cpu_id)
  101. current_set[0] = NULL;
  102. local_ops->cache_all();
  103. }
  104. int __cpuinit smp4d_boot_one_cpu(int i, struct task_struct *idle)
  105. {
  106. unsigned long *entry = &sun4d_cpu_startup;
  107. int timeout;
  108. int cpu_node;
  109. cpu_find_by_instance(i, &cpu_node, NULL);
  110. current_set[i] = task_thread_info(idle);
  111. /*
  112. * Initialize the contexts table
  113. * Since the call to prom_startcpu() trashes the structure,
  114. * we need to re-initialize it for each cpu
  115. */
  116. smp_penguin_ctable.which_io = 0;
  117. smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
  118. smp_penguin_ctable.reg_size = 0;
  119. /* whirrr, whirrr, whirrrrrrrrr... */
  120. printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
  121. local_ops->cache_all();
  122. prom_startcpu(cpu_node,
  123. &smp_penguin_ctable, 0, (char *)entry);
  124. printk(KERN_INFO "prom_startcpu returned :)\n");
  125. /* wheee... it's going... */
  126. for (timeout = 0; timeout < 10000; timeout++) {
  127. if (cpu_callin_map[i])
  128. break;
  129. udelay(200);
  130. }
  131. if (!(cpu_callin_map[i])) {
  132. printk(KERN_ERR "Processor %d is stuck.\n", i);
  133. return -ENODEV;
  134. }
  135. local_ops->cache_all();
  136. return 0;
  137. }
  138. void __init smp4d_smp_done(void)
  139. {
  140. int i, first;
  141. int *prev;
  142. /* setup cpu list for irq rotation */
  143. first = 0;
  144. prev = &first;
  145. for_each_online_cpu(i) {
  146. *prev = i;
  147. prev = &cpu_data(i).next;
  148. }
  149. *prev = first;
  150. local_ops->cache_all();
  151. /* Ok, they are spinning and ready to go. */
  152. smp_processors_ready = 1;
  153. sun4d_distribute_irqs();
  154. }
  155. /* Memory structure giving interrupt handler information about IPI generated */
  156. struct sun4d_ipi_work {
  157. int single;
  158. int msk;
  159. int resched;
  160. };
  161. static DEFINE_PER_CPU_SHARED_ALIGNED(struct sun4d_ipi_work, sun4d_ipi_work);
  162. /* Initialize IPIs on the SUN4D SMP machine */
  163. static void __init smp4d_ipi_init(void)
  164. {
  165. int cpu;
  166. struct sun4d_ipi_work *work;
  167. printk(KERN_INFO "smp4d: setup IPI at IRQ %d\n", SUN4D_IPI_IRQ);
  168. for_each_possible_cpu(cpu) {
  169. work = &per_cpu(sun4d_ipi_work, cpu);
  170. work->single = work->msk = work->resched = 0;
  171. }
  172. }
  173. void sun4d_ipi_interrupt(void)
  174. {
  175. struct sun4d_ipi_work *work = &__get_cpu_var(sun4d_ipi_work);
  176. if (work->single) {
  177. work->single = 0;
  178. smp_call_function_single_interrupt();
  179. }
  180. if (work->msk) {
  181. work->msk = 0;
  182. smp_call_function_interrupt();
  183. }
  184. if (work->resched) {
  185. work->resched = 0;
  186. smp_resched_interrupt();
  187. }
  188. }
  189. /* +-------+-------------+-----------+------------------------------------+
  190. * | bcast | devid | sid | levels mask |
  191. * +-------+-------------+-----------+------------------------------------+
  192. * 31 30 23 22 15 14 0
  193. */
  194. #define IGEN_MESSAGE(bcast, devid, sid, levels) \
  195. (((bcast) << 31) | ((devid) << 23) | ((sid) << 15) | (levels))
  196. static void sun4d_send_ipi(int cpu, int level)
  197. {
  198. cc_set_igen(IGEN_MESSAGE(0, cpu << 3, 6 + ((level >> 1) & 7), 1 << (level - 1)));
  199. }
  200. static void sun4d_ipi_single(int cpu)
  201. {
  202. struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu);
  203. /* Mark work */
  204. work->single = 1;
  205. /* Generate IRQ on the CPU */
  206. sun4d_send_ipi(cpu, SUN4D_IPI_IRQ);
  207. }
  208. static void sun4d_ipi_mask_one(int cpu)
  209. {
  210. struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu);
  211. /* Mark work */
  212. work->msk = 1;
  213. /* Generate IRQ on the CPU */
  214. sun4d_send_ipi(cpu, SUN4D_IPI_IRQ);
  215. }
  216. static void sun4d_ipi_resched(int cpu)
  217. {
  218. struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu);
  219. /* Mark work */
  220. work->resched = 1;
  221. /* Generate IRQ on the CPU (any IRQ will cause resched) */
  222. sun4d_send_ipi(cpu, SUN4D_IPI_IRQ);
  223. }
  224. static struct smp_funcall {
  225. smpfunc_t func;
  226. unsigned long arg1;
  227. unsigned long arg2;
  228. unsigned long arg3;
  229. unsigned long arg4;
  230. unsigned long arg5;
  231. unsigned char processors_in[NR_CPUS]; /* Set when ipi entered. */
  232. unsigned char processors_out[NR_CPUS]; /* Set when ipi exited. */
  233. } ccall_info __attribute__((aligned(8)));
  234. static DEFINE_SPINLOCK(cross_call_lock);
  235. /* Cross calls must be serialized, at least currently. */
  236. static void sun4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
  237. unsigned long arg2, unsigned long arg3,
  238. unsigned long arg4)
  239. {
  240. if (smp_processors_ready) {
  241. register int high = smp_highest_cpu;
  242. unsigned long flags;
  243. spin_lock_irqsave(&cross_call_lock, flags);
  244. {
  245. /*
  246. * If you make changes here, make sure
  247. * gcc generates proper code...
  248. */
  249. register smpfunc_t f asm("i0") = func;
  250. register unsigned long a1 asm("i1") = arg1;
  251. register unsigned long a2 asm("i2") = arg2;
  252. register unsigned long a3 asm("i3") = arg3;
  253. register unsigned long a4 asm("i4") = arg4;
  254. register unsigned long a5 asm("i5") = 0;
  255. __asm__ __volatile__(
  256. "std %0, [%6]\n\t"
  257. "std %2, [%6 + 8]\n\t"
  258. "std %4, [%6 + 16]\n\t" : :
  259. "r"(f), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5),
  260. "r" (&ccall_info.func));
  261. }
  262. /* Init receive/complete mapping, plus fire the IPI's off. */
  263. {
  264. register int i;
  265. cpumask_clear_cpu(smp_processor_id(), &mask);
  266. cpumask_and(&mask, cpu_online_mask, &mask);
  267. for (i = 0; i <= high; i++) {
  268. if (cpumask_test_cpu(i, &mask)) {
  269. ccall_info.processors_in[i] = 0;
  270. ccall_info.processors_out[i] = 0;
  271. sun4d_send_ipi(i, IRQ_CROSS_CALL);
  272. }
  273. }
  274. }
  275. {
  276. register int i;
  277. i = 0;
  278. do {
  279. if (!cpumask_test_cpu(i, &mask))
  280. continue;
  281. while (!ccall_info.processors_in[i])
  282. barrier();
  283. } while (++i <= high);
  284. i = 0;
  285. do {
  286. if (!cpumask_test_cpu(i, &mask))
  287. continue;
  288. while (!ccall_info.processors_out[i])
  289. barrier();
  290. } while (++i <= high);
  291. }
  292. spin_unlock_irqrestore(&cross_call_lock, flags);
  293. }
  294. }
  295. /* Running cross calls. */
  296. void smp4d_cross_call_irq(void)
  297. {
  298. int i = hard_smp_processor_id();
  299. ccall_info.processors_in[i] = 1;
  300. ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
  301. ccall_info.arg4, ccall_info.arg5);
  302. ccall_info.processors_out[i] = 1;
  303. }
  304. void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
  305. {
  306. struct pt_regs *old_regs;
  307. int cpu = hard_smp_processor_id();
  308. struct clock_event_device *ce;
  309. static int cpu_tick[NR_CPUS];
  310. static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd };
  311. old_regs = set_irq_regs(regs);
  312. bw_get_prof_limit(cpu);
  313. bw_clear_intr_mask(0, 1); /* INTR_TABLE[0] & 1 is Profile IRQ */
  314. cpu_tick[cpu]++;
  315. if (!(cpu_tick[cpu] & 15)) {
  316. if (cpu_tick[cpu] == 0x60)
  317. cpu_tick[cpu] = 0;
  318. cpu_leds[cpu] = led_mask[cpu_tick[cpu] >> 4];
  319. show_leds(cpu);
  320. }
  321. ce = &per_cpu(sparc32_clockevent, cpu);
  322. irq_enter();
  323. ce->event_handler(ce);
  324. irq_exit();
  325. set_irq_regs(old_regs);
  326. }
  327. static const struct sparc32_ipi_ops sun4d_ipi_ops = {
  328. .cross_call = sun4d_cross_call,
  329. .resched = sun4d_ipi_resched,
  330. .single = sun4d_ipi_single,
  331. .mask_one = sun4d_ipi_mask_one,
  332. };
  333. void __init sun4d_init_smp(void)
  334. {
  335. int i;
  336. /* Patch ipi15 trap table */
  337. t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m);
  338. sparc32_ipi_ops = &sun4d_ipi_ops;
  339. for (i = 0; i < NR_CPUS; i++) {
  340. ccall_info.processors_in[i] = 1;
  341. ccall_info.processors_out[i] = 1;
  342. }
  343. }