smp_32.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. cpu_data(id).udelay_val = loops_per_jiffy;
  46. cpu_find_by_mid(id, &cpu_node);
  47. cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
  48. "clock-frequency", 0);
  49. cpu_data(id).prom_node = cpu_node;
  50. cpu_data(id).mid = cpu_get_hwmid(cpu_node);
  51. if (cpu_data(id).mid < 0)
  52. panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
  53. }
  54. void __init smp_cpus_done(unsigned int max_cpus)
  55. {
  56. extern void smp4m_smp_done(void);
  57. extern void smp4d_smp_done(void);
  58. unsigned long bogosum = 0;
  59. int cpu, num = 0;
  60. for_each_online_cpu(cpu) {
  61. num++;
  62. bogosum += cpu_data(cpu).udelay_val;
  63. }
  64. printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
  65. num, bogosum/(500000/HZ),
  66. (bogosum/(5000/HZ))%100);
  67. switch(sparc_cpu_model) {
  68. case sun4:
  69. printk("SUN4\n");
  70. BUG();
  71. break;
  72. case sun4c:
  73. printk("SUN4C\n");
  74. BUG();
  75. break;
  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 __cpuinitdata = { 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. BTFIXUP_CALL(smp_ipi_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. BTFIXUP_CALL(smp_ipi_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. BTFIXUP_CALL(smp_ipi_mask_one)(cpu);
  128. }
  129. void smp_resched_interrupt(void)
  130. {
  131. local_cpu_data().irq_resched_count++;
  132. /*
  133. * do nothing, since it all was about calling re-schedule
  134. * routine called by interrupt return code.
  135. */
  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. void smp_flush_cache_all(void)
  152. {
  153. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
  154. local_flush_cache_all();
  155. }
  156. void smp_flush_tlb_all(void)
  157. {
  158. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
  159. local_flush_tlb_all();
  160. }
  161. void smp_flush_cache_mm(struct mm_struct *mm)
  162. {
  163. if(mm->context != NO_CONTEXT) {
  164. cpumask_t cpu_mask = *mm_cpumask(mm);
  165. cpu_clear(smp_processor_id(), cpu_mask);
  166. if (!cpus_empty(cpu_mask))
  167. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
  168. local_flush_cache_mm(mm);
  169. }
  170. }
  171. void smp_flush_tlb_mm(struct mm_struct *mm)
  172. {
  173. if(mm->context != NO_CONTEXT) {
  174. cpumask_t cpu_mask = *mm_cpumask(mm);
  175. cpu_clear(smp_processor_id(), cpu_mask);
  176. if (!cpus_empty(cpu_mask)) {
  177. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
  178. if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  179. cpumask_copy(mm_cpumask(mm),
  180. cpumask_of(smp_processor_id()));
  181. }
  182. local_flush_tlb_mm(mm);
  183. }
  184. }
  185. void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  186. unsigned long end)
  187. {
  188. struct mm_struct *mm = vma->vm_mm;
  189. if (mm->context != NO_CONTEXT) {
  190. cpumask_t cpu_mask = *mm_cpumask(mm);
  191. cpu_clear(smp_processor_id(), cpu_mask);
  192. if (!cpus_empty(cpu_mask))
  193. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
  194. local_flush_cache_range(vma, start, end);
  195. }
  196. }
  197. void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  198. unsigned long end)
  199. {
  200. struct mm_struct *mm = vma->vm_mm;
  201. if (mm->context != NO_CONTEXT) {
  202. cpumask_t cpu_mask = *mm_cpumask(mm);
  203. cpu_clear(smp_processor_id(), cpu_mask);
  204. if (!cpus_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 = *mm_cpumask(mm);
  214. cpu_clear(smp_processor_id(), cpu_mask);
  215. if (!cpus_empty(cpu_mask))
  216. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
  217. local_flush_cache_page(vma, page);
  218. }
  219. }
  220. void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  221. {
  222. struct mm_struct *mm = vma->vm_mm;
  223. if(mm->context != NO_CONTEXT) {
  224. cpumask_t cpu_mask = *mm_cpumask(mm);
  225. cpu_clear(smp_processor_id(), cpu_mask);
  226. if (!cpus_empty(cpu_mask))
  227. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
  228. local_flush_tlb_page(vma, page);
  229. }
  230. }
  231. void smp_reschedule_irq(void)
  232. {
  233. set_need_resched();
  234. }
  235. void smp_flush_page_to_ram(unsigned long page)
  236. {
  237. /* Current theory is that those who call this are the one's
  238. * who have just dirtied their cache with the pages contents
  239. * in kernel space, therefore we only run this on local cpu.
  240. *
  241. * XXX This experiment failed, research further... -DaveM
  242. */
  243. #if 1
  244. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
  245. #endif
  246. local_flush_page_to_ram(page);
  247. }
  248. void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  249. {
  250. cpumask_t cpu_mask = *mm_cpumask(mm);
  251. cpu_clear(smp_processor_id(), cpu_mask);
  252. if (!cpus_empty(cpu_mask))
  253. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
  254. local_flush_sig_insns(mm, insn_addr);
  255. }
  256. extern unsigned int lvl14_resolution;
  257. /* /proc/profile writes can call this, don't __init it please. */
  258. static DEFINE_SPINLOCK(prof_setup_lock);
  259. int setup_profiling_timer(unsigned int multiplier)
  260. {
  261. int i;
  262. unsigned long flags;
  263. /* Prevent level14 ticker IRQ flooding. */
  264. if((!multiplier) || (lvl14_resolution / multiplier) < 500)
  265. return -EINVAL;
  266. spin_lock_irqsave(&prof_setup_lock, flags);
  267. for_each_possible_cpu(i) {
  268. load_profile_irq(i, lvl14_resolution / multiplier);
  269. prof_multiplier(i) = multiplier;
  270. }
  271. spin_unlock_irqrestore(&prof_setup_lock, flags);
  272. return 0;
  273. }
  274. void __init smp_prepare_cpus(unsigned int max_cpus)
  275. {
  276. extern void __init smp4m_boot_cpus(void);
  277. extern void __init smp4d_boot_cpus(void);
  278. int i, cpuid, extra;
  279. printk("Entering SMP Mode...\n");
  280. extra = 0;
  281. for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
  282. if (cpuid >= NR_CPUS)
  283. extra++;
  284. }
  285. /* i = number of cpus */
  286. if (extra && max_cpus > i - extra)
  287. printk("Warning: NR_CPUS is too low to start all cpus\n");
  288. smp_store_cpu_info(boot_cpu_id);
  289. switch(sparc_cpu_model) {
  290. case sun4:
  291. printk("SUN4\n");
  292. BUG();
  293. break;
  294. case sun4c:
  295. printk("SUN4C\n");
  296. BUG();
  297. break;
  298. case sun4m:
  299. smp4m_boot_cpus();
  300. break;
  301. case sun4d:
  302. smp4d_boot_cpus();
  303. break;
  304. case sparc_leon:
  305. leon_boot_cpus();
  306. break;
  307. case sun4e:
  308. printk("SUN4E\n");
  309. BUG();
  310. break;
  311. case sun4u:
  312. printk("SUN4U\n");
  313. BUG();
  314. break;
  315. default:
  316. printk("UNKNOWN!\n");
  317. BUG();
  318. break;
  319. };
  320. }
  321. /* Set this up early so that things like the scheduler can init
  322. * properly. We use the same cpu mask for both the present and
  323. * possible cpu map.
  324. */
  325. void __init smp_setup_cpu_possible_map(void)
  326. {
  327. int instance, mid;
  328. instance = 0;
  329. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  330. if (mid < NR_CPUS) {
  331. set_cpu_possible(mid, true);
  332. set_cpu_present(mid, true);
  333. }
  334. instance++;
  335. }
  336. }
  337. void __init smp_prepare_boot_cpu(void)
  338. {
  339. int cpuid = hard_smp_processor_id();
  340. if (cpuid >= NR_CPUS) {
  341. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  342. prom_halt();
  343. }
  344. if (cpuid != 0)
  345. printk("boot cpu id != 0, this could work but is untested\n");
  346. current_thread_info()->cpu = cpuid;
  347. set_cpu_online(cpuid, true);
  348. set_cpu_possible(cpuid, true);
  349. }
  350. int __cpuinit __cpu_up(unsigned int cpu)
  351. {
  352. extern int __cpuinit smp4m_boot_one_cpu(int);
  353. extern int __cpuinit smp4d_boot_one_cpu(int);
  354. int ret=0;
  355. switch(sparc_cpu_model) {
  356. case sun4:
  357. printk("SUN4\n");
  358. BUG();
  359. break;
  360. case sun4c:
  361. printk("SUN4C\n");
  362. BUG();
  363. break;
  364. case sun4m:
  365. ret = smp4m_boot_one_cpu(cpu);
  366. break;
  367. case sun4d:
  368. ret = smp4d_boot_one_cpu(cpu);
  369. break;
  370. case sparc_leon:
  371. ret = leon_boot_one_cpu(cpu);
  372. break;
  373. case sun4e:
  374. printk("SUN4E\n");
  375. BUG();
  376. break;
  377. case sun4u:
  378. printk("SUN4U\n");
  379. BUG();
  380. break;
  381. default:
  382. printk("UNKNOWN!\n");
  383. BUG();
  384. break;
  385. };
  386. if (!ret) {
  387. cpu_set(cpu, smp_commenced_mask);
  388. while (!cpu_online(cpu))
  389. mb();
  390. }
  391. return ret;
  392. }
  393. void smp_bogo(struct seq_file *m)
  394. {
  395. int i;
  396. for_each_online_cpu(i) {
  397. seq_printf(m,
  398. "Cpu%dBogo\t: %lu.%02lu\n",
  399. i,
  400. cpu_data(i).udelay_val/(500000/HZ),
  401. (cpu_data(i).udelay_val/(5000/HZ))%100);
  402. }
  403. }
  404. void smp_info(struct seq_file *m)
  405. {
  406. int i;
  407. seq_printf(m, "State:\n");
  408. for_each_online_cpu(i)
  409. seq_printf(m, "CPU%d\t\t: online\n", i);
  410. }