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>
37 volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,};
38 unsigned char boot_cpu_id = 0;
39 unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
40 int smp_activated = 0;
41 volatile int __cpu_number_map[NR_CPUS];
42 volatile int __cpu_logical_map[NR_CPUS];
44 cpumask_t cpu_online_map = CPU_MASK_NONE;
45 cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
46 cpumask_t smp_commenced_mask = CPU_MASK_NONE;
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 /* Used to make bitops atomic */
57 unsigned char bitops_spinlock = 0;
59 void __cpuinit smp_store_cpu_info(int id)
63 cpu_data(id).udelay_val = loops_per_jiffy;
65 cpu_find_by_mid(id, &cpu_node);
66 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
67 "clock-frequency", 0);
68 cpu_data(id).prom_node = cpu_node;
69 cpu_data(id).mid = cpu_get_hwmid(cpu_node);
71 if (cpu_data(id).mid < 0)
72 panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
75 void __init smp_cpus_done(unsigned int max_cpus)
77 extern void smp4m_smp_done(void);
78 extern void smp4d_smp_done(void);
79 unsigned long bogosum = 0;
82 for (cpu = 0, num = 0; cpu < NR_CPUS; cpu++)
83 if (cpu_online(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) {
116 printk("UNKNOWN!\n");
124 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
125 panic("SMP bolixed\n");
128 struct linux_prom_registers smp_penguin_ctable __initdata = { 0 };
130 void smp_send_reschedule(int cpu)
135 void smp_send_stop(void)
139 void smp_flush_cache_all(void)
141 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
142 local_flush_cache_all();
145 void smp_flush_tlb_all(void)
147 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
148 local_flush_tlb_all();
151 void smp_flush_cache_mm(struct mm_struct *mm)
153 if(mm->context != NO_CONTEXT) {
154 cpumask_t cpu_mask = mm->cpu_vm_mask;
155 cpu_clear(smp_processor_id(), cpu_mask);
156 if (!cpus_empty(cpu_mask))
157 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
158 local_flush_cache_mm(mm);
162 void smp_flush_tlb_mm(struct mm_struct *mm)
164 if(mm->context != NO_CONTEXT) {
165 cpumask_t cpu_mask = mm->cpu_vm_mask;
166 cpu_clear(smp_processor_id(), cpu_mask);
167 if (!cpus_empty(cpu_mask)) {
168 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
169 if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
170 mm->cpu_vm_mask = cpumask_of_cpu(smp_processor_id());
172 local_flush_tlb_mm(mm);
176 void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
179 struct mm_struct *mm = vma->vm_mm;
181 if (mm->context != NO_CONTEXT) {
182 cpumask_t cpu_mask = mm->cpu_vm_mask;
183 cpu_clear(smp_processor_id(), cpu_mask);
184 if (!cpus_empty(cpu_mask))
185 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
186 local_flush_cache_range(vma, start, end);
190 void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
193 struct mm_struct *mm = vma->vm_mm;
195 if (mm->context != NO_CONTEXT) {
196 cpumask_t cpu_mask = mm->cpu_vm_mask;
197 cpu_clear(smp_processor_id(), cpu_mask);
198 if (!cpus_empty(cpu_mask))
199 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
200 local_flush_tlb_range(vma, start, end);
204 void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
206 struct mm_struct *mm = vma->vm_mm;
208 if(mm->context != NO_CONTEXT) {
209 cpumask_t cpu_mask = mm->cpu_vm_mask;
210 cpu_clear(smp_processor_id(), cpu_mask);
211 if (!cpus_empty(cpu_mask))
212 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
213 local_flush_cache_page(vma, page);
217 void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
219 struct mm_struct *mm = vma->vm_mm;
221 if(mm->context != NO_CONTEXT) {
222 cpumask_t cpu_mask = mm->cpu_vm_mask;
223 cpu_clear(smp_processor_id(), cpu_mask);
224 if (!cpus_empty(cpu_mask))
225 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
226 local_flush_tlb_page(vma, page);
230 void smp_reschedule_irq(void)
235 void smp_flush_page_to_ram(unsigned long page)
237 /* Current theory is that those who call this are the one's
238 * who have just dirtied their cache with the pages contents
239 * in kernel space, therefore we only run this on local cpu.
241 * XXX This experiment failed, research further... -DaveM
244 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
246 local_flush_page_to_ram(page);
249 void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
251 cpumask_t cpu_mask = mm->cpu_vm_mask;
252 cpu_clear(smp_processor_id(), cpu_mask);
253 if (!cpus_empty(cpu_mask))
254 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
255 local_flush_sig_insns(mm, insn_addr);
258 extern unsigned int lvl14_resolution;
260 /* /proc/profile writes can call this, don't __init it please. */
261 static DEFINE_SPINLOCK(prof_setup_lock);
263 int setup_profiling_timer(unsigned int multiplier)
268 /* Prevent level14 ticker IRQ flooding. */
269 if((!multiplier) || (lvl14_resolution / multiplier) < 500)
272 spin_lock_irqsave(&prof_setup_lock, flags);
273 for_each_possible_cpu(i) {
274 load_profile_irq(i, lvl14_resolution / multiplier);
275 prof_multiplier(i) = multiplier;
277 spin_unlock_irqrestore(&prof_setup_lock, flags);
282 void __init smp_prepare_cpus(unsigned int max_cpus)
284 extern void __init smp4m_boot_cpus(void);
285 extern void __init smp4d_boot_cpus(void);
288 printk("Entering SMP Mode...\n");
291 for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
292 if (cpuid >= NR_CPUS)
295 /* i = number of cpus */
296 if (extra && max_cpus > i - extra)
297 printk("Warning: NR_CPUS is too low to start all cpus\n");
299 smp_store_cpu_info(boot_cpu_id);
301 switch(sparc_cpu_model) {
325 printk("UNKNOWN!\n");
331 /* Set this up early so that things like the scheduler can init
332 * properly. We use the same cpu mask for both the present and
335 void __init smp_setup_cpu_possible_map(void)
340 while (!cpu_find_by_instance(instance, NULL, &mid)) {
342 cpu_set(mid, phys_cpu_present_map);
343 cpu_set(mid, cpu_present_map);
349 void __init smp_prepare_boot_cpu(void)
351 int cpuid = hard_smp_processor_id();
353 if (cpuid >= NR_CPUS) {
354 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
358 printk("boot cpu id != 0, this could work but is untested\n");
360 current_thread_info()->cpu = cpuid;
361 cpu_set(cpuid, cpu_online_map);
362 cpu_set(cpuid, phys_cpu_present_map);
365 int __cpuinit __cpu_up(unsigned int cpu)
367 extern int __cpuinit smp4m_boot_one_cpu(int);
368 extern int __cpuinit smp4d_boot_one_cpu(int);
371 switch(sparc_cpu_model) {
381 ret = smp4m_boot_one_cpu(cpu);
384 ret = smp4d_boot_one_cpu(cpu);
395 printk("UNKNOWN!\n");
401 cpu_set(cpu, smp_commenced_mask);
402 while (!cpu_online(cpu))
408 void smp_bogo(struct seq_file *m)
412 for_each_online_cpu(i) {
414 "Cpu%dBogo\t: %lu.%02lu\n",
416 cpu_data(i).udelay_val/(500000/HZ),
417 (cpu_data(i).udelay_val/(5000/HZ))%100);
421 void smp_info(struct seq_file *m)
425 seq_printf(m, "State:\n");
426 for_each_online_cpu(i)
427 seq_printf(m, "CPU%d\t\t: online\n", i);