blob: fb30e7c6a5b15bac54e052010784327f62290589 [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 Ravnborgd3091292014-05-16 23:26:05 +020023#include <linux/profile.h>
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010024#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/ptrace.h>
Arun Sharma600634972011-07-26 16:09:06 -070027#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include <asm/irq.h>
30#include <asm/page.h>
31#include <asm/pgalloc.h>
32#include <asm/pgtable.h>
33#include <asm/oplib.h>
34#include <asm/cacheflush.h>
35#include <asm/tlbflush.h>
36#include <asm/cpudata.h>
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010037#include <asm/timer.h>
Konrad Eisele84017072009-08-31 22:08:13 +000038#include <asm/leon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010040#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070041#include "irq.h"
42
Paul Gortmaker2066aad2013-06-17 15:43:14 -040043volatile unsigned long cpu_callin_map[NR_CPUS] = {0,};
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Bob Breuera54123e2006-03-23 22:36:19 -080045cpumask_t smp_commenced_mask = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Sam Ravnborg4ba22b12012-05-14 15:14:36 +020047const struct sparc32_ipi_ops *sparc32_ipi_ops;
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/* The only guaranteed locking primitive available on all Sparc
50 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
51 * places the current byte at the effective address into dest_reg and
52 * places 0xff there afterwards. Pretty lame locking primitive
53 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
54 * instruction which is much better...
55 */
56
Paul Gortmaker2066aad2013-06-17 15:43:14 -040057void smp_store_cpu_info(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 int cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070060 int mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 cpu_data(id).udelay_val = loops_per_jiffy;
63
64 cpu_find_by_mid(id, &cpu_node);
65 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
66 "clock-frequency", 0);
67 cpu_data(id).prom_node = cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070068 mid = cpu_get_hwmid(cpu_node);
Krzysztof Helt650fb832006-06-10 22:03:43 -070069
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070070 if (mid < 0) {
Hans Wennborg551d57f2014-08-05 21:41:36 -070071 printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08x", id, cpu_node);
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070072 mid = 0;
73 }
74 cpu_data(id).mid = mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77void __init smp_cpus_done(unsigned int max_cpus)
78{
Bob Breuera54123e2006-03-23 22:36:19 -080079 unsigned long bogosum = 0;
Rusty Russellec7c14b2009-03-16 14:40:24 +103080 int cpu, num = 0;
Bob Breuera54123e2006-03-23 22:36:19 -080081
Rusty Russellec7c14b2009-03-16 14:40:24 +103082 for_each_online_cpu(cpu) {
83 num++;
84 bogosum += cpu_data(cpu).udelay_val;
85 }
Bob Breuera54123e2006-03-23 22:36:19 -080086
87 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
88 num, bogosum/(500000/HZ),
89 (bogosum/(5000/HZ))%100);
90
Raymond Burns8b3c8482006-07-17 21:57:09 -070091 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -070092 case sun4m:
93 smp4m_smp_done();
94 break;
95 case sun4d:
96 smp4d_smp_done();
97 break;
Konrad Eisele84017072009-08-31 22:08:13 +000098 case sparc_leon:
99 leon_smp_done();
100 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700101 case sun4e:
102 printk("SUN4E\n");
103 BUG();
104 break;
105 case sun4u:
106 printk("SUN4U\n");
107 BUG();
108 break;
109 default:
110 printk("UNKNOWN!\n");
111 BUG();
112 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
116void cpu_panic(void)
117{
118 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
119 panic("SMP bolixed\n");
120}
121
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400122struct linux_prom_registers smp_penguin_ctable = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124void smp_send_reschedule(int cpu)
125{
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000126 /*
127 * CPU model dependent way of implementing IPI generation targeting
128 * a single CPU. The trap handler needs only to do trap entry/return
129 * to call schedule.
130 */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200131 sparc32_ipi_ops->resched(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134void smp_send_stop(void)
135{
136}
137
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000138void arch_send_call_function_single_ipi(int cpu)
139{
140 /* trigger one IPI single call on one CPU */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200141 sparc32_ipi_ops->single(cpu);
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000142}
143
144void arch_send_call_function_ipi_mask(const struct cpumask *mask)
145{
146 int cpu;
147
148 /* trigger IPI mask call on each CPU */
149 for_each_cpu(cpu, mask)
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200150 sparc32_ipi_ops->mask_one(cpu);
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000151}
152
153void smp_resched_interrupt(void)
154{
David S. Miller90d3ac12011-05-20 13:10:22 -0700155 irq_enter();
156 scheduler_ipi();
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000157 local_cpu_data().irq_resched_count++;
David S. Miller90d3ac12011-05-20 13:10:22 -0700158 irq_exit();
159 /* re-schedule routine called by interrupt return code. */
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000160}
161
162void smp_call_function_single_interrupt(void)
163{
164 irq_enter();
165 generic_smp_call_function_single_interrupt();
166 local_cpu_data().irq_call_count++;
167 irq_exit();
168}
169
170void smp_call_function_interrupt(void)
171{
172 irq_enter();
173 generic_smp_call_function_interrupt();
174 local_cpu_data().irq_call_count++;
175 irq_exit();
176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178int setup_profiling_timer(unsigned int multiplier)
179{
Tkhai Kirill62f08282012-04-04 21:49:26 +0200180 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
Bob Breuera54123e2006-03-23 22:36:19 -0800183void __init smp_prepare_cpus(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Bob Breuer7202fb42006-06-20 00:30:31 -0700185 int i, cpuid, extra;
Bob Breuera54123e2006-03-23 22:36:19 -0800186
Bob Breuera54123e2006-03-23 22:36:19 -0800187 printk("Entering SMP Mode...\n");
188
Bob Breuera54123e2006-03-23 22:36:19 -0800189 extra = 0;
190 for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
Bob Breuer7202fb42006-06-20 00:30:31 -0700191 if (cpuid >= NR_CPUS)
Bob Breuera54123e2006-03-23 22:36:19 -0800192 extra++;
193 }
Bob Breuer7202fb42006-06-20 00:30:31 -0700194 /* i = number of cpus */
195 if (extra && max_cpus > i - extra)
Bob Breuera54123e2006-03-23 22:36:19 -0800196 printk("Warning: NR_CPUS is too low to start all cpus\n");
197
198 smp_store_cpu_info(boot_cpu_id);
199
Raymond Burns8b3c8482006-07-17 21:57:09 -0700200 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -0700201 case sun4m:
202 smp4m_boot_cpus();
203 break;
204 case sun4d:
205 smp4d_boot_cpus();
206 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000207 case sparc_leon:
208 leon_boot_cpus();
209 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700210 case sun4e:
211 printk("SUN4E\n");
212 BUG();
213 break;
214 case sun4u:
215 printk("SUN4U\n");
216 BUG();
217 break;
218 default:
219 printk("UNKNOWN!\n");
220 BUG();
221 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Bob Breuer7202fb42006-06-20 00:30:31 -0700225/* Set this up early so that things like the scheduler can init
226 * properly. We use the same cpu mask for both the present and
227 * possible cpu map.
228 */
229void __init smp_setup_cpu_possible_map(void)
230{
231 int instance, mid;
232
233 instance = 0;
234 while (!cpu_find_by_instance(instance, NULL, &mid)) {
235 if (mid < NR_CPUS) {
Rusty Russellfe739712009-03-16 14:40:22 +1030236 set_cpu_possible(mid, true);
237 set_cpu_present(mid, true);
Bob Breuer7202fb42006-06-20 00:30:31 -0700238 }
239 instance++;
240 }
241}
242
Bob Breuer92d452f2006-06-20 00:36:10 -0700243void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Bob Breuera54123e2006-03-23 22:36:19 -0800245 int cpuid = hard_smp_processor_id();
246
247 if (cpuid >= NR_CPUS) {
248 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
249 prom_halt();
250 }
251 if (cpuid != 0)
252 printk("boot cpu id != 0, this could work but is untested\n");
253
254 current_thread_info()->cpu = cpuid;
Rusty Russellfe739712009-03-16 14:40:22 +1030255 set_cpu_online(cpuid, true);
256 set_cpu_possible(cpuid, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400259int __cpu_up(unsigned int cpu, struct task_struct *tidle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Raymond Burns8b3c8482006-07-17 21:57:09 -0700261 int ret=0;
Bob Breuera54123e2006-03-23 22:36:19 -0800262
Raymond Burns8b3c8482006-07-17 21:57:09 -0700263 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -0700264 case sun4m:
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +0000265 ret = smp4m_boot_one_cpu(cpu, tidle);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700266 break;
267 case sun4d:
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +0000268 ret = smp4d_boot_one_cpu(cpu, tidle);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700269 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000270 case sparc_leon:
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +0000271 ret = leon_boot_one_cpu(cpu, tidle);
Konrad Eisele84017072009-08-31 22:08:13 +0000272 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700273 case sun4e:
274 printk("SUN4E\n");
275 BUG();
276 break;
277 case sun4u:
278 printk("SUN4U\n");
279 BUG();
280 break;
281 default:
282 printk("UNKNOWN!\n");
283 BUG();
284 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000285 }
Bob Breuera54123e2006-03-23 22:36:19 -0800286
287 if (!ret) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700288 cpumask_set_cpu(cpu, &smp_commenced_mask);
Bob Breuera54123e2006-03-23 22:36:19 -0800289 while (!cpu_online(cpu))
290 mb();
291 }
292 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
Sam Ravnborgc0b0ba82014-04-21 21:39:36 +0200295static void arch_cpu_pre_starting(void *arg)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100296{
297 local_ops->cache_all();
298 local_ops->tlb_all();
299
300 switch(sparc_cpu_model) {
301 case sun4m:
302 sun4m_cpu_pre_starting(arg);
303 break;
304 case sun4d:
305 sun4d_cpu_pre_starting(arg);
306 break;
307 case sparc_leon:
308 leon_cpu_pre_starting(arg);
309 break;
310 default:
311 BUG();
312 }
313}
314
Sam Ravnborgc0b0ba82014-04-21 21:39:36 +0200315static void arch_cpu_pre_online(void *arg)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100316{
317 unsigned int cpuid = hard_smp_processor_id();
318
319 register_percpu_ce(cpuid);
320
321 calibrate_delay();
322 smp_store_cpu_info(cpuid);
323
324 local_ops->cache_all();
325 local_ops->tlb_all();
326
327 switch(sparc_cpu_model) {
328 case sun4m:
329 sun4m_cpu_pre_online(arg);
330 break;
331 case sun4d:
332 sun4d_cpu_pre_online(arg);
333 break;
334 case sparc_leon:
335 leon_cpu_pre_online(arg);
336 break;
337 default:
338 BUG();
339 }
340}
341
Sam Ravnborgc0b0ba82014-04-21 21:39:36 +0200342static void sparc_start_secondary(void *arg)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100343{
344 unsigned int cpu;
345
346 /*
347 * SMP booting is extremely fragile in some architectures. So run
348 * the cpu initialization code first before anything else.
349 */
350 arch_cpu_pre_starting(arg);
351
352 preempt_disable();
353 cpu = smp_processor_id();
354
355 /* Invoke the CPU_STARTING notifier callbacks */
356 notify_cpu_starting(cpu);
357
358 arch_cpu_pre_online(arg);
359
360 /* Set the CPU in the cpu_online_mask */
361 set_cpu_online(cpu, true);
362
363 /* Enable local interrupts now */
364 local_irq_enable();
365
366 wmb();
Thomas Gleixnerfc6d73d2016-02-26 18:43:40 +0000367 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100368
369 /* We should never reach here! */
370 BUG();
371}
372
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400373void smp_callin(void)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +0100374{
375 sparc_start_secondary(NULL);
376}
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378void smp_bogo(struct seq_file *m)
379{
380 int i;
381
Andrew Morton394e3902006-03-23 03:01:05 -0800382 for_each_online_cpu(i) {
383 seq_printf(m,
384 "Cpu%dBogo\t: %lu.%02lu\n",
385 i,
386 cpu_data(i).udelay_val/(500000/HZ),
387 (cpu_data(i).udelay_val/(5000/HZ))%100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389}
390
391void smp_info(struct seq_file *m)
392{
393 int i;
394
395 seq_printf(m, "State:\n");
Andrew Morton394e3902006-03-23 03:01:05 -0800396 for_each_online_cpu(i)
397 seq_printf(m, "CPU%d\t\t: online\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}