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/cacheflush.h>
34 #include <asm/tlbflush.h>
35 #include <asm/cpudata.h>
37 volatile int smp_processors_ready
= 0;
39 volatile unsigned long cpu_callin_map
[NR_CPUS
] __initdata
= {0,};
40 unsigned char boot_cpu_id
= 0;
41 unsigned char boot_cpu_id4
= 0; /* boot_cpu_id << 2 */
42 int smp_activated
= 0;
43 volatile int __cpu_number_map
[NR_CPUS
];
44 volatile int __cpu_logical_map
[NR_CPUS
];
46 cpumask_t cpu_online_map
= CPU_MASK_NONE
;
47 cpumask_t phys_cpu_present_map
= CPU_MASK_NONE
;
48 cpumask_t smp_commenced_mask
= CPU_MASK_NONE
;
50 /* The only guaranteed locking primitive available on all Sparc
51 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
52 * places the current byte at the effective address into dest_reg and
53 * places 0xff there afterwards. Pretty lame locking primitive
54 * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
55 * instruction which is much better...
58 /* Used to make bitops atomic */
59 unsigned char bitops_spinlock
= 0;
61 void __cpuinit
smp_store_cpu_info(int id
)
65 cpu_data(id
).udelay_val
= loops_per_jiffy
;
67 cpu_find_by_mid(id
, &cpu_node
);
68 cpu_data(id
).clock_tick
= prom_getintdefault(cpu_node
,
69 "clock-frequency", 0);
70 cpu_data(id
).prom_node
= cpu_node
;
71 cpu_data(id
).mid
= cpu_get_hwmid(cpu_node
);
73 /* this is required to tune the scheduler correctly */
74 /* is it possible to have CPUs with different cache sizes? */
75 if (id
== boot_cpu_id
) {
76 int cache_line
,cache_nlines
;
78 cache_line
= prom_getintdefault(cpu_node
, "ecache-line-size", cache_line
);
79 cache_nlines
= 0x8000;
80 cache_nlines
= prom_getintdefault(cpu_node
, "ecache-nlines", cache_nlines
);
81 max_cache_size
= cache_line
* cache_nlines
;
83 if (cpu_data(id
).mid
< 0)
84 panic("No MID found for CPU%d at node 0x%08d", id
, cpu_node
);
87 void __init
smp_cpus_done(unsigned int max_cpus
)
89 extern void smp4m_smp_done(void);
90 extern void smp4d_smp_done(void);
91 unsigned long bogosum
= 0;
94 for (cpu
= 0, num
= 0; cpu
< NR_CPUS
; cpu
++)
95 if (cpu_online(cpu
)) {
97 bogosum
+= cpu_data(cpu
).udelay_val
;
100 printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
101 num
, bogosum
/(500000/HZ
),
102 (bogosum
/(5000/HZ
))%100);
104 switch(sparc_cpu_model
) {
128 printk("UNKNOWN!\n");
136 printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
137 panic("SMP bolixed\n");
140 struct linux_prom_registers smp_penguin_ctable __initdata
= { 0 };
142 void smp_send_reschedule(int cpu
)
147 void smp_send_stop(void)
151 void smp_flush_cache_all(void)
153 xc0((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_all
));
154 local_flush_cache_all();
157 void smp_flush_tlb_all(void)
159 xc0((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_all
));
160 local_flush_tlb_all();
163 void smp_flush_cache_mm(struct mm_struct
*mm
)
165 if(mm
->context
!= NO_CONTEXT
) {
166 cpumask_t cpu_mask
= mm
->cpu_vm_mask
;
167 cpu_clear(smp_processor_id(), cpu_mask
);
168 if (!cpus_empty(cpu_mask
))
169 xc1((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_mm
), (unsigned long) mm
);
170 local_flush_cache_mm(mm
);
174 void smp_flush_tlb_mm(struct mm_struct
*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 xc1((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_mm
), (unsigned long) mm
);
181 if(atomic_read(&mm
->mm_users
) == 1 && current
->active_mm
== mm
)
182 mm
->cpu_vm_mask
= cpumask_of_cpu(smp_processor_id());
184 local_flush_tlb_mm(mm
);
188 void smp_flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
,
191 struct mm_struct
*mm
= vma
->vm_mm
;
193 if (mm
->context
!= NO_CONTEXT
) {
194 cpumask_t cpu_mask
= mm
->cpu_vm_mask
;
195 cpu_clear(smp_processor_id(), cpu_mask
);
196 if (!cpus_empty(cpu_mask
))
197 xc3((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_range
), (unsigned long) vma
, start
, end
);
198 local_flush_cache_range(vma
, start
, end
);
202 void smp_flush_tlb_range(struct vm_area_struct
*vma
, unsigned long start
,
205 struct mm_struct
*mm
= vma
->vm_mm
;
207 if (mm
->context
!= NO_CONTEXT
) {
208 cpumask_t cpu_mask
= mm
->cpu_vm_mask
;
209 cpu_clear(smp_processor_id(), cpu_mask
);
210 if (!cpus_empty(cpu_mask
))
211 xc3((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_range
), (unsigned long) vma
, start
, end
);
212 local_flush_tlb_range(vma
, start
, end
);
216 void smp_flush_cache_page(struct vm_area_struct
*vma
, unsigned long page
)
218 struct mm_struct
*mm
= vma
->vm_mm
;
220 if(mm
->context
!= NO_CONTEXT
) {
221 cpumask_t cpu_mask
= mm
->cpu_vm_mask
;
222 cpu_clear(smp_processor_id(), cpu_mask
);
223 if (!cpus_empty(cpu_mask
))
224 xc2((smpfunc_t
) BTFIXUP_CALL(local_flush_cache_page
), (unsigned long) vma
, page
);
225 local_flush_cache_page(vma
, page
);
229 void smp_flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
231 struct mm_struct
*mm
= vma
->vm_mm
;
233 if(mm
->context
!= NO_CONTEXT
) {
234 cpumask_t cpu_mask
= mm
->cpu_vm_mask
;
235 cpu_clear(smp_processor_id(), cpu_mask
);
236 if (!cpus_empty(cpu_mask
))
237 xc2((smpfunc_t
) BTFIXUP_CALL(local_flush_tlb_page
), (unsigned long) vma
, page
);
238 local_flush_tlb_page(vma
, page
);
242 void smp_reschedule_irq(void)
247 void smp_flush_page_to_ram(unsigned long page
)
249 /* Current theory is that those who call this are the one's
250 * who have just dirtied their cache with the pages contents
251 * in kernel space, therefore we only run this on local cpu.
253 * XXX This experiment failed, research further... -DaveM
256 xc1((smpfunc_t
) BTFIXUP_CALL(local_flush_page_to_ram
), page
);
258 local_flush_page_to_ram(page
);
261 void smp_flush_sig_insns(struct mm_struct
*mm
, unsigned long insn_addr
)
263 cpumask_t cpu_mask
= mm
->cpu_vm_mask
;
264 cpu_clear(smp_processor_id(), cpu_mask
);
265 if (!cpus_empty(cpu_mask
))
266 xc2((smpfunc_t
) BTFIXUP_CALL(local_flush_sig_insns
), (unsigned long) mm
, insn_addr
);
267 local_flush_sig_insns(mm
, insn_addr
);
270 extern unsigned int lvl14_resolution
;
272 /* /proc/profile writes can call this, don't __init it please. */
273 static DEFINE_SPINLOCK(prof_setup_lock
);
275 int setup_profiling_timer(unsigned int multiplier
)
280 /* Prevent level14 ticker IRQ flooding. */
281 if((!multiplier
) || (lvl14_resolution
/ multiplier
) < 500)
284 spin_lock_irqsave(&prof_setup_lock
, flags
);
285 for_each_possible_cpu(i
) {
286 load_profile_irq(i
, lvl14_resolution
/ multiplier
);
287 prof_multiplier(i
) = multiplier
;
289 spin_unlock_irqrestore(&prof_setup_lock
, flags
);
294 void __init
smp_prepare_cpus(unsigned int max_cpus
)
296 extern void smp4m_boot_cpus(void);
297 extern void smp4d_boot_cpus(void);
300 printk("Entering SMP Mode...\n");
303 for (i
= 0; !cpu_find_by_instance(i
, NULL
, &cpuid
); i
++) {
304 if (cpuid
>= NR_CPUS
)
307 /* i = number of cpus */
308 if (extra
&& max_cpus
> i
- extra
)
309 printk("Warning: NR_CPUS is too low to start all cpus\n");
311 smp_store_cpu_info(boot_cpu_id
);
313 switch(sparc_cpu_model
) {
337 printk("UNKNOWN!\n");
343 /* Set this up early so that things like the scheduler can init
344 * properly. We use the same cpu mask for both the present and
347 void __init
smp_setup_cpu_possible_map(void)
352 while (!cpu_find_by_instance(instance
, NULL
, &mid
)) {
354 cpu_set(mid
, phys_cpu_present_map
);
355 cpu_set(mid
, cpu_present_map
);
361 void __init
smp_prepare_boot_cpu(void)
363 int cpuid
= hard_smp_processor_id();
365 if (cpuid
>= NR_CPUS
) {
366 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
370 printk("boot cpu id != 0, this could work but is untested\n");
372 current_thread_info()->cpu
= cpuid
;
373 cpu_set(cpuid
, cpu_online_map
);
374 cpu_set(cpuid
, phys_cpu_present_map
);
377 int __cpuinit
__cpu_up(unsigned int cpu
)
379 extern int smp4m_boot_one_cpu(int);
380 extern int smp4d_boot_one_cpu(int);
383 switch(sparc_cpu_model
) {
393 ret
= smp4m_boot_one_cpu(cpu
);
396 ret
= smp4d_boot_one_cpu(cpu
);
407 printk("UNKNOWN!\n");
413 cpu_set(cpu
, smp_commenced_mask
);
414 while (!cpu_online(cpu
))
420 void smp_bogo(struct seq_file
*m
)
424 for_each_online_cpu(i
) {
426 "Cpu%dBogo\t: %lu.%02lu\n",
428 cpu_data(i
).udelay_val
/(500000/HZ
),
429 (cpu_data(i
).udelay_val
/(5000/HZ
))%100);
433 void smp_info(struct seq_file
*m
)
437 seq_printf(m
, "State:\n");
438 for_each_online_cpu(i
)
439 seq_printf(m
, "CPU%d\t\t: online\n", i
);