2 * Intel CPU Microcode Update Driver for Linux
4 * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
5 * 2006 Shaohua Li <shaohua.li@intel.com>
7 * Intel CPU microcode early update for Linux
9 * Copyright (C) 2012 Fenghua Yu <fenghua.yu@intel.com>
10 * H Peter Anvin" <hpa@zytor.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
19 * This needs to be before all headers so that pr_debug in printk.h doesn't turn
20 * printk calls into no_printk().
24 #define pr_fmt(fmt) "microcode: " fmt
26 #include <linux/earlycpio.h>
27 #include <linux/firmware.h>
28 #include <linux/uaccess.h>
29 #include <linux/vmalloc.h>
30 #include <linux/initrd.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/cpu.h>
36 #include <asm/microcode_intel.h>
37 #include <asm/processor.h>
38 #include <asm/tlbflush.h>
39 #include <asm/setup.h>
42 static unsigned long mc_saved_in_initrd[MAX_UCODE_COUNT];
43 static struct mc_saved_data {
44 unsigned int num_saved;
45 struct microcode_intel **mc_saved;
48 static enum ucode_state
49 load_microcode_early(struct microcode_intel **saved,
50 unsigned int num_saved, struct ucode_cpu_info *uci)
52 struct microcode_intel *ucode_ptr, *new_mc = NULL;
53 struct microcode_header_intel *mc_hdr;
56 new_rev = uci->cpu_sig.rev;
58 for (i = 0; i < num_saved; i++) {
60 mc_hdr = (struct microcode_header_intel *)ucode_ptr;
62 ret = has_newer_microcode(ucode_ptr,
69 new_rev = mc_hdr->rev;
76 uci->mc = (struct microcode_intel *)new_mc;
81 copy_initrd_ptrs(struct microcode_intel **mc_saved, unsigned long *initrd,
82 unsigned long off, int num_saved)
86 for (i = 0; i < num_saved; i++)
87 mc_saved[i] = (struct microcode_intel *)(initrd[i] + off);
92 microcode_phys(struct microcode_intel **mc_saved_tmp, struct mc_saved_data *mcs)
95 struct microcode_intel ***mc_saved;
97 mc_saved = (struct microcode_intel ***)__pa_nodebug(&mcs->mc_saved);
99 for (i = 0; i < mcs->num_saved; i++) {
100 struct microcode_intel *p;
102 p = *(struct microcode_intel **)__pa_nodebug(mcs->mc_saved + i);
103 mc_saved_tmp[i] = (struct microcode_intel *)__pa_nodebug(p);
108 static enum ucode_state
109 load_microcode(struct mc_saved_data *mcs, unsigned long *initrd,
110 unsigned long initrd_start, struct ucode_cpu_info *uci)
112 struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
113 unsigned int count = mcs->num_saved;
115 if (!mcs->mc_saved) {
116 copy_initrd_ptrs(mc_saved_tmp, initrd, initrd_start, count);
118 return load_microcode_early(mc_saved_tmp, count, uci);
121 microcode_phys(mc_saved_tmp, mcs);
122 return load_microcode_early(mc_saved_tmp, count, uci);
124 return load_microcode_early(mcs->mc_saved, count, uci);
130 * Given CPU signature and a microcode patch, this function finds if the
131 * microcode patch has matching family and model with the CPU.
133 static enum ucode_state
134 matching_model_microcode(struct microcode_header_intel *mc_header,
137 unsigned int fam, model;
138 unsigned int fam_ucode, model_ucode;
139 struct extended_sigtable *ext_header;
140 unsigned long total_size = get_totalsize(mc_header);
141 unsigned long data_size = get_datasize(mc_header);
143 struct extended_signature *ext_sig;
145 fam = x86_family(sig);
146 model = x86_model(sig);
148 fam_ucode = x86_family(mc_header->sig);
149 model_ucode = x86_model(mc_header->sig);
151 if (fam == fam_ucode && model == model_ucode)
154 /* Look for ext. headers: */
155 if (total_size <= data_size + MC_HEADER_SIZE)
158 ext_header = (void *) mc_header + data_size + MC_HEADER_SIZE;
159 ext_sig = (void *)ext_header + EXT_HEADER_SIZE;
160 ext_sigcount = ext_header->count;
162 for (i = 0; i < ext_sigcount; i++) {
163 fam_ucode = x86_family(ext_sig->sig);
164 model_ucode = x86_model(ext_sig->sig);
166 if (fam == fam_ucode && model == model_ucode)
175 save_microcode(struct mc_saved_data *mcs,
176 struct microcode_intel **mc_saved_src,
177 unsigned int num_saved)
180 struct microcode_intel **saved_ptr;
187 * Copy new microcode data.
189 saved_ptr = kcalloc(num_saved, sizeof(struct microcode_intel *), GFP_KERNEL);
193 for (i = 0; i < num_saved; i++) {
194 struct microcode_header_intel *mc_hdr;
195 struct microcode_intel *mc;
198 if (!mc_saved_src[i]) {
203 mc = mc_saved_src[i];
205 size = get_totalsize(mc_hdr);
207 saved_ptr[i] = kmalloc(size, GFP_KERNEL);
213 memcpy(saved_ptr[i], mc, size);
217 * Point to newly saved microcode.
219 mcs->mc_saved = saved_ptr;
220 mcs->num_saved = num_saved;
225 for (j = 0; j <= i; j++)
233 * A microcode patch in ucode_ptr is saved into mc_saved
234 * - if it has matching signature and newer revision compared to an existing
236 * - or if it is a newly discovered microcode patch.
238 * The microcode patch should have matching model with CPU.
240 * Returns: The updated number @num_saved of saved microcode patches.
242 static unsigned int _save_mc(struct microcode_intel **mc_saved,
243 u8 *ucode_ptr, unsigned int num_saved)
245 struct microcode_header_intel *mc_hdr, *mc_saved_hdr;
246 unsigned int sig, pf;
249 mc_hdr = (struct microcode_header_intel *)ucode_ptr;
251 for (i = 0; i < num_saved; i++) {
252 mc_saved_hdr = (struct microcode_header_intel *)mc_saved[i];
253 sig = mc_saved_hdr->sig;
254 pf = mc_saved_hdr->pf;
256 if (!find_matching_signature(ucode_ptr, sig, pf))
261 if (mc_hdr->rev <= mc_saved_hdr->rev)
265 * Found an older ucode saved earlier. Replace it with
268 mc_saved[i] = (struct microcode_intel *)ucode_ptr;
272 /* Newly detected microcode, save it to memory. */
273 if (i >= num_saved && !found)
274 mc_saved[num_saved++] = (struct microcode_intel *)ucode_ptr;
280 * Get microcode matching with BSP's model. Only CPUs with the same model as
281 * BSP can stay in the platform.
283 static enum ucode_state __init
284 get_matching_model_microcode(int cpu, unsigned long start,
285 void *data, size_t size,
286 struct mc_saved_data *mcs,
287 unsigned long *mc_saved_in_initrd,
288 struct ucode_cpu_info *uci)
290 u8 *ucode_ptr = data;
291 unsigned int leftover = size;
292 enum ucode_state state = UCODE_OK;
293 unsigned int mc_size;
294 struct microcode_header_intel *mc_header;
295 struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
296 unsigned int num_saved = mcs->num_saved;
299 while (leftover && num_saved < ARRAY_SIZE(mc_saved_tmp)) {
301 if (leftover < sizeof(mc_header))
304 mc_header = (struct microcode_header_intel *)ucode_ptr;
306 mc_size = get_totalsize(mc_header);
307 if (!mc_size || mc_size > leftover ||
308 microcode_sanity_check(ucode_ptr, 0) < 0)
314 * Since APs with same family and model as the BSP may boot in
315 * the platform, we need to find and save microcode patches
316 * with the same family and model as the BSP.
318 if (matching_model_microcode(mc_header, uci->cpu_sig.sig) !=
320 ucode_ptr += mc_size;
324 num_saved = _save_mc(mc_saved_tmp, ucode_ptr, num_saved);
326 ucode_ptr += mc_size;
335 state = UCODE_NFOUND;
339 for (i = 0; i < num_saved; i++)
340 mc_saved_in_initrd[i] = (unsigned long)mc_saved_tmp[i] - start;
342 mcs->num_saved = num_saved;
347 static int collect_cpu_info_early(struct ucode_cpu_info *uci)
350 unsigned int family, model;
351 struct cpu_signature csig;
352 unsigned int eax, ebx, ecx, edx;
358 memset(uci, 0, sizeof(*uci));
362 native_cpuid(&eax, &ebx, &ecx, &edx);
365 family = x86_family(csig.sig);
366 model = x86_model(csig.sig);
368 if ((model >= 5) || (family > 6)) {
369 /* get processor flags from MSR 0x17 */
370 native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
371 csig.pf = 1 << ((val[1] >> 18) & 7);
373 native_wrmsr(MSR_IA32_UCODE_REV, 0, 0);
375 /* As documented in the SDM: Do a CPUID 1 here */
378 /* get the current revision from MSR 0x8B */
379 native_rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
389 static void show_saved_mc(void)
393 unsigned int sig, pf, rev, total_size, data_size, date;
394 struct ucode_cpu_info uci;
396 if (!mc_saved_data.num_saved) {
397 pr_debug("no microcode data saved.\n");
400 pr_debug("Total microcode saved: %d\n", mc_saved_data.num_saved);
402 collect_cpu_info_early(&uci);
404 sig = uci.cpu_sig.sig;
406 rev = uci.cpu_sig.rev;
407 pr_debug("CPU: sig=0x%x, pf=0x%x, rev=0x%x\n", sig, pf, rev);
409 for (i = 0; i < mc_saved_data.num_saved; i++) {
410 struct microcode_header_intel *mc_saved_header;
411 struct extended_sigtable *ext_header;
413 struct extended_signature *ext_sig;
415 mc_saved_header = (struct microcode_header_intel *)
416 mc_saved_data.mc_saved[i];
417 sig = mc_saved_header->sig;
418 pf = mc_saved_header->pf;
419 rev = mc_saved_header->rev;
420 total_size = get_totalsize(mc_saved_header);
421 data_size = get_datasize(mc_saved_header);
422 date = mc_saved_header->date;
424 pr_debug("mc_saved[%d]: sig=0x%x, pf=0x%x, rev=0x%x, toal size=0x%x, date = %04x-%02x-%02x\n",
425 i, sig, pf, rev, total_size,
428 (date >> 16) & 0xff);
430 /* Look for ext. headers: */
431 if (total_size <= data_size + MC_HEADER_SIZE)
434 ext_header = (void *) mc_saved_header + data_size + MC_HEADER_SIZE;
435 ext_sigcount = ext_header->count;
436 ext_sig = (void *)ext_header + EXT_HEADER_SIZE;
438 for (j = 0; j < ext_sigcount; j++) {
442 pr_debug("\tExtended[%d]: sig=0x%x, pf=0x%x\n",
452 #ifdef CONFIG_HOTPLUG_CPU
453 static DEFINE_MUTEX(x86_cpu_microcode_mutex);
455 * Save this mc into mc_saved_data. So it will be loaded early when a CPU is
456 * hot added or resumes.
458 * Please make sure this mc should be a valid microcode patch before calling
461 int save_mc_for_early(u8 *mc)
463 struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
464 unsigned int mc_saved_count_init;
465 unsigned int num_saved;
466 struct microcode_intel **mc_saved;
471 * Hold hotplug lock so mc_saved_data is not accessed by a CPU in
474 mutex_lock(&x86_cpu_microcode_mutex);
476 mc_saved_count_init = mc_saved_data.num_saved;
477 num_saved = mc_saved_data.num_saved;
478 mc_saved = mc_saved_data.mc_saved;
480 if (mc_saved && num_saved)
481 memcpy(mc_saved_tmp, mc_saved,
482 num_saved * sizeof(struct microcode_intel *));
484 * Save the microcode patch mc in mc_save_tmp structure if it's a newer
487 num_saved = _save_mc(mc_saved_tmp, mc, num_saved);
490 * Save the mc_save_tmp in global mc_saved_data.
492 ret = save_microcode(&mc_saved_data, mc_saved_tmp, num_saved);
494 pr_err("Cannot save microcode patch.\n");
501 * Free old saved microcode data.
504 for (i = 0; i < mc_saved_count_init; i++)
510 mutex_unlock(&x86_cpu_microcode_mutex);
514 EXPORT_SYMBOL_GPL(save_mc_for_early);
517 static bool __init load_builtin_intel_microcode(struct cpio_data *cp)
520 unsigned int eax = 0x00000001, ebx, ecx = 0, edx;
523 native_cpuid(&eax, &ebx, &ecx, &edx);
525 sprintf(name, "intel-ucode/%02x-%02x-%02x",
526 x86_family(eax), x86_model(eax), x86_stepping(eax));
528 return get_builtin_firmware(cp, name);
534 static __initdata char ucode_name[] = "kernel/x86/microcode/GenuineIntel.bin";
535 static __init enum ucode_state
536 scan_microcode(struct mc_saved_data *mcs, unsigned long *initrd,
537 unsigned long start, unsigned long size,
538 struct ucode_cpu_info *uci)
543 char *p = (char *)__pa_nodebug(ucode_name);
545 char *p = ucode_name;
551 /* try built-in microcode if no initrd */
553 if (!load_builtin_intel_microcode(&cd))
556 cd = find_cpio_data(p, (void *)start, size, &offset);
561 return get_matching_model_microcode(0, start, cd.data, cd.size,
566 * Print ucode update info.
569 print_ucode_info(struct ucode_cpu_info *uci, unsigned int date)
571 pr_info_once("microcode updated early to revision 0x%x, date = %04x-%02x-%02x\n",
575 (date >> 16) & 0xff);
580 static int delay_ucode_info;
581 static int current_mc_date;
584 * Print early updated ucode info after printk works. This is delayed info dump.
586 void show_ucode_info_early(void)
588 struct ucode_cpu_info uci;
590 if (delay_ucode_info) {
591 collect_cpu_info_early(&uci);
592 print_ucode_info(&uci, current_mc_date);
593 delay_ucode_info = 0;
598 * At this point, we can not call printk() yet. Keep microcode patch number in
599 * mc_saved_data.mc_saved and delay printing microcode info in
600 * show_ucode_info_early() until printk() works.
602 static void print_ucode(struct ucode_cpu_info *uci)
604 struct microcode_intel *mc;
605 int *delay_ucode_info_p;
606 int *current_mc_date_p;
612 delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
613 current_mc_date_p = (int *)__pa_nodebug(¤t_mc_date);
615 *delay_ucode_info_p = 1;
616 *current_mc_date_p = mc->hdr.date;
621 * Flush global tlb. We only do this in x86_64 where paging has been enabled
622 * already and PGE should be enabled as well.
624 static inline void flush_tlb_early(void)
626 __native_flush_tlb_global_irq_disabled();
629 static inline void print_ucode(struct ucode_cpu_info *uci)
631 struct microcode_intel *mc;
637 print_ucode_info(uci, mc->hdr.date);
641 static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
643 struct microcode_intel *mc;
650 /* write microcode via MSR 0x79 */
651 native_wrmsr(MSR_IA32_UCODE_WRITE,
652 (unsigned long)mc->bits,
653 (unsigned long)mc->bits >> 16 >> 16);
654 native_wrmsr(MSR_IA32_UCODE_REV, 0, 0);
656 /* As documented in the SDM: Do a CPUID 1 here */
659 /* get the current revision from MSR 0x8B */
660 native_rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
661 if (val[1] != mc->hdr.rev)
665 /* Flush global tlb. This is precaution. */
668 uci->cpu_sig.rev = val[1];
673 print_ucode_info(uci, mc->hdr.date);
679 * This function converts microcode patch offsets previously stored in
680 * mc_saved_in_initrd to pointers and stores the pointers in mc_saved_data.
682 int __init save_microcode_in_initrd_intel(void)
684 unsigned int count = mc_saved_data.num_saved;
685 struct microcode_intel *mc_saved[MAX_UCODE_COUNT];
691 copy_initrd_ptrs(mc_saved, mc_saved_in_initrd, get_initrd_start(), count);
693 ret = save_microcode(&mc_saved_data, mc_saved, count);
695 pr_err("Cannot save microcode patches from initrd.\n");
703 _load_ucode_intel_bsp(struct mc_saved_data *mcs, unsigned long *initrd,
704 unsigned long start, unsigned long size)
706 struct ucode_cpu_info uci;
707 enum ucode_state ret;
709 collect_cpu_info_early(&uci);
711 ret = scan_microcode(mcs, initrd, start, size, &uci);
715 ret = load_microcode(mcs, initrd, start, &uci);
719 apply_microcode_early(&uci, true);
722 void __init load_ucode_intel_bsp(void)
726 struct boot_params *p;
728 p = (struct boot_params *)__pa_nodebug(&boot_params);
729 size = p->hdr.ramdisk_size;
732 * Set start only if we have an initrd image. We cannot use initrd_start
733 * because it is not set that early yet.
735 start = (size ? p->hdr.ramdisk_image : 0);
737 _load_ucode_intel_bsp((struct mc_saved_data *)__pa_nodebug(&mc_saved_data),
738 (unsigned long *)__pa_nodebug(&mc_saved_in_initrd),
741 size = boot_params.hdr.ramdisk_size;
742 start = (size ? boot_params.hdr.ramdisk_image + PAGE_OFFSET : 0);
744 _load_ucode_intel_bsp(&mc_saved_data, mc_saved_in_initrd, start, size);
748 void load_ucode_intel_ap(void)
750 unsigned long *mc_saved_in_initrd_p;
751 struct mc_saved_data *mcs_p;
752 struct ucode_cpu_info uci;
753 enum ucode_state ret;
756 mc_saved_in_initrd_p = (unsigned long *)__pa_nodebug(mc_saved_in_initrd);
757 mcs_p = (struct mc_saved_data *)__pa_nodebug(&mc_saved_data);
759 mc_saved_in_initrd_p = mc_saved_in_initrd;
760 mcs_p = &mc_saved_data;
764 * If there is no valid ucode previously saved in memory, no need to
765 * update ucode on this AP.
767 if (!mcs_p->num_saved)
770 collect_cpu_info_early(&uci);
771 ret = load_microcode(mcs_p, mc_saved_in_initrd_p,
772 get_initrd_start_addr(), &uci);
777 apply_microcode_early(&uci, true);
780 void reload_ucode_intel(void)
782 struct ucode_cpu_info uci;
783 enum ucode_state ret;
785 if (!mc_saved_data.num_saved)
788 collect_cpu_info_early(&uci);
790 ret = load_microcode_early(mc_saved_data.mc_saved,
791 mc_saved_data.num_saved, &uci);
795 apply_microcode_early(&uci, false);
798 static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
800 struct cpuinfo_x86 *c = &cpu_data(cpu_num);
803 memset(csig, 0, sizeof(*csig));
805 csig->sig = cpuid_eax(0x00000001);
807 if ((c->x86_model >= 5) || (c->x86 > 6)) {
808 /* get processor flags from MSR 0x17 */
809 rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
810 csig->pf = 1 << ((val[1] >> 18) & 7);
813 csig->rev = c->microcode;
814 pr_info("CPU%d sig=0x%x, pf=0x%x, revision=0x%x\n",
815 cpu_num, csig->sig, csig->pf, csig->rev);
821 * return 0 - no update found
822 * return 1 - found update
824 static int get_matching_mc(struct microcode_intel *mc, int cpu)
826 struct cpu_signature cpu_sig;
827 unsigned int csig, cpf, crev;
829 collect_cpu_info(cpu, &cpu_sig);
835 return has_newer_microcode(mc, csig, cpf, crev);
838 static int apply_microcode_intel(int cpu)
840 struct microcode_intel *mc;
841 struct ucode_cpu_info *uci;
843 int cpu_num = raw_smp_processor_id();
844 struct cpuinfo_x86 *c = &cpu_data(cpu_num);
846 /* We should bind the task to the CPU */
847 if (WARN_ON(cpu_num != cpu))
850 uci = ucode_cpu_info + cpu;
856 * Microcode on this CPU could be updated earlier. Only apply the
857 * microcode patch in mc when it is newer than the one on this
860 if (!get_matching_mc(mc, cpu))
863 /* write microcode via MSR 0x79 */
864 wrmsr(MSR_IA32_UCODE_WRITE,
865 (unsigned long) mc->bits,
866 (unsigned long) mc->bits >> 16 >> 16);
867 wrmsr(MSR_IA32_UCODE_REV, 0, 0);
869 /* As documented in the SDM: Do a CPUID 1 here */
872 /* get the current revision from MSR 0x8B */
873 rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
875 if (val[1] != mc->hdr.rev) {
876 pr_err("CPU%d update to revision 0x%x failed\n",
877 cpu_num, mc->hdr.rev);
880 pr_info("CPU%d updated to revision 0x%x, date = %04x-%02x-%02x\n",
882 mc->hdr.date & 0xffff,
884 (mc->hdr.date >> 16) & 0xff);
886 uci->cpu_sig.rev = val[1];
887 c->microcode = val[1];
892 static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
893 int (*get_ucode_data)(void *, const void *, size_t))
895 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
896 u8 *ucode_ptr = data, *new_mc = NULL, *mc = NULL;
897 int new_rev = uci->cpu_sig.rev;
898 unsigned int leftover = size;
899 enum ucode_state state = UCODE_OK;
900 unsigned int curr_mc_size = 0;
901 unsigned int csig, cpf;
904 struct microcode_header_intel mc_header;
905 unsigned int mc_size;
907 if (leftover < sizeof(mc_header)) {
908 pr_err("error! Truncated header in microcode data file\n");
912 if (get_ucode_data(&mc_header, ucode_ptr, sizeof(mc_header)))
915 mc_size = get_totalsize(&mc_header);
916 if (!mc_size || mc_size > leftover) {
917 pr_err("error! Bad data in microcode data file\n");
921 /* For performance reasons, reuse mc area when possible */
922 if (!mc || mc_size > curr_mc_size) {
924 mc = vmalloc(mc_size);
927 curr_mc_size = mc_size;
930 if (get_ucode_data(mc, ucode_ptr, mc_size) ||
931 microcode_sanity_check(mc, 1) < 0) {
935 csig = uci->cpu_sig.sig;
936 cpf = uci->cpu_sig.pf;
937 if (has_newer_microcode(mc, csig, cpf, new_rev)) {
939 new_rev = mc_header.rev;
941 mc = NULL; /* trigger new vmalloc */
944 ucode_ptr += mc_size;
957 state = UCODE_NFOUND;
962 uci->mc = (struct microcode_intel *)new_mc;
965 * If early loading microcode is supported, save this mc into
966 * permanent memory. So it will be loaded early when a CPU is hot added
969 save_mc_for_early(new_mc);
971 pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
972 cpu, new_rev, uci->cpu_sig.rev);
977 static int get_ucode_fw(void *to, const void *from, size_t n)
983 static enum ucode_state request_microcode_fw(int cpu, struct device *device,
987 struct cpuinfo_x86 *c = &cpu_data(cpu);
988 const struct firmware *firmware;
989 enum ucode_state ret;
991 sprintf(name, "intel-ucode/%02x-%02x-%02x",
992 c->x86, c->x86_model, c->x86_mask);
994 if (request_firmware_direct(&firmware, name, device)) {
995 pr_debug("data file %s load failed\n", name);
999 ret = generic_load_microcode(cpu, (void *)firmware->data,
1000 firmware->size, &get_ucode_fw);
1002 release_firmware(firmware);
1007 static int get_ucode_user(void *to, const void *from, size_t n)
1009 return copy_from_user(to, from, n);
1012 static enum ucode_state
1013 request_microcode_user(int cpu, const void __user *buf, size_t size)
1015 return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
1018 static void microcode_fini_cpu(int cpu)
1020 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
1026 static struct microcode_ops microcode_intel_ops = {
1027 .request_microcode_user = request_microcode_user,
1028 .request_microcode_fw = request_microcode_fw,
1029 .collect_cpu_info = collect_cpu_info,
1030 .apply_microcode = apply_microcode_intel,
1031 .microcode_fini_cpu = microcode_fini_cpu,
1034 struct microcode_ops * __init init_intel_microcode(void)
1036 struct cpuinfo_x86 *c = &boot_cpu_data;
1038 if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
1039 cpu_has(c, X86_FEATURE_IA64)) {
1040 pr_err("Intel CPU family 0x%x not supported\n", c->x86);
1044 return µcode_intel_ops;