Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / arch / x86 / kernel / cpu / microcode / intel_early.c
1 /*
2  *      Intel 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  *
7  *      This allows to early upgrade microcode on Intel processors
8  *      belonging to IA-32 family - PentiumPro, Pentium II,
9  *      Pentium III, Xeon, Pentium 4, etc.
10  *
11  *      Reference: Section 9.11 of Volume 3, IA-32 Intel Architecture
12  *      Software Developer's Manual.
13  *
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.
18  */
19
20 /*
21  * This needs to be before all headers so that pr_debug in printk.h doesn't turn
22  * printk calls into no_printk().
23  *
24  *#define DEBUG
25  */
26
27 #include <linux/module.h>
28 #include <linux/mm.h>
29 #include <linux/slab.h>
30 #include <linux/earlycpio.h>
31 #include <linux/initrd.h>
32 #include <linux/cpu.h>
33 #include <asm/msr.h>
34 #include <asm/microcode_intel.h>
35 #include <asm/processor.h>
36 #include <asm/tlbflush.h>
37 #include <asm/setup.h>
38
39 #undef pr_fmt
40 #define pr_fmt(fmt)     "microcode: " fmt
41
42 static unsigned long mc_saved_in_initrd[MAX_UCODE_COUNT];
43 static struct mc_saved_data {
44         unsigned int mc_saved_count;
45         struct microcode_intel **mc_saved;
46 } mc_saved_data;
47
48 static enum ucode_state
49 load_microcode_early(struct microcode_intel **saved,
50                      unsigned int num_saved, struct ucode_cpu_info *uci)
51 {
52         struct microcode_intel *ucode_ptr, *new_mc = NULL;
53         struct microcode_header_intel *mc_hdr;
54         int new_rev, ret, i;
55
56         new_rev = uci->cpu_sig.rev;
57
58         for (i = 0; i < num_saved; i++) {
59                 ucode_ptr = saved[i];
60                 mc_hdr    = (struct microcode_header_intel *)ucode_ptr;
61
62                 ret = get_matching_microcode(uci->cpu_sig.sig,
63                                              uci->cpu_sig.pf,
64                                              new_rev,
65                                              ucode_ptr);
66                 if (!ret)
67                         continue;
68
69                 new_rev = mc_hdr->rev;
70                 new_mc  = ucode_ptr;
71         }
72
73         if (!new_mc)
74                 return UCODE_NFOUND;
75
76         uci->mc = (struct microcode_intel *)new_mc;
77         return UCODE_OK;
78 }
79
80 static inline void
81 copy_initrd_ptrs(struct microcode_intel **mc_saved, unsigned long *initrd,
82                   unsigned long off, int num_saved)
83 {
84         int i;
85
86         for (i = 0; i < num_saved; i++)
87                 mc_saved[i] = (struct microcode_intel *)(initrd[i] + off);
88 }
89
90 #ifdef CONFIG_X86_32
91 static void
92 microcode_phys(struct microcode_intel **mc_saved_tmp,
93                struct mc_saved_data *mc_saved_data)
94 {
95         int i;
96         struct microcode_intel ***mc_saved;
97
98         mc_saved = (struct microcode_intel ***)
99                    __pa_nodebug(&mc_saved_data->mc_saved);
100         for (i = 0; i < mc_saved_data->mc_saved_count; i++) {
101                 struct microcode_intel *p;
102
103                 p = *(struct microcode_intel **)
104                         __pa_nodebug(mc_saved_data->mc_saved + i);
105                 mc_saved_tmp[i] = (struct microcode_intel *)__pa_nodebug(p);
106         }
107 }
108 #endif
109
110 static enum ucode_state
111 load_microcode(struct mc_saved_data *mc_saved_data, unsigned long *initrd,
112                unsigned long initrd_start, struct ucode_cpu_info *uci)
113 {
114         struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
115         unsigned int count = mc_saved_data->mc_saved_count;
116
117         if (!mc_saved_data->mc_saved) {
118                 copy_initrd_ptrs(mc_saved_tmp, initrd, initrd_start, count);
119
120                 return load_microcode_early(mc_saved_tmp, count, uci);
121         } else {
122 #ifdef CONFIG_X86_32
123                 microcode_phys(mc_saved_tmp, mc_saved_data);
124                 return load_microcode_early(mc_saved_tmp, count, uci);
125 #else
126                 return load_microcode_early(mc_saved_data->mc_saved,
127                                                     count, uci);
128 #endif
129         }
130 }
131
132 /*
133  * Given CPU signature and a microcode patch, this function finds if the
134  * microcode patch has matching family and model with the CPU.
135  */
136 static enum ucode_state
137 matching_model_microcode(struct microcode_header_intel *mc_header,
138                         unsigned long sig)
139 {
140         unsigned int fam, model;
141         unsigned int fam_ucode, model_ucode;
142         struct extended_sigtable *ext_header;
143         unsigned long total_size = get_totalsize(mc_header);
144         unsigned long data_size = get_datasize(mc_header);
145         int ext_sigcount, i;
146         struct extended_signature *ext_sig;
147
148         fam   = __x86_family(sig);
149         model = x86_model(sig);
150
151         fam_ucode   = __x86_family(mc_header->sig);
152         model_ucode = x86_model(mc_header->sig);
153
154         if (fam == fam_ucode && model == model_ucode)
155                 return UCODE_OK;
156
157         /* Look for ext. headers: */
158         if (total_size <= data_size + MC_HEADER_SIZE)
159                 return UCODE_NFOUND;
160
161         ext_header   = (void *) mc_header + data_size + MC_HEADER_SIZE;
162         ext_sig      = (void *)ext_header + EXT_HEADER_SIZE;
163         ext_sigcount = ext_header->count;
164
165         for (i = 0; i < ext_sigcount; i++) {
166                 fam_ucode   = __x86_family(ext_sig->sig);
167                 model_ucode = x86_model(ext_sig->sig);
168
169                 if (fam == fam_ucode && model == model_ucode)
170                         return UCODE_OK;
171
172                 ext_sig++;
173         }
174         return UCODE_NFOUND;
175 }
176
177 static int
178 save_microcode(struct mc_saved_data *mc_saved_data,
179                struct microcode_intel **mc_saved_src,
180                unsigned int mc_saved_count)
181 {
182         int i, j;
183         struct microcode_intel **saved_ptr;
184         int ret;
185
186         if (!mc_saved_count)
187                 return -EINVAL;
188
189         /*
190          * Copy new microcode data.
191          */
192         saved_ptr = kcalloc(mc_saved_count, sizeof(struct microcode_intel *), GFP_KERNEL);
193         if (!saved_ptr)
194                 return -ENOMEM;
195
196         for (i = 0; i < mc_saved_count; i++) {
197                 struct microcode_header_intel *mc_hdr;
198                 struct microcode_intel *mc;
199                 unsigned long size;
200
201                 if (!mc_saved_src[i]) {
202                         ret = -EINVAL;
203                         goto err;
204                 }
205
206                 mc     = mc_saved_src[i];
207                 mc_hdr = &mc->hdr;
208                 size   = get_totalsize(mc_hdr);
209
210                 saved_ptr[i] = kmalloc(size, GFP_KERNEL);
211                 if (!saved_ptr[i]) {
212                         ret = -ENOMEM;
213                         goto err;
214                 }
215
216                 memcpy(saved_ptr[i], mc, size);
217         }
218
219         /*
220          * Point to newly saved microcode.
221          */
222         mc_saved_data->mc_saved = saved_ptr;
223         mc_saved_data->mc_saved_count = mc_saved_count;
224
225         return 0;
226
227 err:
228         for (j = 0; j <= i; j++)
229                 kfree(saved_ptr[j]);
230         kfree(saved_ptr);
231
232         return ret;
233 }
234
235 /*
236  * A microcode patch in ucode_ptr is saved into mc_saved
237  * - if it has matching signature and newer revision compared to an existing
238  *   patch mc_saved.
239  * - or if it is a newly discovered microcode patch.
240  *
241  * The microcode patch should have matching model with CPU.
242  *
243  * Returns: The updated number @num_saved of saved microcode patches.
244  */
245 static unsigned int _save_mc(struct microcode_intel **mc_saved,
246                              u8 *ucode_ptr, unsigned int num_saved)
247 {
248         struct microcode_header_intel *mc_hdr, *mc_saved_hdr;
249         unsigned int sig, pf, new_rev;
250         int found = 0, i;
251
252         mc_hdr = (struct microcode_header_intel *)ucode_ptr;
253
254         for (i = 0; i < num_saved; i++) {
255                 mc_saved_hdr = (struct microcode_header_intel *)mc_saved[i];
256                 sig          = mc_saved_hdr->sig;
257                 pf           = mc_saved_hdr->pf;
258                 new_rev      = mc_hdr->rev;
259
260                 if (!get_matching_sig(sig, pf, new_rev, ucode_ptr))
261                         continue;
262
263                 found = 1;
264
265                 if (!revision_is_newer(mc_hdr, new_rev))
266                         continue;
267
268                 /*
269                  * Found an older ucode saved earlier. Replace it with
270                  * this newer one.
271                  */
272                 mc_saved[i] = (struct microcode_intel *)ucode_ptr;
273                 break;
274         }
275
276         /* Newly detected microcode, save it to memory. */
277         if (i >= num_saved && !found)
278                 mc_saved[num_saved++] = (struct microcode_intel *)ucode_ptr;
279
280         return num_saved;
281 }
282
283 /*
284  * Get microcode matching with BSP's model. Only CPUs with the same model as
285  * BSP can stay in the platform.
286  */
287 static enum ucode_state __init
288 get_matching_model_microcode(int cpu, unsigned long start,
289                              void *data, size_t size,
290                              struct mc_saved_data *mc_saved_data,
291                              unsigned long *mc_saved_in_initrd,
292                              struct ucode_cpu_info *uci)
293 {
294         u8 *ucode_ptr = data;
295         unsigned int leftover = size;
296         enum ucode_state state = UCODE_OK;
297         unsigned int mc_size;
298         struct microcode_header_intel *mc_header;
299         struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
300         unsigned int mc_saved_count = mc_saved_data->mc_saved_count;
301         int i;
302
303         while (leftover && mc_saved_count < ARRAY_SIZE(mc_saved_tmp)) {
304
305                 if (leftover < sizeof(mc_header))
306                         break;
307
308                 mc_header = (struct microcode_header_intel *)ucode_ptr;
309
310                 mc_size = get_totalsize(mc_header);
311                 if (!mc_size || mc_size > leftover ||
312                         microcode_sanity_check(ucode_ptr, 0) < 0)
313                         break;
314
315                 leftover -= mc_size;
316
317                 /*
318                  * Since APs with same family and model as the BSP may boot in
319                  * the platform, we need to find and save microcode patches
320                  * with the same family and model as the BSP.
321                  */
322                 if (matching_model_microcode(mc_header, uci->cpu_sig.sig) !=
323                          UCODE_OK) {
324                         ucode_ptr += mc_size;
325                         continue;
326                 }
327
328                 mc_saved_count = _save_mc(mc_saved_tmp, ucode_ptr, mc_saved_count);
329
330                 ucode_ptr += mc_size;
331         }
332
333         if (leftover) {
334                 state = UCODE_ERROR;
335                 goto out;
336         }
337
338         if (mc_saved_count == 0) {
339                 state = UCODE_NFOUND;
340                 goto out;
341         }
342
343         for (i = 0; i < mc_saved_count; i++)
344                 mc_saved_in_initrd[i] = (unsigned long)mc_saved_tmp[i] - start;
345
346         mc_saved_data->mc_saved_count = mc_saved_count;
347 out:
348         return state;
349 }
350
351 static int collect_cpu_info_early(struct ucode_cpu_info *uci)
352 {
353         unsigned int val[2];
354         unsigned int family, model;
355         struct cpu_signature csig;
356         unsigned int eax, ebx, ecx, edx;
357
358         csig.sig = 0;
359         csig.pf = 0;
360         csig.rev = 0;
361
362         memset(uci, 0, sizeof(*uci));
363
364         eax = 0x00000001;
365         ecx = 0;
366         native_cpuid(&eax, &ebx, &ecx, &edx);
367         csig.sig = eax;
368
369         family = __x86_family(csig.sig);
370         model  = x86_model(csig.sig);
371
372         if ((model >= 5) || (family > 6)) {
373                 /* get processor flags from MSR 0x17 */
374                 native_rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
375                 csig.pf = 1 << ((val[1] >> 18) & 7);
376         }
377         native_wrmsr(MSR_IA32_UCODE_REV, 0, 0);
378
379         /* As documented in the SDM: Do a CPUID 1 here */
380         sync_core();
381
382         /* get the current revision from MSR 0x8B */
383         native_rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
384
385         csig.rev = val[1];
386
387         uci->cpu_sig = csig;
388         uci->valid = 1;
389
390         return 0;
391 }
392
393 #ifdef DEBUG
394 static void __ref show_saved_mc(void)
395 {
396         int i, j;
397         unsigned int sig, pf, rev, total_size, data_size, date;
398         struct ucode_cpu_info uci;
399
400         if (mc_saved_data.mc_saved_count == 0) {
401                 pr_debug("no microcode data saved.\n");
402                 return;
403         }
404         pr_debug("Total microcode saved: %d\n", mc_saved_data.mc_saved_count);
405
406         collect_cpu_info_early(&uci);
407
408         sig = uci.cpu_sig.sig;
409         pf = uci.cpu_sig.pf;
410         rev = uci.cpu_sig.rev;
411         pr_debug("CPU: sig=0x%x, pf=0x%x, rev=0x%x\n", sig, pf, rev);
412
413         for (i = 0; i < mc_saved_data.mc_saved_count; i++) {
414                 struct microcode_header_intel *mc_saved_header;
415                 struct extended_sigtable *ext_header;
416                 int ext_sigcount;
417                 struct extended_signature *ext_sig;
418
419                 mc_saved_header = (struct microcode_header_intel *)
420                                   mc_saved_data.mc_saved[i];
421                 sig = mc_saved_header->sig;
422                 pf = mc_saved_header->pf;
423                 rev = mc_saved_header->rev;
424                 total_size = get_totalsize(mc_saved_header);
425                 data_size = get_datasize(mc_saved_header);
426                 date = mc_saved_header->date;
427
428                 pr_debug("mc_saved[%d]: sig=0x%x, pf=0x%x, rev=0x%x, toal size=0x%x, date = %04x-%02x-%02x\n",
429                          i, sig, pf, rev, total_size,
430                          date & 0xffff,
431                          date >> 24,
432                          (date >> 16) & 0xff);
433
434                 /* Look for ext. headers: */
435                 if (total_size <= data_size + MC_HEADER_SIZE)
436                         continue;
437
438                 ext_header = (void *) mc_saved_header + data_size + MC_HEADER_SIZE;
439                 ext_sigcount = ext_header->count;
440                 ext_sig = (void *)ext_header + EXT_HEADER_SIZE;
441
442                 for (j = 0; j < ext_sigcount; j++) {
443                         sig = ext_sig->sig;
444                         pf = ext_sig->pf;
445
446                         pr_debug("\tExtended[%d]: sig=0x%x, pf=0x%x\n",
447                                  j, sig, pf);
448
449                         ext_sig++;
450                 }
451
452         }
453 }
454 #else
455 static inline void show_saved_mc(void)
456 {
457 }
458 #endif
459
460 #if defined(CONFIG_MICROCODE_INTEL_EARLY) && defined(CONFIG_HOTPLUG_CPU)
461 static DEFINE_MUTEX(x86_cpu_microcode_mutex);
462 /*
463  * Save this mc into mc_saved_data. So it will be loaded early when a CPU is
464  * hot added or resumes.
465  *
466  * Please make sure this mc should be a valid microcode patch before calling
467  * this function.
468  */
469 int save_mc_for_early(u8 *mc)
470 {
471         struct microcode_intel *mc_saved_tmp[MAX_UCODE_COUNT];
472         unsigned int mc_saved_count_init;
473         unsigned int mc_saved_count;
474         struct microcode_intel **mc_saved;
475         int ret = 0;
476         int i;
477
478         /*
479          * Hold hotplug lock so mc_saved_data is not accessed by a CPU in
480          * hotplug.
481          */
482         mutex_lock(&x86_cpu_microcode_mutex);
483
484         mc_saved_count_init = mc_saved_data.mc_saved_count;
485         mc_saved_count = mc_saved_data.mc_saved_count;
486         mc_saved = mc_saved_data.mc_saved;
487
488         if (mc_saved && mc_saved_count)
489                 memcpy(mc_saved_tmp, mc_saved,
490                        mc_saved_count * sizeof(struct microcode_intel *));
491         /*
492          * Save the microcode patch mc in mc_save_tmp structure if it's a newer
493          * version.
494          */
495         mc_saved_count = _save_mc(mc_saved_tmp, mc, mc_saved_count);
496
497         /*
498          * Save the mc_save_tmp in global mc_saved_data.
499          */
500         ret = save_microcode(&mc_saved_data, mc_saved_tmp, mc_saved_count);
501         if (ret) {
502                 pr_err("Cannot save microcode patch.\n");
503                 goto out;
504         }
505
506         show_saved_mc();
507
508         /*
509          * Free old saved microcode data.
510          */
511         if (mc_saved) {
512                 for (i = 0; i < mc_saved_count_init; i++)
513                         kfree(mc_saved[i]);
514                 kfree(mc_saved);
515         }
516
517 out:
518         mutex_unlock(&x86_cpu_microcode_mutex);
519
520         return ret;
521 }
522 EXPORT_SYMBOL_GPL(save_mc_for_early);
523 #endif
524
525 static __initdata char ucode_name[] = "kernel/x86/microcode/GenuineIntel.bin";
526 static __init enum ucode_state
527 scan_microcode(struct mc_saved_data *mc_saved_data, unsigned long *initrd,
528                unsigned long start, unsigned long size,
529                struct ucode_cpu_info *uci)
530 {
531         struct cpio_data cd;
532         long offset = 0;
533 #ifdef CONFIG_X86_32
534         char *p = (char *)__pa_nodebug(ucode_name);
535 #else
536         char *p = ucode_name;
537 #endif
538
539         cd.data = NULL;
540         cd.size = 0;
541
542         cd = find_cpio_data(p, (void *)start, size, &offset);
543         if (!cd.data)
544                 return UCODE_ERROR;
545
546         return get_matching_model_microcode(0, start, cd.data, cd.size,
547                                             mc_saved_data, initrd, uci);
548 }
549
550 /*
551  * Print ucode update info.
552  */
553 static void
554 print_ucode_info(struct ucode_cpu_info *uci, unsigned int date)
555 {
556         int cpu = smp_processor_id();
557
558         pr_info("CPU%d microcode updated early to revision 0x%x, date = %04x-%02x-%02x\n",
559                 cpu,
560                 uci->cpu_sig.rev,
561                 date & 0xffff,
562                 date >> 24,
563                 (date >> 16) & 0xff);
564 }
565
566 #ifdef CONFIG_X86_32
567
568 static int delay_ucode_info;
569 static int current_mc_date;
570
571 /*
572  * Print early updated ucode info after printk works. This is delayed info dump.
573  */
574 void show_ucode_info_early(void)
575 {
576         struct ucode_cpu_info uci;
577
578         if (delay_ucode_info) {
579                 collect_cpu_info_early(&uci);
580                 print_ucode_info(&uci, current_mc_date);
581                 delay_ucode_info = 0;
582         }
583 }
584
585 /*
586  * At this point, we can not call printk() yet. Keep microcode patch number in
587  * mc_saved_data.mc_saved and delay printing microcode info in
588  * show_ucode_info_early() until printk() works.
589  */
590 static void print_ucode(struct ucode_cpu_info *uci)
591 {
592         struct microcode_intel *mc_intel;
593         int *delay_ucode_info_p;
594         int *current_mc_date_p;
595
596         mc_intel = uci->mc;
597         if (mc_intel == NULL)
598                 return;
599
600         delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
601         current_mc_date_p = (int *)__pa_nodebug(&current_mc_date);
602
603         *delay_ucode_info_p = 1;
604         *current_mc_date_p = mc_intel->hdr.date;
605 }
606 #else
607
608 /*
609  * Flush global tlb. We only do this in x86_64 where paging has been enabled
610  * already and PGE should be enabled as well.
611  */
612 static inline void flush_tlb_early(void)
613 {
614         __native_flush_tlb_global_irq_disabled();
615 }
616
617 static inline void print_ucode(struct ucode_cpu_info *uci)
618 {
619         struct microcode_intel *mc_intel;
620
621         mc_intel = uci->mc;
622         if (mc_intel == NULL)
623                 return;
624
625         print_ucode_info(uci, mc_intel->hdr.date);
626 }
627 #endif
628
629 static int apply_microcode_early(struct ucode_cpu_info *uci, bool early)
630 {
631         struct microcode_intel *mc_intel;
632         unsigned int val[2];
633
634         mc_intel = uci->mc;
635         if (mc_intel == NULL)
636                 return 0;
637
638         /* write microcode via MSR 0x79 */
639         native_wrmsr(MSR_IA32_UCODE_WRITE,
640               (unsigned long) mc_intel->bits,
641               (unsigned long) mc_intel->bits >> 16 >> 16);
642         native_wrmsr(MSR_IA32_UCODE_REV, 0, 0);
643
644         /* As documented in the SDM: Do a CPUID 1 here */
645         sync_core();
646
647         /* get the current revision from MSR 0x8B */
648         native_rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]);
649         if (val[1] != mc_intel->hdr.rev)
650                 return -1;
651
652 #ifdef CONFIG_X86_64
653         /* Flush global tlb. This is precaution. */
654         flush_tlb_early();
655 #endif
656         uci->cpu_sig.rev = val[1];
657
658         if (early)
659                 print_ucode(uci);
660         else
661                 print_ucode_info(uci, mc_intel->hdr.date);
662
663         return 0;
664 }
665
666 /*
667  * This function converts microcode patch offsets previously stored in
668  * mc_saved_in_initrd to pointers and stores the pointers in mc_saved_data.
669  */
670 int __init save_microcode_in_initrd_intel(void)
671 {
672         unsigned int count = mc_saved_data.mc_saved_count;
673         struct microcode_intel *mc_saved[MAX_UCODE_COUNT];
674         int ret = 0;
675
676         if (count == 0)
677                 return ret;
678
679         copy_initrd_ptrs(mc_saved, mc_saved_in_initrd, initrd_start, count);
680         ret = save_microcode(&mc_saved_data, mc_saved, count);
681         if (ret)
682                 pr_err("Cannot save microcode patches from initrd.\n");
683
684         show_saved_mc();
685
686         return ret;
687 }
688
689 static void __init
690 _load_ucode_intel_bsp(struct mc_saved_data *mc_saved_data,
691                       unsigned long *initrd,
692                       unsigned long start, unsigned long size)
693 {
694         struct ucode_cpu_info uci;
695         enum ucode_state ret;
696
697         collect_cpu_info_early(&uci);
698
699         ret = scan_microcode(mc_saved_data, initrd, start, size, &uci);
700         if (ret != UCODE_OK)
701                 return;
702
703         ret = load_microcode(mc_saved_data, initrd, start, &uci);
704         if (ret != UCODE_OK)
705                 return;
706
707         apply_microcode_early(&uci, true);
708 }
709
710 void __init load_ucode_intel_bsp(void)
711 {
712         u64 start, size;
713 #ifdef CONFIG_X86_32
714         struct boot_params *p;
715
716         p       = (struct boot_params *)__pa_nodebug(&boot_params);
717         start   = p->hdr.ramdisk_image;
718         size    = p->hdr.ramdisk_size;
719
720         _load_ucode_intel_bsp(
721                         (struct mc_saved_data *)__pa_nodebug(&mc_saved_data),
722                         (unsigned long *)__pa_nodebug(&mc_saved_in_initrd),
723                         start, size);
724 #else
725         start   = boot_params.hdr.ramdisk_image + PAGE_OFFSET;
726         size    = boot_params.hdr.ramdisk_size;
727
728         _load_ucode_intel_bsp(&mc_saved_data, mc_saved_in_initrd, start, size);
729 #endif
730 }
731
732 void load_ucode_intel_ap(void)
733 {
734         struct mc_saved_data *mc_saved_data_p;
735         struct ucode_cpu_info uci;
736         unsigned long *mc_saved_in_initrd_p;
737         unsigned long initrd_start_addr;
738         enum ucode_state ret;
739 #ifdef CONFIG_X86_32
740         unsigned long *initrd_start_p;
741
742         mc_saved_in_initrd_p =
743                 (unsigned long *)__pa_nodebug(mc_saved_in_initrd);
744         mc_saved_data_p = (struct mc_saved_data *)__pa_nodebug(&mc_saved_data);
745         initrd_start_p = (unsigned long *)__pa_nodebug(&initrd_start);
746         initrd_start_addr = (unsigned long)__pa_nodebug(*initrd_start_p);
747 #else
748         mc_saved_data_p = &mc_saved_data;
749         mc_saved_in_initrd_p = mc_saved_in_initrd;
750         initrd_start_addr = initrd_start;
751 #endif
752
753         /*
754          * If there is no valid ucode previously saved in memory, no need to
755          * update ucode on this AP.
756          */
757         if (mc_saved_data_p->mc_saved_count == 0)
758                 return;
759
760         collect_cpu_info_early(&uci);
761         ret = load_microcode(mc_saved_data_p, mc_saved_in_initrd_p,
762                              initrd_start_addr, &uci);
763
764         if (ret != UCODE_OK)
765                 return;
766
767         apply_microcode_early(&uci, true);
768 }
769
770 void reload_ucode_intel(void)
771 {
772         struct ucode_cpu_info uci;
773         enum ucode_state ret;
774
775         if (!mc_saved_data.mc_saved_count)
776                 return;
777
778         collect_cpu_info_early(&uci);
779
780         ret = load_microcode_early(mc_saved_data.mc_saved,
781                                    mc_saved_data.mc_saved_count, &uci);
782         if (ret != UCODE_OK)
783                 return;
784
785         apply_microcode_early(&uci, false);
786 }