blob: 57713758079e89435415cd69e475d7c9b3994ad3 [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
Sam Ravnborg4ba22b12012-05-14 15:14:36 +020043const struct sparc32_ipi_ops *sparc32_ipi_ops;
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/* The only guaranteed locking primitive available on all Sparc
46 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
47 * places the current byte at the effective address into dest_reg and
48 * places 0xff there afterwards. Pretty lame locking primitive
49 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
50 * instruction which is much better...
51 */
52
Bob Breuer92d452f2006-06-20 00:36:10 -070053void __cpuinit smp_store_cpu_info(int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 int cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070056 int mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 cpu_data(id).udelay_val = loops_per_jiffy;
59
60 cpu_find_by_mid(id, &cpu_node);
61 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
62 "clock-frequency", 0);
63 cpu_data(id).prom_node = cpu_node;
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070064 mid = cpu_get_hwmid(cpu_node);
Krzysztof Helt650fb832006-06-10 22:03:43 -070065
Sam Ravnborgf486b3d2011-04-21 16:35:46 -070066 if (mid < 0) {
67 printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08d", id, cpu_node);
68 mid = 0;
69 }
70 cpu_data(id).mid = mid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
73void __init smp_cpus_done(unsigned int max_cpus)
74{
Bob Breuera54123e2006-03-23 22:36:19 -080075 extern void smp4m_smp_done(void);
Raymond Burns8b3c8482006-07-17 21:57:09 -070076 extern void smp4d_smp_done(void);
Bob Breuera54123e2006-03-23 22:36:19 -080077 unsigned long bogosum = 0;
Rusty Russellec7c14b2009-03-16 14:40:24 +103078 int cpu, num = 0;
Bob Breuera54123e2006-03-23 22:36:19 -080079
Rusty Russellec7c14b2009-03-16 14:40:24 +103080 for_each_online_cpu(cpu) {
81 num++;
82 bogosum += cpu_data(cpu).udelay_val;
83 }
Bob Breuera54123e2006-03-23 22:36:19 -080084
85 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
86 num, bogosum/(500000/HZ),
87 (bogosum/(5000/HZ))%100);
88
Raymond Burns8b3c8482006-07-17 21:57:09 -070089 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -070090 case sun4m:
91 smp4m_smp_done();
92 break;
93 case sun4d:
94 smp4d_smp_done();
95 break;
Konrad Eisele84017072009-08-31 22:08:13 +000096 case sparc_leon:
97 leon_smp_done();
98 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -070099 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;
Joe Perches6cb79b32011-06-03 14:45:23 +0000111 }
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{
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000124 /*
125 * CPU model dependent way of implementing IPI generation targeting
126 * a single CPU. The trap handler needs only to do trap entry/return
127 * to call schedule.
128 */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200129 sparc32_ipi_ops->resched(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
132void smp_send_stop(void)
133{
134}
135
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000136void arch_send_call_function_single_ipi(int cpu)
137{
138 /* trigger one IPI single call on one CPU */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200139 sparc32_ipi_ops->single(cpu);
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000140}
141
142void arch_send_call_function_ipi_mask(const struct cpumask *mask)
143{
144 int cpu;
145
146 /* trigger IPI mask call on each CPU */
147 for_each_cpu(cpu, mask)
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200148 sparc32_ipi_ops->mask_one(cpu);
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000149}
150
151void smp_resched_interrupt(void)
152{
David S. Miller90d3ac12011-05-20 13:10:22 -0700153 irq_enter();
154 scheduler_ipi();
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000155 local_cpu_data().irq_resched_count++;
David S. Miller90d3ac12011-05-20 13:10:22 -0700156 irq_exit();
157 /* re-schedule routine called by interrupt return code. */
Daniel Hellstromd6d04812011-05-02 00:08:51 +0000158}
159
160void smp_call_function_single_interrupt(void)
161{
162 irq_enter();
163 generic_smp_call_function_single_interrupt();
164 local_cpu_data().irq_call_count++;
165 irq_exit();
166}
167
168void smp_call_function_interrupt(void)
169{
170 irq_enter();
171 generic_smp_call_function_interrupt();
172 local_cpu_data().irq_call_count++;
173 irq_exit();
174}
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176int setup_profiling_timer(unsigned int multiplier)
177{
Tkhai Kirill62f08282012-04-04 21:49:26 +0200178 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180
Bob Breuera54123e2006-03-23 22:36:19 -0800181void __init smp_prepare_cpus(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Al Virob4cff842007-02-01 13:52:33 +0000183 extern void __init smp4m_boot_cpus(void);
184 extern void __init smp4d_boot_cpus(void);
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
Bob Breuer92d452f2006-06-20 00:36:10 -0700259int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Al Virob4cff842007-02-01 13:52:33 +0000261 extern int __cpuinit smp4m_boot_one_cpu(int);
262 extern int __cpuinit smp4d_boot_one_cpu(int);
Raymond Burns8b3c8482006-07-17 21:57:09 -0700263 int ret=0;
Bob Breuera54123e2006-03-23 22:36:19 -0800264
Raymond Burns8b3c8482006-07-17 21:57:09 -0700265 switch(sparc_cpu_model) {
Raymond Burns8b3c8482006-07-17 21:57:09 -0700266 case sun4m:
267 ret = smp4m_boot_one_cpu(cpu);
268 break;
269 case sun4d:
270 ret = smp4d_boot_one_cpu(cpu);
271 break;
Konrad Eisele84017072009-08-31 22:08:13 +0000272 case sparc_leon:
273 ret = leon_boot_one_cpu(cpu);
274 break;
Raymond Burns8b3c8482006-07-17 21:57:09 -0700275 case sun4e:
276 printk("SUN4E\n");
277 BUG();
278 break;
279 case sun4u:
280 printk("SUN4U\n");
281 BUG();
282 break;
283 default:
284 printk("UNKNOWN!\n");
285 BUG();
286 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000287 }
Bob Breuera54123e2006-03-23 22:36:19 -0800288
289 if (!ret) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700290 cpumask_set_cpu(cpu, &smp_commenced_mask);
Bob Breuera54123e2006-03-23 22:36:19 -0800291 while (!cpu_online(cpu))
292 mb();
293 }
294 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
297void smp_bogo(struct seq_file *m)
298{
299 int i;
300
Andrew Morton394e3902006-03-23 03:01:05 -0800301 for_each_online_cpu(i) {
302 seq_printf(m,
303 "Cpu%dBogo\t: %lu.%02lu\n",
304 i,
305 cpu_data(i).udelay_val/(500000/HZ),
306 (cpu_data(i).udelay_val/(5000/HZ))%100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308}
309
310void smp_info(struct seq_file *m)
311{
312 int i;
313
314 seq_printf(m, "State:\n");
Andrew Morton394e3902006-03-23 03:01:05 -0800315 for_each_online_cpu(i)
316 seq_printf(m, "CPU%d\t\t: online\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}