diff mbox

drm/atomic-helper: add unlocked disable all outputs helper

Message ID 1470992834-12868-1-git-send-email-l.stach@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Stach Aug. 12, 2016, 9:07 a.m. UTC
This adds the unlocked variant of drm_atomic_helper_disable_all(),
which takes all the required modeset locks itself. This is intended
to be used when shutting down the driver, without retaining any
state.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/gpu/drm/drm_atomic_helper.c | 43 +++++++++++++++++++++++++++++++++++++
 include/drm/drm_atomic_helper.h     |  1 +
 2 files changed, 44 insertions(+)

Comments

Sean Paul Aug. 15, 2016, 9:13 p.m. UTC | #1
On Fri, Aug 12, 2016 at 5:07 AM, Lucas Stach <l.stach@pengutronix.de> wrote:
> This adds the unlocked variant of drm_atomic_helper_disable_all(),
> which takes all the required modeset locks itself. This is intended
> to be used when shutting down the driver, without retaining any
> state.
>
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>

So I suppose this is the atomic equivalent of
drm_crtc_force_disable_all? Should you perhaps update the legacy
helper to call this new function?

Sean


> ---
>  drivers/gpu/drm/drm_atomic_helper.c | 43 +++++++++++++++++++++++++++++++++++++
>  include/drm/drm_atomic_helper.h     |  1 +
>  2 files changed, 44 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index 99365087645b..6673021ab21e 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -2435,6 +2435,49 @@ free:
>  EXPORT_SYMBOL(drm_atomic_helper_disable_all);
>
>  /**
> + * drm_atomic_helper_disable_all_unlocked - disable all currently active
> + * outputs taking the modeset locks itself
> + * @dev: DRM device
> + *
> + * 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 when shutting down the DRM device.
> + *
> + * Returns:
> + * 0 on success or a negative error code on failure.
> + */
> +int drm_atomic_helper_disable_all_unlocked(struct drm_device *dev)
> +{
> +       struct drm_modeset_acquire_ctx ctx;
> +       int err;
> +
> +       drm_modeset_acquire_init(&ctx, 0);
> +
> +retry:
> +       err = drm_modeset_lock_all_ctx(dev, &ctx);
> +       if (err < 0)
> +               goto unlock;
> +
> +       err = drm_atomic_helper_disable_all(dev, &ctx);
> +       if (err < 0)
> +               goto unlock;
> +
> +unlock:
> +       if (err == -EDEADLK) {
> +               drm_modeset_backoff(&ctx);
> +               goto retry;
> +       }
> +
> +       drm_modeset_drop_locks(&ctx);
> +       drm_modeset_acquire_fini(&ctx);
> +
> +       return err;
> +}
> +EXPORT_SYMBOL(drm_atomic_helper_disable_all_unlocked);
> +
> +/**
>   * drm_atomic_helper_suspend - subsystem-level suspend helper
>   * @dev: DRM device
>   *
> diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
> index d86ae5dcd7b4..104d310c2c70 100644
> --- a/include/drm/drm_atomic_helper.h
> +++ b/include/drm/drm_atomic_helper.h
> @@ -99,6 +99,7 @@ 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);
> +int drm_atomic_helper_disable_all_unlocked(struct drm_device *dev);
>  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);
> --
> 2.8.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Brian Starkey Oct. 4, 2016, 4:38 p.m. UTC | #2
Hi Lucas,

On Fri, Aug 12, 2016 at 11:07:14AM +0200, Lucas Stach wrote:
>This adds the unlocked variant of drm_atomic_helper_disable_all(),
>which takes all the required modeset locks itself. This is intended
>to be used when shutting down the driver, without retaining any
>state.
>

Is this meant to be analogous to:

	drm_for_each_plane(plane, dev)
		drm_plane_force_disable(plane);
	drm_for_each_crtc(crtc, dev)
		drm_crtc_force_disable(crtc);

?

I may have misunderstood the intention here, but it seems like this
patch only disables the outputs and doesn't disable planes or
remove their framebuffers (which I think we'd want for driver
shutdown).

Thanks,
Brian

>Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
>---
> drivers/gpu/drm/drm_atomic_helper.c | 43 +++++++++++++++++++++++++++++++++++++
> include/drm/drm_atomic_helper.h     |  1 +
> 2 files changed, 44 insertions(+)
>
>diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
>index 99365087645b..6673021ab21e 100644
>--- a/drivers/gpu/drm/drm_atomic_helper.c
>+++ b/drivers/gpu/drm/drm_atomic_helper.c
>@@ -2435,6 +2435,49 @@ free:
> EXPORT_SYMBOL(drm_atomic_helper_disable_all);
>
> /**
>+ * drm_atomic_helper_disable_all_unlocked - disable all currently active
>+ * outputs taking the modeset locks itself
>+ * @dev: DRM device
>+ *
>+ * 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 when shutting down the DRM device.
>+ *
>+ * Returns:
>+ * 0 on success or a negative error code on failure.
>+ */
>+int drm_atomic_helper_disable_all_unlocked(struct drm_device *dev)
>+{
>+	struct drm_modeset_acquire_ctx ctx;
>+	int err;
>+
>+	drm_modeset_acquire_init(&ctx, 0);
>+
>+retry:
>+	err = drm_modeset_lock_all_ctx(dev, &ctx);
>+	if (err < 0)
>+		goto unlock;
>+
>+	err = drm_atomic_helper_disable_all(dev, &ctx);
>+	if (err < 0)
>+		goto unlock;
>+
>+unlock:
>+	if (err == -EDEADLK) {
>+		drm_modeset_backoff(&ctx);
>+		goto retry;
>+	}
>+
>+	drm_modeset_drop_locks(&ctx);
>+	drm_modeset_acquire_fini(&ctx);
>+
>+	return err;
>+}
>+EXPORT_SYMBOL(drm_atomic_helper_disable_all_unlocked);
>+
>+/**
>  * drm_atomic_helper_suspend - subsystem-level suspend helper
>  * @dev: DRM device
>  *
>diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
>index d86ae5dcd7b4..104d310c2c70 100644
>--- a/include/drm/drm_atomic_helper.h
>+++ b/include/drm/drm_atomic_helper.h
>@@ -99,6 +99,7 @@ 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);
>+int drm_atomic_helper_disable_all_unlocked(struct drm_device *dev);
> 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);
>-- 
>2.8.1
>
>_______________________________________________
>dri-devel mailing list
>dri-devel@lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 99365087645b..6673021ab21e 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2435,6 +2435,49 @@  free:
 EXPORT_SYMBOL(drm_atomic_helper_disable_all);
 
 /**
+ * drm_atomic_helper_disable_all_unlocked - disable all currently active
+ * outputs taking the modeset locks itself
+ * @dev: DRM device
+ *
+ * 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 when shutting down the DRM device.
+ *
+ * Returns:
+ * 0 on success or a negative error code on failure.
+ */
+int drm_atomic_helper_disable_all_unlocked(struct drm_device *dev)
+{
+	struct drm_modeset_acquire_ctx ctx;
+	int err;
+
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+	err = drm_modeset_lock_all_ctx(dev, &ctx);
+	if (err < 0)
+		goto unlock;
+
+	err = drm_atomic_helper_disable_all(dev, &ctx);
+	if (err < 0)
+		goto unlock;
+
+unlock:
+	if (err == -EDEADLK) {
+		drm_modeset_backoff(&ctx);
+		goto retry;
+	}
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
+
+	return err;
+}
+EXPORT_SYMBOL(drm_atomic_helper_disable_all_unlocked);
+
+/**
  * drm_atomic_helper_suspend - subsystem-level suspend helper
  * @dev: DRM device
  *
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index d86ae5dcd7b4..104d310c2c70 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -99,6 +99,7 @@  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);
+int drm_atomic_helper_disable_all_unlocked(struct drm_device *dev);
 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);