smp_32.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /* smp.c: Sparc SMP support.
  2. *
  3. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  4. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  5. * Copyright (C) 2004 Keith M Wesolowski (wesolows@foobazco.org)
  6. */
  7. #include <asm/head.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/threads.h>
  11. #include <linux/smp.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/init.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/mm.h>
  17. #include <linux/fs.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/cache.h>
  20. #include <linux/delay.h>
  21. #include <asm/ptrace.h>
  22. #include <linux/atomic.h>
  23. #include <asm/irq.h>
  24. #include <asm/page.h>
  25. #include <asm/pgalloc.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/oplib.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/tlbflush.h>
  30. #include <asm/cpudata.h>
  31. #include <asm/leon.h>
  32. #include "irq.h"
  33. volatile unsigned long cpu_callin_map[NR_CPUS] __cpuinitdata = {0,};
  34. cpumask_t smp_commenced_mask = CPU_MASK_NONE;
  35. /* The only guaranteed locking primitive available on all Sparc
  36. * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
  37. * places the current byte at the effective address into dest_reg and
  38. * places 0xff there afterwards. Pretty lame locking primitive
  39. * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
  40. * instruction which is much better...
  41. */
  42. void __cpuinit smp_store_cpu_info(int id)
  43. {
  44. int cpu_node;
  45. int mid;
  46. cpu_data(id).udelay_val = loops_per_jiffy;
  47. cpu_find_by_mid(id, &cpu_node);
  48. cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
  49. "clock-frequency", 0);
  50. cpu_data(id).prom_node = cpu_node;
  51. mid = cpu_get_hwmid(cpu_node);
  52. if (mid < 0) {
  53. printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08d", id, cpu_node);
  54. mid = 0;
  55. }
  56. cpu_data(id).mid = mid;
  57. }
  58. void __init smp_cpus_done(unsigned int max_cpus)
  59. {
  60. extern void smp4m_smp_done(void);
  61. extern void smp4d_smp_done(void);
  62. unsigned long bogosum = 0;
  63. int cpu, num = 0;
  64. for_each_online_cpu(cpu) {
  65. num++;
  66. bogosum += cpu_data(cpu).udelay_val;
  67. }
  68. printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
  69. num, bogosum/(500000/HZ),
  70. (bogosum/(5000/HZ))%100);
  71. switch(sparc_cpu_model) {
  72. case sun4:
  73. printk("SUN4\n");
  74. BUG();
  75. break;
  76. case sun4c:
  77. printk("SUN4C\n");
  78. BUG();
  79. break;
  80. case sun4m:
  81. smp4m_smp_done();
  82. break;
  83. case sun4d:
  84. smp4d_smp_done();
  85. break;
  86. case sparc_leon:
  87. leon_smp_done();
  88. break;
  89. case sun4e:
  90. printk("SUN4E\n");
  91. BUG();
  92. break;
  93. case sun4u:
  94. printk("SUN4U\n");
  95. BUG();
  96. break;
  97. default:
  98. printk("UNKNOWN!\n");
  99. BUG();
  100. break;
  101. }
  102. }
  103. void cpu_panic(void)
  104. {
  105. printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
  106. panic("SMP bolixed\n");
  107. }
  108. struct linux_prom_registers smp_penguin_ctable __cpuinitdata = { 0 };
  109. void smp_send_reschedule(int cpu)
  110. {
  111. /*
  112. * CPU model dependent way of implementing IPI generation targeting
  113. * a single CPU. The trap handler needs only to do trap entry/return
  114. * to call schedule.
  115. */
  116. BTFIXUP_CALL(smp_ipi_resched)(cpu);
  117. }
  118. void smp_send_stop(void)
  119. {
  120. }
  121. void arch_send_call_function_single_ipi(int cpu)
  122. {
  123. /* trigger one IPI single call on one CPU */
  124. BTFIXUP_CALL(smp_ipi_single)(cpu);
  125. }
  126. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  127. {
  128. int cpu;
  129. /* trigger IPI mask call on each CPU */
  130. for_each_cpu(cpu, mask)
  131. BTFIXUP_CALL(smp_ipi_mask_one)(cpu);
  132. }
  133. void smp_resched_interrupt(void)
  134. {
  135. irq_enter();
  136. scheduler_ipi();
  137. local_cpu_data().irq_resched_count++;
  138. irq_exit();
  139. /* re-schedule routine called by interrupt return code. */
  140. }
  141. void smp_call_function_single_interrupt(void)
  142. {
  143. irq_enter();
  144. generic_smp_call_function_single_interrupt();
  145. local_cpu_data().irq_call_count++;
  146. irq_exit();
  147. }
  148. void smp_call_function_interrupt(void)
  149. {
  150. irq_enter();
  151. generic_smp_call_function_interrupt();
  152. local_cpu_data().irq_call_count++;
  153. irq_exit();
  154. }
  155. void smp_flush_cache_all(void)
  156. {
  157. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
  158. local_flush_cache_all();
  159. }
  160. void smp_flush_tlb_all(void)
  161. {
  162. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
  163. local_flush_tlb_all();
  164. }
  165. void smp_flush_cache_mm(struct mm_struct *mm)
  166. {
  167. if(mm->context != NO_CONTEXT) {
  168. cpumask_t cpu_mask;
  169. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  170. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  171. if (!cpumask_empty(&cpu_mask))
  172. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
  173. local_flush_cache_mm(mm);
  174. }
  175. }
  176. void smp_flush_tlb_mm(struct mm_struct *mm)
  177. {
  178. if(mm->context != NO_CONTEXT) {
  179. cpumask_t cpu_mask;
  180. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  181. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  182. if (!cpumask_empty(&cpu_mask)) {
  183. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
  184. if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  185. cpumask_copy(mm_cpumask(mm),
  186. cpumask_of(smp_processor_id()));
  187. }
  188. local_flush_tlb_mm(mm);
  189. }
  190. }
  191. void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  192. unsigned long end)
  193. {
  194. struct mm_struct *mm = vma->vm_mm;
  195. if (mm->context != NO_CONTEXT) {
  196. cpumask_t cpu_mask;
  197. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  198. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  199. if (!cpumask_empty(&cpu_mask))
  200. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
  201. local_flush_cache_range(vma, start, end);
  202. }
  203. }
  204. void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  205. unsigned long end)
  206. {
  207. struct mm_struct *mm = vma->vm_mm;
  208. if (mm->context != NO_CONTEXT) {
  209. cpumask_t cpu_mask;
  210. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  211. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  212. if (!cpumask_empty(&cpu_mask))
  213. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
  214. local_flush_tlb_range(vma, start, end);
  215. }
  216. }
  217. void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  218. {
  219. struct mm_struct *mm = vma->vm_mm;
  220. if(mm->context != NO_CONTEXT) {
  221. cpumask_t cpu_mask;
  222. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  223. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  224. if (!cpumask_empty(&cpu_mask))
  225. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
  226. local_flush_cache_page(vma, page);
  227. }
  228. }
  229. void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  230. {
  231. struct mm_struct *mm = vma->vm_mm;
  232. if(mm->context != NO_CONTEXT) {
  233. cpumask_t cpu_mask;
  234. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  235. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  236. if (!cpumask_empty(&cpu_mask))
  237. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
  238. local_flush_tlb_page(vma, page);
  239. }
  240. }
  241. void smp_flush_page_to_ram(unsigned long page)
  242. {
  243. /* Current theory is that those who call this are the one's
  244. * who have just dirtied their cache with the pages contents
  245. * in kernel space, therefore we only run this on local cpu.
  246. *
  247. * XXX This experiment failed, research further... -DaveM
  248. */
  249. #if 1
  250. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
  251. #endif
  252. local_flush_page_to_ram(page);
  253. }
  254. void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  255. {
  256. cpumask_t cpu_mask;
  257. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  258. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  259. if (!cpumask_empty(&cpu_mask))
  260. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
  261. local_flush_sig_insns(mm, insn_addr);
  262. }
  263. int setup_profiling_timer(unsigned int multiplier)
  264. {
  265. return -EINVAL;
  266. }
  267. void __init smp_prepare_cpus(unsigned int max_cpus)
  268. {
  269. extern void __init smp4m_boot_cpus(void);
  270. extern void __init smp4d_boot_cpus(void);
  271. int i, cpuid, extra;
  272. printk("Entering SMP Mode...\n");
  273. extra = 0;
  274. for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
  275. if (cpuid >= NR_CPUS)
  276. extra++;
  277. }
  278. /* i = number of cpus */
  279. if (extra && max_cpus > i - extra)
  280. printk("Warning: NR_CPUS is too low to start all cpus\n");
  281. smp_store_cpu_info(boot_cpu_id);
  282. switch(sparc_cpu_model) {
  283. case sun4:
  284. printk("SUN4\n");
  285. BUG();
  286. break;
  287. case sun4c:
  288. printk("SUN4C\n");
  289. BUG();
  290. break;
  291. case sun4m:
  292. smp4m_boot_cpus();
  293. break;
  294. case sun4d:
  295. smp4d_boot_cpus();
  296. break;
  297. case sparc_leon:
  298. leon_boot_cpus();
  299. break;
  300. case sun4e:
  301. printk("SUN4E\n");
  302. BUG();
  303. break;
  304. case sun4u:
  305. printk("SUN4U\n");
  306. BUG();
  307. break;
  308. default:
  309. printk("UNKNOWN!\n");
  310. BUG();
  311. break;
  312. }
  313. }
  314. /* Set this up early so that things like the scheduler can init
  315. * properly. We use the same cpu mask for both the present and
  316. * possible cpu map.
  317. */
  318. void __init smp_setup_cpu_possible_map(void)
  319. {
  320. int instance, mid;
  321. instance = 0;
  322. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  323. if (mid < NR_CPUS) {
  324. set_cpu_possible(mid, true);
  325. set_cpu_present(mid, true);
  326. }
  327. instance++;
  328. }
  329. }
  330. void __init smp_prepare_boot_cpu(void)
  331. {
  332. int cpuid = hard_smp_processor_id();
  333. if (cpuid >= NR_CPUS) {
  334. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  335. prom_halt();
  336. }
  337. if (cpuid != 0)
  338. printk("boot cpu id != 0, this could work but is untested\n");
  339. current_thread_info()->cpu = cpuid;
  340. set_cpu_online(cpuid, true);
  341. set_cpu_possible(cpuid, true);
  342. }
  343. int __cpuinit __cpu_up(unsigned int cpu)
  344. {
  345. extern int __cpuinit smp4m_boot_one_cpu(int);
  346. extern int __cpuinit smp4d_boot_one_cpu(int);
  347. int ret=0;
  348. switch(sparc_cpu_model) {
  349. case sun4:
  350. printk("SUN4\n");
  351. BUG();
  352. break;
  353. case sun4c:
  354. printk("SUN4C\n");
  355. BUG();
  356. break;
  357. case sun4m:
  358. ret = smp4m_boot_one_cpu(cpu);
  359. break;
  360. case sun4d:
  361. ret = smp4d_boot_one_cpu(cpu);
  362. break;
  363. case sparc_leon:
  364. ret = leon_boot_one_cpu(cpu);
  365. break;
  366. case sun4e:
  367. printk("SUN4E\n");
  368. BUG();
  369. break;
  370. case sun4u:
  371. printk("SUN4U\n");
  372. BUG();
  373. break;
  374. default:
  375. printk("UNKNOWN!\n");
  376. BUG();
  377. break;
  378. }
  379. if (!ret) {
  380. cpumask_set_cpu(cpu, &smp_commenced_mask);
  381. while (!cpu_online(cpu))
  382. mb();
  383. }
  384. return ret;
  385. }
  386. void smp_bogo(struct seq_file *m)
  387. {
  388. int i;
  389. for_each_online_cpu(i) {
  390. seq_printf(m,
  391. "Cpu%dBogo\t: %lu.%02lu\n",
  392. i,
  393. cpu_data(i).udelay_val/(500000/HZ),
  394. (cpu_data(i).udelay_val/(5000/HZ))%100);
  395. }
  396. }
  397. void smp_info(struct seq_file *m)
  398. {
  399. int i;
  400. seq_printf(m, "State:\n");
  401. for_each_online_cpu(i)
  402. seq_printf(m, "CPU%d\t\t: online\n", i);
  403. }