* [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state()
@ 2015-09-08 13:00 Thierry Reding
2015-09-08 13:00 ` [PATCH v3 2/2] drm/atomic-helper: Implement subsystem-level suspend/resume Thierry Reding
2015-09-08 13:25 ` [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state() Daniel Vetter
0 siblings, 2 replies; 4+ messages in thread
From: Thierry Reding @ 2015-09-08 13:00 UTC (permalink / raw)
To: dri-devel; +Cc: Daniel Vetter
From: Thierry Reding <treding@nvidia.com>
This function can be used to duplicate an atomic state object. This is
useful for example to implement suspend/resume, where the state before
suspend can be saved and restored upon resume.
v2: move locking to caller, be more explicit about prerequisites
v3: explicitly pass lock acquisition context, improve kerneldoc
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/gpu/drm/drm_atomic_helper.c | 78 +++++++++++++++++++++++++++++++++++++
include/drm/drm_atomic_helper.h | 3 ++
2 files changed, 81 insertions(+)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 634aa617811b..3232f4b838e4 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2349,6 +2349,84 @@ drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
/**
+ * drm_atomic_helper_duplicate_state - duplicate an atomic state object
+ * @dev: DRM device
+ * @ctx: lock acquisition context
+ *
+ * Makes a copy of the current atomic state by looping over all objects and
+ * duplicating their respective states.
+ *
+ * Note that this treats atomic state as persistent between save and restore.
+ * Drivers must make sure that this is possible and won't result in confusion
+ * or erroneous behaviour.
+ *
+ * Note that if callers haven't already acquired all modeset locks this might
+ * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
+ *
+ * Returns:
+ * A pointer to the copy of the atomic state object on success or an
+ * ERR_PTR()-encoded error code on failure.
+ */
+struct drm_atomic_state *
+drm_atomic_helper_duplicate_state(struct drm_device *dev,
+ struct drm_modeset_acquire_ctx *ctx)
+{
+ struct drm_atomic_state *state;
+ struct drm_connector *conn;
+ struct drm_plane *plane;
+ struct drm_crtc *crtc;
+ int err = 0;
+
+ state = drm_atomic_state_alloc(dev);
+ if (!state)
+ return ERR_PTR(-ENOMEM);
+
+ state->acquire_ctx = ctx;
+
+ drm_for_each_crtc(crtc, dev) {
+ struct drm_crtc_state *crtc_state;
+
+ crtc_state = drm_atomic_get_crtc_state(state, crtc);
+ if (IS_ERR(crtc_state)) {
+ err = PTR_ERR(crtc_state);
+ goto free;
+ }
+ }
+
+ drm_for_each_plane(plane, dev) {
+ struct drm_plane_state *plane_state;
+
+ plane_state = drm_atomic_get_plane_state(state, plane);
+ if (IS_ERR(plane_state)) {
+ err = PTR_ERR(plane_state);
+ goto free;
+ }
+ }
+
+ drm_for_each_connector(conn, dev) {
+ struct drm_connector_state *conn_state;
+
+ conn_state = drm_atomic_get_connector_state(state, conn);
+ if (IS_ERR(conn_state)) {
+ err = PTR_ERR(conn_state);
+ goto free;
+ }
+ }
+
+ /* clear the acquire context so that it isn't accidentally reused */
+ state->acquire_ctx = NULL;
+
+free:
+ if (err < 0) {
+ drm_atomic_state_free(state);
+ state = ERR_PTR(err);
+ }
+
+ return state;
+}
+EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
+
+/**
* __drm_atomic_helper_connector_destroy_state - release connector state
* @connector: connector object
* @state: connector state object to release
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index 4ffe9dca07c4..1547eb43c14a 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -118,6 +118,9 @@ __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
struct drm_connector_state *state);
struct drm_connector_state *
drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);
+struct drm_atomic_state *
+drm_atomic_helper_duplicate_state(struct drm_device *dev,
+ struct drm_modeset_acquire_ctx *ctx);
void
__drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
struct drm_connector_state *state);
--
2.5.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] drm/atomic-helper: Implement subsystem-level suspend/resume
2015-09-08 13:00 [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state() Thierry Reding
@ 2015-09-08 13:00 ` Thierry Reding
2015-09-08 13:13 ` Daniel Vetter
2015-09-08 13:25 ` [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state() Daniel Vetter
1 sibling, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2015-09-08 13:00 UTC (permalink / raw)
To: dri-devel; +Cc: Daniel Vetter
From: Thierry Reding <treding@nvidia.com>
Provide subsystem-level suspend and resume helpers that can be used to
implement suspend/resume on atomic mode-setting enabled drivers.
v2: simplify locking, enhance kerneldoc comments
v3: pass lock acquisition context by parameter, improve kerneldoc
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/gpu/drm/drm_atomic_helper.c | 165 +++++++++++++++++++++++++++++++++++-
drivers/gpu/drm/drm_crtc_helper.c | 6 ++
include/drm/drm_atomic_helper.h | 6 ++
3 files changed, 176 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 3232f4b838e4..31823dc8a406 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1742,6 +1742,164 @@ backoff:
EXPORT_SYMBOL(drm_atomic_helper_set_config);
/**
+ * drm_atomic_helper_disable_all - disable all currently active outputs
+ * @dev: DRM device
+ * @ctx: lock acquisition context
+ *
+ * Loops through all connectors, finding those that aren't turned off and then
+ * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
+ * that they are connected to.
+ *
+ * This is used for example in suspend/resume to disable all currently active
+ * functions when suspending.
+ *
+ * Note that if callers haven't already acquired all modeset locks this might
+ * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
+ *
+ * Returns:
+ * 0 on success or a negative error code on failure.
+ *
+ * See also:
+ * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
+ */
+int drm_atomic_helper_disable_all(struct drm_device *dev,
+ struct drm_modeset_acquire_ctx *ctx)
+{
+ struct drm_connector_state *conn_state;
+ struct drm_atomic_state *state;
+ struct drm_connector *conn;
+ unsigned int i;
+ int err;
+
+ state = drm_atomic_state_alloc(dev);
+ if (!state)
+ return -ENOMEM;
+
+ state->acquire_ctx = ctx;
+
+ drm_for_each_connector(conn, dev) {
+ struct drm_crtc *crtc = conn->state->crtc;
+ struct drm_crtc_state *crtc_state;
+
+ if (!crtc || conn->dpms != DRM_MODE_DPMS_ON)
+ continue;
+
+ crtc_state = drm_atomic_get_crtc_state(state, crtc);
+ if (IS_ERR(crtc_state)) {
+ err = PTR_ERR(crtc_state);
+ goto free;
+ }
+
+ err = drm_atomic_add_affected_connectors(state, crtc);
+ if (err < 0)
+ goto free;
+
+ conn->dpms = DRM_MODE_DPMS_OFF;
+ crtc_state->active = false;
+ }
+
+ err = drm_atomic_commit(state);
+ if (err < 0) {
+ /* restore DPMS mode */
+ for_each_connector_in_state(state, conn, conn_state, i)
+ conn->dpms = DRM_MODE_DPMS_ON;
+
+ goto free;
+ }
+
+free:
+ if (err < 0)
+ drm_atomic_state_free(state);
+
+ return err;
+}
+EXPORT_SYMBOL(drm_atomic_helper_disable_all);
+
+/**
+ * drm_atomic_helper_suspend - subsystem-level suspend helper
+ * @dev: DRM device
+ *
+ * Duplicates the current atomic state, disables all active outputs and then
+ * returns a pointer to the original atomic state to the caller. Drivers can
+ * pass this pointer to the drm_atomic_helper_resume() helper upon resume to
+ * restore the output configuration that was active at the time the system
+ * entered suspend.
+ *
+ * Note that it is potentially unsafe to use this. The atomic state object
+ * returned by this function is assumed to be persistent. Drivers must ensure
+ * that this holds true. Before calling this function, drivers must make sure
+ * to suspend fbdev emulation so that nothing can be using the device.
+ *
+ * Returns:
+ * A pointer to a copy of the state before suspend on success or an ERR_PTR()-
+ * encoded error code on failure. Drivers should store the returned atomic
+ * state object and pass it to the drm_atomic_helper_resume() helper upon
+ * resume.
+ *
+ * See also:
+ * drm_atomic_helper_duplicate_state(), drm_atomic_helper_disable_all(),
+ * drm_atomic_helper_resume()
+ */
+struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev)
+{
+ struct drm_modeset_acquire_ctx ctx;
+ struct drm_atomic_state *state;
+ int err;
+
+ drm_modeset_acquire_init(&ctx, 0);
+ drm_modeset_lock_all_ctx(dev, &ctx);
+
+ state = drm_atomic_helper_duplicate_state(dev, &ctx);
+ if (IS_ERR(state))
+ goto unlock;
+
+ err = drm_atomic_helper_disable_all(dev, &ctx);
+ if (err < 0) {
+ drm_atomic_state_free(state);
+ state = ERR_PTR(err);
+ goto unlock;
+ }
+
+unlock:
+ drm_modeset_unlock_all_ctx(dev, &ctx);
+ drm_modeset_acquire_fini(&ctx);
+ return state;
+}
+EXPORT_SYMBOL(drm_atomic_helper_suspend);
+
+/**
+ * drm_atomic_helper_resume - subsystem-level resume helper
+ * @dev: DRM device
+ * @state: atomic state to resume to
+ *
+ * Calls drm_mode_config_reset() to synchronize hardware and software states,
+ * grabs all modeset locks and commits the atomic state object. This can be
+ * used in conjunction with the drm_atomic_helper_suspend() helper to
+ * implement suspend/resume for drivers that support atomic mode-setting.
+ *
+ * Returns:
+ * 0 on success or a negative error code on failure.
+ *
+ * See also:
+ * drm_atomic_helper_suspend()
+ */
+int drm_atomic_helper_resume(struct drm_device *dev,
+ struct drm_atomic_state *state)
+{
+ struct drm_mode_config *config = &dev->mode_config;
+ int err;
+
+ drm_mode_config_reset(dev);
+ drm_modeset_lock_all(dev);
+ state->acquire_ctx = config->acquire_ctx;
+ err = drm_atomic_commit(state);
+ drm_modeset_unlock_all(dev);
+
+ return err;
+}
+EXPORT_SYMBOL(drm_atomic_helper_resume);
+
+/**
* drm_atomic_helper_crtc_set_property - helper for crtc properties
* @crtc: DRM crtc
* @property: DRM property
@@ -2354,7 +2512,9 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
* @ctx: lock acquisition context
*
* Makes a copy of the current atomic state by looping over all objects and
- * duplicating their respective states.
+ * duplicating their respective states. This is used for example by suspend/
+ * resume support code to save the state prior to suspend such that it can
+ * be restored upon resume.
*
* Note that this treats atomic state as persistent between save and restore.
* Drivers must make sure that this is possible and won't result in confusion
@@ -2366,6 +2526,9 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
* Returns:
* A pointer to the copy of the atomic state object on success or an
* ERR_PTR()-encoded error code on failure.
+ *
+ * See also:
+ * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
*/
struct drm_atomic_state *
drm_atomic_helper_duplicate_state(struct drm_device *dev,
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index ef534758a02c..08620a25fe06 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -855,6 +855,12 @@ EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
* due to slight differences in allocating shared resources when the
* configuration is restored in a different order than when userspace set it up)
* need to use their own restore logic.
+ *
+ * This function is deprecated. New drivers should implement atomic mode-
+ * setting and use the atomic suspend/resume helpers.
+ *
+ * See also:
+ * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
*/
void drm_helper_resume_force_mode(struct drm_device *dev)
{
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index 1547eb43c14a..98ffcb231079 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -75,6 +75,12 @@ int drm_atomic_helper_update_plane(struct drm_plane *plane,
int drm_atomic_helper_disable_plane(struct drm_plane *plane);
int drm_atomic_helper_set_config(struct drm_mode_set *set);
+int drm_atomic_helper_disable_all(struct drm_device *dev,
+ struct drm_modeset_acquire_ctx *ctx);
+struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev);
+int drm_atomic_helper_resume(struct drm_device *dev,
+ struct drm_atomic_state *state);
+
int drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
struct drm_property *property,
uint64_t val);
--
2.5.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 2/2] drm/atomic-helper: Implement subsystem-level suspend/resume
2015-09-08 13:00 ` [PATCH v3 2/2] drm/atomic-helper: Implement subsystem-level suspend/resume Thierry Reding
@ 2015-09-08 13:13 ` Daniel Vetter
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2015-09-08 13:13 UTC (permalink / raw)
To: Thierry Reding; +Cc: Daniel Vetter, dri-devel
On Tue, Sep 08, 2015 at 03:00:46PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> Provide subsystem-level suspend and resume helpers that can be used to
> implement suspend/resume on atomic mode-setting enabled drivers.
>
> v2: simplify locking, enhance kerneldoc comments
> v3: pass lock acquisition context by parameter, improve kerneldoc
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> drivers/gpu/drm/drm_atomic_helper.c | 165 +++++++++++++++++++++++++++++++++++-
> drivers/gpu/drm/drm_crtc_helper.c | 6 ++
> include/drm/drm_atomic_helper.h | 6 ++
> 3 files changed, 176 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index 3232f4b838e4..31823dc8a406 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -1742,6 +1742,164 @@ backoff:
> EXPORT_SYMBOL(drm_atomic_helper_set_config);
>
> /**
> + * drm_atomic_helper_disable_all - disable all currently active outputs
> + * @dev: DRM device
> + * @ctx: lock acquisition context
> + *
> + * Loops through all connectors, finding those that aren't turned off and then
> + * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
> + * that they are connected to.
> + *
> + * This is used for example in suspend/resume to disable all currently active
> + * functions when suspending.
> + *
> + * Note that if callers haven't already acquired all modeset locks this might
> + * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
> + *
> + * Returns:
> + * 0 on success or a negative error code on failure.
> + *
> + * See also:
> + * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
> + */
> +int drm_atomic_helper_disable_all(struct drm_device *dev,
> + struct drm_modeset_acquire_ctx *ctx)
> +{
> + struct drm_connector_state *conn_state;
> + struct drm_atomic_state *state;
> + struct drm_connector *conn;
> + unsigned int i;
> + int err;
> +
> + state = drm_atomic_state_alloc(dev);
> + if (!state)
> + return -ENOMEM;
> +
> + state->acquire_ctx = ctx;
> +
> + drm_for_each_connector(conn, dev) {
> + struct drm_crtc *crtc = conn->state->crtc;
> + struct drm_crtc_state *crtc_state;
> +
> + if (!crtc || conn->dpms != DRM_MODE_DPMS_ON)
> + continue;
> +
> + crtc_state = drm_atomic_get_crtc_state(state, crtc);
> + if (IS_ERR(crtc_state)) {
> + err = PTR_ERR(crtc_state);
> + goto free;
> + }
> +
> + err = drm_atomic_add_affected_connectors(state, crtc);
Just elaborating on what Maarten spotted on irc.
You don't need to do this, atomic helpers will do this for you.
> + if (err < 0)
> + goto free;
> +
> + conn->dpms = DRM_MODE_DPMS_OFF;
No need to touch legacy dpms state, that's again updated for you in
drm_atomic_helper_update_legacy_modeset_state.
> + crtc_state->active = false;
> + }
> +
> + err = drm_atomic_commit(state);
> + if (err < 0) {
> + /* restore DPMS mode */
> + for_each_connector_in_state(state, conn, conn_state, i)
> + conn->dpms = DRM_MODE_DPMS_ON;
Same here.
-Daniel
> +
> + goto free;
> + }
> +
> +free:
> + if (err < 0)
> + drm_atomic_state_free(state);
> +
> + return err;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_disable_all);
> +
> +/**
> + * drm_atomic_helper_suspend - subsystem-level suspend helper
> + * @dev: DRM device
> + *
> + * Duplicates the current atomic state, disables all active outputs and then
> + * returns a pointer to the original atomic state to the caller. Drivers can
> + * pass this pointer to the drm_atomic_helper_resume() helper upon resume to
> + * restore the output configuration that was active at the time the system
> + * entered suspend.
> + *
> + * Note that it is potentially unsafe to use this. The atomic state object
> + * returned by this function is assumed to be persistent. Drivers must ensure
> + * that this holds true. Before calling this function, drivers must make sure
> + * to suspend fbdev emulation so that nothing can be using the device.
> + *
> + * Returns:
> + * A pointer to a copy of the state before suspend on success or an ERR_PTR()-
> + * encoded error code on failure. Drivers should store the returned atomic
> + * state object and pass it to the drm_atomic_helper_resume() helper upon
> + * resume.
> + *
> + * See also:
> + * drm_atomic_helper_duplicate_state(), drm_atomic_helper_disable_all(),
> + * drm_atomic_helper_resume()
> + */
> +struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev)
> +{
> + struct drm_modeset_acquire_ctx ctx;
> + struct drm_atomic_state *state;
> + int err;
> +
> + drm_modeset_acquire_init(&ctx, 0);
> + drm_modeset_lock_all_ctx(dev, &ctx);
> +
> + state = drm_atomic_helper_duplicate_state(dev, &ctx);
> + if (IS_ERR(state))
> + goto unlock;
> +
> + err = drm_atomic_helper_disable_all(dev, &ctx);
> + if (err < 0) {
> + drm_atomic_state_free(state);
> + state = ERR_PTR(err);
> + goto unlock;
> + }
> +
> +unlock:
> + drm_modeset_unlock_all_ctx(dev, &ctx);
> + drm_modeset_acquire_fini(&ctx);
> + return state;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_suspend);
> +
> +/**
> + * drm_atomic_helper_resume - subsystem-level resume helper
> + * @dev: DRM device
> + * @state: atomic state to resume to
> + *
> + * Calls drm_mode_config_reset() to synchronize hardware and software states,
> + * grabs all modeset locks and commits the atomic state object. This can be
> + * used in conjunction with the drm_atomic_helper_suspend() helper to
> + * implement suspend/resume for drivers that support atomic mode-setting.
> + *
> + * Returns:
> + * 0 on success or a negative error code on failure.
> + *
> + * See also:
> + * drm_atomic_helper_suspend()
> + */
> +int drm_atomic_helper_resume(struct drm_device *dev,
> + struct drm_atomic_state *state)
> +{
> + struct drm_mode_config *config = &dev->mode_config;
> + int err;
> +
> + drm_mode_config_reset(dev);
> + drm_modeset_lock_all(dev);
> + state->acquire_ctx = config->acquire_ctx;
> + err = drm_atomic_commit(state);
> + drm_modeset_unlock_all(dev);
> +
> + return err;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_resume);
> +
> +/**
> * drm_atomic_helper_crtc_set_property - helper for crtc properties
> * @crtc: DRM crtc
> * @property: DRM property
> @@ -2354,7 +2512,9 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
> * @ctx: lock acquisition context
> *
> * Makes a copy of the current atomic state by looping over all objects and
> - * duplicating their respective states.
> + * duplicating their respective states. This is used for example by suspend/
> + * resume support code to save the state prior to suspend such that it can
> + * be restored upon resume.
> *
> * Note that this treats atomic state as persistent between save and restore.
> * Drivers must make sure that this is possible and won't result in confusion
> @@ -2366,6 +2526,9 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
> * Returns:
> * A pointer to the copy of the atomic state object on success or an
> * ERR_PTR()-encoded error code on failure.
> + *
> + * See also:
> + * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
> */
> struct drm_atomic_state *
> drm_atomic_helper_duplicate_state(struct drm_device *dev,
> diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
> index ef534758a02c..08620a25fe06 100644
> --- a/drivers/gpu/drm/drm_crtc_helper.c
> +++ b/drivers/gpu/drm/drm_crtc_helper.c
> @@ -855,6 +855,12 @@ EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
> * due to slight differences in allocating shared resources when the
> * configuration is restored in a different order than when userspace set it up)
> * need to use their own restore logic.
> + *
> + * This function is deprecated. New drivers should implement atomic mode-
> + * setting and use the atomic suspend/resume helpers.
> + *
> + * See also:
> + * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
> */
> void drm_helper_resume_force_mode(struct drm_device *dev)
> {
> diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
> index 1547eb43c14a..98ffcb231079 100644
> --- a/include/drm/drm_atomic_helper.h
> +++ b/include/drm/drm_atomic_helper.h
> @@ -75,6 +75,12 @@ int drm_atomic_helper_update_plane(struct drm_plane *plane,
> int drm_atomic_helper_disable_plane(struct drm_plane *plane);
> int drm_atomic_helper_set_config(struct drm_mode_set *set);
>
> +int drm_atomic_helper_disable_all(struct drm_device *dev,
> + struct drm_modeset_acquire_ctx *ctx);
> +struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev);
> +int drm_atomic_helper_resume(struct drm_device *dev,
> + struct drm_atomic_state *state);
> +
> int drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
> struct drm_property *property,
> uint64_t val);
> --
> 2.5.0
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state()
2015-09-08 13:00 [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state() Thierry Reding
2015-09-08 13:00 ` [PATCH v3 2/2] drm/atomic-helper: Implement subsystem-level suspend/resume Thierry Reding
@ 2015-09-08 13:25 ` Daniel Vetter
1 sibling, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2015-09-08 13:25 UTC (permalink / raw)
To: Thierry Reding; +Cc: Daniel Vetter, dri-devel
On Tue, Sep 08, 2015 at 03:00:45PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> This function can be used to duplicate an atomic state object. This is
> useful for example to implement suspend/resume, where the state before
> suspend can be saved and restored upon resume.
>
> v2: move locking to caller, be more explicit about prerequisites
> v3: explicitly pass lock acquisition context, improve kerneldoc
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
Applied to drm-misc with 2 tiny spelling fixes in the kerneldoc.
Thanks, Daniel
> ---
> drivers/gpu/drm/drm_atomic_helper.c | 78 +++++++++++++++++++++++++++++++++++++
> include/drm/drm_atomic_helper.h | 3 ++
> 2 files changed, 81 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index 634aa617811b..3232f4b838e4 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -2349,6 +2349,84 @@ drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
> EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
>
> /**
> + * drm_atomic_helper_duplicate_state - duplicate an atomic state object
> + * @dev: DRM device
> + * @ctx: lock acquisition context
> + *
> + * Makes a copy of the current atomic state by looping over all objects and
> + * duplicating their respective states.
> + *
> + * Note that this treats atomic state as persistent between save and restore.
> + * Drivers must make sure that this is possible and won't result in confusion
> + * or erroneous behaviour.
> + *
> + * Note that if callers haven't already acquired all modeset locks this might
> + * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
> + *
> + * Returns:
> + * A pointer to the copy of the atomic state object on success or an
> + * ERR_PTR()-encoded error code on failure.
> + */
> +struct drm_atomic_state *
> +drm_atomic_helper_duplicate_state(struct drm_device *dev,
> + struct drm_modeset_acquire_ctx *ctx)
> +{
> + struct drm_atomic_state *state;
> + struct drm_connector *conn;
> + struct drm_plane *plane;
> + struct drm_crtc *crtc;
> + int err = 0;
> +
> + state = drm_atomic_state_alloc(dev);
> + if (!state)
> + return ERR_PTR(-ENOMEM);
> +
> + state->acquire_ctx = ctx;
> +
> + drm_for_each_crtc(crtc, dev) {
> + struct drm_crtc_state *crtc_state;
> +
> + crtc_state = drm_atomic_get_crtc_state(state, crtc);
> + if (IS_ERR(crtc_state)) {
> + err = PTR_ERR(crtc_state);
> + goto free;
> + }
> + }
> +
> + drm_for_each_plane(plane, dev) {
> + struct drm_plane_state *plane_state;
> +
> + plane_state = drm_atomic_get_plane_state(state, plane);
> + if (IS_ERR(plane_state)) {
> + err = PTR_ERR(plane_state);
> + goto free;
> + }
> + }
> +
> + drm_for_each_connector(conn, dev) {
> + struct drm_connector_state *conn_state;
> +
> + conn_state = drm_atomic_get_connector_state(state, conn);
> + if (IS_ERR(conn_state)) {
> + err = PTR_ERR(conn_state);
> + goto free;
> + }
> + }
> +
> + /* clear the acquire context so that it isn't accidentally reused */
> + state->acquire_ctx = NULL;
> +
> +free:
> + if (err < 0) {
> + drm_atomic_state_free(state);
> + state = ERR_PTR(err);
> + }
> +
> + return state;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
> +
> +/**
> * __drm_atomic_helper_connector_destroy_state - release connector state
> * @connector: connector object
> * @state: connector state object to release
> diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
> index 4ffe9dca07c4..1547eb43c14a 100644
> --- a/include/drm/drm_atomic_helper.h
> +++ b/include/drm/drm_atomic_helper.h
> @@ -118,6 +118,9 @@ __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
> struct drm_connector_state *state);
> struct drm_connector_state *
> drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);
> +struct drm_atomic_state *
> +drm_atomic_helper_duplicate_state(struct drm_device *dev,
> + struct drm_modeset_acquire_ctx *ctx);
> void
> __drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
> struct drm_connector_state *state);
> --
> 2.5.0
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-08 13:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-08 13:00 [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state() Thierry Reding
2015-09-08 13:00 ` [PATCH v3 2/2] drm/atomic-helper: Implement subsystem-level suspend/resume Thierry Reding
2015-09-08 13:13 ` Daniel Vetter
2015-09-08 13:25 ` [PATCH v3 1/2] drm/atomic-helper: Implement drm_atomic_helper_duplicate_state() Daniel Vetter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox