This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / sparc / kernel / smp.c
1 /* smp.c: Sparc SMP support.
2  *
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)
6  */
7
8 #include <asm/head.h>
9
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>
19 #include <linux/mm.h>
20 #include <linux/fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/cache.h>
23 #include <linux/delay.h>
24
25 #include <asm/ptrace.h>
26 #include <asm/atomic.h>
27
28 #include <asm/irq.h>
29 #include <asm/page.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>
37
38 volatile int smp_processors_ready = 0;
39 int smp_num_cpus = 1;
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 */
48
49 cpumask_t cpu_online_map = CPU_MASK_NONE;
50 cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
51
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...
58  */
59
60 /* Used to make bitops atomic */
61 unsigned char bitops_spinlock = 0;
62
63 volatile unsigned long ipi_count;
64
65 volatile int smp_process_available=0;
66 volatile int smp_commenced = 0;
67
68 void __init smp_store_cpu_info(int id)
69 {
70         int cpu_node;
71
72         cpu_data(id).udelay_val = loops_per_jiffy;
73
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);
81 }
82
83 void __init smp_cpus_done(unsigned int max_cpus)
84 {
85 }
86
87 void cpu_panic(void)
88 {
89         printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
90         panic("SMP bolixed\n");
91 }
92
93 struct linux_prom_registers smp_penguin_ctable __initdata = { 0 };
94
95 void __init smp_boot_cpus(void)
96 {
97         extern void smp4m_boot_cpus(void);
98         extern void smp4d_boot_cpus(void);
99         
100         if (sparc_cpu_model == sun4m)
101                 smp4m_boot_cpus();
102         else
103                 smp4d_boot_cpus();
104 }
105
106 void smp_send_reschedule(int cpu)
107 {
108         /* See sparc64 */
109 }
110
111 void smp_send_stop(void)
112 {
113 }
114
115 void smp_flush_cache_all(void)
116 {
117         xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
118         local_flush_cache_all();
119 }
120
121 void smp_flush_tlb_all(void)
122 {
123         xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
124         local_flush_tlb_all();
125 }
126
127 void smp_flush_cache_mm(struct mm_struct *mm)
128 {
129         if(mm->context != NO_CONTEXT) {
130                 cpumask_t cpu_mask = mm->cpu_vm_mask;
131                 cpu_clear(smp_processor_id(), cpu_mask);
132                 if (!cpus_empty(cpu_mask))
133                         xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
134                 local_flush_cache_mm(mm);
135         }
136 }
137
138 void smp_flush_tlb_mm(struct mm_struct *mm)
139 {
140         if(mm->context != NO_CONTEXT) {
141                 cpumask_t cpu_mask = mm->cpu_vm_mask;
142                 cpu_clear(smp_processor_id(), cpu_mask);
143                 if (!cpus_empty(cpu_mask)) {
144                         xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
145                         if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
146                                 mm->cpu_vm_mask = cpumask_of_cpu(smp_processor_id());
147                 }
148                 local_flush_tlb_mm(mm);
149         }
150 }
151
152 void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
153                            unsigned long end)
154 {
155         struct mm_struct *mm = vma->vm_mm;
156
157         if (mm->context != NO_CONTEXT) {
158                 cpumask_t cpu_mask = mm->cpu_vm_mask;
159                 cpu_clear(smp_processor_id(), cpu_mask);
160                 if (!cpus_empty(cpu_mask))
161                         xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
162                 local_flush_cache_range(vma, start, end);
163         }
164 }
165
166 void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
167                          unsigned long end)
168 {
169         struct mm_struct *mm = vma->vm_mm;
170
171         if (mm->context != NO_CONTEXT) {
172                 cpumask_t cpu_mask = mm->cpu_vm_mask;
173                 cpu_clear(smp_processor_id(), cpu_mask);
174                 if (!cpus_empty(cpu_mask))
175                         xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
176                 local_flush_tlb_range(vma, start, end);
177         }
178 }
179
180 void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
181 {
182         struct mm_struct *mm = vma->vm_mm;
183
184         if(mm->context != NO_CONTEXT) {
185                 cpumask_t cpu_mask = mm->cpu_vm_mask;
186                 cpu_clear(smp_processor_id(), cpu_mask);
187                 if (!cpus_empty(cpu_mask))
188                         xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
189                 local_flush_cache_page(vma, page);
190         }
191 }
192
193 void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
194 {
195         struct mm_struct *mm = vma->vm_mm;
196
197         if(mm->context != NO_CONTEXT) {
198                 cpumask_t cpu_mask = mm->cpu_vm_mask;
199                 cpu_clear(smp_processor_id(), cpu_mask);
200                 if (!cpus_empty(cpu_mask))
201                         xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
202                 local_flush_tlb_page(vma, page);
203         }
204 }
205
206 void smp_flush_page_to_ram(unsigned long page)
207 {
208         /* Current theory is that those who call this are the one's
209          * who have just dirtied their cache with the pages contents
210          * in kernel space, therefore we only run this on local cpu.
211          *
212          * XXX This experiment failed, research further... -DaveM
213          */
214 #if 1
215         xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
216 #endif
217         local_flush_page_to_ram(page);
218 }
219
220 void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
221 {
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_sig_insns), (unsigned long) mm, insn_addr);
226         local_flush_sig_insns(mm, insn_addr);
227 }
228
229 extern unsigned int lvl14_resolution;
230
231 /* /proc/profile writes can call this, don't __init it please. */
232 static spinlock_t prof_setup_lock = SPIN_LOCK_UNLOCKED;
233
234 int setup_profiling_timer(unsigned int multiplier)
235 {
236         int i;
237         unsigned long flags;
238
239         /* Prevent level14 ticker IRQ flooding. */
240         if((!multiplier) || (lvl14_resolution / multiplier) < 500)
241                 return -EINVAL;
242
243         spin_lock_irqsave(&prof_setup_lock, flags);
244         for(i = 0; i < NR_CPUS; i++) {
245                 if (cpu_possible(i))
246                         load_profile_irq(i, lvl14_resolution / multiplier);
247                 prof_multiplier(i) = multiplier;
248         }
249         spin_unlock_irqrestore(&prof_setup_lock, flags);
250
251         return 0;
252 }
253
254 void __init smp_prepare_cpus(unsigned int maxcpus)
255 {
256 }
257
258 void __devinit smp_prepare_boot_cpu(void)
259 {
260         current_thread_info()->cpu = hard_smp_processor_id();
261         cpu_set(smp_processor_id(), cpu_online_map);
262         cpu_set(smp_processor_id(), phys_cpu_present_map);
263 }
264
265 int __devinit __cpu_up(unsigned int cpu)
266 {
267         panic("smp doesn't work\n");
268 }
269
270 void smp_bogo(struct seq_file *m)
271 {
272         int i;
273         
274         for (i = 0; i < NR_CPUS; i++) {
275                 if (cpu_online(i))
276                         seq_printf(m,
277                                    "Cpu%dBogo\t: %lu.%02lu\n", 
278                                    i,
279                                    cpu_data(i).udelay_val/(500000/HZ),
280                                    (cpu_data(i).udelay_val/(5000/HZ))%100);
281         }
282 }
283
284 void smp_info(struct seq_file *m)
285 {
286         int i;
287
288         seq_printf(m, "State:\n");
289         for (i = 0; i < NR_CPUS; i++) {
290                 if (cpu_online(i))
291                         seq_printf(m, "CPU%d\t\t: online\n", i);
292         }
293 }