blob: a102bfba6ea866e2495e52647b845b4333d32e98 [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>
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010023#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include <asm/ptrace.h>
Arun Sharma600634972011-07-26 16:09:06 -070026#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <asm/irq.h>
29#include <asm/page.h>
30#include <asm/pgalloc.h>
31#include <asm/pgtable.h>
32#include <asm/oplib.h>
33#include <asm/cacheflush.h>
34#include <asm/tlbflush.h>
35#include <asm/cpudata.h>
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010036#include <asm/timer.h>
Konrad Eisele84017072009-08-31 22:08:13 +000037#include <asm/leon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010039#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070040#include "irq.h"
41
Paul Gortmaker2066aad2013-06-17 15:43:14 -040042volatile unsigned long cpu_callin_map[NR_CPUS] = {0,};
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Bob Breuera54123e2006-03-23 22:36:19 -080044cpumask_t smp_commenced_mask = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Sam Ravnborg4ba22b12012-05-14 15:14:36 +020046const struct sparc32_ipi_ops *sparc32_ipi_ops;
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* The only guaranteed locking primitive available on all Sparc
49 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
50 * places the current byte at the effective address into dest_reg and
51 * places 0xff there afterwards. Pretty lame locking primitive
52 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
53 * instruction which is much better...
54 */
55
Paul Gortmaker2066aad2013-06-17 15:43:14 -040056void smp_store_cpu_info(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 int cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070059 int mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 cpu_data(id).udelay_val = loops_per_jiffy;
62
63 cpu_find_by_mid(id, &cpu_node);
64 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
65 "clock-frequency", 0);
66 cpu_data(id).prom_node = cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070067 mid = cpu_get_hwmid(cpu_node);
Krzysztof Helt650fb832006-06-10 22:03:43 -070068
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070069 if (mid < 0) {
70 printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08d", id, cpu_node);
71 mid = 0;
72 }
73 cpu_data(id).mid = mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
76void __init smp_cpus_done(unsigned int max_cpus)
77{
Bob Breuera54123e2006-03-23 22:36:19 -080078 extern void smp4m_smp_done(void);
Raymond Burns8b3c8482006-07-17 21:57:09 -070079 extern void smp4d_smp_done(void);
Bob Breuera54123e2006-03-23 22:36:19 -080080 unsigned long bogosum = 0;
Rusty Russellec7c14b2009-03-16 14:40:24 +103081 int cpu, num = 0;
Bob Breuera54123e2006-03-23 22:36:19 -080082
Rusty Russellec7c14b2009-03-16 14:40:24 +103083 for_each_online_cpu(cpu) {
84 num++;
85 bogosum += cpu_data(cpu).udelay_val;
86 }
Bob Breuera54123e2006-03-23 22:36:19 -080087
88 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
89 num, bogosum/(500000/HZ),
90 (bogosum/(5000/HZ))%100);
91
Raymond Burns8b3c8482006-07-17 21:57:09 -070092 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -070093 case sun4m:
94 smp4m_smp_done();
95 break;
96 case sun4d:
97 smp4d_smp_done();
98 break;
Konrad Eisele84017072009-08-31 22:08:13 +000099 case sparc_leon:
100 leon_smp_done();
101 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700102 case sun4e:
103 printk("SUN4E\n");
104 BUG();
105 break;
106 case sun4u:
107 printk("SUN4U\n");
108 BUG();
109 break;
110 default:
111 printk("UNKNOWN!\n");
112 BUG();
113 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115}
116
117void cpu_panic(void)
118{
119 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
120 panic("SMP bolixed\n");
121}
122
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400123struct linux_prom_registers smp_penguin_ctable = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125void smp_send_reschedule(int cpu)
126{
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000127 /*
128 * CPU model dependent way of implementing IPI generation targeting
129 * a single CPU. The trap handler needs only to do trap entry/return
130 * to call schedule.
131 */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200132 sparc32_ipi_ops->resched(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
135void smp_send_stop(void)
136{
137}
138
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000139void arch_send_call_function_single_ipi(int cpu)
140{
141 /* trigger one IPI single call on one CPU */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200142 sparc32_ipi_ops->single(cpu);
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000143}
144
145void arch_send_call_function_ipi_mask(const struct cpumask *mask)
146{
147 int cpu;
148
149 /* trigger IPI mask call on each CPU */
150 for_each_cpu(cpu, mask)
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200151 sparc32_ipi_ops->mask_one(cpu);
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000152}
153
154void smp_resched_interrupt(void)
155{
David S. Miller90d3ac12011-05-20 13:10:22 -0700156 irq_enter();
157 scheduler_ipi();
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000158 local_cpu_data().irq_resched_count++;
David S. Miller90d3ac12011-05-20 13:10:22 -0700159 irq_exit();
160 /* re-schedule routine called by interrupt return code. */
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000161}
162
163void smp_call_function_single_interrupt(void)
164{
165 irq_enter();
166 generic_smp_call_function_single_interrupt();
167 local_cpu_data().irq_call_count++;
168 irq_exit();
169}
170
171void smp_call_function_interrupt(void)
172{
173 irq_enter();
174 generic_smp_call_function_interrupt();
175 local_cpu_data().irq_call_count++;
176 irq_exit();
177}
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179int setup_profiling_timer(unsigned int multiplier)
180{
Tkhai Kirill62f08282012-04-04 21:49:26 +0200181 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
Bob Breuera54123e2006-03-23 22:36:19 -0800184void __init smp_prepare_cpus(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Al Virob4cff842007-02-01 13:52:33 +0000186 extern void __init smp4m_boot_cpus(void);
187 extern void __init smp4d_boot_cpus(void);
Bob Breuer7202fb42006-06-20 00:30:31 -0700188 int i, cpuid, extra;
Bob Breuera54123e2006-03-23 22:36:19 -0800189
Bob Breuera54123e2006-03-23 22:36:19 -0800190 printk("Entering SMP Mode...\n");
191
Bob Breuera54123e2006-03-23 22:36:19 -0800192 extra = 0;
193 for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
Bob Breuer7202fb42006-06-20 00:30:31 -0700194 if (cpuid >= NR_CPUS)
Bob Breuera54123e2006-03-23 22:36:19 -0800195 extra++;
196 }
Bob Breuer7202fb42006-06-20 00:30:31 -0700197 /* i = number of cpus */
198 if (extra && max_cpus > i - extra)
Bob Breuera54123e2006-03-23 22:36:19 -0800199 printk("Warning: NR_CPUS is too low to start all cpus\n");
200
201 smp_store_cpu_info(boot_cpu_id);
202
Raymond Burns8b3c8482006-07-17 21:57:09 -0700203 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -0700204 case sun4m:
205 smp4m_boot_cpus();
206 break;
207 case sun4d:
208 smp4d_boot_cpus();
209 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000210 case sparc_leon:
211 leon_boot_cpus();
212 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700213 case sun4e:
214 printk("SUN4E\n");
215 BUG();
216 break;
217 case sun4u:
218 printk("SUN4U\n");
219 BUG();
220 break;
221 default:
222 printk("UNKNOWN!\n");
223 BUG();
224 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Bob Breuer7202fb42006-06-20 00:30:31 -0700228/* Set this up early so that things like the scheduler can init
229 * properly. We use the same cpu mask for both the present and
230 * possible cpu map.
231 */
232void __init smp_setup_cpu_possible_map(void)
233{
234 int instance, mid;
235
236 instance = 0;
237 while (!cpu_find_by_instance(instance, NULL, &mid)) {
238 if (mid < NR_CPUS) {
Rusty Russellfe739712009-03-16 14:40:22 +1030239 set_cpu_possible(mid, true);
240 set_cpu_present(mid, true);
Bob Breuer7202fb42006-06-20 00:30:31 -0700241 }
242 instance++;
243 }
244}
245
Bob Breuer92d452f2006-06-20 00:36:10 -0700246void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Bob Breuera54123e2006-03-23 22:36:19 -0800248 int cpuid = hard_smp_processor_id();
249
250 if (cpuid >= NR_CPUS) {
251 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
252 prom_halt();
253 }
254 if (cpuid != 0)
255 printk("boot cpu id != 0, this could work but is untested\n");
256
257 current_thread_info()->cpu = cpuid;
Rusty Russellfe739712009-03-16 14:40:22 +1030258 set_cpu_online(cpuid, true);
259 set_cpu_possible(cpuid, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400262int __cpu_up(unsigned int cpu, struct task_struct *tidle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400264 extern int smp4m_boot_one_cpu(int, struct task_struct *);
265 extern int smp4d_boot_one_cpu(int, struct task_struct *);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700266 int ret=0;
Bob Breuera54123e2006-03-23 22:36:19 -0800267
Raymond Burns8b3c8482006-07-17 21:57:09 -0700268 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -0700269 case sun4m:
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +0000270 ret = smp4m_boot_one_cpu(cpu, tidle);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700271 break;
272 case sun4d:
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +0000273 ret = smp4d_boot_one_cpu(cpu, tidle);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700274 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000275 case sparc_leon:
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +0000276 ret = leon_boot_one_cpu(cpu, tidle);
Konrad Eisele84017072009-08-31 22:08:13 +0000277 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700278 case sun4e:
279 printk("SUN4E\n");
280 BUG();
281 break;
282 case sun4u:
283 printk("SUN4U\n");
284 BUG();
285 break;
286 default:
287 printk("UNKNOWN!\n");
288 BUG();
289 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000290 }
Bob Breuera54123e2006-03-23 22:36:19 -0800291
292 if (!ret) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700293 cpumask_set_cpu(cpu, &smp_commenced_mask);
Bob Breuera54123e2006-03-23 22:36:19 -0800294 while (!cpu_online(cpu))
295 mb();
296 }
297 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400300void arch_cpu_pre_starting(void *arg)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100301{
302 local_ops->cache_all();
303 local_ops->tlb_all();
304
305 switch(sparc_cpu_model) {
306 case sun4m:
307 sun4m_cpu_pre_starting(arg);
308 break;
309 case sun4d:
310 sun4d_cpu_pre_starting(arg);
311 break;
312 case sparc_leon:
313 leon_cpu_pre_starting(arg);
314 break;
315 default:
316 BUG();
317 }
318}
319
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400320void arch_cpu_pre_online(void *arg)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100321{
322 unsigned int cpuid = hard_smp_processor_id();
323
324 register_percpu_ce(cpuid);
325
326 calibrate_delay();
327 smp_store_cpu_info(cpuid);
328
329 local_ops->cache_all();
330 local_ops->tlb_all();
331
332 switch(sparc_cpu_model) {
333 case sun4m:
334 sun4m_cpu_pre_online(arg);
335 break;
336 case sun4d:
337 sun4d_cpu_pre_online(arg);
338 break;
339 case sparc_leon:
340 leon_cpu_pre_online(arg);
341 break;
342 default:
343 BUG();
344 }
345}
346
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400347void sparc_start_secondary(void *arg)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100348{
349 unsigned int cpu;
350
351 /*
352 * SMP booting is extremely fragile in some architectures. So run
353 * the cpu initialization code first before anything else.
354 */
355 arch_cpu_pre_starting(arg);
356
357 preempt_disable();
358 cpu = smp_processor_id();
359
360 /* Invoke the CPU_STARTING notifier callbacks */
361 notify_cpu_starting(cpu);
362
363 arch_cpu_pre_online(arg);
364
365 /* Set the CPU in the cpu_online_mask */
366 set_cpu_online(cpu, true);
367
368 /* Enable local interrupts now */
369 local_irq_enable();
370
371 wmb();
Sam Ravnborg87fa05a2013-04-11 21:38:50 +0200372 cpu_startup_entry(CPUHP_ONLINE);
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100373
374 /* We should never reach here! */
375 BUG();
376}
377
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400378void smp_callin(void)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100379{
380 sparc_start_secondary(NULL);
381}
382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383void smp_bogo(struct seq_file *m)
384{
385 int i;
386
Andrew Morton394e3902006-03-23 03:01:05 -0800387 for_each_online_cpu(i) {
388 seq_printf(m,
389 "Cpu%dBogo\t: %lu.%02lu\n",
390 i,
391 cpu_data(i).udelay_val/(500000/HZ),
392 (cpu_data(i).udelay_val/(5000/HZ))%100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
394}
395
396void smp_info(struct seq_file *m)
397{
398 int i;
399
400 seq_printf(m, "State:\n");
Andrew Morton394e3902006-03-23 03:01:05 -0800401 for_each_online_cpu(i)
402 seq_printf(m, "CPU%d\t\t: online\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}