]> git.sur5r.net Git - u-boot/commitdiff
x86: Move microcode code to a common location
authorSimon Glass <sjg@chromium.org>
Sat, 12 Mar 2016 05:06:54 +0000 (22:06 -0700)
committerBin Meng <bmeng.cn@gmail.com>
Thu, 17 Mar 2016 02:27:24 +0000 (10:27 +0800)
This code is used on several Intel CPUs. Move it into a common location.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/x86/cpu/intel_common/Makefile
arch/x86/cpu/intel_common/car.S
arch/x86/cpu/intel_common/microcode.c [new file with mode: 0644]
arch/x86/cpu/ivybridge/Makefile
arch/x86/cpu/ivybridge/cpu.c
arch/x86/cpu/ivybridge/microcode_intel.c [deleted file]
arch/x86/include/asm/arch-ivybridge/microcode.h [deleted file]
arch/x86/include/asm/microcode.h [new file with mode: 0644]

index 5dd95739a0996be4d5af5a1c2a4af87d8ec85f6c..ca4e171d20ca9b10bb74d446391a1b0a9bfdfb80 100644 (file)
@@ -5,3 +5,6 @@
 #
 
 obj-$(CONFIG_HAVE_MRC) += car.o
+ifndef CONFIG_TARGET_EFI
+obj-y += microcode.o
+endif
index 1defabf91f07fbe2c549102261b655a3e1a1c83a..81ac976ddd5bafcd7feb8e6307de7e7fdac4df5c 100644 (file)
  */
 
 #include <common.h>
+#include <asm/microcode.h>
 #include <asm/msr-index.h>
 #include <asm/mtrr.h>
 #include <asm/post.h>
 #include <asm/processor.h>
 #include <asm/processor-flags.h>
-#include <asm/arch/microcode.h>
 
 #define MTRR_PHYS_BASE_MSR(reg) (0x200 + 2 * (reg))
 #define MTRR_PHYS_MASK_MSR(reg) (0x200 + 2 * (reg) + 1)
