2 * SPDX-License-Identifier: MIT
4 * Copyright © 2016 Intel Corporation
7 #include "mock_context.h"
8 #include "selftests/mock_drm.h"
9 #include "selftests/mock_gtt.h"
11 struct i915_gem_context
*
12 mock_context(struct drm_i915_private
*i915
,
15 struct i915_gem_context
*ctx
;
16 struct i915_gem_engines
*e
;
18 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
23 INIT_LIST_HEAD(&ctx
->link
);
26 i915_gem_context_set_persistence(ctx
);
28 mutex_init(&ctx
->engines_mutex
);
29 e
= default_engines(ctx
);
32 RCU_INIT_POINTER(ctx
->engines
, e
);
34 INIT_RADIX_TREE(&ctx
->handles_vma
, GFP_KERNEL
);
35 mutex_init(&ctx
->mutex
);
38 struct i915_ppgtt
*ppgtt
;
40 strncpy(ctx
->name
, name
, sizeof(ctx
->name
));
42 ppgtt
= mock_ppgtt(i915
, name
);
46 mutex_lock(&ctx
->mutex
);
47 __set_ppgtt(ctx
, &ppgtt
->vm
);
48 mutex_unlock(&ctx
->mutex
);
50 i915_vm_put(&ppgtt
->vm
);
60 i915_gem_context_set_closed(ctx
);
61 i915_gem_context_put(ctx
);
65 void mock_context_close(struct i915_gem_context
*ctx
)
70 void mock_init_contexts(struct drm_i915_private
*i915
)
72 init_contexts(&i915
->gem
.contexts
);
75 struct i915_gem_context
*
76 live_context(struct drm_i915_private
*i915
, struct file
*file
)
78 struct i915_gem_context
*ctx
;
82 ctx
= i915_gem_create_context(i915
, 0);
86 err
= gem_context_register(ctx
, to_drm_file(file
)->driver_priv
, &id
);
97 struct i915_gem_context
*
98 kernel_context(struct drm_i915_private
*i915
)
100 struct i915_gem_context
*ctx
;
102 ctx
= i915_gem_create_context(i915
, 0);
106 i915_gem_context_clear_bannable(ctx
);
107 i915_gem_context_set_persistence(ctx
);
112 void kernel_context_close(struct i915_gem_context
*ctx
)