]>
Commit | Line | Data |
---|---|---|
a1a9cb0c | 1 | /* |
940e43aa | 2 | * QEMU accel class, system emulation components |
a1a9cb0c EH |
3 | * |
4 | * Copyright (c) 2003-2008 Fabrice Bellard | |
5 | * Copyright (c) 2014 Red Hat Inc. | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
23 | * THE SOFTWARE. | |
24 | */ | |
25 | ||
d38ea87a | 26 | #include "qemu/osdep.h" |
940e43aa | 27 | #include "qemu/accel.h" |
f6a1ef64 | 28 | #include "hw/boards.h" |
0f66536a | 29 | #include "system/accel-ops.h" |
32cad1ff | 30 | #include "system/cpus.h" |
cc37d98b | 31 | #include "qemu/error-report.h" |
64cbcf1d | 32 | #include "accel-internal.h" |
a1a9cb0c | 33 | |
fc5cf826 | 34 | int accel_init_machine(AccelState *accel, MachineState *ms) |
d95c8527 | 35 | { |
fc5cf826 | 36 | AccelClass *acc = ACCEL_GET_CLASS(accel); |
d95c8527 | 37 | int ret; |
ac2da55e | 38 | ms->accelerator = accel; |
d95c8527 | 39 | *(acc->allowed) = true; |
f6a1ef64 | 40 | ret = acc->init_machine(ms); |
d95c8527 | 41 | if (ret < 0) { |
ac2da55e | 42 | ms->accelerator = NULL; |
d95c8527 | 43 | *(acc->allowed) = false; |
ac2da55e | 44 | object_unref(OBJECT(accel)); |
79b9d4bd MA |
45 | } else { |
46 | object_set_accelerator_compat_props(acc->compat_props); | |
d95c8527 EH |
47 | } |
48 | return ret; | |
49 | } | |
50 | ||
ce7cdebd PMD |
51 | AccelState *current_accel(void) |
52 | { | |
53 | return current_machine->accelerator; | |
54 | } | |
55 | ||
7a64c17f IJ |
56 | void accel_setup_post(MachineState *ms) |
57 | { | |
58 | AccelState *accel = ms->accelerator; | |
59 | AccelClass *acc = ACCEL_GET_CLASS(accel); | |
60 | if (acc->setup_post) { | |
61 | acc->setup_post(ms, accel); | |
62 | } | |
63 | } | |
b86f59c7 CF |
64 | |
65 | /* initialize the arch-independent accel operation interfaces */ | |
64cbcf1d | 66 | void accel_init_ops_interfaces(AccelClass *ac) |
b86f59c7 CF |
67 | { |
68 | const char *ac_name; | |
69 | char *ops_name; | |
5141e9a2 | 70 | ObjectClass *oc; |
b86f59c7 CF |
71 | AccelOpsClass *ops; |
72 | ||
73 | ac_name = object_class_get_name(OBJECT_CLASS(ac)); | |
74 | g_assert(ac_name != NULL); | |
75 | ||
76 | ops_name = g_strdup_printf("%s" ACCEL_OPS_SUFFIX, ac_name); | |
5141e9a2 CF |
77 | oc = module_object_class_by_name(ops_name); |
78 | if (!oc) { | |
79 | error_report("fatal: could not load module for type '%s'", ops_name); | |
80 | exit(1); | |
81 | } | |
b86f59c7 | 82 | g_free(ops_name); |
b86f59c7 CF |
83 | /* |
84 | * all accelerators need to define ops, providing at least a mandatory | |
85 | * non-NULL create_vcpu_thread operation. | |
86 | */ | |
8aade934 | 87 | ops = ACCEL_OPS_CLASS(oc); |
b86f59c7 CF |
88 | if (ops->ops_init) { |
89 | ops->ops_init(ops); | |
90 | } | |
91 | cpus_register_accel(ops); | |
92 | } | |
93 | ||
94 | static const TypeInfo accel_ops_type_info = { | |
95 | .name = TYPE_ACCEL_OPS, | |
96 | .parent = TYPE_OBJECT, | |
97 | .abstract = true, | |
98 | .class_size = sizeof(AccelOpsClass), | |
99 | }; | |
100 | ||
0017c64e | 101 | static void accel_system_register_types(void) |
b86f59c7 CF |
102 | { |
103 | type_register_static(&accel_ops_type_info); | |
104 | } | |
0017c64e | 105 | type_init(accel_system_register_types); |