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