2017-02-13 17:15:19 +00:00
|
|
|
/*
|
2019-05-28 09:29:49 +00:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-02-13 17:15:19 +00:00
|
|
|
*
|
2019-05-28 09:29:49 +00:00
|
|
|
* Copyright © 2016 Intel Corporation
|
2017-02-13 17:15:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mock_context.h"
|
2019-05-28 09:29:49 +00:00
|
|
|
#include "selftests/mock_gtt.h"
|
2017-02-13 17:15:19 +00:00
|
|
|
|
|
|
|
struct i915_gem_context *
|
|
|
|
mock_context(struct drm_i915_private *i915,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct i915_gem_context *ctx;
|
2019-04-26 16:33:34 +00:00
|
|
|
struct i915_gem_engines *e;
|
2017-02-13 17:15:19 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
kref_init(&ctx->ref);
|
|
|
|
INIT_LIST_HEAD(&ctx->link);
|
|
|
|
ctx->i915 = i915;
|
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
mutex_init(&ctx->engines_mutex);
|
|
|
|
e = default_engines(ctx);
|
|
|
|
if (IS_ERR(e))
|
|
|
|
goto err_free;
|
|
|
|
RCU_INIT_POINTER(ctx->engines, e);
|
2019-03-08 13:25:19 +00:00
|
|
|
|
2017-08-16 08:52:08 +00:00
|
|
|
INIT_RADIX_TREE(&ctx->handles_vma, GFP_KERNEL);
|
2018-09-04 15:31:17 +00:00
|
|
|
INIT_LIST_HEAD(&ctx->hw_id_link);
|
2019-03-08 13:25:16 +00:00
|
|
|
mutex_init(&ctx->mutex);
|
2017-06-16 14:05:16 +00:00
|
|
|
|
2018-09-04 15:31:17 +00:00
|
|
|
ret = i915_gem_context_pin_hw_id(ctx);
|
2017-02-13 17:15:19 +00:00
|
|
|
if (ret < 0)
|
2019-04-26 16:33:34 +00:00
|
|
|
goto err_engines;
|
2017-02-13 17:15:19 +00:00
|
|
|
|
|
|
|
if (name) {
|
2019-06-11 09:12:38 +00:00
|
|
|
struct i915_ppgtt *ppgtt;
|
2019-03-22 09:23:23 +00:00
|
|
|
|
2017-02-13 17:15:19 +00:00
|
|
|
ctx->name = kstrdup(name, GFP_KERNEL);
|
|
|
|
if (!ctx->name)
|
|
|
|
goto err_put;
|
|
|
|
|
2019-03-22 09:23:23 +00:00
|
|
|
ppgtt = mock_ppgtt(i915, name);
|
|
|
|
if (!ppgtt)
|
2017-02-13 17:15:19 +00:00
|
|
|
goto err_put;
|
2019-03-22 09:23:23 +00:00
|
|
|
|
2019-06-11 09:12:37 +00:00
|
|
|
__set_ppgtt(ctx, &ppgtt->vm);
|
|
|
|
i915_vm_put(&ppgtt->vm);
|
2017-02-13 17:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
err_engines:
|
|
|
|
free_engines(rcu_access_pointer(ctx->engines));
|
|
|
|
err_free:
|
2017-02-13 17:15:19 +00:00
|
|
|
kfree(ctx);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
err_put:
|
|
|
|
i915_gem_context_set_closed(ctx);
|
|
|
|
i915_gem_context_put(ctx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mock_context_close(struct i915_gem_context *ctx)
|
|
|
|
{
|
2017-10-12 12:57:26 +00:00
|
|
|
context_close(ctx);
|
2017-02-13 17:15:19 +00:00
|
|
|
}
|
2017-06-20 11:05:46 +00:00
|
|
|
|
|
|
|
void mock_init_contexts(struct drm_i915_private *i915)
|
|
|
|
{
|
2018-09-04 15:31:17 +00:00
|
|
|
init_contexts(i915);
|
2017-06-20 11:05:46 +00:00
|
|
|
}
|
2017-07-21 12:32:34 +00:00
|
|
|
|
|
|
|
struct i915_gem_context *
|
|
|
|
live_context(struct drm_i915_private *i915, struct drm_file *file)
|
|
|
|
{
|
2019-03-21 14:07:08 +00:00
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
int err;
|
|
|
|
|
2017-07-21 12:32:34 +00:00
|
|
|
lockdep_assert_held(&i915->drm.struct_mutex);
|
|
|
|
|
2019-03-22 09:23:25 +00:00
|
|
|
ctx = i915_gem_create_context(i915, 0);
|
2019-03-21 14:07:08 +00:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
err = gem_context_register(ctx, file->driver_priv);
|
2019-03-21 14:07:10 +00:00
|
|
|
if (err < 0)
|
2019-03-21 14:07:08 +00:00
|
|
|
goto err_ctx;
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
err_ctx:
|
|
|
|
context_close(ctx);
|
|
|
|
return ERR_PTR(err);
|
2017-07-21 12:32:34 +00:00
|
|
|
}
|
2018-02-05 15:24:29 +00:00
|
|
|
|
|
|
|
struct i915_gem_context *
|
|
|
|
kernel_context(struct drm_i915_private *i915)
|
|
|
|
{
|
|
|
|
return i915_gem_context_create_kernel(i915, I915_PRIORITY_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void kernel_context_close(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
context_close(ctx);
|
|
|
|
}
|