2016-12-31 11:20:11 +00:00
|
|
|
/*
|
2019-05-28 09:29:49 +00:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-12-31 11:20:11 +00:00
|
|
|
*
|
2019-05-28 09:29:49 +00:00
|
|
|
* Copyright © 2016 Intel Corporation
|
2016-12-31 11:20:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __I915_GEM_CONTEXT_H__
|
|
|
|
#define __I915_GEM_CONTEXT_H__
|
|
|
|
|
2019-03-08 13:25:17 +00:00
|
|
|
#include "i915_gem_context_types.h"
|
2016-12-31 11:20:11 +00:00
|
|
|
|
2019-04-24 17:48:39 +00:00
|
|
|
#include "gt/intel_context.h"
|
|
|
|
|
2018-02-13 14:18:33 +00:00
|
|
|
#include "i915_gem.h"
|
2018-05-24 15:06:20 +00:00
|
|
|
#include "i915_scheduler.h"
|
2019-02-05 09:50:28 +00:00
|
|
|
#include "intel_device_info.h"
|
2018-02-13 14:18:33 +00:00
|
|
|
|
2016-12-31 11:20:11 +00:00
|
|
|
struct drm_device;
|
|
|
|
struct drm_file;
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_is_closed(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(CONTEXT_CLOSED, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_closed(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
GEM_BUG_ON(i915_gem_context_is_closed(ctx));
|
2018-09-11 13:22:06 +00:00
|
|
|
set_bit(CONTEXT_CLOSED, &ctx->flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_no_error_capture(const struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
return test_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_no_error_capture(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
set_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_clear_no_error_capture(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
clear_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_is_bannable(const struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
return test_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_bannable(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
set_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_clear_bannable(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
clear_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 10:58:21 +00:00
|
|
|
static inline bool i915_gem_context_is_recoverable(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_recoverable(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
set_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_clear_recoverable(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
clear_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
|
|
|
|
}
|
|
|
|
|
2016-12-31 11:20:11 +00:00
|
|
|
static inline bool i915_gem_context_is_banned(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(CONTEXT_BANNED, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_banned(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
set_bit(CONTEXT_BANNED, &ctx->flags);
|
2016-12-31 11:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_force_single_submission(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_force_single_submission(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
__set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
static inline bool
|
|
|
|
i915_gem_context_user_engines(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(CONTEXT_USER_ENGINES, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
i915_gem_context_set_user_engines(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
set_bit(CONTEXT_USER_ENGINES, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
i915_gem_context_clear_user_engines(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
clear_bit(CONTEXT_USER_ENGINES, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
2017-01-06 15:20:13 +00:00
|
|
|
static inline bool i915_gem_context_is_kernel(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return !ctx->file_priv;
|
|
|
|
}
|
|
|
|
|
2016-12-31 11:20:11 +00:00
|
|
|
/* i915_gem_context.c */
|
2017-06-20 11:05:45 +00:00
|
|
|
int __must_check i915_gem_contexts_init(struct drm_i915_private *dev_priv);
|
|
|
|
void i915_gem_contexts_fini(struct drm_i915_private *dev_priv);
|
|
|
|
|
|
|
|
int i915_gem_context_open(struct drm_i915_private *i915,
|
|
|
|
struct drm_file *file);
|
|
|
|
void i915_gem_context_close(struct drm_file *file);
|
|
|
|
|
2017-06-20 11:05:46 +00:00
|
|
|
void i915_gem_context_release(struct kref *ctx_ref);
|
2016-12-31 11:20:11 +00:00
|
|
|
|
2019-03-22 09:23:23 +00:00
|
|
|
int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
|
2016-12-31 11:20:11 +00:00
|
|
|
int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv);
|
|
|
|
int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv);
|
|
|
|
int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
|
2017-11-10 14:26:33 +00:00
|
|
|
struct i915_gem_context *
|
|
|
|
i915_gem_context_create_kernel(struct drm_i915_private *i915, int prio);
|
|
|
|
|
2017-06-20 11:05:46 +00:00
|
|
|
static inline struct i915_gem_context *
|
|
|
|
i915_gem_context_get(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
kref_get(&ctx->ref);
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_put(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
kref_put(&ctx->ref, i915_gem_context_release);
|
|
|
|
}
|
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
static inline struct i915_gem_engines *
|
|
|
|
i915_gem_context_engines(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return rcu_dereference_protected(ctx->engines,
|
|
|
|
lockdep_is_held(&ctx->engines_mutex));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct i915_gem_engines *
|
|
|
|
i915_gem_context_lock_engines(struct i915_gem_context *ctx)
|
|
|
|
__acquires(&ctx->engines_mutex)
|
|
|
|
{
|
|
|
|
mutex_lock(&ctx->engines_mutex);
|
|
|
|
return i915_gem_context_engines(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
i915_gem_context_unlock_engines(struct i915_gem_context *ctx)
|
|
|
|
__releases(&ctx->engines_mutex)
|
|
|
|
{
|
|
|
|
mutex_unlock(&ctx->engines_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct intel_context *
|
|
|
|
i915_gem_context_get_engine(struct i915_gem_context *ctx, unsigned int idx)
|
|
|
|
{
|
|
|
|
struct intel_context *ce = ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
rcu_read_lock(); {
|
|
|
|
struct i915_gem_engines *e = rcu_dereference(ctx->engines);
|
|
|
|
if (likely(idx < e->num_engines && e->engines[idx]))
|
|
|
|
ce = intel_context_get(e->engines[idx]);
|
|
|
|
} rcu_read_unlock();
|
|
|
|
|
|
|
|
return ce;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
i915_gem_engines_iter_init(struct i915_gem_engines_iter *it,
|
|
|
|
struct i915_gem_engines *engines)
|
|
|
|
{
|
|
|
|
GEM_BUG_ON(!engines);
|
|
|
|
it->engines = engines;
|
|
|
|
it->idx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct intel_context *
|
|
|
|
i915_gem_engines_iter_next(struct i915_gem_engines_iter *it);
|
|
|
|
|
|
|
|
#define for_each_gem_engine(ce, engines, it) \
|
|
|
|
for (i915_gem_engines_iter_init(&(it), (engines)); \
|
|
|
|
((ce) = i915_gem_engines_iter_next(&(it)));)
|
|
|
|
|
2019-02-28 10:20:34 +00:00
|
|
|
struct i915_lut_handle *i915_lut_handle_alloc(void);
|
|
|
|
void i915_lut_handle_free(struct i915_lut_handle *lut);
|
|
|
|
|
2016-12-31 11:20:11 +00:00
|
|
|
#endif /* !__I915_GEM_CONTEXT_H__ */
|