Skip to contentSkip to conversation

display/edid: add edid generator to qemu.

PATCH In review Gerd Hoffmann 4 participants 8 messages Sep 12, 2018 – Sep 13, 2018 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 display/edid: add edid generator to qemu.

EDID is a metadata format to describe monitors. On physical hardware the monitor has an eeprom with that data block which can be read over i2c bus.

On a linux system you can usually find the EDID data block in /sys/class/drm/$card/$connector/edid. xorg ships a edid-decode utility which you can use to turn the blob into readable form.

I think it would be a good idea to use EDID for virtual displays too. Needs changes in both qemu and guest kms drivers. This patch is the first step, it adds an generator for EDID blobs to qemu. Comes with a qemu-edid test tool included.

With EDID we can pass more information to the guest. Names and serial numbers, so the guests display configuration has no boring "Unknown Monitor". List of video modes. Display resolution, pretty important in case we want add HiDPI support some day.

---
 configure                  |   2 +-
 Makefile                   |   2 +
 include/hw/display/edid.h  |  18 +++
 hw/display/edid-generate.c | 328 +++++++++++++++++++++++++++++++++++++++++++++
 qemu-edid.c                |  86 ++++++++++++
 hw/display/Makefile.objs   |   2 +
 6 files changed, 437 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/display/edid.h
 create mode 100644 hw/display/edid-generate.c
 create mode 100644 qemu-edid.c
configure +1 -1
index 58862d2ae8..053facfb68 100755
@@ -5715,7 +5715,7 @@ fi
 
 tools=""
 if test "$want_tools" = "yes" ; then
-  tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools"
+  tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-edid\$(EXESUF) $tools"
   if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
     tools="qemu-nbd\$(EXESUF) $tools"
   fi
Makefile +2 -0
index fe623e4634..7bb6675f4a 100644
@@ -543,6 +543,8 @@ qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
 
 qemu-keymap$(EXESUF): qemu-keymap.o ui/input-keymap.o $(COMMON_LDADDS)
 
+qemu-edid$(EXESUF): qemu-edid.o hw/display/edid-generate.o $(COMMON_LDADDS)
+
 fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS)
 fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
 
include/hw/display/edid.h new file +18 -0
new file mode 100644
index 0000000000..63b60015c3
@@ -0,0 +1,18 @@
+#ifndef EDID_H
+#define EDID_H
+
+typedef struct qemu_edid_info {
+    const char *vendor;
+    const char *name;
+    const char *serial;
+    uint32_t    dpi;
+    uint32_t    prefx;
+    uint32_t    prefy;
+    uint32_t    maxx;
+    uint32_t    maxy;
+} qemu_edid_info;
+
+void qemu_edid_generate(uint8_t *edid, size_t size,
+                        qemu_edid_info *info);
+
+#endif /* EDID_H */
hw/display/edid-generate.c new file +328 -0

328 lines not on this page · raw message

qemu-edid.c new file +86 -0

86 lines not on this page · raw message

hw/display/Makefile.objs +2 -0
index a606fb7404..492404c09e 100644
@@ -1,3 +1,5 @@
+common-obj-y += edid-generate.o
+
 common-obj-$(CONFIG_FW_CFG_DMA) += ramfb.o
 common-obj-$(CONFIG_FW_CFG_DMA) += ramfb-standalone.o
 
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/3 display/edid: add region helper.

Create a io region for an EDID data block.

---
 include/hw/display/edid.h |  4 ++++
 hw/display/edid-region.c  | 33 +++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs  |  1 +
 3 files changed, 38 insertions(+)
 create mode 100644 hw/display/edid-region.c
include/hw/display/edid.h +4 -0
index 63b60015c3..c39d5cd77b 100644
@@ -1,6 +1,8 @@
 #ifndef EDID_H
 #define EDID_H
 
