1 /* $NetBSD: i915_gem_context_types.h,v 1.2 2021/12/18 23:45:30 riastradh Exp $ */ 2 3 /* 4 * SPDX-License-Identifier: MIT 5 * 6 * Copyright © 2019 Intel Corporation 7 */ 8 9 #ifndef __I915_GEM_CONTEXT_TYPES_H__ 10 #define __I915_GEM_CONTEXT_TYPES_H__ 11 12 #include <linux/atomic.h> 13 #include <linux/list.h> 14 #include <linux/llist.h> 15 #include <linux/kref.h> 16 #include <linux/mutex.h> 17 #include <linux/radix-tree.h> 18 #include <linux/rbtree.h> 19 #include <linux/rcupdate.h> 20 #include <linux/types.h> 21 22 #include "gt/intel_context_types.h" 23 24 #include "i915_scheduler.h" 25 26 struct pid; 27 28 struct drm_i915_private; 29 struct drm_i915_file_private; 30 struct i915_address_space; 31 struct intel_timeline; 32 struct intel_ring; 33 34 struct i915_gem_engines { 35 struct rcu_head rcu; 36 unsigned int num_engines; 37 struct intel_context *engines[]; 38 }; 39 40 struct i915_gem_engines_iter { 41 unsigned int idx; 42 const struct i915_gem_engines *engines; 43 }; 44 45 /** 46 * struct i915_gem_context - client state 47 * 48 * The struct i915_gem_context represents the combined view of the driver and 49 * logical hardware state for a particular client. 50 */ 51 struct i915_gem_context { 52 /** i915: i915 device backpointer */ 53 struct drm_i915_private *i915; 54 55 /** file_priv: owning file descriptor */ 56 struct drm_i915_file_private *file_priv; 57 58 /** 59 * @engines: User defined engines for this context 60 * 61 * Various uAPI offer the ability to lookup up an 62 * index from this array to select an engine operate on. 63 * 64 * Multiple logically distinct instances of the same engine 65 * may be defined in the array, as well as composite virtual 66 * engines. 67 * 68 * Execbuf uses the I915_EXEC_RING_MASK as an index into this 69 * array to select which HW context + engine to execute on. For 70 * the default array, the user_ring_map[] is used to translate 71 * the legacy uABI onto the approprate index (e.g. both 72 * I915_EXEC_DEFAULT and I915_EXEC_RENDER select the same 73 * context, and I915_EXEC_BSD is weird). For a use defined 74 * array, execbuf uses I915_EXEC_RING_MASK as a plain index. 75 * 76 * User defined by I915_CONTEXT_PARAM_ENGINE (when the 77 * CONTEXT_USER_ENGINES flag is set). 78 */ 79 struct i915_gem_engines __rcu *engines; 80 struct mutex engines_mutex; /* guards writes to engines */ 81 82 struct intel_timeline *timeline; 83 84 /** 85 * @vm: unique address space (GTT) 86 * 87 * In full-ppgtt mode, each context has its own address space ensuring 88 * complete seperation of one client from all others. 89 * 90 * In other modes, this is a NULL pointer with the expectation that 91 * the caller uses the shared global GTT. 92 */ 93 struct i915_address_space __rcu *vm; 94 95 /** 96 * @pid: process id of creator 97 * 98 * Note that who created the context may not be the principle user, 99 * as the context may be shared across a local socket. However, 100 * that should only affect the default context, all contexts created 101 * explicitly by the client are expected to be isolated. 102 */ 103 struct pid *pid; 104 105 /** link: place with &drm_i915_private.context_list */ 106 struct list_head link; 107 struct llist_node free_link; 108 109 /** 110 * @ref: reference count 111 * 112 * A reference to a context is held by both the client who created it 113 * and on each request submitted to the hardware using the request 114 * (to ensure the hardware has access to the state until it has 115 * finished all pending writes). See i915_gem_context_get() and 116 * i915_gem_context_put() for access. 117 */ 118 struct kref ref; 119 120 /** 121 * @rcu: rcu_head for deferred freeing. 122 */ 123 struct rcu_head rcu; 124 125 /** 126 * @user_flags: small set of booleans controlled by the user 127 */ 128 unsigned long user_flags; 129 #define UCONTEXT_NO_ZEROMAP 0 130 #define UCONTEXT_NO_ERROR_CAPTURE 1 131 #define UCONTEXT_BANNABLE 2 132 #define UCONTEXT_RECOVERABLE 3 133 #define UCONTEXT_PERSISTENCE 4 134 135 /** 136 * @flags: small set of booleans 137 */ 138 unsigned long flags; 139 #define CONTEXT_CLOSED 0 140 #define CONTEXT_USER_ENGINES 1 141 142 struct mutex mutex; 143 144 struct i915_sched_attr sched; 145 146 /** guilty_count: How many times this context has caused a GPU hang. */ 147 atomic_t guilty_count; 148 /** 149 * @active_count: How many times this context was active during a GPU 150 * hang, but did not cause it. 151 */ 152 atomic_t active_count; 153 154 /** 155 * @hang_timestamp: The last time(s) this context caused a GPU hang 156 */ 157 unsigned long hang_timestamp[2]; 158 #define CONTEXT_FAST_HANG_JIFFIES (120 * HZ) /* 3 hangs within 120s? Banned! */ 159 160 /** remap_slice: Bitmask of cache lines that need remapping */ 161 u8 remap_slice; 162 163 /** 164 * handles_vma: rbtree to look up our context specific obj/vma for 165 * the user handle. (user handles are per fd, but the binding is 166 * per vm, which may be one per context or shared with the global GTT) 167 */ 168 struct radix_tree_root handles_vma; 169 170 /** 171 * @name: arbitrary name, used for user debug 172 * 173 * A name is constructed for the context from the creator's process 174 * name, pid and user handle in order to uniquely identify the 175 * context in messages. 176 */ 177 char name[TASK_COMM_LEN + 8]; 178 }; 179 180 #endif /* __I915_GEM_CONTEXT_TYPES_H__ */ 181