smp_32.c 9.4 KB

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