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>
19 #include <asm/ptrace.h>
20 #include <asm/atomic.h>
22 #include <asm/delay.h>
25 #include <asm/pgtable.h>
26 #include <asm/oplib.h>
27 #include <asm/atops.h>
28 #include <asm/hardirq.h>
29 #include <asm/softirq.h>
31 #define __KERNEL_SYSCALLS__
32 #include <linux/unistd.h>
34 #define IRQ_RESCHEDULE 13
35 #define IRQ_STOP_CPU 14
36 #define IRQ_CROSS_CALL 15
38 volatile int smp_processors_ready
= 0;
39 unsigned long cpu_present_map
= 0;
41 int smp_threads_ready
=0;
42 unsigned char mid_xlate
[NR_CPUS
] = { 0, 0, 0, 0, };
43 volatile unsigned long cpu_callin_map
[NR_CPUS
] __initdata
= {0,};
45 volatile unsigned long smp_spinning
[NR_CPUS
] = { 0, };
47 unsigned long smp_proc_in_lock
[NR_CPUS
] = { 0, };
48 struct cpuinfo_sparc cpu_data
[NR_CPUS
];
49 unsigned long cpu_offset
[NR_CPUS
];
50 unsigned char boot_cpu_id
= 0;
51 unsigned char boot_cpu_id4
= 0; /* boot_cpu_id << 2 */
52 int smp_activated
= 0;
53 volatile int cpu_number_map
[NR_CPUS
];
54 volatile int __cpu_logical_map
[NR_CPUS
];
55 cycles_t cacheflush_time
= 0; /* XXX */
57 /* The only guaranteed locking primitive available on all Sparc
58 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
59 * places the current byte at the effective address into dest_reg and
60 * places 0xff there afterwards. Pretty lame locking primitive
61 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
62 * instruction which is much better...
66 spinlock_t kernel_flag
= SPIN_LOCK_UNLOCKED
;
68 /* Used to make bitops atomic */
69 unsigned char bitops_spinlock
= 0;
71 volatile unsigned long ipi_count
;
73 volatile int smp_process_available
=0;
74 volatile int smp_commenced
= 0;
76 /* Not supported on Sparc yet. */
77 void __init
smp_setup(char *str
, int *ints
)
82 * The bootstrap kernel entry code has set these up. Save them for
86 void __init
smp_store_cpu_info(int id
)
88 cpu_data
[id
].udelay_val
= loops_per_sec
; /* this is it on sparc. */
91 void __init
smp_commence(void)
94 * Lets the callin's below out of their loop.
96 local_flush_cache_all();
97 local_flush_tlb_all();
99 local_flush_cache_all();
100 local_flush_tlb_all();
103 /* Only broken Intel needs this, thus it should not even be referenced
106 void __init
initialize_secondary(void)
110 extern int cpu_idle(void);
112 /* Activate a secondary processor. */
113 int start_secondary(void *unused
)
115 prom_printf("Start secondary called. Should not happen\n");
121 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
122 panic("SMP bolixed\n");
126 * Cycle through the processors asking the PROM to start each one.
129 extern struct prom_cpuinfo linux_cpus
[NR_CPUS
];
130 struct linux_prom_registers smp_penguin_ctable __initdata
= { 0 };
132 void __init
smp_boot_cpus(void)
134 extern void smp4m_boot_cpus(void);
135 extern void smp4d_boot_cpus(void);
137 if (sparc_cpu_model
== sun4m
)
143 void smp_flush_cache_all(void)
144 { xc0((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_all
)); }
146 void smp_flush_tlb_all(void)
147 { xc0((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_all
)); }
149 void smp_flush_cache_mm(struct mm_struct
*mm
)
151 if(mm
->context
!= NO_CONTEXT
) {
152 if(mm
->cpu_vm_mask
== (1 << smp_processor_id()))
153 local_flush_cache_mm(mm
);
155 xc1((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_mm
), (unsigned long) mm
);
159 void smp_flush_tlb_mm(struct mm_struct
*mm
)
161 if(mm
->context
!= NO_CONTEXT
) {
162 if(mm
->cpu_vm_mask
== (1 << smp_processor_id())) {
163 local_flush_tlb_mm(mm
);
165 xc1((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_mm
), (unsigned long) mm
);
166 if(atomic_read(&mm
->count
) == 1 && current
->mm
== mm
)
167 mm
->cpu_vm_mask
= (1 << smp_processor_id());
172 void smp_flush_cache_range(struct mm_struct
*mm
, unsigned long start
,
175 if(mm
->context
!= NO_CONTEXT
) {
176 if(mm
->cpu_vm_mask
== (1 << smp_processor_id()))
177 local_flush_cache_range(mm
, start
, end
);
179 xc3((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_range
), (unsigned long) mm
,
184 void smp_flush_tlb_range(struct mm_struct
*mm
, unsigned long start
,
187 if(mm
->context
!= NO_CONTEXT
) {
188 if(mm
->cpu_vm_mask
== (1 << smp_processor_id()))
189 local_flush_tlb_range(mm
, start
, end
);
191 xc3((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_range
), (unsigned long) mm
,
196 void smp_flush_cache_page(struct vm_area_struct
*vma
, unsigned long page
)
198 struct mm_struct
*mm
= vma
->vm_mm
;
200 if(mm
->context
!= NO_CONTEXT
) {
201 if(mm
->cpu_vm_mask
== (1 << smp_processor_id()))
202 local_flush_cache_page(vma
, page
);
204 xc2((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_page
),
205 (unsigned long) vma
, page
);
209 void smp_flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
211 struct mm_struct
*mm
= vma
->vm_mm
;
213 if(mm
->context
!= NO_CONTEXT
) {
214 if(mm
->cpu_vm_mask
== (1 << smp_processor_id()))
215 local_flush_tlb_page(vma
, page
);
217 xc2((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_page
), (unsigned long) vma
, page
);
221 void smp_flush_page_to_ram(unsigned long page
)
223 /* Current theory is that those who call this are the one's
224 * who have just dirtied their cache with the pages contents
225 * in kernel space, therefore we only run this on local cpu.
227 * XXX This experiment failed, research further... -DaveM
230 xc1((smpfunc_t
) BTFIXUP_CALL(local_flush_page_to_ram
), page
);
232 local_flush_page_to_ram(page
);
236 void smp_flush_sig_insns(struct mm_struct
*mm
, unsigned long insn_addr
)
238 if(mm
->cpu_vm_mask
== (1 << smp_processor_id()))
239 local_flush_sig_insns(mm
, insn_addr
);
241 xc2((smpfunc_t
) BTFIXUP_CALL(local_flush_sig_insns
), (unsigned long) mm
, insn_addr
);
244 /* Reschedule call back. */
245 void smp_reschedule_irq(void)
247 current
->need_resched
= 1;
250 /* Stopping processors. */
251 void smp_stop_cpu_irq(void)
258 unsigned int prof_multiplier
[NR_CPUS
];
259 unsigned int prof_counter
[NR_CPUS
];
260 extern unsigned int lvl14_resolution
;
262 int setup_profiling_timer(unsigned int multiplier
)
267 /* Prevent level14 ticker IRQ flooding. */
268 if((!multiplier
) || (lvl14_resolution
/ multiplier
) < 500)
272 for(i
= 0; i
< NR_CPUS
; i
++) {
273 if(cpu_present_map
& (1 << i
)) {
274 load_profile_irq(mid_xlate
[i
], lvl14_resolution
/ multiplier
);
275 prof_multiplier
[i
] = multiplier
;
278 restore_flags(flags
);
283 int smp_bogo_info(char *buf
)
287 for (i
= 0; i
< NR_CPUS
; i
++)
288 if (cpu_present_map
& (1 << i
))
289 len
+= sprintf(buf
+ len
, "Cpu%dBogo\t: %lu.%02lu\n",
291 cpu_data
[i
].udelay_val
/500000,
292 (cpu_data
[i
].udelay_val
/5000)%100);
296 int smp_info(char *buf
)
300 for (i
= 0; i
< NR_CPUS
; i
++)
301 if (cpu_present_map
& (1 << i
))
302 len
+= sprintf(buf
+ len
, "CPU%d\t\t: online\n", i
);