From patchwork Sun Apr 7 16:52: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: 10888485 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 CD44E17E0 for ; Sun, 7 Apr 2019 16:55:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4AC228434 for ; Sun, 7 Apr 2019 16:55:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A94F328653; Sun, 7 Apr 2019 16:55:33 +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 3A8CB28434 for ; Sun, 7 Apr 2019 16:55:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B241A895EE; Sun, 7 Apr 2019 16:55:29 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@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 5ACDD895E2; Sun, 7 Apr 2019 16:55:27 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:49162 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 1hDB2S-0008Km-75; Sun, 07 Apr 2019 18:53:00 +0200 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Date: Sun, 7 Apr 2019 18:52:41 +0200 Message-Id: <20190407165243.54043-11-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190407165243.54043-1-noralf@tronnes.org> References: <20190407165243.54043-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=zy/AxGO/3M2fhyIlwvROEIRCs6UDIPA2fewPXUwAwbQ=; b=UTDvZJ5kT35IBqyJtsX7qLbGCH0orsV06ysZOHdyIMpK4JKfSHhYOWD+Qh54PLaa9JuHGST1WedQtHtR0RbtAuqVug/v4zjBckRjgLgaJQ93D5X3L9sgx3s4BV9qF0GUsBDQ9X603TSCnxgO2lShhSPwaAAFVkh4mvw184HysTjcCP9IWTepQzqfGrnnbB20oBDVWQ2hYUdaaT6ZmQb30cmCd8jh3H0sm8Z6YanPhfOneX8JWILEDn8YkFwh0e5acse5QRogb6EhnZHcdWI8TgZfbygs4HF5kP42wwl9jtwBiNEWHiVtZ4CuHP8Gu8SIiuTFy9PS2HhJxgAVHlcwXw==; Subject: [Intel-gfx] [PATCH v2 10/12] drm/fb-helper: Prepare to move out modeset config code X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org, =?utf-8?q?Noral?= =?utf-8?q?f_Tr=C3=B8nnes?= Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 Reviewed-by: Maxime Ripard --- drivers/gpu/drm/drm_fb_helper.c | 63 +++++++++++++++++++++++---------- include/drm/drm_fb_helper.h | 4 --- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index e13026724b2c..9287ff4ae2d8 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -43,6 +43,10 @@ #include "drm_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, @@ -1794,7 +1798,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; @@ -1873,7 +1877,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) { @@ -1906,7 +1910,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; @@ -2070,7 +2074,7 @@ static bool drm_client_firmware_config(struct drm_client_dev *client, 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); @@ -2239,30 +2243,48 @@ static bool drm_client_firmware_config(struct drm_client_dev *client, return ret; } -static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, - u32 width, u32 height) +/** + * drm_client_modeset_probe() - Probe for displays + * @client: DRM client + * @width: Maximum display mode width (optional) + * @height: Maximum display mode height (optional) + * + * This function sets up display pipelines for enabled connectors and stores the + * config in the client's modeset array. + * + * Returns: + * Zero on success or negative error code on failure. + */ + +int drm_client_modeset_probe(struct drm_client_dev *client, unsigned int width, unsigned int height) { struct drm_connector *connector, **connectors = NULL; - struct drm_client_dev *client = &fb_helper->client; struct drm_connector_list_iter conn_iter; - struct drm_device *dev = fb_helper->dev; + struct drm_device *dev = client->dev; 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"); + 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); @@ -2271,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 0; crtcs = kcalloc(connector_count, sizeof(*crtcs), GFP_KERNEL); modes = kcalloc(connector_count, sizeof(*modes), GFP_KERNEL); @@ -2279,12 +2301,13 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, enabled = kcalloc(connector_count, sizeof(bool), GFP_KERNEL); if (!crtcs || !modes || !enabled || !offsets) { DRM_ERROR("Memory allocation failed\n"); + ret = -ENOMEM; goto out; } mutex_lock(&client->modeset_mutex); - 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) @@ -2309,14 +2332,14 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, drm_client_pick_crtcs(client, connectors, connector_count, crtcs, modes, 0, width, height); } - mutex_unlock(&fb_helper->dev->mode_config.mutex); + mutex_unlock(&dev->mode_config.mutex); drm_client_modeset_release(client); 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(client, crtc); @@ -2326,8 +2349,10 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, mode->name, crtc->base.id, offset->x, offset->y); if (WARN_ON_ONCE(modeset->num_connectors == DRM_CLIENT_MAX_CLONED_CONNECTORS || - (dev->mode_config.num_crtc > 1 && modeset->num_connectors == 1))) + (dev->mode_config.num_crtc > 1 && modeset->num_connectors == 1))) { + ret = -EINVAL; break; + } modeset->mode = drm_mode_duplicate(dev, mode); drm_connector_get(connector); @@ -2347,6 +2372,8 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, for (i = 0; i < connector_count; i++) drm_connector_put(connectors[i]); kfree(connectors); + + return ret; } /* @@ -2428,7 +2455,7 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper, width = dev->mode_config.max_width; height = dev->mode_config.max_height; - drm_setup_crtcs(fb_helper, width, height); + drm_client_modeset_probe(&fb_helper->client, width, height); ret = drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); if (ret < 0) { if (ret == -EAGAIN) { @@ -2576,7 +2603,7 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) DRM_DEBUG_KMS("\n"); - drm_setup_crtcs(fb_helper, fb_helper->fb->width, fb_helper->fb->height); + drm_client_modeset_probe(&fb_helper->client, fb_helper->fb->width, fb_helper->fb->height); drm_setup_crtcs_fb(fb_helper); mutex_unlock(&fb_helper->lock); diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index 10481178e7e0..80591bc02de7 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