VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[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 unsigned long cache_decay_ticks = 100;
49
50 cpumask_t cpu_online_map = CPU_MASK_NONE;
51 cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
52
53 /* The only guaranteed locking primitive available on all Sparc
54  * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
55  * places the current byte at the effective address into dest_reg and
56  * places 0xff there afterwards.  Pretty lame locking primitive
57  * compared to the Alpha and the Intel no?  Most Sparcs have 'swap'
58  * instruction which is much better...
59  */
60
61 /* Used to make bitops atomic */
62 unsigned char bitops_spinlock = 0;
63
64 volatile unsigned long ipi_count;
65
66 volatile int smp_process_available=0;
67 volatile int smp_commenced = 0;
68
69 void __init smp_store_cpu_info(int id)
70 {
71         int cpu_node;
72
73         cpu_data(id).udelay_val = loops_per_jiffy;
74
75         cpu_find_by_mid(id, &cpu_node);
76         cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
77                                                      "clock-frequency", 0);
78         cpu_data(id).prom_node = cpu_node;
79         cpu_data(id).mid = cpu_get_hwmid(cpu_node);
80         if (cpu_data(id).mid < 0)
81                 panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
82 }
83
84 void __init smp_cpus_done(unsigned int max_cpus)
85 {
86 }
87
88 void cpu_panic(void)
89 {
90         printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
91         panic("SMP bolixed\n");
92 }
93
94 struct linux_prom_registers smp_penguin_ctable __initdata = { 0 };
95
96 void __init smp_boot_cpus(void)
97 {
98         extern void smp4m_boot_cpus(void);
99         extern void smp4d_boot_cpus(void);
100         
101         if (sparc_cpu_model == sun4m)
102                 smp4m_boot_cpus();
103         else
104                 smp4d_boot_cpus();
105 }
106
107 void smp_send_reschedule(int cpu)
108 {
109         /* See sparc64 */
110 }
111
112 void smp_send_stop(void)
113 {
114 }
115
116 void smp_flush_cache_all(void)
117 {
118         xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
119         local_flush_cache_all();
120 }
121
122 void smp_flush_tlb_all(void)
123 {
124         xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
125         local_flush_tlb_all();
126 }
127
128 void smp_flush_cache_mm(struct mm_struct *mm)
129 {
130         if(mm->context != NO_CONTEXT) {
131                 cpumask_t cpu_mask = mm->cpu_vm_mask;
132                 cpu_clear(smp_processor_id(), cpu_mask);
133                 if (!cpus_empty(cpu_mask))
134                         xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
135                 local_flush_cache_mm(mm);
136         }
137 }
138
139 void smp_flush_tlb_mm(struct mm_struct *mm)
140 {
141         if(mm->context != NO_CONTEXT) {
142                 cpumask_t cpu_mask = mm->cpu_vm_mask;
143                 cpu_clear(smp_processor_id(), cpu_mask);
144                 if (!cpus_empty(cpu_mask)) {
145                         xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
146                         if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
147                                 mm->cpu_vm_mask = cpumask_of_cpu(smp_processor_id());
148                 }
149                 local_flush_tlb_mm(mm);
150         }
151 }
152
153 void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
154                            unsigned long end)
155 {
156         struct mm_struct *mm = vma->vm_mm;
157
158         if (mm->context != NO_CONTEXT) {
159                 cpumask_t cpu_mask = mm->cpu_vm_mask;
160                 cpu_clear(smp_processor_id(), cpu_mask);
161                 if (!cpus_empty(cpu_mask))
162                         xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
163                 local_flush_cache_range(vma, start, end);
164         }
165 }
166
167 void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
168                          unsigned long end)
169 {
170         struct mm_struct *mm = vma->vm_mm;
171
172         if (mm->context != NO_CONTEXT) {
173                 cpumask_t cpu_mask = mm->cpu_vm_mask;
174                 cpu_clear(smp_processor_id(), cpu_mask);
175                 if (!cpus_empty(cpu_mask))
176                         xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
177                 local_flush_tlb_range(vma, start, end);
178         }
179 }
180
181 void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
182 {
183         struct mm_struct *mm = vma->vm_mm;
184
185         if(mm->context != NO_CONTEXT) {
186                 cpumask_t cpu_mask = mm->cpu_vm_mask;
187                 cpu_clear(smp_processor_id(), cpu_mask);
188                 if (!cpus_empty(cpu_mask))
189                         xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
190                 local_flush_cache_page(vma, page);
191         }
192 }
193
194 void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
195 {
196         struct mm_struct *mm = vma->vm_mm;
197
198         if(mm->context != NO_CONTEXT) {
199                 cpumask_t cpu_mask = mm->cpu_vm_mask;
200                 cpu_clear(smp_processor_id(), cpu_mask);
201                 if (!cpus_empty(cpu_mask))
202                         xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
203                 local_flush_tlb_page(vma, page);
204         }
205 }
206
207 void smp_reschedule_irq(void)
208 {
209         set_need_resched();
210 }
211
212 void smp_flush_page_to_ram(unsigned long page)
213 {
214         /* Current theory is that those who call this are the one's
215          * who have just dirtied their cache with the pages contents
216          * in kernel space, therefore we only run this on local cpu.
217          *
218          * XXX This experiment failed, research further... -DaveM
219          */
220 #if 1
221         xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
222 #endif
223         local_flush_page_to_ram(page);
224 }
225
226 void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
227 {
228         cpumask_t cpu_mask = mm->cpu_vm_mask;
229         cpu_clear(smp_processor_id(), cpu_mask);
230         if (!cpus_empty(cpu_mask))
231                 xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
232         local_flush_sig_insns(mm, insn_addr);
233 }
234
235 extern unsigned int lvl14_resolution;
236
237 /* /proc/profile writes can call this, don't __init it please. */
238 static spinlock_t prof_setup_lock = SPIN_LOCK_UNLOCKED;
239
240 int setup_profiling_timer(unsigned int multiplier)
241 {
242         int i;
243         unsigned long flags;
244
245         /* Prevent level14 ticker IRQ flooding. */
246         if((!multiplier) || (lvl14_resolution / multiplier) < 500)
247                 return -EINVAL;
248
249         spin_lock_irqsave(&prof_setup_lock, flags);
250         for(i = 0; i < NR_CPUS; i++) {
251                 if (cpu_possible(i))
252                         load_profile_irq(i, lvl14_resolution / multiplier);
253                 prof_multiplier(i) = multiplier;
254         }
255         spin_unlock_irqrestore(&prof_setup_lock, flags);
256
257         return 0;
258 }
259
260 void __init smp_prepare_cpus(unsigned int maxcpus)
261 {
262 }
263
264 void __devinit smp_prepare_boot_cpu(void)
265 {
266         current_thread_info()->cpu = hard_smp_processor_id();
267         cpu_set(smp_processor_id(), cpu_online_map);
268         cpu_set(smp_processor_id(), phys_cpu_present_map);
269 }
270
271 int __devinit __cpu_up(unsigned int cpu)
272 {
273         panic("smp doesn't work\n");
274 }
275
276 void smp_bogo(struct seq_file *m)
277 {
278         int i;
279         
280         for (i = 0; i < NR_CPUS; i++) {
281                 if (cpu_online(i))
282                         seq_printf(m,
283                                    "Cpu%dBogo\t: %lu.%02lu\n", 
284                                    i,
285                                    cpu_data(i).udelay_val/(500000/HZ),
286                                    (cpu_data(i).udelay_val/(5000/HZ))%100);
287         }
288 }
289
290 void smp_info(struct seq_file *m)
291 {
292         int i;
293
294         seq_printf(m, "State:\n");
295         for (i = 0; i < NR_CPUS; i++) {
296                 if (cpu_online(i))
297                         seq_printf(m, "CPU%d\t\t: online\n", i);
298         }
299 }