2 * x86 HVF CPU type initialization
4 * Copyright 2021 SUSE LLC
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
10 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "sysemu/sysemu.h"
15 #include "hw/boards.h"
16 #include "sysemu/hvf.h"
17 #include "hw/core/accel-cpu.h"
20 static void hvf_cpu_max_instance_init(X86CPU
*cpu
)
22 CPUX86State
*env
= &cpu
->env
;
24 host_cpu_max_instance_init(cpu
);
26 env
->cpuid_min_level
=
27 hvf_get_supported_cpuid(0x0, 0, R_EAX
);
28 env
->cpuid_min_xlevel
=
29 hvf_get_supported_cpuid(0x80000000, 0, R_EAX
);
30 env
->cpuid_min_xlevel2
=
31 hvf_get_supported_cpuid(0xC0000000, 0, R_EAX
);
34 static void hvf_cpu_xsave_init(void)
36 static bool first
= true;
44 /* x87 and SSE states are in the legacy region of the XSAVE area. */
45 x86_ext_save_areas
[XSTATE_FP_BIT
].offset
= 0;
46 x86_ext_save_areas
[XSTATE_SSE_BIT
].offset
= 0;
48 for (i
= XSTATE_SSE_BIT
+ 1; i
< XSAVE_STATE_AREA_COUNT
; i
++) {
49 ExtSaveArea
*esa
= &x86_ext_save_areas
[i
];
52 int sz
= hvf_get_supported_cpuid(0xd, i
, R_EAX
);
54 assert(esa
->size
== sz
);
55 esa
->offset
= hvf_get_supported_cpuid(0xd, i
, R_EBX
);
61 static void hvf_cpu_instance_init(CPUState
*cs
)
63 X86CPU
*cpu
= X86_CPU(cs
);
65 host_cpu_instance_init(cpu
);
67 /* Special cases not set in the X86CPUDefinition structs: */
68 /* TODO: in-kernel irqchip for hvf */
70 if (cpu
->max_features
) {
71 hvf_cpu_max_instance_init(cpu
);
77 static void hvf_cpu_accel_class_init(ObjectClass
*oc
, void *data
)
79 AccelCPUClass
*acc
= ACCEL_CPU_CLASS(oc
);
81 acc
->cpu_target_realize
= host_cpu_realizefn
;
82 acc
->cpu_instance_init
= hvf_cpu_instance_init
;
85 static const TypeInfo hvf_cpu_accel_type_info
= {
86 .name
= ACCEL_CPU_NAME("hvf"),
88 .parent
= TYPE_ACCEL_CPU
,
89 .class_init
= hvf_cpu_accel_class_init
,
93 static void hvf_cpu_accel_register_types(void)
95 type_register_static(&hvf_cpu_accel_type_info
);
98 type_init(hvf_cpu_accel_register_types
);