1#include <asm/cpu_device_id.h>
2#include <asm/cpufeature.h>
3#include <linux/cpu.h>
4#include <linux/module.h>
5#include <linux/slab.h>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
32{
33 const struct x86_cpu_id *m;
34 struct cpuinfo_x86 *c = &boot_cpu_data;
35
36 for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
37 if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
38 continue;
39 if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
40 continue;
41 if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
42 continue;
43 if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
44 continue;
45 return m;
46 }
47 return NULL;
48}
49EXPORT_SYMBOL(x86_match_cpu);
50
51ssize_t arch_print_cpu_modalias(struct device *dev,
52 struct device_attribute *attr,
53 char *bufptr)
54{
55 int size = PAGE_SIZE;
56 int i, n;
57 char *buf = bufptr;
58
59 n = snprintf(buf, size, "x86cpu:vendor:%04X:family:%04X:"
60 "model:%04X:feature:",
61 boot_cpu_data.x86_vendor,
62 boot_cpu_data.x86,
63 boot_cpu_data.x86_model);
64 size -= n;
65 buf += n;
66 size -= 1;
67 for (i = 0; i < NCAPINTS*32; i++) {
68 if (boot_cpu_has(i)) {
69 n = snprintf(buf, size, ",%04X", i);
70 if (n >= size) {
71 WARN(1, "x86 features overflow page\n");
72 break;
73 }
74 size -= n;
75 buf += n;
76 }
77 }
78 *buf++ = '\n';
79 return buf - bufptr;
80}
81
82int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
83{
84 char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
85 if (buf) {
86 arch_print_cpu_modalias(NULL, NULL, buf);
87 add_uevent_var(env, "MODALIAS=%s", buf);
88 kfree(buf);
89 }
90 return 0;
91}
92
93static const struct x86_cpu_desc *
94x86_match_cpu_with_stepping(const struct x86_cpu_desc *match)
95{
96 struct cpuinfo_x86 *c = &boot_cpu_data;
97 const struct x86_cpu_desc *m;
98
99 for (m = match; m->x86_family | m->x86_model; m++) {
100 if (c->x86_vendor != m->x86_vendor)
101 continue;
102 if (c->x86 != m->x86_family)
103 continue;
104 if (c->x86_model != m->x86_model)
105 continue;
106 if (c->x86_mask != m->x86_stepping)
107 continue;
108 return m;
109 }
110 return NULL;
111}
112
113bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table)
114{
115 const struct x86_cpu_desc *res = x86_match_cpu_with_stepping(table);
116
117 if (!res || res->x86_microcode_rev > boot_cpu_data.microcode)
118 return false;
119
120 return true;
121}
122EXPORT_SYMBOL_GPL(x86_cpu_has_min_microcode_rev);
123