All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/bochs: add edid support.
@ 2018-10-05 12:09 ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2018-10-05 12:09 UTC (permalink / raw)
  To: dri-devel
  Cc: Gerd Hoffmann, David Airlie,
	open list:DRM DRIVER FOR BOCHS VIRTUAL GPU, open list

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>
---
 drivers/gpu/drm/bochs/bochs.h     |  1 +
 drivers/gpu/drm/bochs/bochs_hw.c  | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/bochs/bochs_kms.c | 18 +++++++++++++++---
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
index e7a69077e4..06b8166efa 100644
--- a/drivers/gpu/drm/bochs/bochs.h
+++ b/drivers/gpu/drm/bochs/bochs.h
@@ -66,6 +66,7 @@ struct bochs_device {
 	u16 yres_virtual;
 	u32 stride;
 	u32 bpp;
+	struct edid *edid;
 
 	/* drm */
 	struct drm_device  *dev;
diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c
index cacff73a64..6ce4cdac38 100644
--- a/drivers/gpu/drm/bochs/bochs_hw.c
+++ b/drivers/gpu/drm/bochs/bochs_hw.c
@@ -69,6 +69,41 @@ 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_load_edid(struct bochs_device *bochs)
+{
+	uint8_t *blob;
+	size_t i, len;
+	uint8_t num_exts;
+
+	if (!bochs->mmio)
+		return -1;
+
+	if ((readb(bochs->mmio+0) != 0x00 ||
+	     readb(bochs->mmio+1) != 0xff))
+		return -1;
+
+	num_exts = readb(bochs->mmio + 126);
+	len = EDID_LENGTH * (1 + num_exts);
+	if (len > 0x400 /* vga register offset */)
+		return -1;
+
+	kfree(bochs->edid);
+	bochs->edid = kmalloc(len, GFP_KERNEL);
+	blob = (void *)bochs->edid;
+	for (i = 0; i < len; i++) {
+		blob[i] = readb(bochs->mmio+i);
+	}
+
+	if (!drm_edid_is_valid(bochs->edid)) {
+		DRM_ERROR("EDID is not valid, ignoring.\n");
+		kfree(bochs->edid);
+		bochs->edid = NULL;
+		return -1;
+	}
+
+	return 0;
+}
+
 int bochs_hw_init(struct drm_device *dev)
 {
 	struct bochs_device *bochs = dev->dev_private;
@@ -150,6 +185,9 @@ int bochs_hw_init(struct drm_device *dev)
 	}
 
 noext:
+	if (bochs_load_edid(bochs) == 0)
+		DRM_INFO("Found EDID data blob.\n");
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c
index 9bc5b438ae..b9931443a7 100644
--- a/drivers/gpu/drm/bochs/bochs_kms.c
+++ b/drivers/gpu/drm/bochs/bochs_kms.c
@@ -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;
 
-	count = drm_add_modes_noedid(connector, 8192, 8192);
-	drm_set_preferred_mode(connector, defx, defy);
+	if (bochs->edid)
+		count = drm_add_edid_modes(connector, bochs->edid);
+
+	if (!count) {
+		count = drm_add_modes_noedid(connector, 8192, 8192);
+		drm_set_preferred_mode(connector, defx, defy);
+	}
 	return count;
 }
 
@@ -271,6 +278,11 @@ static void bochs_connector_init(struct drm_device *dev)
 	drm_connector_helper_add(connector,
 				 &bochs_connector_connector_helper_funcs);
 	drm_connector_register(connector);
