cpu.c 2.0 KB

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