From 394c6b092251f0da8f0bd159e0eb08a41a6e4afc Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Fri, 12 Feb 2021 14:37:43 -0700 Subject: soc/amd: Move update_microcode.c to common/block/cpu We also want to support uCode loading on cezanne. Signed-off-by: Raul E Rangel Change-Id: I6f10564c93ce72aea7ff52a8565d65d8b56452f3 Reviewed-on: https://review.coreboot.org/c/coreboot/+/50615 Tested-by: build bot (Jenkins) Reviewed-by: Felix Held --- src/soc/amd/common/block/cpu/Kconfig | 13 ++++ src/soc/amd/common/block/cpu/Makefile.inc | 1 + src/soc/amd/common/block/cpu/update_microcode.c | 93 +++++++++++++++++++++++++ src/soc/amd/picasso/Kconfig | 5 +- src/soc/amd/picasso/Makefile.inc | 1 - src/soc/amd/picasso/update_microcode.c | 90 ------------------------ 6 files changed, 111 insertions(+), 92 deletions(-) create mode 100644 src/soc/amd/common/block/cpu/update_microcode.c delete mode 100644 src/soc/amd/picasso/update_microcode.c diff --git a/src/soc/amd/common/block/cpu/Kconfig b/src/soc/amd/common/block/cpu/Kconfig index 996605e7f3..f418ee7cc5 100644 --- a/src/soc/amd/common/block/cpu/Kconfig +++ b/src/soc/amd/common/block/cpu/Kconfig @@ -44,3 +44,16 @@ config SOC_AMD_COMMON_BLOCK_TSC_FAM17H_19H Select this option to add the common functions for getting the TSC frequency of AMD family 17h and 19h CPUs/APUs and to provide TSC- based monotonic timer functionality to the build. + +config SOC_AMD_COMMON_BLOCK_UCODE + bool + select SUPPORT_CPU_UCODE_IN_CBFS + default n + help + Builds in support for loading uCode. + +config SOC_AMD_COMMON_BLOCK_UCODE_SIZE + int + depends on SOC_AMD_COMMON_BLOCK_UCODE + help + Defines the size of the uCode binary in bytes. diff --git a/src/soc/amd/common/block/cpu/Makefile.inc b/src/soc/amd/common/block/cpu/Makefile.inc index 4c0266396c..f402e703c9 100644 --- a/src/soc/amd/common/block/cpu/Makefile.inc +++ b/src/soc/amd/common/block/cpu/Makefile.inc @@ -1 +1,2 @@ subdirs-y += ./* +ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE) += update_microcode.c diff --git a/src/soc/amd/common/block/cpu/update_microcode.c b/src/soc/amd/common/block/cpu/update_microcode.c new file mode 100644 index 0000000000..2ba180298c --- /dev/null +++ b/src/soc/amd/common/block/cpu/update_microcode.c @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include +#include +#include +#include + +_Static_assert(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE_SIZE > 0, + "SOC_AMD_COMMON_BLOCK_UCODE_SIZE is not set"); + +#define MPB_MAX_SIZE CONFIG_SOC_AMD_COMMON_BLOCK_UCODE_SIZE +#define MPB_DATA_OFFSET 32 + +struct microcode { + uint32_t date_code; + uint32_t patch_id; + + uint16_t mc_patch_data_id; + uint8_t reserved1[6]; + + uint32_t chipset1_dev_id; + uint32_t chipset2_dev_id; + + uint16_t processor_rev_id; + + uint8_t chipset1_rev_id; + uint8_t chipset2_rev_id; + + uint8_t reserved2[4]; + + uint8_t m_patch_data[MPB_MAX_SIZE-MPB_DATA_OFFSET]; +} __packed; + +static void apply_microcode_patch(const struct microcode *m) +{ + uint32_t new_patch_id; + msr_t msr; + + msr.hi = (uint64_t)(uintptr_t)m >> 32; + msr.lo = (uintptr_t)m & 0xffffffff; + + wrmsr(MSR_PATCH_LOADER, msr); + + printk(BIOS_DEBUG, "microcode: patch id to apply = 0x%08x\n", + m->patch_id); + + msr = rdmsr(MSR_PATCH_LEVEL); + new_patch_id = msr.lo; + + if (new_patch_id == m->patch_id) + printk(BIOS_INFO, "microcode: being updated to patch id = 0x%08x succeeded\n", + new_patch_id); + else + printk(BIOS_ERR, "microcode: being updated to patch id = 0x%08x failed\n", + new_patch_id); +} + +static uint16_t get_equivalent_processor_rev_id(void) +{ + uint32_t cpuid_family = cpuid_eax(1); + + return (uint16_t)((cpuid_family & 0xff0000) >> 8 | (cpuid_family & 0xff)); +} + +static void amd_update_microcode(const void *ucode, size_t ucode_len, + uint16_t equivalent_processor_rev_id) +{ + const struct microcode *m; + + for (m = (struct microcode *)ucode; + m < (struct microcode *)ucode + ucode_len/MPB_MAX_SIZE; m++) { + if (m->processor_rev_id == equivalent_processor_rev_id) + apply_microcode_patch(m); + } +} + +void amd_update_microcode_from_cbfs(void) +{ + const void *ucode; + size_t ucode_len; + uint16_t equivalent_processor_rev_id = get_equivalent_processor_rev_id(); + + ucode = cbfs_map("cpu_microcode_blob.bin", &ucode_len); + if (!ucode) { + printk(BIOS_WARNING, "cpu_microcode_blob.bin not found. Skipping updates.\n"); + return; + } + + amd_update_microcode(ucode, ucode_len, equivalent_processor_rev_id); +} diff --git a/src/soc/amd/picasso/Kconfig b/src/soc/amd/picasso/Kconfig index d037d48990..16a12972b4 100644 --- a/src/soc/amd/picasso/Kconfig +++ b/src/soc/amd/picasso/Kconfig @@ -46,6 +46,7 @@ config CPU_SPECIFIC_OPTIONS select SOC_AMD_COMMON_BLOCK_SPI select SOC_AMD_COMMON_BLOCK_TSC_FAM17H_19H select SOC_AMD_COMMON_BLOCK_UART + select SOC_AMD_COMMON_BLOCK_UCODE select PROVIDES_ROM_SHARING select BOOT_DEVICE_SUPPORTS_WRITES if BOOT_DEVICE_SPI_FLASH select PARALLEL_MP @@ -58,7 +59,9 @@ config CPU_SPECIFIC_OPTIONS select FSP_COMPRESS_FSP_S_LZMA select UDK_2017_BINDING select HAVE_CF9_RESET - select SUPPORT_CPU_UCODE_IN_CBFS + +config SOC_AMD_COMMON_BLOCK_UCODE_SIZE + default 3200 config FSP_M_FILE string "FSP-M (memory init) binary path and filename" diff --git a/src/soc/amd/picasso/Makefile.inc b/src/soc/amd/picasso/Makefile.inc index 99e2da1040..d2a5e4c393 100644 --- a/src/soc/amd/picasso/Makefile.inc +++ b/src/soc/amd/picasso/Makefile.inc @@ -48,7 +48,6 @@ ramstage-y += uart.c ramstage-y += finalize.c ramstage-y += soc_util.c ramstage-y += fsp_params.c -ramstage-y += update_microcode.c ramstage-y += graphics.c ramstage-y += pcie_gpp.c ramstage-y += xhci.c diff --git a/src/soc/amd/picasso/update_microcode.c b/src/soc/amd/picasso/update_microcode.c deleted file mode 100644 index 47a98353b9..0000000000 --- a/src/soc/amd/picasso/update_microcode.c +++ /dev/null @@ -1,90 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ - -#include -#include -#include -#include -#include -#include -#include - -#define MPB_MAX_SIZE 3200 -#define MPB_DATA_OFFSET 32 - -struct microcode { - uint32_t date_code; - uint32_t patch_id; - - uint16_t mc_patch_data_id; - uint8_t reserved1[6]; - - uint32_t chipset1_dev_id; - uint32_t chipset2_dev_id; - - uint16_t processor_rev_id; - - uint8_t chipset1_rev_id; - uint8_t chipset2_rev_id; - - uint8_t reserved2[4]; - - uint8_t m_patch_data[MPB_MAX_SIZE-MPB_DATA_OFFSET]; -} __packed; - -static void apply_microcode_patch(const struct microcode *m) -{ - uint32_t new_patch_id; - msr_t msr; - - msr.hi = (uint64_t)(uintptr_t)m >> 32; - msr.lo = (uintptr_t)m & 0xffffffff; - - wrmsr(MSR_PATCH_LOADER, msr); - - printk(BIOS_DEBUG, "microcode: patch id to apply = 0x%08x\n", - m->patch_id); - - msr = rdmsr(MSR_PATCH_LEVEL); - new_patch_id = msr.lo; - - if (new_patch_id == m->patch_id) - printk(BIOS_INFO, "microcode: being updated to patch id = 0x%08x succeeded\n", - new_patch_id); - else - printk(BIOS_ERR, "microcode: being updated to patch id = 0x%08x failed\n", - new_patch_id); -} - -static uint16_t get_equivalent_processor_rev_id(void) -{ - uint32_t cpuid_family = cpuid_eax(1); - - return (uint16_t)((cpuid_family & 0xff0000) >> 8 | (cpuid_family & 0xff)); -} - -static void amd_update_microcode(const void *ucode, size_t ucode_len, - uint16_t equivalent_processor_rev_id) -{ - const struct microcode *m; - - for (m = (struct microcode *)ucode; - m < (struct microcode *)ucode + ucode_len/MPB_MAX_SIZE; m++) { - if (m->processor_rev_id == equivalent_processor_rev_id) - apply_microcode_patch(m); - } -} - -void amd_update_microcode_from_cbfs(void) -{ - const void *ucode; - size_t ucode_len; - uint16_t equivalent_processor_rev_id = get_equivalent_processor_rev_id(); - - ucode = cbfs_map("cpu_microcode_blob.bin", &ucode_len); - if (!ucode) { - printk(BIOS_WARNING, "cpu_microcode_blob.bin not found. Skipping updates.\n"); - return; - } - - amd_update_microcode(ucode, ucode_len, equivalent_processor_rev_id); -} -- cgit v1.2.3