microcode_core_early.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * X86 CPU microcode early update for Linux
  3. *
  4. * Copyright (C) 2012 Fenghua Yu <fenghua.yu@intel.com>
  5. * H Peter Anvin" <hpa@zytor.com>
  6. *
  7. * This driver allows to early 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 9.11 of Volume 3, IA-32 Intel Architecture
  12. * Software Developer's Manual.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. */
  19. #include <linux/module.h>
  20. #include <asm/microcode_intel.h>
  21. #include <asm/processor.h>
  22. #define QCHAR(a, b, c, d) ((a) + ((b) << 8) + ((c) << 16) + ((d) << 24))
  23. #define CPUID_INTEL1 QCHAR('G', 'e', 'n', 'u')
  24. #define CPUID_INTEL2 QCHAR('i', 'n', 'e', 'I')
  25. #define CPUID_INTEL3 QCHAR('n', 't', 'e', 'l')
  26. #define CPUID_AMD1 QCHAR('A', 'u', 't', 'h')
  27. #define CPUID_AMD2 QCHAR('e', 'n', 't', 'i')
  28. #define CPUID_AMD3 QCHAR('c', 'A', 'M', 'D')
  29. #define CPUID_IS(a, b, c, ebx, ecx, edx) \
  30. (!((ebx ^ (a))|(edx ^ (b))|(ecx ^ (c))))
  31. /*
  32. * In early loading microcode phase on BSP, boot_cpu_data is not set up yet.
  33. * x86_vendor() gets vendor id for BSP.
  34. *
  35. * In 32 bit AP case, accessing boot_cpu_data needs linear address. To simplify
  36. * coding, we still use x86_vendor() to get vendor id for AP.
  37. *
  38. * x86_vendor() gets vendor information directly through cpuid.
  39. */
  40. static int __cpuinit x86_vendor(void)
  41. {
  42. u32 eax = 0x00000000;
  43. u32 ebx, ecx = 0, edx;
  44. native_cpuid(&eax, &ebx, &ecx, &edx);
  45. if (CPUID_IS(CPUID_INTEL1, CPUID_INTEL2, CPUID_INTEL3, ebx, ecx, edx))
  46. return X86_VENDOR_INTEL;
  47. if (CPUID_IS(CPUID_AMD1, CPUID_AMD2, CPUID_AMD3, ebx, ecx, edx))
  48. return X86_VENDOR_AMD;
  49. return X86_VENDOR_UNKNOWN;
  50. }
  51. static int __cpuinit x86_family(void)
  52. {
  53. u32 eax = 0x00000001;
  54. u32 ebx, ecx = 0, edx;
  55. int x86;
  56. native_cpuid(&eax, &ebx, &ecx, &edx);
  57. x86 = (eax >> 8) & 0xf;
  58. if (x86 == 15)
  59. x86 += (eax >> 20) & 0xff;
  60. return x86;
  61. }
  62. void __init load_ucode_bsp(void)
  63. {
  64. int vendor, x86;
  65. if (!have_cpuid_p())
  66. return;
  67. vendor = x86_vendor();
  68. x86 = x86_family();
  69. if (vendor == X86_VENDOR_INTEL && x86 >= 6)
  70. load_ucode_intel_bsp();
  71. }
  72. void __cpuinit load_ucode_ap(void)
  73. {
  74. int vendor, x86;
  75. if (!have_cpuid_p())
  76. return;
  77. vendor = x86_vendor();
  78. x86 = x86_family();
  79. if (vendor == X86_VENDOR_INTEL && x86 >= 6)
  80. load_ucode_intel_ap();
  81. }