xref: /openbmc/linux/arch/x86/boot/cpu.c (revision f15cbe6f1a4b4d9df59142fc8e4abb973302cf44)
1 /* -*- linux-c -*- ------------------------------------------------------- *
2  *
3  *   Copyright (C) 1991, 1992 Linus Torvalds
4  *   Copyright 2007-2008 rPath, Inc. - All Rights Reserved
5  *
6  *   This file is part of the Linux kernel, and is made available under
7  *   the terms of the GNU General Public License version 2.
8  *
9  * ----------------------------------------------------------------------- */
10 
11 /*
12  * arch/x86/boot/cpu.c
13  *
14  * Check for obligatory CPU features and abort if the features are not
15  * present.
16  */
17 
18 #include "boot.h"
19 #include "bitops.h"
20 #include <asm/cpufeature.h>
21 
22 #include "cpustr.h"
23 
24 static char *cpu_name(int level)
25 {
26 	static char buf[6];
27 
28 	if (level == 64) {
29 		return "x86-64";
30 	} else {
31 		if (level == 15)
32 			level = 6;
33 		sprintf(buf, "i%d86", level);
34 		return buf;
35 	}
36 }
37 
38 int validate_cpu(void)
39 {
40 	u32 *err_flags;
41 	int cpu_level, req_level;
42 	const unsigned char *msg_strs;
43 
44 	check_cpu(&cpu_level, &req_level, &err_flags);
45 
46 	if (cpu_level < req_level) {
47 		printf("This kernel requires an %s CPU, ",
48 		       cpu_name(req_level));
49 		printf("but only detected an %s CPU.\n",
50 		       cpu_name(cpu_level));
51 		return -1;
52 	}
53 
54 	if (err_flags) {
55 		int i, j;
56 		puts("This kernel requires the following features "
57 		     "not present on the CPU:\n");
58 
59 		msg_strs = (const unsigned char *)x86_cap_strs;
60 
61 		for (i = 0; i < NCAPINTS; i++) {
62 			u32 e = err_flags[i];
63 
64 			for (j = 0; j < 32; j++) {
65 				int n = (i << 5)+j;
66 				if (*msg_strs < n) {
67 					/* Skip to the next string */
68 					do {
69 						msg_strs++;
70 					} while (*msg_strs);
71 					msg_strs++;
72 				}
73 				if (e & 1) {
74 					if (*msg_strs == n && msg_strs[1])
75 						printf("%s ", msg_strs+1);
76 					else
77 						printf("%d:%d ", i, j);
78 				}
79 				e >>= 1;
80 			}
81 		}
82 		putchar('\n');
83 		return -1;
84 	} else {
85 		return 0;
86 	}
87 }
88