Skip to content

Commit f9fd348

Browse files
sravnborgdavem330
authored andcommitted
sparc32: refactor smp boot
Introduce a common smp_callin() function to call from trampoline_32.S. Add platform specific functions to handle the platform details. This is in preparation for a patch that will unify the smp boot stuff for all architectures. sparc32 was significantly different to warrant this patch in preparation. Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Acked-by: David S. Miller <davem@davemloft.net> Cc: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com> Acked-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 76968ad commit f9fd348

6 files changed

Lines changed: 132 additions & 78 deletions

File tree

‎arch/sparc/kernel/kernel.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ extern void sun4m_init_IRQ(void);
4848
extern void sun4m_unmask_profile_irq(void);
4949
extern void sun4m_clear_profile_irq(int cpu);
5050

51+
/* sun4m_smp.c */
52+
void sun4m_cpu_pre_starting(void *arg);
53+
void sun4m_cpu_pre_online(void *arg);
54+
5155
/* sun4d_irq.c */
5256
extern spinlock_t sun4d_imsk_lock;
5357

@@ -60,6 +64,14 @@ extern int show_sun4d_interrupts(struct seq_file *, void *);
6064
extern void sun4d_distribute_irqs(void);
6165
extern void sun4d_free_irq(unsigned int irq, void *dev_id);
6266

67+
/* sun4d_smp.c */
68+
void sun4d_cpu_pre_starting(void *arg);
69+
void sun4d_cpu_pre_online(void *arg);
70+
71+
/* leon_smp.c */
72+
void leon_cpu_pre_starting(void *arg);
73+
void leon_cpu_pre_online(void *arg);
74+
6375
/* head_32.S */
6476
extern unsigned int t_nmi[];
6577
extern unsigned int linux_trap_ipi15_sun4d[];

‎arch/sparc/kernel/leon_smp.c‎

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,19 @@ static inline unsigned long do_swap(volatile unsigned long *ptr,
6969
return val;
7070
}
7171

72-
void __cpuinit leon_callin(void)
72+
void __cpuinit leon_cpu_pre_starting(void *arg)
7373
{
74-
int cpuid = hard_smp_processor_id();
75-
76-
local_ops->cache_all();
77-
local_ops->tlb_all();
7874
leon_configure_cache_smp();
75+
}
7976

80-
notify_cpu_starting(cpuid);
81-
82-
/* Get our local ticker going. */
83-
register_percpu_ce(cpuid);
84-
85-
calibrate_delay();
86-
smp_store_cpu_info(cpuid);
87-
88-
local_ops->cache_all();
89-
local_ops->tlb_all();
77+
void __cpuinit leon_cpu_pre_online(void *arg)
78+
{
79+
int cpuid = hard_smp_processor_id();
9080

91-
/*
92-
* Unblock the master CPU _only_ when the scheduler state
93-
* of all secondary CPUs will be up-to-date, so after
94-
* the SMP initialization the master will be just allowed
95-
* to call the scheduler code.
96-
* Allow master to continue.
81+
/* Allow master to continue. The master will then give us the
82+
* go-ahead by setting the smp_commenced_mask and will wait without
83+
* timeouts until our setup is completed fully (signified by
84+
* our bit being set in the cpu_online_mask).
9785
*/
9886
do_swap(&cpu_callin_map[cpuid], 1);
9987

@@ -110,9 +98,6 @@ void __cpuinit leon_callin(void)
11098

11199
while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
112100
mb();
113-
114-
local_irq_enable();
115-
set_cpu_online(cpuid, true);
116101
}
117102

118103
/*

‎arch/sparc/kernel/smp_32.c‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/seq_file.h>
2121
#include <linux/cache.h>
2222
#include <linux/delay.h>
23+
#include <linux/cpu.h>
2324

2425
#include <asm/ptrace.h>
2526
#include <linux/atomic.h>
@@ -32,8 +33,10 @@
3233
#include <asm/cacheflush.h>
3334
#include <asm/tlbflush.h>
3435
#include <asm/cpudata.h>
36+
#include <asm/timer.h>
3537
#include <asm/leon.h>
3638

39+
#include "kernel.h"
3740
#include "irq.h"
3841

3942
volatile unsigned long cpu_callin_map[NR_CPUS] __cpuinitdata = {0,};
@@ -294,6 +297,89 @@ int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *tidle)
294297
return ret;
295298
}
296299

300+
void __cpuinit arch_cpu_pre_starting(void *arg)
301+
{
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+
320+
void __cpuinit arch_cpu_pre_online(void *arg)
321+
{
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+
347+
void __cpuinit sparc_start_secondary(void *arg)
348+
{
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();
372+
cpu_idle();
373+
374+
/* We should never reach here! */
375+
BUG();
376+
}
377+
378+
void __cpuinit smp_callin(void)
379+
{
380+
sparc_start_secondary(NULL);
381+
}
382+
297383
void smp_bogo(struct seq_file *m)
298384
{
299385
int i;

‎arch/sparc/kernel/sun4d_smp.c‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,30 @@ static inline void show_leds(int cpuid)
5050
"i" (ASI_M_CTL));
5151
}
5252

