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>
24 #include <asm/ptrace.h>
25 #include <linux/atomic.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>
39 volatile unsigned long cpu_callin_map[NR_CPUS] __cpuinitdata = {0,};
41 cpumask_t smp_commenced_mask = CPU_MASK_NONE;
43 /* The only guaranteed locking primitive available on all Sparc
44 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
45 * places the current byte at the effective address into dest_reg and
46 * places 0xff there afterwards. Pretty lame locking primitive
47 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
48 * instruction which is much better...
51 void __cpuinit smp_store_cpu_info(int id)
56 cpu_data(id).udelay_val = loops_per_jiffy;
58 cpu_find_by_mid(id, &cpu_node);
59 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
60 "clock-frequency", 0);
61 cpu_data(id).prom_node = cpu_node;
62 mid = cpu_get_hwmid(cpu_node);
65 printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08d", id, cpu_node);
68 cpu_data(id).mid = mid;
71 void __init smp_cpus_done(unsigned int max_cpus)
73 extern void smp4m_smp_done(void);
74 extern void smp4d_smp_done(void);
75 unsigned long bogosum = 0;
78 for_each_online_cpu(cpu) {
80 bogosum += cpu_data(cpu).udelay_val;
83 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
84 num, bogosum/(500000/HZ),
85 (bogosum/(5000/HZ))%100);
87 switch(sparc_cpu_model) {
106 printk("UNKNOWN!\n");
114 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
115 panic("SMP bolixed\n");
118 struct linux_prom_registers smp_penguin_ctable __cpuinitdata = { 0 };
120 void smp_send_reschedule(int cpu)
123 * CPU model dependent way of implementing IPI generation targeting
124 * a single CPU. The trap handler needs only to do trap entry/return
127 BTFIXUP_CALL(smp_ipi_resched)(cpu);
130 void smp_send_stop(void)
134 void arch_send_call_function_single_ipi(int cpu)
136 /* trigger one IPI single call on one CPU */
137 BTFIXUP_CALL(smp_ipi_single)(cpu);
140 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
144 /* trigger IPI mask call on each CPU */
145 for_each_cpu(cpu, mask)
146 BTFIXUP_CALL(smp_ipi_mask_one)(cpu);
149 void smp_resched_interrupt(void)
153 local_cpu_data().irq_resched_count++;
155 /* re-schedule routine called by interrupt return code. */
158 void smp_call_function_single_interrupt(void)
161 generic_smp_call_function_single_interrupt();
162 local_cpu_data().irq_call_count++;
166 void smp_call_function_interrupt(void)
169 generic_smp_call_function_interrupt();
170 local_cpu_data().irq_call_count++;
174 int setup_profiling_timer(unsigned int multiplier)
179 void __init smp_prepare_cpus(unsigned int max_cpus)
181 extern void __init smp4m_boot_cpus(void);
182 extern void __init smp4d_boot_cpus(void);
185 printk("Entering SMP Mode...\n");
188 for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
189 if (cpuid >= NR_CPUS)
192 /* i = number of cpus */
193 if (extra && max_cpus > i - extra)
194 printk("Warning: NR_CPUS is too low to start all cpus\n");
196 smp_store_cpu_info(boot_cpu_id);
198 switch(sparc_cpu_model) {
217 printk("UNKNOWN!\n");
223 /* Set this up early so that things like the scheduler can init
224 * properly. We use the same cpu mask for both the present and
227 void __init smp_setup_cpu_possible_map(void)
232 while (!cpu_find_by_instance(instance, NULL, &mid)) {
234 set_cpu_possible(mid, true);
235 set_cpu_present(mid, true);
241 void __init smp_prepare_boot_cpu(void)
243 int cpuid = hard_smp_processor_id();
245 if (cpuid >= NR_CPUS) {
246 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
250 printk("boot cpu id != 0, this could work but is untested\n");
252 current_thread_info()->cpu = cpuid;
253 set_cpu_online(cpuid, true);
254 set_cpu_possible(cpuid, true);
257 int __cpuinit __cpu_up(unsigned int cpu)
259 extern int __cpuinit smp4m_boot_one_cpu(int);
260 extern int __cpuinit smp4d_boot_one_cpu(int);
263 switch(sparc_cpu_model) {
265 ret = smp4m_boot_one_cpu(cpu);
268 ret = smp4d_boot_one_cpu(cpu);
271 ret = leon_boot_one_cpu(cpu);
282 printk("UNKNOWN!\n");
288 cpumask_set_cpu(cpu, &smp_commenced_mask);
289 while (!cpu_online(cpu))
295 void smp_bogo(struct seq_file *m)
299 for_each_online_cpu(i) {
301 "Cpu%dBogo\t: %lu.%02lu\n",
303 cpu_data(i).udelay_val/(500000/HZ),
304 (cpu_data(i).udelay_val/(5000/HZ))%100);
308 void smp_info(struct seq_file *m)
312 seq_printf(m, "State:\n");
313 for_each_online_cpu(i)
314 seq_printf(m, "CPU%d\t\t: online\n", i);