sparc32: Move cache and TLB flushes over to method ops.
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / sparc / kernel / smp_32.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/interrupt.h>
15 #include <linux/kernel_stat.h>
16 #include <linux/init.h>
17 #include <linux/spinlock.h>
18 #include <linux/mm.h>
19 #include <linux/fs.h>
20 #include <linux/seq_file.h>
21 #include <linux/cache.h>
22 #include <linux/delay.h>
23
24 #include <asm/ptrace.h>
25 #include <linux/atomic.h>
26
27 #include <asm/irq.h>
28 #include <asm/page.h>
29 #include <asm/pgalloc.h>
30 #include <asm/pgtable.h>
31 #include <asm/oplib.h>
32 #include <asm/cacheflush.h>
33 #include <asm/tlbflush.h>
34 #include <asm/cpudata.h>
35 #include <asm/leon.h>
36
37 #include "irq.h"
38
39 volatile unsigned long cpu_callin_map[NR_CPUS] __cpuinitdata = {0,};
40
41 cpumask_t smp_commenced_mask = CPU_MASK_NONE;
42
43 /* The only guaranteed locking primitive available on all Sparc
44  * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
45  * places the current byte at the effective address into dest_reg and
46  * places 0xff there afterwards.  Pretty lame locking primitive
47  * compared to the Alpha and the Intel no?  Most Sparcs have 'swap'
48  * instruction which is much better...
49  */
50
51 void __cpuinit smp_store_cpu_info(int id)
52 {
53         int cpu_node;
54         int mid;
55
56         cpu_data(id).udelay_val = loops_per_jiffy;
57
58         cpu_find_by_mid(id, &cpu_node);
59         cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
60                                                      "clock-frequency", 0);
61         cpu_data(id).prom_node = cpu_node;
62         mid = cpu_get_hwmid(cpu_node);
63
64         if (mid < 0) {
65                 printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08d", id, cpu_node);
66                 mid = 0;
67         }
68         cpu_data(id).mid = mid;
69 }
70
71 void __init smp_cpus_done(unsigned int max_cpus)
72 {
73         extern void smp4m_smp_done(void);
74         extern void smp4d_smp_done(void);
75         unsigned long bogosum = 0;
76         int cpu, num = 0;
77
78         for_each_online_cpu(cpu) {
79                 num++;
80                 bogosum += cpu_data(cpu).udelay_val;
81         }
82
83         printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
84                 num, bogosum/(500000/HZ),
85                 (bogosum/(5000/HZ))%100);
86
87         switch(sparc_cpu_model) {
88         case sun4m:
89                 smp4m_smp_done();
90                 break;
91         case sun4d:
92                 smp4d_smp_done();
93                 break;
94         case sparc_leon:
95                 leon_smp_done();
96                 break;
97         case sun4e:
98                 printk("SUN4E\n");
99                 BUG();
100                 break;
101         case sun4u:
102                 printk("SUN4U\n");
103                 BUG();
104                 break;
105         default:
106                 printk("UNKNOWN!\n");
107                 BUG();
108                 break;
109         }
110 }
111
112 void cpu_panic(void)
113 {
114         printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
115         panic("SMP bolixed\n");
116 }
117
118 struct linux_prom_registers smp_penguin_ctable __cpuinitdata = { 0 };
119
120 void smp_send_reschedule(int cpu)
121 {
122         /*
123          * CPU model dependent way of implementing IPI generation targeting
124          * a single CPU. The trap handler needs only to do trap entry/return
125          * to call schedule.
126          */
127         BTFIXUP_CALL(smp_ipi_resched)(cpu);
128 }
129
130 void smp_send_stop(void)
131 {
132 }
133
134 void arch_send_call_function_single_ipi(int cpu)
135 {
136         /* trigger one IPI single call on one CPU */
137         BTFIXUP_CALL(smp_ipi_single)(cpu);
138 }
139
140 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
141 {
142         int cpu;
143
144         /* trigger IPI mask call on each CPU */
145         for_each_cpu(cpu, mask)
146                 BTFIXUP_CALL(smp_ipi_mask_one)(cpu);
147 }
148
149 void smp_resched_interrupt(void)
150 {
151         irq_enter();
152         scheduler_ipi();
153         local_cpu_data().irq_resched_count++;
154         irq_exit();
155         /* re-schedule routine called by interrupt return code. */
156 }
157
158 void smp_call_function_single_interrupt(void)
159 {
160         irq_enter();
161         generic_smp_call_function_single_interrupt();
162         local_cpu_data().irq_call_count++;
163         irq_exit();
164 }
165
166 void smp_call_function_interrupt(void)
167 {
168         irq_enter();
169         generic_smp_call_function_interrupt();
170         local_cpu_data().irq_call_count++;
171         irq_exit();
172 }
173
174 int setup_profiling_timer(unsigned int multiplier)
175 {
176         return -EINVAL;
177 }
178
179 void __init smp_prepare_cpus(unsigned int max_cpus)
180 {
181         extern void __init smp4m_boot_cpus(void);
182         extern void __init smp4d_boot_cpus(void);
183         int i, cpuid, extra;
184
185         printk("Entering SMP Mode...\n");
186
187         extra = 0;
188         for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
189                 if (cpuid >= NR_CPUS)
190                         extra++;
191         }
192         /* i = number of cpus */
193         if (extra && max_cpus > i - extra)
194                 printk("Warning: NR_CPUS is too low to start all cpus\n");
195
196         smp_store_cpu_info(boot_cpu_id);
197
198         switch(sparc_cpu_model) {
199         case sun4m:
200                 smp4m_boot_cpus();
201                 break;
202         case sun4d:
203                 smp4d_boot_cpus();
204                 break;
205         case sparc_leon:
206                 leon_boot_cpus();
207                 break;
208         case sun4e:
209                 printk("SUN4E\n");
210                 BUG();
211                 break;
212         case sun4u:
213                 printk("SUN4U\n");
214                 BUG();
215                 break;
216         default:
217                 printk("UNKNOWN!\n");
218                 BUG();
219                 break;
220         }
221 }
222
223 /* Set this up early so that things like the scheduler can init
224  * properly.  We use the same cpu mask for both the present and
225  * possible cpu map.
226  */
227 void __init smp_setup_cpu_possible_map(void)
228 {
229         int instance, mid;
230
231         instance = 0;
232         while (!cpu_find_by_instance(instance, NULL, &mid)) {
233                 if (mid < NR_CPUS) {
234                         set_cpu_possible(mid, true);
235                         set_cpu_present(mid, true);
236                 }
237                 instance++;
238         }
239 }
240
241 void __init smp_prepare_boot_cpu(void)
242 {
243         int cpuid = hard_smp_processor_id();
244
245         if (cpuid >= NR_CPUS) {
246                 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
247                 prom_halt();
248         }
249         if (cpuid != 0)
250                 printk("boot cpu id != 0, this could work but is untested\n");
251
252         current_thread_info()->cpu = cpuid;
253         set_cpu_online(cpuid, true);
254         set_cpu_possible(cpuid, true);
255 }
256
257 int __cpuinit __cpu_up(unsigned int cpu)
258 {
259         extern int __cpuinit smp4m_boot_one_cpu(int);
260         extern int __cpuinit smp4d_boot_one_cpu(int);
261         int ret=0;
262
263         switch(sparc_cpu_model) {
264         case sun4m:
265                 ret = smp4m_boot_one_cpu(cpu);
266                 break;
267         case sun4d:
268                 ret = smp4d_boot_one_cpu(cpu);
269                 break;
270         case sparc_leon:
271                 ret = leon_boot_one_cpu(cpu);
272                 break;
273         case sun4e:
274                 printk("SUN4E\n");
275                 BUG();
276                 break;
277         case sun4u:
278                 printk("SUN4U\n");
279                 BUG();
280                 break;
281         default:
282                 printk("UNKNOWN!\n");
283                 BUG();
284                 break;
285         }
286
287         if (!ret) {
288                 cpumask_set_cpu(cpu, &smp_commenced_mask);
289                 while (!cpu_online(cpu))
290                         mb();
291         }
292         return ret;
293 }
294
295 void smp_bogo(struct seq_file *m)
296 {
297         int i;
298         
299         for_each_online_cpu(i) {
300                 seq_printf(m,
301                            "Cpu%dBogo\t: %lu.%02lu\n",
302                            i,
303                            cpu_data(i).udelay_val/(500000/HZ),
304                            (cpu_data(i).udelay_val/(5000/HZ))%100);
305         }
306 }
307
308 void smp_info(struct seq_file *m)
309 {
310         int i;
311
312         seq_printf(m, "State:\n");
313         for_each_online_cpu(i)
314                 seq_printf(m, "CPU%d\t\t: online\n", i);
315 }