From patchwork Wed Oct 26 08:55:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Starkey X-Patchwork-Id: 9396351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 71F4260477 for ; Wed, 26 Oct 2016 08:55:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F84F283F2 for ; Wed, 26 Oct 2016 08:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 227E028B86; Wed, 26 Oct 2016 08:55:53 +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=-4.2 required=2.0 tests=BAYES_00, 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 CFBBD28A32 for ; Wed, 26 Oct 2016 08:55:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6A7986E821; Wed, 26 Oct 2016 08:55:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by gabe.freedesktop.org (Postfix) with ESMTP id 965286E81A for ; Wed, 26 Oct 2016 08:55:36 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7CA50152F; Wed, 26 Oct 2016 01:55:36 -0700 (PDT) Received: from e106950-lin.cambridge.arm.com (e106950-lin.cambridge.arm.com [10.2.133.193]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC58A3F220; Wed, 26 Oct 2016 01:55:35 -0700 (PDT) From: Brian Starkey To: dri-devel@lists.freedesktop.org Subject: [RFC PATCH v2 7/9] drm: atomic: factor out common out-fence operations Date: Wed, 26 Oct 2016 09:55:06 +0100 Message-Id: <1477472108-27222-8-git-send-email-brian.starkey@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1477472108-27222-1-git-send-email-brian.starkey@arm.com> References: <1477472108-27222-1-git-send-email-brian.starkey@arm.com> Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some parts of setting up the CRTC out-fence can be re-used for writeback out-fences. Factor this out into a separate function. Signed-off-by: Brian Starkey --- drivers/gpu/drm/drm_atomic.c | 64 +++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index f434f34..3f8fc97 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1693,37 +1693,46 @@ void drm_atomic_clean_old_fb(struct drm_device *dev, } EXPORT_SYMBOL(drm_atomic_clean_old_fb); -static int crtc_setup_out_fence(struct drm_crtc *crtc, - struct drm_crtc_state *crtc_state, - struct drm_out_fence_state *fence_state) +static struct fence *get_crtc_fence(struct drm_crtc *crtc, + struct drm_crtc_state *crtc_state) { struct fence *fence; - fence_state->fd = get_unused_fd_flags(O_CLOEXEC); - if (fence_state->fd < 0) { - return fence_state->fd; - } - - fence_state->out_fence_ptr = crtc_state->out_fence_ptr; - crtc_state->out_fence_ptr = NULL; - - if (put_user(fence_state->fd, fence_state->out_fence_ptr)) - return -EFAULT; - fence = kzalloc(sizeof(*fence), GFP_KERNEL); if (!fence) - return -ENOMEM; + return NULL; fence_init(fence, &drm_crtc_fence_ops, &crtc->fence_lock, crtc->fence_context, ++crtc->fence_seqno); + crtc_state->event->base.fence = fence_get(fence); + + return fence; +} + +static int setup_out_fence(struct drm_out_fence_state *fence_state, + u64 __user *out_fence_ptr, + struct fence *fence) +{ + int ret; + + DRM_DEBUG_ATOMIC("Putting out-fence %p into user ptr: %p\n", + fence, out_fence_ptr); + + fence_state->fd = get_unused_fd_flags(O_CLOEXEC); + if (fence_state->fd < 0) + return fence_state->fd; + + ret = put_user(fence_state->fd, out_fence_ptr); + if (ret) + return ret; + + fence_state->out_fence_ptr = out_fence_ptr; + fence_state->sync_file = sync_file_create(fence); - if(!fence_state->sync_file) { - fence_put(fence); + if (!fence_state->sync_file) return -ENOMEM; - } - crtc_state->event->base.fence = fence_get(fence); return 0; } @@ -1896,10 +1905,21 @@ retry: } if (crtc_state->out_fence_ptr) { - ret = crtc_setup_out_fence(crtc, crtc_state, - &fence_state[fence_idx++]); - if (ret) + struct fence *fence = get_crtc_fence(crtc, crtc_state); + if (!fence) { + ret = -ENOMEM; + goto out; + } + + ret = setup_out_fence(&fence_state[fence_idx++], + crtc_state->out_fence_ptr, + fence); + if (ret) { + fence_put(fence); goto out; + } + + crtc_state->out_fence_ptr = NULL; } }