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)
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/threads.h>
12 #include <linux/smp.h>
13 #include <linux/smp_lock.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>
23 #include <asm/ptrace.h>
24 #include <asm/atomic.h>
26 #include <asm/delay.h>
29 #include <asm/pgalloc.h>
30 #include <asm/pgtable.h>
31 #include <asm/oplib.h>
32 #include <asm/hardirq.h>
33 #include <asm/softirq.h>
35 #define __KERNEL_SYSCALLS__
36 #include <linux/unistd.h>
38 #define IRQ_RESCHEDULE 13
39 #define IRQ_STOP_CPU 14
40 #define IRQ_CROSS_CALL 15
42 volatile int smp_processors_ready = 0;
43 unsigned long cpu_present_map = 0;
45 int smp_threads_ready=0;
46 unsigned char mid_xlate[NR_CPUS] = { 0, 0, 0, 0, };
47 volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,};
49 volatile unsigned long smp_spinning[NR_CPUS] = { 0, };
51 unsigned long smp_proc_in_lock[NR_CPUS] = { 0, };
52 struct cpuinfo_sparc cpu_data[NR_CPUS];
53 unsigned long cpu_offset[NR_CPUS];
54 unsigned char boot_cpu_id = 0;
55 unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
56 int smp_activated = 0;
57 volatile int __cpu_number_map[NR_CPUS];
58 volatile int __cpu_logical_map[NR_CPUS];
59 cycles_t cacheflush_time = 0; /* XXX */
61 /* The only guaranteed locking primitive available on all Sparc
62 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
63 * places the current byte at the effective address into dest_reg and
64 * places 0xff there afterwards. Pretty lame locking primitive
65 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
66 * instruction which is much better...
70 spinlock_t kernel_flag __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
72 /* Used to make bitops atomic */
73 unsigned char bitops_spinlock = 0;
75 volatile unsigned long ipi_count;
77 volatile int smp_process_available=0;
78 volatile int smp_commenced = 0;
80 /* Not supported on Sparc yet. */
81 void __init smp_setup(char *str, int *ints)
86 * The bootstrap kernel entry code has set these up. Save them for
90 void __init smp_store_cpu_info(int id)
92 cpu_data[id].udelay_val = loops_per_jiffy; /* this is it on sparc. */
95 void __init smp_commence(void)
98 * Lets the callin's below out of their loop.
100 local_flush_cache_all();
101 local_flush_tlb_all();
103 local_flush_cache_all();
104 local_flush_tlb_all();
107 extern int cpu_idle(void);
109 /* Activate a secondary processor. */
110 int start_secondary(void *unused)
112 prom_printf("Start secondary called. Should not happen\n");
118 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
119 panic("SMP bolixed\n");
123 * Cycle through the processors asking the PROM to start each one.
126 extern struct prom_cpuinfo linux_cpus[NR_CPUS];
127 struct linux_prom_registers smp_penguin_ctable __initdata = { 0 };
129 void __init smp_boot_cpus(void)
131 extern void smp4m_boot_cpus(void);
132 extern void smp4d_boot_cpus(void);
134 if (sparc_cpu_model == sun4m)
140 void smp_flush_cache_all(void)
142 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
143 local_flush_cache_all();
146 void smp_flush_tlb_all(void)
148 xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
149 local_flush_tlb_all();
152 void smp_flush_cache_mm(struct mm_struct *mm)
154 if(mm->context != NO_CONTEXT) {
155 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
156 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
157 local_flush_cache_mm(mm);
161 void smp_flush_tlb_mm(struct mm_struct *mm)
163 if(mm->context != NO_CONTEXT) {
164 if(mm->cpu_vm_mask != (1 << smp_processor_id())) {
165 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
166 if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
167 mm->cpu_vm_mask = (1 << smp_processor_id());
169 local_flush_tlb_mm(mm);
173 void smp_flush_cache_range(struct mm_struct *mm, unsigned long start,
176 if(mm->context != NO_CONTEXT) {
177 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
178 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) mm, start, end);
179 local_flush_cache_range(mm, start, end);
183 void smp_flush_tlb_range(struct mm_struct *mm, unsigned long start,
186 if(mm->context != NO_CONTEXT) {
187 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
188 xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) mm, start, end);
189 local_flush_tlb_range(mm, start, end);
193 void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
195 struct mm_struct *mm = vma->vm_mm;
197 if(mm->context != NO_CONTEXT) {
198 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
199 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
200 local_flush_cache_page(vma, page);
204 void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
206 struct mm_struct *mm = vma->vm_mm;
208 if(mm->context != NO_CONTEXT) {
209 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
210 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
211 local_flush_tlb_page(vma, page);
215 void smp_flush_page_to_ram(unsigned long page)
217 /* Current theory is that those who call this are the one's
218 * who have just dirtied their cache with the pages contents
219 * in kernel space, therefore we only run this on local cpu.
221 * XXX This experiment failed, research further... -DaveM
224 xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
226 local_flush_page_to_ram(page);
229 void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
231 if(mm->cpu_vm_mask != (1 << smp_processor_id()))
232 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
233 local_flush_sig_insns(mm, insn_addr);
236 /* Reschedule call back. */
237 void smp_reschedule_irq(void)
239 current->need_resched = 1;
242 /* Stopping processors. */
243 void smp_stop_cpu_irq(void)
250 unsigned int prof_multiplier[NR_CPUS];
251 unsigned int prof_counter[NR_CPUS];
252 extern unsigned int lvl14_resolution;
254 int setup_profiling_timer(unsigned int multiplier)
259 /* Prevent level14 ticker IRQ flooding. */
260 if((!multiplier) || (lvl14_resolution / multiplier) < 500)
264 for(i = 0; i < NR_CPUS; i++) {
265 if(cpu_present_map & (1 << i)) {
266 load_profile_irq(mid_xlate[i], lvl14_resolution / multiplier);
267 prof_multiplier[i] = multiplier;
270 restore_flags(flags);
275 void smp_bogo_info(struct seq_file *m)
279 for (i = 0; i < NR_CPUS; i++) {
280 if (cpu_present_map & (1 << i))
282 "Cpu%dBogo\t: %lu.%02lu\n",
284 cpu_data[i].udelay_val/(500000/HZ),
285 (cpu_data[i].udelay_val/(5000/HZ))%100);
289 void smp_info(struct seq_file *m)
293 for (i = 0; i < NR_CPUS; i++) {
294 if (cpu_present_map & (1 << i))
295 seq_printf(m, "CPU%d\t\t: online\n", i);