1 /* smp.c: Sparc SMP support.
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)
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/threads.h>
13 #include <linux/smp.h>
14 #include <linux/interrupt.h>
15 #include <linux/kernel_stat.h>
16 #include <linux/init.h>
17 #include <linux/spinlock.h>
20 #include <linux/seq_file.h>
21 #include <linux/cache.h>
22 #include <linux/delay.h>
23 #include <linux/cpu.h>
25 #include <asm/ptrace.h>
26 #include <linux/atomic.h>
30 #include <asm/pgalloc.h>
31 #include <asm/pgtable.h>
32 #include <asm/oplib.h>
33 #include <asm/cacheflush.h>
34 #include <asm/tlbflush.h>
35 #include <asm/cpudata.h>
36 #include <asm/timer.h>
42 volatile unsigned long cpu_callin_map
[NR_CPUS
] = {0,};
44 cpumask_t smp_commenced_mask
= CPU_MASK_NONE
;
46 const struct sparc32_ipi_ops
*sparc32_ipi_ops
;
48 /* The only guaranteed locking primitive available on all Sparc
49 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
50 * places the current byte at the effective address into dest_reg and
51 * places 0xff there afterwards. Pretty lame locking primitive
52 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
53 * instruction which is much better...
56 void smp_store_cpu_info(int id
)
61 cpu_data(id
).udelay_val
= loops_per_jiffy
;
63 cpu_find_by_mid(id
, &cpu_node
);
64 cpu_data(id
).clock_tick
= prom_getintdefault(cpu_node
,
65 "clock-frequency", 0);
66 cpu_data(id
).prom_node
= cpu_node
;
67 mid
= cpu_get_hwmid(cpu_node
);
70 printk(KERN_NOTICE
"No MID found for CPU%d at node 0x%08d", id
, cpu_node
);
73 cpu_data(id
).mid
= mid
;
76 void __init
smp_cpus_done(unsigned int max_cpus
)
78 extern void smp4m_smp_done(void);
79 extern void smp4d_smp_done(void);
80 unsigned long bogosum
= 0;
83 for_each_online_cpu(cpu
) {
85 bogosum
+= cpu_data(cpu
).udelay_val
;
88 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
89 num
, bogosum
/(500000/HZ
),
90 (bogosum
/(5000/HZ
))%100);
92 switch(sparc_cpu_model
) {
111 printk("UNKNOWN!\n");
119 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
120 panic("SMP bolixed\n");
123 struct linux_prom_registers smp_penguin_ctable
= { 0 };
125 void smp_send_reschedule(int cpu
)
128 * CPU model dependent way of implementing IPI generation targeting
129 * a single CPU. The trap handler needs only to do trap entry/return
132 sparc32_ipi_ops
->resched(cpu
);
135 void smp_send_stop(void)
139 void arch_send_call_function_single_ipi(int cpu
)
141 /* trigger one IPI single call on one CPU */
142 sparc32_ipi_ops
->single(cpu
);
145 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
149 /* trigger IPI mask call on each CPU */
150 for_each_cpu(cpu
, mask
)
151 sparc32_ipi_ops
->mask_one(cpu
);
154 void smp_resched_interrupt(void)
158 local_cpu_data().irq_resched_count
++;
160 /* re-schedule routine called by interrupt return code. */
163 void smp_call_function_single_interrupt(void)
166 generic_smp_call_function_single_interrupt();
167 local_cpu_data().irq_call_count
++;
171 void smp_call_function_interrupt(void)
174 generic_smp_call_function_interrupt();
175 local_cpu_data().irq_call_count
++;
179 int setup_profiling_timer(unsigned int multiplier
)
184 void __init
smp_prepare_cpus(unsigned int max_cpus
)
186 extern void __init
smp4m_boot_cpus(void);
187 extern void __init
smp4d_boot_cpus(void);
190 printk("Entering SMP Mode...\n");
193 for (i
= 0; !cpu_find_by_instance(i
, NULL
, &cpuid
); i
++) {
194 if (cpuid
>= NR_CPUS
)
197 /* i = number of cpus */
198 if (extra
&& max_cpus
> i
- extra
)
199 printk("Warning: NR_CPUS is too low to start all cpus\n");
201 smp_store_cpu_info(boot_cpu_id
);
203 switch(sparc_cpu_model
) {
222 printk("UNKNOWN!\n");
228 /* Set this up early so that things like the scheduler can init
229 * properly. We use the same cpu mask for both the present and
232 void __init
smp_setup_cpu_possible_map(void)
237 while (!cpu_find_by_instance(instance
, NULL
, &mid
)) {
239 set_cpu_possible(mid
, true);
240 set_cpu_present(mid
, true);
246 void __init
smp_prepare_boot_cpu(void)
248 int cpuid
= hard_smp_processor_id();
250 if (cpuid
>= NR_CPUS
) {
251 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
255 printk("boot cpu id != 0, this could work but is untested\n");
257 current_thread_info()->cpu
= cpuid
;
258 set_cpu_online(cpuid
, true);
259 set_cpu_possible(cpuid
, true);
262 int __cpu_up(unsigned int cpu
, struct task_struct
*tidle
)
264 extern int smp4m_boot_one_cpu(int, struct task_struct
*);
265 extern int smp4d_boot_one_cpu(int, struct task_struct
*);
268 switch(sparc_cpu_model
) {
270 ret
= smp4m_boot_one_cpu(cpu
, tidle
);
273 ret
= smp4d_boot_one_cpu(cpu
, tidle
);
276 ret
= leon_boot_one_cpu(cpu
, tidle
);
287 printk("UNKNOWN!\n");
293 cpumask_set_cpu(cpu
, &smp_commenced_mask
);
294 while (!cpu_online(cpu
))
300 void arch_cpu_pre_starting(void *arg
)
302 local_ops
->cache_all();
303 local_ops
->tlb_all();
305 switch(sparc_cpu_model
) {
307 sun4m_cpu_pre_starting(arg
);
310 sun4d_cpu_pre_starting(arg
);
313 leon_cpu_pre_starting(arg
);
320 void arch_cpu_pre_online(void *arg
)
322 unsigned int cpuid
= hard_smp_processor_id();
324 register_percpu_ce(cpuid
);
327 smp_store_cpu_info(cpuid
);
329 local_ops
->cache_all();
330 local_ops
->tlb_all();
332 switch(sparc_cpu_model
) {
334 sun4m_cpu_pre_online(arg
);
337 sun4d_cpu_pre_online(arg
);
340 leon_cpu_pre_online(arg
);
347 void sparc_start_secondary(void *arg
)
352 * SMP booting is extremely fragile in some architectures. So run
353 * the cpu initialization code first before anything else.
355 arch_cpu_pre_starting(arg
);
358 cpu
= smp_processor_id();
360 /* Invoke the CPU_STARTING notifier callbacks */
361 notify_cpu_starting(cpu
);
363 arch_cpu_pre_online(arg
);
365 /* Set the CPU in the cpu_online_mask */
366 set_cpu_online(cpu
, true);
368 /* Enable local interrupts now */
372 cpu_startup_entry(CPUHP_ONLINE
);
374 /* We should never reach here! */
378 void smp_callin(void)
380 sparc_start_secondary(NULL
);
383 void smp_bogo(struct seq_file
*m
)
387 for_each_online_cpu(i
) {
389 "Cpu%dBogo\t: %lu.%02lu\n",
391 cpu_data(i
).udelay_val
/(500000/HZ
),
392 (cpu_data(i
).udelay_val
/(5000/HZ
))%100);
396 void smp_info(struct seq_file
*m
)
400 seq_printf(m
, "State:\n");
401 for_each_online_cpu(i
)
402 seq_printf(m
, "CPU%d\t\t: online\n", i
);