drm/bochs: add edid support.
authorGerd Hoffmann <kraxel@redhat.com>
Mon, 29 Oct 2018 20:50:48 +0000 (21:50 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Tue, 30 Oct 2018 13:42:28 +0000 (14:42 +0100)
Recent qemu (latest master branch, upcoming 3.1 release) got support
for EDID data.  This patch adds guest driver support.

EDID support in qemu is not (yet) enabled by default, so please use
'qemu -device VGA,edid=on' for testing.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20181029205048.13200-1-kraxel@redhat.com
drivers/gpu/drm/bochs/bochs.h
drivers/gpu/drm/bochs/bochs_hw.c
drivers/gpu/drm/bochs/bochs_kms.c

index e7a69077e45adfa15431fdb8bb89d6d00c420541..577a8b917cb912e2884cc13431334187049fda73 100644 (file)
@@ -66,6 +66,7 @@ struct bochs_device {
        u16 yres_virtual;
        u32 stride;
        u32 bpp;
+       struct edid *edid;
 
        /* drm */
        struct drm_device  *dev;
@@ -126,6 +127,7 @@ void bochs_hw_setmode(struct bochs_device *bochs,
                      const struct drm_format_info *format);
 void bochs_hw_setbase(struct bochs_device *bochs,
                      int x, int y, u64 addr);
+int bochs_hw_load_edid(struct bochs_device *bochs);
 
 /* bochs_mm.c */
 int bochs_mm_init(struct bochs_device *bochs);
index cacff73a64abf15fc67790521914b75074df9969..c90a0d492fd5973fe53f0430919e0fa8f2883368 100644 (file)
@@ -69,6 +69,35 @@ static void bochs_hw_set_little_endian(struct bochs_device *bochs)
 #define bochs_hw_set_native_endian(_b) bochs_hw_set_little_endian(_b)
 #endif
 
+static int bochs_get_edid_block(void *data, u8 *buf,
+                               unsigned int block, size_t len)
+{
+       struct bochs_device *bochs = data;
+       size_t i, start = block * EDID_LENGTH;
+
+       if (start + len > 0x400 /* vga register offset */)
+               return -1;
+
+       for (i = 0; i < len; i++) {
+               buf[i] = readb(bochs->mmio + start + i);
+       }
+       return 0;
+}
+
+int bochs_hw_load_edid(struct bochs_device *bochs)
+{
+       if (!bochs->mmio)
+               return -1;
+
+       kfree(bochs->edid);
+       bochs->edid = drm_do_get_edid(&bochs->connector,
+                                     bochs_get_edid_block, bochs);
+       if (bochs->edid == NULL)
+               return -1;
+
+       return 0;
+}
+
 int bochs_hw_init(struct drm_device *dev)
 {
        struct bochs_device *bochs = dev->dev_private;
@@ -164,6 +193,7 @@ void bochs_hw_fini(struct drm_device *dev)
        if (bochs->fb_map)
                iounmap(bochs->fb_map);
        pci_release_regions(dev->pdev);
+       kfree(bochs->edid);
 }
 
 void bochs_hw_setmode(struct bochs_device *bochs,
index 9bc5b438aefdb342bde508ece4cf46bde7c97592..f87c284dd93d896c720172e66bb9b8ada9c6e2a8 100644 (file)
@@ -213,10 +213,17 @@ static void bochs_encoder_init(struct drm_device *dev)
 
 static int bochs_connector_get_modes(struct drm_connector *connector)
 {
-       int count;
+       struct bochs_device *bochs =
+               container_of(connector, struct bochs_device, connector);
+       int count = 0;
+
+       if (bochs->edid)
+               count = drm_add_edid_modes(connector, bochs->edid);
 
-       count = drm_add_modes_noedid(connector, 8192, 8192);
-       drm_set_preferred_mode(connector, defx, defy);
+       if (!count) {
+               count = drm_add_modes_noedid(connector, 8192, 8192);
+               drm_set_preferred_mode(connector, defx, defy);
+       }
        return count;
 }
 
@@ -271,6 +278,13 @@ static void bochs_connector_init(struct drm_device *dev)
        drm_connector_helper_add(connector,
                                 &bochs_connector_connector_helper_funcs);
        drm_connector_register(connector);
+
+       bochs_hw_load_edid(bochs);
+       if (bochs->edid) {
+               DRM_INFO("Found EDID data blob.\n");
+               drm_connector_attach_edid_property(connector);
+               drm_connector_update_edid_property(connector, bochs->edid);
+       }
 }