From patchwork Tue Mar 26 17:55:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10871853 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 E073E922 for ; Tue, 26 Mar 2019 18:02:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF4C41FF3E for ; Tue, 26 Mar 2019 18:02:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2E0B2862A; Tue, 26 Mar 2019 18:02:47 +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=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 56DA51FF3E for ; Tue, 26 Mar 2019 18:02:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8E48E6E075; Tue, 26 Mar 2019 18:02:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id B7C636E075; Tue, 26 Mar 2019 18:02:37 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:46322 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1h8qIx-0006Mj-9a; Tue, 26 Mar 2019 18:56:07 +0100 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 11/16] drm/fb-helper: Prepare to move out modeset config code Date: Tue, 26 Mar 2019 18:55:41 +0100 Message-Id: <20190326175546.18126-12-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190326175546.18126-1-noralf@tronnes.org> References: <20190326175546.18126-1-noralf@tronnes.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=f2t6yK0nAg9QjgNUMJyvCkLbW9SCqvwQIfbUuW1QlvA=; b=fLinQ1i16RenaWQMS0KBBSb4v2gmGhr1CjSzpbExRAkEt0dNHqo7gl5hSSCNddVzAQydTorO0Lz/df/UpW9KN+Yf2tlIwTtNG8MQLzjuwcARrPdpar/BBGyYEz4SVLhWdEbQ9U8qTUTBe3lE3rgTHXcscCmCBuJkFmMUbuC4bqPx4gxiJVw+/f5v04zOs0Ey5ip+7lxIu9fwqkZDQCySdUoAbXHpgTFJUetOkmK54mHwIGgPKzDLsxYTjufxF2LYW7YeOTjIkfm2YNYS2q7iS20uLE2KuAzgNbiSlfdBPzEErldwGS3mEp5mz5blov6lHLTA6UQPj7jQS1EprNAZ0Q==; 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: intel-gfx@lists.freedesktop.org, mstaudt@suse.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This prepares the modeset code so it can be moved out as-is in the next patch. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_fb_helper.c | 75 +++++++++++++++++++++++++-------- include/drm/drm_fb_helper.h | 4 -- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index de805956849d..afe4d4220e4d 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -45,6 +45,10 @@ #include "drm_crtc_internal.h" #include "drm_crtc_helper_internal.h" +struct drm_client_offset { + int x, y; +}; + static bool drm_fbdev_emulation = true; module_param_named(fbdev_emulation, drm_fbdev_emulation, bool, 0600); MODULE_PARM_DESC(fbdev_emulation, @@ -1792,7 +1796,7 @@ static bool drm_client_target_cloned(struct drm_device *dev, struct drm_connector **connectors, unsigned int connector_count, struct drm_display_mode **modes, - struct drm_fb_offset *offsets, + struct drm_client_offset *offsets, bool *enabled, int width, int height) { int count, i, j; @@ -1871,7 +1875,7 @@ static bool drm_client_target_cloned(struct drm_device *dev, static int drm_client_get_tile_offsets(struct drm_connector **connectors, unsigned int connector_count, struct drm_display_mode **modes, - struct drm_fb_offset *offsets, + struct drm_client_offset *offsets, int idx, int h_idx, int v_idx) { @@ -1904,7 +1908,7 @@ static int drm_client_get_tile_offsets(struct drm_connector **connectors, static bool drm_client_target_preferred(struct drm_connector **connectors, unsigned int connector_count, struct drm_display_mode **modes, - struct drm_fb_offset *offsets, + struct drm_client_offset *offsets, bool *enabled, int width, int height) { const u64 mask = BIT_ULL(connector_count) - 1; @@ -2068,7 +2072,7 @@ static bool drm_client_firmware_config(struct drm_device *dev, unsigned int connector_count, struct drm_crtc **crtcs, struct drm_display_mode **modes, - struct drm_fb_offset *offsets, + struct drm_client_offset *offsets, bool *enabled, int width, int height) { unsigned int count = min_t(unsigned int, connector_count, BITS_PER_LONG); @@ -2236,32 +2240,51 @@ static bool drm_client_firmware_config(struct drm_device *dev, return ret; } -static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, - u32 width, u32 height) +/** + * drm_client_modesets_probe() - Probe for displays + * @dev: DRM device + * @width: Maximum display mode width (optional) + * @height: Maximum display mode height (optional) + * + * This function tries to set up pipelines for enabled connectors and returns + * the CRTC config as a &drm_mode_set array. + * + * Use drm_client_modesets_release() to free the array and its resources. + * + * Returns: + * A &drm_mode_set array on success, NULL if no connectors are found + * or error pointer on failure. + */ +struct drm_mode_set * +drm_client_modesets_probe(struct drm_device *dev, unsigned int width, unsigned int height) { struct drm_connector *connector, **connectors = NULL; struct drm_connector_list_iter conn_iter; - struct drm_device *dev = fb_helper->dev; struct drm_mode_set *modesets = NULL; unsigned int total_modes_count = 0; + struct drm_client_offset *offsets; unsigned int connector_count = 0; struct drm_display_mode **modes; - struct drm_fb_offset *offsets; struct drm_crtc **crtcs; + int i, ret = 0; bool *enabled; - int i; DRM_DEBUG_KMS("\n"); - /* prevent concurrent modification of connector_count by hotplug */ - lockdep_assert_held(&fb_helper->lock); + + if (!width) + width = dev->mode_config.max_width; + if (!height) + height = dev->mode_config.max_height; drm_connector_list_iter_begin(dev, &conn_iter); drm_client_for_each_connector_iter(connector, &conn_iter) { struct drm_connector **tmp; tmp = krealloc(connectors, (connector_count + 1) * sizeof(*connectors), GFP_KERNEL); - if (!tmp) + if (!tmp) { + ret = -ENOMEM; goto free_connectors; + } connectors = tmp; drm_connector_get(connector); @@ -2270,7 +2293,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, drm_connector_list_iter_end(&conn_iter); if (!connector_count) - return; + return NULL; modesets = drm_client_modesets_create(dev); crtcs = kcalloc(connector_count, sizeof(*crtcs), GFP_KERNEL); @@ -2279,10 +2302,11 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, enabled = kcalloc(connector_count, sizeof(bool), GFP_KERNEL); if (IS_ERR(modesets) || !crtcs || !modes || !enabled || !offsets) { DRM_ERROR("Memory allocation failed\n"); + ret = -ENOMEM; goto out; } - mutex_lock(&fb_helper->dev->mode_config.mutex); + mutex_lock(&dev->mode_config.mutex); for (i = 0; i < connector_count; i++) total_modes_count += connectors[i]->funcs->fill_modes(connectors[i], width, height); if (!total_modes_count) @@ -2307,12 +2331,12 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, drm_client_pick_crtcs(dev, modesets, connectors, connector_count, crtcs, modes, 0, width, height); } - mutex_unlock(&fb_helper->dev->mode_config.mutex); + mutex_unlock(&dev->mode_config.mutex); for (i = 0; i < connector_count; i++) { struct drm_display_mode *mode = modes[i]; struct drm_crtc *crtc = crtcs[i]; - struct drm_fb_offset *offset = &offsets[i]; + struct drm_client_offset *offset = &offsets[i]; if (mode && crtc) { struct drm_mode_set *modeset = drm_client_find_modeset(modesets, crtc); @@ -2332,8 +2356,6 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, modeset->y = offset->y; } } - - swap(fb_helper->modesets, modesets); out: kfree(crtcs); kfree(modes); @@ -2346,6 +2368,23 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, kfree(connectors); } + if (ret) { + drm_client_modesets_release(modesets); + return ERR_PTR(ret); + } + + return modesets; +} + +static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, u32 width, u32 height) +{ + struct drm_mode_set *modesets; + + modesets = drm_client_modesets_probe(fb_helper->dev, width, height); + if (IS_ERR_OR_NULL(modesets)) + return; + + swap(fb_helper->modesets, modesets); drm_client_modesets_release(modesets); } diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index 946bf179e96e..bd38d5c85c92 100644 --- a/include/drm/drm_fb_helper.h +++ b/include/drm/drm_fb_helper.h @@ -42,10 +42,6 @@ enum mode_set_atomic { ENTER_ATOMIC_MODE_SET, }; -struct drm_fb_offset { - int x, y; -}; - /** * struct drm_fb_helper_surface_size - describes fbdev size and scanout surface size * @fb_width: fbdev width