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 <subratabanik@google.com>
Change-Id: I9a7cdc2d2c9211f1e0c7921015126f7a1be87761
Reviewed-on: https://review.coreboot.org/c/coreboot/+/65249
Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Subrata Banik 2022-06-20 08:10:39 +00:00 committed by Felix Held
parent 861ec01b44
commit 7734af81bc
1 changed files with 26 additions and 31 deletions

View File

@ -68,10 +68,30 @@ static inline u32 read_microcode_rev(void)
#define MICROCODE_CBFS_FILE "cpu_microcode_blob.bin" #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; u32 current_rev;
msr_t msr; 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; const struct microcode *m = microcode_patch;
if (!m) if (!m)
@ -93,20 +113,9 @@ void intel_microcode_load_unlocked(const void *microcode_patch)
} }
#endif #endif
msr.lo = (unsigned long)m + sizeof(struct microcode); printk(BIOS_INFO, "microcode: load microcode patch\n");
msr.hi = 0; if (load_microcode(m) < 0)
wrmsr(IA32_BIOS_UPDT_TRIG, msr); printk(BIOS_ERR, "microcode: Update failed\n");
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");
} }
uint32_t get_current_microcode_rev(void) uint32_t get_current_microcode_rev(void)
@ -255,8 +264,6 @@ void intel_reload_microcode(void)
if (!CONFIG(RELOAD_MICROCODE_PATCH)) if (!CONFIG(RELOAD_MICROCODE_PATCH))
return; return;
u32 current_rev;
msr_t msr;
const struct microcode *m = intel_microcode_find(); const struct microcode *m = intel_microcode_find();
if (!m) { if (!m) {
@ -266,19 +273,7 @@ void intel_reload_microcode(void)
printk(BIOS_INFO, "microcode: Re-load microcode patch\n"); printk(BIOS_INFO, "microcode: Re-load microcode patch\n");
msr.lo = (unsigned long)m + sizeof(struct microcode); if (load_microcode(m) < 0)
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"); printk(BIOS_ERR, "microcode: Re-load failed\n");
} }