xref: /openbmc/qemu/accel/qtest/qtest.c (revision 29318db1)
1 /*
2  * QTest accelerator code
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  *
12  */
13 
14 #include "qemu/osdep.h"
15 #include "qemu/rcu.h"
16 #include "qapi/error.h"
17 #include "qemu/module.h"
18 #include "qemu/option.h"
19 #include "qemu/config-file.h"
20 #include "qemu/accel.h"
21 #include "sysemu/qtest.h"
22 #include "sysemu/cpus.h"
23 #include "qemu/guest-random.h"
24 #include "qemu/main-loop.h"
25 #include "hw/core/cpu.h"
26 
27 static int64_t qtest_clock_counter;
28 
29 static int64_t qtest_get_virtual_clock(void)
30 {
31     return qatomic_read_i64(&qtest_clock_counter);
32 }
33 
34 static void qtest_set_virtual_clock(int64_t count)
35 {
36     qatomic_set_i64(&qtest_clock_counter, count);
37 }
38 
39 static int qtest_init_accel(MachineState *ms)
40 {
41     return 0;
42 }
43 
44 static void qtest_accel_class_init(ObjectClass *oc, void *data)
45 {
46     AccelClass *ac = ACCEL_CLASS(oc);
47     ac->name = "QTest";
48     ac->init_machine = qtest_init_accel;
49     ac->allowed = &qtest_allowed;
50 }
51 
52 #define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
53 
54 static const TypeInfo qtest_accel_type = {
55     .name = TYPE_QTEST_ACCEL,
56     .parent = TYPE_ACCEL,
57     .class_init = qtest_accel_class_init,
58 };
59 module_obj(TYPE_QTEST_ACCEL);
60 
61 static void qtest_accel_ops_class_init(ObjectClass *oc, void *data)
62 {
63     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
64 
65     ops->create_vcpu_thread = dummy_start_vcpu_thread;
66     ops->get_virtual_clock = qtest_get_virtual_clock;
67     ops->set_virtual_clock = qtest_set_virtual_clock;
68 };
69 
70 static const TypeInfo qtest_accel_ops_type = {
71     .name = ACCEL_OPS_NAME("qtest"),
72 
73     .parent = TYPE_ACCEL_OPS,
74     .class_init = qtest_accel_ops_class_init,
75     .abstract = true,
76 };
77 module_obj(ACCEL_OPS_NAME("qtest"));
78 
79 static void qtest_type_init(void)
80 {
81     type_register_static(&qtest_accel_type);
82     type_register_static(&qtest_accel_ops_type);
83 }
84 
85 type_init(qtest_type_init);
86