0001
0002
0003
0004
0005
0006
0007 #ifndef __I915_GEM_CONTEXT_H__
0008 #define __I915_GEM_CONTEXT_H__
0009
0010 #include "i915_gem_context_types.h"
0011
0012 #include "gt/intel_context.h"
0013
0014 #include "i915_drv.h"
0015 #include "i915_gem.h"
0016 #include "i915_scheduler.h"
0017 #include "intel_device_info.h"
0018
0019 struct drm_device;
0020 struct drm_file;
0021
0022 static inline bool i915_gem_context_is_closed(const struct i915_gem_context *ctx)
0023 {
0024 return test_bit(CONTEXT_CLOSED, &ctx->flags);
0025 }
0026
0027 static inline void i915_gem_context_set_closed(struct i915_gem_context *ctx)
0028 {
0029 GEM_BUG_ON(i915_gem_context_is_closed(ctx));
0030 set_bit(CONTEXT_CLOSED, &ctx->flags);
0031 }
0032
0033 static inline bool i915_gem_context_no_error_capture(const struct i915_gem_context *ctx)
0034 {
0035 return test_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
0036 }
0037
0038 static inline void i915_gem_context_set_no_error_capture(struct i915_gem_context *ctx)
0039 {
0040 set_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
0041 }
0042
0043 static inline void i915_gem_context_clear_no_error_capture(struct i915_gem_context *ctx)
0044 {
0045 clear_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
0046 }
0047
0048 static inline bool i915_gem_context_is_bannable(const struct i915_gem_context *ctx)
0049 {
0050 return test_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
0051 }
0052
0053 static inline void i915_gem_context_set_bannable(struct i915_gem_context *ctx)
0054 {
0055 set_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
0056 }
0057
0058 static inline void i915_gem_context_clear_bannable(struct i915_gem_context *ctx)
0059 {
0060 clear_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
0061 }
0062
0063 static inline bool i915_gem_context_is_recoverable(const struct i915_gem_context *ctx)
0064 {
0065 return test_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
0066 }
0067
0068 static inline void i915_gem_context_set_recoverable(struct i915_gem_context *ctx)
0069 {
0070 set_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
0071 }
0072
0073 static inline void i915_gem_context_clear_recoverable(struct i915_gem_context *ctx)
0074 {
0075 clear_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
0076 }
0077
0078 static inline bool i915_gem_context_is_persistent(const struct i915_gem_context *ctx)
0079 {
0080 return test_bit(UCONTEXT_PERSISTENCE, &ctx->user_flags);
0081 }
0082
0083 static inline void i915_gem_context_set_persistence(struct i915_gem_context *ctx)
0084 {
0085 set_bit(UCONTEXT_PERSISTENCE, &ctx->user_flags);
0086 }
0087
0088 static inline void i915_gem_context_clear_persistence(struct i915_gem_context *ctx)
0089 {
0090 clear_bit(UCONTEXT_PERSISTENCE, &ctx->user_flags);
0091 }
0092
0093 static inline bool
0094 i915_gem_context_user_engines(const struct i915_gem_context *ctx)
0095 {
0096 return test_bit(CONTEXT_USER_ENGINES, &ctx->flags);
0097 }
0098
0099 static inline void
0100 i915_gem_context_set_user_engines(struct i915_gem_context *ctx)
0101 {
0102 set_bit(CONTEXT_USER_ENGINES, &ctx->flags);
0103 }
0104
0105 static inline void
0106 i915_gem_context_clear_user_engines(struct i915_gem_context *ctx)
0107 {
0108 clear_bit(CONTEXT_USER_ENGINES, &ctx->flags);
0109 }
0110
0111 static inline bool
0112 i915_gem_context_uses_protected_content(const struct i915_gem_context *ctx)
0113 {
0114 return ctx->uses_protected_content;
0115 }
0116
0117
0118 void i915_gem_init__contexts(struct drm_i915_private *i915);
0119
0120 int i915_gem_context_open(struct drm_i915_private *i915,
0121 struct drm_file *file);
0122 void i915_gem_context_close(struct drm_file *file);
0123
0124 void i915_gem_context_release(struct kref *ctx_ref);
0125
0126 int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
0127 struct drm_file *file);
0128 int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data,
0129 struct drm_file *file);
0130
0131 int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
0132 struct drm_file *file);
0133 int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
0134 struct drm_file *file);
0135 int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
0136 struct drm_file *file_priv);
0137 int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
0138 struct drm_file *file_priv);
0139 int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data,
0140 struct drm_file *file);
0141
0142 struct i915_gem_context *
0143 i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id);
0144
0145 static inline struct i915_gem_context *
0146 i915_gem_context_get(struct i915_gem_context *ctx)
0147 {
0148 kref_get(&ctx->ref);
0149 return ctx;
0150 }
0151
0152 static inline void i915_gem_context_put(struct i915_gem_context *ctx)
0153 {
0154 kref_put(&ctx->ref, i915_gem_context_release);
0155 }
0156
0157 static inline struct i915_address_space *
0158 i915_gem_context_vm(struct i915_gem_context *ctx)
0159 {
0160 return rcu_dereference_protected(ctx->vm, lockdep_is_held(&ctx->mutex));
0161 }
0162
0163 static inline bool i915_gem_context_has_full_ppgtt(struct i915_gem_context *ctx)
0164 {
0165 GEM_BUG_ON(!!ctx->vm != HAS_FULL_PPGTT(ctx->i915));
0166
0167 return !!ctx->vm;
0168 }
0169
0170 static inline struct i915_address_space *
0171 i915_gem_context_get_eb_vm(struct i915_gem_context *ctx)
0172 {
0173 struct i915_address_space *vm;
0174
0175 vm = ctx->vm;
0176 if (!vm)
0177 vm = &to_gt(ctx->i915)->ggtt->vm;
0178 vm = i915_vm_get(vm);
0179
0180 return vm;
0181 }
0182
0183 static inline struct i915_gem_engines *
0184 i915_gem_context_engines(struct i915_gem_context *ctx)
0185 {
0186 return rcu_dereference_protected(ctx->engines,
0187 lockdep_is_held(&ctx->engines_mutex));
0188 }
0189
0190 static inline struct i915_gem_engines *
0191 i915_gem_context_lock_engines(struct i915_gem_context *ctx)
0192 __acquires(&ctx->engines_mutex)
0193 {
0194 mutex_lock(&ctx->engines_mutex);
0195 return i915_gem_context_engines(ctx);
0196 }
0197
0198 static inline void
0199 i915_gem_context_unlock_engines(struct i915_gem_context *ctx)
0200 __releases(&ctx->engines_mutex)
0201 {
0202 mutex_unlock(&ctx->engines_mutex);
0203 }
0204
0205 static inline struct intel_context *
0206 i915_gem_context_get_engine(struct i915_gem_context *ctx, unsigned int idx)
0207 {
0208 struct intel_context *ce;
0209
0210 rcu_read_lock(); {
0211 struct i915_gem_engines *e = rcu_dereference(ctx->engines);
0212 if (unlikely(!e))
0213 ce = ERR_PTR(-ENOENT);
0214 else if (likely(idx < e->num_engines && e->engines[idx]))
0215 ce = intel_context_get(e->engines[idx]);
0216 else
0217 ce = ERR_PTR(-EINVAL);
0218 } rcu_read_unlock();
0219
0220 return ce;
0221 }
0222
0223 static inline void
0224 i915_gem_engines_iter_init(struct i915_gem_engines_iter *it,
0225 struct i915_gem_engines *engines)
0226 {
0227 it->engines = engines;
0228 it->idx = 0;
0229 }
0230
0231 struct intel_context *
0232 i915_gem_engines_iter_next(struct i915_gem_engines_iter *it);
0233
0234 #define for_each_gem_engine(ce, engines, it) \
0235 for (i915_gem_engines_iter_init(&(it), (engines)); \
0236 ((ce) = i915_gem_engines_iter_next(&(it)));)
0237
0238 void i915_gem_context_module_exit(void);
0239 int i915_gem_context_module_init(void);
0240
0241 struct i915_lut_handle *i915_lut_handle_alloc(void);
0242 void i915_lut_handle_free(struct i915_lut_handle *lut);
0243
0244 int i915_gem_user_to_context_sseu(struct intel_gt *gt,
0245 const struct drm_i915_gem_context_param_sseu *user,
0246 struct intel_sseu *context);
0247
0248 #endif