cpu.c revision 1.3 1 /* $NetBSD: cpu.c,v 1.3 2001/06/03 18:32:34 chris Exp $ */
2
3 /*
4 * Copyright (c) 1995 Mark Brinicombe.
5 * Copyright (c) 1995 Brini.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Brini.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * RiscBSD kernel project
36 *
37 * cpu.c
38 *
39 * Probing and configuration for the master cpu
40 *
41 * Created : 10/10/95
42 */
43
44 #include "opt_armfpe.h"
45 #include "opt_cputypes.h"
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51 #include <sys/proc.h>
52 #include <uvm/uvm_extern.h>
53 #include <machine/conf.h>
54 #include <machine/cpu.h>
55 #include <machine/cpus.h>
56 #include <machine/undefined.h>
57
58 #ifdef ARMFPE
59 #include <machine/bootconfig.h> /* For boot args */
60 #include <arm32/fpe-arm/armfpe.h>
61 #endif /* ARMFPE */
62
63 cpu_t cpus[MAX_CPUS];
64
65 char cpu_model[64];
66 volatile int undefined_test; /* Used for FPA test */
67 extern int cpuctrl; /* cpu control register value */
68
69 /* Prototypes */
70 void identify_master_cpu __P((struct device *dv, int cpu_number));
71 void identify_arm_cpu __P((struct device *dv, int cpu_number));
72 void identify_arm_fpu __P((struct device *dv, int cpu_number));
73
74
75 /*
76 * void cpusattach(struct device *parent, struct device *dev, void *aux)
77 *
78 * Attach the main cpu
79 */
80
81 void
82 cpu_attach(dv)
83 struct device *dv;
84 {
85 identify_master_cpu(dv, CPU_MASTER);
86 }
87
88 /*
89 * Used to test for an FPA. The following function is installed as a coproc1
90 * handler on the undefined instruction vector and then we issue a FPA
91 * instruction. If undefined_test is non zero then the FPA did not handle
92 * the instruction so must be absent.
93 */
94
95 int
96 fpa_test(address, instruction, frame)
97 u_int address;
98 u_int instruction;
99 trapframe_t *frame;
100 {
101
102 frame->tf_pc += INSN_SIZE;
103 ++undefined_test;
104 return(0);
105 }
106
107 /*
108 * If an FPA was found then this function is installed as the coproc1 handler
109 * on the undefined instruction vector. Currently we don't support FPA's
110 * so this just triggers an exception.
111 */
112
113 int
114 fpa_handler(address, instruction, frame, fault_code)
115 u_int address;
116 u_int instruction;
117 trapframe_t *frame;
118 int fault_code;
119 {
120 u_int fpsr;
121
122 __asm __volatile("stmfd sp!, {r0}; .word 0xee300110; mov %0, r0; ldmfd sp!, {r0}" : "=r" (fpsr));
123
124 printf("FPA exception: fpsr = %08x\n", fpsr);
125
126 return(1);
127 }
128
129
130 /*
131 * Identify the master (boot) CPU
132 * This also probes for an FPU and will install an FPE if necessary
133 */
134
135 void
136 identify_master_cpu(dv, cpu_number)
137 struct device *dv;
138 int cpu_number;
139 {
140 u_int fpsr;
141 void *uh;
142
143 cpus[cpu_number].cpu_ctrl = cpuctrl;
144
145 /* Get the cpu ID from coprocessor 15 */
146
147 cpus[cpu_number].cpu_id = cpu_id();
148
149 identify_arm_cpu(dv, cpu_number);
150 strcpy(cpu_model, cpus[cpu_number].cpu_model);
151
152 if (cpus[CPU_MASTER].cpu_class == CPU_CLASS_SA1
153 && (cpus[CPU_MASTER].cpu_id & CPU_ID_REVISION_MASK) < 3) {
154 printf("%s: SA-110 with bugged STM^ instruction\n",
155 dv->dv_xname);
156 }
157
158 #ifdef CPU_ARM8
159 if ((cpus[CPU_MASTER].cpu_id & CPU_ID_CPU_MASK) == CPU_ID_ARM810) {
160 int clock = arm8_clock_config(0, 0);
161 char *fclk;
162 printf("%s: ARM810 cp15=%02x", dv->dv_xname, clock);
163 printf(" clock:%s", (clock & 1) ? " dynamic" : "");
164 printf("%s", (clock & 2) ? " sync" : "");
165 switch ((clock >> 2) & 3) {
166 case 0 :
167 fclk = "bus clock";
168 break;
169 case 1 :
170 fclk = "ref clock";
171 break;
172 case 3 :
173 fclk = "pll";
174 break;
175 default :
176 fclk = "illegal";
177 break;
178 }
179 printf(" fclk source=%s\n", fclk);
180 }
181 #endif
182
183 /*
184 * Ok now we test for an FPA
185 * At this point no floating point emulator has been installed.
186 * This means any FP instruction will cause undefined exception.
187 * We install a temporay coproc 1 handler which will modify
188 * undefined_test if it is called.
189 * We then try to read the FP status register. If undefined_test
190 * has been decremented then the instruction was not handled by
191 * an FPA so we know the FPA is missing. If undefined_test is
192 * still 1 then we know the instruction was handled by an FPA.
193 * We then remove our test handler and look at the
194 * FP status register for identification.
195 */
196
197 uh = install_coproc_handler(FP_COPROC, fpa_test);
198
199 undefined_test = 0;
200
201 __asm __volatile("stmfd sp!, {r0}; .word 0xee300110; mov %0, r0; ldmfd sp!, {r0}" : "=r" (fpsr));
202
203 remove_coproc_handler(uh);
204
205 if (undefined_test == 0) {
206 cpus[cpu_number].fpu_type = (fpsr >> 24);
207 switch (fpsr >> 24) {
208 case 0x81 :
209 cpus[cpu_number].fpu_class = FPU_CLASS_FPA;
210 break;
211
212 default :
213 cpus[cpu_number].fpu_class = FPU_CLASS_FPU;
214 break;
215 }
216 cpus[cpu_number].fpu_flags = 0;
217 install_coproc_handler(FP_COPROC, fpa_handler);
218 } else {
219 cpus[cpu_number].fpu_class = FPU_CLASS_NONE;
220 cpus[cpu_number].fpu_flags = 0;
221
222 /*
223 * Ok if ARMFPE is defined and the boot options request the
224 * ARM FPE then it will be installed as the FPE.
225 * This is just while I work on integrating the new FPE.
226 * It means the new FPE gets installed if compiled int (ARMFPE
227 * defined) and also gives me a on/off option when I boot in
228 * case the new FPE is causing panics.
229 */
230
231 #ifdef ARMFPE
232 if (boot_args) {
233 int usearmfpe = 1;
234
235 get_bootconf_option(boot_args, "armfpe",
236 BOOTOPT_TYPE_BOOLEAN, &usearmfpe);
237 if (usearmfpe) {
238 if (initialise_arm_fpe(&cpus[cpu_number]) != 0)
239 identify_arm_fpu(dv, cpu_number);
240 }
241 }
242
243 #endif
244 }
245
246 identify_arm_fpu(dv, cpu_number);
247 }
248
249 struct cpuidtab {
250 u_int32_t cpuid;
251 enum cpu_class cpu_class;
252 char * cpu_name;
253 };
254
255 const struct cpuidtab cpuids[] = {
256 { CPU_ID_ARM2, CPU_CLASS_ARM2, "ARM2" },
257 { CPU_ID_ARM250, CPU_CLASS_ARM2AS, "ARM250" },
258 { CPU_ID_ARM3, CPU_CLASS_ARM3, "ARM3" },
259 { CPU_ID_ARM600, CPU_CLASS_ARM6, "ARM600" },
260 { CPU_ID_ARM610, CPU_CLASS_ARM6, "ARM610" },
261 { CPU_ID_ARM620, CPU_CLASS_ARM6, "ARM620" },
262 { CPU_ID_ARM700, CPU_CLASS_ARM7, "ARM700" },
263 { CPU_ID_ARM710, CPU_CLASS_ARM7, "ARM710" },
264 { CPU_ID_ARM7500, CPU_CLASS_ARM7, "ARM7500" },
265 { CPU_ID_ARM710A, CPU_CLASS_ARM7, "ARM710a" },
266 { CPU_ID_ARM7500FE, CPU_CLASS_ARM7, "ARM7500FE" },
267 { CPU_ID_ARM710T, CPU_CLASS_ARM7TDMI, "ARM710T" },
268 { CPU_ID_ARM720T, CPU_CLASS_ARM7TDMI, "ARM720T" },
269 { CPU_ID_ARM740T8K, CPU_CLASS_ARM7TDMI, "ARM740T (8 KB cache)" },
270 { CPU_ID_ARM740T4K, CPU_CLASS_ARM7TDMI, "ARM740T (4 KB cache)" },
271 { CPU_ID_ARM810, CPU_CLASS_ARM8, "ARM810" },
272 { CPU_ID_ARM920T, CPU_CLASS_ARM9TDMI, "ARM920T" },
273 { CPU_ID_ARM922T, CPU_CLASS_ARM9TDMI, "ARM922T" },
274 { CPU_ID_ARM940T, CPU_CLASS_ARM9TDMI, "ARM940T" },
275 { CPU_ID_ARM946ES, CPU_CLASS_ARM9ES, "ARM946E-S" },
276 { CPU_ID_ARM966ES, CPU_CLASS_ARM9ES, "ARM966E-S" },
277 { CPU_ID_ARM966ESR1, CPU_CLASS_ARM9ES, "ARM966E-S (Rev 1)" },
278 { CPU_ID_SA110, CPU_CLASS_SA1, "SA-110" },
279 { CPU_ID_SA1100, CPU_CLASS_SA1, "SA-1100" },
280 { CPU_ID_SA1110, CPU_CLASS_SA1, "SA-1110" },
281 { CPU_ID_I80200, CPU_CLASS_XSCALE, "80200" },
282 { 0, CPU_CLASS_NONE, NULL }
283 };
284
285 struct cpu_classtab {
286 char *class_name;
287 char *class_option;
288 };
289
290 const struct cpu_classtab cpu_classes[] = {
291 { "unknown", NULL }, /* CPU_CLASS_NONE */
292 { "ARM2", "CPU_ARM2" }, /* CPU_CLASS_ARM2 */
293 { "ARM2as", "CPU_ARM250" }, /* CPU_CLASS_ARM2AS */
294 { "ARM3", "CPU_ARM3" }, /* CPU_CLASS_ARM3 */
295 { "ARM6", "CPU_ARM6" }, /* CPU_CLASS_ARM6 */
296 { "ARM7", "CPU_ARM7" }, /* CPU_CLASS_ARM7 */
297 { "ARM7TDMI", "CPU_ARM7TDMI" },/* CPU_CLASS_ARM7TDMI */
298 { "ARM8", "CPU_ARM8" }, /* CPU_CLASS_ARM8 */
299 { "ARM9TDMI", NULL }, /* CPU_CLASS_ARM9TDMI */
300 { "ARM9E-S", NULL }, /* CPU_CLASS_ARM9ES */
301 { "SA-1", "CPU_SA110" }, /* CPU_CLASS_SA1 */
302 { "Xscale", NULL }, /* CPU_CLASS_XSCALE */
303 };
304
305 /*
306 * Report the type of the specifed arm processor. This uses the generic and
307 * arm specific information in the cpu structure to identify the processor.
308 * The remaining fields in the cpu structure are filled in appropriately.
309 */
310
311 void
312 identify_arm_cpu(dv, cpu_number)
313 struct device *dv;
314 int cpu_number;
315 {
316 cpu_t *cpu;
317 u_int cpuid;
318 int i;
319
320 cpu = &cpus[cpu_number];
321 cpuid = cpu->cpu_id;
322
323 if (cpuid == 0) {
324 printf("Processor failed probe - no CPU ID\n");
325 return;
326 }
327
328 for (i = 0; cpuids[i].cpuid != 0; i++)
329 if (cpuids[i].cpuid == (cpuid & CPU_ID_CPU_MASK)) {
330 cpu->cpu_class = cpuids[i].cpu_class;
331 sprintf(cpu->cpu_model, "%s rev %d (%s core)",
332 cpuids[i].cpu_name, cpuid & CPU_ID_REVISION_MASK,
333 cpu_classes[cpu->cpu_class].class_name);
334 break;
335 }
336
337 if (cpuids[i].cpuid == 0)
338 sprintf(cpu->cpu_model, "unknown CPU (ID = 0x%x)", cpuid);
339
340 switch (cpu->cpu_class) {
341 case CPU_CLASS_ARM6:
342 case CPU_CLASS_ARM7:
343 case CPU_CLASS_ARM7TDMI:
344 case CPU_CLASS_ARM8:
345 if ((cpu->cpu_ctrl & CPU_CONTROL_IDC_ENABLE) == 0)
346 strcat(cpu->cpu_model, " IDC disabled");
347 else
348 strcat(cpu->cpu_model, " IDC enabled");
349 break;
350 case CPU_CLASS_SA1:
351 if ((cpu->cpu_ctrl & CPU_CONTROL_DC_ENABLE) == 0)
352 strcat(cpu->cpu_model, " DC disabled");
353 else
354 strcat(cpu->cpu_model, " DC enabled");
355 if ((cpu->cpu_ctrl & CPU_CONTROL_IC_ENABLE) == 0)
356 strcat(cpu->cpu_model, " IC disabled");
357 else
358 strcat(cpu->cpu_model, " IC enabled");
359 break;
360 }
361 if ((cpu->cpu_ctrl & CPU_CONTROL_WBUF_ENABLE) == 0)
362 strcat(cpu->cpu_model, " WB disabled");
363 else
364 strcat(cpu->cpu_model, " WB enabled");
365
366 if (cpu->cpu_ctrl & CPU_CONTROL_LABT_ENABLE)
367 strcat(cpu->cpu_model, " LABT");
368 else
369 strcat(cpu->cpu_model, " EABT");
370
371 if (cpu->cpu_ctrl & CPU_CONTROL_BPRD_ENABLE)
372 strcat(cpu->cpu_model, " branch prediction enabled");
373
374 /* Print the info */
375
376 printf(": %s\n", cpu->cpu_model);
377
378 switch (cpu->cpu_class) {
379 #ifdef CPU_ARM2
380 case CPU_CLASS_ARM2:
381 #endif
382 #ifdef CPU_ARM250
383 case CPU_CLASS_ARM2AS:
384 #endif
385 #ifdef CPU_ARM3
386 case CPU_CLASS_ARM3:
387 #endif
388 #ifdef CPU_ARM6
389 case CPU_CLASS_ARM6:
390 #endif
391 #ifdef CPU_ARM7
392 case CPU_CLASS_ARM7:
393 #endif
394 #ifdef CPU_ARM7TDMI
395 case CPU_CLASS_ARM7TDMI:
396 #endif
397 #ifdef CPU_ARM8
398 case CPU_CLASS_ARM8:
399 #endif
400 #ifdef CPU_SA110
401 case CPU_CLASS_SA1:
402 #endif
403 break;
404 default:
405 if (cpu_classes[cpu->cpu_class].class_option != NULL)
406 printf("%s: %s does not fully support this CPU."
407 "\n", dv->dv_xname, ostype);
408 else {
409 printf("%s: This kernel does not fully support "
410 "this CPU.\n", dv->dv_xname);
411 printf("%s: Recompile with \"options %s\" to "
412 "correct this.\n", dv->dv_xname,
413 cpu_classes[cpu->cpu_class].class_option);
414 }
415 break;
416 }
417
418 }
419
420
421 /*
422 * Report the type of the specifed arm fpu. This uses the generic and arm
423 * specific information in the cpu structure to identify the fpu. The
424 * remaining fields in the cpu structure are filled in appropriately.
425 */
426
427 void
428 identify_arm_fpu(dv, cpu_number)
429 struct device *dv;
430 int cpu_number;
431 {
432 cpu_t *cpu;
433
434 cpu = &cpus[cpu_number];
435
436 /* Now for the FP info */
437
438 switch (cpu->fpu_class) {
439 case FPU_CLASS_NONE :
440 strcpy(cpu->fpu_model, "None");
441 break;
442 case FPU_CLASS_FPE :
443 printf("%s: FPE: %s\n", dv->dv_xname, cpu->fpu_model);
444 printf("%s: no FP hardware found\n", dv->dv_xname);
445 break;
446 case FPU_CLASS_FPA :
447 printf("%s: FPE: %s\n", dv->dv_xname, cpu->fpu_model);
448 if (cpu->fpu_type == FPU_TYPE_FPA11) {
449 strcpy(cpu->fpu_model, "FPA11");
450 printf("%s: FPA11 found\n", dv->dv_xname);
451 } else {
452 strcpy(cpu->fpu_model, "FPA");
453 printf("%s: FPA10 found\n", dv->dv_xname);
454 }
455 if ((cpu->fpu_flags & 4) == 0)
456 strcat(cpu->fpu_model, "");
457 else
458 strcat(cpu->fpu_model, " clk/2");
459 break;
460 case FPU_CLASS_FPU :
461 sprintf(cpu->fpu_model, "Unknown FPU (ID=%02x)\n",
462 cpu->fpu_type);
463 printf("%s: %s\n", dv->dv_xname, cpu->fpu_model);
464 break;
465 }
466 }
467
468 /* End of cpu.c */
469