smp_32.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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 <asm/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. extern unsigned int lvl14_resolution;
  264. /* /proc/profile writes can call this, don't __init it please. */
  265. static DEFINE_SPINLOCK(prof_setup_lock);
  266. int setup_profiling_timer(unsigned int multiplier)
  267. {
  268. int i;
  269. unsigned long flags;
  270. /* Prevent level14 ticker IRQ flooding. */
  271. if((!multiplier) || (lvl14_resolution / multiplier) < 500)
  272. return -EINVAL;
  273. spin_lock_irqsave(&prof_setup_lock, flags);
  274. for_each_possible_cpu(i) {
  275. load_profile_irq(i, lvl14_resolution / multiplier);
  276. prof_multiplier(i) = multiplier;
  277. }
  278. spin_unlock_irqrestore(&prof_setup_lock, flags);
  279. return 0;
  280. }
  281. void __init smp_prepare_cpus(unsigned int max_cpus)
  282. {
  283. extern void __init smp4m_boot_cpus(void);
  284. extern void __init smp4d_boot_cpus(void);
  285. int i, cpuid, extra;
  286. printk("Entering SMP Mode...\n");
  287. extra = 0;
  288. for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
  289. if (cpuid >= NR_CPUS)
  290. extra++;
  291. }
  292. /* i = number of cpus */
  293. if (extra && max_cpus > i - extra)
  294. printk("Warning: NR_CPUS is too low to start all cpus\n");
  295. smp_store_cpu_info(boot_cpu_id);
  296. switch(sparc_cpu_model) {
  297. case sun4:
  298. printk("SUN4\n");
  299. BUG();
  300. break;
  301. case sun4c:
  302. printk("SUN4C\n");
  303. BUG();
  304. break;
  305. case sun4m:
  306. smp4m_boot_cpus();
  307. break;
  308. case sun4d:
  309. smp4d_boot_cpus();
  310. break;
  311. case sparc_leon:
  312. leon_boot_cpus();
  313. break;
  314. case sun4e:
  315. printk("SUN4E\n");
  316. BUG();
  317. break;
  318. case sun4u:
  319. printk("SUN4U\n");
  320. BUG();
  321. break;
  322. default:
  323. printk("UNKNOWN!\n");
  324. BUG();
  325. break;
  326. }
  327. }
  328. /* Set this up early so that things like the scheduler can init
  329. * properly. We use the same cpu mask for both the present and
  330. * possible cpu map.
  331. */
  332. void __init smp_setup_cpu_possible_map(void)
  333. {
  334. int instance, mid;
  335. instance = 0;
  336. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  337. if (mid < NR_CPUS) {
  338. set_cpu_possible(mid, true);
  339. set_cpu_present(mid, true);
  340. }
  341. instance++;
  342. }
  343. }
  344. void __init smp_prepare_boot_cpu(void)
  345. {
  346. int cpuid = hard_smp_processor_id();
  347. if (cpuid >= NR_CPUS) {
  348. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  349. prom_halt();
  350. }
  351. if (cpuid != 0)
  352. printk("boot cpu id != 0, this could work but is untested\n");
  353. current_thread_info()->cpu = cpuid;
  354. set_cpu_online(cpuid, true);
  355. set_cpu_possible(cpuid, true);
  356. }
  357. int __cpuinit __cpu_up(unsigned int cpu)
  358. {
  359. extern int __cpuinit smp4m_boot_one_cpu(int);
  360. extern int __cpuinit smp4d_boot_one_cpu(int);
  361. int ret=0;
  362. switch(sparc_cpu_model) {
  363. case sun4:
  364. printk("SUN4\n");
  365. BUG();
  366. break;
  367. case sun4c:
  368. printk("SUN4C\n");
  369. BUG();
  370. break;
  371. case sun4m:
  372. ret = smp4m_boot_one_cpu(cpu);
  373. break;
  374. case sun4d:
  375. ret = smp4d_boot_one_cpu(cpu);
  376. break;
  377. case sparc_leon:
  378. ret = leon_boot_one_cpu(cpu);
  379. break;
  380. case sun4e:
  381. printk("SUN4E\n");
  382. BUG();
  383. break;
  384. case sun4u:
  385. printk("SUN4U\n");
  386. BUG();
  387. break;
  388. default:
  389. printk("UNKNOWN!\n");
  390. BUG();
  391. break;
  392. }
  393. if (!ret) {
  394. cpumask_set_cpu(cpu, &smp_commenced_mask);
  395. while (!cpu_online(cpu))
  396. mb();
  397. }
  398. return ret;
  399. }
  400. void smp_bogo(struct seq_file *m)
  401. {
  402. int i;
  403. for_each_online_cpu(i) {
  404. seq_printf(m,
  405. "Cpu%dBogo\t: %lu.%02lu\n",
  406. i,
  407. cpu_data(i).udelay_val/(500000/HZ),
  408. (cpu_data(i).udelay_val/(5000/HZ))%100);
  409. }
  410. }
  411. void smp_info(struct seq_file *m)
  412. {
  413. int i;
  414. seq_printf(m, "State:\n");
  415. for_each_online_cpu(i)
  416. seq_printf(m, "CPU%d\t\t: online\n", i);
  417. }