blob: 9c804ba9e3b68e48d75f8dec90ce01041f7092bd [file] [log] [blame]
Eduardo Habkosta1a9cb02014-09-26 17:45:17 -03001/*
Claudio Fontana940e43a2021-02-04 17:39:24 +01002 * QEMU accel class, system emulation components
Eduardo Habkosta1a9cb02014-09-26 17:45:17 -03003 *
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
Peter Maydelld38ea872016-01-29 17:50:05 +000026#include "qemu/osdep.h"
Claudio Fontana940e43a2021-02-04 17:39:24 +010027#include "qemu/accel.h"
Eduardo Habkostf6a1ef62014-09-26 17:45:30 -030028#include "hw/boards.h"
Claudio Fontanab86f59c2021-02-04 17:39:25 +010029#include "sysemu/cpus.h"
Richard Hendersoncc37d982023-03-15 17:43:13 +000030#include "qemu/error-report.h"
Claudio Fontanab86f59c2021-02-04 17:39:25 +010031#include "accel-softmmu.h"
Eduardo Habkosta1a9cb02014-09-26 17:45:17 -030032
Paolo Bonzinifc5cf822019-11-13 14:03:46 +010033int accel_init_machine(AccelState *accel, MachineState *ms)
Eduardo Habkostd95c8522014-09-26 17:45:28 -030034{
Paolo Bonzinifc5cf822019-11-13 14:03:46 +010035 AccelClass *acc = ACCEL_GET_CLASS(accel);
Eduardo Habkostd95c8522014-09-26 17:45:28 -030036 int ret;
Eduardo Habkostac2da552014-09-26 17:45:31 -030037 ms->accelerator = accel;
Eduardo Habkostd95c8522014-09-26 17:45:28 -030038 *(acc->allowed) = true;
Eduardo Habkostf6a1ef62014-09-26 17:45:30 -030039 ret = acc->init_machine(ms);
Eduardo Habkostd95c8522014-09-26 17:45:28 -030040 if (ret < 0) {
Eduardo Habkostac2da552014-09-26 17:45:31 -030041 ms->accelerator = NULL;
Eduardo Habkostd95c8522014-09-26 17:45:28 -030042 *(acc->allowed) = false;
Eduardo Habkostac2da552014-09-26 17:45:31 -030043 object_unref(OBJECT(accel));
Markus Armbruster79b9d4b2019-04-01 11:08:27 +020044 } else {
45 object_set_accelerator_compat_props(acc->compat_props);
Eduardo Habkostd95c8522014-09-26 17:45:28 -030046 }
47 return ret;
48}
49
Philippe Mathieu-Daudéce7cdeb2020-01-21 12:03:47 +010050AccelState *current_accel(void)
51{
52 return current_machine->accelerator;
53}
54
Ian Jackson7a64c172018-03-09 12:02:50 +000055void accel_setup_post(MachineState *ms)
56{
57 AccelState *accel = ms->accelerator;
58 AccelClass *acc = ACCEL_GET_CLASS(accel);
59 if (acc->setup_post) {
60 acc->setup_post(ms, accel);
61 }
62}
Claudio Fontanab86f59c2021-02-04 17:39:25 +010063
64/* initialize the arch-independent accel operation interfaces */
65void accel_init_ops_interfaces(AccelClass *ac)
66{
67 const char *ac_name;
68 char *ops_name;
Claudio Fontana5141e9a2022-09-29 11:30:35 +020069 ObjectClass *oc;
Claudio Fontanab86f59c2021-02-04 17:39:25 +010070 AccelOpsClass *ops;
71
72 ac_name = object_class_get_name(OBJECT_CLASS(ac));
73 g_assert(ac_name != NULL);
74
75 ops_name = g_strdup_printf("%s" ACCEL_OPS_SUFFIX, ac_name);
Gerd Hoffmannf9349072021-06-24 12:38:27 +020076 ops = ACCEL_OPS_CLASS(module_object_class_by_name(ops_name));
Claudio Fontana5141e9a2022-09-29 11:30:35 +020077 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 }
Claudio Fontanab86f59c2021-02-04 17:39:25 +010082 g_free(ops_name);
Claudio Fontana5141e9a2022-09-29 11:30:35 +020083 ops = ACCEL_OPS_CLASS(oc);
Claudio Fontanab86f59c2021-02-04 17:39:25 +010084 /*
85 * all accelerators need to define ops, providing at least a mandatory
86 * non-NULL create_vcpu_thread operation.
87 */
88 g_assert(ops != NULL);
89 if (ops->ops_init) {
90 ops->ops_init(ops);
91 }
92 cpus_register_accel(ops);
93}
94
95static const TypeInfo accel_ops_type_info = {
96 .name = TYPE_ACCEL_OPS,
97 .parent = TYPE_OBJECT,
98 .abstract = true,
99 .class_size = sizeof(AccelOpsClass),
100};
101
102static void accel_softmmu_register_types(void)
103{
104 type_register_static(&accel_ops_type_info);
105}
106type_init(accel_softmmu_register_types);