Merge remote-tracking branch 'remotes/elmarco/tags/slirp-pull-request' into staging
[qemu.git] / hw / display / ramfb-standalone.c
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
10 #define RAMFB(obj) OBJECT_CHECK(RAMFBStandaloneState, (obj), TYPE_RAMFB_DEVICE)
11
12 typedef struct RAMFBStandaloneState {
13 SysBusDevice parent_obj;
14 QemuConsole *con;
15 RAMFBState *state;
16 uint32_t xres;
17 uint32_t yres;
18 } RAMFBStandaloneState;
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(dev, errp);
41 }
42
43 static Property ramfb_properties[] = {
44 DEFINE_PROP_UINT32("xres", RAMFBStandaloneState, xres, 0),
45 DEFINE_PROP_UINT32("yres", RAMFBStandaloneState, yres, 0),
46 DEFINE_PROP_END_OF_LIST(),
47 };
48
49 static void ramfb_class_initfn(ObjectClass *klass, void *data)
50 {
51 DeviceClass *dc = DEVICE_CLASS(klass);
52
53 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
54 dc->realize = ramfb_realizefn;
55 device_class_set_props(dc, ramfb_properties);
56 dc->desc = "ram framebuffer standalone device";
57 dc->user_creatable = true;
58 }
59
60 static const TypeInfo ramfb_info = {
61 .name = TYPE_RAMFB_DEVICE,
62 .parent = TYPE_SYS_BUS_DEVICE,
63 .instance_size = sizeof(RAMFBStandaloneState),
64 .class_init = ramfb_class_initfn,
65 };
66
67 static void ramfb_register_types(void)
68 {
69 type_register_static(&ramfb_info);
70 }
71
72 type_init(ramfb_register_types)