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 11 typedef struct RAMFBStandaloneState RAMFBStandaloneState; 12 DECLARE_INSTANCE_CHECKER(RAMFBStandaloneState, RAMFB, 13 TYPE_RAMFB_DEVICE) 14 15 struct RAMFBStandaloneState { 16 SysBusDevice parent_obj; 17 QemuConsole *con; 18 RAMFBState *state; 19 bool migrate; 20 bool use_legacy_x86_rom; 21 }; 22 23 static void display_update_wrapper(void *dev) 24 { 25 RAMFBStandaloneState *ramfb = RAMFB(dev); 26 27 if (0 /* native driver active */) { 28 /* non-standalone device would run native display update here */; 29 } else { 30 ramfb_display_update(ramfb->con, ramfb->state); 31 } 32 } 33 34 static const GraphicHwOps wrapper_ops = { 35 .gfx_update = display_update_wrapper, 36 }; 37 38 static void ramfb_realizefn(DeviceState *dev, Error **errp) 39 { 40 RAMFBStandaloneState *ramfb = RAMFB(dev); 41 42 ramfb->con = graphic_console_init(dev, 0, &wrapper_ops, dev); 43 ramfb->state = ramfb_setup(ramfb->use_legacy_x86_rom, errp); 44 } 45 46 static bool migrate_needed(void *opaque) 47 { 48 RAMFBStandaloneState *ramfb = RAMFB(opaque); 49 50 return ramfb->migrate; 51 } 52 53 static const VMStateDescription ramfb_dev_vmstate = { 54 .name = "ramfb-dev", 55 .version_id = 1, 56 .minimum_version_id = 1, 57 .needed = migrate_needed, 58 .fields = (const VMStateField[]) { 59 VMSTATE_STRUCT_POINTER(state, RAMFBStandaloneState, ramfb_vmstate, RAMFBState), 60 VMSTATE_END_OF_LIST() 61 } 62 }; 63 64 static const Property ramfb_properties[] = { 65 DEFINE_PROP_BOOL("x-migrate", RAMFBStandaloneState, migrate, true), 66 DEFINE_PROP_BOOL("use-legacy-x86-rom", RAMFBStandaloneState, 67 use_legacy_x86_rom, false), 68 }; 69 70 static void ramfb_class_initfn(ObjectClass *klass, const void *data) 71 { 72 DeviceClass *dc = DEVICE_CLASS(klass); 73 74 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); 75 dc->vmsd = &ramfb_dev_vmstate; 76 dc->realize = ramfb_realizefn; 77 dc->desc = "ram framebuffer standalone device"; 78 device_class_set_props(dc, ramfb_properties); 79 } 80 81 static const TypeInfo ramfb_info = { 82 .name = TYPE_RAMFB_DEVICE, 83 .parent = TYPE_DYNAMIC_SYS_BUS_DEVICE, 84 .instance_size = sizeof(RAMFBStandaloneState), 85 .class_init = ramfb_class_initfn, 86 }; 87 88 static void ramfb_register_types(void) 89 { 90 type_register_static(&ramfb_info); 91 } 92 93 type_init(ramfb_register_types) 94