74 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
78 #include <linux/capability.h>
79 #include <linux/kernel.h>
80 #include <linux/module.h>
88 #include <asm/processor.h>
90 #include <asm/perf_event.h>
96 #define MICROCODE_VERSION "2.00"
126 static void collect_cpu_info_local(
void *
arg)
146 static int collect_cpu_info(
int cpu)
151 memset(uci, 0,
sizeof(*uci));
153 ret = collect_cpu_info_on_target(cpu, &uci->
cpu_sig);
164 static void apply_microcode_local(
void *
arg)
171 static int apply_microcode_on_target(
int cpu)
183 #ifdef CONFIG_MICROCODE_OLD_INTERFACE
184 static int do_microcode_update(
const void __user *
buf,
size_t size)
201 apply_microcode_on_target(cpu);
212 static ssize_t microcode_write(
struct file *file,
const char __user *buf,
213 size_t len, loff_t *ppos)
218 pr_err(
"too much data (max %ld pages)\n", totalram_pages);
225 if (do_microcode_update(buf, len) == 0)
239 .write = microcode_write,
240 .open = microcode_open,
247 .nodename =
"cpu/microcode",
248 .fops = µcode_fops,
272 #define microcode_dev_init() 0
273 #define microcode_dev_exit() do { } while (0)
279 static int reload_for_cpu(
int cpu)
290 apply_microcode_on_target(cpu);
299 const char *buf,
size_t size)
305 ret = kstrtoul(buf, 0, &val);
315 tmp_ret = reload_for_cpu(cpu);
317 pr_warn(
"Error reloading microcode on CPU %d\n", cpu);
354 static struct attribute *mc_default_attrs[] = {
355 &dev_attr_version.attr,
356 &dev_attr_processor_flags.attr,
361 .attrs = mc_default_attrs,
365 static void microcode_fini_cpu(
int cpu)
373 static enum ucode_state microcode_resume_cpu(
int cpu)
375 pr_debug(
"CPU%d updated upon resume\n", cpu);
377 if (apply_microcode_on_target(cpu))
383 static enum ucode_state microcode_init_cpu(
int cpu,
bool refresh_fw)
387 if (collect_cpu_info(cpu))
398 pr_debug(
"CPU%d updated upon init\n", cpu);
399 apply_microcode_on_target(cpu);
405 static enum ucode_state microcode_update_cpu(
int cpu)
410 return microcode_resume_cpu(cpu);
412 return microcode_init_cpu(cpu,
false);
417 int err, cpu = dev->
id;
442 microcode_fini_cpu(cpu);
450 .add_dev = mc_device_add,
451 .remove_dev = mc_device_remove,
457 static void mc_bp_resume(
void)
467 .resume = mc_bp_resume,
473 unsigned int cpu = (
unsigned long)hcpu;
480 microcode_update_cpu(cpu);
489 pr_err(
"Failed to create group for CPU%d\n", cpu);
510 microcode_fini_cpu(cpu);
516 .notifier_call = mc_cpu_callback,
522 #ifdef CONFIG_MICROCODE_INTEL
525 #ifdef CONFIG_MICROCODE_AMD
533 static struct attribute *cpu_root_microcode_attrs[] = {
534 &dev_attr_reload.attr,
540 .attrs = cpu_root_microcode_attrs,
543 static int __init microcode_init(
void)
553 pr_err(
"no support for this CPU vendor\n");
558 microcode_pdev = platform_device_register_simple(
"microcode", -1,
560 if (IS_ERR(microcode_pdev))
561 return PTR_ERR(microcode_pdev);
576 &cpu_root_microcode_group);
579 pr_err(
"Error creating microcode group!\n");
585 goto out_ucode_group;
597 &cpu_root_microcode_group);
615 static void __exit microcode_exit(
void)
625 &cpu_root_microcode_group);
637 microcode_ops =
NULL;