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