]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/x86/kernel/microcode.c
x86_64: printout msr -v2
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / microcode.c
index 40cfd5488719b96fd6ccd8d3a890e54761d0c6c0..6994c751590ec14ea31b7418bfd4659722466b2e 100644 (file)
@@ -5,13 +5,14 @@
  *                   2006      Shaohua Li <shaohua.li@intel.com>
  *
  *     This driver allows to upgrade microcode on Intel processors
- *     belonging to IA-32 family - PentiumPro, Pentium II, 
+ *     belonging to IA-32 family - PentiumPro, Pentium II,
  *     Pentium III, Xeon, Pentium 4, etc.
  *
- *     Reference: Section 8.10 of Volume III, Intel Pentium 4 Manual, 
- *     Order Number 245472 or free download from:
- *             
- *     http://developer.intel.com/design/pentium4/manuals/245472.htm
+ *     Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture
+ *     Software Developer's Manual
+ *     Order Number 253668 or free download from:
+ *
+ *     http://developer.intel.com/design/pentium4/manuals/253668.htm
  *
  *     For more information, go to http://www.urbanmyth.org/microcode
  *
  *             nature of implementation.
  *     1.11    22 Mar 2002 Tigran Aivazian <tigran@veritas.com>
  *             Fix the panic when writing zero-length microcode chunk.
- *     1.12    29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, 
+ *     1.12    29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>,
  *             Jun Nakajima <jun.nakajima@intel.com>
  *             Support for the microcode updates in the new format.
  *     1.13    10 Oct 2003 Tigran Aivazian <tigran@veritas.com>
  *             Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl
- *             because we no longer hold a copy of applied microcode 
+ *             because we no longer hold a copy of applied microcode
  *             in kernel memory.
  *     1.14    25 Jun 2004 Tigran Aivazian <tigran@veritas.com>
  *             Fix sigmatch() macro to handle old CPUs with pf == 0.
