From patchwork Wed Feb 13 16:05:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 220186 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 CE77F2C0294 for ; Thu, 14 Feb 2013 03:05:16 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759821Ab3BMQFP (ORCPT ); Wed, 13 Feb 2013 11:05:15 -0500 Received: from moutng.kundenserver.de ([212.227.126.187]:50600 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759820Ab3BMQFO (ORCPT ); Wed, 13 Feb 2013 11:05:14 -0500 Received: from mailbox.adnet.avionic-design.de (mailbox.avionic-design.de [109.75.18.3]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0MKuxg-1U5epZ3Hea-000jxH; Wed, 13 Feb 2013 17:05:10 +0100 Received: from localhost (localhost [127.0.0.1]) by mailbox.adnet.avionic-design.de (Postfix) with ESMTP id 1BA9428B02A7; Wed, 13 Feb 2013 17:05:09 +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 kX4hwu6Sp2cC; Wed, 13 Feb 2013 17:05:07 +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 4D96928B029D; Wed, 13 Feb 2013 17:05:07 +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 A226C1006BD; Wed, 13 Feb 2013 17:05:03 +0100 (CET) From: Thierry Reding To: Dave Airlie Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH v3 1/7] drm: Add consistency check for page-flipping Date: Wed, 13 Feb 2013 17:05:00 +0100 Message-Id: <1360771506-17849-2-git-send-email-thierry.reding@avionic-design.de> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360771506-17849-1-git-send-email-thierry.reding@avionic-design.de> References: <1360771506-17849-1-git-send-email-thierry.reding@avionic-design.de> X-Provags-ID: V02:K0:XStFv21YKSPEKNpuit7QcmPgyin5zot6/EbsBf9bpCU m9pXu+Vljmd2gl8Y/IYAaSiRM+NOMQJdwy6fu3CRo42lO8Hgae WUQBaPhWRA3KFv07L3WYgIJsXfcxJQcSoVLT/szpHi55rThoeP o1xLMwVmxu3bXX54eXsEmjwxjbufGDDabyvSnCnKzQGJ7MPoRj OXam+osh7C2P6bMJ3/yNKn6o12NaDpnlxZkUv0NHsnk6EyEXTN WPnw3r22yVT1M4TxMqvadV8wO+8U7DujD4aCT/VYM2DcbpEXGu wwLnP/6iNNL4CSHNMm8pNiKpn9W7a3MpwjrkkjQzFztSquM+Br 9R8U+skAB3cMW5xEzdC77aBWGtQaCVH4mwb8by6m/Oru9wTS+o tb4pKo97Rx6QdNCnGNy78lyAkfbxOPRfimEAPrgo14HgrE9cS/ hrGGk 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 fae8018..8dfaeb0 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 838c9b6..d86edc1 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3766,6 +3766,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; }