Print this page
8956 Implement KPTI
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/os/cpuid.c
+++ new/usr/src/uts/i86pc/os/cpuid.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
24 24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
25 25 * Copyright 2014 Josef "Jeff" Sipek <jeffpc@josefsipek.net>
26 26 */
27 27 /*
28 28 * Copyright (c) 2010, Intel Corporation.
29 29 * All rights reserved.
30 30 */
31 31 /*
32 32 * Portions Copyright 2009 Advanced Micro Devices, Inc.
33 33 */
34 34 /*
35 - * Copyright 2017 Joyent, Inc.
35 + * Copyright 2018 Joyent, Inc.
36 36 */
37 37 /*
38 38 * Various routines to handle identification
39 39 * and classification of x86 processors.
40 40 */
41 41
42 42 #include <sys/types.h>
43 43 #include <sys/archsystm.h>
44 44 #include <sys/x86_archext.h>
45 45 #include <sys/kmem.h>
46 46 #include <sys/systm.h>
47 47 #include <sys/cmn_err.h>
48 48 #include <sys/sunddi.h>
49 49 #include <sys/sunndi.h>
50 50 #include <sys/cpuvar.h>
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
51 51 #include <sys/processor.h>
52 52 #include <sys/sysmacros.h>
53 53 #include <sys/pg.h>
54 54 #include <sys/fp.h>
55 55 #include <sys/controlregs.h>
56 56 #include <sys/bitmap.h>
57 57 #include <sys/auxv_386.h>
58 58 #include <sys/memnode.h>
59 59 #include <sys/pci_cfgspace.h>
60 60 #include <sys/comm_page.h>
61 +#include <sys/mach_mmu.h>
61 62 #include <sys/tsc.h>
62 63
63 64 #ifdef __xpv
64 65 #include <sys/hypervisor.h>
65 66 #else
66 67 #include <sys/ontrap.h>
67 68 #endif
68 69
69 70 /*
70 71 * Pass 0 of cpuid feature analysis happens in locore. It contains special code
71 72 * to recognize Cyrix processors that are not cpuid-compliant, and to deal with
72 73 * them accordingly. For most modern processors, feature detection occurs here
73 74 * in pass 1.
74 75 *
75 76 * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup()
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
76 77 * for the boot CPU and does the basic analysis that the early kernel needs.
77 78 * x86_featureset is set based on the return value of cpuid_pass1() of the boot
78 79 * CPU.
79 80 *
80 81 * Pass 1 includes:
81 82 *
82 83 * o Determining vendor/model/family/stepping and setting x86_type and
83 84 * x86_vendor accordingly.
84 85 * o Processing the feature flags returned by the cpuid instruction while
85 86 * applying any workarounds or tricks for the specific processor.
86 - * o Mapping the feature flags into Solaris feature bits (X86_*).
87 + * o Mapping the feature flags into illumos feature bits (X86_*).
87 88 * o Processing extended feature flags if supported by the processor,
88 89 * again while applying specific processor knowledge.
89 90 * o Determining the CMT characteristics of the system.
90 91 *
91 92 * Pass 1 is done on non-boot CPUs during their initialization and the results
92 93 * are used only as a meager attempt at ensuring that all processors within the
93 94 * system support the same features.
94 95 *
95 96 * Pass 2 of cpuid feature analysis happens just at the beginning
96 97 * of startup(). It just copies in and corrects the remainder
97 98 * of the cpuid data we depend on: standard cpuid functions that we didn't
98 99 * need for pass1 feature analysis, and extended cpuid functions beyond the
99 100 * simple feature processing done in pass1.
100 101 *
101 102 * Pass 3 of cpuid analysis is invoked after basic kernel services; in
102 103 * particular kernel memory allocation has been made available. It creates a
103 104 * readable brand string based on the data collected in the first two passes.
104 105 *
105 106 * Pass 4 of cpuid analysis is invoked after post_startup() when all
106 107 * the support infrastructure for various hardware features has been
107 108 * initialized. It determines which processor features will be reported
108 109 * to userland via the aux vector.
109 110 *
110 111 * All passes are executed on all CPUs, but only the boot CPU determines what
111 112 * features the kernel will use.
112 113 *
113 114 * Much of the worst junk in this file is for the support of processors
114 115 * that didn't really implement the cpuid instruction properly.
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
115 116 *
116 117 * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon,
117 118 * the pass numbers. Accordingly, changes to the pass code may require changes
118 119 * to the accessor code.
119 120 */
120 121
121 122 uint_t x86_vendor = X86_VENDOR_IntelClone;
122 123 uint_t x86_type = X86_TYPE_OTHER;
123 124 uint_t x86_clflush_size = 0;
124 125
126 +#if defined(__xpv)
127 +int x86_use_pcid = 0;
128 +int x86_use_invpcid = 0;
129 +#else
130 +int x86_use_pcid = -1;
131 +int x86_use_invpcid = -1;
132 +#endif
133 +
125 134 uint_t pentiumpro_bug4046376;
126 135
127 136 uchar_t x86_featureset[BT_SIZEOFMAP(NUM_X86_FEATURES)];
128 137
129 138 static char *x86_feature_names[NUM_X86_FEATURES] = {
130 139 "lgpg",
131 140 "tsc",
132 141 "msr",
133 142 "mtrr",
134 143 "pge",
135 144 "de",
136 145 "cmov",
137 146 "mmx",
138 147 "mca",
139 148 "pae",
140 149 "cv8",
141 150 "pat",
142 151 "sep",
143 152 "sse",
144 153 "sse2",
145 154 "htt",
146 155 "asysc",
147 156 "nx",
148 157 "sse3",
149 158 "cx16",
150 159 "cmp",
151 160 "tscp",
152 161 "mwait",
153 162 "sse4a",
154 163 "cpuid",
155 164 "ssse3",
156 165 "sse4_1",
157 166 "sse4_2",
158 167 "1gpg",
159 168 "clfsh",
160 169 "64",
161 170 "aes",
162 171 "pclmulqdq",
163 172 "xsave",
164 173 "avx",
165 174 "vmx",
166 175 "svm",
167 176 "topoext",
168 177 "f16c",
169 178 "rdrand",
170 179 "x2apic",
171 180 "avx2",
172 181 "bmi1",
173 182 "bmi2",
174 183 "fma",
175 184 "smep",
176 185 "smap",
177 186 "adx",
178 187 "rdseed",
179 188 "mpx",
180 189 "avx512f",
181 190 "avx512dq",
182 191 "avx512pf",
183 192 "avx512er",
184 193 "avx512cd",
185 194 "avx512bw",
186 195 "avx512vl",
187 196 "avx512fma",
188 197 "avx512vbmi",
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
189 198 "avx512_vpopcntdq",
190 199 "avx512_4vnniw",
191 200 "avx512_4fmaps",
192 201 "xsaveopt",
193 202 "xsavec",
194 203 "xsaves",
195 204 "sha",
196 205 "umip",
197 206 "pku",
198 207 "ospke",
208 + "pcid",
209 + "invpcid",
199 210 };
200 211
201 212 boolean_t
202 213 is_x86_feature(void *featureset, uint_t feature)
203 214 {
204 215 ASSERT(feature < NUM_X86_FEATURES);
205 216 return (BT_TEST((ulong_t *)featureset, feature));
206 217 }
207 218
208 219 void
209 220 add_x86_feature(void *featureset, uint_t feature)
210 221 {
211 222 ASSERT(feature < NUM_X86_FEATURES);
212 223 BT_SET((ulong_t *)featureset, feature);
213 224 }
214 225
215 226 void
216 227 remove_x86_feature(void *featureset, uint_t feature)
217 228 {
218 229 ASSERT(feature < NUM_X86_FEATURES);
219 230 BT_CLEAR((ulong_t *)featureset, feature);
220 231 }
221 232
222 233 boolean_t
223 234 compare_x86_featureset(void *setA, void *setB)
224 235 {
225 236 /*
226 237 * We assume that the unused bits of the bitmap are always zero.
227 238 */
228 239 if (memcmp(setA, setB, BT_SIZEOFMAP(NUM_X86_FEATURES)) == 0) {
229 240 return (B_TRUE);
230 241 } else {
231 242 return (B_FALSE);
232 243 }
233 244 }
234 245
235 246 void
236 247 print_x86_featureset(void *featureset)
237 248 {
238 249 uint_t i;
239 250
240 251 for (i = 0; i < NUM_X86_FEATURES; i++) {
241 252 if (is_x86_feature(featureset, i)) {
242 253 cmn_err(CE_CONT, "?x86_feature: %s\n",
243 254 x86_feature_names[i]);
244 255 }
245 256 }
246 257 }
247 258
248 259 /* Note: This is the maximum size for the CPU, not the size of the structure. */
249 260 static size_t xsave_state_size = 0;
250 261 uint64_t xsave_bv_all = (XFEATURE_LEGACY_FP | XFEATURE_SSE);
251 262 boolean_t xsave_force_disable = B_FALSE;
252 263 extern int disable_smap;
253 264
254 265 /*
255 266 * This is set to platform type we are running on.
256 267 */
257 268 static int platform_type = -1;
258 269
259 270 #if !defined(__xpv)
260 271 /*
261 272 * Variable to patch if hypervisor platform detection needs to be
262 273 * disabled (e.g. platform_type will always be HW_NATIVE if this is 0).
263 274 */
264 275 int enable_platform_detection = 1;
265 276 #endif
266 277
267 278 /*
268 279 * monitor/mwait info.
269 280 *
270 281 * size_actual and buf_actual are the real address and size allocated to get
271 282 * proper mwait_buf alignement. buf_actual and size_actual should be passed
272 283 * to kmem_free(). Currently kmem_alloc() and mwait happen to both use
273 284 * processor cache-line alignment, but this is not guarantied in the furture.
274 285 */
275 286 struct mwait_info {
276 287 size_t mon_min; /* min size to avoid missed wakeups */
277 288 size_t mon_max; /* size to avoid false wakeups */
278 289 size_t size_actual; /* size actually allocated */
279 290 void *buf_actual; /* memory actually allocated */
280 291 uint32_t support; /* processor support of monitor/mwait */
281 292 };
282 293
283 294 /*
284 295 * xsave/xrestor info.
285 296 *
286 297 * This structure contains HW feature bits and the size of the xsave save area.
287 298 * Note: the kernel declares a fixed size (AVX_XSAVE_SIZE) structure
288 299 * (xsave_state) to describe the xsave layout. However, at runtime the
289 300 * per-lwp xsave area is dynamically allocated based on xsav_max_size. The
290 301 * xsave_state structure simply represents the legacy layout of the beginning
291 302 * of the xsave area.
292 303 */
293 304 struct xsave_info {
294 305 uint32_t xsav_hw_features_low; /* Supported HW features */
295 306 uint32_t xsav_hw_features_high; /* Supported HW features */
296 307 size_t xsav_max_size; /* max size save area for HW features */
297 308 size_t ymm_size; /* AVX: size of ymm save area */
298 309 size_t ymm_offset; /* AVX: offset for ymm save area */
299 310 size_t bndregs_size; /* MPX: size of bndregs save area */
300 311 size_t bndregs_offset; /* MPX: offset for bndregs save area */
301 312 size_t bndcsr_size; /* MPX: size of bndcsr save area */
302 313 size_t bndcsr_offset; /* MPX: offset for bndcsr save area */
303 314 size_t opmask_size; /* AVX512: size of opmask save */
304 315 size_t opmask_offset; /* AVX512: offset for opmask save */
305 316 size_t zmmlo_size; /* AVX512: size of zmm 256 save */
306 317 size_t zmmlo_offset; /* AVX512: offset for zmm 256 save */
307 318 size_t zmmhi_size; /* AVX512: size of zmm hi reg save */
308 319 size_t zmmhi_offset; /* AVX512: offset for zmm hi reg save */
309 320 };
310 321
311 322
312 323 /*
313 324 * These constants determine how many of the elements of the
314 325 * cpuid we cache in the cpuid_info data structure; the
315 326 * remaining elements are accessible via the cpuid instruction.
316 327 */
317 328
318 329 #define NMAX_CPI_STD 8 /* eax = 0 .. 7 */
319 330 #define NMAX_CPI_EXTD 0x1f /* eax = 0x80000000 .. 0x8000001e */
320 331
321 332 /*
322 333 * Some terminology needs to be explained:
323 334 * - Socket: Something that can be plugged into a motherboard.
324 335 * - Package: Same as socket
325 336 * - Chip: Same as socket. Note that AMD's documentation uses term "chip"
326 337 * differently: there, chip is the same as processor node (below)
327 338 * - Processor node: Some AMD processors have more than one
328 339 * "subprocessor" embedded in a package. These subprocessors (nodes)
329 340 * are fully-functional processors themselves with cores, caches,
330 341 * memory controllers, PCI configuration spaces. They are connected
331 342 * inside the package with Hypertransport links. On single-node
332 343 * processors, processor node is equivalent to chip/socket/package.
333 344 * - Compute Unit: Some AMD processors pair cores in "compute units" that
334 345 * share the FPU and the I$ and L2 caches.
335 346 */
336 347
337 348 struct cpuid_info {
338 349 uint_t cpi_pass; /* last pass completed */
339 350 /*
340 351 * standard function information
341 352 */
342 353 uint_t cpi_maxeax; /* fn 0: %eax */
343 354 char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */
344 355 uint_t cpi_vendor; /* enum of cpi_vendorstr */
345 356
346 357 uint_t cpi_family; /* fn 1: extended family */
347 358 uint_t cpi_model; /* fn 1: extended model */
348 359 uint_t cpi_step; /* fn 1: stepping */
349 360 chipid_t cpi_chipid; /* fn 1: %ebx: Intel: chip # */
350 361 /* AMD: package/socket # */
351 362 uint_t cpi_brandid; /* fn 1: %ebx: brand ID */
352 363 int cpi_clogid; /* fn 1: %ebx: thread # */
353 364 uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */
354 365 uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */
355 366 uint_t cpi_ncache; /* fn 2: number of elements */
356 367 uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */
357 368 id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */
358 369 uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */
359 370 struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */
360 371 struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 7 */
361 372 /*
362 373 * extended function information
363 374 */
364 375 uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */
365 376 char cpi_brandstr[49]; /* fn 0x8000000[234] */
366 377 uint8_t cpi_pabits; /* fn 0x80000006: %eax */
367 378 uint8_t cpi_vabits; /* fn 0x80000006: %eax */
368 379 uint8_t cpi_fp_amd_save; /* AMD: FP error pointer save rqd. */
369 380 struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x800000XX */
370 381
371 382 id_t cpi_coreid; /* same coreid => strands share core */
372 383 int cpi_pkgcoreid; /* core number within single package */
373 384 uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */
374 385 /* Intel: fn 4: %eax[31-26] */
375 386 /*
376 387 * supported feature information
377 388 */
378 389 uint32_t cpi_support[6];
379 390 #define STD_EDX_FEATURES 0
380 391 #define AMD_EDX_FEATURES 1
381 392 #define TM_EDX_FEATURES 2
382 393 #define STD_ECX_FEATURES 3
383 394 #define AMD_ECX_FEATURES 4
384 395 #define STD_EBX_FEATURES 5
385 396 /*
386 397 * Synthesized information, where known.
387 398 */
388 399 uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */
389 400 const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */
390 401 uint32_t cpi_socket; /* Chip package/socket type */
391 402
392 403 struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */
393 404 uint32_t cpi_apicid;
394 405 uint_t cpi_procnodeid; /* AMD: nodeID on HT, Intel: chipid */
395 406 uint_t cpi_procnodes_per_pkg; /* AMD: # of nodes in the package */
396 407 /* Intel: 1 */
397 408 uint_t cpi_compunitid; /* AMD: ComputeUnit ID, Intel: coreid */
398 409 uint_t cpi_cores_per_compunit; /* AMD: # of cores in the ComputeUnit */
399 410
400 411 struct xsave_info cpi_xsave; /* fn D: xsave/xrestor info */
401 412 };
402 413
403 414
404 415 static struct cpuid_info cpuid_info0;
405 416
406 417 /*
407 418 * These bit fields are defined by the Intel Application Note AP-485
408 419 * "Intel Processor Identification and the CPUID Instruction"
409 420 */
410 421 #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20)
411 422 #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16)
412 423 #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12)
413 424 #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8)
414 425 #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0)
415 426 #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4)
416 427
417 428 #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx)
418 429 #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx)
419 430 #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx)
420 431 #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx)
421 432 #define CPI_FEATURES_7_0_EBX(cpi) ((cpi)->cpi_std[7].cp_ebx)
422 433 #define CPI_FEATURES_7_0_ECX(cpi) ((cpi)->cpi_std[7].cp_ecx)
423 434 #define CPI_FEATURES_7_0_EDX(cpi) ((cpi)->cpi_std[7].cp_edx)
424 435
425 436 #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0)
426 437 #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7)
427 438 #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16)
428 439 #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24)
429 440
430 441 #define CPI_MAXEAX_MAX 0x100 /* sanity control */
431 442 #define CPI_XMAXEAX_MAX 0x80000100
432 443 #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */
433 444 #define CPI_FNB_ECX_MAX 0x20 /* sanity: max fn B levels */
434 445
435 446 /*
436 447 * Function 4 (Deterministic Cache Parameters) macros
437 448 * Defined by Intel Application Note AP-485
438 449 */
439 450 #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26)
440 451 #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14)
441 452 #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9)
442 453 #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8)
443 454 #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5)
444 455 #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0)
445 456 #define CPI_CPU_LEVEL_TYPE(regs) BITX((regs)->cp_ecx, 15, 8)
446 457
447 458 #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22)
448 459 #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12)
449 460 #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0)
450 461
451 462 #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0)
452 463
453 464 #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0)
454 465
455 466
456 467 /*
457 468 * A couple of shorthand macros to identify "later" P6-family chips
458 469 * like the Pentium M and Core. First, the "older" P6-based stuff
459 470 * (loosely defined as "pre-Pentium-4"):
460 471 * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon
461 472 */
462 473 #define IS_LEGACY_P6(cpi) ( \
463 474 cpi->cpi_family == 6 && \
464 475 (cpi->cpi_model == 1 || \
465 476 cpi->cpi_model == 3 || \
466 477 cpi->cpi_model == 5 || \
467 478 cpi->cpi_model == 6 || \
468 479 cpi->cpi_model == 7 || \
469 480 cpi->cpi_model == 8 || \
470 481 cpi->cpi_model == 0xA || \
471 482 cpi->cpi_model == 0xB) \
472 483 )
473 484
474 485 /* A "new F6" is everything with family 6 that's not the above */
475 486 #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi))
476 487
477 488 /* Extended family/model support */
478 489 #define IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \
479 490 cpi->cpi_family >= 0xf)
480 491
481 492 /*
482 493 * Info for monitor/mwait idle loop.
483 494 *
484 495 * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's
485 496 * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November
486 497 * 2006.
487 498 * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual
488 499 * Documentation Updates" #33633, Rev 2.05, December 2006.
489 500 */
490 501 #define MWAIT_SUPPORT (0x00000001) /* mwait supported */
491 502 #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */
492 503 #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */
493 504 #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON)
494 505 #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2)
495 506 #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1)
496 507 #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0)
497 508 #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0)
498 509 /*
499 510 * Number of sub-cstates for a given c-state.
500 511 */
501 512 #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \
502 513 BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state)
503 514
504 515 /*
505 516 * XSAVE leaf 0xD enumeration
506 517 */
507 518 #define CPUID_LEAFD_2_YMM_OFFSET 576
508 519 #define CPUID_LEAFD_2_YMM_SIZE 256
509 520
510 521 /*
511 522 * Functions we consune from cpuid_subr.c; don't publish these in a header
512 523 * file to try and keep people using the expected cpuid_* interfaces.
513 524 */
514 525 extern uint32_t _cpuid_skt(uint_t, uint_t, uint_t, uint_t);
515 526 extern const char *_cpuid_sktstr(uint_t, uint_t, uint_t, uint_t);
516 527 extern uint32_t _cpuid_chiprev(uint_t, uint_t, uint_t, uint_t);
517 528 extern const char *_cpuid_chiprevstr(uint_t, uint_t, uint_t, uint_t);
518 529 extern uint_t _cpuid_vendorstr_to_vendorcode(char *);
519 530
520 531 /*
521 532 * Apply up various platform-dependent restrictions where the
522 533 * underlying platform restrictions mean the CPU can be marked
523 534 * as less capable than its cpuid instruction would imply.
524 535 */
525 536 #if defined(__xpv)
526 537 static void
527 538 platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp)
528 539 {
529 540 switch (eax) {
530 541 case 1: {
531 542 uint32_t mcamask = DOMAIN_IS_INITDOMAIN(xen_info) ?
532 543 0 : CPUID_INTC_EDX_MCA;
533 544 cp->cp_edx &=
534 545 ~(mcamask |
535 546 CPUID_INTC_EDX_PSE |
536 547 CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE |
537 548 CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR |
538 549 CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT |
539 550 CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP |
540 551 CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT);
541 552 break;
542 553 }
543 554
544 555 case 0x80000001:
545 556 cp->cp_edx &=
546 557 ~(CPUID_AMD_EDX_PSE |
547 558 CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE |
548 559 CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE |
549 560 CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 |
550 561 CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP |
551 562 CPUID_AMD_EDX_TSCP);
552 563 cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY;
553 564 break;
554 565 default:
555 566 break;
556 567 }
557 568
558 569 switch (vendor) {
559 570 case X86_VENDOR_Intel:
560 571 switch (eax) {
561 572 case 4:
562 573 /*
563 574 * Zero out the (ncores-per-chip - 1) field
564 575 */
565 576 cp->cp_eax &= 0x03fffffff;
566 577 break;
567 578 default:
568 579 break;
569 580 }
570 581 break;
571 582 case X86_VENDOR_AMD:
572 583 switch (eax) {
573 584
574 585 case 0x80000001:
575 586 cp->cp_ecx &= ~CPUID_AMD_ECX_CR8D;
576 587 break;
577 588
578 589 case 0x80000008:
579 590 /*
580 591 * Zero out the (ncores-per-chip - 1) field
581 592 */
582 593 cp->cp_ecx &= 0xffffff00;
583 594 break;
584 595 default:
585 596 break;
586 597 }
587 598 break;
588 599 default:
589 600 break;
590 601 }
591 602 }
592 603 #else
593 604 #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */
594 605 #endif
595 606
596 607 /*
597 608 * Some undocumented ways of patching the results of the cpuid
598 609 * instruction to permit running Solaris 10 on future cpus that
599 610 * we don't currently support. Could be set to non-zero values
600 611 * via settings in eeprom.
601 612 */
602 613
603 614 uint32_t cpuid_feature_ecx_include;
604 615 uint32_t cpuid_feature_ecx_exclude;
605 616 uint32_t cpuid_feature_edx_include;
606 617 uint32_t cpuid_feature_edx_exclude;
607 618
608 619 /*
609 620 * Allocate space for mcpu_cpi in the machcpu structure for all non-boot CPUs.
610 621 */
611 622 void
612 623 cpuid_alloc_space(cpu_t *cpu)
613 624 {
614 625 /*
615 626 * By convention, cpu0 is the boot cpu, which is set up
616 627 * before memory allocation is available. All other cpus get
617 628 * their cpuid_info struct allocated here.
618 629 */
619 630 ASSERT(cpu->cpu_id != 0);
620 631 ASSERT(cpu->cpu_m.mcpu_cpi == NULL);
621 632 cpu->cpu_m.mcpu_cpi =
622 633 kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP);
623 634 }
624 635
625 636 void
626 637 cpuid_free_space(cpu_t *cpu)
627 638 {
628 639 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
629 640 int i;
630 641
631 642 ASSERT(cpi != NULL);
632 643 ASSERT(cpi != &cpuid_info0);
633 644
634 645 /*
635 646 * Free up any function 4 related dynamic storage
636 647 */
637 648 for (i = 1; i < cpi->cpi_std_4_size; i++)
638 649 kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs));
639 650 if (cpi->cpi_std_4_size > 0)
640 651 kmem_free(cpi->cpi_std_4,
641 652 cpi->cpi_std_4_size * sizeof (struct cpuid_regs *));
642 653
643 654 kmem_free(cpi, sizeof (*cpi));
644 655 cpu->cpu_m.mcpu_cpi = NULL;
645 656 }
646 657
647 658 #if !defined(__xpv)
648 659 /*
649 660 * Determine the type of the underlying platform. This is used to customize
650 661 * initialization of various subsystems (e.g. TSC). determine_platform() must
651 662 * only ever be called once to prevent two processors from seeing different
652 663 * values of platform_type. Must be called before cpuid_pass1(), the earliest
653 664 * consumer to execute (uses _cpuid_chiprev --> synth_amd_info --> get_hwenv).
654 665 */
655 666 void
656 667 determine_platform(void)
657 668 {
658 669 struct cpuid_regs cp;
659 670 uint32_t base;
660 671 uint32_t regs[4];
661 672 char *hvstr = (char *)regs;
662 673
663 674 ASSERT(platform_type == -1);
664 675
665 676 platform_type = HW_NATIVE;
666 677
667 678 if (!enable_platform_detection)
668 679 return;
669 680
670 681 /*
671 682 * If Hypervisor CPUID bit is set, try to determine hypervisor
672 683 * vendor signature, and set platform type accordingly.
673 684 *
674 685 * References:
675 686 * http://lkml.org/lkml/2008/10/1/246
676 687 * http://kb.vmware.com/kb/1009458
677 688 */
678 689 cp.cp_eax = 0x1;
679 690 (void) __cpuid_insn(&cp);
680 691 if ((cp.cp_ecx & CPUID_INTC_ECX_HV) != 0) {
681 692 cp.cp_eax = 0x40000000;
682 693 (void) __cpuid_insn(&cp);
683 694 regs[0] = cp.cp_ebx;
684 695 regs[1] = cp.cp_ecx;
685 696 regs[2] = cp.cp_edx;
686 697 regs[3] = 0;
687 698 if (strcmp(hvstr, HVSIG_XEN_HVM) == 0) {
688 699 platform_type = HW_XEN_HVM;
689 700 return;
690 701 }
691 702 if (strcmp(hvstr, HVSIG_VMWARE) == 0) {
692 703 platform_type = HW_VMWARE;
693 704 return;
694 705 }
695 706 if (strcmp(hvstr, HVSIG_KVM) == 0) {
696 707 platform_type = HW_KVM;
697 708 return;
698 709 }
699 710 if (strcmp(hvstr, HVSIG_MICROSOFT) == 0)
700 711 platform_type = HW_MICROSOFT;
701 712 } else {
702 713 /*
703 714 * Check older VMware hardware versions. VMware hypervisor is
704 715 * detected by performing an IN operation to VMware hypervisor
705 716 * port and checking that value returned in %ebx is VMware
706 717 * hypervisor magic value.
707 718 *
708 719 * References: http://kb.vmware.com/kb/1009458
709 720 */
710 721 vmware_port(VMWARE_HVCMD_GETVERSION, regs);
711 722 if (regs[1] == VMWARE_HVMAGIC) {
712 723 platform_type = HW_VMWARE;
713 724 return;
714 725 }
715 726 }
716 727
717 728 /*
718 729 * Check Xen hypervisor. In a fully virtualized domain,
719 730 * Xen's pseudo-cpuid function returns a string representing the
720 731 * Xen signature in %ebx, %ecx, and %edx. %eax contains the maximum
721 732 * supported cpuid function. We need at least a (base + 2) leaf value
722 733 * to do what we want to do. Try different base values, since the
723 734 * hypervisor might use a different one depending on whether Hyper-V
724 735 * emulation is switched on by default or not.
725 736 */
726 737 for (base = 0x40000000; base < 0x40010000; base += 0x100) {
727 738 cp.cp_eax = base;
728 739 (void) __cpuid_insn(&cp);
729 740 regs[0] = cp.cp_ebx;
730 741 regs[1] = cp.cp_ecx;
731 742 regs[2] = cp.cp_edx;
732 743 regs[3] = 0;
733 744 if (strcmp(hvstr, HVSIG_XEN_HVM) == 0 &&
734 745 cp.cp_eax >= (base + 2)) {
735 746 platform_type &= ~HW_NATIVE;
736 747 platform_type |= HW_XEN_HVM;
737 748 return;
738 749 }
739 750 }
740 751 }
741 752
742 753 int
743 754 get_hwenv(void)
744 755 {
745 756 ASSERT(platform_type != -1);
746 757 return (platform_type);
747 758 }
748 759
749 760 int
750 761 is_controldom(void)
751 762 {
752 763 return (0);
753 764 }
754 765
755 766 #else
756 767
757 768 int
758 769 get_hwenv(void)
759 770 {
760 771 return (HW_XEN_PV);
761 772 }
762 773
763 774 int
764 775 is_controldom(void)
765 776 {
766 777 return (DOMAIN_IS_INITDOMAIN(xen_info));
767 778 }
768 779
769 780 #endif /* __xpv */
770 781
771 782 static void
772 783 cpuid_intel_getids(cpu_t *cpu, void *feature)
773 784 {
774 785 uint_t i;
775 786 uint_t chipid_shift = 0;
776 787 uint_t coreid_shift = 0;
777 788 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
778 789
779 790 for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1)
780 791 chipid_shift++;
781 792
782 793 cpi->cpi_chipid = cpi->cpi_apicid >> chipid_shift;
783 794 cpi->cpi_clogid = cpi->cpi_apicid & ((1 << chipid_shift) - 1);
784 795
785 796 if (is_x86_feature(feature, X86FSET_CMP)) {
786 797 /*
787 798 * Multi-core (and possibly multi-threaded)
788 799 * processors.
789 800 */
790 801 uint_t ncpu_per_core;
791 802 if (cpi->cpi_ncore_per_chip == 1)
792 803 ncpu_per_core = cpi->cpi_ncpu_per_chip;
793 804 else if (cpi->cpi_ncore_per_chip > 1)
794 805 ncpu_per_core = cpi->cpi_ncpu_per_chip /
795 806 cpi->cpi_ncore_per_chip;
796 807 /*
797 808 * 8bit APIC IDs on dual core Pentiums
798 809 * look like this:
799 810 *
800 811 * +-----------------------+------+------+
801 812 * | Physical Package ID | MC | HT |
802 813 * +-----------------------+------+------+
803 814 * <------- chipid -------->
804 815 * <------- coreid --------------->
805 816 * <--- clogid -->
806 817 * <------>
807 818 * pkgcoreid
808 819 *
809 820 * Where the number of bits necessary to
810 821 * represent MC and HT fields together equals
811 822 * to the minimum number of bits necessary to
812 823 * store the value of cpi->cpi_ncpu_per_chip.
813 824 * Of those bits, the MC part uses the number
814 825 * of bits necessary to store the value of
815 826 * cpi->cpi_ncore_per_chip.
816 827 */
817 828 for (i = 1; i < ncpu_per_core; i <<= 1)
818 829 coreid_shift++;
819 830 cpi->cpi_coreid = cpi->cpi_apicid >> coreid_shift;
820 831 cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift;
821 832 } else if (is_x86_feature(feature, X86FSET_HTT)) {
822 833 /*
823 834 * Single-core multi-threaded processors.
824 835 */
825 836 cpi->cpi_coreid = cpi->cpi_chipid;
826 837 cpi->cpi_pkgcoreid = 0;
827 838 }
828 839 cpi->cpi_procnodeid = cpi->cpi_chipid;
829 840 cpi->cpi_compunitid = cpi->cpi_coreid;
830 841 }
831 842
832 843 static void
833 844 cpuid_amd_getids(cpu_t *cpu)
834 845 {
835 846 int i, first_half, coreidsz;
836 847 uint32_t nb_caps_reg;
837 848 uint_t node2_1;
838 849 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
839 850 struct cpuid_regs *cp;
840 851
841 852 /*
842 853 * AMD CMP chips currently have a single thread per core.
843 854 *
844 855 * Since no two cpus share a core we must assign a distinct coreid
845 856 * per cpu, and we do this by using the cpu_id. This scheme does not,
846 857 * however, guarantee that sibling cores of a chip will have sequential
847 858 * coreids starting at a multiple of the number of cores per chip -
848 859 * that is usually the case, but if the ACPI MADT table is presented
849 860 * in a different order then we need to perform a few more gymnastics
850 861 * for the pkgcoreid.
851 862 *
852 863 * All processors in the system have the same number of enabled
853 864 * cores. Cores within a processor are always numbered sequentially
854 865 * from 0 regardless of how many or which are disabled, and there
855 866 * is no way for operating system to discover the real core id when some
856 867 * are disabled.
857 868 *
858 869 * In family 0x15, the cores come in pairs called compute units. They
859 870 * share I$ and L2 caches and the FPU. Enumeration of this feature is
860 871 * simplified by the new topology extensions CPUID leaf, indicated by
861 872 * the X86 feature X86FSET_TOPOEXT.
862 873 */
863 874
864 875 cpi->cpi_coreid = cpu->cpu_id;
865 876 cpi->cpi_compunitid = cpu->cpu_id;
866 877
867 878 if (cpi->cpi_xmaxeax >= 0x80000008) {
868 879
869 880 coreidsz = BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12);
870 881
871 882 /*
872 883 * In AMD parlance chip is really a node while Solaris
873 884 * sees chip as equivalent to socket/package.
874 885 */
875 886 cpi->cpi_ncore_per_chip =
876 887 BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1;
877 888 if (coreidsz == 0) {
878 889 /* Use legacy method */
879 890 for (i = 1; i < cpi->cpi_ncore_per_chip; i <<= 1)
880 891 coreidsz++;
881 892 if (coreidsz == 0)
882 893 coreidsz = 1;
883 894 }
884 895 } else {
885 896 /* Assume single-core part */
886 897 cpi->cpi_ncore_per_chip = 1;
887 898 coreidsz = 1;
888 899 }
889 900
890 901 cpi->cpi_clogid = cpi->cpi_pkgcoreid =
891 902 cpi->cpi_apicid & ((1<<coreidsz) - 1);
892 903 cpi->cpi_ncpu_per_chip = cpi->cpi_ncore_per_chip;
893 904
894 905 /* Get node ID, compute unit ID */
895 906 if (is_x86_feature(x86_featureset, X86FSET_TOPOEXT) &&
896 907 cpi->cpi_xmaxeax >= 0x8000001e) {
897 908 cp = &cpi->cpi_extd[0x1e];
898 909 cp->cp_eax = 0x8000001e;
899 910 (void) __cpuid_insn(cp);
900 911
901 912 cpi->cpi_procnodes_per_pkg = BITX(cp->cp_ecx, 10, 8) + 1;
902 913 cpi->cpi_procnodeid = BITX(cp->cp_ecx, 7, 0);
903 914 cpi->cpi_cores_per_compunit = BITX(cp->cp_ebx, 15, 8) + 1;
904 915 cpi->cpi_compunitid = BITX(cp->cp_ebx, 7, 0)
905 916 + (cpi->cpi_ncore_per_chip / cpi->cpi_cores_per_compunit)
906 917 * (cpi->cpi_procnodeid / cpi->cpi_procnodes_per_pkg);
907 918 } else if (cpi->cpi_family == 0xf || cpi->cpi_family >= 0x11) {
908 919 cpi->cpi_procnodeid = (cpi->cpi_apicid >> coreidsz) & 7;
909 920 } else if (cpi->cpi_family == 0x10) {
910 921 /*
911 922 * See if we are a multi-node processor.
912 923 * All processors in the system have the same number of nodes
913 924 */
914 925 nb_caps_reg = pci_getl_func(0, 24, 3, 0xe8);
915 926 if ((cpi->cpi_model < 8) || BITX(nb_caps_reg, 29, 29) == 0) {
916 927 /* Single-node */
917 928 cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 5,
918 929 coreidsz);
919 930 } else {
920 931
921 932 /*
922 933 * Multi-node revision D (2 nodes per package
923 934 * are supported)
924 935 */
925 936 cpi->cpi_procnodes_per_pkg = 2;
926 937
927 938 first_half = (cpi->cpi_pkgcoreid <=
928 939 (cpi->cpi_ncore_per_chip/2 - 1));
929 940
930 941 if (cpi->cpi_apicid == cpi->cpi_pkgcoreid) {
931 942 /* We are BSP */
932 943 cpi->cpi_procnodeid = (first_half ? 0 : 1);
933 944 } else {
934 945
935 946 /* We are AP */
936 947 /* NodeId[2:1] bits to use for reading F3xe8 */
937 948 node2_1 = BITX(cpi->cpi_apicid, 5, 4) << 1;
938 949
939 950 nb_caps_reg =
940 951 pci_getl_func(0, 24 + node2_1, 3, 0xe8);
941 952
942 953 /*
943 954 * Check IntNodeNum bit (31:30, but bit 31 is
944 955 * always 0 on dual-node processors)
945 956 */
946 957 if (BITX(nb_caps_reg, 30, 30) == 0)
947 958 cpi->cpi_procnodeid = node2_1 +
948 959 !first_half;
949 960 else
950 961 cpi->cpi_procnodeid = node2_1 +
951 962 first_half;
952 963 }
953 964 }
954 965 } else {
955 966 cpi->cpi_procnodeid = 0;
956 967 }
957 968
958 969 cpi->cpi_chipid =
959 970 cpi->cpi_procnodeid / cpi->cpi_procnodes_per_pkg;
960 971 }
961 972
962 973 /*
963 974 * Setup XFeature_Enabled_Mask register. Required by xsave feature.
964 975 */
965 976 void
966 977 setup_xfem(void)
967 978 {
968 979 uint64_t flags = XFEATURE_LEGACY_FP;
969 980
970 981 ASSERT(is_x86_feature(x86_featureset, X86FSET_XSAVE));
971 982
972 983 if (is_x86_feature(x86_featureset, X86FSET_SSE))
973 984 flags |= XFEATURE_SSE;
974 985
975 986 if (is_x86_feature(x86_featureset, X86FSET_AVX))
976 987 flags |= XFEATURE_AVX;
977 988
978 989 if (is_x86_feature(x86_featureset, X86FSET_AVX512F))
979 990 flags |= XFEATURE_AVX512;
980 991
981 992 set_xcr(XFEATURE_ENABLED_MASK, flags);
982 993
983 994 xsave_bv_all = flags;
984 995 }
985 996
986 997 void
987 998 cpuid_pass1(cpu_t *cpu, uchar_t *featureset)
988 999 {
989 1000 uint32_t mask_ecx, mask_edx;
990 1001 struct cpuid_info *cpi;
991 1002 struct cpuid_regs *cp;
992 1003 int xcpuid;
993 1004 #if !defined(__xpv)
994 1005 extern int idle_cpu_prefer_mwait;
995 1006 #endif
996 1007
997 1008 /*
998 1009 * Space statically allocated for BSP, ensure pointer is set
999 1010 */
1000 1011 if (cpu->cpu_id == 0) {
1001 1012 if (cpu->cpu_m.mcpu_cpi == NULL)
1002 1013 cpu->cpu_m.mcpu_cpi = &cpuid_info0;
1003 1014 }
1004 1015
1005 1016 add_x86_feature(featureset, X86FSET_CPUID);
1006 1017
1007 1018 cpi = cpu->cpu_m.mcpu_cpi;
1008 1019 ASSERT(cpi != NULL);
1009 1020 cp = &cpi->cpi_std[0];
1010 1021 cp->cp_eax = 0;
1011 1022 cpi->cpi_maxeax = __cpuid_insn(cp);
1012 1023 {
1013 1024 uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr;
1014 1025 *iptr++ = cp->cp_ebx;
1015 1026 *iptr++ = cp->cp_edx;
1016 1027 *iptr++ = cp->cp_ecx;
1017 1028 *(char *)&cpi->cpi_vendorstr[12] = '\0';
1018 1029 }
1019 1030
1020 1031 cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr);
1021 1032 x86_vendor = cpi->cpi_vendor; /* for compatibility */
1022 1033
1023 1034 /*
1024 1035 * Limit the range in case of weird hardware
1025 1036 */
1026 1037 if (cpi->cpi_maxeax > CPI_MAXEAX_MAX)
1027 1038 cpi->cpi_maxeax = CPI_MAXEAX_MAX;
1028 1039 if (cpi->cpi_maxeax < 1)
1029 1040 goto pass1_done;
1030 1041
1031 1042 cp = &cpi->cpi_std[1];
1032 1043 cp->cp_eax = 1;
1033 1044 (void) __cpuid_insn(cp);
1034 1045
1035 1046 /*
1036 1047 * Extract identifying constants for easy access.
1037 1048 */
1038 1049 cpi->cpi_model = CPI_MODEL(cpi);
1039 1050 cpi->cpi_family = CPI_FAMILY(cpi);
1040 1051
1041 1052 if (cpi->cpi_family == 0xf)
1042 1053 cpi->cpi_family += CPI_FAMILY_XTD(cpi);
1043 1054
1044 1055 /*
1045 1056 * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf.
1046 1057 * Intel, and presumably everyone else, uses model == 0xf, as
1047 1058 * one would expect (max value means possible overflow). Sigh.
1048 1059 */
1049 1060
1050 1061 switch (cpi->cpi_vendor) {
1051 1062 case X86_VENDOR_Intel:
1052 1063 if (IS_EXTENDED_MODEL_INTEL(cpi))
1053 1064 cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
1054 1065 break;
1055 1066 case X86_VENDOR_AMD:
1056 1067 if (CPI_FAMILY(cpi) == 0xf)
1057 1068 cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
1058 1069 break;
1059 1070 default:
1060 1071 if (cpi->cpi_model == 0xf)
1061 1072 cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
1062 1073 break;
1063 1074 }
1064 1075
1065 1076 cpi->cpi_step = CPI_STEP(cpi);
1066 1077 cpi->cpi_brandid = CPI_BRANDID(cpi);
1067 1078
1068 1079 /*
1069 1080 * *default* assumptions:
1070 1081 * - believe %edx feature word
1071 1082 * - ignore %ecx feature word
1072 1083 * - 32-bit virtual and physical addressing
1073 1084 */
1074 1085 mask_edx = 0xffffffff;
1075 1086 mask_ecx = 0;
1076 1087
1077 1088 cpi->cpi_pabits = cpi->cpi_vabits = 32;
1078 1089
1079 1090 switch (cpi->cpi_vendor) {
1080 1091 case X86_VENDOR_Intel:
1081 1092 if (cpi->cpi_family == 5)
1082 1093 x86_type = X86_TYPE_P5;
1083 1094 else if (IS_LEGACY_P6(cpi)) {
1084 1095 x86_type = X86_TYPE_P6;
1085 1096 pentiumpro_bug4046376 = 1;
1086 1097 /*
1087 1098 * Clear the SEP bit when it was set erroneously
1088 1099 */
1089 1100 if (cpi->cpi_model < 3 && cpi->cpi_step < 3)
1090 1101 cp->cp_edx &= ~CPUID_INTC_EDX_SEP;
1091 1102 } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) {
1092 1103 x86_type = X86_TYPE_P4;
1093 1104 /*
1094 1105 * We don't currently depend on any of the %ecx
1095 1106 * features until Prescott, so we'll only check
1096 1107 * this from P4 onwards. We might want to revisit
1097 1108 * that idea later.
1098 1109 */
1099 1110 mask_ecx = 0xffffffff;
1100 1111 } else if (cpi->cpi_family > 0xf)
1101 1112 mask_ecx = 0xffffffff;
1102 1113 /*
1103 1114 * We don't support MONITOR/MWAIT if leaf 5 is not available
1104 1115 * to obtain the monitor linesize.
1105 1116 */
1106 1117 if (cpi->cpi_maxeax < 5)
1107 1118 mask_ecx &= ~CPUID_INTC_ECX_MON;
1108 1119 break;
1109 1120 case X86_VENDOR_IntelClone:
1110 1121 default:
1111 1122 break;
1112 1123 case X86_VENDOR_AMD:
1113 1124 #if defined(OPTERON_ERRATUM_108)
1114 1125 if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) {
1115 1126 cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0;
1116 1127 cpi->cpi_model = 0xc;
1117 1128 } else
1118 1129 #endif
1119 1130 if (cpi->cpi_family == 5) {
1120 1131 /*
1121 1132 * AMD K5 and K6
1122 1133 *
1123 1134 * These CPUs have an incomplete implementation
1124 1135 * of MCA/MCE which we mask away.
1125 1136 */
1126 1137 mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA);
1127 1138
1128 1139 /*
1129 1140 * Model 0 uses the wrong (APIC) bit
1130 1141 * to indicate PGE. Fix it here.
1131 1142 */
1132 1143 if (cpi->cpi_model == 0) {
1133 1144 if (cp->cp_edx & 0x200) {
1134 1145 cp->cp_edx &= ~0x200;
1135 1146 cp->cp_edx |= CPUID_INTC_EDX_PGE;
1136 1147 }
1137 1148 }
1138 1149
1139 1150 /*
1140 1151 * Early models had problems w/ MMX; disable.
1141 1152 */
1142 1153 if (cpi->cpi_model < 6)
1143 1154 mask_edx &= ~CPUID_INTC_EDX_MMX;
1144 1155 }
1145 1156
1146 1157 /*
1147 1158 * For newer families, SSE3 and CX16, at least, are valid;
1148 1159 * enable all
1149 1160 */
1150 1161 if (cpi->cpi_family >= 0xf)
1151 1162 mask_ecx = 0xffffffff;
1152 1163 /*
1153 1164 * We don't support MONITOR/MWAIT if leaf 5 is not available
1154 1165 * to obtain the monitor linesize.
1155 1166 */
1156 1167 if (cpi->cpi_maxeax < 5)
1157 1168 mask_ecx &= ~CPUID_INTC_ECX_MON;
1158 1169
1159 1170 #if !defined(__xpv)
1160 1171 /*
1161 1172 * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD
1162 1173 * processors. AMD does not intend MWAIT to be used in the cpu
1163 1174 * idle loop on current and future processors. 10h and future
1164 1175 * AMD processors use more power in MWAIT than HLT.
1165 1176 * Pre-family-10h Opterons do not have the MWAIT instruction.
1166 1177 */
1167 1178 idle_cpu_prefer_mwait = 0;
1168 1179 #endif
1169 1180
1170 1181 break;
1171 1182 case X86_VENDOR_TM:
1172 1183 /*
1173 1184 * workaround the NT workaround in CMS 4.1
1174 1185 */
1175 1186 if (cpi->cpi_family == 5 && cpi->cpi_model == 4 &&
1176 1187 (cpi->cpi_step == 2 || cpi->cpi_step == 3))
1177 1188 cp->cp_edx |= CPUID_INTC_EDX_CX8;
1178 1189 break;
1179 1190 case X86_VENDOR_Centaur:
1180 1191 /*
1181 1192 * workaround the NT workarounds again
1182 1193 */
1183 1194 if (cpi->cpi_family == 6)
1184 1195 cp->cp_edx |= CPUID_INTC_EDX_CX8;
1185 1196 break;
1186 1197 case X86_VENDOR_Cyrix:
1187 1198 /*
1188 1199 * We rely heavily on the probing in locore
1189 1200 * to actually figure out what parts, if any,
1190 1201 * of the Cyrix cpuid instruction to believe.
1191 1202 */
1192 1203 switch (x86_type) {
1193 1204 case X86_TYPE_CYRIX_486:
1194 1205 mask_edx = 0;
1195 1206 break;
1196 1207 case X86_TYPE_CYRIX_6x86:
1197 1208 mask_edx = 0;
1198 1209 break;
1199 1210 case X86_TYPE_CYRIX_6x86L:
1200 1211 mask_edx =
1201 1212 CPUID_INTC_EDX_DE |
1202 1213 CPUID_INTC_EDX_CX8;
1203 1214 break;
1204 1215 case X86_TYPE_CYRIX_6x86MX:
1205 1216 mask_edx =
1206 1217 CPUID_INTC_EDX_DE |
1207 1218 CPUID_INTC_EDX_MSR |
1208 1219 CPUID_INTC_EDX_CX8 |
1209 1220 CPUID_INTC_EDX_PGE |
1210 1221 CPUID_INTC_EDX_CMOV |
1211 1222 CPUID_INTC_EDX_MMX;
1212 1223 break;
1213 1224 case X86_TYPE_CYRIX_GXm:
1214 1225 mask_edx =
1215 1226 CPUID_INTC_EDX_MSR |
1216 1227 CPUID_INTC_EDX_CX8 |
1217 1228 CPUID_INTC_EDX_CMOV |
1218 1229 CPUID_INTC_EDX_MMX;
1219 1230 break;
1220 1231 case X86_TYPE_CYRIX_MediaGX:
1221 1232 break;
1222 1233 case X86_TYPE_CYRIX_MII:
1223 1234 case X86_TYPE_VIA_CYRIX_III:
1224 1235 mask_edx =
1225 1236 CPUID_INTC_EDX_DE |
1226 1237 CPUID_INTC_EDX_TSC |
1227 1238 CPUID_INTC_EDX_MSR |
1228 1239 CPUID_INTC_EDX_CX8 |
1229 1240 CPUID_INTC_EDX_PGE |
1230 1241 CPUID_INTC_EDX_CMOV |
1231 1242 CPUID_INTC_EDX_MMX;
1232 1243 break;
1233 1244 default:
1234 1245 break;
1235 1246 }
1236 1247 break;
1237 1248 }
1238 1249
1239 1250 #if defined(__xpv)
1240 1251 /*
1241 1252 * Do not support MONITOR/MWAIT under a hypervisor
1242 1253 */
1243 1254 mask_ecx &= ~CPUID_INTC_ECX_MON;
1244 1255 /*
1245 1256 * Do not support XSAVE under a hypervisor for now
1246 1257 */
1247 1258 xsave_force_disable = B_TRUE;
1248 1259
1249 1260 #endif /* __xpv */
1250 1261
1251 1262 if (xsave_force_disable) {
1252 1263 mask_ecx &= ~CPUID_INTC_ECX_XSAVE;
1253 1264 mask_ecx &= ~CPUID_INTC_ECX_AVX;
1254 1265 mask_ecx &= ~CPUID_INTC_ECX_F16C;
1255 1266 mask_ecx &= ~CPUID_INTC_ECX_FMA;
1256 1267 }
1257 1268
1258 1269 /*
1259 1270 * Now we've figured out the masks that determine
1260 1271 * which bits we choose to believe, apply the masks
1261 1272 * to the feature words, then map the kernel's view
1262 1273 * of these feature words into its feature word.
1263 1274 */
1264 1275 cp->cp_edx &= mask_edx;
1265 1276 cp->cp_ecx &= mask_ecx;
1266 1277
1267 1278 /*
1268 1279 * apply any platform restrictions (we don't call this
1269 1280 * immediately after __cpuid_insn here, because we need the
1270 1281 * workarounds applied above first)
1271 1282 */
1272 1283 platform_cpuid_mangle(cpi->cpi_vendor, 1, cp);
1273 1284
1274 1285 /*
1275 1286 * In addition to ecx and edx, Intel is storing a bunch of instruction
1276 1287 * set extensions in leaf 7's ebx, ecx, and edx.
1277 1288 */
1278 1289 if (cpi->cpi_vendor == X86_VENDOR_Intel && cpi->cpi_maxeax >= 7) {
1279 1290 struct cpuid_regs *ecp;
1280 1291 ecp = &cpi->cpi_std[7];
1281 1292 ecp->cp_eax = 7;
1282 1293 ecp->cp_ecx = 0;
1283 1294 (void) __cpuid_insn(ecp);
1284 1295 /*
1285 1296 * If XSAVE has been disabled, just ignore all of the
1286 1297 * extended-save-area dependent flags here.
1287 1298 */
1288 1299 if (xsave_force_disable) {
1289 1300 ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_BMI1;
1290 1301 ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_BMI2;
↓ open down ↓ |
1082 lines elided |
↑ open up ↑ |
1291 1302 ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_AVX2;
1292 1303 ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_MPX;
1293 1304 ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_ALL_AVX512;
1294 1305 ecp->cp_ecx &= ~CPUID_INTC_ECX_7_0_ALL_AVX512;
1295 1306 ecp->cp_edx &= ~CPUID_INTC_EDX_7_0_ALL_AVX512;
1296 1307 }
1297 1308
1298 1309 if (ecp->cp_ebx & CPUID_INTC_EBX_7_0_SMEP)
1299 1310 add_x86_feature(featureset, X86FSET_SMEP);
1300 1311
1312 + if (ecp->cp_ebx & CPUID_INTC_EBX_7_0_INVPCID) {
1313 + add_x86_feature(featureset, X86FSET_INVPCID);
1314 + }
1315 +
1301 1316 /*
1302 1317 * We check disable_smap here in addition to in startup_smap()
1303 1318 * to ensure CPUs that aren't the boot CPU don't accidentally
1304 1319 * include it in the feature set and thus generate a mismatched
1305 1320 * x86 feature set across CPUs. Note that at this time we only
1306 1321 * enable SMAP for the 64-bit kernel.
1307 1322 */
1308 1323 #if defined(__amd64)
1309 1324 if (ecp->cp_ebx & CPUID_INTC_EBX_7_0_SMAP &&
1310 1325 disable_smap == 0)
1311 1326 add_x86_feature(featureset, X86FSET_SMAP);
1312 1327 #endif
1313 1328 if (ecp->cp_ebx & CPUID_INTC_EBX_7_0_MPX)
1314 1329 add_x86_feature(featureset, X86FSET_MPX);
1315 1330
1316 1331 if (ecp->cp_ebx & CPUID_INTC_EBX_7_0_RDSEED)
1317 1332 add_x86_feature(featureset, X86FSET_RDSEED);
1318 1333
1319 1334 if (ecp->cp_ebx & CPUID_INTC_EBX_7_0_ADX)
1320 1335 add_x86_feature(featureset, X86FSET_ADX);
1321 1336 }
1322 1337
1323 1338 /*
1324 1339 * fold in overrides from the "eeprom" mechanism
1325 1340 */
1326 1341 cp->cp_edx |= cpuid_feature_edx_include;
1327 1342 cp->cp_edx &= ~cpuid_feature_edx_exclude;
1328 1343
1329 1344 cp->cp_ecx |= cpuid_feature_ecx_include;
1330 1345 cp->cp_ecx &= ~cpuid_feature_ecx_exclude;
1331 1346
1332 1347 if (cp->cp_edx & CPUID_INTC_EDX_PSE) {
1333 1348 add_x86_feature(featureset, X86FSET_LARGEPAGE);
1334 1349 }
1335 1350 if (cp->cp_edx & CPUID_INTC_EDX_TSC) {
1336 1351 add_x86_feature(featureset, X86FSET_TSC);
1337 1352 }
1338 1353 if (cp->cp_edx & CPUID_INTC_EDX_MSR) {
1339 1354 add_x86_feature(featureset, X86FSET_MSR);
1340 1355 }
1341 1356 if (cp->cp_edx & CPUID_INTC_EDX_MTRR) {
1342 1357 add_x86_feature(featureset, X86FSET_MTRR);
1343 1358 }
1344 1359 if (cp->cp_edx & CPUID_INTC_EDX_PGE) {
1345 1360 add_x86_feature(featureset, X86FSET_PGE);
1346 1361 }
1347 1362 if (cp->cp_edx & CPUID_INTC_EDX_CMOV) {
1348 1363 add_x86_feature(featureset, X86FSET_CMOV);
1349 1364 }
1350 1365 if (cp->cp_edx & CPUID_INTC_EDX_MMX) {
1351 1366 add_x86_feature(featureset, X86FSET_MMX);
1352 1367 }
1353 1368 if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 &&
1354 1369 (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) {
1355 1370 add_x86_feature(featureset, X86FSET_MCA);
1356 1371 }
1357 1372 if (cp->cp_edx & CPUID_INTC_EDX_PAE) {
1358 1373 add_x86_feature(featureset, X86FSET_PAE);
1359 1374 }
1360 1375 if (cp->cp_edx & CPUID_INTC_EDX_CX8) {
1361 1376 add_x86_feature(featureset, X86FSET_CX8);
1362 1377 }
1363 1378 if (cp->cp_ecx & CPUID_INTC_ECX_CX16) {
1364 1379 add_x86_feature(featureset, X86FSET_CX16);
1365 1380 }
1366 1381 if (cp->cp_edx & CPUID_INTC_EDX_PAT) {
1367 1382 add_x86_feature(featureset, X86FSET_PAT);
1368 1383 }
1369 1384 if (cp->cp_edx & CPUID_INTC_EDX_SEP) {
1370 1385 add_x86_feature(featureset, X86FSET_SEP);
1371 1386 }
1372 1387 if (cp->cp_edx & CPUID_INTC_EDX_FXSR) {
1373 1388 /*
1374 1389 * In our implementation, fxsave/fxrstor
1375 1390 * are prerequisites before we'll even
1376 1391 * try and do SSE things.
1377 1392 */
1378 1393 if (cp->cp_edx & CPUID_INTC_EDX_SSE) {
1379 1394 add_x86_feature(featureset, X86FSET_SSE);
1380 1395 }
1381 1396 if (cp->cp_edx & CPUID_INTC_EDX_SSE2) {
1382 1397 add_x86_feature(featureset, X86FSET_SSE2);
1383 1398 }
1384 1399 if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) {
1385 1400 add_x86_feature(featureset, X86FSET_SSE3);
1386 1401 }
1387 1402 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) {
1388 1403 add_x86_feature(featureset, X86FSET_SSSE3);
1389 1404 }
1390 1405 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) {
1391 1406 add_x86_feature(featureset, X86FSET_SSE4_1);
1392 1407 }
1393 1408 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) {
1394 1409 add_x86_feature(featureset, X86FSET_SSE4_2);
1395 1410 }
1396 1411 if (cp->cp_ecx & CPUID_INTC_ECX_AES) {
1397 1412 add_x86_feature(featureset, X86FSET_AES);
1398 1413 }
1399 1414 if (cp->cp_ecx & CPUID_INTC_ECX_PCLMULQDQ) {
1400 1415 add_x86_feature(featureset, X86FSET_PCLMULQDQ);
1401 1416 }
1402 1417
1403 1418 if (cpi->cpi_std[7].cp_ebx & CPUID_INTC_EBX_7_0_SHA)
1404 1419 add_x86_feature(featureset, X86FSET_SHA);
1405 1420
1406 1421 if (cpi->cpi_std[7].cp_ecx & CPUID_INTC_ECX_7_0_UMIP)
1407 1422 add_x86_feature(featureset, X86FSET_UMIP);
1408 1423 if (cpi->cpi_std[7].cp_ecx & CPUID_INTC_ECX_7_0_PKU)
1409 1424 add_x86_feature(featureset, X86FSET_PKU);
1410 1425 if (cpi->cpi_std[7].cp_ecx & CPUID_INTC_ECX_7_0_OSPKE)
1411 1426 add_x86_feature(featureset, X86FSET_OSPKE);
1412 1427
1413 1428 if (cp->cp_ecx & CPUID_INTC_ECX_XSAVE) {
1414 1429 add_x86_feature(featureset, X86FSET_XSAVE);
1415 1430
1416 1431 /* We only test AVX & AVX512 when there is XSAVE */
1417 1432
1418 1433 if (cp->cp_ecx & CPUID_INTC_ECX_AVX) {
1419 1434 add_x86_feature(featureset,
1420 1435 X86FSET_AVX);
1421 1436
1422 1437 /*
1423 1438 * Intel says we can't check these without also
1424 1439 * checking AVX.
1425 1440 */
1426 1441 if (cp->cp_ecx & CPUID_INTC_ECX_F16C)
1427 1442 add_x86_feature(featureset,
1428 1443 X86FSET_F16C);
1429 1444
1430 1445 if (cp->cp_ecx & CPUID_INTC_ECX_FMA)
1431 1446 add_x86_feature(featureset,
1432 1447 X86FSET_FMA);
1433 1448
1434 1449 if (cpi->cpi_std[7].cp_ebx &
1435 1450 CPUID_INTC_EBX_7_0_BMI1)
1436 1451 add_x86_feature(featureset,
1437 1452 X86FSET_BMI1);
1438 1453
1439 1454 if (cpi->cpi_std[7].cp_ebx &
1440 1455 CPUID_INTC_EBX_7_0_BMI2)
1441 1456 add_x86_feature(featureset,
1442 1457 X86FSET_BMI2);
1443 1458
1444 1459 if (cpi->cpi_std[7].cp_ebx &
1445 1460 CPUID_INTC_EBX_7_0_AVX2)
1446 1461 add_x86_feature(featureset,
1447 1462 X86FSET_AVX2);
1448 1463 }
1449 1464
1450 1465 if (cpi->cpi_std[7].cp_ebx &
1451 1466 CPUID_INTC_EBX_7_0_AVX512F) {
1452 1467 add_x86_feature(featureset, X86FSET_AVX512F);
1453 1468
1454 1469 if (cpi->cpi_std[7].cp_ebx &
1455 1470 CPUID_INTC_EBX_7_0_AVX512DQ)
1456 1471 add_x86_feature(featureset,
1457 1472 X86FSET_AVX512DQ);
1458 1473 if (cpi->cpi_std[7].cp_ebx &
1459 1474 CPUID_INTC_EBX_7_0_AVX512IFMA)
1460 1475 add_x86_feature(featureset,
1461 1476 X86FSET_AVX512FMA);
1462 1477 if (cpi->cpi_std[7].cp_ebx &
1463 1478 CPUID_INTC_EBX_7_0_AVX512PF)
1464 1479 add_x86_feature(featureset,
1465 1480 X86FSET_AVX512PF);
1466 1481 if (cpi->cpi_std[7].cp_ebx &
1467 1482 CPUID_INTC_EBX_7_0_AVX512ER)
1468 1483 add_x86_feature(featureset,
1469 1484 X86FSET_AVX512ER);
1470 1485 if (cpi->cpi_std[7].cp_ebx &
1471 1486 CPUID_INTC_EBX_7_0_AVX512CD)
1472 1487 add_x86_feature(featureset,
1473 1488 X86FSET_AVX512CD);
1474 1489 if (cpi->cpi_std[7].cp_ebx &
1475 1490 CPUID_INTC_EBX_7_0_AVX512BW)
1476 1491 add_x86_feature(featureset,
1477 1492 X86FSET_AVX512BW);
1478 1493 if (cpi->cpi_std[7].cp_ebx &
1479 1494 CPUID_INTC_EBX_7_0_AVX512VL)
1480 1495 add_x86_feature(featureset,
1481 1496 X86FSET_AVX512VL);
1482 1497
1483 1498 if (cpi->cpi_std[7].cp_ecx &
1484 1499 CPUID_INTC_ECX_7_0_AVX512VBMI)
1485 1500 add_x86_feature(featureset,
1486 1501 X86FSET_AVX512VBMI);
1487 1502 if (cpi->cpi_std[7].cp_ecx &
1488 1503 CPUID_INTC_ECX_7_0_AVX512VPOPCDQ)
1489 1504 add_x86_feature(featureset,
1490 1505 X86FSET_AVX512VPOPCDQ);
1491 1506
1492 1507 if (cpi->cpi_std[7].cp_edx &
↓ open down ↓ |
182 lines elided |
↑ open up ↑ |
1493 1508 CPUID_INTC_EDX_7_0_AVX5124NNIW)
1494 1509 add_x86_feature(featureset,
1495 1510 X86FSET_AVX512NNIW);
1496 1511 if (cpi->cpi_std[7].cp_edx &
1497 1512 CPUID_INTC_EDX_7_0_AVX5124FMAPS)
1498 1513 add_x86_feature(featureset,
1499 1514 X86FSET_AVX512FMAPS);
1500 1515 }
1501 1516 }
1502 1517 }
1518 +
1519 + if (cpi->cpi_vendor == X86_VENDOR_Intel) {
1520 + if (cp->cp_ecx & CPUID_INTC_ECX_PCID) {
1521 + add_x86_feature(featureset, X86FSET_PCID);
1522 + }
1523 + }
1524 +
1503 1525 if (cp->cp_ecx & CPUID_INTC_ECX_X2APIC) {
1504 1526 add_x86_feature(featureset, X86FSET_X2APIC);
1505 1527 }
1506 1528 if (cp->cp_edx & CPUID_INTC_EDX_DE) {
1507 1529 add_x86_feature(featureset, X86FSET_DE);
1508 1530 }
1509 1531 #if !defined(__xpv)
1510 1532 if (cp->cp_ecx & CPUID_INTC_ECX_MON) {
1511 1533
1512 1534 /*
1513 1535 * We require the CLFLUSH instruction for erratum workaround
1514 1536 * to use MONITOR/MWAIT.
1515 1537 */
1516 1538 if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) {
1517 1539 cpi->cpi_mwait.support |= MWAIT_SUPPORT;
1518 1540 add_x86_feature(featureset, X86FSET_MWAIT);
1519 1541 } else {
1520 1542 extern int idle_cpu_assert_cflush_monitor;
1521 1543
1522 1544 /*
1523 1545 * All processors we are aware of which have
1524 1546 * MONITOR/MWAIT also have CLFLUSH.
1525 1547 */
1526 1548 if (idle_cpu_assert_cflush_monitor) {
1527 1549 ASSERT((cp->cp_ecx & CPUID_INTC_ECX_MON) &&
1528 1550 (cp->cp_edx & CPUID_INTC_EDX_CLFSH));
1529 1551 }
1530 1552 }
1531 1553 }
1532 1554 #endif /* __xpv */
1533 1555
1534 1556 if (cp->cp_ecx & CPUID_INTC_ECX_VMX) {
1535 1557 add_x86_feature(featureset, X86FSET_VMX);
1536 1558 }
1537 1559
1538 1560 if (cp->cp_ecx & CPUID_INTC_ECX_RDRAND)
1539 1561 add_x86_feature(featureset, X86FSET_RDRAND);
1540 1562
1541 1563 /*
1542 1564 * Only need it first time, rest of the cpus would follow suit.
1543 1565 * we only capture this for the bootcpu.
1544 1566 */
1545 1567 if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) {
1546 1568 add_x86_feature(featureset, X86FSET_CLFSH);
1547 1569 x86_clflush_size = (BITX(cp->cp_ebx, 15, 8) * 8);
1548 1570 }
1549 1571 if (is_x86_feature(featureset, X86FSET_PAE))
1550 1572 cpi->cpi_pabits = 36;
1551 1573
1552 1574 /*
1553 1575 * Hyperthreading configuration is slightly tricky on Intel
1554 1576 * and pure clones, and even trickier on AMD.
1555 1577 *
1556 1578 * (AMD chose to set the HTT bit on their CMP processors,
1557 1579 * even though they're not actually hyperthreaded. Thus it
1558 1580 * takes a bit more work to figure out what's really going
1559 1581 * on ... see the handling of the CMP_LGCY bit below)
1560 1582 */
1561 1583 if (cp->cp_edx & CPUID_INTC_EDX_HTT) {
1562 1584 cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi);
1563 1585 if (cpi->cpi_ncpu_per_chip > 1)
1564 1586 add_x86_feature(featureset, X86FSET_HTT);
1565 1587 } else {
1566 1588 cpi->cpi_ncpu_per_chip = 1;
1567 1589 }
1568 1590
1569 1591 if (cpi->cpi_vendor == X86_VENDOR_Intel && cpi->cpi_maxeax >= 0xD &&
1570 1592 !xsave_force_disable) {
1571 1593 struct cpuid_regs r, *ecp;
1572 1594
1573 1595 ecp = &r;
1574 1596 ecp->cp_eax = 0xD;
1575 1597 ecp->cp_ecx = 1;
1576 1598 ecp->cp_edx = ecp->cp_ebx = 0;
1577 1599 (void) __cpuid_insn(ecp);
1578 1600
1579 1601 if (ecp->cp_eax & CPUID_INTC_EAX_D_1_XSAVEOPT)
1580 1602 add_x86_feature(featureset, X86FSET_XSAVEOPT);
1581 1603 if (ecp->cp_eax & CPUID_INTC_EAX_D_1_XSAVEC)
1582 1604 add_x86_feature(featureset, X86FSET_XSAVEC);
1583 1605 if (ecp->cp_eax & CPUID_INTC_EAX_D_1_XSAVES)
1584 1606 add_x86_feature(featureset, X86FSET_XSAVES);
1585 1607 }
1586 1608
1587 1609 /*
1588 1610 * Work on the "extended" feature information, doing
1589 1611 * some basic initialization for cpuid_pass2()
1590 1612 */
1591 1613 xcpuid = 0;
1592 1614 switch (cpi->cpi_vendor) {
1593 1615 case X86_VENDOR_Intel:
1594 1616 /*
1595 1617 * On KVM we know we will have proper support for extended
1596 1618 * cpuid.
1597 1619 */
1598 1620 if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf ||
1599 1621 (get_hwenv() == HW_KVM && cpi->cpi_family == 6 &&
1600 1622 (cpi->cpi_model == 6 || cpi->cpi_model == 2)))
1601 1623 xcpuid++;
1602 1624 break;
1603 1625 case X86_VENDOR_AMD:
1604 1626 if (cpi->cpi_family > 5 ||
1605 1627 (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
1606 1628 xcpuid++;
1607 1629 break;
1608 1630 case X86_VENDOR_Cyrix:
1609 1631 /*
1610 1632 * Only these Cyrix CPUs are -known- to support
1611 1633 * extended cpuid operations.
1612 1634 */
1613 1635 if (x86_type == X86_TYPE_VIA_CYRIX_III ||
1614 1636 x86_type == X86_TYPE_CYRIX_GXm)
1615 1637 xcpuid++;
1616 1638 break;
1617 1639 case X86_VENDOR_Centaur:
1618 1640 case X86_VENDOR_TM:
1619 1641 default:
1620 1642 xcpuid++;
1621 1643 break;
1622 1644 }
1623 1645
1624 1646 if (xcpuid) {
1625 1647 cp = &cpi->cpi_extd[0];
1626 1648 cp->cp_eax = 0x80000000;
1627 1649 cpi->cpi_xmaxeax = __cpuid_insn(cp);
1628 1650 }
1629 1651
1630 1652 if (cpi->cpi_xmaxeax & 0x80000000) {
1631 1653
1632 1654 if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX)
1633 1655 cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX;
1634 1656
1635 1657 switch (cpi->cpi_vendor) {
1636 1658 case X86_VENDOR_Intel:
1637 1659 case X86_VENDOR_AMD:
1638 1660 if (cpi->cpi_xmaxeax < 0x80000001)
1639 1661 break;
1640 1662 cp = &cpi->cpi_extd[1];
1641 1663 cp->cp_eax = 0x80000001;
1642 1664 (void) __cpuid_insn(cp);
1643 1665
1644 1666 if (cpi->cpi_vendor == X86_VENDOR_AMD &&
1645 1667 cpi->cpi_family == 5 &&
1646 1668 cpi->cpi_model == 6 &&
1647 1669 cpi->cpi_step == 6) {
1648 1670 /*
1649 1671 * K6 model 6 uses bit 10 to indicate SYSC
1650 1672 * Later models use bit 11. Fix it here.
1651 1673 */
1652 1674 if (cp->cp_edx & 0x400) {
1653 1675 cp->cp_edx &= ~0x400;
1654 1676 cp->cp_edx |= CPUID_AMD_EDX_SYSC;
1655 1677 }
1656 1678 }
1657 1679
1658 1680 platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp);
1659 1681
1660 1682 /*
1661 1683 * Compute the additions to the kernel's feature word.
1662 1684 */
1663 1685 if (cp->cp_edx & CPUID_AMD_EDX_NX) {
1664 1686 add_x86_feature(featureset, X86FSET_NX);
1665 1687 }
1666 1688
1667 1689 /*
1668 1690 * Regardless whether or not we boot 64-bit,
1669 1691 * we should have a way to identify whether
1670 1692 * the CPU is capable of running 64-bit.
1671 1693 */
1672 1694 if (cp->cp_edx & CPUID_AMD_EDX_LM) {
1673 1695 add_x86_feature(featureset, X86FSET_64);
1674 1696 }
1675 1697
1676 1698 #if defined(__amd64)
1677 1699 /* 1 GB large page - enable only for 64 bit kernel */
1678 1700 if (cp->cp_edx & CPUID_AMD_EDX_1GPG) {
1679 1701 add_x86_feature(featureset, X86FSET_1GPG);
1680 1702 }
1681 1703 #endif
1682 1704
1683 1705 if ((cpi->cpi_vendor == X86_VENDOR_AMD) &&
1684 1706 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) &&
1685 1707 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) {
1686 1708 add_x86_feature(featureset, X86FSET_SSE4A);
1687 1709 }
1688 1710
1689 1711 /*
1690 1712 * If both the HTT and CMP_LGCY bits are set,
1691 1713 * then we're not actually HyperThreaded. Read
1692 1714 * "AMD CPUID Specification" for more details.
1693 1715 */
1694 1716 if (cpi->cpi_vendor == X86_VENDOR_AMD &&
1695 1717 is_x86_feature(featureset, X86FSET_HTT) &&
1696 1718 (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) {
1697 1719 remove_x86_feature(featureset, X86FSET_HTT);
1698 1720 add_x86_feature(featureset, X86FSET_CMP);
1699 1721 }
1700 1722 #if defined(__amd64)
1701 1723 /*
1702 1724 * It's really tricky to support syscall/sysret in
1703 1725 * the i386 kernel; we rely on sysenter/sysexit
1704 1726 * instead. In the amd64 kernel, things are -way-
1705 1727 * better.
1706 1728 */
1707 1729 if (cp->cp_edx & CPUID_AMD_EDX_SYSC) {
1708 1730 add_x86_feature(featureset, X86FSET_ASYSC);
1709 1731 }
1710 1732
1711 1733 /*
1712 1734 * While we're thinking about system calls, note
1713 1735 * that AMD processors don't support sysenter
1714 1736 * in long mode at all, so don't try to program them.
1715 1737 */
1716 1738 if (x86_vendor == X86_VENDOR_AMD) {
1717 1739 remove_x86_feature(featureset, X86FSET_SEP);
1718 1740 }
1719 1741 #endif
1720 1742 if (cp->cp_edx & CPUID_AMD_EDX_TSCP) {
1721 1743 add_x86_feature(featureset, X86FSET_TSCP);
1722 1744 }
1723 1745
1724 1746 if (cp->cp_ecx & CPUID_AMD_ECX_SVM) {
1725 1747 add_x86_feature(featureset, X86FSET_SVM);
1726 1748 }
1727 1749
1728 1750 if (cp->cp_ecx & CPUID_AMD_ECX_TOPOEXT) {
1729 1751 add_x86_feature(featureset, X86FSET_TOPOEXT);
1730 1752 }
1731 1753 break;
1732 1754 default:
1733 1755 break;
1734 1756 }
1735 1757
1736 1758 /*
1737 1759 * Get CPUID data about processor cores and hyperthreads.
1738 1760 */
1739 1761 switch (cpi->cpi_vendor) {
1740 1762 case X86_VENDOR_Intel:
1741 1763 if (cpi->cpi_maxeax >= 4) {
1742 1764 cp = &cpi->cpi_std[4];
1743 1765 cp->cp_eax = 4;
1744 1766 cp->cp_ecx = 0;
1745 1767 (void) __cpuid_insn(cp);
1746 1768 platform_cpuid_mangle(cpi->cpi_vendor, 4, cp);
1747 1769 }
1748 1770 /*FALLTHROUGH*/
1749 1771 case X86_VENDOR_AMD:
1750 1772 if (cpi->cpi_xmaxeax < 0x80000008)
1751 1773 break;
1752 1774 cp = &cpi->cpi_extd[8];
1753 1775 cp->cp_eax = 0x80000008;
1754 1776 (void) __cpuid_insn(cp);
1755 1777 platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp);
1756 1778
1757 1779 /*
1758 1780 * Virtual and physical address limits from
1759 1781 * cpuid override previously guessed values.
1760 1782 */
1761 1783 cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0);
1762 1784 cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8);
1763 1785 break;
1764 1786 default:
1765 1787 break;
1766 1788 }
1767 1789
1768 1790 /*
1769 1791 * Derive the number of cores per chip
1770 1792 */
1771 1793 switch (cpi->cpi_vendor) {
1772 1794 case X86_VENDOR_Intel:
1773 1795 if (cpi->cpi_maxeax < 4) {
1774 1796 cpi->cpi_ncore_per_chip = 1;
1775 1797 break;
1776 1798 } else {
1777 1799 cpi->cpi_ncore_per_chip =
1778 1800 BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1;
1779 1801 }
1780 1802 break;
1781 1803 case X86_VENDOR_AMD:
1782 1804 if (cpi->cpi_xmaxeax < 0x80000008) {
1783 1805 cpi->cpi_ncore_per_chip = 1;
1784 1806 break;
1785 1807 } else {
1786 1808 /*
1787 1809 * On family 0xf cpuid fn 2 ECX[7:0] "NC" is
1788 1810 * 1 less than the number of physical cores on
1789 1811 * the chip. In family 0x10 this value can
1790 1812 * be affected by "downcoring" - it reflects
1791 1813 * 1 less than the number of cores actually
1792 1814 * enabled on this node.
1793 1815 */
1794 1816 cpi->cpi_ncore_per_chip =
1795 1817 BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1;
1796 1818 }
1797 1819 break;
1798 1820 default:
1799 1821 cpi->cpi_ncore_per_chip = 1;
1800 1822 break;
1801 1823 }
1802 1824
1803 1825 /*
1804 1826 * Get CPUID data about TSC Invariance in Deep C-State.
1805 1827 */
1806 1828 switch (cpi->cpi_vendor) {
1807 1829 case X86_VENDOR_Intel:
1808 1830 if (cpi->cpi_maxeax >= 7) {
1809 1831 cp = &cpi->cpi_extd[7];
1810 1832 cp->cp_eax = 0x80000007;
1811 1833 cp->cp_ecx = 0;
1812 1834 (void) __cpuid_insn(cp);
1813 1835 }
1814 1836 break;
1815 1837 default:
1816 1838 break;
1817 1839 }
1818 1840 } else {
1819 1841 cpi->cpi_ncore_per_chip = 1;
1820 1842 }
1821 1843
1822 1844 /*
1823 1845 * If more than one core, then this processor is CMP.
1824 1846 */
1825 1847 if (cpi->cpi_ncore_per_chip > 1) {
1826 1848 add_x86_feature(featureset, X86FSET_CMP);
1827 1849 }
1828 1850
1829 1851 /*
1830 1852 * If the number of cores is the same as the number
1831 1853 * of CPUs, then we cannot have HyperThreading.
1832 1854 */
1833 1855 if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) {
1834 1856 remove_x86_feature(featureset, X86FSET_HTT);
1835 1857 }
1836 1858
1837 1859 cpi->cpi_apicid = CPI_APIC_ID(cpi);
1838 1860 cpi->cpi_procnodes_per_pkg = 1;
1839 1861 cpi->cpi_cores_per_compunit = 1;
1840 1862 if (is_x86_feature(featureset, X86FSET_HTT) == B_FALSE &&
1841 1863 is_x86_feature(featureset, X86FSET_CMP) == B_FALSE) {
1842 1864 /*
1843 1865 * Single-core single-threaded processors.
1844 1866 */
1845 1867 cpi->cpi_chipid = -1;
1846 1868 cpi->cpi_clogid = 0;
1847 1869 cpi->cpi_coreid = cpu->cpu_id;
1848 1870 cpi->cpi_pkgcoreid = 0;
1849 1871 if (cpi->cpi_vendor == X86_VENDOR_AMD)
1850 1872 cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 3, 0);
1851 1873 else
1852 1874 cpi->cpi_procnodeid = cpi->cpi_chipid;
1853 1875 } else if (cpi->cpi_ncpu_per_chip > 1) {
1854 1876 if (cpi->cpi_vendor == X86_VENDOR_Intel)
1855 1877 cpuid_intel_getids(cpu, featureset);
1856 1878 else if (cpi->cpi_vendor == X86_VENDOR_AMD)
1857 1879 cpuid_amd_getids(cpu);
1858 1880 else {
1859 1881 /*
1860 1882 * All other processors are currently
1861 1883 * assumed to have single cores.
1862 1884 */
1863 1885 cpi->cpi_coreid = cpi->cpi_chipid;
1864 1886 cpi->cpi_pkgcoreid = 0;
1865 1887 cpi->cpi_procnodeid = cpi->cpi_chipid;
1866 1888 cpi->cpi_compunitid = cpi->cpi_chipid;
1867 1889 }
1868 1890 }
1869 1891
1870 1892 /*
1871 1893 * Synthesize chip "revision" and socket type
1872 1894 */
1873 1895 cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family,
1874 1896 cpi->cpi_model, cpi->cpi_step);
1875 1897 cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor,
1876 1898 cpi->cpi_family, cpi->cpi_model, cpi->cpi_step);
1877 1899 cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family,
1878 1900 cpi->cpi_model, cpi->cpi_step);
1879 1901
1880 1902 /*
1881 1903 * While we're here, check for the AMD "Error Pointer Zero/Restore"
1882 1904 * feature. This can be used to setup the FP save handlers
1883 1905 * appropriately.
1884 1906 */
1885 1907 if (cpi->cpi_vendor == X86_VENDOR_AMD) {
1886 1908 if (cpi->cpi_xmaxeax >= 0x80000008 &&
1887 1909 cpi->cpi_extd[8].cp_ebx & CPUID_AMD_EBX_ERR_PTR_ZERO) {
1888 1910 /* Special handling for AMD FP not necessary. */
1889 1911 cpi->cpi_fp_amd_save = 0;
1890 1912 } else {
1891 1913 cpi->cpi_fp_amd_save = 1;
1892 1914 }
1893 1915 }
1894 1916
1895 1917 pass1_done:
1896 1918 cpi->cpi_pass = 1;
1897 1919 }
1898 1920
1899 1921 /*
1900 1922 * Make copies of the cpuid table entries we depend on, in
1901 1923 * part for ease of parsing now, in part so that we have only
1902 1924 * one place to correct any of it, in part for ease of
1903 1925 * later export to userland, and in part so we can look at
1904 1926 * this stuff in a crash dump.
1905 1927 */
1906 1928
1907 1929 /*ARGSUSED*/
1908 1930 void
1909 1931 cpuid_pass2(cpu_t *cpu)
1910 1932 {
1911 1933 uint_t n, nmax;
1912 1934 int i;
1913 1935 struct cpuid_regs *cp;
1914 1936 uint8_t *dp;
1915 1937 uint32_t *iptr;
1916 1938 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
1917 1939
1918 1940 ASSERT(cpi->cpi_pass == 1);
1919 1941
1920 1942 if (cpi->cpi_maxeax < 1)
1921 1943 goto pass2_done;
1922 1944
1923 1945 if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD)
1924 1946 nmax = NMAX_CPI_STD;
1925 1947 /*
1926 1948 * (We already handled n == 0 and n == 1 in pass 1)
1927 1949 */
1928 1950 for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) {
1929 1951 cp->cp_eax = n;
1930 1952
1931 1953 /*
1932 1954 * CPUID function 4 expects %ecx to be initialized
1933 1955 * with an index which indicates which cache to return
1934 1956 * information about. The OS is expected to call function 4
1935 1957 * with %ecx set to 0, 1, 2, ... until it returns with
1936 1958 * EAX[4:0] set to 0, which indicates there are no more
1937 1959 * caches.
1938 1960 *
1939 1961 * Here, populate cpi_std[4] with the information returned by
1940 1962 * function 4 when %ecx == 0, and do the rest in cpuid_pass3()
1941 1963 * when dynamic memory allocation becomes available.
1942 1964 *
1943 1965 * Note: we need to explicitly initialize %ecx here, since
1944 1966 * function 4 may have been previously invoked.
1945 1967 *
1946 1968 * The same is all true for CPUID function 7.
1947 1969 */
1948 1970 if (n == 4 || n == 7)
1949 1971 cp->cp_ecx = 0;
1950 1972
1951 1973 (void) __cpuid_insn(cp);
1952 1974 platform_cpuid_mangle(cpi->cpi_vendor, n, cp);
1953 1975 switch (n) {
1954 1976 case 2:
1955 1977 /*
1956 1978 * "the lower 8 bits of the %eax register
1957 1979 * contain a value that identifies the number
1958 1980 * of times the cpuid [instruction] has to be
1959 1981 * executed to obtain a complete image of the
1960 1982 * processor's caching systems."
1961 1983 *
1962 1984 * How *do* they make this stuff up?
1963 1985 */
1964 1986 cpi->cpi_ncache = sizeof (*cp) *
1965 1987 BITX(cp->cp_eax, 7, 0);
1966 1988 if (cpi->cpi_ncache == 0)
1967 1989 break;
1968 1990 cpi->cpi_ncache--; /* skip count byte */
1969 1991
1970 1992 /*
1971 1993 * Well, for now, rather than attempt to implement
1972 1994 * this slightly dubious algorithm, we just look
1973 1995 * at the first 15 ..
1974 1996 */
1975 1997 if (cpi->cpi_ncache > (sizeof (*cp) - 1))
1976 1998 cpi->cpi_ncache = sizeof (*cp) - 1;
1977 1999
1978 2000 dp = cpi->cpi_cacheinfo;
1979 2001 if (BITX(cp->cp_eax, 31, 31) == 0) {
1980 2002 uint8_t *p = (void *)&cp->cp_eax;
1981 2003 for (i = 1; i < 4; i++)
1982 2004 if (p[i] != 0)
1983 2005 *dp++ = p[i];
1984 2006 }
1985 2007 if (BITX(cp->cp_ebx, 31, 31) == 0) {
1986 2008 uint8_t *p = (void *)&cp->cp_ebx;
1987 2009 for (i = 0; i < 4; i++)
1988 2010 if (p[i] != 0)
1989 2011 *dp++ = p[i];
1990 2012 }
1991 2013 if (BITX(cp->cp_ecx, 31, 31) == 0) {
1992 2014 uint8_t *p = (void *)&cp->cp_ecx;
1993 2015 for (i = 0; i < 4; i++)
1994 2016 if (p[i] != 0)
1995 2017 *dp++ = p[i];
1996 2018 }
1997 2019 if (BITX(cp->cp_edx, 31, 31) == 0) {
1998 2020 uint8_t *p = (void *)&cp->cp_edx;
1999 2021 for (i = 0; i < 4; i++)
2000 2022 if (p[i] != 0)
2001 2023 *dp++ = p[i];
2002 2024 }
2003 2025 break;
2004 2026
2005 2027 case 3: /* Processor serial number, if PSN supported */
2006 2028 break;
2007 2029
2008 2030 case 4: /* Deterministic cache parameters */
2009 2031 break;
2010 2032
2011 2033 case 5: /* Monitor/Mwait parameters */
2012 2034 {
2013 2035 size_t mwait_size;
2014 2036
2015 2037 /*
2016 2038 * check cpi_mwait.support which was set in cpuid_pass1
2017 2039 */
2018 2040 if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT))
2019 2041 break;
2020 2042
2021 2043 /*
2022 2044 * Protect ourself from insane mwait line size.
2023 2045 * Workaround for incomplete hardware emulator(s).
2024 2046 */
2025 2047 mwait_size = (size_t)MWAIT_SIZE_MAX(cpi);
2026 2048 if (mwait_size < sizeof (uint32_t) ||
2027 2049 !ISP2(mwait_size)) {
2028 2050 #if DEBUG
2029 2051 cmn_err(CE_NOTE, "Cannot handle cpu %d mwait "
2030 2052 "size %ld", cpu->cpu_id, (long)mwait_size);
2031 2053 #endif
2032 2054 break;
2033 2055 }
2034 2056
2035 2057 cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi);
2036 2058 cpi->cpi_mwait.mon_max = mwait_size;
2037 2059 if (MWAIT_EXTENSION(cpi)) {
2038 2060 cpi->cpi_mwait.support |= MWAIT_EXTENSIONS;
2039 2061 if (MWAIT_INT_ENABLE(cpi))
2040 2062 cpi->cpi_mwait.support |=
2041 2063 MWAIT_ECX_INT_ENABLE;
2042 2064 }
2043 2065 break;
2044 2066 }
2045 2067 default:
2046 2068 break;
2047 2069 }
2048 2070 }
2049 2071
2050 2072 if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) {
2051 2073 struct cpuid_regs regs;
2052 2074
2053 2075 cp = ®s;
2054 2076 cp->cp_eax = 0xB;
2055 2077 cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0;
2056 2078
2057 2079 (void) __cpuid_insn(cp);
2058 2080
2059 2081 /*
2060 2082 * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which
2061 2083 * indicates that the extended topology enumeration leaf is
2062 2084 * available.
2063 2085 */
2064 2086 if (cp->cp_ebx) {
2065 2087 uint32_t x2apic_id;
2066 2088 uint_t coreid_shift = 0;
2067 2089 uint_t ncpu_per_core = 1;
2068 2090 uint_t chipid_shift = 0;
2069 2091 uint_t ncpu_per_chip = 1;
2070 2092 uint_t i;
2071 2093 uint_t level;
2072 2094
2073 2095 for (i = 0; i < CPI_FNB_ECX_MAX; i++) {
2074 2096 cp->cp_eax = 0xB;
2075 2097 cp->cp_ecx = i;
2076 2098
2077 2099 (void) __cpuid_insn(cp);
2078 2100 level = CPI_CPU_LEVEL_TYPE(cp);
2079 2101
2080 2102 if (level == 1) {
2081 2103 x2apic_id = cp->cp_edx;
2082 2104 coreid_shift = BITX(cp->cp_eax, 4, 0);
2083 2105 ncpu_per_core = BITX(cp->cp_ebx, 15, 0);
2084 2106 } else if (level == 2) {
2085 2107 x2apic_id = cp->cp_edx;
2086 2108 chipid_shift = BITX(cp->cp_eax, 4, 0);
2087 2109 ncpu_per_chip = BITX(cp->cp_ebx, 15, 0);
2088 2110 }
2089 2111 }
2090 2112
2091 2113 cpi->cpi_apicid = x2apic_id;
2092 2114 cpi->cpi_ncpu_per_chip = ncpu_per_chip;
2093 2115 cpi->cpi_ncore_per_chip = ncpu_per_chip /
2094 2116 ncpu_per_core;
2095 2117 cpi->cpi_chipid = x2apic_id >> chipid_shift;
2096 2118 cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1);
2097 2119 cpi->cpi_coreid = x2apic_id >> coreid_shift;
2098 2120 cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift;
2099 2121 }
2100 2122
2101 2123 /* Make cp NULL so that we don't stumble on others */
2102 2124 cp = NULL;
2103 2125 }
2104 2126
2105 2127 /*
2106 2128 * XSAVE enumeration
2107 2129 */
2108 2130 if (cpi->cpi_maxeax >= 0xD) {
2109 2131 struct cpuid_regs regs;
2110 2132 boolean_t cpuid_d_valid = B_TRUE;
2111 2133
2112 2134 cp = ®s;
2113 2135 cp->cp_eax = 0xD;
2114 2136 cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0;
2115 2137
2116 2138 (void) __cpuid_insn(cp);
2117 2139
2118 2140 /*
2119 2141 * Sanity checks for debug
2120 2142 */
2121 2143 if ((cp->cp_eax & XFEATURE_LEGACY_FP) == 0 ||
2122 2144 (cp->cp_eax & XFEATURE_SSE) == 0) {
2123 2145 cpuid_d_valid = B_FALSE;
2124 2146 }
2125 2147
2126 2148 cpi->cpi_xsave.xsav_hw_features_low = cp->cp_eax;
2127 2149 cpi->cpi_xsave.xsav_hw_features_high = cp->cp_edx;
2128 2150 cpi->cpi_xsave.xsav_max_size = cp->cp_ecx;
2129 2151
2130 2152 /*
2131 2153 * If the hw supports AVX, get the size and offset in the save
2132 2154 * area for the ymm state.
2133 2155 */
2134 2156 if (cpi->cpi_xsave.xsav_hw_features_low & XFEATURE_AVX) {
2135 2157 cp->cp_eax = 0xD;
2136 2158 cp->cp_ecx = 2;
2137 2159 cp->cp_edx = cp->cp_ebx = 0;
2138 2160
2139 2161 (void) __cpuid_insn(cp);
2140 2162
2141 2163 if (cp->cp_ebx != CPUID_LEAFD_2_YMM_OFFSET ||
2142 2164 cp->cp_eax != CPUID_LEAFD_2_YMM_SIZE) {
2143 2165 cpuid_d_valid = B_FALSE;
2144 2166 }
2145 2167
2146 2168 cpi->cpi_xsave.ymm_size = cp->cp_eax;
2147 2169 cpi->cpi_xsave.ymm_offset = cp->cp_ebx;
2148 2170 }
2149 2171
2150 2172 /*
2151 2173 * If the hw supports MPX, get the size and offset in the
2152 2174 * save area for BNDREGS and BNDCSR.
2153 2175 */
2154 2176 if (cpi->cpi_xsave.xsav_hw_features_low & XFEATURE_MPX) {
2155 2177 cp->cp_eax = 0xD;
2156 2178 cp->cp_ecx = 3;
2157 2179 cp->cp_edx = cp->cp_ebx = 0;
2158 2180
2159 2181 (void) __cpuid_insn(cp);
2160 2182
2161 2183 cpi->cpi_xsave.bndregs_size = cp->cp_eax;
2162 2184 cpi->cpi_xsave.bndregs_offset = cp->cp_ebx;
2163 2185
2164 2186 cp->cp_eax = 0xD;
2165 2187 cp->cp_ecx = 4;
2166 2188 cp->cp_edx = cp->cp_ebx = 0;
2167 2189
2168 2190 (void) __cpuid_insn(cp);
2169 2191
2170 2192 cpi->cpi_xsave.bndcsr_size = cp->cp_eax;
2171 2193 cpi->cpi_xsave.bndcsr_offset = cp->cp_ebx;
2172 2194 }
2173 2195
2174 2196 /*
2175 2197 * If the hw supports AVX512, get the size and offset in the
2176 2198 * save area for the opmask registers and zmm state.
2177 2199 */
2178 2200 if (cpi->cpi_xsave.xsav_hw_features_low & XFEATURE_AVX512) {
2179 2201 cp->cp_eax = 0xD;
2180 2202 cp->cp_ecx = 5;
2181 2203 cp->cp_edx = cp->cp_ebx = 0;
2182 2204
2183 2205 (void) __cpuid_insn(cp);
2184 2206
2185 2207 cpi->cpi_xsave.opmask_size = cp->cp_eax;
2186 2208 cpi->cpi_xsave.opmask_offset = cp->cp_ebx;
2187 2209
2188 2210 cp->cp_eax = 0xD;
2189 2211 cp->cp_ecx = 6;
2190 2212 cp->cp_edx = cp->cp_ebx = 0;
2191 2213
2192 2214 (void) __cpuid_insn(cp);
2193 2215
2194 2216 cpi->cpi_xsave.zmmlo_size = cp->cp_eax;
2195 2217 cpi->cpi_xsave.zmmlo_offset = cp->cp_ebx;
2196 2218
2197 2219 cp->cp_eax = 0xD;
2198 2220 cp->cp_ecx = 7;
2199 2221 cp->cp_edx = cp->cp_ebx = 0;
2200 2222
2201 2223 (void) __cpuid_insn(cp);
2202 2224
2203 2225 cpi->cpi_xsave.zmmhi_size = cp->cp_eax;
2204 2226 cpi->cpi_xsave.zmmhi_offset = cp->cp_ebx;
2205 2227 }
2206 2228
2207 2229 if (is_x86_feature(x86_featureset, X86FSET_XSAVE)) {
2208 2230 xsave_state_size = 0;
2209 2231 } else if (cpuid_d_valid) {
2210 2232 xsave_state_size = cpi->cpi_xsave.xsav_max_size;
2211 2233 } else {
2212 2234 /* Broken CPUID 0xD, probably in HVM */
2213 2235 cmn_err(CE_WARN, "cpu%d: CPUID.0xD returns invalid "
2214 2236 "value: hw_low = %d, hw_high = %d, xsave_size = %d"
2215 2237 ", ymm_size = %d, ymm_offset = %d\n",
2216 2238 cpu->cpu_id, cpi->cpi_xsave.xsav_hw_features_low,
2217 2239 cpi->cpi_xsave.xsav_hw_features_high,
2218 2240 (int)cpi->cpi_xsave.xsav_max_size,
2219 2241 (int)cpi->cpi_xsave.ymm_size,
2220 2242 (int)cpi->cpi_xsave.ymm_offset);
2221 2243
2222 2244 if (xsave_state_size != 0) {
2223 2245 /*
2224 2246 * This must be a non-boot CPU. We cannot
2225 2247 * continue, because boot cpu has already
2226 2248 * enabled XSAVE.
2227 2249 */
2228 2250 ASSERT(cpu->cpu_id != 0);
2229 2251 cmn_err(CE_PANIC, "cpu%d: we have already "
2230 2252 "enabled XSAVE on boot cpu, cannot "
2231 2253 "continue.", cpu->cpu_id);
2232 2254 } else {
2233 2255 /*
2234 2256 * If we reached here on the boot CPU, it's also
2235 2257 * almost certain that we'll reach here on the
2236 2258 * non-boot CPUs. When we're here on a boot CPU
2237 2259 * we should disable the feature, on a non-boot
2238 2260 * CPU we need to confirm that we have.
2239 2261 */
2240 2262 if (cpu->cpu_id == 0) {
2241 2263 remove_x86_feature(x86_featureset,
2242 2264 X86FSET_XSAVE);
2243 2265 remove_x86_feature(x86_featureset,
2244 2266 X86FSET_AVX);
2245 2267 remove_x86_feature(x86_featureset,
2246 2268 X86FSET_F16C);
2247 2269 remove_x86_feature(x86_featureset,
2248 2270 X86FSET_BMI1);
2249 2271 remove_x86_feature(x86_featureset,
2250 2272 X86FSET_BMI2);
2251 2273 remove_x86_feature(x86_featureset,
2252 2274 X86FSET_FMA);
2253 2275 remove_x86_feature(x86_featureset,
2254 2276 X86FSET_AVX2);
2255 2277 remove_x86_feature(x86_featureset,
2256 2278 X86FSET_MPX);
2257 2279 remove_x86_feature(x86_featureset,
2258 2280 X86FSET_AVX512F);
2259 2281 remove_x86_feature(x86_featureset,
2260 2282 X86FSET_AVX512DQ);
2261 2283 remove_x86_feature(x86_featureset,
2262 2284 X86FSET_AVX512PF);
2263 2285 remove_x86_feature(x86_featureset,
2264 2286 X86FSET_AVX512ER);
2265 2287 remove_x86_feature(x86_featureset,
2266 2288 X86FSET_AVX512CD);
2267 2289 remove_x86_feature(x86_featureset,
2268 2290 X86FSET_AVX512BW);
2269 2291 remove_x86_feature(x86_featureset,
2270 2292 X86FSET_AVX512VL);
2271 2293 remove_x86_feature(x86_featureset,
2272 2294 X86FSET_AVX512FMA);
2273 2295 remove_x86_feature(x86_featureset,
2274 2296 X86FSET_AVX512VBMI);
2275 2297 remove_x86_feature(x86_featureset,
2276 2298 X86FSET_AVX512VPOPCDQ);
2277 2299 remove_x86_feature(x86_featureset,
2278 2300 X86FSET_AVX512NNIW);
2279 2301 remove_x86_feature(x86_featureset,
2280 2302 X86FSET_AVX512FMAPS);
2281 2303
2282 2304 CPI_FEATURES_ECX(cpi) &=
2283 2305 ~CPUID_INTC_ECX_XSAVE;
2284 2306 CPI_FEATURES_ECX(cpi) &=
2285 2307 ~CPUID_INTC_ECX_AVX;
2286 2308 CPI_FEATURES_ECX(cpi) &=
2287 2309 ~CPUID_INTC_ECX_F16C;
2288 2310 CPI_FEATURES_ECX(cpi) &=
2289 2311 ~CPUID_INTC_ECX_FMA;
2290 2312 CPI_FEATURES_7_0_EBX(cpi) &=
2291 2313 ~CPUID_INTC_EBX_7_0_BMI1;
2292 2314 CPI_FEATURES_7_0_EBX(cpi) &=
2293 2315 ~CPUID_INTC_EBX_7_0_BMI2;
2294 2316 CPI_FEATURES_7_0_EBX(cpi) &=
2295 2317 ~CPUID_INTC_EBX_7_0_AVX2;
2296 2318 CPI_FEATURES_7_0_EBX(cpi) &=
2297 2319 ~CPUID_INTC_EBX_7_0_MPX;
2298 2320 CPI_FEATURES_7_0_EBX(cpi) &=
2299 2321 ~CPUID_INTC_EBX_7_0_ALL_AVX512;
2300 2322
2301 2323 CPI_FEATURES_7_0_ECX(cpi) &=
2302 2324 ~CPUID_INTC_ECX_7_0_ALL_AVX512;
2303 2325
2304 2326 CPI_FEATURES_7_0_EDX(cpi) &=
2305 2327 ~CPUID_INTC_EDX_7_0_ALL_AVX512;
2306 2328
2307 2329 xsave_force_disable = B_TRUE;
2308 2330 } else {
2309 2331 VERIFY(is_x86_feature(x86_featureset,
2310 2332 X86FSET_XSAVE) == B_FALSE);
2311 2333 }
2312 2334 }
2313 2335 }
2314 2336 }
2315 2337
2316 2338
2317 2339 if ((cpi->cpi_xmaxeax & 0x80000000) == 0)
2318 2340 goto pass2_done;
2319 2341
2320 2342 if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD)
2321 2343 nmax = NMAX_CPI_EXTD;
2322 2344 /*
2323 2345 * Copy the extended properties, fixing them as we go.
2324 2346 * (We already handled n == 0 and n == 1 in pass 1)
2325 2347 */
2326 2348 iptr = (void *)cpi->cpi_brandstr;
2327 2349 for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) {
2328 2350 cp->cp_eax = 0x80000000 + n;
2329 2351 (void) __cpuid_insn(cp);
2330 2352 platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp);
2331 2353 switch (n) {
2332 2354 case 2:
2333 2355 case 3:
2334 2356 case 4:
2335 2357 /*
2336 2358 * Extract the brand string
2337 2359 */
2338 2360 *iptr++ = cp->cp_eax;
2339 2361 *iptr++ = cp->cp_ebx;
2340 2362 *iptr++ = cp->cp_ecx;
2341 2363 *iptr++ = cp->cp_edx;
2342 2364 break;
2343 2365 case 5:
2344 2366 switch (cpi->cpi_vendor) {
2345 2367 case X86_VENDOR_AMD:
2346 2368 /*
2347 2369 * The Athlon and Duron were the first
2348 2370 * parts to report the sizes of the
2349 2371 * TLB for large pages. Before then,
2350 2372 * we don't trust the data.
2351 2373 */
2352 2374 if (cpi->cpi_family < 6 ||
2353 2375 (cpi->cpi_family == 6 &&
2354 2376 cpi->cpi_model < 1))
2355 2377 cp->cp_eax = 0;
2356 2378 break;
2357 2379 default:
2358 2380 break;
2359 2381 }
2360 2382 break;
2361 2383 case 6:
2362 2384 switch (cpi->cpi_vendor) {
2363 2385 case X86_VENDOR_AMD:
2364 2386 /*
2365 2387 * The Athlon and Duron were the first
2366 2388 * AMD parts with L2 TLB's.
2367 2389 * Before then, don't trust the data.
2368 2390 */
2369 2391 if (cpi->cpi_family < 6 ||
2370 2392 cpi->cpi_family == 6 &&
2371 2393 cpi->cpi_model < 1)
2372 2394 cp->cp_eax = cp->cp_ebx = 0;
2373 2395 /*
2374 2396 * AMD Duron rev A0 reports L2
2375 2397 * cache size incorrectly as 1K
2376 2398 * when it is really 64K
2377 2399 */
2378 2400 if (cpi->cpi_family == 6 &&
2379 2401 cpi->cpi_model == 3 &&
2380 2402 cpi->cpi_step == 0) {
2381 2403 cp->cp_ecx &= 0xffff;
2382 2404 cp->cp_ecx |= 0x400000;
2383 2405 }
2384 2406 break;
2385 2407 case X86_VENDOR_Cyrix: /* VIA C3 */
2386 2408 /*
2387 2409 * VIA C3 processors are a bit messed
2388 2410 * up w.r.t. encoding cache sizes in %ecx
2389 2411 */
2390 2412 if (cpi->cpi_family != 6)
2391 2413 break;
2392 2414 /*
2393 2415 * model 7 and 8 were incorrectly encoded
2394 2416 *
2395 2417 * xxx is model 8 really broken?
2396 2418 */
2397 2419 if (cpi->cpi_model == 7 ||
2398 2420 cpi->cpi_model == 8)
2399 2421 cp->cp_ecx =
2400 2422 BITX(cp->cp_ecx, 31, 24) << 16 |
2401 2423 BITX(cp->cp_ecx, 23, 16) << 12 |
2402 2424 BITX(cp->cp_ecx, 15, 8) << 8 |
2403 2425 BITX(cp->cp_ecx, 7, 0);
2404 2426 /*
2405 2427 * model 9 stepping 1 has wrong associativity
2406 2428 */
2407 2429 if (cpi->cpi_model == 9 && cpi->cpi_step == 1)
2408 2430 cp->cp_ecx |= 8 << 12;
2409 2431 break;
2410 2432 case X86_VENDOR_Intel:
2411 2433 /*
2412 2434 * Extended L2 Cache features function.
2413 2435 * First appeared on Prescott.
2414 2436 */
2415 2437 default:
2416 2438 break;
2417 2439 }
2418 2440 break;
2419 2441 default:
2420 2442 break;
2421 2443 }
2422 2444 }
2423 2445
2424 2446 pass2_done:
2425 2447 cpi->cpi_pass = 2;
2426 2448 }
2427 2449
2428 2450 static const char *
2429 2451 intel_cpubrand(const struct cpuid_info *cpi)
2430 2452 {
2431 2453 int i;
2432 2454
2433 2455 if (!is_x86_feature(x86_featureset, X86FSET_CPUID) ||
2434 2456 cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
2435 2457 return ("i486");
2436 2458
2437 2459 switch (cpi->cpi_family) {
2438 2460 case 5:
2439 2461 return ("Intel Pentium(r)");
2440 2462 case 6:
2441 2463 switch (cpi->cpi_model) {
2442 2464 uint_t celeron, xeon;
2443 2465 const struct cpuid_regs *cp;
2444 2466 case 0:
2445 2467 case 1:
2446 2468 case 2:
2447 2469 return ("Intel Pentium(r) Pro");
2448 2470 case 3:
2449 2471 case 4:
2450 2472 return ("Intel Pentium(r) II");
2451 2473 case 6:
2452 2474 return ("Intel Celeron(r)");
2453 2475 case 5:
2454 2476 case 7:
2455 2477 celeron = xeon = 0;
2456 2478 cp = &cpi->cpi_std[2]; /* cache info */
2457 2479
2458 2480 for (i = 1; i < 4; i++) {
2459 2481 uint_t tmp;
2460 2482
2461 2483 tmp = (cp->cp_eax >> (8 * i)) & 0xff;
2462 2484 if (tmp == 0x40)
2463 2485 celeron++;
2464 2486 if (tmp >= 0x44 && tmp <= 0x45)
2465 2487 xeon++;
2466 2488 }
2467 2489
2468 2490 for (i = 0; i < 2; i++) {
2469 2491 uint_t tmp;
2470 2492
2471 2493 tmp = (cp->cp_ebx >> (8 * i)) & 0xff;
2472 2494 if (tmp == 0x40)
2473 2495 celeron++;
2474 2496 else if (tmp >= 0x44 && tmp <= 0x45)
2475 2497 xeon++;
2476 2498 }
2477 2499
2478 2500 for (i = 0; i < 4; i++) {
2479 2501 uint_t tmp;
2480 2502
2481 2503 tmp = (cp->cp_ecx >> (8 * i)) & 0xff;
2482 2504 if (tmp == 0x40)
2483 2505 celeron++;
2484 2506 else if (tmp >= 0x44 && tmp <= 0x45)
2485 2507 xeon++;
2486 2508 }
2487 2509
2488 2510 for (i = 0; i < 4; i++) {
2489 2511 uint_t tmp;
2490 2512
2491 2513 tmp = (cp->cp_edx >> (8 * i)) & 0xff;
2492 2514 if (tmp == 0x40)
2493 2515 celeron++;
2494 2516 else if (tmp >= 0x44 && tmp <= 0x45)
2495 2517 xeon++;
2496 2518 }
2497 2519
2498 2520 if (celeron)
2499 2521 return ("Intel Celeron(r)");
2500 2522 if (xeon)
2501 2523 return (cpi->cpi_model == 5 ?
2502 2524 "Intel Pentium(r) II Xeon(tm)" :
2503 2525 "Intel Pentium(r) III Xeon(tm)");
2504 2526 return (cpi->cpi_model == 5 ?
2505 2527 "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" :
2506 2528 "Intel Pentium(r) III or Pentium(r) III Xeon(tm)");
2507 2529 default:
2508 2530 break;
2509 2531 }
2510 2532 default:
2511 2533 break;
2512 2534 }
2513 2535
2514 2536 /* BrandID is present if the field is nonzero */
2515 2537 if (cpi->cpi_brandid != 0) {
2516 2538 static const struct {
2517 2539 uint_t bt_bid;
2518 2540 const char *bt_str;
2519 2541 } brand_tbl[] = {
2520 2542 { 0x1, "Intel(r) Celeron(r)" },
2521 2543 { 0x2, "Intel(r) Pentium(r) III" },
2522 2544 { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" },
2523 2545 { 0x4, "Intel(r) Pentium(r) III" },
2524 2546 { 0x6, "Mobile Intel(r) Pentium(r) III" },
2525 2547 { 0x7, "Mobile Intel(r) Celeron(r)" },
2526 2548 { 0x8, "Intel(r) Pentium(r) 4" },
2527 2549 { 0x9, "Intel(r) Pentium(r) 4" },
2528 2550 { 0xa, "Intel(r) Celeron(r)" },
2529 2551 { 0xb, "Intel(r) Xeon(tm)" },
2530 2552 { 0xc, "Intel(r) Xeon(tm) MP" },
2531 2553 { 0xe, "Mobile Intel(r) Pentium(r) 4" },
2532 2554 { 0xf, "Mobile Intel(r) Celeron(r)" },
2533 2555 { 0x11, "Mobile Genuine Intel(r)" },
2534 2556 { 0x12, "Intel(r) Celeron(r) M" },
2535 2557 { 0x13, "Mobile Intel(r) Celeron(r)" },
2536 2558 { 0x14, "Intel(r) Celeron(r)" },
2537 2559 { 0x15, "Mobile Genuine Intel(r)" },
2538 2560 { 0x16, "Intel(r) Pentium(r) M" },
2539 2561 { 0x17, "Mobile Intel(r) Celeron(r)" }
2540 2562 };
2541 2563 uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]);
2542 2564 uint_t sgn;
2543 2565
2544 2566 sgn = (cpi->cpi_family << 8) |
2545 2567 (cpi->cpi_model << 4) | cpi->cpi_step;
2546 2568
2547 2569 for (i = 0; i < btblmax; i++)
2548 2570 if (brand_tbl[i].bt_bid == cpi->cpi_brandid)
2549 2571 break;
2550 2572 if (i < btblmax) {
2551 2573 if (sgn == 0x6b1 && cpi->cpi_brandid == 3)
2552 2574 return ("Intel(r) Celeron(r)");
2553 2575 if (sgn < 0xf13 && cpi->cpi_brandid == 0xb)
2554 2576 return ("Intel(r) Xeon(tm) MP");
2555 2577 if (sgn < 0xf13 && cpi->cpi_brandid == 0xe)
2556 2578 return ("Intel(r) Xeon(tm)");
2557 2579 return (brand_tbl[i].bt_str);
2558 2580 }
2559 2581 }
2560 2582
2561 2583 return (NULL);
2562 2584 }
2563 2585
2564 2586 static const char *
2565 2587 amd_cpubrand(const struct cpuid_info *cpi)
2566 2588 {
2567 2589 if (!is_x86_feature(x86_featureset, X86FSET_CPUID) ||
2568 2590 cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
2569 2591 return ("i486 compatible");
2570 2592
2571 2593 switch (cpi->cpi_family) {
2572 2594 case 5:
2573 2595 switch (cpi->cpi_model) {
2574 2596 case 0:
2575 2597 case 1:
2576 2598 case 2:
2577 2599 case 3:
2578 2600 case 4:
2579 2601 case 5:
2580 2602 return ("AMD-K5(r)");
2581 2603 case 6:
2582 2604 case 7:
2583 2605 return ("AMD-K6(r)");
2584 2606 case 8:
2585 2607 return ("AMD-K6(r)-2");
2586 2608 case 9:
2587 2609 return ("AMD-K6(r)-III");
2588 2610 default:
2589 2611 return ("AMD (family 5)");
2590 2612 }
2591 2613 case 6:
2592 2614 switch (cpi->cpi_model) {
2593 2615 case 1:
2594 2616 return ("AMD-K7(tm)");
2595 2617 case 0:
2596 2618 case 2:
2597 2619 case 4:
2598 2620 return ("AMD Athlon(tm)");
2599 2621 case 3:
2600 2622 case 7:
2601 2623 return ("AMD Duron(tm)");
2602 2624 case 6:
2603 2625 case 8:
2604 2626 case 10:
2605 2627 /*
2606 2628 * Use the L2 cache size to distinguish
2607 2629 */
2608 2630 return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ?
2609 2631 "AMD Athlon(tm)" : "AMD Duron(tm)");
2610 2632 default:
2611 2633 return ("AMD (family 6)");
2612 2634 }
2613 2635 default:
2614 2636 break;
2615 2637 }
2616 2638
2617 2639 if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 &&
2618 2640 cpi->cpi_brandid != 0) {
2619 2641 switch (BITX(cpi->cpi_brandid, 7, 5)) {
2620 2642 case 3:
2621 2643 return ("AMD Opteron(tm) UP 1xx");
2622 2644 case 4:
2623 2645 return ("AMD Opteron(tm) DP 2xx");
2624 2646 case 5:
2625 2647 return ("AMD Opteron(tm) MP 8xx");
2626 2648 default:
2627 2649 return ("AMD Opteron(tm)");
2628 2650 }
2629 2651 }
2630 2652
2631 2653 return (NULL);
2632 2654 }
2633 2655
2634 2656 static const char *
2635 2657 cyrix_cpubrand(struct cpuid_info *cpi, uint_t type)
2636 2658 {
2637 2659 if (!is_x86_feature(x86_featureset, X86FSET_CPUID) ||
2638 2660 cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 ||
2639 2661 type == X86_TYPE_CYRIX_486)
2640 2662 return ("i486 compatible");
2641 2663
2642 2664 switch (type) {
2643 2665 case X86_TYPE_CYRIX_6x86:
2644 2666 return ("Cyrix 6x86");
2645 2667 case X86_TYPE_CYRIX_6x86L:
2646 2668 return ("Cyrix 6x86L");
2647 2669 case X86_TYPE_CYRIX_6x86MX:
2648 2670 return ("Cyrix 6x86MX");
2649 2671 case X86_TYPE_CYRIX_GXm:
2650 2672 return ("Cyrix GXm");
2651 2673 case X86_TYPE_CYRIX_MediaGX:
2652 2674 return ("Cyrix MediaGX");
2653 2675 case X86_TYPE_CYRIX_MII:
2654 2676 return ("Cyrix M2");
2655 2677 case X86_TYPE_VIA_CYRIX_III:
2656 2678 return ("VIA Cyrix M3");
2657 2679 default:
2658 2680 /*
2659 2681 * Have another wild guess ..
2660 2682 */
2661 2683 if (cpi->cpi_family == 4 && cpi->cpi_model == 9)
2662 2684 return ("Cyrix 5x86");
2663 2685 else if (cpi->cpi_family == 5) {
2664 2686 switch (cpi->cpi_model) {
2665 2687 case 2:
2666 2688 return ("Cyrix 6x86"); /* Cyrix M1 */
2667 2689 case 4:
2668 2690 return ("Cyrix MediaGX");
2669 2691 default:
2670 2692 break;
2671 2693 }
2672 2694 } else if (cpi->cpi_family == 6) {
2673 2695 switch (cpi->cpi_model) {
2674 2696 case 0:
2675 2697 return ("Cyrix 6x86MX"); /* Cyrix M2? */
2676 2698 case 5:
2677 2699 case 6:
2678 2700 case 7:
2679 2701 case 8:
2680 2702 case 9:
2681 2703 return ("VIA C3");
2682 2704 default:
2683 2705 break;
2684 2706 }
2685 2707 }
2686 2708 break;
2687 2709 }
2688 2710 return (NULL);
2689 2711 }
2690 2712
2691 2713 /*
2692 2714 * This only gets called in the case that the CPU extended
2693 2715 * feature brand string (0x80000002, 0x80000003, 0x80000004)
2694 2716 * aren't available, or contain null bytes for some reason.
2695 2717 */
2696 2718 static void
2697 2719 fabricate_brandstr(struct cpuid_info *cpi)
2698 2720 {
2699 2721 const char *brand = NULL;
2700 2722
2701 2723 switch (cpi->cpi_vendor) {
2702 2724 case X86_VENDOR_Intel:
2703 2725 brand = intel_cpubrand(cpi);
2704 2726 break;
2705 2727 case X86_VENDOR_AMD:
2706 2728 brand = amd_cpubrand(cpi);
2707 2729 break;
2708 2730 case X86_VENDOR_Cyrix:
2709 2731 brand = cyrix_cpubrand(cpi, x86_type);
2710 2732 break;
2711 2733 case X86_VENDOR_NexGen:
2712 2734 if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
2713 2735 brand = "NexGen Nx586";
2714 2736 break;
2715 2737 case X86_VENDOR_Centaur:
2716 2738 if (cpi->cpi_family == 5)
2717 2739 switch (cpi->cpi_model) {
2718 2740 case 4:
2719 2741 brand = "Centaur C6";
2720 2742 break;
2721 2743 case 8:
2722 2744 brand = "Centaur C2";
2723 2745 break;
2724 2746 case 9:
2725 2747 brand = "Centaur C3";
2726 2748 break;
2727 2749 default:
2728 2750 break;
2729 2751 }
2730 2752 break;
2731 2753 case X86_VENDOR_Rise:
2732 2754 if (cpi->cpi_family == 5 &&
2733 2755 (cpi->cpi_model == 0 || cpi->cpi_model == 2))
2734 2756 brand = "Rise mP6";
2735 2757 break;
2736 2758 case X86_VENDOR_SiS:
2737 2759 if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
2738 2760 brand = "SiS 55x";
2739 2761 break;
2740 2762 case X86_VENDOR_TM:
2741 2763 if (cpi->cpi_family == 5 && cpi->cpi_model == 4)
2742 2764 brand = "Transmeta Crusoe TM3x00 or TM5x00";
2743 2765 break;
2744 2766 case X86_VENDOR_NSC:
2745 2767 case X86_VENDOR_UMC:
2746 2768 default:
2747 2769 break;
2748 2770 }
2749 2771 if (brand) {
2750 2772 (void) strcpy((char *)cpi->cpi_brandstr, brand);
2751 2773 return;
2752 2774 }
2753 2775
2754 2776 /*
2755 2777 * If all else fails ...
2756 2778 */
2757 2779 (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr),
2758 2780 "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family,
2759 2781 cpi->cpi_model, cpi->cpi_step);
2760 2782 }
2761 2783
2762 2784 /*
2763 2785 * This routine is called just after kernel memory allocation
2764 2786 * becomes available on cpu0, and as part of mp_startup() on
2765 2787 * the other cpus.
2766 2788 *
2767 2789 * Fixup the brand string, and collect any information from cpuid
2768 2790 * that requires dynamically allocated storage to represent.
2769 2791 */
2770 2792 /*ARGSUSED*/
2771 2793 void
2772 2794 cpuid_pass3(cpu_t *cpu)
2773 2795 {
2774 2796 int i, max, shft, level, size;
2775 2797 struct cpuid_regs regs;
2776 2798 struct cpuid_regs *cp;
2777 2799 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
2778 2800
2779 2801 ASSERT(cpi->cpi_pass == 2);
2780 2802
2781 2803 /*
2782 2804 * Function 4: Deterministic cache parameters
2783 2805 *
2784 2806 * Take this opportunity to detect the number of threads
2785 2807 * sharing the last level cache, and construct a corresponding
2786 2808 * cache id. The respective cpuid_info members are initialized
2787 2809 * to the default case of "no last level cache sharing".
2788 2810 */
2789 2811 cpi->cpi_ncpu_shr_last_cache = 1;
2790 2812 cpi->cpi_last_lvl_cacheid = cpu->cpu_id;
2791 2813
2792 2814 if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) {
2793 2815
2794 2816 /*
2795 2817 * Find the # of elements (size) returned by fn 4, and along
2796 2818 * the way detect last level cache sharing details.
2797 2819 */
2798 2820 bzero(®s, sizeof (regs));
2799 2821 cp = ®s;
2800 2822 for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) {
2801 2823 cp->cp_eax = 4;
2802 2824 cp->cp_ecx = i;
2803 2825
2804 2826 (void) __cpuid_insn(cp);
2805 2827
2806 2828 if (CPI_CACHE_TYPE(cp) == 0)
2807 2829 break;
2808 2830 level = CPI_CACHE_LVL(cp);
2809 2831 if (level > max) {
2810 2832 max = level;
2811 2833 cpi->cpi_ncpu_shr_last_cache =
2812 2834 CPI_NTHR_SHR_CACHE(cp) + 1;
2813 2835 }
2814 2836 }
2815 2837 cpi->cpi_std_4_size = size = i;
2816 2838
2817 2839 /*
2818 2840 * Allocate the cpi_std_4 array. The first element
2819 2841 * references the regs for fn 4, %ecx == 0, which
2820 2842 * cpuid_pass2() stashed in cpi->cpi_std[4].
2821 2843 */
2822 2844 if (size > 0) {
2823 2845 cpi->cpi_std_4 =
2824 2846 kmem_alloc(size * sizeof (cp), KM_SLEEP);
2825 2847 cpi->cpi_std_4[0] = &cpi->cpi_std[4];
2826 2848
2827 2849 /*
2828 2850 * Allocate storage to hold the additional regs
2829 2851 * for function 4, %ecx == 1 .. cpi_std_4_size.
2830 2852 *
2831 2853 * The regs for fn 4, %ecx == 0 has already
2832 2854 * been allocated as indicated above.
2833 2855 */
2834 2856 for (i = 1; i < size; i++) {
2835 2857 cp = cpi->cpi_std_4[i] =
2836 2858 kmem_zalloc(sizeof (regs), KM_SLEEP);
2837 2859 cp->cp_eax = 4;
2838 2860 cp->cp_ecx = i;
2839 2861
2840 2862 (void) __cpuid_insn(cp);
2841 2863 }
2842 2864 }
2843 2865 /*
2844 2866 * Determine the number of bits needed to represent
2845 2867 * the number of CPUs sharing the last level cache.
2846 2868 *
2847 2869 * Shift off that number of bits from the APIC id to
2848 2870 * derive the cache id.
2849 2871 */
2850 2872 shft = 0;
2851 2873 for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1)
2852 2874 shft++;
2853 2875 cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft;
2854 2876 }
2855 2877
2856 2878 /*
2857 2879 * Now fixup the brand string
2858 2880 */
2859 2881 if ((cpi->cpi_xmaxeax & 0x80000000) == 0) {
2860 2882 fabricate_brandstr(cpi);
2861 2883 } else {
2862 2884
2863 2885 /*
2864 2886 * If we successfully extracted a brand string from the cpuid
2865 2887 * instruction, clean it up by removing leading spaces and
2866 2888 * similar junk.
2867 2889 */
2868 2890 if (cpi->cpi_brandstr[0]) {
2869 2891 size_t maxlen = sizeof (cpi->cpi_brandstr);
2870 2892 char *src, *dst;
2871 2893
2872 2894 dst = src = (char *)cpi->cpi_brandstr;
2873 2895 src[maxlen - 1] = '\0';
2874 2896 /*
2875 2897 * strip leading spaces
2876 2898 */
2877 2899 while (*src == ' ')
2878 2900 src++;
2879 2901 /*
2880 2902 * Remove any 'Genuine' or "Authentic" prefixes
2881 2903 */
2882 2904 if (strncmp(src, "Genuine ", 8) == 0)
2883 2905 src += 8;
2884 2906 if (strncmp(src, "Authentic ", 10) == 0)
2885 2907 src += 10;
2886 2908
2887 2909 /*
2888 2910 * Now do an in-place copy.
2889 2911 * Map (R) to (r) and (TM) to (tm).
2890 2912 * The era of teletypes is long gone, and there's
2891 2913 * -really- no need to shout.
2892 2914 */
2893 2915 while (*src != '\0') {
2894 2916 if (src[0] == '(') {
2895 2917 if (strncmp(src + 1, "R)", 2) == 0) {
2896 2918 (void) strncpy(dst, "(r)", 3);
2897 2919 src += 3;
2898 2920 dst += 3;
2899 2921 continue;
2900 2922 }
2901 2923 if (strncmp(src + 1, "TM)", 3) == 0) {
2902 2924 (void) strncpy(dst, "(tm)", 4);
2903 2925 src += 4;
2904 2926 dst += 4;
2905 2927 continue;
2906 2928 }
2907 2929 }
2908 2930 *dst++ = *src++;
2909 2931 }
2910 2932 *dst = '\0';
2911 2933
2912 2934 /*
2913 2935 * Finally, remove any trailing spaces
2914 2936 */
2915 2937 while (--dst > cpi->cpi_brandstr)
2916 2938 if (*dst == ' ')
2917 2939 *dst = '\0';
2918 2940 else
2919 2941 break;
2920 2942 } else
2921 2943 fabricate_brandstr(cpi);
2922 2944 }
2923 2945 cpi->cpi_pass = 3;
2924 2946 }
2925 2947
2926 2948 /*
2927 2949 * This routine is called out of bind_hwcap() much later in the life
2928 2950 * of the kernel (post_startup()). The job of this routine is to resolve
2929 2951 * the hardware feature support and kernel support for those features into
2930 2952 * what we're actually going to tell applications via the aux vector.
2931 2953 */
2932 2954 void
2933 2955 cpuid_pass4(cpu_t *cpu, uint_t *hwcap_out)
2934 2956 {
2935 2957 struct cpuid_info *cpi;
2936 2958 uint_t hwcap_flags = 0, hwcap_flags_2 = 0;
2937 2959
2938 2960 if (cpu == NULL)
2939 2961 cpu = CPU;
2940 2962 cpi = cpu->cpu_m.mcpu_cpi;
2941 2963
2942 2964 ASSERT(cpi->cpi_pass == 3);
2943 2965
2944 2966 if (cpi->cpi_maxeax >= 1) {
2945 2967 uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES];
2946 2968 uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES];
2947 2969 uint32_t *ebx = &cpi->cpi_support[STD_EBX_FEATURES];
2948 2970
2949 2971 *edx = CPI_FEATURES_EDX(cpi);
2950 2972 *ecx = CPI_FEATURES_ECX(cpi);
2951 2973 *ebx = CPI_FEATURES_7_0_EBX(cpi);
2952 2974
2953 2975 /*
2954 2976 * [these require explicit kernel support]
2955 2977 */
2956 2978 if (!is_x86_feature(x86_featureset, X86FSET_SEP))
2957 2979 *edx &= ~CPUID_INTC_EDX_SEP;
2958 2980
2959 2981 if (!is_x86_feature(x86_featureset, X86FSET_SSE))
2960 2982 *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE);
2961 2983 if (!is_x86_feature(x86_featureset, X86FSET_SSE2))
2962 2984 *edx &= ~CPUID_INTC_EDX_SSE2;
2963 2985
2964 2986 if (!is_x86_feature(x86_featureset, X86FSET_HTT))
2965 2987 *edx &= ~CPUID_INTC_EDX_HTT;
2966 2988
2967 2989 if (!is_x86_feature(x86_featureset, X86FSET_SSE3))
2968 2990 *ecx &= ~CPUID_INTC_ECX_SSE3;
2969 2991
2970 2992 if (!is_x86_feature(x86_featureset, X86FSET_SSSE3))
2971 2993 *ecx &= ~CPUID_INTC_ECX_SSSE3;
2972 2994 if (!is_x86_feature(x86_featureset, X86FSET_SSE4_1))
2973 2995 *ecx &= ~CPUID_INTC_ECX_SSE4_1;
2974 2996 if (!is_x86_feature(x86_featureset, X86FSET_SSE4_2))
2975 2997 *ecx &= ~CPUID_INTC_ECX_SSE4_2;
2976 2998 if (!is_x86_feature(x86_featureset, X86FSET_AES))
2977 2999 *ecx &= ~CPUID_INTC_ECX_AES;
2978 3000 if (!is_x86_feature(x86_featureset, X86FSET_PCLMULQDQ))
2979 3001 *ecx &= ~CPUID_INTC_ECX_PCLMULQDQ;
2980 3002 if (!is_x86_feature(x86_featureset, X86FSET_XSAVE))
2981 3003 *ecx &= ~(CPUID_INTC_ECX_XSAVE |
2982 3004 CPUID_INTC_ECX_OSXSAVE);
2983 3005 if (!is_x86_feature(x86_featureset, X86FSET_AVX))
2984 3006 *ecx &= ~CPUID_INTC_ECX_AVX;
2985 3007 if (!is_x86_feature(x86_featureset, X86FSET_F16C))
2986 3008 *ecx &= ~CPUID_INTC_ECX_F16C;
2987 3009 if (!is_x86_feature(x86_featureset, X86FSET_FMA))
2988 3010 *ecx &= ~CPUID_INTC_ECX_FMA;
2989 3011 if (!is_x86_feature(x86_featureset, X86FSET_BMI1))
2990 3012 *ebx &= ~CPUID_INTC_EBX_7_0_BMI1;
2991 3013 if (!is_x86_feature(x86_featureset, X86FSET_BMI2))
2992 3014 *ebx &= ~CPUID_INTC_EBX_7_0_BMI2;
2993 3015 if (!is_x86_feature(x86_featureset, X86FSET_AVX2))
2994 3016 *ebx &= ~CPUID_INTC_EBX_7_0_AVX2;
2995 3017 if (!is_x86_feature(x86_featureset, X86FSET_RDSEED))
2996 3018 *ebx &= ~CPUID_INTC_EBX_7_0_RDSEED;
2997 3019 if (!is_x86_feature(x86_featureset, X86FSET_ADX))
2998 3020 *ebx &= ~CPUID_INTC_EBX_7_0_ADX;
2999 3021
3000 3022 /*
3001 3023 * [no explicit support required beyond x87 fp context]
3002 3024 */
3003 3025 if (!fpu_exists)
3004 3026 *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX);
3005 3027
3006 3028 /*
3007 3029 * Now map the supported feature vector to things that we
3008 3030 * think userland will care about.
3009 3031 */
3010 3032 if (*edx & CPUID_INTC_EDX_SEP)
3011 3033 hwcap_flags |= AV_386_SEP;
3012 3034 if (*edx & CPUID_INTC_EDX_SSE)
3013 3035 hwcap_flags |= AV_386_FXSR | AV_386_SSE;
3014 3036 if (*edx & CPUID_INTC_EDX_SSE2)
3015 3037 hwcap_flags |= AV_386_SSE2;
3016 3038 if (*ecx & CPUID_INTC_ECX_SSE3)
3017 3039 hwcap_flags |= AV_386_SSE3;
3018 3040 if (*ecx & CPUID_INTC_ECX_SSSE3)
3019 3041 hwcap_flags |= AV_386_SSSE3;
3020 3042 if (*ecx & CPUID_INTC_ECX_SSE4_1)
3021 3043 hwcap_flags |= AV_386_SSE4_1;
3022 3044 if (*ecx & CPUID_INTC_ECX_SSE4_2)
3023 3045 hwcap_flags |= AV_386_SSE4_2;
3024 3046 if (*ecx & CPUID_INTC_ECX_MOVBE)
3025 3047 hwcap_flags |= AV_386_MOVBE;
3026 3048 if (*ecx & CPUID_INTC_ECX_AES)
3027 3049 hwcap_flags |= AV_386_AES;
3028 3050 if (*ecx & CPUID_INTC_ECX_PCLMULQDQ)
3029 3051 hwcap_flags |= AV_386_PCLMULQDQ;
3030 3052 if ((*ecx & CPUID_INTC_ECX_XSAVE) &&
3031 3053 (*ecx & CPUID_INTC_ECX_OSXSAVE)) {
3032 3054 hwcap_flags |= AV_386_XSAVE;
3033 3055
3034 3056 if (*ecx & CPUID_INTC_ECX_AVX) {
3035 3057 uint32_t *ecx_7 = &CPI_FEATURES_7_0_ECX(cpi);
3036 3058 uint32_t *edx_7 = &CPI_FEATURES_7_0_EDX(cpi);
3037 3059
3038 3060 hwcap_flags |= AV_386_AVX;
3039 3061 if (*ecx & CPUID_INTC_ECX_F16C)
3040 3062 hwcap_flags_2 |= AV_386_2_F16C;
3041 3063 if (*ecx & CPUID_INTC_ECX_FMA)
3042 3064 hwcap_flags_2 |= AV_386_2_FMA;
3043 3065
3044 3066 if (*ebx & CPUID_INTC_EBX_7_0_BMI1)
3045 3067 hwcap_flags_2 |= AV_386_2_BMI1;
3046 3068 if (*ebx & CPUID_INTC_EBX_7_0_BMI2)
3047 3069 hwcap_flags_2 |= AV_386_2_BMI2;
3048 3070 if (*ebx & CPUID_INTC_EBX_7_0_AVX2)
3049 3071 hwcap_flags_2 |= AV_386_2_AVX2;
3050 3072 if (*ebx & CPUID_INTC_EBX_7_0_AVX512F)
3051 3073 hwcap_flags_2 |= AV_386_2_AVX512F;
3052 3074 if (*ebx & CPUID_INTC_EBX_7_0_AVX512DQ)
3053 3075 hwcap_flags_2 |= AV_386_2_AVX512DQ;
3054 3076 if (*ebx & CPUID_INTC_EBX_7_0_AVX512IFMA)
3055 3077 hwcap_flags_2 |= AV_386_2_AVX512IFMA;
3056 3078 if (*ebx & CPUID_INTC_EBX_7_0_AVX512PF)
3057 3079 hwcap_flags_2 |= AV_386_2_AVX512PF;
3058 3080 if (*ebx & CPUID_INTC_EBX_7_0_AVX512ER)
3059 3081 hwcap_flags_2 |= AV_386_2_AVX512ER;
3060 3082 if (*ebx & CPUID_INTC_EBX_7_0_AVX512CD)
3061 3083 hwcap_flags_2 |= AV_386_2_AVX512CD;
3062 3084 if (*ebx & CPUID_INTC_EBX_7_0_AVX512BW)
3063 3085 hwcap_flags_2 |= AV_386_2_AVX512BW;
3064 3086 if (*ebx & CPUID_INTC_EBX_7_0_AVX512VL)
3065 3087 hwcap_flags_2 |= AV_386_2_AVX512VL;
3066 3088
3067 3089 if (*ecx_7 & CPUID_INTC_ECX_7_0_AVX512VBMI)
3068 3090 hwcap_flags_2 |= AV_386_2_AVX512VBMI;
3069 3091 if (*ecx_7 & CPUID_INTC_ECX_7_0_AVX512VPOPCDQ)
3070 3092 hwcap_flags_2 |= AV_386_2_AVX512VPOPCDQ;
3071 3093
3072 3094 if (*edx_7 & CPUID_INTC_EDX_7_0_AVX5124NNIW)
3073 3095 hwcap_flags_2 |= AV_386_2_AVX512_4NNIW;
3074 3096 if (*edx_7 & CPUID_INTC_EDX_7_0_AVX5124FMAPS)
3075 3097 hwcap_flags_2 |= AV_386_2_AVX512_4FMAPS;
3076 3098 }
3077 3099 }
3078 3100 if (*ecx & CPUID_INTC_ECX_VMX)
3079 3101 hwcap_flags |= AV_386_VMX;
3080 3102 if (*ecx & CPUID_INTC_ECX_POPCNT)
3081 3103 hwcap_flags |= AV_386_POPCNT;
3082 3104 if (*edx & CPUID_INTC_EDX_FPU)
3083 3105 hwcap_flags |= AV_386_FPU;
3084 3106 if (*edx & CPUID_INTC_EDX_MMX)
3085 3107 hwcap_flags |= AV_386_MMX;
3086 3108
3087 3109 if (*edx & CPUID_INTC_EDX_TSC)
3088 3110 hwcap_flags |= AV_386_TSC;
3089 3111 if (*edx & CPUID_INTC_EDX_CX8)
3090 3112 hwcap_flags |= AV_386_CX8;
3091 3113 if (*edx & CPUID_INTC_EDX_CMOV)
3092 3114 hwcap_flags |= AV_386_CMOV;
3093 3115 if (*ecx & CPUID_INTC_ECX_CX16)
3094 3116 hwcap_flags |= AV_386_CX16;
3095 3117
3096 3118 if (*ecx & CPUID_INTC_ECX_RDRAND)
3097 3119 hwcap_flags_2 |= AV_386_2_RDRAND;
3098 3120 if (*ebx & CPUID_INTC_EBX_7_0_ADX)
3099 3121 hwcap_flags_2 |= AV_386_2_ADX;
3100 3122 if (*ebx & CPUID_INTC_EBX_7_0_RDSEED)
3101 3123 hwcap_flags_2 |= AV_386_2_RDSEED;
3102 3124
3103 3125 }
3104 3126
3105 3127 if (cpi->cpi_xmaxeax < 0x80000001)
3106 3128 goto pass4_done;
3107 3129
3108 3130 switch (cpi->cpi_vendor) {
3109 3131 struct cpuid_regs cp;
3110 3132 uint32_t *edx, *ecx;
3111 3133
3112 3134 case X86_VENDOR_Intel:
3113 3135 /*
3114 3136 * Seems like Intel duplicated what we necessary
3115 3137 * here to make the initial crop of 64-bit OS's work.
3116 3138 * Hopefully, those are the only "extended" bits
3117 3139 * they'll add.
3118 3140 */
3119 3141 /*FALLTHROUGH*/
3120 3142
3121 3143 case X86_VENDOR_AMD:
3122 3144 edx = &cpi->cpi_support[AMD_EDX_FEATURES];
3123 3145 ecx = &cpi->cpi_support[AMD_ECX_FEATURES];
3124 3146
3125 3147 *edx = CPI_FEATURES_XTD_EDX(cpi);
3126 3148 *ecx = CPI_FEATURES_XTD_ECX(cpi);
3127 3149
3128 3150 /*
3129 3151 * [these features require explicit kernel support]
3130 3152 */
3131 3153 switch (cpi->cpi_vendor) {
3132 3154 case X86_VENDOR_Intel:
3133 3155 if (!is_x86_feature(x86_featureset, X86FSET_TSCP))
3134 3156 *edx &= ~CPUID_AMD_EDX_TSCP;
3135 3157 break;
3136 3158
3137 3159 case X86_VENDOR_AMD:
3138 3160 if (!is_x86_feature(x86_featureset, X86FSET_TSCP))
3139 3161 *edx &= ~CPUID_AMD_EDX_TSCP;
3140 3162 if (!is_x86_feature(x86_featureset, X86FSET_SSE4A))
3141 3163 *ecx &= ~CPUID_AMD_ECX_SSE4A;
3142 3164 break;
3143 3165
3144 3166 default:
3145 3167 break;
3146 3168 }
3147 3169
3148 3170 /*
3149 3171 * [no explicit support required beyond
3150 3172 * x87 fp context and exception handlers]
3151 3173 */
3152 3174 if (!fpu_exists)
3153 3175 *edx &= ~(CPUID_AMD_EDX_MMXamd |
3154 3176 CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx);
3155 3177
3156 3178 if (!is_x86_feature(x86_featureset, X86FSET_NX))
3157 3179 *edx &= ~CPUID_AMD_EDX_NX;
3158 3180 #if !defined(__amd64)
3159 3181 *edx &= ~CPUID_AMD_EDX_LM;
3160 3182 #endif
3161 3183 /*
3162 3184 * Now map the supported feature vector to
3163 3185 * things that we think userland will care about.
3164 3186 */
3165 3187 #if defined(__amd64)
3166 3188 if (*edx & CPUID_AMD_EDX_SYSC)
3167 3189 hwcap_flags |= AV_386_AMD_SYSC;
3168 3190 #endif
3169 3191 if (*edx & CPUID_AMD_EDX_MMXamd)
3170 3192 hwcap_flags |= AV_386_AMD_MMX;
3171 3193 if (*edx & CPUID_AMD_EDX_3DNow)
3172 3194 hwcap_flags |= AV_386_AMD_3DNow;
3173 3195 if (*edx & CPUID_AMD_EDX_3DNowx)
3174 3196 hwcap_flags |= AV_386_AMD_3DNowx;
3175 3197 if (*ecx & CPUID_AMD_ECX_SVM)
3176 3198 hwcap_flags |= AV_386_AMD_SVM;
3177 3199
3178 3200 switch (cpi->cpi_vendor) {
3179 3201 case X86_VENDOR_AMD:
3180 3202 if (*edx & CPUID_AMD_EDX_TSCP)
3181 3203 hwcap_flags |= AV_386_TSCP;
3182 3204 if (*ecx & CPUID_AMD_ECX_AHF64)
3183 3205 hwcap_flags |= AV_386_AHF;
3184 3206 if (*ecx & CPUID_AMD_ECX_SSE4A)
3185 3207 hwcap_flags |= AV_386_AMD_SSE4A;
3186 3208 if (*ecx & CPUID_AMD_ECX_LZCNT)
3187 3209 hwcap_flags |= AV_386_AMD_LZCNT;
3188 3210 break;
3189 3211
3190 3212 case X86_VENDOR_Intel:
3191 3213 if (*edx & CPUID_AMD_EDX_TSCP)
3192 3214 hwcap_flags |= AV_386_TSCP;
3193 3215 /*
3194 3216 * Aarrgh.
3195 3217 * Intel uses a different bit in the same word.
3196 3218 */
3197 3219 if (*ecx & CPUID_INTC_ECX_AHF64)
3198 3220 hwcap_flags |= AV_386_AHF;
3199 3221 break;
3200 3222
3201 3223 default:
3202 3224 break;
3203 3225 }
3204 3226 break;
3205 3227
3206 3228 case X86_VENDOR_TM:
3207 3229 cp.cp_eax = 0x80860001;
3208 3230 (void) __cpuid_insn(&cp);
3209 3231 cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx;
3210 3232 break;
3211 3233
3212 3234 default:
3213 3235 break;
3214 3236 }
3215 3237
3216 3238 pass4_done:
3217 3239 cpi->cpi_pass = 4;
3218 3240 if (hwcap_out != NULL) {
3219 3241 hwcap_out[0] = hwcap_flags;
3220 3242 hwcap_out[1] = hwcap_flags_2;
3221 3243 }
3222 3244 }
3223 3245
3224 3246
3225 3247 /*
3226 3248 * Simulate the cpuid instruction using the data we previously
3227 3249 * captured about this CPU. We try our best to return the truth
3228 3250 * about the hardware, independently of kernel support.
3229 3251 */
3230 3252 uint32_t
3231 3253 cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp)
3232 3254 {
3233 3255 struct cpuid_info *cpi;
3234 3256 struct cpuid_regs *xcp;
3235 3257
3236 3258 if (cpu == NULL)
3237 3259 cpu = CPU;
3238 3260 cpi = cpu->cpu_m.mcpu_cpi;
3239 3261
3240 3262 ASSERT(cpuid_checkpass(cpu, 3));
3241 3263
3242 3264 /*
3243 3265 * CPUID data is cached in two separate places: cpi_std for standard
3244 3266 * CPUID functions, and cpi_extd for extended CPUID functions.
3245 3267 */
3246 3268 if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD)
3247 3269 xcp = &cpi->cpi_std[cp->cp_eax];
3248 3270 else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax &&
3249 3271 cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD)
3250 3272 xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000];
3251 3273 else
3252 3274 /*
3253 3275 * The caller is asking for data from an input parameter which
3254 3276 * the kernel has not cached. In this case we go fetch from
3255 3277 * the hardware and return the data directly to the user.
3256 3278 */
3257 3279 return (__cpuid_insn(cp));
3258 3280
3259 3281 cp->cp_eax = xcp->cp_eax;
3260 3282 cp->cp_ebx = xcp->cp_ebx;
3261 3283 cp->cp_ecx = xcp->cp_ecx;
3262 3284 cp->cp_edx = xcp->cp_edx;
3263 3285 return (cp->cp_eax);
3264 3286 }
3265 3287
3266 3288 int
3267 3289 cpuid_checkpass(cpu_t *cpu, int pass)
3268 3290 {
3269 3291 return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL &&
3270 3292 cpu->cpu_m.mcpu_cpi->cpi_pass >= pass);
3271 3293 }
3272 3294
3273 3295 int
3274 3296 cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n)
3275 3297 {
3276 3298 ASSERT(cpuid_checkpass(cpu, 3));
3277 3299
3278 3300 return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr));
3279 3301 }
3280 3302
3281 3303 int
3282 3304 cpuid_is_cmt(cpu_t *cpu)
3283 3305 {
3284 3306 if (cpu == NULL)
3285 3307 cpu = CPU;
3286 3308
3287 3309 ASSERT(cpuid_checkpass(cpu, 1));
3288 3310
3289 3311 return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0);
3290 3312 }
3291 3313
3292 3314 /*
3293 3315 * AMD and Intel both implement the 64-bit variant of the syscall
3294 3316 * instruction (syscallq), so if there's -any- support for syscall,
3295 3317 * cpuid currently says "yes, we support this".
3296 3318 *
3297 3319 * However, Intel decided to -not- implement the 32-bit variant of the
3298 3320 * syscall instruction, so we provide a predicate to allow our caller
3299 3321 * to test that subtlety here.
3300 3322 *
3301 3323 * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor,
3302 3324 * even in the case where the hardware would in fact support it.
3303 3325 */
3304 3326 /*ARGSUSED*/
3305 3327 int
3306 3328 cpuid_syscall32_insn(cpu_t *cpu)
3307 3329 {
3308 3330 ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1));
3309 3331
3310 3332 #if !defined(__xpv)
3311 3333 if (cpu == NULL)
3312 3334 cpu = CPU;
3313 3335
3314 3336 /*CSTYLED*/
3315 3337 {
3316 3338 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
3317 3339
3318 3340 if (cpi->cpi_vendor == X86_VENDOR_AMD &&
3319 3341 cpi->cpi_xmaxeax >= 0x80000001 &&
3320 3342 (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC))
3321 3343 return (1);
3322 3344 }
3323 3345 #endif
3324 3346 return (0);
3325 3347 }
3326 3348
3327 3349 int
3328 3350 cpuid_getidstr(cpu_t *cpu, char *s, size_t n)
3329 3351 {
3330 3352 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
3331 3353
3332 3354 static const char fmt[] =
3333 3355 "x86 (%s %X family %d model %d step %d clock %d MHz)";
3334 3356 static const char fmt_ht[] =
3335 3357 "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)";
3336 3358
3337 3359 ASSERT(cpuid_checkpass(cpu, 1));
3338 3360
3339 3361 if (cpuid_is_cmt(cpu))
3340 3362 return (snprintf(s, n, fmt_ht, cpi->cpi_chipid,
3341 3363 cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax,
3342 3364 cpi->cpi_family, cpi->cpi_model,
3343 3365 cpi->cpi_step, cpu->cpu_type_info.pi_clock));
3344 3366 return (snprintf(s, n, fmt,
3345 3367 cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax,
3346 3368 cpi->cpi_family, cpi->cpi_model,
3347 3369 cpi->cpi_step, cpu->cpu_type_info.pi_clock));
3348 3370 }
3349 3371
3350 3372 const char *
3351 3373 cpuid_getvendorstr(cpu_t *cpu)
3352 3374 {
3353 3375 ASSERT(cpuid_checkpass(cpu, 1));
3354 3376 return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr);
3355 3377 }
3356 3378
3357 3379 uint_t
3358 3380 cpuid_getvendor(cpu_t *cpu)
3359 3381 {
3360 3382 ASSERT(cpuid_checkpass(cpu, 1));
3361 3383 return (cpu->cpu_m.mcpu_cpi->cpi_vendor);
3362 3384 }
3363 3385
3364 3386 uint_t
3365 3387 cpuid_getfamily(cpu_t *cpu)
3366 3388 {
3367 3389 ASSERT(cpuid_checkpass(cpu, 1));
3368 3390 return (cpu->cpu_m.mcpu_cpi->cpi_family);
3369 3391 }
3370 3392
3371 3393 uint_t
3372 3394 cpuid_getmodel(cpu_t *cpu)
3373 3395 {
3374 3396 ASSERT(cpuid_checkpass(cpu, 1));
3375 3397 return (cpu->cpu_m.mcpu_cpi->cpi_model);
3376 3398 }
3377 3399
3378 3400 uint_t
3379 3401 cpuid_get_ncpu_per_chip(cpu_t *cpu)
3380 3402 {
3381 3403 ASSERT(cpuid_checkpass(cpu, 1));
3382 3404 return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip);
3383 3405 }
3384 3406
3385 3407 uint_t
3386 3408 cpuid_get_ncore_per_chip(cpu_t *cpu)
3387 3409 {
3388 3410 ASSERT(cpuid_checkpass(cpu, 1));
3389 3411 return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip);
3390 3412 }
3391 3413
3392 3414 uint_t
3393 3415 cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu)
3394 3416 {
3395 3417 ASSERT(cpuid_checkpass(cpu, 2));
3396 3418 return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache);
3397 3419 }
3398 3420
3399 3421 id_t
3400 3422 cpuid_get_last_lvl_cacheid(cpu_t *cpu)
3401 3423 {
3402 3424 ASSERT(cpuid_checkpass(cpu, 2));
3403 3425 return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid);
3404 3426 }
3405 3427
3406 3428 uint_t
3407 3429 cpuid_getstep(cpu_t *cpu)
3408 3430 {
3409 3431 ASSERT(cpuid_checkpass(cpu, 1));
3410 3432 return (cpu->cpu_m.mcpu_cpi->cpi_step);
3411 3433 }
3412 3434
3413 3435 uint_t
3414 3436 cpuid_getsig(struct cpu *cpu)
3415 3437 {
3416 3438 ASSERT(cpuid_checkpass(cpu, 1));
3417 3439 return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax);
3418 3440 }
3419 3441
3420 3442 uint32_t
3421 3443 cpuid_getchiprev(struct cpu *cpu)
3422 3444 {
3423 3445 ASSERT(cpuid_checkpass(cpu, 1));
3424 3446 return (cpu->cpu_m.mcpu_cpi->cpi_chiprev);
3425 3447 }
3426 3448
3427 3449 const char *
3428 3450 cpuid_getchiprevstr(struct cpu *cpu)
3429 3451 {
3430 3452 ASSERT(cpuid_checkpass(cpu, 1));
3431 3453 return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr);
3432 3454 }
3433 3455
3434 3456 uint32_t
3435 3457 cpuid_getsockettype(struct cpu *cpu)
3436 3458 {
3437 3459 ASSERT(cpuid_checkpass(cpu, 1));
3438 3460 return (cpu->cpu_m.mcpu_cpi->cpi_socket);
3439 3461 }
3440 3462
3441 3463 const char *
3442 3464 cpuid_getsocketstr(cpu_t *cpu)
3443 3465 {
3444 3466 static const char *socketstr = NULL;
3445 3467 struct cpuid_info *cpi;
3446 3468
3447 3469 ASSERT(cpuid_checkpass(cpu, 1));
3448 3470 cpi = cpu->cpu_m.mcpu_cpi;
3449 3471
3450 3472 /* Assume that socket types are the same across the system */
3451 3473 if (socketstr == NULL)
3452 3474 socketstr = _cpuid_sktstr(cpi->cpi_vendor, cpi->cpi_family,
3453 3475 cpi->cpi_model, cpi->cpi_step);
3454 3476
3455 3477
3456 3478 return (socketstr);
3457 3479 }
3458 3480
3459 3481 int
3460 3482 cpuid_get_chipid(cpu_t *cpu)
3461 3483 {
3462 3484 ASSERT(cpuid_checkpass(cpu, 1));
3463 3485
3464 3486 if (cpuid_is_cmt(cpu))
3465 3487 return (cpu->cpu_m.mcpu_cpi->cpi_chipid);
3466 3488 return (cpu->cpu_id);
3467 3489 }
3468 3490
3469 3491 id_t
3470 3492 cpuid_get_coreid(cpu_t *cpu)
3471 3493 {
3472 3494 ASSERT(cpuid_checkpass(cpu, 1));
3473 3495 return (cpu->cpu_m.mcpu_cpi->cpi_coreid);
3474 3496 }
3475 3497
3476 3498 int
3477 3499 cpuid_get_pkgcoreid(cpu_t *cpu)
3478 3500 {
3479 3501 ASSERT(cpuid_checkpass(cpu, 1));
3480 3502 return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid);
3481 3503 }
3482 3504
3483 3505 int
3484 3506 cpuid_get_clogid(cpu_t *cpu)
3485 3507 {
3486 3508 ASSERT(cpuid_checkpass(cpu, 1));
3487 3509 return (cpu->cpu_m.mcpu_cpi->cpi_clogid);
3488 3510 }
3489 3511
3490 3512 int
3491 3513 cpuid_get_cacheid(cpu_t *cpu)
3492 3514 {
3493 3515 ASSERT(cpuid_checkpass(cpu, 1));
3494 3516 return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid);
3495 3517 }
3496 3518
3497 3519 uint_t
3498 3520 cpuid_get_procnodeid(cpu_t *cpu)
3499 3521 {
3500 3522 ASSERT(cpuid_checkpass(cpu, 1));
3501 3523 return (cpu->cpu_m.mcpu_cpi->cpi_procnodeid);
3502 3524 }
3503 3525
3504 3526 uint_t
3505 3527 cpuid_get_procnodes_per_pkg(cpu_t *cpu)
3506 3528 {
3507 3529 ASSERT(cpuid_checkpass(cpu, 1));
3508 3530 return (cpu->cpu_m.mcpu_cpi->cpi_procnodes_per_pkg);
3509 3531 }
3510 3532
3511 3533 uint_t
3512 3534 cpuid_get_compunitid(cpu_t *cpu)
3513 3535 {
3514 3536 ASSERT(cpuid_checkpass(cpu, 1));
3515 3537 return (cpu->cpu_m.mcpu_cpi->cpi_compunitid);
3516 3538 }
3517 3539
3518 3540 uint_t
3519 3541 cpuid_get_cores_per_compunit(cpu_t *cpu)
3520 3542 {
3521 3543 ASSERT(cpuid_checkpass(cpu, 1));
3522 3544 return (cpu->cpu_m.mcpu_cpi->cpi_cores_per_compunit);
3523 3545 }
3524 3546
3525 3547 /*ARGSUSED*/
3526 3548 int
3527 3549 cpuid_have_cr8access(cpu_t *cpu)
3528 3550 {
3529 3551 #if defined(__amd64)
3530 3552 return (1);
3531 3553 #else
3532 3554 struct cpuid_info *cpi;
3533 3555
3534 3556 ASSERT(cpu != NULL);
3535 3557 cpi = cpu->cpu_m.mcpu_cpi;
3536 3558 if (cpi->cpi_vendor == X86_VENDOR_AMD && cpi->cpi_maxeax >= 1 &&
3537 3559 (CPI_FEATURES_XTD_ECX(cpi) & CPUID_AMD_ECX_CR8D) != 0)
3538 3560 return (1);
3539 3561 return (0);
3540 3562 #endif
3541 3563 }
3542 3564
3543 3565 uint32_t
3544 3566 cpuid_get_apicid(cpu_t *cpu)
3545 3567 {
3546 3568 ASSERT(cpuid_checkpass(cpu, 1));
3547 3569 if (cpu->cpu_m.mcpu_cpi->cpi_maxeax < 1) {
3548 3570 return (UINT32_MAX);
3549 3571 } else {
3550 3572 return (cpu->cpu_m.mcpu_cpi->cpi_apicid);
3551 3573 }
3552 3574 }
3553 3575
3554 3576 void
3555 3577 cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits)
3556 3578 {
3557 3579 struct cpuid_info *cpi;
3558 3580
3559 3581 if (cpu == NULL)
3560 3582 cpu = CPU;
3561 3583 cpi = cpu->cpu_m.mcpu_cpi;
3562 3584
3563 3585 ASSERT(cpuid_checkpass(cpu, 1));
3564 3586
3565 3587 if (pabits)
3566 3588 *pabits = cpi->cpi_pabits;
3567 3589 if (vabits)
3568 3590 *vabits = cpi->cpi_vabits;
3569 3591 }
3570 3592
3571 3593 size_t
3572 3594 cpuid_get_xsave_size()
3573 3595 {
3574 3596 return (MAX(cpuid_info0.cpi_xsave.xsav_max_size,
3575 3597 sizeof (struct xsave_state)));
3576 3598 }
3577 3599
3578 3600 /*
3579 3601 * Return true if the CPUs on this system require 'pointer clearing' for the
3580 3602 * floating point error pointer exception handling. In the past, this has been
3581 3603 * true for all AMD K7 & K8 CPUs, although newer AMD CPUs have been changed to
3582 3604 * behave the same as Intel. This is checked via the CPUID_AMD_EBX_ERR_PTR_ZERO
3583 3605 * feature bit and is reflected in the cpi_fp_amd_save member. Once this has
3584 3606 * been confirmed on hardware which supports that feature, this test should be
3585 3607 * narrowed. In the meantime, we always follow the existing behavior on any AMD
3586 3608 * CPU.
3587 3609 */
3588 3610 boolean_t
3589 3611 cpuid_need_fp_excp_handling()
3590 3612 {
3591 3613 return (cpuid_info0.cpi_vendor == X86_VENDOR_AMD);
3592 3614 }
3593 3615
3594 3616 /*
3595 3617 * Returns the number of data TLB entries for a corresponding
3596 3618 * pagesize. If it can't be computed, or isn't known, the
3597 3619 * routine returns zero. If you ask about an architecturally
3598 3620 * impossible pagesize, the routine will panic (so that the
3599 3621 * hat implementor knows that things are inconsistent.)
3600 3622 */
3601 3623 uint_t
3602 3624 cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize)
3603 3625 {
3604 3626 struct cpuid_info *cpi;
3605 3627 uint_t dtlb_nent = 0;
3606 3628
3607 3629 if (cpu == NULL)
3608 3630 cpu = CPU;
3609 3631 cpi = cpu->cpu_m.mcpu_cpi;
3610 3632
3611 3633 ASSERT(cpuid_checkpass(cpu, 1));
3612 3634
3613 3635 /*
3614 3636 * Check the L2 TLB info
3615 3637 */
3616 3638 if (cpi->cpi_xmaxeax >= 0x80000006) {
3617 3639 struct cpuid_regs *cp = &cpi->cpi_extd[6];
3618 3640
3619 3641 switch (pagesize) {
3620 3642
3621 3643 case 4 * 1024:
3622 3644 /*
3623 3645 * All zero in the top 16 bits of the register
3624 3646 * indicates a unified TLB. Size is in low 16 bits.
3625 3647 */
3626 3648 if ((cp->cp_ebx & 0xffff0000) == 0)
3627 3649 dtlb_nent = cp->cp_ebx & 0x0000ffff;
3628 3650 else
3629 3651 dtlb_nent = BITX(cp->cp_ebx, 27, 16);
3630 3652 break;
3631 3653
3632 3654 case 2 * 1024 * 1024:
3633 3655 if ((cp->cp_eax & 0xffff0000) == 0)
3634 3656 dtlb_nent = cp->cp_eax & 0x0000ffff;
3635 3657 else
3636 3658 dtlb_nent = BITX(cp->cp_eax, 27, 16);
3637 3659 break;
3638 3660
3639 3661 default:
3640 3662 panic("unknown L2 pagesize");
3641 3663 /*NOTREACHED*/
3642 3664 }
3643 3665 }
3644 3666
3645 3667 if (dtlb_nent != 0)
3646 3668 return (dtlb_nent);
3647 3669
3648 3670 /*
3649 3671 * No L2 TLB support for this size, try L1.
3650 3672 */
3651 3673 if (cpi->cpi_xmaxeax >= 0x80000005) {
3652 3674 struct cpuid_regs *cp = &cpi->cpi_extd[5];
3653 3675
3654 3676 switch (pagesize) {
3655 3677 case 4 * 1024:
3656 3678 dtlb_nent = BITX(cp->cp_ebx, 23, 16);
3657 3679 break;
3658 3680 case 2 * 1024 * 1024:
3659 3681 dtlb_nent = BITX(cp->cp_eax, 23, 16);
3660 3682 break;
3661 3683 default:
3662 3684 panic("unknown L1 d-TLB pagesize");
3663 3685 /*NOTREACHED*/
3664 3686 }
3665 3687 }
3666 3688
3667 3689 return (dtlb_nent);
3668 3690 }
3669 3691
3670 3692 /*
3671 3693 * Return 0 if the erratum is not present or not applicable, positive
3672 3694 * if it is, and negative if the status of the erratum is unknown.
3673 3695 *
3674 3696 * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm)
3675 3697 * Processors" #25759, Rev 3.57, August 2005
3676 3698 */
3677 3699 int
3678 3700 cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum)
3679 3701 {
3680 3702 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
3681 3703 uint_t eax;
3682 3704
3683 3705 /*
3684 3706 * Bail out if this CPU isn't an AMD CPU, or if it's
3685 3707 * a legacy (32-bit) AMD CPU.
3686 3708 */
3687 3709 if (cpi->cpi_vendor != X86_VENDOR_AMD ||
3688 3710 cpi->cpi_family == 4 || cpi->cpi_family == 5 ||
3689 3711 cpi->cpi_family == 6)
3690 3712
3691 3713 return (0);
3692 3714
3693 3715 eax = cpi->cpi_std[1].cp_eax;
3694 3716
3695 3717 #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50)
3696 3718 #define SH_B3(eax) (eax == 0xf51)
3697 3719 #define B(eax) (SH_B0(eax) || SH_B3(eax))
3698 3720
3699 3721 #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58)
3700 3722
3701 3723 #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a)
3702 3724 #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0)
3703 3725 #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2)
3704 3726 #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax))
3705 3727
3706 3728 #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70)
3707 3729 #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0)
3708 3730 #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0)
3709 3731 #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax))
3710 3732
3711 3733 #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70)
3712 3734 #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */
3713 3735 #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0)
3714 3736 #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71)
3715 3737 #define BH_E4(eax) (eax == 0x20fb1)
3716 3738 #define SH_E5(eax) (eax == 0x20f42)
3717 3739 #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2)
3718 3740 #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32)
3719 3741 #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \
3720 3742 SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \
3721 3743 DH_E6(eax) || JH_E6(eax))
3722 3744
3723 3745 #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02)
3724 3746 #define DR_B0(eax) (eax == 0x100f20)
3725 3747 #define DR_B1(eax) (eax == 0x100f21)
3726 3748 #define DR_BA(eax) (eax == 0x100f2a)
3727 3749 #define DR_B2(eax) (eax == 0x100f22)
3728 3750 #define DR_B3(eax) (eax == 0x100f23)
3729 3751 #define RB_C0(eax) (eax == 0x100f40)
3730 3752
3731 3753 switch (erratum) {
3732 3754 case 1:
3733 3755 return (cpi->cpi_family < 0x10);
3734 3756 case 51: /* what does the asterisk mean? */
3735 3757 return (B(eax) || SH_C0(eax) || CG(eax));
3736 3758 case 52:
3737 3759 return (B(eax));
3738 3760 case 57:
3739 3761 return (cpi->cpi_family <= 0x11);
3740 3762 case 58:
3741 3763 return (B(eax));
3742 3764 case 60:
3743 3765 return (cpi->cpi_family <= 0x11);
3744 3766 case 61:
3745 3767 case 62:
3746 3768 case 63:
3747 3769 case 64:
3748 3770 case 65:
3749 3771 case 66:
3750 3772 case 68:
3751 3773 case 69:
3752 3774 case 70:
3753 3775 case 71:
3754 3776 return (B(eax));
3755 3777 case 72:
3756 3778 return (SH_B0(eax));
3757 3779 case 74:
3758 3780 return (B(eax));
3759 3781 case 75:
3760 3782 return (cpi->cpi_family < 0x10);
3761 3783 case 76:
3762 3784 return (B(eax));
3763 3785 case 77:
3764 3786 return (cpi->cpi_family <= 0x11);
3765 3787 case 78:
3766 3788 return (B(eax) || SH_C0(eax));
3767 3789 case 79:
3768 3790 return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
3769 3791 case 80:
3770 3792 case 81:
3771 3793 case 82:
3772 3794 return (B(eax));
3773 3795 case 83:
3774 3796 return (B(eax) || SH_C0(eax) || CG(eax));
3775 3797 case 85:
3776 3798 return (cpi->cpi_family < 0x10);
3777 3799 case 86:
3778 3800 return (SH_C0(eax) || CG(eax));
3779 3801 case 88:
3780 3802 #if !defined(__amd64)
3781 3803 return (0);
3782 3804 #else
3783 3805 return (B(eax) || SH_C0(eax));
3784 3806 #endif
3785 3807 case 89:
3786 3808 return (cpi->cpi_family < 0x10);
3787 3809 case 90:
3788 3810 return (B(eax) || SH_C0(eax) || CG(eax));
3789 3811 case 91:
3790 3812 case 92:
3791 3813 return (B(eax) || SH_C0(eax));
3792 3814 case 93:
3793 3815 return (SH_C0(eax));
3794 3816 case 94:
3795 3817 return (B(eax) || SH_C0(eax) || CG(eax));
3796 3818 case 95:
3797 3819 #if !defined(__amd64)
3798 3820 return (0);
3799 3821 #else
3800 3822 return (B(eax) || SH_C0(eax));
3801 3823 #endif
3802 3824 case 96:
3803 3825 return (B(eax) || SH_C0(eax) || CG(eax));
3804 3826 case 97:
3805 3827 case 98:
3806 3828 return (SH_C0(eax) || CG(eax));
3807 3829 case 99:
3808 3830 return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
3809 3831 case 100:
3810 3832 return (B(eax) || SH_C0(eax));
3811 3833 case 101:
3812 3834 case 103:
3813 3835 return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
3814 3836 case 104:
3815 3837 return (SH_C0(eax) || CG(eax) || D0(eax));
3816 3838 case 105:
3817 3839 case 106:
3818 3840 case 107:
3819 3841 return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
3820 3842 case 108:
3821 3843 return (DH_CG(eax));
3822 3844 case 109:
3823 3845 return (SH_C0(eax) || CG(eax) || D0(eax));
3824 3846 case 110:
3825 3847 return (D0(eax) || EX(eax));
3826 3848 case 111:
3827 3849 return (CG(eax));
3828 3850 case 112:
3829 3851 return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
3830 3852 case 113:
3831 3853 return (eax == 0x20fc0);
3832 3854 case 114:
3833 3855 return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
3834 3856 case 115:
3835 3857 return (SH_E0(eax) || JH_E1(eax));
3836 3858 case 116:
3837 3859 return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
3838 3860 case 117:
3839 3861 return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
3840 3862 case 118:
3841 3863 return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) ||
3842 3864 JH_E6(eax));
3843 3865 case 121:
3844 3866 return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
3845 3867 case 122:
3846 3868 return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11);
3847 3869 case 123:
3848 3870 return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax));
3849 3871 case 131:
3850 3872 return (cpi->cpi_family < 0x10);
3851 3873 case 6336786:
3852 3874 /*
3853 3875 * Test for AdvPowerMgmtInfo.TscPStateInvariant
3854 3876 * if this is a K8 family or newer processor
3855 3877 */
3856 3878 if (CPI_FAMILY(cpi) == 0xf) {
3857 3879 struct cpuid_regs regs;
3858 3880 regs.cp_eax = 0x80000007;
3859 3881 (void) __cpuid_insn(®s);
3860 3882 return (!(regs.cp_edx & 0x100));
3861 3883 }
3862 3884 return (0);
3863 3885 case 6323525:
3864 3886 return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) |
3865 3887 (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40);
3866 3888
3867 3889 case 6671130:
3868 3890 /*
3869 3891 * check for processors (pre-Shanghai) that do not provide
3870 3892 * optimal management of 1gb ptes in its tlb.
3871 3893 */
3872 3894 return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4);
3873 3895
3874 3896 case 298:
3875 3897 return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) ||
3876 3898 DR_B2(eax) || RB_C0(eax));
3877 3899
3878 3900 case 721:
3879 3901 #if defined(__amd64)
3880 3902 return (cpi->cpi_family == 0x10 || cpi->cpi_family == 0x12);
3881 3903 #else
3882 3904 return (0);
3883 3905 #endif
3884 3906
3885 3907 default:
3886 3908 return (-1);
3887 3909
3888 3910 }
3889 3911 }
3890 3912
3891 3913 /*
3892 3914 * Determine if specified erratum is present via OSVW (OS Visible Workaround).
3893 3915 * Return 1 if erratum is present, 0 if not present and -1 if indeterminate.
3894 3916 */
3895 3917 int
3896 3918 osvw_opteron_erratum(cpu_t *cpu, uint_t erratum)
3897 3919 {
3898 3920 struct cpuid_info *cpi;
3899 3921 uint_t osvwid;
3900 3922 static int osvwfeature = -1;
3901 3923 uint64_t osvwlength;
3902 3924
3903 3925
3904 3926 cpi = cpu->cpu_m.mcpu_cpi;
3905 3927
3906 3928 /* confirm OSVW supported */
3907 3929 if (osvwfeature == -1) {
3908 3930 osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW;
3909 3931 } else {
3910 3932 /* assert that osvw feature setting is consistent on all cpus */
3911 3933 ASSERT(osvwfeature ==
3912 3934 (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW));
3913 3935 }
3914 3936 if (!osvwfeature)
3915 3937 return (-1);
3916 3938
3917 3939 osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK;
3918 3940
3919 3941 switch (erratum) {
3920 3942 case 298: /* osvwid is 0 */
3921 3943 osvwid = 0;
3922 3944 if (osvwlength <= (uint64_t)osvwid) {
3923 3945 /* osvwid 0 is unknown */
3924 3946 return (-1);
3925 3947 }
3926 3948
3927 3949 /*
3928 3950 * Check the OSVW STATUS MSR to determine the state
3929 3951 * of the erratum where:
3930 3952 * 0 - fixed by HW
3931 3953 * 1 - BIOS has applied the workaround when BIOS
3932 3954 * workaround is available. (Or for other errata,
3933 3955 * OS workaround is required.)
3934 3956 * For a value of 1, caller will confirm that the
3935 3957 * erratum 298 workaround has indeed been applied by BIOS.
3936 3958 *
3937 3959 * A 1 may be set in cpus that have a HW fix
3938 3960 * in a mixed cpu system. Regarding erratum 298:
3939 3961 * In a multiprocessor platform, the workaround above
3940 3962 * should be applied to all processors regardless of
3941 3963 * silicon revision when an affected processor is
3942 3964 * present.
3943 3965 */
3944 3966
3945 3967 return (rdmsr(MSR_AMD_OSVW_STATUS +
3946 3968 (osvwid / OSVW_ID_CNT_PER_MSR)) &
3947 3969 (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR)));
3948 3970
3949 3971 default:
3950 3972 return (-1);
3951 3973 }
3952 3974 }
3953 3975
3954 3976 static const char assoc_str[] = "associativity";
3955 3977 static const char line_str[] = "line-size";
3956 3978 static const char size_str[] = "size";
3957 3979
3958 3980 static void
3959 3981 add_cache_prop(dev_info_t *devi, const char *label, const char *type,
3960 3982 uint32_t val)
3961 3983 {
3962 3984 char buf[128];
3963 3985
3964 3986 /*
3965 3987 * ndi_prop_update_int() is used because it is desirable for
3966 3988 * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set.
3967 3989 */
3968 3990 if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf))
3969 3991 (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val);
3970 3992 }
3971 3993
3972 3994 /*
3973 3995 * Intel-style cache/tlb description
3974 3996 *
3975 3997 * Standard cpuid level 2 gives a randomly ordered
3976 3998 * selection of tags that index into a table that describes
3977 3999 * cache and tlb properties.
3978 4000 */
3979 4001
3980 4002 static const char l1_icache_str[] = "l1-icache";
3981 4003 static const char l1_dcache_str[] = "l1-dcache";
3982 4004 static const char l2_cache_str[] = "l2-cache";
3983 4005 static const char l3_cache_str[] = "l3-cache";
3984 4006 static const char itlb4k_str[] = "itlb-4K";
3985 4007 static const char dtlb4k_str[] = "dtlb-4K";
3986 4008 static const char itlb2M_str[] = "itlb-2M";
3987 4009 static const char itlb4M_str[] = "itlb-4M";
3988 4010 static const char dtlb4M_str[] = "dtlb-4M";
3989 4011 static const char dtlb24_str[] = "dtlb0-2M-4M";
3990 4012 static const char itlb424_str[] = "itlb-4K-2M-4M";
3991 4013 static const char itlb24_str[] = "itlb-2M-4M";
3992 4014 static const char dtlb44_str[] = "dtlb-4K-4M";
3993 4015 static const char sl1_dcache_str[] = "sectored-l1-dcache";
3994 4016 static const char sl2_cache_str[] = "sectored-l2-cache";
3995 4017 static const char itrace_str[] = "itrace-cache";
3996 4018 static const char sl3_cache_str[] = "sectored-l3-cache";
3997 4019 static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k";
3998 4020
3999 4021 static const struct cachetab {
4000 4022 uint8_t ct_code;
4001 4023 uint8_t ct_assoc;
4002 4024 uint16_t ct_line_size;
4003 4025 size_t ct_size;
4004 4026 const char *ct_label;
4005 4027 } intel_ctab[] = {
4006 4028 /*
4007 4029 * maintain descending order!
4008 4030 *
4009 4031 * Codes ignored - Reason
4010 4032 * ----------------------
4011 4033 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache
4012 4034 * f0H/f1H - Currently we do not interpret prefetch size by design
4013 4035 */
4014 4036 { 0xe4, 16, 64, 8*1024*1024, l3_cache_str},
4015 4037 { 0xe3, 16, 64, 4*1024*1024, l3_cache_str},
4016 4038 { 0xe2, 16, 64, 2*1024*1024, l3_cache_str},
4017 4039 { 0xde, 12, 64, 6*1024*1024, l3_cache_str},
4018 4040 { 0xdd, 12, 64, 3*1024*1024, l3_cache_str},
4019 4041 { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str},
4020 4042 { 0xd8, 8, 64, 4*1024*1024, l3_cache_str},
4021 4043 { 0xd7, 8, 64, 2*1024*1024, l3_cache_str},
4022 4044 { 0xd6, 8, 64, 1*1024*1024, l3_cache_str},
4023 4045 { 0xd2, 4, 64, 2*1024*1024, l3_cache_str},
4024 4046 { 0xd1, 4, 64, 1*1024*1024, l3_cache_str},
4025 4047 { 0xd0, 4, 64, 512*1024, l3_cache_str},
4026 4048 { 0xca, 4, 0, 512, sh_l2_tlb4k_str},
4027 4049 { 0xc0, 4, 0, 8, dtlb44_str },
4028 4050 { 0xba, 4, 0, 64, dtlb4k_str },
4029 4051 { 0xb4, 4, 0, 256, dtlb4k_str },
4030 4052 { 0xb3, 4, 0, 128, dtlb4k_str },
4031 4053 { 0xb2, 4, 0, 64, itlb4k_str },
4032 4054 { 0xb0, 4, 0, 128, itlb4k_str },
4033 4055 { 0x87, 8, 64, 1024*1024, l2_cache_str},
4034 4056 { 0x86, 4, 64, 512*1024, l2_cache_str},
4035 4057 { 0x85, 8, 32, 2*1024*1024, l2_cache_str},
4036 4058 { 0x84, 8, 32, 1024*1024, l2_cache_str},
4037 4059 { 0x83, 8, 32, 512*1024, l2_cache_str},
4038 4060 { 0x82, 8, 32, 256*1024, l2_cache_str},
4039 4061 { 0x80, 8, 64, 512*1024, l2_cache_str},
4040 4062 { 0x7f, 2, 64, 512*1024, l2_cache_str},
4041 4063 { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str},
4042 4064 { 0x7c, 8, 64, 1024*1024, sl2_cache_str},
4043 4065 { 0x7b, 8, 64, 512*1024, sl2_cache_str},
4044 4066 { 0x7a, 8, 64, 256*1024, sl2_cache_str},
4045 4067 { 0x79, 8, 64, 128*1024, sl2_cache_str},
4046 4068 { 0x78, 8, 64, 1024*1024, l2_cache_str},
4047 4069 { 0x73, 8, 0, 64*1024, itrace_str},
4048 4070 { 0x72, 8, 0, 32*1024, itrace_str},
4049 4071 { 0x71, 8, 0, 16*1024, itrace_str},
4050 4072 { 0x70, 8, 0, 12*1024, itrace_str},
4051 4073 { 0x68, 4, 64, 32*1024, sl1_dcache_str},
4052 4074 { 0x67, 4, 64, 16*1024, sl1_dcache_str},
4053 4075 { 0x66, 4, 64, 8*1024, sl1_dcache_str},
4054 4076 { 0x60, 8, 64, 16*1024, sl1_dcache_str},
4055 4077 { 0x5d, 0, 0, 256, dtlb44_str},
4056 4078 { 0x5c, 0, 0, 128, dtlb44_str},
4057 4079 { 0x5b, 0, 0, 64, dtlb44_str},
4058 4080 { 0x5a, 4, 0, 32, dtlb24_str},
4059 4081 { 0x59, 0, 0, 16, dtlb4k_str},
4060 4082 { 0x57, 4, 0, 16, dtlb4k_str},
4061 4083 { 0x56, 4, 0, 16, dtlb4M_str},
4062 4084 { 0x55, 0, 0, 7, itlb24_str},
4063 4085 { 0x52, 0, 0, 256, itlb424_str},
4064 4086 { 0x51, 0, 0, 128, itlb424_str},
4065 4087 { 0x50, 0, 0, 64, itlb424_str},
4066 4088 { 0x4f, 0, 0, 32, itlb4k_str},
4067 4089 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str},
4068 4090 { 0x4d, 16, 64, 16*1024*1024, l3_cache_str},
4069 4091 { 0x4c, 12, 64, 12*1024*1024, l3_cache_str},
4070 4092 { 0x4b, 16, 64, 8*1024*1024, l3_cache_str},
4071 4093 { 0x4a, 12, 64, 6*1024*1024, l3_cache_str},
4072 4094 { 0x49, 16, 64, 4*1024*1024, l3_cache_str},
4073 4095 { 0x48, 12, 64, 3*1024*1024, l2_cache_str},
4074 4096 { 0x47, 8, 64, 8*1024*1024, l3_cache_str},
4075 4097 { 0x46, 4, 64, 4*1024*1024, l3_cache_str},
4076 4098 { 0x45, 4, 32, 2*1024*1024, l2_cache_str},
4077 4099 { 0x44, 4, 32, 1024*1024, l2_cache_str},
4078 4100 { 0x43, 4, 32, 512*1024, l2_cache_str},
4079 4101 { 0x42, 4, 32, 256*1024, l2_cache_str},
4080 4102 { 0x41, 4, 32, 128*1024, l2_cache_str},
4081 4103 { 0x3e, 4, 64, 512*1024, sl2_cache_str},
4082 4104 { 0x3d, 6, 64, 384*1024, sl2_cache_str},
4083 4105 { 0x3c, 4, 64, 256*1024, sl2_cache_str},
4084 4106 { 0x3b, 2, 64, 128*1024, sl2_cache_str},
4085 4107 { 0x3a, 6, 64, 192*1024, sl2_cache_str},
4086 4108 { 0x39, 4, 64, 128*1024, sl2_cache_str},
4087 4109 { 0x30, 8, 64, 32*1024, l1_icache_str},
4088 4110 { 0x2c, 8, 64, 32*1024, l1_dcache_str},
4089 4111 { 0x29, 8, 64, 4096*1024, sl3_cache_str},
4090 4112 { 0x25, 8, 64, 2048*1024, sl3_cache_str},
4091 4113 { 0x23, 8, 64, 1024*1024, sl3_cache_str},
4092 4114 { 0x22, 4, 64, 512*1024, sl3_cache_str},
4093 4115 { 0x0e, 6, 64, 24*1024, l1_dcache_str},
4094 4116 { 0x0d, 4, 32, 16*1024, l1_dcache_str},
4095 4117 { 0x0c, 4, 32, 16*1024, l1_dcache_str},
4096 4118 { 0x0b, 4, 0, 4, itlb4M_str},
4097 4119 { 0x0a, 2, 32, 8*1024, l1_dcache_str},
4098 4120 { 0x08, 4, 32, 16*1024, l1_icache_str},
4099 4121 { 0x06, 4, 32, 8*1024, l1_icache_str},
4100 4122 { 0x05, 4, 0, 32, dtlb4M_str},
4101 4123 { 0x04, 4, 0, 8, dtlb4M_str},
4102 4124 { 0x03, 4, 0, 64, dtlb4k_str},
4103 4125 { 0x02, 4, 0, 2, itlb4M_str},
4104 4126 { 0x01, 4, 0, 32, itlb4k_str},
4105 4127 { 0 }
4106 4128 };
4107 4129
4108 4130 static const struct cachetab cyrix_ctab[] = {
4109 4131 { 0x70, 4, 0, 32, "tlb-4K" },
4110 4132 { 0x80, 4, 16, 16*1024, "l1-cache" },
4111 4133 { 0 }
4112 4134 };
4113 4135
4114 4136 /*
4115 4137 * Search a cache table for a matching entry
4116 4138 */
4117 4139 static const struct cachetab *
4118 4140 find_cacheent(const struct cachetab *ct, uint_t code)
4119 4141 {
4120 4142 if (code != 0) {
4121 4143 for (; ct->ct_code != 0; ct++)
4122 4144 if (ct->ct_code <= code)
4123 4145 break;
4124 4146 if (ct->ct_code == code)
4125 4147 return (ct);
4126 4148 }
4127 4149 return (NULL);
4128 4150 }
4129 4151
4130 4152 /*
4131 4153 * Populate cachetab entry with L2 or L3 cache-information using
4132 4154 * cpuid function 4. This function is called from intel_walk_cacheinfo()
4133 4155 * when descriptor 0x49 is encountered. It returns 0 if no such cache
4134 4156 * information is found.
4135 4157 */
4136 4158 static int
4137 4159 intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi)
4138 4160 {
4139 4161 uint32_t level, i;
4140 4162 int ret = 0;
4141 4163
4142 4164 for (i = 0; i < cpi->cpi_std_4_size; i++) {
4143 4165 level = CPI_CACHE_LVL(cpi->cpi_std_4[i]);
4144 4166
4145 4167 if (level == 2 || level == 3) {
4146 4168 ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1;
4147 4169 ct->ct_line_size =
4148 4170 CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1;
4149 4171 ct->ct_size = ct->ct_assoc *
4150 4172 (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) *
4151 4173 ct->ct_line_size *
4152 4174 (cpi->cpi_std_4[i]->cp_ecx + 1);
4153 4175
4154 4176 if (level == 2) {
4155 4177 ct->ct_label = l2_cache_str;
4156 4178 } else if (level == 3) {
4157 4179 ct->ct_label = l3_cache_str;
4158 4180 }
4159 4181 ret = 1;
4160 4182 }
4161 4183 }
4162 4184
4163 4185 return (ret);
4164 4186 }
4165 4187
4166 4188 /*
4167 4189 * Walk the cacheinfo descriptor, applying 'func' to every valid element
4168 4190 * The walk is terminated if the walker returns non-zero.
4169 4191 */
4170 4192 static void
4171 4193 intel_walk_cacheinfo(struct cpuid_info *cpi,
4172 4194 void *arg, int (*func)(void *, const struct cachetab *))
4173 4195 {
4174 4196 const struct cachetab *ct;
4175 4197 struct cachetab des_49_ct, des_b1_ct;
4176 4198 uint8_t *dp;
4177 4199 int i;
4178 4200
4179 4201 if ((dp = cpi->cpi_cacheinfo) == NULL)
4180 4202 return;
4181 4203 for (i = 0; i < cpi->cpi_ncache; i++, dp++) {
4182 4204 /*
4183 4205 * For overloaded descriptor 0x49 we use cpuid function 4
4184 4206 * if supported by the current processor, to create
4185 4207 * cache information.
4186 4208 * For overloaded descriptor 0xb1 we use X86_PAE flag
4187 4209 * to disambiguate the cache information.
4188 4210 */
4189 4211 if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 &&
4190 4212 intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) {
4191 4213 ct = &des_49_ct;
4192 4214 } else if (*dp == 0xb1) {
4193 4215 des_b1_ct.ct_code = 0xb1;
4194 4216 des_b1_ct.ct_assoc = 4;
4195 4217 des_b1_ct.ct_line_size = 0;
4196 4218 if (is_x86_feature(x86_featureset, X86FSET_PAE)) {
4197 4219 des_b1_ct.ct_size = 8;
4198 4220 des_b1_ct.ct_label = itlb2M_str;
4199 4221 } else {
4200 4222 des_b1_ct.ct_size = 4;
4201 4223 des_b1_ct.ct_label = itlb4M_str;
4202 4224 }
4203 4225 ct = &des_b1_ct;
4204 4226 } else {
4205 4227 if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) {
4206 4228 continue;
4207 4229 }
4208 4230 }
4209 4231
4210 4232 if (func(arg, ct) != 0) {
4211 4233 break;
4212 4234 }
4213 4235 }
4214 4236 }
4215 4237
4216 4238 /*
4217 4239 * (Like the Intel one, except for Cyrix CPUs)
4218 4240 */
4219 4241 static void
4220 4242 cyrix_walk_cacheinfo(struct cpuid_info *cpi,
4221 4243 void *arg, int (*func)(void *, const struct cachetab *))
4222 4244 {
4223 4245 const struct cachetab *ct;
4224 4246 uint8_t *dp;
4225 4247 int i;
4226 4248
4227 4249 if ((dp = cpi->cpi_cacheinfo) == NULL)
4228 4250 return;
4229 4251 for (i = 0; i < cpi->cpi_ncache; i++, dp++) {
4230 4252 /*
4231 4253 * Search Cyrix-specific descriptor table first ..
4232 4254 */
4233 4255 if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) {
4234 4256 if (func(arg, ct) != 0)
4235 4257 break;
4236 4258 continue;
4237 4259 }
4238 4260 /*
4239 4261 * .. else fall back to the Intel one
4240 4262 */
4241 4263 if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) {
4242 4264 if (func(arg, ct) != 0)
4243 4265 break;
4244 4266 continue;
4245 4267 }
4246 4268 }
4247 4269 }
4248 4270
4249 4271 /*
4250 4272 * A cacheinfo walker that adds associativity, line-size, and size properties
4251 4273 * to the devinfo node it is passed as an argument.
4252 4274 */
4253 4275 static int
4254 4276 add_cacheent_props(void *arg, const struct cachetab *ct)
4255 4277 {
4256 4278 dev_info_t *devi = arg;
4257 4279
4258 4280 add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc);
4259 4281 if (ct->ct_line_size != 0)
4260 4282 add_cache_prop(devi, ct->ct_label, line_str,
4261 4283 ct->ct_line_size);
4262 4284 add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size);
4263 4285 return (0);
4264 4286 }
4265 4287
4266 4288
4267 4289 static const char fully_assoc[] = "fully-associative?";
4268 4290
4269 4291 /*
4270 4292 * AMD style cache/tlb description
4271 4293 *
4272 4294 * Extended functions 5 and 6 directly describe properties of
4273 4295 * tlbs and various cache levels.
4274 4296 */
4275 4297 static void
4276 4298 add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc)
4277 4299 {
4278 4300 switch (assoc) {
4279 4301 case 0: /* reserved; ignore */
4280 4302 break;
4281 4303 default:
4282 4304 add_cache_prop(devi, label, assoc_str, assoc);
4283 4305 break;
4284 4306 case 0xff:
4285 4307 add_cache_prop(devi, label, fully_assoc, 1);
4286 4308 break;
4287 4309 }
4288 4310 }
4289 4311
4290 4312 static void
4291 4313 add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
4292 4314 {
4293 4315 if (size == 0)
4294 4316 return;
4295 4317 add_cache_prop(devi, label, size_str, size);
4296 4318 add_amd_assoc(devi, label, assoc);
4297 4319 }
4298 4320
4299 4321 static void
4300 4322 add_amd_cache(dev_info_t *devi, const char *label,
4301 4323 uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
4302 4324 {
4303 4325 if (size == 0 || line_size == 0)
4304 4326 return;
4305 4327 add_amd_assoc(devi, label, assoc);
4306 4328 /*
4307 4329 * Most AMD parts have a sectored cache. Multiple cache lines are
4308 4330 * associated with each tag. A sector consists of all cache lines
4309 4331 * associated with a tag. For example, the AMD K6-III has a sector
4310 4332 * size of 2 cache lines per tag.
4311 4333 */
4312 4334 if (lines_per_tag != 0)
4313 4335 add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
4314 4336 add_cache_prop(devi, label, line_str, line_size);
4315 4337 add_cache_prop(devi, label, size_str, size * 1024);
4316 4338 }
4317 4339
4318 4340 static void
4319 4341 add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc)
4320 4342 {
4321 4343 switch (assoc) {
4322 4344 case 0: /* off */
4323 4345 break;
4324 4346 case 1:
4325 4347 case 2:
4326 4348 case 4:
4327 4349 add_cache_prop(devi, label, assoc_str, assoc);
4328 4350 break;
4329 4351 case 6:
4330 4352 add_cache_prop(devi, label, assoc_str, 8);
4331 4353 break;
4332 4354 case 8:
4333 4355 add_cache_prop(devi, label, assoc_str, 16);
4334 4356 break;
4335 4357 case 0xf:
4336 4358 add_cache_prop(devi, label, fully_assoc, 1);
4337 4359 break;
4338 4360 default: /* reserved; ignore */
4339 4361 break;
4340 4362 }
4341 4363 }
4342 4364
4343 4365 static void
4344 4366 add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
4345 4367 {
4346 4368 if (size == 0 || assoc == 0)
4347 4369 return;
4348 4370 add_amd_l2_assoc(devi, label, assoc);
4349 4371 add_cache_prop(devi, label, size_str, size);
4350 4372 }
4351 4373
4352 4374 static void
4353 4375 add_amd_l2_cache(dev_info_t *devi, const char *label,
4354 4376 uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
4355 4377 {
4356 4378 if (size == 0 || assoc == 0 || line_size == 0)
4357 4379 return;
4358 4380 add_amd_l2_assoc(devi, label, assoc);
4359 4381 if (lines_per_tag != 0)
4360 4382 add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
4361 4383 add_cache_prop(devi, label, line_str, line_size);
4362 4384 add_cache_prop(devi, label, size_str, size * 1024);
4363 4385 }
4364 4386
4365 4387 static void
4366 4388 amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi)
4367 4389 {
4368 4390 struct cpuid_regs *cp;
4369 4391
4370 4392 if (cpi->cpi_xmaxeax < 0x80000005)
4371 4393 return;
4372 4394 cp = &cpi->cpi_extd[5];
4373 4395
4374 4396 /*
4375 4397 * 4M/2M L1 TLB configuration
4376 4398 *
4377 4399 * We report the size for 2M pages because AMD uses two
4378 4400 * TLB entries for one 4M page.
4379 4401 */
4380 4402 add_amd_tlb(devi, "dtlb-2M",
4381 4403 BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16));
4382 4404 add_amd_tlb(devi, "itlb-2M",
4383 4405 BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0));
4384 4406
4385 4407 /*
4386 4408 * 4K L1 TLB configuration
4387 4409 */
4388 4410
4389 4411 switch (cpi->cpi_vendor) {
4390 4412 uint_t nentries;
4391 4413 case X86_VENDOR_TM:
4392 4414 if (cpi->cpi_family >= 5) {
4393 4415 /*
4394 4416 * Crusoe processors have 256 TLB entries, but
4395 4417 * cpuid data format constrains them to only
4396 4418 * reporting 255 of them.
4397 4419 */
4398 4420 if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255)
4399 4421 nentries = 256;
4400 4422 /*
4401 4423 * Crusoe processors also have a unified TLB
4402 4424 */
4403 4425 add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24),
4404 4426 nentries);
4405 4427 break;
4406 4428 }
4407 4429 /*FALLTHROUGH*/
4408 4430 default:
4409 4431 add_amd_tlb(devi, itlb4k_str,
4410 4432 BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16));
4411 4433 add_amd_tlb(devi, dtlb4k_str,
4412 4434 BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0));
4413 4435 break;
4414 4436 }
4415 4437
4416 4438 /*
4417 4439 * data L1 cache configuration
4418 4440 */
4419 4441
4420 4442 add_amd_cache(devi, l1_dcache_str,
4421 4443 BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16),
4422 4444 BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0));
4423 4445
4424 4446 /*
4425 4447 * code L1 cache configuration
4426 4448 */
4427 4449
4428 4450 add_amd_cache(devi, l1_icache_str,
4429 4451 BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16),
4430 4452 BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0));
4431 4453
4432 4454 if (cpi->cpi_xmaxeax < 0x80000006)
4433 4455 return;
4434 4456 cp = &cpi->cpi_extd[6];
4435 4457
4436 4458 /* Check for a unified L2 TLB for large pages */
4437 4459
4438 4460 if (BITX(cp->cp_eax, 31, 16) == 0)
4439 4461 add_amd_l2_tlb(devi, "l2-tlb-2M",
4440 4462 BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
4441 4463 else {
4442 4464 add_amd_l2_tlb(devi, "l2-dtlb-2M",
4443 4465 BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
4444 4466 add_amd_l2_tlb(devi, "l2-itlb-2M",
4445 4467 BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
4446 4468 }
4447 4469
4448 4470 /* Check for a unified L2 TLB for 4K pages */
4449 4471
4450 4472 if (BITX(cp->cp_ebx, 31, 16) == 0) {
4451 4473 add_amd_l2_tlb(devi, "l2-tlb-4K",
4452 4474 BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
4453 4475 } else {
4454 4476 add_amd_l2_tlb(devi, "l2-dtlb-4K",
4455 4477 BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
4456 4478 add_amd_l2_tlb(devi, "l2-itlb-4K",
4457 4479 BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
4458 4480 }
4459 4481
4460 4482 add_amd_l2_cache(devi, l2_cache_str,
4461 4483 BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12),
4462 4484 BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0));
4463 4485 }
4464 4486
4465 4487 /*
4466 4488 * There are two basic ways that the x86 world describes it cache
4467 4489 * and tlb architecture - Intel's way and AMD's way.
4468 4490 *
4469 4491 * Return which flavor of cache architecture we should use
4470 4492 */
4471 4493 static int
4472 4494 x86_which_cacheinfo(struct cpuid_info *cpi)
4473 4495 {
4474 4496 switch (cpi->cpi_vendor) {
4475 4497 case X86_VENDOR_Intel:
4476 4498 if (cpi->cpi_maxeax >= 2)
4477 4499 return (X86_VENDOR_Intel);
4478 4500 break;
4479 4501 case X86_VENDOR_AMD:
4480 4502 /*
4481 4503 * The K5 model 1 was the first part from AMD that reported
4482 4504 * cache sizes via extended cpuid functions.
4483 4505 */
4484 4506 if (cpi->cpi_family > 5 ||
4485 4507 (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
4486 4508 return (X86_VENDOR_AMD);
4487 4509 break;
4488 4510 case X86_VENDOR_TM:
4489 4511 if (cpi->cpi_family >= 5)
4490 4512 return (X86_VENDOR_AMD);
4491 4513 /*FALLTHROUGH*/
4492 4514 default:
4493 4515 /*
4494 4516 * If they have extended CPU data for 0x80000005
4495 4517 * then we assume they have AMD-format cache
4496 4518 * information.
4497 4519 *
4498 4520 * If not, and the vendor happens to be Cyrix,
4499 4521 * then try our-Cyrix specific handler.
4500 4522 *
4501 4523 * If we're not Cyrix, then assume we're using Intel's
4502 4524 * table-driven format instead.
4503 4525 */
4504 4526 if (cpi->cpi_xmaxeax >= 0x80000005)
4505 4527 return (X86_VENDOR_AMD);
4506 4528 else if (cpi->cpi_vendor == X86_VENDOR_Cyrix)
4507 4529 return (X86_VENDOR_Cyrix);
4508 4530 else if (cpi->cpi_maxeax >= 2)
4509 4531 return (X86_VENDOR_Intel);
4510 4532 break;
4511 4533 }
4512 4534 return (-1);
4513 4535 }
4514 4536
4515 4537 void
4516 4538 cpuid_set_cpu_properties(void *dip, processorid_t cpu_id,
4517 4539 struct cpuid_info *cpi)
4518 4540 {
4519 4541 dev_info_t *cpu_devi;
4520 4542 int create;
4521 4543
4522 4544 cpu_devi = (dev_info_t *)dip;
4523 4545
4524 4546 /* device_type */
4525 4547 (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
4526 4548 "device_type", "cpu");
4527 4549
4528 4550 /* reg */
4529 4551 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4530 4552 "reg", cpu_id);
4531 4553
4532 4554 /* cpu-mhz, and clock-frequency */
4533 4555 if (cpu_freq > 0) {
4534 4556 long long mul;
4535 4557
4536 4558 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4537 4559 "cpu-mhz", cpu_freq);
4538 4560 if ((mul = cpu_freq * 1000000LL) <= INT_MAX)
4539 4561 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4540 4562 "clock-frequency", (int)mul);
4541 4563 }
4542 4564
4543 4565 if (!is_x86_feature(x86_featureset, X86FSET_CPUID)) {
4544 4566 return;
4545 4567 }
4546 4568
4547 4569 /* vendor-id */
4548 4570 (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
4549 4571 "vendor-id", cpi->cpi_vendorstr);
4550 4572
4551 4573 if (cpi->cpi_maxeax == 0) {
4552 4574 return;
4553 4575 }
4554 4576
4555 4577 /*
4556 4578 * family, model, and step
4557 4579 */
4558 4580 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4559 4581 "family", CPI_FAMILY(cpi));
4560 4582 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4561 4583 "cpu-model", CPI_MODEL(cpi));
4562 4584 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4563 4585 "stepping-id", CPI_STEP(cpi));
4564 4586
4565 4587 /* type */
4566 4588 switch (cpi->cpi_vendor) {
4567 4589 case X86_VENDOR_Intel:
4568 4590 create = 1;
4569 4591 break;
4570 4592 default:
4571 4593 create = 0;
4572 4594 break;
4573 4595 }
4574 4596 if (create)
4575 4597 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4576 4598 "type", CPI_TYPE(cpi));
4577 4599
4578 4600 /* ext-family */
4579 4601 switch (cpi->cpi_vendor) {
4580 4602 case X86_VENDOR_Intel:
4581 4603 case X86_VENDOR_AMD:
4582 4604 create = cpi->cpi_family >= 0xf;
4583 4605 break;
4584 4606 default:
4585 4607 create = 0;
4586 4608 break;
4587 4609 }
4588 4610 if (create)
4589 4611 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4590 4612 "ext-family", CPI_FAMILY_XTD(cpi));
4591 4613
4592 4614 /* ext-model */
4593 4615 switch (cpi->cpi_vendor) {
4594 4616 case X86_VENDOR_Intel:
4595 4617 create = IS_EXTENDED_MODEL_INTEL(cpi);
4596 4618 break;
4597 4619 case X86_VENDOR_AMD:
4598 4620 create = CPI_FAMILY(cpi) == 0xf;
4599 4621 break;
4600 4622 default:
4601 4623 create = 0;
4602 4624 break;
4603 4625 }
4604 4626 if (create)
4605 4627 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4606 4628 "ext-model", CPI_MODEL_XTD(cpi));
4607 4629
4608 4630 /* generation */
4609 4631 switch (cpi->cpi_vendor) {
4610 4632 case X86_VENDOR_AMD:
4611 4633 /*
4612 4634 * AMD K5 model 1 was the first part to support this
4613 4635 */
4614 4636 create = cpi->cpi_xmaxeax >= 0x80000001;
4615 4637 break;
4616 4638 default:
4617 4639 create = 0;
4618 4640 break;
4619 4641 }
4620 4642 if (create)
4621 4643 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4622 4644 "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8));
4623 4645
4624 4646 /* brand-id */
4625 4647 switch (cpi->cpi_vendor) {
4626 4648 case X86_VENDOR_Intel:
4627 4649 /*
4628 4650 * brand id first appeared on Pentium III Xeon model 8,
4629 4651 * and Celeron model 8 processors and Opteron
4630 4652 */
4631 4653 create = cpi->cpi_family > 6 ||
4632 4654 (cpi->cpi_family == 6 && cpi->cpi_model >= 8);
4633 4655 break;
4634 4656 case X86_VENDOR_AMD:
4635 4657 create = cpi->cpi_family >= 0xf;
4636 4658 break;
4637 4659 default:
4638 4660 create = 0;
4639 4661 break;
4640 4662 }
4641 4663 if (create && cpi->cpi_brandid != 0) {
4642 4664 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4643 4665 "brand-id", cpi->cpi_brandid);
4644 4666 }
4645 4667
4646 4668 /* chunks, and apic-id */
4647 4669 switch (cpi->cpi_vendor) {
4648 4670 /*
4649 4671 * first available on Pentium IV and Opteron (K8)
4650 4672 */
4651 4673 case X86_VENDOR_Intel:
4652 4674 create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf;
4653 4675 break;
4654 4676 case X86_VENDOR_AMD:
4655 4677 create = cpi->cpi_family >= 0xf;
4656 4678 break;
4657 4679 default:
4658 4680 create = 0;
4659 4681 break;
4660 4682 }
4661 4683 if (create) {
4662 4684 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4663 4685 "chunks", CPI_CHUNKS(cpi));
4664 4686 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4665 4687 "apic-id", cpi->cpi_apicid);
4666 4688 if (cpi->cpi_chipid >= 0) {
4667 4689 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4668 4690 "chip#", cpi->cpi_chipid);
4669 4691 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4670 4692 "clog#", cpi->cpi_clogid);
4671 4693 }
4672 4694 }
4673 4695
4674 4696 /* cpuid-features */
4675 4697 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4676 4698 "cpuid-features", CPI_FEATURES_EDX(cpi));
4677 4699
4678 4700
4679 4701 /* cpuid-features-ecx */
4680 4702 switch (cpi->cpi_vendor) {
4681 4703 case X86_VENDOR_Intel:
4682 4704 create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf;
4683 4705 break;
4684 4706 case X86_VENDOR_AMD:
4685 4707 create = cpi->cpi_family >= 0xf;
4686 4708 break;
4687 4709 default:
4688 4710 create = 0;
4689 4711 break;
4690 4712 }
4691 4713 if (create)
4692 4714 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4693 4715 "cpuid-features-ecx", CPI_FEATURES_ECX(cpi));
4694 4716
4695 4717 /* ext-cpuid-features */
4696 4718 switch (cpi->cpi_vendor) {
4697 4719 case X86_VENDOR_Intel:
4698 4720 case X86_VENDOR_AMD:
4699 4721 case X86_VENDOR_Cyrix:
4700 4722 case X86_VENDOR_TM:
4701 4723 case X86_VENDOR_Centaur:
4702 4724 create = cpi->cpi_xmaxeax >= 0x80000001;
4703 4725 break;
4704 4726 default:
4705 4727 create = 0;
4706 4728 break;
4707 4729 }
4708 4730 if (create) {
4709 4731 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4710 4732 "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi));
4711 4733 (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
4712 4734 "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi));
4713 4735 }
4714 4736
4715 4737 /*
4716 4738 * Brand String first appeared in Intel Pentium IV, AMD K5
4717 4739 * model 1, and Cyrix GXm. On earlier models we try and
4718 4740 * simulate something similar .. so this string should always
4719 4741 * same -something- about the processor, however lame.
4720 4742 */
4721 4743 (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
4722 4744 "brand-string", cpi->cpi_brandstr);
4723 4745
4724 4746 /*
4725 4747 * Finally, cache and tlb information
4726 4748 */
4727 4749 switch (x86_which_cacheinfo(cpi)) {
4728 4750 case X86_VENDOR_Intel:
4729 4751 intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
4730 4752 break;
4731 4753 case X86_VENDOR_Cyrix:
4732 4754 cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
4733 4755 break;
4734 4756 case X86_VENDOR_AMD:
4735 4757 amd_cache_info(cpi, cpu_devi);
4736 4758 break;
4737 4759 default:
4738 4760 break;
4739 4761 }
4740 4762 }
4741 4763
4742 4764 struct l2info {
4743 4765 int *l2i_csz;
4744 4766 int *l2i_lsz;
4745 4767 int *l2i_assoc;
4746 4768 int l2i_ret;
4747 4769 };
4748 4770
4749 4771 /*
4750 4772 * A cacheinfo walker that fetches the size, line-size and associativity
4751 4773 * of the L2 cache
4752 4774 */
4753 4775 static int
4754 4776 intel_l2cinfo(void *arg, const struct cachetab *ct)
4755 4777 {
4756 4778 struct l2info *l2i = arg;
4757 4779 int *ip;
4758 4780
4759 4781 if (ct->ct_label != l2_cache_str &&
4760 4782 ct->ct_label != sl2_cache_str)
4761 4783 return (0); /* not an L2 -- keep walking */
4762 4784
4763 4785 if ((ip = l2i->l2i_csz) != NULL)
4764 4786 *ip = ct->ct_size;
4765 4787 if ((ip = l2i->l2i_lsz) != NULL)
4766 4788 *ip = ct->ct_line_size;
4767 4789 if ((ip = l2i->l2i_assoc) != NULL)
4768 4790 *ip = ct->ct_assoc;
4769 4791 l2i->l2i_ret = ct->ct_size;
4770 4792 return (1); /* was an L2 -- terminate walk */
4771 4793 }
4772 4794
4773 4795 /*
4774 4796 * AMD L2/L3 Cache and TLB Associativity Field Definition:
4775 4797 *
4776 4798 * Unlike the associativity for the L1 cache and tlb where the 8 bit
4777 4799 * value is the associativity, the associativity for the L2 cache and
4778 4800 * tlb is encoded in the following table. The 4 bit L2 value serves as
4779 4801 * an index into the amd_afd[] array to determine the associativity.
4780 4802 * -1 is undefined. 0 is fully associative.
4781 4803 */
4782 4804
4783 4805 static int amd_afd[] =
4784 4806 {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0};
4785 4807
4786 4808 static void
4787 4809 amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i)
4788 4810 {
4789 4811 struct cpuid_regs *cp;
4790 4812 uint_t size, assoc;
4791 4813 int i;
4792 4814 int *ip;
4793 4815
4794 4816 if (cpi->cpi_xmaxeax < 0x80000006)
4795 4817 return;
4796 4818 cp = &cpi->cpi_extd[6];
4797 4819
4798 4820 if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 &&
4799 4821 (size = BITX(cp->cp_ecx, 31, 16)) != 0) {
4800 4822 uint_t cachesz = size * 1024;
4801 4823 assoc = amd_afd[i];
4802 4824
4803 4825 ASSERT(assoc != -1);
4804 4826
4805 4827 if ((ip = l2i->l2i_csz) != NULL)
4806 4828 *ip = cachesz;
4807 4829 if ((ip = l2i->l2i_lsz) != NULL)
4808 4830 *ip = BITX(cp->cp_ecx, 7, 0);
4809 4831 if ((ip = l2i->l2i_assoc) != NULL)
4810 4832 *ip = assoc;
4811 4833 l2i->l2i_ret = cachesz;
4812 4834 }
4813 4835 }
4814 4836
4815 4837 int
4816 4838 getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc)
4817 4839 {
4818 4840 struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
4819 4841 struct l2info __l2info, *l2i = &__l2info;
4820 4842
4821 4843 l2i->l2i_csz = csz;
4822 4844 l2i->l2i_lsz = lsz;
4823 4845 l2i->l2i_assoc = assoc;
4824 4846 l2i->l2i_ret = -1;
4825 4847
4826 4848 switch (x86_which_cacheinfo(cpi)) {
4827 4849 case X86_VENDOR_Intel:
4828 4850 intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
4829 4851 break;
4830 4852 case X86_VENDOR_Cyrix:
4831 4853 cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
4832 4854 break;
4833 4855 case X86_VENDOR_AMD:
4834 4856 amd_l2cacheinfo(cpi, l2i);
4835 4857 break;
4836 4858 default:
4837 4859 break;
4838 4860 }
4839 4861 return (l2i->l2i_ret);
4840 4862 }
4841 4863
4842 4864 #if !defined(__xpv)
4843 4865
4844 4866 uint32_t *
4845 4867 cpuid_mwait_alloc(cpu_t *cpu)
4846 4868 {
4847 4869 uint32_t *ret;
4848 4870 size_t mwait_size;
4849 4871
4850 4872 ASSERT(cpuid_checkpass(CPU, 2));
4851 4873
4852 4874 mwait_size = CPU->cpu_m.mcpu_cpi->cpi_mwait.mon_max;
4853 4875 if (mwait_size == 0)
4854 4876 return (NULL);
4855 4877
4856 4878 /*
4857 4879 * kmem_alloc() returns cache line size aligned data for mwait_size
4858 4880 * allocations. mwait_size is currently cache line sized. Neither
4859 4881 * of these implementation details are guarantied to be true in the
4860 4882 * future.
4861 4883 *
4862 4884 * First try allocating mwait_size as kmem_alloc() currently returns
4863 4885 * correctly aligned memory. If kmem_alloc() does not return
4864 4886 * mwait_size aligned memory, then use mwait_size ROUNDUP.
4865 4887 *
4866 4888 * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we
4867 4889 * decide to free this memory.
4868 4890 */
4869 4891 ret = kmem_zalloc(mwait_size, KM_SLEEP);
4870 4892 if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) {
4871 4893 cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret;
4872 4894 cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size;
4873 4895 *ret = MWAIT_RUNNING;
4874 4896 return (ret);
4875 4897 } else {
4876 4898 kmem_free(ret, mwait_size);
4877 4899 ret = kmem_zalloc(mwait_size * 2, KM_SLEEP);
4878 4900 cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret;
4879 4901 cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2;
4880 4902 ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size);
4881 4903 *ret = MWAIT_RUNNING;
4882 4904 return (ret);
4883 4905 }
4884 4906 }
4885 4907
4886 4908 void
4887 4909 cpuid_mwait_free(cpu_t *cpu)
4888 4910 {
4889 4911 if (cpu->cpu_m.mcpu_cpi == NULL) {
4890 4912 return;
4891 4913 }
4892 4914
4893 4915 if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL &&
4894 4916 cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) {
4895 4917 kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual,
4896 4918 cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual);
4897 4919 }
4898 4920
4899 4921 cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL;
4900 4922 cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0;
4901 4923 }
4902 4924
4903 4925 void
4904 4926 patch_tsc_read(int flag)
4905 4927 {
4906 4928 size_t cnt;
4907 4929
4908 4930 switch (flag) {
4909 4931 case TSC_NONE:
4910 4932 cnt = &_no_rdtsc_end - &_no_rdtsc_start;
4911 4933 (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt);
4912 4934 break;
4913 4935 case TSC_RDTSC_MFENCE:
4914 4936 cnt = &_tsc_mfence_end - &_tsc_mfence_start;
4915 4937 (void) memcpy((void *)tsc_read,
4916 4938 (void *)&_tsc_mfence_start, cnt);
4917 4939 break;
4918 4940 case TSC_RDTSC_LFENCE:
4919 4941 cnt = &_tsc_lfence_end - &_tsc_lfence_start;
4920 4942 (void) memcpy((void *)tsc_read,
4921 4943 (void *)&_tsc_lfence_start, cnt);
4922 4944 break;
4923 4945 case TSC_TSCP:
4924 4946 cnt = &_tscp_end - &_tscp_start;
4925 4947 (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt);
4926 4948 break;
4927 4949 default:
4928 4950 /* Bail for unexpected TSC types. (TSC_NONE covers 0) */
4929 4951 cmn_err(CE_PANIC, "Unrecogized TSC type: %d", flag);
4930 4952 break;
4931 4953 }
4932 4954 tsc_type = flag;
4933 4955 }
4934 4956
4935 4957 int
4936 4958 cpuid_deep_cstates_supported(void)
4937 4959 {
4938 4960 struct cpuid_info *cpi;
4939 4961 struct cpuid_regs regs;
4940 4962
4941 4963 ASSERT(cpuid_checkpass(CPU, 1));
4942 4964
4943 4965 cpi = CPU->cpu_m.mcpu_cpi;
4944 4966
4945 4967 if (!is_x86_feature(x86_featureset, X86FSET_CPUID))
4946 4968 return (0);
4947 4969
4948 4970 switch (cpi->cpi_vendor) {
4949 4971 case X86_VENDOR_Intel:
4950 4972 if (cpi->cpi_xmaxeax < 0x80000007)
4951 4973 return (0);
4952 4974
4953 4975 /*
4954 4976 * TSC run at a constant rate in all ACPI C-states?
4955 4977 */
4956 4978 regs.cp_eax = 0x80000007;
4957 4979 (void) __cpuid_insn(®s);
4958 4980 return (regs.cp_edx & CPUID_TSC_CSTATE_INVARIANCE);
4959 4981
4960 4982 default:
4961 4983 return (0);
4962 4984 }
4963 4985 }
4964 4986
4965 4987 #endif /* !__xpv */
4966 4988
4967 4989 void
4968 4990 post_startup_cpu_fixups(void)
4969 4991 {
4970 4992 #ifndef __xpv
4971 4993 /*
4972 4994 * Some AMD processors support C1E state. Entering this state will
4973 4995 * cause the local APIC timer to stop, which we can't deal with at
4974 4996 * this time.
4975 4997 */
4976 4998 if (cpuid_getvendor(CPU) == X86_VENDOR_AMD) {
4977 4999 on_trap_data_t otd;
4978 5000 uint64_t reg;
4979 5001
4980 5002 if (!on_trap(&otd, OT_DATA_ACCESS)) {
4981 5003 reg = rdmsr(MSR_AMD_INT_PENDING_CMP_HALT);
4982 5004 /* Disable C1E state if it is enabled by BIOS */
4983 5005 if ((reg >> AMD_ACTONCMPHALT_SHIFT) &
4984 5006 AMD_ACTONCMPHALT_MASK) {
↓ open down ↓ |
3472 lines elided |
↑ open up ↑ |
4985 5007 reg &= ~(AMD_ACTONCMPHALT_MASK <<
4986 5008 AMD_ACTONCMPHALT_SHIFT);
4987 5009 wrmsr(MSR_AMD_INT_PENDING_CMP_HALT, reg);
4988 5010 }
4989 5011 }
4990 5012 no_trap();
4991 5013 }
4992 5014 #endif /* !__xpv */
4993 5015 }
4994 5016
5017 +void
5018 +enable_pcid(void)
5019 +{
5020 + if (x86_use_pcid == -1)
5021 + x86_use_pcid = is_x86_feature(x86_featureset, X86FSET_PCID);
5022 +
5023 + if (x86_use_invpcid == -1) {
5024 + x86_use_invpcid = is_x86_feature(x86_featureset,
5025 + X86FSET_INVPCID);
5026 + }
5027 +
5028 + if (!x86_use_pcid)
5029 + return;
5030 +
5031 + /*
5032 + * Intel say that on setting PCIDE, it immediately starts using the PCID
5033 + * bits; better make sure there's nothing there.
5034 + */
5035 + ASSERT((getcr3() & MMU_PAGEOFFSET) == PCID_NONE);
5036 +
5037 + setcr4(getcr4() | CR4_PCIDE);
5038 +}
5039 +
4995 5040 /*
4996 5041 * Setup necessary registers to enable XSAVE feature on this processor.
4997 5042 * This function needs to be called early enough, so that no xsave/xrstor
4998 5043 * ops will execute on the processor before the MSRs are properly set up.
4999 5044 *
5000 5045 * Current implementation has the following assumption:
5001 5046 * - cpuid_pass1() is done, so that X86 features are known.
5002 5047 * - fpu_probe() is done, so that fp_save_mech is chosen.
5003 5048 */
5004 5049 void
5005 5050 xsave_setup_msr(cpu_t *cpu)
5006 5051 {
5007 5052 ASSERT(fp_save_mech == FP_XSAVE);
5008 5053 ASSERT(is_x86_feature(x86_featureset, X86FSET_XSAVE));
5009 5054
5010 5055 /* Enable OSXSAVE in CR4. */
5011 5056 setcr4(getcr4() | CR4_OSXSAVE);
5012 5057 /*
5013 5058 * Update SW copy of ECX, so that /dev/cpu/self/cpuid will report
5014 5059 * correct value.
5015 5060 */
5016 5061 cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_ecx |= CPUID_INTC_ECX_OSXSAVE;
5017 5062 setup_xfem();
5018 5063 }
5019 5064
5020 5065 /*
5021 5066 * Starting with the Westmere processor the local
5022 5067 * APIC timer will continue running in all C-states,
5023 5068 * including the deepest C-states.
5024 5069 */
5025 5070 int
5026 5071 cpuid_arat_supported(void)
5027 5072 {
5028 5073 struct cpuid_info *cpi;
5029 5074 struct cpuid_regs regs;
5030 5075
5031 5076 ASSERT(cpuid_checkpass(CPU, 1));
5032 5077 ASSERT(is_x86_feature(x86_featureset, X86FSET_CPUID));
5033 5078
5034 5079 cpi = CPU->cpu_m.mcpu_cpi;
5035 5080
5036 5081 switch (cpi->cpi_vendor) {
5037 5082 case X86_VENDOR_Intel:
5038 5083 /*
5039 5084 * Always-running Local APIC Timer is
5040 5085 * indicated by CPUID.6.EAX[2].
5041 5086 */
5042 5087 if (cpi->cpi_maxeax >= 6) {
5043 5088 regs.cp_eax = 6;
5044 5089 (void) cpuid_insn(NULL, ®s);
5045 5090 return (regs.cp_eax & CPUID_CSTATE_ARAT);
5046 5091 } else {
5047 5092 return (0);
5048 5093 }
5049 5094 default:
5050 5095 return (0);
5051 5096 }
5052 5097 }
5053 5098
5054 5099 /*
5055 5100 * Check support for Intel ENERGY_PERF_BIAS feature
5056 5101 */
5057 5102 int
5058 5103 cpuid_iepb_supported(struct cpu *cp)
5059 5104 {
5060 5105 struct cpuid_info *cpi = cp->cpu_m.mcpu_cpi;
5061 5106 struct cpuid_regs regs;
5062 5107
5063 5108 ASSERT(cpuid_checkpass(cp, 1));
5064 5109
5065 5110 if (!(is_x86_feature(x86_featureset, X86FSET_CPUID)) ||
5066 5111 !(is_x86_feature(x86_featureset, X86FSET_MSR))) {
5067 5112 return (0);
5068 5113 }
5069 5114
5070 5115 /*
5071 5116 * Intel ENERGY_PERF_BIAS MSR is indicated by
5072 5117 * capability bit CPUID.6.ECX.3
5073 5118 */
5074 5119 if ((cpi->cpi_vendor != X86_VENDOR_Intel) || (cpi->cpi_maxeax < 6))
5075 5120 return (0);
5076 5121
5077 5122 regs.cp_eax = 0x6;
5078 5123 (void) cpuid_insn(NULL, ®s);
5079 5124 return (regs.cp_ecx & CPUID_EPB_SUPPORT);
5080 5125 }
5081 5126
5082 5127 /*
5083 5128 * Check support for TSC deadline timer
5084 5129 *
5085 5130 * TSC deadline timer provides a superior software programming
5086 5131 * model over local APIC timer that eliminates "time drifts".
5087 5132 * Instead of specifying a relative time, software specifies an
5088 5133 * absolute time as the target at which the processor should
5089 5134 * generate a timer event.
5090 5135 */
5091 5136 int
5092 5137 cpuid_deadline_tsc_supported(void)
5093 5138 {
5094 5139 struct cpuid_info *cpi = CPU->cpu_m.mcpu_cpi;
5095 5140 struct cpuid_regs regs;
5096 5141
5097 5142 ASSERT(cpuid_checkpass(CPU, 1));
5098 5143 ASSERT(is_x86_feature(x86_featureset, X86FSET_CPUID));
5099 5144
5100 5145 switch (cpi->cpi_vendor) {
5101 5146 case X86_VENDOR_Intel:
5102 5147 if (cpi->cpi_maxeax >= 1) {
5103 5148 regs.cp_eax = 1;
5104 5149 (void) cpuid_insn(NULL, ®s);
5105 5150 return (regs.cp_ecx & CPUID_DEADLINE_TSC);
5106 5151 } else {
5107 5152 return (0);
5108 5153 }
5109 5154 default:
5110 5155 return (0);
5111 5156 }
5112 5157 }
5113 5158
5114 5159 #if defined(__amd64) && !defined(__xpv)
5115 5160 /*
5116 5161 * Patch in versions of bcopy for high performance Intel Nhm processors
5117 5162 * and later...
5118 5163 */
5119 5164 void
5120 5165 patch_memops(uint_t vendor)
5121 5166 {
5122 5167 size_t cnt, i;
5123 5168 caddr_t to, from;
5124 5169
5125 5170 if ((vendor == X86_VENDOR_Intel) &&
5126 5171 is_x86_feature(x86_featureset, X86FSET_SSE4_2)) {
5127 5172 cnt = &bcopy_patch_end - &bcopy_patch_start;
5128 5173 to = &bcopy_ck_size;
5129 5174 from = &bcopy_patch_start;
5130 5175 for (i = 0; i < cnt; i++) {
5131 5176 *to++ = *from++;
5132 5177 }
5133 5178 }
5134 5179 }
5135 5180 #endif /* __amd64 && !__xpv */
5136 5181
5137 5182 /*
5138 5183 * This function finds the number of bits to represent the number of cores per
5139 5184 * chip and the number of strands per core for the Intel platforms.
5140 5185 * It re-uses the x2APIC cpuid code of the cpuid_pass2().
5141 5186 */
5142 5187 void
5143 5188 cpuid_get_ext_topo(uint_t vendor, uint_t *core_nbits, uint_t *strand_nbits)
5144 5189 {
5145 5190 struct cpuid_regs regs;
5146 5191 struct cpuid_regs *cp = ®s;
5147 5192
5148 5193 if (vendor != X86_VENDOR_Intel) {
5149 5194 return;
5150 5195 }
5151 5196
5152 5197 /* if the cpuid level is 0xB, extended topo is available. */
5153 5198 cp->cp_eax = 0;
5154 5199 if (__cpuid_insn(cp) >= 0xB) {
5155 5200
5156 5201 cp->cp_eax = 0xB;
5157 5202 cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0;
5158 5203 (void) __cpuid_insn(cp);
5159 5204
5160 5205 /*
5161 5206 * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which
5162 5207 * indicates that the extended topology enumeration leaf is
5163 5208 * available.
5164 5209 */
5165 5210 if (cp->cp_ebx) {
5166 5211 uint_t coreid_shift = 0;
5167 5212 uint_t chipid_shift = 0;
5168 5213 uint_t i;
5169 5214 uint_t level;
5170 5215
5171 5216 for (i = 0; i < CPI_FNB_ECX_MAX; i++) {
5172 5217 cp->cp_eax = 0xB;
5173 5218 cp->cp_ecx = i;
5174 5219
5175 5220 (void) __cpuid_insn(cp);
5176 5221 level = CPI_CPU_LEVEL_TYPE(cp);
5177 5222
5178 5223 if (level == 1) {
5179 5224 /*
5180 5225 * Thread level processor topology
5181 5226 * Number of bits shift right APIC ID
5182 5227 * to get the coreid.
5183 5228 */
5184 5229 coreid_shift = BITX(cp->cp_eax, 4, 0);
5185 5230 } else if (level == 2) {
5186 5231 /*
5187 5232 * Core level processor topology
5188 5233 * Number of bits shift right APIC ID
5189 5234 * to get the chipid.
5190 5235 */
5191 5236 chipid_shift = BITX(cp->cp_eax, 4, 0);
5192 5237 }
5193 5238 }
5194 5239
5195 5240 if (coreid_shift > 0 && chipid_shift > coreid_shift) {
5196 5241 *strand_nbits = coreid_shift;
5197 5242 *core_nbits = chipid_shift - coreid_shift;
5198 5243 }
5199 5244 }
5200 5245 }
5201 5246 }
↓ open down ↓ |
197 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX