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