Skip to content

Commit aba1030

Browse files
committed
sh: Bring SMP support back from the dead.
There was a very preliminary bunch of SMP code scattered around for the SH7604 microcontrollers from way back when, and it has mostly suffered bitrot since then. With the tree already having been slowly getting prepped for SMP, this plugs in most of the remaining platform-independent bits. Signed-off-by: Magnus Damm <damm@igel.co.jp> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent f18d533 commit aba1030

6 files changed

Lines changed: 142 additions & 99 deletions

File tree

‎arch/sh/kernel/cpu/init.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <asm/cache.h>
2323
#include <asm/io.h>
2424
#include <asm/ubc.h>
25+
#include <asm/smp.h>
2526

2627
/*
2728
* Generic wrapper for command line arguments to disable on-chip
@@ -216,8 +217,11 @@ static void __init dsp_init(void)
216217
* Each processor family is still responsible for doing its own probing
217218
* and cache configuration in detect_cpu_and_cache_system().
218219
*/
219-
asmlinkage void __init sh_cpu_init(void)
220+
221+
asmlinkage void __cpuinit sh_cpu_init(void)
220222
{
223+
current_thread_info()->cpu = hard_smp_processor_id();
224+
221225
/* First, probe the CPU */
222226
detect_cpu_and_cache_system();
223227

@@ -227,9 +231,10 @@ asmlinkage void __init sh_cpu_init(void)
227231
/* Init the cache */
228232
cache_init();
229233

230-
shm_align_mask = max_t(unsigned long,
231-
current_cpu_data.dcache.way_size - 1,
232-
PAGE_SIZE - 1);
234+
if (raw_smp_processor_id() == 0)
235+
shm_align_mask = max_t(unsigned long,
236+
current_cpu_data.dcache.way_size - 1,
237+
PAGE_SIZE - 1);
233238

234239
/* Disable the FPU */
235240
if (fpu_disabled) {
@@ -268,6 +273,7 @@ asmlinkage void __init sh_cpu_init(void)
268273
* like PTRACE_SINGLESTEP or doing hardware watchpoints in GDB. So ..
269274
* we wake it up and hope that all is well.
270275
*/
271-
ubc_wakeup();
276+
if (raw_smp_processor_id() == 0)
277+
ubc_wakeup();
272278
speculative_execution_init();
273279
}

‎arch/sh/kernel/head.S‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ ENTRY(_stext)
5454
mov.l 1f, r0 ! MD=1, RB=0, BL=0, IMASK=0xF
5555
ldc r0, sr
5656
! Initialize global interrupt mask
57-
mov #0, r0
5857
#ifdef CONFIG_CPU_HAS_SR_RB
58+
mov #0, r0
5959
ldc r0, r6_bank
6060
#endif
6161
@@ -72,15 +72,18 @@ ENTRY(_stext)
7272
!
7373
mov.l 2f, r0
7474
mov r0, r15 ! Set initial r15 (stack pointer)
75-
mov #(THREAD_SIZE >> 10), r1
76-
shll8 r1 ! r1 = THREAD_SIZE
77-
shll2 r1
78-
sub r1, r0 !
7975
#ifdef CONFIG_CPU_HAS_SR_RB
76+
mov.l 7f, r0
8077
ldc r0, r7_bank ! ... and initial thread_info
8178
#endif
8279
8380
! Clear BSS area
81+
#ifdef CONFIG_SMP
82+
mov.l 3f, r0
83+
cmp/eq #0, r0 ! skip clear if set to zero
84+
bt 10f
85+
#endif
86+
8487
mov.l 3f, r1
8588
add #4, r1
8689
mov.l 4f, r2
@@ -89,13 +92,14 @@ ENTRY(_stext)
8992
bf/s 9b ! while (r1 < r2)
9093
mov.l r0,@-r2
9194

95+
10:
9296
! Additional CPU initialization
9397
mov.l 6f, r0
9498
jsr @r0
9599
nop
96100

97101
SYNCO() ! Wait for pending instructions..
98-
102+
99103
! Start kernel
100104
mov.l 5f, r0
101105
jmp @r0
@@ -107,8 +111,10 @@ ENTRY(_stext)
107111
#else
108112
1: .long 0x400080F0 ! MD=1, RB=0, BL=0, FD=1, IMASK=0xF
109113
#endif
114+
ENTRY(stack_start)
110115
2: .long init_thread_union+THREAD_SIZE
111116
3: .long __bss_start
112117
4: .long _end
113118
5: .long start_kernel
114119
6: .long sh_cpu_init
120+
7: .long init_thread_union

‎arch/sh/kernel/smp.c‎

Lines changed: 92 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,40 @@
33
*
44
* SMP support for the SuperH processors.
55
*
6-
* Copyright (C) 2002, 2003 Paul Mundt
6+
* Copyright (C) 2002 - 2007 Paul Mundt
7+
* Copyright (C) 2006 - 2007 Akio Idehara
78
*
8-
* This program is free software; you can redistribute it and/or modify it
9-
* under the terms of the GNU General Public License as published by the
10-
* Free Software Foundation; either version 2 of the License, or (at your
11-
* option) any later version.
9+
* This file is subject to the terms and conditions of the GNU General Public
10+
* License. See the file "COPYING" in the main directory of this archive
11+
* for more details.
1212
*/
13-
1413
#include <linux/err.h>
1514
#include <linux/cache.h>
1615
#include <linux/cpumask.h>
1716
#include <linux/delay.h>
1817
#include <linux/init.h>
19-
#include <linux/interrupt.h>
2018
#include <linux/spinlock.h>
21-
#include <linux/threads.h>
19+
#include <linux/mm.h>
2220
#include <linux/module.h>
23-
#include <linux/time.h>
24-
#include <linux/timex.h>
25-
#include <linux/sched.h>
26-
#include <linux/module.h>
27-
21+
#include <linux/interrupt.h>
2822
#include <asm/atomic.h>
2923
#include <asm/processor.h>
3024
#include <asm/system.h>
3125
#include <asm/mmu_context.h>
3226
#include <asm/smp.h>
27+
#include <asm/cacheflush.h>
28+
#include <asm/sections.h>
3329

34-
/*
35-
* This was written with the Sega Saturn (SMP SH-2 7604) in mind,
36-
* but is designed to be usable regardless if there's an MMU
37-
* present or not.
38-
*/
39-
struct sh_cpuinfo cpu_data[NR_CPUS];
40-
41-
extern void per_cpu_trap_init(void);
30+
int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
31+
int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
4232

4333
cpumask_t cpu_possible_map;
4434
EXPORT_SYMBOL(cpu_possible_map);
4535

4636
cpumask_t cpu_online_map;
4737
EXPORT_SYMBOL(cpu_online_map);
48-
static atomic_t cpus_booted = ATOMIC_INIT(0);
49-
50-
/* These are defined by the board-specific code. */
5138

52-
/*
53-
* Cause the function described by call_data to be executed on the passed
54-
* cpu. When the function has finished, increment the finished field of
55-
* call_data.
56-
*/
57-
void __smp_send_ipi(unsigned int cpu, unsigned int action);
58-
59-
/*
60-
* Find the number of available processors
61-
*/
62-
unsigned int __smp_probe_cpus(void);
63-
64-
/*
65-
* Start a particular processor
66-
*/
67-
void __smp_slave_init(unsigned int cpu);
39+
static atomic_t cpus_booted = ATOMIC_INIT(0);
6840

6941
/*
7042
* Run specified function on a particular processor.
@@ -73,74 +45,123 @@ void __smp_call_function(unsigned int cpu);
7345

7446
static inline void __init smp_store_cpu_info(unsigned int cpu)
7547
{
76-
cpu_data[cpu].loops_per_jiffy = loops_per_jiffy;
48+
struct sh_cpuinfo *c = cpu_data + cpu;
49+
50+
c->loops_per_jiffy = loops_per_jiffy;
7751
}
7852

7953
void __init smp_prepare_cpus(unsigned int max_cpus)
8054
{
8155
unsigned int cpu = smp_processor_id();
82-
int i;
8356

84-
atomic_set(&cpus_booted, 1);
85-
smp_store_cpu_info(cpu);
86-
87-
for (i = 0; i < __smp_probe_cpus(); i++)
88-
cpu_set(i, cpu_possible_map);
57+
init_new_context(current, &init_mm);
58+
current_thread_info()->cpu = cpu;
59+
plat_prepare_cpus(max_cpus);
60+
61+
#ifndef CONFIG_HOTPLUG_CPU
62+
cpu_present_map = cpu_possible_map;
63+
#endif
8964
}
9065

9166
void __devinit smp_prepare_boot_cpu(void)
9267
{
9368
unsigned int cpu = smp_processor_id();
9469

70+
__cpu_number_map[0] = cpu;
71+
__cpu_logical_map[0] = cpu;
72+
9573
cpu_set(cpu, cpu_online_map);
9674
cpu_set(cpu, cpu_possible_map);
9775
}
9876

99-
int __cpu_up(unsigned int cpu)
77+
asmlinkage void __cpuinit start_secondary(void)
10078
{
101-
struct task_struct *tsk;
79+
unsigned int cpu;
80+
struct mm_struct *mm = &init_mm;
10281

103-
tsk = fork_idle(cpu);
82+
atomic_inc(&mm->mm_count);
83+
atomic_inc(&mm->mm_users);
84+
current->active_mm = mm;
85+
BUG_ON(current->mm);
86+
enter_lazy_tlb(mm, current);
87+
88+
per_cpu_trap_init();
10489

105-
if (IS_ERR(tsk))
106-
panic("Failed forking idle task for cpu %d\n", cpu);
107-
108-
task_thread_info(tsk)->cpu = cpu;
90+
preempt_disable();
91+
92+
local_irq_enable();
93+
94+
calibrate_delay();
95+
96+
cpu = smp_processor_id();
97+
smp_store_cpu_info(cpu);
10998

11099
cpu_set(cpu, cpu_online_map);
111100

112-
return 0;
101+
cpu_idle();
113102
}
114103

115-
int start_secondary(void *unused)
104+
extern struct {
105+
unsigned long sp;
106+
unsigned long bss_start;
107+
unsigned long bss_end;
108+
void *start_kernel_fn;
109+
void *cpu_init_fn;
110+
void *thread_info;
111+
} stack_start;
112+
113+
int __cpuinit __cpu_up(unsigned int cpu)
116114
{
117-
unsigned int cpu;
115+
struct task_struct *tsk;
116+
unsigned long timeout;
118117

119-
cpu = smp_processor_id();
118+
tsk = fork_idle(cpu);
119+
if (IS_ERR(tsk)) {
120+
printk(KERN_ERR "Failed forking idle task for cpu %d\n", cpu);
121+
return PTR_ERR(tsk);
122+
}
120123

121-
atomic_inc(&init_mm.mm_count);
122-
current->active_mm = &init_mm;
124+
/* Fill in data in head.S for secondary cpus */
125+
stack_start.sp = tsk->thread.sp;
126+
stack_start.thread_info = tsk->stack;
127+
stack_start.bss_start = 0; /* don't clear bss for secondary cpus */
128+
stack_start.start_kernel_fn = start_secondary;
123129

124-
smp_store_cpu_info(cpu);
130+
flush_cache_all();
125131

126-
__smp_slave_init(cpu);
127-
preempt_disable();
128-
per_cpu_trap_init();
129-
130-
atomic_inc(&cpus_booted);
132+
plat_start_cpu(cpu, (unsigned long)_stext);
131133

132-
cpu_idle();
133-
return 0;
134+
timeout = jiffies + HZ;
135+
while (time_before(jiffies, timeout)) {
136+
if (cpu_online(cpu))
137+
break;
138+
139+
udelay(10);
140+
}
141+
142+
if (cpu_online(cpu))
143+
return 0;
144+
145+
return -ENOENT;
134146
}
135147

