From patchwork Tue Mar 21 08:13:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 9636197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 701C8602CC for ; Tue, 21 Mar 2017 08:15:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F1E61FF8F for ; Tue, 21 Mar 2017 08:15:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 542D827F10; Tue, 21 Mar 2017 08:15:14 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable 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 C36191FF8F for ; Tue, 21 Mar 2017 08:15:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DBE316E318; Tue, 21 Mar 2017 08:14:19 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id E7ED16E227; Tue, 21 Mar 2017 08:14:08 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id l37so21314607wrc.3; Tue, 21 Mar 2017 01:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KIq/lhTA39Z/Y9EaZxbjapZ+dQg4pem+dQ6ZKxuuFoQ=; b=pPBavrqdb3hYUlOdNeJjxtujy8f49dgTFGMJraU6zsnTdy+Iaf8Cexg7fkIx5Thzj1 krccolCBrendvAtXCZ7xUccEx8ApgXHeyPBJ10Cl8HnSZd2kZZj+7TfGpx69xcXF6EWY V6I5isQj3nAFCcDKE8rQwkv2MsX+nmHPj9pnkCVJqhiJ1laKyT1ImegrHP2u6+GTq+9D fRttCnX6+ruSQpGk+5JgL9AXSSB1LPAZZfNM1HQv3jwusGpSxPxcQiBCUfo/8GFmXRB3 CqMShTX9XA7WvHOq/c/G7QCMdwLBgzfjxfH+ZVbRBLQ+aVEHjOHoj+OEZAdMVp9c5DG6 mLKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KIq/lhTA39Z/Y9EaZxbjapZ+dQg4pem+dQ6ZKxuuFoQ=; b=IBT0TgcY2umBUFaLDHZM7AxkcxW3wnvVkJyDN5MI0TRE2yw/MPwFYGbh+vDSdQZAi6 ZVXTbDjj0g3meLt5pNc+KzQEnbcYxE0R8++9ze/lTL+erqD3SkD3nao4WX/bHHtTaBfW 8XBUnBksOZBvRi3PAPMZa5qmlyiCbm7ugvRz8OUMI6KetGR+9Sx+Fs6Mf6bpnzMz9Mkb Bwybez8bFPM0zUNxg1OIo40IHQdqQlWd6+Bo4QLQQlIpDPG+haLs1QZqdek/NinJK7M7 +3jHWvShfqQKfUY9s60RvQZT15IGw9A1LTQUYkB2k0GTdjP5evOYxpTUBb3pIksWw+Qz hnyg== X-Gm-Message-State: AFeK/H16XJOEoN/yJT9WbQhtmc6vEpMtVrNXttCCmsHveuYcglQaSFm0AfWPd+x/m+o3iw== X-Received: by 10.223.152.83 with SMTP id v77mr29404154wrb.109.1490084047279; Tue, 21 Mar 2017 01:14:07 -0700 (PDT) Received: from localhost (port-52488.pppoe.wtnet.de. [46.59.205.174]) by smtp.gmail.com with ESMTPSA id 53sm23906336wrt.52.2017.03.21.01.14.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Mar 2017 01:14:06 -0700 (PDT) From: Thierry Reding To: Daniel Vetter Date: Tue, 21 Mar 2017 09:13:54 +0100 Message-Id: <20170321081358.27237-7-thierry.reding@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170321081358.27237-1-thierry.reding@gmail.com> References: <20170321081358.27237-1-thierry.reding@gmail.com> Cc: John Stultz , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [Intel-gfx] [PATCH v3 06/10] drm/fb-helper: Support deferred setup X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding FB helper code falls back to a 1024x768 mode if no outputs are connected or don't report back any modes upon initialization. This can be annoying because outputs that are added to FB helper later on can't be used with FB helper if they don't support a matching mode. The fallback is in place because VGA connectors can happen to report an unknown connection status even when they are in fact connected. Some drivers have custom solutions in place to defer FB helper setup until at least one output is connected. But the logic behind these solutions is always the same and there is nothing driver-specific about it, so a better alterative is to fix the FB helper core and add support for all drivers automatically. This patch adds support for deferred FB helper setup. It checks all the connectors for their connection status, and if all of them report to be disconnected marks the FB helper as needing deferred setup. Whet setup is deferred, the FB helper core will automatically retry setup after a hotplug event, and it will keep trying until it succeeds. Tested-by: John Stultz Signed-off-by: Thierry Reding Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_fb_helper.c | 60 +++++++++++++++++++++++++++++++++++++---- include/drm/drm_fb_helper.h | 21 +++++++++++++++ 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 9060adcf7cf8..d4a2c97d8b02 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -511,6 +511,9 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) if (!drm_fbdev_emulation) return -ENODEV; + if (fb_helper->deferred_setup) + return 0; + mutex_lock(&fb_helper->lock); drm_modeset_lock_all(dev); @@ -1597,6 +1600,23 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, } EXPORT_SYMBOL(drm_fb_helper_pan_display); +static bool drm_fb_helper_maybe_connected(struct drm_fb_helper *helper) +{ + bool connected = false; + unsigned int i; + + for (i = 0; i < helper->connector_count; i++) { + struct drm_fb_helper_connector *fb = helper->connector_info[i]; + + if (fb->connector->status != connector_status_disconnected) { + connected = true; + break; + } + } + + return connected; +} + /* * Allocates the backing storage and sets up the fbdev info structure through * the ->fb_probe callback and then registers the fbdev and sets up the panic @@ -2254,8 +2274,6 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, int i; DRM_DEBUG_KMS("\n"); - if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0) - DRM_DEBUG_KMS("No connectors reported connected with modes\n"); /* prevent concurrent modification of connector_count by hotplug */ lockdep_assert_held(&fb_helper->dev->mode_config.mutex); @@ -2378,6 +2396,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel) { struct drm_device *dev = fb_helper->dev; + unsigned int width, height; struct fb_info *info; int ret; @@ -2385,14 +2404,34 @@ int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel) return 0; mutex_lock(&dev->mode_config.mutex); - drm_setup_crtcs(fb_helper, - dev->mode_config.max_width, - dev->mode_config.max_height); + + width = dev->mode_config.max_width; + height = dev->mode_config.max_height; + + if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0) + DRM_DEBUG_KMS("No connectors reported connected with modes\n"); + + /* + * If everything's disconnected, there's no use in attempting to set + * up fbdev. + */ + if (!drm_fb_helper_maybe_connected(fb_helper)) { + DRM_INFO("No outputs connected, deferring setup\n"); + fb_helper->preferred_bpp = bpp_sel; + fb_helper->deferred_setup = true; + mutex_unlock(&dev->mode_config.mutex); + return 0; + } + + drm_setup_crtcs(fb_helper, width, height); + ret = drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); mutex_unlock(&dev->mode_config.mutex); if (ret) return ret; + fb_helper->deferred_setup = false; + info = fb_helper->fbdev; info->var.pixclock = 0; ret = register_framebuffer(info); @@ -2437,11 +2476,16 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config); int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) { struct drm_device *dev = fb_helper->dev; + unsigned int width, height; int err = 0; if (!drm_fbdev_emulation) return 0; + if (fb_helper->deferred_setup) + return drm_fb_helper_initial_config(fb_helper, + fb_helper->preferred_bpp); + mutex_lock(&fb_helper->lock); mutex_lock(&dev->mode_config.mutex); @@ -2453,6 +2497,12 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) DRM_DEBUG_KMS("\n"); + width = dev->mode_config.max_width; + height = dev->mode_config.max_height; + + if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0) + DRM_DEBUG_KMS("No connectors reported connected with modes\n"); + drm_setup_crtcs(fb_helper, fb_helper->fb->width, fb_helper->fb->height); mutex_unlock(&dev->mode_config.mutex); diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index 33771d0c44e3..41c3587751f8 100644 --- a/include/drm/drm_fb_helper.h +++ b/include/drm/drm_fb_helper.h @@ -222,6 +222,27 @@ struct drm_fb_helper { * needs to be reprobe when fbdev is in control again. */ bool delayed_hotplug; + + /** + * @deferred_setup: + * + * If no outputs are connected (disconnected or unknown) the FB helper + * code will defer setup until at least one of the outputs shows up. + * This field keeps track of the status so that setup can be retried + * at every hotplug event until it succeeds eventually. + */ + bool deferred_setup; + + /** + * @preferred_bpp: + * + * Temporary storage for the driver's preferred BPP setting passed to + * FB helper initialization. This needs to be tracked so that deferred + * FB helper setup can pass this on. + * + * See also: @deferred_setup + */ + int preferred_bpp; }; /**