+#include "hw/hw.h"
+
 typedef struct qemu_edid_info {
     const char *vendor;
     const char *name;
@@ -14,5 +16,7 @@ typedef struct qemu_edid_info {
 
 void qemu_edid_generate(uint8_t *edid, size_t size,
                         qemu_edid_info *info);
+void qemu_edid_region_io(MemoryRegion *region, Object *owner,
+                         uint8_t *edid, size_t size);
 
 #endif /* EDID_H */
hw/display/edid-region.c new file +33 -0
new file mode 100644
index 0000000000..9a15734d3a
@@ -0,0 +1,33 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/display/edid.h"
+
+static uint64_t edid_region_read(void *ptr, hwaddr addr, unsigned size)
+{
+    uint8_t *edid = ptr;
+
+    return edid[addr];
+}
+
+static void edid_region_write(void *ptr, hwaddr addr,
+                             uint64_t val, unsigned size)
+{
+    /* read only */
+}
+
+static const MemoryRegionOps edid_region_ops = {
+    .read = edid_region_read,
+    .write = edid_region_write,
+    .valid.min_access_size = 1,
+    .valid.max_access_size = 4,
+    .impl.min_access_size = 1,
+    .impl.max_access_size = 1,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+void qemu_edid_region_io(MemoryRegion *region, Object *owner,
+                         uint8_t *edid, size_t size)
+{
+    memory_region_init_io(region, owner, &edid_region_ops,
+                          edid, "edid", size);
+}
hw/display/Makefile.objs +1 -0
index 492404c09e..780a76b9f0 100644
@@ -15,6 +15,7 @@ common-obj-$(CONFIG_XEN) += xenfb.o
 
 common-obj-$(CONFIG_VGA_PCI) += vga-pci.o
 common-obj-$(CONFIG_VGA_PCI) += bochs-display.o
+common-obj-$(CONFIG_VGA_PCI) += edid-region.o
 common-obj-$(CONFIG_VGA_ISA) += vga-isa.o
 common-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
 common-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
Signature · 1 line
2.9.3
Reviewed-by on v1 2/3
#2 lore raw

Re: [Qemu-devel] [PATCH 2/3] display/edid: add region helper.

Quoted 3 lines · Gerd Hoffmann

Create a io region for an EDID data block.

Quoted 80 lines
---
 include/hw/display/edid.h |  4 ++++
 hw/display/edid-region.c  | 33 +++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs  |  1 +
 3 files changed, 38 insertions(+)
 create mode 100644 hw/display/edid-region.c
include/hw/display/edid.h +4 -0
index 63b60015c3..c39d5cd77b 100644
@@ -1,6 +1,8 @@
 #ifndef EDID_H
 #define EDID_H
 
+#include "hw/hw.h"
+
 typedef struct qemu_edid_info {
     const char *vendor;
     const char *name;
@@ -14,5 +16,7 @@ typedef struct qemu_edid_info {
 
 void qemu_edid_generate(uint8_t *edid, size_t size,
                         qemu_edid_info *info);
+void qemu_edid_region_io(MemoryRegion *region, Object *owner,
+                         uint8_t *edid, size_t size);
 
 #endif /* EDID_H */
hw/display/edid-region.c new file +33 -0
new file mode 100644
index 0000000000..9a15734d3a
@@ -0,0 +1,33 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/display/edid.h"
+
+static uint64_t edid_region_read(void *ptr, hwaddr addr, unsigned size)
+{
+    uint8_t *edid = ptr;
+
+    return edid[addr];
+}
+
+static void edid_region_write(void *ptr, hwaddr addr,
+                             uint64_t val, unsigned size)
+{
+    /* read only */
+}
+
+static const MemoryRegionOps edid_region_ops = {
+    .read = edid_region_read,
+    .write = edid_region_write,
+    .valid.min_access_size = 1,
+    .valid.max_access_size = 4,
+    .impl.min_access_size = 1,
+    .impl.max_access_size = 1,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+void qemu_edid_region_io(MemoryRegion *region, Object *owner,
+                         uint8_t *edid, size_t size)
+{
+    memory_region_init_io(region, owner, &edid_region_ops,
+                          edid, "edid", size);
+}
hw/display/Makefile.objs +1 -0
index 492404c09e..780a76b9f0 100644
@@ -15,6 +15,7 @@ common-obj-$(CONFIG_XEN) += xenfb.o
 
 common-obj-$(CONFIG_VGA_PCI) += vga-pci.o
 common-obj-$(CONFIG_VGA_PCI) += bochs-display.o
+common-obj-$(CONFIG_VGA_PCI) += edid-region.o
 common-obj-$(CONFIG_VGA_ISA) += vga-isa.o
 common-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
 common-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
#3 lore raw

PATCH 3/3 display/stdvga: add edid support.

In reply to Gerd Hoffmann

This patch adds edid support to the qemu stdvga. It is turned off by default and can be enabled with the new edid property. The patch also adds xres and yres properties to specify the video mode you want the guest use. Works only with edid enabled and updated guest driver.

The mmio bar of the stdvga has some unused address space at the start. It was reserved just in case it'll be needed for virtio, but it turned out to not be needed for that. So lets use that region to place the EDID data block there.

---
 docs/specs/standard-vga.txt |  2 +-
 hw/display/vga_int.h        |  2 +-
 hw/display/vga-pci.c        | 42 ++++++++++++++++++++++++++++++++++++++----
 hw/display/virtio-vga.c     |  2 +-
 4 files changed, 41 insertions(+), 7 deletions(-)
docs/specs/standard-vga.txt +1 -1
index 19d2a74509..18f75f1b30 100644
@@ -61,7 +61,7 @@ MMIO area spec
 
 Likewise applies to the pci variant only for obvious reasons.
 
-0000 - 03ff : reserved, for possible virtio extension.
+0000 - 03ff : edid data blob.
 0400 - 041f : vga ioports (0x3c0 -> 0x3df), remapped 1:1.
               word access is supported, bytes are written
               in little endia order (aka index port first),
hw/display/vga_int.h +1 -1
index 339661bc01..6e4fa48a79 100644
@@ -197,6 +197,6 @@ void pci_std_vga_mmio_region_init(VGACommonState *s,
                                   Object *owner,
                                   MemoryRegion *parent,
                                   MemoryRegion *subs,
-                                  bool qext);
+                                  bool qext, bool edid);
 
 #endif
hw/display/vga-pci.c +38 -4

108 lines not on this page · raw message

hw/display/virtio-vga.c +1 -1
index 701d980872..3bea0693f6 100644
@@ -163,7 +163,7 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
 
     /* add stdvga mmio regions */
     pci_std_vga_mmio_region_init(vga, OBJECT(vvga), &vpci_dev->modern_bar,
-                                 vvga->vga_mrs, true);
+                                 vvga->vga_mrs, true, false);
 
     vga->con = g->scanout[0].con;
     g->disable_scanout = virtio_vga_disable_scanout;
Signature · 1 line
2.9.3
#4 lore raw

Re: [Qemu-devel] [PATCH 3/3] display/stdvga: add edid support.

Quoted 8 lines · Gerd Hoffmann

This patch adds edid support to the qemu stdvga. It is turned off by default and can be enabled with the new edid property. The patch also adds xres and yres properties to specify the video mode you want the guest use. Works only with edid enabled and updated guest driver.

The mmio bar of the stdvga has some unused address space at the start. It was reserved just in case it'll be needed for virtio, but it turned out to not be needed for that. So lets use that region to place the

s/lets/let's/

Quoted 20 lines

EDID data block there.

---
  docs/specs/standard-vga.txt |  2 +-
  hw/display/vga_int.h        |  2 +-
  hw/display/vga-pci.c        | 42 ++++++++++++++++++++++++++++++++++++++----
  hw/display/virtio-vga.c     |  2 +-
  4 files changed, 41 insertions(+), 7 deletions(-)
docs/specs/standard-vga.txt +1 -1
index 19d2a74509..18f75f1b30 100644
@@ -61,7 +61,7 @@ MMIO area spec
 
  Likewise applies to the pci variant only for obvious reasons.
 
-0000 - 03ff : reserved, for possible virtio extension.
+0000 - 03ff : edid data blob.

docs/specs/standard-vga.txt MMIO area spec

Quoted 10 lines
docs/specs/standard-vga.txt +8 -0
 
 
+    if (edid) {
+        qemu_edid_info info = {
+            .prefx = d->xres,
+            .prefy = d->yres,
+        };
+        qemu_edid_generate(d->edid, sizeof(d->edid), &info);
+        qemu_edid_region_io(&subs[3], owner, d->edid, sizeof(d->edid));
+        memory_region_add_subregion(parent, 0, &subs[3]);

Is there ever a risk that this could overflow? Or, if the blob is always smaller than 0x3ff, should we still leave reserved bytes?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH 3/3] display/stdvga: add edid support.

Quoted 17 lines
Quoted 6 lines
docs/specs/standard-vga.txt +1 -1
@@ -61,7 +61,7 @@ MMIO area spec
  Likewise applies to the pci variant only for obvious reasons.
-0000 - 03ff : reserved, for possible virtio extension.
+0000 - 03ff : edid data blob.

docs/specs/standard-vga.txt MMIO area spec

Quoted 10 lines
docs/specs/standard-vga.txt +8 -0
 
 
+    if (edid) {
+        qemu_edid_info info = {
+            .prefx = d->xres,
+            .prefy = d->yres,
+        };
+        qemu_edid_generate(d->edid, sizeof(d->edid), &info);
+        qemu_edid_region_io(&subs[3], owner, d->edid, sizeof(d->edid));
+        memory_region_add_subregion(parent, 0, &subs[3]);
Quoted 2 lines

Is there ever a risk that this could overflow? Or, if the blob is always smaller than 0x3ff, should we still leave reserved bytes?

It's 128 bytes long. There can be (multiple) extensions, each 128 bytes long too. Current generator doesn't create any extensions. So, only a fraction of the space is actually used right now.

I'd leave the room reserved for edid nevertheless. There is still plenty of unused address space should we need something at some point in the future. The mmio bar is one page (4k), with more than 2k at the end being not used (from info mtree):

00000000febf0000-00000000febf0fff (prio 1, i/o): vga.mmio

    00000000febf0000-00000000febf007f (prio 0, i/o): edid
    00000000febf0400-00000000febf041f (prio 0, i/o): vga ioports remapped
    00000000febf0500-00000000febf0515 (prio 0, i/o): bochs dispi interface
    00000000febf0600-00000000febf0607 (prio 0, i/o): qemu extended regs

cheers,
Gerd

#6 lore raw
In reply to Gerd Hoffmann
Quoted 30 lines · Gerd Hoffmann

EDID is a metadata format to describe monitors. On physical hardware the monitor has an eeprom with that data block which can be read over i2c bus.

On a linux system you can usually find the EDID data block in /sys/class/drm/$card/$connector/edid. xorg ships a edid-decode utility which you can use to turn the blob into readable form.

I think it would be a good idea to use EDID for virtual displays too. Needs changes in both qemu and guest kms drivers. This patch is the first step, it adds an generator for EDID blobs to qemu. Comes with a qemu-edid test tool included.

With EDID we can pass more information to the guest. Names and serial numbers, so the guests display configuration has no boring "Unknown Monitor". List of video modes. Display resolution, pretty important in case we want add HiDPI support some day.

---

include/hw/display/edid.h new file +2 -0
@@ -0,0 +1,18 @@
+#ifndef EDID_H
+#define EDID_H

hw/display/edid-generate.c line 5

Quoted 5 lines
hw/display/edid-generate.c new file +5 -0
@@ -0,0 +1,328 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/bswap.h"
+#include "hw/display/edid.h"
+

No copyright blurbs?

hw/display/edid-generate.c line 280

Quoted 13 lines
hw/display/edid-generate.c new file +13 -0
+    /* =============== basic display parameters =============== */
+
+    /* video input: digital, 8bpc, displayport */
+    edid[20] = 0xa5;
+
+    /* screen size: undefined */
+    edid[21] = info->prefx * info->dpi / 2540;
+    edid[22] = info->prefy * info->dpi / 2540;
+
+    /* display gamma: 1.0 */
+    edid[23] = 0x00;
+
+    /* supported features bitmap: prefered timing */

preferred

qemu-edid.c line 4

Quoted 7 lines
qemu-edid.c new file +4 -0
@@ -0,0 +1,86 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/bswap.h"
+#include "hw/display/edid.h"

and again

Quoted 7 lines
qemu-edid.c new file +7 -0
+int main(int argc, char *argv[])
+{
+    FILE *outfile = NULL;
+    uint8_t blob[128];
+    int rc;
+
+    for (;;) {

qemu-edid.c line 46

Quoted 10 lines
qemu-edid.c new file +10 -0
+        rc = getopt(argc, argv, "ho:x:y:d:v:n:s:");
+        if (rc == -1) {
+            break;
+        }
+        switch (rc) {
+        case 'o':
+            outfile = fopen(optarg, "w");
+            if (outfile == NULL) {
+                fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
+                exit(1);

Leaks if -o is passed on the command line more than once.

qemu-edid.c line 50

Quoted 4 lines
qemu-edid.c new file +4 -0
+            }
+            break;
+        case 'x':
+            info.prefx = atoi(optarg);

atoi() can't flag errors like '-x 1garbage'. Better is to use qemu_strtoi().

qemu-edid.c line 85

Quoted 6 lines
qemu-edid.c new file +6 -0
+    memset(blob, 0, sizeof(blob));
+    qemu_edid_generate(blob, sizeof(blob), &info);
+    fwrite(blob, sizeof(blob), 1, outfile);
+    fflush(outfile);
+
+    exit(0);

You could just 'return 0;' instead.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#7 lore raw
In reply to Gerd Hoffmann

hw/display/edid-generate.c line 12

Quoted 7 lines · Gerd Hoffmann
hw/display/edid-generate.c new file +7 -0
+static struct edid_mode {
+    uint32_t xres;
+    uint32_t yres;
+    uint32_t byte;
+    uint32_t xtra3;
+    uint32_t bit;
+} modes[] = {

static const?

r~