|
5 | 5 |
|
6 | 6 | #include <drm/ttm/ttm_bo_driver.h>
|
7 | 7 |
|
| 8 | +#include "i915_deps.h" |
8 | 9 | #include "i915_drv.h"
|
9 | 10 | #include "intel_memory_region.h"
|
10 | 11 | #include "intel_region_ttm.h"
|
@@ -41,176 +42,6 @@ void i915_ttm_migrate_set_failure_modes(bool gpu_migration,
|
41 | 42 | }
|
42 | 43 | #endif
|
43 | 44 |
|
44 |
| -/** |
45 |
| - * DOC: Set of utilities to dynamically collect dependencies into a |
46 |
| - * structure which is fed into the GT migration code. |
47 |
| - * |
48 |
| - * Once we can do async unbinding, this is also needed to coalesce |
49 |
| - * the migration fence with the unbind fences if these are coalesced |
50 |
| - * post-migration. |
51 |
| - * |
52 |
| - * While collecting the individual dependencies, we store the refcounted |
53 |
| - * struct dma_fence pointers in a realloc-managed pointer array, since |
54 |
| - * that can be easily fed into a dma_fence_array. Other options are |
55 |
| - * available, like for example an xarray for similarity with drm/sched. |
56 |
| - * Can be changed easily if needed. |
57 |
| - * |
58 |
| - * A struct i915_deps need to be initialized using i915_deps_init(). |
59 |
| - * If i915_deps_add_dependency() or i915_deps_add_resv() return an |
60 |
| - * error code they will internally call i915_deps_fini(), which frees |
61 |
| - * all internal references and allocations. |
62 |
| - * |
63 |
| - * We might want to break this out into a separate file as a utility. |
64 |
| - */ |
65 |
| - |
66 |
| -#define I915_DEPS_MIN_ALLOC_CHUNK 8U |
67 |
| - |
68 |
| -static void i915_deps_reset_fences(struct i915_deps *deps) |
69 |
| -{ |
70 |
| - if (deps->fences != &deps->single) |
71 |
| - kfree(deps->fences); |
72 |
| - deps->num_deps = 0; |
73 |
| - deps->fences_size = 1; |
74 |
| - deps->fences = &deps->single; |
75 |
| -} |
76 |
| - |
77 |
| -static void i915_deps_init(struct i915_deps *deps, gfp_t gfp) |
78 |
| -{ |
79 |
| - deps->fences = NULL; |
80 |
| - deps->gfp = gfp; |
81 |
| - i915_deps_reset_fences(deps); |
82 |
| -} |
83 |
| - |
84 |
| -static void i915_deps_fini(struct i915_deps *deps) |
85 |
| -{ |
86 |
| - unsigned int i; |
87 |
| - |
88 |
| - for (i = 0; i < deps->num_deps; ++i) |
89 |
| - dma_fence_put(deps->fences[i]); |
90 |
| - |
91 |
| - if (deps->fences != &deps->single) |
92 |
| - kfree(deps->fences); |
93 |
| -} |
94 |
| - |
95 |
| -static int i915_deps_grow(struct i915_deps *deps, struct dma_fence *fence, |
96 |
| - const struct ttm_operation_ctx *ctx) |
97 |
| -{ |
98 |
| - int ret; |
99 |
| - |
100 |
| - if (deps->num_deps >= deps->fences_size) { |
101 |
| - unsigned int new_size = 2 * deps->fences_size; |
102 |
| - struct dma_fence **new_fences; |
103 |
| - |
104 |
| - new_size = max(new_size, I915_DEPS_MIN_ALLOC_CHUNK); |
105 |
| - new_fences = kmalloc_array(new_size, sizeof(*new_fences), deps->gfp); |
106 |
| - if (!new_fences) |
107 |
| - goto sync; |
108 |
| - |
109 |
| - memcpy(new_fences, deps->fences, |
110 |
| - deps->fences_size * sizeof(*new_fences)); |
111 |
| - swap(new_fences, deps->fences); |
112 |
| - if (new_fences != &deps->single) |
113 |
| - kfree(new_fences); |
114 |
| - deps->fences_size = new_size; |
115 |
| - } |
116 |
| - deps->fences[deps->num_deps++] = dma_fence_get(fence); |
117 |
| - return 0; |
118 |
| - |
119 |
| -sync: |
120 |
| - if (ctx->no_wait_gpu && !dma_fence_is_signaled(fence)) { |
121 |
| - ret = -EBUSY; |
122 |
| - goto unref; |
123 |
| - } |
124 |
| - |
125 |
| - ret = dma_fence_wait(fence, ctx->interruptible); |
126 |
| - if (ret) |
127 |
| - goto unref; |
128 |
| - |
129 |
| - ret = fence->error; |
130 |
| - if (ret) |
131 |
| - goto unref; |
132 |
| - |
133 |
| - return 0; |
134 |
| - |
135 |
| -unref: |
136 |
| - i915_deps_fini(deps); |
137 |
| - return ret; |
138 |
| -} |
139 |
| - |
140 |
| -static int i915_deps_sync(const struct i915_deps *deps, |
141 |
| - const struct ttm_operation_ctx *ctx) |
142 |
| -{ |
143 |
| - struct dma_fence **fences = deps->fences; |
144 |
| - unsigned int i; |
145 |
| - int ret = 0; |
146 |
| - |
147 |
| - for (i = 0; i < deps->num_deps; ++i, ++fences) { |
148 |
| - if (ctx->no_wait_gpu && !dma_fence_is_signaled(*fences)) { |
149 |
| - ret = -EBUSY; |
150 |
| - break; |
151 |
| - } |
152 |
| - |
153 |
| - ret = dma_fence_wait(*fences, ctx->interruptible); |
154 |
| - if (!ret) |
155 |
| - ret = (*fences)->error; |
156 |
| - if (ret) |
157 |
| - break; |
158 |
| - } |
159 |
| - |
160 |
| - return ret; |
161 |
| -} |
162 |
| - |
163 |
| -static int i915_deps_add_dependency(struct i915_deps *deps, |
164 |
| - struct dma_fence *fence, |
165 |
| - const struct ttm_operation_ctx *ctx) |
166 |
| -{ |
167 |
| - unsigned int i; |
168 |
| - int ret; |
169 |
| - |
170 |
| - if (!fence) |
171 |
| - return 0; |
172 |
| - |
173 |
| - if (dma_fence_is_signaled(fence)) { |
174 |
| - ret = fence->error; |
175 |
| - if (ret) |
176 |
| - i915_deps_fini(deps); |
177 |
| - return ret; |
178 |
| - } |
179 |
| - |
180 |
| - for (i = 0; i < deps->num_deps; ++i) { |
181 |
| - struct dma_fence *entry = deps->fences[i]; |
182 |
| - |
183 |
| - if (!entry->context || entry->context != fence->context) |
184 |
| - continue; |
185 |
| - |
186 |
| - if (dma_fence_is_later(fence, entry)) { |
187 |
| - dma_fence_put(entry); |
188 |
| - deps->fences[i] = dma_fence_get(fence); |
189 |
| - } |
190 |
| - |
191 |
| - return 0; |
192 |
| - } |
193 |
| - |
194 |
| - return i915_deps_grow(deps, fence, ctx); |
195 |
| -} |
196 |
| - |
197 |
| -static int i915_deps_add_resv(struct i915_deps *deps, struct dma_resv *resv, |
198 |
| - const struct ttm_operation_ctx *ctx) |
199 |
| -{ |
200 |
| - struct dma_resv_iter iter; |
201 |
| - struct dma_fence *fence; |
202 |
| - int ret; |
203 |
| - |
204 |
| - dma_resv_assert_held(resv); |
205 |
| - dma_resv_for_each_fence(&iter, resv, true, fence) { |
206 |
| - ret = i915_deps_add_dependency(deps, fence, ctx); |
207 |
| - if (ret) |
208 |
| - return ret; |
209 |
| - } |
210 |
| - |
211 |
| - return 0; |
212 |
| -} |
213 |
| - |
214 | 45 | static enum i915_cache_level
|
215 | 46 | i915_ttm_cache_level(struct drm_i915_private *i915, struct ttm_resource *res,
|
216 | 47 | struct ttm_tt *ttm)
|
|
0 commit comments