136148
void __init smp_cpus_done(unsigned int max_cpus)
137149
{
138-
smp_mb();
150+
unsigned long bogosum = 0;
151+
int cpu;
152+
153+
for_each_online_cpu(cpu)
154+
bogosum += cpu_data[cpu].loops_per_jiffy;
155+
156+
printk(KERN_INFO "SMP: Total of %d processors activated "
157+
"(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
158+
bogosum / (500000/HZ),
159+
(bogosum / (5000/HZ)) % 100);
139160
}
140161

141162
void smp_send_reschedule(int cpu)
142163
{
143-
__smp_send_ipi(cpu, SMP_MSG_RESCHEDULE);
164+
plat_send_ipi(cpu, SMP_MSG_RESCHEDULE);
144165
}
145166

146167
static void stop_this_cpu(void *unused)
@@ -157,7 +178,6 @@ void smp_send_stop(void)
157178
smp_call_function(stop_this_cpu, 0, 1, 0);
158179
}
159180

160-
161181
struct smp_fn_call_struct smp_fn_call = {
162182
.lock = SPIN_LOCK_UNLOCKED,
163183
.finished = ATOMIC_INIT(0),
@@ -175,9 +195,6 @@ int smp_call_function(void (*func)(void *info), void *info, int retry, int wait)
175195
unsigned int nr_cpus = atomic_read(&cpus_booted);
176196
int i;
177197

178-
if (nr_cpus < 2)
179-
return 0;
180-
181198
/* Can deadlock when called with interrupts disabled */
182199
WARN_ON(irqs_disabled());
183200

@@ -189,7 +206,7 @@ int smp_call_function(void (*func)(void *info), void *info, int retry, int wait)
189206

190207
for (i = 0; i < nr_cpus; i++)
191208
if (i != smp_processor_id())
192-
__smp_call_function(i);
209+
plat_send_ipi(i, SMP_MSG_FUNCTION);
193210

194211
if (wait)
195212
while (atomic_read(&smp_fn_call.finished) != (nr_cpus - 1));

‎arch/sh/kernel/traps.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,12 +807,13 @@ static inline void __init gdb_vbr_init(void)
807807
}
808808
#endif
809809

810-
void __init per_cpu_trap_init(void)
810+
void __cpuinit per_cpu_trap_init(void)
811811
{
812812
extern void *vbr_base;
813813

814814
#ifdef CONFIG_SH_STANDARD_BIOS
815-
gdb_vbr_init();
815+
if (raw_smp_processor_id() == 0)
816+
gdb_vbr_init();
816817
#endif
817818

818819
/* NOTE: The VBR value should be at P1

0 commit comments

Comments
 (0)