xref: /openbmc/qemu/accel/accel-system.c (revision c94bee4cd6693c1c65ba43bb8970cf909dec378b)
10017c64eSPhilippe Mathieu-Daudé /*
20017c64eSPhilippe Mathieu-Daudé  * QEMU accel class, system emulation components
30017c64eSPhilippe Mathieu-Daudé  *
40017c64eSPhilippe Mathieu-Daudé  * Copyright (c) 2003-2008 Fabrice Bellard
50017c64eSPhilippe Mathieu-Daudé  * Copyright (c) 2014 Red Hat Inc.
60017c64eSPhilippe Mathieu-Daudé  *
70017c64eSPhilippe Mathieu-Daudé  * Permission is hereby granted, free of charge, to any person obtaining a copy
80017c64eSPhilippe Mathieu-Daudé  * of this software and associated documentation files (the "Software"), to deal
90017c64eSPhilippe Mathieu-Daudé  * in the Software without restriction, including without limitation the rights
100017c64eSPhilippe Mathieu-Daudé  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
110017c64eSPhilippe Mathieu-Daudé  * copies of the Software, and to permit persons to whom the Software is
120017c64eSPhilippe Mathieu-Daudé  * furnished to do so, subject to the following conditions:
130017c64eSPhilippe Mathieu-Daudé  *
140017c64eSPhilippe Mathieu-Daudé  * The above copyright notice and this permission notice shall be included in
150017c64eSPhilippe Mathieu-Daudé  * all copies or substantial portions of the Software.
160017c64eSPhilippe Mathieu-Daudé  *
170017c64eSPhilippe Mathieu-Daudé  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
180017c64eSPhilippe Mathieu-Daudé  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
190017c64eSPhilippe Mathieu-Daudé  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
200017c64eSPhilippe Mathieu-Daudé  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
210017c64eSPhilippe Mathieu-Daudé  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
220017c64eSPhilippe Mathieu-Daudé  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
230017c64eSPhilippe Mathieu-Daudé  * THE SOFTWARE.
240017c64eSPhilippe Mathieu-Daudé  */
250017c64eSPhilippe Mathieu-Daudé 
260017c64eSPhilippe Mathieu-Daudé #include "qemu/osdep.h"
270017c64eSPhilippe Mathieu-Daudé #include "qemu/accel.h"
280017c64eSPhilippe Mathieu-Daudé #include "hw/boards.h"
290017c64eSPhilippe Mathieu-Daudé #include "sysemu/cpus.h"
300017c64eSPhilippe Mathieu-Daudé #include "qemu/error-report.h"
310017c64eSPhilippe Mathieu-Daudé #include "accel-system.h"
320017c64eSPhilippe Mathieu-Daudé 
accel_init_machine(AccelState * accel,MachineState * ms)330017c64eSPhilippe Mathieu-Daudé int accel_init_machine(AccelState *accel, MachineState *ms)
340017c64eSPhilippe Mathieu-Daudé {
350017c64eSPhilippe Mathieu-Daudé     AccelClass *acc = ACCEL_GET_CLASS(accel);
360017c64eSPhilippe Mathieu-Daudé     int ret;
370017c64eSPhilippe Mathieu-Daudé     ms->accelerator = accel;
380017c64eSPhilippe Mathieu-Daudé     *(acc->allowed) = true;
390017c64eSPhilippe Mathieu-Daudé     ret = acc->init_machine(ms);
400017c64eSPhilippe Mathieu-Daudé     if (ret < 0) {
410017c64eSPhilippe Mathieu-Daudé         ms->accelerator = NULL;
420017c64eSPhilippe Mathieu-Daudé         *(acc->allowed) = false;
430017c64eSPhilippe Mathieu-Daudé         object_unref(OBJECT(accel));
440017c64eSPhilippe Mathieu-Daudé     } else {
450017c64eSPhilippe Mathieu-Daudé         object_set_accelerator_compat_props(acc->compat_props);
460017c64eSPhilippe Mathieu-Daudé     }
470017c64eSPhilippe Mathieu-Daudé     return ret;
480017c64eSPhilippe Mathieu-Daudé }
490017c64eSPhilippe Mathieu-Daudé 
current_accel(void)500017c64eSPhilippe Mathieu-Daudé AccelState *current_accel(void)
510017c64eSPhilippe Mathieu-Daudé {
520017c64eSPhilippe Mathieu-Daudé     return current_machine->accelerator;
530017c64eSPhilippe Mathieu-Daudé }
540017c64eSPhilippe Mathieu-Daudé 
accel_setup_post(MachineState * ms)550017c64eSPhilippe Mathieu-Daudé void accel_setup_post(MachineState *ms)
560017c64eSPhilippe Mathieu-Daudé {
570017c64eSPhilippe Mathieu-Daudé     AccelState *accel = ms->accelerator;
580017c64eSPhilippe Mathieu-Daudé     AccelClass *acc = ACCEL_GET_CLASS(accel);
590017c64eSPhilippe Mathieu-Daudé     if (acc->setup_post) {
600017c64eSPhilippe Mathieu-Daudé         acc->setup_post(ms, accel);
610017c64eSPhilippe Mathieu-Daudé     }
620017c64eSPhilippe Mathieu-Daudé }
630017c64eSPhilippe Mathieu-Daudé 
640017c64eSPhilippe Mathieu-Daudé /* initialize the arch-independent accel operation interfaces */
accel_system_init_ops_interfaces(AccelClass * ac)65463b0068SPhilippe Mathieu-Daudé void accel_system_init_ops_interfaces(AccelClass *ac)
660017c64eSPhilippe Mathieu-Daudé {
670017c64eSPhilippe Mathieu-Daudé     const char *ac_name;
680017c64eSPhilippe Mathieu-Daudé     char *ops_name;
690017c64eSPhilippe Mathieu-Daudé     ObjectClass *oc;
700017c64eSPhilippe Mathieu-Daudé     AccelOpsClass *ops;
710017c64eSPhilippe Mathieu-Daudé 
720017c64eSPhilippe Mathieu-Daudé     ac_name = object_class_get_name(OBJECT_CLASS(ac));
730017c64eSPhilippe Mathieu-Daudé     g_assert(ac_name != NULL);
740017c64eSPhilippe Mathieu-Daudé 
750017c64eSPhilippe Mathieu-Daudé     ops_name = g_strdup_printf("%s" ACCEL_OPS_SUFFIX, ac_name);
760017c64eSPhilippe Mathieu-Daudé     oc = module_object_class_by_name(ops_name);
770017c64eSPhilippe Mathieu-Daudé     if (!oc) {
780017c64eSPhilippe Mathieu-Daudé         error_report("fatal: could not load module for type '%s'", ops_name);
790017c64eSPhilippe Mathieu-Daudé         exit(1);
800017c64eSPhilippe Mathieu-Daudé     }
810017c64eSPhilippe Mathieu-Daudé     g_free(ops_name);
820017c64eSPhilippe Mathieu-Daudé     /*
830017c64eSPhilippe Mathieu-Daudé      * all accelerators need to define ops, providing at least a mandatory
840017c64eSPhilippe Mathieu-Daudé      * non-NULL create_vcpu_thread operation.
850017c64eSPhilippe Mathieu-Daudé      */
86*8aade934SPaolo Bonzini     ops = ACCEL_OPS_CLASS(oc);
870017c64eSPhilippe Mathieu-Daudé     if (ops->ops_init) {
880017c64eSPhilippe Mathieu-Daudé         ops->ops_init(ops);
890017c64eSPhilippe Mathieu-Daudé     }
900017c64eSPhilippe Mathieu-Daudé     cpus_register_accel(ops);
910017c64eSPhilippe Mathieu-Daudé }
920017c64eSPhilippe Mathieu-Daudé 
930017c64eSPhilippe Mathieu-Daudé static const TypeInfo accel_ops_type_info = {
940017c64eSPhilippe Mathieu-Daudé     .name = TYPE_ACCEL_OPS,
950017c64eSPhilippe Mathieu-Daudé     .parent = TYPE_OBJECT,
960017c64eSPhilippe Mathieu-Daudé     .abstract = true,
970017c64eSPhilippe Mathieu-Daudé     .class_size = sizeof(AccelOpsClass),
980017c64eSPhilippe Mathieu-Daudé };
990017c64eSPhilippe Mathieu-Daudé 
accel_system_register_types(void)1000017c64eSPhilippe Mathieu-Daudé static void accel_system_register_types(void)
1010017c64eSPhilippe Mathieu-Daudé {
1020017c64eSPhilippe Mathieu-Daudé     type_register_static(&accel_ops_type_info);
1030017c64eSPhilippe Mathieu-Daudé }
1040017c64eSPhilippe Mathieu-Daudé type_init(accel_system_register_types);
105