From patchwork Thu Feb 21 14:35:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 222298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2B7412C0089 for ; Fri, 22 Feb 2013 01:36:14 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753547Ab3BUOgN (ORCPT ); Thu, 21 Feb 2013 09:36:13 -0500 Received: from moutng.kundenserver.de ([212.227.126.187]:57463 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093Ab3BUOgM (ORCPT ); Thu, 21 Feb 2013 09:36:12 -0500 Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mrbap0) with ESMTP (Nemesis) id 0MFi3J-1U3GSy3stZ-00Ej70; Thu, 21 Feb 2013 15:36:10 +0100 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id AE4C62A28241; Thu, 21 Feb 2013 15:36:08 +0100 (CET) X-Virus-Scanned: amavisd-new at avionic-design.de Received: from mailbox.adnet.avionic-design.de ([127.0.0.1]) by localhost (mailbox.avionic-design.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Nih-hTZh4NDI; Thu, 21 Feb 2013 15:36:02 +0100 (CET) Received: from mailman.adnet.avionic-design.de (mailman.adnet.avionic-design.de [172.20.31.172]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id 6AF8C2A28162; Thu, 21 Feb 2013 15:36:02 +0100 (CET) Received: from localhost (avionic-0098.adnet.avionic-design.de [172.20.31.233]) by mailman.adnet.avionic-design.de (Postfix) with ESMTP id D4EE510091A; Thu, 21 Feb 2013 15:35:57 +0100 (CET) From: Thierry Reding To: Dave Airlie Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH v4 1/9] drm: Add consistency check for page-flipping Date: Thu, 21 Feb 2013 15:35:53 +0100 Message-Id: <1361457361-13838-2-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361457361-13838-1-git-send-email-thierry.reding@avionic-design.de> References: <1361457361-13838-1-git-send-email-thierry.reding@avionic-design.de> X-Provags-ID: V02:K0:1pYTulT1sPIriDqALyLcLOWEoavyLduZX3b3CMSV9PX T0Se2RVK97EXb2F0aWE1GGwFDphciTjQgo9IOcbNdur+8oexYk 8lx2bl4PvP3oOYT9AD65CoMkRzWoL6PztGlm7ft5pOjKjIpDMj IMIaspSJyggeq9qflSCBBnEVU0/8HsK2W4ZXT7odvcDgZdsmvO N8EMEjIqTXLsZj9FOAf2yU8fughEX79EJhTsc28SajKLW4Qcuk 7hpGIcz+NfsuzsMGUJIG1YCXp0tUppcybjVAtgqY0WCfAqPuoZ hsVz5+wVj2f5USLM3MenMxjk0I5ebKBEQ2qpq4TC7/eTewvdCB UHjKZL4Gs0gda/ODkyCtJPWHT3bxGFxlUjU2NR0+B8rwiCG8oz b4twQtylTyYa9ngn6A/AFnARQz82hfjVJClctdnnmZKrckLHSI FDNz3 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Driver implementations of the drm_crtc's .page_flip() function are required to update the crtc->fb field on success to reflect that the new framebuffer is now in use. This is important to keep reference counting on the framebuffers balanced. While at it, document this requirement to keep others from falling into the same trap. Suggested-by: Daniel Vetter Signed-off-by: Thierry Reding Reviewed-by: Daniel Vetter --- Documentation/DocBook/drm.tmpl | 6 ++++++ drivers/gpu/drm/drm_crtc.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/Documentation/DocBook/drm.tmpl b/Documentation/DocBook/drm.tmpl index 51e1904..a6428dd 100644 --- a/Documentation/DocBook/drm.tmpl +++ b/Documentation/DocBook/drm.tmpl @@ -1161,6 +1161,12 @@ int max_width, max_height; any new rendering to the frame buffer until the page flip completes. + If a page flip can be successfully scheduled the driver must set the + drm_crtc-<fb field to the new framebuffer pointed to + by fb. This is important so that the reference counting + on framebuffers stays balanced. + + If a page flip is already pending, the page_flip operation must return -EBUSY. diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 781aef5..3bdf2a6 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3792,6 +3792,13 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, /* Keep the old fb, don't unref it. */ old_fb = NULL; } else { + /* + * Warn if the driver hasn't properly updated the crtc->fb + * field to reflect that the new framebuffer is now used. + * Failing to do so will screw with the reference counting + * on framebuffers. + */ + WARN_ON(crtc->fb != fb); /* Unref only the old framebuffer. */ fb = NULL; }