1 /*-
2 * Copyright (c) 1992 Terrence R. Lambert.
3 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
4 * Copyright (c) 1997 KATO Takenori.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * from: Id: machdep.c,v 1.193 1996/06/18 01:22:04 bde Exp
39 */
40
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
43
44 #include "opt_cpu.h"
45
46 #include <sys/param.h>
47 #include <sys/bus.h>
48 #include <sys/cpu.h>
49 #include <sys/eventhandler.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/sysctl.h>
53 #include <sys/power.h>
54
55 #include <machine/asmacros.h>
56 #include <machine/clock.h>
57 #include <machine/cputypes.h>
58 #include <machine/intr_machdep.h>
59 #include <machine/md_var.h>
60 #include <machine/segments.h>
61 #include <machine/specialreg.h>
62
63 #define IDENTBLUE_CYRIX486 0
64 #define IDENTBLUE_IBMCPU 1
65 #define IDENTBLUE_CYRIXM2 2
66
67 /* XXX - should be in header file: */
68 void printcpuinfo(void);
69 void finishidentcpu(void);
70 void earlysetcpuclass(void);
71 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
72 void enable_K5_wt_alloc(void);
73 void enable_K6_wt_alloc(void);
74 void enable_K6_2_wt_alloc(void);
75 #endif
76 void panicifcpuunsupported(void);
77
78 static void identifycyrix(void);
79 static void init_exthigh(void);
80 static u_int find_cpu_vendor_id(void);
81 static void print_AMD_info(void);
82 static void print_INTEL_info(void);
83 static void print_INTEL_TLB(u_int data);
84 static void print_AMD_assoc(int i);
85 static void print_transmeta_info(void);
86 static void print_via_padlock_info(void);
87
88 int cpu_class;
89 u_int cpu_exthigh; /* Highest arg to extended CPUID */
90 u_int cyrix_did; /* Device ID of Cyrix CPU */
91 char machine[] = MACHINE;
92 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,
93 machine, 0, "Machine class");
94
95 static char cpu_model[128];
96 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD,
97 cpu_model, 0, "Machine model");
98
99 static int hw_clockrate;
100 SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD,
101 &hw_clockrate, 0, "CPU instruction clock rate");
102
103 static char cpu_brand[48];
104
105 #define MAX_BRAND_INDEX 8
106
107 static const char *cpu_brandtable[MAX_BRAND_INDEX + 1] = {
108 NULL, /* No brand */
109 "Intel Celeron",
110 "Intel Pentium III",
111 "Intel Pentium III Xeon",
112 NULL,
113 NULL,
114 NULL,
115 NULL,
116 "Intel Pentium 4"
117 };
118
119 static struct {
120 char *cpu_name;
121 int cpu_class;
122 } i386_cpus[] = {
123 { "Intel 80286", CPUCLASS_286 }, /* CPU_286 */
124 { "i386SX", CPUCLASS_386 }, /* CPU_386SX */
125 { "i386DX", CPUCLASS_386 }, /* CPU_386 */
126 { "i486SX", CPUCLASS_486 }, /* CPU_486SX */
127 { "i486DX", CPUCLASS_486 }, /* CPU_486 */
128 { "Pentium", CPUCLASS_586 }, /* CPU_586 */
129 { "Cyrix 486", CPUCLASS_486 }, /* CPU_486DLC */
130 { "Pentium Pro", CPUCLASS_686 }, /* CPU_686 */
131 { "Cyrix 5x86", CPUCLASS_486 }, /* CPU_M1SC */
132 { "Cyrix 6x86", CPUCLASS_486 }, /* CPU_M1 */
133 { "Blue Lightning", CPUCLASS_486 }, /* CPU_BLUE */
134 { "Cyrix 6x86MX", CPUCLASS_686 }, /* CPU_M2 */
135 { "NexGen 586", CPUCLASS_386 }, /* CPU_NX586 (XXX) */
136 { "Cyrix 486S/DX", CPUCLASS_486 }, /* CPU_CY486DX */
137 { "Pentium II", CPUCLASS_686 }, /* CPU_PII */
138 { "Pentium III", CPUCLASS_686 }, /* CPU_PIII */
139 { "Pentium 4", CPUCLASS_686 }, /* CPU_P4 */
140 };
141
142 static struct {
143 char *vendor;
144 u_int vendor_id;
145 } cpu_vendors[] = {
146 { INTEL_VENDOR_ID, CPU_VENDOR_INTEL }, /* GenuineIntel */
147 { AMD_VENDOR_ID, CPU_VENDOR_AMD }, /* AuthenticAMD */
148 { CENTAUR_VENDOR_ID, CPU_VENDOR_CENTAUR }, /* CentaurHauls */
149 { NSC_VENDOR_ID, CPU_VENDOR_NSC }, /* Geode by NSC */
150 { CYRIX_VENDOR_ID, CPU_VENDOR_CYRIX }, /* CyrixInstead */
151 { TRANSMETA_VENDOR_ID, CPU_VENDOR_TRANSMETA }, /* GenuineTMx86 */
152 { SIS_VENDOR_ID, CPU_VENDOR_SIS }, /* SiS SiS SiS */
153 { UMC_VENDOR_ID, CPU_VENDOR_UMC }, /* UMC UMC UMC */
154 { NEXGEN_VENDOR_ID, CPU_VENDOR_NEXGEN }, /* NexGenDriven */
155 { RISE_VENDOR_ID, CPU_VENDOR_RISE }, /* RiseRiseRise */
156 #if 0
157 /* XXX CPUID 8000_0000h and 8086_0000h, not 0000_0000h */
158 { "TransmetaCPU", CPU_VENDOR_TRANSMETA },
159 #endif
160 };
161
162 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
163 int has_f00f_bug = 0; /* Initialized so that it can be patched. */
164 #endif
165
166 static void
167 init_exthigh(void)
168 {
169 static int done = 0;
170 u_int regs[4];
171
172 if (done == 0) {
173 if (cpu_high > 0 &&
174 (cpu_vendor_id == CPU_VENDOR_INTEL ||
175 cpu_vendor_id == CPU_VENDOR_AMD ||
176 cpu_vendor_id == CPU_VENDOR_TRANSMETA ||
177 cpu_vendor_id == CPU_VENDOR_CENTAUR ||
178 cpu_vendor_id == CPU_VENDOR_NSC)) {
179 do_cpuid(0x80000000, regs);
180 if (regs[0] >= 0x80000000)
181 cpu_exthigh = regs[0];
182 }
183
184 done = 1;
185 }
186 }
187
188 void
189 printcpuinfo(void)
190 {
191 u_int regs[4], i;
192 char *brand;
193
194 cpu_class = i386_cpus[cpu].cpu_class;
195 printf("CPU: ");
196 strncpy(cpu_model, i386_cpus[cpu].cpu_name, sizeof (cpu_model));
197
198 /* Check for extended CPUID information and a processor name. */
199 init_exthigh();
200 if (cpu_exthigh >= 0x80000004) {
201 brand = cpu_brand;
202 for (i = 0x80000002; i < 0x80000005; i++) {
203 do_cpuid(i, regs);
204 memcpy(brand, regs, sizeof(regs));
205 brand += sizeof(regs);
206 }
207 }
208
209 if (cpu_vendor_id == CPU_VENDOR_INTEL) {
210 if ((cpu_id & 0xf00) > 0x300) {
211 u_int brand_index;
212
213 cpu_model[0] = '\0';
214
215 switch (cpu_id & 0x3000) {
216 case 0x1000:
217 strcpy(cpu_model, "Overdrive ");
218 break;
219 case 0x2000:
220 strcpy(cpu_model, "Dual ");
221 break;
222 }
223
224 switch (cpu_id & 0xf00) {
225 case 0x400:
226 strcat(cpu_model, "i486 ");
227 /* Check the particular flavor of 486 */
228 switch (cpu_id & 0xf0) {
229 case 0x00:
230 case 0x10:
231 strcat(cpu_model, "DX");
232 break;
233 case 0x20:
234 strcat(cpu_model, "SX");
235 break;
236 case 0x30:
237 strcat(cpu_model, "DX2");
238 break;
239 case 0x40:
240 strcat(cpu_model, "SL");
241 break;
242 case 0x50:
243 strcat(cpu_model, "SX2");
244 break;
245 case 0x70:
246 strcat(cpu_model,
247 "DX2 Write-Back Enhanced");
248 break;
249 case 0x80:
250 strcat(cpu_model, "DX4");
251 break;
252 }
253 break;
254 case 0x500:
255 /* Check the particular flavor of 586 */
256 strcat(cpu_model, "Pentium");
257 switch (cpu_id & 0xf0) {
258 case 0x00:
259 strcat(cpu_model, " A-step");
260 break;
261 case 0x10:
262 strcat(cpu_model, "/P5");
263 break;
264 case 0x20:
265 strcat(cpu_model, "/P54C");
266 break;
267 case 0x30:
268 strcat(cpu_model, "/P24T");
269 break;
270 case 0x40:
271 strcat(cpu_model, "/P55C");
272 break;
273 case 0x70:
274 strcat(cpu_model, "/P54C");
275 break;
276 case 0x80:
277 strcat(cpu_model, "/P55C (quarter-micron)");
278 break;
279 default:
280 /* nothing */
281 break;
282 }
283 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
284 /*
285 * XXX - If/when Intel fixes the bug, this
286 * should also check the version of the
287 * CPU, not just that it's a Pentium.
288 */
289 has_f00f_bug = 1;
290 #endif
291 break;
292 case 0x600:
293 /* Check the particular flavor of 686 */
294 switch (cpu_id & 0xf0) {
295 case 0x00:
296 strcat(cpu_model, "Pentium Pro A-step");
297 break;
298 case 0x10:
299 strcat(cpu_model, "Pentium Pro");
300 break;
301 case 0x30:
302 case 0x50:
303 case 0x60:
304 strcat(cpu_model,
305 "Pentium II/Pentium II Xeon/Celeron");
306 cpu = CPU_PII;
307 break;
308 case 0x70:
309 case 0x80:
310 case 0xa0:
311 case 0xb0:
312 strcat(cpu_model,
313 "Pentium III/Pentium III Xeon/Celeron");
314 cpu = CPU_PIII;
315 break;
316 default:
317 strcat(cpu_model, "Unknown 80686");
318 break;
319 }
320 break;
321 case 0xf00:
322 strcat(cpu_model, "Pentium 4");
323 cpu = CPU_P4;
324 break;
325 default:
326 strcat(cpu_model, "unknown");
327 break;
328 }
329
330 /*
331 * If we didn't get a brand name from the extended
332 * CPUID, try to look it up in the brand table.
333 */
334 if (cpu_high > 0 && *cpu_brand == '\0') {
335 brand_index = cpu_procinfo & CPUID_BRAND_INDEX;
336 if (brand_index <= MAX_BRAND_INDEX &&
337 cpu_brandtable[brand_index] != NULL)
338 strcpy(cpu_brand,
339 cpu_brandtable[brand_index]);
340 }
341 }
342 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
343 /*
344 * Values taken from AMD Processor Recognition
345 * http://www.amd.com/K6/k6docs/pdf/20734g.pdf
346 * (also describes ``Features'' encodings.
347 */
348 strcpy(cpu_model, "AMD ");
349 switch (cpu_id & 0xFF0) {
350 case 0x410:
351 strcat(cpu_model, "Standard Am486DX");
352 break;
353 case 0x430:
354 strcat(cpu_model, "Enhanced Am486DX2 Write-Through");
355 break;
356 case 0x470:
357 strcat(cpu_model, "Enhanced Am486DX2 Write-Back");
358 break;
359 case 0x480:
360 strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Through");
361 break;
362 case 0x490:
363 strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Back");
364 break;
365 case 0x4E0:
366 strcat(cpu_model, "Am5x86 Write-Through");
367 break;
368 case 0x4F0:
369 strcat(cpu_model, "Am5x86 Write-Back");
370 break;
371 case 0x500:
372 strcat(cpu_model, "K5 model 0");
373 tsc_is_broken = 1;
374 break;
375 case 0x510:
376 strcat(cpu_model, "K5 model 1");
377 break;
378 case 0x520:
379 strcat(cpu_model, "K5 PR166 (model 2)");
380 break;
381 case 0x530:
382 strcat(cpu_model, "K5 PR200 (model 3)");
383 break;
384 case 0x560:
385 strcat(cpu_model, "K6");
386 break;
387 case 0x570:
388 strcat(cpu_model, "K6 266 (model 1)");
389 break;
390 case 0x580:
391 strcat(cpu_model, "K6-2");
392 break;
393 case 0x590:
394 strcat(cpu_model, "K6-III");
395 break;
396 case 0x5a0:
397 strcat(cpu_model, "Geode LX");
398 /*
399 * Make sure the TSC runs through suspension,
400 * otherwise we can't use it as timecounter
401 */
402 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
403 break;
404 default:
405 strcat(cpu_model, "Unknown");
406 break;
407 }
408 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
409 if ((cpu_id & 0xf00) == 0x500) {
410 if (((cpu_id & 0x0f0) > 0)
411 && ((cpu_id & 0x0f0) < 0x60)
412 && ((cpu_id & 0x00f) > 3))
413 enable_K5_wt_alloc();
414 else if (((cpu_id & 0x0f0) > 0x80)
415 || (((cpu_id & 0x0f0) == 0x80)
416 && (cpu_id & 0x00f) > 0x07))
417 enable_K6_2_wt_alloc();
418 else if ((cpu_id & 0x0f0) > 0x50)
419 enable_K6_wt_alloc();
420 }
421 #endif
422 } else if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
423 strcpy(cpu_model, "Cyrix ");
424 switch (cpu_id & 0xff0) {
425 case 0x440:
426 strcat(cpu_model, "MediaGX");
427 break;
428 case 0x520:
429 strcat(cpu_model, "6x86");
430 break;
431 case 0x540:
432 cpu_class = CPUCLASS_586;
433 strcat(cpu_model, "GXm");
434 break;
435 case 0x600:
436 strcat(cpu_model, "6x86MX");
437 break;
438 default:
439 /*
440 * Even though CPU supports the cpuid
441 * instruction, it can be disabled.
442 * Therefore, this routine supports all Cyrix
443 * CPUs.
444 */
445 switch (cyrix_did & 0xf0) {
446 case 0x00:
447 switch (cyrix_did & 0x0f) {
448 case 0x00:
449 strcat(cpu_model, "486SLC");
450 break;
451 case 0x01:
452 strcat(cpu_model, "486DLC");
453 break;
454 case 0x02:
455 strcat(cpu_model, "486SLC2");
456 break;
457 case 0x03:
458 strcat(cpu_model, "486DLC2");
459 break;
460 case 0x04:
461 strcat(cpu_model, "486SRx");
462 break;
463 case 0x05:
464 strcat(cpu_model, "486DRx");
465 break;
466 case 0x06:
467 strcat(cpu_model, "486SRx2");
468 break;
469 case 0x07:
470 strcat(cpu_model, "486DRx2");
471 break;
472 case 0x08:
473 strcat(cpu_model, "486SRu");
474 break;
475 case 0x09:
476 strcat(cpu_model, "486DRu");
477 break;
478 case 0x0a:
479 strcat(cpu_model, "486SRu2");
480 break;
481 case 0x0b:
482 strcat(cpu_model, "486DRu2");
483 break;
484 default:
485 strcat(cpu_model, "Unknown");
486 break;
487 }
488 break;
489 case 0x10:
490 switch (cyrix_did & 0x0f) {
491 case 0x00:
492 strcat(cpu_model, "486S");
493 break;
494 case 0x01:
495 strcat(cpu_model, "486S2");
496 break;
497 case 0x02:
498 strcat(cpu_model, "486Se");
499 break;
500 case 0x03:
501 strcat(cpu_model, "486S2e");
502 break;
503 case 0x0a:
504 strcat(cpu_model, "486DX");
505 break;
506 case 0x0b:
507 strcat(cpu_model, "486DX2");
508 break;
509 case 0x0f:
510 strcat(cpu_model, "486DX4");
511 break;
512 default:
513 strcat(cpu_model, "Unknown");
514 break;
515 }
516 break;
517 case 0x20:
518 if ((cyrix_did & 0x0f) < 8)
519 strcat(cpu_model, "6x86"); /* Where did you get it? */
520 else
521 strcat(cpu_model, "5x86");
522 break;
523 case 0x30:
524 strcat(cpu_model, "6x86");
525 break;
526 case 0x40:
527 if ((cyrix_did & 0xf000) == 0x3000) {
528 cpu_class = CPUCLASS_586;
529 strcat(cpu_model, "GXm");
530 } else
531 strcat(cpu_model, "MediaGX");
532 break;
533 case 0x50:
534 strcat(cpu_model, "6x86MX");
535 break;
536 case 0xf0:
537 switch (cyrix_did & 0x0f) {
538 case 0x0d:
539 strcat(cpu_model, "Overdrive CPU");
540 break;
541 case 0x0e:
542 strcpy(cpu_model, "Texas Instruments 486SXL");
543 break;
544 case 0x0f:
545 strcat(cpu_model, "486SLC/DLC");
546 break;
547 default:
548 strcat(cpu_model, "Unknown");
549 break;
550 }
551 break;
552 default:
553 strcat(cpu_model, "Unknown");
554 break;
555 }
556 break;
557 }
558 } else if (cpu_vendor_id == CPU_VENDOR_RISE) {
559 strcpy(cpu_model, "Rise ");
560 switch (cpu_id & 0xff0) {
561 case 0x500:
562 strcat(cpu_model, "mP6");
563 break;
564 default:
565 strcat(cpu_model, "Unknown");
566 }
567 } else if (cpu_vendor_id == CPU_VENDOR_CENTAUR) {
568 switch (cpu_id & 0xff0) {
569 case 0x540:
570 strcpy(cpu_model, "IDT WinChip C6");
571 tsc_is_broken = 1;
572 break;
573 case 0x580:
574 strcpy(cpu_model, "IDT WinChip 2");
575 break;
576 case 0x660:
577 strcpy(cpu_model, "VIA C3 Samuel");
578 break;
579 case 0x670:
580 if (cpu_id & 0x8)
581 strcpy(cpu_model, "VIA C3 Ezra");
582 else
583 strcpy(cpu_model, "VIA C3 Samuel 2");
584 break;
585 case 0x680:
586 strcpy(cpu_model, "VIA C3 Ezra-T");
587 break;
588 case 0x690:
589 strcpy(cpu_model, "VIA C3 Nehemiah");
590 break;
591 case 0x6a0:
592 case 0x6d0:
593 strcpy(cpu_model, "VIA C7 Esther");
594 break;
595 case 0x6f0:
596 strcpy(cpu_model, "VIA Nano");
597 break;
598 default:
599 strcpy(cpu_model, "VIA/IDT Unknown");
600 }
601 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
602 strcpy(cpu_model, "Blue Lightning CPU");
603 } else if (cpu_vendor_id == CPU_VENDOR_NSC) {
604 switch (cpu_id & 0xfff) {
605 case 0x540:
606 strcpy(cpu_model, "Geode SC1100");
607 cpu = CPU_GEODE1100;
608 tsc_is_broken = 1;
609 break;
610 default:
611 strcpy(cpu_model, "Geode/NSC unknown");
612 break;
613 }
614 }
615
616 /*
617 * Replace cpu_model with cpu_brand minus leading spaces if
618 * we have one.
619 */
620 brand = cpu_brand;
621 while (*brand == ' ')
622 ++brand;
623 if (*brand != '\0')
624 strcpy(cpu_model, brand);
625
626 printf("%s (", cpu_model);
627 switch(cpu_class) {
628 case CPUCLASS_286:
629 printf("286");
630 break;
631 case CPUCLASS_386:
632 printf("386");
633 break;
634 #if defined(I486_CPU)
635 case CPUCLASS_486:
636 printf("486");
637 bzero_vector = i486_bzero;
638 break;
639 #endif
640 #if defined(I586_CPU)
641 case CPUCLASS_586:
642 hw_clockrate = (tsc_freq + 5000) / 1000000;
643 printf("%jd.%02d-MHz ",
644 (intmax_t)(tsc_freq + 4999) / 1000000,
645 (u_int)((tsc_freq + 4999) / 10000) % 100);
646 printf("586");
647 break;
648 #endif
649 #if defined(I686_CPU)
650 case CPUCLASS_686:
651 hw_clockrate = (tsc_freq + 5000) / 1000000;
652 printf("%jd.%02d-MHz ",
653 (intmax_t)(tsc_freq + 4999) / 1000000,
654 (u_int)((tsc_freq + 4999) / 10000) % 100);
655 printf("686");
656 break;
657 #endif
658 default:
659 printf("Unknown"); /* will panic below... */
660 }
661 printf("-class CPU)\n");
662 if(*cpu_vendor)
663 printf(" Origin = \"%s\"",cpu_vendor);
664 if(cpu_id)
665 printf(" Id = 0x%x", cpu_id);
666
667 if (cpu_vendor_id == CPU_VENDOR_INTEL ||
668 cpu_vendor_id == CPU_VENDOR_AMD ||
669 cpu_vendor_id == CPU_VENDOR_TRANSMETA ||
670 cpu_vendor_id == CPU_VENDOR_RISE ||
671 cpu_vendor_id == CPU_VENDOR_CENTAUR ||
672 cpu_vendor_id == CPU_VENDOR_NSC ||
673 (cpu_vendor_id == CPU_VENDOR_CYRIX &&
674 ((cpu_id & 0xf00) > 0x500))) {
675 printf(" Family = %x", CPUID_TO_FAMILY(cpu_id));
676 printf(" Model = %x", CPUID_TO_MODEL(cpu_id));
677 printf(" Stepping = %u", cpu_id & CPUID_STEPPING);
678 if (cpu_vendor_id == CPU_VENDOR_CYRIX)
679 printf("\n DIR=0x%04x", cyrix_did);
680 if (cpu_high > 0) {
681 u_int cmp = 1, htt = 1;
682
683 /*
684 * Here we should probably set up flags indicating
685 * whether or not various features are available.
686 * The interesting ones are probably VME, PSE, PAE,
687 * and PGE. The code already assumes without bothering
688 * to check that all CPUs >= Pentium have a TSC and
689 * MSRs.
690 */
691 printf("\n Features=0x%b", cpu_feature,
692 "\020"
693 "\001FPU" /* Integral FPU */
694 "\002VME" /* Extended VM86 mode support */
695 "\003DE" /* Debugging Extensions (CR4.DE) */
696 "\004PSE" /* 4MByte page tables */
697 "\005TSC" /* Timestamp counter */
698 "\006MSR" /* Machine specific registers */
699 "\007PAE" /* Physical address extension */
700 "\010MCE" /* Machine Check support */
701 "\011CX8" /* CMPEXCH8 instruction */
702 "\012APIC" /* SMP local APIC */
703 "\013oldMTRR" /* Previous implementation of MTRR */
704 "\014SEP" /* Fast System Call */
705 "\015MTRR" /* Memory Type Range Registers */
706 "\016PGE" /* PG_G (global bit) support */
707 "\017MCA" /* Machine Check Architecture */
708 "\020CMOV" /* CMOV instruction */
709 "\021PAT" /* Page attributes table */
710 "\022PSE36" /* 36 bit address space support */
711 "\023PN" /* Processor Serial number */
712 "\024CLFLUSH" /* Has the CLFLUSH instruction */
713 "\025<b20>"
714 "\026DTS" /* Debug Trace Store */
715 "\027ACPI" /* ACPI support */
716 "\030MMX" /* MMX instructions */
717 "\031FXSR" /* FXSAVE/FXRSTOR */
718 "\032SSE" /* Streaming SIMD Extensions */
719 "\033SSE2" /* Streaming SIMD Extensions #2 */
720 "\034SS" /* Self snoop */
721 "\035HTT" /* Hyperthreading (see EBX bit 16-23) */
722 "\036TM" /* Thermal Monitor clock slowdown */
723 "\037IA64" /* CPU can execute IA64 instructions */
724 "\040PBE" /* Pending Break Enable */
725 );
726
727 if (cpu_feature2 != 0) {
728 printf("\n Features2=0x%b", cpu_feature2,
729 "\020"
730 "\001SSE3" /* SSE3 */
731 "\002<b1>"
732 "\003DTES64" /* 64-bit Debug Trace */
733 "\004MON" /* MONITOR/MWAIT Instructions */
734 "\005DS_CPL" /* CPL Qualified Debug Store */
735 "\006VMX" /* Virtual Machine Extensions */
736 "\007SMX" /* Safer Mode Extensions */
737 "\010EST" /* Enhanced SpeedStep */
738 "\011TM2" /* Thermal Monitor 2 */
739 "\012SSSE3" /* SSSE3 */
740 "\013CNXT-ID" /* L1 context ID available */
741 "\014<b11>"
742 "\015<b12>"
743 "\016CX16" /* CMPXCHG16B Instruction */
744 "\017xTPR" /* Send Task Priority Messages*/
745 "\020PDCM" /* Perf/Debug Capability MSR */
746 "\021<b16>"
747 "\022<b17>"
748 "\023DCA" /* Direct Cache Access */
749 "\024SSE4.1"
750 "\025SSE4.2"
751 "\026x2APIC" /* xAPIC Extensions */
752 "\027MOVBE"
753 "\030POPCNT"
754 "\031<b24>"
755 "\032<b25>"
756 "\033XSAVE"
757 "\034OSXSAVE"
758 "\035<b28>"
759 "\036<b29>"
760 "\037<b30>"
761 "\040HV" /* Hypervisor */
762 );
763 }
764
765 /*
766 * AMD64 Architecture Programmer's Manual Volume 3:
767 * General-Purpose and System Instructions
768 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24594.pdf
769 *
770 * IA-32 Intel Architecture Software Developer's Manual,
771 * Volume 2A: Instruction Set Reference, A-M
772 * ftp://download.intel.com/design/Pentium4/manuals/25366617.pdf
773 */
774 if (amd_feature != 0) {
775 printf("\n AMD Features=0x%b", amd_feature,
776 "\020" /* in hex */
777 "\001<s0>" /* Same */
778 "\002<s1>" /* Same */
779 "\003<s2>" /* Same */
780 "\004<s3>" /* Same */
781 "\005<s4>" /* Same */
782 "\006<s5>" /* Same */
783 "\007<s6>" /* Same */
784 "\010<s7>" /* Same */
785 "\011<s8>" /* Same */
786 "\012<s9>" /* Same */
787 "\013<b10>" /* Undefined */
788 "\014SYSCALL" /* Have SYSCALL/SYSRET */
789 "\015<s12>" /* Same */
790 "\016<s13>" /* Same */
791 "\017<s14>" /* Same */
792 "\020<s15>" /* Same */
793 "\021<s16>" /* Same */
794 "\022<s17>" /* Same */
795 "\023<b18>" /* Reserved, unknown */
796 "\024MP" /* Multiprocessor Capable */
797 "\025NX" /* Has EFER.NXE, NX */
798 "\026<b21>" /* Undefined */
799 "\027MMX+" /* AMD MMX Extensions */
800 "\030<s23>" /* Same */
801 "\031<s24>" /* Same */
802 "\032FFXSR" /* Fast FXSAVE/FXRSTOR */
803 "\033Page1GB" /* 1-GB large page support */
804 "\034RDTSCP" /* RDTSCP */
805 "\035<b28>" /* Undefined */
806 "\036LM" /* 64 bit long mode */
807 "\0373DNow!+" /* AMD 3DNow! Extensions */
808 "\0403DNow!" /* AMD 3DNow! */
809 );
810 }
811
812 if (amd_feature2 != 0) {
813 printf("\n AMD Features2=0x%b", amd_feature2,
814 "\020"
815 "\001LAHF" /* LAHF/SAHF in long mode */
816 "\002CMP" /* CMP legacy */
817 "\003SVM" /* Secure Virtual Mode */
818 "\004ExtAPIC" /* Extended APIC register */
819 "\005CR8" /* CR8 in legacy mode */
820 "\006ABM" /* LZCNT instruction */
821 "\007SSE4A" /* SSE4A */
822 "\010MAS" /* Misaligned SSE mode */
823 "\011Prefetch" /* 3DNow! Prefetch/PrefetchW */
824 "\012OSVW" /* OS visible workaround */
825 "\013IBS" /* Instruction based sampling */
826 "\014SSE5" /* SSE5 */
827 "\015SKINIT" /* SKINIT/STGI */
828 "\016WDT" /* Watchdog timer */
829 "\017<b14>"
830 "\020<b15>"
831 "\021<b16>"
832 "\022<b17>"
833 "\023<b18>"
834 "\024<b19>"
835 "\025<b20>"
836 "\026<b21>"
837 "\027<b22>"
838 "\030<b23>"
839 "\031<b24>"
840 "\032<b25>"
841 "\033<b26>"
842 "\034<b27>"
843 "\035<b28>"
844 "\036<b29>"
845 "\037<b30>"
846 "\040<b31>"
847 );
848 }
849
850 if (cpu_vendor_id == CPU_VENDOR_CENTAUR)
851 print_via_padlock_info();
852
853 if ((cpu_feature & CPUID_HTT) &&
854 cpu_vendor_id == CPU_VENDOR_AMD)
855 cpu_feature &= ~CPUID_HTT;
856
857 /*
858 * If this CPU supports P-state invariant TSC then
859 * mention the capability.
860 */
861 switch (cpu_vendor_id) {
862 case CPU_VENDOR_AMD:
863 if ((amd_pminfo & AMDPM_TSC_INVARIANT) ||
864 CPUID_TO_FAMILY(cpu_id) >= 0x10 ||
865 cpu_id == 0x60fb2)
866 tsc_is_invariant = 1;
867 break;
868 case CPU_VENDOR_INTEL:
869 if (amd_pminfo & AMDPM_TSC_INVARIANT)
870 tsc_is_invariant = 1;
871 break;
872 case CPU_VENDOR_CENTAUR:
873 if (CPUID_TO_FAMILY(cpu_id) == 0x6 &&
874 CPUID_TO_MODEL(cpu_id) >= 0xf &&
875 (rdmsr(0x1203) & 0x100000000ULL) == 0)
876 tsc_is_invariant = 1;
877 break;
878 }
879 if (tsc_is_invariant)
880 printf("\n TSC: P-state invariant");
881
882 /*
883 * If this CPU supports HTT or CMP then mention the
884 * number of physical/logical cores it contains.
885 */
886 if (cpu_feature & CPUID_HTT)
887 htt = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
888 if (cpu_vendor_id == CPU_VENDOR_AMD &&
889 (amd_feature2 & AMDID2_CMP))
890 cmp = (cpu_procinfo2 & AMDID_CMP_CORES) + 1;
891 else if (cpu_vendor_id == CPU_VENDOR_INTEL &&
892 (cpu_high >= 4)) {
893 cpuid_count(4, 0, regs);
894 if ((regs[0] & 0x1f) != 0)
895 cmp = ((regs[0] >> 26) & 0x3f) + 1;
896 }
897 if (cmp > 1)
898 printf("\n Cores per package: %d", cmp);
899 if ((htt / cmp) > 1)
900 printf("\n Logical CPUs per core: %d",
901 htt / cmp);
902 }
903 } else if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
904 printf(" DIR=0x%04x", cyrix_did);
905 printf(" Stepping=%u", (cyrix_did & 0xf000) >> 12);
906 printf(" Revision=%u", (cyrix_did & 0x0f00) >> 8);
907 #ifndef CYRIX_CACHE_REALLY_WORKS
908 if (cpu == CPU_M1 && (cyrix_did & 0xff00) < 0x1700)
909 printf("\n CPU cache: write-through mode");
910 #endif
911 }
912
913 /* Avoid ugly blank lines: only print newline when we have to. */
914 if (*cpu_vendor || cpu_id)
915 printf("\n");
916
917 if (!bootverbose)
918 return;
919
920 if (cpu_vendor_id == CPU_VENDOR_AMD)
921 print_AMD_info();
922 else if (cpu_vendor_id == CPU_VENDOR_INTEL)
923 print_INTEL_info();
924 else if (cpu_vendor_id == CPU_VENDOR_TRANSMETA)
925 print_transmeta_info();
926 }
927
928 void
929 panicifcpuunsupported(void)
930 {
931
932 #if !defined(lint)
933 #if !defined(I486_CPU) && !defined(I586_CPU) && !defined(I686_CPU)
934 #error This kernel is not configured for one of the supported CPUs
935 #endif
936 #else /* lint */
937 #endif /* lint */
938 /*
939 * Now that we have told the user what they have,
940 * let them know if that machine type isn't configured.
941 */
942 switch (cpu_class) {
943 case CPUCLASS_286: /* a 286 should not make it this far, anyway */
944 case CPUCLASS_386:
945 #if !defined(I486_CPU)
946 case CPUCLASS_486:
947 #endif
948 #if !defined(I586_CPU)
949 case CPUCLASS_586:
950 #endif
951 #if !defined(I686_CPU)
952 case CPUCLASS_686:
953 #endif
954 panic("CPU class not configured");
955 default:
956 break;
957 }
958 }
959
960
961 static volatile u_int trap_by_rdmsr;
962
963 /*
964 * Special exception 6 handler.
965 * The rdmsr instruction generates invalid opcodes fault on 486-class
966 * Cyrix CPU. Stacked eip register points the rdmsr instruction in the
967 * function identblue() when this handler is called. Stacked eip should
968 * be advanced.
969 */
970 inthand_t bluetrap6;
971 #ifdef __GNUCLIKE_ASM
972 __asm
973 (" \n\
974 .text \n\
975 .p2align 2,0x90 \n\
976 .type " __XSTRING(CNAME(bluetrap6)) ",@function \n\
977 " __XSTRING(CNAME(bluetrap6)) ": \n\
978 ss \n\
979 movl $0xa8c1d," __XSTRING(CNAME(trap_by_rdmsr)) " \n\
980 addl $2, (%esp) /* rdmsr is a 2-byte instruction */ \n\
981 iret \n\
982 ");
983 #endif
984
985 /*
986 * Special exception 13 handler.
987 * Accessing non-existent MSR generates general protection fault.
988 */
989 inthand_t bluetrap13;
990 #ifdef __GNUCLIKE_ASM
991 __asm
992 (" \n\
993 .text \n\
994 .p2align 2,0x90 \n\
995 .type " __XSTRING(CNAME(bluetrap13)) ",@function \n\
996 " __XSTRING(CNAME(bluetrap13)) ": \n\
997 ss \n\
998 movl $0xa89c4," __XSTRING(CNAME(trap_by_rdmsr)) " \n\
999 popl %eax /* discard error code */ \n\
1000 addl $2, (%esp) /* rdmsr is a 2-byte instruction */ \n\
1001 iret \n\
1002 ");
1003 #endif
1004
1005 /*
1006 * Distinguish IBM Blue Lightning CPU from Cyrix CPUs that does not
1007 * support cpuid instruction. This function should be called after
1008 * loading interrupt descriptor table register.
1009 *
1010 * I don't like this method that handles fault, but I couldn't get
1011 * information for any other methods. Does blue giant know?
1012 */
1013 static int
1014 identblue(void)
1015 {
1016
1017 trap_by_rdmsr = 0;
1018
1019 /*
1020 * Cyrix 486-class CPU does not support rdmsr instruction.
1021 * The rdmsr instruction generates invalid opcode fault, and exception
1022 * will be trapped by bluetrap6() on Cyrix 486-class CPU. The
1023 * bluetrap6() set the magic number to trap_by_rdmsr.
1024 */
1025 setidt(IDT_UD, bluetrap6, SDT_SYS386TGT, SEL_KPL,
1026 GSEL(GCODE_SEL, SEL_KPL));
1027
1028 /*
1029 * Certain BIOS disables cpuid instruction of Cyrix 6x86MX CPU.
1030 * In this case, rdmsr generates general protection fault, and
1031 * exception will be trapped by bluetrap13().
1032 */
1033 setidt(IDT_GP, bluetrap13, SDT_SYS386TGT, SEL_KPL,
1034 GSEL(GCODE_SEL, SEL_KPL));
1035
1036 rdmsr(0x1002); /* Cyrix CPU generates fault. */
1037
1038 if (trap_by_rdmsr == 0xa8c1d)
1039 return IDENTBLUE_CYRIX486;
1040 else if (trap_by_rdmsr == 0xa89c4)
1041 return IDENTBLUE_CYRIXM2;
1042 return IDENTBLUE_IBMCPU;
1043 }
1044
1045
1046 /*
1047 * identifycyrix() set lower 16 bits of cyrix_did as follows:
1048 *
1049 * F E D C B A 9 8 7 6 5 4 3 2 1 0
1050 * +-------+-------+---------------+
1051 * | SID | RID | Device ID |
1052 * | (DIR 1) | (DIR 0) |
1053 * +-------+-------+---------------+
1054 */
1055 static void
1056 identifycyrix(void)
1057 {
1058 u_int eflags;
1059 int ccr2_test = 0, dir_test = 0;
1060 u_char ccr2, ccr3;
1061
1062 eflags = read_eflags();
1063 disable_intr();
1064
1065 ccr2 = read_cyrix_reg(CCR2);
1066 write_cyrix_reg(CCR2, ccr2 ^ CCR2_LOCK_NW);
1067 read_cyrix_reg(CCR2);
1068 if (read_cyrix_reg(CCR2) != ccr2)
1069 ccr2_test = 1;
1070 write_cyrix_reg(CCR2, ccr2);
1071
1072 ccr3 = read_cyrix_reg(CCR3);
1073 write_cyrix_reg(CCR3, ccr3 ^ CCR3_MAPEN3);
1074 read_cyrix_reg(CCR3);
1075 if (read_cyrix_reg(CCR3) != ccr3)
1076 dir_test = 1; /* CPU supports DIRs. */
1077 write_cyrix_reg(CCR3, ccr3);
1078
1079 if (dir_test) {
1080 /* Device ID registers are available. */
1081 cyrix_did = read_cyrix_reg(DIR1) << 8;
1082 cyrix_did += read_cyrix_reg(DIR0);
1083 } else if (ccr2_test)
1084 cyrix_did = 0x0010; /* 486S A-step */
1085 else
1086 cyrix_did = 0x00ff; /* Old 486SLC/DLC and TI486SXLC/SXL */
1087
1088 write_eflags(eflags);
1089 }
1090
1091 /* Update TSC freq with the value indicated by the caller. */
1092 static void
1093 tsc_freq_changed(void *arg, const struct cf_level *level, int status)
1094 {
1095 /*
1096 * If there was an error during the transition or
1097 * TSC is P-state invariant, don't do anything.
1098 */
1099 if (status != 0 || tsc_is_invariant)
1100 return;
1101
1102 /* Total setting for this level gives the new frequency in MHz. */
1103 hw_clockrate = level->total_set.freq;
1104 }
1105
1106 EVENTHANDLER_DEFINE(cpufreq_post_change, tsc_freq_changed, NULL,
1107 EVENTHANDLER_PRI_ANY);
1108
1109 /*
1110 * Final stage of CPU identification. -- Should I check TI?
1111 */
1112 void
1113 finishidentcpu(void)
1114 {
1115 int isblue = 0;
1116 u_char ccr3;
1117 u_int regs[4];
1118
1119 cpu_vendor_id = find_cpu_vendor_id();
1120
1121 /*
1122 * Clear "Limit CPUID Maxval" bit and get the largest standard CPUID
1123 * function number again if it is set from BIOS. It is necessary
1124 * for probing correct CPU topology later.
1125 * XXX This is only done on the BSP package.
1126 */
1127 if (cpu_vendor_id == CPU_VENDOR_INTEL && cpu_high > 0 && cpu_high < 4 &&
1128 ((CPUID_TO_FAMILY(cpu_id) == 0xf && CPUID_TO_MODEL(cpu_id) >= 0x3) ||
1129 (CPUID_TO_FAMILY(cpu_id) == 0x6 && CPUID_TO_MODEL(cpu_id) >= 0xe))) {
1130 uint64_t msr;
1131 msr = rdmsr(MSR_IA32_MISC_ENABLE);
1132 if ((msr & 0x400000ULL) != 0) {
1133 wrmsr(MSR_IA32_MISC_ENABLE, msr & ~0x400000ULL);
1134 do_cpuid(0, regs);
1135 cpu_high = regs[0];
1136 }
1137 }
1138
1139 /* Detect AMD features (PTE no-execute bit, 3dnow, 64 bit mode etc) */
1140 if (cpu_vendor_id == CPU_VENDOR_INTEL ||
1141 cpu_vendor_id == CPU_VENDOR_AMD) {
1142 init_exthigh();
1143 if (cpu_exthigh >= 0x80000001) {
1144 do_cpuid(0x80000001, regs);
1145 amd_feature = regs[3] & ~(cpu_feature & 0x0183f3ff);
1146 amd_feature2 = regs[2];
1147 }
1148 if (cpu_exthigh >= 0x80000007) {
1149 do_cpuid(0x80000007, regs);
1150 amd_pminfo = regs[3];
1151 }
1152 if (cpu_exthigh >= 0x80000008) {
1153 do_cpuid(0x80000008, regs);
1154 cpu_procinfo2 = regs[2];
1155 }
1156 } else if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1157 if (cpu == CPU_486) {
1158 /*
1159 * These conditions are equivalent to:
1160 * - CPU does not support cpuid instruction.
1161 * - Cyrix/IBM CPU is detected.
1162 */
1163 isblue = identblue();
1164 if (isblue == IDENTBLUE_IBMCPU) {
1165 strcpy(cpu_vendor, "IBM");
1166 cpu_vendor_id = CPU_VENDOR_IBM;
1167 cpu = CPU_BLUE;
1168 return;
1169 }
1170 }
1171 switch (cpu_id & 0xf00) {
1172 case 0x600:
1173 /*
1174 * Cyrix's datasheet does not describe DIRs.
1175 * Therefor, I assume it does not have them
1176 * and use the result of the cpuid instruction.
1177 * XXX they seem to have it for now at least. -Peter
1178 */
1179 identifycyrix();
1180 cpu = CPU_M2;
1181 break;
1182 default:
1183 identifycyrix();
1184 /*
1185 * This routine contains a trick.
1186 * Don't check (cpu_id & 0x00f0) == 0x50 to detect M2, now.
1187 */
1188 switch (cyrix_did & 0x00f0) {
1189 case 0x00:
1190 case 0xf0:
1191 cpu = CPU_486DLC;
1192 break;
1193 case 0x10:
1194 cpu = CPU_CY486DX;
1195 break;
1196 case 0x20:
1197 if ((cyrix_did & 0x000f) < 8)
1198 cpu = CPU_M1;
1199 else
1200 cpu = CPU_M1SC;
1201 break;
1202 case 0x30:
1203 cpu = CPU_M1;
1204 break;
1205 case 0x40:
1206 /* MediaGX CPU */
1207 cpu = CPU_M1SC;
1208 break;
1209 default:
1210 /* M2 and later CPUs are treated as M2. */
1211 cpu = CPU_M2;
1212
1213 /*
1214 * enable cpuid instruction.
1215 */
1216 ccr3 = read_cyrix_reg(CCR3);
1217 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1218 write_cyrix_reg(CCR4, read_cyrix_reg(CCR4) | CCR4_CPUID);
1219 write_cyrix_reg(CCR3, ccr3);
1220
1221 do_cpuid(0, regs);
1222 cpu_high = regs[0]; /* eax */
1223 do_cpuid(1, regs);
1224 cpu_id = regs[0]; /* eax */
1225 cpu_feature = regs[3]; /* edx */
1226 break;
1227 }
1228 }
1229 } else if (cpu == CPU_486 && *cpu_vendor == '\0') {
1230 /*
1231 * There are BlueLightning CPUs that do not change
1232 * undefined flags by dividing 5 by 2. In this case,
1233 * the CPU identification routine in locore.s leaves
1234 * cpu_vendor null string and puts CPU_486 into the
1235 * cpu.
1236 */
1237 isblue = identblue();
1238 if (isblue == IDENTBLUE_IBMCPU) {
1239 strcpy(cpu_vendor, "IBM");
1240 cpu_vendor_id = CPU_VENDOR_IBM;
1241 cpu = CPU_BLUE;
1242 return;
1243 }
1244 }
1245 }
1246
1247 static u_int
1248 find_cpu_vendor_id(void)
1249 {
1250 int i;
1251
1252 for (i = 0; i < sizeof(cpu_vendors) / sizeof(cpu_vendors[0]); i++)
1253 if (strcmp(cpu_vendor, cpu_vendors[i].vendor) == 0)
1254 return (cpu_vendors[i].vendor_id);
1255 return (0);
1256 }
1257
1258 static void
1259 print_AMD_assoc(int i)
1260 {
1261 if (i == 255)
1262 printf(", fully associative\n");
1263 else
1264 printf(", %d-way associative\n", i);
1265 }
1266
1267 static void
1268 print_AMD_info(void)
1269 {
1270 quad_t amd_whcr;
1271
1272 if (cpu_exthigh >= 0x80000005) {
1273 u_int regs[4];
1274
1275 do_cpuid(0x80000005, regs);
1276 printf("Data TLB: %d entries", (regs[1] >> 16) & 0xff);
1277 print_AMD_assoc(regs[1] >> 24);
1278 printf("Instruction TLB: %d entries", regs[1] & 0xff);
1279 print_AMD_assoc((regs[1] >> 8) & 0xff);
1280 printf("L1 data cache: %d kbytes", regs[2] >> 24);
1281 printf(", %d bytes/line", regs[2] & 0xff);
1282 printf(", %d lines/tag", (regs[2] >> 8) & 0xff);
1283 print_AMD_assoc((regs[2] >> 16) & 0xff);
1284 printf("L1 instruction cache: %d kbytes", regs[3] >> 24);
1285 printf(", %d bytes/line", regs[3] & 0xff);
1286 printf(", %d lines/tag", (regs[3] >> 8) & 0xff);
1287 print_AMD_assoc((regs[3] >> 16) & 0xff);
1288 if (cpu_exthigh >= 0x80000006) { /* K6-III only */
1289 do_cpuid(0x80000006, regs);
1290 printf("L2 internal cache: %d kbytes", regs[2] >> 16);
1291 printf(", %d bytes/line", regs[2] & 0xff);
1292 printf(", %d lines/tag", (regs[2] >> 8) & 0x0f);
1293 print_AMD_assoc((regs[2] >> 12) & 0x0f);
1294 }
1295 }
1296 if (((cpu_id & 0xf00) == 0x500)
1297 && (((cpu_id & 0x0f0) > 0x80)
1298 || (((cpu_id & 0x0f0) == 0x80)
1299 && (cpu_id & 0x00f) > 0x07))) {
1300 /* K6-2(new core [Stepping 8-F]), K6-III or later */
1301 amd_whcr = rdmsr(0xc0000082);
1302 if (!(amd_whcr & (0x3ff << 22))) {
1303 printf("Write Allocate Disable\n");
1304 } else {
1305 printf("Write Allocate Enable Limit: %dM bytes\n",
1306 (u_int32_t)((amd_whcr & (0x3ff << 22)) >> 22) * 4);
1307 printf("Write Allocate 15-16M bytes: %s\n",
1308 (amd_whcr & (1 << 16)) ? "Enable" : "Disable");
1309 }
1310 } else if (((cpu_id & 0xf00) == 0x500)
1311 && ((cpu_id & 0x0f0) > 0x50)) {
1312 /* K6, K6-2(old core) */
1313 amd_whcr = rdmsr(0xc0000082);
1314 if (!(amd_whcr & (0x7f << 1))) {
1315 printf("Write Allocate Disable\n");
1316 } else {
1317 printf("Write Allocate Enable Limit: %dM bytes\n",
1318 (u_int32_t)((amd_whcr & (0x7f << 1)) >> 1) * 4);
1319 printf("Write Allocate 15-16M bytes: %s\n",
1320 (amd_whcr & 0x0001) ? "Enable" : "Disable");
1321 printf("Hardware Write Allocate Control: %s\n",
1322 (amd_whcr & 0x0100) ? "Enable" : "Disable");
1323 }
1324 }
1325
1326 /*
1327 * Opteron Rev E shows a bug as in very rare occasions a read memory
1328 * barrier is not performed as expected if it is followed by a
1329 * non-atomic read-modify-write instruction.
1330 * As long as that bug pops up very rarely (intensive machine usage
1331 * on other operating systems generally generates one unexplainable
1332 * crash any 2 months) and as long as a model specific fix would be
1333 * impratical at this stage, print out a warning string if the broken
1334 * model and family are identified.
1335 */
1336 if (CPUID_TO_FAMILY(cpu_id) == 0xf && CPUID_TO_MODEL(cpu_id) >= 0x20 &&
1337 CPUID_TO_MODEL(cpu_id) <= 0x3f)
1338 printf("WARNING: This architecture revision has known SMP "
1339 "hardware bugs which may cause random instability\n");
1340 }
1341
1342 static void
1343 print_INTEL_info(void)
1344 {
1345 u_int regs[4];
1346 u_int rounds, regnum;
1347 u_int nwaycode, nway;
1348
1349 if (cpu_high >= 2) {
1350 rounds = 0;
1351 do {
1352 do_cpuid(0x2, regs);
1353 if (rounds == 0 && (rounds = (regs[0] & 0xff)) == 0)
1354 break; /* we have a buggy CPU */
1355
1356 for (regnum = 0; regnum <= 3; ++regnum) {
1357 if (regs[regnum] & (1<<31))
1358 continue;
1359 if (regnum != 0)
1360 print_INTEL_TLB(regs[regnum] & 0xff);
1361 print_INTEL_TLB((regs[regnum] >> 8) & 0xff);
1362 print_INTEL_TLB((regs[regnum] >> 16) & 0xff);
1363 print_INTEL_TLB((regs[regnum] >> 24) & 0xff);
1364 }
1365 } while (--rounds > 0);
1366 }
1367
1368 if (cpu_exthigh >= 0x80000006) {
1369 do_cpuid(0x80000006, regs);
1370 nwaycode = (regs[2] >> 12) & 0x0f;
1371 if (nwaycode >= 0x02 && nwaycode <= 0x08)
1372 nway = 1 << (nwaycode / 2);
1373 else
1374 nway = 0;
1375 printf("\nL2 cache: %u kbytes, %u-way associative, %u bytes/line",
1376 (regs[2] >> 16) & 0xffff, nway, regs[2] & 0xff);
1377 }
1378
1379 printf("\n");
1380 }
1381
1382 static void
1383 print_INTEL_TLB(u_int data)
1384 {
1385 switch (data) {
1386 case 0x0:
1387 case 0x40:
1388 default:
1389 break;
1390 case 0x1:
1391 printf("\nInstruction TLB: 4 KB pages, 4-way set associative, 32 entries");
1392 break;
1393 case 0x2:
1394 printf("\nInstruction TLB: 4 MB pages, fully associative, 2 entries");
1395 break;
1396 case 0x3:
1397 printf("\nData TLB: 4 KB pages, 4-way set associative, 64 entries");
1398 break;
1399 case 0x4:
1400 printf("\nData TLB: 4 MB Pages, 4-way set associative, 8 entries");
1401 break;
1402 case 0x6:
1403 printf("\n1st-level instruction cache: 8 KB, 4-way set associative, 32 byte line size");
1404 break;
1405 case 0x8:
1406 printf("\n1st-level instruction cache: 16 KB, 4-way set associative, 32 byte line size");
1407 break;
1408 case 0xa:
1409 printf("\n1st-level data cache: 8 KB, 2-way set associative, 32 byte line size");
1410 break;
1411 case 0xc:
1412 printf("\n1st-level data cache: 16 KB, 4-way set associative, 32 byte line size");
1413 break;
1414 case 0x22:
1415 printf("\n3rd-level cache: 512 KB, 4-way set associative, sectored cache, 64 byte line size");
1416 break;
1417 case 0x23:
1418 printf("\n3rd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size");
1419 break;
1420 case 0x25:
1421 printf("\n3rd-level cache: 2 MB, 8-way set associative, sectored cache, 64 byte line size");
1422 break;
1423 case 0x29:
1424 printf("\n3rd-level cache: 4 MB, 8-way set associative, sectored cache, 64 byte line size");
1425 break;
1426 case 0x2c:
1427 printf("\n1st-level data cache: 32 KB, 8-way set associative, 64 byte line size");
1428 break;
1429 case 0x30:
1430 printf("\n1st-level instruction cache: 32 KB, 8-way set associative, 64 byte line size");
1431 break;
1432 case 0x39:
1433 printf("\n2nd-level cache: 128 KB, 4-way set associative, sectored cache, 64 byte line size");
1434 break;
1435 case 0x3b:
1436 printf("\n2nd-level cache: 128 KB, 2-way set associative, sectored cache, 64 byte line size");
1437 break;
1438 case 0x3c:
1439 printf("\n2nd-level cache: 256 KB, 4-way set associative, sectored cache, 64 byte line size");
1440 break;
1441 case 0x41:
1442 printf("\n2nd-level cache: 128 KB, 4-way set associative, 32 byte line size");
1443 break;
1444 case 0x42:
1445 printf("\n2nd-level cache: 256 KB, 4-way set associative, 32 byte line size");
1446 break;
1447 case 0x43:
1448 printf("\n2nd-level cache: 512 KB, 4-way set associative, 32 byte line size");
1449 break;
1450 case 0x44:
1451 printf("\n2nd-level cache: 1 MB, 4-way set associative, 32 byte line size");
1452 break;
1453 case 0x45:
1454 printf("\n2nd-level cache: 2 MB, 4-way set associative, 32 byte line size");
1455 break;
1456 case 0x46:
1457 printf("\n3rd-level cache: 4 MB, 4-way set associative, 64 byte line size");
1458 break;
1459 case 0x47:
1460 printf("\n3rd-level cache: 8 MB, 8-way set associative, 64 byte line size");
1461 break;
1462 case 0x50:
1463 printf("\nInstruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 64 entries");
1464 break;
1465 case 0x51:
1466 printf("\nInstruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 128 entries");
1467 break;
1468 case 0x52:
1469 printf("\nInstruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 256 entries");
1470 break;
1471 case 0x5b:
1472 printf("\nData TLB: 4 KB or 4 MB pages, fully associative, 64 entries");
1473 break;
1474 case 0x5c:
1475 printf("\nData TLB: 4 KB or 4 MB pages, fully associative, 128 entries");
1476 break;
1477 case 0x5d:
1478 printf("\nData TLB: 4 KB or 4 MB pages, fully associative, 256 entries");
1479 break;
1480 case 0x60:
1481 printf("\n1st-level data cache: 16 KB, 8-way set associative, sectored cache, 64 byte line size");
1482 break;
1483 case 0x66:
1484 printf("\n1st-level data cache: 8 KB, 4-way set associative, sectored cache, 64 byte line size");
1485 break;
1486 case 0x67:
1487 printf("\n1st-level data cache: 16 KB, 4-way set associative, sectored cache, 64 byte line size");
1488 break;
1489 case 0x68:
1490 printf("\n1st-level data cache: 32 KB, 4 way set associative, sectored cache, 64 byte line size");
1491 break;
1492 case 0x70:
1493 printf("\nTrace cache: 12K-uops, 8-way set associative");
1494 break;
1495 case 0x71:
1496 printf("\nTrace cache: 16K-uops, 8-way set associative");
1497 break;
1498 case 0x72:
1499 printf("\nTrace cache: 32K-uops, 8-way set associative");
1500 break;
1501 case 0x78:
1502 printf("\n2nd-level cache: 1 MB, 4-way set associative, 64-byte line size");
1503 break;
1504 case 0x79:
1505 printf("\n2nd-level cache: 128 KB, 8-way set associative, sectored cache, 64 byte line size");
1506 break;
1507 case 0x7a:
1508 printf("\n2nd-level cache: 256 KB, 8-way set associative, sectored cache, 64 byte line size");
1509 break;
1510 case 0x7b:
1511 printf("\n2nd-level cache: 512 KB, 8-way set associative, sectored cache, 64 byte line size");
1512 break;
1513 case 0x7c:
1514 printf("\n2nd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size");
1515 break;
1516 case 0x7d:
1517 printf("\n2nd-level cache: 2-MB, 8-way set associative, 64-byte line size");
1518 break;
1519 case 0x7f:
1520 printf("\n2nd-level cache: 512-KB, 2-way set associative, 64-byte line size");
1521 break;
1522 case 0x82:
1523 printf("\n2nd-level cache: 256 KB, 8-way set associative, 32 byte line size");
1524 break;
1525 case 0x83:
1526 printf("\n2nd-level cache: 512 KB, 8-way set associative, 32 byte line size");
1527 break;
1528 case 0x84:
1529 printf("\n2nd-level cache: 1 MB, 8-way set associative, 32 byte line size");
1530 break;
1531 case 0x85:
1532 printf("\n2nd-level cache: 2 MB, 8-way set associative, 32 byte line size");
1533 break;
1534 case 0x86:
1535 printf("\n2nd-level cache: 512 KB, 4-way set associative, 64 byte line size");
1536 break;
1537 case 0x87:
1538 printf("\n2nd-level cache: 1 MB, 8-way set associative, 64 byte line size");
1539 break;
1540 case 0xb0:
1541 printf("\nInstruction TLB: 4 KB Pages, 4-way set associative, 128 entries");
1542 break;
1543 case 0xb3:
1544 printf("\nData TLB: 4 KB Pages, 4-way set associative, 128 entries");
1545 break;
1546 }
1547 }
1548
1549 static void
1550 print_transmeta_info(void)
1551 {
1552 u_int regs[4], nreg = 0;
1553
1554 do_cpuid(0x80860000, regs);
1555 nreg = regs[0];
1556 if (nreg >= 0x80860001) {
1557 do_cpuid(0x80860001, regs);
1558 printf(" Processor revision %u.%u.%u.%u\n",
1559 (regs[1] >> 24) & 0xff,
1560 (regs[1] >> 16) & 0xff,
1561 (regs[1] >> 8) & 0xff,
1562 regs[1] & 0xff);
1563 }
1564 if (nreg >= 0x80860002) {
1565 do_cpuid(0x80860002, regs);
1566 printf(" Code Morphing Software revision %u.%u.%u-%u-%u\n",
1567 (regs[1] >> 24) & 0xff,
1568 (regs[1] >> 16) & 0xff,
1569 (regs[1] >> 8) & 0xff,
1570 regs[1] & 0xff,
1571 regs[2]);
1572 }
1573 if (nreg >= 0x80860006) {
1574 char info[65];
1575 do_cpuid(0x80860003, (u_int*) &info[0]);
1576 do_cpuid(0x80860004, (u_int*) &info[16]);
1577 do_cpuid(0x80860005, (u_int*) &info[32]);
1578 do_cpuid(0x80860006, (u_int*) &info[48]);
1579 info[64] = 0;
1580 printf(" %s\n", info);
1581 }
1582 }
1583
1584 static void
1585 print_via_padlock_info(void)
1586 {
1587 u_int regs[4];
1588
1589 /* Check for supported models. */
1590 switch (cpu_id & 0xff0) {
1591 case 0x690:
1592 if ((cpu_id & 0xf) < 3)
1593 return;
1594 case 0x6a0:
1595 case 0x6d0:
1596 case 0x6f0:
1597 break;
1598 default:
1599 return;
1600 }
1601
1602 do_cpuid(0xc0000000, regs);
1603 if (regs[0] >= 0xc0000001)
1604 do_cpuid(0xc0000001, regs);
1605 else
1606 return;
1607
1608 printf("\n VIA Padlock Features=0x%b", regs[3],
1609 "\020"
1610 "\003RNG" /* RNG */
1611 "\007AES" /* ACE */
1612 "\011AES-CTR" /* ACE2 */
1613 "\013SHA1,SHA256" /* PHE */
1614 "\015RSA" /* PMM */
1615 );
1616 }
Cache object: 762e710368ee0d94491523f468bd9be9
|