| 1 | /* SPDX-License-Identifier: MIT */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Copyright © 2016 Intel Corporation | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef __I915_GEM_CONTEXT_H__ | 
|---|
| 7 | #define __I915_GEM_CONTEXT_H__ | 
|---|
| 8 |  | 
|---|
| 9 | #include "i915_gem_context_types.h" | 
|---|
| 10 |  | 
|---|
| 11 | #include "gt/intel_context.h" | 
|---|
| 12 |  | 
|---|
| 13 | #include "i915_drv.h" | 
|---|
| 14 | #include "i915_gem.h" | 
|---|
| 15 | #include "i915_scheduler.h" | 
|---|
| 16 | #include "intel_device_info.h" | 
|---|
| 17 |  | 
|---|
| 18 | struct drm_device; | 
|---|
| 19 | struct drm_file; | 
|---|
| 20 |  | 
|---|
| 21 | static inline bool i915_gem_context_is_closed(const struct i915_gem_context *ctx) | 
|---|
| 22 | { | 
|---|
| 23 | return test_bit(CONTEXT_CLOSED, &ctx->flags); | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | static inline void i915_gem_context_set_closed(struct i915_gem_context *ctx) | 
|---|
| 27 | { | 
|---|
| 28 | GEM_BUG_ON(i915_gem_context_is_closed(ctx)); | 
|---|
| 29 | set_bit(CONTEXT_CLOSED, addr: &ctx->flags); | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | static inline bool i915_gem_context_no_error_capture(const struct i915_gem_context *ctx) | 
|---|
| 33 | { | 
|---|
| 34 | return test_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags); | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 | static inline void i915_gem_context_set_no_error_capture(struct i915_gem_context *ctx) | 
|---|
| 38 | { | 
|---|
| 39 | set_bit(UCONTEXT_NO_ERROR_CAPTURE, addr: &ctx->user_flags); | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | static inline void i915_gem_context_clear_no_error_capture(struct i915_gem_context *ctx) | 
|---|
| 43 | { | 
|---|
| 44 | clear_bit(UCONTEXT_NO_ERROR_CAPTURE, addr: &ctx->user_flags); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | static inline bool i915_gem_context_is_bannable(const struct i915_gem_context *ctx) | 
|---|
| 48 | { | 
|---|
| 49 | return test_bit(UCONTEXT_BANNABLE, &ctx->user_flags); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | static inline void i915_gem_context_set_bannable(struct i915_gem_context *ctx) | 
|---|
| 53 | { | 
|---|
| 54 | set_bit(UCONTEXT_BANNABLE, addr: &ctx->user_flags); | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | static inline void i915_gem_context_clear_bannable(struct i915_gem_context *ctx) | 
|---|
| 58 | { | 
|---|
| 59 | clear_bit(UCONTEXT_BANNABLE, addr: &ctx->user_flags); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | static inline bool i915_gem_context_is_recoverable(const struct i915_gem_context *ctx) | 
|---|
| 63 | { | 
|---|
| 64 | return test_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags); | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | static inline void i915_gem_context_set_recoverable(struct i915_gem_context *ctx) | 
|---|
| 68 | { | 
|---|
| 69 | set_bit(UCONTEXT_RECOVERABLE, addr: &ctx->user_flags); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | static inline void i915_gem_context_clear_recoverable(struct i915_gem_context *ctx) | 
|---|
| 73 | { | 
|---|
| 74 | clear_bit(UCONTEXT_RECOVERABLE, addr: &ctx->user_flags); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | static inline bool i915_gem_context_is_persistent(const struct i915_gem_context *ctx) | 
|---|
| 78 | { | 
|---|
| 79 | return test_bit(UCONTEXT_PERSISTENCE, &ctx->user_flags); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | static inline void i915_gem_context_set_persistence(struct i915_gem_context *ctx) | 
|---|
| 83 | { | 
|---|
| 84 | set_bit(UCONTEXT_PERSISTENCE, addr: &ctx->user_flags); | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | static inline void i915_gem_context_clear_persistence(struct i915_gem_context *ctx) | 
|---|
| 88 | { | 
|---|
| 89 | clear_bit(UCONTEXT_PERSISTENCE, addr: &ctx->user_flags); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | static inline bool | 
|---|
| 93 | i915_gem_context_user_engines(const struct i915_gem_context *ctx) | 
|---|
| 94 | { | 
|---|
| 95 | return test_bit(CONTEXT_USER_ENGINES, &ctx->flags); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | static inline void | 
|---|
| 99 | i915_gem_context_set_user_engines(struct i915_gem_context *ctx) | 
|---|
| 100 | { | 
|---|
| 101 | set_bit(CONTEXT_USER_ENGINES, addr: &ctx->flags); | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 | static inline void | 
|---|
| 105 | i915_gem_context_clear_user_engines(struct i915_gem_context *ctx) | 
|---|
| 106 | { | 
|---|
| 107 | clear_bit(CONTEXT_USER_ENGINES, addr: &ctx->flags); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | static inline bool | 
|---|
| 111 | i915_gem_context_uses_protected_content(const struct i915_gem_context *ctx) | 
|---|
| 112 | { | 
|---|
| 113 | return ctx->uses_protected_content; | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | /* i915_gem_context.c */ | 
|---|
| 117 | void i915_gem_init__contexts(struct drm_i915_private *i915); | 
|---|
| 118 |  | 
|---|
| 119 | int i915_gem_context_open(struct drm_i915_private *i915, | 
|---|
| 120 | struct drm_file *file); | 
|---|
| 121 | void i915_gem_context_close(struct drm_file *file); | 
|---|
| 122 |  | 
|---|
| 123 | void i915_gem_context_release(struct kref *ctx_ref); | 
|---|
| 124 |  | 
|---|
| 125 | int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data, | 
|---|
| 126 | struct drm_file *file); | 
|---|
| 127 | int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data, | 
|---|
| 128 | struct drm_file *file); | 
|---|
| 129 |  | 
|---|
| 130 | int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, | 
|---|
| 131 | struct drm_file *file); | 
|---|
| 132 | int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, | 
|---|
| 133 | struct drm_file *file); | 
|---|
| 134 | int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, | 
|---|
| 135 | struct drm_file *file_priv); | 
|---|
| 136 | int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, | 
|---|
| 137 | struct drm_file *file_priv); | 
|---|
| 138 | int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data, | 
|---|
| 139 | struct drm_file *file); | 
|---|
| 140 |  | 
|---|
| 141 | struct i915_gem_context * | 
|---|
| 142 | i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id); | 
|---|
| 143 |  | 
|---|
| 144 | static inline struct i915_gem_context * | 
|---|
| 145 | i915_gem_context_get(struct i915_gem_context *ctx) | 
|---|
| 146 | { | 
|---|
| 147 | kref_get(kref: &ctx->ref); | 
|---|
| 148 | return ctx; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | static inline void i915_gem_context_put(struct i915_gem_context *ctx) | 
|---|
| 152 | { | 
|---|
| 153 | kref_put(kref: &ctx->ref, release: i915_gem_context_release); | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | static inline struct i915_address_space * | 
|---|
| 157 | i915_gem_context_vm(struct i915_gem_context *ctx) | 
|---|
| 158 | { | 
|---|
| 159 | return rcu_dereference_protected(ctx->vm, lockdep_is_held(&ctx->mutex)); | 
|---|
| 160 | } | 
|---|
| 161 |  | 
|---|
| 162 | static inline bool i915_gem_context_has_full_ppgtt(struct i915_gem_context *ctx) | 
|---|
| 163 | { | 
|---|
| 164 | GEM_BUG_ON(!!ctx->vm != HAS_FULL_PPGTT(ctx->i915)); | 
|---|
| 165 |  | 
|---|
| 166 | return !!ctx->vm; | 
|---|
| 167 | } | 
|---|
| 168 |  | 
|---|
| 169 | static inline struct i915_address_space * | 
|---|
| 170 | i915_gem_context_get_eb_vm(struct i915_gem_context *ctx) | 
|---|
| 171 | { | 
|---|
| 172 | struct i915_address_space *vm; | 
|---|
| 173 |  | 
|---|
| 174 | vm = ctx->vm; | 
|---|
| 175 | if (!vm) | 
|---|
| 176 | vm = &to_gt(i915: ctx->i915)->ggtt->vm; | 
|---|
| 177 | vm = i915_vm_get(vm); | 
|---|
| 178 |  | 
|---|
| 179 | return vm; | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | static inline struct i915_gem_engines * | 
|---|
| 183 | i915_gem_context_engines(struct i915_gem_context *ctx) | 
|---|
| 184 | { | 
|---|
| 185 | return rcu_dereference_protected(ctx->engines, | 
|---|
| 186 | lockdep_is_held(&ctx->engines_mutex)); | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | static inline struct i915_gem_engines * | 
|---|
| 190 | i915_gem_context_lock_engines(struct i915_gem_context *ctx) | 
|---|
| 191 | __acquires(&ctx->engines_mutex) | 
|---|
| 192 | { | 
|---|
| 193 | mutex_lock(lock: &ctx->engines_mutex); | 
|---|
| 194 | return i915_gem_context_engines(ctx); | 
|---|
| 195 | } | 
|---|
| 196 |  | 
|---|
| 197 | static inline void | 
|---|
| 198 | i915_gem_context_unlock_engines(struct i915_gem_context *ctx) | 
|---|
| 199 | __releases(&ctx->engines_mutex) | 
|---|
| 200 | { | 
|---|
| 201 | mutex_unlock(lock: &ctx->engines_mutex); | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 204 | static inline struct intel_context * | 
|---|
| 205 | i915_gem_context_get_engine(struct i915_gem_context *ctx, unsigned int idx) | 
|---|
| 206 | { | 
|---|
| 207 | struct intel_context *ce; | 
|---|
| 208 |  | 
|---|
| 209 | rcu_read_lock(); { | 
|---|
| 210 | struct i915_gem_engines *e = rcu_dereference(ctx->engines); | 
|---|
| 211 | if (unlikely(!e)) /* context was closed! */ | 
|---|
| 212 | ce = ERR_PTR(error: -ENOENT); | 
|---|
| 213 | else if (likely(idx < e->num_engines && e->engines[idx])) | 
|---|
| 214 | ce = intel_context_get(ce: e->engines[idx]); | 
|---|
| 215 | else | 
|---|
| 216 | ce = ERR_PTR(error: -EINVAL); | 
|---|
| 217 | } rcu_read_unlock(); | 
|---|
| 218 |  | 
|---|
| 219 | return ce; | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | static inline void | 
|---|
| 223 | i915_gem_engines_iter_init(struct i915_gem_engines_iter *it, | 
|---|
| 224 | struct i915_gem_engines *engines) | 
|---|
| 225 | { | 
|---|
| 226 | it->engines = engines; | 
|---|
| 227 | it->idx = 0; | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | struct intel_context * | 
|---|
| 231 | i915_gem_engines_iter_next(struct i915_gem_engines_iter *it); | 
|---|
| 232 |  | 
|---|
| 233 | #define for_each_gem_engine(ce, engines, it) \ | 
|---|
| 234 | for (i915_gem_engines_iter_init(&(it), (engines)); \ | 
|---|
| 235 | ((ce) = i915_gem_engines_iter_next(&(it)));) | 
|---|
| 236 |  | 
|---|
| 237 | void i915_gem_context_module_exit(void); | 
|---|
| 238 | int i915_gem_context_module_init(void); | 
|---|
| 239 |  | 
|---|
| 240 | struct i915_lut_handle *i915_lut_handle_alloc(void); | 
|---|
| 241 | void i915_lut_handle_free(struct i915_lut_handle *lut); | 
|---|
| 242 |  | 
|---|
| 243 | int i915_gem_user_to_context_sseu(struct intel_gt *gt, | 
|---|
| 244 | const struct drm_i915_gem_context_param_sseu *user, | 
|---|
| 245 | struct intel_sseu *context); | 
|---|
| 246 |  | 
|---|
| 247 | #endif /* !__I915_GEM_CONTEXT_H__ */ | 
|---|
| 248 |  | 
|---|