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 <asm/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>
38 volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,};
39 unsigned char boot_cpu_id = 0;
40 unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
42 cpumask_t cpu_online_map = CPU_MASK_NONE;
43 cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
44 cpumask_t smp_commenced_mask = CPU_MASK_NONE;
46 /* The only guaranteed locking primitive available on all Sparc
47 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
48 * places the current byte at the effective address into dest_reg and
49 * places 0xff there afterwards. Pretty lame locking primitive
50 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
51 * instruction which is much better...
54 void __cpuinit smp_store_cpu_info(int id)
58 cpu_data(id).udelay_val = loops_per_jiffy;
60 cpu_find_by_mid(id, &cpu_node);
61 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
62 "clock-frequency", 0);
63 cpu_data(id).prom_node = cpu_node;
64 cpu_data(id).mid = cpu_get_hwmid(cpu_node);
66 if (cpu_data(id).mid < 0)
67 panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
70 void __init smp_cpus_done(unsigned int max_cpus)
72 extern void smp4m_smp_done(void);
73 extern void smp4d_smp_done(void);
74 unsigned long bogosum = 0;
77 for (cpu = 0, num = 0; cpu < NR_CPUS; cpu++)
78 if (cpu_online(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) {
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 __initdata = { 0 };
125 void smp_send_reschedule(int cpu)
130 void smp_send_stop(void)
134 void smp_flush_cache_all(void)
136 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
137 local_flush_cache_all();
140 void smp_flush_tlb_all(void)
142 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
143 local_flush_tlb_all();
146 void smp_flush_cache_mm(struct mm_struct *mm)
148 if(mm->context != NO_CONTEXT) {
149 cpumask_t cpu_mask = mm->cpu_vm_mask;
150 cpu_clear(smp_processor_id(), cpu_mask);
151 if (!cpus_empty(cpu_mask))
152 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
153 local_flush_cache_mm(mm);
157 void smp_flush_tlb_mm(struct mm_struct *mm)
159 if(mm->context != NO_CONTEXT) {
160 cpumask_t cpu_mask = mm->cpu_vm_mask;
161 cpu_clear(smp_processor_id(), cpu_mask);
162 if (!cpus_empty(cpu_mask)) {
163 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
164 if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
165 mm->cpu_vm_mask = cpumask_of_cpu(smp_processor_id());
167 local_flush_tlb_mm(mm);
171 void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
174 struct mm_struct *mm = vma->vm_mm;
176 if (mm->context != NO_CONTEXT) {
177 cpumask_t cpu_mask = mm->cpu_vm_mask;
178 cpu_clear(smp_processor_id(), cpu_mask);
179 if (!cpus_empty(cpu_mask))
180 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
181 local_flush_cache_range(vma, start, end);
185 void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
188 struct mm_struct *mm = vma->vm_mm;
190 if (mm->context != NO_CONTEXT) {
191 cpumask_t cpu_mask = mm->cpu_vm_mask;
192 cpu_clear(smp_processor_id(), cpu_mask);
193 if (!cpus_empty(cpu_mask))
194 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
195 local_flush_tlb_range(vma, start, end);
199 void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
201 struct mm_struct *mm = vma->vm_mm;
203 if(mm->context != NO_CONTEXT) {
204 cpumask_t cpu_mask = mm->cpu_vm_mask;
205 cpu_clear(smp_processor_id(), cpu_mask);
206 if (!cpus_empty(cpu_mask))
207 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
208 local_flush_cache_page(vma, page);
212 void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
214 struct mm_struct *mm = vma->vm_mm;
216 if(mm->context != NO_CONTEXT) {
217 cpumask_t cpu_mask = mm->cpu_vm_mask;
218 cpu_clear(smp_processor_id(), cpu_mask);
219 if (!cpus_empty(cpu_mask))
220 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
221 local_flush_tlb_page(vma, page);
225 void smp_reschedule_irq(void)
230 void smp_flush_page_to_ram(unsigned long page)
232 /* Current theory is that those who call this are the one's
233 * who have just dirtied their cache with the pages contents
234 * in kernel space, therefore we only run this on local cpu.
236 * XXX This experiment failed, research further... -DaveM
239 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
241 local_flush_page_to_ram(page);
244 void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
246 cpumask_t cpu_mask = mm->cpu_vm_mask;
247 cpu_clear(smp_processor_id(), cpu_mask);
248 if (!cpus_empty(cpu_mask))
249 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
250 local_flush_sig_insns(mm, insn_addr);
253 extern unsigned int lvl14_resolution;
255 /* /proc/profile writes can call this, don't __init it please. */
256 static DEFINE_SPINLOCK(prof_setup_lock);
258 int setup_profiling_timer(unsigned int multiplier)
263 /* Prevent level14 ticker IRQ flooding. */
264 if((!multiplier) || (lvl14_resolution / multiplier) < 500)
267 spin_lock_irqsave(&prof_setup_lock, flags);
268 for_each_possible_cpu(i) {
269 load_profile_irq(i, lvl14_resolution / multiplier);
270 prof_multiplier(i) = multiplier;
272 spin_unlock_irqrestore(&prof_setup_lock, flags);
277 void __init smp_prepare_cpus(unsigned int max_cpus)
279 extern void __init smp4m_boot_cpus(void);
280 extern void __init smp4d_boot_cpus(void);
283 printk("Entering SMP Mode...\n");
286 for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
287 if (cpuid >= NR_CPUS)
290 /* i = number of cpus */
291 if (extra && max_cpus > i - extra)
292 printk("Warning: NR_CPUS is too low to start all cpus\n");
294 smp_store_cpu_info(boot_cpu_id);
296 switch(sparc_cpu_model) {
320 printk("UNKNOWN!\n");
326 /* Set this up early so that things like the scheduler can init
327 * properly. We use the same cpu mask for both the present and
330 void __init smp_setup_cpu_possible_map(void)
335 while (!cpu_find_by_instance(instance, NULL, &mid)) {
337 cpu_set(mid, phys_cpu_present_map);
338 cpu_set(mid, cpu_present_map);
344 void __init smp_prepare_boot_cpu(void)
346 int cpuid = hard_smp_processor_id();
348 if (cpuid >= NR_CPUS) {
349 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
353 printk("boot cpu id != 0, this could work but is untested\n");
355 current_thread_info()->cpu = cpuid;
356 cpu_set(cpuid, cpu_online_map);
357 cpu_set(cpuid, phys_cpu_present_map);
360 int __cpuinit __cpu_up(unsigned int cpu)
362 extern int __cpuinit smp4m_boot_one_cpu(int);
363 extern int __cpuinit smp4d_boot_one_cpu(int);
366 switch(sparc_cpu_model) {
376 ret = smp4m_boot_one_cpu(cpu);
379 ret = smp4d_boot_one_cpu(cpu);
390 printk("UNKNOWN!\n");
396 cpu_set(cpu, smp_commenced_mask);
397 while (!cpu_online(cpu))
403 void smp_bogo(struct seq_file *m)
407 for_each_online_cpu(i) {
409 "Cpu%dBogo\t: %lu.%02lu\n",
411 cpu_data(i).udelay_val/(500000/HZ),
412 (cpu_data(i).udelay_val/(5000/HZ))%100);
416 void smp_info(struct seq_file *m)
420 seq_printf(m, "State:\n");
421 for_each_online_cpu(i)
422 seq_printf(m, "CPU%d\t\t: online\n", i);