Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* -*- linux-c -*- ------------------------------------------------------- *
0003  *
0004  *   Copyright (C) 1991, 1992 Linus Torvalds
0005  *   Copyright 2007-2008 rPath, Inc. - All Rights Reserved
0006  *
0007  * ----------------------------------------------------------------------- */
0008 
0009 /*
0010  * arch/x86/boot/cpu.c
0011  *
0012  * Check for obligatory CPU features and abort if the features are not
0013  * present.
0014  */
0015 
0016 #include "boot.h"
0017 #ifdef CONFIG_X86_FEATURE_NAMES
0018 #include "cpustr.h"
0019 #endif
0020 
0021 static char *cpu_name(int level)
0022 {
0023     static char buf[6];
0024 
0025     if (level == 64) {
0026         return "x86-64";
0027     } else {
0028         if (level == 15)
0029             level = 6;
0030         sprintf(buf, "i%d86", level);
0031         return buf;
0032     }
0033 }
0034 
0035 static void show_cap_strs(u32 *err_flags)
0036 {
0037     int i, j;
0038 #ifdef CONFIG_X86_FEATURE_NAMES
0039     const unsigned char *msg_strs = (const unsigned char *)x86_cap_strs;
0040     for (i = 0; i < NCAPINTS; i++) {
0041         u32 e = err_flags[i];
0042         for (j = 0; j < 32; j++) {
0043             if (msg_strs[0] < i ||
0044                 (msg_strs[0] == i && msg_strs[1] < j)) {
0045                 /* Skip to the next string */
0046                 msg_strs += 2;
0047                 while (*msg_strs++)
0048                     ;
0049             }
0050             if (e & 1) {
0051                 if (msg_strs[0] == i &&
0052                     msg_strs[1] == j &&
0053                     msg_strs[2])
0054                     printf("%s ", msg_strs+2);
0055                 else
0056                     printf("%d:%d ", i, j);
0057             }
0058             e >>= 1;
0059         }
0060     }
0061 #else
0062     for (i = 0; i < NCAPINTS; i++) {
0063         u32 e = err_flags[i];
0064         for (j = 0; j < 32; j++) {
0065             if (e & 1)
0066                 printf("%d:%d ", i, j);
0067             e >>= 1;
0068         }
0069     }
0070 #endif
0071 }
0072 
0073 int validate_cpu(void)
0074 {
0075     u32 *err_flags;
0076     int cpu_level, req_level;
0077 
0078     check_cpu(&cpu_level, &req_level, &err_flags);
0079 
0080     if (cpu_level < req_level) {
0081         printf("This kernel requires an %s CPU, ",
0082                cpu_name(req_level));
0083         printf("but only detected an %s CPU.\n",
0084                cpu_name(cpu_level));
0085         return -1;
0086     }
0087 
0088     if (err_flags) {
0089         puts("This kernel requires the following features "
0090              "not present on the CPU:\n");
0091         show_cap_strs(err_flags);
0092         putchar('\n');
0093         return -1;
0094     } else if (check_knl_erratum()) {
0095         return -1;
0096     } else {
0097         return 0;
0098     }
0099 }