[RFC v1 2/6] drm/atomic: Add support for release_fence and its associated property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <vivek.kasireddy@xxxxxxxxx>
---
 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.
-- 
2.30.2




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux