]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ff6e181a A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
1c79356b | 12 | * |
ff6e181a A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ff6e181a A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
1c79356b A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* | |
24 | * @OSF_COPYRIGHT@ | |
25 | */ | |
26 | ||
91447636 A |
27 | #include <pexpert/pexpert.h> |
28 | ||
55e303ae | 29 | #include "cpuid.h" |
1c79356b | 30 | |
55e303ae | 31 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
1c79356b A |
32 | |
33 | /* | |
55e303ae A |
34 | * CPU identification routines. |
35 | * | |
36 | * Note that this code assumes a processor that supports the | |
37 | * 'cpuid' instruction. | |
1c79356b | 38 | */ |
1c79356b | 39 | |
55e303ae | 40 | static unsigned int cpuid_maxcpuid; |
d7e50217 | 41 | |
55e303ae | 42 | static i386_cpu_info_t cpuid_cpu_info; |
d7e50217 | 43 | |
55e303ae | 44 | uint32_t cpuid_feature; /* XXX obsolescent for compat */ |
1c79356b A |
45 | |
46 | /* | |
55e303ae A |
47 | * We only identify Intel CPUs here. Adding support |
48 | * for others would be straightforward. | |
1c79356b | 49 | */ |
91447636 | 50 | static void set_cpu_generic(i386_cpu_info_t *); |
55e303ae | 51 | static void set_cpu_intel(i386_cpu_info_t *); |
91447636 A |
52 | static void set_cpu_amd(i386_cpu_info_t *); |
53 | static void set_cpu_nsc(i386_cpu_info_t *); | |
55e303ae A |
54 | static void set_cpu_unknown(i386_cpu_info_t *); |
55 | ||
56 | struct { | |
91447636 A |
57 | const char *vendor; |
58 | void (* func)(i386_cpu_info_t *); | |
55e303ae A |
59 | } cpu_vendors[] = { |
60 | {CPUID_VID_INTEL, set_cpu_intel}, | |
91447636 A |
61 | {CPUID_VID_AMD, set_cpu_amd}, |
62 | {CPUID_VID_NSC, set_cpu_nsc}, | |
55e303ae | 63 | {0, set_cpu_unknown} |
1c79356b | 64 | }; |
d7e50217 | 65 | |
55e303ae A |
66 | void |
67 | cpuid_get_info(i386_cpu_info_t *info_p) | |
68 | { | |
69 | uint32_t cpuid_result[4]; | |
70 | int i; | |
71 | ||
72 | bzero((void *)info_p, sizeof(i386_cpu_info_t)); | |
73 | ||
74 | /* do cpuid 0 to get vendor */ | |
75 | do_cpuid(0, cpuid_result); | |
76 | cpuid_maxcpuid = cpuid_result[0]; | |
77 | bcopy((char *)&cpuid_result[1], &info_p->cpuid_vendor[0], 4); /* ugh */ | |
78 | bcopy((char *)&cpuid_result[2], &info_p->cpuid_vendor[8], 4); | |
79 | bcopy((char *)&cpuid_result[3], &info_p->cpuid_vendor[4], 4); | |
80 | info_p->cpuid_vendor[12] = 0; | |
81 | ||
82 | /* look up vendor */ | |
83 | for (i = 0; ; i++) { | |
84 | if ((cpu_vendors[i].vendor == 0) || | |
85 | (!strcmp(cpu_vendors[i].vendor, info_p->cpuid_vendor))) { | |
86 | cpu_vendors[i].func(info_p); | |
87 | break; | |
88 | } | |
89 | } | |
90 | } | |
91 | ||
de355530 | 92 | /* |
55e303ae A |
93 | * Cache descriptor table. Each row has the form: |
94 | * (descriptor_value, cache, size, linesize, | |
95 | * description) | |
96 | * Note: the CACHE_DESC macro does not expand description text in the kernel. | |
de355530 | 97 | */ |
55e303ae A |
98 | static cpuid_cache_desc_t cpuid_cache_desc_tab[] = { |
99 | CACHE_DESC(CPUID_CACHE_ITLB_4K, Lnone, 0, 0, \ | |
100 | "Instruction TLB, 4K, pages 4-way set associative, 64 entries"), | |
101 | CACHE_DESC(CPUID_CACHE_ITLB_4M, Lnone, 0, 0, \ | |
91447636 | 102 | "Instruction TLB, 4M, pages 4-way set associative, 2 entries"), |
55e303ae A |
103 | CACHE_DESC(CPUID_CACHE_DTLB_4K, Lnone, 0, 0, \ |
104 | "Data TLB, 4K pages, 4-way set associative, 64 entries"), | |
105 | CACHE_DESC(CPUID_CACHE_DTLB_4M, Lnone, 0, 0, \ | |
91447636 | 106 | "Data TLB, 4M pages, 4-way set associative, 8 entries"), |
55e303ae A |
107 | CACHE_DESC(CPUID_CACHE_ITLB_64, Lnone, 0, 0, \ |
108 | "Instruction TLB, 4K and 2M or 4M pages, 64 entries"), | |
109 | CACHE_DESC(CPUID_CACHE_ITLB_128, Lnone, 0, 0, \ | |
110 | "Instruction TLB, 4K and 2M or 4M pages, 128 entries"), | |
111 | CACHE_DESC(CPUID_CACHE_ITLB_256, Lnone, 0, 0, \ | |
112 | "Instruction TLB, 4K and 2M or 4M pages, 256 entries"), | |
113 | CACHE_DESC(CPUID_CACHE_DTLB_64, Lnone, 0, 0, \ | |
114 | "Data TLB, 4K and 4M pages, 64 entries"), | |
115 | CACHE_DESC(CPUID_CACHE_DTLB_128, Lnone, 0, 0, \ | |
116 | "Data TLB, 4K and 4M pages, 128 entries"), | |
117 | CACHE_DESC(CPUID_CACHE_DTLB_256, Lnone, 0, 0, \ | |
118 | "Data TLB, 4K and 4M pages, 256 entries"), | |
91447636 A |
119 | CACHE_DESC(CPUID_CACHE_ITLB_128_4, Lnone, 0, 0, \ |
120 | "Instruction TLB, 4K pages, 4-way set associative, 128 entries"), | |
121 | CACHE_DESC(CPUID_CACHE_DTLB_128_4, Lnone, 0, 0, \ | |
122 | "Data TLB, 4K pages, 4-way set associative, 128 entries"), | |
55e303ae A |
123 | CACHE_DESC(CPUID_CACHE_ICACHE_8K, L1I, 8*1024, 32, \ |
124 | "Instruction L1 cache, 8K, 4-way set associative, 32byte line size"), | |
125 | CACHE_DESC(CPUID_CACHE_DCACHE_8K, L1D, 8*1024, 32, \ | |
126 | "Data L1 cache, 8K, 2-way set associative, 32byte line size"), | |
127 | CACHE_DESC(CPUID_CACHE_ICACHE_16K, L1I, 16*1024, 32, \ | |
128 | "Instruction L1 cache, 16K, 4-way set associative, 32byte line size"), | |
129 | CACHE_DESC(CPUID_CACHE_DCACHE_16K, L1D, 16*1024, 32, \ | |
130 | "Data L1 cache, 16K, 4-way set associative, 32byte line size"), | |
131 | CACHE_DESC(CPUID_CACHE_DCACHE_8K_64, L1D, 8*1024, 64, \ | |
132 | "Data L1 cache, 8K, 4-way set associative, 64byte line size"), | |
133 | CACHE_DESC(CPUID_CACHE_DCACHE_16K_64, L1D, 16*1024, 64, \ | |
134 | "Data L1 cache, 16K, 4-way set associative, 64byte line size"), | |
135 | CACHE_DESC(CPUID_CACHE_DCACHE_32K_64, L1D, 32*1024, 64, \ | |
136 | "Data L1 cache, 32K, 4-way set associative, 64byte line size"), | |
91447636 A |
137 | CACHE_DESC(CPUID_CACHE_DCACHE_32K, L1D, 32*1024, 64, \ |
138 | "Data L1 cache, 32K, 8-way set assocative, 64byte line size"), | |
139 | CACHE_DESC(CPUID_CACHE_ICACHE_32K, L1I, 32*1024, 64, \ | |
140 | "Instruction L1 cache, 32K, 8-way set associative, 64byte line size"), | |
141 | CACHE_DESC(CPUID_CACHE_DCACHE_16K_8, L1D, 16*1024, 64, \ | |
142 | "Data L1 cache, 16K, 8-way set associative, 64byte line size"), | |
55e303ae A |
143 | CACHE_DESC(CPUID_CACHE_TRACE_12K, L1I, 12*1024, 64, \ |
144 | "Trace cache, 12K-uop, 8-way set associative"), | |
91447636 | 145 | CACHE_DESC(CPUID_CACHE_TRACE_16K, L1I, 16*1024, 64, \ |
55e303ae | 146 | "Trace cache, 16K-uop, 8-way set associative"), |
91447636 | 147 | CACHE_DESC(CPUID_CACHE_TRACE_32K, L1I, 32*1024, 64, \ |
55e303ae A |
148 | "Trace cache, 32K-uop, 8-way set associative"), |
149 | CACHE_DESC(CPUID_CACHE_UCACHE_128K, L2U, 128*1024, 32, \ | |
150 | "Unified L2 cache, 128K, 4-way set associative, 32byte line size"), | |
151 | CACHE_DESC(CPUID_CACHE_UCACHE_256K, L2U, 128*1024, 32, \ | |
152 | "Unified L2 cache, 256K, 4-way set associative, 32byte line size"), | |
153 | CACHE_DESC(CPUID_CACHE_UCACHE_512K, L2U, 512*1024, 32, \ | |
154 | "Unified L2 cache, 512K, 4-way set associative, 32byte line size"), | |
155 | CACHE_DESC(CPUID_CACHE_UCACHE_1M, L2U, 1*1024*1024, 32, \ | |
156 | "Unified L2 cache, 1M, 4-way set associative, 32byte line size"), | |
157 | CACHE_DESC(CPUID_CACHE_UCACHE_2M, L2U, 2*1024*1024, 32, \ | |
158 | "Unified L2 cache, 2M, 4-way set associative, 32byte line size"), | |
159 | CACHE_DESC(CPUID_CACHE_UCACHE_128K_64, L2U, 128*1024, 64, \ | |
160 | "Unified L2 cache, 128K, 8-way set associative, 64byte line size"), | |
161 | CACHE_DESC(CPUID_CACHE_UCACHE_256K_64, L2U, 256*1024, 64, \ | |
162 | "Unified L2 cache, 256K, 8-way set associative, 64byte line size"), | |
163 | CACHE_DESC(CPUID_CACHE_UCACHE_512K_64, L2U, 512*1024, 64, \ | |
164 | "Unified L2 cache, 512K, 8-way set associative, 64byte line size"), | |
165 | CACHE_DESC(CPUID_CACHE_UCACHE_1M_64, L2U, 1*1024*1024, 64, \ | |
166 | "Unified L2 cache, 1M, 8-way set associative, 64byte line size"), | |
167 | CACHE_DESC(CPUID_CACHE_UCACHE_256K_32, L2U, 256*1024, 32, \ | |
168 | "Unified L2 cache, 256K, 8-way set associative, 32byte line size"), | |
169 | CACHE_DESC(CPUID_CACHE_UCACHE_512K_32, L2U, 512*1024, 32, \ | |
170 | "Unified L2 cache, 512K, 8-way set associative, 32byte line size"), | |
171 | CACHE_DESC(CPUID_CACHE_UCACHE_1M_32, L2U, 1*1024*1024, 32, \ | |
172 | "Unified L2 cache, 1M, 8-way set associative, 32byte line size"), | |
173 | CACHE_DESC(CPUID_CACHE_UCACHE_2M_32, L2U, 2*1024*1024, 32, \ | |
174 | "Unified L2 cache, 2M, 8-way set associative, 32byte line size"), | |
91447636 A |
175 | CACHE_DESC(CPUID_CACHE_UCACHE_1M_64_4, L2U, 1*1024*1024, 64, \ |
176 | "Unified L2 cache, 1M, 4-way set associative, 64byte line size"), | |
177 | CACHE_DESC(CPUID_CACHE_UCACHE_2M_64, L2U, 2*1024*1024, 64, \ | |
178 | "Unified L2 cache, 2M, 8-way set associative, 64byte line size"), | |
179 | CACHE_DESC(CPUID_CACHE_UCACHE_512K_64_2,L2U, 512*1024, 64, \ | |
180 | "Unified L2 cache, 512K, 2-way set associative, 64byte line size"), | |
181 | CACHE_DESC(CPUID_CACHE_UCACHE_512K_64_4,L2U, 512*1024, 64, \ | |
182 | "Unified L2 cache, 512K, 4-way set associative, 64byte line size"), | |
183 | CACHE_DESC(CPUID_CACHE_UCACHE_1M_64_8, L2U, 1*1024*1024, 64, \ | |
184 | "Unified L2 cache, 1M, 8-way set associative, 64byte line size"), | |
185 | CACHE_DESC(CPUID_CACHE_UCACHE_128K_S4, L2U, 128*1024, 64, \ | |
186 | "Unified L2 sectored cache, 128K, 4-way set associative, 64byte line size"), | |
187 | CACHE_DESC(CPUID_CACHE_UCACHE_128K_S2, L2U, 128*1024, 64, \ | |
188 | "Unified L2 sectored cache, 128K, 2-way set associative, 64byte line size"), | |
189 | CACHE_DESC(CPUID_CACHE_UCACHE_256K_S4, L2U, 256*1024, 64, \ | |
190 | "Unified L2 sectored cache, 256K, 4-way set associative, 64byte line size"), | |
191 | CACHE_DESC(CPUID_CACHE_L3CACHE_512K, L3U, 512*1024, 64, \ | |
192 | "Unified L3 cache, 512K, 4-way set associative, 64byte line size"), | |
193 | CACHE_DESC(CPUID_CACHE_L3CACHE_1M, L3U, 1*1024*1024, 64, \ | |
194 | "Unified L3 cache, 1M, 8-way set associative, 64byte line size"), | |
195 | CACHE_DESC(CPUID_CACHE_L3CACHE_2M, L3U, 2*1024*1024, 64, \ | |
196 | "Unified L3 cache, 2M, 8-way set associative, 64byte line size"), | |
197 | CACHE_DESC(CPUID_CACHE_L3CACHE_4M, L3U, 4*1024*1024, 64, \ | |
198 | "Unified L3 cache, 4M, 8-way set associative, 64byte line size"), | |
199 | CACHE_DESC(CPUID_CACHE_PREFETCH_64, Lnone, 0, 0, \ | |
200 | "64-Byte Prefetching"), | |
201 | CACHE_DESC(CPUID_CACHE_PREFETCH_128, Lnone, 0, 0, \ | |
202 | "128-Byte Prefetching"), | |
203 | CACHE_DESC(CPUID_CACHE_NOCACHE, Lnone, 0, 0, \ | |
204 | "No L2 cache or, if valid L2 cache, no L3 cache"), | |
55e303ae A |
205 | CACHE_DESC(CPUID_CACHE_NULL, Lnone, 0, 0, \ |
206 | (char *)0), | |
de355530 | 207 | }; |
55e303ae | 208 | |
91447636 | 209 | static const char * get_intel_model_string( i386_cpu_info_t * info_p ) |
55e303ae | 210 | { |
91447636 A |
211 | /* check for brand id */ |
212 | switch(info_p->cpuid_brand) { | |
213 | case CPUID_BRAND_UNSUPPORTED: | |
214 | /* brand ID not supported; use alternate method. */ | |
215 | switch(info_p->cpuid_family) { | |
216 | case CPUID_FAMILY_486: | |
217 | return "Intel 486"; | |
218 | case CPUID_FAMILY_586: | |
219 | return "Intel Pentium"; | |
220 | case CPUID_FAMILY_686: | |
221 | switch(info_p->cpuid_model) { | |
222 | case CPUID_MODEL_P6: | |
223 | return "Intel Pentium Pro"; | |
224 | case CPUID_MODEL_PII: | |
225 | return "Intel Pentium II"; | |
226 | case CPUID_MODEL_P65: | |
227 | case CPUID_MODEL_P66: | |
228 | return "Intel Celeron"; | |
229 | case CPUID_MODEL_P67: | |
230 | case CPUID_MODEL_P68: | |
231 | case CPUID_MODEL_P6A: | |
232 | case CPUID_MODEL_P6B: | |
233 | return "Intel Pentium III"; | |
234 | case CPUID_MODEL_PM9: | |
235 | case CPUID_MODEL_PMD: | |
236 | return "Intel Pentium M"; | |
237 | default: | |
238 | return "Unknown Intel P6 Family"; | |
239 | } | |
240 | case CPUID_FAMILY_ITANIUM: | |
241 | return "Intel Itanium"; | |
242 | case CPUID_FAMILY_EXTENDED: | |
243 | switch (info_p->cpuid_extfamily) { | |
244 | case CPUID_EXTFAMILY_PENTIUM4: | |
245 | return "Intel Pentium 4"; | |
246 | case CPUID_EXTFAMILY_ITANIUM2: | |
247 | return "Intel Itanium 2"; | |
248 | } | |
249 | default: | |
250 | return "Unknown Intel Family"; | |
251 | } | |
252 | break; | |
253 | case CPUID_BRAND_CELERON_1: | |
254 | case CPUID_BRAND_CELERON_A: | |
255 | case CPUID_BRAND_CELERON_14: | |
256 | return "Intel Celeron"; | |
257 | case CPUID_BRAND_PENTIUM_III_2: | |
258 | case CPUID_BRAND_PENTIUM_III_4: | |
259 | return "Pentium III"; | |
260 | case CPUID_BRAND_PIII_XEON: | |
261 | if (info_p->cpuid_signature == 0x6B1) | |
262 | return "Intel Celeron"; | |
263 | else | |
264 | return "Intel Pentium III Xeon"; | |
265 | case CPUID_BRAND_PENTIUM_III_M: | |
266 | return "Mobile Intel Pentium III-M"; | |
267 | case CPUID_BRAND_M_CELERON_7: | |
268 | case CPUID_BRAND_M_CELERON_F: | |
269 | case CPUID_BRAND_M_CELERON_13: | |
270 | case CPUID_BRAND_M_CELERON_17: | |
271 | return "Mobile Intel Celeron"; | |
272 | case CPUID_BRAND_PENTIUM4_8: | |
273 | case CPUID_BRAND_PENTIUM4_9: | |
274 | return "Intel Pentium 4"; | |
275 | case CPUID_BRAND_XEON: | |
276 | return "Intel Xeon"; | |
277 | case CPUID_BRAND_XEON_MP: | |
278 | return "Intel Xeon MP"; | |
279 | case CPUID_BRAND_PENTIUM4_M: | |
280 | if (info_p->cpuid_signature == 0xF13) | |
281 | return "Intel Xeon"; | |
282 | else | |
283 | return "Mobile Intel Pentium 4"; | |
284 | case CPUID_BRAND_CELERON_M: | |
285 | return "Intel Celeron M"; | |
286 | case CPUID_BRAND_PENTIUM_M: | |
287 | return "Intel Pentium M"; | |
288 | case CPUID_BRAND_MOBILE_15: | |
289 | case CPUID_BRAND_MOBILE_17: | |
290 | return "Mobile Intel"; | |
291 | } | |
292 | ||
293 | return "Unknown Intel"; | |
294 | } | |
d7e50217 | 295 | |
91447636 A |
296 | static void set_intel_cache_info( i386_cpu_info_t * info_p ) |
297 | { | |
298 | uint32_t cpuid_result[4]; | |
299 | uint32_t l1d_cache_linesize = 0; | |
300 | unsigned int i; | |
301 | unsigned int j; | |
55e303ae A |
302 | |
303 | /* get processor cache descriptor info */ | |
304 | do_cpuid(2, cpuid_result); | |
305 | for (j = 0; j < 4; j++) { | |
306 | if ((cpuid_result[j] >> 31) == 1) /* bit31 is validity */ | |
307 | continue; | |
308 | ((uint32_t *) info_p->cache_info)[j] = cpuid_result[j]; | |
309 | } | |
310 | /* first byte gives number of cpuid calls to get all descriptors */ | |
311 | for (i = 1; i < info_p->cache_info[0]; i++) { | |
312 | if (i*16 > sizeof(info_p->cache_info)) | |
313 | break; | |
314 | do_cpuid(2, cpuid_result); | |
315 | for (j = 0; j < 4; j++) { | |
316 | if ((cpuid_result[j] >> 31) == 1) | |
317 | continue; | |
318 | ((uint32_t *) info_p->cache_info)[4*i+j] = | |
319 | cpuid_result[j]; | |
320 | } | |
321 | } | |
322 | ||
323 | /* decode the descriptors looking for L1/L2/L3 size info */ | |
324 | for (i = 1; i < sizeof(info_p->cache_info); i++) { | |
325 | cpuid_cache_desc_t *descp; | |
326 | uint8_t desc = info_p->cache_info[i]; | |
327 | ||
328 | if (desc == CPUID_CACHE_NULL) | |
329 | continue; | |
330 | for (descp = cpuid_cache_desc_tab; | |
331 | descp->value != CPUID_CACHE_NULL; descp++) { | |
332 | if (descp->value != desc) | |
333 | continue; | |
334 | info_p->cache_size[descp->type] = descp->size; | |
335 | if (descp->type == L2U) | |
336 | info_p->cache_linesize = descp->linesize; | |
91447636 A |
337 | if (descp->type == L1D) |
338 | l1d_cache_linesize = descp->linesize; | |
55e303ae A |
339 | break; |
340 | } | |
341 | } | |
342 | /* For P-IIIs, L2 could be 256k or 512k but we can't tell */ | |
343 | if (info_p->cache_size[L2U] == 0 && | |
344 | info_p->cpuid_family == 0x6 && info_p->cpuid_model == 0xb) { | |
345 | info_p->cache_size[L2U] = 256*1024; | |
346 | info_p->cache_linesize = 32; | |
347 | } | |
91447636 A |
348 | /* If we have no L2 cache, use the L1 data cache line size */ |
349 | if (info_p->cache_size[L2U] == 0) | |
350 | info_p->cache_linesize = l1d_cache_linesize; | |
351 | } | |
352 | ||
353 | static void set_cpu_intel( i386_cpu_info_t * info_p ) | |
354 | { | |
355 | set_cpu_generic(info_p); | |
356 | set_intel_cache_info(info_p); | |
357 | info_p->cpuid_model_string = get_intel_model_string(info_p); | |
358 | } | |
359 | ||
360 | static const char * get_amd_model_string( i386_cpu_info_t * info_p ) | |
361 | { | |
362 | switch (info_p->cpuid_family) | |
363 | { | |
364 | case CPUID_FAMILY_486: | |
365 | switch (info_p->cpuid_model) { | |
366 | case CPUID_MODEL_AM486_DX: | |
367 | case CPUID_MODEL_AM486_DX2: | |
368 | case CPUID_MODEL_AM486_DX2WB: | |
369 | case CPUID_MODEL_AM486_DX4: | |
370 | case CPUID_MODEL_AM486_DX4WB: | |
371 | return "Am486"; | |
372 | case CPUID_MODEL_AM486_5X86: | |
373 | case CPUID_MODEL_AM486_5X86WB: | |
374 | return "Am5x86"; | |
375 | } | |
376 | break; | |
377 | case CPUID_FAMILY_586: | |
378 | switch (info_p->cpuid_model) { | |
379 | case CPUID_MODEL_K5M0: | |
380 | case CPUID_MODEL_K5M1: | |
381 | case CPUID_MODEL_K5M2: | |
382 | case CPUID_MODEL_K5M3: | |
383 | return "AMD-K5"; | |
384 | case CPUID_MODEL_K6M6: | |
385 | case CPUID_MODEL_K6M7: | |
386 | return "AMD-K6"; | |
387 | case CPUID_MODEL_K6_2: | |
388 | return "AMD-K6-2"; | |
389 | case CPUID_MODEL_K6_III: | |
390 | return "AMD-K6-III"; | |
391 | } | |
392 | break; | |
393 | case CPUID_FAMILY_686: | |
394 | switch (info_p->cpuid_model) { | |
395 | case CPUID_MODEL_ATHLON_M1: | |
396 | case CPUID_MODEL_ATHLON_M2: | |
397 | case CPUID_MODEL_ATHLON_M4: | |
398 | case CPUID_MODEL_ATHLON_M6: | |
399 | case CPUID_MODEL_ATHLON_M8: | |
400 | case CPUID_MODEL_ATHLON_M10: | |
401 | return "AMD Athlon"; | |
402 | case CPUID_MODEL_DURON_M3: | |
403 | case CPUID_MODEL_DURON_M7: | |
404 | return "AMD Duron"; | |
405 | default: | |
406 | return "Unknown AMD Athlon"; | |
407 | } | |
408 | case CPUID_FAMILY_EXTENDED: | |
409 | switch (info_p->cpuid_model) { | |
410 | case CPUID_MODEL_ATHLON64: | |
411 | return "AMD Athlon 64"; | |
412 | case CPUID_MODEL_OPTERON: | |
413 | return "AMD Opteron"; | |
414 | default: | |
415 | return "Unknown AMD-64"; | |
416 | } | |
417 | } | |
418 | return "Unknown AMD"; | |
419 | } | |
420 | ||
421 | static void set_amd_cache_info( i386_cpu_info_t * info_p ) | |
422 | { | |
423 | uint32_t cpuid_result[4]; | |
424 | ||
425 | /* It would make sense to fill in info_p->cache_info with complete information | |
426 | * on the TLBs and data cache associativity, lines, etc, either by mapping | |
427 | * to the Intel tags (if possible), or replacing cache_info with a generic | |
428 | * mechanism. But right now, nothing makes use of that information (that I know | |
429 | * of). | |
430 | */ | |
431 | ||
432 | /* L1 Cache and TLB Information */ | |
433 | do_cpuid(0x80000005, cpuid_result); | |
434 | ||
435 | /* EAX: TLB Information for 2-Mbyte and 4-MByte Pages */ | |
436 | /* (ignore) */ | |
437 | ||
438 | /* EBX: TLB Information for 4-Kbyte Pages */ | |
439 | /* (ignore) */ | |
440 | ||
441 | /* ECX: L1 Data Cache Information */ | |
442 | info_p->cache_size[L1D] = ((cpuid_result[2] >> 24) & 0xFF) * 1024; | |
443 | info_p->cache_linesize = (cpuid_result[2] & 0xFF); | |
444 | ||
445 | /* EDX: L1 Instruction Cache Information */ | |
446 | info_p->cache_size[L1I] = ((cpuid_result[3] >> 24) & 0xFF) * 1024; | |
447 | ||
448 | /* L2 Cache Information */ | |
449 | do_cpuid(0x80000006, cpuid_result); | |
450 | ||
451 | /* EAX: L2 TLB Information for 2-Mbyte and 4-Mbyte Pages */ | |
452 | /* (ignore) */ | |
453 | ||
454 | /* EBX: L2 TLB Information for 4-Kbyte Pages */ | |
455 | /* (ignore) */ | |
456 | ||
457 | /* ECX: L2 Cache Information */ | |
458 | info_p->cache_size[L2U] = ((cpuid_result[2] >> 16) & 0xFFFF) * 1024; | |
459 | if (info_p->cache_size[L2U] > 0) | |
460 | info_p->cache_linesize = cpuid_result[2] & 0xFF; | |
461 | } | |
462 | ||
463 | static void set_cpu_amd( i386_cpu_info_t * info_p ) | |
464 | { | |
465 | set_cpu_generic(info_p); | |
466 | set_amd_cache_info(info_p); | |
467 | info_p->cpuid_model_string = get_amd_model_string(info_p); | |
468 | } | |
469 | ||
470 | static void set_cpu_nsc( i386_cpu_info_t * info_p ) | |
471 | { | |
472 | set_cpu_generic(info_p); | |
473 | set_amd_cache_info(info_p); | |
474 | ||
475 | if (info_p->cpuid_family == CPUID_FAMILY_586 && info_p->cpuid_model == CPUID_MODEL_GX1) | |
476 | info_p->cpuid_model_string = "AMD Geode GX1"; | |
477 | else if (info_p->cpuid_family == CPUID_FAMILY_586 && info_p->cpuid_model == CPUID_MODEL_GX2) | |
478 | info_p->cpuid_model_string = "AMD Geode GX"; | |
479 | else | |
480 | info_p->cpuid_model_string = "Unknown National Semiconductor"; | |
481 | } | |
482 | ||
483 | static void | |
484 | set_cpu_generic(i386_cpu_info_t *info_p) | |
485 | { | |
486 | uint32_t cpuid_result[4]; | |
487 | uint32_t max_extid; | |
488 | char str[128], *p; | |
489 | ||
490 | /* get extended cpuid results */ | |
491 | do_cpuid(0x80000000, cpuid_result); | |
492 | max_extid = cpuid_result[0]; | |
493 | ||
494 | /* check to see if we can get brand string */ | |
495 | if (max_extid >= 0x80000004) { | |
496 | /* | |
497 | * The brand string 48 bytes (max), guaranteed to | |
498 | * be NUL terminated. | |
499 | */ | |
500 | do_cpuid(0x80000002, cpuid_result); | |
501 | bcopy((char *)cpuid_result, &str[0], 16); | |
502 | do_cpuid(0x80000003, cpuid_result); | |
503 | bcopy((char *)cpuid_result, &str[16], 16); | |
504 | do_cpuid(0x80000004, cpuid_result); | |
505 | bcopy((char *)cpuid_result, &str[32], 16); | |
506 | for (p = str; *p != '\0'; p++) { | |
507 | if (*p != ' ') break; | |
508 | } | |
509 | strncpy(info_p->cpuid_brand_string, | |
510 | p, sizeof(info_p->cpuid_brand_string)-1); | |
511 | info_p->cpuid_brand_string[sizeof(info_p->cpuid_brand_string)-1] = '\0'; | |
512 | ||
513 | if (!strcmp(info_p->cpuid_brand_string, CPUID_STRING_UNKNOWN)) { | |
514 | /* | |
515 | * This string means we have a BIOS-programmable brand string, | |
516 | * and the BIOS couldn't figure out what sort of CPU we have. | |
517 | */ | |
518 | info_p->cpuid_brand_string[0] = '\0'; | |
519 | } | |
520 | } | |
521 | ||
522 | /* get processor signature and decode */ | |
523 | do_cpuid(1, cpuid_result); | |
524 | info_p->cpuid_signature = cpuid_result[0]; | |
525 | info_p->cpuid_stepping = cpuid_result[0] & 0x0f; | |
526 | info_p->cpuid_model = (cpuid_result[0] >> 4) & 0x0f; | |
527 | info_p->cpuid_family = (cpuid_result[0] >> 8) & 0x0f; | |
528 | info_p->cpuid_type = (cpuid_result[0] >> 12) & 0x03; | |
529 | info_p->cpuid_extmodel = (cpuid_result[0] >> 16) & 0x0f; | |
530 | info_p->cpuid_extfamily = (cpuid_result[0] >> 20) & 0xff; | |
531 | info_p->cpuid_brand = cpuid_result[1] & 0xff; | |
532 | info_p->cpuid_features = cpuid_result[3]; | |
55e303ae A |
533 | |
534 | return; | |
535 | } | |
536 | ||
537 | static void | |
91447636 | 538 | set_cpu_unknown(__unused i386_cpu_info_t *info_p) |
d7e50217 | 539 | { |
91447636 | 540 | info_p->cpuid_model_string = "Unknown"; |
55e303ae A |
541 | } |
542 | ||
543 | ||
544 | static struct { | |
545 | uint32_t mask; | |
91447636 | 546 | const char *name; |
55e303ae A |
547 | } feature_names[] = { |
548 | {CPUID_FEATURE_FPU, "FPU",}, | |
549 | {CPUID_FEATURE_VME, "VME",}, | |
550 | {CPUID_FEATURE_DE, "DE",}, | |
551 | {CPUID_FEATURE_PSE, "PSE",}, | |
552 | {CPUID_FEATURE_TSC, "TSC",}, | |
553 | {CPUID_FEATURE_MSR, "MSR",}, | |
554 | {CPUID_FEATURE_PAE, "PAE",}, | |
555 | {CPUID_FEATURE_MCE, "MCE",}, | |
556 | {CPUID_FEATURE_CX8, "CX8",}, | |
557 | {CPUID_FEATURE_APIC, "APIC",}, | |
558 | {CPUID_FEATURE_SEP, "SEP",}, | |
559 | {CPUID_FEATURE_MTRR, "MTRR",}, | |
560 | {CPUID_FEATURE_PGE, "PGE",}, | |
561 | {CPUID_FEATURE_MCA, "MCA",}, | |
562 | {CPUID_FEATURE_CMOV, "CMOV",}, | |
563 | {CPUID_FEATURE_PAT, "PAT",}, | |
564 | {CPUID_FEATURE_PSE36, "PSE36",}, | |
565 | {CPUID_FEATURE_PSN, "PSN",}, | |
566 | {CPUID_FEATURE_CLFSH, "CLFSH",}, | |
567 | {CPUID_FEATURE_DS, "DS",}, | |
568 | {CPUID_FEATURE_ACPI, "ACPI",}, | |
569 | {CPUID_FEATURE_MMX, "MMX",}, | |
570 | {CPUID_FEATURE_FXSR, "FXSR",}, | |
571 | {CPUID_FEATURE_SSE, "SSE",}, | |
572 | {CPUID_FEATURE_SSE2, "SSE2",}, | |
573 | {CPUID_FEATURE_SS, "SS",}, | |
574 | {CPUID_FEATURE_HTT, "HTT",}, | |
575 | {CPUID_FEATURE_TM, "TM",}, | |
576 | {0, 0} | |
577 | }; | |
578 | ||
579 | char * | |
580 | cpuid_get_feature_names(uint32_t feature, char *buf, unsigned buf_len) | |
581 | { | |
582 | int i; | |
583 | int len; | |
584 | char *p = buf; | |
585 | ||
586 | for (i = 0; feature_names[i].mask != 0; i++) { | |
587 | if ((feature & feature_names[i].mask) == 0) | |
588 | continue; | |
589 | if (i > 0) | |
590 | *p++ = ' '; | |
591 | len = min(strlen(feature_names[i].name), (buf_len-1) - (p-buf)); | |
592 | if (len == 0) | |
593 | break; | |
594 | bcopy(feature_names[i].name, p, len); | |
595 | p += len; | |
596 | } | |
597 | *p = '\0'; | |
598 | return buf; | |
599 | } | |
600 | ||
601 | void | |
602 | cpuid_feature_display( | |
91447636 A |
603 | const char *header, |
604 | __unused int my_cpu) | |
55e303ae A |
605 | { |
606 | char buf[256]; | |
607 | ||
608 | printf("%s: %s\n", header, | |
609 | cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf))); | |
1c79356b A |
610 | } |
611 | ||
1c79356b A |
612 | void |
613 | cpuid_cpu_display( | |
91447636 A |
614 | const char *header, |
615 | __unused int my_cpu) | |
d7e50217 | 616 | { |
91447636 | 617 | if (cpuid_cpu_info.cpuid_brand_string[0] != '\0') { |
55e303ae | 618 | printf("%s: %s\n", header, |
91447636 A |
619 | cpuid_cpu_info.cpuid_brand_string); |
620 | } | |
d7e50217 A |
621 | } |
622 | ||
55e303ae A |
623 | unsigned int |
624 | cpuid_family(void) | |
625 | { | |
626 | return cpuid_cpu_info.cpuid_family; | |
627 | } | |
628 | ||
629 | unsigned int | |
630 | cpuid_features(void) | |
631 | { | |
91447636 A |
632 | static int checked = 0; |
633 | char fpu_arg[16] = { 0 }; | |
634 | if (!checked) { | |
635 | /* check for boot-time fpu limitations */ | |
636 | if (PE_parse_boot_arg("_fpu", &fpu_arg[0])) { | |
637 | printf("limiting fpu features to: %s\n", fpu_arg); | |
638 | if (!strncmp("387", fpu_arg, sizeof "387") || !strncmp("mmx", fpu_arg, sizeof "mmx")) { | |
639 | printf("no sse or sse2\n"); | |
640 | cpuid_cpu_info.cpuid_features &= ~(CPUID_FEATURE_SSE | CPUID_FEATURE_SSE2 | CPUID_FEATURE_FXSR); | |
641 | } else if (!strncmp("sse", fpu_arg, sizeof "sse")) { | |
642 | printf("no sse2\n"); | |
643 | cpuid_cpu_info.cpuid_features &= ~(CPUID_FEATURE_SSE2); | |
644 | } | |
645 | } | |
646 | checked = 1; | |
647 | } | |
55e303ae A |
648 | return cpuid_cpu_info.cpuid_features; |
649 | } | |
650 | ||
651 | i386_cpu_info_t * | |
652 | cpuid_info(void) | |
653 | { | |
654 | return &cpuid_cpu_info; | |
655 | } | |
656 | ||
657 | /* XXX for temporary compatibility */ | |
1c79356b | 658 | void |
55e303ae | 659 | set_cpu_model(void) |
1c79356b | 660 | { |
55e303ae A |
661 | cpuid_get_info(&cpuid_cpu_info); |
662 | cpuid_feature = cpuid_cpu_info.cpuid_features; /* XXX compat */ | |
1c79356b | 663 | } |
55e303ae | 664 |