core_early.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * X86 CPU microcode early update for Linux
  3. *
  4. * Copyright (C) 2012 Fenghua Yu <fenghua.yu@intel.com>
  5. * H Peter Anvin" <hpa@zytor.com>
  6. * (C) 2015 Borislav Petkov <bp@alien8.de>
  7. *
  8. * This driver allows to early upgrade microcode on Intel processors
  9. * belonging to IA-32 family - PentiumPro, Pentium II,
  10. * Pentium III, Xeon, Pentium 4, etc.
  11. *
  12. * Reference: Section 9.11 of Volume 3, IA-32 Intel Architecture
  13. * Software Developer's Manual.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/firmware.h>
  22. #include <asm/microcode.h>
  23. #include <asm/microcode_intel.h>
  24. #include <asm/microcode_amd.h>
  25. #include <asm/processor.h>
  26. #include <asm/cmdline.h>
  27. static bool __init check_loader_disabled_bsp(void)
  28. {
  29. #ifdef CONFIG_X86_32
  30. const char *cmdline = (const char *)__pa_nodebug(boot_command_line);
  31. const char *opt = "dis_ucode_ldr";
  32. const char *option = (const char *)__pa_nodebug(opt);
  33. bool *res = (bool *)__pa_nodebug(&dis_ucode_ldr);
  34. #else /* CONFIG_X86_64 */
  35. const char *cmdline = boot_command_line;
  36. const char *option = "dis_ucode_ldr";
  37. bool *res = &dis_ucode_ldr;
  38. #endif
  39. if (cmdline_find_option_bool(cmdline, option))
  40. *res = true;
  41. return *res;
  42. }
  43. extern struct builtin_fw __start_builtin_fw[];
  44. extern struct builtin_fw __end_builtin_fw[];
  45. bool get_builtin_firmware(struct cpio_data *cd, const char *name)
  46. {
  47. #ifdef CONFIG_FW_LOADER
  48. struct builtin_fw *b_fw;
  49. for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
  50. if (!strcmp(name, b_fw->name)) {
  51. cd->size = b_fw->size;
  52. cd->data = b_fw->data;
  53. return true;
  54. }
  55. }
  56. #endif
  57. return false;
  58. }
  59. void __init load_ucode_bsp(void)
  60. {
  61. int vendor;
  62. unsigned int family;
  63. if (check_loader_disabled_bsp())
  64. return;
  65. if (!have_cpuid_p())
  66. return;
  67. vendor = x86_vendor();
  68. family = x86_family();
  69. switch (vendor) {
  70. case X86_VENDOR_INTEL:
  71. if (family >= 6)
  72. load_ucode_intel_bsp();
  73. break;
  74. case X86_VENDOR_AMD:
  75. if (family >= 0x10)
  76. load_ucode_amd_bsp(family);
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82. static bool check_loader_disabled_ap(void)
  83. {
  84. #ifdef CONFIG_X86_32
  85. return *((bool *)__pa_nodebug(&dis_ucode_ldr));
  86. #else
  87. return dis_ucode_ldr;
  88. #endif
  89. }
  90. void load_ucode_ap(void)
  91. {
  92. int vendor, family;
  93. if (check_loader_disabled_ap())
  94. return;
  95. if (!have_cpuid_p())
  96. return;
  97. vendor = x86_vendor();
  98. family = x86_family();
  99. switch (vendor) {
  100. case X86_VENDOR_INTEL:
  101. if (family >= 6)
  102. load_ucode_intel_ap();
  103. break;
  104. case X86_VENDOR_AMD:
  105. if (family >= 0x10)
  106. load_ucode_amd_ap();
  107. break;
  108. default:
  109. break;
  110. }
  111. }
  112. int __init save_microcode_in_initrd(void)
  113. {
  114. struct cpuinfo_x86 *c = &boot_cpu_data;
  115. switch (c->x86_vendor) {
  116. case X86_VENDOR_INTEL:
  117. if (c->x86 >= 6)
  118. save_microcode_in_initrd_intel();
  119. break;
  120. case X86_VENDOR_AMD:
  121. if (c->x86 >= 0x10)
  122. save_microcode_in_initrd_amd();
  123. break;
  124. default:
  125. break;
  126. }
  127. return 0;
  128. }
  129. void reload_early_microcode(void)
  130. {
  131. int vendor, family;
  132. vendor = x86_vendor();
  133. family = x86_family();
  134. switch (vendor) {
  135. case X86_VENDOR_INTEL:
  136. if (family >= 6)
  137. reload_ucode_intel();
  138. break;
  139. case X86_VENDOR_AMD:
  140. if (family >= 0x10)
  141. reload_ucode_amd();
  142. break;
  143. default:
  144. break;
  145. }
  146. }