aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_context.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/drm_context.c')
-rw-r--r--drivers/gpu/drm/drm_context.c102
1 files changed, 64 insertions, 38 deletions
diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
index a4b017b6849e..9b23525c0ed0 100644
--- a/drivers/gpu/drm/drm_context.c
+++ b/drivers/gpu/drm/drm_context.c
@@ -1,18 +1,13 @@
1/**
2 * \file drm_context.c
3 * IOCTLs for generic contexts
4 *
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
7 */
8
9/* 1/*
10 * Created: Fri Nov 24 18:31:37 2000 by gareth@valinux.com 2 * Legacy: Generic DRM Contexts
11 * 3 *
12 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. 4 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14 * All Rights Reserved. 6 * All Rights Reserved.
15 * 7 *
8 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
9 * Author: Gareth Hughes <gareth@valinux.com>
10 *
16 * Permission is hereby granted, free of charge, to any person obtaining a 11 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"), 12 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation 13 * to deal in the Software without restriction, including without limitation
@@ -33,14 +28,14 @@
33 * OTHER DEALINGS IN THE SOFTWARE. 28 * OTHER DEALINGS IN THE SOFTWARE.
34 */ 29 */
35 30
36/*
37 * ChangeLog:
38 * 2001-11-16 Torsten Duwe <duwe@caldera.de>
39 * added context constructor/destructor hooks,
40 * needed by SiS driver's memory management.
41 */
42
43#include <drm/drmP.h> 31#include <drm/drmP.h>
32#include "drm_legacy.h"
33
34struct drm_ctx_list {
35 struct list_head head;
36 drm_context_t handle;
37 struct drm_file *tag;
38};
44 39
45/******************************************************************/ 40/******************************************************************/
46/** \name Context bitmap support */ 41/** \name Context bitmap support */
@@ -56,7 +51,7 @@
56 * in drm_device::ctx_idr, while holding the drm_device::struct_mutex 51 * in drm_device::ctx_idr, while holding the drm_device::struct_mutex
57 * lock. 52 * lock.
58 */ 53 */
59void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle) 54void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
60{ 55{
61 mutex_lock(&dev->struct_mutex); 56 mutex_lock(&dev->struct_mutex);
62 idr_remove(&dev->ctx_idr, ctx_handle); 57 idr_remove(&dev->ctx_idr, ctx_handle);
@@ -72,7 +67,7 @@ void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
72 * Allocate a new idr from drm_device::ctx_idr while holding the 67 * Allocate a new idr from drm_device::ctx_idr while holding the
73 * drm_device::struct_mutex lock. 68 * drm_device::struct_mutex lock.
74 */ 69 */
75static int drm_ctxbitmap_next(struct drm_device * dev) 70static int drm_legacy_ctxbitmap_next(struct drm_device * dev)
76{ 71{
77 int ret; 72 int ret;
78 73
@@ -90,7 +85,7 @@ static int drm_ctxbitmap_next(struct drm_device * dev)
90 * 85 *
91 * Initialise the drm_device::ctx_idr 86 * Initialise the drm_device::ctx_idr
92 */ 87 */
93int drm_ctxbitmap_init(struct drm_device * dev) 88int drm_legacy_ctxbitmap_init(struct drm_device * dev)
94{ 89{
95 idr_init(&dev->ctx_idr); 90 idr_init(&dev->ctx_idr);
96 return 0; 91 return 0;
@@ -104,13 +99,43 @@ int drm_ctxbitmap_init(struct drm_device * dev)
104 * Free all idr members using drm_ctx_sarea_free helper function 99 * Free all idr members using drm_ctx_sarea_free helper function
105 * while holding the drm_device::struct_mutex lock. 100 * while holding the drm_device::struct_mutex lock.
106 */ 101 */
107void drm_ctxbitmap_cleanup(struct drm_device * dev) 102void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
108{ 103{
109 mutex_lock(&dev->struct_mutex); 104 mutex_lock(&dev->struct_mutex);
110 idr_destroy(&dev->ctx_idr); 105 idr_destroy(&dev->ctx_idr);
111 mutex_unlock(&dev->struct_mutex); 106 mutex_unlock(&dev->struct_mutex);
112} 107}
113 108
109/**
110 * drm_ctxbitmap_flush() - Flush all contexts owned by a file
111 * @dev: DRM device to operate on
112 * @file: Open file to flush contexts for
113 *
114 * This iterates over all contexts on @dev and drops them if they're owned by
115 * @file. Note that after this call returns, new contexts might be added if
116 * the file is still alive.
117 */
118void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file)
119{
120 struct drm_ctx_list *pos, *tmp;
121
122 mutex_lock(&dev->ctxlist_mutex);
123
124 list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) {
125 if (pos->tag == file &&
126 pos->handle != DRM_KERNEL_CONTEXT) {
127 if (dev->driver->context_dtor)
128 dev->driver->context_dtor(dev, pos->handle);
129
130 drm_legacy_ctxbitmap_free(dev, pos->handle);
131 list_del(&pos->head);
132 kfree(pos);
133 }
134 }
135
136 mutex_unlock(&dev->ctxlist_mutex);
137}
138
114/*@}*/ 139/*@}*/
115 140
116/******************************************************************/ 141/******************************************************************/
@@ -129,8 +154,8 @@ void drm_ctxbitmap_cleanup(struct drm_device * dev)
129 * Gets the map from drm_device::ctx_idr with the handle specified and 154 * Gets the map from drm_device::ctx_idr with the handle specified and
130 * returns its handle. 155 * returns its handle.
131 */ 156 */
132int drm_getsareactx(struct drm_device *dev, void *data, 157int drm_legacy_getsareactx(struct drm_device *dev, void *data,
133 struct drm_file *file_priv) 158 struct drm_file *file_priv)
134{ 159{
135 struct drm_ctx_priv_map *request = data; 160 struct drm_ctx_priv_map *request = data;
136 struct drm_local_map *map; 161 struct drm_local_map *map;
@@ -173,8 +198,8 @@ int drm_getsareactx(struct drm_device *dev, void *data,
173 * Searches the mapping specified in \p arg and update the entry in 198 * Searches the mapping specified in \p arg and update the entry in
174 * drm_device::ctx_idr with it. 199 * drm_device::ctx_idr with it.
175 */ 200 */
176int drm_setsareactx(struct drm_device *dev, void *data, 201int drm_legacy_setsareactx(struct drm_device *dev, void *data,
177 struct drm_file *file_priv) 202 struct drm_file *file_priv)
178{ 203{
179 struct drm_ctx_priv_map *request = data; 204 struct drm_ctx_priv_map *request = data;
180 struct drm_local_map *map = NULL; 205 struct drm_local_map *map = NULL;
@@ -273,8 +298,8 @@ static int drm_context_switch_complete(struct drm_device *dev,
273 * \param arg user argument pointing to a drm_ctx_res structure. 298 * \param arg user argument pointing to a drm_ctx_res structure.
274 * \return zero on success or a negative number on failure. 299 * \return zero on success or a negative number on failure.
275 */ 300 */
276int drm_resctx(struct drm_device *dev, void *data, 301int drm_legacy_resctx(struct drm_device *dev, void *data,
277 struct drm_file *file_priv) 302 struct drm_file *file_priv)
278{ 303{
279 struct drm_ctx_res *res = data; 304 struct drm_ctx_res *res = data;
280 struct drm_ctx ctx; 305 struct drm_ctx ctx;
@@ -304,16 +329,16 @@ int drm_resctx(struct drm_device *dev, void *data,
304 * 329 *
305 * Get a new handle for the context and copy to userspace. 330 * Get a new handle for the context and copy to userspace.
306 */ 331 */
307int drm_addctx(struct drm_device *dev, void *data, 332int drm_legacy_addctx(struct drm_device *dev, void *data,
308 struct drm_file *file_priv) 333 struct drm_file *file_priv)
309{ 334{
310 struct drm_ctx_list *ctx_entry; 335 struct drm_ctx_list *ctx_entry;
311 struct drm_ctx *ctx = data; 336 struct drm_ctx *ctx = data;
312 337
313 ctx->handle = drm_ctxbitmap_next(dev); 338 ctx->handle = drm_legacy_ctxbitmap_next(dev);
314 if (ctx->handle == DRM_KERNEL_CONTEXT) { 339 if (ctx->handle == DRM_KERNEL_CONTEXT) {
315 /* Skip kernel's context and get a new one. */ 340 /* Skip kernel's context and get a new one. */
316 ctx->handle = drm_ctxbitmap_next(dev); 341 ctx->handle = drm_legacy_ctxbitmap_next(dev);
317 } 342 }
318 DRM_DEBUG("%d\n", ctx->handle); 343 DRM_DEBUG("%d\n", ctx->handle);
319 if (ctx->handle == -1) { 344 if (ctx->handle == -1) {
@@ -348,7 +373,8 @@ int drm_addctx(struct drm_device *dev, void *data,
348 * \param arg user argument pointing to a drm_ctx structure. 373 * \param arg user argument pointing to a drm_ctx structure.
349 * \return zero on success or a negative number on failure. 374 * \return zero on success or a negative number on failure.
350 */ 375 */
351int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv) 376int drm_legacy_getctx(struct drm_device *dev, void *data,
377 struct drm_file *file_priv)
352{ 378{
353 struct drm_ctx *ctx = data; 379 struct drm_ctx *ctx = data;
354 380
@@ -369,8 +395,8 @@ int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
369 * 395 *
370 * Calls context_switch(). 396 * Calls context_switch().
371 */ 397 */
372int drm_switchctx(struct drm_device *dev, void *data, 398int drm_legacy_switchctx(struct drm_device *dev, void *data,
373 struct drm_file *file_priv) 399 struct drm_file *file_priv)
374{ 400{
375 struct drm_ctx *ctx = data; 401 struct drm_ctx *ctx = data;
376 402
@@ -389,8 +415,8 @@ int drm_switchctx(struct drm_device *dev, void *data,
389 * 415 *
390 * Calls context_switch_complete(). 416 * Calls context_switch_complete().
391 */ 417 */
392int drm_newctx(struct drm_device *dev, void *data, 418int drm_legacy_newctx(struct drm_device *dev, void *data,
393 struct drm_file *file_priv) 419 struct drm_file *file_priv)
394{ 420{
395 struct drm_ctx *ctx = data; 421 struct drm_ctx *ctx = data;
396 422
@@ -411,8 +437,8 @@ int drm_newctx(struct drm_device *dev, void *data,
411 * 437 *
412 * If not the special kernel context, calls ctxbitmap_free() to free the specified context. 438 * If not the special kernel context, calls ctxbitmap_free() to free the specified context.
413 */ 439 */
414int drm_rmctx(struct drm_device *dev, void *data, 440int drm_legacy_rmctx(struct drm_device *dev, void *data,
415 struct drm_file *file_priv) 441 struct drm_file *file_priv)
416{ 442{
417 struct drm_ctx *ctx = data; 443 struct drm_ctx *ctx = data;
418 444
@@ -420,7 +446,7 @@ int drm_rmctx(struct drm_device *dev, void *data,
420 if (ctx->handle != DRM_KERNEL_CONTEXT) { 446 if (ctx->handle != DRM_KERNEL_CONTEXT) {
421 if (dev->driver->context_dtor) 447 if (dev->driver->context_dtor)
422 dev->driver->context_dtor(dev, ctx->handle); 448 dev->driver->context_dtor(dev, ctx->handle);
423 drm_ctxbitmap_free(dev, ctx->handle); 449 drm_legacy_ctxbitmap_free(dev, ctx->handle);
424 } 450 }
425 451
426 mutex_lock(&dev->ctxlist_mutex); 452 mutex_lock(&dev->ctxlist_mutex);