aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel/sun4d_smp.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc/kernel/sun4d_smp.c')
-rw-r--r--arch/sparc/kernel/sun4d_smp.c267
1 files changed, 149 insertions, 118 deletions
diff --git a/arch/sparc/kernel/sun4d_smp.c b/arch/sparc/kernel/sun4d_smp.c
index 482f2ab92692..133387980b56 100644
--- a/arch/sparc/kernel/sun4d_smp.c
+++ b/arch/sparc/kernel/sun4d_smp.c
@@ -1,4 +1,4 @@
1/* sun4d_smp.c: Sparc SS1000/SC2000 SMP support. 1/* Sparc SS1000/SC2000 SMP support.
2 * 2 *
3 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 3 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
4 * 4 *
@@ -6,59 +6,23 @@
6 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 6 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 */ 7 */
8 8
9#include <asm/head.h>
10
11#include <linux/kernel.h>
12#include <linux/sched.h>
13#include <linux/threads.h>
14#include <linux/smp.h>
15#include <linux/interrupt.h> 9#include <linux/interrupt.h>
16#include <linux/kernel_stat.h>
17#include <linux/init.h>
18#include <linux/spinlock.h>
19#include <linux/mm.h>
20#include <linux/swap.h>
21#include <linux/profile.h> 10#include <linux/profile.h>
22#include <linux/delay.h> 11#include <linux/delay.h>
23#include <linux/cpu.h> 12#include <linux/cpu.h>
24 13
25#include <asm/ptrace.h>
26#include <asm/atomic.h>
27#include <asm/irq_regs.h>
28
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/sbi.h> 14#include <asm/sbi.h>
15#include <asm/mmu.h>
35#include <asm/tlbflush.h> 16#include <asm/tlbflush.h>
36#include <asm/cacheflush.h> 17#include <asm/cacheflush.h>
37#include <asm/cpudata.h>
38 18
19#include "kernel.h"
39#include "irq.h" 20#include "irq.h"
40#define IRQ_CROSS_CALL 15
41 21
42extern ctxd_t *srmmu_ctx_table_phys; 22#define IRQ_CROSS_CALL 15
43 23
44static volatile int smp_processors_ready = 0; 24static volatile int smp_processors_ready;
45static int smp_highest_cpu; 25static int smp_highest_cpu;
46extern volatile unsigned long cpu_callin_map[NR_CPUS];
47extern cpuinfo_sparc cpu_data[NR_CPUS];
48extern unsigned char boot_cpu_id;
49extern volatile int smp_process_available;
50
51extern cpumask_t smp_commenced_mask;
52
53extern int __smp4d_processor_id(void);
54
55/* #define SMP_DEBUG */
56
57#ifdef SMP_DEBUG
58#define SMP_PRINTK(x) printk x
59#else
60#define SMP_PRINTK(x)
61#endif
62 26
63static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned long val) 27static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned long val)
64{ 28{
@@ -68,9 +32,8 @@ static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned lon
68 return val; 32 return val;
69} 33}
70 34
35static void smp4d_ipi_init(void);
71static void smp_setup_percpu_timer(void); 36static void smp_setup_percpu_timer(void);
72extern void cpu_probe(void);
73extern void sun4d_distribute_irqs(void);
74 37
75static unsigned char cpu_leds[32]; 38static unsigned char cpu_leds[32];
76 39
@@ -86,9 +49,8 @@ static inline void show_leds(int cpuid)
86void __cpuinit smp4d_callin(void) 49void __cpuinit smp4d_callin(void)
87{ 50{
88 int cpuid = hard_smp4d_processor_id(); 51 int cpuid = hard_smp4d_processor_id();
89 extern spinlock_t sun4d_imsk_lock;
90 unsigned long flags; 52 unsigned long flags;
91 53
92 /* Show we are alive */ 54 /* Show we are alive */
93 cpu_leds[cpuid] = 0x6; 55 cpu_leds[cpuid] = 0x6;
94 show_leds(cpuid); 56 show_leds(cpuid);
@@ -118,15 +80,13 @@ void __cpuinit smp4d_callin(void)
118 sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1); 80 sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1);
119 local_flush_cache_all(); 81 local_flush_cache_all();
120 local_flush_tlb_all(); 82 local_flush_tlb_all();
121
122 cpu_probe();
123 83
124 while((unsigned long)current_set[cpuid] < PAGE_OFFSET) 84 while ((unsigned long)current_set[cpuid] < PAGE_OFFSET)
125 barrier(); 85 barrier();
126 86
127 while(current_set[cpuid]->cpu != cpuid) 87 while (current_set[cpuid]->cpu != cpuid)
128 barrier(); 88 barrier();
129 89
130 /* Fix idle thread fields. */ 90 /* Fix idle thread fields. */
131 __asm__ __volatile__("ld [%0], %%g6\n\t" 91 __asm__ __volatile__("ld [%0], %%g6\n\t"
132 : : "r" (&current_set[cpuid]) 92 : : "r" (&current_set[cpuid])
@@ -134,17 +94,17 @@ void __cpuinit smp4d_callin(void)
134 94
135 cpu_leds[cpuid] = 0x9; 95 cpu_leds[cpuid] = 0x9;
136 show_leds(cpuid); 96 show_leds(cpuid);
137 97
138 /* Attach to the address space of init_task. */ 98 /* Attach to the address space of init_task. */
139 atomic_inc(&init_mm.mm_count); 99 atomic_inc(&init_mm.mm_count);
140 current->active_mm = &init_mm; 100 current->active_mm = &init_mm;
141 101
142 local_flush_cache_all(); 102 local_flush_cache_all();
143 local_flush_tlb_all(); 103 local_flush_tlb_all();
144 104
145 local_irq_enable(); /* We don't allow PIL 14 yet */ 105 local_irq_enable(); /* We don't allow PIL 14 yet */
146 106
147 while (!cpu_isset(cpuid, smp_commenced_mask)) 107 while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
148 barrier(); 108 barrier();
149 109
150 spin_lock_irqsave(&sun4d_imsk_lock, flags); 110 spin_lock_irqsave(&sun4d_imsk_lock, flags);
@@ -154,17 +114,12 @@ void __cpuinit smp4d_callin(void)
154 114
155} 115}
156 116
157extern void init_IRQ(void);
158extern void cpu_panic(void);
159
160/* 117/*
161 * Cycle through the processors asking the PROM to start each one. 118 * Cycle through the processors asking the PROM to start each one.
162 */ 119 */
163
164extern struct linux_prom_registers smp_penguin_ctable;
165
166void __init smp4d_boot_cpus(void) 120void __init smp4d_boot_cpus(void)
167{ 121{
122 smp4d_ipi_init();
168 if (boot_cpu_id) 123 if (boot_cpu_id)
169 current_set[0] = NULL; 124 current_set[0] = NULL;
170 smp_setup_percpu_timer(); 125 smp_setup_percpu_timer();
@@ -173,43 +128,42 @@ void __init smp4d_boot_cpus(void)
173 128
174int __cpuinit smp4d_boot_one_cpu(int i) 129int __cpuinit smp4d_boot_one_cpu(int i)
175{ 130{
176 extern unsigned long sun4d_cpu_startup; 131 unsigned long *entry = &sun4d_cpu_startup;
177 unsigned long *entry = &sun4d_cpu_startup; 132 struct task_struct *p;
178 struct task_struct *p; 133 int timeout;
179 int timeout; 134 int cpu_node;
180 int cpu_node;
181 135
182 cpu_find_by_instance(i, &cpu_node,NULL); 136 cpu_find_by_instance(i, &cpu_node, NULL);
183 /* Cook up an idler for this guy. */ 137 /* Cook up an idler for this guy. */
184 p = fork_idle(i); 138 p = fork_idle(i);
185 current_set[i] = task_thread_info(p); 139 current_set[i] = task_thread_info(p);
140
141 /*
142 * Initialize the contexts table
143 * Since the call to prom_startcpu() trashes the structure,
144 * we need to re-initialize it for each cpu
145 */
146 smp_penguin_ctable.which_io = 0;
147 smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
148 smp_penguin_ctable.reg_size = 0;
149
150 /* whirrr, whirrr, whirrrrrrrrr... */
151 printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
152 local_flush_cache_all();
153 prom_startcpu(cpu_node,
154 &smp_penguin_ctable, 0, (char *)entry);
155
156 printk(KERN_INFO "prom_startcpu returned :)\n");
157
158 /* wheee... it's going... */
159 for (timeout = 0; timeout < 10000; timeout++) {
160 if (cpu_callin_map[i])
161 break;
162 udelay(200);
163 }
186 164
187 /*
188 * Initialize the contexts table
189 * Since the call to prom_startcpu() trashes the structure,
190 * we need to re-initialize it for each cpu
191 */
192 smp_penguin_ctable.which_io = 0;
193 smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
194 smp_penguin_ctable.reg_size = 0;
195
196 /* whirrr, whirrr, whirrrrrrrrr... */
197 SMP_PRINTK(("Starting CPU %d at %p\n", i, entry));
198 local_flush_cache_all();
199 prom_startcpu(cpu_node,
200 &smp_penguin_ctable, 0, (char *)entry);
201
202 SMP_PRINTK(("prom_startcpu returned :)\n"));
203
204 /* wheee... it's going... */
205 for(timeout = 0; timeout < 10000; timeout++) {
206 if(cpu_callin_map[i])
207 break;
208 udelay(200);
209 }
210
211 if (!(cpu_callin_map[i])) { 165 if (!(cpu_callin_map[i])) {
212 printk("Processor %d is stuck.\n", i); 166 printk(KERN_ERR "Processor %d is stuck.\n", i);
213 return -ENODEV; 167 return -ENODEV;
214 168
215 } 169 }
@@ -237,6 +191,80 @@ void __init smp4d_smp_done(void)
237 sun4d_distribute_irqs(); 191 sun4d_distribute_irqs();
238} 192}
239 193
194/* Memory structure giving interrupt handler information about IPI generated */
195struct sun4d_ipi_work {
196 int single;
197 int msk;
198 int resched;
199};
200
201static DEFINE_PER_CPU_SHARED_ALIGNED(struct sun4d_ipi_work, sun4d_ipi_work);
202
203/* Initialize IPIs on the SUN4D SMP machine */
204static void __init smp4d_ipi_init(void)
205{
206 int cpu;
207 struct sun4d_ipi_work *work;
208
209 printk(KERN_INFO "smp4d: setup IPI at IRQ %d\n", SUN4D_IPI_IRQ);
210
211 for_each_possible_cpu(cpu) {
212 work = &per_cpu(sun4d_ipi_work, cpu);
213 work->single = work->msk = work->resched = 0;
214 }
215}
216
217void sun4d_ipi_interrupt(void)
218{
219 struct sun4d_ipi_work *work = &__get_cpu_var(sun4d_ipi_work);
220
221 if (work->single) {
222 work->single = 0;
223 smp_call_function_single_interrupt();
224 }
225 if (work->msk) {
226 work->msk = 0;
227 smp_call_function_interrupt();
228 }
229 if (work->resched) {
230 work->resched = 0;
231 smp_resched_interrupt();
232 }
233}
234
235static void smp4d_ipi_single(int cpu)
236{
237 struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu);
238
239 /* Mark work */
240 work->single = 1;
241
242 /* Generate IRQ on the CPU */
243 sun4d_send_ipi(cpu, SUN4D_IPI_IRQ);
244}
245
246static void smp4d_ipi_mask_one(int cpu)
247{
248 struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu);
249
250 /* Mark work */
251 work->msk = 1;
252
253 /* Generate IRQ on the CPU */
254 sun4d_send_ipi(cpu, SUN4D_IPI_IRQ);
255}
256
257static void smp4d_ipi_resched(int cpu)
258{
259 struct sun4d_ipi_work *work = &per_cpu(sun4d_ipi_work, cpu);
260
261 /* Mark work */
262 work->resched = 1;
263
264 /* Generate IRQ on the CPU (any IRQ will cause resched) */
265 sun4d_send_ipi(cpu, SUN4D_IPI_IRQ);
266}
267
240static struct smp_funcall { 268static struct smp_funcall {
241 smpfunc_t func; 269 smpfunc_t func;
242 unsigned long arg1; 270 unsigned long arg1;
@@ -255,14 +283,17 @@ static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
255 unsigned long arg2, unsigned long arg3, 283 unsigned long arg2, unsigned long arg3,
256 unsigned long arg4) 284 unsigned long arg4)
257{ 285{
258 if(smp_processors_ready) { 286 if (smp_processors_ready) {
259 register int high = smp_highest_cpu; 287 register int high = smp_highest_cpu;
260 unsigned long flags; 288 unsigned long flags;
261 289
262 spin_lock_irqsave(&cross_call_lock, flags); 290 spin_lock_irqsave(&cross_call_lock, flags);
263 291
264 { 292 {
265 /* If you make changes here, make sure gcc generates proper code... */ 293 /*
294 * If you make changes here, make sure
295 * gcc generates proper code...
296 */
266 register smpfunc_t f asm("i0") = func; 297 register smpfunc_t f asm("i0") = func;
267 register unsigned long a1 asm("i1") = arg1; 298 register unsigned long a1 asm("i1") = arg1;
268 register unsigned long a2 asm("i2") = arg2; 299 register unsigned long a2 asm("i2") = arg2;
@@ -282,10 +313,10 @@ static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
282 { 313 {
283 register int i; 314 register int i;
284 315
285 cpu_clear(smp_processor_id(), mask); 316 cpumask_clear_cpu(smp_processor_id(), &mask);
286 cpus_and(mask, cpu_online_map, mask); 317 cpumask_and(&mask, cpu_online_mask, &mask);
287 for(i = 0; i <= high; i++) { 318 for (i = 0; i <= high; i++) {
288 if (cpu_isset(i, mask)) { 319 if (cpumask_test_cpu(i, &mask)) {
289 ccall_info.processors_in[i] = 0; 320 ccall_info.processors_in[i] = 0;
290 ccall_info.processors_out[i] = 0; 321 ccall_info.processors_out[i] = 0;
291 sun4d_send_ipi(i, IRQ_CROSS_CALL); 322 sun4d_send_ipi(i, IRQ_CROSS_CALL);
@@ -298,19 +329,19 @@ static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
298 329
299 i = 0; 330 i = 0;
300 do { 331 do {
301 if (!cpu_isset(i, mask)) 332 if (!cpumask_test_cpu(i, &mask))
302 continue; 333 continue;
303 while(!ccall_info.processors_in[i]) 334 while (!ccall_info.processors_in[i])
304 barrier(); 335 barrier();
305 } while(++i <= high); 336 } while (++i <= high);
306 337
307 i = 0; 338 i = 0;
308 do { 339 do {
309 if (!cpu_isset(i, mask)) 340 if (!cpumask_test_cpu(i, &mask))
310 continue; 341 continue;
311 while(!ccall_info.processors_out[i]) 342 while (!ccall_info.processors_out[i])
312 barrier(); 343 barrier();
313 } while(++i <= high); 344 } while (++i <= high);
314 } 345 }
315 346
316 spin_unlock_irqrestore(&cross_call_lock, flags); 347 spin_unlock_irqrestore(&cross_call_lock, flags);
@@ -336,7 +367,7 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
336 static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd }; 367 static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd };
337 368
338 old_regs = set_irq_regs(regs); 369 old_regs = set_irq_regs(regs);
339 bw_get_prof_limit(cpu); 370 bw_get_prof_limit(cpu);
340 bw_clear_intr_mask(0, 1); /* INTR_TABLE[0] & 1 is Profile IRQ */ 371 bw_clear_intr_mask(0, 1); /* INTR_TABLE[0] & 1 is Profile IRQ */
341 372
342 cpu_tick[cpu]++; 373 cpu_tick[cpu]++;
@@ -349,7 +380,7 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
349 380
350 profile_tick(CPU_PROFILING); 381 profile_tick(CPU_PROFILING);
351 382
352 if(!--prof_counter(cpu)) { 383 if (!--prof_counter(cpu)) {
353 int user = user_mode(regs); 384 int user = user_mode(regs);
354 385
355 irq_enter(); 386 irq_enter();
@@ -361,8 +392,6 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
361 set_irq_regs(old_regs); 392 set_irq_regs(old_regs);
362} 393}
363 394
364extern unsigned int lvl14_resolution;
365
366static void __cpuinit smp_setup_percpu_timer(void) 395static void __cpuinit smp_setup_percpu_timer(void)
367{ 396{
368 int cpu = hard_smp4d_processor_id(); 397 int cpu = hard_smp4d_processor_id();
@@ -374,16 +403,16 @@ static void __cpuinit smp_setup_percpu_timer(void)
374void __init smp4d_blackbox_id(unsigned *addr) 403void __init smp4d_blackbox_id(unsigned *addr)
375{ 404{
376 int rd = *addr & 0x3e000000; 405 int rd = *addr & 0x3e000000;
377 406
378 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */ 407 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
379 addr[1] = 0x01000000; /* nop */ 408 addr[1] = 0x01000000; /* nop */
380 addr[2] = 0x01000000; /* nop */ 409 addr[2] = 0x01000000; /* nop */
381} 410}
382 411
383void __init smp4d_blackbox_current(unsigned *addr) 412void __init smp4d_blackbox_current(unsigned *addr)
384{ 413{
385 int rd = *addr & 0x3e000000; 414 int rd = *addr & 0x3e000000;
386 415
387 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */ 416 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
388 addr[2] = 0x81282002 | rd | (rd >> 11); /* sll reg, 2, reg */ 417 addr[2] = 0x81282002 | rd | (rd >> 11); /* sll reg, 2, reg */
389 addr[4] = 0x01000000; /* nop */ 418 addr[4] = 0x01000000; /* nop */
@@ -392,17 +421,19 @@ void __init smp4d_blackbox_current(unsigned *addr)
392void __init sun4d_init_smp(void) 421void __init sun4d_init_smp(void)
393{ 422{
394 int i; 423 int i;
395 extern unsigned int t_nmi[], linux_trap_ipi15_sun4d[], linux_trap_ipi15_sun4m[];
396 424
397 /* Patch ipi15 trap table */ 425 /* Patch ipi15 trap table */
398 t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m); 426 t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m);
399 427
400 /* And set btfixup... */ 428 /* And set btfixup... */
401 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id); 429 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id);
402 BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current); 430 BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current);
403 BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM); 431 BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM);
404 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM); 432 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM);
405 433 BTFIXUPSET_CALL(smp_ipi_resched, smp4d_ipi_resched, BTFIXUPCALL_NORM);
434 BTFIXUPSET_CALL(smp_ipi_single, smp4d_ipi_single, BTFIXUPCALL_NORM);
435 BTFIXUPSET_CALL(smp_ipi_mask_one, smp4d_ipi_mask_one, BTFIXUPCALL_NORM);
436
406 for (i = 0; i < NR_CPUS; i++) { 437 for (i = 0; i < NR_CPUS; i++) {
407 ccall_info.processors_in[i] = 1; 438 ccall_info.processors_in[i] = 1;
408 ccall_info.processors_out[i] = 1; 439 ccall_info.processors_out[i] = 1;