Linux 4.1.18
[linux/fpc-iii.git] / arch / x86 / kernel / cpu / microcode / core_early.c
bloba413a69cbd744f2e2873434ee20b66e86fb466dd
1 /*
2 * X86 CPU microcode early update for Linux
4 * Copyright (C) 2012 Fenghua Yu <fenghua.yu@intel.com>
5 * H Peter Anvin" <hpa@zytor.com>
7 * This driver allows to early upgrade microcode on Intel processors
8 * belonging to IA-32 family - PentiumPro, Pentium II,
9 * Pentium III, Xeon, Pentium 4, etc.
11 * Reference: Section 9.11 of Volume 3, IA-32 Intel Architecture
12 * Software Developer's Manual.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
19 #include <linux/module.h>
20 #include <asm/microcode.h>
21 #include <asm/microcode_intel.h>
22 #include <asm/microcode_amd.h>
23 #include <asm/processor.h>
24 #include <asm/cmdline.h>
26 static bool __init check_loader_disabled_bsp(void)
28 #ifdef CONFIG_X86_32
29 const char *cmdline = (const char *)__pa_nodebug(boot_command_line);
30 const char *opt = "dis_ucode_ldr";
31 const char *option = (const char *)__pa_nodebug(opt);
32 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
40 if (cmdline_find_option_bool(cmdline, option))
41 *res = true;
43 return *res;
46 void __init load_ucode_bsp(void)
48 int vendor, family;
50 if (check_loader_disabled_bsp())
51 return;
53 if (!have_cpuid_p())
54 return;
56 vendor = x86_vendor();
57 family = x86_family();
59 switch (vendor) {
60 case X86_VENDOR_INTEL:
61 if (family >= 6)
62 load_ucode_intel_bsp();
63 break;
64 case X86_VENDOR_AMD:
65 if (family >= 0x10)
66 load_ucode_amd_bsp();
67 break;
68 default:
69 break;
73 static bool check_loader_disabled_ap(void)
75 #ifdef CONFIG_X86_32
76 return *((bool *)__pa_nodebug(&dis_ucode_ldr));
77 #else
78 return dis_ucode_ldr;
79 #endif
82 void load_ucode_ap(void)
84 int vendor, family;
86 if (check_loader_disabled_ap())
87 return;
89 if (!have_cpuid_p())
90 return;
92 vendor = x86_vendor();
93 family = x86_family();
95 switch (vendor) {
96 case X86_VENDOR_INTEL:
97 if (family >= 6)
98 load_ucode_intel_ap();
99 break;
100 case X86_VENDOR_AMD:
101 if (family >= 0x10)
102 load_ucode_amd_ap();
103 break;
104 default:
105 break;
109 int __init save_microcode_in_initrd(void)
111 struct cpuinfo_x86 *c = &boot_cpu_data;
113 switch (c->x86_vendor) {
114 case X86_VENDOR_INTEL:
115 if (c->x86 >= 6)
116 save_microcode_in_initrd_intel();
117 break;
118 case X86_VENDOR_AMD:
119 if (c->x86 >= 0x10)
120 save_microcode_in_initrd_amd();
121 break;
122 default:
123 break;
126 return 0;
129 void reload_early_microcode(void)
131 int vendor, family;
133 vendor = x86_vendor();
134 family = x86_family();
136 switch (vendor) {
137 case X86_VENDOR_INTEL:
138 if (family >= 6)
139 reload_ucode_intel();
140 break;
141 case X86_VENDOR_AMD:
142 if (family >= 0x10)
143 reload_ucode_amd();
144 break;
145 default:
146 break;