From patchwork Mon May 6 18:01:34 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: 10931759 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 8BD6D1515 for ; Mon, 6 May 2019 18:02:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B8AF2884B for ; Mon, 6 May 2019 18:02:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FB7828866; Mon, 6 May 2019 18:02: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 E70652884B for ; Mon, 6 May 2019 18:02:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 98FC889B7D; Mon, 6 May 2019 18:02:14 +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 3800D89B69; Mon, 6 May 2019 18:02:11 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:52392 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 1hNhwH-0007OJ-F5; Mon, 06 May 2019 20:02:09 +0200 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [PATCH v5 06/11] drm/fb-helper: Prepare to move out commit code Date: Mon, 6 May 2019 20:01:34 +0200 Message-Id: <20190506180139.6913-7-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190506180139.6913-1-noralf@tronnes.org> References: <20190506180139.6913-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=tsCPXiLEGE1txneUev7qOTAPj7/Ez99hKxosej1TAMg=; b=Al3Nxy9tKjVAxlOh3XnLyKDAzi7HRL7DsZ+UFEXdMpZScA9J7Jp56BNv85zzapdTbKZpssl7UP/2m14FVa6aPtkFizaNEJlIjJ9saNnkEJG8uMGeC5JvhC8t3ump2ATzeg7yk6fQ9FsAW8w1LZLJaagvpR7DsLWpqesdE5CcI6fpW10iT6rOQcX+DEJJGvEyA1aLX5tjTXeGdYrnWh8QQRcuueUKZ12SsrK5g4cUb8WX/vFGFc8V/5reElDkkrOnqrDrjZr3axChpjm3S9dXlNUMi2IjNpgmHP+Y+069LqqSPvnI6fU2AYyQk9udqWQ8KCiSysEkyBsGyjzEYRP6Ew==; 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 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This makes the necessary changes so the commit code can be moved out to drm_client as-is in the next patch. It's split up to ease review. Signed-off-by: Noralf Trønnes Reviewed-by: Sam Ravnborg --- drivers/gpu/drm/drm_fb_helper.c | 122 +++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 6637858bf530..617e86d010fb 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -388,9 +388,20 @@ int drm_fb_helper_debug_leave(struct fb_info *info) } EXPORT_SYMBOL(drm_fb_helper_debug_leave); -/* Check if the plane can hw rotate to match panel orientation */ -static bool drm_fb_helper_panel_rotation(struct drm_mode_set *modeset, - unsigned int *rotation) +/** + * drm_client_panel_rotation() - Check panel orientation + * @modeset: DRM modeset + * @rotation: Returned rotation value + * + * This function checks if the primary plane in @modeset can hw rotate to match + * the panel orientation on its connector. + * + * Note: Currently only 0 and 180 degrees are supported. + * + * Return: + * True if the plane can do the rotation, false otherwise. + */ +bool drm_client_panel_rotation(struct drm_mode_set *modeset, unsigned int *rotation) { struct drm_connector *connector = modeset->connectors[0]; struct drm_plane *plane = modeset->crtc->primary; @@ -431,10 +442,9 @@ static bool drm_fb_helper_panel_rotation(struct drm_mode_set *modeset, return true; } -static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool active) +static int drm_client_modeset_commit_atomic(struct drm_client_dev *client, bool active) { - struct drm_client_dev *client = &fb_helper->client; - struct drm_device *dev = fb_helper->dev; + struct drm_device *dev = client->dev; struct drm_plane_state *plane_state; struct drm_plane *plane; struct drm_atomic_state *state; @@ -474,7 +484,7 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ struct drm_plane *primary = mode_set->crtc->primary; unsigned int rotation; - if (drm_fb_helper_panel_rotation(mode_set, &rotation)) { + if (drm_client_panel_rotation(mode_set, &rotation)) { /* Cannot fail as we've already gotten the plane state above */ plane_state = drm_atomic_get_new_plane_state(state, primary); plane_state->rotation = rotation; @@ -516,15 +526,14 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ goto retry; } -static int restore_fbdev_mode_legacy(struct drm_fb_helper *fb_helper) +static int drm_client_modeset_commit_legacy(struct drm_client_dev *client) { - struct drm_client_dev *client = &fb_helper->client; - struct drm_device *dev = fb_helper->dev; + struct drm_device *dev = client->dev; struct drm_mode_set *mode_set; struct drm_plane *plane; int ret = 0; - drm_modeset_lock_all(fb_helper->dev); + drm_modeset_lock_all(dev); drm_for_each_plane(plane, dev) { if (plane->type != DRM_PLANE_TYPE_PRIMARY) drm_plane_force_disable(plane); @@ -553,35 +562,53 @@ static int restore_fbdev_mode_legacy(struct drm_fb_helper *fb_helper) goto out; } out: - drm_modeset_unlock_all(fb_helper->dev); + drm_modeset_unlock_all(dev); return ret; } -static int restore_fbdev_mode_force(struct drm_fb_helper *fb_helper) +/** + * drm_client_modeset_commit_force() - Force commit CRTC configuration + * @client: DRM client + * + * Commit modeset configuration to crtcs without checking if there is a DRM master. + * + * Returns: + * Zero on success or negative error code on failure. + */ +int drm_client_modeset_commit_force(struct drm_client_dev *client) { - struct drm_device *dev = fb_helper->dev; + struct drm_device *dev = client->dev; int ret; - mutex_lock(&fb_helper->client.modeset_mutex); + mutex_lock(&client->modeset_mutex); if (drm_drv_uses_atomic_modeset(dev)) - ret = restore_fbdev_mode_atomic(fb_helper, true); + ret = drm_client_modeset_commit_atomic(client, true); else - ret = restore_fbdev_mode_legacy(fb_helper); - mutex_unlock(&fb_helper->client.modeset_mutex); + ret = drm_client_modeset_commit_legacy(client); + mutex_unlock(&client->modeset_mutex); return ret; } -static int restore_fbdev_mode(struct drm_fb_helper *fb_helper) +/** + * drm_client_modeset_commit() - Commit CRTC configuration + * @client: DRM client + * + * Commit modeset configuration to crtcs. + * + * Returns: + * Zero on success or negative error code on failure. + */ +int drm_client_modeset_commit(struct drm_client_dev *client) { - struct drm_device *dev = fb_helper->dev; + struct drm_device *dev = client->dev; int ret; if (!drm_master_internal_acquire(dev)) return -EBUSY; - ret = restore_fbdev_mode_force(fb_helper); + ret = drm_client_modeset_commit_force(client); drm_master_internal_release(dev); @@ -621,7 +648,7 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) * So first these tests need to be fixed so they drop master or don't * have an fd open. */ - ret = restore_fbdev_mode_force(fb_helper); + ret = drm_client_modeset_commit_force(&fb_helper->client); do_delayed = fb_helper->delayed_hotplug; if (do_delayed) @@ -655,7 +682,7 @@ static bool drm_fb_helper_force_kernel_mode(void) continue; mutex_lock(&helper->lock); - ret = restore_fbdev_mode_force(helper); + ret = drm_client_modeset_commit_force(&helper->client); if (ret) error = true; mutex_unlock(&helper->lock); @@ -687,10 +714,9 @@ static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { }; #endif -static void dpms_legacy(struct drm_fb_helper *fb_helper, int dpms_mode) +static void drm_client_modeset_dpms_legacy(struct drm_client_dev *client, int dpms_mode) { - struct drm_client_dev *client = &fb_helper->client; - struct drm_device *dev = fb_helper->dev; + struct drm_device *dev = client->dev; struct drm_connector *connector; struct drm_mode_set *modeset; int j; @@ -710,28 +736,42 @@ static void dpms_legacy(struct drm_fb_helper *fb_helper, int dpms_mode) drm_modeset_unlock_all(dev); } -static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode) +/** + * drm_client_modeset_dpms() - Set DPMS mode + * @client: DRM client + * @mode: DPMS mode + * + * Note: For atomic drivers @mode is reduced to on/off. + * + * Returns: + * Zero on success or negative error code on failure. + */ +int drm_client_modeset_dpms(struct drm_client_dev *client, int mode) { - struct drm_fb_helper *fb_helper = info->par; - struct drm_client_dev *client = &fb_helper->client; - struct drm_device *dev = fb_helper->dev; + struct drm_device *dev = client->dev; + int ret = 0; - /* - * For each CRTC in this fb, turn the connectors on/off. - */ - mutex_lock(&fb_helper->lock); if (!drm_master_internal_acquire(dev)) - goto unlock; + return -EBUSY; mutex_lock(&client->modeset_mutex); if (drm_drv_uses_atomic_modeset(dev)) - restore_fbdev_mode_atomic(fb_helper, dpms_mode == DRM_MODE_DPMS_ON); + ret = drm_client_modeset_commit_atomic(client, mode == DRM_MODE_DPMS_ON); else - dpms_legacy(fb_helper, dpms_mode); + drm_client_modeset_dpms_legacy(client, mode); mutex_unlock(&client->modeset_mutex); drm_master_internal_release(dev); -unlock: + + return ret; +} + +static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode) +{ + struct drm_fb_helper *fb_helper = info->par; + + mutex_lock(&fb_helper->lock); + drm_client_modeset_dpms(&fb_helper->client, dpms_mode); mutex_unlock(&fb_helper->lock); } @@ -1805,7 +1845,7 @@ static int pan_display_atomic(struct fb_var_screeninfo *var, pan_set(fb_helper, var->xoffset, var->yoffset); - ret = restore_fbdev_mode_force(fb_helper); + ret = drm_client_modeset_commit_force(&fb_helper->client); if (!ret) { info->var.xoffset = var->xoffset; info->var.yoffset = var->yoffset; @@ -2031,7 +2071,7 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, /* First time: disable all crtc's.. */ if (!fb_helper->deferred_setup) - restore_fbdev_mode(fb_helper); + drm_client_modeset_commit(client); return -EAGAIN; } @@ -2805,7 +2845,7 @@ static void drm_setup_crtcs_fb(struct drm_fb_helper *fb_helper) modeset->fb = fb_helper->fb; - if (drm_fb_helper_panel_rotation(modeset, &rotation)) + if (drm_client_panel_rotation(modeset, &rotation)) /* Rotating in hardware, fbcon should not rotate */ sw_rotations |= DRM_MODE_ROTATE_0; else