microcode_intel.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_MICROCODE_INTEL_H
  3. #define _ASM_X86_MICROCODE_INTEL_H
  4. #include <asm/microcode.h>
  5. struct microcode_header_intel {
  6. unsigned int hdrver;
  7. unsigned int rev;
  8. unsigned int date;
  9. unsigned int sig;
  10. unsigned int cksum;
  11. unsigned int ldrver;
  12. unsigned int pf;
  13. unsigned int datasize;
  14. unsigned int totalsize;
  15. unsigned int reserved[3];
  16. };
  17. struct microcode_intel {
  18. struct microcode_header_intel hdr;
  19. unsigned int bits[];
  20. };
  21. /* microcode format is extended from prescott processors */
  22. struct extended_signature {
  23. unsigned int sig;
  24. unsigned int pf;
  25. unsigned int cksum;
  26. };
  27. struct extended_sigtable {
  28. unsigned int count;
  29. unsigned int cksum;
  30. unsigned int reserved[3];
  31. struct extended_signature sigs[];
  32. };
  33. #define DEFAULT_UCODE_DATASIZE (2000)
  34. #define MC_HEADER_SIZE (sizeof(struct microcode_header_intel))
  35. #define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE)
  36. #define EXT_HEADER_SIZE (sizeof(struct extended_sigtable))
  37. #define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature))
  38. #define get_totalsize(mc) \
  39. (((struct microcode_intel *)mc)->hdr.datasize ? \
  40. ((struct microcode_intel *)mc)->hdr.totalsize : \
  41. DEFAULT_UCODE_TOTALSIZE)
  42. #define get_datasize(mc) \
  43. (((struct microcode_intel *)mc)->hdr.datasize ? \
  44. ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE)
  45. #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)
  46. static inline u32 intel_get_microcode_revision(void)
  47. {
  48. u32 rev, dummy;
  49. native_wrmsrl(MSR_IA32_UCODE_REV, 0);
  50. /* As documented in the SDM: Do a CPUID 1 here */
  51. native_cpuid_eax(1);
  52. /* get the current revision from MSR 0x8B */
  53. native_rdmsr(MSR_IA32_UCODE_REV, dummy, rev);
  54. return rev;
  55. }
  56. #ifdef CONFIG_MICROCODE_INTEL
  57. extern void __init load_ucode_intel_bsp(void);
  58. extern void load_ucode_intel_ap(void);
  59. extern void show_ucode_info_early(void);
  60. extern int __init save_microcode_in_initrd_intel(void);
  61. void reload_ucode_intel(void);
  62. #else
  63. static inline __init void load_ucode_intel_bsp(void) {}
  64. static inline void load_ucode_intel_ap(void) {}
  65. static inline void show_ucode_info_early(void) {}
  66. static inline int __init save_microcode_in_initrd_intel(void) { return -EINVAL; }
  67. static inline void reload_ucode_intel(void) {}
  68. #endif
  69. #endif /* _ASM_X86_MICROCODE_INTEL_H */