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/smp_lock.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/init.h>
18 #include <linux/spinlock.h>
21 #include <linux/seq_file.h>
22 #include <linux/cache.h>
23 #include <linux/delay.h>
25 #include <asm/ptrace.h>
26 #include <asm/atomic.h>
30 #include <asm/pgalloc.h>
31 #include <asm/pgtable.h>
32 #include <asm/oplib.h>
33 #include <asm/hardirq.h>
34 #include <asm/cacheflush.h>
35 #include <asm/tlbflush.h>
36 #include <asm/cpudata.h>
38 volatile int smp_processors_ready = 0;
40 int smp_threads_ready=0;
41 volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,};
42 unsigned char boot_cpu_id = 0;
43 unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
44 int smp_activated = 0;
45 volatile int __cpu_number_map[NR_CPUS];
46 volatile int __cpu_logical_map[NR_CPUS];
47 cycles_t cacheflush_time = 0; /* XXX */
49 cpumask_t cpu_online_map = CPU_MASK_NONE;
50 cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
52 /* The only guaranteed locking primitive available on all Sparc
53 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
54 * places the current byte at the effective address into dest_reg and
55 * places 0xff there afterwards. Pretty lame locking primitive
56 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
57 * instruction which is much better...
60 /* Used to make bitops atomic */
61 unsigned char bitops_spinlock = 0;
63 volatile unsigned long ipi_count;
65 volatile int smp_process_available=0;
66 volatile int smp_commenced = 0;
68 void __init smp_store_cpu_info(int id)
72 cpu_data(id).udelay_val = loops_per_jiffy;
74 cpu_find_by_mid(id, &cpu_node);
75 cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
76 "clock-frequency", 0);
77 cpu_data(id).prom_node = cpu_node;
78 cpu_data(id).mid = cpu_get_hwmid(cpu_node);
79 if (cpu_data(id).mid < 0)
80 panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
83 void __init smp_cpus_done(unsigned int max_cpus)
89 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
90 panic("SMP bolixed\n");
93 struct linux_prom_registers smp_penguin_ctable __initdata = { 0 };
95 void __init smp_boot_cpus(void)
97 extern void smp4m_boot_cpus(void);
98 extern void smp4d_boot_cpus(void);
100 if (sparc_cpu_model == sun4m)
106 void smp_send_reschedule(int cpu)
111 void smp_send_stop(void)
115 void smp_flush_cache_all(void)
117 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
118 local_flush_cache_all();
121 void smp_flush_tlb_all(void)
123 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
124 local_flush_tlb_all();
127 void smp_flush_cache_mm(struct mm_struct *mm)
129 if(mm->context != NO_CONTEXT) {
130 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
131 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
132 local_flush_cache_mm(mm);
136 void smp_flush_tlb_mm(struct mm_struct *mm)
138 if(mm->context != NO_CONTEXT) {
139 if(mm->cpu_vm_mask != (1 << smp_processor_id())) {
140 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
141 if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
142 mm->cpu_vm_mask = (1 << smp_processor_id());
144 local_flush_tlb_mm(mm);
148 void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
151 struct mm_struct *mm = vma->vm_mm;
153 if (mm->context != NO_CONTEXT) {
154 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
155 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
156 local_flush_cache_range(vma, start, end);
160 void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
163 struct mm_struct *mm = vma->vm_mm;
165 if (mm->context != NO_CONTEXT) {
166 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
167 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
168 local_flush_tlb_range(vma, start, end);
172 void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
174 struct mm_struct *mm = vma->vm_mm;
176 if(mm->context != NO_CONTEXT) {
177 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
178 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
179 local_flush_cache_page(vma, page);
183 void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
185 struct mm_struct *mm = vma->vm_mm;
187 if(mm->context != NO_CONTEXT) {
188 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
189 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
190 local_flush_tlb_page(vma, page);
194 void smp_flush_page_to_ram(unsigned long page)
196 /* Current theory is that those who call this are the one's
197 * who have just dirtied their cache with the pages contents
198 * in kernel space, therefore we only run this on local cpu.
200 * XXX This experiment failed, research further... -DaveM
203 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
205 local_flush_page_to_ram(page);
208 void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
210 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
211 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
212 local_flush_sig_insns(mm, insn_addr);
215 extern unsigned int lvl14_resolution;
217 /* /proc/profile writes can call this, don't __init it please. */
218 static spinlock_t prof_setup_lock = SPIN_LOCK_UNLOCKED;
220 int setup_profiling_timer(unsigned int multiplier)
225 /* Prevent level14 ticker IRQ flooding. */
226 if((!multiplier) || (lvl14_resolution / multiplier) < 500)
229 spin_lock_irqsave(&prof_setup_lock, flags);
230 for(i = 0; i < NR_CPUS; i++) {
232 load_profile_irq(i, lvl14_resolution / multiplier);
233 prof_multiplier(i) = multiplier;
235 spin_unlock_irqrestore(&prof_setup_lock, flags);
240 void __init smp_prepare_cpus(unsigned int maxcpus)
244 void __devinit smp_prepare_boot_cpu(void)
246 current_thread_info()->cpu = hard_smp_processor_id();
247 cpu_set(smp_processor_id(), cpu_online_map);
248 cpu_set(smp_processor_id(), phys_cpu_present_map);
251 int __devinit __cpu_up(unsigned int cpu)
253 panic("smp doesn't work\n");
256 void smp_bogo(struct seq_file *m)
260 for (i = 0; i < NR_CPUS; i++) {
263 "Cpu%dBogo\t: %lu.%02lu\n",
265 cpu_data(i).udelay_val/(500000/HZ),
266 (cpu_data(i).udelay_val/(5000/HZ))%100);
270 void smp_info(struct seq_file *m)
274 seq_printf(m, "State:\n");
275 for (i = 0; i < NR_CPUS; i++) {
277 seq_printf(m, "CPU%d\t\t: online\n", i);