2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include "mock_context.h"
28 struct i915_gem_context *
29 mock_context(struct drm_i915_private *i915,
32 struct i915_gem_context *ctx;
36 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
41 INIT_LIST_HEAD(&ctx->link);
44 INIT_RADIX_TREE(&ctx->handles_vma, GFP_KERNEL);
45 INIT_LIST_HEAD(&ctx->handles_list);
47 for (n = 0; n < ARRAY_SIZE(ctx->__engine); n++) {
48 struct intel_context *ce = &ctx->__engine[n];
50 ce->gem_context = ctx;
53 ret = ida_simple_get(&i915->contexts.hw_ida,
54 0, MAX_CONTEXT_HW_ID, GFP_KERNEL);
60 ctx->name = kstrdup(name, GFP_KERNEL);
64 ctx->ppgtt = mock_ppgtt(i915, name);
76 i915_gem_context_set_closed(ctx);
77 i915_gem_context_put(ctx);
81 void mock_context_close(struct i915_gem_context *ctx)
86 void mock_init_contexts(struct drm_i915_private *i915)
88 INIT_LIST_HEAD(&i915->contexts.list);
89 ida_init(&i915->contexts.hw_ida);
91 INIT_WORK(&i915->contexts.free_work, contexts_free_worker);
92 init_llist_head(&i915->contexts.free_list);
95 struct i915_gem_context *
96 live_context(struct drm_i915_private *i915, struct drm_file *file)
98 lockdep_assert_held(&i915->drm.struct_mutex);
100 return i915_gem_create_context(i915, file->driver_priv);
103 struct i915_gem_context *
104 kernel_context(struct drm_i915_private *i915)
106 return i915_gem_context_create_kernel(i915, I915_PRIORITY_NORMAL);
109 void kernel_context_close(struct i915_gem_context *ctx)