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