From 7734af81bcdc602b71811343dd8f8d092fc1028f Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Mon, 20 Jun 2022 08:10:39 +0000 Subject: cpu/intel/microcode: Create helper function to load microcode patch This patch refactors the microcode loading and reloading API with a helper function that perform the actual MSR write operation after taking the microcode pointer from the caller function. Also, convert the microcode loading failure msg type from `BIOS_INFO` to `BIOS_ERR` to catch the error in proper. TEST=Able to perform microcode loading on google/kano. Signed-off-by: Subrata Banik Change-Id: I9a7cdc2d2c9211f1e0c7921015126f7a1be87761 Reviewed-on: https://review.coreboot.org/c/coreboot/+/65249 Reviewed-by: Eric Lai Tested-by: build bot (Jenkins) --- src/cpu/intel/microcode/microcode.c | 57 +++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 31 deletions(-) (limited to 'src/cpu/intel') diff --git a/src/cpu/intel/microcode/microcode.c b/src/cpu/intel/microcode/microcode.c index 5ed6190e26..4c85a56096 100644 --- a/src/cpu/intel/microcode/microcode.c +++ b/src/cpu/intel/microcode/microcode.c @@ -68,10 +68,30 @@ static inline u32 read_microcode_rev(void) #define MICROCODE_CBFS_FILE "cpu_microcode_blob.bin" -void intel_microcode_load_unlocked(const void *microcode_patch) +static int load_microcode(const struct microcode *ucode_patch) { u32 current_rev; msr_t msr; + + msr.lo = (unsigned long)ucode_patch + sizeof(struct microcode); + msr.hi = 0; + wrmsr(IA32_BIOS_UPDT_TRIG, msr); + + current_rev = read_microcode_rev(); + if (current_rev == ucode_patch->rev) { + printk(BIOS_INFO, "microcode: updated to revision " + "0x%x date=%04x-%02x-%02x\n", read_microcode_rev(), + ucode_patch->date & 0xffff, (ucode_patch->date >> 24) & 0xff, + (ucode_patch->date >> 16) & 0xff); + return 0; + } + + return -1; +} + +void intel_microcode_load_unlocked(const void *microcode_patch) +{ + u32 current_rev; const struct microcode *m = microcode_patch; if (!m) @@ -93,20 +113,9 @@ void intel_microcode_load_unlocked(const void *microcode_patch) } #endif - msr.lo = (unsigned long)m + sizeof(struct microcode); - msr.hi = 0; - wrmsr(IA32_BIOS_UPDT_TRIG, msr); - - current_rev = read_microcode_rev(); - if (current_rev == m->rev) { - printk(BIOS_INFO, "microcode: updated to revision " - "0x%x date=%04x-%02x-%02x\n", read_microcode_rev(), - m->date & 0xffff, (m->date >> 24) & 0xff, - (m->date >> 16) & 0xff); - return; - } - - printk(BIOS_INFO, "microcode: Update failed\n"); + printk(BIOS_INFO, "microcode: load microcode patch\n"); + if (load_microcode(m) < 0) + printk(BIOS_ERR, "microcode: Update failed\n"); } uint32_t get_current_microcode_rev(void) @@ -255,8 +264,6 @@ void intel_reload_microcode(void) if (!CONFIG(RELOAD_MICROCODE_PATCH)) return; - u32 current_rev; - msr_t msr; const struct microcode *m = intel_microcode_find(); if (!m) { @@ -266,20 +273,8 @@ void intel_reload_microcode(void) printk(BIOS_INFO, "microcode: Re-load microcode patch\n"); - msr.lo = (unsigned long)m + sizeof(struct microcode); - msr.hi = 0; - wrmsr(IA32_BIOS_UPDT_TRIG, msr); - - current_rev = read_microcode_rev(); - if (current_rev == m->rev) { - printk(BIOS_INFO, "microcode: updated to revision " - "0x%x date=%04x-%02x-%02x\n", read_microcode_rev(), - m->date & 0xffff, (m->date >> 24) & 0xff, - (m->date >> 16) & 0xff); - return; - } - - printk(BIOS_ERR, "microcode: Re-load failed\n"); + if (load_microcode(m) < 0) + printk(BIOS_ERR, "microcode: Re-load failed\n"); } #if ENV_RAMSTAGE -- cgit v1.2.3