drm: extract legacy ctxbitmap flushing
authorDavid Herrmann <dh.herrmann@gmail.com>
Wed, 23 Jul 2014 07:01:12 +0000 (09:01 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Tue, 5 Aug 2014 14:07:45 +0000 (16:07 +0200)
The ctxbitmap code is only used by legacy drivers so lets try to keep it
as separated as possible. Furthermore, the locking is non-obvious and
kinda weird with ctxlist_mutex *and* struct_mutex. Keeping all ctxbitmap
access in one file is much easier to review and makes drm_release() more
readable.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
drivers/gpu/drm/drm_context.c
drivers/gpu/drm/drm_fops.c
include/drm/drmP.h

index a4b017b6849efd79686693e0e5cad7b5edf9ae09..c045505978f1464b72d4d5621a840c9f8ab097d1 100644 (file)
@@ -111,6 +111,36 @@ void drm_ctxbitmap_cleanup(struct drm_device * dev)
        mutex_unlock(&dev->struct_mutex);
 }
 
+/**
+ * drm_ctxbitmap_flush() - Flush all contexts owned by a file
+ * @dev: DRM device to operate on
+ * @file: Open file to flush contexts for
+ *
+ * This iterates over all contexts on @dev and drops them if they're owned by
+ * @file. Note that after this call returns, new contexts might be added if
+ * the file is still alive.
+ */
+void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file)
+{
+       struct drm_ctx_list *pos, *tmp;
+
+       mutex_lock(&dev->ctxlist_mutex);
+
+       list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) {
+               if (pos->tag == file &&
+                   pos->handle != DRM_KERNEL_CONTEXT) {
+                       if (dev->driver->context_dtor)
+                               dev->driver->context_dtor(dev, pos->handle);
+
+                       drm_ctxbitmap_free(dev, pos->handle);
+                       list_del(&pos->head);
+                       kfree(pos);
+               }
+       }
+
+       mutex_unlock(&dev->ctxlist_mutex);
+}
+
 /*@}*/
 
 /******************************************************************/
index bc583fe51e45dca0cc708a4f38a5226d662d7227..55143f7747f37be6fdb07658ae24c0d5c7a9e24a 100644 (file)
@@ -457,25 +457,7 @@ int drm_release(struct inode *inode, struct file *filp)
        if (dev->driver->driver_features & DRIVER_GEM)
                drm_gem_release(dev, file_priv);
 
-       mutex_lock(&dev->ctxlist_mutex);
-       if (!list_empty(&dev->ctxlist)) {
-               struct drm_ctx_list *pos, *n;
-
-               list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
-                       if (pos->tag == file_priv &&
-                           pos->handle != DRM_KERNEL_CONTEXT) {
-                               if (dev->driver->context_dtor)
-                                       dev->driver->context_dtor(dev,
-                                                                 pos->handle);
-
-                               drm_ctxbitmap_free(dev, pos->handle);
-
-                               list_del(&pos->head);
-                               kfree(pos);
-                       }
-               }
-       }
-       mutex_unlock(&dev->ctxlist_mutex);
+       drm_ctxbitmap_flush(dev, file_priv);
 
        mutex_lock(&dev->master_mutex);
 
index d3d9be6b83efe13a0aa1425656f83c46429b4e46..80889982d19612b5c1ca9d73bdfe5ceecd540ce2 100644 (file)
@@ -1242,6 +1242,7 @@ extern int drm_rmctx(struct drm_device *dev, void *data,
 extern int drm_ctxbitmap_init(struct drm_device *dev);
 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
+extern void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file);
 
 extern int drm_setsareactx(struct drm_device *dev, void *data,
                           struct drm_file *file_priv);