2
0

accel-system.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * QEMU accel class, system emulation components
  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. #include "qemu/osdep.h"
  26. #include "qemu/accel.h"
  27. #include "hw/boards.h"
  28. #include "system/accel-ops.h"
  29. #include "system/cpus.h"
  30. #include "qemu/error-report.h"
  31. #include "accel-system.h"
  32. int accel_init_machine(AccelState *accel, MachineState *ms)
  33. {
  34. AccelClass *acc = ACCEL_GET_CLASS(accel);
  35. int ret;
  36. ms->accelerator = accel;
  37. *(acc->allowed) = true;
  38. ret = acc->init_machine(ms);
  39. if (ret < 0) {
  40. ms->accelerator = NULL;
  41. *(acc->allowed) = false;
  42. object_unref(OBJECT(accel));
  43. } else {
  44. object_set_accelerator_compat_props(acc->compat_props);
  45. }
  46. return ret;
  47. }
  48. AccelState *current_accel(void)
  49. {
  50. return current_machine->accelerator;
  51. }
  52. void accel_setup_post(MachineState *ms)
  53. {
  54. AccelState *accel = ms->accelerator;
  55. AccelClass *acc = ACCEL_GET_CLASS(accel);
  56. if (acc->setup_post) {
  57. acc->setup_post(ms, accel);
  58. }
  59. }
  60. /* initialize the arch-independent accel operation interfaces */
  61. void accel_system_init_ops_interfaces(AccelClass *ac)
  62. {
  63. const char *ac_name;
  64. char *ops_name;
  65. ObjectClass *oc;
  66. AccelOpsClass *ops;
  67. ac_name = object_class_get_name(OBJECT_CLASS(ac));
  68. g_assert(ac_name != NULL);
  69. ops_name = g_strdup_printf("%s" ACCEL_OPS_SUFFIX, ac_name);
  70. oc = module_object_class_by_name(ops_name);
  71. if (!oc) {
  72. error_report("fatal: could not load module for type '%s'", ops_name);
  73. exit(1);
  74. }
  75. g_free(ops_name);
  76. /*
  77. * all accelerators need to define ops, providing at least a mandatory
  78. * non-NULL create_vcpu_thread operation.
  79. */
  80. ops = ACCEL_OPS_CLASS(oc);
  81. if (ops->ops_init) {
  82. ops->ops_init(ops);
  83. }
  84. cpus_register_accel(ops);
  85. }
  86. static const TypeInfo accel_ops_type_info = {
  87. .name = TYPE_ACCEL_OPS,
  88. .parent = TYPE_OBJECT,
  89. .abstract = true,
  90. .class_size = sizeof(AccelOpsClass),
  91. };
  92. static void accel_system_register_types(void)
  93. {
  94. type_register_static(&accel_ops_type_info);
  95. }
  96. type_init(accel_system_register_types);