Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Intel CPU Microcode Update Driver for Linux |
| 3 | * |
Tigran Aivazian | 6968826 | 2006-12-13 00:35:14 -0800 | [diff] [blame] | 4 | * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk> |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 5 | * 2006 Shaohua Li <shaohua.li@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This driver allows to upgrade microcode on Intel processors |
| 8 | * belonging to IA-32 family - PentiumPro, Pentium II, |
| 9 | * Pentium III, Xeon, Pentium 4, etc. |
| 10 | * |
| 11 | * Reference: Section 8.10 of Volume III, Intel Pentium 4 Manual, |
| 12 | * Order Number 245472 or free download from: |
| 13 | * |
| 14 | * http://developer.intel.com/design/pentium4/manuals/245472.htm |
| 15 | * |
| 16 | * For more information, go to http://www.urbanmyth.org/microcode |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License |
| 20 | * as published by the Free Software Foundation; either version |
| 21 | * 2 of the License, or (at your option) any later version. |
| 22 | * |
| 23 | * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com> |
| 24 | * Initial release. |
| 25 | * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com> |
| 26 | * Added read() support + cleanups. |
| 27 | * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com> |
| 28 | * Added 'device trimming' support. open(O_WRONLY) zeroes |
| 29 | * and frees the saved copy of applied microcode. |
| 30 | * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com> |
| 31 | * Made to use devfs (/dev/cpu/microcode) + cleanups. |
| 32 | * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com> |
| 33 | * Added misc device support (now uses both devfs and misc). |
| 34 | * Added MICROCODE_IOCFREE ioctl to clear memory. |
| 35 | * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com> |
| 36 | * Messages for error cases (non Intel & no suitable microcode). |
| 37 | * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com> |
| 38 | * Removed ->release(). Removed exclusive open and status bitmap. |
| 39 | * Added microcode_rwsem to serialize read()/write()/ioctl(). |
| 40 | * Removed global kernel lock usage. |
| 41 | * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com> |
| 42 | * Write 0 to 0x8B msr and then cpuid before reading revision, |
| 43 | * so that it works even if there were no update done by the |
| 44 | * BIOS. Otherwise, reading from 0x8B gives junk (which happened |
| 45 | * to be 0 on my machine which is why it worked even when I |
| 46 | * disabled update by the BIOS) |
| 47 | * Thanks to Eric W. Biederman <ebiederman@lnxi.com> for the fix. |
| 48 | * 1.08 11 Dec 2000, Richard Schaal <richard.schaal@intel.com> and |
| 49 | * Tigran Aivazian <tigran@veritas.com> |
| 50 | * Intel Pentium 4 processor support and bugfixes. |
| 51 | * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com> |
| 52 | * Bugfix for HT (Hyper-Threading) enabled processors |
| 53 | * whereby processor resources are shared by all logical processors |
| 54 | * in a single CPU package. |
| 55 | * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and |
| 56 | * Tigran Aivazian <tigran@veritas.com>, |
| 57 | * Serialize updates as required on HT processors due to speculative |
| 58 | * nature of implementation. |
| 59 | * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com> |
| 60 | * Fix the panic when writing zero-length microcode chunk. |
| 61 | * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, |
| 62 | * Jun Nakajima <jun.nakajima@intel.com> |
| 63 | * Support for the microcode updates in the new format. |
| 64 | * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com> |
| 65 | * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl |
| 66 | * because we no longer hold a copy of applied microcode |
| 67 | * in kernel memory. |
| 68 | * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com> |
| 69 | * Fix sigmatch() macro to handle old CPUs with pf == 0. |
| 70 | * Thanks to Stuart Swales for pointing out this bug. |
| 71 | */ |
| 72 | |
| 73 | //#define DEBUG /* pr_debug */ |
Randy Dunlap | a941564 | 2006-01-11 12:17:48 -0800 | [diff] [blame] | 74 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #include <linux/kernel.h> |
| 76 | #include <linux/init.h> |
| 77 | #include <linux/sched.h> |
Dave Jones | 5cf6c54 | 2006-02-28 16:58:53 -0800 | [diff] [blame] | 78 | #include <linux/cpumask.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #include <linux/module.h> |
| 80 | #include <linux/slab.h> |
| 81 | #include <linux/vmalloc.h> |
| 82 | #include <linux/miscdevice.h> |
| 83 | #include <linux/spinlock.h> |
| 84 | #include <linux/mm.h> |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 85 | #include <linux/mutex.h> |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 86 | #include <linux/cpu.h> |
| 87 | #include <linux/firmware.h> |
| 88 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | #include <asm/msr.h> |
| 91 | #include <asm/uaccess.h> |
| 92 | #include <asm/processor.h> |
| 93 | |
| 94 | MODULE_DESCRIPTION("Intel CPU (IA-32) Microcode Update Driver"); |
Tigran Aivazian | 6968826 | 2006-12-13 00:35:14 -0800 | [diff] [blame] | 95 | MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | MODULE_LICENSE("GPL"); |
| 97 | |
Jan Beulich | ba528f2 | 2006-06-23 02:04:19 -0700 | [diff] [blame] | 98 | #define MICROCODE_VERSION "1.14a" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | #define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */ |
| 101 | #define MC_HEADER_SIZE (sizeof (microcode_header_t)) /* 48 bytes */ |
| 102 | #define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */ |
| 103 | #define EXT_HEADER_SIZE (sizeof (struct extended_sigtable)) /* 20 bytes */ |
| 104 | #define EXT_SIGNATURE_SIZE (sizeof (struct extended_signature)) /* 12 bytes */ |
| 105 | #define DWSIZE (sizeof (u32)) |
| 106 | #define get_totalsize(mc) \ |
| 107 | (((microcode_t *)mc)->hdr.totalsize ? \ |
| 108 | ((microcode_t *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE) |
| 109 | #define get_datasize(mc) \ |
| 110 | (((microcode_t *)mc)->hdr.datasize ? \ |
| 111 | ((microcode_t *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE) |
| 112 | |
| 113 | #define sigmatch(s1, s2, p1, p2) \ |
| 114 | (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0)))) |
| 115 | |
| 116 | #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) |
| 117 | |
| 118 | /* serialize access to the physical write to MSR 0x79 */ |
| 119 | static DEFINE_SPINLOCK(microcode_update_lock); |
| 120 | |
| 121 | /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 122 | static DEFINE_MUTEX(microcode_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static struct ucode_cpu_info { |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 125 | int valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | unsigned int sig; |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 127 | unsigned int pf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | unsigned int rev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | microcode_t *mc; |
| 130 | } ucode_cpu_info[NR_CPUS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 132 | static void collect_cpu_info(int cpu_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | struct cpuinfo_x86 *c = cpu_data + cpu_num; |
| 135 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; |
| 136 | unsigned int val[2]; |
| 137 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 138 | /* We should bind the task to the CPU */ |
| 139 | BUG_ON(raw_smp_processor_id() != cpu_num); |
| 140 | uci->pf = uci->rev = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | uci->mc = NULL; |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 142 | uci->valid = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 || |
| 145 | cpu_has(c, X86_FEATURE_IA64)) { |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 146 | printk(KERN_ERR "microcode: CPU%d not a capable Intel " |
| 147 | "processor\n", cpu_num); |
| 148 | uci->valid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | return; |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 152 | uci->sig = cpuid_eax(0x00000001); |
| 153 | |
| 154 | if ((c->x86_model >= 5) || (c->x86 > 6)) { |
| 155 | /* get processor flags from MSR 0x17 */ |
| 156 | rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]); |
| 157 | uci->pf = 1 << ((val[1] >> 18) & 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | wrmsr(MSR_IA32_UCODE_REV, 0, 0); |
Zachary Amsden | 245067d | 2005-09-03 15:56:37 -0700 | [diff] [blame] | 161 | /* see notes above for revision 1.07. Apparent chip bug */ |
Andi Kleen | 487472b | 2006-01-11 22:45:27 +0100 | [diff] [blame] | 162 | sync_core(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* get the current revision from MSR 0x8B */ |
| 164 | rdmsr(MSR_IA32_UCODE_REV, val[0], uci->rev); |
| 165 | pr_debug("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n", |
| 166 | uci->sig, uci->pf, uci->rev); |
| 167 | } |
| 168 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 169 | static inline int microcode_update_match(int cpu_num, |
| 170 | microcode_header_t *mc_header, int sig, int pf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; |
| 173 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 174 | if (!sigmatch(sig, uci->sig, pf, uci->pf) |
| 175 | || mc_header->rev <= uci->rev) |
| 176 | return 0; |
| 177 | return 1; |
| 178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 180 | static int microcode_sanity_check(void *mc) |
| 181 | { |
| 182 | microcode_header_t *mc_header = mc; |
| 183 | struct extended_sigtable *ext_header = NULL; |
| 184 | struct extended_signature *ext_sig; |
| 185 | unsigned long total_size, data_size, ext_table_size; |
| 186 | int sum, orig_sum, ext_sigcount = 0, i; |
| 187 | |
| 188 | total_size = get_totalsize(mc_header); |
| 189 | data_size = get_datasize(mc_header); |
Shaohua Li | bd8e39f | 2006-09-27 01:50:54 -0700 | [diff] [blame] | 190 | if (data_size + MC_HEADER_SIZE > total_size) { |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 191 | printk(KERN_ERR "microcode: error! " |
| 192 | "Bad data size in microcode data file\n"); |
| 193 | return -EINVAL; |
| 194 | } |
| 195 | |
| 196 | if (mc_header->ldrver != 1 || mc_header->hdrver != 1) { |
| 197 | printk(KERN_ERR "microcode: error! " |
| 198 | "Unknown microcode update format\n"); |
| 199 | return -EINVAL; |
| 200 | } |
| 201 | ext_table_size = total_size - (MC_HEADER_SIZE + data_size); |
| 202 | if (ext_table_size) { |
| 203 | if ((ext_table_size < EXT_HEADER_SIZE) |
| 204 | || ((ext_table_size - EXT_HEADER_SIZE) % EXT_SIGNATURE_SIZE)) { |
| 205 | printk(KERN_ERR "microcode: error! " |
| 206 | "Small exttable size in microcode data file\n"); |
| 207 | return -EINVAL; |
Jan Beulich | ba528f2 | 2006-06-23 02:04:19 -0700 | [diff] [blame] | 208 | } |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 209 | ext_header = mc + MC_HEADER_SIZE + data_size; |
| 210 | if (ext_table_size != exttable_size(ext_header)) { |
| 211 | printk(KERN_ERR "microcode: error! " |
| 212 | "Bad exttable size in microcode data file\n"); |
| 213 | return -EFAULT; |
Jan Beulich | ba528f2 | 2006-06-23 02:04:19 -0700 | [diff] [blame] | 214 | } |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 215 | ext_sigcount = ext_header->count; |
| 216 | } |
| 217 | |
| 218 | /* check extended table checksum */ |
| 219 | if (ext_table_size) { |
| 220 | int ext_table_sum = 0; |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 221 | int *ext_tablep = (int *)ext_header; |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 222 | |
| 223 | i = ext_table_size / DWSIZE; |
| 224 | while (i--) |
| 225 | ext_table_sum += ext_tablep[i]; |
| 226 | if (ext_table_sum) { |
| 227 | printk(KERN_WARNING "microcode: aborting, " |
| 228 | "bad extended signature table checksum\n"); |
| 229 | return -EINVAL; |
Jan Beulich | ba528f2 | 2006-06-23 02:04:19 -0700 | [diff] [blame] | 230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 232 | |
| 233 | /* calculate the checksum */ |
| 234 | orig_sum = 0; |
| 235 | i = (MC_HEADER_SIZE + data_size) / DWSIZE; |
| 236 | while (i--) |
| 237 | orig_sum += ((int *)mc)[i]; |
| 238 | if (orig_sum) { |
| 239 | printk(KERN_ERR "microcode: aborting, bad checksum\n"); |
| 240 | return -EINVAL; |
| 241 | } |
| 242 | if (!ext_table_size) |
| 243 | return 0; |
| 244 | /* check extended signature checksum */ |
| 245 | for (i = 0; i < ext_sigcount; i++) { |
| 246 | ext_sig = (struct extended_signature *)((void *)ext_header |
| 247 | + EXT_HEADER_SIZE + EXT_SIGNATURE_SIZE * i); |
| 248 | sum = orig_sum |
| 249 | - (mc_header->sig + mc_header->pf + mc_header->cksum) |
| 250 | + (ext_sig->sig + ext_sig->pf + ext_sig->cksum); |
| 251 | if (sum) { |
| 252 | printk(KERN_ERR "microcode: aborting, bad checksum\n"); |
| 253 | return -EINVAL; |
| 254 | } |
| 255 | } |
| 256 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 259 | /* |
| 260 | * return 0 - no update found |
| 261 | * return 1 - found update |
| 262 | * return < 0 - error |
| 263 | */ |
| 264 | static int get_maching_microcode(void *mc, int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 266 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
| 267 | microcode_header_t *mc_header = mc; |
| 268 | struct extended_sigtable *ext_header; |
| 269 | unsigned long total_size = get_totalsize(mc_header); |
| 270 | int ext_sigcount, i; |
| 271 | struct extended_signature *ext_sig; |
| 272 | void *new_mc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 274 | if (microcode_update_match(cpu, mc_header, |
| 275 | mc_header->sig, mc_header->pf)) |
| 276 | goto find; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 278 | if (total_size <= get_datasize(mc_header) + MC_HEADER_SIZE) |
| 279 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 281 | ext_header = (struct extended_sigtable *)(mc + |
| 282 | get_datasize(mc_header) + MC_HEADER_SIZE); |
| 283 | ext_sigcount = ext_header->count; |
| 284 | ext_sig = (struct extended_signature *)((void *)ext_header |
| 285 | + EXT_HEADER_SIZE); |
| 286 | for (i = 0; i < ext_sigcount; i++) { |
| 287 | if (microcode_update_match(cpu, mc_header, |
| 288 | ext_sig->sig, ext_sig->pf)) |
| 289 | goto find; |
| 290 | ext_sig++; |
| 291 | } |
| 292 | return 0; |
| 293 | find: |
| 294 | pr_debug("microcode: CPU %d found a matching microcode update with" |
| 295 | " version 0x%x (current=0x%x)\n", cpu, mc_header->rev,uci->rev); |
| 296 | new_mc = vmalloc(total_size); |
| 297 | if (!new_mc) { |
| 298 | printk(KERN_ERR "microcode: error! Can not allocate memory\n"); |
| 299 | return -ENOMEM; |
| 300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 302 | /* free previous update file */ |
| 303 | vfree(uci->mc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 305 | memcpy(new_mc, mc, total_size); |
| 306 | uci->mc = new_mc; |
| 307 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 310 | static void apply_microcode(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
| 312 | unsigned long flags; |
| 313 | unsigned int val[2]; |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 314 | int cpu_num = raw_smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num; |
| 316 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 317 | /* We should bind the task to the CPU */ |
| 318 | BUG_ON(cpu_num != cpu); |
| 319 | |
| 320 | if (uci->mc == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | /* serialize access to the physical write to MSR 0x79 */ |
| 324 | spin_lock_irqsave(µcode_update_lock, flags); |
| 325 | |
| 326 | /* write microcode via MSR 0x79 */ |
| 327 | wrmsr(MSR_IA32_UCODE_WRITE, |
| 328 | (unsigned long) uci->mc->bits, |
| 329 | (unsigned long) uci->mc->bits >> 16 >> 16); |
| 330 | wrmsr(MSR_IA32_UCODE_REV, 0, 0); |
| 331 | |
Zachary Amsden | 245067d | 2005-09-03 15:56:37 -0700 | [diff] [blame] | 332 | /* see notes above for revision 1.07. Apparent chip bug */ |
Andi Kleen | 487472b | 2006-01-11 22:45:27 +0100 | [diff] [blame] | 333 | sync_core(); |
Zachary Amsden | 245067d | 2005-09-03 15:56:37 -0700 | [diff] [blame] | 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* get the current revision from MSR 0x8B */ |
| 336 | rdmsr(MSR_IA32_UCODE_REV, val[0], val[1]); |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | spin_unlock_irqrestore(µcode_update_lock, flags); |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 339 | if (val[1] != uci->mc->hdr.rev) { |
| 340 | printk(KERN_ERR "microcode: CPU%d updated from revision " |
| 341 | "0x%x to 0x%x failed\n", cpu_num, uci->rev, val[1]); |
| 342 | return; |
| 343 | } |
| 344 | pr_debug("microcode: CPU%d updated from revision " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | "0x%x to 0x%x, date = %08x \n", |
| 346 | cpu_num, uci->rev, val[1], uci->mc->hdr.date); |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 347 | uci->rev = val[1]; |
| 348 | } |
| 349 | |
| 350 | #ifdef CONFIG_MICROCODE_OLD_INTERFACE |
| 351 | static void __user *user_buffer; /* user area microcode data buffer */ |
| 352 | static unsigned int user_buffer_size; /* it's size */ |
| 353 | |
| 354 | static long get_next_ucode(void **mc, long offset) |
| 355 | { |
| 356 | microcode_header_t mc_header; |
| 357 | unsigned long total_size; |
| 358 | |
| 359 | /* No more data */ |
| 360 | if (offset >= user_buffer_size) |
| 361 | return 0; |
| 362 | if (copy_from_user(&mc_header, user_buffer + offset, MC_HEADER_SIZE)) { |
| 363 | printk(KERN_ERR "microcode: error! Can not read user data\n"); |
| 364 | return -EFAULT; |
| 365 | } |
| 366 | total_size = get_totalsize(&mc_header); |
Shaohua Li | bd8e39f | 2006-09-27 01:50:54 -0700 | [diff] [blame] | 367 | if (offset + total_size > user_buffer_size) { |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 368 | printk(KERN_ERR "microcode: error! Bad total size in microcode " |
| 369 | "data file\n"); |
| 370 | return -EINVAL; |
| 371 | } |
| 372 | *mc = vmalloc(total_size); |
| 373 | if (!*mc) |
| 374 | return -ENOMEM; |
| 375 | if (copy_from_user(*mc, user_buffer + offset, total_size)) { |
| 376 | printk(KERN_ERR "microcode: error! Can not read user data\n"); |
| 377 | vfree(*mc); |
| 378 | return -EFAULT; |
| 379 | } |
| 380 | return offset + total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static int do_microcode_update (void) |
| 384 | { |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 385 | long cursor = 0; |
| 386 | int error = 0; |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 387 | void *new_mc; |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 388 | int cpu; |
| 389 | cpumask_t old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 391 | old = current->cpus_allowed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 393 | while ((cursor = get_next_ucode(&new_mc, cursor)) > 0) { |
| 394 | error = microcode_sanity_check(new_mc); |
| 395 | if (error) |
| 396 | goto out; |
| 397 | /* |
| 398 | * It's possible the data file has multiple matching ucode, |
| 399 | * lets keep searching till the latest version |
| 400 | */ |
| 401 | for_each_online_cpu(cpu) { |
| 402 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 404 | if (!uci->valid) |
| 405 | continue; |
| 406 | set_cpus_allowed(current, cpumask_of_cpu(cpu)); |
| 407 | error = get_maching_microcode(new_mc, cpu); |
| 408 | if (error < 0) |
| 409 | goto out; |
| 410 | if (error == 1) |
| 411 | apply_microcode(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 413 | vfree(new_mc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | out: |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 416 | if (cursor > 0) |
| 417 | vfree(new_mc); |
| 418 | if (cursor < 0) |
| 419 | error = cursor; |
| 420 | set_cpus_allowed(current, old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | return error; |
| 422 | } |
| 423 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 424 | static int microcode_open (struct inode *unused1, struct file *unused2) |
| 425 | { |
| 426 | return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; |
| 427 | } |
| 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | static ssize_t microcode_write (struct file *file, const char __user *buf, size_t len, loff_t *ppos) |
| 430 | { |
| 431 | ssize_t ret; |
| 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | if ((len >> PAGE_SHIFT) > num_physpages) { |
| 434 | printk(KERN_ERR "microcode: too much data (max %ld pages)\n", num_physpages); |
| 435 | return -EINVAL; |
| 436 | } |
| 437 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 438 | lock_cpu_hotplug(); |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 439 | mutex_lock(µcode_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | user_buffer = (void __user *) buf; |
| 442 | user_buffer_size = (int) len; |
| 443 | |
| 444 | ret = do_microcode_update(); |
| 445 | if (!ret) |
| 446 | ret = (ssize_t)len; |
| 447 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 448 | mutex_unlock(µcode_mutex); |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 449 | unlock_cpu_hotplug(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | return ret; |
| 452 | } |
| 453 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 454 | static const struct file_operations microcode_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | .owner = THIS_MODULE, |
| 456 | .write = microcode_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | .open = microcode_open, |
| 458 | }; |
| 459 | |
| 460 | static struct miscdevice microcode_dev = { |
| 461 | .minor = MICROCODE_MINOR, |
| 462 | .name = "microcode", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | .fops = µcode_fops, |
| 464 | }; |
| 465 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 466 | static int __init microcode_dev_init (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
| 468 | int error; |
| 469 | |
| 470 | error = misc_register(µcode_dev); |
| 471 | if (error) { |
| 472 | printk(KERN_ERR |
| 473 | "microcode: can't misc_register on minor=%d\n", |
| 474 | MICROCODE_MINOR); |
| 475 | return error; |
| 476 | } |
| 477 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | static void __exit microcode_dev_exit (void) |
| 482 | { |
| 483 | misc_deregister(µcode_dev); |
| 484 | } |
| 485 | |
| 486 | MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); |
| 487 | #else |
| 488 | #define microcode_dev_init() 0 |
| 489 | #define microcode_dev_exit() do { } while(0) |
| 490 | #endif |
| 491 | |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 492 | static long get_next_ucode_from_buffer(void **mc, void *buf, |
| 493 | unsigned long size, long offset) |
| 494 | { |
| 495 | microcode_header_t *mc_header; |
| 496 | unsigned long total_size; |
| 497 | |
| 498 | /* No more data */ |
| 499 | if (offset >= size) |
| 500 | return 0; |
| 501 | mc_header = (microcode_header_t *)(buf + offset); |
| 502 | total_size = get_totalsize(mc_header); |
| 503 | |
Shaohua Li | bd8e39f | 2006-09-27 01:50:54 -0700 | [diff] [blame] | 504 | if (offset + total_size > size) { |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 505 | printk(KERN_ERR "microcode: error! Bad data in microcode data file\n"); |
| 506 | return -EINVAL; |
| 507 | } |
| 508 | |
| 509 | *mc = vmalloc(total_size); |
| 510 | if (!*mc) { |
| 511 | printk(KERN_ERR "microcode: error! Can not allocate memory\n"); |
| 512 | return -ENOMEM; |
| 513 | } |
| 514 | memcpy(*mc, buf + offset, total_size); |
| 515 | return offset + total_size; |
| 516 | } |
| 517 | |
| 518 | /* fake device for request_firmware */ |
| 519 | static struct platform_device *microcode_pdev; |
| 520 | |
| 521 | static int cpu_request_microcode(int cpu) |
| 522 | { |
| 523 | char name[30]; |
| 524 | struct cpuinfo_x86 *c = cpu_data + cpu; |
| 525 | const struct firmware *firmware; |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 526 | void *buf; |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 527 | unsigned long size; |
| 528 | long offset = 0; |
| 529 | int error; |
| 530 | void *mc; |
| 531 | |
| 532 | /* We should bind the task to the CPU */ |
| 533 | BUG_ON(cpu != raw_smp_processor_id()); |
| 534 | sprintf(name,"intel-ucode/%02x-%02x-%02x", |
| 535 | c->x86, c->x86_model, c->x86_mask); |
| 536 | error = request_firmware(&firmware, name, µcode_pdev->dev); |
| 537 | if (error) { |
| 538 | pr_debug("ucode data file %s load failed\n", name); |
| 539 | return error; |
| 540 | } |
| 541 | buf = (void *)firmware->data; |
| 542 | size = firmware->size; |
| 543 | while ((offset = get_next_ucode_from_buffer(&mc, buf, size, offset)) |
| 544 | > 0) { |
| 545 | error = microcode_sanity_check(mc); |
| 546 | if (error) |
| 547 | break; |
| 548 | error = get_maching_microcode(mc, cpu); |
| 549 | if (error < 0) |
| 550 | break; |
| 551 | /* |
| 552 | * It's possible the data file has multiple matching ucode, |
| 553 | * lets keep searching till the latest version |
| 554 | */ |
| 555 | if (error == 1) { |
| 556 | apply_microcode(cpu); |
| 557 | error = 0; |
| 558 | } |
| 559 | vfree(mc); |
| 560 | } |
| 561 | if (offset > 0) |
| 562 | vfree(mc); |
| 563 | if (offset < 0) |
| 564 | error = offset; |
| 565 | release_firmware(firmware); |
| 566 | |
| 567 | return error; |
| 568 | } |
| 569 | |
| 570 | static void microcode_init_cpu(int cpu) |
| 571 | { |
| 572 | cpumask_t old; |
| 573 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
| 574 | |
| 575 | old = current->cpus_allowed; |
| 576 | |
| 577 | set_cpus_allowed(current, cpumask_of_cpu(cpu)); |
| 578 | mutex_lock(µcode_mutex); |
| 579 | collect_cpu_info(cpu); |
Arjan van de Ven | d654c67 | 2006-11-08 17:44:37 -0800 | [diff] [blame] | 580 | if (uci->valid && system_state == SYSTEM_RUNNING) |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 581 | cpu_request_microcode(cpu); |
| 582 | mutex_unlock(µcode_mutex); |
| 583 | set_cpus_allowed(current, old); |
| 584 | } |
| 585 | |
| 586 | static void microcode_fini_cpu(int cpu) |
| 587 | { |
| 588 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
| 589 | |
| 590 | mutex_lock(µcode_mutex); |
| 591 | uci->valid = 0; |
| 592 | vfree(uci->mc); |
| 593 | uci->mc = NULL; |
| 594 | mutex_unlock(µcode_mutex); |
| 595 | } |
| 596 | |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 597 | static ssize_t reload_store(struct sys_device *dev, const char *buf, size_t sz) |
| 598 | { |
| 599 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; |
| 600 | char *end; |
| 601 | unsigned long val = simple_strtoul(buf, &end, 0); |
| 602 | int err = 0; |
| 603 | int cpu = dev->id; |
| 604 | |
| 605 | if (end == buf) |
| 606 | return -EINVAL; |
| 607 | if (val == 1) { |
| 608 | cpumask_t old; |
| 609 | |
| 610 | old = current->cpus_allowed; |
| 611 | |
| 612 | lock_cpu_hotplug(); |
| 613 | set_cpus_allowed(current, cpumask_of_cpu(cpu)); |
| 614 | |
| 615 | mutex_lock(µcode_mutex); |
| 616 | if (uci->valid) |
| 617 | err = cpu_request_microcode(cpu); |
| 618 | mutex_unlock(µcode_mutex); |
| 619 | unlock_cpu_hotplug(); |
| 620 | set_cpus_allowed(current, old); |
| 621 | } |
| 622 | if (err) |
| 623 | return err; |
| 624 | return sz; |
| 625 | } |
| 626 | |
| 627 | static ssize_t version_show(struct sys_device *dev, char *buf) |
| 628 | { |
| 629 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; |
| 630 | |
| 631 | return sprintf(buf, "0x%x\n", uci->rev); |
| 632 | } |
| 633 | |
| 634 | static ssize_t pf_show(struct sys_device *dev, char *buf) |
| 635 | { |
| 636 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; |
| 637 | |
| 638 | return sprintf(buf, "0x%x\n", uci->pf); |
| 639 | } |
| 640 | |
| 641 | static SYSDEV_ATTR(reload, 0200, NULL, reload_store); |
| 642 | static SYSDEV_ATTR(version, 0400, version_show, NULL); |
| 643 | static SYSDEV_ATTR(processor_flags, 0400, pf_show, NULL); |
| 644 | |
| 645 | static struct attribute *mc_default_attrs[] = { |
| 646 | &attr_reload.attr, |
| 647 | &attr_version.attr, |
| 648 | &attr_processor_flags.attr, |
| 649 | NULL |
| 650 | }; |
| 651 | |
| 652 | static struct attribute_group mc_attr_group = { |
| 653 | .attrs = mc_default_attrs, |
| 654 | .name = "microcode", |
| 655 | }; |
| 656 | |
| 657 | static int mc_sysdev_add(struct sys_device *sys_dev) |
| 658 | { |
Jeff Garzik | 2e3ad8a | 2006-10-11 01:21:53 -0700 | [diff] [blame] | 659 | int err, cpu = sys_dev->id; |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 660 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
| 661 | |
| 662 | if (!cpu_online(cpu)) |
| 663 | return 0; |
Jeff Garzik | 2e3ad8a | 2006-10-11 01:21:53 -0700 | [diff] [blame] | 664 | |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 665 | pr_debug("Microcode:CPU %d added\n", cpu); |
| 666 | memset(uci, 0, sizeof(*uci)); |
Jeff Garzik | 2e3ad8a | 2006-10-11 01:21:53 -0700 | [diff] [blame] | 667 | |
| 668 | err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group); |
| 669 | if (err) |
| 670 | return err; |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 671 | |
| 672 | microcode_init_cpu(cpu); |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | static int mc_sysdev_remove(struct sys_device *sys_dev) |
| 677 | { |
| 678 | int cpu = sys_dev->id; |
| 679 | |
| 680 | if (!cpu_online(cpu)) |
| 681 | return 0; |
| 682 | pr_debug("Microcode:CPU %d removed\n", cpu); |
| 683 | microcode_fini_cpu(cpu); |
| 684 | sysfs_remove_group(&sys_dev->kobj, &mc_attr_group); |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static int mc_sysdev_resume(struct sys_device *dev) |
| 689 | { |
| 690 | int cpu = dev->id; |
| 691 | |
| 692 | if (!cpu_online(cpu)) |
| 693 | return 0; |
| 694 | pr_debug("Microcode:CPU %d resumed\n", cpu); |
| 695 | /* only CPU 0 will apply ucode here */ |
| 696 | apply_microcode(0); |
| 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | static struct sysdev_driver mc_sysdev_driver = { |
| 701 | .add = mc_sysdev_add, |
| 702 | .remove = mc_sysdev_remove, |
| 703 | .resume = mc_sysdev_resume, |
| 704 | }; |
| 705 | |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 706 | static __cpuinit int |
| 707 | mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) |
| 708 | { |
| 709 | unsigned int cpu = (unsigned long)hcpu; |
| 710 | struct sys_device *sys_dev; |
| 711 | |
| 712 | sys_dev = get_cpu_sysdev(cpu); |
| 713 | switch (action) { |
| 714 | case CPU_ONLINE: |
| 715 | case CPU_DOWN_FAILED: |
| 716 | mc_sysdev_add(sys_dev); |
| 717 | break; |
| 718 | case CPU_DOWN_PREPARE: |
| 719 | mc_sysdev_remove(sys_dev); |
| 720 | break; |
| 721 | } |
| 722 | return NOTIFY_OK; |
| 723 | } |
| 724 | |
Jean Delvare | be31f9c | 2006-12-22 01:10:19 -0800 | [diff] [blame] | 725 | static struct notifier_block __cpuinitdata mc_cpu_notifier = { |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 726 | .notifier_call = mc_cpu_callback, |
| 727 | }; |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 728 | |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 729 | static int __init microcode_init (void) |
| 730 | { |
| 731 | int error; |
| 732 | |
| 733 | error = microcode_dev_init(); |
| 734 | if (error) |
| 735 | return error; |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 736 | microcode_pdev = platform_device_register_simple("microcode", -1, |
| 737 | NULL, 0); |
| 738 | if (IS_ERR(microcode_pdev)) { |
| 739 | microcode_dev_exit(); |
| 740 | return PTR_ERR(microcode_pdev); |
| 741 | } |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 742 | |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 743 | lock_cpu_hotplug(); |
| 744 | error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver); |
| 745 | unlock_cpu_hotplug(); |
| 746 | if (error) { |
| 747 | microcode_dev_exit(); |
| 748 | platform_device_unregister(microcode_pdev); |
| 749 | return error; |
| 750 | } |
| 751 | |
| 752 | register_hotcpu_notifier(&mc_cpu_notifier); |
| 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | printk(KERN_INFO |
Tigran Aivazian | 6968826 | 2006-12-13 00:35:14 -0800 | [diff] [blame] | 755 | "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | static void __exit microcode_exit (void) |
| 760 | { |
Shaohua Li | 9a3110b | 2006-09-27 01:50:51 -0700 | [diff] [blame] | 761 | microcode_dev_exit(); |
Shaohua Li | 9a4b9ef | 2006-09-27 01:50:53 -0700 | [diff] [blame] | 762 | |
| 763 | unregister_hotcpu_notifier(&mc_cpu_notifier); |
| 764 | |
| 765 | lock_cpu_hotplug(); |
| 766 | sysdev_driver_unregister(&cpu_sysdev_class, &mc_sysdev_driver); |
| 767 | unlock_cpu_hotplug(); |
| 768 | |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 769 | platform_device_unregister(microcode_pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | module_init(microcode_init) |
| 773 | module_exit(microcode_exit) |