blob: be1ae37e7733b3281d6697ed02116bac3d4aa0f2 [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>
25#include <asm/atomic.h>
26
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>
35
Al Viro32231a62007-07-21 19:18:57 -070036#include "irq.h"
37
Al Viro409832f2008-11-22 17:33:54 +000038volatile unsigned long cpu_callin_map[NR_CPUS] __cpuinitdata = {0,};
Linus Torvalds1da177e2005-04-16 15:20:36 -070039unsigned char boot_cpu_id = 0;
40unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Bob Breuera54123e2006-03-23 22:36:19 -080042cpumask_t smp_commenced_mask = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* The only guaranteed locking primitive available on all Sparc
45 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
46 * places the current byte at the effective address into dest_reg and
47 * places 0xff there afterwards. Pretty lame locking primitive
48 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
49 * instruction which is much better...
50 */
51
Bob Breuer92d452f2006-06-20 00:36:10 -070052void __cpuinit smp_store_cpu_info(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 int cpu_node;
55
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;
62 cpu_data(id).mid = cpu_get_hwmid(cpu_node);
Krzysztof Helt650fb832006-06-10 22:03:43 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 if (cpu_data(id).mid < 0)
65 panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
66}
67
68void __init smp_cpus_done(unsigned int max_cpus)
69{
Bob Breuera54123e2006-03-23 22:36:19 -080070 extern void smp4m_smp_done(void);
Raymond Burns8b3c8482006-07-17 21:57:09 -070071 extern void smp4d_smp_done(void);
Bob Breuera54123e2006-03-23 22:36:19 -080072 unsigned long bogosum = 0;
Rusty Russellec7c14b2009-03-16 14:40:24 +103073 int cpu, num = 0;
Bob Breuera54123e2006-03-23 22:36:19 -080074
Rusty Russellec7c14b2009-03-16 14:40:24 +103075 for_each_online_cpu(cpu) {
76 num++;
77 bogosum += cpu_data(cpu).udelay_val;
78 }
Bob Breuera54123e2006-03-23 22:36:19 -080079
80 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
81 num, bogosum/(500000/HZ),
82 (bogosum/(5000/HZ))%100);
83
Raymond Burns8b3c8482006-07-17 21:57:09 -070084 switch(sparc_cpu_model) {
85 case sun4:
86 printk("SUN4\n");
87 BUG();
88 break;
89 case sun4c:
90 printk("SUN4C\n");
91 BUG();
92 break;
93 case sun4m:
94 smp4m_smp_done();
95 break;
96 case sun4d:
97 smp4d_smp_done();
98 break;
99 case sun4e:
100 printk("SUN4E\n");
101 BUG();
102 break;
103 case sun4u:
104 printk("SUN4U\n");
105 BUG();
106 break;
107 default:
108 printk("UNKNOWN!\n");
109 BUG();
110 break;
111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
114void cpu_panic(void)
115{
116 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
117 panic("SMP bolixed\n");
118}
119
Al Viro409832f2008-11-22 17:33:54 +0000120struct linux_prom_registers smp_penguin_ctable __cpuinitdata = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122void smp_send_reschedule(int cpu)
123{
124 /* See sparc64 */
125}
126
127void smp_send_stop(void)
128{
129}
130
131void smp_flush_cache_all(void)
132{
133 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
134 local_flush_cache_all();
135}
136
137void smp_flush_tlb_all(void)
138{
139 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
140 local_flush_tlb_all();
141}
142
143void smp_flush_cache_mm(struct mm_struct *mm)
144{
145 if(mm->context != NO_CONTEXT) {
146 cpumask_t cpu_mask = mm->cpu_vm_mask;
147 cpu_clear(smp_processor_id(), cpu_mask);
148 if (!cpus_empty(cpu_mask))
149 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
150 local_flush_cache_mm(mm);
151 }
152}
153
154void smp_flush_tlb_mm(struct mm_struct *mm)
155{
156 if(mm->context != NO_CONTEXT) {
157 cpumask_t cpu_mask = mm->cpu_vm_mask;
158 cpu_clear(smp_processor_id(), cpu_mask);
159 if (!cpus_empty(cpu_mask)) {
160 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
161 if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
162 mm->cpu_vm_mask = cpumask_of_cpu(smp_processor_id());
163 }
164 local_flush_tlb_mm(mm);
165 }
166}
167
168void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
169 unsigned long end)
170{
171 struct mm_struct *mm = vma->vm_mm;
172
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 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
178 local_flush_cache_range(vma, start, end);
179 }
180}
181
182void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
183 unsigned long end)
184{
185 struct mm_struct *mm = vma->vm_mm;
186
187 if (mm->context != NO_CONTEXT) {
188 cpumask_t cpu_mask = mm->cpu_vm_mask;
189 cpu_clear(smp_processor_id(), cpu_mask);
190 if (!cpus_empty(cpu_mask))
191 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
192 local_flush_tlb_range(vma, start, end);
193 }
194}
195
196void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
197{
198 struct mm_struct *mm = vma->vm_mm;
199
200 if(mm->context != NO_CONTEXT) {
201 cpumask_t cpu_mask = mm->cpu_vm_mask;
202 cpu_clear(smp_processor_id(), cpu_mask);
203 if (!cpus_empty(cpu_mask))
204 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
205 local_flush_cache_page(vma, page);
206 }
207}
208
209void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
210{
211 struct mm_struct *mm = vma->vm_mm;
212
213 if(mm->context != NO_CONTEXT) {
214 cpumask_t cpu_mask = mm->cpu_vm_mask;
215 cpu_clear(smp_processor_id(), cpu_mask);
216 if (!cpus_empty(cpu_mask))
217 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
218 local_flush_tlb_page(vma, page);
219 }
220}
221
222void smp_reschedule_irq(void)
223{
224 set_need_resched();
225}
226
227void smp_flush_page_to_ram(unsigned long page)
228{
229 /* Current theory is that those who call this are the one's
230 * who have just dirtied their cache with the pages contents
231 * in kernel space, therefore we only run this on local cpu.
232 *
233 * XXX This experiment failed, research further... -DaveM
234 */
235#if 1
236 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
237#endif
238 local_flush_page_to_ram(page);
239}
240
241void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
242{
243 cpumask_t cpu_mask = mm->cpu_vm_mask;
244 cpu_clear(smp_processor_id(), cpu_mask);
245 if (!cpus_empty(cpu_mask))
246 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
247 local_flush_sig_insns(mm, insn_addr);
248}
249
250extern unsigned int lvl14_resolution;
251
252/* /proc/profile writes can call this, don't __init it please. */
253static DEFINE_SPINLOCK(prof_setup_lock);
254
255int setup_profiling_timer(unsigned int multiplier)
256{
257 int i;
258 unsigned long flags;
259
260 /* Prevent level14 ticker IRQ flooding. */
261 if((!multiplier) || (lvl14_resolution / multiplier) < 500)
262 return -EINVAL;
263
264 spin_lock_irqsave(&prof_setup_lock, flags);
KAMEZAWA Hiroyukifff8efe2006-04-10 22:52:51 -0700265 for_each_possible_cpu(i) {
Andrew Morton394e3902006-03-23 03:01:05 -0800266 load_profile_irq(i, lvl14_resolution / multiplier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 prof_multiplier(i) = multiplier;
268 }
269 spin_unlock_irqrestore(&prof_setup_lock, flags);
270
271 return 0;
272}
273
Bob Breuera54123e2006-03-23 22:36:19 -0800274void __init smp_prepare_cpus(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Al Virob4cff842007-02-01 13:52:33 +0000276 extern void __init smp4m_boot_cpus(void);
277 extern void __init smp4d_boot_cpus(void);
Bob Breuer7202fb42006-06-20 00:30:31 -0700278 int i, cpuid, extra;
Bob Breuera54123e2006-03-23 22:36:19 -0800279
Bob Breuera54123e2006-03-23 22:36:19 -0800280 printk("Entering SMP Mode...\n");
281
Bob Breuera54123e2006-03-23 22:36:19 -0800282 extra = 0;
283 for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
Bob Breuer7202fb42006-06-20 00:30:31 -0700284 if (cpuid >= NR_CPUS)
Bob Breuera54123e2006-03-23 22:36:19 -0800285 extra++;
286 }
Bob Breuer7202fb42006-06-20 00:30:31 -0700287 /* i = number of cpus */
288 if (extra && max_cpus > i - extra)
Bob Breuera54123e2006-03-23 22:36:19 -0800289 printk("Warning: NR_CPUS is too low to start all cpus\n");
290
291 smp_store_cpu_info(boot_cpu_id);
292
Raymond Burns8b3c8482006-07-17 21:57:09 -0700293 switch(sparc_cpu_model) {
294 case sun4:
295 printk("SUN4\n");
296 BUG();
297 break;
298 case sun4c:
299 printk("SUN4C\n");
300 BUG();
301 break;
302 case sun4m:
303 smp4m_boot_cpus();
304 break;
305 case sun4d:
306 smp4d_boot_cpus();
307 break;
308 case sun4e:
309 printk("SUN4E\n");
310 BUG();
311 break;
312 case sun4u:
313 printk("SUN4U\n");
314 BUG();
315 break;
316 default:
317 printk("UNKNOWN!\n");
318 BUG();
319 break;
320 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
Bob Breuer7202fb42006-06-20 00:30:31 -0700323/* Set this up early so that things like the scheduler can init
324 * properly. We use the same cpu mask for both the present and
325 * possible cpu map.
326 */
327void __init smp_setup_cpu_possible_map(void)
328{
329 int instance, mid;
330
331 instance = 0;
332 while (!cpu_find_by_instance(instance, NULL, &mid)) {
333 if (mid < NR_CPUS) {
Rusty Russellfe739712009-03-16 14:40:22 +1030334 set_cpu_possible(mid, true);
335 set_cpu_present(mid, true);
Bob Breuer7202fb42006-06-20 00:30:31 -0700336 }
337 instance++;
338 }
339}
340
Bob Breuer92d452f2006-06-20 00:36:10 -0700341void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Bob Breuera54123e2006-03-23 22:36:19 -0800343 int cpuid = hard_smp_processor_id();
344
345 if (cpuid >= NR_CPUS) {
346 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
347 prom_halt();
348 }
349 if (cpuid != 0)
350 printk("boot cpu id != 0, this could work but is untested\n");
351
352 current_thread_info()->cpu = cpuid;
Rusty Russellfe739712009-03-16 14:40:22 +1030353 set_cpu_online(cpuid, true);
354 set_cpu_possible(cpuid, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
Bob Breuer92d452f2006-06-20 00:36:10 -0700357int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Al Virob4cff842007-02-01 13:52:33 +0000359 extern int __cpuinit smp4m_boot_one_cpu(int);
360 extern int __cpuinit smp4d_boot_one_cpu(int);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700361 int ret=0;
Bob Breuera54123e2006-03-23 22:36:19 -0800362
Raymond Burns8b3c8482006-07-17 21:57:09 -0700363 switch(sparc_cpu_model) {
364 case sun4:
365 printk("SUN4\n");
366 BUG();
367 break;
368 case sun4c:
369 printk("SUN4C\n");
370 BUG();
371 break;
372 case sun4m:
373 ret = smp4m_boot_one_cpu(cpu);
374 break;
375 case sun4d:
376 ret = smp4d_boot_one_cpu(cpu);
377 break;
378 case sun4e:
379 printk("SUN4E\n");
380 BUG();
381 break;
382 case sun4u:
383 printk("SUN4U\n");
384 BUG();
385 break;
386 default:
387 printk("UNKNOWN!\n");
388 BUG();
389 break;
390 };
Bob Breuera54123e2006-03-23 22:36:19 -0800391
392 if (!ret) {
393 cpu_set(cpu, smp_commenced_mask);
394 while (!cpu_online(cpu))
395 mb();
396 }
397 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
400void smp_bogo(struct seq_file *m)
401{
402 int i;
403
Andrew Morton394e3902006-03-23 03:01:05 -0800404 for_each_online_cpu(i) {
405 seq_printf(m,
406 "Cpu%dBogo\t: %lu.%02lu\n",
407 i,
408 cpu_data(i).udelay_val/(500000/HZ),
409 (cpu_data(i).udelay_val/(5000/HZ))%100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411}
412
413void smp_info(struct seq_file *m)
414{
415 int i;
416
417 seq_printf(m, "State:\n");
Andrew Morton394e3902006-03-23 03:01:05 -0800418 for_each_online_cpu(i)
419 seq_printf(m, "CPU%d\t\t: online\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}