Lines Matching +full:per +full:- +full:context

39  *  2001-11-16	Torsten Duwe <duwe@caldera.de>
40 * added context constructor/destructor hooks,
47 /** \name Context bitmap support */
51 * Free a handle from the context bitmap.
54 * \param ctx_handle context handle.
63 dev->ctx_bitmap == NULL) { in drm_ctxbitmap_free()
64 DRM_ERROR("Attempt to free invalid context handle: %d\n", in drm_ctxbitmap_free()
70 clear_bit(ctx_handle, dev->ctx_bitmap); in drm_ctxbitmap_free()
71 dev->context_sareas[ctx_handle] = NULL; in drm_ctxbitmap_free()
76 * Context bitmap allocation.
79 * \return (non-negative) context handle on success or a negative number on failure.
88 if (dev->ctx_bitmap == NULL) in drm_ctxbitmap_next()
89 return -1; in drm_ctxbitmap_next()
92 bit = find_first_zero_bit(dev->ctx_bitmap, DRM_MAX_CTXBITMAP); in drm_ctxbitmap_next()
95 return -1; in drm_ctxbitmap_next()
98 set_bit(bit, dev->ctx_bitmap); in drm_ctxbitmap_next()
100 if ((bit+1) > dev->max_context) { in drm_ctxbitmap_next()
104 ctx_sareas = realloc(dev->context_sareas, in drm_ctxbitmap_next()
105 max_ctx * sizeof(*dev->context_sareas), in drm_ctxbitmap_next()
108 clear_bit(bit, dev->ctx_bitmap); in drm_ctxbitmap_next()
111 return -1; in drm_ctxbitmap_next()
113 dev->max_context = max_ctx; in drm_ctxbitmap_next()
114 dev->context_sareas = ctx_sareas; in drm_ctxbitmap_next()
115 dev->context_sareas[bit] = NULL; in drm_ctxbitmap_next()
122 * Context bitmap initialization.
134 dev->ctx_bitmap = malloc(PAGE_SIZE, DRM_MEM_CTXBITMAP, in drm_ctxbitmap_init()
136 if (dev->ctx_bitmap == NULL) { in drm_ctxbitmap_init()
140 dev->context_sareas = NULL; in drm_ctxbitmap_init()
141 dev->max_context = -1; in drm_ctxbitmap_init()
153 * Context bitmap cleanup.
163 if (dev->context_sareas != NULL) in drm_ctxbitmap_cleanup()
164 free(dev->context_sareas, DRM_MEM_SAREA); in drm_ctxbitmap_cleanup()
165 free(dev->ctx_bitmap, DRM_MEM_CTXBITMAP); in drm_ctxbitmap_cleanup()
172 /** \name Per Context SAREA Support */
176 * Get per-context SAREA.
194 if (dev->max_context < 0 || in drm_getsareactx()
195 request->ctx_id >= (unsigned) dev->max_context) { in drm_getsareactx()
200 map = dev->context_sareas[request->ctx_id]; in drm_getsareactx()
203 request->handle = (void *)map->handle; in drm_getsareactx()
209 * Set per-context SAREA.
228 list_for_each_entry(r_list, &dev->maplist, head) { in drm_setsareactx()
229 if (r_list->map in drm_setsareactx()
230 && r_list->user_token == (unsigned long) request->handle) { in drm_setsareactx()
231 if (dev->max_context < 0) in drm_setsareactx()
233 if (request->ctx_id >= (unsigned) dev->max_context) in drm_setsareactx()
235 dev->context_sareas[request->ctx_id] = map; in drm_setsareactx()
249 /** \name The actual DRM context handling routines */
253 * Switch context.
256 * \param old old context handle.
257 * \param new new context handle.
264 if (test_and_set_bit(0, &dev->context_flag)) { in drm_context_switch()
265 DRM_ERROR("Reentering -- FIXME\n"); in drm_context_switch()
266 return -EBUSY; in drm_context_switch()
269 DRM_DEBUG("Context switch from %d to %d\n", old, new); in drm_context_switch()
271 if (new == dev->last_context) { in drm_context_switch()
272 clear_bit(0, &dev->context_flag); in drm_context_switch()
280 * Complete context switch.
283 * \param new new context handle.
293 dev->last_context = new; /* PRE/POST: This is the _only_ writer. */ in drm_context_switch_complete()
294 dev->last_switch = jiffies; in drm_context_switch_complete()
296 if (!_DRM_LOCK_IS_HELD(file_priv->master->lock.hw_lock->lock)) { in drm_context_switch_complete()
297 DRM_ERROR("Lock isn't held after context switch\n"); in drm_context_switch_complete()
300 /* If a context switch is ever initiated in drm_context_switch_complete()
303 clear_bit(0, &dev->context_flag); in drm_context_switch_complete()
304 wakeup(&dev->context_wait); in drm_context_switch_complete()
325 if (res->count >= DRM_RESERVED_CONTEXTS) { in drm_resctx()
329 if (copy_to_user(&res->contexts[i], &ctx, sizeof(ctx))) in drm_resctx()
330 return -EFAULT; in drm_resctx()
333 res->count = DRM_RESERVED_CONTEXTS; in drm_resctx()
339 * Add context.
347 * Get a new handle for the context and copy to userspace.
355 ctx->handle = drm_ctxbitmap_next(dev); in drm_addctx()
356 if (ctx->handle == DRM_KERNEL_CONTEXT) { in drm_addctx()
357 /* Skip kernel's context and get a new one. */ in drm_addctx()
358 ctx->handle = drm_ctxbitmap_next(dev); in drm_addctx()
360 DRM_DEBUG("%d\n", ctx->handle); in drm_addctx()
361 if (ctx->handle == -1) { in drm_addctx()
363 /* Should this return -EBUSY instead? */ in drm_addctx()
364 return -ENOMEM; in drm_addctx()
370 return -ENOMEM; in drm_addctx()
373 INIT_LIST_HEAD(&ctx_entry->head); in drm_addctx()
374 ctx_entry->handle = ctx->handle; in drm_addctx()
375 ctx_entry->tag = file_priv; in drm_addctx()
378 list_add(&ctx_entry->head, &dev->ctxlist); in drm_addctx()
379 ++dev->ctx_count; in drm_addctx()
392 * Get context.
404 /* This is 0, because we don't handle any context flags */ in drm_getctx()
405 ctx->flags = 0; in drm_getctx()
411 * Switch context.
426 DRM_DEBUG("%d\n", ctx->handle); in drm_switchctx()
427 return drm_context_switch(dev, dev->last_context, ctx->handle); in drm_switchctx()
431 * New context.
446 DRM_DEBUG("%d\n", ctx->handle); in drm_newctx()
447 drm_context_switch_complete(dev, file_priv, ctx->handle); in drm_newctx()
453 * Remove context.
461 * If not the special kernel context, calls ctxbitmap_free() to free the specified context.
468 DRM_DEBUG("%d\n", ctx->handle); in drm_rmctx()
469 if (ctx->handle != DRM_KERNEL_CONTEXT) { in drm_rmctx()
470 if (dev->driver->context_dtor) in drm_rmctx()
471 dev->driver->context_dtor(dev, ctx->handle); in drm_rmctx()
472 drm_ctxbitmap_free(dev, ctx->handle); in drm_rmctx()
476 if (!list_empty(&dev->ctxlist)) { in drm_rmctx()
479 list_for_each_entry_safe(pos, n, &dev->ctxlist, head) { in drm_rmctx()
480 if (pos->handle == ctx->handle) { in drm_rmctx()
481 list_del(&pos->head); in drm_rmctx()
483 --dev->ctx_count; in drm_rmctx()