Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3071821imu; Fri, 18 Jan 2019 04:24:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN5fojk7F7mT7G8Th8AnSb0rOlAFOrgVG+Vsf4o+Dj2QWRbDQFaqz3I30hQ3k9/Ymox1Jcyc X-Received: by 2002:a17:902:66e6:: with SMTP id e93mr18619964plk.92.1547814282287; Fri, 18 Jan 2019 04:24:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547814282; cv=none; d=google.com; s=arc-20160816; b=ibOMuhxEHDv9R1icJ88U2nkTrCDMtS8RznXOrvhryGQ+SIwA5biOWTURCdFcI52IjU 2Cr0xk/nrHeNCw2ZHJ0pBOX4XmXzfR8BsMG/dP7/oSzOPe4IEiMIWC4Qc+w2dbRPhpTP Qc8BERBIbYUGle3KCmb/rgqITUdXNhDu4XNKkI2gybDoDt8wJ7/3DE0y3nPyFOrjYpg9 GPIqnUp/O+g9FPYxhJH8OJMbzVuCbMOqh4Ev57bdJJwF0jXPz7Rbd/zfylFXUvNx/OKk DujVHM1Q32Us1BZVemO7yCR82zVaEsTvI+imdiqtwhgYVo2/9ds7WBpGIA93KivIsFz3 1/lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=iM9SVkoAXaflqSGa77S6PpipzKjAmraHs7OQ7n4tuHk=; b=GRUBjKV62phck/zqCM6KkffcckhZsMIDrjLXUXQNTW/TBAnG7WSuU5RFV54us8zx16 ush1oAXr4fTN3a4CCp3jdGktSJuyFwZPI/taQABL5r+P9GRyKxxtQEd6gQRum4m+aqAc nJnllX+p/FEXVWxUo7gNKJhgPgy37ZnB5JM0cetWukyoJavIIcTufGfVTAUAP1u67YXN s5YEtlG/nswbBu0mASb3iK6/l/epzfL9+CdX7XyX8T+2d4z+4G1XhauPjYKEK8+bKCFt tjGPfHJ4wvCbHDksBQDKlWfX4Jl1Qot+UTgu+6VRwVJDNd1la+C/t2fg1gez2CzJqLpX WpUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11si4537083pgf.450.2019.01.18.04.24.27; Fri, 18 Jan 2019 04:24:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727924AbfARMVj (ORCPT + 99 others); Fri, 18 Jan 2019 07:21:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46924 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727591AbfARMU3 (ORCPT ); Fri, 18 Jan 2019 07:20:29 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F9342D4B7E; Fri, 18 Jan 2019 12:20:28 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3A865D967; Fri, 18 Jan 2019 12:20:27 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 70D244F972; Fri, 18 Jan 2019 13:20:23 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: Gerd Hoffmann , Dave Airlie , David Airlie , Daniel Vetter , virtualization@lists.linux-foundation.org (open list:DRM DRIVER FOR QXL VIRTUAL GPU), spice-devel@lists.freedesktop.org (open list:DRM DRIVER FOR QXL VIRTUAL GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 21/23] drm/qxl: add qxl_add_mode helper function Date: Fri, 18 Jan 2019 13:20:18 +0100 Message-Id: <20190118122020.27596-22-kraxel@redhat.com> In-Reply-To: <20190118122020.27596-1-kraxel@redhat.com> References: <20190118122020.27596-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Jan 2019 12:20:28 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper function to add custom video modes to a connector. Signed-off-by: Gerd Hoffmann --- drivers/gpu/drm/qxl/qxl_display.c | 84 +++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c index fed2ea018d..926fcb49b2 100644 --- a/drivers/gpu/drm/qxl/qxl_display.c +++ b/drivers/gpu/drm/qxl/qxl_display.c @@ -212,15 +212,36 @@ static int qxl_check_framebuffer(struct qxl_device *qdev, return qxl_check_mode(qdev, bo->surf.width, bo->surf.height); } -static int qxl_add_monitors_config_modes(struct drm_connector *connector, - unsigned *pwidth, - unsigned *pheight) +static int qxl_add_mode(struct drm_connector *connector, + unsigned int width, + unsigned int height, + bool preferred) +{ + struct drm_device *dev = connector->dev; + struct qxl_device *qdev = dev->dev_private; + struct drm_display_mode *mode = NULL; + int rc; + + rc = qxl_check_mode(qdev, width, height); + if (rc != 0) + return 0; + + mode = drm_cvt_mode(dev, width, height, 60, false, false, false); + if (preferred) + mode->type |= DRM_MODE_TYPE_PREFERRED; + mode->hdisplay = width; + mode->vdisplay = height; + drm_mode_set_name(mode); + drm_mode_probed_add(connector, mode); + return 1; +} + +static int qxl_add_monitors_config_modes(struct drm_connector *connector) { struct drm_device *dev = connector->dev; struct qxl_device *qdev = dev->dev_private; struct qxl_output *output = drm_connector_to_qxl_output(connector); int h = output->index; - struct drm_display_mode *mode = NULL; struct qxl_head *head; if (!qdev->monitors_config) @@ -235,19 +256,7 @@ static int qxl_add_monitors_config_modes(struct drm_connector *connector, head = &qdev->client_monitors_config->heads[h]; DRM_DEBUG_KMS("head %d is %dx%d\n", h, head->width, head->height); - mode = drm_cvt_mode(dev, head->width, head->height, 60, false, false, - false); - mode->type |= DRM_MODE_TYPE_PREFERRED; - mode->hdisplay = head->width; - mode->vdisplay = head->height; - drm_mode_set_name(mode); - *pwidth = head->width; - *pheight = head->height; - drm_mode_probed_add(connector, mode); - /* remember the last custom size for mode validation */ - qdev->monitors_config_width = mode->hdisplay; - qdev->monitors_config_height = mode->vdisplay; - return 1; + return qxl_add_mode(connector, head->width, head->height, true); } static struct mode_size { @@ -273,22 +282,16 @@ static struct mode_size { {1920, 1200} }; -static int qxl_add_common_modes(struct drm_connector *connector, - unsigned int pwidth, - unsigned int pheight) +static int qxl_add_common_modes(struct drm_connector *connector) { - struct drm_device *dev = connector->dev; - struct drm_display_mode *mode = NULL; - int i; + int i, ret = 0; - for (i = 0; i < ARRAY_SIZE(common_modes); i++) { - mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, - 60, false, false, false); - if (common_modes[i].w == pwidth && common_modes[i].h == pheight) - mode->type |= DRM_MODE_TYPE_PREFERRED; - drm_mode_probed_add(connector, mode); - } - return i - 1; + for (i = 0; i < ARRAY_SIZE(common_modes); i++) + ret += qxl_add_mode(connector, + common_modes[i].w, + common_modes[i].h, + false); + return ret; } static void qxl_send_monitors_config(struct qxl_device *qdev) @@ -991,14 +994,25 @@ static int qdev_crtc_init(struct drm_device *dev, int crtc_id) static int qxl_conn_get_modes(struct drm_connector *connector) { + struct drm_device *dev = connector->dev; + struct qxl_device *qdev = dev->dev_private; + struct qxl_output *output = drm_connector_to_qxl_output(connector); unsigned int pwidth = 1024; unsigned int pheight = 768; int ret = 0; - ret = qxl_add_monitors_config_modes(connector, &pwidth, &pheight); - if (ret < 0) - return ret; - ret += qxl_add_common_modes(connector, pwidth, pheight); + if (qdev->client_monitors_config) { + struct qxl_head *head; + head = &qdev->client_monitors_config->heads[output->index]; + if (head->width) + pwidth = head->width; + if (head->height) + pheight = head->height; + } + + ret += qxl_add_common_modes(connector); + ret += qxl_add_monitors_config_modes(connector); + drm_set_preferred_mode(connector, pwidth, pheight); return ret; } -- 2.9.3