xref: /openbmc/qemu/hw/display/ramfb-standalone.c (revision 7f6c3d1a)
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/display/ramfb.h"
7 #include "ui/console.h"
8 #include "qom/object.h"
9 
10 typedef struct RAMFBStandaloneState RAMFBStandaloneState;
11 DECLARE_INSTANCE_CHECKER(RAMFBStandaloneState, RAMFB,
12                          TYPE_RAMFB_DEVICE)
13 
14 struct RAMFBStandaloneState {
15     SysBusDevice parent_obj;
16     QemuConsole *con;
17     RAMFBState *state;
18 };
19 
20 static void display_update_wrapper(void *dev)
21 {
22     RAMFBStandaloneState *ramfb = RAMFB(dev);
23 
24     if (0 /* native driver active */) {
25         /* non-standalone device would run native display update here */;
26     } else {
27         ramfb_display_update(ramfb->con, ramfb->state);
28     }
29 }
30 
31 static const GraphicHwOps wrapper_ops = {
32     .gfx_update = display_update_wrapper,
33 };
34 
35 static void ramfb_realizefn(DeviceState *dev, Error **errp)
36 {
37     RAMFBStandaloneState *ramfb = RAMFB(dev);
38 
39     ramfb->con = graphic_console_init(dev, 0, &wrapper_ops, dev);
40     ramfb->state = ramfb_setup(errp);
41 }
42 
43 static void ramfb_class_initfn(ObjectClass *klass, void *data)
44 {
45     DeviceClass *dc = DEVICE_CLASS(klass);
46 
47     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
48     dc->realize = ramfb_realizefn;
49     dc->desc = "ram framebuffer standalone device";
50     dc->user_creatable = true;
51 }
52 
53 static const TypeInfo ramfb_info = {
54     .name          = TYPE_RAMFB_DEVICE,
55     .parent        = TYPE_SYS_BUS_DEVICE,
56     .instance_size = sizeof(RAMFBStandaloneState),
57     .class_init    = ramfb_class_initfn,
58 };
59 
60 static void ramfb_register_types(void)
61 {
62     type_register_static(&ramfb_info);
63 }
64 
65 type_init(ramfb_register_types)
66