From patchwork Fri Apr 15 01:29:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 8844181 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 641429F71A for ; Fri, 15 Apr 2016 01:30:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E6B9202FF for ; Fri, 15 Apr 2016 01:30:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3B09720374 for ; Fri, 15 Apr 2016 01:30:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 533C46EB66; Fri, 15 Apr 2016 01:30:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-f179.google.com (mail-pf0-f179.google.com [209.85.192.179]) by gabe.freedesktop.org (Postfix) with ESMTPS id EC33E6EB66 for ; Fri, 15 Apr 2016 01:29:55 +0000 (UTC) Received: by mail-pf0-f179.google.com with SMTP id c20so51439222pfc.1 for ; Thu, 14 Apr 2016 18:29:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F0C+KqHmaj5XB0b6+Z7YojMqrFBHhAml5F6WnHj0v90=; b=D5SRzxEuqhBYjAPQ67R41FJ+Y1vvsczv104odQDdu81gkjUGJ1f3zvr3UTDyKlZSG+ AuSS4UskiJrE77Hd65rDsmXFSwLf/AOZy3tptXEeC496FI10Ez9fzjzDjpQyFfcQqSss neOpfDaRUo+OKBtbW9nDdIZKP9qShW0Ludc1620YzvbV2kVvOhx/KVM+UZtvjIg1Uwd1 agPS9aee53xdzT+Z2JKn3m9rnzeVdFMz4yI7hNWlLJPb8kJY5V7jdJ10RZD8RCNQvJxv vHF05wRg4/2U7ID6sr2YL4VtgY4gD+Rr+mxvvT01D55PNfpD88lpY6xDygzhrse3A3Uh 1qCA== X-Gm-Message-State: AOPr4FXFgEbDUCGAWrpRmN0oLpkADPM3BSLE1G3itjPSYhCKQdJnAZNlc8s4Yv1fs06FyQ== X-Received: by 10.98.72.29 with SMTP id v29mr25277937pfa.71.1460683795397; Thu, 14 Apr 2016 18:29:55 -0700 (PDT) Received: from jade.localdomain (c-73-241-147-137.hsd1.ca.comcast.net. [73.241.147.137]) by smtp.gmail.com with ESMTPSA id 132sm10740538pfw.35.2016.04.14.18.29.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Apr 2016 18:29:54 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [RFC 8/8] drm/fence: add out-fences support Date: Thu, 14 Apr 2016 18:29:41 -0700 Message-Id: <1460683781-22535-9-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460683781-22535-1-git-send-email-gustavo@padovan.org> References: <1460683781-22535-1-git-send-email-gustavo@padovan.org> Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , linux-kernel@vger.kernel.org, Riley Andrews , laurent.pinchart@ideasonboard.com, Gustavo Padovan , John Harrison , m.chehab@samsung.com 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-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan Support DRM out-fences creating a sync_file with a fence for each crtc update with the DRM_MODE_ATOMIC_OUT_FENCE flag. We then send an struct drm_out_fences array with the out-fences fds back in the drm_atomic_ioctl() as an out arg in the out_fences_ptr field. struct drm_out_fences { __u32 crtc_id; __u32 fd; }; Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/drm_atomic.c | 109 +++++++++++++++++++++++++++++++++++- drivers/gpu/drm/drm_atomic_helper.c | 1 + include/drm/drm_crtc.h | 3 + include/uapi/drm/drm_mode.h | 7 +++ 4 files changed, 119 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 0b95526..af6e051 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1560,6 +1560,103 @@ void drm_atomic_clean_old_fb(struct drm_device *dev, } EXPORT_SYMBOL(drm_atomic_clean_old_fb); +static int drm_atomic_get_out_fences(struct drm_device *dev, + struct drm_atomic_state *state, + uint32_t __user *out_fences_ptr, + uint64_t count_out_fences, + uint64_t user_data) +{ + struct drm_crtc *crtc; + struct drm_crtc_state *crtc_state; + struct drm_out_fences *out_fences; + struct sync_file **sync_file; + int num_fences = 0; + int i, ret; + + out_fences = kcalloc(count_out_fences, sizeof(*out_fences), + GFP_KERNEL); + if (!out_fences) + return -ENOMEM; + + sync_file = kcalloc(count_out_fences, sizeof(*sync_file), + GFP_KERNEL); + if (!sync_file) { + kfree(out_fences); + return -ENOMEM; + } + + for_each_crtc_in_state(state, crtc, crtc_state, i) { + struct drm_pending_vblank_event *e; + struct fence *fence; + char name[32]; + int fd; + + fence = sync_timeline_create_fence(crtc->timeline, + crtc->fence_seqno); + if (!fence) { + ret = -ENOMEM; + goto out; + } + + snprintf(name, sizeof(name), "crtc-%d_%lu", + drm_crtc_index(crtc), crtc->fence_seqno++); + + sync_file[i] = sync_file_create(name, fence); + if(!sync_file[i]) { + ret = -ENOMEM; + goto out; + } + + fd = get_unused_fd_flags(O_CLOEXEC); + if (fd < 0) { + ret = fd; + goto out; + } + + sync_file_install(sync_file[i], fd); + + if (crtc_state->event) { + crtc_state->event->base.fence = fence; + } else { + e = create_vblank_event(dev, NULL, fence, user_data); + if (!e) { + put_unused_fd(fd); + ret = -ENOMEM; + goto out; + } + + crtc_state->event = e; + } + if (num_fences > count_out_fences) { + put_unused_fd(fd); + ret = -EINVAL; + goto out; + } + + fence_get(fence); + + out_fences[num_fences].crtc_id = crtc->base.id; + out_fences[num_fences].fd = fd; + num_fences++; + } + + if (copy_to_user(out_fences_ptr, out_fences, + num_fences * sizeof(*out_fences))) { + ret = -EFAULT; + goto out; + } + + return 0; + +out: + for (i = 0 ; i < count_out_fences ; i++) { + if (sync_file[i]) + sync_file_put(sync_file[i]); + } + + return ret; +} + int drm_mode_atomic_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { @@ -1568,6 +1665,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, uint32_t __user *count_props_ptr = (uint32_t __user *)(unsigned long)(arg->count_props_ptr); uint32_t __user *props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr); uint64_t __user *prop_values_ptr = (uint64_t __user *)(unsigned long)(arg->prop_values_ptr); + uint32_t __user *out_fences_ptr = (uint32_t __user *)(unsigned long)(arg->out_fences_ptr); unsigned int copied_objs, copied_props; struct drm_atomic_state *state; struct drm_modeset_acquire_ctx ctx; @@ -1601,7 +1699,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, /* can't test and expect an event at the same time. */ if ((arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) && - (arg->flags & DRM_MODE_PAGE_FLIP_EVENT)) + (arg->flags & (DRM_MODE_PAGE_FLIP_EVENT + | DRM_MODE_ATOMIC_OUT_FENCE))) return -EINVAL; drm_modeset_acquire_init(&ctx, 0); @@ -1693,6 +1792,14 @@ retry: } } + if (arg->flags & DRM_MODE_ATOMIC_OUT_FENCE) { + ret = drm_atomic_get_out_fences(dev, state, out_fences_ptr, + arg->count_out_fences, + arg->user_data); + if (ret < 0) + goto out; + } + if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) { /* * Unlike commit, check_only does not clean up state. diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 6ed8339..15ba3a8 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -31,6 +31,7 @@ #include #include #include +#include /** * DOC: overview diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 7934178..53e4e71 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -717,6 +717,7 @@ struct drm_crtc_funcs { * @properties: property tracking for this CRTC * @state: current atomic state for this CRTC * @timeline: sync timeline for fence sigalling + * @fence_seqno: seqno variable to create fences * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for * legacy IOCTLs * @@ -773,7 +774,9 @@ struct drm_crtc { struct drm_crtc_state *state; + /* for out-fences */ struct sync_timeline *timeline; + unsigned long fence_seqno; /* * For legacy crtc IOCTLs so that atomic drivers can get at the locking diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index 39905cc..4cdcd22 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -592,6 +592,11 @@ struct drm_mode_destroy_dumb { DRM_MODE_ATOMIC_ALLOW_MODESET |\ DRM_MODE_ATOMIC_OUT_FENCE) +struct drm_out_fences { + __u32 crtc_id; + __u32 fd; +}; + struct drm_mode_atomic { __u32 flags; __u32 count_objs; @@ -601,6 +606,8 @@ struct drm_mode_atomic { __u64 prop_values_ptr; __u64 reserved; __u64 user_data; + __u64 count_out_fences; + __u64 out_fences_ptr; }; /**