Jacob Shin | a76096a | 2013-05-30 14:09:18 -0500 | [diff] [blame] | 1 | #ifndef _ASM_X86_MICROCODE_AMD_H |
| 2 | #define _ASM_X86_MICROCODE_AMD_H |
| 3 | |
| 4 | #include <asm/microcode.h> |
| 5 | |
| 6 | #define UCODE_MAGIC 0x00414d44 |
| 7 | #define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000 |
| 8 | #define UCODE_UCODE_TYPE 0x00000001 |
| 9 | |
| 10 | #define SECTION_HDR_SIZE 8 |
| 11 | #define CONTAINER_HDR_SZ 12 |
| 12 | |
| 13 | struct equiv_cpu_entry { |
| 14 | u32 installed_cpu; |
| 15 | u32 fixed_errata_mask; |
| 16 | u32 fixed_errata_compare; |
| 17 | u16 equiv_cpu; |
| 18 | u16 res; |
| 19 | } __attribute__((packed)); |
| 20 | |
| 21 | struct microcode_header_amd { |
| 22 | u32 data_code; |
| 23 | u32 patch_id; |
| 24 | u16 mc_patch_data_id; |
| 25 | u8 mc_patch_data_len; |
| 26 | u8 init_flag; |
| 27 | u32 mc_patch_data_checksum; |
| 28 | u32 nb_dev_id; |
| 29 | u32 sb_dev_id; |
| 30 | u16 processor_rev_id; |
| 31 | u8 nb_rev_id; |
| 32 | u8 sb_rev_id; |
| 33 | u8 bios_api_rev; |
| 34 | u8 reserved1[3]; |
| 35 | u32 match_reg[8]; |
| 36 | } __attribute__((packed)); |
| 37 | |
| 38 | struct microcode_amd { |
| 39 | struct microcode_header_amd hdr; |
| 40 | unsigned int mpb[0]; |
| 41 | }; |
| 42 | |
| 43 | static inline u16 find_equiv_id(struct equiv_cpu_entry *equiv_cpu_table, |
| 44 | unsigned int sig) |
| 45 | { |
| 46 | int i = 0; |
| 47 | |
| 48 | if (!equiv_cpu_table) |
| 49 | return 0; |
| 50 | |
| 51 | while (equiv_cpu_table[i].installed_cpu != 0) { |
| 52 | if (sig == equiv_cpu_table[i].installed_cpu) |
| 53 | return equiv_cpu_table[i].equiv_cpu; |
| 54 | |
| 55 | i++; |
| 56 | } |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | extern int __apply_microcode_amd(struct microcode_amd *mc_amd); |
| 61 | extern int apply_microcode_amd(int cpu); |
Borislav Petkov | 2ef84b3 | 2014-12-01 11:12:21 +0100 | [diff] [blame] | 62 | extern enum ucode_state load_microcode_amd(int cpu, u8 family, const u8 *data, size_t size); |
Jacob Shin | a76096a | 2013-05-30 14:09:18 -0500 | [diff] [blame] | 63 | |
Borislav Petkov | 5335ba5 | 2013-11-29 14:58:44 +0100 | [diff] [blame] | 64 | #define PATCH_MAX_SIZE PAGE_SIZE |
| 65 | extern u8 amd_ucode_patch[PATCH_MAX_SIZE]; |
| 66 | |
Jacob Shin | 757885e | 2013-05-30 14:09:19 -0500 | [diff] [blame] | 67 | #ifdef CONFIG_MICROCODE_AMD_EARLY |
Andy Shevchenko | 7b179b8 | 2015-06-04 18:55:28 +0200 | [diff] [blame] | 68 | extern void __init load_ucode_amd_bsp(unsigned int family); |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 69 | extern void load_ucode_amd_ap(void); |
Jacob Shin | 757885e | 2013-05-30 14:09:19 -0500 | [diff] [blame] | 70 | extern int __init save_microcode_in_initrd_amd(void); |
Borislav Petkov | fbae4ba | 2014-12-03 17:21:41 +0100 | [diff] [blame] | 71 | void reload_ucode_amd(void); |
Jacob Shin | 757885e | 2013-05-30 14:09:19 -0500 | [diff] [blame] | 72 | #else |
Andy Shevchenko | 7b179b8 | 2015-06-04 18:55:28 +0200 | [diff] [blame] | 73 | static inline void __init load_ucode_amd_bsp(unsigned int family) {} |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 74 | static inline void load_ucode_amd_ap(void) {} |
Jacob Shin | 757885e | 2013-05-30 14:09:19 -0500 | [diff] [blame] | 75 | static inline int __init save_microcode_in_initrd_amd(void) { return -EINVAL; } |
Borislav Petkov | fbae4ba | 2014-12-03 17:21:41 +0100 | [diff] [blame] | 76 | void reload_ucode_amd(void) {} |
Jacob Shin | 757885e | 2013-05-30 14:09:19 -0500 | [diff] [blame] | 77 | #endif |
| 78 | |
Jacob Shin | a76096a | 2013-05-30 14:09:18 -0500 | [diff] [blame] | 79 | #endif /* _ASM_X86_MICROCODE_AMD_H */ |