Browse Source

hw/display/ramfb: initialize fw-config space with xres/ yres

If xres / yres were specified in QEMU command line, write them as an initial
resolution to the fw-config space on guest reset, which a later BIOS / OVMF
patch can take advantage of.

Signed-off-by: HOU Qiming <hqm03ster@gmail.com>
Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Message-id: 2019051311.17588-4-marcel.apfelbaum@gmail.com
[fixed malformed patch]
Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
master
Hou Qiming 1 month ago
parent
commit
f79081b4b7
5 changed files with 30 additions and 6 deletions
  1. 11
    1
      hw/display/ramfb-standalone.c
  2. 15
    1
      hw/display/ramfb.c
  3. 2
    2
      hw/vfio/display.c
  4. 1
    1
      include/hw/display/ramfb.h
  5. 1
    1
      stubs/ramfb.c

+ 11
- 1
hw/display/ramfb-standalone.c View File

@@ -1,6 +1,7 @@
1 1
 #include "qemu/osdep.h"
2 2
 #include "qapi/error.h"
3 3
 #include "hw/loader.h"
4
+#include "hw/isa/isa.h"
4 5
 #include "hw/display/ramfb.h"
5 6
 #include "ui/console.h"
6 7
 #include "sysemu/sysemu.h"
@@ -11,6 +12,8 @@ typedef struct RAMFBStandaloneState {
11 12
     SysBusDevice parent_obj;
12 13
     QemuConsole *con;
13 14
     RAMFBState *state;
15
+    uint32_t xres;
16
+    uint32_t yres;
14 17
 } RAMFBStandaloneState;
15 18
 
16 19
 static void display_update_wrapper(void *dev)
@@ -33,15 +36,22 @@ static void ramfb_realizefn(DeviceState *dev, Error **errp)
33 36
     RAMFBStandaloneState *ramfb = RAMFB(dev);
34 37
 
35 38
     ramfb->con = graphic_console_init(dev, 0, &wrapper_ops, dev);
36
-    ramfb->state = ramfb_setup(errp);
39
+    ramfb->state = ramfb_setup(dev, errp);
37 40
 }
38 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
+
39 48
 static void ramfb_class_initfn(ObjectClass *klass, void *data)
40 49
 {
41 50
     DeviceClass *dc = DEVICE_CLASS(klass);
42 51
 
43 52
     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
44 53
     dc->realize = ramfb_realizefn;
54
+    dc->props = ramfb_properties;
45 55
     dc->desc = "ram framebuffer standalone device";
46 56
     dc->user_creatable = true;
47 57
 }

+ 15
- 1
hw/display/ramfb.c View File

@@ -12,6 +12,7 @@
12 12
  */
13 13
 #include "qemu/osdep.h"
14 14
 #include "qapi/error.h"
15
+#include "qemu/option.h"
15 16
 #include "hw/loader.h"
16 17
 #include "hw/display/ramfb.h"
17 18
 #include "ui/console.h"
@@ -29,6 +30,7 @@ struct QEMU_PACKED RAMFBCfg {
29 30
 struct RAMFBState {
30 31
     DisplaySurface *ds;
31 32
     uint32_t width, height;
33
+    uint32_t starting_width, starting_height;
32 34
     struct RAMFBCfg cfg;
33 35
     bool locked;
34 36
 };
@@ -114,9 +116,11 @@ static void ramfb_reset(void *opaque)
114 116
     RAMFBState *s = (RAMFBState *)opaque;
115 117
     s->locked = false;
116 118
     memset(&s->cfg, 0, sizeof(s->cfg));
119
+    s->cfg.width = s->starting_width;
120
+    s->cfg.height = s->starting_height;
117 121
 }
118 122
 
119
-RAMFBState *ramfb_setup(Error **errp)
123
+RAMFBState *ramfb_setup(DeviceState* dev, Error **errp)
120 124
 {
121 125
     FWCfgState *fw_cfg = fw_cfg_find();
122 126
     RAMFBState *s;
@@ -128,6 +132,16 @@ RAMFBState *ramfb_setup(Error **errp)
128 132
 
129 133
     s = g_new0(RAMFBState, 1);
130 134
 
135
+    const char *s_fb_width = qemu_opt_get(dev->opts, "xres");
136
+    const char *s_fb_height = qemu_opt_get(dev->opts, "yres");
137
+    if (s_fb_width) {
138
+        s->cfg.width = atoi(s_fb_width);
139
+        s->starting_width = s->cfg.width;
140
+    }
141
+    if (s_fb_height) {
142
+        s->cfg.height = atoi(s_fb_height);
143
+        s->starting_height = s->cfg.height;
144
+    }
131 145
     s->locked = false;
132 146
 
133 147
     rom_add_vga("vgabios-ramfb.bin");

+ 2
- 2
hw/vfio/display.c View File

@@ -352,7 +352,7 @@ static int vfio_display_dmabuf_init(VFIOPCIDevice *vdev, Error **errp)
352 352
                                           &vfio_display_dmabuf_ops,
353 353
                                           vdev);
354 354
     if (vdev->enable_ramfb) {
355
-        vdev->dpy->ramfb = ramfb_setup(errp);
355
+        vdev->dpy->ramfb = ramfb_setup(DEVICE(vdev), errp);
356 356
     }
357 357
     vfio_display_edid_init(vdev);
358 358
     return 0;
@@ -478,7 +478,7 @@ static int vfio_display_region_init(VFIOPCIDevice *vdev, Error **errp)
478 478
                                           &vfio_display_region_ops,
479 479
                                           vdev);
480 480
     if (vdev->enable_ramfb) {
481
-        vdev->dpy->ramfb = ramfb_setup(errp);
481
+        vdev->dpy->ramfb = ramfb_setup(DEVICE(vdev), errp);
482 482
     }
483 483
     return 0;
484 484
 }

+ 1
- 1
include/hw/display/ramfb.h View File

@@ -4,7 +4,7 @@
4 4
 /* ramfb.c */
5 5
 typedef struct RAMFBState RAMFBState;
6 6
 void ramfb_display_update(QemuConsole *con, RAMFBState *s);
7
-RAMFBState *ramfb_setup(Error **errp);
7
+RAMFBState *ramfb_setup(DeviceState *dev, Error **errp);
8 8
 
9 9
 /* ramfb-standalone.c */
10 10
 #define TYPE_RAMFB_DEVICE "ramfb"

+ 1
- 1
stubs/ramfb.c View File

@@ -6,7 +6,7 @@ void ramfb_display_update(QemuConsole *con, RAMFBState *s)
6 6
 {
7 7
 }
8 8
 
9
-RAMFBState *ramfb_setup(Error **errp)
9
+RAMFBState *ramfb_setup(DeviceState* dev, Error **errp)
10 10
 {
11 11
     error_setg(errp, "ramfb support not available");
12 12
     return NULL;

Loading…
Cancel
Save