53-
void __cpuinit smp4d_callin(void)
53+
void __cpuinit sun4d_cpu_pre_starting(void *arg)
5454
{
5555
int cpuid = hard_smp_processor_id();
56-
unsigned long flags;
5756

5857
/* Show we are alive */
5958
cpu_leds[cpuid] = 0x6;
6059
show_leds(cpuid);
6160

6261
/* Enable level15 interrupt, disable level14 interrupt for now */
6362
cc_set_imsk((cc_get_imsk() & ~0x8000) | 0x4000);
63+
}
6464

65-
local_ops->cache_all();
66-
local_ops->tlb_all();
65+
void __cpuinit sun4d_cpu_pre_online(void *arg)
66+
{
67+
unsigned long flags;
68+
int cpuid;
6769

68-
notify_cpu_starting(cpuid);
69-
/*
70-
* Unblock the master CPU _only_ when the scheduler state
70+
cpuid = hard_smp_processor_id();
71+
72+
/* Unblock the master CPU _only_ when the scheduler state
7173
* of all secondary CPUs will be up-to-date, so after
7274
* the SMP initialization the master will be just allowed
7375
* to call the scheduler code.
7476
*/
75-
/* Get our local ticker going. */
76-
register_percpu_ce(cpuid);
77-
78-
calibrate_delay();
79-
smp_store_cpu_info(cpuid);
80-
local_ops->cache_all();
81-
local_ops->tlb_all();
82-
83-
/* Allow master to continue. */
8477
sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1);
8578
local_ops->cache_all();
8679
local_ops->tlb_all();
@@ -106,16 +99,12 @@ void __cpuinit smp4d_callin(void)
10699
local_ops->cache_all();
107100
local_ops->tlb_all();
108101

109-
local_irq_enable(); /* We don't allow PIL 14 yet */
110-
111102
while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
112103
barrier();
113104

114105
spin_lock_irqsave(&sun4d_imsk_lock, flags);
115106
cc_set_imsk(cc_get_imsk() & ~0x4000); /* Allow PIL 14 as well */
116107
spin_unlock_irqrestore(&sun4d_imsk_lock, flags);
117-
set_cpu_online(cpuid, true);
118-
119108
}
120109

121110
/*

‎arch/sparc/kernel/sun4m_smp.c‎

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,19 @@ swap_ulong(volatile unsigned long *ptr, unsigned long val)
3434
return val;
3535
}
3636

37-
void __cpuinit smp4m_callin(void)
37+
void __cpuinit sun4m_cpu_pre_starting(void *arg)
3838
{
39-
int cpuid = hard_smp_processor_id();
40-
41-
local_ops->cache_all();
42-
local_ops->tlb_all();
43-
44-
notify_cpu_starting(cpuid);
45-
46-
register_percpu_ce(cpuid);
47-
48-
calibrate_delay();
49-
smp_store_cpu_info(cpuid);
39+
}
5040

51-
local_ops->cache_all();
52-
local_ops->tlb_all();
41+
void __cpuinit sun4m_cpu_pre_online(void *arg)
42+
{
43+
int cpuid = hard_smp_processor_id();
5344

54-
/*
55-
* Unblock the master CPU _only_ when the scheduler state
56-
* of all secondary CPUs will be up-to-date, so after
57-
* the SMP initialization the master will be just allowed
58-
* to call the scheduler code.
45+
/* Allow master to continue. The master will then give us the
46+
* go-ahead by setting the smp_commenced_mask and will wait without
47+
* timeouts until our setup is completed fully (signified by
48+
* our bit being set in the cpu_online_mask).
5949
*/
60-
/* Allow master to continue. */
6150
swap_ulong(&cpu_callin_map[cpuid], 1);
6251

6352
/* XXX: What's up with all the flushes? */
@@ -75,10 +64,6 @@ void __cpuinit smp4m_callin(void)
7564

7665
while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
7766
mb();
78-
79-
local_irq_enable();
80-
81-
set_cpu_online(cpuid, true);
8267
}
8368

8469
/*

‎arch/sparc/kernel/trampoline_32.S‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@ cpu3_startup:
7979
nop
8080

8181
/* Start this processor. */
82-
call smp4m_callin
82+
call smp_callin
8383
nop
8484

85-
b,a smp_do_cpu_idle
85+
b,a smp_panic
8686

8787
.text
8888
.align 4
8989

90-
smp_do_cpu_idle:
91-
call cpu_idle
92-
mov 0, %o0
93-
90+
smp_panic:
9491
call cpu_panic
9592
nop
9693

@@ -144,10 +141,10 @@ sun4d_cpu_startup:
144141
nop
145142

146143
/* Start this processor. */
147-
call smp4d_callin
144+
call smp_callin
148145
nop
149146

150-
b,a smp_do_cpu_idle
147+
b,a smp_panic
151148

152149
__CPUINIT
153150
.align 4
@@ -201,7 +198,7 @@ leon_smp_cpu_startup:
201198
nop
202199

203200
/* Start this processor. */
204-
call leon_callin
201+
call smp_callin
205202
nop
206203

207-
b,a smp_do_cpu_idle
204+
b,a smp_panic

0 commit comments

Comments
 (0)