+
+ if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK)
+ ret = drm_atomic_nonblocking_commit(state);
+ else
+ ret = drm_atomic_commit(state);
}
if (!ret)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index bba8672..88da299 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -3234,8 +3234,9 @@ __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
if (state->crtc)
drm_connector_reference(connector);
- /* Don't copy over framebuffers, they are used only once */
+ /* Don't copy over framebuffers or fences, they are used only once */
state->fb = NULL;
+ state->out_fence = NULL;
}
EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
@@ -3365,6 +3366,8 @@ __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
drm_connector_unreference(state->connector);
if (state->fb)
drm_framebuffer_unreference(state->fb);
+
+ fence_put(state->out_fence);
}
EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
diff --git a/drivers/gpu/drm/drm_writeback.c b/drivers/gpu/drm/drm_writeback.c
index 5a6e0ad..4a6ef30 100644
--- a/drivers/gpu/drm/drm_writeback.c
+++ b/drivers/gpu/drm/drm_writeback.c
@@ -11,6 +11,7 @@
#include <drm/drm_crtc.h>
#include <drm/drm_property.h>
#include <drm/drmP.h>
+#include <linux/fence.h>
/**
* DOC: overview
@@ -32,6 +33,16 @@
* explicitly cleared in order to make a subsequent commit which doesn't use
* writeback.
*
+ * Unlike with planes, when a writeback framebuffer is removed by userspace DRM
+ * makes no attempt to remove it from active use by the connector. This is
+ * because no method is provided to abort a writeback operation, and in any
+ * case making a new commit whilst a writeback is ongoing is undefined (see
+ * OUT_FENCE_PTR below). As soon as the current writeback is finished, the
+ * framebuffer will automatically no longer be in active use. As it will also
+ * have already been removed from the framebuffer list, there will be no way for
+ * any userspace application to retrieve a reference to it in the intervening
+ * period.
+ *
* Writeback connectors have several additional properties, which userspace
* can use to query and control them:
*
@@ -52,8 +63,48 @@
* "PIXEL_FORMATS_SIZE":
* Immutable unsigned range property storing the number of entries in the
* PIXEL_FORMATS array.
+ *
+ * "OUT_FENCE_PTR":
+ * Userspace can provide the address of a 64-bit integer in this property,
+ * which will be filled with a sync_file file descriptor by the kernel.
+ * The sync_file will signal when the associated writeback has finished.
+ * Userspace should wait for this fence to signal before making another
+ * commit affecting any of the same CRTCs, Planes or Connectors.
+ * **Failure to do so will result in undefined behaviour.**
+ * For this reason it is strongly recommended that all userspace
+ * applications making use of writeback connectors *always* retrieve an
+ * out-fence for the commit and use it appropriately.
+ * From userspace, this property will always read as zero.
*/
+#define fence_to_connector(x) container_of(x->lock, struct drm_connector, fence_lock)
+
+static const char *drm_writeback_fence_get_driver_name(struct fence *fence)
+{
+ struct drm_connector *connector = fence_to_connector(fence);
+
+ return connector->dev->driver->name;
+}
+
+static const char *drm_writeback_fence_get_timeline_name(struct fence *fence)
+{
+ struct drm_connector *connector = fence_to_connector(fence);
+
+ return connector->timeline_name;
+}
+
+static bool drm_writeback_fence_enable_signaling(struct fence *fence)
+{
+ return true;
+}
+
+static const struct fence_ops drm_writeback_fence_ops = {
+ .get_driver_name = drm_writeback_fence_get_driver_name,
+ .get_timeline_name = drm_writeback_fence_get_timeline_name,
+ .enable_signaling = drm_writeback_fence_enable_signaling,
+ .wait = fence_default_wait,
+};
+
/**
* create_writeback_properties - Create writeback connector-specific properties
* @dev: DRM device
@@ -136,6 +187,14 @@ int drm_writeback_connector_init(struct drm_device *dev,
if (ret)
goto fail;
+ connector->fence_context = fence_context_alloc(1);
+ spin_lock_init(&connector->fence_lock);
+ snprintf(connector->timeline_name, sizeof(connector->timeline_name),
+ "CONNECTOR:%d", connector->base.id);
+
+ drm_object_attach_property(&connector->base,
+ config->prop_out_fence_ptr, 0);
+
drm_object_attach_property(&connector->base,
config->writeback_fb_id_property, 0);
@@ -155,3 +214,24 @@ fail:
return ret;
}
EXPORT_SYMBOL(drm_writeback_connector_init);
+
+struct fence *drm_writeback_get_out_fence(struct drm_connector *connector,
+ struct drm_connector_state *conn_state)
+{
+ struct fence *fence;
+
+ if (WARN_ON(connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK))
+ return NULL;
+
+ fence = kzalloc(sizeof(*fence), GFP_KERNEL);
+ if (!fence)
+ return NULL;
+
+ fence_init(fence, &drm_writeback_fence_ops, &connector->fence_lock,
+ connector->fence_context, ++connector->fence_seqno);
+
+ conn_state->out_fence = fence_get(fence);
+
+ return fence;
+}
+EXPORT_SYMBOL(drm_writeback_get_out_fence);
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index a5e3778..7d40537 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -199,6 +199,7 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
* @best_encoder: can be used by helpers and drivers to select the encoder
* @state: backpointer to global drm_atomic_state
* @fb: Writeback framebuffer, for DRM_MODE_CONNECTOR_WRITEBACK
+ * @out_fence: Fence which will clear when the framebuffer write has finished
*/
struct drm_connector_state {
struct drm_connector *connector;
@@ -216,6 +217,9 @@ struct drm_connector_state {
struct drm_atomic_state *state;
struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_connector() */
+
+ struct fence *out_fence;
+ u64 __user *out_fence_ptr;
};
/**
@@ -546,6 +550,10 @@ struct drm_cmdline_mode {
* @tile_v_loc: vertical location of this tile
* @tile_h_size: horizontal size of this tile.
* @tile_v_size: vertical size of this tile.
+ * @fence_context: context for fence signalling
+ * @fence_lock: fence lock for the fence context
+ * @fence_seqno: seqno variable to create fences
+ * @timeline_name: fence timeline name
*
* Each connector may be connected to one or more CRTCs, or may be clonable by
* another connector if they can share a CRTC. Each connector also has a specific
@@ -694,6 +702,12 @@ struct drm_connector {
uint8_t num_h_tile, num_v_tile;
uint8_t tile_h_loc, tile_v_loc;
uint16_t tile_h_size, tile_v_size;
+
+ /* fence timelines info for DRM out-fences */
+ unsigned int fence_context;
+ spinlock_t fence_lock;
+ unsigned long fence_seqno;
+ char timeline_name[32];
};
#define obj_to_connector(x) container_of(x, struct drm_connector, base)
diff --git a/include/drm/drm_writeback.h b/include/drm/drm_writeback.h
index afdc2742..01f33bc 100644
--- a/include/drm/drm_writeback.h
+++ b/include/drm/drm_writeback.h
@@ -16,4 +16,6 @@ int drm_writeback_connector_init(struct drm_device *dev,
const struct drm_connector_funcs *funcs,
u32 *formats, int n_formats);
+struct fence *drm_writeback_get_out_fence(struct drm_connector *connector,
+ struct drm_connector_state *conn_state);
#endif
--
1.7.9.5
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel