From patchwork Mon Nov 26 15:38:48 2018 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: 10698559 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 134C413BB for ; Mon, 26 Nov 2018 15:39:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00C8D29F07 for ; Mon, 26 Nov 2018 15:39:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E781229F16; Mon, 26 Nov 2018 15:39:04 +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=ham 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 442D629F07 for ; Mon, 26 Nov 2018 15:39:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F090B6E247; Mon, 26 Nov 2018 15:39:02 +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 8D0C06E247 for ; Mon, 26 Nov 2018 15:39:01 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:46846 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 1gRIyR-0004NG-Ei; Mon, 26 Nov 2018 16:38:59 +0100 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm/fb-helper/generic: Only restore when in use Date: Mon, 26 Nov 2018 16:38:48 +0100 Message-Id: <20181126153848.64966-1-noralf@tronnes.org> X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP On drm_driver->last_close the generic fbdev emulation will restore fbdev regardless of it being used or not. This is a problem for e-ink displays which don't want to be overwritten with zeroes when DRM userspace closes. Amend this by adding an open counter to track use in order to know when to restore. v1: Avoid special-casing and move the check to drm_fbdev_client_restore() (Daniel Vetter) Signed-off-by: Noralf Trønnes --- I was tied up in my previous attempt to solve this which predated the generic emulation, so I failed to see that I could solve this within the scope of the generic fbdev. drivers/gpu/drm/drm_fb_helper.c | 24 +++++++++++++++++++++++- include/drm/drm_fb_helper.h | 10 ++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 9a69ad7e9f3b..be93e7393704 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -2942,16 +2942,32 @@ EXPORT_SYMBOL(drm_fb_helper_output_poll_changed); static int drm_fbdev_fb_open(struct fb_info *info, int user) { struct drm_fb_helper *fb_helper = info->par; + unsigned int fb_open_count; if (!try_module_get(fb_helper->dev->driver->fops->owner)) return -ENODEV; + mutex_lock(&fb_helper->lock); + fb_open_count = fb_helper->fb_open_count++; + mutex_unlock(&fb_helper->lock); + + if (!fb_open_count) + drm_fb_helper_blank(FB_BLANK_UNBLANK, info); + return 0; } static int drm_fbdev_fb_release(struct fb_info *info, int user) { struct drm_fb_helper *fb_helper = info->par; + unsigned int fb_open_count; + + mutex_lock(&fb_helper->lock); + fb_open_count = --fb_helper->fb_open_count; + mutex_unlock(&fb_helper->lock); + + if (!fb_open_count) + drm_fb_helper_blank(FB_BLANK_POWERDOWN, info); module_put(fb_helper->dev->driver->fops->owner); @@ -3143,8 +3159,14 @@ static void drm_fbdev_client_unregister(struct drm_client_dev *client) static int drm_fbdev_client_restore(struct drm_client_dev *client) { struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client); + unsigned int fb_open_count; - drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); + mutex_lock(&fb_helper->lock); + fb_open_count = fb_helper->fb_open_count; + mutex_unlock(&fb_helper->lock); + + if (fb_open_count) + drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); return 0; } diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index bb9acea61369..e6ca1119d524 100644 --- a/include/drm/drm_fb_helper.h +++ b/include/drm/drm_fb_helper.h @@ -247,6 +247,16 @@ struct drm_fb_helper { * See also: @deferred_setup */ int preferred_bpp; + + /** + * @fb_open_count: + * + * The generic fbdev emulation uses this to track userspace/fbcon opens + * to know when to restore. + * + * Protected by @lock. + */ + unsigned int fb_open_count; }; static inline struct drm_fb_helper *