Alexandru Gagniuc (mr.nuke.me@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4502
-gerrit
commit 81a1a97e0240b01ebb8baa83a30f93be2d5391c7 Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Sun Dec 8 07:21:05 2013 +0200
cpu/amd (non-AGESA): Load microcode updates from CBFS
Change-Id: Ic67856414ea2fea9a9eb95d72136cb05da9483fa Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com Signed-off-by: Alexandru Gagniuc mr.nuke.me@gmail.com --- src/cpu/amd/microcode/microcode.c | 70 ++++++++++----- src/cpu/amd/microcode/microcode.h | 8 ++ src/cpu/amd/model_10xxx/Makefile.inc | 2 + src/cpu/amd/model_10xxx/microcode_blob.c | 28 ++++++ src/cpu/amd/model_10xxx/update_microcode.c | 27 +----- src/cpu/amd/model_fxx/Makefile.inc | 2 + src/cpu/amd/model_fxx/microcode_blob.c | 34 +++++++ src/cpu/amd/model_fxx/model_fxx_init.c | 2 +- src/cpu/amd/model_fxx/model_fxx_update_microcode.c | 100 +++++++-------------- src/include/cpu/amd/microcode.h | 9 -- 10 files changed, 158 insertions(+), 124 deletions(-)
diff --git a/src/cpu/amd/microcode/microcode.c b/src/cpu/amd/microcode/microcode.c index cdc6e4a..9bad5e2 100644 --- a/src/cpu/amd/microcode/microcode.c +++ b/src/cpu/amd/microcode/microcode.c @@ -21,6 +21,10 @@ #include <console/console.h> #include <cpu/x86/msr.h> #include <cpu/amd/microcode.h> +#include <cbfs.h> + +#define UCODE_DEBUG(fmt, args...) \ + do { printk(BIOS_DEBUG, "[microcode] "fmt, ##args); } while(0)
struct microcode { u32 date_code; @@ -51,40 +55,62 @@ struct microcode { u8 x86_code_entry[191]; };
-void amd_update_microcode(void *microcode_updates, u32 equivalent_processor_rev_id) +static void apply_microcode_patch(struct microcode *m) { - u32 patch_id, new_patch_id; - struct microcode *m; - char *c; + uint32_t new_patch_id; msr_t msr;
- msr = rdmsr(0x8b); - patch_id = msr.lo; - - printk(BIOS_DEBUG, "microcode: equivalent rev id = 0x%04x, current patch id = 0x%08x\n", equivalent_processor_rev_id, patch_id); - - m = microcode_updates; - - for(c = microcode_updates; m->date_code; m = (struct microcode *)c) { + /* apply patch */ + msr.hi = 0; + msr.lo = (uint32_t)m;
- if (m->processor_rev_id == equivalent_processor_rev_id) { - //apply patch + wrmsr(0xc0010020, msr);
- msr.hi = 0; - msr.lo = (u32)m; + UCODE_DEBUG("patch id to apply = 0x%08x\n", m->patch_id);
- wrmsr(0xc0010020, msr); + /* read the patch_id again */ + msr = rdmsr(0x8b); + new_patch_id = msr.lo;
- printk(BIOS_DEBUG, "microcode: patch id to apply = 0x%08x\n", m->patch_id); + UCODE_DEBUG("updated to patch id = 0x%08x %s\n", new_patch_id , + (new_patch_id == m->patch_id) ? "success" : "fail"); +}
- //read the patch_id again - msr = rdmsr(0x8b); - new_patch_id = msr.lo; +static void amd_update_microcode(const void *ucode, size_t ucode_len, + uint32_t equivalent_processor_rev_id) +{ + uint32_t new_patch_id; + const struct microcode *m; + uint8_t *c; + msr_t msr;
- printk(BIOS_DEBUG, "microcode: updated to patch id = 0x%08x %s\n", new_patch_id , (new_patch_id == m->patch_id)?" success\n":" fail\n" ); + for(c = ucode; m->date_code; m = (struct microcode *)c) { + if (m->processor_rev_id == equivalent_processor_rev_id) { + apply_microcode_patch(m); break; } c += 2048; } +} + +#define MICROCODE_CBFS_FILE "cpu_microcode_blob.bin" + +void amd_update_microcode_from_cbfs(u32 equivalent_processor_rev_id) +{ + const void *ucode; + size_t ucode_len; + + if (equivalent_processor_rev_id == 0) { + UCODE_DEBUG("rev id not found. Skipping microcode patch!\n"); + return; + } + + ucode = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, MICROCODE_CBFS_FILE, + CBFS_TYPE_MICROCODE, &ucode_len); + if (!ucode) { + UCODE_DEBUG("microcode file not found. Skipping updates.\n"); + return; + }
+ amd_update_microcode(ucode, ucode_len, equivalent_processor_rev_id); } diff --git a/src/cpu/amd/microcode/microcode.h b/src/cpu/amd/microcode/microcode.h new file mode 100644 index 0000000..5ac04e9 --- /dev/null +++ b/src/cpu/amd/microcode/microcode.h @@ -0,0 +1,8 @@ +#ifndef CPU_AMD_MICROCODE_H +#define CPU_AMD_MICROCODE_H + +void update_microcode(u32 cpu_deviceid); +void amd_update_microcode_from_cbfs(u32 equivalent_processor_rev_id); + +#endif /* CPU_AMD_MICROCODE_H */ + diff --git a/src/cpu/amd/model_10xxx/Makefile.inc b/src/cpu/amd/model_10xxx/Makefile.inc index 2f04762..f5cf375 100644 --- a/src/cpu/amd/model_10xxx/Makefile.inc +++ b/src/cpu/amd/model_10xxx/Makefile.inc @@ -4,3 +4,5 @@ ramstage-y += processor_name.c
romstage-y += update_microcode.c ramstage-$(CONFIG_HAVE_ACPI_TABLES) += powernow_acpi.c + +cpu_microcode-$(CONFIG_CPU_MICROCODE_CBFS_GENERATE) += microcode_blob.c diff --git a/src/cpu/amd/model_10xxx/microcode_blob.c b/src/cpu/amd/model_10xxx/microcode_blob.c new file mode 100644 index 0000000..c697cea --- /dev/null +++ b/src/cpu/amd/model_10xxx/microcode_blob.c @@ -0,0 +1,28 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2007 Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +unsigned char microcode[] __attribute__ ((aligned(16))) = { +#include CONFIG_AMD_UCODE_PATCH_FILE + + /* Dummy terminator */ + 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, +}; diff --git a/src/cpu/amd/model_10xxx/update_microcode.c b/src/cpu/amd/model_10xxx/update_microcode.c index 3cdf978..8dcd90d 100644 --- a/src/cpu/amd/model_10xxx/update_microcode.c +++ b/src/cpu/amd/model_10xxx/update_microcode.c @@ -19,13 +19,8 @@ */
#include <stdint.h> -#include <console/console.h> #include <cpu/amd/microcode.h>
-static const u8 microcode_updates[] __attribute__ ((aligned(16))) = { - -#ifdef __PRE_RAM__ - /* From the Revision Guide : * Equivalent Processor Table for AMD Family 10h Processors * @@ -47,16 +42,6 @@ static const u8 microcode_updates[] __attribute__ ((aligned(16))) = { * 00100FA0h (PH-E0) 10A0h 010000bfh */
-#include CONFIG_AMD_UCODE_PATCH_FILE - -#endif - /* Dummy terminator */ - 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, -}; - struct id_mapping { uint32_t orig_id; uint16_t new_id; @@ -101,14 +86,6 @@ static u16 get_equivalent_processor_rev_id(u32 orig_id) {
void update_microcode(u32 cpu_deviceid) { - u32 equivalent_processor_rev_id; - - /* Update the microcode */ - equivalent_processor_rev_id = get_equivalent_processor_rev_id(cpu_deviceid ); - if (equivalent_processor_rev_id != 0) { - amd_update_microcode((void *) microcode_updates, equivalent_processor_rev_id); - } else { - printk(BIOS_DEBUG, "microcode: rev id not found. Skipping microcode patch!\n"); - } - + u32 equivalent_processor_rev_id = get_equivalent_processor_rev_id(cpu_deviceid); + amd_update_microcode_from_cbfs(equivalent_processor_rev_id); } diff --git a/src/cpu/amd/model_fxx/Makefile.inc b/src/cpu/amd/model_fxx/Makefile.inc index cf4ac21..19a6255 100644 --- a/src/cpu/amd/model_fxx/Makefile.inc +++ b/src/cpu/amd/model_fxx/Makefile.inc @@ -5,3 +5,5 @@ ramstage-y += model_fxx_init.c ramstage-y += model_fxx_update_microcode.c ramstage-y += processor_name.c ramstage-$(CONFIG_HAVE_ACPI_TABLES) += powernow_acpi.c + +cpu_microcode-$(CONFIG_CPU_MICROCODE_CBFS_GENERATE) += microcode_blob.c diff --git a/src/cpu/amd/model_fxx/microcode_blob.c b/src/cpu/amd/model_fxx/microcode_blob.c new file mode 100644 index 0000000..3210f62 --- /dev/null +++ b/src/cpu/amd/model_fxx/microcode_blob.c @@ -0,0 +1,34 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2005 Advanced Micro Devices, Inc. + * Copyright (C) 2010 Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +unsigned char microcode[] __attribute__ ((aligned(16))) = { +#if !CONFIG_K8_REV_F_SUPPORT + #include "microcode_rev_c.h" + #include "microcode_rev_d.h" + #include "microcode_rev_e.h" +#endif + + /* Dummy terminator */ + 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, +}; diff --git a/src/cpu/amd/model_fxx/model_fxx_init.c b/src/cpu/amd/model_fxx/model_fxx_init.c index 260e83e..33226d4 100644 --- a/src/cpu/amd/model_fxx/model_fxx_init.c +++ b/src/cpu/amd/model_fxx/model_fxx_init.c @@ -468,7 +468,7 @@ static void model_fxx_init(device_t dev) x86_mtrr_check();
/* Update the microcode */ - model_fxx_update_microcode(dev->device); + update_microcode(dev->device);
disable_cache();
diff --git a/src/cpu/amd/model_fxx/model_fxx_update_microcode.c b/src/cpu/amd/model_fxx/model_fxx_update_microcode.c index af10ce0..213294c 100644 --- a/src/cpu/amd/model_fxx/model_fxx_update_microcode.c +++ b/src/cpu/amd/model_fxx/model_fxx_update_microcode.c @@ -20,74 +20,44 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
-#include <console/console.h> +#include <stdint.h> +#include <stdlib.h> #include <cpu/amd/microcode.h>
-static uint8_t microcode_updates[] __attribute__ ((aligned(16))) = { - +static const u32 id_mapping_table[] = { #if !CONFIG_K8_REV_F_SUPPORT - #include "microcode_rev_c.h" - #include "microcode_rev_d.h" - #include "microcode_rev_e.h" -#endif - -#if CONFIG_K8_REV_F_SUPPORT -// #include "microcode_rev_f.h" + 0x0f48, 0x0048, + 0x0f58, 0x0048, + + 0x0f4a, 0x004a, + 0x0f5a, 0x004a, + 0x0f7a, 0x004a, + 0x0f82, 0x004a, + 0x0fc0, 0x004a, + 0x0ff0, 0x004a, + + 0x10f50, 0x0150, + 0x10f70, 0x0150, + 0x10f80, 0x0150, + 0x10fc0, 0x0150, + 0x10ff0, 0x0150, + + 0x20f10, 0x0210, + 0x20f12, 0x0210, + 0x20f32, 0x0210, + 0x20fb1, 0x0210, #endif - /* Dummy terminator */ - 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, -}; - -struct id_mapping { - uint32_t orig_id; - uint16_t new_id; }; +#define ID_MAPPING_TABLE_LEN ARRAY_SIZE(id_mapping_table)
-static u16 get_equivalent_processor_rev_id(u32 orig_id) { - static const struct id_mapping id_mapping_table[] = { - #if !CONFIG_K8_REV_F_SUPPORT - { 0x0f48, 0x0048 }, - { 0x0f58, 0x0048 }, - - { 0x0f4a, 0x004a }, - { 0x0f5a, 0x004a }, - { 0x0f7a, 0x004a }, - { 0x0f82, 0x004a }, - { 0x0fc0, 0x004a }, - { 0x0ff0, 0x004a }, - - { 0x10f50, 0x0150 }, - { 0x10f70, 0x0150 }, - { 0x10f80, 0x0150 }, - { 0x10fc0, 0x0150 }, - { 0x10ff0, 0x0150 }, - - { 0x20f10, 0x0210 }, - { 0x20f12, 0x0210 }, - { 0x20f32, 0x0210 }, - { 0x20fb1, 0x0210 }, - #endif - - #if CONFIG_K8_REV_F_SUPPORT - /* FIXME */ - #endif - - /* Array terminator */ - { 0xffffff, 0x0000 }, - - }; - - unsigned new_id; +static unsigned get_equivalent_processor_rev_id(unsigned orig_id) +{ + unsigned new_id = 0; int i;
- new_id = 0; - - for (i = 0; id_mapping_table[i].orig_id != 0xffffff; i++ ) { - if (id_mapping_table[i].orig_id == orig_id) { - new_id = id_mapping_table[i].new_id; + for (i = 0; i < ID_MAPPING_TABLE_LEN; i += 2) { + if (id_mapping_table[i]==orig_id) { + new_id = id_mapping_table[i + 1]; break; } } @@ -95,12 +65,8 @@ static u16 get_equivalent_processor_rev_id(u32 orig_id) { return new_id; }
-void model_fxx_update_microcode(unsigned cpu_deviceid) +void update_microcode(u32 cpu_deviceid) { - unsigned equivalent_processor_rev_id; - - /* Update the microcode */ - equivalent_processor_rev_id = get_equivalent_processor_rev_id(cpu_deviceid ); - if(equivalent_processor_rev_id != 0) - amd_update_microcode(microcode_updates, equivalent_processor_rev_id); + u32 equivalent_processor_rev_id = get_equivalent_processor_rev_id(cpu_deviceid); + amd_update_microcode_from_cbfs(equivalent_processor_rev_id); } diff --git a/src/include/cpu/amd/microcode.h b/src/include/cpu/amd/microcode.h deleted file mode 100644 index 3485b6f..0000000 --- a/src/include/cpu/amd/microcode.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef CPU_AMD_MICROCODE_H -#define CPU_AMD_MICROCODE_H - -void amd_update_microcode(void *microcode_updates, unsigned processor_rev_id); -void model_fxx_update_microcode(unsigned cpu_deviceid); -void update_microcode(u32 processor_rev_id); - -#endif /* CPU_AMD_MICROCODE_H */ -