aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-07-23 03:01:12 -0400
committerDavid Herrmann <dh.herrmann@gmail.com>2014-08-05 10:07:45 -0400
commit9f8d21ea276177547725a60cefc1b6da742f14d3 (patch)
tree1511b996ef09915f43246b7ecf145b2bd2ac349b
parenta91576d7916f6cce76d30303e60e1ac47cf4a76d (diff)
drm: extract legacy ctxbitmap flushing
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>
-rw-r--r--drivers/gpu/drm/drm_context.c30
-rw-r--r--drivers/gpu/drm/drm_fops.c20
-rw-r--r--include/drm/drmP.h1
3 files changed, 32 insertions, 19 deletions
diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
index a4b017b6849e..c045505978f1 100644
--- a/drivers/gpu/drm/drm_context.c
+++ b/drivers/gpu/drm/drm_context.c
@@ -111,6 +111,36 @@ void drm_ctxbitmap_cleanup(struct drm_device * dev)
111 mutex_unlock(&dev->struct_mutex); 111 mutex_unlock(&dev->struct_mutex);
112} 112}
113 113
114/**
115 * drm_ctxbitmap_flush() - Flush all contexts owned by a file
116 * @dev: DRM device to operate on
117 * @file: Open file to flush contexts for
118 *
119 * This iterates over all contexts on @dev and drops them if they're owned by
120 * @file. Note that after this call returns, new contexts might be added if
121 * the file is still alive.
122 */
123void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file)
124{
125 struct drm_ctx_list *pos, *tmp;
126
127 mutex_lock(&dev->ctxlist_mutex);
128
129 list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) {
130 if (pos->tag == file &&
131 pos->handle != DRM_KERNEL_CONTEXT) {
132 if (dev->driver->context_dtor)
133 dev->driver->context_dtor(dev, pos->handle);
134
135 drm_ctxbitmap_free(dev, pos->handle);
136 list_del(&pos->head);
137 kfree(pos);
138 }
139 }
140
141 mutex_unlock(&dev->ctxlist_mutex);
142}
143
114/*@}*/ 144/*@}*/
115 145
116/******************************************************************/ 146/******************************************************************/
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index bc583fe51e45..55143f7747f3 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -457,25 +457,7 @@ int drm_release(struct inode *inode, struct file *filp)
457 if (dev->driver->driver_features & DRIVER_GEM) 457 if (dev->driver->driver_features & DRIVER_GEM)
458 drm_gem_release(dev, file_priv); 458 drm_gem_release(dev, file_priv);
459 459
460 mutex_lock(&dev->ctxlist_mutex); 460 drm_ctxbitmap_flush(dev, file_priv);
461 if (!list_empty(&dev->ctxlist)) {
462 struct drm_ctx_list *pos, *n;
463
464 list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
465 if (pos->tag == file_priv &&
466 pos->handle != DRM_KERNEL_CONTEXT) {
467 if (dev->driver->context_dtor)
468 dev->driver->context_dtor(dev,
469 pos->handle);
470
471 drm_ctxbitmap_free(dev, pos->handle);
472
473 list_del(&pos->head);
474 kfree(pos);
475 }
476 }
477 }
478 mutex_unlock(&dev->ctxlist_mutex);
479 461
480 mutex_lock(&dev->master_mutex); 462 mutex_lock(&dev->master_mutex);
481 463
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index d3d9be6b83ef..80889982d196 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1242,6 +1242,7 @@ extern int drm_rmctx(struct drm_device *dev, void *data,
1242extern int drm_ctxbitmap_init(struct drm_device *dev); 1242extern int drm_ctxbitmap_init(struct drm_device *dev);
1243extern void drm_ctxbitmap_cleanup(struct drm_device *dev); 1243extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1244extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 1244extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1245extern void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file);
1245 1246
1246extern int drm_setsareactx(struct drm_device *dev, void *data, 1247extern int drm_setsareactx(struct drm_device *dev, void *data,
1247 struct drm_file *file_priv); 1248 struct drm_file *file_priv);