2 * i386 CPUID helper functions
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "sysemu/kvm.h"
26 #include "sysemu/cpus.h"
30 #include "qemu/option.h"
31 #include "qemu/config-file.h"
32 #include "qapi/qmp/qerror.h"
34 #include "qapi-types.h"
35 #include "qapi-visit.h"
36 #include "qapi/visitor.h"
37 #include "sysemu/arch_init.h"
40 #if defined(CONFIG_KVM)
41 #include <linux/kvm_para.h>
44 #include "sysemu/sysemu.h"
45 #include "hw/qdev-properties.h"
46 #include "hw/cpu/icc_bus.h"
47 #ifndef CONFIG_USER_ONLY
48 #include "hw/xen/xen.h"
49 #include "hw/i386/apic_internal.h"
53 /* Cache topology CPUID constants: */
55 /* CPUID Leaf 2 Descriptors */
57 #define CPUID_2_L1D_32KB_8WAY_64B 0x2c
58 #define CPUID_2_L1I_32KB_8WAY_64B 0x30
59 #define CPUID_2_L2_2MB_8WAY_64B 0x7d
62 /* CPUID Leaf 4 constants: */
65 #define CPUID_4_TYPE_DCACHE 1
66 #define CPUID_4_TYPE_ICACHE 2
67 #define CPUID_4_TYPE_UNIFIED 3
69 #define CPUID_4_LEVEL(l) ((l) << 5)
71 #define CPUID_4_SELF_INIT_LEVEL (1 << 8)
72 #define CPUID_4_FULLY_ASSOC (1 << 9)
75 #define CPUID_4_NO_INVD_SHARING (1 << 0)
76 #define CPUID_4_INCLUSIVE (1 << 1)
77 #define CPUID_4_COMPLEX_IDX (1 << 2)
79 #define ASSOC_FULL 0xFF
81 /* AMD associativity encoding used on CPUID Leaf 0x80000006: */
82 #define AMD_ENC_ASSOC(a) (a <= 1 ? a : \
92 a == ASSOC_FULL ? 0xF : \
93 0 /* invalid value */)
96 /* Definitions of the hardcoded cache entries we expose: */
99 #define L1D_LINE_SIZE 64
100 #define L1D_ASSOCIATIVITY 8
102 #define L1D_PARTITIONS 1
103 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 32KiB */
104 #define L1D_DESCRIPTOR CPUID_2_L1D_32KB_8WAY_64B
105 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */
106 #define L1D_LINES_PER_TAG 1
107 #define L1D_SIZE_KB_AMD 64
108 #define L1D_ASSOCIATIVITY_AMD 2
110 /* L1 instruction cache: */
111 #define L1I_LINE_SIZE 64
112 #define L1I_ASSOCIATIVITY 8
114 #define L1I_PARTITIONS 1
115 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 32KiB */
116 #define L1I_DESCRIPTOR CPUID_2_L1I_32KB_8WAY_64B
117 /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */
118 #define L1I_LINES_PER_TAG 1
119 #define L1I_SIZE_KB_AMD 64
120 #define L1I_ASSOCIATIVITY_AMD 2
122 /* Level 2 unified cache: */
123 #define L2_LINE_SIZE 64
124 #define L2_ASSOCIATIVITY 16
126 #define L2_PARTITIONS 1
127 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 4MiB */
128 /*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */
129 #define L2_DESCRIPTOR CPUID_2_L2_2MB_8WAY_64B
130 /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */
131 #define L2_LINES_PER_TAG 1
132 #define L2_SIZE_KB_AMD 512
135 #define L3_SIZE_KB 0 /* disabled */
136 #define L3_ASSOCIATIVITY 0 /* disabled */
137 #define L3_LINES_PER_TAG 0 /* disabled */
138 #define L3_LINE_SIZE 0 /* disabled */
140 /* TLB definitions: */
142 #define L1_DTLB_2M_ASSOC 1
143 #define L1_DTLB_2M_ENTRIES 255
144 #define L1_DTLB_4K_ASSOC 1
145 #define L1_DTLB_4K_ENTRIES 255
147 #define L1_ITLB_2M_ASSOC 1
148 #define L1_ITLB_2M_ENTRIES 255
149 #define L1_ITLB_4K_ASSOC 1
150 #define L1_ITLB_4K_ENTRIES 255
152 #define L2_DTLB_2M_ASSOC 0 /* disabled */
153 #define L2_DTLB_2M_ENTRIES 0 /* disabled */
154 #define L2_DTLB_4K_ASSOC 4
155 #define L2_DTLB_4K_ENTRIES 512
157 #define L2_ITLB_2M_ASSOC 0 /* disabled */
158 #define L2_ITLB_2M_ENTRIES 0 /* disabled */
159 #define L2_ITLB_4K_ASSOC 4
160 #define L2_ITLB_4K_ENTRIES 512
164 static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
165 uint32_t vendor2, uint32_t vendor3)
168 for (i = 0; i < 4; i++) {
169 dst[i] = vendor1 >> (8 * i);
170 dst[i + 4] = vendor2 >> (8 * i);
171 dst[i + 8] = vendor3 >> (8 * i);
173 dst[CPUID_VENDOR_SZ] = '\0';
176 /* feature flags taken from "Intel Processor Identification and the CPUID
177 * Instruction" and AMD's "CPUID Specification". In cases of disagreement
178 * between feature naming conventions, aliases may be added.
180 static const char *feature_name[] = {
181 "fpu", "vme", "de", "pse",
182 "tsc", "msr", "pae", "mce",
183 "cx8", "apic", NULL, "sep",
184 "mtrr", "pge", "mca", "cmov",
185 "pat", "pse36", "pn" /* Intel psn */, "clflush" /* Intel clfsh */,
186 NULL, "ds" /* Intel dts */, "acpi", "mmx",
187 "fxsr", "sse", "sse2", "ss",
188 "ht" /* Intel htt */, "tm", "ia64", "pbe",
190 static const char *ext_feature_name[] = {
191 "pni|sse3" /* Intel,AMD sse3 */, "pclmulqdq|pclmuldq", "dtes64", "monitor",
192 "ds_cpl", "vmx", "smx", "est",
193 "tm2", "ssse3", "cid", NULL,
194 "fma", "cx16", "xtpr", "pdcm",
195 NULL, "pcid", "dca", "sse4.1|sse4_1",
196 "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
197 "tsc-deadline", "aes", "xsave", "osxsave",
198 "avx", "f16c", "rdrand", "hypervisor",
200 /* Feature names that are already defined on feature_name[] but are set on
201 * CPUID[8000_0001].EDX on AMD CPUs don't have their names on
202 * ext2_feature_name[]. They are copied automatically to cpuid_ext2_features
203 * if and only if CPU vendor is AMD.
205 static const char *ext2_feature_name[] = {
206 NULL /* fpu */, NULL /* vme */, NULL /* de */, NULL /* pse */,
207 NULL /* tsc */, NULL /* msr */, NULL /* pae */, NULL /* mce */,
208 NULL /* cx8 */ /* AMD CMPXCHG8B */, NULL /* apic */, NULL, "syscall",
209 NULL /* mtrr */, NULL /* pge */, NULL /* mca */, NULL /* cmov */,
210 NULL /* pat */, NULL /* pse36 */, NULL, NULL /* Linux mp */,
211 "nx|xd", NULL, "mmxext", NULL /* mmx */,
212 NULL /* fxsr */, "fxsr_opt|ffxsr", "pdpe1gb" /* AMD Page1GB */, "rdtscp",
213 NULL, "lm|i64", "3dnowext", "3dnow",
215 static const char *ext3_feature_name[] = {
216 "lahf_lm" /* AMD LahfSahf */, "cmp_legacy", "svm", "extapic" /* AMD ExtApicSpace */,
217 "cr8legacy" /* AMD AltMovCr8 */, "abm", "sse4a", "misalignsse",
218 "3dnowprefetch", "osvw", "ibs", "xop",
219 "skinit", "wdt", NULL, "lwp",
220 "fma4", "tce", NULL, "nodeid_msr",
221 NULL, "tbm", "topoext", "perfctr_core",
222 "perfctr_nb", NULL, NULL, NULL,
223 NULL, NULL, NULL, NULL,
226 static const char *ext4_feature_name[] = {
227 NULL, NULL, "xstore", "xstore-en",
228 NULL, NULL, "xcrypt", "xcrypt-en",
229 "ace2", "ace2-en", "phe", "phe-en",
230 "pmm", "pmm-en", NULL, NULL,
231 NULL, NULL, NULL, NULL,
232 NULL, NULL, NULL, NULL,
233 NULL, NULL, NULL, NULL,
234 NULL, NULL, NULL, NULL,
237 static const char *kvm_feature_name[] = {
238 "kvmclock", "kvm_nopiodelay", "kvm_mmu", "kvmclock",
239 "kvm_asyncpf", "kvm_steal_time", "kvm_pv_eoi", "kvm_pv_unhalt",
240 NULL, NULL, NULL, NULL,
241 NULL, NULL, NULL, NULL,
242 NULL, NULL, NULL, NULL,
243 NULL, NULL, NULL, NULL,
244 NULL, NULL, NULL, NULL,
245 NULL, NULL, NULL, NULL,
248 static const char *svm_feature_name[] = {
249 "npt", "lbrv", "svm_lock", "nrip_save",
250 "tsc_scale", "vmcb_clean", "flushbyasid", "decodeassists",
251 NULL, NULL, "pause_filter", NULL,
252 "pfthreshold", NULL, NULL, NULL,
253 NULL, NULL, NULL, NULL,
254 NULL, NULL, NULL, NULL,
255 NULL, NULL, NULL, NULL,
256 NULL, NULL, NULL, NULL,
259 static const char *cpuid_7_0_ebx_feature_name[] = {
260 "fsgsbase", NULL, NULL, "bmi1", "hle", "avx2", NULL, "smep",
261 "bmi2", "erms", "invpcid", "rtm", NULL, NULL, NULL, NULL,
262 NULL, NULL, "rdseed", "adx", "smap", NULL, NULL, NULL,
263 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
266 typedef struct FeatureWordInfo {
267 const char **feat_names;
268 uint32_t cpuid_eax; /* Input EAX for CPUID */
269 bool cpuid_needs_ecx; /* CPUID instruction uses ECX as input */
270 uint32_t cpuid_ecx; /* Input ECX value for CPUID */
271 int cpuid_reg; /* output register (R_* constant) */
274 static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
276 .feat_names = feature_name,
277 .cpuid_eax = 1, .cpuid_reg = R_EDX,
280 .feat_names = ext_feature_name,
281 .cpuid_eax = 1, .cpuid_reg = R_ECX,
283 [FEAT_8000_0001_EDX] = {
284 .feat_names = ext2_feature_name,
285 .cpuid_eax = 0x80000001, .cpuid_reg = R_EDX,
287 [FEAT_8000_0001_ECX] = {
288 .feat_names = ext3_feature_name,
289 .cpuid_eax = 0x80000001, .cpuid_reg = R_ECX,
291 [FEAT_C000_0001_EDX] = {
292 .feat_names = ext4_feature_name,
293 .cpuid_eax = 0xC0000001, .cpuid_reg = R_EDX,
296 .feat_names = kvm_feature_name,
297 .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EAX,
300 .feat_names = svm_feature_name,
301 .cpuid_eax = 0x8000000A, .cpuid_reg = R_EDX,
304 .feat_names = cpuid_7_0_ebx_feature_name,
306 .cpuid_needs_ecx = true, .cpuid_ecx = 0,
311 typedef struct X86RegisterInfo32 {
312 /* Name of register */
314 /* QAPI enum value register */
315 X86CPURegister32 qapi_enum;
318 #define REGISTER(reg) \
319 [R_##reg] = { .name = #reg, .qapi_enum = X86_CPU_REGISTER32_##reg }
320 static const X86RegisterInfo32 x86_reg_info_32[CPU_NB_REGS32] = {
332 typedef struct ExtSaveArea {
333 uint32_t feature, bits;
334 uint32_t offset, size;
337 static const ExtSaveArea ext_save_areas[] = {
338 [2] = { .feature = FEAT_1_ECX, .bits = CPUID_EXT_AVX,
339 .offset = 0x240, .size = 0x100 },
340 [3] = { .feature = FEAT_7_0_EBX, .bits = CPUID_7_0_EBX_MPX,
341 .offset = 0x3c0, .size = 0x40 },
342 [4] = { .feature = FEAT_7_0_EBX, .bits = CPUID_7_0_EBX_MPX,
343 .offset = 0x400, .size = 0x40 },
346 const char *get_register_name_32(unsigned int reg)
348 if (reg >= CPU_NB_REGS32) {
351 return x86_reg_info_32[reg].name;
354 /* collects per-function cpuid data
356 typedef struct model_features_t {
357 uint32_t *guest_feat;
359 FeatureWord feat_word;
362 /* KVM-specific features that are automatically added to all CPU models
363 * when KVM is enabled.
365 static uint32_t kvm_default_features[FEATURE_WORDS] = {
366 [FEAT_KVM] = (1 << KVM_FEATURE_CLOCKSOURCE) |
367 (1 << KVM_FEATURE_NOP_IO_DELAY) |
368 (1 << KVM_FEATURE_CLOCKSOURCE2) |
369 (1 << KVM_FEATURE_ASYNC_PF) |
370 (1 << KVM_FEATURE_STEAL_TIME) |
371 (1 << KVM_FEATURE_PV_EOI) |
372 (1 << KVM_FEATURE_CLOCKSOURCE_STABLE_BIT),
373 [FEAT_1_ECX] = CPUID_EXT_X2APIC,
376 /* Features that are not added by default to any CPU model when KVM is enabled.
378 static uint32_t kvm_default_unset_features[FEATURE_WORDS] = {
379 [FEAT_1_ECX] = CPUID_EXT_MONITOR,
382 void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features)
384 kvm_default_features[w] &= ~features;
387 void host_cpuid(uint32_t function, uint32_t count,
388 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
394 : "=a"(vec[0]), "=b"(vec[1]),
395 "=c"(vec[2]), "=d"(vec[3])
396 : "0"(function), "c"(count) : "cc");
397 #elif defined(__i386__)
398 asm volatile("pusha \n\t"
400 "mov %%eax, 0(%2) \n\t"
401 "mov %%ebx, 4(%2) \n\t"
402 "mov %%ecx, 8(%2) \n\t"
403 "mov %%edx, 12(%2) \n\t"
405 : : "a"(function), "c"(count), "S"(vec)
421 #define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
423 /* general substring compare of *[s1..e1) and *[s2..e2). sx is start of
424 * a substring. ex if !NULL points to the first char after a substring,
425 * otherwise the string is assumed to sized by a terminating nul.
426 * Return lexical ordering of *s1:*s2.
428 static int sstrcmp(const char *s1, const char *e1, const char *s2,
432 if (!*s1 || !*s2 || *s1 != *s2)
435 if (s1 == e1 && s2 == e2)
444 /* compare *[s..e) to *altstr. *altstr may be a simple string or multiple
445 * '|' delimited (possibly empty) strings in which case search for a match
446 * within the alternatives proceeds left to right. Return 0 for success,
447 * non-zero otherwise.
449 static int altcmp(const char *s, const char *e, const char *altstr)
453 for (q = p = altstr; ; ) {
454 while (*p && *p != '|')
456 if ((q == p && !*s) || (q != p && !sstrcmp(s, e, q, p)))
465 /* search featureset for flag *[s..e), if found set corresponding bit in
466 * *pval and return true, otherwise return false
468 static bool lookup_feature(uint32_t *pval, const char *s, const char *e,
469 const char **featureset)
475 for (mask = 1, ppc = featureset; mask; mask <<= 1, ++ppc) {
476 if (*ppc && !altcmp(s, e, *ppc)) {
484 static void add_flagname_to_bitmaps(const char *flagname,
485 FeatureWordArray words)
488 for (w = 0; w < FEATURE_WORDS; w++) {
489 FeatureWordInfo *wi = &feature_word_info[w];
490 if (wi->feat_names &&
491 lookup_feature(&words[w], flagname, NULL, wi->feat_names)) {
495 if (w == FEATURE_WORDS) {
496 fprintf(stderr, "CPU feature %s not found\n", flagname);
500 /* CPU class name definitions: */
502 #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
503 #define X86_CPU_TYPE_NAME(name) (name X86_CPU_TYPE_SUFFIX)
505 /* Return type name for a given CPU model name
506 * Caller is responsible for freeing the returned string.
508 static char *x86_cpu_type_name(const char *model_name)
510 return g_strdup_printf(X86_CPU_TYPE_NAME("%s"), model_name);
513 static ObjectClass *x86_cpu_class_by_name(const char *cpu_model)
518 if (cpu_model == NULL) {
522 typename = x86_cpu_type_name(cpu_model);
523 oc = object_class_by_name(typename);
528 struct X86CPUDefinition {
533 /* vendor is zero-terminated, 12 character ASCII string */
534 char vendor[CPUID_VENDOR_SZ + 1];
538 FeatureWordArray features;
540 bool cache_info_passthrough;
543 #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
544 #define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
545 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
546 #define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \
547 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
548 CPUID_PSE36 | CPUID_FXSR)
549 #define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE)
550 #define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \
551 CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \
552 CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \
553 CPUID_PAE | CPUID_SEP | CPUID_APIC)
555 #define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \
556 CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \
557 CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \
558 CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \
559 CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS)
560 /* partly implemented:
561 CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64) */
563 CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */
564 #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \
565 CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \
566 CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \
567 CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR)
569 CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX,
570 CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA,
571 CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA,
572 CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE,
573 CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C,
577 #define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM)
579 #define TCG_EXT2_X86_64_FEATURES 0
582 #define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \
583 CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \
584 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_PDPE1GB | \
585 TCG_EXT2_X86_64_FEATURES)
586 #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
587 CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)
588 #define TCG_EXT4_FEATURES 0
589 #define TCG_SVM_FEATURES 0
590 #define TCG_KVM_FEATURES 0
591 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \
592 CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)
594 CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
595 CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
596 CPUID_7_0_EBX_RDSEED */
598 static X86CPUDefinition builtin_x86_defs[] = {
602 .vendor = CPUID_VENDOR_AMD,
606 .features[FEAT_1_EDX] =
608 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
610 .features[FEAT_1_ECX] =
611 CPUID_EXT_SSE3 | CPUID_EXT_CX16 | CPUID_EXT_POPCNT,
612 .features[FEAT_8000_0001_EDX] =
613 (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
614 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
615 .features[FEAT_8000_0001_ECX] =
616 CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM |
617 CPUID_EXT3_ABM | CPUID_EXT3_SSE4A,
618 .xlevel = 0x8000000A,
623 .vendor = CPUID_VENDOR_AMD,
627 .features[FEAT_1_EDX] =
629 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
630 CPUID_PSE36 | CPUID_VME | CPUID_HT,
631 .features[FEAT_1_ECX] =
632 CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_CX16 |
634 .features[FEAT_8000_0001_EDX] =
635 (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
636 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX |
637 CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_MMXEXT |
638 CPUID_EXT2_FFXSR | CPUID_EXT2_PDPE1GB | CPUID_EXT2_RDTSCP,
639 /* Missing: CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
641 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
642 CPUID_EXT3_OSVW, CPUID_EXT3_IBS */
643 .features[FEAT_8000_0001_ECX] =
644 CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM |
645 CPUID_EXT3_ABM | CPUID_EXT3_SSE4A,
646 .features[FEAT_SVM] =
647 CPUID_SVM_NPT | CPUID_SVM_LBRV,
648 .xlevel = 0x8000001A,
649 .model_id = "AMD Phenom(tm) 9550 Quad-Core Processor"
654 .vendor = CPUID_VENDOR_INTEL,
658 .features[FEAT_1_EDX] =
660 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
661 CPUID_PSE36 | CPUID_VME | CPUID_DTS | CPUID_ACPI | CPUID_SS |
662 CPUID_HT | CPUID_TM | CPUID_PBE,
663 .features[FEAT_1_ECX] =
664 CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 |
665 CPUID_EXT_DTES64 | CPUID_EXT_DSCPL | CPUID_EXT_VMX | CPUID_EXT_EST |
666 CPUID_EXT_TM2 | CPUID_EXT_CX16 | CPUID_EXT_XTPR | CPUID_EXT_PDCM,
667 .features[FEAT_8000_0001_EDX] =
668 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
669 .features[FEAT_8000_0001_ECX] =
671 .xlevel = 0x80000008,
672 .model_id = "Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz",
677 .vendor = CPUID_VENDOR_INTEL,
681 /* Missing: CPUID_VME, CPUID_HT */
682 .features[FEAT_1_EDX] =
684 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
686 /* Missing: CPUID_EXT_POPCNT, CPUID_EXT_MONITOR */
687 .features[FEAT_1_ECX] =
688 CPUID_EXT_SSE3 | CPUID_EXT_CX16,
689 /* Missing: CPUID_EXT2_PDPE1GB, CPUID_EXT2_RDTSCP */
690 .features[FEAT_8000_0001_EDX] =
691 (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
692 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
693 /* Missing: CPUID_EXT3_LAHF_LM, CPUID_EXT3_CMP_LEG, CPUID_EXT3_EXTAPIC,
694 CPUID_EXT3_CR8LEG, CPUID_EXT3_ABM, CPUID_EXT3_SSE4A,
695 CPUID_EXT3_MISALIGNSSE, CPUID_EXT3_3DNOWPREFETCH,
696 CPUID_EXT3_OSVW, CPUID_EXT3_IBS, CPUID_EXT3_SVM */
697 .features[FEAT_8000_0001_ECX] =
699 .xlevel = 0x80000008,
700 .model_id = "Common KVM processor"
705 .vendor = CPUID_VENDOR_INTEL,
709 .features[FEAT_1_EDX] =
711 .features[FEAT_1_ECX] =
712 CPUID_EXT_SSE3 | CPUID_EXT_POPCNT,
713 .xlevel = 0x80000004,
718 .vendor = CPUID_VENDOR_INTEL,
722 .features[FEAT_1_EDX] =
724 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_PSE36,
725 .features[FEAT_1_ECX] =
727 .features[FEAT_8000_0001_EDX] =
728 PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES,
729 .features[FEAT_8000_0001_ECX] =
731 .xlevel = 0x80000008,
732 .model_id = "Common 32-bit KVM processor"
737 .vendor = CPUID_VENDOR_INTEL,
741 .features[FEAT_1_EDX] =
742 PPRO_FEATURES | CPUID_VME |
743 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_DTS | CPUID_ACPI |
744 CPUID_SS | CPUID_HT | CPUID_TM | CPUID_PBE,
745 .features[FEAT_1_ECX] =
746 CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_VMX |
747 CPUID_EXT_EST | CPUID_EXT_TM2 | CPUID_EXT_XTPR | CPUID_EXT_PDCM,
748 .features[FEAT_8000_0001_EDX] =
750 .xlevel = 0x80000008,
751 .model_id = "Genuine Intel(R) CPU T2600 @ 2.16GHz",
756 .vendor = CPUID_VENDOR_INTEL,
760 .features[FEAT_1_EDX] =
767 .vendor = CPUID_VENDOR_INTEL,
771 .features[FEAT_1_EDX] =
778 .vendor = CPUID_VENDOR_INTEL,
782 .features[FEAT_1_EDX] =
789 .vendor = CPUID_VENDOR_INTEL,
793 .features[FEAT_1_EDX] =
800 .vendor = CPUID_VENDOR_AMD,
804 .features[FEAT_1_EDX] =
805 PPRO_FEATURES | CPUID_PSE36 | CPUID_VME | CPUID_MTRR |
807 .features[FEAT_8000_0001_EDX] =
808 (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
809 CPUID_EXT2_MMXEXT | CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT,
810 .xlevel = 0x80000008,
814 /* original is on level 10 */
816 .vendor = CPUID_VENDOR_INTEL,
820 .features[FEAT_1_EDX] =
822 CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA | CPUID_VME | CPUID_DTS |
823 CPUID_ACPI | CPUID_SS | CPUID_HT | CPUID_TM | CPUID_PBE,
824 /* Some CPUs got no CPUID_SEP */
825 .features[FEAT_1_ECX] =
826 CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 |
827 CPUID_EXT_DSCPL | CPUID_EXT_EST | CPUID_EXT_TM2 | CPUID_EXT_XTPR |
829 .features[FEAT_8000_0001_EDX] =
830 (PPRO_FEATURES & CPUID_EXT2_AMD_ALIASES) |
832 .features[FEAT_8000_0001_ECX] =
834 .xlevel = 0x8000000A,
835 .model_id = "Intel(R) Atom(TM) CPU N270 @ 1.60GHz",
840 .vendor = CPUID_VENDOR_INTEL,
844 .features[FEAT_1_EDX] =
845 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
846 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
847 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
848 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
849 CPUID_DE | CPUID_FP87,
850 .features[FEAT_1_ECX] =
851 CPUID_EXT_SSSE3 | CPUID_EXT_SSE3,
852 .features[FEAT_8000_0001_EDX] =
853 CPUID_EXT2_LM | CPUID_EXT2_NX | CPUID_EXT2_SYSCALL,
854 .features[FEAT_8000_0001_ECX] =
856 .xlevel = 0x8000000A,
857 .model_id = "Intel Celeron_4x0 (Conroe/Merom Class Core 2)",
862 .vendor = CPUID_VENDOR_INTEL,
866 .features[FEAT_1_EDX] =
867 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
868 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
869 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
870 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
871 CPUID_DE | CPUID_FP87,
872 .features[FEAT_1_ECX] =
873 CPUID_EXT_SSE41 | CPUID_EXT_CX16 | CPUID_EXT_SSSE3 |
875 .features[FEAT_8000_0001_EDX] =
876 CPUID_EXT2_LM | CPUID_EXT2_NX | CPUID_EXT2_SYSCALL,
877 .features[FEAT_8000_0001_ECX] =
879 .xlevel = 0x8000000A,
880 .model_id = "Intel Core 2 Duo P9xxx (Penryn Class Core 2)",
885 .vendor = CPUID_VENDOR_INTEL,
889 .features[FEAT_1_EDX] =
890 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
891 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
892 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
893 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
894 CPUID_DE | CPUID_FP87,
895 .features[FEAT_1_ECX] =
896 CPUID_EXT_POPCNT | CPUID_EXT_SSE42 | CPUID_EXT_SSE41 |
897 CPUID_EXT_CX16 | CPUID_EXT_SSSE3 | CPUID_EXT_SSE3,
898 .features[FEAT_8000_0001_EDX] =
899 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
900 .features[FEAT_8000_0001_ECX] =
902 .xlevel = 0x8000000A,
903 .model_id = "Intel Core i7 9xx (Nehalem Class Core i7)",
908 .vendor = CPUID_VENDOR_INTEL,
912 .features[FEAT_1_EDX] =
913 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
914 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
915 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
916 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
917 CPUID_DE | CPUID_FP87,
918 .features[FEAT_1_ECX] =
919 CPUID_EXT_AES | CPUID_EXT_POPCNT | CPUID_EXT_SSE42 |
920 CPUID_EXT_SSE41 | CPUID_EXT_CX16 | CPUID_EXT_SSSE3 |
921 CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSE3,
922 .features[FEAT_8000_0001_EDX] =
923 CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
924 .features[FEAT_8000_0001_ECX] =
926 .xlevel = 0x8000000A,
927 .model_id = "Westmere E56xx/L56xx/X56xx (Nehalem-C)",
930 .name = "SandyBridge",
932 .vendor = CPUID_VENDOR_INTEL,
936 .features[FEAT_1_EDX] =
937 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
938 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
939 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
940 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
941 CPUID_DE | CPUID_FP87,
942 .features[FEAT_1_ECX] =
943 CPUID_EXT_AVX | CPUID_EXT_XSAVE | CPUID_EXT_AES |
944 CPUID_EXT_TSC_DEADLINE_TIMER | CPUID_EXT_POPCNT |
945 CPUID_EXT_X2APIC | CPUID_EXT_SSE42 | CPUID_EXT_SSE41 |
946 CPUID_EXT_CX16 | CPUID_EXT_SSSE3 | CPUID_EXT_PCLMULQDQ |
948 .features[FEAT_8000_0001_EDX] =
949 CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPUID_EXT2_NX |
951 .features[FEAT_8000_0001_ECX] =
953 .xlevel = 0x8000000A,
954 .model_id = "Intel Xeon E312xx (Sandy Bridge)",
959 .vendor = CPUID_VENDOR_INTEL,
963 .features[FEAT_1_EDX] =
964 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
965 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
966 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
967 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
968 CPUID_DE | CPUID_FP87,
969 .features[FEAT_1_ECX] =
970 CPUID_EXT_AVX | CPUID_EXT_XSAVE | CPUID_EXT_AES |
971 CPUID_EXT_POPCNT | CPUID_EXT_X2APIC | CPUID_EXT_SSE42 |
972 CPUID_EXT_SSE41 | CPUID_EXT_CX16 | CPUID_EXT_SSSE3 |
973 CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSE3 |
974 CPUID_EXT_TSC_DEADLINE_TIMER | CPUID_EXT_FMA | CPUID_EXT_MOVBE |
976 .features[FEAT_8000_0001_EDX] =
977 CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPUID_EXT2_NX |
979 .features[FEAT_8000_0001_ECX] =
981 .features[FEAT_7_0_EBX] =
982 CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 |
983 CPUID_7_0_EBX_HLE | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_SMEP |
984 CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_INVPCID |
986 .xlevel = 0x8000000A,
987 .model_id = "Intel Core Processor (Haswell)",
990 .name = "Opteron_G1",
992 .vendor = CPUID_VENDOR_AMD,
996 .features[FEAT_1_EDX] =
997 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
998 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
999 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
1000 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
1001 CPUID_DE | CPUID_FP87,
1002 .features[FEAT_1_ECX] =
1004 .features[FEAT_8000_0001_EDX] =
1005 CPUID_EXT2_LM | CPUID_EXT2_FXSR | CPUID_EXT2_MMX |
1006 CPUID_EXT2_NX | CPUID_EXT2_PSE36 | CPUID_EXT2_PAT |
1007 CPUID_EXT2_CMOV | CPUID_EXT2_MCA | CPUID_EXT2_PGE |
1008 CPUID_EXT2_MTRR | CPUID_EXT2_SYSCALL | CPUID_EXT2_APIC |
1009 CPUID_EXT2_CX8 | CPUID_EXT2_MCE | CPUID_EXT2_PAE | CPUID_EXT2_MSR |
1010 CPUID_EXT2_TSC | CPUID_EXT2_PSE | CPUID_EXT2_DE | CPUID_EXT2_FPU,
1011 .xlevel = 0x80000008,
1012 .model_id = "AMD Opteron 240 (Gen 1 Class Opteron)",
1015 .name = "Opteron_G2",
1017 .vendor = CPUID_VENDOR_AMD,
1021 .features[FEAT_1_EDX] =
1022 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
1023 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
1024 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
1025 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
1026 CPUID_DE | CPUID_FP87,
1027 .features[FEAT_1_ECX] =
1028 CPUID_EXT_CX16 | CPUID_EXT_SSE3,
1029 .features[FEAT_8000_0001_EDX] =
1030 CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPUID_EXT2_FXSR |
1031 CPUID_EXT2_MMX | CPUID_EXT2_NX | CPUID_EXT2_PSE36 |
1032 CPUID_EXT2_PAT | CPUID_EXT2_CMOV | CPUID_EXT2_MCA |
1033 CPUID_EXT2_PGE | CPUID_EXT2_MTRR | CPUID_EXT2_SYSCALL |
1034 CPUID_EXT2_APIC | CPUID_EXT2_CX8 | CPUID_EXT2_MCE |
1035 CPUID_EXT2_PAE | CPUID_EXT2_MSR | CPUID_EXT2_TSC | CPUID_EXT2_PSE |
1036 CPUID_EXT2_DE | CPUID_EXT2_FPU,
1037 .features[FEAT_8000_0001_ECX] =
1038 CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM,
1039 .xlevel = 0x80000008,
1040 .model_id = "AMD Opteron 22xx (Gen 2 Class Opteron)",
1043 .name = "Opteron_G3",
1045 .vendor = CPUID_VENDOR_AMD,
1049 .features[FEAT_1_EDX] =
1050 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
1051 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
1052 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
1053 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
1054 CPUID_DE | CPUID_FP87,
1055 .features[FEAT_1_ECX] =
1056 CPUID_EXT_POPCNT | CPUID_EXT_CX16 | CPUID_EXT_MONITOR |
1058 .features[FEAT_8000_0001_EDX] =
1059 CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPUID_EXT2_FXSR |
1060 CPUID_EXT2_MMX | CPUID_EXT2_NX | CPUID_EXT2_PSE36 |
1061 CPUID_EXT2_PAT | CPUID_EXT2_CMOV | CPUID_EXT2_MCA |
1062 CPUID_EXT2_PGE | CPUID_EXT2_MTRR | CPUID_EXT2_SYSCALL |
1063 CPUID_EXT2_APIC | CPUID_EXT2_CX8 | CPUID_EXT2_MCE |
1064 CPUID_EXT2_PAE | CPUID_EXT2_MSR | CPUID_EXT2_TSC | CPUID_EXT2_PSE |
1065 CPUID_EXT2_DE | CPUID_EXT2_FPU,
1066 .features[FEAT_8000_0001_ECX] =
1067 CPUID_EXT3_MISALIGNSSE | CPUID_EXT3_SSE4A |
1068 CPUID_EXT3_ABM | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM,
1069 .xlevel = 0x80000008,
1070 .model_id = "AMD Opteron 23xx (Gen 3 Class Opteron)",
1073 .name = "Opteron_G4",
1075 .vendor = CPUID_VENDOR_AMD,
1079 .features[FEAT_1_EDX] =
1080 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
1081 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
1082 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
1083 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
1084 CPUID_DE | CPUID_FP87,
1085 .features[FEAT_1_ECX] =
1086 CPUID_EXT_AVX | CPUID_EXT_XSAVE | CPUID_EXT_AES |
1087 CPUID_EXT_POPCNT | CPUID_EXT_SSE42 | CPUID_EXT_SSE41 |
1088 CPUID_EXT_CX16 | CPUID_EXT_SSSE3 | CPUID_EXT_PCLMULQDQ |
1090 .features[FEAT_8000_0001_EDX] =
1091 CPUID_EXT2_LM | CPUID_EXT2_RDTSCP |
1092 CPUID_EXT2_PDPE1GB | CPUID_EXT2_FXSR | CPUID_EXT2_MMX |
1093 CPUID_EXT2_NX | CPUID_EXT2_PSE36 | CPUID_EXT2_PAT |
1094 CPUID_EXT2_CMOV | CPUID_EXT2_MCA | CPUID_EXT2_PGE |
1095 CPUID_EXT2_MTRR | CPUID_EXT2_SYSCALL | CPUID_EXT2_APIC |
1096 CPUID_EXT2_CX8 | CPUID_EXT2_MCE | CPUID_EXT2_PAE | CPUID_EXT2_MSR |
1097 CPUID_EXT2_TSC | CPUID_EXT2_PSE | CPUID_EXT2_DE | CPUID_EXT2_FPU,
1098 .features[FEAT_8000_0001_ECX] =
1099 CPUID_EXT3_FMA4 | CPUID_EXT3_XOP |
1100 CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_MISALIGNSSE |
1101 CPUID_EXT3_SSE4A | CPUID_EXT3_ABM | CPUID_EXT3_SVM |
1103 .xlevel = 0x8000001A,
1104 .model_id = "AMD Opteron 62xx class CPU",
1107 .name = "Opteron_G5",
1109 .vendor = CPUID_VENDOR_AMD,
1113 .features[FEAT_1_EDX] =
1114 CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX |
1115 CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | CPUID_MCA |
1116 CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | CPUID_CX8 |
1117 CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | CPUID_PSE |
1118 CPUID_DE | CPUID_FP87,
1119 .features[FEAT_1_ECX] =
1120 CPUID_EXT_F16C | CPUID_EXT_AVX | CPUID_EXT_XSAVE |
1121 CPUID_EXT_AES | CPUID_EXT_POPCNT | CPUID_EXT_SSE42 |
1122 CPUID_EXT_SSE41 | CPUID_EXT_CX16 | CPUID_EXT_FMA |
1123 CPUID_EXT_SSSE3 | CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSE3,
1124 .features[FEAT_8000_0001_EDX] =
1125 CPUID_EXT2_LM | CPUID_EXT2_RDTSCP |
1126 CPUID_EXT2_PDPE1GB | CPUID_EXT2_FXSR | CPUID_EXT2_MMX |
1127 CPUID_EXT2_NX | CPUID_EXT2_PSE36 | CPUID_EXT2_PAT |
1128 CPUID_EXT2_CMOV | CPUID_EXT2_MCA | CPUID_EXT2_PGE |
1129 CPUID_EXT2_MTRR | CPUID_EXT2_SYSCALL | CPUID_EXT2_APIC |
1130 CPUID_EXT2_CX8 | CPUID_EXT2_MCE | CPUID_EXT2_PAE | CPUID_EXT2_MSR |
1131 CPUID_EXT2_TSC | CPUID_EXT2_PSE | CPUID_EXT2_DE | CPUID_EXT2_FPU,
1132 .features[FEAT_8000_0001_ECX] =
1133 CPUID_EXT3_TBM | CPUID_EXT3_FMA4 | CPUID_EXT3_XOP |
1134 CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_MISALIGNSSE |
1135 CPUID_EXT3_SSE4A | CPUID_EXT3_ABM | CPUID_EXT3_SVM |
1137 .xlevel = 0x8000001A,
1138 .model_id = "AMD Opteron 63xx class CPU",
1143 * x86_cpu_compat_set_features:
1144 * @cpu_model: CPU model name to be changed. If NULL, all CPU models are changed
1145 * @w: Identifies the feature word to be changed.
1146 * @feat_add: Feature bits to be added to feature word
1147 * @feat_remove: Feature bits to be removed from feature word
1149 * Change CPU model feature bits for compatibility.
1151 * This function may be used by machine-type compatibility functions
1152 * to enable or disable feature bits on specific CPU models.
1154 void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
1155 uint32_t feat_add, uint32_t feat_remove)
1157 X86CPUDefinition *def;
1159 for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
1160 def = &builtin_x86_defs[i];
1161 if (!cpu_model || !strcmp(cpu_model, def->name)) {
1162 def->features[w] |= feat_add;
1163 def->features[w] &= ~feat_remove;
1170 static int cpu_x86_fill_model_id(char *str)
1172 uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
1175 for (i = 0; i < 3; i++) {
1176 host_cpuid(0x80000002 + i, 0, &eax, &ebx, &ecx, &edx);
1177 memcpy(str + i * 16 + 0, &eax, 4);
1178 memcpy(str + i * 16 + 4, &ebx, 4);
1179 memcpy(str + i * 16 + 8, &ecx, 4);
1180 memcpy(str + i * 16 + 12, &edx, 4);
1185 static X86CPUDefinition host_cpudef;
1187 /* class_init for the "host" CPU model
1189 * This function may be called before KVM is initialized.
1191 static void host_x86_cpu_class_init(ObjectClass *oc, void *data)
1193 X86CPUClass *xcc = X86_CPU_CLASS(oc);
1194 uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
1196 xcc->kvm_required = true;
1198 host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx);
1199 x86_cpu_vendor_words2str(host_cpudef.vendor, ebx, edx, ecx);
1201 host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx);
1202 host_cpudef.family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF);
1203 host_cpudef.model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12);
1204 host_cpudef.stepping = eax & 0x0F;
1206 cpu_x86_fill_model_id(host_cpudef.model_id);
1208 xcc->cpu_def = &host_cpudef;
1209 host_cpudef.cache_info_passthrough = true;
1211 /* level, xlevel, xlevel2, and the feature words are initialized on
1212 * instance_init, because they require KVM to be initialized.
1216 static void host_x86_cpu_initfn(Object *obj)
1218 X86CPU *cpu = X86_CPU(obj);
1219 CPUX86State *env = &cpu->env;
1220 KVMState *s = kvm_state;
1223 assert(kvm_enabled());
1225 env->cpuid_level = kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX);
1226 env->cpuid_xlevel = kvm_arch_get_supported_cpuid(s, 0x80000000, 0, R_EAX);
1227 env->cpuid_xlevel2 = kvm_arch_get_supported_cpuid(s, 0xC0000000, 0, R_EAX);
1229 for (w = 0; w < FEATURE_WORDS; w++) {
1230 FeatureWordInfo *wi = &feature_word_info[w];
1232 kvm_arch_get_supported_cpuid(s, wi->cpuid_eax, wi->cpuid_ecx,
1235 object_property_set_bool(OBJECT(cpu), true, "pmu", &error_abort);
1238 static const TypeInfo host_x86_cpu_type_info = {
1239 .name = X86_CPU_TYPE_NAME("host"),
1240 .parent = TYPE_X86_CPU,
1241 .instance_init = host_x86_cpu_initfn,
1242 .class_init = host_x86_cpu_class_init,
1247 static void report_unavailable_features(FeatureWord w, uint32_t mask)
1249 FeatureWordInfo *f = &feature_word_info[w];
1252 for (i = 0; i < 32; ++i) {
1253 if (1 << i & mask) {
1254 const char *reg = get_register_name_32(f->cpuid_reg);
1256 fprintf(stderr, "warning: host doesn't support requested feature: "
1257 "CPUID.%02XH:%s%s%s [bit %d]\n",
1259 f->feat_names[i] ? "." : "",
1260 f->feat_names[i] ? f->feat_names[i] : "", i);
1265 static void x86_cpuid_version_get_family(Object *obj, Visitor *v, void *opaque,
1266 const char *name, Error **errp)
1268 X86CPU *cpu = X86_CPU(obj);
1269 CPUX86State *env = &cpu->env;
1272 value = (env->cpuid_version >> 8) & 0xf;
1274 value += (env->cpuid_version >> 20) & 0xff;
1276 visit_type_int(v, &value, name, errp);
1279 static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque,
1280 const char *name, Error **errp)
1282 X86CPU *cpu = X86_CPU(obj);
1283 CPUX86State *env = &cpu->env;
1284 const int64_t min = 0;
1285 const int64_t max = 0xff + 0xf;
1286 Error *local_err = NULL;
1289 visit_type_int(v, &value, name, &local_err);
1291 error_propagate(errp, local_err);
1294 if (value < min || value > max) {
1295 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
1296 name ? name : "null", value, min, max);
1300 env->cpuid_version &= ~0xff00f00;
1302 env->cpuid_version |= 0xf00 | ((value - 0x0f) << 20);
1304 env->cpuid_version |= value << 8;
1308 static void x86_cpuid_version_get_model(Object *obj, Visitor *v, void *opaque,
1309 const char *name, Error **errp)
1311 X86CPU *cpu = X86_CPU(obj);
1312 CPUX86State *env = &cpu->env;
1315 value = (env->cpuid_version >> 4) & 0xf;
1316 value |= ((env->cpuid_version >> 16) & 0xf) << 4;
1317 visit_type_int(v, &value, name, errp);
1320 static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque,
1321 const char *name, Error **errp)
1323 X86CPU *cpu = X86_CPU(obj);
1324 CPUX86State *env = &cpu->env;
1325 const int64_t min = 0;
1326 const int64_t max = 0xff;
1327 Error *local_err = NULL;
1330 visit_type_int(v, &value, name, &local_err);
1332 error_propagate(errp, local_err);
1335 if (value < min || value > max) {
1336 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
1337 name ? name : "null", value, min, max);
1341 env->cpuid_version &= ~0xf00f0;
1342 env->cpuid_version |= ((value & 0xf) << 4) | ((value >> 4) << 16);
1345 static void x86_cpuid_version_get_stepping(Object *obj, Visitor *v,
1346 void *opaque, const char *name,
1349 X86CPU *cpu = X86_CPU(obj);
1350 CPUX86State *env = &cpu->env;
1353 value = env->cpuid_version & 0xf;
1354 visit_type_int(v, &value, name, errp);
1357 static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v,
1358 void *opaque, const char *name,
1361 X86CPU *cpu = X86_CPU(obj);
1362 CPUX86State *env = &cpu->env;
1363 const int64_t min = 0;
1364 const int64_t max = 0xf;
1365 Error *local_err = NULL;
1368 visit_type_int(v, &value, name, &local_err);
1370 error_propagate(errp, local_err);
1373 if (value < min || value > max) {
1374 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
1375 name ? name : "null", value, min, max);
1379 env->cpuid_version &= ~0xf;
1380 env->cpuid_version |= value & 0xf;
1383 static void x86_cpuid_get_level(Object *obj, Visitor *v, void *opaque,
1384 const char *name, Error **errp)
1386 X86CPU *cpu = X86_CPU(obj);
1388 visit_type_uint32(v, &cpu->env.cpuid_level, name, errp);
1391 static void x86_cpuid_set_level(Object *obj, Visitor *v, void *opaque,
1392 const char *name, Error **errp)
1394 X86CPU *cpu = X86_CPU(obj);
1396 visit_type_uint32(v, &cpu->env.cpuid_level, name, errp);
1399 static void x86_cpuid_get_xlevel(Object *obj, Visitor *v, void *opaque,
1400 const char *name, Error **errp)
1402 X86CPU *cpu = X86_CPU(obj);
1404 visit_type_uint32(v, &cpu->env.cpuid_xlevel, name, errp);
1407 static void x86_cpuid_set_xlevel(Object *obj, Visitor *v, void *opaque,
1408 const char *name, Error **errp)
1410 X86CPU *cpu = X86_CPU(obj);
1412 visit_type_uint32(v, &cpu->env.cpuid_xlevel, name, errp);
1415 static char *x86_cpuid_get_vendor(Object *obj, Error **errp)
1417 X86CPU *cpu = X86_CPU(obj);
1418 CPUX86State *env = &cpu->env;
1421 value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
1422 x86_cpu_vendor_words2str(value, env->cpuid_vendor1, env->cpuid_vendor2,
1423 env->cpuid_vendor3);
1427 static void x86_cpuid_set_vendor(Object *obj, const char *value,
1430 X86CPU *cpu = X86_CPU(obj);
1431 CPUX86State *env = &cpu->env;
1434 if (strlen(value) != CPUID_VENDOR_SZ) {
1435 error_set(errp, QERR_PROPERTY_VALUE_BAD, "",
1440 env->cpuid_vendor1 = 0;
1441 env->cpuid_vendor2 = 0;
1442 env->cpuid_vendor3 = 0;
1443 for (i = 0; i < 4; i++) {
1444 env->cpuid_vendor1 |= ((uint8_t)value[i ]) << (8 * i);
1445 env->cpuid_vendor2 |= ((uint8_t)value[i + 4]) << (8 * i);
1446 env->cpuid_vendor3 |= ((uint8_t)value[i + 8]) << (8 * i);
1450 static char *x86_cpuid_get_model_id(Object *obj, Error **errp)
1452 X86CPU *cpu = X86_CPU(obj);
1453 CPUX86State *env = &cpu->env;
1457 value = g_malloc(48 + 1);
1458 for (i = 0; i < 48; i++) {
1459 value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3));
1465 static void x86_cpuid_set_model_id(Object *obj, const char *model_id,
1468 X86CPU *cpu = X86_CPU(obj);
1469 CPUX86State *env = &cpu->env;
1472 if (model_id == NULL) {
1475 len = strlen(model_id);
1476 memset(env->cpuid_model, 0, 48);
1477 for (i = 0; i < 48; i++) {
1481 c = (uint8_t)model_id[i];
1483 env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
1487 static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque,
1488 const char *name, Error **errp)
1490 X86CPU *cpu = X86_CPU(obj);
1493 value = cpu->env.tsc_khz * 1000;
1494 visit_type_int(v, &value, name, errp);
1497 static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
1498 const char *name, Error **errp)
1500 X86CPU *cpu = X86_CPU(obj);
1501 const int64_t min = 0;
1502 const int64_t max = INT64_MAX;
1503 Error *local_err = NULL;
1506 visit_type_int(v, &value, name, &local_err);
1508 error_propagate(errp, local_err);
1511 if (value < min || value > max) {
1512 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
1513 name ? name : "null", value, min, max);
1517 cpu->env.tsc_khz = value / 1000;
1520 static void x86_cpuid_get_apic_id(Object *obj, Visitor *v, void *opaque,
1521 const char *name, Error **errp)
1523 X86CPU *cpu = X86_CPU(obj);
1524 int64_t value = cpu->env.cpuid_apic_id;
1526 visit_type_int(v, &value, name, errp);
1529 static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque,
1530 const char *name, Error **errp)
1532 X86CPU *cpu = X86_CPU(obj);
1533 DeviceState *dev = DEVICE(obj);
1534 const int64_t min = 0;
1535 const int64_t max = UINT32_MAX;
1536 Error *error = NULL;
1539 if (dev->realized) {
1540 error_setg(errp, "Attempt to set property '%s' on '%s' after "
1541 "it was realized", name, object_get_typename(obj));
1545 visit_type_int(v, &value, name, &error);
1547 error_propagate(errp, error);
1550 if (value < min || value > max) {
1551 error_setg(errp, "Property %s.%s doesn't take value %" PRId64
1552 " (minimum: %" PRId64 ", maximum: %" PRId64 ")" ,
1553 object_get_typename(obj), name, value, min, max);
1557 if ((value != cpu->env.cpuid_apic_id) && cpu_exists(value)) {
1558 error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value);
1561 cpu->env.cpuid_apic_id = value;
1564 /* Generic getter for "feature-words" and "filtered-features" properties */
1565 static void x86_cpu_get_feature_words(Object *obj, Visitor *v, void *opaque,
1566 const char *name, Error **errp)
1568 uint32_t *array = (uint32_t *)opaque;
1571 X86CPUFeatureWordInfo word_infos[FEATURE_WORDS] = { };
1572 X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS] = { };
1573 X86CPUFeatureWordInfoList *list = NULL;
1575 for (w = 0; w < FEATURE_WORDS; w++) {
1576 FeatureWordInfo *wi = &feature_word_info[w];
1577 X86CPUFeatureWordInfo *qwi = &word_infos[w];
1578 qwi->cpuid_input_eax = wi->cpuid_eax;
1579 qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx;
1580 qwi->cpuid_input_ecx = wi->cpuid_ecx;
1581 qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum;
1582 qwi->features = array[w];
1584 /* List will be in reverse order, but order shouldn't matter */
1585 list_entries[w].next = list;
1586 list_entries[w].value = &word_infos[w];
1587 list = &list_entries[w];
1590 visit_type_X86CPUFeatureWordInfoList(v, &list, "feature-words", &err);
1591 error_propagate(errp, err);
1594 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
1595 const char *name, Error **errp)
1597 X86CPU *cpu = X86_CPU(obj);
1598 int64_t value = cpu->hyperv_spinlock_attempts;
1600 visit_type_int(v, &value, name, errp);
1603 static void x86_set_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
1604 const char *name, Error **errp)
1606 const int64_t min = 0xFFF;
1607 const int64_t max = UINT_MAX;
1608 X86CPU *cpu = X86_CPU(obj);
1612 visit_type_int(v, &value, name, &err);
1614 error_propagate(errp, err);
1618 if (value < min || value > max) {
1619 error_setg(errp, "Property %s.%s doesn't take value %" PRId64
1620 " (minimum: %" PRId64 ", maximum: %" PRId64 ")",
1621 object_get_typename(obj), name ? name : "null",
1625 cpu->hyperv_spinlock_attempts = value;
1628 static PropertyInfo qdev_prop_spinlocks = {
1630 .get = x86_get_hv_spinlocks,
1631 .set = x86_set_hv_spinlocks,
1634 /* Convert all '_' in a feature string option name to '-', to make feature
1635 * name conform to QOM property naming rule, which uses '-' instead of '_'.
1637 static inline void feat2prop(char *s)
1639 while ((s = strchr(s, '_'))) {
1644 /* Parse "+feature,-feature,feature=foo" CPU feature string
1646 static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
1649 X86CPU *cpu = X86_CPU(cs);
1650 char *featurestr; /* Single 'key=value" string being parsed */
1651 /* Features to be added */
1652 FeatureWordArray plus_features = { 0 };
1653 /* Features to be removed */
1654 FeatureWordArray minus_features = { 0 };
1656 CPUX86State *env = &cpu->env;
1657 Error *local_err = NULL;
1659 featurestr = features ? strtok(features, ",") : NULL;
1661 while (featurestr) {
1663 if (featurestr[0] == '+') {
1664 add_flagname_to_bitmaps(featurestr + 1, plus_features);
1665 } else if (featurestr[0] == '-') {
1666 add_flagname_to_bitmaps(featurestr + 1, minus_features);
1667 } else if ((val = strchr(featurestr, '='))) {
1669 feat2prop(featurestr);
1670 if (!strcmp(featurestr, "xlevel")) {
1674 numvalue = strtoul(val, &err, 0);
1675 if (!*val || *err) {
1676 error_setg(errp, "bad numerical value %s", val);
1679 if (numvalue < 0x80000000) {
1680 error_report("xlevel value shall always be >= 0x80000000"
1681 ", fixup will be removed in future versions");
1682 numvalue += 0x80000000;
1684 snprintf(num, sizeof(num), "%" PRIu32, numvalue);
1685 object_property_parse(OBJECT(cpu), num, featurestr, &local_err);
1686 } else if (!strcmp(featurestr, "tsc-freq")) {
1691 tsc_freq = strtosz_suffix_unit(val, &err,
1692 STRTOSZ_DEFSUFFIX_B, 1000);
1693 if (tsc_freq < 0 || *err) {
1694 error_setg(errp, "bad numerical value %s", val);
1697 snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
1698 object_property_parse(OBJECT(cpu), num, "tsc-frequency",
1700 } else if (!strcmp(featurestr, "hv-spinlocks")) {
1702 const int min = 0xFFF;
1704 numvalue = strtoul(val, &err, 0);
1705 if (!*val || *err) {
1706 error_setg(errp, "bad numerical value %s", val);
1709 if (numvalue < min) {
1710 error_report("hv-spinlocks value shall always be >= 0x%x"
1711 ", fixup will be removed in future versions",
1715 snprintf(num, sizeof(num), "%" PRId32, numvalue);
1716 object_property_parse(OBJECT(cpu), num, featurestr, &local_err);
1718 object_property_parse(OBJECT(cpu), val, featurestr, &local_err);
1721 feat2prop(featurestr);
1722 object_property_parse(OBJECT(cpu), "on", featurestr, &local_err);
1725 error_propagate(errp, local_err);
1728 featurestr = strtok(NULL, ",");
1730 env->features[FEAT_1_EDX] |= plus_features[FEAT_1_EDX];
1731 env->features[FEAT_1_ECX] |= plus_features[FEAT_1_ECX];
1732 env->features[FEAT_8000_0001_EDX] |= plus_features[FEAT_8000_0001_EDX];
1733 env->features[FEAT_8000_0001_ECX] |= plus_features[FEAT_8000_0001_ECX];
1734 env->features[FEAT_C000_0001_EDX] |= plus_features[FEAT_C000_0001_EDX];
1735 env->features[FEAT_KVM] |= plus_features[FEAT_KVM];
1736 env->features[FEAT_SVM] |= plus_features[FEAT_SVM];
1737 env->features[FEAT_7_0_EBX] |= plus_features[FEAT_7_0_EBX];
1738 env->features[FEAT_1_EDX] &= ~minus_features[FEAT_1_EDX];
1739 env->features[FEAT_1_ECX] &= ~minus_features[FEAT_1_ECX];
1740 env->features[FEAT_8000_0001_EDX] &= ~minus_features[FEAT_8000_0001_EDX];
1741 env->features[FEAT_8000_0001_ECX] &= ~minus_features[FEAT_8000_0001_ECX];
1742 env->features[FEAT_C000_0001_EDX] &= ~minus_features[FEAT_C000_0001_EDX];
1743 env->features[FEAT_KVM] &= ~minus_features[FEAT_KVM];
1744 env->features[FEAT_SVM] &= ~minus_features[FEAT_SVM];
1745 env->features[FEAT_7_0_EBX] &= ~minus_features[FEAT_7_0_EBX];
1748 /* generate a composite string into buf of all cpuid names in featureset
1749 * selected by fbits. indicate truncation at bufsize in the event of overflow.
1750 * if flags, suppress names undefined in featureset.
1752 static void listflags(char *buf, int bufsize, uint32_t fbits,
1753 const char **featureset, uint32_t flags)
1755 const char **p = &featureset[31];
1759 b = 4 <= bufsize ? buf + (bufsize -= 3) - 1 : NULL;
1761 for (q = buf, bit = 31; fbits && bufsize; --p, fbits &= ~(1 << bit), --bit)
1762 if (fbits & 1 << bit && (*p || !flags)) {
1764 nc = snprintf(q, bufsize, "%s%s", q == buf ? "" : " ", *p);
1766 nc = snprintf(q, bufsize, "%s[%d]", q == buf ? "" : " ", bit);
1767 if (bufsize <= nc) {
1769 memcpy(b, "...", sizeof("..."));
1778 /* generate CPU information. */
1779 void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
1781 X86CPUDefinition *def;
1785 for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
1786 def = &builtin_x86_defs[i];
1787 snprintf(buf, sizeof(buf), "%s", def->name);
1788 (*cpu_fprintf)(f, "x86 %16s %-48s\n", buf, def->model_id);
1791 (*cpu_fprintf)(f, "x86 %16s %-48s\n", "host",
1792 "KVM processor with all supported host features "
1793 "(only available in KVM mode)");
1796 (*cpu_fprintf)(f, "\nRecognized CPUID flags:\n");
1797 for (i = 0; i < ARRAY_SIZE(feature_word_info); i++) {
1798 FeatureWordInfo *fw = &feature_word_info[i];
1800 listflags(buf, sizeof(buf), (uint32_t)~0, fw->feat_names, 1);
1801 (*cpu_fprintf)(f, " %s\n", buf);
1805 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
1807 CpuDefinitionInfoList *cpu_list = NULL;
1808 X86CPUDefinition *def;
1811 for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
1812 CpuDefinitionInfoList *entry;
1813 CpuDefinitionInfo *info;
1815 def = &builtin_x86_defs[i];
1816 info = g_malloc0(sizeof(*info));
1817 info->name = g_strdup(def->name);
1819 entry = g_malloc0(sizeof(*entry));
1820 entry->value = info;
1821 entry->next = cpu_list;
1828 static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w)
1830 FeatureWordInfo *wi = &feature_word_info[w];
1832 assert(kvm_enabled());
1833 return kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid_eax,
1839 * Filters CPU feature words based on host availability of each feature.
1841 * This function may be called only if KVM is enabled.
1843 * Returns: 0 if all flags are supported by the host, non-zero otherwise.
1845 static int x86_cpu_filter_features(X86CPU *cpu)
1847 CPUX86State *env = &cpu->env;
1851 for (w = 0; w < FEATURE_WORDS; w++) {
1852 uint32_t host_feat = x86_cpu_get_supported_feature_word(w);
1853 uint32_t requested_features = env->features[w];
1854 env->features[w] &= host_feat;
1855 cpu->filtered_features[w] = requested_features & ~env->features[w];
1856 if (cpu->filtered_features[w]) {
1857 if (cpu->check_cpuid || cpu->enforce_cpuid) {
1858 report_unavailable_features(w, cpu->filtered_features[w]);
1867 /* Load data from X86CPUDefinition
1869 static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp)
1871 CPUX86State *env = &cpu->env;
1873 char host_vendor[CPUID_VENDOR_SZ + 1];
1875 object_property_set_int(OBJECT(cpu), def->level, "level", errp);
1876 object_property_set_int(OBJECT(cpu), def->family, "family", errp);
1877 object_property_set_int(OBJECT(cpu), def->model, "model", errp);
1878 object_property_set_int(OBJECT(cpu), def->stepping, "stepping", errp);
1879 env->features[FEAT_1_EDX] = def->features[FEAT_1_EDX];
1880 env->features[FEAT_1_ECX] = def->features[FEAT_1_ECX];
1881 env->features[FEAT_8000_0001_EDX] = def->features[FEAT_8000_0001_EDX];
1882 env->features[FEAT_8000_0001_ECX] = def->features[FEAT_8000_0001_ECX];
1883 object_property_set_int(OBJECT(cpu), def->xlevel, "xlevel", errp);
1884 env->features[FEAT_KVM] = def->features[FEAT_KVM];
1885 env->features[FEAT_SVM] = def->features[FEAT_SVM];
1886 env->features[FEAT_C000_0001_EDX] = def->features[FEAT_C000_0001_EDX];
1887 env->features[FEAT_7_0_EBX] = def->features[FEAT_7_0_EBX];
1888 env->cpuid_xlevel2 = def->xlevel2;
1889 cpu->cache_info_passthrough = def->cache_info_passthrough;
1891 object_property_set_str(OBJECT(cpu), def->model_id, "model-id", errp);
1893 /* Special cases not set in the X86CPUDefinition structs: */
1894 if (kvm_enabled()) {
1896 for (w = 0; w < FEATURE_WORDS; w++) {
1897 env->features[w] |= kvm_default_features[w];
1898 env->features[w] &= ~kvm_default_unset_features[w];
1902 env->features[FEAT_1_ECX] |= CPUID_EXT_HYPERVISOR;
1904 /* sysenter isn't supported in compatibility mode on AMD,
1905 * syscall isn't supported in compatibility mode on Intel.
1906 * Normally we advertise the actual CPU vendor, but you can
1907 * override this using the 'vendor' property if you want to use
1908 * KVM's sysenter/syscall emulation in compatibility mode and
1909 * when doing cross vendor migration
1911 vendor = def->vendor;
1912 if (kvm_enabled()) {
1913 uint32_t ebx = 0, ecx = 0, edx = 0;
1914 host_cpuid(0, 0, NULL, &ebx, &ecx, &edx);
1915 x86_cpu_vendor_words2str(host_vendor, ebx, edx, ecx);
1916 vendor = host_vendor;
1919 object_property_set_str(OBJECT(cpu), vendor, "vendor", errp);
1923 X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
1929 gchar **model_pieces;
1930 char *name, *features;
1931 Error *error = NULL;
1933 model_pieces = g_strsplit(cpu_model, ",", 2);
1934 if (!model_pieces[0]) {
1935 error_setg(&error, "Invalid/empty CPU model name");
1938 name = model_pieces[0];
1939 features = model_pieces[1];
1941 oc = x86_cpu_class_by_name(name);
1943 error_setg(&error, "Unable to find CPU definition: %s", name);
1946 xcc = X86_CPU_CLASS(oc);
1948 if (xcc->kvm_required && !kvm_enabled()) {
1949 error_setg(&error, "CPU model '%s' requires KVM", name);
1953 cpu = X86_CPU(object_new(object_class_get_name(oc)));
1955 #ifndef CONFIG_USER_ONLY
1956 if (icc_bridge == NULL) {
1957 error_setg(&error, "Invalid icc-bridge value");
1960 qdev_set_parent_bus(DEVICE(cpu), qdev_get_child_bus(icc_bridge, "icc"));
1961 object_unref(OBJECT(cpu));
1964 x86_cpu_parse_featurestr(CPU(cpu), features, &error);
1970 if (error != NULL) {
1971 error_propagate(errp, error);
1973 object_unref(OBJECT(cpu));
1977 g_strfreev(model_pieces);
1981 X86CPU *cpu_x86_init(const char *cpu_model)
1983 Error *error = NULL;
1986 cpu = cpu_x86_create(cpu_model, NULL, &error);
1991 object_property_set_bool(OBJECT(cpu), true, "realized", &error);
1995 error_report("%s", error_get_pretty(error));
1998 object_unref(OBJECT(cpu));
2005 static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)
2007 X86CPUDefinition *cpudef = data;
2008 X86CPUClass *xcc = X86_CPU_CLASS(oc);
2010 xcc->cpu_def = cpudef;
2013 static void x86_register_cpudef_type(X86CPUDefinition *def)
2015 char *typename = x86_cpu_type_name(def->name);
2018 .parent = TYPE_X86_CPU,
2019 .class_init = x86_cpu_cpudef_class_init,
2027 #if !defined(CONFIG_USER_ONLY)
2029 void cpu_clear_apic_feature(CPUX86State *env)
2031 env->features[FEAT_1_EDX] &= ~CPUID_APIC;
2034 #endif /* !CONFIG_USER_ONLY */
2036 /* Initialize list of CPU models, filling some non-static fields if necessary
2038 void x86_cpudef_setup(void)
2041 static const char *model_with_versions[] = { "qemu32", "qemu64", "athlon" };
2043 for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); ++i) {
2044 X86CPUDefinition *def = &builtin_x86_defs[i];
2046 /* Look for specific "cpudef" models that */
2047 /* have the QEMU version in .model_id */
2048 for (j = 0; j < ARRAY_SIZE(model_with_versions); j++) {
2049 if (strcmp(model_with_versions[j], def->name) == 0) {
2050 pstrcpy(def->model_id, sizeof(def->model_id),
2051 "QEMU Virtual CPU version ");
2052 pstrcat(def->model_id, sizeof(def->model_id),
2053 qemu_get_version());
2060 static void get_cpuid_vendor(CPUX86State *env, uint32_t *ebx,
2061 uint32_t *ecx, uint32_t *edx)
2063 *ebx = env->cpuid_vendor1;
2064 *edx = env->cpuid_vendor2;
2065 *ecx = env->cpuid_vendor3;
2068 void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
2069 uint32_t *eax, uint32_t *ebx,
2070 uint32_t *ecx, uint32_t *edx)
2072 X86CPU *cpu = x86_env_get_cpu(env);
2073 CPUState *cs = CPU(cpu);
2075 /* test if maximum index reached */
2076 if (index & 0x80000000) {
2077 if (index > env->cpuid_xlevel) {
2078 if (env->cpuid_xlevel2 > 0) {
2079 /* Handle the Centaur's CPUID instruction. */
2080 if (index > env->cpuid_xlevel2) {
2081 index = env->cpuid_xlevel2;
2082 } else if (index < 0xC0000000) {
2083 index = env->cpuid_xlevel;
2086 /* Intel documentation states that invalid EAX input will
2087 * return the same information as EAX=cpuid_level
2088 * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
2090 index = env->cpuid_level;
2094 if (index > env->cpuid_level)
2095 index = env->cpuid_level;
2100 *eax = env->cpuid_level;
2101 get_cpuid_vendor(env, ebx, ecx, edx);
2104 *eax = env->cpuid_version;
2105 *ebx = (env->cpuid_apic_id << 24) | 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */
2106 *ecx = env->features[FEAT_1_ECX];
2107 *edx = env->features[FEAT_1_EDX];
2108 if (cs->nr_cores * cs->nr_threads > 1) {
2109 *ebx |= (cs->nr_cores * cs->nr_threads) << 16;
2110 *edx |= 1 << 28; /* HTT bit */
2114 /* cache info: needed for Pentium Pro compatibility */
2115 if (cpu->cache_info_passthrough) {
2116 host_cpuid(index, 0, eax, ebx, ecx, edx);
2119 *eax = 1; /* Number of CPUID[EAX=2] calls required */
2122 *edx = (L1D_DESCRIPTOR << 16) | \
2123 (L1I_DESCRIPTOR << 8) | \
2127 /* cache info: needed for Core compatibility */
2128 if (cpu->cache_info_passthrough) {
2129 host_cpuid(index, count, eax, ebx, ecx, edx);
2130 *eax &= ~0xFC000000;
2134 case 0: /* L1 dcache info */
2135 *eax |= CPUID_4_TYPE_DCACHE | \
2136 CPUID_4_LEVEL(1) | \
2137 CPUID_4_SELF_INIT_LEVEL;
2138 *ebx = (L1D_LINE_SIZE - 1) | \
2139 ((L1D_PARTITIONS - 1) << 12) | \
2140 ((L1D_ASSOCIATIVITY - 1) << 22);
2141 *ecx = L1D_SETS - 1;
2142 *edx = CPUID_4_NO_INVD_SHARING;
2144 case 1: /* L1 icache info */
2145 *eax |= CPUID_4_TYPE_ICACHE | \
2146 CPUID_4_LEVEL(1) | \
2147 CPUID_4_SELF_INIT_LEVEL;
2148 *ebx = (L1I_LINE_SIZE - 1) | \
2149 ((L1I_PARTITIONS - 1) << 12) | \
2150 ((L1I_ASSOCIATIVITY - 1) << 22);
2151 *ecx = L1I_SETS - 1;
2152 *edx = CPUID_4_NO_INVD_SHARING;
2154 case 2: /* L2 cache info */
2155 *eax |= CPUID_4_TYPE_UNIFIED | \
2156 CPUID_4_LEVEL(2) | \
2157 CPUID_4_SELF_INIT_LEVEL;
2158 if (cs->nr_threads > 1) {
2159 *eax |= (cs->nr_threads - 1) << 14;
2161 *ebx = (L2_LINE_SIZE - 1) | \
2162 ((L2_PARTITIONS - 1) << 12) | \
2163 ((L2_ASSOCIATIVITY - 1) << 22);
2165 *edx = CPUID_4_NO_INVD_SHARING;
2167 default: /* end of info */
2176 /* QEMU gives out its own APIC IDs, never pass down bits 31..26. */
2177 if ((*eax & 31) && cs->nr_cores > 1) {
2178 *eax |= (cs->nr_cores - 1) << 26;
2182 /* mwait info: needed for Core compatibility */
2183 *eax = 0; /* Smallest monitor-line size in bytes */
2184 *ebx = 0; /* Largest monitor-line size in bytes */
2185 *ecx = CPUID_MWAIT_EMX | CPUID_MWAIT_IBE;
2189 /* Thermal and Power Leaf */
2196 /* Structured Extended Feature Flags Enumeration Leaf */
2198 *eax = 0; /* Maximum ECX value for sub-leaves */
2199 *ebx = env->features[FEAT_7_0_EBX]; /* Feature flags */
2200 *ecx = 0; /* Reserved */
2201 *edx = 0; /* Reserved */
2210 /* Direct Cache Access Information Leaf */
2211 *eax = 0; /* Bits 0-31 in DCA_CAP MSR */
2217 /* Architectural Performance Monitoring Leaf */
2218 if (kvm_enabled() && cpu->enable_pmu) {
2219 KVMState *s = cs->kvm_state;
2221 *eax = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX);
2222 *ebx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EBX);
2223 *ecx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_ECX);
2224 *edx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EDX);
2233 KVMState *s = cs->kvm_state;
2237 /* Processor Extended State */
2242 if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE) || !kvm_enabled()) {
2246 kvm_arch_get_supported_cpuid(s, 0xd, 0, R_EAX) |
2247 ((uint64_t)kvm_arch_get_supported_cpuid(s, 0xd, 0, R_EDX) << 32);
2251 for (i = 2; i < ARRAY_SIZE(ext_save_areas); i++) {
2252 const ExtSaveArea *esa = &ext_save_areas[i];
2253 if ((env->features[esa->feature] & esa->bits) == esa->bits &&
2254 (kvm_mask & (1 << i)) != 0) {
2258 *edx |= 1 << (i - 32);
2260 *ecx = MAX(*ecx, esa->offset + esa->size);
2263 *eax |= kvm_mask & (XSTATE_FP | XSTATE_SSE);
2265 } else if (count == 1) {
2266 *eax = kvm_arch_get_supported_cpuid(s, 0xd, 1, R_EAX);
2267 } else if (count < ARRAY_SIZE(ext_save_areas)) {
2268 const ExtSaveArea *esa = &ext_save_areas[count];
2269 if ((env->features[esa->feature] & esa->bits) == esa->bits &&
2270 (kvm_mask & (1 << count)) != 0) {
2278 *eax = env->cpuid_xlevel;
2279 *ebx = env->cpuid_vendor1;
2280 *edx = env->cpuid_vendor2;
2281 *ecx = env->cpuid_vendor3;
2284 *eax = env->cpuid_version;
2286 *ecx = env->features[FEAT_8000_0001_ECX];
2287 *edx = env->features[FEAT_8000_0001_EDX];
2289 /* The Linux kernel checks for the CMPLegacy bit and
2290 * discards multiple thread information if it is set.
2291 * So dont set it here for Intel to make Linux guests happy.
2293 if (cs->nr_cores * cs->nr_threads > 1) {
2294 uint32_t tebx, tecx, tedx;
2295 get_cpuid_vendor(env, &tebx, &tecx, &tedx);
2296 if (tebx != CPUID_VENDOR_INTEL_1 ||
2297 tedx != CPUID_VENDOR_INTEL_2 ||
2298 tecx != CPUID_VENDOR_INTEL_3) {
2299 *ecx |= 1 << 1; /* CmpLegacy bit */
2306 *eax = env->cpuid_model[(index - 0x80000002) * 4 + 0];
2307 *ebx = env->cpuid_model[(index - 0x80000002) * 4 + 1];
2308 *ecx = env->cpuid_model[(index - 0x80000002) * 4 + 2];
2309 *edx = env->cpuid_model[(index - 0x80000002) * 4 + 3];
2312 /* cache info (L1 cache) */
2313 if (cpu->cache_info_passthrough) {
2314 host_cpuid(index, 0, eax, ebx, ecx, edx);
2317 *eax = (L1_DTLB_2M_ASSOC << 24) | (L1_DTLB_2M_ENTRIES << 16) | \
2318 (L1_ITLB_2M_ASSOC << 8) | (L1_ITLB_2M_ENTRIES);
2319 *ebx = (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) | \
2320 (L1_ITLB_4K_ASSOC << 8) | (L1_ITLB_4K_ENTRIES);
2321 *ecx = (L1D_SIZE_KB_AMD << 24) | (L1D_ASSOCIATIVITY_AMD << 16) | \
2322 (L1D_LINES_PER_TAG << 8) | (L1D_LINE_SIZE);
2323 *edx = (L1I_SIZE_KB_AMD << 24) | (L1I_ASSOCIATIVITY_AMD << 16) | \
2324 (L1I_LINES_PER_TAG << 8) | (L1I_LINE_SIZE);
2327 /* cache info (L2 cache) */
2328 if (cpu->cache_info_passthrough) {
2329 host_cpuid(index, 0, eax, ebx, ecx, edx);
2332 *eax = (AMD_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | \
2333 (L2_DTLB_2M_ENTRIES << 16) | \
2334 (AMD_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | \
2335 (L2_ITLB_2M_ENTRIES);
2336 *ebx = (AMD_ENC_ASSOC(L2_DTLB_4K_ASSOC) << 28) | \
2337 (L2_DTLB_4K_ENTRIES << 16) | \
2338 (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | \
2339 (L2_ITLB_4K_ENTRIES);
2340 *ecx = (L2_SIZE_KB_AMD << 16) | \
2341 (AMD_ENC_ASSOC(L2_ASSOCIATIVITY) << 12) | \
2342 (L2_LINES_PER_TAG << 8) | (L2_LINE_SIZE);
2343 *edx = ((L3_SIZE_KB/512) << 18) | \
2344 (AMD_ENC_ASSOC(L3_ASSOCIATIVITY) << 12) | \
2345 (L3_LINES_PER_TAG << 8) | (L3_LINE_SIZE);
2348 /* virtual & phys address size in low 2 bytes. */
2349 /* XXX: This value must match the one used in the MMU code. */
2350 if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) {
2351 /* 64 bit processor */
2352 /* XXX: The physical address space is limited to 42 bits in exec.c. */
2353 *eax = 0x00003028; /* 48 bits virtual, 40 bits physical */
2355 if (env->features[FEAT_1_EDX] & CPUID_PSE36) {
2356 *eax = 0x00000024; /* 36 bits physical */
2358 *eax = 0x00000020; /* 32 bits physical */
2364 if (cs->nr_cores * cs->nr_threads > 1) {
2365 *ecx |= (cs->nr_cores * cs->nr_threads) - 1;
2369 if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
2370 *eax = 0x00000001; /* SVM Revision */
2371 *ebx = 0x00000010; /* nr of ASIDs */
2373 *edx = env->features[FEAT_SVM]; /* optional features */
2382 *eax = env->cpuid_xlevel2;
2388 /* Support for VIA CPU's CPUID instruction */
2389 *eax = env->cpuid_version;
2392 *edx = env->features[FEAT_C000_0001_EDX];
2397 /* Reserved for the future, and now filled with zero */
2404 /* reserved values: zero */
2413 /* CPUClass::reset() */
2414 static void x86_cpu_reset(CPUState *s)
2416 X86CPU *cpu = X86_CPU(s);
2417 X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu);
2418 CPUX86State *env = &cpu->env;
2421 xcc->parent_reset(s);
2423 memset(env, 0, offsetof(CPUX86State, cpuid_level));
2427 env->old_exception = -1;
2429 /* init to reset state */
2431 #ifdef CONFIG_SOFTMMU
2432 env->hflags |= HF_SOFTMMU_MASK;
2434 env->hflags2 |= HF2_GIF_MASK;
2436 cpu_x86_update_cr0(env, 0x60000010);
2437 env->a20_mask = ~0x0;
2438 env->smbase = 0x30000;
2440 env->idt.limit = 0xffff;
2441 env->gdt.limit = 0xffff;
2442 env->ldt.limit = 0xffff;
2443 env->ldt.flags = DESC_P_MASK | (2 << DESC_TYPE_SHIFT);
2444 env->tr.limit = 0xffff;
2445 env->tr.flags = DESC_P_MASK | (11 << DESC_TYPE_SHIFT);
2447 cpu_x86_load_seg_cache(env, R_CS, 0xf000, 0xffff0000, 0xffff,
2448 DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK |
2449 DESC_R_MASK | DESC_A_MASK);
2450 cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffff,
2451 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
2453 cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffff,
2454 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
2456 cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffff,
2457 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
2459 cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0xffff,
2460 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
2462 cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0xffff,
2463 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
2467 env->regs[R_EDX] = env->cpuid_version;
2472 for (i = 0; i < 8; i++) {
2477 env->mxcsr = 0x1f80;
2478 env->xstate_bv = XSTATE_FP | XSTATE_SSE;
2480 env->pat = 0x0007040600070406ULL;
2481 env->msr_ia32_misc_enable = MSR_IA32_MISC_ENABLE_DEFAULT;
2483 memset(env->dr, 0, sizeof(env->dr));
2484 env->dr[6] = DR6_FIXED_1;
2485 env->dr[7] = DR7_FIXED_1;
2486 cpu_breakpoint_remove_all(s, BP_CPU);
2487 cpu_watchpoint_remove_all(s, BP_CPU);
2491 #if !defined(CONFIG_USER_ONLY)
2492 /* We hard-wire the BSP to the first CPU. */
2493 if (s->cpu_index == 0) {
2494 apic_designate_bsp(cpu->apic_state);
2497 s->halted = !cpu_is_bsp(cpu);
2499 if (kvm_enabled()) {
2500 kvm_arch_reset_vcpu(cpu);
2505 #ifndef CONFIG_USER_ONLY
2506 bool cpu_is_bsp(X86CPU *cpu)
2508 return cpu_get_apic_base(cpu->apic_state) & MSR_IA32_APICBASE_BSP;
2511 /* TODO: remove me, when reset over QOM tree is implemented */
2512 static void x86_cpu_machine_reset_cb(void *opaque)
2514 X86CPU *cpu = opaque;
2515 cpu_reset(CPU(cpu));
2519 static void mce_init(X86CPU *cpu)
2521 CPUX86State *cenv = &cpu->env;
2524 if (((cenv->cpuid_version >> 8) & 0xf) >= 6
2525 && (cenv->features[FEAT_1_EDX] & (CPUID_MCE | CPUID_MCA)) ==
2526 (CPUID_MCE | CPUID_MCA)) {
2527 cenv->mcg_cap = MCE_CAP_DEF | MCE_BANKS_DEF;
2528 cenv->mcg_ctl = ~(uint64_t)0;
2529 for (bank = 0; bank < MCE_BANKS_DEF; bank++) {
2530 cenv->mce_banks[bank * 4] = ~(uint64_t)0;
2535 #ifndef CONFIG_USER_ONLY
2536 static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
2538 CPUX86State *env = &cpu->env;
2539 DeviceState *dev = DEVICE(cpu);
2540 APICCommonState *apic;
2541 const char *apic_type = "apic";
2543 if (kvm_irqchip_in_kernel()) {
2544 apic_type = "kvm-apic";
2545 } else if (xen_enabled()) {
2546 apic_type = "xen-apic";
2549 cpu->apic_state = qdev_try_create(qdev_get_parent_bus(dev), apic_type);
2550 if (cpu->apic_state == NULL) {
2551 error_setg(errp, "APIC device '%s' could not be created", apic_type);
2555 object_property_add_child(OBJECT(cpu), "apic",
2556 OBJECT(cpu->apic_state), NULL);
2557 qdev_prop_set_uint8(cpu->apic_state, "id", env->cpuid_apic_id);
2558 /* TODO: convert to link<> */
2559 apic = APIC_COMMON(cpu->apic_state);
2563 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
2565 if (cpu->apic_state == NULL) {
2569 if (qdev_init(cpu->apic_state)) {
2570 error_setg(errp, "APIC device '%s' could not be initialized",
2571 object_get_typename(OBJECT(cpu->apic_state)));
2576 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
2581 static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
2583 CPUState *cs = CPU(dev);
2584 X86CPU *cpu = X86_CPU(dev);
2585 X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
2586 CPUX86State *env = &cpu->env;
2587 Error *local_err = NULL;
2589 if (env->features[FEAT_7_0_EBX] && env->cpuid_level < 7) {
2590 env->cpuid_level = 7;
2593 /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
2596 if (env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 &&
2597 env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 &&
2598 env->cpuid_vendor3 == CPUID_VENDOR_AMD_3) {
2599 env->features[FEAT_8000_0001_EDX] &= ~CPUID_EXT2_AMD_ALIASES;
2600 env->features[FEAT_8000_0001_EDX] |= (env->features[FEAT_1_EDX]
2601 & CPUID_EXT2_AMD_ALIASES);
2604 if (!kvm_enabled()) {
2605 env->features[FEAT_1_EDX] &= TCG_FEATURES;
2606 env->features[FEAT_1_ECX] &= TCG_EXT_FEATURES;
2607 env->features[FEAT_7_0_EBX] &= TCG_7_0_EBX_FEATURES;
2608 env->features[FEAT_8000_0001_EDX] &= TCG_EXT2_FEATURES;
2609 env->features[FEAT_8000_0001_ECX] &= TCG_EXT3_FEATURES;
2610 env->features[FEAT_SVM] &= TCG_SVM_FEATURES;
2611 env->features[FEAT_KVM] &= TCG_KVM_FEATURES;
2612 env->features[FEAT_C000_0001_EDX] &= TCG_EXT4_FEATURES;
2614 if (x86_cpu_filter_features(cpu) && cpu->enforce_cpuid) {
2615 error_setg(&local_err,
2616 "Host's CPU doesn't support requested features");
2621 #ifndef CONFIG_USER_ONLY
2622 qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
2624 if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || smp_cpus > 1) {
2625 x86_cpu_apic_create(cpu, &local_err);
2626 if (local_err != NULL) {
2635 x86_cpu_apic_realize(cpu, &local_err);
2636 if (local_err != NULL) {
2641 xcc->parent_realize(dev, &local_err);
2643 if (local_err != NULL) {
2644 error_propagate(errp, local_err);
2649 /* Enables contiguous-apic-ID mode, for compatibility */
2650 static bool compat_apic_id_mode;
2652 void enable_compat_apic_id_mode(void)
2654 compat_apic_id_mode = true;
2657 /* Calculates initial APIC ID for a specific CPU index
2659 * Currently we need to be able to calculate the APIC ID from the CPU index
2660 * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have
2661 * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
2662 * all CPUs up to max_cpus.
2664 uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
2666 uint32_t correct_id;
2669 correct_id = x86_apicid_from_cpu_idx(smp_cores, smp_threads, cpu_index);
2670 if (compat_apic_id_mode) {
2671 if (cpu_index != correct_id && !warned) {
2672 error_report("APIC IDs set in compatibility mode, "
2673 "CPU topology won't match the configuration");
2682 static void x86_cpu_initfn(Object *obj)
2684 CPUState *cs = CPU(obj);
2685 X86CPU *cpu = X86_CPU(obj);
2686 X86CPUClass *xcc = X86_CPU_GET_CLASS(obj);
2687 CPUX86State *env = &cpu->env;
2693 object_property_add(obj, "family", "int",
2694 x86_cpuid_version_get_family,
2695 x86_cpuid_version_set_family, NULL, NULL, NULL);
2696 object_property_add(obj, "model", "int",
2697 x86_cpuid_version_get_model,
2698 x86_cpuid_version_set_model, NULL, NULL, NULL);
2699 object_property_add(obj, "stepping", "int",
2700 x86_cpuid_version_get_stepping,
2701 x86_cpuid_version_set_stepping, NULL, NULL, NULL);
2702 object_property_add(obj, "level", "int",
2703 x86_cpuid_get_level,
2704 x86_cpuid_set_level, NULL, NULL, NULL);
2705 object_property_add(obj, "xlevel", "int",
2706 x86_cpuid_get_xlevel,
2707 x86_cpuid_set_xlevel, NULL, NULL, NULL);
2708 object_property_add_str(obj, "vendor",
2709 x86_cpuid_get_vendor,
2710 x86_cpuid_set_vendor, NULL);
2711 object_property_add_str(obj, "model-id",
2712 x86_cpuid_get_model_id,
2713 x86_cpuid_set_model_id, NULL);
2714 object_property_add(obj, "tsc-frequency", "int",
2715 x86_cpuid_get_tsc_freq,
2716 x86_cpuid_set_tsc_freq, NULL, NULL, NULL);
2717 object_property_add(obj, "apic-id", "int",
2718 x86_cpuid_get_apic_id,
2719 x86_cpuid_set_apic_id, NULL, NULL, NULL);
2720 object_property_add(obj, "feature-words", "X86CPUFeatureWordInfo",
2721 x86_cpu_get_feature_words,
2722 NULL, NULL, (void *)env->features, NULL);
2723 object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo",
2724 x86_cpu_get_feature_words,
2725 NULL, NULL, (void *)cpu->filtered_features, NULL);
2727 cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
2728 env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
2730 x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
2732 /* init various static tables used in TCG mode */
2733 if (tcg_enabled() && !inited) {
2735 optimize_flags_init();
2736 #ifndef CONFIG_USER_ONLY
2737 cpu_set_debug_excp_handler(breakpoint_handler);
2742 static int64_t x86_cpu_get_arch_id(CPUState *cs)
2744 X86CPU *cpu = X86_CPU(cs);
2745 CPUX86State *env = &cpu->env;
2747 return env->cpuid_apic_id;
2750 static bool x86_cpu_get_paging_enabled(const CPUState *cs)
2752 X86CPU *cpu = X86_CPU(cs);
2754 return cpu->env.cr[0] & CR0_PG_MASK;
2757 static void x86_cpu_set_pc(CPUState *cs, vaddr value)
2759 X86CPU *cpu = X86_CPU(cs);
2761 cpu->env.eip = value;
2764 static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
2766 X86CPU *cpu = X86_CPU(cs);
2768 cpu->env.eip = tb->pc - tb->cs_base;
2771 static bool x86_cpu_has_work(CPUState *cs)
2773 X86CPU *cpu = X86_CPU(cs);
2774 CPUX86State *env = &cpu->env;
2776 return ((cs->interrupt_request & (CPU_INTERRUPT_HARD |
2777 CPU_INTERRUPT_POLL)) &&
2778 (env->eflags & IF_MASK)) ||
2779 (cs->interrupt_request & (CPU_INTERRUPT_NMI |
2780 CPU_INTERRUPT_INIT |
2781 CPU_INTERRUPT_SIPI |
2782 CPU_INTERRUPT_MCE));
2785 static Property x86_cpu_properties[] = {
2786 DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false),
2787 { .name = "hv-spinlocks", .info = &qdev_prop_spinlocks },
2788 DEFINE_PROP_BOOL("hv-relaxed", X86CPU, hyperv_relaxed_timing, false),
2789 DEFINE_PROP_BOOL("hv-vapic", X86CPU, hyperv_vapic, false),
2790 DEFINE_PROP_BOOL("hv-time", X86CPU, hyperv_time, false),
2791 DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, false),
2792 DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
2793 DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
2794 DEFINE_PROP_END_OF_LIST()
2797 static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
2799 X86CPUClass *xcc = X86_CPU_CLASS(oc);
2800 CPUClass *cc = CPU_CLASS(oc);
2801 DeviceClass *dc = DEVICE_CLASS(oc);
2803 xcc->parent_realize = dc->realize;
2804 dc->realize = x86_cpu_realizefn;
2805 dc->bus_type = TYPE_ICC_BUS;
2806 dc->props = x86_cpu_properties;
2808 xcc->parent_reset = cc->reset;
2809 cc->reset = x86_cpu_reset;
2810 cc->reset_dump_flags = CPU_DUMP_FPU | CPU_DUMP_CCOP;
2812 cc->class_by_name = x86_cpu_class_by_name;
2813 cc->parse_features = x86_cpu_parse_featurestr;
2814 cc->has_work = x86_cpu_has_work;
2815 cc->do_interrupt = x86_cpu_do_interrupt;
2816 cc->dump_state = x86_cpu_dump_state;
2817 cc->set_pc = x86_cpu_set_pc;
2818 cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
2819 cc->gdb_read_register = x86_cpu_gdb_read_register;
2820 cc->gdb_write_register = x86_cpu_gdb_write_register;
2821 cc->get_arch_id = x86_cpu_get_arch_id;
2822 cc->get_paging_enabled = x86_cpu_get_paging_enabled;
2823 #ifdef CONFIG_USER_ONLY
2824 cc->handle_mmu_fault = x86_cpu_handle_mmu_fault;
2826 cc->get_memory_mapping = x86_cpu_get_memory_mapping;
2827 cc->get_phys_page_debug = x86_cpu_get_phys_page_debug;
2828 cc->write_elf64_note = x86_cpu_write_elf64_note;
2829 cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;
2830 cc->write_elf32_note = x86_cpu_write_elf32_note;
2831 cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;
2832 cc->vmsd = &vmstate_x86_cpu;
2834 cc->gdb_num_core_regs = CPU_NB_REGS * 2 + 25;
2837 static const TypeInfo x86_cpu_type_info = {
2838 .name = TYPE_X86_CPU,
2840 .instance_size = sizeof(X86CPU),
2841 .instance_init = x86_cpu_initfn,
2843 .class_size = sizeof(X86CPUClass),
2844 .class_init = x86_cpu_common_class_init,
2847 static void x86_cpu_register_types(void)
2851 type_register_static(&x86_cpu_type_info);
2852 for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
2853 x86_register_cpudef_type(&builtin_x86_defs[i]);
2856 type_register_static(&host_x86_cpu_type_info);
2860 type_init(x86_cpu_register_types)