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