From patchwork Tue Oct 2 06:19:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10623049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA32913BB for ; Tue, 2 Oct 2018 06:19:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4CFD28709 for ; Tue, 2 Oct 2018 06:19:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98E542871B; Tue, 2 Oct 2018 06:19:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4951B28709 for ; Tue, 2 Oct 2018 06:19:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8EC9E6E0A3; Tue, 2 Oct 2018 06:19:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id A16676E0A3 for ; Tue, 2 Oct 2018 06:19:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 429AB308FE90; Tue, 2 Oct 2018 06:19:15 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF42C2010CA3; Tue, 2 Oct 2018 06:19:07 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A32C96CB; Tue, 2 Oct 2018 08:19:05 +0200 (CEST) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/2] drm/bochs: add edid support. Date: Tue, 2 Oct 2018 08:19:05 +0200 Message-Id: <20181002061905.10496-3-kraxel@redhat.com> In-Reply-To: <20181002061905.10496-1-kraxel@redhat.com> References: <20181002061905.10496-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 02 Oct 2018 06:19:15 +0000 (UTC) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , open list , Gerd Hoffmann , "open list:DRM DRIVER FOR BOCHS VIRTUAL GPU" MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 375bf92cd0..055d7b437a 100644 --- a/drivers/gpu/drm/bochs/bochs.h +++ b/drivers/gpu/drm/bochs/bochs.h @@ -70,6 +70,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 a39b0343c1..21a769e48c 100644 --- a/drivers/gpu/drm/bochs/bochs_hw.c +++ b/drivers/gpu/drm/bochs/bochs_hw.c @@ -47,6 +47,41 @@ static void bochs_dispi_write(struct bochs_device *bochs, u16 reg, u16 val) } } +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, uint32_t flags) { struct bochs_device *bochs = dev->dev_private; @@ -133,6 +168,9 @@ int bochs_hw_init(struct drm_device *dev, uint32_t flags) } 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 ca5a9afdd5..5b3afe9364 100644 --- a/drivers/gpu/drm/bochs/bochs_kms.c +++ b/drivers/gpu/drm/bochs/bochs_kms.c @@ -181,10 +181,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; } @@ -239,6 +246,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); + } }