smp_32.c 9.2 KB

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