blob: 92d6fd73dc7dff60681d6ab7dee1362fba783d70 [file] [log] [blame]
H. Peter Anvin31b54f42007-07-11 12:18:47 -07001/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
H. Peter Anvinf0be6c62008-02-04 16:48:00 +01004 * Copyright 2007-2008 rPath, Inc. - All Rights Reserved
H. Peter Anvin31b54f42007-07-11 12:18:47 -07005 *
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/*
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010012 * arch/x86/boot/cpu.c
H. Peter Anvin31b54f42007-07-11 12:18:47 -070013 *
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
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010022#include "cpustr.h"
23
H. Peter Anvin31b54f42007-07-11 12:18:47 -070024static char *cpu_name(int level)
25{
26 static char buf[6];
27
28 if (level == 64) {
29 return "x86-64";
30 } else {
Dave Jonesc7d624d2008-05-28 12:57:13 -040031 if (level == 15)
32 level = 6;
H. Peter Anvin31b54f42007-07-11 12:18:47 -070033 sprintf(buf, "i%d86", level);
34 return buf;
35 }
36}
37
38int validate_cpu(void)
39{
40 u32 *err_flags;
41 int cpu_level, req_level;
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010042 const unsigned char *msg_strs;
H. Peter Anvin31b54f42007-07-11 12:18:47 -070043
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
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010059 msg_strs = (const unsigned char *)x86_cap_strs;
60
H. Peter Anvin31b54f42007-07-11 12:18:47 -070061 for (i = 0; i < NCAPINTS; i++) {
62 u32 e = err_flags[i];
63
64 for (j = 0; j < 32; j++) {
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010065 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 }
H. Peter Anvin31b54f42007-07-11 12:18:47 -070079 e >>= 1;
80 }
81 }
82 putchar('\n');
83 return -1;
84 } else {
85 return 0;
86 }
87}