1 #ifndef ASM_X86_MICROCODE_PRIVATE_H
2 #define ASM_X86_MICROCODE_PRIVATE_H
3 
4 #include <public/platform.h>
5 
6 #include <asm/microcode.h>
7 
8 /* Opaque.  Internals are vendor-specific. */
9 struct microcode_patch;
10 
11 struct microcode_ops {
12     /*
13      * Parse a microcode container.  Format is vendor-specific.
14      *
15      * Search within the container for the patch, suitable for the current
16      * CPU, which has the highest revision.  (Note: May be a patch which is
17      * older that what is running in the CPU.  This is a feature, to better
18      * cope with corner cases from buggy firmware.)
19      *
20      * If one is found, behaviour depends on the make_copy argument:
21      *
22      *     true: allocate and return a struct microcode_patch encapsulating
23      *           the appropriate microcode patch.  Does not alias the original
24      *           buffer.  Must be suitable to be freed with a single xfree().
25      *
26      *    false: return a pointer to the patch within the original buffer.
27      *           This is useful for early microcode loading when xmalloc might
28      *           not be available yet.
29      *
30      * If one is not found, (nothing matches the current CPU), return NULL.
31      * Also may return ERR_PTR(-err), e.g. bad container, out of memory.
32      */
33     struct microcode_patch *(*cpu_request_microcode)(
34         const void *buf, size_t size, bool make_copy);
35 
36     /*
37      * Obtain microcode-relevant details for the current CPU.  Results in
38      * per_cpu(cpu_sig).
39      */
40     void (*collect_cpu_info)(void);
41 
42     /*
43      * Attempt to load the provided patch into the CPU.  Returns an error if
44      * anything didn't go as expected.
45      */
46     int (*apply_microcode)(const struct microcode_patch *patch,
47                            unsigned int flags);
48 
49     /*
50      * Given a current patch, and a proposed new patch, order them based on revision.
51      *
52      * This operation is not necessarily symmetrical.  In some cases, a debug
53      * "new" patch will always considered to be newer, on the expectation that
54      * whomever is using debug patches knows exactly what they're doing.
55      */
56 #define OLD_UCODE  (-1)
57 #define SAME_UCODE  (0)
58 #define NEW_UCODE   (1)
59     int (*compare)(const struct microcode_patch *old,
60                    const struct microcode_patch *new);
61 
62     /*
63      * For Linux inird microcode compatibliity.
64      *
65      * The path where this vendor's microcode can be found in CPIO.
66      */
67     const char *cpio_path;
68 };
69 
70 extern bool opt_digest_check;
71 
72 /*
73  * Microcode loading falls into one of 3 states.
74  *   - No support at all
75  *   - Read-only (locked by firmware, or we're virtualised)
76  *   - Loading available
77  *
78  * These are encoded by (not) filling in ops->collect_cpu_info (i.e. no
79  * support available) and (not) ops->apply_microcode (i.e. read only).
80  * Otherwise, all hooks must be filled in.
81  */
82 #ifdef CONFIG_AMD
83 void ucode_probe_amd(struct microcode_ops *ops);
84 #else
ucode_probe_amd(struct microcode_ops * ops)85 static inline void ucode_probe_amd(struct microcode_ops *ops) {}
86 #endif
87 
88 #ifdef CONFIG_INTEL
89 void ucode_probe_intel(struct microcode_ops *ops);
90 #else
ucode_probe_intel(struct microcode_ops * ops)91 static inline void ucode_probe_intel(struct microcode_ops *ops) {}
92 #endif
93 
94 #endif /* ASM_X86_MICROCODE_PRIVATE_H */
95