| 1 | #include "qemu/osdep.h" |
| 2 | #include "migration/vmstate.h" |
| 3 | #include "qapi/error.h" |
| 4 | #include "qemu/module.h" |
| 5 | #include "hw/core/loader.h" |
| 6 | #include "hw/core/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 bool 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 | return true; |
| 34 | } |
| 35 | |
| 36 | static const GraphicHwOps wrapper_ops = { |
| 37 | .gfx_update = display_update_wrapper, |
| 38 | }; |
| 39 | |
| 40 | static void ramfb_realizefn(DeviceState *dev, Error **errp) |
| 41 | { |
| 42 | RAMFBStandaloneState *ramfb = RAMFB(dev); |
| 43 | |
| 44 | ramfb->con = qemu_graphic_console_create(dev, 0, &wrapper_ops, dev); |
| 45 | ramfb->state = ramfb_setup(ramfb->use_legacy_x86_rom, errp); |
| 46 | } |
| 47 | |
| 48 | static bool migrate_needed(void *opaque) |
| 49 | { |
| 50 | RAMFBStandaloneState *ramfb = RAMFB(opaque); |
| 51 | |
| 52 | return ramfb->migrate; |
| 53 | } |
| 54 | |
| 55 | static const VMStateDescription ramfb_dev_vmstate = { |
| 56 | .name = "ramfb-dev", |
| 57 | .version_id = 1, |
| 58 | .minimum_version_id = 1, |
| 59 | .needed = migrate_needed, |
| 60 | .fields = (const VMStateField[]) { |
| 61 | VMSTATE_STRUCT_POINTER(state, RAMFBStandaloneState, ramfb_vmstate, RAMFBState), |
| 62 | VMSTATE_END_OF_LIST() |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | static const Property ramfb_properties[] = { |
| 67 | DEFINE_PROP_BOOL("x-migrate", RAMFBStandaloneState, migrate, true), |
| 68 | DEFINE_PROP_BOOL("use-legacy-x86-rom", RAMFBStandaloneState, |
| 69 | use_legacy_x86_rom, false), |
| 70 | }; |
| 71 | |
| 72 | static void ramfb_class_initfn(ObjectClass *klass, const void *data) |
| 73 | { |
| 74 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 75 | |
| 76 | set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); |
| 77 | dc->vmsd = &ramfb_dev_vmstate; |
| 78 | dc->realize = ramfb_realizefn; |
| 79 | dc->desc = "ram framebuffer standalone device"; |
| 80 | device_class_set_props(dc, ramfb_properties); |
| 81 | } |
| 82 | |
| 83 | static const TypeInfo ramfb_info = { |
| 84 | .name = TYPE_RAMFB_DEVICE, |
| 85 | .parent = TYPE_DYNAMIC_SYS_BUS_DEVICE, |
| 86 | .instance_size = sizeof(RAMFBStandaloneState), |
| 87 | .class_init = ramfb_class_initfn, |
| 88 | }; |
| 89 | |
| 90 | static void ramfb_register_types(void) |
| 91 | { |
| 92 | type_register_static(&ramfb_info); |
| 93 | } |
| 94 | |
| 95 | type_init(ramfb_register_types) |