提交 4bae1967 编写于 作者: I Ingo Molnar

x86: microcode: cleanup

Impact: cleanup

Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Dmitry Adamushko <dmitry.adamushko@gmail.com>
Cc: Peter Oruba <peter.oruba@amd.com>
LKML-Reference: <200903111632.37279.rusty@rustcorp.com.au>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
上级 af5c820a
...@@ -12,31 +12,30 @@ ...@@ -12,31 +12,30 @@
* *
* Licensed under the terms of the GNU General Public * Licensed under the terms of the GNU General Public
* License version 2. See file COPYING for details. * License version 2. See file COPYING for details.
*/ */
#include <linux/platform_device.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/cpumask.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/firmware.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/mm.h> #include <linux/cpumask.h>
#include <linux/fs.h> #include <linux/pci_ids.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/firmware.h>
#include <linux/platform_device.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci_ids.h> #include <linux/fs.h>
#include <linux/uaccess.h> #include <linux/mm.h>
#include <asm/msr.h>
#include <asm/processor.h>
#include <asm/microcode.h> #include <asm/microcode.h>
#include <asm/processor.h>
#include <asm/msr.h>
MODULE_DESCRIPTION("AMD Microcode Update Driver"); MODULE_DESCRIPTION("AMD Microcode Update Driver");
MODULE_AUTHOR("Peter Oruba"); MODULE_AUTHOR("Peter Oruba");
...@@ -184,8 +183,8 @@ static int get_ucode_data(void *to, const u8 *from, size_t n) ...@@ -184,8 +183,8 @@ static int get_ucode_data(void *to, const u8 *from, size_t n)
return 0; return 0;
} }
static void *get_next_ucode(const u8 *buf, unsigned int size, static void *
unsigned int *mc_size) get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
{ {
unsigned int total_size; unsigned int total_size;
u8 section_hdr[UCODE_CONTAINER_SECTION_HDR]; u8 section_hdr[UCODE_CONTAINER_SECTION_HDR];
...@@ -223,7 +222,6 @@ static void *get_next_ucode(const u8 *buf, unsigned int size, ...@@ -223,7 +222,6 @@ static void *get_next_ucode(const u8 *buf, unsigned int size,
return mc; return mc;
} }
static int install_equiv_cpu_table(const u8 *buf) static int install_equiv_cpu_table(const u8 *buf)
{ {
u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE]; u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE];
...@@ -372,4 +370,3 @@ struct microcode_ops * __init init_amd_microcode(void) ...@@ -372,4 +370,3 @@ struct microcode_ops * __init init_amd_microcode(void)
{ {
return &microcode_amd_ops; return &microcode_amd_ops;
} }
...@@ -70,28 +70,28 @@ ...@@ -70,28 +70,28 @@
* Fix sigmatch() macro to handle old CPUs with pf == 0. * Fix sigmatch() macro to handle old CPUs with pf == 0.
* Thanks to Stuart Swales for pointing out this bug. * Thanks to Stuart Swales for pointing out this bug.
*/ */
#include <linux/platform_device.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/kernel.h> #include <linux/miscdevice.h>
#include <linux/init.h> #include <linux/firmware.h>
#include <linux/sched.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/spinlock.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/module.h> #include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/miscdevice.h> #include <linux/kernel.h>
#include <linux/spinlock.h> #include <linux/module.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/firmware.h> #include <linux/fs.h>
#include <linux/platform_device.h> #include <linux/mm.h>
#include <asm/msr.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
#include <asm/microcode.h> #include <asm/microcode.h>
#include <asm/processor.h>
#include <asm/msr.h>
MODULE_DESCRIPTION("Microcode Update Driver"); MODULE_DESCRIPTION("Microcode Update Driver");
MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
......
...@@ -70,28 +70,28 @@ ...@@ -70,28 +70,28 @@
* Fix sigmatch() macro to handle old CPUs with pf == 0. * Fix sigmatch() macro to handle old CPUs with pf == 0.
* Thanks to Stuart Swales for pointing out this bug. * Thanks to Stuart Swales for pointing out this bug.
*/ */
#include <linux/platform_device.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/kernel.h> #include <linux/miscdevice.h>
#include <linux/init.h> #include <linux/firmware.h>
#include <linux/sched.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/spinlock.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/module.h> #include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/miscdevice.h> #include <linux/kernel.h>
#include <linux/spinlock.h> #include <linux/module.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/firmware.h> #include <linux/fs.h>
#include <linux/platform_device.h> #include <linux/mm.h>
#include <linux/uaccess.h>
#include <asm/msr.h>
#include <asm/processor.h>
#include <asm/microcode.h> #include <asm/microcode.h>
#include <asm/processor.h>
#include <asm/msr.h>
MODULE_DESCRIPTION("Microcode Update Driver"); MODULE_DESCRIPTION("Microcode Update Driver");
MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
...@@ -135,6 +135,7 @@ struct extended_sigtable { ...@@ -135,6 +135,7 @@ struct extended_sigtable {
#define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) #define EXT_HEADER_SIZE (sizeof(struct extended_sigtable))
#define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) #define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature))
#define DWSIZE (sizeof(u32)) #define DWSIZE (sizeof(u32))
#define get_totalsize(mc) \ #define get_totalsize(mc) \
(((struct microcode_intel *)mc)->hdr.totalsize ? \ (((struct microcode_intel *)mc)->hdr.totalsize ? \
((struct microcode_intel *)mc)->hdr.totalsize : \ ((struct microcode_intel *)mc)->hdr.totalsize : \
...@@ -204,14 +205,15 @@ update_match_revision(struct microcode_header_intel *mc_header, int rev) ...@@ -204,14 +205,15 @@ update_match_revision(struct microcode_header_intel *mc_header, int rev)
static int microcode_sanity_check(void *mc) static int microcode_sanity_check(void *mc)
{ {
unsigned long total_size, data_size, ext_table_size;
struct microcode_header_intel *mc_header = mc; struct microcode_header_intel *mc_header = mc;
struct extended_sigtable *ext_header = NULL; struct extended_sigtable *ext_header = NULL;
struct extended_signature *ext_sig;
unsigned long total_size, data_size, ext_table_size;
int sum, orig_sum, ext_sigcount = 0, i; int sum, orig_sum, ext_sigcount = 0, i;
struct extended_signature *ext_sig;
total_size = get_totalsize(mc_header); total_size = get_totalsize(mc_header);
data_size = get_datasize(mc_header); data_size = get_datasize(mc_header);
if (data_size + MC_HEADER_SIZE > total_size) { if (data_size + MC_HEADER_SIZE > total_size) {
printk(KERN_ERR "microcode: error! " printk(KERN_ERR "microcode: error! "
"Bad data size in microcode data file\n"); "Bad data size in microcode data file\n");
...@@ -318,11 +320,15 @@ get_matching_microcode(struct cpu_signature *cpu_sig, void *mc, int rev) ...@@ -318,11 +320,15 @@ get_matching_microcode(struct cpu_signature *cpu_sig, void *mc, int rev)
static void apply_microcode(int cpu) static void apply_microcode(int cpu)
{ {
struct microcode_intel *mc_intel;
struct ucode_cpu_info *uci;
unsigned long flags; unsigned long flags;
unsigned int val[2]; unsigned int val[2];
int cpu_num = raw_smp_processor_id(); int cpu_num;
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
struct microcode_intel *mc_intel = uci->mc; cpu_num = raw_smp_processor_id();
uci = ucode_cpu_info + cpu;
mc_intel = uci->mc;
/* We should bind the task to the CPU */ /* We should bind the task to the CPU */
BUG_ON(cpu_num != cpu); BUG_ON(cpu_num != cpu);
...@@ -348,7 +354,8 @@ static void apply_microcode(int cpu) ...@@ -348,7 +354,8 @@ static void apply_microcode(int cpu)
spin_unlock_irqrestore(&microcode_update_lock, flags); spin_unlock_irqrestore(&microcode_update_lock, flags);
if (val[1] != mc_intel->hdr.rev) { if (val[1] != mc_intel->hdr.rev) {
printk(KERN_ERR "microcode: CPU%d update from revision " printk(KERN_ERR "microcode: CPU%d update from revision "
"0x%x to 0x%x failed\n", cpu_num, uci->cpu_sig.rev, val[1]); "0x%x to 0x%x failed\n",
cpu_num, uci->cpu_sig.rev, val[1]);
return; return;
} }
printk(KERN_INFO "microcode: CPU%d updated from revision " printk(KERN_INFO "microcode: CPU%d updated from revision "
...@@ -357,6 +364,7 @@ static void apply_microcode(int cpu) ...@@ -357,6 +364,7 @@ static void apply_microcode(int cpu)
mc_intel->hdr.date & 0xffff, mc_intel->hdr.date & 0xffff,
mc_intel->hdr.date >> 24, mc_intel->hdr.date >> 24,
(mc_intel->hdr.date >> 16) & 0xff); (mc_intel->hdr.date >> 16) & 0xff);
uci->cpu_sig.rev = val[1]; uci->cpu_sig.rev = val[1];
} }
...@@ -404,18 +412,23 @@ static int generic_load_microcode(int cpu, void *data, size_t size, ...@@ -404,18 +412,23 @@ static int generic_load_microcode(int cpu, void *data, size_t size,
leftover -= mc_size; leftover -= mc_size;
} }
if (new_mc) { if (!new_mc)
if (!leftover) { goto out;
if (leftover) {
vfree(new_mc);
goto out;
}
if (uci->mc) if (uci->mc)
vfree(uci->mc); vfree(uci->mc);
uci->mc = (struct microcode_intel *)new_mc; uci->mc = (struct microcode_intel *)new_mc;
pr_debug("microcode: CPU%d found a matching microcode update with" pr_debug("microcode: CPU%d found a matching microcode update with"
" version 0x%x (current=0x%x)\n", " version 0x%x (current=0x%x)\n",
cpu, new_rev, uci->cpu_sig.rev); cpu, new_rev, uci->cpu_sig.rev);
} else
vfree(new_mc);
}
out:
return (int)leftover; return (int)leftover;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册