drm: Introduce writeback connectors
Subsystems (3)
v7 cover drm: Introduce writeback connectors
Hi,
This is v7 of the writeback connector series. This is just a refresh of the v6 series in order to get it ready for merging into the kernel, now that the userspace implementation has been reviewed and ACKed by Sean Paul here [1].
For anyone that wants a refresh on what changed in v6, the series can be found here [2]. The only change in v7 is that the userspace capabilities patch does not depend on the cleanup patch that got NACKed.
Best regards,
Liviu
[1] https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/merge_requests/3
[2] https://lists.freedesktop.org/archives/dri-devel/2018-February/167703.html
Brian Starkey (2):
drm: Add writeback connector type
drm: writeback: Add out-fences for writeback connectors
Liviu Dudau (1):
drm: writeback: Add client capability for exposing writeback
connectors
Documentation/gpu/drm-kms.rst | 9 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_atomic.c | 227 +++++++++++++- drivers/gpu/drm/drm_atomic_helper.c | 30 ++ drivers/gpu/drm/drm_connector.c | 4 +- drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 5 + drivers/gpu/drm/drm_writeback.c | 360 +++++++++++++++++++++++ include/drm/drm_atomic.h | 11 + include/drm/drm_connector.h | 13 + include/drm/drm_file.h | 7 + include/drm/drm_mode_config.h | 23 ++ include/drm/drm_modeset_helper_vtables.h | 11 + include/drm/drm_writeback.h | 129 ++++++++ include/uapi/drm/drm.h | 9 + include/uapi/drm/drm_mode.h | 1 + 16 files changed, 837 insertions(+), 11 deletions(-) create mode 100644 drivers/gpu/drm/drm_writeback.c create mode 100644 include/drm/drm_writeback.h
Signature · 6 lines
2.17.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v7 1/3 drm: Add writeback connector type
From: Brian Starkey <[email protected]>
Writeback connectors represent writeback engines which can write the CRTC output to a memory framebuffer. Add a writeback connector type and related support functions.
Drivers should initialize a writeback connector with drm_writeback_connector_init() which takes care of setting up all the writeback-specific details on top of the normal functionality of drm_connector_init().
Writeback connectors have a WRITEBACK_FB_ID property, used to set the output framebuffer, and a WRITEBACK_PIXEL_FORMATS blob used to expose the supported writeback formats to userspace.
When a framebuffer is attached to a writeback connector with the WRITEBACK_FB_ID property, it is used only once (for the commit in which it was included), and userspace can never read back the value of WRITEBACK_FB_ID. WRITEBACK_FB_ID can only be set if the connector is attached to a CRTC.
Changes since v1:
- Added drm_writeback.c + documentation
- Added helper to initialize writeback connector in one go
- Added core checks
- Squashed into a single commit
- Dropped the client cap
- Writeback framebuffers are no longer persistent
Changes since v2:
Daniel Vetter:
- Subclass drm_connector to drm_writeback_connector
- Relax check to allow CRTC to be set without an FB
- Add some writeback_ prefixes
- Drop PIXEL_FORMATS_SIZE property, as it was unnecessary Gustavo Padovan:
- Add drm_writeback_job to handle writeback signalling centrally
Changes since v3:
- Rebased
- Rename PIXEL_FORMATS -> WRITEBACK_PIXEL_FORMATS
Chances since v4:
- Embed a drm_encoder inside the drm_writeback_connector to reduce the amount of boilerplate code required from the drivers that are using it.
Changes since v5:
- Added Rob Clark's atomic_commit() vfunc to connector helper funcs, so that writeback jobs are committed from atomic helpers
- Updated create_writeback_properties() signature to return an error code rather than a boolean false for failure.
- Free writeback job with the connector state rather than when doing the cleanup_work()
--- Documentation/gpu/drm-kms.rst | 9 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_atomic.c | 128 ++++++++++++ drivers/gpu/drm/drm_atomic_helper.c | 30 +++ drivers/gpu/drm/drm_connector.c | 4 +- drivers/gpu/drm/drm_writeback.c | 256 +++++++++++++++++++++++ include/drm/drm_atomic.h | 3 + include/drm/drm_connector.h | 13 ++ include/drm/drm_mode_config.h | 15 ++ include/drm/drm_modeset_helper_vtables.h | 11 + include/drm/drm_writeback.h | 88 ++++++++ include/uapi/drm/drm_mode.h | 1 + 12 files changed, 558 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/drm_writeback.c create mode 100644 include/drm/drm_writeback.h
Documentation/gpu/drm-kms.rst +9 -0
@@ -373,6 +373,15 @@ Connector Functions Reference .. kernel-doc:: drivers/gpu/drm/drm_connector.c :export: +Writeback Connectors +-------------------- + +.. kernel-doc:: drivers/gpu/drm/drm_writeback.c + :doc: overview + +.. kernel-doc:: drivers/gpu/drm/drm_writeback.c + :export: + Encoder Abstraction ===================
drivers/gpu/drm/Makefile +1 -1
@@ -18,7 +18,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_encoder.o drm_mode_object.o drm_property.o \ drm_plane.o drm_color_mgmt.o drm_print.o \ drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \ - drm_syncobj.o drm_lease.o + drm_syncobj.o drm_lease.o drm_writeback.o drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o drm-$(CONFIG_DRM_VM) += drm_vm.o
drivers/gpu/drm/drm_atomic.c +128 -0
170 lines not on this page · raw message
drivers/gpu/drm/drm_atomic_helper.c +30 -0
@@ -30,6 +30,7 @@#include <drm/drm_plane_helper.h> #include <drm/drm_crtc_helper.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_writeback.h> #include <linux/dma-fence.h> #include "drm_crtc_helper_internal.h"
@@ -1161,6 +1162,25 @@ void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev, }EXPORT_SYMBOL (drm_atomic_helper_commit_modeset_disables); +static void drm_atomic_helper_commit_writebacks (struct drm_device *dev, +struct drm_atomic_state *old_state) +{ +struct drm_connector *connector; +struct drm_connector_state *new_conn_state; +int i; + +for_each_new_connector_in_state (old_state, connector, new_conn_state, i) { +const struct drm_connector_helper_funcs *funcs; + + funcs = connector->helper_private; + +if (new_conn_state->writeback_job && new_conn_state->writeback_job->fb) { +WARN_ON (connector->connector_type !=DRM_MODE_CONNECTOR_WRITEBACK ); + funcs->atomic_commit (connector, new_conn_state->writeback_job); + } + } +} +/** * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs * @dev: DRM device
@@ -1240,6 +1260,8 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,drm_bridge_enable (encoder->bridge); } + +drm_atomic_helper_commit_writebacks (dev, old_state); }EXPORT_SYMBOL (drm_atomic_helper_commit_modeset_enables);
@@ -3629,6 +3651,9 @@ __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,if (state->crtc)drm_connector_get (connector); state->commit =NULL ; + +/* Don't copy over a writeback job, they are used only once */ + state->writeback_job =NULL ; }EXPORT_SYMBOL (__drm_atomic_helper_connector_duplicate_state);
@@ -3758,6 +3783,11 @@ __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)if (state->commit)drm_crtc_commit_put (state->commit); + +if (state->writeback_job) { +drm_writeback_cleanup_job (state->writeback_job); +kfree (state->writeback_job); + } }EXPORT_SYMBOL (__drm_atomic_helper_connector_destroy_state);
drivers/gpu/drm/drm_connector.c +3 -1
@@ -87,6 +87,7 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, { DRM_MODE_CONNECTOR_DSI, "DSI" }, { DRM_MODE_CONNECTOR_DPI, "DPI" }, + { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, };void drm_connector_ida_init (void )
@@ -249,7 +250,8 @@ int drm_connector_init(struct drm_device *dev, config->num_connector++;spin_unlock_irq (&config->connector_list_lock); -if (connector_type !=DRM_MODE_CONNECTOR_VIRTUAL ) +if (connector_type !=DRM_MODE_CONNECTOR_VIRTUAL && + connector_type !=DRM_MODE_CONNECTOR_WRITEBACK )drm_object_attach_property (&connector->base, config->edid_property,0 );
drivers/gpu/drm/drm_writeback.c new file +256 -0
256 lines not on this page · raw message
include/drm/drm_atomic.h +3 -0
@@ -594,6 +594,9 @@ void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,int __must_check drm_atomic_set_crtc_for_connector (struct drm_connector_state *conn_state,struct drm_crtc *crtc); +int drm_atomic_set_writeback_fb_for_connector ( +struct drm_connector_state *conn_state, +struct drm_framebuffer *fb);int __must_check drm_atomic_add_affected_connectors (struct drm_atomic_state *state,struct drm_crtc *crtc);
include/drm/drm_connector.h +13 -0
@@ -429,6 +429,19 @@ struct drm_connector_state {* protection. This is most commonly used for HDCP. */ unsigned int content_protection; + +/** +* @writeback_job: Writeback job for writeback connectors +* +* Holds the framebuffer for a writeback connector. As the writeback +* completion may be asynchronous to the normal commit cycle, the +* writeback job lifetime is managed separately from the normal atomic +* state by this object. +* +* See also: drm_writeback_queue_job() and +* drm_writeback_signal_completion() +*/ +struct drm_writeback_job *writeback_job; };/**
include/drm/drm_mode_config.h +15 -0
@@ -779,6 +779,21 @@ struct drm_mode_config {*/ struct drm_property *panel_orientation_property; +/** +* @writeback_fb_id_property: Property for writeback connectors, storing +* the ID of the output framebuffer. +* See also: drm_writeback_connector_init() +*/ +struct drm_property *writeback_fb_id_property; + +/** +* @writeback_pixel_formats_property: Property for writeback connectors, +* storing an array of the supported pixel formats for the writeback +* engine (read-only). +* See also: drm_writeback_connector_init() +*/ +struct drm_property *writeback_pixel_formats_property; +/* dumb ioctl parameters */ uint32_t preferred_depth, prefer_shadow;
include/drm/drm_modeset_helper_vtables.h +11 -0
@@ -974,6 +974,17 @@ struct drm_connector_helper_funcs {*/ int (*atomic_check)(struct drm_connector *connector,struct drm_connector_state *state); + +/** +* @atomic_commit: +* +* This hook is to be used by drivers implementing writeback connectors +* that need a point when to commit the writeback job to the hardware. +* +* This callback is used by the atomic modeset helpers. +*/ +void (*atomic_commit)(struct drm_connector *connector, +struct drm_writeback_job *writeback_job); };/**
include/drm/drm_writeback.h new file +88 -0
88 lines not on this page · raw message
include/uapi/drm/drm_mode.h +1 -0
@@ -338,6 +338,7 @@ enum drm_mode_subconnector {#define DRM_MODE_CONNECTOR_VIRTUAL 15#define DRM_MODE_CONNECTOR_DSI 16#define DRM_MODE_CONNECTOR_DPI 17 +#define DRM_MODE_CONNECTOR_WRITEBACK 18struct drm_mode_get_connector {
Signature · 6 lines
2.17.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v7 2/3 drm: writeback: Add out-fences for writeback connectors
In reply to Liviu DudauFrom: Brian Starkey <[email protected]>
Add the WRITEBACK_OUT_FENCE_PTR property to writeback connectors, to enable userspace to get a fence which will signal once the writeback is complete. It is not allowed to request an out-fence without a framebuffer attached to the connector.
A timeline is added to drm_writeback_connector for use by the writeback out-fences.
In the case of a commit failure or DRM_MODE_ATOMIC_TEST_ONLY, the fence is set to -1.
Changes from v2:
- Rebase onto Gustavo Padovan's v9 explicit sync series
- Change out_fence_ptr type to s32 __user *
- Set *out_fence_ptr to -1 in drm_atomic_connector_set_property
- Store fence in drm_writeback_job
Gustavo Padovan:
- Move out_fence_ptr out of connector_state
- Signal fence from drm_writeback_signal_completion instead of in driver directly
Changes from v3:
- Rebase onto commit 7e9081c5aac7 ("drm/fence: fix memory overwrite when setting out_fence fd") (change out_fence_ptr to s32 __user *, for real this time.)
- Update documentation around WRITEBACK_OUT_FENCE_PTR
--- drivers/gpu/drm/drm_atomic.c | 99 ++++++++++++++++++++++++++--- drivers/gpu/drm/drm_writeback.c | 108 +++++++++++++++++++++++++++++++- include/drm/drm_atomic.h | 8 +++ include/drm/drm_connector.h | 8 +-- include/drm/drm_mode_config.h | 8 +++ include/drm/drm_writeback.h | 43 ++++++++++++- 6 files changed, 258 insertions(+), 16 deletions(-)
drivers/gpu/drm/drm_atomic.c +90 -9
@@ -318,6 +318,35 @@ static s32 __user *get_out_fence_for_crtc(struct drm_atomic_state *state,return fence_ptr; } +static int set_out_fence_for_connector (struct drm_atomic_state *state, +struct drm_connector *connector, +s32 __user *fence_ptr) +{ +unsigned int index =drm_connector_index (connector); + +if (!fence_ptr) +return 0 ; + +if (put_user (-1 , fence_ptr)) +return -EFAULT ; + + state->connectors[index].out_fence_ptr = fence_ptr; + +return 0 ; +} + +static s32 __user *get_out_fence_for_connector (struct drm_atomic_state *state, +struct drm_connector *connector) +{ +unsigned int index =drm_connector_index (connector); +s32 __user *fence_ptr; + + fence_ptr = state->connectors[index].out_fence_ptr; + state->connectors[index].out_fence_ptr =NULL ; + +return fence_ptr; +} +/** * drm_atomic_set_mode_for_crtc - set mode for CRTC * @state: the CRTC whose incoming state to update
@@ -705,6 +734,12 @@ static int drm_atomic_connector_check(struct drm_connector *connector,return -EINVAL ; } +if (writeback_job->out_fence && !writeback_job->fb) { +DRM_DEBUG_ATOMIC ("[CONNECTOR:%d:%s] requesting out-fence without framebuffer\n" , + connector->base.id, connector->name); +return -EINVAL ; + } +return 0 ; }
@@ -1320,6 +1355,11 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,if (fb)drm_framebuffer_unreference (fb);return ret; + }else if (property == config->writeback_out_fence_ptr_property) { +s32 __user *fence_ptr =u64_to_user_ptr (val); + +return set_out_fence_for_connector (state->state, connector, + fence_ptr); }else if (connector->funcs->atomic_set_property) {return connector->funcs->atomic_set_property (connector, state, property, val);
@@ -1404,6 +1444,8 @@ drm_atomic_connector_get_property(struct drm_connector *connector, }else if (property == config->writeback_fb_id_property) {/* Writeback framebuffer is one-shot, write and forget */ *val =0 ; + }else if (property == config->writeback_out_fence_ptr_property) { + *val =0 ; }else if (connector->funcs->atomic_get_property) {return connector->funcs->atomic_get_property (connector, state, property, val);
@@ -2263,7 +2305,7 @@ static int setup_out_fence(struct drm_out_fence_state *fence_state,return 0 ; } -static int prepare_crtc_signaling(struct drm_device *dev, +static int prepare_signaling(struct drm_device *dev, struct drm_atomic_state *state, struct drm_mode_atomic *arg, struct drm_file *file_priv,
@@ -2272,6 +2314,8 @@ static int prepare_crtc_signaling(struct drm_device *dev, {struct drm_crtc *crtc;struct drm_crtc_state *crtc_state; +struct drm_connector *conn; +struct drm_connector_state *conn_state;int i, c =0 , ret;if (arg->flags &DRM_MODE_ATOMIC_TEST_ONLY )
@@ -2337,6 +2381,43 @@ static int prepare_crtc_signaling(struct drm_device *dev, c++; } +for_each_new_connector_in_state (state, conn, conn_state, i) { +struct drm_writeback_job *job; +struct drm_out_fence_state *f; +struct dma_fence *fence; +s32 __user *fence_ptr; + + fence_ptr =get_out_fence_for_connector (state, conn); +if (!fence_ptr) +continue ; + + job =drm_atomic_get_writeback_job (conn_state); +if (!job) +return -ENOMEM ; + + f =krealloc (*fence_state,sizeof (**fence_state) * + (*num_fences +1 ),GFP_KERNEL ); +if (!f) +return -ENOMEM ; + +memset (&f[*num_fences],0 ,sizeof (*f)); + + f[*num_fences].out_fence_ptr = fence_ptr; + *fence_state = f; + + fence =drm_writeback_get_out_fence ((struct drm_writeback_connector *)conn); +if (!fence) +return -ENOMEM ; + + ret =setup_out_fence (&f[(*num_fences)++], fence); +if (ret) { +dma_fence_put (fence); +return ret; + } + + job->out_fence = fence; + } +/* * Having this flag means user mode pends on event which will never * reach due to lack of at least one CRTC for signaling
@@ -2347,11 +2428,11 @@ static int prepare_crtc_signaling(struct drm_device *dev,return 0 ; } -static void complete_crtc_signaling (struct drm_device *dev, -struct drm_atomic_state *state, -struct drm_out_fence_state *fence_state, -unsigned int num_fences, -bool install_fds) +static void complete_signaling (struct drm_device *dev, +struct drm_atomic_state *state, +struct drm_out_fence_state *fence_state, +unsigned int num_fences, +bool install_fds) {struct drm_crtc *crtc;struct drm_crtc_state *crtc_state;
@@ -2530,8 +2611,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,drm_mode_object_put (obj); } - ret =prepare_crtc_signaling (dev, state, arg, file_priv, &fence_state, - &num_fences); + ret =prepare_signaling (dev, state, arg, file_priv, &fence_state, + &num_fences);if (ret) goto out;
@@ -2549,7 +2630,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, out:drm_atomic_clean_old_fb (dev, plane_mask, ret); -complete_crtc_signaling (dev, state, fence_state, num_fences, !ret); +complete_signaling (dev, state, fence_state, num_fences, !ret);if (ret == -EDEADLK ) {drm_atomic_state_clear (state);
drivers/gpu/drm/drm_writeback.c +106 -2
162 lines not on this page · raw message
include/drm/drm_atomic.h +8 -0
@@ -160,6 +160,14 @@ struct __drm_crtcs_state {struct __drm_connnectors_state {struct drm_connector *ptr;struct drm_connector_state *state, *old_state, *new_state; +/** +* @out_fence_ptr: +* +* User-provided pointer which the kernel uses to return a sync_file +* file descriptor. Used by writeback connectors to signal completion of +* the writeback. +*/ +s32 __user *out_fence_ptr; };struct drm_private_obj ;
include/drm/drm_connector.h +4 -4
@@ -433,10 +433,10 @@ struct drm_connector_state {/** * @writeback_job: Writeback job for writeback connectors * -* Holds the framebuffer for a writeback connector. As the writeback -* completion may be asynchronous to the normal commit cycle, the -* writeback job lifetime is managed separately from the normal atomic -* state by this object. +* Holds the framebuffer and out-fence for a writeback connector. As +* the writeback completion may be asynchronous to the normal commit +* cycle, the writeback job lifetime is managed separately from the +* normal atomic state by this object. * * See also: drm_writeback_queue_job() and * drm_writeback_signal_completion()
include/drm/drm_mode_config.h +8 -0
@@ -793,6 +793,14 @@ struct drm_mode_config {* See also: drm_writeback_connector_init() */ struct drm_property *writeback_pixel_formats_property; +/** +* @writeback_out_fence_ptr_property: Property for writeback connectors, +* fd pointer representing the outgoing fences for a writeback +* connector. Userspace should provide a pointer to a value of type s32, +* and then cast that pointer to u64. +* See also: drm_writeback_connector_init() +*/ +struct drm_property *writeback_out_fence_ptr_property;/* dumb ioctl parameters */ uint32_t preferred_depth, prefer_shadow;
include/drm/drm_writeback.h +42 -1
71 lines not on this page · raw message
Signature · 6 lines
2.17.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v7 3/3 drm: writeback: Add client capability for exposing writeback connectors
In reply to Liviu DudauDue to the fact that writeback connectors behave in a special way in DRM (they always report being disconnected) we might confuse some userspace. Add a client capability for writeback connectors that will filter them out for clients that don't understand the capability.
--- drivers/gpu/drm/drm_ioctl.c | 7 +++++++ drivers/gpu/drm/drm_mode_config.c | 5 +++++ include/drm/drm_file.h | 7 +++++++ include/uapi/drm/drm.h | 9 +++++++++ 4 files changed, 28 insertions(+)
drivers/gpu/drm/drm_ioctl.c +7 -0
@@ -325,6 +325,13 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv) file_priv->atomic = req->value; file_priv->universal_planes = req->value;break ; +case DRM_CLIENT_CAP_WRITEBACK_CONNECTORS : +if (!file_priv->atomic || !drm_core_check_feature (dev,DRIVER_ATOMIC )) +return -EINVAL ; +if (req->value >1 ) +return -EINVAL ; + file_priv->writeback_connectors = req->value; +break ;default :return -EINVAL ; }
drivers/gpu/drm/drm_mode_config.c +5 -0
@@ -145,6 +145,11 @@ int drm_mode_getresources(struct drm_device *dev, void *data, count =0 ; connector_id =u64_to_user_ptr (card_res->connector_id_ptr);drm_for_each_connector_iter (connector, &conn_iter) { +/* only expose writeback connectors if userspace understands them */ +if (!file_priv->writeback_connectors && + (connector->connector_type ==DRM_MODE_CONNECTOR_WRITEBACK )) +continue ; +if (drm_lease_held (file_priv, connector->base.id)) {if (count < card_res->count_connectors &&put_user (connector->base.id, connector_id + count)) {
include/drm/drm_file.h +7 -0
@@ -181,6 +181,13 @@ struct drm_file {/** @atomic: True if client understands atomic properties. */ unsigned atomic:1; +/** +* @writeback_connectors: +* +* True if client understands writeback connectors +*/ + unsigned writeback_connectors:1; +/** * @is_master: *
include/uapi/drm/drm.h +9 -0
@@ -680,6 +680,15 @@ struct drm_get_cap {*/ #define DRM_CLIENT_CAP_ATOMIC 3 +/** +* DRM_CLIENT_CAP_WRITEBACK_CONNECTORS +* +* If set to 1, the DRM core will expose special connectors to be used for +* writing back to memory the scene setup in the commit. Depends on client +* also supporting DRM_CLIENT_CAP_ATOMIC +*/ +#define DRM_CLIENT_CAP_WRITEBACK_CONNECTORS 4 +/** DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */ struct drm_set_client_cap {__u64 capability;
Signature · 6 lines
2.17.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel