18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_MICROCODE_INTEL_H 38c2ecf20Sopenharmony_ci#define _ASM_X86_MICROCODE_INTEL_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm/microcode.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_cistruct microcode_header_intel { 88c2ecf20Sopenharmony_ci unsigned int hdrver; 98c2ecf20Sopenharmony_ci unsigned int rev; 108c2ecf20Sopenharmony_ci unsigned int date; 118c2ecf20Sopenharmony_ci unsigned int sig; 128c2ecf20Sopenharmony_ci unsigned int cksum; 138c2ecf20Sopenharmony_ci unsigned int ldrver; 148c2ecf20Sopenharmony_ci unsigned int pf; 158c2ecf20Sopenharmony_ci unsigned int datasize; 168c2ecf20Sopenharmony_ci unsigned int totalsize; 178c2ecf20Sopenharmony_ci unsigned int reserved[3]; 188c2ecf20Sopenharmony_ci}; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct microcode_intel { 218c2ecf20Sopenharmony_ci struct microcode_header_intel hdr; 228c2ecf20Sopenharmony_ci unsigned int bits[0]; 238c2ecf20Sopenharmony_ci}; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* microcode format is extended from prescott processors */ 268c2ecf20Sopenharmony_cistruct extended_signature { 278c2ecf20Sopenharmony_ci unsigned int sig; 288c2ecf20Sopenharmony_ci unsigned int pf; 298c2ecf20Sopenharmony_ci unsigned int cksum; 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct extended_sigtable { 338c2ecf20Sopenharmony_ci unsigned int count; 348c2ecf20Sopenharmony_ci unsigned int cksum; 358c2ecf20Sopenharmony_ci unsigned int reserved[3]; 368c2ecf20Sopenharmony_ci struct extended_signature sigs[0]; 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define DEFAULT_UCODE_DATASIZE (2000) 408c2ecf20Sopenharmony_ci#define MC_HEADER_SIZE (sizeof(struct microcode_header_intel)) 418c2ecf20Sopenharmony_ci#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) 428c2ecf20Sopenharmony_ci#define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) 438c2ecf20Sopenharmony_ci#define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define get_totalsize(mc) \ 468c2ecf20Sopenharmony_ci (((struct microcode_intel *)mc)->hdr.datasize ? \ 478c2ecf20Sopenharmony_ci ((struct microcode_intel *)mc)->hdr.totalsize : \ 488c2ecf20Sopenharmony_ci DEFAULT_UCODE_TOTALSIZE) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define get_datasize(mc) \ 518c2ecf20Sopenharmony_ci (((struct microcode_intel *)mc)->hdr.datasize ? \ 528c2ecf20Sopenharmony_ci ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic inline u32 intel_get_microcode_revision(void) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci u32 rev, dummy; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci native_wrmsrl(MSR_IA32_UCODE_REV, 0); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci /* As documented in the SDM: Do a CPUID 1 here */ 638c2ecf20Sopenharmony_ci native_cpuid_eax(1); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci /* get the current revision from MSR 0x8B */ 668c2ecf20Sopenharmony_ci native_rdmsr(MSR_IA32_UCODE_REV, dummy, rev); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci return rev; 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#ifdef CONFIG_MICROCODE_INTEL 728c2ecf20Sopenharmony_ciextern void __init load_ucode_intel_bsp(void); 738c2ecf20Sopenharmony_ciextern void load_ucode_intel_ap(void); 748c2ecf20Sopenharmony_ciextern void show_ucode_info_early(void); 758c2ecf20Sopenharmony_ciextern int __init save_microcode_in_initrd_intel(void); 768c2ecf20Sopenharmony_civoid reload_ucode_intel(void); 778c2ecf20Sopenharmony_ci#else 788c2ecf20Sopenharmony_cistatic inline __init void load_ucode_intel_bsp(void) {} 798c2ecf20Sopenharmony_cistatic inline void load_ucode_intel_ap(void) {} 808c2ecf20Sopenharmony_cistatic inline void show_ucode_info_early(void) {} 818c2ecf20Sopenharmony_cistatic inline int __init save_microcode_in_initrd_intel(void) { return -EINVAL; } 828c2ecf20Sopenharmony_cistatic inline void reload_ucode_intel(void) {} 838c2ecf20Sopenharmony_ci#endif 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#endif /* _ASM_X86_MICROCODE_INTEL_H */ 86