Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_X86_MICROCODE_H
0003 #define _ASM_X86_MICROCODE_H
0004 
0005 #include <asm/cpu.h>
0006 #include <linux/earlycpio.h>
0007 #include <linux/initrd.h>
0008 
0009 struct ucode_patch {
0010     struct list_head plist;
0011     void *data;     /* Intel uses only this one */
0012     u32 patch_id;
0013     u16 equiv_cpu;
0014 };
0015 
0016 extern struct list_head microcode_cache;
0017 
0018 struct cpu_signature {
0019     unsigned int sig;
0020     unsigned int pf;
0021     unsigned int rev;
0022 };
0023 
0024 struct device;
0025 
0026 enum ucode_state {
0027     UCODE_OK    = 0,
0028     UCODE_NEW,
0029     UCODE_UPDATED,
0030     UCODE_NFOUND,
0031     UCODE_ERROR,
0032 };
0033 
0034 struct microcode_ops {
0035     enum ucode_state (*request_microcode_user) (int cpu,
0036                 const void __user *buf, size_t size);
0037 
0038     enum ucode_state (*request_microcode_fw) (int cpu, struct device *,
0039                           bool refresh_fw);
0040 
0041     void (*microcode_fini_cpu) (int cpu);
0042 
0043     /*
0044      * The generic 'microcode_core' part guarantees that
0045      * the callbacks below run on a target cpu when they
0046      * are being called.
0047      * See also the "Synchronization" section in microcode_core.c.
0048      */
0049     enum ucode_state (*apply_microcode) (int cpu);
0050     int (*collect_cpu_info) (int cpu, struct cpu_signature *csig);
0051 };
0052 
0053 struct ucode_cpu_info {
0054     struct cpu_signature    cpu_sig;
0055     int         valid;
0056     void            *mc;
0057 };
0058 extern struct ucode_cpu_info ucode_cpu_info[];
0059 struct cpio_data find_microcode_in_initrd(const char *path, bool use_pa);
0060 
0061 #ifdef CONFIG_MICROCODE_INTEL
0062 extern struct microcode_ops * __init init_intel_microcode(void);
0063 #else
0064 static inline struct microcode_ops * __init init_intel_microcode(void)
0065 {
0066     return NULL;
0067 }
0068 #endif /* CONFIG_MICROCODE_INTEL */
0069 
0070 #ifdef CONFIG_MICROCODE_AMD
0071 extern struct microcode_ops * __init init_amd_microcode(void);
0072 extern void __exit exit_amd_microcode(void);
0073 #else
0074 static inline struct microcode_ops * __init init_amd_microcode(void)
0075 {
0076     return NULL;
0077 }
0078 static inline void __exit exit_amd_microcode(void) {}
0079 #endif
0080 
0081 #define MAX_UCODE_COUNT 128
0082 
0083 #define QCHAR(a, b, c, d) ((a) + ((b) << 8) + ((c) << 16) + ((d) << 24))
0084 #define CPUID_INTEL1 QCHAR('G', 'e', 'n', 'u')
0085 #define CPUID_INTEL2 QCHAR('i', 'n', 'e', 'I')
0086 #define CPUID_INTEL3 QCHAR('n', 't', 'e', 'l')
0087 #define CPUID_AMD1 QCHAR('A', 'u', 't', 'h')
0088 #define CPUID_AMD2 QCHAR('e', 'n', 't', 'i')
0089 #define CPUID_AMD3 QCHAR('c', 'A', 'M', 'D')
0090 
0091 #define CPUID_IS(a, b, c, ebx, ecx, edx)    \
0092         (!((ebx ^ (a))|(edx ^ (b))|(ecx ^ (c))))
0093 
0094 /*
0095  * In early loading microcode phase on BSP, boot_cpu_data is not set up yet.
0096  * x86_cpuid_vendor() gets vendor id for BSP.
0097  *
0098  * In 32 bit AP case, accessing boot_cpu_data needs linear address. To simplify
0099  * coding, we still use x86_cpuid_vendor() to get vendor id for AP.
0100  *
0101  * x86_cpuid_vendor() gets vendor information directly from CPUID.
0102  */
0103 static inline int x86_cpuid_vendor(void)
0104 {
0105     u32 eax = 0x00000000;
0106     u32 ebx, ecx = 0, edx;
0107 
0108     native_cpuid(&eax, &ebx, &ecx, &edx);
0109 
0110     if (CPUID_IS(CPUID_INTEL1, CPUID_INTEL2, CPUID_INTEL3, ebx, ecx, edx))
0111         return X86_VENDOR_INTEL;
0112 
0113     if (CPUID_IS(CPUID_AMD1, CPUID_AMD2, CPUID_AMD3, ebx, ecx, edx))
0114         return X86_VENDOR_AMD;
0115 
0116     return X86_VENDOR_UNKNOWN;
0117 }
0118 
0119 static inline unsigned int x86_cpuid_family(void)
0120 {
0121     u32 eax = 0x00000001;
0122     u32 ebx, ecx = 0, edx;
0123 
0124     native_cpuid(&eax, &ebx, &ecx, &edx);
0125 
0126     return x86_family(eax);
0127 }
0128 
0129 #ifdef CONFIG_MICROCODE
0130 extern void __init load_ucode_bsp(void);
0131 extern void load_ucode_ap(void);
0132 void reload_early_microcode(void);
0133 extern bool initrd_gone;
0134 void microcode_bsp_resume(void);
0135 #else
0136 static inline void __init load_ucode_bsp(void)          { }
0137 static inline void load_ucode_ap(void)              { }
0138 static inline void reload_early_microcode(void)         { }
0139 static inline void microcode_bsp_resume(void)           { }
0140 #endif
0141 
0142 #endif /* _ASM_X86_MICROCODE_H */