diff --git a/arch/x86/cpu/intel_common/microcode.c b/arch/x86/cpu/intel_common/microcode.c
new file mode 100644 (file)
index 0000000..3054fab
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2014 Google, Inc
+ * Copyright (C) 2000 Ronald G. Minnich
+ *
+ * Microcode update for Intel PIII and later CPUs
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <libfdt.h>
+#include <asm/cpu.h>
+#include <asm/microcode.h>
+#include <asm/msr.h>
+#include <asm/msr-index.h>
+#include <asm/processor.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/**
+ * struct microcode_update - standard microcode header from Intel
+ *
+ * We read this information out of the device tree and use it to determine
+ * whether the update is applicable or not. We also use the same structure
+ * to read information from the CPU.
+ */
+struct microcode_update {
+       uint header_version;
+       uint update_revision;
+       uint date_code;
+       uint processor_signature;
+       uint checksum;
+       uint loader_revision;
+       uint processor_flags;
+       const void *data;
+       int size;
+};
+
+static int microcode_decode_node(const void *blob, int node,
+                                struct microcode_update *update)
+{
+       update->data = fdt_getprop(blob, node, "data", &update->size);
+       if (!update->data)
+               return -EINVAL;
+       update->data += UCODE_HEADER_LEN;
+       update->size -= UCODE_HEADER_LEN;
+
+       update->header_version = fdtdec_get_int(blob, node,
+                                               "intel,header-version", 0);
+       update->update_revision = fdtdec_get_int(blob, node,
+                                                "intel,update-revision", 0);
+       update->date_code = fdtdec_get_int(blob, node,
+                                          "intel,date-code", 0);
+       update->processor_signature = fdtdec_get_int(blob, node,
+                                       "intel,processor-signature", 0);
+       update->checksum = fdtdec_get_int(blob, node, "intel,checksum", 0);
+       update->loader_revision = fdtdec_get_int(blob, node,
+                                                "intel,loader-revision", 0);
+       update->processor_flags = fdtdec_get_int(blob, node,
+                                                "intel,processor-flags", 0);
+
+       return 0;
+}
+
+static inline uint32_t microcode_read_rev(void)
+{
+       /*
+        * Some Intel CPUs can be very finicky about the CPUID sequence used.
+        * So this is implemented in assembly so that it works reliably.
+        */
+       uint32_t low, high;
+
+       asm volatile (
+               "xorl %%eax, %%eax\n"
+               "xorl %%edx, %%edx\n"
+               "movl %2, %%ecx\n"
+               "wrmsr\n"
+               "movl $0x01, %%eax\n"
+               "cpuid\n"
+               "movl %2, %%ecx\n"
+               "rdmsr\n"
+               : /* outputs */
+               "=a" (low), "=d" (high)
+               : /* inputs */
+               "i" (MSR_IA32_UCODE_REV)
+               : /* clobbers */
+                "ebx", "ecx"
+       );
+
+       return high;
+}
+
+static void microcode_read_cpu(struct microcode_update *cpu)
+{
+       /* CPUID sets MSR 0x8B iff a microcode update has been loaded. */
+       unsigned int x86_model, x86_family;
+       struct cpuid_result result;
+       uint32_t low, high;
+
+       wrmsr(MSR_IA32_UCODE_REV, 0, 0);
+       result = cpuid(1);
+       rdmsr(MSR_IA32_UCODE_REV, low, cpu->update_revision);
+       x86_model = (result.eax >> 4) & 0x0f;
+       x86_family = (result.eax >> 8) & 0x0f;
+       cpu->processor_signature = result.eax;
+
+       cpu->processor_flags = 0;
+       if ((x86_model >= 5) || (x86_family > 6)) {
+               rdmsr(0x17, low, high);
+               cpu->processor_flags = 1 << ((high >> 18) & 7);
+       }
+       debug("microcode: sig=%#x pf=%#x revision=%#x\n",
+             cpu->processor_signature, cpu->processor_flags,
+             cpu->update_revision);
+}
+
+/* Get a microcode update from the device tree and apply it */
+int microcode_update_intel(void)
+{
+       struct microcode_update cpu, update;
+       const void *blob = gd->fdt_blob;
+       int skipped;
+       int count;
+       int node;
+       int ret;
+       int rev;
+
+       microcode_read_cpu(&cpu);
+       node = 0;
+       count = 0;
+       skipped = 0;
+       do {
+               node = fdtdec_next_compatible(blob, node,
+                                             COMPAT_INTEL_MICROCODE);
+               if (node < 0) {
+                       debug("%s: Found %d updates\n", __func__, count);
+                       return count ? 0 : skipped ? -EEXIST : -ENOENT;
+               }
+
+               ret = microcode_decode_node(blob, node, &update);
+               if (ret) {
+                       debug("%s: Unable to decode update: %d\n", __func__,
+                             ret);
+                       return ret;
+               }
+               if (!(update.processor_signature == cpu.processor_signature &&
+                     (update.processor_flags & cpu.processor_flags))) {
+                       debug("%s: Skipping non-matching update, sig=%x, pf=%x\n",
+                             __func__, update.processor_signature,
+                             update.processor_flags);
+                       skipped++;
+                       continue;
+               }
+               wrmsr(MSR_IA32_UCODE_WRITE, (ulong)update.data, 0);
+               rev = microcode_read_rev();
+               debug("microcode: updated to revision 0x%x date=%04x-%02x-%02x\n",
+                     rev, update.date_code & 0xffff,
+                     (update.date_code >> 24) & 0xff,
+                     (update.date_code >> 16) & 0xff);
+               if (update.update_revision != rev) {
+                       printf("Microcode update failed\n");
+                       return -EFAULT;
+               }
+               count++;
+       } while (1);
+}
index b117f0deb294a7f2db86cdb015a84b0432b5e6d6..78006f12b39252a7dca024ee85448862644e72b1 100644 (file)
@@ -13,7 +13,6 @@ obj-y += gma.o
 obj-y += lpc.o
 obj-y += me_status.o
 obj-y += model_206ax.o
