From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3139DC4332F for ; Tue, 20 Dec 2022 16:12:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E868B10E0C1; Tue, 20 Dec 2022 16:12:02 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0975E10E0BB for ; Tue, 20 Dec 2022 16:11:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A010876489; Tue, 20 Dec 2022 16:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1671552711; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/3Kua9axI5PV7LrYjvndaYIPH5JX8TtLl4Z9WPA7fQc=; b=bAlzs93/6FQPGmbdbljOXtoJxZZbVmDJ0RwD1ib7wXXwYXrlIhM9yasSQzWi2NUCVwh5mi OdsN8fEiUeNFkyQUDckXcCOgH+I9FiI1HJHD4p/qSu4CEx4qebawmOTvzZi52COvNE9tdU RG2lpbwD8ggDd07BjRGkmMoDC11Dgrw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1671552711; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/3Kua9axI5PV7LrYjvndaYIPH5JX8TtLl4Z9WPA7fQc=; b=ZErBS9PsG0BibEoRsR32MCwwP9PUWAId2vwD8CzWFM6AuEwHvbTWbwFMFj6T0dl2RE1rs2 o36xtYyyheoGXKCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7281E1390E; Tue, 20 Dec 2022 16:11:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KA0yG8feoWMiZQAAMHmgww (envelope-from ); Tue, 20 Dec 2022 16:11:51 +0000 From: Thomas Zimmermann To: daniel@ffwll.ch, airlied@gmail.com, javierm@redhat.com, jose.exposito89@gmail.com, mairacanal@riseup.net, mripard@kernel.org, maarten.lankhorst@linux.intel.com Subject: [PATCH v2 10/13] drm/fh-helper: Split fbdev single-probe helper Date: Tue, 20 Dec 2022 17:11:42 +0100 Message-Id: <20221220161145.27568-11-tzimmermann@suse.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221220161145.27568-1-tzimmermann@suse.de> References: <20221220161145.27568-1-tzimmermann@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Split the single-probe helper's implementation into multiple functions and get locking and overallocation out of the way of the surface setup. Simplifies later changes to the setup code. Signed-off-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/drm_fb_helper.c | 116 ++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 43 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index b3a731b9170a..af1495394d38 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1726,36 +1726,30 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, } EXPORT_SYMBOL(drm_fb_helper_pan_display); -/* - * Allocates the backing storage and sets up the fbdev info structure through - * the ->fb_probe callback. - */ -static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, - int preferred_bpp) + +static int __drm_fb_helper_find_sizes(struct drm_fb_helper *fb_helper, int preferred_bpp, + struct drm_fb_helper_surface_size *sizes) { struct drm_client_dev *client = &fb_helper->client; struct drm_device *dev = fb_helper->dev; - struct drm_mode_config *config = &dev->mode_config; - int ret = 0; int crtc_count = 0; struct drm_connector_list_iter conn_iter; - struct drm_fb_helper_surface_size sizes; struct drm_connector *connector; struct drm_mode_set *mode_set; int best_depth = 0; - memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); - sizes.surface_depth = 24; - sizes.surface_bpp = 32; - sizes.fb_width = (u32)-1; - sizes.fb_height = (u32)-1; + memset(sizes, 0, sizeof(struct drm_fb_helper_surface_size)); + sizes->surface_depth = 24; + sizes->surface_bpp = 32; + sizes->fb_width = (u32)-1; + sizes->fb_height = (u32)-1; /* * If driver picks 8 or 16 by default use that for both depth/bpp * to begin with */ - if (preferred_bpp != sizes.surface_bpp) - sizes.surface_depth = sizes.surface_bpp = preferred_bpp; + if (preferred_bpp != sizes->surface_bpp) + sizes->surface_depth = sizes->surface_bpp = preferred_bpp; drm_connector_list_iter_begin(fb_helper->dev, &conn_iter); drm_client_for_each_connector_iter(connector, &conn_iter) { @@ -1766,21 +1760,21 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, if (cmdline_mode->bpp_specified) { switch (cmdline_mode->bpp) { case 8: - sizes.surface_depth = sizes.surface_bpp = 8; + sizes->surface_depth = sizes->surface_bpp = 8; break; case 15: - sizes.surface_depth = 15; - sizes.surface_bpp = 16; + sizes->surface_depth = 15; + sizes->surface_bpp = 16; break; case 16: - sizes.surface_depth = sizes.surface_bpp = 16; + sizes->surface_depth = sizes->surface_bpp = 16; break; case 24: - sizes.surface_depth = sizes.surface_bpp = 24; + sizes->surface_depth = sizes->surface_bpp = 24; break; case 32: - sizes.surface_depth = 24; - sizes.surface_bpp = 32; + sizes->surface_depth = 24; + sizes->surface_bpp = 32; break; } break; @@ -1793,7 +1787,6 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, * supports RGBA5551 (16 bpp, depth 15) but not RGB565 (16 bpp, depth * 16) we need to scale down the depth of the sizes we request. */ - mutex_lock(&client->modeset_mutex); drm_client_for_each_modeset(mode_set, client) { struct drm_crtc *crtc = mode_set->crtc; struct drm_plane *plane = crtc->primary; @@ -1817,13 +1810,13 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, continue; /* We found a perfect fit, great */ - if (fmt->depth == sizes.surface_depth) { + if (fmt->depth == sizes->surface_depth) { best_depth = fmt->depth; break; } /* Skip depths above what we're looking for */ - if (fmt->depth > sizes.surface_depth) + if (fmt->depth > sizes->surface_depth) continue; /* Best depth found so far */ @@ -1831,10 +1824,10 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, best_depth = fmt->depth; } } - if (sizes.surface_depth != best_depth && best_depth) { + if (sizes->surface_depth != best_depth && best_depth) { drm_info(dev, "requested bpp %d, scaled depth down to %d", - sizes.surface_bpp, best_depth); - sizes.surface_depth = best_depth; + sizes->surface_bpp, best_depth); + sizes->surface_depth = best_depth; } /* first up get a count of crtcs now in use and new min/maxes width/heights */ @@ -1858,8 +1851,10 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, x = mode_set->x; y = mode_set->y; - sizes.surface_width = max_t(u32, desired_mode->hdisplay + x, sizes.surface_width); - sizes.surface_height = max_t(u32, desired_mode->vdisplay + y, sizes.surface_height); + sizes->surface_width = + max_t(u32, desired_mode->hdisplay + x, sizes->surface_width); + sizes->surface_height = + max_t(u32, desired_mode->vdisplay + y, sizes->surface_height); for (j = 0; j < mode_set->num_connectors; j++) { struct drm_connector *connector = mode_set->connectors[j]; @@ -1875,28 +1870,63 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, } if (lasth) - sizes.fb_width = min_t(u32, desired_mode->hdisplay + x, sizes.fb_width); + sizes->fb_width = min_t(u32, desired_mode->hdisplay + x, sizes->fb_width); if (lastv) - sizes.fb_height = min_t(u32, desired_mode->vdisplay + y, sizes.fb_height); + sizes->fb_height = min_t(u32, desired_mode->vdisplay + y, sizes->fb_height); } - mutex_unlock(&client->modeset_mutex); - if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) { + if (crtc_count == 0 || sizes->fb_width == -1 || sizes->fb_height == -1) { drm_info(dev, "Cannot find any crtc or sizes\n"); - - /* First time: disable all crtc's.. */ - if (!fb_helper->deferred_setup) - drm_client_modeset_commit(client); return -EAGAIN; } + return 0; +} + +static int drm_fb_helper_find_sizes(struct drm_fb_helper *fb_helper, int preferred_bpp, + struct drm_fb_helper_surface_size *sizes) +{ + struct drm_client_dev *client = &fb_helper->client; + struct drm_device *dev = fb_helper->dev; + struct drm_mode_config *config = &dev->mode_config; + int ret; + + mutex_lock(&client->modeset_mutex); + ret = __drm_fb_helper_find_sizes(fb_helper, preferred_bpp, sizes); + mutex_unlock(&client->modeset_mutex); + + if (ret) + return ret; + /* Handle our overallocation */ - sizes.surface_height *= drm_fbdev_overalloc; - sizes.surface_height /= 100; - if (sizes.surface_height > config->max_height) { + sizes->surface_height *= drm_fbdev_overalloc; + sizes->surface_height /= 100; + if (sizes->surface_height > config->max_height) { drm_dbg_kms(dev, "Fbdev over-allocation too large; clamping height to %d\n", config->max_height); - sizes.surface_height = config->max_height; + sizes->surface_height = config->max_height; + } + + return 0; +} + +/* + * Allocates the backing storage and sets up the fbdev info structure through + * the ->fb_probe callback. + */ +static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, + int preferred_bpp) +{ + struct drm_client_dev *client = &fb_helper->client; + struct drm_fb_helper_surface_size sizes; + int ret; + + ret = drm_fb_helper_find_sizes(fb_helper, preferred_bpp, &sizes); + if (ret) { + /* First time: disable all crtc's.. */ + if (!fb_helper->deferred_setup) + drm_client_modeset_commit(client); + return ret; } #if IS_ENABLED(CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM) -- 2.39.0