FILE
i915_gem_context.h
File preview with syntax highlighting.
linux-6.19.14/drivers/gpu/drm/i915/gem/i915_gem_context.h
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 18struct drm_device; 19struct drm_file; 20 21static inline bool i915_gem_context_is_closed(const struct i915_gem_context *ctx) 22{ 23 return test_bit(CONTEXT_CLOSED, &ctx->flags); 24} 25 26static 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, &ctx->flags); 30} 31 32static 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 37static inline void i915_gem_context_set_no_error_capture(struct i915_gem_context *ctx) 38{ 39 set_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags); 40} 41 42static inline void i915_gem_context_clear_no_error_capture(struct i915_gem_context *ctx) 43{ 44 clear_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags); 45} 46 47static 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 52static inline void i915_gem_context_set_bannable(struct i915_gem_context *ctx) 53{ 54 set_bit(UCONTEXT_BANNABLE, &ctx->user_flags); 55} 56 57static inline void i915_gem_context_clear_bannable(struct i915_gem_context *ctx) 58{ 59 clear_bit(UCONTEXT_BANNABLE, &ctx->user_flags); 60} 61 62static 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 67static inline void i915_gem_context_set_recoverable(struct i915_gem_context *ctx) 68{ 69 set_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags); 70} 71 72static inline void i915_gem_context_clear_recoverable(struct i915_gem_context *ctx) 73{ 74 clear_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags); 75} 76 77static 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 82static inline void i915_gem_context_set_persistence(struct i915_gem_context *ctx) 83{ 84 set_bit(UCONTEXT_PERSISTENCE, &ctx->user_flags); 85} 86 87static inline void i915_gem_context_clear_persistence(struct i915_gem_context *ctx) 88{ 89 clear_bit(UCONTEXT_PERSISTENCE, &ctx->user_flags); 90} 91 92static inline bool 93i915_gem_context_user_engines(const struct i915_gem_context *ctx) 94{ 95 return test_bit(CONTEXT_USER_ENGINES, &ctx->flags); 96} 97 98static inline void 99i915_gem_context_set_user_engines(struct i915_gem_context *ctx) 100{ 101 set_bit(CONTEXT_USER_ENGINES, &ctx->flags); 102} 103 104static inline void 105i915_gem_context_clear_user_engines(struct i915_gem_context *ctx) 106{ 107 clear_bit(CONTEXT_USER_ENGINES, &ctx->flags); 108} 109 110static inline bool 111i915_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 */ 117void i915_gem_init__contexts(struct drm_i915_private *i915); 118 119int i915_gem_context_open(struct drm_i915_private *i915, 120 struct drm_file *file); 121void i915_gem_context_close(struct drm_file *file); 122 123void i915_gem_context_release(struct kref *ctx_ref); 124 125int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data, 126 struct drm_file *file); 127int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data, 128 struct drm_file *file); 129 130int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, 131 struct drm_file *file); 132int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, 133 struct drm_file *file); 134int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, 135 struct drm_file *file_priv); 136int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, 137 struct drm_file *file_priv); 138int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data, 139 struct drm_file *file); 140 141struct i915_gem_context * 142i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id); 143 144static inline struct i915_gem_context * 145i915_gem_context_get(struct i915_gem_context *ctx) 146{ 147 kref_get(&ctx->ref); 148 return ctx; 149} 150 151static inline void i915_gem_context_put(struct i915_gem_context *ctx) 152{ 153 kref_put(&ctx->ref, i915_gem_context_release); 154} 155 156static inline struct i915_address_space * 157i915_gem_context_vm(struct i915_gem_context *ctx) 158{ 159 return rcu_dereference_protected(ctx->vm, lockdep_is_held(&ctx->mutex)); 160} 161 162static 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 169static inline struct i915_address_space * 170i915_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(ctx->i915)->ggtt->vm; 177 vm = i915_vm_get(vm); 178 179 return vm; 180} 181 182static inline struct i915_gem_engines * 183i915_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 189static inline struct i915_gem_engines * 190i915_gem_context_lock_engines(struct i915_gem_context *ctx) 191 __acquires(&ctx->engines_mutex) 192{ 193 mutex_lock(&ctx->engines_mutex); 194 return i915_gem_context_engines(ctx); 195} 196 197static inline void 198i915_gem_context_unlock_engines(struct i915_gem_context *ctx) 199 __releases(&ctx->engines_mutex) 200{ 201 mutex_unlock(&ctx->engines_mutex); 202} 203 204static inline struct intel_context * 205i915_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(-ENOENT); 213 else if (likely(idx < e->num_engines && e->engines[idx])) 214 ce = intel_context_get(e->engines[idx]); 215 else 216 ce = ERR_PTR(-EINVAL); 217 } rcu_read_unlock(); 218 219 return ce; 220} 221 222static inline void 223i915_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 230struct intel_context * 231i915_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 237void i915_gem_context_module_exit(void); 238int i915_gem_context_module_init(void); 239 240struct i915_lut_handle *i915_lut_handle_alloc(void); 241void i915_lut_handle_free(struct i915_lut_handle *lut); 242 243int 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__ */
~/
Read-only file preview.