-obj-y += microcode_intel.o
 obj-y += northbridge.o
 obj-y += report_platform.o
 obj-y += sata.o
index 5d839a7e1befae9f0355194e7c8771cca65bcddb..f0e733bc33101e1c798f5e258548f184b08ce8e9 100644 (file)
 #include <asm/cpu.h>
 #include <asm/io.h>
 #include <asm/lapic.h>
+#include <asm/microcode.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
 #include <asm/pci.h>
 #include <asm/post.h>
 #include <asm/processor.h>
 #include <asm/arch/model_206ax.h>
-#include <asm/arch/microcode.h>
 #include <asm/arch/pch.h>
 #include <asm/arch/sandybridge.h>
 
diff --git a/arch/x86/cpu/ivybridge/microcode_intel.c b/arch/x86/cpu/ivybridge/microcode_intel.c
deleted file mode 100644 (file)
index 2440a97..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (c) 2014 Google, Inc
- * Copyright (C) 2000 Ronald G. Minnich
- *
- * Microcode update for Intel PIII and later CPUs
- *
- * SPDX-License-Identifier:    GPL-2.0
- */
-
-#include <common.h>
-#include <errno.h>
-#include <fdtdec.h>
-#include <libfdt.h>
-#include <asm/cpu.h>
-#include <asm/msr.h>
-#include <asm/msr-index.h>
-#include <asm/processor.h>
-#include <asm/arch/microcode.h>
-
-/**
- * struct microcode_update - standard microcode header from Intel
- *
- * We read this information out of the device tree and use it to determine
- * whether the update is applicable or not. We also use the same structure
- * to read information from the CPU.
- */
-struct microcode_update {
-       uint header_version;
-       uint update_revision;
-       uint date_code;
-       uint processor_signature;
-       uint checksum;
-       uint loader_revision;
-       uint processor_flags;
-       const void *data;
-       int size;
-};
-
-static int microcode_decode_node(const void *blob, int node,
-                                struct microcode_update *update)
-{
-       update->data = fdt_getprop(blob, node, "data", &update->size);
-       if (!update->data)
-               return -EINVAL;
-       update->data += UCODE_HEADER_LEN;
-       update->size -= UCODE_HEADER_LEN;
-
-       update->header_version = fdtdec_get_int(blob, node,
-                                               "intel,header-version", 0);
-       update->update_revision = fdtdec_get_int(blob, node,
-                                                "intel,update-revision", 0);
-       update->date_code = fdtdec_get_int(blob, node,
-                                          "intel,date-code", 0);
-       update->processor_signature = fdtdec_get_int(blob, node,
-                                       "intel,processor-signature", 0);
-       update->checksum = fdtdec_get_int(blob, node, "intel,checksum", 0);
-       update->loader_revision = fdtdec_get_int(blob, node,
-                                                "intel,loader-revision", 0);
-       update->processor_flags = fdtdec_get_int(blob, node,
-                                                "intel,processor-flags", 0);
-
-       return 0;
-}
-
-static inline uint32_t microcode_read_rev(void)
-{
-       /*
-        * Some Intel CPUs can be very finicky about the CPUID sequence used.
-        * So this is implemented in assembly so that it works reliably.
-        */
-       uint32_t low, high;
-
-       asm volatile (
-               "xorl %%eax, %%eax\n"
-               "xorl %%edx, %%edx\n"
-               "movl %2, %%ecx\n"
-               "wrmsr\n"
-               "movl $0x01, %%eax\n"
-               "cpuid\n"
-               "movl %2, %%ecx\n"
-               "rdmsr\n"
-               : /* outputs */
-               "=a" (low), "=d" (high)
-               : /* inputs */
-               "i" (MSR_IA32_UCODE_REV)
-               : /* clobbers */
-                "ebx", "ecx"
-       );
-
-       return high;
-}
-
-static void microcode_read_cpu(struct microcode_update *cpu)
-{
-       /* CPUID sets MSR 0x8B iff a microcode update has been loaded. */
-       unsigned int x86_model, x86_family;
-       struct cpuid_result result;
-       uint32_t low, high;
-
-       wrmsr(MSR_IA32_UCODE_REV, 0, 0);
-       result = cpuid(1);
-       rdmsr(MSR_IA32_UCODE_REV, low, cpu->update_revision);
-       x86_model = (result.eax >> 4) & 0x0f;
-       x86_family = (result.eax >> 8) & 0x0f;
-       cpu->processor_signature = result.eax;
-
-       cpu->processor_flags = 0;
-       if ((x86_model >= 5) || (x86_family > 6)) {
-               rdmsr(0x17, low, high);
-               cpu->processor_flags = 1 << ((high >> 18) & 7);
-       }
-       debug("microcode: sig=%#x pf=%#x revision=%#x\n",
-             cpu->processor_signature, cpu->processor_flags,
-             cpu->update_revision);
-}
-
-/* Get a microcode update from the device tree and apply it */
-int microcode_update_intel(void)
-{
-       struct microcode_update cpu, update;
-       const void *blob = gd->fdt_blob;
-       int skipped;
-       int count;
-       int node;
-       int ret;
-       int rev;
-
-       microcode_read_cpu(&cpu);
-       node = 0;
-       count = 0;
-       skipped = 0;
-       do {
-               node = fdtdec_next_compatible(blob, node,
-                                             COMPAT_INTEL_MICROCODE);
-               if (node < 0) {
-                       debug("%s: Found %d updates\n", __func__, count);
-                       return count ? 0 : skipped ? -EEXIST : -ENOENT;
-               }
-
-               ret = microcode_decode_node(blob, node, &update);
-               if (ret) {
-                       debug("%s: Unable to decode update: %d\n", __func__,
-                             ret);
-                       return ret;
-               }
-               if (!(update.processor_signature == cpu.processor_signature &&
-                     (update.processor_flags & cpu.processor_flags))) {
-                       debug("%s: Skipping non-matching update, sig=%x, pf=%x\n",
-                             __func__, update.processor_signature,
-                             update.processor_flags);
-                       skipped++;
-                       continue;
-               }
-               wrmsr(MSR_IA32_UCODE_WRITE, (ulong)update.data, 0);
-               rev = microcode_read_rev();
-               debug("microcode: updated to revision 0x%x date=%04x-%02x-%02x\n",
-                     rev, update.date_code & 0xffff,
-                     (update.date_code >> 24) & 0xff,
-                     (update.date_code >> 16) & 0xff);
-               if (update.update_revision != rev) {
-                       printf("Microcode update failed\n");
-                       return -EFAULT;
-               }
-               count++;
-       } while (1);
-}
diff --git a/arch/x86/include/asm/arch-ivybridge/microcode.h b/arch/x86/include/asm/arch-ivybridge/microcode.h
deleted file mode 100644 (file)
index 67f32cc..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2015 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
- */
-
-#ifndef __ASM_ARCH_MICROCODE_H
-#define __ASM_ARCH_MICROCODE_H
-
-#ifndef __ASSEMBLY__
-
-/**
- * microcode_update_intel() - Apply microcode updates
- *
- * Applies any microcode updates in the device tree.
- *
- * @return 0 if OK, -EEXIST if the updates were already applied, -ENOENT if
- * not updates were found, -EINVAL if an update was invalid
- */
-int microcode_update_intel(void);
-#endif /* __ASSEMBLY__ */
-
-#endif
diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
new file mode 100644 (file)
index 0000000..67f32cc
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __ASM_ARCH_MICROCODE_H
+#define __ASM_ARCH_MICROCODE_H
+
+#ifndef __ASSEMBLY__
+
+/**
+ * microcode_update_intel() - Apply microcode updates
+ *
+ * Applies any microcode updates in the device tree.
+ *
+ * @return 0 if OK, -EEXIST if the updates were already applied, -ENOENT if
+ * not updates were found, -EINVAL if an update was invalid
+ */
+int microcode_update_intel(void);
+#endif /* __ASSEMBLY__ */
+
+#endif