smp.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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 "irq.h"
  32. volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,};
  33. unsigned char boot_cpu_id = 0;
  34. unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
  35. cpumask_t cpu_online_map = CPU_MASK_NONE;
  36. cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
  37. cpumask_t smp_commenced_mask = CPU_MASK_NONE;
  38. /* The only guaranteed locking primitive available on all Sparc
  39. * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
  40. * places the current byte at the effective address into dest_reg and
  41. * places 0xff there afterwards. Pretty lame locking primitive
  42. * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
  43. * instruction which is much better...
  44. */
  45. void __cpuinit smp_store_cpu_info(int id)
  46. {
  47. int cpu_node;
  48. cpu_data(id).udelay_val = loops_per_jiffy;
  49. cpu_find_by_mid(id, &cpu_node);
  50. cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
  51. "clock-frequency", 0);
  52. cpu_data(id).prom_node = cpu_node;
  53. cpu_data(id).mid = cpu_get_hwmid(cpu_node);
  54. if (cpu_data(id).mid < 0)
  55. panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
  56. }
  57. void __init smp_cpus_done(unsigned int max_cpus)
  58. {
  59. extern void smp4m_smp_done(void);
  60. extern void smp4d_smp_done(void);
  61. unsigned long bogosum = 0;
  62. int cpu, num;
  63. for (cpu = 0, num = 0; cpu < NR_CPUS; cpu++)
  64. if (cpu_online(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 sun4e:
  87. printk("SUN4E\n");
  88. BUG();
  89. break;
  90. case sun4u:
  91. printk("SUN4U\n");
  92. BUG();
  93. break;
  94. default:
  95. printk("UNKNOWN!\n");
  96. BUG();
  97. break;
  98. };
  99. }
  100. void cpu_panic(void)
  101. {
  102. printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
  103. panic("SMP bolixed\n");
  104. }
  105. struct linux_prom_registers smp_penguin_ctable __initdata = { 0 };
  106. void smp_send_reschedule(int cpu)
  107. {
  108. /* See sparc64 */
  109. }
  110. void smp_send_stop(void)
  111. {
  112. }
  113. void smp_flush_cache_all(void)
  114. {
  115. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
  116. local_flush_cache_all();
  117. }
  118. void smp_flush_tlb_all(void)
  119. {
  120. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
  121. local_flush_tlb_all();
  122. }
  123. void smp_flush_cache_mm(struct mm_struct *mm)
  124. {
  125. if(mm->context != NO_CONTEXT) {
  126. cpumask_t cpu_mask = mm->cpu_vm_mask;
  127. cpu_clear(smp_processor_id(), cpu_mask);
  128. if (!cpus_empty(cpu_mask))
  129. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
  130. local_flush_cache_mm(mm);
  131. }
  132. }
  133. void smp_flush_tlb_mm(struct mm_struct *mm)
  134. {
  135. if(mm->context != NO_CONTEXT) {
  136. cpumask_t cpu_mask = mm->cpu_vm_mask;
  137. cpu_clear(smp_processor_id(), cpu_mask);
  138. if (!cpus_empty(cpu_mask)) {
  139. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
  140. if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  141. mm->cpu_vm_mask = cpumask_of_cpu(smp_processor_id());
  142. }
  143. local_flush_tlb_mm(mm);
  144. }
  145. }
  146. void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  147. unsigned long end)
  148. {
  149. struct mm_struct *mm = vma->vm_mm;
  150. if (mm->context != NO_CONTEXT) {
  151. cpumask_t cpu_mask = mm->cpu_vm_mask;
  152. cpu_clear(smp_processor_id(), cpu_mask);
  153. if (!cpus_empty(cpu_mask))
  154. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
  155. local_flush_cache_range(vma, start, end);
  156. }
  157. }
  158. void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  159. unsigned long end)
  160. {
  161. struct mm_struct *mm = vma->vm_mm;
  162. if (mm->context != NO_CONTEXT) {
  163. cpumask_t cpu_mask = mm->cpu_vm_mask;
  164. cpu_clear(smp_processor_id(), cpu_mask);
  165. if (!cpus_empty(cpu_mask))
  166. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
  167. local_flush_tlb_range(vma, start, end);
  168. }
  169. }
  170. void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  171. {
  172. struct mm_struct *mm = vma->vm_mm;
  173. if(mm->context != NO_CONTEXT) {
  174. cpumask_t cpu_mask = mm->cpu_vm_mask;
  175. cpu_clear(smp_processor_id(), cpu_mask);
  176. if (!cpus_empty(cpu_mask))
  177. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
  178. local_flush_cache_page(vma, page);
  179. }
  180. }
  181. void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  182. {
  183. struct mm_struct *mm = vma->vm_mm;
  184. if(mm->context != NO_CONTEXT) {
  185. cpumask_t cpu_mask = mm->cpu_vm_mask;
  186. cpu_clear(smp_processor_id(), cpu_mask);
  187. if (!cpus_empty(cpu_mask))
  188. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
  189. local_flush_tlb_page(vma, page);
  190. }
  191. }
  192. void smp_reschedule_irq(void)
  193. {
  194. set_need_resched();
  195. }
  196. void smp_flush_page_to_ram(unsigned long page)
  197. {
  198. /* Current theory is that those who call this are the one's
  199. * who have just dirtied their cache with the pages contents
  200. * in kernel space, therefore we only run this on local cpu.
  201. *
  202. * XXX This experiment failed, research further... -DaveM
  203. */
  204. #if 1
  205. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
  206. #endif
  207. local_flush_page_to_ram(page);
  208. }
  209. void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  210. {
  211. cpumask_t cpu_mask = mm->cpu_vm_mask;
  212. cpu_clear(smp_processor_id(), cpu_mask);
  213. if (!cpus_empty(cpu_mask))
  214. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
  215. local_flush_sig_insns(mm, insn_addr);
  216. }
  217. extern unsigned int lvl14_resolution;
  218. /* /proc/profile writes can call this, don't __init it please. */
  219. static DEFINE_SPINLOCK(prof_setup_lock);
  220. int setup_profiling_timer(unsigned int multiplier)
  221. {
  222. int i;
  223. unsigned long flags;
  224. /* Prevent level14 ticker IRQ flooding. */
  225. if((!multiplier) || (lvl14_resolution / multiplier) < 500)
  226. return -EINVAL;
  227. spin_lock_irqsave(&prof_setup_lock, flags);
  228. for_each_possible_cpu(i) {
  229. load_profile_irq(i, lvl14_resolution / multiplier);
  230. prof_multiplier(i) = multiplier;
  231. }
  232. spin_unlock_irqrestore(&prof_setup_lock, flags);
  233. return 0;
  234. }
  235. void __init smp_prepare_cpus(unsigned int max_cpus)
  236. {
  237. extern void __init smp4m_boot_cpus(void);
  238. extern void __init smp4d_boot_cpus(void);
  239. int i, cpuid, extra;
  240. printk("Entering SMP Mode...\n");
  241. extra = 0;
  242. for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
  243. if (cpuid >= NR_CPUS)
  244. extra++;
  245. }
  246. /* i = number of cpus */
  247. if (extra && max_cpus > i - extra)
  248. printk("Warning: NR_CPUS is too low to start all cpus\n");
  249. smp_store_cpu_info(boot_cpu_id);
  250. switch(sparc_cpu_model) {
  251. case sun4:
  252. printk("SUN4\n");
  253. BUG();
  254. break;
  255. case sun4c:
  256. printk("SUN4C\n");
  257. BUG();
  258. break;
  259. case sun4m:
  260. smp4m_boot_cpus();
  261. break;
  262. case sun4d:
  263. smp4d_boot_cpus();
  264. break;
  265. case sun4e:
  266. printk("SUN4E\n");
  267. BUG();
  268. break;
  269. case sun4u:
  270. printk("SUN4U\n");
  271. BUG();
  272. break;
  273. default:
  274. printk("UNKNOWN!\n");
  275. BUG();
  276. break;
  277. };
  278. }
  279. /* Set this up early so that things like the scheduler can init
  280. * properly. We use the same cpu mask for both the present and
  281. * possible cpu map.
  282. */
  283. void __init smp_setup_cpu_possible_map(void)
  284. {
  285. int instance, mid;
  286. instance = 0;
  287. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  288. if (mid < NR_CPUS) {
  289. cpu_set(mid, phys_cpu_present_map);
  290. cpu_set(mid, cpu_present_map);
  291. }
  292. instance++;
  293. }
  294. }
  295. void __init smp_prepare_boot_cpu(void)
  296. {
  297. int cpuid = hard_smp_processor_id();
  298. if (cpuid >= NR_CPUS) {
  299. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  300. prom_halt();
  301. }
  302. if (cpuid != 0)
  303. printk("boot cpu id != 0, this could work but is untested\n");
  304. current_thread_info()->cpu = cpuid;
  305. cpu_set(cpuid, cpu_online_map);
  306. cpu_set(cpuid, phys_cpu_present_map);
  307. }
  308. int __cpuinit __cpu_up(unsigned int cpu)
  309. {
  310. extern int __cpuinit smp4m_boot_one_cpu(int);
  311. extern int __cpuinit smp4d_boot_one_cpu(int);
  312. int ret=0;
  313. switch(sparc_cpu_model) {
  314. case sun4:
  315. printk("SUN4\n");
  316. BUG();
  317. break;
  318. case sun4c:
  319. printk("SUN4C\n");
  320. BUG();
  321. break;
  322. case sun4m:
  323. ret = smp4m_boot_one_cpu(cpu);
  324. break;
  325. case sun4d:
  326. ret = smp4d_boot_one_cpu(cpu);
  327. break;
  328. case sun4e:
  329. printk("SUN4E\n");
  330. BUG();
  331. break;
  332. case sun4u:
  333. printk("SUN4U\n");
  334. BUG();
  335. break;
  336. default:
  337. printk("UNKNOWN!\n");
  338. BUG();
  339. break;
  340. };
  341. if (!ret) {
  342. cpu_set(cpu, smp_commenced_mask);
  343. while (!cpu_online(cpu))
  344. mb();
  345. }
  346. return ret;
  347. }
  348. void smp_bogo(struct seq_file *m)
  349. {
  350. int i;
  351. for_each_online_cpu(i) {
  352. seq_printf(m,
  353. "Cpu%dBogo\t: %lu.%02lu\n",
  354. i,
  355. cpu_data(i).udelay_val/(500000/HZ),
  356. (cpu_data(i).udelay_val/(5000/HZ))%100);
  357. }
  358. }
  359. void smp_info(struct seq_file *m)
  360. {
  361. int i;
  362. seq_printf(m, "State:\n");
  363. for_each_online_cpu(i)
  364. seq_printf(m, "CPU%d\t\t: online\n", i);
  365. }