ramfb-standalone.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "qemu/osdep.h"
  2. #include "migration/vmstate.h"
  3. #include "qapi/error.h"
  4. #include "qemu/module.h"
  5. #include "hw/loader.h"
  6. #include "hw/qdev-properties.h"
  7. #include "hw/display/ramfb.h"
  8. #include "ui/console.h"
  9. #include "qom/object.h"
  10. typedef struct RAMFBStandaloneState RAMFBStandaloneState;
  11. DECLARE_INSTANCE_CHECKER(RAMFBStandaloneState, RAMFB,
  12. TYPE_RAMFB_DEVICE)
  13. struct RAMFBStandaloneState {
  14. SysBusDevice parent_obj;
  15. QemuConsole *con;
  16. RAMFBState *state;
  17. bool migrate;
  18. };
  19. static void display_update_wrapper(void *dev)
  20. {
  21. RAMFBStandaloneState *ramfb = RAMFB(dev);
  22. if (0 /* native driver active */) {
  23. /* non-standalone device would run native display update here */;
  24. } else {
  25. ramfb_display_update(ramfb->con, ramfb->state);
  26. }
  27. }
  28. static const GraphicHwOps wrapper_ops = {
  29. .gfx_update = display_update_wrapper,
  30. };
  31. static void ramfb_realizefn(DeviceState *dev, Error **errp)
  32. {
  33. RAMFBStandaloneState *ramfb = RAMFB(dev);
  34. ramfb->con = graphic_console_init(dev, 0, &wrapper_ops, dev);
  35. ramfb->state = ramfb_setup(errp);
  36. }
  37. static bool migrate_needed(void *opaque)
  38. {
  39. RAMFBStandaloneState *ramfb = RAMFB(opaque);
  40. return ramfb->migrate;
  41. }
  42. static const VMStateDescription ramfb_dev_vmstate = {
  43. .name = "ramfb-dev",
  44. .version_id = 1,
  45. .minimum_version_id = 1,
  46. .needed = migrate_needed,
  47. .fields = (const VMStateField[]) {
  48. VMSTATE_STRUCT_POINTER(state, RAMFBStandaloneState, ramfb_vmstate, RAMFBState),
  49. VMSTATE_END_OF_LIST()
  50. }
  51. };
  52. static const Property ramfb_properties[] = {
  53. DEFINE_PROP_BOOL("x-migrate", RAMFBStandaloneState, migrate, true),
  54. };
  55. static void ramfb_class_initfn(ObjectClass *klass, void *data)
  56. {
  57. DeviceClass *dc = DEVICE_CLASS(klass);
  58. set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
  59. dc->vmsd = &ramfb_dev_vmstate;
  60. dc->realize = ramfb_realizefn;
  61. dc->desc = "ram framebuffer standalone device";
  62. device_class_set_props(dc, ramfb_properties);
  63. }
  64. static const TypeInfo ramfb_info = {
  65. .name = TYPE_RAMFB_DEVICE,
  66. .parent = TYPE_DYNAMIC_SYS_BUS_DEVICE,
  67. .instance_size = sizeof(RAMFBStandaloneState),
  68. .class_init = ramfb_class_initfn,
  69. };
  70. static void ramfb_register_types(void)
  71. {
  72. type_register_static(&ramfb_info);
  73. }
  74. type_init(ramfb_register_types)