2 * Intel CPU Microcode Update Driver for Linux
4 * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
5 * 2006 Shaohua Li <shaohua.li@intel.com>
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.
11 * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture
12 * Software Developer's Manual
13 * Order Number 253668 or free download from:
15 * http://developer.intel.com/design/pentium4/manuals/253668.htm
17 * For more information, go to http://www.urbanmyth.org/microcode
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version
22 * 2 of the License, or (at your option) any later version.
24 * 1.0 16 Feb 2000, Tigran Aivazian <tigran@sco.com>
26 * 1.01 18 Feb 2000, Tigran Aivazian <tigran@sco.com>
27 * Added read() support + cleanups.
28 * 1.02 21 Feb 2000, Tigran Aivazian <tigran@sco.com>
29 * Added 'device trimming' support. open(O_WRONLY) zeroes
30 * and frees the saved copy of applied microcode.
31 * 1.03 29 Feb 2000, Tigran Aivazian <tigran@sco.com>
32 * Made to use devfs (/dev/cpu/microcode) + cleanups.
33 * 1.04 06 Jun 2000, Simon Trimmer <simon@veritas.com>
34 * Added misc device support (now uses both devfs and misc).
35 * Added MICROCODE_IOCFREE ioctl to clear memory.
36 * 1.05 09 Jun 2000, Simon Trimmer <simon@veritas.com>
37 * Messages for error cases (non Intel & no suitable microcode).
38 * 1.06 03 Aug 2000, Tigran Aivazian <tigran@veritas.com>
39 * Removed ->release(). Removed exclusive open and status bitmap.
40 * Added microcode_rwsem to serialize read()/write()/ioctl().
41 * Removed global kernel lock usage.
42 * 1.07 07 Sep 2000, Tigran Aivazian <tigran@veritas.com>
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
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
47 * disabled update by the BIOS)
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
50 * Tigran Aivazian <tigran@veritas.com>
51 * Intel Pentium 4 processor support and bugfixes.
52 * 1.09 30 Oct 2001, Tigran Aivazian <tigran@veritas.com>
53 * Bugfix for HT (Hyper-Threading) enabled processors
54 * whereby processor resources are shared by all logical processors
55 * in a single CPU package.
56 * 1.10 28 Feb 2002 Asit K Mallick <asit.k.mallick@intel.com> and
57 * Tigran Aivazian <tigran@veritas.com>,
58 * Serialize updates as required on HT processors due to speculative
59 * nature of implementation.
60 * 1.11 22 Mar 2002 Tigran Aivazian <tigran@veritas.com>
61 * Fix the panic when writing zero-length microcode chunk.
62 * 1.12 29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>,
63 * Jun Nakajima <jun.nakajima@intel.com>
64 * Support for the microcode updates in the new format.
65 * 1.13 10 Oct 2003 Tigran Aivazian <tigran@veritas.com>
66 * Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl
67 * because we no longer hold a copy of applied microcode
69 * 1.14 25 Jun 2004 Tigran Aivazian <tigran@veritas.com>
70 * Fix sigmatch() macro to handle old CPUs with pf == 0.
71 * Thanks to Stuart Swales for pointing out this bug.
74 //#define DEBUG /* pr_debug */
75 #include <linux/capability.h>
76 #include <linux/kernel.h>
77 #include <linux/init.h>
78 #include <linux/sched.h>
79 #include <linux/smp_lock.h>
80 #include <linux/cpumask.h>
81 #include <linux/module.h>
82 #include <linux/slab.h>
83 #include <linux/vmalloc.h>
84 #include <linux/miscdevice.h>
85 #include <linux/spinlock.h>
88 #include <linux/mutex.h>
89 #include <linux/cpu.h>
90 #include <linux/firmware.h>
91 #include <linux/platform_device.h>
94 #include <asm/uaccess.h>
95 #include <asm/processor.h>
97 MODULE_DESCRIPTION("Intel CPU (IA-32) Microcode Update Driver");
98 MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>");
99 MODULE_LICENSE("GPL");
101 #define MICROCODE_VERSION "1.14a"
103 #define DEFAULT_UCODE_DATASIZE (2000) /* 2000 bytes */
104 #define MC_HEADER_SIZE (sizeof (microcode_header_t)) /* 48 bytes */
105 #define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) /* 2048 bytes */
106 #define EXT_HEADER_SIZE (sizeof (struct extended_sigtable)) /* 20 bytes */
107 #define EXT_SIGNATURE_SIZE (sizeof (struct extended_signature)) /* 12 bytes */
108 #define DWSIZE (sizeof (u32))
109 #define get_totalsize(mc) \
110 (((microcode_t *)mc)->hdr.totalsize ? \
111 ((microcode_t *)mc)->hdr.totalsize : DEFAULT_UCODE_TOTALSIZE)
112 #define get_datasize(mc) \
113 (((microcode_t *)mc)->hdr.datasize ? \
114 ((microcode_t *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
116 #define sigmatch(s1, s2, p1, p2) \
117 (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0))))
119 #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)
121 /* serialize access to the physical write to MSR 0x79 */
122 static DEFINE_SPINLOCK(microcode_update_lock
);
124 /* no concurrent ->write()s are allowed on /dev/cpu/microcode */
125 static DEFINE_MUTEX(microcode_mutex
);
127 static struct ucode_cpu_info
{
133 } ucode_cpu_info
[NR_CPUS
];
135 static void collect_cpu_info(int cpu_num
)
137 struct cpuinfo_x86
*c
= &cpu_data(cpu_num
);
138 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu_num
;
141 /* We should bind the task to the CPU */
142 BUG_ON(raw_smp_processor_id() != cpu_num
);
143 uci
->pf
= uci
->rev
= 0;
147 if (c
->x86_vendor
!= X86_VENDOR_INTEL
|| c
->x86
< 6 ||
148 cpu_has(c
, X86_FEATURE_IA64
)) {
149 printk(KERN_ERR
"microcode: CPU%d not a capable Intel "
150 "processor\n", cpu_num
);
155 uci
->sig
= cpuid_eax(0x00000001);
157 if ((c
->x86_model
>= 5) || (c
->x86
> 6)) {
158 /* get processor flags from MSR 0x17 */
159 rdmsr(MSR_IA32_PLATFORM_ID
, val
[0], val
[1]);
160 uci
->pf
= 1 << ((val
[1] >> 18) & 7);
163 wrmsr(MSR_IA32_UCODE_REV
, 0, 0);
164 /* see notes above for revision 1.07. Apparent chip bug */
166 /* get the current revision from MSR 0x8B */
167 rdmsr(MSR_IA32_UCODE_REV
, val
[0], uci
->rev
);
168 pr_debug("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n",
169 uci
->sig
, uci
->pf
, uci
->rev
);
172 static inline int microcode_update_match(int cpu_num
,
173 microcode_header_t
*mc_header
, int sig
, int pf
)
175 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu_num
;
177 if (!sigmatch(sig
, uci
->sig
, pf
, uci
->pf
)
178 || mc_header
->rev
<= uci
->rev
)
183 static int microcode_sanity_check(void *mc
)
185 microcode_header_t
*mc_header
= mc
;
186 struct extended_sigtable
*ext_header
= NULL
;
187 struct extended_signature
*ext_sig
;
188 unsigned long total_size
, data_size
, ext_table_size
;
189 int sum
, orig_sum
, ext_sigcount
= 0, i
;
191 total_size
= get_totalsize(mc_header
);
192 data_size
= get_datasize(mc_header
);
193 if (data_size
+ MC_HEADER_SIZE
> total_size
) {
194 printk(KERN_ERR
"microcode: error! "
195 "Bad data size in microcode data file\n");
199 if (mc_header
->ldrver
!= 1 || mc_header
->hdrver
!= 1) {
200 printk(KERN_ERR
"microcode: error! "
201 "Unknown microcode update format\n");
204 ext_table_size
= total_size
- (MC_HEADER_SIZE
+ data_size
);
205 if (ext_table_size
) {
206 if ((ext_table_size
< EXT_HEADER_SIZE
)
207 || ((ext_table_size
- EXT_HEADER_SIZE
) % EXT_SIGNATURE_SIZE
)) {
208 printk(KERN_ERR
"microcode: error! "
209 "Small exttable size in microcode data file\n");
212 ext_header
= mc
+ MC_HEADER_SIZE
+ data_size
;
213 if (ext_table_size
!= exttable_size(ext_header
)) {
214 printk(KERN_ERR
"microcode: error! "
215 "Bad exttable size in microcode data file\n");
218 ext_sigcount
= ext_header
->count
;
221 /* check extended table checksum */
222 if (ext_table_size
) {
223 int ext_table_sum
= 0;
224 int *ext_tablep
= (int *)ext_header
;
226 i
= ext_table_size
/ DWSIZE
;
228 ext_table_sum
+= ext_tablep
[i
];
230 printk(KERN_WARNING
"microcode: aborting, "
231 "bad extended signature table checksum\n");
236 /* calculate the checksum */
238 i
= (MC_HEADER_SIZE
+ data_size
) / DWSIZE
;
240 orig_sum
+= ((int *)mc
)[i
];
242 printk(KERN_ERR
"microcode: aborting, bad checksum\n");
247 /* check extended signature checksum */
248 for (i
= 0; i
< ext_sigcount
; i
++) {
249 ext_sig
= (void *)ext_header
+ EXT_HEADER_SIZE
+
250 EXT_SIGNATURE_SIZE
* i
;
252 - (mc_header
->sig
+ mc_header
->pf
+ mc_header
->cksum
)
253 + (ext_sig
->sig
+ ext_sig
->pf
+ ext_sig
->cksum
);
255 printk(KERN_ERR
"microcode: aborting, bad checksum\n");
263 * return 0 - no update found
264 * return 1 - found update
267 static int get_maching_microcode(void *mc
, int cpu
)
269 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu
;
270 microcode_header_t
*mc_header
= mc
;
271 struct extended_sigtable
*ext_header
;
272 unsigned long total_size
= get_totalsize(mc_header
);
274 struct extended_signature
*ext_sig
;
277 if (microcode_update_match(cpu
, mc_header
,
278 mc_header
->sig
, mc_header
->pf
))
281 if (total_size
<= get_datasize(mc_header
) + MC_HEADER_SIZE
)
284 ext_header
= mc
+ get_datasize(mc_header
) + MC_HEADER_SIZE
;
285 ext_sigcount
= ext_header
->count
;
286 ext_sig
= (void *)ext_header
+ EXT_HEADER_SIZE
;
287 for (i
= 0; i
< ext_sigcount
; i
++) {
288 if (microcode_update_match(cpu
, mc_header
,
289 ext_sig
->sig
, ext_sig
->pf
))
295 pr_debug("microcode: CPU%d found a matching microcode update with"
296 " version 0x%x (current=0x%x)\n", cpu
, mc_header
->rev
,uci
->rev
);
297 new_mc
= vmalloc(total_size
);
299 printk(KERN_ERR
"microcode: error! Can not allocate memory\n");
303 /* free previous update file */
306 memcpy(new_mc
, mc
, total_size
);
311 static void apply_microcode(int cpu
)
315 int cpu_num
= raw_smp_processor_id();
316 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu_num
;
318 /* We should bind the task to the CPU */
319 BUG_ON(cpu_num
!= cpu
);
324 /* serialize access to the physical write to MSR 0x79 */
325 spin_lock_irqsave(µcode_update_lock
, flags
);
327 /* write microcode via MSR 0x79 */
328 wrmsr(MSR_IA32_UCODE_WRITE
,
329 (unsigned long) uci
->mc
->bits
,
330 (unsigned long) uci
->mc
->bits
>> 16 >> 16);
331 wrmsr(MSR_IA32_UCODE_REV
, 0, 0);
333 /* see notes above for revision 1.07. Apparent chip bug */
336 /* get the current revision from MSR 0x8B */
337 rdmsr(MSR_IA32_UCODE_REV
, val
[0], val
[1]);
339 spin_unlock_irqrestore(µcode_update_lock
, flags
);
340 if (val
[1] != uci
->mc
->hdr
.rev
) {
341 printk(KERN_ERR
"microcode: CPU%d update from revision "
342 "0x%x to 0x%x failed\n", cpu_num
, uci
->rev
, val
[1]);
345 printk(KERN_INFO
"microcode: CPU%d updated from revision "
346 "0x%x to 0x%x, date = %08x \n",
347 cpu_num
, uci
->rev
, val
[1], uci
->mc
->hdr
.date
);
351 #ifdef CONFIG_MICROCODE_OLD_INTERFACE
352 static void __user
*user_buffer
; /* user area microcode data buffer */
353 static unsigned int user_buffer_size
; /* it's size */
355 static long get_next_ucode(void **mc
, long offset
)
357 microcode_header_t mc_header
;
358 unsigned long total_size
;
361 if (offset
>= user_buffer_size
)
363 if (copy_from_user(&mc_header
, user_buffer
+ offset
, MC_HEADER_SIZE
)) {
364 printk(KERN_ERR
"microcode: error! Can not read user data\n");
367 total_size
= get_totalsize(&mc_header
);
368 if (offset
+ total_size
> user_buffer_size
) {
369 printk(KERN_ERR
"microcode: error! Bad total size in microcode "
373 *mc
= vmalloc(total_size
);
376 if (copy_from_user(*mc
, user_buffer
+ offset
, total_size
)) {
377 printk(KERN_ERR
"microcode: error! Can not read user data\n");
381 return offset
+ total_size
;
384 static int do_microcode_update (void)
391 cpumask_of_cpu_ptr_declare(newmask
);
393 old
= current
->cpus_allowed
;
395 while ((cursor
= get_next_ucode(&new_mc
, cursor
)) > 0) {
396 error
= microcode_sanity_check(new_mc
);
400 * It's possible the data file has multiple matching ucode,
401 * lets keep searching till the latest version
403 for_each_online_cpu(cpu
) {
404 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu
;
408 cpumask_of_cpu_ptr_next(newmask
, cpu
);
409 set_cpus_allowed_ptr(current
, newmask
);
410 error
= get_maching_microcode(new_mc
, cpu
);
414 apply_microcode(cpu
);
423 set_cpus_allowed_ptr(current
, &old
);
427 static int microcode_open (struct inode
*unused1
, struct file
*unused2
)
430 return capable(CAP_SYS_RAWIO
) ? 0 : -EPERM
;
433 static ssize_t
microcode_write (struct file
*file
, const char __user
*buf
, size_t len
, loff_t
*ppos
)
437 if ((len
>> PAGE_SHIFT
) > num_physpages
) {
438 printk(KERN_ERR
"microcode: too much data (max %ld pages)\n", num_physpages
);
443 mutex_lock(µcode_mutex
);
445 user_buffer
= (void __user
*) buf
;
446 user_buffer_size
= (int) len
;
448 ret
= do_microcode_update();
452 mutex_unlock(µcode_mutex
);
458 static const struct file_operations microcode_fops
= {
459 .owner
= THIS_MODULE
,
460 .write
= microcode_write
,
461 .open
= microcode_open
,
464 static struct miscdevice microcode_dev
= {
465 .minor
= MICROCODE_MINOR
,
467 .fops
= µcode_fops
,
470 static int __init
microcode_dev_init (void)
474 error
= misc_register(µcode_dev
);
477 "microcode: can't misc_register on minor=%d\n",
485 static void microcode_dev_exit (void)
487 misc_deregister(µcode_dev
);
490 MODULE_ALIAS_MISCDEV(MICROCODE_MINOR
);
492 #define microcode_dev_init() 0
493 #define microcode_dev_exit() do { } while(0)
496 static long get_next_ucode_from_buffer(void **mc
, const u8
*buf
,
497 unsigned long size
, long offset
)
499 microcode_header_t
*mc_header
;
500 unsigned long total_size
;
505 mc_header
= (microcode_header_t
*)(buf
+ offset
);
506 total_size
= get_totalsize(mc_header
);
508 if (offset
+ total_size
> size
) {
509 printk(KERN_ERR
"microcode: error! Bad data in microcode data file\n");
513 *mc
= vmalloc(total_size
);
515 printk(KERN_ERR
"microcode: error! Can not allocate memory\n");
518 memcpy(*mc
, buf
+ offset
, total_size
);
519 return offset
+ total_size
;
522 /* fake device for request_firmware */
523 static struct platform_device
*microcode_pdev
;
525 static int cpu_request_microcode(int cpu
)
528 struct cpuinfo_x86
*c
= &cpu_data(cpu
);
529 const struct firmware
*firmware
;
536 /* We should bind the task to the CPU */
537 BUG_ON(cpu
!= raw_smp_processor_id());
538 sprintf(name
,"intel-ucode/%02x-%02x-%02x",
539 c
->x86
, c
->x86_model
, c
->x86_mask
);
540 error
= request_firmware(&firmware
, name
, µcode_pdev
->dev
);
542 pr_debug("microcode: data file %s load failed\n", name
);
545 buf
= firmware
->data
;
546 size
= firmware
->size
;
547 while ((offset
= get_next_ucode_from_buffer(&mc
, buf
, size
, offset
))
549 error
= microcode_sanity_check(mc
);
552 error
= get_maching_microcode(mc
, cpu
);
556 * It's possible the data file has multiple matching ucode,
557 * lets keep searching till the latest version
560 apply_microcode(cpu
);
569 release_firmware(firmware
);
574 static int apply_microcode_check_cpu(int cpu
)
576 struct cpuinfo_x86
*c
= &cpu_data(cpu
);
577 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu
;
579 cpumask_of_cpu_ptr(newmask
, cpu
);
583 /* Check if the microcode is available */
587 old
= current
->cpus_allowed
;
588 set_cpus_allowed_ptr(current
, newmask
);
590 /* Check if the microcode we have in memory matches the CPU */
591 if (c
->x86_vendor
!= X86_VENDOR_INTEL
|| c
->x86
< 6 ||
592 cpu_has(c
, X86_FEATURE_IA64
) || uci
->sig
!= cpuid_eax(0x00000001))
595 if (!err
&& ((c
->x86_model
>= 5) || (c
->x86
> 6))) {
596 /* get processor flags from MSR 0x17 */
597 rdmsr(MSR_IA32_PLATFORM_ID
, val
[0], val
[1]);
598 if (uci
->pf
!= (1 << ((val
[1] >> 18) & 7)))
603 wrmsr(MSR_IA32_UCODE_REV
, 0, 0);
604 /* see notes above for revision 1.07. Apparent chip bug */
606 /* get the current revision from MSR 0x8B */
607 rdmsr(MSR_IA32_UCODE_REV
, val
[0], val
[1]);
608 if (uci
->rev
!= val
[1])
613 apply_microcode(cpu
);
615 printk(KERN_ERR
"microcode: Could not apply microcode to CPU%d:"
616 " sig=0x%x, pf=0x%x, rev=0x%x\n",
617 cpu
, uci
->sig
, uci
->pf
, uci
->rev
);
619 set_cpus_allowed_ptr(current
, &old
);
623 static void microcode_init_cpu(int cpu
, int resume
)
626 cpumask_of_cpu_ptr(newmask
, cpu
);
627 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu
;
629 old
= current
->cpus_allowed
;
631 set_cpus_allowed_ptr(current
, newmask
);
632 mutex_lock(µcode_mutex
);
633 collect_cpu_info(cpu
);
634 if (uci
->valid
&& system_state
== SYSTEM_RUNNING
&& !resume
)
635 cpu_request_microcode(cpu
);
636 mutex_unlock(µcode_mutex
);
637 set_cpus_allowed_ptr(current
, &old
);
640 static void microcode_fini_cpu(int cpu
)
642 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu
;
644 mutex_lock(µcode_mutex
);
648 mutex_unlock(µcode_mutex
);
651 static ssize_t
reload_store(struct sys_device
*dev
,
652 struct sysdev_attribute
*attr
,
653 const char *buf
, size_t sz
)
655 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ dev
->id
;
657 unsigned long val
= simple_strtoul(buf
, &end
, 0);
665 cpumask_of_cpu_ptr(newmask
, cpu
);
667 old
= current
->cpus_allowed
;
670 set_cpus_allowed_ptr(current
, newmask
);
672 mutex_lock(µcode_mutex
);
674 err
= cpu_request_microcode(cpu
);
675 mutex_unlock(µcode_mutex
);
677 set_cpus_allowed_ptr(current
, &old
);
684 static ssize_t
version_show(struct sys_device
*dev
,
685 struct sysdev_attribute
*attr
, char *buf
)
687 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ dev
->id
;
689 return sprintf(buf
, "0x%x\n", uci
->rev
);
692 static ssize_t
pf_show(struct sys_device
*dev
,
693 struct sysdev_attribute
*attr
, char *buf
)
695 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ dev
->id
;
697 return sprintf(buf
, "0x%x\n", uci
->pf
);
700 static SYSDEV_ATTR(reload
, 0200, NULL
, reload_store
);
701 static SYSDEV_ATTR(version
, 0400, version_show
, NULL
);
702 static SYSDEV_ATTR(processor_flags
, 0400, pf_show
, NULL
);
704 static struct attribute
*mc_default_attrs
[] = {
707 &attr_processor_flags
.attr
,
711 static struct attribute_group mc_attr_group
= {
712 .attrs
= mc_default_attrs
,
716 static int __mc_sysdev_add(struct sys_device
*sys_dev
, int resume
)
718 int err
, cpu
= sys_dev
->id
;
719 struct ucode_cpu_info
*uci
= ucode_cpu_info
+ cpu
;
721 if (!cpu_online(cpu
))
724 pr_debug("microcode: CPU%d added\n", cpu
);
725 memset(uci
, 0, sizeof(*uci
));
727 err
= sysfs_create_group(&sys_dev
->kobj
, &mc_attr_group
);
731 microcode_init_cpu(cpu
, resume
);
736 static int mc_sysdev_add(struct sys_device
*sys_dev
)
738 return __mc_sysdev_add(sys_dev
, 0);
741 static int mc_sysdev_remove(struct sys_device
*sys_dev
)
743 int cpu
= sys_dev
->id
;
745 if (!cpu_online(cpu
))
748 pr_debug("microcode: CPU%d removed\n", cpu
);
749 microcode_fini_cpu(cpu
);
750 sysfs_remove_group(&sys_dev
->kobj
, &mc_attr_group
);
754 static int mc_sysdev_resume(struct sys_device
*dev
)
758 if (!cpu_online(cpu
))
760 pr_debug("microcode: CPU%d resumed\n", cpu
);
761 /* only CPU 0 will apply ucode here */
766 static struct sysdev_driver mc_sysdev_driver
= {
767 .add
= mc_sysdev_add
,
768 .remove
= mc_sysdev_remove
,
769 .resume
= mc_sysdev_resume
,
773 mc_cpu_callback(struct notifier_block
*nb
, unsigned long action
, void *hcpu
)
775 unsigned int cpu
= (unsigned long)hcpu
;
776 struct sys_device
*sys_dev
;
778 sys_dev
= get_cpu_sysdev(cpu
);
780 case CPU_UP_CANCELED_FROZEN
:
781 /* The CPU refused to come up during a system resume */
782 microcode_fini_cpu(cpu
);
785 case CPU_DOWN_FAILED
:
786 mc_sysdev_add(sys_dev
);
788 case CPU_ONLINE_FROZEN
:
789 /* System-wide resume is in progress, try to apply microcode */
790 if (apply_microcode_check_cpu(cpu
)) {
791 /* The application of microcode failed */
792 microcode_fini_cpu(cpu
);
793 __mc_sysdev_add(sys_dev
, 1);
796 case CPU_DOWN_FAILED_FROZEN
:
797 if (sysfs_create_group(&sys_dev
->kobj
, &mc_attr_group
))
798 printk(KERN_ERR
"microcode: Failed to create the sysfs "
799 "group for CPU%d\n", cpu
);
801 case CPU_DOWN_PREPARE
:
802 mc_sysdev_remove(sys_dev
);
804 case CPU_DOWN_PREPARE_FROZEN
:
805 /* Suspend is in progress, only remove the interface */
806 sysfs_remove_group(&sys_dev
->kobj
, &mc_attr_group
);
812 static struct notifier_block __refdata mc_cpu_notifier
= {
813 .notifier_call
= mc_cpu_callback
,
816 static int __init
microcode_init (void)
821 "IA-32 Microcode Update Driver: v" MICROCODE_VERSION
" <tigran@aivazian.fsnet.co.uk>\n");
823 error
= microcode_dev_init();
826 microcode_pdev
= platform_device_register_simple("microcode", -1,
828 if (IS_ERR(microcode_pdev
)) {
829 microcode_dev_exit();
830 return PTR_ERR(microcode_pdev
);
834 error
= sysdev_driver_register(&cpu_sysdev_class
, &mc_sysdev_driver
);
837 microcode_dev_exit();
838 platform_device_unregister(microcode_pdev
);
842 register_hotcpu_notifier(&mc_cpu_notifier
);
846 static void __exit
microcode_exit (void)
848 microcode_dev_exit();
850 unregister_hotcpu_notifier(&mc_cpu_notifier
);
853 sysdev_driver_unregister(&cpu_sysdev_class
, &mc_sysdev_driver
);
856 platform_device_unregister(microcode_pdev
);
859 module_init(microcode_init
)
860 module_exit(microcode_exit
)