Skip to content

Commit 9d48960

Browse files
suryasaimadhugregkh
authored andcommitted
x86/microcode: Use the firmware_loader built-in API
The microcode loader has been looping through __start_builtin_fw down to __end_builtin_fw to look for possibly built-in firmware for microcode updates. Now that the firmware loader code has exported an API for looping through the kernel's built-in firmware section, use it and drop the x86 implementation in favor. Signed-off-by: Borislav Petkov <bp@suse.de> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Link: https://lore.kernel.org/r/20211021155843.1969401-4-mcgrof@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e520ecf commit 9d48960

4 files changed

Lines changed: 18 additions & 25 deletions

File tree

arch/x86/include/asm/microcode.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,11 @@ static inline unsigned int x86_cpuid_family(void)
130130
extern void __init load_ucode_bsp(void);
131131
extern void load_ucode_ap(void);
132132
void reload_early_microcode(void);
133-
extern bool get_builtin_firmware(struct cpio_data *cd, const char *name);
134133
extern bool initrd_gone;
135134
#else
136135
static inline void __init load_ucode_bsp(void) { }
137136
static inline void load_ucode_ap(void) { }
138137
static inline void reload_early_microcode(void) { }
139-
static inline bool
140-
get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; }
141138
#endif
142139

143140
#endif /* _ASM_X86_MICROCODE_H */

arch/x86/kernel/cpu/microcode/amd.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,17 +456,23 @@ apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_p
456456

457457
static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
458458
{
459-
#ifdef CONFIG_X86_64
460459
char fw_name[36] = "amd-ucode/microcode_amd.bin";
460+
struct firmware fw;
461+
462+
if (IS_ENABLED(CONFIG_X86_32))
463+
return false;
461464

462465
if (family >= 0x15)
463466
snprintf(fw_name, sizeof(fw_name),
464467
"amd-ucode/microcode_amd_fam%.2xh.bin", family);
465468

466-
return get_builtin_firmware(cp, fw_name);
467-
#else
469+
if (firmware_request_builtin(&fw, fw_name)) {
470+
cp->size = fw.size;
471+
cp->data = (void *)fw.data;
472+
return true;
473+
}
474+
468475
return false;
469-
#endif
470476
}
471477

472478
static void __load_ucode_amd(unsigned int cpuid_1_eax, struct cpio_data *ret)

arch/x86/kernel/cpu/microcode/core.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,6 @@ static bool __init check_loader_disabled_bsp(void)
140140
return *res;
141141
}
142142

143-
extern struct builtin_fw __start_builtin_fw[];
144-
extern struct builtin_fw __end_builtin_fw[];
145-
146-
bool get_builtin_firmware(struct cpio_data *cd, const char *name)
147-
{
148-
struct builtin_fw *b_fw;
149-
150-
for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
151-
if (!strcmp(name, b_fw->name)) {
152-
cd->size = b_fw->size;
153-
cd->data = b_fw->data;
154-
return true;
155-
}
156-
}
157-
return false;
158-
}
159-
160143
void __init load_ucode_bsp(void)
161144
{
162145
unsigned int cpuid_1_eax;

arch/x86/kernel/cpu/microcode/intel.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ static void save_mc_for_early(struct ucode_cpu_info *uci, u8 *mc, unsigned int s
456456
static bool load_builtin_intel_microcode(struct cpio_data *cp)
457457
{
458458
unsigned int eax = 1, ebx, ecx = 0, edx;
459+
struct firmware fw;
459460
char name[30];
460461

461462
if (IS_ENABLED(CONFIG_X86_32))
@@ -466,7 +467,13 @@ static bool load_builtin_intel_microcode(struct cpio_data *cp)
466467
sprintf(name, "intel-ucode/%02x-%02x-%02x",
467468
x86_family(eax), x86_model(eax), x86_stepping(eax));
468469

469-
return get_builtin_firmware(cp, name);
470+
if (firmware_request_builtin(&fw, name)) {
471+
cp->size = fw.size;
472+
cp->data = (void *)fw.data;
473+
return true;
474+
}
475+
476+
return false;
470477
}
471478

472479
/*

0 commit comments

Comments
 (0)