From 3745d59ee489bccdab8f678a0f7972e7dbe189f9 Mon Sep 17 00:00:00 2001 From: Guoqing Zhang Date: Fri, 18 Sep 2020 19:16:32 +0800 Subject: [PATCH 1/9] virtio-gpu-3d: fix abnormal display after a warm reboot When resetting virtio-gpu, virgl_renderer_reset() should be called to ensure that the virglrenderer status is correct. Signed-off-by: Guoqing Zhang Reviewed-by: Qi Liu Message-id: 20200918111632.37354-1-zhangguoqing.kernel@bytedance.com Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu-3d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/display/virtio-gpu-3d.c b/hw/display/virtio-gpu-3d.c index 96621576c2..1bd33d7aed 100644 --- a/hw/display/virtio-gpu-3d.c +++ b/hw/display/virtio-gpu-3d.c @@ -595,7 +595,7 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g) { int i; - /* virgl_renderer_reset() ??? */ + virgl_renderer_reset(); for (i = 0; i < g->parent_obj.conf.max_outputs; i++) { if (i != 0) { dpy_gfx_replace_surface(g->parent_obj.scanout[i].con, NULL); From 6c8f847ac1356387692f224b48c7a83ac5918b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 27 Sep 2020 18:57:46 +0400 Subject: [PATCH 2/9] edid: fix physical display size computation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Divide the resolution by the DPI, and multiply to mm. Note the computation done for edid[21/22] is correct (in cm). Signed-off-by: Marc-André Lureau Message-id: 20200927145751.365446-2-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/edid-generate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/display/edid-generate.c b/hw/display/edid-generate.c index e58472fde5..618c74e1df 100644 --- a/hw/display/edid-generate.c +++ b/hw/display/edid-generate.c @@ -208,8 +208,8 @@ static void edid_desc_timing(uint8_t *desc, uint32_t dpi) { /* physical display size */ - uint32_t xmm = xres * dpi / 254; - uint32_t ymm = yres * dpi / 254; + uint32_t xmm = xres * 254 / 10 / dpi; + uint32_t ymm = yres * 254 / 10 / dpi; /* pull some realistic looking timings out of thin air */ uint32_t xfront = xres * 25 / 100; From fd36eade0187a4efe0507b41fae22277300d1c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 27 Sep 2020 18:57:47 +0400 Subject: [PATCH 3/9] edid: use physical dimensions if available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace dpi with width_mm/height_mm in qemu_edid_info. Use it when set (non-zero) to compute the DPI and generate the EDID. Signed-off-by: Marc-André Lureau Message-id: 20200927145751.365446-3-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/edid-generate.c | 36 +++++++++++++++++++++++++----------- include/hw/display/edid.h | 5 ++++- qemu-edid.c | 11 +++++++++-- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/hw/display/edid-generate.c b/hw/display/edid-generate.c index 618c74e1df..1665b7cbb2 100644 --- a/hw/display/edid-generate.c +++ b/hw/display/edid-generate.c @@ -205,12 +205,8 @@ static void edid_desc_dummy(uint8_t *desc) static void edid_desc_timing(uint8_t *desc, uint32_t xres, uint32_t yres, - uint32_t dpi) + uint32_t xmm, uint32_t ymm) { - /* physical display size */ - uint32_t xmm = xres * 254 / 10 / dpi; - uint32_t ymm = yres * 254 / 10 / dpi; - /* pull some realistic looking timings out of thin air */ uint32_t xfront = xres * 25 / 100; uint32_t xsync = xres * 3 / 100; @@ -290,12 +286,24 @@ static void edid_colorspace(uint8_t *edid, edid[34] = white_y >> 2; } +static uint32_t qemu_edid_dpi_from_mm(uint32_t mm, uint32_t res) +{ + return res * 254 / 10 / mm; +} + +uint32_t qemu_edid_dpi_to_mm(uint32_t dpi, uint32_t res) +{ + return res * 254 / 10 / dpi; +} + void qemu_edid_generate(uint8_t *edid, size_t size, qemu_edid_info *info) { uint32_t desc = 54; uint8_t *xtra3 = NULL; uint8_t *dta = NULL; + uint32_t width_mm, height_mm; + uint32_t dpi = 100; /* if no width_mm/height_mm */ /* =============== set defaults =============== */ @@ -305,15 +313,20 @@ void qemu_edid_generate(uint8_t *edid, size_t size, if (!info->name) { info->name = "QEMU Monitor"; } - if (!info->dpi) { - info->dpi = 100; - } if (!info->prefx) { info->prefx = 1024; } if (!info->prefy) { info->prefy = 768; } + if (info->width_mm && info->height_mm) { + width_mm = info->width_mm; + height_mm = info->height_mm; + dpi = qemu_edid_dpi_from_mm(width_mm, info->prefx); + } else { + width_mm = qemu_edid_dpi_to_mm(dpi, info->prefx); + height_mm = qemu_edid_dpi_to_mm(dpi, info->prefy); + } /* =============== extensions =============== */ @@ -360,8 +373,8 @@ void qemu_edid_generate(uint8_t *edid, size_t size, edid[20] = 0xa5; /* screen size: undefined */ - edid[21] = info->prefx * 254 / 100 / info->dpi; - edid[22] = info->prefy * 254 / 100 / info->dpi; + edid[21] = width_mm / 10; + edid[22] = height_mm / 10; /* display gamma: 2.2 */ edid[23] = 220 - 100; @@ -387,7 +400,8 @@ void qemu_edid_generate(uint8_t *edid, size_t size, /* =============== descriptor blocks =============== */ - edid_desc_timing(edid + desc, info->prefx, info->prefy, info->dpi); + edid_desc_timing(edid + desc, info->prefx, info->prefy, + width_mm, height_mm); desc += 18; edid_desc_ranges(edid + desc); diff --git a/include/hw/display/edid.h b/include/hw/display/edid.h index 5b1de57f24..1f8fc9b375 100644 --- a/include/hw/display/edid.h +++ b/include/hw/display/edid.h @@ -5,7 +5,8 @@ typedef struct qemu_edid_info { const char *vendor; /* http://www.uefi.org/pnp_id_list */ const char *name; const char *serial; - uint32_t dpi; + uint16_t width_mm; + uint16_t height_mm; uint32_t prefx; uint32_t prefy; uint32_t maxx; @@ -18,6 +19,8 @@ size_t qemu_edid_size(uint8_t *edid); void qemu_edid_region_io(MemoryRegion *region, Object *owner, uint8_t *edid, size_t size); +uint32_t qemu_edid_dpi_to_mm(uint32_t dpi, uint32_t res); + #define DEFINE_EDID_PROPERTIES(_state, _edid_info) \ DEFINE_PROP_UINT32("xres", _state, _edid_info.prefx, 0), \ DEFINE_PROP_UINT32("yres", _state, _edid_info.prefy, 0), \ diff --git a/qemu-edid.c b/qemu-edid.c index 46eef70498..1db3372b98 100644 --- a/qemu-edid.c +++ b/qemu-edid.c @@ -9,7 +9,10 @@ #include "qemu/cutils.h" #include "hw/display/edid.h" -static qemu_edid_info info; +static qemu_edid_info info = (qemu_edid_info) { + .prefx = 1024, + .prefy = 768, +}; static void usage(FILE *out) { @@ -39,6 +42,7 @@ int main(int argc, char *argv[]) { FILE *outfile = NULL; uint8_t blob[256]; + uint32_t dpi = 100; int rc; for (;;) { @@ -83,7 +87,7 @@ int main(int argc, char *argv[]) } break; case 'd': - if (qemu_strtoui(optarg, NULL, 10, &info.dpi) < 0) { + if (qemu_strtoui(optarg, NULL, 10, &dpi) < 0) { fprintf(stderr, "not a number: %s\n", optarg); exit(1); } @@ -110,6 +114,9 @@ int main(int argc, char *argv[]) outfile = stdout; } + info.width_mm = qemu_edid_dpi_to_mm(dpi, info.prefx); + info.height_mm = qemu_edid_dpi_to_mm(dpi, info.prefy); + memset(blob, 0, sizeof(blob)); qemu_edid_generate(blob, sizeof(blob), &info); fwrite(blob, sizeof(blob), 1, outfile); From 5eaf1e48ff397185ec2f702f9968787d4d29e3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 27 Sep 2020 18:57:48 +0400 Subject: [PATCH 4/9] ui: add getter for UIInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following patch is going to introduce extra fields / details to UIInfo. Add a getter and keep the current values, instead of memset(0) Signed-off-by: Marc-André Lureau Message-id: 20200927145751.365446-4-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 1 + ui/console.c | 7 +++++++ ui/spice-display.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/ui/console.h b/include/ui/console.h index 79e301f946..353d2e49a1 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -264,6 +264,7 @@ void update_displaychangelistener(DisplayChangeListener *dcl, void unregister_displaychangelistener(DisplayChangeListener *dcl); bool dpy_ui_info_supported(QemuConsole *con); +const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con); int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info); void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h); diff --git a/ui/console.c b/ui/console.c index 7592c3c324..54a74c0b16 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1516,6 +1516,13 @@ bool dpy_ui_info_supported(QemuConsole *con) return con->hw_ops->ui_info != NULL; } +const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con) +{ + assert(con != NULL); + + return &con->ui_info; +} + int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info) { assert(con != NULL); diff --git a/ui/spice-display.c b/ui/spice-display.c index 19632fdf6c..625d9232b9 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -672,7 +672,7 @@ static int interface_client_monitors_config(QXLInstance *sin, return 1; } - memset(&info, 0, sizeof(info)); + info = *dpy_get_ui_info(ssd->dcl.con); if (mc->num_of_monitors == 1) { /* From 6244f988bfd9ded0daafcabf728455e94e099bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 27 Sep 2020 18:57:49 +0400 Subject: [PATCH 5/9] spice: remove the single monitor config logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced in commit 9c956e646178fee8c14ce7dfae5a9d7cb901876c ("spice: prepare for upcoming spice-server change"), the new logic never materialized in the spice server source tree. Let's remove it for now, until it actually changes in Spice. Signed-off-by: Marc-André Lureau Message-id: 20200927145751.365446-5-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- ui/spice-display.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/ui/spice-display.c b/ui/spice-display.c index 625d9232b9..b304c13149 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -674,28 +674,10 @@ static int interface_client_monitors_config(QXLInstance *sin, info = *dpy_get_ui_info(ssd->dcl.con); - if (mc->num_of_monitors == 1) { - /* - * New spice-server version which filters the list of monitors - * to only include those that belong to our display channel. - * - * single-head configuration (where filtering doesn't matter) - * takes this code path too. - */ - info.width = mc->monitors[0].width; - info.height = mc->monitors[0].height; - } else { - /* - * Old spice-server which gives us all monitors, so we have to - * figure ourself which entry we need. Array index is the - * channel_id, which is the qemu console index, see - * qemu_spice_add_display_interface(). - */ - head = qemu_console_get_index(ssd->dcl.con); - if (mc->num_of_monitors > head) { - info.width = mc->monitors[head].width; - info.height = mc->monitors[head].height; - } + head = qemu_console_get_index(ssd->dcl.con); + if (mc->num_of_monitors > head) { + info.width = mc->monitors[head].width; + info.height = mc->monitors[head].height; } trace_qemu_spice_ui_info(ssd->qxl.id, info.width, info.height); From 9028ab1f5b2e4803aa984c2da40ab56030d02c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 27 Sep 2020 18:57:50 +0400 Subject: [PATCH 6/9] spice: get monitors physical dimension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With upcoming Spice server version 0.14.4, the monitor configuration can contain additional fields for the monitor physical dimensions. Signed-off-by: Marc-André Lureau Message-id: 20200927145751.365446-6-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 3 +++ ui/spice-display.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/include/ui/console.h b/include/ui/console.h index 353d2e49a1..e7303d8b98 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -119,6 +119,9 @@ typedef struct DisplaySurface { } DisplaySurface; typedef struct QemuUIInfo { + /* physical dimension */ + uint16_t width_mm; + uint16_t height_mm; /* geometry */ int xoff; int yoff; diff --git a/ui/spice-display.c b/ui/spice-display.c index b304c13149..0178d5766d 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -678,6 +678,13 @@ static int interface_client_monitors_config(QXLInstance *sin, if (mc->num_of_monitors > head) { info.width = mc->monitors[head].width; info.height = mc->monitors[head].height; +#if SPICE_SERVER_VERSION >= 0x000e04 /* release 0.14.4 */ + if (mc->flags & VD_AGENT_CONFIG_MONITORS_FLAG_PHYSICAL_SIZE) { + VDAgentMonitorMM *mm = (void *)&mc->monitors[mc->num_of_monitors]; + info.width_mm = mm[head].width; + info.height_mm = mm[head].height; + } +#endif } trace_qemu_spice_ui_info(ssd->qxl.id, info.width, info.height); From 4bf47f3634af105b25c3c073ae53b36ba73733b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 27 Sep 2020 18:57:51 +0400 Subject: [PATCH 7/9] virtio-gpu: set physical dimensions for EDID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Message-id: 20200927145751.365446-7-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu-base.c | 2 ++ hw/display/virtio-gpu.c | 2 ++ include/hw/virtio/virtio-gpu.h | 1 + 3 files changed, 5 insertions(+) diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index aeb8723542..40ccd00f94 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -82,6 +82,8 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info) g->req_state[idx].y = info->yoff; g->req_state[idx].width = info->width; g->req_state[idx].height = info->height; + g->req_state[idx].width_mm = info->width_mm; + g->req_state[idx].height_mm = info->height_mm; if (info->width && info->height) { g->enabled_output_bitmask |= (1 << idx); diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 90be4e3ed7..f3b71fa9c7 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -212,6 +212,8 @@ virtio_gpu_generate_edid(VirtIOGPU *g, int scanout, { VirtIOGPUBase *b = VIRTIO_GPU_BASE(g); qemu_edid_info info = { + .width_mm = b->req_state[scanout].width_mm, + .height_mm = b->req_state[scanout].height_mm, .prefx = b->req_state[scanout].width, .prefy = b->req_state[scanout].height, }; diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 455e0a7433..1aed7275c8 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -62,6 +62,7 @@ struct virtio_gpu_scanout { }; struct virtio_gpu_requested_state { + uint16_t width_mm, height_mm; uint32_t width, height; int x, y; }; From 8be61ce2ce324d726e327101ca95332e32419fea Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 28 Sep 2020 10:53:34 +0200 Subject: [PATCH 8/9] virtio-vga: implement big-endian-framebuffer property Allows to switch the (vga mode) framebuffer into bigendian mode by setting the property, simliar to stdvga. Signed-off-by: Gerd Hoffmann Message-id: 20200928085335.21961-2-kraxel@redhat.com --- hw/display/virtio-vga.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c index f9410a0c2e..81f776ee36 100644 --- a/hw/display/virtio-vga.c +++ b/hw/display/virtio-vga.c @@ -168,6 +168,20 @@ static void virtio_vga_base_reset(DeviceState *dev) vga_dirty_log_start(&vvga->vga); } +static bool virtio_vga_get_big_endian_fb(Object *obj, Error **errp) +{ + VirtIOVGABase *d = VIRTIO_VGA_BASE(obj); + + return d->vga.big_endian_fb; +} + +static void virtio_vga_set_big_endian_fb(Object *obj, bool value, Error **errp) +{ + VirtIOVGABase *d = VIRTIO_VGA_BASE(obj); + + d->vga.big_endian_fb = value; +} + static Property virtio_vga_base_properties[] = { DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy), DEFINE_PROP_END_OF_LIST(), @@ -190,6 +204,11 @@ static void virtio_vga_base_class_init(ObjectClass *klass, void *data) k->realize = virtio_vga_base_realize; pcidev_k->romfile = "vgabios-virtio.bin"; pcidev_k->class_id = PCI_CLASS_DISPLAY_VGA; + + /* Expose framebuffer byteorder via QOM */ + object_class_property_add_bool(klass, "big-endian-framebuffer", + virtio_vga_get_big_endian_fb, + virtio_vga_set_big_endian_fb); } static TypeInfo virtio_vga_base_info = { From 97a0530bb71fb96468f218b622cd840e2c667bf6 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 28 Sep 2020 10:53:35 +0200 Subject: [PATCH 9/9] ppc/pseries: enable big-endian-framebuffer quirk for bochs-display and virtio-vga Already done for stdvga and secondary-vga, bochs-display and virtio-vga support the big-endian-framebuffer property too. Fixes blue console background at boot (offb firmware console). Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1881912 Signed-off-by: Gerd Hoffmann Message-id: 20200928085335.21961-3-kraxel@redhat.com --- hw/ppc/spapr_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 4d97ff6c70..5db912b48c 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2464,7 +2464,9 @@ static int spapr_switch_one_vga(DeviceState *dev, void *opaque) bool be = *(bool *)opaque; if (object_dynamic_cast(OBJECT(dev), "VGA") - || object_dynamic_cast(OBJECT(dev), "secondary-vga")) { + || object_dynamic_cast(OBJECT(dev), "secondary-vga") + || object_dynamic_cast(OBJECT(dev), "bochs-display") + || object_dynamic_cast(OBJECT(dev), "virtio-vga")) { object_property_set_bool(OBJECT(dev), "big-endian-framebuffer", be, &error_abort); }