cpu.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include "cpustr.h"
  16. static char *cpu_name(int level)
  17. {
  18. static char buf[6];
  19. if (level == 64) {
  20. return "x86-64";
  21. } else {
  22. if (level == 15)
  23. level = 6;
  24. sprintf(buf, "i%d86", level);
  25. return buf;
  26. }
  27. }
  28. static void show_cap_strs(u32 *err_flags)
  29. {
  30. int i, j;
  31. const unsigned char *msg_strs = (const unsigned char *)x86_cap_strs;
  32. for (i = 0; i < NCAPINTS; i++) {
  33. u32 e = err_flags[i];
  34. for (j = 0; j < 32; j++) {
  35. if (msg_strs[0] < i ||
  36. (msg_strs[0] == i && msg_strs[1] < j)) {
  37. /* Skip to the next string */
  38. msg_strs += 2;
  39. while (*msg_strs++)
  40. ;
  41. }
  42. if (e & 1) {
  43. if (msg_strs[0] == i &&
  44. msg_strs[1] == j &&
  45. msg_strs[2])
  46. printf("%s ", msg_strs+2);
  47. else
  48. printf("%d:%d ", i, j);
  49. }
  50. e >>= 1;
  51. }
  52. }
  53. }
  54. int validate_cpu(void)
  55. {
  56. u32 *err_flags;
  57. int cpu_level, req_level;
  58. check_cpu(&cpu_level, &req_level, &err_flags);
  59. if (cpu_level < req_level) {
  60. printf("This kernel requires an %s CPU, ",
  61. cpu_name(req_level));
  62. printf("but only detected an %s CPU.\n",
  63. cpu_name(cpu_level));
  64. return -1;
  65. }
  66. if (err_flags) {
  67. puts("This kernel requires the following features "
  68. "not present on the CPU:\n");
  69. show_cap_strs(err_flags);
  70. putchar('\n');
  71. return -1;
  72. } else if (check_knl_erratum()) {
  73. return -1;
  74. } else {
  75. return 0;
  76. }
  77. }