Commit beb5af4033cbeae2d50b4a6d770ab8901fd34d7a
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Thomas Gleixner: "Two final fixlets for 3.18: - Prevent microcode reload wreckage on 32bit - Unbreak cross compilation" * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, microcode: Limit the microcode reloading to 64-bit for now x86: Use $(OBJDUMP) instead of plain objdump
Showing 2 changed files Inline Diff
arch/x86/boot/compressed/Makefile
1 | # | 1 | # |
2 | # linux/arch/x86/boot/compressed/Makefile | 2 | # linux/arch/x86/boot/compressed/Makefile |
3 | # | 3 | # |
4 | # create a compressed vmlinux image from the original vmlinux | 4 | # create a compressed vmlinux image from the original vmlinux |
5 | # | 5 | # |
6 | 6 | ||
7 | targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ | 7 | targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ |
8 | vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 | 8 | vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 |
9 | 9 | ||
10 | KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 | 10 | KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 |
11 | KBUILD_CFLAGS += -fno-strict-aliasing -fPIC | 11 | KBUILD_CFLAGS += -fno-strict-aliasing -fPIC |
12 | KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING | 12 | KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING |
13 | cflags-$(CONFIG_X86_32) := -march=i386 | 13 | cflags-$(CONFIG_X86_32) := -march=i386 |
14 | cflags-$(CONFIG_X86_64) := -mcmodel=small | 14 | cflags-$(CONFIG_X86_64) := -mcmodel=small |
15 | KBUILD_CFLAGS += $(cflags-y) | 15 | KBUILD_CFLAGS += $(cflags-y) |
16 | KBUILD_CFLAGS += -mno-mmx -mno-sse | 16 | KBUILD_CFLAGS += -mno-mmx -mno-sse |
17 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) | 17 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) |
18 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) | 18 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) |
19 | 19 | ||
20 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ | 20 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ |
21 | GCOV_PROFILE := n | 21 | GCOV_PROFILE := n |
22 | 22 | ||
23 | LDFLAGS := -m elf_$(UTS_MACHINE) | 23 | LDFLAGS := -m elf_$(UTS_MACHINE) |
24 | LDFLAGS_vmlinux := -T | 24 | LDFLAGS_vmlinux := -T |
25 | 25 | ||
26 | hostprogs-y := mkpiggy | 26 | hostprogs-y := mkpiggy |
27 | HOST_EXTRACFLAGS += -I$(srctree)/tools/include | 27 | HOST_EXTRACFLAGS += -I$(srctree)/tools/include |
28 | 28 | ||
29 | vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ | 29 | vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ |
30 | $(obj)/string.o $(obj)/cmdline.o \ | 30 | $(obj)/string.o $(obj)/cmdline.o \ |
31 | $(obj)/piggy.o $(obj)/cpuflags.o | 31 | $(obj)/piggy.o $(obj)/cpuflags.o |
32 | 32 | ||
33 | vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o | 33 | vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o |
34 | vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o | 34 | vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o |
35 | 35 | ||
36 | $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone | 36 | $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone |
37 | 37 | ||
38 | vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o | 38 | vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o |
39 | 39 | ||
40 | $(obj)/vmlinux: $(vmlinux-objs-y) FORCE | 40 | $(obj)/vmlinux: $(vmlinux-objs-y) FORCE |
41 | $(call if_changed,ld) | 41 | $(call if_changed,ld) |
42 | @: | 42 | @: |
43 | 43 | ||
44 | OBJCOPYFLAGS_vmlinux.bin := -R .comment -S | 44 | OBJCOPYFLAGS_vmlinux.bin := -R .comment -S |
45 | $(obj)/vmlinux.bin: vmlinux FORCE | 45 | $(obj)/vmlinux.bin: vmlinux FORCE |
46 | $(call if_changed,objcopy) | 46 | $(call if_changed,objcopy) |
47 | 47 | ||
48 | targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs | 48 | targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs |
49 | 49 | ||
50 | CMD_RELOCS = arch/x86/tools/relocs | 50 | CMD_RELOCS = arch/x86/tools/relocs |
51 | quiet_cmd_relocs = RELOCS $@ | 51 | quiet_cmd_relocs = RELOCS $@ |
52 | cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< | 52 | cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $< |
53 | $(obj)/vmlinux.relocs: vmlinux FORCE | 53 | $(obj)/vmlinux.relocs: vmlinux FORCE |
54 | $(call if_changed,relocs) | 54 | $(call if_changed,relocs) |
55 | 55 | ||
56 | vmlinux.bin.all-y := $(obj)/vmlinux.bin | 56 | vmlinux.bin.all-y := $(obj)/vmlinux.bin |
57 | vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs | 57 | vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs |
58 | 58 | ||
59 | $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE | 59 | $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE |
60 | $(call if_changed,gzip) | 60 | $(call if_changed,gzip) |
61 | $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE | 61 | $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE |
62 | $(call if_changed,bzip2) | 62 | $(call if_changed,bzip2) |
63 | $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE | 63 | $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE |
64 | $(call if_changed,lzma) | 64 | $(call if_changed,lzma) |
65 | $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE | 65 | $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE |
66 | $(call if_changed,xzkern) | 66 | $(call if_changed,xzkern) |
67 | $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE | 67 | $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE |
68 | $(call if_changed,lzo) | 68 | $(call if_changed,lzo) |
69 | $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE | 69 | $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE |
70 | $(call if_changed,lz4) | 70 | $(call if_changed,lz4) |
71 | 71 | ||
72 | suffix-$(CONFIG_KERNEL_GZIP) := gz | 72 | suffix-$(CONFIG_KERNEL_GZIP) := gz |
73 | suffix-$(CONFIG_KERNEL_BZIP2) := bz2 | 73 | suffix-$(CONFIG_KERNEL_BZIP2) := bz2 |
74 | suffix-$(CONFIG_KERNEL_LZMA) := lzma | 74 | suffix-$(CONFIG_KERNEL_LZMA) := lzma |
75 | suffix-$(CONFIG_KERNEL_XZ) := xz | 75 | suffix-$(CONFIG_KERNEL_XZ) := xz |
76 | suffix-$(CONFIG_KERNEL_LZO) := lzo | 76 | suffix-$(CONFIG_KERNEL_LZO) := lzo |
77 | suffix-$(CONFIG_KERNEL_LZ4) := lz4 | 77 | suffix-$(CONFIG_KERNEL_LZ4) := lz4 |
78 | 78 | ||
79 | RUN_SIZE = $(shell objdump -h vmlinux | \ | 79 | RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \ |
80 | perl $(srctree)/arch/x86/tools/calc_run_size.pl) | 80 | perl $(srctree)/arch/x86/tools/calc_run_size.pl) |
81 | quiet_cmd_mkpiggy = MKPIGGY $@ | 81 | quiet_cmd_mkpiggy = MKPIGGY $@ |
82 | cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false ) | 82 | cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false ) |
83 | 83 | ||
84 | targets += piggy.S | 84 | targets += piggy.S |
85 | $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE | 85 | $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE |
86 | $(call if_changed,mkpiggy) | 86 | $(call if_changed,mkpiggy) |
87 | 87 |
arch/x86/kernel/cpu/microcode/core.c
1 | /* | 1 | /* |
2 | * Intel CPU Microcode Update Driver for Linux | 2 | * Intel CPU Microcode Update Driver for Linux |
3 | * | 3 | * |
4 | * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk> | 4 | * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk> |
5 | * 2006 Shaohua Li <shaohua.li@intel.com> | 5 | * 2006 Shaohua Li <shaohua.li@intel.com> |
6 | * | 6 | * |
7 | * This driver allows to upgrade microcode on Intel processors | 7 | * This driver allows to upgrade microcode on Intel processors |
8 | * belonging to IA-32 family - PentiumPro, Pentium II, | 8 | * belonging to IA-32 family - PentiumPro, Pentium II, |
9 | * Pentium III, Xeon, Pentium 4, etc. | 9 | * Pentium III, Xeon, Pentium 4, etc. |
10 | * | 10 | * |
11 | * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture | 11 | * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture |
12 | * Software Developer's Manual | 12 | * Software Developer's Manual |
13 | * Order Number 253668 or free download from: | 13 | * Order Number 253668 or free download from: |
14 | * | 14 | * |
15 | * http://developer.intel.com/Assets/PDF/manual/253668.pdf | 15 | * http://developer.intel.com/Assets/PDF/manual/253668.pdf |
16 | * | 16 | * |
17 | * For more information, go to http://www.urbanmyth.org/microcode | 17 | * For more information, go to http://www.urbanmyth.org/microcode |
18 | * | 18 | * |
19 | * This program is free software; you can redistribute it and/or | 19 | * This program is free software; you can redistribute it and/or |
20 | * modify it under the terms of the GNU General Public License | 20 | * modify it under the terms of the GNU General Public License |
21 | * as published by the Free Software Foundation; either version | 21 | * as published by the Free Software Foundation; either version |
22 | * 2 of the License, or (at your option) any later version. | 22 | * 2 of the License, or (at your option) any later version. |
23 | * | 23 | * |
24 | * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com> | 24 | * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com> |
25 | * Initial release. | 25 | * Initial release. |
26 | * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com> | 26 | * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com> |
27 | * Added read() support + cleanups. | 27 | * Added read() support + cleanups. |
28 | * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com> | 28 | * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com> |
29 | * Added 'device trimming' support. open(O_WRONLY) zeroes | 29 | * Added 'device trimming' support. open(O_WRONLY) zeroes |
30 | * and frees the saved copy of applied microcode. | 30 | * and frees the saved copy of applied microcode. |
31 | * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com> | 31 | * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com> |
32 | * Made to use devfs (/dev/cpu/microcode) + cleanups. | 32 | * Made to use devfs (/dev/cpu/microcode) + cleanups. |
33 | * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com> | 33 | * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com> |
34 | * Added misc device support (now uses both devfs and misc). | 34 | * Added misc device support (now uses both devfs and misc). |
35 | * Added MICROCODE_IOCFREE ioctl to clear memory. | 35 | * Added MICROCODE_IOCFREE ioctl to clear memory. |
36 | * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com> | 36 | * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com> |
37 | * Messages for error cases (non Intel & no suitable microcode). | 37 | * Messages for error cases (non Intel & no suitable microcode). |
38 | * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com> | 38 | * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com> |
39 | * Removed ->release(). Removed exclusive open and status bitmap. | 39 | * Removed ->release(). Removed exclusive open and status bitmap. |
40 | * Added microcode_rwsem to serialize read()/write()/ioctl(). | 40 | * Added microcode_rwsem to serialize read()/write()/ioctl(). |
41 | * Removed global kernel lock usage. | 41 | * Removed global kernel lock usage. |
42 | * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com> | 42 | * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com> |
43 | * Write 0 to 0x8B msr and then cpuid before reading revision, | 43 | * Write 0 to 0x8B msr and then cpuid before reading revision, |
44 | * so that it works even if there were no update done by the | 44 | * so that it works even if there were no update done by the |
45 | * BIOS. Otherwise, reading from 0x8B gives junk (which happened | 45 | * BIOS. Otherwise, reading from 0x8B gives junk (which happened |
46 | * to be 0 on my machine which is why it worked even when I | 46 | * to be 0 on my machine which is why it worked even when I |
47 | * disabled update by the BIOS) | 47 | * disabled update by the BIOS) |
48 | * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix. | 48 | * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix. |
49 | * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and | 49 | * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and |
50 | * Tigran Aivazian <tigran@veritas.com> | 50 | * Tigran Aivazian <tigran@veritas.com> |
51 | * Intel Pentium 4 processor support and bugfixes. | 51 | * Intel Pentium 4 processor support and bugfixes. |
52 | * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com> | 52 | * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com> |
53 | * Bugfix for HT (Hyper-Threading) enabled processors | 53 | * Bugfix for HT (Hyper-Threading) enabled processors |
54 | * whereby processor resources are shared by all logical processors | 54 | * whereby processor resources are shared by all logical processors |
55 | * in a single CPU package. | 55 | * in a single CPU package. |
56 | * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and | 56 | * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and |
57 | * Tigran Aivazian <tigran@veritas.com>, | 57 | * Tigran Aivazian <tigran@veritas.com>, |
58 | * Serialize updates as required on HT processors due to | 58 | * Serialize updates as required on HT processors due to |
59 | * speculative nature of implementation. | 59 | * speculative nature of implementation. |
60 | * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com> | 60 | * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com> |
61 | * Fix the panic when writing zero-length microcode chunk. | 61 | * Fix the panic when writing zero-length microcode chunk. |
62 | * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, | 62 | * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, |
63 | * Jun Nakajima <jun.nakajima@intel.com> | 63 | * Jun Nakajima <jun.nakajima@intel.com> |
64 | * Support for the microcode updates in the new format. | 64 | * Support for the microcode updates in the new format. |
65 | * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com> | 65 | * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com> |
66 | * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl | 66 | * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl |
67 | * because we no longer hold a copy of applied microcode | 67 | * because we no longer hold a copy of applied microcode |
68 | * in kernel memory. | 68 | * in kernel memory. |
69 | * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com> | 69 | * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com> |
70 | * Fix sigmatch() macro to handle old CPUs with pf == 0. | 70 | * Fix sigmatch() macro to handle old CPUs with pf == 0. |
71 | * Thanks to Stuart Swales for pointing out this bug. | 71 | * Thanks to Stuart Swales for pointing out this bug. |
72 | */ | 72 | */ |
73 | 73 | ||
74 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 74 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
75 | 75 | ||
76 | #include <linux/platform_device.h> | 76 | #include <linux/platform_device.h> |
77 | #include <linux/miscdevice.h> | 77 | #include <linux/miscdevice.h> |
78 | #include <linux/capability.h> | 78 | #include <linux/capability.h> |
79 | #include <linux/kernel.h> | 79 | #include <linux/kernel.h> |
80 | #include <linux/module.h> | 80 | #include <linux/module.h> |
81 | #include <linux/mutex.h> | 81 | #include <linux/mutex.h> |
82 | #include <linux/cpu.h> | 82 | #include <linux/cpu.h> |
83 | #include <linux/fs.h> | 83 | #include <linux/fs.h> |
84 | #include <linux/mm.h> | 84 | #include <linux/mm.h> |
85 | #include <linux/syscore_ops.h> | 85 | #include <linux/syscore_ops.h> |
86 | 86 | ||
87 | #include <asm/microcode.h> | 87 | #include <asm/microcode.h> |
88 | #include <asm/processor.h> | 88 | #include <asm/processor.h> |
89 | #include <asm/cpu_device_id.h> | 89 | #include <asm/cpu_device_id.h> |
90 | #include <asm/perf_event.h> | 90 | #include <asm/perf_event.h> |
91 | 91 | ||
92 | MODULE_DESCRIPTION("Microcode Update Driver"); | 92 | MODULE_DESCRIPTION("Microcode Update Driver"); |
93 | MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); | 93 | MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); |
94 | MODULE_LICENSE("GPL"); | 94 | MODULE_LICENSE("GPL"); |
95 | 95 | ||
96 | #define MICROCODE_VERSION "2.00" | 96 | #define MICROCODE_VERSION "2.00" |
97 | 97 | ||
98 | static struct microcode_ops *microcode_ops; | 98 | static struct microcode_ops *microcode_ops; |
99 | 99 | ||
100 | bool dis_ucode_ldr; | 100 | bool dis_ucode_ldr; |
101 | module_param(dis_ucode_ldr, bool, 0); | 101 | module_param(dis_ucode_ldr, bool, 0); |
102 | 102 | ||
103 | /* | 103 | /* |
104 | * Synchronization. | 104 | * Synchronization. |
105 | * | 105 | * |
106 | * All non cpu-hotplug-callback call sites use: | 106 | * All non cpu-hotplug-callback call sites use: |
107 | * | 107 | * |
108 | * - microcode_mutex to synchronize with each other; | 108 | * - microcode_mutex to synchronize with each other; |
109 | * - get/put_online_cpus() to synchronize with | 109 | * - get/put_online_cpus() to synchronize with |
110 | * the cpu-hotplug-callback call sites. | 110 | * the cpu-hotplug-callback call sites. |
111 | * | 111 | * |
112 | * We guarantee that only a single cpu is being | 112 | * We guarantee that only a single cpu is being |
113 | * updated at any particular moment of time. | 113 | * updated at any particular moment of time. |
114 | */ | 114 | */ |
115 | static DEFINE_MUTEX(microcode_mutex); | 115 | static DEFINE_MUTEX(microcode_mutex); |
116 | 116 | ||
117 | struct ucode_cpu_info ucode_cpu_info[NR_CPUS]; | 117 | struct ucode_cpu_info ucode_cpu_info[NR_CPUS]; |
118 | EXPORT_SYMBOL_GPL(ucode_cpu_info); | 118 | EXPORT_SYMBOL_GPL(ucode_cpu_info); |
119 | 119 | ||
120 | /* | 120 | /* |
121 | * Operations that are run on a target cpu: | 121 | * Operations that are run on a target cpu: |
122 | */ | 122 | */ |
123 | 123 | ||
124 | struct cpu_info_ctx { | 124 | struct cpu_info_ctx { |
125 | struct cpu_signature *cpu_sig; | 125 | struct cpu_signature *cpu_sig; |
126 | int err; | 126 | int err; |
127 | }; | 127 | }; |
128 | 128 | ||
129 | static void collect_cpu_info_local(void *arg) | 129 | static void collect_cpu_info_local(void *arg) |
130 | { | 130 | { |
131 | struct cpu_info_ctx *ctx = arg; | 131 | struct cpu_info_ctx *ctx = arg; |
132 | 132 | ||
133 | ctx->err = microcode_ops->collect_cpu_info(smp_processor_id(), | 133 | ctx->err = microcode_ops->collect_cpu_info(smp_processor_id(), |
134 | ctx->cpu_sig); | 134 | ctx->cpu_sig); |
135 | } | 135 | } |
136 | 136 | ||
137 | static int collect_cpu_info_on_target(int cpu, struct cpu_signature *cpu_sig) | 137 | static int collect_cpu_info_on_target(int cpu, struct cpu_signature *cpu_sig) |
138 | { | 138 | { |
139 | struct cpu_info_ctx ctx = { .cpu_sig = cpu_sig, .err = 0 }; | 139 | struct cpu_info_ctx ctx = { .cpu_sig = cpu_sig, .err = 0 }; |
140 | int ret; | 140 | int ret; |
141 | 141 | ||
142 | ret = smp_call_function_single(cpu, collect_cpu_info_local, &ctx, 1); | 142 | ret = smp_call_function_single(cpu, collect_cpu_info_local, &ctx, 1); |
143 | if (!ret) | 143 | if (!ret) |
144 | ret = ctx.err; | 144 | ret = ctx.err; |
145 | 145 | ||
146 | return ret; | 146 | return ret; |
147 | } | 147 | } |
148 | 148 | ||
149 | static int collect_cpu_info(int cpu) | 149 | static int collect_cpu_info(int cpu) |
150 | { | 150 | { |
151 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 151 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
152 | int ret; | 152 | int ret; |
153 | 153 | ||
154 | memset(uci, 0, sizeof(*uci)); | 154 | memset(uci, 0, sizeof(*uci)); |
155 | 155 | ||
156 | ret = collect_cpu_info_on_target(cpu, &uci->cpu_sig); | 156 | ret = collect_cpu_info_on_target(cpu, &uci->cpu_sig); |
157 | if (!ret) | 157 | if (!ret) |
158 | uci->valid = 1; | 158 | uci->valid = 1; |
159 | 159 | ||
160 | return ret; | 160 | return ret; |
161 | } | 161 | } |
162 | 162 | ||
163 | struct apply_microcode_ctx { | 163 | struct apply_microcode_ctx { |
164 | int err; | 164 | int err; |
165 | }; | 165 | }; |
166 | 166 | ||
167 | static void apply_microcode_local(void *arg) | 167 | static void apply_microcode_local(void *arg) |
168 | { | 168 | { |
169 | struct apply_microcode_ctx *ctx = arg; | 169 | struct apply_microcode_ctx *ctx = arg; |
170 | 170 | ||
171 | ctx->err = microcode_ops->apply_microcode(smp_processor_id()); | 171 | ctx->err = microcode_ops->apply_microcode(smp_processor_id()); |
172 | } | 172 | } |
173 | 173 | ||
174 | static int apply_microcode_on_target(int cpu) | 174 | static int apply_microcode_on_target(int cpu) |
175 | { | 175 | { |
176 | struct apply_microcode_ctx ctx = { .err = 0 }; | 176 | struct apply_microcode_ctx ctx = { .err = 0 }; |
177 | int ret; | 177 | int ret; |
178 | 178 | ||
179 | ret = smp_call_function_single(cpu, apply_microcode_local, &ctx, 1); | 179 | ret = smp_call_function_single(cpu, apply_microcode_local, &ctx, 1); |
180 | if (!ret) | 180 | if (!ret) |
181 | ret = ctx.err; | 181 | ret = ctx.err; |
182 | 182 | ||
183 | return ret; | 183 | return ret; |
184 | } | 184 | } |
185 | 185 | ||
186 | #ifdef CONFIG_MICROCODE_OLD_INTERFACE | 186 | #ifdef CONFIG_MICROCODE_OLD_INTERFACE |
187 | static int do_microcode_update(const void __user *buf, size_t size) | 187 | static int do_microcode_update(const void __user *buf, size_t size) |
188 | { | 188 | { |
189 | int error = 0; | 189 | int error = 0; |
190 | int cpu; | 190 | int cpu; |
191 | 191 | ||
192 | for_each_online_cpu(cpu) { | 192 | for_each_online_cpu(cpu) { |
193 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 193 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
194 | enum ucode_state ustate; | 194 | enum ucode_state ustate; |
195 | 195 | ||
196 | if (!uci->valid) | 196 | if (!uci->valid) |
197 | continue; | 197 | continue; |
198 | 198 | ||
199 | ustate = microcode_ops->request_microcode_user(cpu, buf, size); | 199 | ustate = microcode_ops->request_microcode_user(cpu, buf, size); |
200 | if (ustate == UCODE_ERROR) { | 200 | if (ustate == UCODE_ERROR) { |
201 | error = -1; | 201 | error = -1; |
202 | break; | 202 | break; |
203 | } else if (ustate == UCODE_OK) | 203 | } else if (ustate == UCODE_OK) |
204 | apply_microcode_on_target(cpu); | 204 | apply_microcode_on_target(cpu); |
205 | } | 205 | } |
206 | 206 | ||
207 | return error; | 207 | return error; |
208 | } | 208 | } |
209 | 209 | ||
210 | static int microcode_open(struct inode *inode, struct file *file) | 210 | static int microcode_open(struct inode *inode, struct file *file) |
211 | { | 211 | { |
212 | return capable(CAP_SYS_RAWIO) ? nonseekable_open(inode, file) : -EPERM; | 212 | return capable(CAP_SYS_RAWIO) ? nonseekable_open(inode, file) : -EPERM; |
213 | } | 213 | } |
214 | 214 | ||
215 | static ssize_t microcode_write(struct file *file, const char __user *buf, | 215 | static ssize_t microcode_write(struct file *file, const char __user *buf, |
216 | size_t len, loff_t *ppos) | 216 | size_t len, loff_t *ppos) |
217 | { | 217 | { |
218 | ssize_t ret = -EINVAL; | 218 | ssize_t ret = -EINVAL; |
219 | 219 | ||
220 | if ((len >> PAGE_SHIFT) > totalram_pages) { | 220 | if ((len >> PAGE_SHIFT) > totalram_pages) { |
221 | pr_err("too much data (max %ld pages)\n", totalram_pages); | 221 | pr_err("too much data (max %ld pages)\n", totalram_pages); |
222 | return ret; | 222 | return ret; |
223 | } | 223 | } |
224 | 224 | ||
225 | get_online_cpus(); | 225 | get_online_cpus(); |
226 | mutex_lock(µcode_mutex); | 226 | mutex_lock(µcode_mutex); |
227 | 227 | ||
228 | if (do_microcode_update(buf, len) == 0) | 228 | if (do_microcode_update(buf, len) == 0) |
229 | ret = (ssize_t)len; | 229 | ret = (ssize_t)len; |
230 | 230 | ||
231 | if (ret > 0) | 231 | if (ret > 0) |
232 | perf_check_microcode(); | 232 | perf_check_microcode(); |
233 | 233 | ||
234 | mutex_unlock(µcode_mutex); | 234 | mutex_unlock(µcode_mutex); |
235 | put_online_cpus(); | 235 | put_online_cpus(); |
236 | 236 | ||
237 | return ret; | 237 | return ret; |
238 | } | 238 | } |
239 | 239 | ||
240 | static const struct file_operations microcode_fops = { | 240 | static const struct file_operations microcode_fops = { |
241 | .owner = THIS_MODULE, | 241 | .owner = THIS_MODULE, |
242 | .write = microcode_write, | 242 | .write = microcode_write, |
243 | .open = microcode_open, | 243 | .open = microcode_open, |
244 | .llseek = no_llseek, | 244 | .llseek = no_llseek, |
245 | }; | 245 | }; |
246 | 246 | ||
247 | static struct miscdevice microcode_dev = { | 247 | static struct miscdevice microcode_dev = { |
248 | .minor = MICROCODE_MINOR, | 248 | .minor = MICROCODE_MINOR, |
249 | .name = "microcode", | 249 | .name = "microcode", |
250 | .nodename = "cpu/microcode", | 250 | .nodename = "cpu/microcode", |
251 | .fops = µcode_fops, | 251 | .fops = µcode_fops, |
252 | }; | 252 | }; |
253 | 253 | ||
254 | static int __init microcode_dev_init(void) | 254 | static int __init microcode_dev_init(void) |
255 | { | 255 | { |
256 | int error; | 256 | int error; |
257 | 257 | ||
258 | error = misc_register(µcode_dev); | 258 | error = misc_register(µcode_dev); |
259 | if (error) { | 259 | if (error) { |
260 | pr_err("can't misc_register on minor=%d\n", MICROCODE_MINOR); | 260 | pr_err("can't misc_register on minor=%d\n", MICROCODE_MINOR); |
261 | return error; | 261 | return error; |
262 | } | 262 | } |
263 | 263 | ||
264 | return 0; | 264 | return 0; |
265 | } | 265 | } |
266 | 266 | ||
267 | static void __exit microcode_dev_exit(void) | 267 | static void __exit microcode_dev_exit(void) |
268 | { | 268 | { |
269 | misc_deregister(µcode_dev); | 269 | misc_deregister(µcode_dev); |
270 | } | 270 | } |
271 | 271 | ||
272 | MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); | 272 | MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); |
273 | MODULE_ALIAS("devname:cpu/microcode"); | 273 | MODULE_ALIAS("devname:cpu/microcode"); |
274 | #else | 274 | #else |
275 | #define microcode_dev_init() 0 | 275 | #define microcode_dev_init() 0 |
276 | #define microcode_dev_exit() do { } while (0) | 276 | #define microcode_dev_exit() do { } while (0) |
277 | #endif | 277 | #endif |
278 | 278 | ||
279 | /* fake device for request_firmware */ | 279 | /* fake device for request_firmware */ |
280 | static struct platform_device *microcode_pdev; | 280 | static struct platform_device *microcode_pdev; |
281 | 281 | ||
282 | static int reload_for_cpu(int cpu) | 282 | static int reload_for_cpu(int cpu) |
283 | { | 283 | { |
284 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 284 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
285 | enum ucode_state ustate; | 285 | enum ucode_state ustate; |
286 | int err = 0; | 286 | int err = 0; |
287 | 287 | ||
288 | if (!uci->valid) | 288 | if (!uci->valid) |
289 | return err; | 289 | return err; |
290 | 290 | ||
291 | ustate = microcode_ops->request_microcode_fw(cpu, µcode_pdev->dev, true); | 291 | ustate = microcode_ops->request_microcode_fw(cpu, µcode_pdev->dev, true); |
292 | if (ustate == UCODE_OK) | 292 | if (ustate == UCODE_OK) |
293 | apply_microcode_on_target(cpu); | 293 | apply_microcode_on_target(cpu); |
294 | else | 294 | else |
295 | if (ustate == UCODE_ERROR) | 295 | if (ustate == UCODE_ERROR) |
296 | err = -EINVAL; | 296 | err = -EINVAL; |
297 | return err; | 297 | return err; |
298 | } | 298 | } |
299 | 299 | ||
300 | static ssize_t reload_store(struct device *dev, | 300 | static ssize_t reload_store(struct device *dev, |
301 | struct device_attribute *attr, | 301 | struct device_attribute *attr, |
302 | const char *buf, size_t size) | 302 | const char *buf, size_t size) |
303 | { | 303 | { |
304 | unsigned long val; | 304 | unsigned long val; |
305 | int cpu; | 305 | int cpu; |
306 | ssize_t ret = 0, tmp_ret; | 306 | ssize_t ret = 0, tmp_ret; |
307 | 307 | ||
308 | ret = kstrtoul(buf, 0, &val); | 308 | ret = kstrtoul(buf, 0, &val); |
309 | if (ret) | 309 | if (ret) |
310 | return ret; | 310 | return ret; |
311 | 311 | ||
312 | if (val != 1) | 312 | if (val != 1) |
313 | return size; | 313 | return size; |
314 | 314 | ||
315 | get_online_cpus(); | 315 | get_online_cpus(); |
316 | mutex_lock(µcode_mutex); | 316 | mutex_lock(µcode_mutex); |
317 | for_each_online_cpu(cpu) { | 317 | for_each_online_cpu(cpu) { |
318 | tmp_ret = reload_for_cpu(cpu); | 318 | tmp_ret = reload_for_cpu(cpu); |
319 | if (tmp_ret != 0) | 319 | if (tmp_ret != 0) |
320 | pr_warn("Error reloading microcode on CPU %d\n", cpu); | 320 | pr_warn("Error reloading microcode on CPU %d\n", cpu); |
321 | 321 | ||
322 | /* save retval of the first encountered reload error */ | 322 | /* save retval of the first encountered reload error */ |
323 | if (!ret) | 323 | if (!ret) |
324 | ret = tmp_ret; | 324 | ret = tmp_ret; |
325 | } | 325 | } |
326 | if (!ret) | 326 | if (!ret) |
327 | perf_check_microcode(); | 327 | perf_check_microcode(); |
328 | mutex_unlock(µcode_mutex); | 328 | mutex_unlock(µcode_mutex); |
329 | put_online_cpus(); | 329 | put_online_cpus(); |
330 | 330 | ||
331 | if (!ret) | 331 | if (!ret) |
332 | ret = size; | 332 | ret = size; |
333 | 333 | ||
334 | return ret; | 334 | return ret; |
335 | } | 335 | } |
336 | 336 | ||
337 | static ssize_t version_show(struct device *dev, | 337 | static ssize_t version_show(struct device *dev, |
338 | struct device_attribute *attr, char *buf) | 338 | struct device_attribute *attr, char *buf) |
339 | { | 339 | { |
340 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; | 340 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; |
341 | 341 | ||
342 | return sprintf(buf, "0x%x\n", uci->cpu_sig.rev); | 342 | return sprintf(buf, "0x%x\n", uci->cpu_sig.rev); |
343 | } | 343 | } |
344 | 344 | ||
345 | static ssize_t pf_show(struct device *dev, | 345 | static ssize_t pf_show(struct device *dev, |
346 | struct device_attribute *attr, char *buf) | 346 | struct device_attribute *attr, char *buf) |
347 | { | 347 | { |
348 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; | 348 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; |
349 | 349 | ||
350 | return sprintf(buf, "0x%x\n", uci->cpu_sig.pf); | 350 | return sprintf(buf, "0x%x\n", uci->cpu_sig.pf); |
351 | } | 351 | } |
352 | 352 | ||
353 | static DEVICE_ATTR(reload, 0200, NULL, reload_store); | 353 | static DEVICE_ATTR(reload, 0200, NULL, reload_store); |
354 | static DEVICE_ATTR(version, 0400, version_show, NULL); | 354 | static DEVICE_ATTR(version, 0400, version_show, NULL); |
355 | static DEVICE_ATTR(processor_flags, 0400, pf_show, NULL); | 355 | static DEVICE_ATTR(processor_flags, 0400, pf_show, NULL); |
356 | 356 | ||
357 | static struct attribute *mc_default_attrs[] = { | 357 | static struct attribute *mc_default_attrs[] = { |
358 | &dev_attr_version.attr, | 358 | &dev_attr_version.attr, |
359 | &dev_attr_processor_flags.attr, | 359 | &dev_attr_processor_flags.attr, |
360 | NULL | 360 | NULL |
361 | }; | 361 | }; |
362 | 362 | ||
363 | static struct attribute_group mc_attr_group = { | 363 | static struct attribute_group mc_attr_group = { |
364 | .attrs = mc_default_attrs, | 364 | .attrs = mc_default_attrs, |
365 | .name = "microcode", | 365 | .name = "microcode", |
366 | }; | 366 | }; |
367 | 367 | ||
368 | static void microcode_fini_cpu(int cpu) | 368 | static void microcode_fini_cpu(int cpu) |
369 | { | 369 | { |
370 | microcode_ops->microcode_fini_cpu(cpu); | 370 | microcode_ops->microcode_fini_cpu(cpu); |
371 | } | 371 | } |
372 | 372 | ||
373 | static enum ucode_state microcode_resume_cpu(int cpu) | 373 | static enum ucode_state microcode_resume_cpu(int cpu) |
374 | { | 374 | { |
375 | pr_debug("CPU%d updated upon resume\n", cpu); | 375 | pr_debug("CPU%d updated upon resume\n", cpu); |
376 | 376 | ||
377 | if (apply_microcode_on_target(cpu)) | 377 | if (apply_microcode_on_target(cpu)) |
378 | return UCODE_ERROR; | 378 | return UCODE_ERROR; |
379 | 379 | ||
380 | return UCODE_OK; | 380 | return UCODE_OK; |
381 | } | 381 | } |
382 | 382 | ||
383 | static enum ucode_state microcode_init_cpu(int cpu, bool refresh_fw) | 383 | static enum ucode_state microcode_init_cpu(int cpu, bool refresh_fw) |
384 | { | 384 | { |
385 | enum ucode_state ustate; | 385 | enum ucode_state ustate; |
386 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 386 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
387 | 387 | ||
388 | if (uci && uci->valid) | 388 | if (uci && uci->valid) |
389 | return UCODE_OK; | 389 | return UCODE_OK; |
390 | 390 | ||
391 | if (collect_cpu_info(cpu)) | 391 | if (collect_cpu_info(cpu)) |
392 | return UCODE_ERROR; | 392 | return UCODE_ERROR; |
393 | 393 | ||
394 | /* --dimm. Trigger a delayed update? */ | 394 | /* --dimm. Trigger a delayed update? */ |
395 | if (system_state != SYSTEM_RUNNING) | 395 | if (system_state != SYSTEM_RUNNING) |
396 | return UCODE_NFOUND; | 396 | return UCODE_NFOUND; |
397 | 397 | ||
398 | ustate = microcode_ops->request_microcode_fw(cpu, µcode_pdev->dev, | 398 | ustate = microcode_ops->request_microcode_fw(cpu, µcode_pdev->dev, |
399 | refresh_fw); | 399 | refresh_fw); |
400 | 400 | ||
401 | if (ustate == UCODE_OK) { | 401 | if (ustate == UCODE_OK) { |
402 | pr_debug("CPU%d updated upon init\n", cpu); | 402 | pr_debug("CPU%d updated upon init\n", cpu); |
403 | apply_microcode_on_target(cpu); | 403 | apply_microcode_on_target(cpu); |
404 | } | 404 | } |
405 | 405 | ||
406 | return ustate; | 406 | return ustate; |
407 | } | 407 | } |
408 | 408 | ||
409 | static enum ucode_state microcode_update_cpu(int cpu) | 409 | static enum ucode_state microcode_update_cpu(int cpu) |
410 | { | 410 | { |
411 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 411 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
412 | 412 | ||
413 | if (uci->valid) | 413 | if (uci->valid) |
414 | return microcode_resume_cpu(cpu); | 414 | return microcode_resume_cpu(cpu); |
415 | 415 | ||
416 | return microcode_init_cpu(cpu, false); | 416 | return microcode_init_cpu(cpu, false); |
417 | } | 417 | } |
418 | 418 | ||
419 | static int mc_device_add(struct device *dev, struct subsys_interface *sif) | 419 | static int mc_device_add(struct device *dev, struct subsys_interface *sif) |
420 | { | 420 | { |
421 | int err, cpu = dev->id; | 421 | int err, cpu = dev->id; |
422 | 422 | ||
423 | if (!cpu_online(cpu)) | 423 | if (!cpu_online(cpu)) |
424 | return 0; | 424 | return 0; |
425 | 425 | ||
426 | pr_debug("CPU%d added\n", cpu); | 426 | pr_debug("CPU%d added\n", cpu); |
427 | 427 | ||
428 | err = sysfs_create_group(&dev->kobj, &mc_attr_group); | 428 | err = sysfs_create_group(&dev->kobj, &mc_attr_group); |
429 | if (err) | 429 | if (err) |
430 | return err; | 430 | return err; |
431 | 431 | ||
432 | if (microcode_init_cpu(cpu, true) == UCODE_ERROR) | 432 | if (microcode_init_cpu(cpu, true) == UCODE_ERROR) |
433 | return -EINVAL; | 433 | return -EINVAL; |
434 | 434 | ||
435 | return err; | 435 | return err; |
436 | } | 436 | } |
437 | 437 | ||
438 | static int mc_device_remove(struct device *dev, struct subsys_interface *sif) | 438 | static int mc_device_remove(struct device *dev, struct subsys_interface *sif) |
439 | { | 439 | { |
440 | int cpu = dev->id; | 440 | int cpu = dev->id; |
441 | 441 | ||
442 | if (!cpu_online(cpu)) | 442 | if (!cpu_online(cpu)) |
443 | return 0; | 443 | return 0; |
444 | 444 | ||
445 | pr_debug("CPU%d removed\n", cpu); | 445 | pr_debug("CPU%d removed\n", cpu); |
446 | microcode_fini_cpu(cpu); | 446 | microcode_fini_cpu(cpu); |
447 | sysfs_remove_group(&dev->kobj, &mc_attr_group); | 447 | sysfs_remove_group(&dev->kobj, &mc_attr_group); |
448 | return 0; | 448 | return 0; |
449 | } | 449 | } |
450 | 450 | ||
451 | static struct subsys_interface mc_cpu_interface = { | 451 | static struct subsys_interface mc_cpu_interface = { |
452 | .name = "microcode", | 452 | .name = "microcode", |
453 | .subsys = &cpu_subsys, | 453 | .subsys = &cpu_subsys, |
454 | .add_dev = mc_device_add, | 454 | .add_dev = mc_device_add, |
455 | .remove_dev = mc_device_remove, | 455 | .remove_dev = mc_device_remove, |
456 | }; | 456 | }; |
457 | 457 | ||
458 | /** | 458 | /** |
459 | * mc_bp_resume - Update boot CPU microcode during resume. | 459 | * mc_bp_resume - Update boot CPU microcode during resume. |
460 | */ | 460 | */ |
461 | static void mc_bp_resume(void) | 461 | static void mc_bp_resume(void) |
462 | { | 462 | { |
463 | int cpu = smp_processor_id(); | 463 | int cpu = smp_processor_id(); |
464 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 464 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
465 | 465 | ||
466 | if (uci->valid && uci->mc) | 466 | if (uci->valid && uci->mc) |
467 | microcode_ops->apply_microcode(cpu); | 467 | microcode_ops->apply_microcode(cpu); |
468 | #ifdef CONFIG_X86_64 | ||
468 | else if (!uci->mc) | 469 | else if (!uci->mc) |
469 | /* | 470 | /* |
470 | * We might resume and not have applied late microcode but still | 471 | * We might resume and not have applied late microcode but still |
471 | * have a newer patch stashed from the early loader. We don't | 472 | * have a newer patch stashed from the early loader. We don't |
472 | * have it in uci->mc so we have to load it the same way we're | 473 | * have it in uci->mc so we have to load it the same way we're |
473 | * applying patches early on the APs. | 474 | * applying patches early on the APs. |
474 | */ | 475 | */ |
475 | load_ucode_ap(); | 476 | load_ucode_ap(); |
477 | #endif | ||
476 | } | 478 | } |
477 | 479 | ||
478 | static struct syscore_ops mc_syscore_ops = { | 480 | static struct syscore_ops mc_syscore_ops = { |
479 | .resume = mc_bp_resume, | 481 | .resume = mc_bp_resume, |
480 | }; | 482 | }; |
481 | 483 | ||
482 | static int | 484 | static int |
483 | mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) | 485 | mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) |
484 | { | 486 | { |
485 | unsigned int cpu = (unsigned long)hcpu; | 487 | unsigned int cpu = (unsigned long)hcpu; |
486 | struct device *dev; | 488 | struct device *dev; |
487 | 489 | ||
488 | dev = get_cpu_device(cpu); | 490 | dev = get_cpu_device(cpu); |
489 | 491 | ||
490 | switch (action & ~CPU_TASKS_FROZEN) { | 492 | switch (action & ~CPU_TASKS_FROZEN) { |
491 | case CPU_ONLINE: | 493 | case CPU_ONLINE: |
492 | microcode_update_cpu(cpu); | 494 | microcode_update_cpu(cpu); |
493 | pr_debug("CPU%d added\n", cpu); | 495 | pr_debug("CPU%d added\n", cpu); |
494 | /* | 496 | /* |
495 | * "break" is missing on purpose here because we want to fall | 497 | * "break" is missing on purpose here because we want to fall |
496 | * through in order to create the sysfs group. | 498 | * through in order to create the sysfs group. |
497 | */ | 499 | */ |
498 | 500 | ||
499 | case CPU_DOWN_FAILED: | 501 | case CPU_DOWN_FAILED: |
500 | if (sysfs_create_group(&dev->kobj, &mc_attr_group)) | 502 | if (sysfs_create_group(&dev->kobj, &mc_attr_group)) |
501 | pr_err("Failed to create group for CPU%d\n", cpu); | 503 | pr_err("Failed to create group for CPU%d\n", cpu); |
502 | break; | 504 | break; |
503 | 505 | ||
504 | case CPU_DOWN_PREPARE: | 506 | case CPU_DOWN_PREPARE: |
505 | /* Suspend is in progress, only remove the interface */ | 507 | /* Suspend is in progress, only remove the interface */ |
506 | sysfs_remove_group(&dev->kobj, &mc_attr_group); | 508 | sysfs_remove_group(&dev->kobj, &mc_attr_group); |
507 | pr_debug("CPU%d removed\n", cpu); | 509 | pr_debug("CPU%d removed\n", cpu); |
508 | break; | 510 | break; |
509 | 511 | ||
510 | /* | 512 | /* |
511 | * case CPU_DEAD: | 513 | * case CPU_DEAD: |
512 | * | 514 | * |
513 | * When a CPU goes offline, don't free up or invalidate the copy of | 515 | * When a CPU goes offline, don't free up or invalidate the copy of |
514 | * the microcode in kernel memory, so that we can reuse it when the | 516 | * the microcode in kernel memory, so that we can reuse it when the |
515 | * CPU comes back online without unnecessarily requesting the userspace | 517 | * CPU comes back online without unnecessarily requesting the userspace |
516 | * for it again. | 518 | * for it again. |
517 | */ | 519 | */ |
518 | } | 520 | } |
519 | 521 | ||
520 | /* The CPU refused to come up during a system resume */ | 522 | /* The CPU refused to come up during a system resume */ |
521 | if (action == CPU_UP_CANCELED_FROZEN) | 523 | if (action == CPU_UP_CANCELED_FROZEN) |
522 | microcode_fini_cpu(cpu); | 524 | microcode_fini_cpu(cpu); |
523 | 525 | ||
524 | return NOTIFY_OK; | 526 | return NOTIFY_OK; |
525 | } | 527 | } |
526 | 528 | ||
527 | static struct notifier_block __refdata mc_cpu_notifier = { | 529 | static struct notifier_block __refdata mc_cpu_notifier = { |
528 | .notifier_call = mc_cpu_callback, | 530 | .notifier_call = mc_cpu_callback, |
529 | }; | 531 | }; |
530 | 532 | ||
531 | #ifdef MODULE | 533 | #ifdef MODULE |
532 | /* Autoload on Intel and AMD systems */ | 534 | /* Autoload on Intel and AMD systems */ |
533 | static const struct x86_cpu_id __initconst microcode_id[] = { | 535 | static const struct x86_cpu_id __initconst microcode_id[] = { |
534 | #ifdef CONFIG_MICROCODE_INTEL | 536 | #ifdef CONFIG_MICROCODE_INTEL |
535 | { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, }, | 537 | { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, }, |
536 | #endif | 538 | #endif |
537 | #ifdef CONFIG_MICROCODE_AMD | 539 | #ifdef CONFIG_MICROCODE_AMD |
538 | { X86_VENDOR_AMD, X86_FAMILY_ANY, X86_MODEL_ANY, }, | 540 | { X86_VENDOR_AMD, X86_FAMILY_ANY, X86_MODEL_ANY, }, |
539 | #endif | 541 | #endif |
540 | {} | 542 | {} |
541 | }; | 543 | }; |
542 | MODULE_DEVICE_TABLE(x86cpu, microcode_id); | 544 | MODULE_DEVICE_TABLE(x86cpu, microcode_id); |
543 | #endif | 545 | #endif |
544 | 546 | ||
545 | static struct attribute *cpu_root_microcode_attrs[] = { | 547 | static struct attribute *cpu_root_microcode_attrs[] = { |
546 | &dev_attr_reload.attr, | 548 | &dev_attr_reload.attr, |
547 | NULL | 549 | NULL |
548 | }; | 550 | }; |
549 | 551 | ||
550 | static struct attribute_group cpu_root_microcode_group = { | 552 | static struct attribute_group cpu_root_microcode_group = { |
551 | .name = "microcode", | 553 | .name = "microcode", |
552 | .attrs = cpu_root_microcode_attrs, | 554 | .attrs = cpu_root_microcode_attrs, |
553 | }; | 555 | }; |
554 | 556 | ||
555 | static int __init microcode_init(void) | 557 | static int __init microcode_init(void) |
556 | { | 558 | { |
557 | struct cpuinfo_x86 *c = &cpu_data(0); | 559 | struct cpuinfo_x86 *c = &cpu_data(0); |
558 | int error; | 560 | int error; |
559 | 561 | ||
560 | if (dis_ucode_ldr) | 562 | if (dis_ucode_ldr) |
561 | return 0; | 563 | return 0; |
562 | 564 | ||
563 | if (c->x86_vendor == X86_VENDOR_INTEL) | 565 | if (c->x86_vendor == X86_VENDOR_INTEL) |
564 | microcode_ops = init_intel_microcode(); | 566 | microcode_ops = init_intel_microcode(); |
565 | else if (c->x86_vendor == X86_VENDOR_AMD) | 567 | else if (c->x86_vendor == X86_VENDOR_AMD) |
566 | microcode_ops = init_amd_microcode(); | 568 | microcode_ops = init_amd_microcode(); |
567 | else | 569 | else |
568 | pr_err("no support for this CPU vendor\n"); | 570 | pr_err("no support for this CPU vendor\n"); |
569 | 571 | ||
570 | if (!microcode_ops) | 572 | if (!microcode_ops) |
571 | return -ENODEV; | 573 | return -ENODEV; |
572 | 574 | ||
573 | microcode_pdev = platform_device_register_simple("microcode", -1, | 575 | microcode_pdev = platform_device_register_simple("microcode", -1, |
574 | NULL, 0); | 576 | NULL, 0); |
575 | if (IS_ERR(microcode_pdev)) | 577 | if (IS_ERR(microcode_pdev)) |
576 | return PTR_ERR(microcode_pdev); | 578 | return PTR_ERR(microcode_pdev); |
577 | 579 | ||
578 | get_online_cpus(); | 580 | get_online_cpus(); |
579 | mutex_lock(µcode_mutex); | 581 | mutex_lock(µcode_mutex); |
580 | 582 | ||
581 | error = subsys_interface_register(&mc_cpu_interface); | 583 | error = subsys_interface_register(&mc_cpu_interface); |
582 | if (!error) | 584 | if (!error) |
583 | perf_check_microcode(); | 585 | perf_check_microcode(); |
584 | mutex_unlock(µcode_mutex); | 586 | mutex_unlock(µcode_mutex); |
585 | put_online_cpus(); | 587 | put_online_cpus(); |
586 | 588 | ||
587 | if (error) | 589 | if (error) |
588 | goto out_pdev; | 590 | goto out_pdev; |
589 | 591 | ||
590 | error = sysfs_create_group(&cpu_subsys.dev_root->kobj, | 592 | error = sysfs_create_group(&cpu_subsys.dev_root->kobj, |
591 | &cpu_root_microcode_group); | 593 | &cpu_root_microcode_group); |
592 | 594 | ||
593 | if (error) { | 595 | if (error) { |
594 | pr_err("Error creating microcode group!\n"); | 596 | pr_err("Error creating microcode group!\n"); |
595 | goto out_driver; | 597 | goto out_driver; |
596 | } | 598 | } |
597 | 599 | ||
598 | error = microcode_dev_init(); | 600 | error = microcode_dev_init(); |
599 | if (error) | 601 | if (error) |
600 | goto out_ucode_group; | 602 | goto out_ucode_group; |
601 | 603 | ||
602 | register_syscore_ops(&mc_syscore_ops); | 604 | register_syscore_ops(&mc_syscore_ops); |
603 | register_hotcpu_notifier(&mc_cpu_notifier); | 605 | register_hotcpu_notifier(&mc_cpu_notifier); |
604 | 606 | ||
605 | pr_info("Microcode Update Driver: v" MICROCODE_VERSION | 607 | pr_info("Microcode Update Driver: v" MICROCODE_VERSION |
606 | " <tigran@aivazian.fsnet.co.uk>, Peter Oruba\n"); | 608 | " <tigran@aivazian.fsnet.co.uk>, Peter Oruba\n"); |
607 | 609 | ||
608 | return 0; | 610 | return 0; |
609 | 611 | ||
610 | out_ucode_group: | 612 | out_ucode_group: |
611 | sysfs_remove_group(&cpu_subsys.dev_root->kobj, | 613 | sysfs_remove_group(&cpu_subsys.dev_root->kobj, |
612 | &cpu_root_microcode_group); | 614 | &cpu_root_microcode_group); |
613 | 615 | ||
614 | out_driver: | 616 | out_driver: |
615 | get_online_cpus(); | 617 | get_online_cpus(); |
616 | mutex_lock(µcode_mutex); | 618 | mutex_lock(µcode_mutex); |
617 | 619 | ||
618 | subsys_interface_unregister(&mc_cpu_interface); | 620 | subsys_interface_unregister(&mc_cpu_interface); |
619 | 621 | ||
620 | mutex_unlock(µcode_mutex); | 622 | mutex_unlock(µcode_mutex); |
621 | put_online_cpus(); | 623 | put_online_cpus(); |
622 | 624 | ||
623 | out_pdev: | 625 | out_pdev: |
624 | platform_device_unregister(microcode_pdev); | 626 | platform_device_unregister(microcode_pdev); |
625 | return error; | 627 | return error; |
626 | 628 | ||
627 | } | 629 | } |
628 | module_init(microcode_init); | 630 | module_init(microcode_init); |
629 | 631 | ||
630 | static void __exit microcode_exit(void) | 632 | static void __exit microcode_exit(void) |
631 | { | 633 | { |
632 | struct cpuinfo_x86 *c = &cpu_data(0); | 634 | struct cpuinfo_x86 *c = &cpu_data(0); |
633 | 635 | ||
634 | microcode_dev_exit(); | 636 | microcode_dev_exit(); |
635 | 637 | ||
636 | unregister_hotcpu_notifier(&mc_cpu_notifier); | 638 | unregister_hotcpu_notifier(&mc_cpu_notifier); |
637 | unregister_syscore_ops(&mc_syscore_ops); | 639 | unregister_syscore_ops(&mc_syscore_ops); |
638 | 640 | ||
639 | sysfs_remove_group(&cpu_subsys.dev_root->kobj, | 641 | sysfs_remove_group(&cpu_subsys.dev_root->kobj, |
640 | &cpu_root_microcode_group); | 642 | &cpu_root_microcode_group); |
641 | 643 | ||
642 | get_online_cpus(); | 644 | get_online_cpus(); |
643 | mutex_lock(µcode_mutex); | 645 | mutex_lock(µcode_mutex); |
644 | 646 | ||
645 | subsys_interface_unregister(&mc_cpu_interface); | 647 | subsys_interface_unregister(&mc_cpu_interface); |
646 | 648 | ||
647 | mutex_unlock(µcode_mutex); | 649 | mutex_unlock(µcode_mutex); |
648 | put_online_cpus(); | 650 | put_online_cpus(); |
649 | 651 | ||
650 | platform_device_unregister(microcode_pdev); | 652 | platform_device_unregister(microcode_pdev); |
651 | 653 | ||
652 | microcode_ops = NULL; | 654 | microcode_ops = NULL; |
653 | 655 | ||
654 | if (c->x86_vendor == X86_VENDOR_AMD) | 656 | if (c->x86_vendor == X86_VENDOR_AMD) |
655 | exit_amd_microcode(); | 657 | exit_amd_microcode(); |
656 | 658 | ||
657 | pr_info("Microcode Update Driver: v" MICROCODE_VERSION " removed.\n"); | 659 | pr_info("Microcode Update Driver: v" MICROCODE_VERSION " removed.\n"); |
658 | } | 660 | } |
659 | module_exit(microcode_exit); | 661 | module_exit(microcode_exit); |
660 | 662 |