smp_32.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* smp.c: Sparc SMP support.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. * Copyright (C) 2004 Keith M Wesolowski (wesolows@foobazco.org)
  7. */
  8. #include <asm/head.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/threads.h>
  12. #include <linux/smp.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/init.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/mm.h>
  18. #include <linux/fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/cache.h>
  21. #include <linux/delay.h>
  22. #include <linux/profile.h>
  23. #include <linux/cpu.h>
  24. #include <asm/ptrace.h>
  25. #include <linux/atomic.h>
  26. #include <asm/irq.h>
  27. #include <asm/page.h>
  28. #include <asm/pgalloc.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/oplib.h>
  31. #include <asm/cacheflush.h>
  32. #include <asm/tlbflush.h>
  33. #include <asm/cpudata.h>
  34. #include <asm/timer.h>
  35. #include <asm/leon.h>
  36. #include "kernel.h"
  37. #include "irq.h"
  38. volatile unsigned long cpu_callin_map[NR_CPUS] = {0,};
  39. cpumask_t smp_commenced_mask = CPU_MASK_NONE;
  40. const struct sparc32_ipi_ops *sparc32_ipi_ops;
  41. /* The only guaranteed locking primitive available on all Sparc
  42. * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
  43. * places the current byte at the effective address into dest_reg and
  44. * places 0xff there afterwards. Pretty lame locking primitive
  45. * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
  46. * instruction which is much better...
  47. */
  48. void smp_store_cpu_info(int id)
  49. {
  50. int cpu_node;
  51. int mid;
  52. cpu_data(id).udelay_val = loops_per_jiffy;
  53. cpu_find_by_mid(id, &cpu_node);
  54. cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
  55. "clock-frequency", 0);
  56. cpu_data(id).prom_node = cpu_node;
  57. mid = cpu_get_hwmid(cpu_node);
  58. if (mid < 0) {
  59. printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08x", id, cpu_node);
  60. mid = 0;
  61. }
  62. cpu_data(id).mid = mid;
  63. }
  64. void __init smp_cpus_done(unsigned int max_cpus)
  65. {
  66. unsigned long bogosum = 0;
  67. int cpu, num = 0;
  68. for_each_online_cpu(cpu) {
  69. num++;
  70. bogosum += cpu_data(cpu).udelay_val;
  71. }
  72. printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
  73. num, bogosum/(500000/HZ),
  74. (bogosum/(5000/HZ))%100);
  75. switch(sparc_cpu_model) {
  76. case sun4m:
  77. smp4m_smp_done();
  78. break;
  79. case sun4d:
  80. smp4d_smp_done();
  81. break;
  82. case sparc_leon:
  83. leon_smp_done();
  84. break;
  85. case sun4e:
  86. printk("SUN4E\n");
  87. BUG();
  88. break;
  89. case sun4u:
  90. printk("SUN4U\n");
  91. BUG();
  92. break;
  93. default:
  94. printk("UNKNOWN!\n");
  95. BUG();
  96. break;
  97. }
  98. }
  99. void cpu_panic(void)
  100. {
  101. printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
  102. panic("SMP bolixed\n");
  103. }
  104. struct linux_prom_registers smp_penguin_ctable = { 0 };
  105. void smp_send_reschedule(int cpu)
  106. {
  107. /*
  108. * CPU model dependent way of implementing IPI generation targeting
  109. * a single CPU. The trap handler needs only to do trap entry/return
  110. * to call schedule.
  111. */
  112. sparc32_ipi_ops->resched(cpu);
  113. }
  114. void smp_send_stop(void)
  115. {
  116. }
  117. void arch_send_call_function_single_ipi(int cpu)
  118. {
  119. /* trigger one IPI single call on one CPU */
  120. sparc32_ipi_ops->single(cpu);
  121. }
  122. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  123. {
  124. int cpu;
  125. /* trigger IPI mask call on each CPU */
  126. for_each_cpu(cpu, mask)
  127. sparc32_ipi_ops->mask_one(cpu);
  128. }
  129. void smp_resched_interrupt(void)
  130. {
  131. irq_enter();
  132. scheduler_ipi();
  133. local_cpu_data().irq_resched_count++;
  134. irq_exit();
  135. /* re-schedule routine called by interrupt return code. */
  136. }
  137. void smp_call_function_single_interrupt(void)
  138. {
  139. irq_enter();
  140. generic_smp_call_function_single_interrupt();
  141. local_cpu_data().irq_call_count++;
  142. irq_exit();
  143. }
  144. void smp_call_function_interrupt(void)
  145. {
  146. irq_enter();
  147. generic_smp_call_function_interrupt();
  148. local_cpu_data().irq_call_count++;
  149. irq_exit();
  150. }
  151. int setup_profiling_timer(unsigned int multiplier)
  152. {
  153. return -EINVAL;
  154. }
  155. void __init smp_prepare_cpus(unsigned int max_cpus)
  156. {
  157. int i, cpuid, extra;
  158. printk("Entering SMP Mode...\n");
  159. extra = 0;
  160. for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
  161. if (cpuid >= NR_CPUS)
  162. extra++;
  163. }
  164. /* i = number of cpus */
  165. if (extra && max_cpus > i - extra)
  166. printk("Warning: NR_CPUS is too low to start all cpus\n");
  167. smp_store_cpu_info(boot_cpu_id);
  168. switch(sparc_cpu_model) {
  169. case sun4m:
  170. smp4m_boot_cpus();
  171. break;
  172. case sun4d:
  173. smp4d_boot_cpus();
  174. break;
  175. case sparc_leon:
  176. leon_boot_cpus();
  177. break;
  178. case sun4e:
  179. printk("SUN4E\n");
  180. BUG();
  181. break;
  182. case sun4u:
  183. printk("SUN4U\n");
  184. BUG();
  185. break;
  186. default:
  187. printk("UNKNOWN!\n");
  188. BUG();
  189. break;
  190. }
  191. }
  192. /* Set this up early so that things like the scheduler can init
  193. * properly. We use the same cpu mask for both the present and
  194. * possible cpu map.
  195. */
  196. void __init smp_setup_cpu_possible_map(void)
  197. {
  198. int instance, mid;
  199. instance = 0;
  200. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  201. if (mid < NR_CPUS) {
  202. set_cpu_possible(mid, true);
  203. set_cpu_present(mid, true);
  204. }
  205. instance++;
  206. }
  207. }
  208. void __init smp_prepare_boot_cpu(void)
  209. {
  210. int cpuid = hard_smp_processor_id();
  211. if (cpuid >= NR_CPUS) {
  212. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  213. prom_halt();
  214. }
  215. if (cpuid != 0)
  216. printk("boot cpu id != 0, this could work but is untested\n");
  217. current_thread_info()->cpu = cpuid;
  218. set_cpu_online(cpuid, true);
  219. set_cpu_possible(cpuid, true);
  220. }
  221. int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  222. {
  223. int ret=0;
  224. switch(sparc_cpu_model) {
  225. case sun4m:
  226. ret = smp4m_boot_one_cpu(cpu, tidle);
  227. break;
  228. case sun4d:
  229. ret = smp4d_boot_one_cpu(cpu, tidle);
  230. break;
  231. case sparc_leon:
  232. ret = leon_boot_one_cpu(cpu, tidle);
  233. break;
  234. case sun4e:
  235. printk("SUN4E\n");
  236. BUG();
  237. break;
  238. case sun4u:
  239. printk("SUN4U\n");
  240. BUG();
  241. break;
  242. default:
  243. printk("UNKNOWN!\n");
  244. BUG();
  245. break;
  246. }
  247. if (!ret) {
  248. cpumask_set_cpu(cpu, &smp_commenced_mask);
  249. while (!cpu_online(cpu))
  250. mb();
  251. }
  252. return ret;
  253. }
  254. static void arch_cpu_pre_starting(void *arg)
  255. {
  256. local_ops->cache_all();
  257. local_ops->tlb_all();
  258. switch(sparc_cpu_model) {
  259. case sun4m:
  260. sun4m_cpu_pre_starting(arg);
  261. break;
  262. case sun4d:
  263. sun4d_cpu_pre_starting(arg);
  264. break;
  265. case sparc_leon:
  266. leon_cpu_pre_starting(arg);
  267. break;
  268. default:
  269. BUG();
  270. }
  271. }
  272. static void arch_cpu_pre_online(void *arg)
  273. {
  274. unsigned int cpuid = hard_smp_processor_id();
  275. register_percpu_ce(cpuid);
  276. calibrate_delay();
  277. smp_store_cpu_info(cpuid);
  278. local_ops->cache_all();
  279. local_ops->tlb_all();
  280. switch(sparc_cpu_model) {
  281. case sun4m:
  282. sun4m_cpu_pre_online(arg);
  283. break;
  284. case sun4d:
  285. sun4d_cpu_pre_online(arg);
  286. break;
  287. case sparc_leon:
  288. leon_cpu_pre_online(arg);
  289. break;
  290. default:
  291. BUG();
  292. }
  293. }
  294. static void sparc_start_secondary(void *arg)
  295. {
  296. unsigned int cpu;
  297. /*
  298. * SMP booting is extremely fragile in some architectures. So run
  299. * the cpu initialization code first before anything else.
  300. */
  301. arch_cpu_pre_starting(arg);
  302. preempt_disable();
  303. cpu = smp_processor_id();
  304. notify_cpu_starting(cpu);
  305. arch_cpu_pre_online(arg);
  306. /* Set the CPU in the cpu_online_mask */
  307. set_cpu_online(cpu, true);
  308. /* Enable local interrupts now */
  309. local_irq_enable();
  310. wmb();
  311. cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
  312. /* We should never reach here! */
  313. BUG();
  314. }
  315. void smp_callin(void)
  316. {
  317. sparc_start_secondary(NULL);
  318. }
  319. void smp_bogo(struct seq_file *m)
  320. {
  321. int i;
  322. for_each_online_cpu(i) {
  323. seq_printf(m,
  324. "Cpu%dBogo\t: %lu.%02lu\n",
  325. i,
  326. cpu_data(i).udelay_val/(500000/HZ),
  327. (cpu_data(i).udelay_val/(5000/HZ))%100);
  328. }
  329. }
  330. void smp_info(struct seq_file *m)
  331. {
  332. int i;
  333. seq_printf(m, "State:\n");
  334. for_each_online_cpu(i)
  335. seq_printf(m, "CPU%d\t\t: online\n", i);
  336. }