18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_MICROCODE_AMD_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_MICROCODE_AMD_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <asm/microcode.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define UCODE_MAGIC			0x00414d44
88c2ecf20Sopenharmony_ci#define UCODE_EQUIV_CPU_TABLE_TYPE	0x00000000
98c2ecf20Sopenharmony_ci#define UCODE_UCODE_TYPE		0x00000001
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define SECTION_HDR_SIZE		8
128c2ecf20Sopenharmony_ci#define CONTAINER_HDR_SZ		12
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct equiv_cpu_entry {
158c2ecf20Sopenharmony_ci	u32	installed_cpu;
168c2ecf20Sopenharmony_ci	u32	fixed_errata_mask;
178c2ecf20Sopenharmony_ci	u32	fixed_errata_compare;
188c2ecf20Sopenharmony_ci	u16	equiv_cpu;
198c2ecf20Sopenharmony_ci	u16	res;
208c2ecf20Sopenharmony_ci} __attribute__((packed));
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistruct microcode_header_amd {
238c2ecf20Sopenharmony_ci	u32	data_code;
248c2ecf20Sopenharmony_ci	u32	patch_id;
258c2ecf20Sopenharmony_ci	u16	mc_patch_data_id;
268c2ecf20Sopenharmony_ci	u8	mc_patch_data_len;
278c2ecf20Sopenharmony_ci	u8	init_flag;
288c2ecf20Sopenharmony_ci	u32	mc_patch_data_checksum;
298c2ecf20Sopenharmony_ci	u32	nb_dev_id;
308c2ecf20Sopenharmony_ci	u32	sb_dev_id;
318c2ecf20Sopenharmony_ci	u16	processor_rev_id;
328c2ecf20Sopenharmony_ci	u8	nb_rev_id;
338c2ecf20Sopenharmony_ci	u8	sb_rev_id;
348c2ecf20Sopenharmony_ci	u8	bios_api_rev;
358c2ecf20Sopenharmony_ci	u8	reserved1[3];
368c2ecf20Sopenharmony_ci	u32	match_reg[8];
378c2ecf20Sopenharmony_ci} __attribute__((packed));
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistruct microcode_amd {
408c2ecf20Sopenharmony_ci	struct microcode_header_amd	hdr;
418c2ecf20Sopenharmony_ci	unsigned int			mpb[0];
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define PATCH_MAX_SIZE (3 * PAGE_SIZE)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#ifdef CONFIG_MICROCODE_AMD
478c2ecf20Sopenharmony_ciextern void __init load_ucode_amd_bsp(unsigned int family);
488c2ecf20Sopenharmony_ciextern void load_ucode_amd_ap(unsigned int family);
498c2ecf20Sopenharmony_ciextern int __init save_microcode_in_initrd_amd(unsigned int family);
508c2ecf20Sopenharmony_civoid reload_ucode_amd(unsigned int cpu);
518c2ecf20Sopenharmony_ciextern void amd_check_microcode(void);
528c2ecf20Sopenharmony_ci#else
538c2ecf20Sopenharmony_cistatic inline void __init load_ucode_amd_bsp(unsigned int family) {}
548c2ecf20Sopenharmony_cistatic inline void load_ucode_amd_ap(unsigned int family) {}
558c2ecf20Sopenharmony_cistatic inline int __init
568c2ecf20Sopenharmony_cisave_microcode_in_initrd_amd(unsigned int family) { return -EINVAL; }
578c2ecf20Sopenharmony_cistatic inline void reload_ucode_amd(unsigned int cpu) {}
588c2ecf20Sopenharmony_cistatic inline void amd_check_microcode(void) {}
598c2ecf20Sopenharmony_ci#endif
608c2ecf20Sopenharmony_ci#endif /* _ASM_X86_MICROCODE_AMD_H */
61