+
+	if (bochs->edid) {
+		drm_connector_attach_edid_property(connector);
+		drm_connector_update_edid_property(connector, bochs->edid);
+	}
 }
 
 
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2] drm/bochs: add edid support.
@ 2018-10-05 12:09 ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2018-10-05 12:09 UTC (permalink / raw)
  To: dri-devel
  Cc: Gerd Hoffmann, David Airlie,
	open list:DRM DRIVER FOR BOCHS VIRTUAL GPU, open list

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>
---
 drivers/gpu/drm/bochs/bochs.h     |  1 +
 drivers/gpu/drm/bochs/bochs_hw.c  | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/bochs/bochs_kms.c | 18 +++++++++++++++---
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
index e7a69077e4..06b8166efa 100644
--- a/drivers/gpu/drm/bochs/bochs.h
+++ b/drivers/gpu/drm/bochs/bochs.h
@@ -66,6 +66,7 @@ struct bochs_device {
 	u16 yres_virtual;
 	u32 stride;
 	u32 bpp;
+	struct edid *edid;
 
 	/* drm */
 	struct drm_device  *dev;
diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c
index cacff73a64..6ce4cdac38 100644
--- a/drivers/gpu/drm/bochs/bochs_hw.c
+++ b/drivers/gpu/drm/bochs/bochs_hw.c
@@ -69,6 +69,41 @@ 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_load_edid(struct bochs_device *bochs)
+{
+	uint8_t *blob;
+	size_t i, len;
+	uint8_t num_exts;
+
+	if (!bochs->mmio)
+		return -1;
+
+	if ((readb(bochs->mmio+0) != 0x00 ||
+	     readb(bochs->mmio+1) != 0xff))
+		return -1;
+
+	num_exts = readb(bochs->mmio + 126);
+	len = EDID_LENGTH * (1 + num_exts);
+	if (len > 0x400 /* vga register offset */)
+		return -1;
+
+	kfree(bochs->edid);
+	bochs->edid = kmalloc(len, GFP_KERNEL);
+	blob = (void *)bochs->edid;
+	for (i = 0; i < len; i++) {
+		blob[i] = readb(bochs->mmio+i);
+	}
+
+	if (!drm_edid_is_valid(bochs->edid)) {
+		DRM_ERROR("EDID is not valid, ignoring.\n");
+		kfree(bochs->edid);
+		bochs->edid = NULL;
+		return -1;
+	}
+
+	return 0;
+}
+
 int bochs_hw_init(struct drm_device *dev)
 {
 	struct bochs_device *bochs = dev->dev_private;
@@ -150,6 +185,9 @@ int bochs_hw_init(struct drm_device *dev)
 	}
 
 noext:
+	if (bochs_load_edid(bochs) == 0)
+		DRM_INFO("Found EDID data blob.\n");
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c
index 9bc5b438ae..b9931443a7 100644
--- a/drivers/gpu/drm/bochs/bochs_kms.c
+++ b/drivers/gpu/drm/bochs/bochs_kms.c
@@ -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;
 
-	count = drm_add_modes_noedid(connector, 8192, 8192);
-	drm_set_preferred_mode(connector, defx, defy);
+	if (bochs->edid)
+		count = drm_add_edid_modes(connector, bochs->edid);
+
+	if (!count) {
+		count = drm_add_modes_noedid(connector, 8192, 8192);
+		drm_set_preferred_mode(connector, defx, defy);
+	}
 	return count;
 }
 
@@ -271,6 +278,11 @@ static void bochs_connector_init(struct drm_device *dev)
 	drm_connector_helper_add(connector,
 				 &bochs_connector_connector_helper_funcs);
 	drm_connector_register(connector);
+
+	if (bochs->edid) {
+		drm_connector_attach_edid_property(connector);
+		drm_connector_update_edid_property(connector, bochs->edid);
+	}
 }
 
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] drm/bochs: add edid support.
  2018-10-05 12:09 ` Gerd Hoffmann
@ 2018-10-18  1:15   ` Dave Airlie
  -1 siblings, 0 replies; 9+ messages in thread
From: Dave Airlie @ 2018-10-18  1:15 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: dri-devel, Dave Airlie, LKML, open list:VIRTIO CORE, NET...

On Fri, 5 Oct 2018 at 22:10, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> 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.

