From patchwork Mon Sep 13 23:35:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kasireddy, Vivek" X-Patchwork-Id: 12491027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFEE9C433EF for ; Mon, 13 Sep 2021 23:48:58 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A72F60EC0 for ; Mon, 13 Sep 2021 23:48:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8A72F60EC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 271846E2DF; Mon, 13 Sep 2021 23:48:45 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id E25686E2C8 for ; Mon, 13 Sep 2021 23:48:39 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10106"; a="285516271" X-IronPort-AV: E=Sophos;i="5.85,291,1624345200"; d="scan'208";a="285516271" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 16:48:39 -0700 X-IronPort-AV: E=Sophos;i="5.85,291,1624345200"; d="scan'208";a="543534424" Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2021 16:48:38 -0700 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org Cc: Vivek Kasireddy Subject: [RFC v1 2/6] drm/atomic: Add support for release_fence and its associated property Date: Mon, 13 Sep 2021 16:35:25 -0700 Message-Id: <20210913233529.3194401-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210913233529.3194401-1-vivek.kasireddy@intel.com> References: <20210913233529.3194401-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Release_fence is very similar if not the same as out_fence; it is an additional signalling mechanism for a page flip completion. Signed-off-by: Vivek Kasireddy --- drivers/gpu/drm/drm_atomic_uapi.c | 43 +++++++++++++++++++++++++++++-- drivers/gpu/drm/drm_crtc.c | 2 ++ drivers/gpu/drm/drm_mode_config.c | 6 +++++ include/drm/drm_atomic.h | 1 + include/drm/drm_file.h | 9 +++++++ include/drm/drm_mode_config.h | 7 +++++ 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 6436677fa2f8..5d0bf3e525b3 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -367,6 +367,23 @@ static s32 __user *get_out_fence_for_crtc(struct drm_atomic_state *state, return fence_ptr; } +static void set_release_fence_for_crtc(struct drm_atomic_state *state, + struct drm_crtc *crtc, s32 __user *fence_ptr) +{ + state->crtcs[drm_crtc_index(crtc)].release_fence_ptr = fence_ptr; +} + +static s32 __user *get_release_fence_for_crtc(struct drm_atomic_state *state, + struct drm_crtc *crtc) +{ + s32 __user *fence_ptr; + + fence_ptr = state->crtcs[drm_crtc_index(crtc)].release_fence_ptr; + state->crtcs[drm_crtc_index(crtc)].release_fence_ptr = NULL; + + return fence_ptr; +} + static int set_out_fence_for_connector(struct drm_atomic_state *state, struct drm_connector *connector, s32 __user *fence_ptr) @@ -482,6 +499,16 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc, return -EFAULT; set_out_fence_for_crtc(state->state, crtc, fence_ptr); + } else if (property == config->prop_release_fence_ptr) { + s32 __user *fence_ptr = u64_to_user_ptr(val); + + if (!fence_ptr) + return 0; + + if (put_user(-1, fence_ptr)) + return -EFAULT; + + set_release_fence_for_crtc(state->state, crtc, fence_ptr); } else if (property == crtc->scaling_filter_property) { state->scaling_filter = val; } else if (crtc->funcs->atomic_set_property) { @@ -519,6 +546,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, *val = (state->gamma_lut) ? state->gamma_lut->base.id : 0; else if (property == config->prop_out_fence_ptr) *val = 0; + else if (property == config->prop_release_fence_ptr) + *val = 0; else if (property == crtc->scaling_filter_property) *val = state->scaling_filter; else if (crtc->funcs->atomic_get_property) @@ -1185,7 +1214,7 @@ static int prepare_signaling(struct drm_device *dev, for_each_new_crtc_in_state(state, crtc, crtc_state, i) { struct dma_fence *fence; - s32 __user *fence_ptr; + s32 __user *fence_ptr, *rel_fence_ptr; fence_ptr = get_out_fence_for_crtc(crtc_state->state, crtc); @@ -1220,9 +1249,19 @@ static int prepare_signaling(struct drm_device *dev, if (IS_ERR(fence)) return PTR_ERR(fence); + crtc_state->event->base.fence = fence; + } + rel_fence_ptr = get_release_fence_for_crtc(crtc_state->state, + crtc); + if (rel_fence_ptr) { + fence = crtc_create_out_fence(crtc, fence_state, + rel_fence_ptr, + num_fences); + if (IS_ERR(fence)) + return PTR_ERR(fence); - crtc_state->event->base.fence = fence; + crtc_state->event->base.release_fence = fence; } c++; diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 26a77a735905..e682ac04f873 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -312,6 +312,8 @@ static int __drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc * drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); drm_object_attach_property(&crtc->base, config->prop_out_fence_ptr, 0); + drm_object_attach_property(&crtc->base, + config->prop_release_fence_ptr, 0); drm_object_attach_property(&crtc->base, config->prop_vrr_enabled, 0); } diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index 37b4b9f0e468..fc1f5a8d2991 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -297,6 +297,12 @@ static int drm_mode_create_standard_properties(struct drm_device *dev) return -ENOMEM; dev->mode_config.prop_out_fence_ptr = prop; + prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, + "RELEASE_FENCE_PTR", 0, U64_MAX); + if (!prop) + return -ENOMEM; + dev->mode_config.prop_release_fence_ptr = prop; + prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, "CRTC_ID", DRM_MODE_OBJECT_CRTC); if (!prop) diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 1701c2128a5c..00f5fad87757 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -177,6 +177,7 @@ struct __drm_crtcs_state { struct drm_crtc_commit *commit; s32 __user *out_fence_ptr; + s32 __user *release_fence_ptr; u64 last_vblank_count; }; diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index a3acb7ac3550..ba79e1765721 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -124,6 +124,15 @@ struct drm_pending_event { */ struct dma_fence *fence; + /** + * @release_fence: + * + * Optional DMA fence that will be signalled by the drm driver to + * indicate that all references on FBs associated with a page flip + * can be dropped. + */ + struct dma_fence *release_fence; + /** * @file_priv: * diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index 48b7de80daf5..12b964540069 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -642,6 +642,13 @@ struct drm_mode_config { * value of type s32, and then cast that pointer to u64. */ struct drm_property *prop_out_fence_ptr; + /** + * @prop_release_fence_ptr: Sync File fd pointer that is used as an + * additional flip completion signalling mechanism. Userspace should + * provide a pointer to a value of type s32, and then cast that pointer + * to u64. + */ + struct drm_property *prop_release_fence_ptr; /** * @prop_crtc_id: Default atomic plane property to specify the * &drm_crtc.