xref: /qemu/target/i386/hvf/hvf-cpu.c (revision d0fb9657)
1 /*
2  * x86 HVF CPU type initialization
3  *
4  * Copyright 2021 SUSE LLC
5  *
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.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "cpu.h"
12 #include "host-cpu.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"
18 
19 static void hvf_cpu_max_instance_init(X86CPU *cpu)
20 {
21     CPUX86State *env = &cpu->env;
22 
23     host_cpu_max_instance_init(cpu);
24 
25     env->cpuid_min_level =
26         hvf_get_supported_cpuid(0x0, 0, R_EAX);
27     env->cpuid_min_xlevel =
28         hvf_get_supported_cpuid(0x80000000, 0, R_EAX);
29     env->cpuid_min_xlevel2 =
30         hvf_get_supported_cpuid(0xC0000000, 0, R_EAX);
31 }
32 
33 static void hvf_cpu_instance_init(CPUState *cs)
34 {
35     X86CPU *cpu = X86_CPU(cs);
36 
37     host_cpu_instance_init(cpu);
38 
39     /* Special cases not set in the X86CPUDefinition structs: */
40     /* TODO: in-kernel irqchip for hvf */
41 
42     if (cpu->max_features) {
43         hvf_cpu_max_instance_init(cpu);
44     }
45 }
46 
47 static void hvf_cpu_accel_class_init(ObjectClass *oc, void *data)
48 {
49     AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
50 
51     acc->cpu_realizefn = host_cpu_realizefn;
52     acc->cpu_instance_init = hvf_cpu_instance_init;
53 }
54 
55 static const TypeInfo hvf_cpu_accel_type_info = {
56     .name = ACCEL_CPU_NAME("hvf"),
57 
58     .parent = TYPE_ACCEL_CPU,
59     .class_init = hvf_cpu_accel_class_init,
60     .abstract = true,
61 };
62 
63 static void hvf_cpu_accel_register_types(void)
64 {
65     type_register_static(&hvf_cpu_accel_type_info);
66 }
67 
68 type_init(hvf_cpu_accel_register_types);
69