smp_32.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 sun4m:
  73. smp4m_smp_done();
  74. break;
  75. case sun4d:
  76. smp4d_smp_done();
  77. break;
  78. case sparc_leon:
  79. leon_smp_done();
  80. break;
  81. case sun4e:
  82. printk("SUN4E\n");
  83. BUG();
  84. break;
  85. case sun4u:
  86. printk("SUN4U\n");
  87. BUG();
  88. break;
  89. default:
  90. printk("UNKNOWN!\n");
  91. BUG();
  92. break;
  93. }
  94. }
  95. void cpu_panic(void)
  96. {
  97. printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
  98. panic("SMP bolixed\n");
  99. }
  100. struct linux_prom_registers smp_penguin_ctable __cpuinitdata = { 0 };
  101. void smp_send_reschedule(int cpu)
  102. {
  103. /*
  104. * CPU model dependent way of implementing IPI generation targeting
  105. * a single CPU. The trap handler needs only to do trap entry/return
  106. * to call schedule.
  107. */
  108. BTFIXUP_CALL(smp_ipi_resched)(cpu);
  109. }
  110. void smp_send_stop(void)
  111. {
  112. }
  113. void arch_send_call_function_single_ipi(int cpu)
  114. {
  115. /* trigger one IPI single call on one CPU */
  116. BTFIXUP_CALL(smp_ipi_single)(cpu);
  117. }
  118. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  119. {
  120. int cpu;
  121. /* trigger IPI mask call on each CPU */
  122. for_each_cpu(cpu, mask)
  123. BTFIXUP_CALL(smp_ipi_mask_one)(cpu);
  124. }
  125. void smp_resched_interrupt(void)
  126. {
  127. irq_enter();
  128. scheduler_ipi();
  129. local_cpu_data().irq_resched_count++;
  130. irq_exit();
  131. /* re-schedule routine called by interrupt return code. */
  132. }
  133. void smp_call_function_single_interrupt(void)
  134. {
  135. irq_enter();
  136. generic_smp_call_function_single_interrupt();
  137. local_cpu_data().irq_call_count++;
  138. irq_exit();
  139. }
  140. void smp_call_function_interrupt(void)
  141. {
  142. irq_enter();
  143. generic_smp_call_function_interrupt();
  144. local_cpu_data().irq_call_count++;
  145. irq_exit();
  146. }
  147. void smp_flush_cache_all(void)
  148. {
  149. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
  150. local_flush_cache_all();
  151. }
  152. void smp_flush_tlb_all(void)
  153. {
  154. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
  155. local_flush_tlb_all();
  156. }
  157. void smp_flush_cache_mm(struct mm_struct *mm)
  158. {
  159. if(mm->context != NO_CONTEXT) {
  160. cpumask_t cpu_mask;
  161. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  162. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  163. if (!cpumask_empty(&cpu_mask))
  164. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
  165. local_flush_cache_mm(mm);
  166. }
  167. }
  168. void smp_flush_tlb_mm(struct mm_struct *mm)
  169. {
  170. if(mm->context != NO_CONTEXT) {
  171. cpumask_t cpu_mask;
  172. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  173. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  174. if (!cpumask_empty(&cpu_mask)) {
  175. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
  176. if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  177. cpumask_copy(mm_cpumask(mm),
  178. cpumask_of(smp_processor_id()));
  179. }
  180. local_flush_tlb_mm(mm);
  181. }
  182. }
  183. void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  184. unsigned long end)
  185. {
  186. struct mm_struct *mm = vma->vm_mm;
  187. if (mm->context != NO_CONTEXT) {
  188. cpumask_t cpu_mask;
  189. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  190. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  191. if (!cpumask_empty(&cpu_mask))
  192. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
  193. local_flush_cache_range(vma, start, end);
  194. }
  195. }
  196. void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  197. unsigned long end)
  198. {
  199. struct mm_struct *mm = vma->vm_mm;
  200. if (mm->context != NO_CONTEXT) {
  201. cpumask_t cpu_mask;
  202. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  203. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  204. if (!cpumask_empty(&cpu_mask))
  205. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
  206. local_flush_tlb_range(vma, start, end);
  207. }
  208. }
  209. void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  210. {
  211. struct mm_struct *mm = vma->vm_mm;
  212. if(mm->context != NO_CONTEXT) {
  213. cpumask_t cpu_mask;
  214. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  215. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  216. if (!cpumask_empty(&cpu_mask))
  217. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
  218. local_flush_cache_page(vma, page);
  219. }
  220. }
  221. void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  222. {
  223. struct mm_struct *mm = vma->vm_mm;
  224. if(mm->context != NO_CONTEXT) {
  225. cpumask_t cpu_mask;
  226. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  227. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  228. if (!cpumask_empty(&cpu_mask))
  229. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
  230. local_flush_tlb_page(vma, page);
  231. }
  232. }
  233. void smp_flush_page_to_ram(unsigned long page)
  234. {
  235. /* Current theory is that those who call this are the one's
  236. * who have just dirtied their cache with the pages contents
  237. * in kernel space, therefore we only run this on local cpu.
  238. *
  239. * XXX This experiment failed, research further... -DaveM
  240. */
  241. #if 1
  242. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
  243. #endif
  244. local_flush_page_to_ram(page);
  245. }
  246. void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  247. {
  248. cpumask_t cpu_mask;
  249. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  250. cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
  251. if (!cpumask_empty(&cpu_mask))
  252. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
  253. local_flush_sig_insns(mm, insn_addr);
  254. }
  255. int setup_profiling_timer(unsigned int multiplier)
  256. {
  257. return -EINVAL;
  258. }
  259. void __init smp_prepare_cpus(unsigned int max_cpus)
  260. {
  261. extern void __init smp4m_boot_cpus(void);
  262. extern void __init smp4d_boot_cpus(void);
  263. int i, cpuid, extra;
  264. printk("Entering SMP Mode...\n");
  265. extra = 0;
  266. for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
  267. if (cpuid >= NR_CPUS)
  268. extra++;
  269. }
  270. /* i = number of cpus */
  271. if (extra && max_cpus > i - extra)
  272. printk("Warning: NR_CPUS is too low to start all cpus\n");
  273. smp_store_cpu_info(boot_cpu_id);
  274. switch(sparc_cpu_model) {
  275. case sun4m:
  276. smp4m_boot_cpus();
  277. break;
  278. case sun4d:
  279. smp4d_boot_cpus();
  280. break;
  281. case sparc_leon:
  282. leon_boot_cpus();
  283. break;
  284. case sun4e:
  285. printk("SUN4E\n");
  286. BUG();
  287. break;
  288. case sun4u:
  289. printk("SUN4U\n");
  290. BUG();
  291. break;
  292. default:
  293. printk("UNKNOWN!\n");
  294. BUG();
  295. break;
  296. }
  297. }
  298. /* Set this up early so that things like the scheduler can init
  299. * properly. We use the same cpu mask for both the present and
  300. * possible cpu map.
  301. */
  302. void __init smp_setup_cpu_possible_map(void)
  303. {
  304. int instance, mid;
  305. instance = 0;
  306. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  307. if (mid < NR_CPUS) {
  308. set_cpu_possible(mid, true);
  309. set_cpu_present(mid, true);
  310. }
  311. instance++;
  312. }
  313. }
  314. void __init smp_prepare_boot_cpu(void)
  315. {
  316. int cpuid = hard_smp_processor_id();
  317. if (cpuid >= NR_CPUS) {
  318. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  319. prom_halt();
  320. }
  321. if (cpuid != 0)
  322. printk("boot cpu id != 0, this could work but is untested\n");
  323. current_thread_info()->cpu = cpuid;
  324. set_cpu_online(cpuid, true);
  325. set_cpu_possible(cpuid, true);
  326. }
  327. int __cpuinit __cpu_up(unsigned int cpu)
  328. {
  329. extern int __cpuinit smp4m_boot_one_cpu(int);
  330. extern int __cpuinit smp4d_boot_one_cpu(int);
  331. int ret=0;
  332. switch(sparc_cpu_model) {
  333. case sun4m:
  334. ret = smp4m_boot_one_cpu(cpu);
  335. break;
  336. case sun4d:
  337. ret = smp4d_boot_one_cpu(cpu);
  338. break;
  339. case sparc_leon:
  340. ret = leon_boot_one_cpu(cpu);
  341. break;
  342. case sun4e:
  343. printk("SUN4E\n");
  344. BUG();
  345. break;
  346. case sun4u:
  347. printk("SUN4U\n");
  348. BUG();
  349. break;
  350. default:
  351. printk("UNKNOWN!\n");
  352. BUG();
  353. break;
  354. }
  355. if (!ret) {
  356. cpumask_set_cpu(cpu, &smp_commenced_mask);
  357. while (!cpu_online(cpu))
  358. mb();
  359. }
  360. return ret;
  361. }
  362. void smp_bogo(struct seq_file *m)
  363. {
  364. int i;
  365. for_each_online_cpu(i) {
  366. seq_printf(m,
  367. "Cpu%dBogo\t: %lu.%02lu\n",
  368. i,
  369. cpu_data(i).udelay_val/(500000/HZ),
  370. (cpu_data(i).udelay_val/(5000/HZ))%100);
  371. }
  372. }
  373. void smp_info(struct seq_file *m)
  374. {
  375. int i;
  376. seq_printf(m, "State:\n");
  377. for_each_online_cpu(i)
  378. seq_printf(m, "CPU%d\t\t: online\n", i);
  379. }