2013-05-30 19:09:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Author: Jacob Shin <jacob.shin@amd.com>
|
2013-11-29 13:58:44 +00:00
|
|
|
* Fixes: Borislav Petkov <bp@suse.de>
|
2013-05-30 19:09:19 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/earlycpio.h>
|
2013-06-05 20:13:55 +00:00
|
|
|
#include <linux/initrd.h>
|
2013-05-30 19:09:19 +00:00
|
|
|
|
|
|
|
#include <asm/cpu.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/microcode_amd.h>
|
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
/*
|
|
|
|
* This points to the current valid container of microcode patches which we will
|
|
|
|
* save from the initrd before jettisoning its contents.
|
|
|
|
*/
|
|
|
|
static u8 *container;
|
|
|
|
static size_t container_size;
|
|
|
|
|
2013-05-30 19:09:19 +00:00
|
|
|
static u32 ucode_new_rev;
|
2013-11-29 13:58:44 +00:00
|
|
|
u8 amd_ucode_patch[PATCH_MAX_SIZE];
|
|
|
|
static u16 this_equiv_id;
|
|
|
|
|
2014-07-23 20:10:44 +00:00
|
|
|
static struct cpio_data ucode_cpio;
|
2013-05-30 19:09:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Microcode patch container file is prepended to the initrd in cpio format.
|
|
|
|
* See Documentation/x86/early-microcode.txt
|
|
|
|
*/
|
2013-06-05 20:13:55 +00:00
|
|
|
static __initdata char ucode_path[] = "kernel/x86/microcode/AuthenticAMD.bin";
|
2013-05-30 19:09:19 +00:00
|
|
|
|
2013-06-05 20:13:55 +00:00
|
|
|
static struct cpio_data __init find_ucode_in_initrd(void)
|
2013-05-30 19:09:19 +00:00
|
|
|
{
|
|
|
|
long offset = 0;
|
2013-06-05 20:13:55 +00:00
|
|
|
char *path;
|
|
|
|
void *start;
|
|
|
|
size_t size;
|
2013-05-30 19:09:19 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
2013-06-05 20:13:55 +00:00
|
|
|
struct boot_params *p;
|
|
|
|
|
2013-05-30 19:09:19 +00:00
|
|
|
/*
|
|
|
|
* On 32-bit, early load occurs before paging is turned on so we need
|
|
|
|
* to use physical addresses.
|
|
|
|
*/
|
2013-06-05 20:13:55 +00:00
|
|
|
p = (struct boot_params *)__pa_nodebug(&boot_params);
|
|
|
|
path = (char *)__pa_nodebug(ucode_path);
|
|
|
|
start = (void *)p->hdr.ramdisk_image;
|
|
|
|
size = p->hdr.ramdisk_size;
|
|
|
|
#else
|
|
|
|
path = ucode_path;
|
|
|
|
start = (void *)(boot_params.hdr.ramdisk_image + PAGE_OFFSET);
|
|
|
|
size = boot_params.hdr.ramdisk_size;
|
2013-05-30 19:09:19 +00:00
|
|
|
#endif
|
2013-06-05 20:13:55 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
return find_cpio_data(path, start, size, &offset);
|
|
|
|
}
|
2013-05-30 19:09:19 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
static size_t compute_container_size(u8 *data, u32 total_size)
|
|
|
|
{
|
|
|
|
size_t size = 0;
|
|
|
|
u32 *header = (u32 *)data;
|
2013-05-30 19:09:19 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
if (header[0] != UCODE_MAGIC ||
|
|
|
|
header[1] != UCODE_EQUIV_CPU_TABLE_TYPE || /* type */
|
|
|
|
header[2] == 0) /* size */
|
|
|
|
return size;
|
2013-06-05 20:13:55 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
size = header[2] + CONTAINER_HDR_SZ;
|
|
|
|
total_size -= size;
|
|
|
|
data += size;
|
|
|
|
|
|
|
|
while (total_size) {
|
|
|
|
u16 patch_size;
|
|
|
|
|
|
|
|
header = (u32 *)data;
|
|
|
|
|
|
|
|
if (header[0] != UCODE_UCODE_TYPE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity-check patch size.
|
|
|
|
*/
|
|
|
|
patch_size = header[1];
|
|
|
|
if (patch_size > PATCH_MAX_SIZE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
size += patch_size + SECTION_HDR_SIZE;
|
|
|
|
data += patch_size + SECTION_HDR_SIZE;
|
|
|
|
total_size -= patch_size + SECTION_HDR_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2013-05-30 19:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Early load occurs before we can vmalloc(). So we look for the microcode
|
|
|
|
* patch container file in initrd, traverse equivalent cpu table, look for a
|
|
|
|
* matching microcode patch, and update, all in initrd memory in place.
|
|
|
|
* When vmalloc() is available for use later -- on 64-bit during first AP load,
|
|
|
|
* and on 32-bit during save_microcode_in_initrd_amd() -- we can call
|
|
|
|
* load_microcode_amd() to save equivalent cpu table and microcode patches in
|
|
|
|
* kernel heap memory.
|
|
|
|
*/
|
2014-11-05 16:42:42 +00:00
|
|
|
static void apply_ucode_in_initrd(void *ucode, size_t size, bool save_patch)
|
2013-05-30 19:09:19 +00:00
|
|
|
{
|
|
|
|
struct equiv_cpu_entry *eq;
|
2013-11-29 13:58:44 +00:00
|
|
|
size_t *cont_sz;
|
2013-05-30 19:09:19 +00:00
|
|
|
u32 *header;
|
2013-11-29 13:58:44 +00:00
|
|
|
u8 *data, **cont;
|
2014-11-05 16:42:42 +00:00
|
|
|
u8 (*patch)[PATCH_MAX_SIZE];
|
2013-06-05 20:13:56 +00:00
|
|
|
u16 eq_id = 0;
|
2013-05-30 19:09:19 +00:00
|
|
|
int offset, left;
|
2013-11-29 13:58:44 +00:00
|
|
|
u32 rev, eax, ebx, ecx, edx;
|
2013-05-30 19:09:19 +00:00
|
|
|
u32 *new_rev;
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
new_rev = (u32 *)__pa_nodebug(&ucode_new_rev);
|
2013-11-29 13:58:44 +00:00
|
|
|
cont_sz = (size_t *)__pa_nodebug(&container_size);
|
|
|
|
cont = (u8 **)__pa_nodebug(&container);
|
2014-11-05 16:42:42 +00:00
|
|
|
patch = (u8 (*)[PATCH_MAX_SIZE])__pa_nodebug(&amd_ucode_patch);
|
2013-05-30 19:09:19 +00:00
|
|
|
#else
|
|
|
|
new_rev = &ucode_new_rev;
|
2013-11-29 13:58:44 +00:00
|
|
|
cont_sz = &container_size;
|
|
|
|
cont = &container;
|
2014-11-05 16:42:42 +00:00
|
|
|
patch = &amd_ucode_patch;
|
2013-05-30 19:09:19 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-05 20:13:55 +00:00
|
|
|
data = ucode;
|
|
|
|
left = size;
|
2013-05-30 19:09:19 +00:00
|
|
|
header = (u32 *)data;
|
|
|
|
|
|
|
|
/* find equiv cpu table */
|
2013-11-29 13:58:44 +00:00
|
|
|
if (header[0] != UCODE_MAGIC ||
|
|
|
|
header[1] != UCODE_EQUIV_CPU_TABLE_TYPE || /* type */
|
2013-05-30 19:09:19 +00:00
|
|
|
header[2] == 0) /* size */
|
|
|
|
return;
|
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
eax = 0x00000001;
|
|
|
|
ecx = 0;
|
|
|
|
native_cpuid(&eax, &ebx, &ecx, &edx);
|
2013-06-05 20:13:56 +00:00
|
|
|
|
|
|
|
while (left > 0) {
|
|
|
|
eq = (struct equiv_cpu_entry *)(data + CONTAINER_HDR_SZ);
|
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
*cont = data;
|
|
|
|
|
|
|
|
/* Advance past the container header */
|
2013-06-05 20:13:56 +00:00
|
|
|
offset = header[2] + CONTAINER_HDR_SZ;
|
|
|
|
data += offset;
|
|
|
|
left -= offset;
|
|
|
|
|
|
|
|
eq_id = find_equiv_id(eq, eax);
|
2013-11-29 13:58:44 +00:00
|
|
|
if (eq_id) {
|
|
|
|
this_equiv_id = eq_id;
|
|
|
|
*cont_sz = compute_container_size(*cont, left + offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* truncate how much we need to iterate over in the
|
|
|
|
* ucode update loop below
|
|
|
|
*/
|
|
|
|
left = *cont_sz - offset;
|
2013-06-05 20:13:56 +00:00
|
|
|
break;
|
2013-11-29 13:58:44 +00:00
|
|
|
}
|
2013-06-05 20:13:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* support multiple container files appended together. if this
|
|
|
|
* one does not have a matching equivalent cpu entry, we fast
|
|
|
|
* forward to the next container file.
|
|
|
|
*/
|
|
|
|
while (left > 0) {
|
|
|
|
header = (u32 *)data;
|
|
|
|
if (header[0] == UCODE_MAGIC &&
|
|
|
|
header[1] == UCODE_EQUIV_CPU_TABLE_TYPE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset = header[1] + SECTION_HDR_SIZE;
|
|
|
|
data += offset;
|
|
|
|
left -= offset;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:52:50 +00:00
|
|
|
/* mark where the next microcode container file starts */
|
|
|
|
offset = data - (u8 *)ucode;
|
|
|
|
ucode = data;
|
2013-06-05 20:13:56 +00:00
|
|
|
}
|
2013-05-30 19:09:19 +00:00
|
|
|
|
2013-06-20 14:52:50 +00:00
|
|
|
if (!eq_id) {
|
2013-11-29 13:58:44 +00:00
|
|
|
*cont = NULL;
|
|
|
|
*cont_sz = 0;
|
2013-05-30 19:09:19 +00:00
|
|
|
return;
|
2013-06-20 14:52:50 +00:00
|
|
|
}
|
2013-05-30 19:09:19 +00:00
|
|
|
|
|
|
|
/* find ucode and update if needed */
|
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, eax);
|
2013-05-30 19:09:19 +00:00
|
|
|
|
|
|
|
while (left > 0) {
|
|
|
|
struct microcode_amd *mc;
|
|
|
|
|
|
|
|
header = (u32 *)data;
|
|
|
|
if (header[0] != UCODE_UCODE_TYPE || /* type */
|
|
|
|
header[1] == 0) /* size */
|
|
|
|
break;
|
|
|
|
|
|
|
|
mc = (struct microcode_amd *)(data + SECTION_HDR_SIZE);
|
2013-11-29 13:58:44 +00:00
|
|
|
|
|
|
|
if (eq_id == mc->hdr.processor_rev_id && rev < mc->hdr.patch_id) {
|
|
|
|
|
|
|
|
if (!__apply_microcode_amd(mc)) {
|
2013-06-20 14:52:50 +00:00
|
|
|
rev = mc->hdr.patch_id;
|
|
|
|
*new_rev = rev;
|
2013-11-29 13:58:44 +00:00
|
|
|
|
2014-11-05 16:42:42 +00:00
|
|
|
if (save_patch)
|
|
|
|
memcpy(patch, mc,
|
|
|
|
min_t(u32, header[1], PATCH_MAX_SIZE));
|
2013-05-30 19:09:19 +00:00
|
|
|
}
|
2013-11-29 13:58:44 +00:00
|
|
|
}
|
2013-05-30 19:09:19 +00:00
|
|
|
|
|
|
|
offset = header[1] + SECTION_HDR_SIZE;
|
|
|
|
data += offset;
|
|
|
|
left -= offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init load_ucode_amd_bsp(void)
|
|
|
|
{
|
2013-11-29 13:58:44 +00:00
|
|
|
struct cpio_data cp;
|
|
|
|
void **data;
|
|
|
|
size_t *size;
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
data = (void **)__pa_nodebug(&ucode_cpio.data);
|
|
|
|
size = (size_t *)__pa_nodebug(&ucode_cpio.size);
|
|
|
|
#else
|
|
|
|
data = &ucode_cpio.data;
|
|
|
|
size = &ucode_cpio.size;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cp = find_ucode_in_initrd();
|
|
|
|
if (!cp.data)
|
2013-06-05 20:13:55 +00:00
|
|
|
return;
|
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
*data = cp.data;
|
|
|
|
*size = cp.size;
|
|
|
|
|
2014-11-05 16:42:42 +00:00
|
|
|
apply_ucode_in_initrd(cp.data, cp.size, true);
|
2013-05-30 19:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
/*
|
|
|
|
* On 32-bit, since AP's early load occurs before paging is turned on, we
|
|
|
|
* cannot traverse cpu_equiv_table and pcache in kernel heap memory. So during
|
|
|
|
* cold boot, AP will apply_ucode_in_initrd() just like the BSP. During
|
2013-11-29 13:58:44 +00:00
|
|
|
* save_microcode_in_initrd_amd() BSP's patch is copied to amd_ucode_patch,
|
|
|
|
* which is used upon resume from suspend.
|
2013-05-30 19:09:19 +00:00
|
|
|
*/
|
x86: delete __cpuinit usage from all x86 files
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
are flagged as __cpuinit -- so if we remove the __cpuinit from
arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
content into no-ops as early as possible, since that will get rid
of these warnings. In any case, they are temporary and harmless.
This removes all the arch/x86 uses of the __cpuinit macros from
all C files. x86 only had the one __CPUINIT used in assembly files,
and it wasn't paired off with a .previous or a __FINIT, so we can
delete it directly w/o any corresponding additional change there.
[1] https://lkml.org/lkml/2013/5/20/589
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2013-06-18 22:23:59 +00:00
|
|
|
void load_ucode_amd_ap(void)
|
2013-05-30 19:09:19 +00:00
|
|
|
{
|
|
|
|
struct microcode_amd *mc;
|
2013-06-05 20:13:55 +00:00
|
|
|
size_t *usize;
|
2013-11-29 13:58:44 +00:00
|
|
|
void **ucode;
|
2013-05-30 19:09:19 +00:00
|
|
|
|
2014-11-05 16:42:42 +00:00
|
|
|
mc = (struct microcode_amd *)__pa_nodebug(amd_ucode_patch);
|
2013-06-05 20:13:55 +00:00
|
|
|
if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
|
2013-05-30 19:09:19 +00:00
|
|
|
__apply_microcode_amd(mc);
|
2013-06-05 20:13:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
ucode = (void *)__pa_nodebug(&container);
|
|
|
|
usize = (size_t *)__pa_nodebug(&container_size);
|
2013-06-20 14:52:50 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
if (!*ucode || !*usize)
|
2013-06-05 20:13:55 +00:00
|
|
|
return;
|
|
|
|
|
2014-11-05 16:42:42 +00:00
|
|
|
apply_ucode_in_initrd(*ucode, *usize, false);
|
2013-05-30 19:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __init collect_cpu_sig_on_bsp(void *arg)
|
|
|
|
{
|
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
|
2013-11-29 13:58:44 +00:00
|
|
|
|
2013-05-30 19:09:19 +00:00
|
|
|
uci->cpu_sig.sig = cpuid_eax(0x00000001);
|
|
|
|
}
|
2014-02-03 20:41:44 +00:00
|
|
|
|
|
|
|
static void __init get_bsp_sig(void)
|
|
|
|
{
|
|
|
|
unsigned int bsp = boot_cpu_data.cpu_index;
|
|
|
|
struct ucode_cpu_info *uci = ucode_cpu_info + bsp;
|
|
|
|
|
|
|
|
if (!uci->cpu_sig.sig)
|
|
|
|
smp_call_function_single(bsp, collect_cpu_sig_on_bsp, NULL, 1);
|
|
|
|
}
|
2013-05-30 19:09:19 +00:00
|
|
|
#else
|
2013-08-08 17:38:18 +00:00
|
|
|
void load_ucode_amd_ap(void)
|
2013-05-30 19:09:19 +00:00
|
|
|
{
|
2013-08-08 17:38:18 +00:00
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
|
2013-11-29 13:58:44 +00:00
|
|
|
struct equiv_cpu_entry *eq;
|
|
|
|
struct microcode_amd *mc;
|
2013-05-30 19:09:19 +00:00
|
|
|
u32 rev, eax;
|
2013-11-29 13:58:44 +00:00
|
|
|
u16 eq_id;
|
|
|
|
|
|
|
|
/* Exit if called on the BSP. */
|
|
|
|
if (!cpu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!container)
|
|
|
|
return;
|
2013-05-30 19:09:19 +00:00
|
|
|
|
|
|
|
rdmsr(MSR_AMD64_PATCH_LEVEL, rev, eax);
|
|
|
|
|
|
|
|
uci->cpu_sig.rev = rev;
|
2013-08-08 17:38:18 +00:00
|
|
|
uci->cpu_sig.sig = eax;
|
2013-05-30 19:09:19 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
eax = cpuid_eax(0x00000001);
|
|
|
|
eq = (struct equiv_cpu_entry *)(container + CONTAINER_HDR_SZ);
|
2013-06-05 20:13:55 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
eq_id = find_equiv_id(eq, eax);
|
|
|
|
if (!eq_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (eq_id == this_equiv_id) {
|
|
|
|
mc = (struct microcode_amd *)amd_ucode_patch;
|
2013-06-05 20:13:55 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
if (mc && rev < mc->hdr.patch_id) {
|
|
|
|
if (!__apply_microcode_amd(mc))
|
|
|
|
ucode_new_rev = mc->hdr.patch_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!ucode_cpio.data)
|
2013-05-30 19:09:19 +00:00
|
|
|
return;
|
2013-08-08 17:38:18 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
/*
|
|
|
|
* AP has a different equivalence ID than BSP, looks like
|
|
|
|
* mixed-steppings silicon so go through the ucode blob anew.
|
|
|
|
*/
|
2014-11-05 16:42:42 +00:00
|
|
|
apply_ucode_in_initrd(ucode_cpio.data, ucode_cpio.size, false);
|
2013-05-30 19:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int __init save_microcode_in_initrd_amd(void)
|
|
|
|
{
|
2014-02-03 20:41:44 +00:00
|
|
|
unsigned long cont;
|
2014-11-05 16:42:42 +00:00
|
|
|
int retval = 0;
|
2013-05-30 19:09:19 +00:00
|
|
|
enum ucode_state ret;
|
2014-10-31 22:23:43 +00:00
|
|
|
u8 *cont_va;
|
2013-08-08 17:38:18 +00:00
|
|
|
u32 eax;
|
|
|
|
|
2014-02-03 20:41:44 +00:00
|
|
|
if (!container)
|
|
|
|
return -EINVAL;
|
2013-11-29 13:58:44 +00:00
|
|
|
|
2014-02-03 20:41:44 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
get_bsp_sig();
|
2014-10-31 22:23:43 +00:00
|
|
|
cont = (unsigned long)container;
|
|
|
|
cont_va = __va(container);
|
2014-02-03 20:41:44 +00:00
|
|
|
#else
|
2013-11-29 13:58:44 +00:00
|
|
|
/*
|
2014-02-03 20:41:44 +00:00
|
|
|
* We need the physical address of the container for both bitness since
|
|
|
|
* boot_params.hdr.ramdisk_image is a physical address.
|
2013-11-29 13:58:44 +00:00
|
|
|
*/
|
2014-10-31 22:23:43 +00:00
|
|
|
cont = __pa(container);
|
|
|
|
cont_va = container;
|
2013-05-30 19:09:19 +00:00
|
|
|
#endif
|
2014-02-03 20:41:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Take into account the fact that the ramdisk might get relocated and
|
|
|
|
* therefore we need to recompute the container's position in virtual
|
|
|
|
* memory space.
|
|
|
|
*/
|
|
|
|
if (relocated_ramdisk)
|
|
|
|
container = (u8 *)(__va(relocated_ramdisk) +
|
|
|
|
(cont - boot_params.hdr.ramdisk_image));
|
2014-10-31 22:23:43 +00:00
|
|
|
else
|
|
|
|
container = cont_va;
|
2014-02-03 20:41:44 +00:00
|
|
|
|
2013-05-30 19:09:19 +00:00
|
|
|
if (ucode_new_rev)
|
|
|
|
pr_info("microcode: updated early to new patch_level=0x%08x\n",
|
|
|
|
ucode_new_rev);
|
|
|
|
|
2013-08-08 17:38:18 +00:00
|
|
|
eax = cpuid_eax(0x00000001);
|
|
|
|
eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff);
|
|
|
|
|
2014-12-01 10:12:21 +00:00
|
|
|
ret = load_microcode_amd(smp_processor_id(), eax, container, container_size);
|
2013-05-30 19:09:19 +00:00
|
|
|
if (ret != UCODE_OK)
|
2014-11-05 16:42:42 +00:00
|
|
|
retval = -EINVAL;
|
2013-05-30 19:09:19 +00:00
|
|
|
|
2013-11-29 13:58:44 +00:00
|
|
|
/*
|
|
|
|
* This will be freed any msec now, stash patches for the current
|
|
|
|
* family and switch to patch cache for cpu hotplug, etc later.
|
|
|
|
*/
|
|
|
|
container = NULL;
|
|
|
|
container_size = 0;
|
|
|
|
|
2014-11-05 16:42:42 +00:00
|
|
|
return retval;
|
2013-05-30 19:09:19 +00:00
|
|
|
}
|
2014-12-03 16:21:41 +00:00
|
|
|
|
|
|
|
void reload_ucode_amd(void)
|
|
|
|
{
|
|
|
|
struct microcode_amd *mc;
|
|
|
|
u32 rev, eax;
|
|
|
|
|
|
|
|
rdmsr(MSR_AMD64_PATCH_LEVEL, rev, eax);
|
|
|
|
|
|
|
|
mc = (struct microcode_amd *)amd_ucode_patch;
|
|
|
|
|
|
|
|
if (mc && rev < mc->hdr.patch_id) {
|
|
|
|
if (!__apply_microcode_amd(mc)) {
|
|
|
|
ucode_new_rev = mc->hdr.patch_id;
|
|
|
|
pr_info("microcode: reload patch_level=0x%08x\n",
|
|
|
|
ucode_new_rev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|