blob: b59827e765292459247baa6866329ddec3e7fa91 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_MICROCODE_H
2#define _ASM_X86_MICROCODE_H
Dmitry Adamushkod45de402008-08-20 00:22:26 +02003
Borislav Petkove1b43e32013-12-04 12:31:31 +01004#define native_rdmsr(msr, val1, val2) \
5do { \
6 u64 __val = native_read_msr((msr)); \
7 (void)((val1) = (u32)__val); \
8 (void)((val2) = (u32)(__val >> 32)); \
9} while (0)
10
11#define native_wrmsr(msr, low, high) \
12 native_write_msr(msr, low, high)
13
14#define native_wrmsrl(msr, val) \
15 native_write_msr((msr), \
16 (u32)((u64)(val)), \
17 (u32)((u64)(val) >> 32))
18
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020019struct cpu_signature {
20 unsigned int sig;
21 unsigned int pf;
22 unsigned int rev;
23};
Peter Oruba8d86f392008-07-28 18:44:21 +020024
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +020025struct device;
Dmitry Adamushkod45de402008-08-20 00:22:26 +020026
Dmitry Adamushko871b72d2009-05-11 23:48:27 +020027enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
28
Peter Oruba26bf7a42008-07-28 18:44:20 +020029struct microcode_ops {
Dmitry Adamushko871b72d2009-05-11 23:48:27 +020030 enum ucode_state (*request_microcode_user) (int cpu,
31 const void __user *buf, size_t size);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +020032
Borislav Petkov48e30682012-07-26 15:51:00 +020033 enum ucode_state (*request_microcode_fw) (int cpu, struct device *,
34 bool refresh_fw);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +020035
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +020036 void (*microcode_fini_cpu) (int cpu);
Dmitry Adamushko871b72d2009-05-11 23:48:27 +020037
38 /*
39 * The generic 'microcode_core' part guarantees that
40 * the callbacks below run on a target cpu when they
41 * are being called.
42 * See also the "Synchronization" section in microcode_core.c.
43 */
44 int (*apply_microcode) (int cpu);
45 int (*collect_cpu_info) (int cpu, struct cpu_signature *csig);
Peter Oruba26bf7a42008-07-28 18:44:20 +020046};
47
Dmitry Adamushkod45de402008-08-20 00:22:26 +020048struct ucode_cpu_info {
Dmitry Adamushko871b72d2009-05-11 23:48:27 +020049 struct cpu_signature cpu_sig;
50 int valid;
51 void *mc;
Peter Orubac3b71bc2008-07-28 18:44:15 +020052};
Dmitry Adamushkod45de402008-08-20 00:22:26 +020053extern struct ucode_cpu_info ucode_cpu_info[];
54
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020055#ifdef CONFIG_MICROCODE_INTEL
56extern struct microcode_ops * __init init_intel_microcode(void);
57#else
58static inline struct microcode_ops * __init init_intel_microcode(void)
59{
60 return NULL;
61}
62#endif /* CONFIG_MICROCODE_INTEL */
63
64#ifdef CONFIG_MICROCODE_AMD
65extern struct microcode_ops * __init init_amd_microcode(void);
Borislav Petkovf72c1a52011-12-02 16:50:04 +010066extern void __exit exit_amd_microcode(void);
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020067#else
68static inline struct microcode_ops * __init init_amd_microcode(void)
69{
70 return NULL;
71}
Borislav Petkovf72c1a52011-12-02 16:50:04 +010072static inline void __exit exit_amd_microcode(void) {}
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020073#endif
74
Fenghua Yua8ebf6d2012-12-20 23:44:25 -080075#ifdef CONFIG_MICROCODE_EARLY
76#define MAX_UCODE_COUNT 128
77extern void __init load_ucode_bsp(void);
Paul Gortmaker148f9bb2013-06-18 18:23:59 -040078extern void load_ucode_ap(void);
Fenghua Yua8ebf6d2012-12-20 23:44:25 -080079extern int __init save_microcode_in_initrd(void);
80#else
81static inline void __init load_ucode_bsp(void) {}
Paul Gortmaker148f9bb2013-06-18 18:23:59 -040082static inline void load_ucode_ap(void) {}
Fenghua Yua8ebf6d2012-12-20 23:44:25 -080083static inline int __init save_microcode_in_initrd(void)
84{
85 return 0;
86}
87#endif
88
H. Peter Anvin1965aae2008-10-22 22:26:29 -070089#endif /* _ASM_X86_MICROCODE_H */