The EDID never changes after boot? Is there plans to let it?
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  drivers/gpu/drm/bochs/bochs.h     |  1 +
>  drivers/gpu/drm/bochs/bochs_hw.c  | 38 ++++++++++++++++++++++++++++++++++++++
>  drivers/gpu/drm/bochs/bochs_kms.c | 18 +++++++++++++++---
>  3 files changed, 54 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
> index e7a69077e4..06b8166efa 100644
> --- a/drivers/gpu/drm/bochs/bochs.h
> +++ b/drivers/gpu/drm/bochs/bochs.h
> @@ -66,6 +66,7 @@ struct bochs_device {
>         u16 yres_virtual;
>         u32 stride;
>         u32 bpp;
> +       struct edid *edid;
>
>         /* drm */
>         struct drm_device  *dev;
> diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c
> index cacff73a64..6ce4cdac38 100644
> --- a/drivers/gpu/drm/bochs/bochs_hw.c
> +++ b/drivers/gpu/drm/bochs/bochs_hw.c
> @@ -69,6 +69,41 @@ 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_load_edid(struct bochs_device *bochs)
> +{
> +       uint8_t *blob;
> +       size_t i, len;
> +       uint8_t num_exts;
> +
> +       if (!bochs->mmio)
> +               return -1;
> +
> +       if ((readb(bochs->mmio+0) != 0x00 ||
> +            readb(bochs->mmio+1) != 0xff))
> +               return -1;
> +
> +       num_exts = readb(bochs->mmio + 126);
> +       len = EDID_LENGTH * (1 + num_exts);
> +       if (len > 0x400 /* vga register offset */)
> +               return -1;
> +
> +       kfree(bochs->edid);
> +       bochs->edid = kmalloc(len, GFP_KERNEL);

Don't you need to free it somewhere?

Dave.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] drm/bochs: add edid support.
  2018-10-05 12:09 ` Gerd Hoffmann
  (?)
@ 2018-10-18  1:15 ` Dave Airlie
  -1 siblings, 0 replies; 9+ messages in thread
From: Dave Airlie @ 2018-10-18  1:15 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Dave Airlie, LKML, dri-devel, open list:VIRTIO CORE, NET...

On Fri, 5 Oct 2018 at 22:10, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> 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.

The EDID never changes after boot? Is there plans to let it?
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  drivers/gpu/drm/bochs/bochs.h     |  1 +
>  drivers/gpu/drm/bochs/bochs_hw.c  | 38 ++++++++++++++++++++++++++++++++++++++
>  drivers/gpu/drm/bochs/bochs_kms.c | 18 +++++++++++++++---
>  3 files changed, 54 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
> index e7a69077e4..06b8166efa 100644
> --- a/drivers/gpu/drm/bochs/bochs.h
> +++ b/drivers/gpu/drm/bochs/bochs.h
> @@ -66,6 +66,7 @@ struct bochs_device {
>         u16 yres_virtual;
>         u32 stride;
>         u32 bpp;
> +       struct edid *edid;
>
>         /* drm */
>         struct drm_device  *dev;
> diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c
> index cacff73a64..6ce4cdac38 100644
> --- a/drivers/gpu/drm/bochs/bochs_hw.c
> +++ b/drivers/gpu/drm/bochs/bochs_hw.c
> @@ -69,6 +69,41 @@ 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_load_edid(struct bochs_device *bochs)
> +{
> +       uint8_t *blob;
> +       size_t i, len;
> +       uint8_t num_exts;
> +
> +       if (!bochs->mmio)
> +               return -1;
> +
> +       if ((readb(bochs->mmio+0) != 0x00 ||
> +            readb(bochs->mmio+1) != 0xff))
> +               return -1;
> +
> +       num_exts = readb(bochs->mmio + 126);
> +       len = EDID_LENGTH * (1 + num_exts);
> +       if (len > 0x400 /* vga register offset */)
> +               return -1;
> +
> +       kfree(bochs->edid);
> +       bochs->edid = kmalloc(len, GFP_KERNEL);

Don't you need to free it somewhere?

Dave.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] drm/bochs: add edid support.
@ 2018-10-18  1:15   ` Dave Airlie
  0 siblings, 0 replies; 9+ messages in thread
From: Dave Airlie @ 2018-10-18  1:15 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Dave Airlie, LKML, dri-devel, open list:VIRTIO CORE, NET...

On Fri, 5 Oct 2018 at 22:10, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> 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.

The EDID never changes after boot? Is there plans to let it?
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  drivers/gpu/drm/bochs/bochs.h     |  1 +
>  drivers/gpu/drm/bochs/bochs_hw.c  | 38 ++++++++++++++++++++++++++++++++++++++
>  drivers/gpu/drm/bochs/bochs_kms.c | 18 +++++++++++++++---
>  3 files changed, 54 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
> index e7a69077e4..06b8166efa 100644
> --- a/drivers/gpu/drm/bochs/bochs.h
> +++ b/drivers/gpu/drm/bochs/bochs.h
> @@ -66,6 +66,7 @@ struct bochs_device {
>         u16 yres_virtual;
>         u32 stride;
>         u32 bpp;
> +       struct edid *edid;
>
>         /* drm */
>         struct drm_device  *dev;
> diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c
> index cacff73a64..6ce4cdac38 100644
> --- a/drivers/gpu/drm/bochs/bochs_hw.c
> +++ b/drivers/gpu/drm/bochs/bochs_hw.c
> @@ -69,6 +69,41 @@ 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_load_edid(struct bochs_device *bochs)
> +{
> +       uint8_t *blob;
> +       size_t i, len;
> +       uint8_t num_exts;
> +
> +       if (!bochs->mmio)
> +               return -1;
> +
> +       if ((readb(bochs->mmio+0) != 0x00 ||
> +            readb(bochs->mmio+1) != 0xff))
> +               return -1;
> +
> +       num_exts = readb(bochs->mmio + 126);
> +       len = EDID_LENGTH * (1 + num_exts);
> +       if (len > 0x400 /* vga register offset */)
> +               return -1;
> +
> +       kfree(bochs->edid);
> +       bochs->edid = kmalloc(len, GFP_KERNEL);

Don't you need to free it somewhere?

Dave.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] drm/bochs: add edid support.
  2018-10-18  1:15   ` Dave Airlie
@ 2018-10-18  5:11     ` Gerd Hoffmann
  -1 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2018-10-18  5:11 UTC (permalink / raw)
  To: Dave Airlie; +Cc: dri-devel, Dave Airlie, LKML, open list:VIRTIO CORE, NET...

  Hi,

> > 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.
> 
> The EDID never changes after boot?

Right now it doesn't.

> Is there plans to let it?

Needs more virtual hardware changes, the stdvga has no support for
interrupts, so qemu can't signal an edid update to the guest.

So not not sure yet what to do about it.  Maybe add it later (but it's
not high priority).  Maybe simply recommend to use virtio-gpu instead.

> > +       kfree(bochs->edid);
> > +       bochs->edid = kmalloc(len, GFP_KERNEL);
> 
> Don't you need to free it somewhere?

Oh, yes, we leak that on driver unload.
I'll fix it.

cheers,
  Gerd


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] drm/bochs: add edid support.
  2018-10-18  1:15   ` Dave Airlie
  (?)
@ 2018-10-18  5:11   ` Gerd Hoffmann
  -1 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2018-10-18  5:11 UTC (permalink / raw)
  To: Dave Airlie; +Cc: Dave Airlie, LKML, dri-devel, open list:VIRTIO CORE, NET...

  Hi,

> > 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.
> 
> The EDID never changes after boot?

Right now it doesn't.

> Is there plans to let it?

Needs more virtual hardware changes, the stdvga has no support for
interrupts, so qemu can't signal an edid update to the guest.

So not not sure yet what to do about it.  Maybe add it later (but it's
not high priority).  Maybe simply recommend to use virtio-gpu instead.

> > +       kfree(bochs->edid);
> > +       bochs->edid = kmalloc(len, GFP_KERNEL);
> 
> Don't you need to free it somewhere?

Oh, yes, we leak that on driver unload.
I'll fix it.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] drm/bochs: add edid support.
@ 2018-10-18  5:11     ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2018-10-18  5:11 UTC (permalink / raw)
  To: Dave Airlie; +Cc: dri-devel, Dave Airlie, LKML, open list:VIRTIO CORE, NET...

  Hi,

> > 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.
> 
> The EDID never changes after boot?

Right now it doesn't.

> Is there plans to let it?

Needs more virtual hardware changes, the stdvga has no support for
interrupts, so qemu can't signal an edid update to the guest.

So not not sure yet what to do about it.  Maybe add it later (but it's
not high priority).  Maybe simply recommend to use virtio-gpu instead.

> > +       kfree(bochs->edid);
> > +       bochs->edid = kmalloc(len, GFP_KERNEL);
> 
> Don't you need to free it somewhere?

Oh, yes, we leak that on driver unload.
I'll fix it.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] drm/bochs: add edid support.
@ 2018-10-05 12:09 Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2018-10-05 12:09 UTC (permalink / raw)
  To: dri-devel
  Cc: David Airlie, open list, open list:DRM DRIVER FOR BOCHS VIRTUAL GPU

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>
---
 drivers/gpu/drm/bochs/bochs.h     |  1 +
 drivers/gpu/drm/bochs/bochs_hw.c  | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/bochs/bochs_kms.c | 18 +++++++++++++++---
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
index e7a69077e4..06b8166efa 100644
--- a/drivers/gpu/drm/bochs/bochs.h
+++ b/drivers/gpu/drm/bochs/bochs.h
@@ -66,6 +66,7 @@ struct bochs_device {
 	u16 yres_virtual;
 	u32 stride;
 	u32 bpp;
+	struct edid *edid;
 
 	/* drm */
 	struct drm_device  *dev;
diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c
index cacff73a64..6ce4cdac38 100644
--- a/drivers/gpu/drm/bochs/bochs_hw.c
+++ b/drivers/gpu/drm/bochs/bochs_hw.c
@@ -69,6 +69,41 @@ 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_load_edid(struct bochs_device *bochs)
+{
+	uint8_t *blob;
+	size_t i, len;
+	uint8_t num_exts;
+
+	if (!bochs->mmio)
+		return -1;
+
+	if ((readb(bochs->mmio+0) != 0x00 ||
+	     readb(bochs->mmio+1) != 0xff))
+		return -1;
+
+	num_exts = readb(bochs->mmio + 126);
+	len = EDID_LENGTH * (1 + num_exts);
+	if (len > 0x400 /* vga register offset */)
+		return -1;
+
+	kfree(bochs->edid);
+	bochs->edid = kmalloc(len, GFP_KERNEL);
+	blob = (void *)bochs->edid;
+	for (i = 0; i < len; i++) {
+		blob[i] = readb(bochs->mmio+i);
+	}
+
+	if (!drm_edid_is_valid(bochs->edid)) {
+		DRM_ERROR("EDID is not valid, ignoring.\n");
+		kfree(bochs->edid);
+		bochs->edid = NULL;
+		return -1;
+	}
+
+	return 0;
+}
+
 int bochs_hw_init(struct drm_device *dev)
 {
 	struct bochs_device *bochs = dev->dev_private;
@@ -150,6 +185,9 @@ int bochs_hw_init(struct drm_device *dev)
 	}
 
 noext:
+	if (bochs_load_edid(bochs) == 0)
+		DRM_INFO("Found EDID data blob.\n");
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c
index 9bc5b438ae..b9931443a7 100644
--- a/drivers/gpu/drm/bochs/bochs_kms.c
+++ b/drivers/gpu/drm/bochs/bochs_kms.c
@@ -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;
 
-	count = drm_add_modes_noedid(connector, 8192, 8192);
-	drm_set_preferred_mode(connector, defx, defy);
+	if (bochs->edid)
+		count = drm_add_edid_modes(connector, bochs->edid);
+
+	if (!count) {
+		count = drm_add_modes_noedid(connector, 8192, 8192);
+		drm_set_preferred_mode(connector, defx, defy);
+	}
 	return count;
 }
 
@@ -271,6 +278,11 @@ static void bochs_connector_init(struct drm_device *dev)
 	drm_connector_helper_add(connector,
 				 &bochs_connector_connector_helper_funcs);
 	drm_connector_register(connector);
+
+	if (bochs->edid) {
+		drm_connector_attach_edid_property(connector);
+		drm_connector_update_edid_property(connector, bochs->edid);
+	}
 }
 
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-10-18  5:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-05 12:09 [PATCH v2] drm/bochs: add edid support Gerd Hoffmann
2018-10-05 12:09 ` Gerd Hoffmann
2018-10-18  1:15 ` Dave Airlie
2018-10-18  1:15 ` Dave Airlie
2018-10-18  1:15   ` Dave Airlie
2018-10-18  5:11   ` Gerd Hoffmann
2018-10-18  5:11   ` Gerd Hoffmann
2018-10-18  5:11     ` Gerd Hoffmann
2018-10-05 12:09 Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.