blob: 00e19edd852c60d8cc32a2b009a604938747dd77 [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 {
31 sprintf(buf, "i%d86", level);
32 return buf;
33 }
34}
35
36int validate_cpu(void)
37{
38 u32 *err_flags;
39 int cpu_level, req_level;
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010040 const unsigned char *msg_strs;
H. Peter Anvin31b54f42007-07-11 12:18:47 -070041
42 check_cpu(&cpu_level, &req_level, &err_flags);
43
44 if (cpu_level < req_level) {
45 printf("This kernel requires an %s CPU, ",
46 cpu_name(req_level));
47 printf("but only detected an %s CPU.\n",
48 cpu_name(cpu_level));
49 return -1;
50 }
51
52 if (err_flags) {
53 int i, j;
54 puts("This kernel requires the following features "
55 "not present on the CPU:\n");
56
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010057 msg_strs = (const unsigned char *)x86_cap_strs;
58
H. Peter Anvin31b54f42007-07-11 12:18:47 -070059 for (i = 0; i < NCAPINTS; i++) {
60 u32 e = err_flags[i];
61
62 for (j = 0; j < 32; j++) {
H. Peter Anvinf0be6c62008-02-04 16:48:00 +010063 int n = (i << 5)+j;
64 if (*msg_strs < n) {
65 /* Skip to the next string */
66 do {
67 msg_strs++;
68 } while (*msg_strs);
69 msg_strs++;
70 }
71 if (e & 1) {
72 if (*msg_strs == n && msg_strs[1])
73 printf("%s ", msg_strs+1);
74 else
75 printf("%d:%d ", i, j);
76 }
H. Peter Anvin31b54f42007-07-11 12:18:47 -070077 e >>= 1;
78 }
79 }
80 putchar('\n');
81 return -1;
82 } else {
83 return 0;
84 }
85}