@@ -75,6 +76,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/cpumask.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -244,8 +246,8 @@ static int microcode_sanity_check(void *mc)
                return 0;
        /* check extended signature checksum */
        for (i = 0; i < ext_sigcount; i++) {
-               ext_sig = (struct extended_signature *)((void *)ext_header
-                       + EXT_HEADER_SIZE + EXT_SIGNATURE_SIZE * i);
+               ext_sig = (void *)ext_header + EXT_HEADER_SIZE +
+                         EXT_SIGNATURE_SIZE * i;
                sum = orig_sum
                        - (mc_header->sig + mc_header->pf + mc_header->cksum)
                        + (ext_sig->sig + ext_sig->pf + ext_sig->cksum);
@@ -279,11 +281,9 @@ static int get_maching_microcode(void *mc, int cpu)
        if (total_size <= get_datasize(mc_header) + MC_HEADER_SIZE)
                return 0;
 
-       ext_header = (struct extended_sigtable *)(mc +
-                       get_datasize(mc_header) + MC_HEADER_SIZE);
+       ext_header = mc + get_datasize(mc_header) + MC_HEADER_SIZE;
        ext_sigcount = ext_header->count;
-       ext_sig = (struct extended_signature *)((void *)ext_header
-                       + EXT_HEADER_SIZE);
+       ext_sig = (void *)ext_header + EXT_HEADER_SIZE;
        for (i = 0; i < ext_sigcount; i++) {
                if (microcode_update_match(cpu, mc_header,
                                ext_sig->sig, ext_sig->pf))
@@ -292,7 +292,7 @@ static int get_maching_microcode(void *mc, int cpu)
        }
        return 0;
 find:
-       pr_debug("microcode: CPU %d found a matching microcode update with"
+       pr_debug("microcode: CPU%d found a matching microcode update with"
                " version 0x%x (current=0x%x)\n", cpu, mc_header->rev,uci->rev);
        new_mc = vmalloc(total_size);
        if (!new_mc) {
@@ -322,11 +322,11 @@ static void apply_microcode(int cpu)
                return;
 
        /* serialize access to the physical write to MSR 0x79 */
-       spin_lock_irqsave(&microcode_update_lock, flags);          
+       spin_lock_irqsave(&microcode_update_lock, flags);
 
        /* write microcode via MSR 0x79 */
        wrmsr(MSR_IA32_UCODE_WRITE,
-               (unsigned long) uci->mc->bits, 
+               (unsigned long) uci->mc->bits,
                (unsigned long) uci->mc->bits >> 16 >> 16);
        wrmsr(MSR_IA32_UCODE_REV, 0, 0);
 
@@ -338,12 +338,12 @@ static void apply_microcode(int cpu)
 
        spin_unlock_irqrestore(&microcode_update_lock, flags);
        if (val[1] != uci->mc->hdr.rev) {
-               printk(KERN_ERR "microcode: CPU%d updated from revision "
+               printk(KERN_ERR "microcode: CPU%d update from revision "
                        "0x%x to 0x%x failed\n", cpu_num, uci->rev, val[1]);
                return;
        }
-       pr_debug("microcode: CPU%d updated from revision "
-              "0x%x to 0x%x, date = %08x \n", 
+       printk(KERN_INFO "microcode: CPU%d updated from revision "
+              "0x%x to 0x%x, date = %08x \n",
               cpu_num, uci->rev, val[1], uci->mc->hdr.date);
        uci->rev = val[1];
 }
@@ -388,6 +388,7 @@ static int do_microcode_update (void)
        void *new_mc = NULL;
        int cpu;
        cpumask_t old;
+       cpumask_of_cpu_ptr_declare(newmask);
 
        old = current->cpus_allowed;
 
@@ -404,7 +405,8 @@ static int do_microcode_update (void)
 
                        if (!uci->valid)
                                continue;
-                       set_cpus_allowed(current, cpumask_of_cpu(cpu));
+                       cpumask_of_cpu_ptr_next(newmask, cpu);
+                       set_cpus_allowed_ptr(current, newmask);
                        error = get_maching_microcode(new_mc, cpu);
                        if (error < 0)
                                goto out;
@@ -418,12 +420,13 @@ out:
                vfree(new_mc);
        if (cursor < 0)
                error = cursor;
-       set_cpus_allowed(current, old);
+       set_cpus_allowed_ptr(current, &old);
        return error;
 }
 
 static int microcode_open (struct inode *unused1, struct file *unused2)
 {
+       cycle_kernel_lock();
        return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
 }
 
@@ -490,7 +493,7 @@ MODULE_ALIAS_MISCDEV(MICROCODE_MINOR);
 #define microcode_dev_exit() do { } while(0)
 #endif
 
-static long get_next_ucode_from_buffer(void **mc, void *buf,
+static long get_next_ucode_from_buffer(void **mc, const u8 *buf,
        unsigned long size, long offset)
 {
        microcode_header_t *mc_header;
@@ -524,7 +527,7 @@ static int cpu_request_microcode(int cpu)
        char name[30];
        struct cpuinfo_x86 *c = &cpu_data(cpu);
        const struct firmware *firmware;
-       void *buf;
+       const u8 *buf;
        unsigned long size;
        long offset = 0;
        int error;
@@ -536,10 +539,10 @@ static int cpu_request_microcode(int cpu)
                c->x86, c->x86_model, c->x86_mask);
        error = request_firmware(&firmware, name, &microcode_pdev->dev);
        if (error) {
-               pr_debug("ucode data file %s load failed\n", name);
+               pr_debug("microcode: data file %s load failed\n", name);
                return error;
        }
-       buf = (void *)firmware->data;
+       buf = firmware->data;
        size = firmware->size;
        while ((offset = get_next_ucode_from_buffer(&mc, buf, size, offset))
                        > 0) {
@@ -573,6 +576,7 @@ static int apply_microcode_check_cpu(int cpu)
        struct cpuinfo_x86 *c = &cpu_data(cpu);
        struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
        cpumask_t old;
+       cpumask_of_cpu_ptr(newmask, cpu);
        unsigned int val[2];
        int err = 0;
 
@@ -581,7 +585,7 @@ static int apply_microcode_check_cpu(int cpu)
                return 0;
 
        old = current->cpus_allowed;
-       set_cpus_allowed(current, cpumask_of_cpu(cpu));
+       set_cpus_allowed_ptr(current, newmask);
 
        /* Check if the microcode we have in memory matches the CPU */
        if (c->x86_vendor != X86_VENDOR_INTEL || c->x86 < 6 ||
@@ -612,24 +616,25 @@ static int apply_microcode_check_cpu(int cpu)
                        " sig=0x%x, pf=0x%x, rev=0x%x\n",
                        cpu, uci->sig, uci->pf, uci->rev);
 
-       set_cpus_allowed(current, old);
+       set_cpus_allowed_ptr(current, &old);
        return err;
 }
 
 static void microcode_init_cpu(int cpu, int resume)
 {
        cpumask_t old;
+       cpumask_of_cpu_ptr(newmask, cpu);
        struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
 
        old = current->cpus_allowed;
 
-       set_cpus_allowed(current, cpumask_of_cpu(cpu));
+       set_cpus_allowed_ptr(current, newmask);
        mutex_lock(&microcode_mutex);
        collect_cpu_info(cpu);
        if (uci->valid && system_state == SYSTEM_RUNNING && !resume)
                cpu_request_microcode(cpu);
        mutex_unlock(&microcode_mutex);
-       set_cpus_allowed(current, old);
+       set_cpus_allowed_ptr(current, &old);
 }
 
 static void microcode_fini_cpu(int cpu)
@@ -643,7 +648,9 @@ static void microcode_fini_cpu(int cpu)
        mutex_unlock(&microcode_mutex);
 }
 
-static ssize_t reload_store(struct sys_device *dev, const char *buf, size_t sz)
+static ssize_t reload_store(struct sys_device *dev,
+                           struct sysdev_attribute *attr,
+                           const char *buf, size_t sz)
 {
        struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
        char *end;
@@ -655,32 +662,35 @@ static ssize_t reload_store(struct sys_device *dev, const char *buf, size_t sz)
                return -EINVAL;
        if (val == 1) {
                cpumask_t old;
+               cpumask_of_cpu_ptr(newmask, cpu);
 
                old = current->cpus_allowed;
 
                get_online_cpus();
-               set_cpus_allowed(current, cpumask_of_cpu(cpu));
+               set_cpus_allowed_ptr(current, newmask);
 
                mutex_lock(&microcode_mutex);
                if (uci->valid)
                        err = cpu_request_microcode(cpu);
                mutex_unlock(&microcode_mutex);
                put_online_cpus();
-               set_cpus_allowed(current, old);
+               set_cpus_allowed_ptr(current, &old);
        }
        if (err)
                return err;
        return sz;
 }
 
-static ssize_t version_show(struct sys_device *dev, char *buf)
+static ssize_t version_show(struct sys_device *dev,
+                       struct sysdev_attribute *attr, char *buf)
 {
        struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
 
        return sprintf(buf, "0x%x\n", uci->rev);
 }
 
-static ssize_t pf_show(struct sys_device *dev, char *buf)
+static ssize_t pf_show(struct sys_device *dev,
+                       struct sysdev_attribute *attr, char *buf)
 {
        struct ucode_cpu_info *uci = ucode_cpu_info + dev->id;
 
@@ -711,7 +721,7 @@ static int __mc_sysdev_add(struct sys_device *sys_dev, int resume)
        if (!cpu_online(cpu))
                return 0;
 
-       pr_debug("Microcode:CPU %d added\n", cpu);
+       pr_debug("microcode: CPU%d added\n", cpu);
        memset(uci, 0, sizeof(*uci));
 
        err = sysfs_create_group(&sys_dev->kobj, &mc_attr_group);
@@ -735,7 +745,7 @@ static int mc_sysdev_remove(struct sys_device *sys_dev)
        if (!cpu_online(cpu))
                return 0;
 
-       pr_debug("Microcode:CPU %d removed\n", cpu);
+       pr_debug("microcode: CPU%d removed\n", cpu);
        microcode_fini_cpu(cpu);
        sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
        return 0;
@@ -747,7 +757,7 @@ static int mc_sysdev_resume(struct sys_device *dev)
 
        if (!cpu_online(cpu))
                return 0;
-       pr_debug("Microcode:CPU %d resumed\n", cpu);
+       pr_debug("microcode: CPU%d resumed\n", cpu);
        /* only CPU 0 will apply ucode here */
        apply_microcode(0);
        return 0;
@@ -785,7 +795,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
                }
        case CPU_DOWN_FAILED_FROZEN:
                if (sysfs_create_group(&sys_dev->kobj, &mc_attr_group))
-                       printk(KERN_ERR "Microcode: Failed to create the sysfs "
+                       printk(KERN_ERR "microcode: Failed to create the sysfs "
                                "group for CPU%d\n", cpu);
                break;
        case CPU_DOWN_PREPARE:
@@ -799,7 +809,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
        return NOTIFY_OK;
 }
 
-static struct notifier_block __cpuinitdata mc_cpu_notifier = {
+static struct notifier_block __refdata mc_cpu_notifier = {
        .notifier_call = mc_cpu_callback,
 };
 
@@ -807,6 +817,9 @@ static int __init microcode_init (void)
 {
        int error;
 
+       printk(KERN_INFO
+               "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
+
        error = microcode_dev_init();
        if (error)
                return error;
@@ -827,9 +840,6 @@ static int __init microcode_init (void)
        }
 
        register_hotcpu_notifier(&mc_cpu_notifier);
-
-       printk(KERN_INFO 
-               "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
        return 0;
 }