blob: 569a8a9d24a2b29f28bd36fd698e6519ac0c3b5f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
8#include <asm/head.h>
9
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/threads.h>
13#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/interrupt.h>
15#include <linux/kernel_stat.h>
16#include <linux/init.h>
17#include <linux/spinlock.h>
18#include <linux/mm.h>
19#include <linux/fs.h>
20#include <linux/seq_file.h>
21#include <linux/cache.h>
22#include <linux/delay.h>
23
24#include <asm/ptrace.h>
Arun Sharma600634972011-07-26 16:09:06 -070025#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/irq.h>
28#include <asm/page.h>
29#include <asm/pgalloc.h>
30#include <asm/pgtable.h>
31#include <asm/oplib.h>
32#include <asm/cacheflush.h>
33#include <asm/tlbflush.h>
34#include <asm/cpudata.h>
Konrad Eisele84017072009-08-31 22:08:13 +000035#include <asm/leon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Al Viro32231a62007-07-21 19:18:57 -070037#include "irq.h"
38
Al Viro409832f2008-11-22 17:33:54 +000039volatile unsigned long cpu_callin_map[NR_CPUS] __cpuinitdata = {0,};
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Bob Breuera54123e2006-03-23 22:36:19 -080041cpumask_t smp_commenced_mask = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* The only guaranteed locking primitive available on all Sparc
44 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
45 * places the current byte at the effective address into dest_reg and
46 * places 0xff there afterwards. Pretty lame locking primitive
47 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
48 * instruction which is much better...
49 */
50
Bob Breuer92d452f2006-06-20 00:36:10 -070051void __cpuinit smp_store_cpu_info(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 int cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070054 int mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 cpu_data(id).udelay_val = loops_per_jiffy;
57
58 cpu_find_by_mid(id, &cpu_node);
59 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
60 "clock-frequency", 0);
61 cpu_data(id).prom_node = cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070062 mid = cpu_get_hwmid(cpu_node);
Krzysztof Helt650fb832006-06-10 22:03:43 -070063
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070064 if (mid < 0) {
65 printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08d", id, cpu_node);
66 mid = 0;
67 }
68 cpu_data(id).mid = mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71void __init smp_cpus_done(unsigned int max_cpus)
72{
Bob Breuera54123e2006-03-23 22:36:19 -080073 extern void smp4m_smp_done(void);
Raymond Burns8b3c8482006-07-17 21:57:09 -070074 extern void smp4d_smp_done(void);
Bob Breuera54123e2006-03-23 22:36:19 -080075 unsigned long bogosum = 0;
Rusty Russellec7c14b2009-03-16 14:40:24 +103076 int cpu, num = 0;
Bob Breuera54123e2006-03-23 22:36:19 -080077
Rusty Russellec7c14b2009-03-16 14:40:24 +103078 for_each_online_cpu(cpu) {
79 num++;
80 bogosum += cpu_data(cpu).udelay_val;
81 }
Bob Breuera54123e2006-03-23 22:36:19 -080082
83 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
84 num, bogosum/(500000/HZ),
85 (bogosum/(5000/HZ))%100);
86
Raymond Burns8b3c8482006-07-17 21:57:09 -070087 switch(sparc_cpu_model) {
88 case sun4:
89 printk("SUN4\n");
90 BUG();
91 break;
92 case sun4c:
93 printk("SUN4C\n");
94 BUG();
95 break;
96 case sun4m:
97 smp4m_smp_done();
98 break;
99 case sun4d:
100 smp4d_smp_done();
101 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000102 case sparc_leon:
103 leon_smp_done();
104 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700105 case sun4e:
106 printk("SUN4E\n");
107 BUG();
108 break;
109 case sun4u:
110 printk("SUN4U\n");
111 BUG();
112 break;
113 default:
114 printk("UNKNOWN!\n");
115 BUG();
116 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
120void cpu_panic(void)
121{
122 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
123 panic("SMP bolixed\n");
124}
125
Al Viro409832f2008-11-22 17:33:54 +0000126struct linux_prom_registers smp_penguin_ctable __cpuinitdata = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128void smp_send_reschedule(int cpu)
129{
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000130 /*
131 * CPU model dependent way of implementing IPI generation targeting
132 * a single CPU. The trap handler needs only to do trap entry/return
133 * to call schedule.
134 */
135 BTFIXUP_CALL(smp_ipi_resched)(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
138void smp_send_stop(void)
139{
140}
141
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000142void arch_send_call_function_single_ipi(int cpu)
143{
144 /* trigger one IPI single call on one CPU */
145 BTFIXUP_CALL(smp_ipi_single)(cpu);
146}
147
148void arch_send_call_function_ipi_mask(const struct cpumask *mask)
149{
150 int cpu;
151
152 /* trigger IPI mask call on each CPU */
153 for_each_cpu(cpu, mask)
154 BTFIXUP_CALL(smp_ipi_mask_one)(cpu);
155}
156
157void smp_resched_interrupt(void)
158{
David S. Miller90d3ac12011-05-20 13:10:22 -0700159 irq_enter();
160 scheduler_ipi();
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000161 local_cpu_data().irq_resched_count++;
David S. Miller90d3ac12011-05-20 13:10:22 -0700162 irq_exit();
163 /* re-schedule routine called by interrupt return code. */
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000164}
165
166void smp_call_function_single_interrupt(void)
167{
168 irq_enter();
169 generic_smp_call_function_single_interrupt();
170 local_cpu_data().irq_call_count++;
171 irq_exit();
172}
173
174void smp_call_function_interrupt(void)
175{
176 irq_enter();
177 generic_smp_call_function_interrupt();
178 local_cpu_data().irq_call_count++;
179 irq_exit();
180}
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182void smp_flush_cache_all(void)
183{
184 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
185 local_flush_cache_all();
186}
187
188void smp_flush_tlb_all(void)
189{
190 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
191 local_flush_tlb_all();
192}
193
194void smp_flush_cache_mm(struct mm_struct *mm)
195{
196 if(mm->context != NO_CONTEXT) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700197 cpumask_t cpu_mask;
198 cpumask_copy(&cpu_mask, mm_cpumask(mm));
199 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
200 if (!cpumask_empty(&cpu_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
202 local_flush_cache_mm(mm);
203 }
204}
205
206void smp_flush_tlb_mm(struct mm_struct *mm)
207{
208 if(mm->context != NO_CONTEXT) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700209 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)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
214 if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
Rusty Russell81f1adf2009-03-16 14:40:39 +1030215 cpumask_copy(mm_cpumask(mm),
216 cpumask_of(smp_processor_id()));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 }
218 local_flush_tlb_mm(mm);
219 }
220}
221
222void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
223 unsigned long end)
224{
225 struct mm_struct *mm = vma->vm_mm;
226
227 if (mm->context != NO_CONTEXT) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700228 cpumask_t cpu_mask;
229 cpumask_copy(&cpu_mask, mm_cpumask(mm));
230 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
231 if (!cpumask_empty(&cpu_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
233 local_flush_cache_range(vma, start, end);
234 }
235}
236
237void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
238 unsigned long end)
239{
240 struct mm_struct *mm = vma->vm_mm;
241
242 if (mm->context != NO_CONTEXT) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700243 cpumask_t cpu_mask;
244 cpumask_copy(&cpu_mask, mm_cpumask(mm));
245 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
246 if (!cpumask_empty(&cpu_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
248 local_flush_tlb_range(vma, start, end);
249 }
250}
251
252void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
253{
254 struct mm_struct *mm = vma->vm_mm;
255
256 if(mm->context != NO_CONTEXT) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700257 cpumask_t cpu_mask;
258 cpumask_copy(&cpu_mask, mm_cpumask(mm));
259 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
260 if (!cpumask_empty(&cpu_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
262 local_flush_cache_page(vma, page);
263 }
264}
265
266void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
267{
268 struct mm_struct *mm = vma->vm_mm;
269
270 if(mm->context != NO_CONTEXT) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700271 cpumask_t cpu_mask;
272 cpumask_copy(&cpu_mask, mm_cpumask(mm));
273 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
274 if (!cpumask_empty(&cpu_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
276 local_flush_tlb_page(vma, page);
277 }
278}
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280void smp_flush_page_to_ram(unsigned long page)
281{
282 /* Current theory is that those who call this are the one's
283 * who have just dirtied their cache with the pages contents
284 * in kernel space, therefore we only run this on local cpu.
285 *
286 * XXX This experiment failed, research further... -DaveM
287 */
288#if 1
289 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
290#endif
291 local_flush_page_to_ram(page);
292}
293
294void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
295{
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700296 cpumask_t cpu_mask;
297 cpumask_copy(&cpu_mask, mm_cpumask(mm));
298 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
299 if (!cpumask_empty(&cpu_mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
301 local_flush_sig_insns(mm, insn_addr);
302}
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304int setup_profiling_timer(unsigned int multiplier)
305{
Tkhai Kirill62f08282012-04-04 21:49:26 +0200306 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Bob Breuera54123e2006-03-23 22:36:19 -0800309void __init smp_prepare_cpus(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Al Virob4cff842007-02-01 13:52:33 +0000311 extern void __init smp4m_boot_cpus(void);
312 extern void __init smp4d_boot_cpus(void);
Bob Breuer7202fb42006-06-20 00:30:31 -0700313 int i, cpuid, extra;
Bob Breuera54123e2006-03-23 22:36:19 -0800314
Bob Breuera54123e2006-03-23 22:36:19 -0800315 printk("Entering SMP Mode...\n");
316
Bob Breuera54123e2006-03-23 22:36:19 -0800317 extra = 0;
318 for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
Bob Breuer7202fb42006-06-20 00:30:31 -0700319 if (cpuid >= NR_CPUS)
Bob Breuera54123e2006-03-23 22:36:19 -0800320 extra++;
321 }
Bob Breuer7202fb42006-06-20 00:30:31 -0700322 /* i = number of cpus */
323 if (extra && max_cpus > i - extra)
Bob Breuera54123e2006-03-23 22:36:19 -0800324 printk("Warning: NR_CPUS is too low to start all cpus\n");
325
326 smp_store_cpu_info(boot_cpu_id);
327
Raymond Burns8b3c8482006-07-17 21:57:09 -0700328 switch(sparc_cpu_model) {
329 case sun4:
330 printk("SUN4\n");
331 BUG();
332 break;
333 case sun4c:
334 printk("SUN4C\n");
335 BUG();
336 break;
337 case sun4m:
338 smp4m_boot_cpus();
339 break;
340 case sun4d:
341 smp4d_boot_cpus();
342 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000343 case sparc_leon:
344 leon_boot_cpus();
345 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700346 case sun4e:
347 printk("SUN4E\n");
348 BUG();
349 break;
350 case sun4u:
351 printk("SUN4U\n");
352 BUG();
353 break;
354 default:
355 printk("UNKNOWN!\n");
356 BUG();
357 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Bob Breuer7202fb42006-06-20 00:30:31 -0700361/* Set this up early so that things like the scheduler can init
362 * properly. We use the same cpu mask for both the present and
363 * possible cpu map.
364 */
365void __init smp_setup_cpu_possible_map(void)
366{
367 int instance, mid;
368
369 instance = 0;
370 while (!cpu_find_by_instance(instance, NULL, &mid)) {
371 if (mid < NR_CPUS) {
Rusty Russellfe739712009-03-16 14:40:22 +1030372 set_cpu_possible(mid, true);
373 set_cpu_present(mid, true);
Bob Breuer7202fb42006-06-20 00:30:31 -0700374 }
375 instance++;
376 }
377}
378
Bob Breuer92d452f2006-06-20 00:36:10 -0700379void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Bob Breuera54123e2006-03-23 22:36:19 -0800381 int cpuid = hard_smp_processor_id();
382
383 if (cpuid >= NR_CPUS) {
384 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
385 prom_halt();
386 }
387 if (cpuid != 0)
388 printk("boot cpu id != 0, this could work but is untested\n");
389
390 current_thread_info()->cpu = cpuid;
Rusty Russellfe739712009-03-16 14:40:22 +1030391 set_cpu_online(cpuid, true);
392 set_cpu_possible(cpuid, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
Bob Breuer92d452f2006-06-20 00:36:10 -0700395int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Al Virob4cff842007-02-01 13:52:33 +0000397 extern int __cpuinit smp4m_boot_one_cpu(int);
398 extern int __cpuinit smp4d_boot_one_cpu(int);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700399 int ret=0;
Bob Breuera54123e2006-03-23 22:36:19 -0800400
Raymond Burns8b3c8482006-07-17 21:57:09 -0700401 switch(sparc_cpu_model) {
402 case sun4:
403 printk("SUN4\n");
404 BUG();
405 break;
406 case sun4c:
407 printk("SUN4C\n");
408 BUG();
409 break;
410 case sun4m:
411 ret = smp4m_boot_one_cpu(cpu);
412 break;
413 case sun4d:
414 ret = smp4d_boot_one_cpu(cpu);
415 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000416 case sparc_leon:
417 ret = leon_boot_one_cpu(cpu);
418 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700419 case sun4e:
420 printk("SUN4E\n");
421 BUG();
422 break;
423 case sun4u:
424 printk("SUN4U\n");
425 BUG();
426 break;
427 default:
428 printk("UNKNOWN!\n");
429 BUG();
430 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000431 }
Bob Breuera54123e2006-03-23 22:36:19 -0800432
433 if (!ret) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700434 cpumask_set_cpu(cpu, &smp_commenced_mask);
Bob Breuera54123e2006-03-23 22:36:19 -0800435 while (!cpu_online(cpu))
436 mb();
437 }
438 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
441void smp_bogo(struct seq_file *m)
442{
443 int i;
444
Andrew Morton394e3902006-03-23 03:01:05 -0800445 for_each_online_cpu(i) {
446 seq_printf(m,
447 "Cpu%dBogo\t: %lu.%02lu\n",
448 i,
449 cpu_data(i).udelay_val/(500000/HZ),
450 (cpu_data(i).udelay_val/(5000/HZ))%100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
452}
453
454void smp_info(struct seq_file *m)
455{
456 int i;
457
458 seq_printf(m, "State:\n");
Andrew Morton394e3902006-03-23 03:01:05 -0800459 for_each_online_cpu(i)
460 seq_printf(m, "CPU%d\t\t: online\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}