microcode.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #ifndef _ASM_X86_MICROCODE_H
  2. #define _ASM_X86_MICROCODE_H
  3. #include <asm/cpu.h>
  4. #include <linux/earlycpio.h>
  5. #include <linux/initrd.h>
  6. #define native_rdmsr(msr, val1, val2) \
  7. do { \
  8. u64 __val = __rdmsr((msr)); \
  9. (void)((val1) = (u32)__val); \
  10. (void)((val2) = (u32)(__val >> 32)); \
  11. } while (0)
  12. #define native_wrmsr(msr, low, high) \
  13. __wrmsr(msr, low, high)
  14. #define native_wrmsrl(msr, val) \
  15. __wrmsr((msr), (u32)((u64)(val)), \
  16. (u32)((u64)(val) >> 32))
  17. struct ucode_patch {
  18. struct list_head plist;
  19. void *data; /* Intel uses only this one */
  20. u32 patch_id;
  21. u16 equiv_cpu;
  22. };
  23. extern struct list_head microcode_cache;
  24. struct cpu_signature {
  25. unsigned int sig;
  26. unsigned int pf;
  27. unsigned int rev;
  28. };
  29. struct device;
  30. enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
  31. struct microcode_ops {
  32. enum ucode_state (*request_microcode_user) (int cpu,
  33. const void __user *buf, size_t size);
  34. enum ucode_state (*request_microcode_fw) (int cpu, struct device *,
  35. bool refresh_fw);
  36. void (*microcode_fini_cpu) (int cpu);
  37. /*
  38. * The generic 'microcode_core' part guarantees that
  39. * the callbacks below run on a target cpu when they
  40. * are being called.
  41. * See also the "Synchronization" section in microcode_core.c.
  42. */
  43. int (*apply_microcode) (int cpu);
  44. int (*collect_cpu_info) (int cpu, struct cpu_signature *csig);
  45. };
  46. struct ucode_cpu_info {
  47. struct cpu_signature cpu_sig;
  48. int valid;
  49. void *mc;
  50. };
  51. extern struct ucode_cpu_info ucode_cpu_info[];
  52. struct cpio_data find_microcode_in_initrd(const char *path, bool use_pa);
  53. #ifdef CONFIG_MICROCODE_INTEL
  54. extern struct microcode_ops * __init init_intel_microcode(void);
  55. #else
  56. static inline struct microcode_ops * __init init_intel_microcode(void)
  57. {
  58. return NULL;
  59. }
  60. #endif /* CONFIG_MICROCODE_INTEL */
  61. #ifdef CONFIG_MICROCODE_AMD
  62. extern struct microcode_ops * __init init_amd_microcode(void);
  63. extern void __exit exit_amd_microcode(void);
  64. #else
  65. static inline struct microcode_ops * __init init_amd_microcode(void)
  66. {
  67. return NULL;
  68. }
  69. static inline void __exit exit_amd_microcode(void) {}
  70. #endif
  71. #define MAX_UCODE_COUNT 128
  72. #define QCHAR(a, b, c, d) ((a) + ((b) << 8) + ((c) << 16) + ((d) << 24))
  73. #define CPUID_INTEL1 QCHAR('G', 'e', 'n', 'u')
  74. #define CPUID_INTEL2 QCHAR('i', 'n', 'e', 'I')
  75. #define CPUID_INTEL3 QCHAR('n', 't', 'e', 'l')
  76. #define CPUID_AMD1 QCHAR('A', 'u', 't', 'h')
  77. #define CPUID_AMD2 QCHAR('e', 'n', 't', 'i')
  78. #define CPUID_AMD3 QCHAR('c', 'A', 'M', 'D')
  79. #define CPUID_IS(a, b, c, ebx, ecx, edx) \
  80. (!((ebx ^ (a))|(edx ^ (b))|(ecx ^ (c))))
  81. /*
  82. * In early loading microcode phase on BSP, boot_cpu_data is not set up yet.
  83. * x86_cpuid_vendor() gets vendor id for BSP.
  84. *
  85. * In 32 bit AP case, accessing boot_cpu_data needs linear address. To simplify
  86. * coding, we still use x86_cpuid_vendor() to get vendor id for AP.
  87. *
  88. * x86_cpuid_vendor() gets vendor information directly from CPUID.
  89. */
  90. static inline int x86_cpuid_vendor(void)
  91. {
  92. u32 eax = 0x00000000;
  93. u32 ebx, ecx = 0, edx;
  94. native_cpuid(&eax, &ebx, &ecx, &edx);
  95. if (CPUID_IS(CPUID_INTEL1, CPUID_INTEL2, CPUID_INTEL3, ebx, ecx, edx))
  96. return X86_VENDOR_INTEL;
  97. if (CPUID_IS(CPUID_AMD1, CPUID_AMD2, CPUID_AMD3, ebx, ecx, edx))
  98. return X86_VENDOR_AMD;
  99. return X86_VENDOR_UNKNOWN;
  100. }
  101. static inline unsigned int x86_cpuid_family(void)
  102. {
  103. u32 eax = 0x00000001;
  104. u32 ebx, ecx = 0, edx;
  105. native_cpuid(&eax, &ebx, &ecx, &edx);
  106. return x86_family(eax);
  107. }
  108. #ifdef CONFIG_MICROCODE
  109. int __init microcode_init(void);
  110. extern void __init load_ucode_bsp(void);
  111. extern void load_ucode_ap(void);
  112. void reload_early_microcode(void);
  113. extern bool get_builtin_firmware(struct cpio_data *cd, const char *name);
  114. extern bool initrd_gone;
  115. #else
  116. static inline int __init microcode_init(void) { return 0; };
  117. static inline void __init load_ucode_bsp(void) { }
  118. static inline void load_ucode_ap(void) { }
  119. static inline void reload_early_microcode(void) { }
  120. static inline bool
  121. get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; }
  122. #endif
  123. #endif /* _ASM_X86_MICROCODE_H */