Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 1 | #ifndef _ASM_X86_MICROCODE_INTEL_H |
| 2 | #define _ASM_X86_MICROCODE_INTEL_H |
| 3 | |
| 4 | #include <asm/microcode.h> |
| 5 | |
| 6 | struct microcode_header_intel { |
| 7 | unsigned int hdrver; |
| 8 | unsigned int rev; |
| 9 | unsigned int date; |
| 10 | unsigned int sig; |
| 11 | unsigned int cksum; |
| 12 | unsigned int ldrver; |
| 13 | unsigned int pf; |
| 14 | unsigned int datasize; |
| 15 | unsigned int totalsize; |
| 16 | unsigned int reserved[3]; |
| 17 | }; |
| 18 | |
| 19 | struct microcode_intel { |
| 20 | struct microcode_header_intel hdr; |
| 21 | unsigned int bits[0]; |
| 22 | }; |
| 23 | |
| 24 | /* microcode format is extended from prescott processors */ |
| 25 | struct extended_signature { |
| 26 | unsigned int sig; |
| 27 | unsigned int pf; |
| 28 | unsigned int cksum; |
| 29 | }; |
| 30 | |
| 31 | struct extended_sigtable { |
| 32 | unsigned int count; |
| 33 | unsigned int cksum; |
| 34 | unsigned int reserved[3]; |
| 35 | struct extended_signature sigs[0]; |
| 36 | }; |
| 37 | |
| 38 | #define DEFAULT_UCODE_DATASIZE (2000) |
| 39 | #define MC_HEADER_SIZE (sizeof(struct microcode_header_intel)) |
| 40 | #define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) |
| 41 | #define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) |
| 42 | #define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 43 | |
| 44 | #define get_totalsize(mc) \ |
Henrique de Moraes Holschuh | ebc14dd | 2014-07-23 17:10:49 -0300 | [diff] [blame] | 45 | (((struct microcode_intel *)mc)->hdr.datasize ? \ |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 46 | ((struct microcode_intel *)mc)->hdr.totalsize : \ |
| 47 | DEFAULT_UCODE_TOTALSIZE) |
| 48 | |
| 49 | #define get_datasize(mc) \ |
| 50 | (((struct microcode_intel *)mc)->hdr.datasize ? \ |
| 51 | ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE) |
| 52 | |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 53 | #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) |
| 54 | |
Borislav Petkov | 4167709 | 2017-01-09 12:41:45 +0100 | [diff] [blame^] | 55 | static inline u32 intel_get_microcode_revision(void) |
| 56 | { |
| 57 | u32 rev, dummy; |
| 58 | |
| 59 | native_wrmsrl(MSR_IA32_UCODE_REV, 0); |
| 60 | |
| 61 | /* As documented in the SDM: Do a CPUID 1 here */ |
| 62 | native_cpuid_eax(1); |
| 63 | |
| 64 | /* get the current revision from MSR 0x8B */ |
| 65 | native_rdmsr(MSR_IA32_UCODE_REV, dummy, rev); |
| 66 | |
| 67 | return rev; |
| 68 | } |
| 69 | |
Borislav Petkov | fe05589 | 2015-10-20 11:54:45 +0200 | [diff] [blame] | 70 | #ifdef CONFIG_MICROCODE_INTEL |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 71 | extern void __init load_ucode_intel_bsp(void); |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 72 | extern void load_ucode_intel_ap(void); |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 73 | extern void show_ucode_info_early(void); |
Jacob Shin | f2b3ee8 | 2013-05-30 14:09:17 -0500 | [diff] [blame] | 74 | extern int __init save_microcode_in_initrd_intel(void); |
Borislav Petkov | fbae4ba | 2014-12-03 17:21:41 +0100 | [diff] [blame] | 75 | void reload_ucode_intel(void); |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 76 | #else |
| 77 | static inline __init void load_ucode_intel_bsp(void) {} |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 78 | static inline void load_ucode_intel_ap(void) {} |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 79 | static inline void show_ucode_info_early(void) {} |
Jacob Shin | f2b3ee8 | 2013-05-30 14:09:17 -0500 | [diff] [blame] | 80 | static inline int __init save_microcode_in_initrd_intel(void) { return -EINVAL; } |
Borislav Petkov | fbae4ba | 2014-12-03 17:21:41 +0100 | [diff] [blame] | 81 | static inline void reload_ucode_intel(void) {} |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 82 | #endif |
| 83 | |
Fenghua Yu | 9cd4d78 | 2012-12-20 23:44:22 -0800 | [diff] [blame] | 84 | #endif /* _ASM_X86_MICROCODE_INTEL_H */ |