master
c 78 lines 2.11 KB
Raw
1 /*
2 * QEMU binary/target API (QOM types)
3 *
4 * Copyright (c) Linaro
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "qemu/osdep.h"
10 #include "qapi/error.h"
11 #include "qom/object.h"
12 #include "qemu/target-info-impl.h"
13 #include "qemu/target-info-init.h"
14 #include "qemu/target-info-qom.h"
15 #include "hw/arm/machines-qom.h"
16 #include "hw/riscv/machines-qom.h"
17
18 static const TypeInfo target_info_types[] = {
19 {
20 .name = TYPE_TARGET_ARM_MACHINE,
21 .parent = TYPE_INTERFACE,
22 },
23 {
24 .name = TYPE_TARGET_AARCH64_MACHINE,
25 .parent = TYPE_INTERFACE,
26 },
27 {
28 .name = TYPE_TARGET_RISCV32_MACHINE,
29 .parent = TYPE_INTERFACE,
30 },
31 {
32 .name = TYPE_TARGET_RISCV64_MACHINE,
33 .parent = TYPE_INTERFACE,
34 },
35 };
36
37 DEFINE_TYPES(target_info_types)
38
39 static void target_info_qom_class_init(ObjectClass *oc, const void * data)
40 {
41 TargetInfoQomClass *klass = TARGET_INFO_CLASS(oc);
42 klass->target_info = data;
43 }
44
45 static const TypeInfo target_info_parent_type = {
46 .name = TYPE_TARGET_INFO,
47 .parent = TYPE_OBJECT,
48 .instance_size = sizeof(TargetInfoQom),
49 .class_size = sizeof(TargetInfoQomClass),
50 /* use class_base_init so children classes can set class_data accordingly */
51 .class_base_init = target_info_qom_class_init,
52 /* children classes will be concrete, which allows to easily query them
53 * without listing this parent class also */
54 .abstract = true,
55 };
56
57 DEFINE_TARGET_INFO_TYPE(target_info_parent_type)
58
59 static const TargetInfo *target_info_ptr;
60
61 const TargetInfo *target_info(void)
62 {
63 return target_info_ptr;
64 }
65
66 void target_info_qom_set_target(void)
67 {
68 g_autoptr(GSList) targets = object_class_get_list(TYPE_TARGET_INFO, false);
69
70 size_t num_found = g_slist_length(targets);
71 if (num_found != 1) {
72 error_setg(&error_fatal, num_found == 0 ?
73 "no target-info is available" :
74 "more than one target-info is available");
75 }
76
77 target_info_ptr = TARGET_INFO_CLASS(targets->data)->target_info;
78 }