These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / gpu / drm / drm_modeset_lock.c
index 51cc47d..6675b14 100644 (file)
  *     drm_modeset_acquire_fini(&ctx);
  */
 
-
 /**
- * __drm_modeset_lock_all - internal helper to grab all modeset locks
- * @dev: DRM device
- * @trylock: trylock mode for atomic contexts
- *
- * This is a special version of drm_modeset_lock_all() which can also be used in
- * atomic contexts. Then @trylock must be set to true.
+ * drm_modeset_lock_all - take all modeset locks
+ * @dev: drm device
  *
- * Returns:
- * 0 on success or negative error code on failure.
+ * This function takes all modeset locks, suitable where a more fine-grained
+ * scheme isn't (yet) implemented. Locks must be dropped with
+ * drm_modeset_unlock_all.
  */
-int __drm_modeset_lock_all(struct drm_device *dev,
-                          bool trylock)
+void drm_modeset_lock_all(struct drm_device *dev)
 {
        struct drm_mode_config *config = &dev->mode_config;
        struct drm_modeset_acquire_ctx *ctx;
        int ret;
 
-       ctx = kzalloc(sizeof(*ctx),
-                     trylock ? GFP_ATOMIC : GFP_KERNEL);
-       if (!ctx)
-               return -ENOMEM;
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (WARN_ON(!ctx))
+               return;
 
-       if (trylock) {
-               if (!mutex_trylock(&config->mutex))
-                       return -EBUSY;
-       } else {
-               mutex_lock(&config->mutex);
-       }
+       mutex_lock(&config->mutex);
 
        drm_modeset_acquire_init(ctx, 0);
-       ctx->trylock_only = trylock;
 
 retry:
        ret = drm_modeset_lock(&config->connection_mutex, ctx);
@@ -106,7 +94,7 @@ retry:
 
        drm_warn_on_modeset_not_all_locked(dev);
 
-       return 0;
+       return;
 
 fail:
        if (ret == -EDEADLK) {
@@ -114,21 +102,7 @@ fail:
                goto retry;
        }
 
-       return ret;
-}
-EXPORT_SYMBOL(__drm_modeset_lock_all);
-
-/**
- * drm_modeset_lock_all - take all modeset locks
- * @dev: drm device
- *
- * This function takes all modeset locks, suitable where a more fine-grained
- * scheme isn't (yet) implemented. Locks must be dropped with
- * drm_modeset_unlock_all.
- */
-void drm_modeset_lock_all(struct drm_device *dev)
-{
-       WARN_ON(__drm_modeset_lock_all(dev, false) != 0);
+       kfree(ctx);
 }
 EXPORT_SYMBOL(drm_modeset_lock_all);
 
@@ -272,7 +246,7 @@ void drm_warn_on_modeset_not_all_locked(struct drm_device *dev)
        if (oops_in_progress)
                return;
 
-       list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
+       drm_for_each_crtc(crtc, dev)
                WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
 
        WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
@@ -333,6 +307,8 @@ static inline int modeset_lock(struct drm_modeset_lock *lock,
        WARN_ON(ctx->contended);
 
        if (ctx->trylock_only) {
+               lockdep_assert_held(&ctx->ww_ctx);
+
                if (!ww_mutex_trylock(&lock->mutex))
                        return -EBUSY;
                else
@@ -460,18 +436,17 @@ EXPORT_SYMBOL(drm_modeset_unlock);
 int drm_modeset_lock_all_crtcs(struct drm_device *dev,
                struct drm_modeset_acquire_ctx *ctx)
 {
-       struct drm_mode_config *config = &dev->mode_config;
        struct drm_crtc *crtc;
        struct drm_plane *plane;
        int ret = 0;
 
-       list_for_each_entry(crtc, &config->crtc_list, head) {
+       drm_for_each_crtc(crtc, dev) {
                ret = drm_modeset_lock(&crtc->mutex, ctx);
                if (ret)
                        return ret;
        }
 
-       list_for_each_entry(plane, &config->plane_list, head) {
+       drm_for_each_plane(plane, dev) {
                ret = drm_modeset_lock(&plane->mutex, ctx);
                if (ret)
                        return ret;