hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
....@@ -35,6 +35,42 @@
3535
3636 #define VMW_RES_HT_ORDER 12
3737
38
+/*
39
+ * Helper macro to get dx_ctx_node if available otherwise print an error
40
+ * message. This is for use in command verifier function where if dx_ctx_node
41
+ * is not set then command is invalid.
42
+ */
43
+#define VMW_GET_CTX_NODE(__sw_context) \
44
+({ \
45
+ __sw_context->dx_ctx_node ? __sw_context->dx_ctx_node : ({ \
46
+ VMW_DEBUG_USER("SM context is not set at %s\n", __func__); \
47
+ __sw_context->dx_ctx_node; \
48
+ }); \
49
+})
50
+
51
+#define VMW_DECLARE_CMD_VAR(__var, __type) \
52
+ struct { \
53
+ SVGA3dCmdHeader header; \
54
+ __type body; \
55
+ } __var
56
+
57
+/**
58
+ * struct vmw_relocation - Buffer object relocation
59
+ *
60
+ * @head: List head for the command submission context's relocation list
61
+ * @vbo: Non ref-counted pointer to buffer object
62
+ * @mob_loc: Pointer to location for mob id to be modified
63
+ * @location: Pointer to location for guest pointer to be modified
64
+ */
65
+struct vmw_relocation {
66
+ struct list_head head;
67
+ struct vmw_buffer_object *vbo;
68
+ union {
69
+ SVGAMobId *mob_loc;
70
+ SVGAGuestPtr *location;
71
+ };
72
+};
73
+
3874 /**
3975 * enum vmw_resource_relocation_type - Relocation type for resources
4076 *
....@@ -42,9 +78,8 @@
4278 * command stream is replaced with the actual id after validation.
4379 * @vmw_res_rel_nop: NOP relocation. The command is unconditionally replaced
4480 * with a NOP.
45
- * @vmw_res_rel_cond_nop: Conditional NOP relocation. If the resource id
46
- * after validation is -1, the command is replaced with a NOP. Otherwise no
47
- * action.
81
+ * @vmw_res_rel_cond_nop: Conditional NOP relocation. If the resource id after
82
+ * validation is -1, the command is replaced with a NOP. Otherwise no action.
4883 */
4984 enum vmw_resource_relocation_type {
5085 vmw_res_rel_normal,
....@@ -58,8 +93,8 @@
5893 *
5994 * @head: List head for the software context's relocation list.
6095 * @res: Non-ref-counted pointer to the resource.
61
- * @offset: Offset of single byte entries into the command buffer where the
62
- * id that needs fixup is located.
96
+ * @offset: Offset of single byte entries into the command buffer where the id
97
+ * that needs fixup is located.
6398 * @rel_type: Type of relocation.
6499 */
65100 struct vmw_resource_relocation {
....@@ -70,34 +105,18 @@
70105 };
71106
72107 /**
73
- * struct vmw_resource_val_node - Validation info for resources
108
+ * struct vmw_ctx_validation_info - Extra validation metadata for contexts
74109 *
75
- * @head: List head for the software context's resource list.
76
- * @hash: Hash entry for quick resouce to val_node lookup.
77
- * @res: Ref-counted pointer to the resource.
78
- * @switch_backup: Boolean whether to switch backup buffer on unreserve.
79
- * @new_backup: Refcounted pointer to the new backup buffer.
80
- * @staged_bindings: If @res is a context, tracks bindings set up during
81
- * the command batch. Otherwise NULL.
82
- * @new_backup_offset: New backup buffer offset if @new_backup is non-NUll.
83
- * @first_usage: Set to true the first time the resource is referenced in
84
- * the command stream.
85
- * @switching_backup: The command stream provides a new backup buffer for a
86
- * resource.
87
- * @no_buffer_needed: This means @switching_backup is true on first buffer
88
- * reference. So resource reservation does not need to allocate a backup
89
- * buffer for the resource.
110
+ * @head: List head of context list
111
+ * @ctx: The context resource
112
+ * @cur: The context's persistent binding state
113
+ * @staged: The binding state changes of this command buffer
90114 */
91
-struct vmw_resource_val_node {
115
+struct vmw_ctx_validation_info {
92116 struct list_head head;
93
- struct drm_hash_item hash;
94
- struct vmw_resource *res;
95
- struct vmw_buffer_object *new_backup;
96
- struct vmw_ctx_binding_state *staged_bindings;
97
- unsigned long new_backup_offset;
98
- u32 first_usage : 1;
99
- u32 switching_backup : 1;
100
- u32 no_buffer_needed : 1;
117
+ struct vmw_resource *ctx;
118
+ struct vmw_ctx_binding_state *cur;
119
+ struct vmw_ctx_binding_state *staged;
101120 };
102121
103122 /**
....@@ -127,10 +146,6 @@
127146 struct vmw_sw_context *sw_context,
128147 SVGAMobId *id,
129148 struct vmw_buffer_object **vmw_bo_p);
130
-static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context,
131
- struct vmw_buffer_object *vbo,
132
- bool validate_as_mob,
133
- uint32_t *p_val_node);
134149 /**
135150 * vmw_ptr_diff - Compute the offset from a to b in bytes
136151 *
....@@ -145,74 +160,65 @@
145160 }
146161
147162 /**
148
- * vmw_resources_unreserve - unreserve resources previously reserved for
149
- * command submission.
163
+ * vmw_execbuf_bindings_commit - Commit modified binding state
150164 *
151
- * @sw_context: pointer to the software context
152
- * @backoff: Whether command submission failed.
165
+ * @sw_context: The command submission context
166
+ * @backoff: Whether this is part of the error path and binding state changes
167
+ * should be ignored
153168 */
154
-static void vmw_resources_unreserve(struct vmw_sw_context *sw_context,
155
- bool backoff)
169
+static void vmw_execbuf_bindings_commit(struct vmw_sw_context *sw_context,
170
+ bool backoff)
156171 {
157
- struct vmw_resource_val_node *val;
158
- struct list_head *list = &sw_context->resource_list;
172
+ struct vmw_ctx_validation_info *entry;
159173
160
- if (sw_context->dx_query_mob && !backoff)
161
- vmw_context_bind_dx_query(sw_context->dx_query_ctx,
162
- sw_context->dx_query_mob);
174
+ list_for_each_entry(entry, &sw_context->ctx_list, head) {
175
+ if (!backoff)
176
+ vmw_binding_state_commit(entry->cur, entry->staged);
163177
164
- list_for_each_entry(val, list, head) {
165
- struct vmw_resource *res = val->res;
166
- bool switch_backup =
167
- (backoff) ? false : val->switching_backup;
168
-
169
- /*
170
- * Transfer staged context bindings to the
171
- * persistent context binding tracker.
172
- */
173
- if (unlikely(val->staged_bindings)) {
174
- if (!backoff) {
175
- vmw_binding_state_commit
176
- (vmw_context_binding_state(val->res),
177
- val->staged_bindings);
178
- }
179
-
180
- if (val->staged_bindings != sw_context->staged_bindings)
181
- vmw_binding_state_free(val->staged_bindings);
182
- else
183
- sw_context->staged_bindings_inuse = false;
184
- val->staged_bindings = NULL;
185
- }
186
- vmw_resource_unreserve(res, switch_backup, val->new_backup,
187
- val->new_backup_offset);
188
- vmw_bo_unreference(&val->new_backup);
178
+ if (entry->staged != sw_context->staged_bindings)
179
+ vmw_binding_state_free(entry->staged);
180
+ else
181
+ sw_context->staged_bindings_inuse = false;
189182 }
183
+
184
+ /* List entries are freed with the validation context */
185
+ INIT_LIST_HEAD(&sw_context->ctx_list);
190186 }
191187
192188 /**
193
- * vmw_cmd_ctx_first_setup - Perform the setup needed when a context is
194
- * added to the validate list.
189
+ * vmw_bind_dx_query_mob - Bind the DX query MOB if referenced
190
+ *
191
+ * @sw_context: The command submission context
192
+ */
193
+static void vmw_bind_dx_query_mob(struct vmw_sw_context *sw_context)
194
+{
195
+ if (sw_context->dx_query_mob)
196
+ vmw_context_bind_dx_query(sw_context->dx_query_ctx,
197
+ sw_context->dx_query_mob);
198
+}
199
+
200
+/**
201
+ * vmw_cmd_ctx_first_setup - Perform the setup needed when a context is added to
202
+ * the validate list.
195203 *
196204 * @dev_priv: Pointer to the device private:
197
- * @sw_context: The validation context:
198
- * @node: The validation node holding this context.
205
+ * @sw_context: The command submission context
206
+ * @node: The validation node holding the context resource metadata
199207 */
200208 static int vmw_cmd_ctx_first_setup(struct vmw_private *dev_priv,
201209 struct vmw_sw_context *sw_context,
202
- struct vmw_resource_val_node *node)
210
+ struct vmw_resource *res,
211
+ struct vmw_ctx_validation_info *node)
203212 {
204213 int ret;
205214
206
- ret = vmw_resource_context_res_add(dev_priv, sw_context, node->res);
215
+ ret = vmw_resource_context_res_add(dev_priv, sw_context, res);
207216 if (unlikely(ret != 0))
208217 goto out_err;
209218
210219 if (!sw_context->staged_bindings) {
211
- sw_context->staged_bindings =
212
- vmw_binding_state_alloc(dev_priv);
220
+ sw_context->staged_bindings = vmw_binding_state_alloc(dev_priv);
213221 if (IS_ERR(sw_context->staged_bindings)) {
214
- DRM_ERROR("Failed to allocate context binding "
215
- "information.\n");
216222 ret = PTR_ERR(sw_context->staged_bindings);
217223 sw_context->staged_bindings = NULL;
218224 goto out_err;
....@@ -220,96 +226,158 @@
220226 }
221227
222228 if (sw_context->staged_bindings_inuse) {
223
- node->staged_bindings = vmw_binding_state_alloc(dev_priv);
224
- if (IS_ERR(node->staged_bindings)) {
225
- DRM_ERROR("Failed to allocate context binding "
226
- "information.\n");
227
- ret = PTR_ERR(node->staged_bindings);
228
- node->staged_bindings = NULL;
229
+ node->staged = vmw_binding_state_alloc(dev_priv);
230
+ if (IS_ERR(node->staged)) {
231
+ ret = PTR_ERR(node->staged);
232
+ node->staged = NULL;
229233 goto out_err;
230234 }
231235 } else {
232
- node->staged_bindings = sw_context->staged_bindings;
236
+ node->staged = sw_context->staged_bindings;
233237 sw_context->staged_bindings_inuse = true;
234238 }
235239
240
+ node->ctx = res;
241
+ node->cur = vmw_context_binding_state(res);
242
+ list_add_tail(&node->head, &sw_context->ctx_list);
243
+
236244 return 0;
245
+
237246 out_err:
238247 return ret;
239248 }
240249
241250 /**
242
- * vmw_resource_val_add - Add a resource to the software context's
243
- * resource list if it's not already on it.
251
+ * vmw_execbuf_res_size - calculate extra size fore the resource validation node
244252 *
245
- * @sw_context: Pointer to the software context.
246
- * @res: Pointer to the resource.
247
- * @p_node On successful return points to a valid pointer to a
248
- * struct vmw_resource_val_node, if non-NULL on entry.
253
+ * @dev_priv: Pointer to the device private struct.
254
+ * @res_type: The resource type.
255
+ *
256
+ * Guest-backed contexts and DX contexts require extra size to store execbuf
257
+ * private information in the validation node. Typically the binding manager
258
+ * associated data structures.
259
+ *
260
+ * Returns: The extra size requirement based on resource type.
249261 */
250
-static int vmw_resource_val_add(struct vmw_sw_context *sw_context,
251
- struct vmw_resource *res,
252
- struct vmw_resource_val_node **p_node)
262
+static unsigned int vmw_execbuf_res_size(struct vmw_private *dev_priv,
263
+ enum vmw_res_type res_type)
253264 {
254
- struct vmw_private *dev_priv = res->dev_priv;
255
- struct vmw_resource_val_node *node;
256
- struct drm_hash_item *hash;
257
- int ret;
258
-
259
- if (likely(drm_ht_find_item(&sw_context->res_ht, (unsigned long) res,
260
- &hash) == 0)) {
261
- node = container_of(hash, struct vmw_resource_val_node, hash);
262
- node->first_usage = false;
263
- if (unlikely(p_node != NULL))
264
- *p_node = node;
265
- return 0;
266
- }
267
-
268
- node = kzalloc(sizeof(*node), GFP_KERNEL);
269
- if (unlikely(!node)) {
270
- DRM_ERROR("Failed to allocate a resource validation "
271
- "entry.\n");
272
- return -ENOMEM;
273
- }
274
-
275
- node->hash.key = (unsigned long) res;
276
- ret = drm_ht_insert_item(&sw_context->res_ht, &node->hash);
277
- if (unlikely(ret != 0)) {
278
- DRM_ERROR("Failed to initialize a resource validation "
279
- "entry.\n");
280
- kfree(node);
281
- return ret;
282
- }
283
- node->res = vmw_resource_reference(res);
284
- node->first_usage = true;
285
- if (unlikely(p_node != NULL))
286
- *p_node = node;
287
-
288
- if (!dev_priv->has_mob) {
289
- list_add_tail(&node->head, &sw_context->resource_list);
290
- return 0;
291
- }
292
-
293
- switch (vmw_res_type(res)) {
294
- case vmw_res_context:
295
- case vmw_res_dx_context:
296
- list_add(&node->head, &sw_context->ctx_resource_list);
297
- ret = vmw_cmd_ctx_first_setup(dev_priv, sw_context, node);
298
- break;
299
- case vmw_res_cotable:
300
- list_add_tail(&node->head, &sw_context->ctx_resource_list);
301
- break;
302
- default:
303
- list_add_tail(&node->head, &sw_context->resource_list);
304
- break;
305
- }
306
-
307
- return ret;
265
+ return (res_type == vmw_res_dx_context ||
266
+ (res_type == vmw_res_context && dev_priv->has_mob)) ?
267
+ sizeof(struct vmw_ctx_validation_info) : 0;
308268 }
309269
310270 /**
311
- * vmw_view_res_val_add - Add a view and the surface it's pointing to
312
- * to the validation list
271
+ * vmw_execbuf_rcache_update - Update a resource-node cache entry
272
+ *
273
+ * @rcache: Pointer to the entry to update.
274
+ * @res: Pointer to the resource.
275
+ * @private: Pointer to the execbuf-private space in the resource validation
276
+ * node.
277
+ */
278
+static void vmw_execbuf_rcache_update(struct vmw_res_cache_entry *rcache,
279
+ struct vmw_resource *res,
280
+ void *private)
281
+{
282
+ rcache->res = res;
283
+ rcache->private = private;
284
+ rcache->valid = 1;
285
+ rcache->valid_handle = 0;
286
+}
287
+
288
+/**
289
+ * vmw_execbuf_res_noref_val_add - Add a resource described by an unreferenced
290
+ * rcu-protected pointer to the validation list.
291
+ *
292
+ * @sw_context: Pointer to the software context.
293
+ * @res: Unreferenced rcu-protected pointer to the resource.
294
+ * @dirty: Whether to change dirty status.
295
+ *
296
+ * Returns: 0 on success. Negative error code on failure. Typical error codes
297
+ * are %-EINVAL on inconsistency and %-ESRCH if the resource was doomed.
298
+ */
299
+static int vmw_execbuf_res_noref_val_add(struct vmw_sw_context *sw_context,
300
+ struct vmw_resource *res,
301
+ u32 dirty)
302
+{
303
+ struct vmw_private *dev_priv = res->dev_priv;
304
+ int ret;
305
+ enum vmw_res_type res_type = vmw_res_type(res);
306
+ struct vmw_res_cache_entry *rcache;
307
+ struct vmw_ctx_validation_info *ctx_info;
308
+ bool first_usage;
309
+ unsigned int priv_size;
310
+
311
+ rcache = &sw_context->res_cache[res_type];
312
+ if (likely(rcache->valid && rcache->res == res)) {
313
+ if (dirty)
314
+ vmw_validation_res_set_dirty(sw_context->ctx,
315
+ rcache->private, dirty);
316
+ vmw_user_resource_noref_release();
317
+ return 0;
318
+ }
319
+
320
+ priv_size = vmw_execbuf_res_size(dev_priv, res_type);
321
+ ret = vmw_validation_add_resource(sw_context->ctx, res, priv_size,
322
+ dirty, (void **)&ctx_info,
323
+ &first_usage);
324
+ vmw_user_resource_noref_release();
325
+ if (ret)
326
+ return ret;
327
+
328
+ if (priv_size && first_usage) {
329
+ ret = vmw_cmd_ctx_first_setup(dev_priv, sw_context, res,
330
+ ctx_info);
331
+ if (ret) {
332
+ VMW_DEBUG_USER("Failed first usage context setup.\n");
333
+ return ret;
334
+ }
335
+ }
336
+
337
+ vmw_execbuf_rcache_update(rcache, res, ctx_info);
338
+ return 0;
339
+}
340
+
341
+/**
342
+ * vmw_execbuf_res_noctx_val_add - Add a non-context resource to the resource
343
+ * validation list if it's not already on it
344
+ *
345
+ * @sw_context: Pointer to the software context.
346
+ * @res: Pointer to the resource.
347
+ * @dirty: Whether to change dirty status.
348
+ *
349
+ * Returns: Zero on success. Negative error code on failure.
350
+ */
351
+static int vmw_execbuf_res_noctx_val_add(struct vmw_sw_context *sw_context,
352
+ struct vmw_resource *res,
353
+ u32 dirty)
354
+{
355
+ struct vmw_res_cache_entry *rcache;
356
+ enum vmw_res_type res_type = vmw_res_type(res);
357
+ void *ptr;
358
+ int ret;
359
+
360
+ rcache = &sw_context->res_cache[res_type];
361
+ if (likely(rcache->valid && rcache->res == res)) {
362
+ if (dirty)
363
+ vmw_validation_res_set_dirty(sw_context->ctx,
364
+ rcache->private, dirty);
365
+ return 0;
366
+ }
367
+
368
+ ret = vmw_validation_add_resource(sw_context->ctx, res, 0, dirty,
369
+ &ptr, NULL);
370
+ if (ret)
371
+ return ret;
372
+
373
+ vmw_execbuf_rcache_update(rcache, res, ptr);
374
+
375
+ return 0;
376
+}
377
+
378
+/**
379
+ * vmw_view_res_val_add - Add a view and the surface it's pointing to to the
380
+ * validation list
313381 *
314382 * @sw_context: The software context holding the validation list.
315383 * @view: Pointer to the view resource.
....@@ -322,48 +390,53 @@
322390 int ret;
323391
324392 /*
325
- * First add the resource the view is pointing to, otherwise
326
- * it may be swapped out when the view is validated.
393
+ * First add the resource the view is pointing to, otherwise it may be
394
+ * swapped out when the view is validated.
327395 */
328
- ret = vmw_resource_val_add(sw_context, vmw_view_srf(view), NULL);
396
+ ret = vmw_execbuf_res_noctx_val_add(sw_context, vmw_view_srf(view),
397
+ vmw_view_dirtying(view));
329398 if (ret)
330399 return ret;
331400
332
- return vmw_resource_val_add(sw_context, view, NULL);
401
+ return vmw_execbuf_res_noctx_val_add(sw_context, view,
402
+ VMW_RES_DIRTY_NONE);
333403 }
334404
335405 /**
336
- * vmw_view_id_val_add - Look up a view and add it and the surface it's
337
- * pointing to to the validation list.
406
+ * vmw_view_id_val_add - Look up a view and add it and the surface it's pointing
407
+ * to to the validation list.
338408 *
339409 * @sw_context: The software context holding the validation list.
340410 * @view_type: The view type to look up.
341411 * @id: view id of the view.
342412 *
343
- * The view is represented by a view id and the DX context it's created on,
344
- * or scheduled for creation on. If there is no DX context set, the function
345
- * will return -EINVAL. Otherwise returns 0 on success and -EINVAL on failure.
413
+ * The view is represented by a view id and the DX context it's created on, or
414
+ * scheduled for creation on. If there is no DX context set, the function will
415
+ * return an -EINVAL error pointer.
416
+ *
417
+ * Returns: Unreferenced pointer to the resource on success, negative error
418
+ * pointer on failure.
346419 */
347
-static int vmw_view_id_val_add(struct vmw_sw_context *sw_context,
348
- enum vmw_view_type view_type, u32 id)
420
+static struct vmw_resource *
421
+vmw_view_id_val_add(struct vmw_sw_context *sw_context,
422
+ enum vmw_view_type view_type, u32 id)
349423 {
350
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
424
+ struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node;
351425 struct vmw_resource *view;
352426 int ret;
353427
354
- if (!ctx_node) {
355
- DRM_ERROR("DX Context not set.\n");
356
- return -EINVAL;
357
- }
428
+ if (!ctx_node)
429
+ return ERR_PTR(-EINVAL);
358430
359431 view = vmw_view_lookup(sw_context->man, view_type, id);
360432 if (IS_ERR(view))
361
- return PTR_ERR(view);
433
+ return view;
362434
363435 ret = vmw_view_res_val_add(sw_context, view);
364
- vmw_resource_unreference(&view);
436
+ if (ret)
437
+ return ERR_PTR(ret);
365438
366
- return ret;
439
+ return view;
367440 }
368441
369442 /**
....@@ -374,8 +447,8 @@
374447 * @sw_context: Pointer to a software context used for this command submission
375448 * @ctx: Pointer to the context resource
376449 *
377
- * This function puts all resources that were previously bound to @ctx on
378
- * the resource validation list. This is part of the context state reemission
450
+ * This function puts all resources that were previously bound to @ctx on the
451
+ * resource validation list. This is part of the context state reemission
379452 */
380453 static int vmw_resource_context_res_add(struct vmw_private *dev_priv,
381454 struct vmw_sw_context *sw_context,
....@@ -386,50 +459,47 @@
386459 int ret = 0;
387460 struct vmw_resource *res;
388461 u32 i;
462
+ u32 cotable_max = has_sm5_context(ctx->dev_priv) ?
463
+ SVGA_COTABLE_MAX : SVGA_COTABLE_DX10_MAX;
389464
390465 /* Add all cotables to the validation list. */
391
- if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) {
392
- for (i = 0; i < SVGA_COTABLE_DX10_MAX; ++i) {
466
+ if (has_sm4_context(dev_priv) &&
467
+ vmw_res_type(ctx) == vmw_res_dx_context) {
468
+ for (i = 0; i < cotable_max; ++i) {
393469 res = vmw_context_cotable(ctx, i);
394470 if (IS_ERR(res))
395471 continue;
396472
397
- ret = vmw_resource_val_add(sw_context, res, NULL);
398
- vmw_resource_unreference(&res);
473
+ ret = vmw_execbuf_res_noctx_val_add(sw_context, res,
474
+ VMW_RES_DIRTY_SET);
399475 if (unlikely(ret != 0))
400476 return ret;
401477 }
402478 }
403
-
404479
405480 /* Add all resources bound to the context to the validation list */
406481 mutex_lock(&dev_priv->binding_mutex);
407482 binding_list = vmw_context_binding_list(ctx);
408483
409484 list_for_each_entry(entry, binding_list, ctx_list) {
410
- /* entry->res is not refcounted */
411
- res = vmw_resource_reference_unless_doomed(entry->res);
412
- if (unlikely(res == NULL))
413
- continue;
414
-
415485 if (vmw_res_type(entry->res) == vmw_res_view)
416486 ret = vmw_view_res_val_add(sw_context, entry->res);
417487 else
418
- ret = vmw_resource_val_add(sw_context, entry->res,
419
- NULL);
420
- vmw_resource_unreference(&res);
488
+ ret = vmw_execbuf_res_noctx_val_add
489
+ (sw_context, entry->res,
490
+ vmw_binding_dirtying(entry->bt));
421491 if (unlikely(ret != 0))
422492 break;
423493 }
424494
425
- if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) {
495
+ if (has_sm4_context(dev_priv) &&
496
+ vmw_res_type(ctx) == vmw_res_dx_context) {
426497 struct vmw_buffer_object *dx_query_mob;
427498
428499 dx_query_mob = vmw_context_get_dx_query_mob(ctx);
429500 if (dx_query_mob)
430
- ret = vmw_bo_to_validate_list(sw_context,
431
- dx_query_mob,
432
- true, NULL);
501
+ ret = vmw_validation_add_bo(sw_context->ctx,
502
+ dx_query_mob, true, false);
433503 }
434504
435505 mutex_unlock(&dev_priv->binding_mutex);
....@@ -441,11 +511,11 @@
441511 *
442512 * @list: Pointer to head of relocation list.
443513 * @res: The resource.
444
- * @offset: Offset into the command buffer currently being parsed where the
445
- * id that needs fixup is located. Granularity is one byte.
514
+ * @offset: Offset into the command buffer currently being parsed where the id
515
+ * that needs fixup is located. Granularity is one byte.
446516 * @rel_type: Relocation type.
447517 */
448
-static int vmw_resource_relocation_add(struct list_head *list,
518
+static int vmw_resource_relocation_add(struct vmw_sw_context *sw_context,
449519 const struct vmw_resource *res,
450520 unsigned long offset,
451521 enum vmw_resource_relocation_type
....@@ -453,16 +523,16 @@
453523 {
454524 struct vmw_resource_relocation *rel;
455525
456
- rel = kmalloc(sizeof(*rel), GFP_KERNEL);
526
+ rel = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*rel));
457527 if (unlikely(!rel)) {
458
- DRM_ERROR("Failed to allocate a resource relocation.\n");
528
+ VMW_DEBUG_USER("Failed to allocate a resource relocation.\n");
459529 return -ENOMEM;
460530 }
461531
462532 rel->res = res;
463533 rel->offset = offset;
464534 rel->rel_type = rel_type;
465
- list_add_tail(&rel->head, list);
535
+ list_add_tail(&rel->head, &sw_context->res_relocations);
466536
467537 return 0;
468538 }
....@@ -470,25 +540,20 @@
470540 /**
471541 * vmw_resource_relocations_free - Free all relocations on a list
472542 *
473
- * @list: Pointer to the head of the relocation list.
543
+ * @list: Pointer to the head of the relocation list
474544 */
475545 static void vmw_resource_relocations_free(struct list_head *list)
476546 {
477
- struct vmw_resource_relocation *rel, *n;
478
-
479
- list_for_each_entry_safe(rel, n, list, head) {
480
- list_del(&rel->head);
481
- kfree(rel);
482
- }
547
+ /* Memory is validation context memory, so no need to free it */
548
+ INIT_LIST_HEAD(list);
483549 }
484550
485551 /**
486552 * vmw_resource_relocations_apply - Apply all relocations on a list
487553 *
488
- * @cb: Pointer to the start of the command buffer bein patch. This need
489
- * not be the same buffer as the one being parsed when the relocation
490
- * list was built, but the contents must be the same modulo the
491
- * resource ids.
554
+ * @cb: Pointer to the start of the command buffer bein patch. This need not be
555
+ * the same buffer as the one being parsed when the relocation list was built,
556
+ * but the contents must be the same modulo the resource ids.
492557 * @list: Pointer to the head of the relocation list.
493558 */
494559 static void vmw_resource_relocations_apply(uint32_t *cb,
....@@ -532,100 +597,22 @@
532597 }
533598
534599 /**
535
- * vmw_bo_to_validate_list - add a bo to a validate list
536
- *
537
- * @sw_context: The software context used for this command submission batch.
538
- * @bo: The buffer object to add.
539
- * @validate_as_mob: Validate this buffer as a MOB.
540
- * @p_val_node: If non-NULL Will be updated with the validate node number
541
- * on return.
542
- *
543
- * Returns -EINVAL if the limit of number of buffer objects per command
544
- * submission is reached.
545
- */
546
-static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context,
547
- struct vmw_buffer_object *vbo,
548
- bool validate_as_mob,
549
- uint32_t *p_val_node)
550
-{
551
- uint32_t val_node;
552
- struct vmw_validate_buffer *vval_buf;
553
- struct ttm_validate_buffer *val_buf;
554
- struct drm_hash_item *hash;
555
- int ret;
556
-
557
- if (likely(drm_ht_find_item(&sw_context->res_ht, (unsigned long) vbo,
558
- &hash) == 0)) {
559
- vval_buf = container_of(hash, struct vmw_validate_buffer,
560
- hash);
561
- if (unlikely(vval_buf->validate_as_mob != validate_as_mob)) {
562
- DRM_ERROR("Inconsistent buffer usage.\n");
563
- return -EINVAL;
564
- }
565
- val_buf = &vval_buf->base;
566
- val_node = vval_buf - sw_context->val_bufs;
567
- } else {
568
- val_node = sw_context->cur_val_buf;
569
- if (unlikely(val_node >= VMWGFX_MAX_VALIDATIONS)) {
570
- DRM_ERROR("Max number of DMA buffers per submission "
571
- "exceeded.\n");
572
- return -EINVAL;
573
- }
574
- vval_buf = &sw_context->val_bufs[val_node];
575
- vval_buf->hash.key = (unsigned long) vbo;
576
- ret = drm_ht_insert_item(&sw_context->res_ht, &vval_buf->hash);
577
- if (unlikely(ret != 0)) {
578
- DRM_ERROR("Failed to initialize a buffer validation "
579
- "entry.\n");
580
- return ret;
581
- }
582
- ++sw_context->cur_val_buf;
583
- val_buf = &vval_buf->base;
584
- val_buf->bo = ttm_bo_reference(&vbo->base);
585
- val_buf->shared = false;
586
- list_add_tail(&val_buf->head, &sw_context->validate_nodes);
587
- vval_buf->validate_as_mob = validate_as_mob;
588
- }
589
-
590
- if (p_val_node)
591
- *p_val_node = val_node;
592
-
593
- return 0;
594
-}
595
-
596
-/**
597
- * vmw_resources_reserve - Reserve all resources on the sw_context's
598
- * resource list.
600
+ * vmw_resources_reserve - Reserve all resources on the sw_context's resource
601
+ * list.
599602 *
600603 * @sw_context: Pointer to the software context.
601604 *
602
- * Note that since vmware's command submission currently is protected by
603
- * the cmdbuf mutex, no fancy deadlock avoidance is required for resources,
604
- * since only a single thread at once will attempt this.
605
+ * Note that since vmware's command submission currently is protected by the
606
+ * cmdbuf mutex, no fancy deadlock avoidance is required for resources, since
607
+ * only a single thread at once will attempt this.
605608 */
606609 static int vmw_resources_reserve(struct vmw_sw_context *sw_context)
607610 {
608
- struct vmw_resource_val_node *val;
609
- int ret = 0;
611
+ int ret;
610612
611
- list_for_each_entry(val, &sw_context->resource_list, head) {
612
- struct vmw_resource *res = val->res;
613
-
614
- ret = vmw_resource_reserve(res, true, val->no_buffer_needed);
615
- if (unlikely(ret != 0))
616
- return ret;
617
-
618
- if (res->backup) {
619
- struct vmw_buffer_object *vbo = res->backup;
620
-
621
- ret = vmw_bo_to_validate_list
622
- (sw_context, vbo,
623
- vmw_resource_needs_backup(res), NULL);
624
-
625
- if (unlikely(ret != 0))
626
- return ret;
627
- }
628
- }
613
+ ret = vmw_validation_res_reserve(sw_context->ctx, true);
614
+ if (ret)
615
+ return ret;
629616
630617 if (sw_context->dx_query_mob) {
631618 struct vmw_buffer_object *expected_dx_query_mob;
....@@ -642,173 +629,81 @@
642629 }
643630
644631 /**
645
- * vmw_resources_validate - Validate all resources on the sw_context's
646
- * resource list.
647
- *
648
- * @sw_context: Pointer to the software context.
649
- *
650
- * Before this function is called, all resource backup buffers must have
651
- * been validated.
652
- */
653
-static int vmw_resources_validate(struct vmw_sw_context *sw_context)
654
-{
655
- struct vmw_resource_val_node *val;
656
- int ret;
657
-
658
- list_for_each_entry(val, &sw_context->resource_list, head) {
659
- struct vmw_resource *res = val->res;
660
- struct vmw_buffer_object *backup = res->backup;
661
-
662
- ret = vmw_resource_validate(res);
663
- if (unlikely(ret != 0)) {
664
- if (ret != -ERESTARTSYS)
665
- DRM_ERROR("Failed to validate resource.\n");
666
- return ret;
667
- }
668
-
669
- /* Check if the resource switched backup buffer */
670
- if (backup && res->backup && (backup != res->backup)) {
671
- struct vmw_buffer_object *vbo = res->backup;
672
-
673
- ret = vmw_bo_to_validate_list
674
- (sw_context, vbo,
675
- vmw_resource_needs_backup(res), NULL);
676
- if (ret) {
677
- ttm_bo_unreserve(&vbo->base);
678
- return ret;
679
- }
680
- }
681
- }
682
- return 0;
683
-}
684
-
685
-/**
686
- * vmw_cmd_res_reloc_add - Add a resource to a software context's
687
- * relocation- and validation lists.
688
- *
689
- * @dev_priv: Pointer to a struct vmw_private identifying the device.
690
- * @sw_context: Pointer to the software context.
691
- * @id_loc: Pointer to where the id that needs translation is located.
692
- * @res: Valid pointer to a struct vmw_resource.
693
- * @p_val: If non null, a pointer to the struct vmw_resource_validate_node
694
- * used for this resource is returned here.
695
- */
696
-static int vmw_cmd_res_reloc_add(struct vmw_private *dev_priv,
697
- struct vmw_sw_context *sw_context,
698
- uint32_t *id_loc,
699
- struct vmw_resource *res,
700
- struct vmw_resource_val_node **p_val)
701
-{
702
- int ret;
703
- struct vmw_resource_val_node *node;
704
-
705
- *p_val = NULL;
706
- ret = vmw_resource_relocation_add(&sw_context->res_relocations,
707
- res,
708
- vmw_ptr_diff(sw_context->buf_start,
709
- id_loc),
710
- vmw_res_rel_normal);
711
- if (unlikely(ret != 0))
712
- return ret;
713
-
714
- ret = vmw_resource_val_add(sw_context, res, &node);
715
- if (unlikely(ret != 0))
716
- return ret;
717
-
718
- if (p_val)
719
- *p_val = node;
720
-
721
- return 0;
722
-}
723
-
724
-
725
-/**
726
- * vmw_cmd_res_check - Check that a resource is present and if so, put it
727
- * on the resource validate list unless it's already there.
632
+ * vmw_cmd_res_check - Check that a resource is present and if so, put it on the
633
+ * resource validate list unless it's already there.
728634 *
729635 * @dev_priv: Pointer to a device private structure.
730636 * @sw_context: Pointer to the software context.
731637 * @res_type: Resource type.
638
+ * @dirty: Whether to change dirty status.
732639 * @converter: User-space visisble type specific information.
733
- * @id_loc: Pointer to the location in the command buffer currently being
734
- * parsed from where the user-space resource id handle is located.
735
- * @p_val: Pointer to pointer to resource validalidation node. Populated
736
- * on exit.
640
+ * @id_loc: Pointer to the location in the command buffer currently being parsed
641
+ * from where the user-space resource id handle is located.
642
+ * @p_val: Pointer to pointer to resource validalidation node. Populated on
643
+ * exit.
737644 */
738645 static int
739646 vmw_cmd_res_check(struct vmw_private *dev_priv,
740647 struct vmw_sw_context *sw_context,
741648 enum vmw_res_type res_type,
649
+ u32 dirty,
742650 const struct vmw_user_resource_conv *converter,
743651 uint32_t *id_loc,
744
- struct vmw_resource_val_node **p_val)
652
+ struct vmw_resource **p_res)
745653 {
746
- struct vmw_res_cache_entry *rcache =
747
- &sw_context->res_cache[res_type];
654
+ struct vmw_res_cache_entry *rcache = &sw_context->res_cache[res_type];
748655 struct vmw_resource *res;
749
- struct vmw_resource_val_node *node;
750656 int ret;
751657
658
+ if (p_res)
659
+ *p_res = NULL;
660
+
752661 if (*id_loc == SVGA3D_INVALID_ID) {
753
- if (p_val)
754
- *p_val = NULL;
755662 if (res_type == vmw_res_context) {
756
- DRM_ERROR("Illegal context invalid id.\n");
663
+ VMW_DEBUG_USER("Illegal context invalid id.\n");
757664 return -EINVAL;
758665 }
759666 return 0;
760667 }
761668
762
- /*
763
- * Fastpath in case of repeated commands referencing the same
764
- * resource
765
- */
669
+ if (likely(rcache->valid_handle && *id_loc == rcache->handle)) {
670
+ res = rcache->res;
671
+ if (dirty)
672
+ vmw_validation_res_set_dirty(sw_context->ctx,
673
+ rcache->private, dirty);
674
+ } else {
675
+ unsigned int size = vmw_execbuf_res_size(dev_priv, res_type);
766676
767
- if (likely(rcache->valid && *id_loc == rcache->handle)) {
768
- const struct vmw_resource *res = rcache->res;
677
+ ret = vmw_validation_preload_res(sw_context->ctx, size);
678
+ if (ret)
679
+ return ret;
769680
770
- rcache->node->first_usage = false;
771
- if (p_val)
772
- *p_val = rcache->node;
681
+ res = vmw_user_resource_noref_lookup_handle
682
+ (dev_priv, sw_context->fp->tfile, *id_loc, converter);
683
+ if (IS_ERR(res)) {
684
+ VMW_DEBUG_USER("Could not find/use resource 0x%08x.\n",
685
+ (unsigned int) *id_loc);
686
+ return PTR_ERR(res);
687
+ }
773688
774
- return vmw_resource_relocation_add
775
- (&sw_context->res_relocations, res,
776
- vmw_ptr_diff(sw_context->buf_start, id_loc),
777
- vmw_res_rel_normal);
689
+ ret = vmw_execbuf_res_noref_val_add(sw_context, res, dirty);
690
+ if (unlikely(ret != 0))
691
+ return ret;
692
+
693
+ if (rcache->valid && rcache->res == res) {
694
+ rcache->valid_handle = true;
695
+ rcache->handle = *id_loc;
696
+ }
778697 }
779698
780
- ret = vmw_user_resource_lookup_handle(dev_priv,
781
- sw_context->fp->tfile,
782
- *id_loc,
783
- converter,
784
- &res);
785
- if (unlikely(ret != 0)) {
786
- DRM_ERROR("Could not find or use resource 0x%08x.\n",
787
- (unsigned) *id_loc);
788
- dump_stack();
789
- return ret;
790
- }
699
+ ret = vmw_resource_relocation_add(sw_context, res,
700
+ vmw_ptr_diff(sw_context->buf_start,
701
+ id_loc),
702
+ vmw_res_rel_normal);
703
+ if (p_res)
704
+ *p_res = res;
791705
792
- rcache->valid = true;
793
- rcache->res = res;
794
- rcache->handle = *id_loc;
795
-
796
- ret = vmw_cmd_res_reloc_add(dev_priv, sw_context, id_loc,
797
- res, &node);
798
- if (unlikely(ret != 0))
799
- goto out_no_reloc;
800
-
801
- rcache->node = node;
802
- if (p_val)
803
- *p_val = node;
804
- vmw_resource_unreference(&res);
805706 return 0;
806
-
807
-out_no_reloc:
808
- BUG_ON(sw_context->error_resource != NULL);
809
- sw_context->error_resource = res;
810
-
811
- return ret;
812707 }
813708
814709 /**
....@@ -822,23 +717,16 @@
822717 {
823718 struct vmw_private *dev_priv = ctx_res->dev_priv;
824719 struct vmw_buffer_object *dx_query_mob;
825
- struct {
826
- SVGA3dCmdHeader header;
827
- SVGA3dCmdDXBindAllQuery body;
828
- } *cmd;
829
-
720
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBindAllQuery);
830721
831722 dx_query_mob = vmw_context_get_dx_query_mob(ctx_res);
832723
833724 if (!dx_query_mob || dx_query_mob->dx_query_ctx)
834725 return 0;
835726
836
- cmd = vmw_fifo_reserve_dx(dev_priv, sizeof(*cmd), ctx_res->id);
837
-
838
- if (cmd == NULL) {
839
- DRM_ERROR("Failed to rebind queries.\n");
727
+ cmd = VMW_FIFO_RESERVE_DX(dev_priv, sizeof(*cmd), ctx_res->id);
728
+ if (cmd == NULL)
840729 return -ENOMEM;
841
- }
842730
843731 cmd->header.id = SVGA_3D_CMD_DX_BIND_ALL_QUERY;
844732 cmd->header.size = sizeof(cmd->body);
....@@ -852,8 +740,8 @@
852740 }
853741
854742 /**
855
- * vmw_rebind_contexts - Rebind all resources previously bound to
856
- * referenced contexts.
743
+ * vmw_rebind_contexts - Rebind all resources previously bound to referenced
744
+ * contexts.
857745 *
858746 * @sw_context: Pointer to the software context.
859747 *
....@@ -861,32 +749,30 @@
861749 */
862750 static int vmw_rebind_contexts(struct vmw_sw_context *sw_context)
863751 {
864
- struct vmw_resource_val_node *val;
752
+ struct vmw_ctx_validation_info *val;
865753 int ret;
866754
867
- list_for_each_entry(val, &sw_context->resource_list, head) {
868
- if (unlikely(!val->staged_bindings))
869
- break;
870
-
871
- ret = vmw_binding_rebind_all
872
- (vmw_context_binding_state(val->res));
755
+ list_for_each_entry(val, &sw_context->ctx_list, head) {
756
+ ret = vmw_binding_rebind_all(val->cur);
873757 if (unlikely(ret != 0)) {
874758 if (ret != -ERESTARTSYS)
875
- DRM_ERROR("Failed to rebind context.\n");
759
+ VMW_DEBUG_USER("Failed to rebind context.\n");
876760 return ret;
877761 }
878762
879
- ret = vmw_rebind_all_dx_query(val->res);
880
- if (ret != 0)
763
+ ret = vmw_rebind_all_dx_query(val->ctx);
764
+ if (ret != 0) {
765
+ VMW_DEBUG_USER("Failed to rebind queries.\n");
881766 return ret;
767
+ }
882768 }
883769
884770 return 0;
885771 }
886772
887773 /**
888
- * vmw_view_bindings_add - Add an array of view bindings to a context
889
- * binding state tracker.
774
+ * vmw_view_bindings_add - Add an array of view bindings to a context binding
775
+ * state tracker.
890776 *
891777 * @sw_context: The execbuf state used for this command.
892778 * @view_type: View type for the bindings.
....@@ -903,45 +789,31 @@
903789 uint32 view_ids[], u32 num_views,
904790 u32 first_slot)
905791 {
906
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
907
- struct vmw_cmdbuf_res_manager *man;
792
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
908793 u32 i;
909
- int ret;
910794
911
- if (!ctx_node) {
912
- DRM_ERROR("DX Context not set.\n");
795
+ if (!ctx_node)
913796 return -EINVAL;
914
- }
915797
916
- man = sw_context->man;
917798 for (i = 0; i < num_views; ++i) {
918799 struct vmw_ctx_bindinfo_view binding;
919800 struct vmw_resource *view = NULL;
920801
921802 if (view_ids[i] != SVGA3D_INVALID_ID) {
922
- view = vmw_view_lookup(man, view_type, view_ids[i]);
803
+ view = vmw_view_id_val_add(sw_context, view_type,
804
+ view_ids[i]);
923805 if (IS_ERR(view)) {
924
- DRM_ERROR("View not found.\n");
806
+ VMW_DEBUG_USER("View not found.\n");
925807 return PTR_ERR(view);
926808 }
927
-
928
- ret = vmw_view_res_val_add(sw_context, view);
929
- if (ret) {
930
- DRM_ERROR("Could not add view to "
931
- "validation list.\n");
932
- vmw_resource_unreference(&view);
933
- return ret;
934
- }
935809 }
936
- binding.bi.ctx = ctx_node->res;
810
+ binding.bi.ctx = ctx_node->ctx;
937811 binding.bi.res = view;
938812 binding.bi.bt = binding_type;
939813 binding.shader_slot = shader_slot;
940814 binding.slot = first_slot + i;
941
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
815
+ vmw_binding_add(ctx_node->staged, &binding.bi,
942816 shader_slot, binding.slot);
943
- if (view)
944
- vmw_resource_unreference(&view);
945817 }
946818
947819 return 0;
....@@ -961,57 +833,84 @@
961833 struct vmw_sw_context *sw_context,
962834 SVGA3dCmdHeader *header)
963835 {
964
- struct vmw_cid_cmd {
965
- SVGA3dCmdHeader header;
966
- uint32_t cid;
967
- } *cmd;
836
+ VMW_DECLARE_CMD_VAR(*cmd, uint32_t) =
837
+ container_of(header, typeof(*cmd), header);
968838
969
- cmd = container_of(header, struct vmw_cid_cmd, header);
970839 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
971
- user_context_converter, &cmd->cid, NULL);
840
+ VMW_RES_DIRTY_SET, user_context_converter,
841
+ &cmd->body, NULL);
842
+}
843
+
844
+/**
845
+ * vmw_execbuf_info_from_res - Get the private validation metadata for a
846
+ * recently validated resource
847
+ *
848
+ * @sw_context: Pointer to the command submission context
849
+ * @res: The resource
850
+ *
851
+ * The resource pointed to by @res needs to be present in the command submission
852
+ * context's resource cache and hence the last resource of that type to be
853
+ * processed by the validation code.
854
+ *
855
+ * Return: a pointer to the private metadata of the resource, or NULL if it
856
+ * wasn't found
857
+ */
858
+static struct vmw_ctx_validation_info *
859
+vmw_execbuf_info_from_res(struct vmw_sw_context *sw_context,
860
+ struct vmw_resource *res)
861
+{
862
+ struct vmw_res_cache_entry *rcache =
863
+ &sw_context->res_cache[vmw_res_type(res)];
864
+
865
+ if (rcache->valid && rcache->res == res)
866
+ return rcache->private;
867
+
868
+ WARN_ON_ONCE(true);
869
+ return NULL;
972870 }
973871
974872 static int vmw_cmd_set_render_target_check(struct vmw_private *dev_priv,
975873 struct vmw_sw_context *sw_context,
976874 SVGA3dCmdHeader *header)
977875 {
978
- struct vmw_sid_cmd {
979
- SVGA3dCmdHeader header;
980
- SVGA3dCmdSetRenderTarget body;
981
- } *cmd;
982
- struct vmw_resource_val_node *ctx_node;
983
- struct vmw_resource_val_node *res_node;
876
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetRenderTarget);
877
+ struct vmw_resource *ctx;
878
+ struct vmw_resource *res;
984879 int ret;
985880
986
- cmd = container_of(header, struct vmw_sid_cmd, header);
881
+ cmd = container_of(header, typeof(*cmd), header);
987882
988883 if (cmd->body.type >= SVGA3D_RT_MAX) {
989
- DRM_ERROR("Illegal render target type %u.\n",
990
- (unsigned) cmd->body.type);
884
+ VMW_DEBUG_USER("Illegal render target type %u.\n",
885
+ (unsigned int) cmd->body.type);
991886 return -EINVAL;
992887 }
993888
994889 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
995
- user_context_converter, &cmd->body.cid,
996
- &ctx_node);
890
+ VMW_RES_DIRTY_SET, user_context_converter,
891
+ &cmd->body.cid, &ctx);
997892 if (unlikely(ret != 0))
998893 return ret;
999894
1000895 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1001
- user_surface_converter,
1002
- &cmd->body.target.sid, &res_node);
1003
- if (unlikely(ret != 0))
896
+ VMW_RES_DIRTY_SET, user_surface_converter,
897
+ &cmd->body.target.sid, &res);
898
+ if (unlikely(ret))
1004899 return ret;
1005900
1006901 if (dev_priv->has_mob) {
1007902 struct vmw_ctx_bindinfo_view binding;
903
+ struct vmw_ctx_validation_info *node;
1008904
1009
- binding.bi.ctx = ctx_node->res;
1010
- binding.bi.res = res_node ? res_node->res : NULL;
905
+ node = vmw_execbuf_info_from_res(sw_context, ctx);
906
+ if (!node)
907
+ return -EINVAL;
908
+
909
+ binding.bi.ctx = ctx;
910
+ binding.bi.res = res;
1011911 binding.bi.bt = vmw_ctx_binding_rt;
1012912 binding.slot = cmd->body.type;
1013
- vmw_binding_add(ctx_node->staged_bindings,
1014
- &binding.bi, 0, binding.slot);
913
+ vmw_binding_add(node->staged, &binding.bi, 0, binding.slot);
1015914 }
1016915
1017916 return 0;
....@@ -1021,44 +920,38 @@
1021920 struct vmw_sw_context *sw_context,
1022921 SVGA3dCmdHeader *header)
1023922 {
1024
- struct vmw_sid_cmd {
1025
- SVGA3dCmdHeader header;
1026
- SVGA3dCmdSurfaceCopy body;
1027
- } *cmd;
923
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSurfaceCopy);
1028924 int ret;
1029925
1030
- cmd = container_of(header, struct vmw_sid_cmd, header);
926
+ cmd = container_of(header, typeof(*cmd), header);
1031927
1032928 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1033
- user_surface_converter,
929
+ VMW_RES_DIRTY_NONE, user_surface_converter,
1034930 &cmd->body.src.sid, NULL);
1035931 if (ret)
1036932 return ret;
1037933
1038934 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1039
- user_surface_converter,
935
+ VMW_RES_DIRTY_SET, user_surface_converter,
1040936 &cmd->body.dest.sid, NULL);
1041937 }
1042938
1043939 static int vmw_cmd_buffer_copy_check(struct vmw_private *dev_priv,
1044
- struct vmw_sw_context *sw_context,
1045
- SVGA3dCmdHeader *header)
940
+ struct vmw_sw_context *sw_context,
941
+ SVGA3dCmdHeader *header)
1046942 {
1047
- struct {
1048
- SVGA3dCmdHeader header;
1049
- SVGA3dCmdDXBufferCopy body;
1050
- } *cmd;
943
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBufferCopy);
1051944 int ret;
1052945
1053946 cmd = container_of(header, typeof(*cmd), header);
1054947 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1055
- user_surface_converter,
948
+ VMW_RES_DIRTY_NONE, user_surface_converter,
1056949 &cmd->body.src, NULL);
1057950 if (ret != 0)
1058951 return ret;
1059952
1060953 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1061
- user_surface_converter,
954
+ VMW_RES_DIRTY_SET, user_surface_converter,
1062955 &cmd->body.dest, NULL);
1063956 }
1064957
....@@ -1066,21 +959,18 @@
1066959 struct vmw_sw_context *sw_context,
1067960 SVGA3dCmdHeader *header)
1068961 {
1069
- struct {
1070
- SVGA3dCmdHeader header;
1071
- SVGA3dCmdDXPredCopyRegion body;
1072
- } *cmd;
962
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXPredCopyRegion);
1073963 int ret;
1074964
1075965 cmd = container_of(header, typeof(*cmd), header);
1076966 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1077
- user_surface_converter,
967
+ VMW_RES_DIRTY_NONE, user_surface_converter,
1078968 &cmd->body.srcSid, NULL);
1079969 if (ret != 0)
1080970 return ret;
1081971
1082972 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1083
- user_surface_converter,
973
+ VMW_RES_DIRTY_SET, user_surface_converter,
1084974 &cmd->body.dstSid, NULL);
1085975 }
1086976
....@@ -1088,20 +978,18 @@
1088978 struct vmw_sw_context *sw_context,
1089979 SVGA3dCmdHeader *header)
1090980 {
1091
- struct vmw_sid_cmd {
1092
- SVGA3dCmdHeader header;
1093
- SVGA3dCmdSurfaceStretchBlt body;
1094
- } *cmd;
981
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSurfaceStretchBlt);
1095982 int ret;
1096983
1097
- cmd = container_of(header, struct vmw_sid_cmd, header);
984
+ cmd = container_of(header, typeof(*cmd), header);
1098985 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1099
- user_surface_converter,
986
+ VMW_RES_DIRTY_NONE, user_surface_converter,
1100987 &cmd->body.src.sid, NULL);
1101988 if (unlikely(ret != 0))
1102989 return ret;
990
+
1103991 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1104
- user_surface_converter,
992
+ VMW_RES_DIRTY_SET, user_surface_converter,
1105993 &cmd->body.dest.sid, NULL);
1106994 }
1107995
....@@ -1109,15 +997,11 @@
1109997 struct vmw_sw_context *sw_context,
1110998 SVGA3dCmdHeader *header)
1111999 {
1112
- struct vmw_sid_cmd {
1113
- SVGA3dCmdHeader header;
1114
- SVGA3dCmdBlitSurfaceToScreen body;
1115
- } *cmd;
1116
-
1117
- cmd = container_of(header, struct vmw_sid_cmd, header);
1000
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBlitSurfaceToScreen) =
1001
+ container_of(header, typeof(*cmd), header);
11181002
11191003 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1120
- user_surface_converter,
1004
+ VMW_RES_DIRTY_NONE, user_surface_converter,
11211005 &cmd->body.srcImage.sid, NULL);
11221006 }
11231007
....@@ -1125,17 +1009,12 @@
11251009 struct vmw_sw_context *sw_context,
11261010 SVGA3dCmdHeader *header)
11271011 {
1128
- struct vmw_sid_cmd {
1129
- SVGA3dCmdHeader header;
1130
- SVGA3dCmdPresent body;
1131
- } *cmd;
1132
-
1133
-
1134
- cmd = container_of(header, struct vmw_sid_cmd, header);
1012
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdPresent) =
1013
+ container_of(header, typeof(*cmd), header);
11351014
11361015 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1137
- user_surface_converter, &cmd->body.sid,
1138
- NULL);
1016
+ VMW_RES_DIRTY_NONE, user_surface_converter,
1017
+ &cmd->body.sid, NULL);
11391018 }
11401019
11411020 /**
....@@ -1145,11 +1024,10 @@
11451024 * @new_query_bo: The new buffer holding query results.
11461025 * @sw_context: The software context used for this command submission.
11471026 *
1148
- * This function checks whether @new_query_bo is suitable for holding
1149
- * query results, and if another buffer currently is pinned for query
1150
- * results. If so, the function prepares the state of @sw_context for
1151
- * switching pinned buffers after successful submission of the current
1152
- * command batch.
1027
+ * This function checks whether @new_query_bo is suitable for holding query
1028
+ * results, and if another buffer currently is pinned for query results. If so,
1029
+ * the function prepares the state of @sw_context for switching pinned buffers
1030
+ * after successful submission of the current command batch.
11531031 */
11541032 static int vmw_query_bo_switch_prepare(struct vmw_private *dev_priv,
11551033 struct vmw_buffer_object *new_query_bo,
....@@ -1165,31 +1043,29 @@
11651043 if (unlikely(new_query_bo != sw_context->cur_query_bo)) {
11661044
11671045 if (unlikely(new_query_bo->base.num_pages > 4)) {
1168
- DRM_ERROR("Query buffer too large.\n");
1046
+ VMW_DEBUG_USER("Query buffer too large.\n");
11691047 return -EINVAL;
11701048 }
11711049
11721050 if (unlikely(sw_context->cur_query_bo != NULL)) {
11731051 sw_context->needs_post_query_barrier = true;
1174
- ret = vmw_bo_to_validate_list(sw_context,
1175
- sw_context->cur_query_bo,
1176
- dev_priv->has_mob, NULL);
1052
+ ret = vmw_validation_add_bo(sw_context->ctx,
1053
+ sw_context->cur_query_bo,
1054
+ dev_priv->has_mob, false);
11771055 if (unlikely(ret != 0))
11781056 return ret;
11791057 }
11801058 sw_context->cur_query_bo = new_query_bo;
11811059
1182
- ret = vmw_bo_to_validate_list(sw_context,
1183
- dev_priv->dummy_query_bo,
1184
- dev_priv->has_mob, NULL);
1060
+ ret = vmw_validation_add_bo(sw_context->ctx,
1061
+ dev_priv->dummy_query_bo,
1062
+ dev_priv->has_mob, false);
11851063 if (unlikely(ret != 0))
11861064 return ret;
1187
-
11881065 }
11891066
11901067 return 0;
11911068 }
1192
-
11931069
11941070 /**
11951071 * vmw_query_bo_switch_commit - Finalize switching pinned query buffer
....@@ -1199,11 +1075,11 @@
11991075 *
12001076 * This function will check if we're switching query buffers, and will then,
12011077 * issue a dummy occlusion query wait used as a query barrier. When the fence
1202
- * object following that query wait has signaled, we are sure that all
1203
- * preceding queries have finished, and the old query buffer can be unpinned.
1204
- * However, since both the new query buffer and the old one are fenced with
1205
- * that fence, we can do an asynchronus unpin now, and be sure that the
1206
- * old query buffer won't be moved until the fence has signaled.
1078
+ * object following that query wait has signaled, we are sure that all preceding
1079
+ * queries have finished, and the old query buffer can be unpinned. However,
1080
+ * since both the new query buffer and the old one are fenced with that fence,
1081
+ * we can do an asynchronus unpin now, and be sure that the old query buffer
1082
+ * won't be moved until the fence has signaled.
12071083 *
12081084 * As mentioned above, both the new - and old query buffers need to be fenced
12091085 * using a sequence emitted *after* calling this function.
....@@ -1215,7 +1091,6 @@
12151091 * The validate list should still hold references to all
12161092 * contexts here.
12171093 */
1218
-
12191094 if (sw_context->needs_post_query_barrier) {
12201095 struct vmw_res_cache_entry *ctx_entry =
12211096 &sw_context->res_cache[vmw_res_context];
....@@ -1228,7 +1103,7 @@
12281103 ret = vmw_fifo_emit_dummy_query(dev_priv, ctx->id);
12291104
12301105 if (unlikely(ret != 0))
1231
- DRM_ERROR("Out of fifo space for dummy query.\n");
1106
+ VMW_DEBUG_USER("Out of fifo space for dummy query.\n");
12321107 }
12331108
12341109 if (dev_priv->pinned_bo != sw_context->cur_query_bo) {
....@@ -1242,10 +1117,9 @@
12421117
12431118 /*
12441119 * We pin also the dummy_query_bo buffer so that we
1245
- * don't need to validate it when emitting
1246
- * dummy queries in context destroy paths.
1120
+ * don't need to validate it when emitting dummy queries
1121
+ * in context destroy paths.
12471122 */
1248
-
12491123 if (!dev_priv->dummy_query_bo_pinned) {
12501124 vmw_bo_pin_reserved(dev_priv->dummy_query_bo,
12511125 true);
....@@ -1262,78 +1136,75 @@
12621136 }
12631137
12641138 /**
1265
- * vmw_translate_mob_pointer - Prepare to translate a user-space buffer
1266
- * handle to a MOB id.
1139
+ * vmw_translate_mob_pointer - Prepare to translate a user-space buffer handle
1140
+ * to a MOB id.
12671141 *
12681142 * @dev_priv: Pointer to a device private structure.
12691143 * @sw_context: The software context used for this command batch validation.
12701144 * @id: Pointer to the user-space handle to be translated.
1271
- * @vmw_bo_p: Points to a location that, on successful return will carry
1272
- * a reference-counted pointer to the DMA buffer identified by the
1145
+ * @vmw_bo_p: Points to a location that, on successful return will carry a
1146
+ * non-reference-counted pointer to the buffer object identified by the
12731147 * user-space handle in @id.
12741148 *
12751149 * This function saves information needed to translate a user-space buffer
12761150 * handle to a MOB id. The translation does not take place immediately, but
1277
- * during a call to vmw_apply_relocations(). This function builds a relocation
1278
- * list and a list of buffers to validate. The former needs to be freed using
1279
- * either vmw_apply_relocations() or vmw_free_relocations(). The latter
1280
- * needs to be freed using vmw_clear_validations.
1151
+ * during a call to vmw_apply_relocations().
1152
+ *
1153
+ * This function builds a relocation list and a list of buffers to validate. The
1154
+ * former needs to be freed using either vmw_apply_relocations() or
1155
+ * vmw_free_relocations(). The latter needs to be freed using
1156
+ * vmw_clear_validations.
12811157 */
12821158 static int vmw_translate_mob_ptr(struct vmw_private *dev_priv,
12831159 struct vmw_sw_context *sw_context,
12841160 SVGAMobId *id,
12851161 struct vmw_buffer_object **vmw_bo_p)
12861162 {
1287
- struct vmw_buffer_object *vmw_bo = NULL;
1163
+ struct vmw_buffer_object *vmw_bo;
12881164 uint32_t handle = *id;
12891165 struct vmw_relocation *reloc;
12901166 int ret;
12911167
1292
- ret = vmw_user_bo_lookup(sw_context->fp->tfile, handle, &vmw_bo, NULL);
1293
- if (unlikely(ret != 0)) {
1294
- DRM_ERROR("Could not find or use MOB buffer.\n");
1295
- ret = -EINVAL;
1296
- goto out_no_reloc;
1168
+ vmw_validation_preload_bo(sw_context->ctx);
1169
+ vmw_bo = vmw_user_bo_noref_lookup(sw_context->fp->tfile, handle);
1170
+ if (IS_ERR(vmw_bo)) {
1171
+ VMW_DEBUG_USER("Could not find or use MOB buffer.\n");
1172
+ return PTR_ERR(vmw_bo);
12971173 }
12981174
1299
- if (unlikely(sw_context->cur_reloc >= VMWGFX_MAX_RELOCATIONS)) {
1300
- DRM_ERROR("Max number relocations per submission"
1301
- " exceeded\n");
1302
- ret = -EINVAL;
1303
- goto out_no_reloc;
1304
- }
1305
-
1306
- reloc = &sw_context->relocs[sw_context->cur_reloc++];
1307
- reloc->mob_loc = id;
1308
- reloc->location = NULL;
1309
-
1310
- ret = vmw_bo_to_validate_list(sw_context, vmw_bo, true, &reloc->index);
1175
+ ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, true, false);
1176
+ vmw_user_bo_noref_release();
13111177 if (unlikely(ret != 0))
1312
- goto out_no_reloc;
1178
+ return ret;
1179
+
1180
+ reloc = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*reloc));
1181
+ if (!reloc)
1182
+ return -ENOMEM;
1183
+
1184
+ reloc->mob_loc = id;
1185
+ reloc->vbo = vmw_bo;
13131186
13141187 *vmw_bo_p = vmw_bo;
1315
- return 0;
1188
+ list_add_tail(&reloc->head, &sw_context->bo_relocations);
13161189
1317
-out_no_reloc:
1318
- vmw_bo_unreference(&vmw_bo);
1319
- *vmw_bo_p = NULL;
1320
- return ret;
1190
+ return 0;
13211191 }
13221192
13231193 /**
1324
- * vmw_translate_guest_pointer - Prepare to translate a user-space buffer
1325
- * handle to a valid SVGAGuestPtr
1194
+ * vmw_translate_guest_pointer - Prepare to translate a user-space buffer handle
1195
+ * to a valid SVGAGuestPtr
13261196 *
13271197 * @dev_priv: Pointer to a device private structure.
13281198 * @sw_context: The software context used for this command batch validation.
13291199 * @ptr: Pointer to the user-space handle to be translated.
1330
- * @vmw_bo_p: Points to a location that, on successful return will carry
1331
- * a reference-counted pointer to the DMA buffer identified by the
1332
- * user-space handle in @id.
1200
+ * @vmw_bo_p: Points to a location that, on successful return will carry a
1201
+ * non-reference-counted pointer to the DMA buffer identified by the user-space
1202
+ * handle in @id.
13331203 *
13341204 * This function saves information needed to translate a user-space buffer
13351205 * handle to a valid SVGAGuestPtr. The translation does not take place
13361206 * immediately, but during a call to vmw_apply_relocations().
1207
+ *
13371208 * This function builds a relocation list and a list of buffers to validate.
13381209 * The former needs to be freed using either vmw_apply_relocations() or
13391210 * vmw_free_relocations(). The latter needs to be freed using
....@@ -1344,45 +1215,37 @@
13441215 SVGAGuestPtr *ptr,
13451216 struct vmw_buffer_object **vmw_bo_p)
13461217 {
1347
- struct vmw_buffer_object *vmw_bo = NULL;
1218
+ struct vmw_buffer_object *vmw_bo;
13481219 uint32_t handle = ptr->gmrId;
13491220 struct vmw_relocation *reloc;
13501221 int ret;
13511222
1352
- ret = vmw_user_bo_lookup(sw_context->fp->tfile, handle, &vmw_bo, NULL);
1353
- if (unlikely(ret != 0)) {
1354
- DRM_ERROR("Could not find or use GMR region.\n");
1355
- ret = -EINVAL;
1356
- goto out_no_reloc;
1223
+ vmw_validation_preload_bo(sw_context->ctx);
1224
+ vmw_bo = vmw_user_bo_noref_lookup(sw_context->fp->tfile, handle);
1225
+ if (IS_ERR(vmw_bo)) {
1226
+ VMW_DEBUG_USER("Could not find or use GMR region.\n");
1227
+ return PTR_ERR(vmw_bo);
13571228 }
13581229
1359
- if (unlikely(sw_context->cur_reloc >= VMWGFX_MAX_RELOCATIONS)) {
1360
- DRM_ERROR("Max number relocations per submission"
1361
- " exceeded\n");
1362
- ret = -EINVAL;
1363
- goto out_no_reloc;
1364
- }
1365
-
1366
- reloc = &sw_context->relocs[sw_context->cur_reloc++];
1367
- reloc->location = ptr;
1368
-
1369
- ret = vmw_bo_to_validate_list(sw_context, vmw_bo, false, &reloc->index);
1230
+ ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, false, false);
1231
+ vmw_user_bo_noref_release();
13701232 if (unlikely(ret != 0))
1371
- goto out_no_reloc;
1233
+ return ret;
13721234
1235
+ reloc = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*reloc));
1236
+ if (!reloc)
1237
+ return -ENOMEM;
1238
+
1239
+ reloc->location = ptr;
1240
+ reloc->vbo = vmw_bo;
13731241 *vmw_bo_p = vmw_bo;
1374
- return 0;
1242
+ list_add_tail(&reloc->head, &sw_context->bo_relocations);
13751243
1376
-out_no_reloc:
1377
- vmw_bo_unreference(&vmw_bo);
1378
- *vmw_bo_p = NULL;
1379
- return ret;
1244
+ return 0;
13801245 }
13811246
1382
-
1383
-
13841247 /**
1385
- * vmw_cmd_dx_define_query - validate a SVGA_3D_CMD_DX_DEFINE_QUERY command.
1248
+ * vmw_cmd_dx_define_query - validate SVGA_3D_CMD_DX_DEFINE_QUERY command.
13861249 *
13871250 * @dev_priv: Pointer to a device private struct.
13881251 * @sw_context: The software context used for this command submission.
....@@ -1394,85 +1257,64 @@
13941257 struct vmw_sw_context *sw_context,
13951258 SVGA3dCmdHeader *header)
13961259 {
1397
- struct vmw_dx_define_query_cmd {
1398
- SVGA3dCmdHeader header;
1399
- SVGA3dCmdDXDefineQuery q;
1400
- } *cmd;
1401
-
1402
- int ret;
1403
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
1260
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXDefineQuery);
1261
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
14041262 struct vmw_resource *cotable_res;
1263
+ int ret;
14051264
1406
-
1407
- if (ctx_node == NULL) {
1408
- DRM_ERROR("DX Context not set for query.\n");
1409
- return -EINVAL;
1410
- }
1411
-
1412
- cmd = container_of(header, struct vmw_dx_define_query_cmd, header);
1413
-
1414
- if (cmd->q.type < SVGA3D_QUERYTYPE_MIN ||
1415
- cmd->q.type >= SVGA3D_QUERYTYPE_MAX)
1265
+ if (!ctx_node)
14161266 return -EINVAL;
14171267
1418
- cotable_res = vmw_context_cotable(ctx_node->res, SVGA_COTABLE_DXQUERY);
1419
- ret = vmw_cotable_notify(cotable_res, cmd->q.queryId);
1420
- vmw_resource_unreference(&cotable_res);
1268
+ cmd = container_of(header, typeof(*cmd), header);
1269
+
1270
+ if (cmd->body.type < SVGA3D_QUERYTYPE_MIN ||
1271
+ cmd->body.type >= SVGA3D_QUERYTYPE_MAX)
1272
+ return -EINVAL;
1273
+
1274
+ cotable_res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXQUERY);
1275
+ ret = vmw_cotable_notify(cotable_res, cmd->body.queryId);
14211276
14221277 return ret;
14231278 }
14241279
1425
-
1426
-
14271280 /**
1428
- * vmw_cmd_dx_bind_query - validate a SVGA_3D_CMD_DX_BIND_QUERY command.
1281
+ * vmw_cmd_dx_bind_query - validate SVGA_3D_CMD_DX_BIND_QUERY command.
14291282 *
14301283 * @dev_priv: Pointer to a device private struct.
14311284 * @sw_context: The software context used for this command submission.
14321285 * @header: Pointer to the command header in the command stream.
14331286 *
1434
- * The query bind operation will eventually associate the query ID
1435
- * with its backing MOB. In this function, we take the user mode
1436
- * MOB ID and use vmw_translate_mob_ptr() to translate it to its
1437
- * kernel mode equivalent.
1287
+ * The query bind operation will eventually associate the query ID with its
1288
+ * backing MOB. In this function, we take the user mode MOB ID and use
1289
+ * vmw_translate_mob_ptr() to translate it to its kernel mode equivalent.
14381290 */
14391291 static int vmw_cmd_dx_bind_query(struct vmw_private *dev_priv,
14401292 struct vmw_sw_context *sw_context,
14411293 SVGA3dCmdHeader *header)
14421294 {
1443
- struct vmw_dx_bind_query_cmd {
1444
- SVGA3dCmdHeader header;
1445
- SVGA3dCmdDXBindQuery q;
1446
- } *cmd;
1447
-
1295
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBindQuery);
14481296 struct vmw_buffer_object *vmw_bo;
1449
- int ret;
1297
+ int ret;
14501298
1451
-
1452
- cmd = container_of(header, struct vmw_dx_bind_query_cmd, header);
1299
+ cmd = container_of(header, typeof(*cmd), header);
14531300
14541301 /*
14551302 * Look up the buffer pointed to by q.mobid, put it on the relocation
14561303 * list so its kernel mode MOB ID can be filled in later
14571304 */
1458
- ret = vmw_translate_mob_ptr(dev_priv, sw_context, &cmd->q.mobid,
1305
+ ret = vmw_translate_mob_ptr(dev_priv, sw_context, &cmd->body.mobid,
14591306 &vmw_bo);
14601307
14611308 if (ret != 0)
14621309 return ret;
14631310
14641311 sw_context->dx_query_mob = vmw_bo;
1465
- sw_context->dx_query_ctx = sw_context->dx_ctx_node->res;
1466
-
1467
- vmw_bo_unreference(&vmw_bo);
1468
-
1469
- return ret;
1312
+ sw_context->dx_query_ctx = sw_context->dx_ctx_node->ctx;
1313
+ return 0;
14701314 }
14711315
1472
-
1473
-
14741316 /**
1475
- * vmw_cmd_begin_gb_query - validate a SVGA_3D_CMD_BEGIN_GB_QUERY command.
1317
+ * vmw_cmd_begin_gb_query - validate SVGA_3D_CMD_BEGIN_GB_QUERY command.
14761318 *
14771319 * @dev_priv: Pointer to a device private struct.
14781320 * @sw_context: The software context used for this command submission.
....@@ -1482,21 +1324,16 @@
14821324 struct vmw_sw_context *sw_context,
14831325 SVGA3dCmdHeader *header)
14841326 {
1485
- struct vmw_begin_gb_query_cmd {
1486
- SVGA3dCmdHeader header;
1487
- SVGA3dCmdBeginGBQuery q;
1488
- } *cmd;
1489
-
1490
- cmd = container_of(header, struct vmw_begin_gb_query_cmd,
1491
- header);
1327
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBeginGBQuery) =
1328
+ container_of(header, typeof(*cmd), header);
14921329
14931330 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
1494
- user_context_converter, &cmd->q.cid,
1495
- NULL);
1331
+ VMW_RES_DIRTY_SET, user_context_converter,
1332
+ &cmd->body.cid, NULL);
14961333 }
14971334
14981335 /**
1499
- * vmw_cmd_begin_query - validate a SVGA_3D_CMD_BEGIN_QUERY command.
1336
+ * vmw_cmd_begin_query - validate SVGA_3D_CMD_BEGIN_QUERY command.
15001337 *
15011338 * @dev_priv: Pointer to a device private struct.
15021339 * @sw_context: The software context used for this command submission.
....@@ -1506,38 +1343,30 @@
15061343 struct vmw_sw_context *sw_context,
15071344 SVGA3dCmdHeader *header)
15081345 {
1509
- struct vmw_begin_query_cmd {
1510
- SVGA3dCmdHeader header;
1511
- SVGA3dCmdBeginQuery q;
1512
- } *cmd;
1513
-
1514
- cmd = container_of(header, struct vmw_begin_query_cmd,
1515
- header);
1346
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBeginQuery) =
1347
+ container_of(header, typeof(*cmd), header);
15161348
15171349 if (unlikely(dev_priv->has_mob)) {
1518
- struct {
1519
- SVGA3dCmdHeader header;
1520
- SVGA3dCmdBeginGBQuery q;
1521
- } gb_cmd;
1350
+ VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdBeginGBQuery);
15221351
15231352 BUG_ON(sizeof(gb_cmd) != sizeof(*cmd));
15241353
15251354 gb_cmd.header.id = SVGA_3D_CMD_BEGIN_GB_QUERY;
15261355 gb_cmd.header.size = cmd->header.size;
1527
- gb_cmd.q.cid = cmd->q.cid;
1528
- gb_cmd.q.type = cmd->q.type;
1356
+ gb_cmd.body.cid = cmd->body.cid;
1357
+ gb_cmd.body.type = cmd->body.type;
15291358
15301359 memcpy(cmd, &gb_cmd, sizeof(*cmd));
15311360 return vmw_cmd_begin_gb_query(dev_priv, sw_context, header);
15321361 }
15331362
15341363 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
1535
- user_context_converter, &cmd->q.cid,
1536
- NULL);
1364
+ VMW_RES_DIRTY_SET, user_context_converter,
1365
+ &cmd->body.cid, NULL);
15371366 }
15381367
15391368 /**
1540
- * vmw_cmd_end_gb_query - validate a SVGA_3D_CMD_END_GB_QUERY command.
1369
+ * vmw_cmd_end_gb_query - validate SVGA_3D_CMD_END_GB_QUERY command.
15411370 *
15421371 * @dev_priv: Pointer to a device private struct.
15431372 * @sw_context: The software context used for this command submission.
....@@ -1548,31 +1377,26 @@
15481377 SVGA3dCmdHeader *header)
15491378 {
15501379 struct vmw_buffer_object *vmw_bo;
1551
- struct vmw_query_cmd {
1552
- SVGA3dCmdHeader header;
1553
- SVGA3dCmdEndGBQuery q;
1554
- } *cmd;
1380
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdEndGBQuery);
15551381 int ret;
15561382
1557
- cmd = container_of(header, struct vmw_query_cmd, header);
1383
+ cmd = container_of(header, typeof(*cmd), header);
15581384 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
15591385 if (unlikely(ret != 0))
15601386 return ret;
15611387
1562
- ret = vmw_translate_mob_ptr(dev_priv, sw_context,
1563
- &cmd->q.mobid,
1388
+ ret = vmw_translate_mob_ptr(dev_priv, sw_context, &cmd->body.mobid,
15641389 &vmw_bo);
15651390 if (unlikely(ret != 0))
15661391 return ret;
15671392
15681393 ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context);
15691394
1570
- vmw_bo_unreference(&vmw_bo);
15711395 return ret;
15721396 }
15731397
15741398 /**
1575
- * vmw_cmd_end_query - validate a SVGA_3D_CMD_END_QUERY command.
1399
+ * vmw_cmd_end_query - validate SVGA_3D_CMD_END_QUERY command.
15761400 *
15771401 * @dev_priv: Pointer to a device private struct.
15781402 * @sw_context: The software context used for this command submission.
....@@ -1583,27 +1407,21 @@
15831407 SVGA3dCmdHeader *header)
15841408 {
15851409 struct vmw_buffer_object *vmw_bo;
1586
- struct vmw_query_cmd {
1587
- SVGA3dCmdHeader header;
1588
- SVGA3dCmdEndQuery q;
1589
- } *cmd;
1410
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdEndQuery);
15901411 int ret;
15911412
1592
- cmd = container_of(header, struct vmw_query_cmd, header);
1413
+ cmd = container_of(header, typeof(*cmd), header);
15931414 if (dev_priv->has_mob) {
1594
- struct {
1595
- SVGA3dCmdHeader header;
1596
- SVGA3dCmdEndGBQuery q;
1597
- } gb_cmd;
1415
+ VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdEndGBQuery);
15981416
15991417 BUG_ON(sizeof(gb_cmd) != sizeof(*cmd));
16001418
16011419 gb_cmd.header.id = SVGA_3D_CMD_END_GB_QUERY;
16021420 gb_cmd.header.size = cmd->header.size;
1603
- gb_cmd.q.cid = cmd->q.cid;
1604
- gb_cmd.q.type = cmd->q.type;
1605
- gb_cmd.q.mobid = cmd->q.guestResult.gmrId;
1606
- gb_cmd.q.offset = cmd->q.guestResult.offset;
1421
+ gb_cmd.body.cid = cmd->body.cid;
1422
+ gb_cmd.body.type = cmd->body.type;
1423
+ gb_cmd.body.mobid = cmd->body.guestResult.gmrId;
1424
+ gb_cmd.body.offset = cmd->body.guestResult.offset;
16071425
16081426 memcpy(cmd, &gb_cmd, sizeof(*cmd));
16091427 return vmw_cmd_end_gb_query(dev_priv, sw_context, header);
....@@ -1614,19 +1432,17 @@
16141432 return ret;
16151433
16161434 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
1617
- &cmd->q.guestResult,
1618
- &vmw_bo);
1435
+ &cmd->body.guestResult, &vmw_bo);
16191436 if (unlikely(ret != 0))
16201437 return ret;
16211438
16221439 ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context);
16231440
1624
- vmw_bo_unreference(&vmw_bo);
16251441 return ret;
16261442 }
16271443
16281444 /**
1629
- * vmw_cmd_wait_gb_query - validate a SVGA_3D_CMD_WAIT_GB_QUERY command.
1445
+ * vmw_cmd_wait_gb_query - validate SVGA_3D_CMD_WAIT_GB_QUERY command.
16301446 *
16311447 * @dev_priv: Pointer to a device private struct.
16321448 * @sw_context: The software context used for this command submission.
....@@ -1637,29 +1453,24 @@
16371453 SVGA3dCmdHeader *header)
16381454 {
16391455 struct vmw_buffer_object *vmw_bo;
1640
- struct vmw_query_cmd {
1641
- SVGA3dCmdHeader header;
1642
- SVGA3dCmdWaitForGBQuery q;
1643
- } *cmd;
1456
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdWaitForGBQuery);
16441457 int ret;
16451458
1646
- cmd = container_of(header, struct vmw_query_cmd, header);
1459
+ cmd = container_of(header, typeof(*cmd), header);
16471460 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
16481461 if (unlikely(ret != 0))
16491462 return ret;
16501463
1651
- ret = vmw_translate_mob_ptr(dev_priv, sw_context,
1652
- &cmd->q.mobid,
1464
+ ret = vmw_translate_mob_ptr(dev_priv, sw_context, &cmd->body.mobid,
16531465 &vmw_bo);
16541466 if (unlikely(ret != 0))
16551467 return ret;
16561468
1657
- vmw_bo_unreference(&vmw_bo);
16581469 return 0;
16591470 }
16601471
16611472 /**
1662
- * vmw_cmd_wait_query - validate a SVGA_3D_CMD_WAIT_QUERY command.
1473
+ * vmw_cmd_wait_query - validate SVGA_3D_CMD_WAIT_QUERY command.
16631474 *
16641475 * @dev_priv: Pointer to a device private struct.
16651476 * @sw_context: The software context used for this command submission.
....@@ -1670,27 +1481,21 @@
16701481 SVGA3dCmdHeader *header)
16711482 {
16721483 struct vmw_buffer_object *vmw_bo;
1673
- struct vmw_query_cmd {
1674
- SVGA3dCmdHeader header;
1675
- SVGA3dCmdWaitForQuery q;
1676
- } *cmd;
1484
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdWaitForQuery);
16771485 int ret;
16781486
1679
- cmd = container_of(header, struct vmw_query_cmd, header);
1487
+ cmd = container_of(header, typeof(*cmd), header);
16801488 if (dev_priv->has_mob) {
1681
- struct {
1682
- SVGA3dCmdHeader header;
1683
- SVGA3dCmdWaitForGBQuery q;
1684
- } gb_cmd;
1489
+ VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdWaitForGBQuery);
16851490
16861491 BUG_ON(sizeof(gb_cmd) != sizeof(*cmd));
16871492
16881493 gb_cmd.header.id = SVGA_3D_CMD_WAIT_FOR_GB_QUERY;
16891494 gb_cmd.header.size = cmd->header.size;
1690
- gb_cmd.q.cid = cmd->q.cid;
1691
- gb_cmd.q.type = cmd->q.type;
1692
- gb_cmd.q.mobid = cmd->q.guestResult.gmrId;
1693
- gb_cmd.q.offset = cmd->q.guestResult.offset;
1495
+ gb_cmd.body.cid = cmd->body.cid;
1496
+ gb_cmd.body.type = cmd->body.type;
1497
+ gb_cmd.body.mobid = cmd->body.guestResult.gmrId;
1498
+ gb_cmd.body.offset = cmd->body.guestResult.offset;
16941499
16951500 memcpy(cmd, &gb_cmd, sizeof(*cmd));
16961501 return vmw_cmd_wait_gb_query(dev_priv, sw_context, header);
....@@ -1701,12 +1506,10 @@
17011506 return ret;
17021507
17031508 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
1704
- &cmd->q.guestResult,
1705
- &vmw_bo);
1509
+ &cmd->body.guestResult, &vmw_bo);
17061510 if (unlikely(ret != 0))
17071511 return ret;
17081512
1709
- vmw_bo_unreference(&vmw_bo);
17101513 return 0;
17111514 }
17121515
....@@ -1716,68 +1519,61 @@
17161519 {
17171520 struct vmw_buffer_object *vmw_bo = NULL;
17181521 struct vmw_surface *srf = NULL;
1719
- struct vmw_dma_cmd {
1720
- SVGA3dCmdHeader header;
1721
- SVGA3dCmdSurfaceDMA dma;
1722
- } *cmd;
1522
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSurfaceDMA);
17231523 int ret;
17241524 SVGA3dCmdSurfaceDMASuffix *suffix;
17251525 uint32_t bo_size;
1526
+ bool dirty;
17261527
1727
- cmd = container_of(header, struct vmw_dma_cmd, header);
1728
- suffix = (SVGA3dCmdSurfaceDMASuffix *)((unsigned long) &cmd->dma +
1528
+ cmd = container_of(header, typeof(*cmd), header);
1529
+ suffix = (SVGA3dCmdSurfaceDMASuffix *)((unsigned long) &cmd->body +
17291530 header->size - sizeof(*suffix));
17301531
17311532 /* Make sure device and verifier stays in sync. */
17321533 if (unlikely(suffix->suffixSize != sizeof(*suffix))) {
1733
- DRM_ERROR("Invalid DMA suffix size.\n");
1534
+ VMW_DEBUG_USER("Invalid DMA suffix size.\n");
17341535 return -EINVAL;
17351536 }
17361537
17371538 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
1738
- &cmd->dma.guest.ptr,
1739
- &vmw_bo);
1539
+ &cmd->body.guest.ptr, &vmw_bo);
17401540 if (unlikely(ret != 0))
17411541 return ret;
17421542
17431543 /* Make sure DMA doesn't cross BO boundaries. */
17441544 bo_size = vmw_bo->base.num_pages * PAGE_SIZE;
1745
- if (unlikely(cmd->dma.guest.ptr.offset > bo_size)) {
1746
- DRM_ERROR("Invalid DMA offset.\n");
1545
+ if (unlikely(cmd->body.guest.ptr.offset > bo_size)) {
1546
+ VMW_DEBUG_USER("Invalid DMA offset.\n");
17471547 return -EINVAL;
17481548 }
17491549
1750
- bo_size -= cmd->dma.guest.ptr.offset;
1550
+ bo_size -= cmd->body.guest.ptr.offset;
17511551 if (unlikely(suffix->maximumOffset > bo_size))
17521552 suffix->maximumOffset = bo_size;
17531553
1554
+ dirty = (cmd->body.transfer == SVGA3D_WRITE_HOST_VRAM) ?
1555
+ VMW_RES_DIRTY_SET : 0;
17541556 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1755
- user_surface_converter, &cmd->dma.host.sid,
1756
- NULL);
1557
+ dirty, user_surface_converter,
1558
+ &cmd->body.host.sid, NULL);
17571559 if (unlikely(ret != 0)) {
17581560 if (unlikely(ret != -ERESTARTSYS))
1759
- DRM_ERROR("could not find surface for DMA.\n");
1760
- goto out_no_surface;
1561
+ VMW_DEBUG_USER("could not find surface for DMA.\n");
1562
+ return ret;
17611563 }
17621564
17631565 srf = vmw_res_to_srf(sw_context->res_cache[vmw_res_surface].res);
17641566
1765
- vmw_kms_cursor_snoop(srf, sw_context->fp->tfile, &vmw_bo->base,
1766
- header);
1567
+ vmw_kms_cursor_snoop(srf, sw_context->fp->tfile, &vmw_bo->base, header);
17671568
1768
-out_no_surface:
1769
- vmw_bo_unreference(&vmw_bo);
1770
- return ret;
1569
+ return 0;
17711570 }
17721571
17731572 static int vmw_cmd_draw(struct vmw_private *dev_priv,
17741573 struct vmw_sw_context *sw_context,
17751574 SVGA3dCmdHeader *header)
17761575 {
1777
- struct vmw_draw_cmd {
1778
- SVGA3dCmdHeader header;
1779
- SVGA3dCmdDrawPrimitives body;
1780
- } *cmd;
1576
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDrawPrimitives);
17811577 SVGA3dVertexDecl *decl = (SVGA3dVertexDecl *)(
17821578 (unsigned long)header + sizeof(*cmd));
17831579 SVGA3dPrimitiveRange *range;
....@@ -1789,16 +1585,17 @@
17891585 if (unlikely(ret != 0))
17901586 return ret;
17911587
1792
- cmd = container_of(header, struct vmw_draw_cmd, header);
1588
+ cmd = container_of(header, typeof(*cmd), header);
17931589 maxnum = (header->size - sizeof(cmd->body)) / sizeof(*decl);
17941590
17951591 if (unlikely(cmd->body.numVertexDecls > maxnum)) {
1796
- DRM_ERROR("Illegal number of vertex declarations.\n");
1592
+ VMW_DEBUG_USER("Illegal number of vertex declarations.\n");
17971593 return -EINVAL;
17981594 }
17991595
18001596 for (i = 0; i < cmd->body.numVertexDecls; ++i, ++decl) {
18011597 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1598
+ VMW_RES_DIRTY_NONE,
18021599 user_surface_converter,
18031600 &decl->array.surfaceId, NULL);
18041601 if (unlikely(ret != 0))
....@@ -1808,13 +1605,14 @@
18081605 maxnum = (header->size - sizeof(cmd->body) -
18091606 cmd->body.numVertexDecls * sizeof(*decl)) / sizeof(*range);
18101607 if (unlikely(cmd->body.numRanges > maxnum)) {
1811
- DRM_ERROR("Illegal number of index ranges.\n");
1608
+ VMW_DEBUG_USER("Illegal number of index ranges.\n");
18121609 return -EINVAL;
18131610 }
18141611
18151612 range = (SVGA3dPrimitiveRange *) decl;
18161613 for (i = 0; i < cmd->body.numRanges; ++i, ++range) {
18171614 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1615
+ VMW_RES_DIRTY_NONE,
18181616 user_surface_converter,
18191617 &range->indexArray.surfaceId, NULL);
18201618 if (unlikely(ret != 0))
....@@ -1823,30 +1621,24 @@
18231621 return 0;
18241622 }
18251623
1826
-
18271624 static int vmw_cmd_tex_state(struct vmw_private *dev_priv,
18281625 struct vmw_sw_context *sw_context,
18291626 SVGA3dCmdHeader *header)
18301627 {
1831
- struct vmw_tex_state_cmd {
1832
- SVGA3dCmdHeader header;
1833
- SVGA3dCmdSetTextureState state;
1834
- } *cmd;
1835
-
1628
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetTextureState);
18361629 SVGA3dTextureState *last_state = (SVGA3dTextureState *)
18371630 ((unsigned long) header + header->size + sizeof(header));
18381631 SVGA3dTextureState *cur_state = (SVGA3dTextureState *)
1839
- ((unsigned long) header + sizeof(struct vmw_tex_state_cmd));
1840
- struct vmw_resource_val_node *ctx_node;
1841
- struct vmw_resource_val_node *res_node;
1632
+ ((unsigned long) header + sizeof(*cmd));
1633
+ struct vmw_resource *ctx;
1634
+ struct vmw_resource *res;
18421635 int ret;
18431636
1844
- cmd = container_of(header, struct vmw_tex_state_cmd,
1845
- header);
1637
+ cmd = container_of(header, typeof(*cmd), header);
18461638
18471639 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
1848
- user_context_converter, &cmd->state.cid,
1849
- &ctx_node);
1640
+ VMW_RES_DIRTY_SET, user_context_converter,
1641
+ &cmd->body.cid, &ctx);
18501642 if (unlikely(ret != 0))
18511643 return ret;
18521644
....@@ -1855,26 +1647,32 @@
18551647 continue;
18561648
18571649 if (cur_state->stage >= SVGA3D_NUM_TEXTURE_UNITS) {
1858
- DRM_ERROR("Illegal texture/sampler unit %u.\n",
1859
- (unsigned) cur_state->stage);
1650
+ VMW_DEBUG_USER("Illegal texture/sampler unit %u.\n",
1651
+ (unsigned int) cur_state->stage);
18601652 return -EINVAL;
18611653 }
18621654
18631655 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
1656
+ VMW_RES_DIRTY_NONE,
18641657 user_surface_converter,
1865
- &cur_state->value, &res_node);
1658
+ &cur_state->value, &res);
18661659 if (unlikely(ret != 0))
18671660 return ret;
18681661
18691662 if (dev_priv->has_mob) {
18701663 struct vmw_ctx_bindinfo_tex binding;
1664
+ struct vmw_ctx_validation_info *node;
18711665
1872
- binding.bi.ctx = ctx_node->res;
1873
- binding.bi.res = res_node ? res_node->res : NULL;
1666
+ node = vmw_execbuf_info_from_res(sw_context, ctx);
1667
+ if (!node)
1668
+ return -EINVAL;
1669
+
1670
+ binding.bi.ctx = ctx;
1671
+ binding.bi.res = res;
18741672 binding.bi.bt = vmw_ctx_binding_tex;
18751673 binding.texture_stage = cur_state->stage;
1876
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
1877
- 0, binding.texture_stage);
1674
+ vmw_binding_add(node->staged, &binding.bi, 0,
1675
+ binding.texture_stage);
18781676 }
18791677 }
18801678
....@@ -1886,24 +1684,15 @@
18861684 void *buf)
18871685 {
18881686 struct vmw_buffer_object *vmw_bo;
1889
- int ret;
18901687
18911688 struct {
18921689 uint32_t header;
18931690 SVGAFifoCmdDefineGMRFB body;
18941691 } *cmd = buf;
18951692
1896
- ret = vmw_translate_guest_ptr(dev_priv, sw_context,
1897
- &cmd->body.ptr,
1898
- &vmw_bo);
1899
- if (unlikely(ret != 0))
1900
- return ret;
1901
-
1902
- vmw_bo_unreference(&vmw_bo);
1903
-
1904
- return ret;
1693
+ return vmw_translate_guest_ptr(dev_priv, sw_context, &cmd->body.ptr,
1694
+ &vmw_bo);
19051695 }
1906
-
19071696
19081697 /**
19091698 * vmw_cmd_res_switch_backup - Utility function to handle backup buffer
....@@ -1916,34 +1705,31 @@
19161705 * stream.
19171706 * @backup_offset: Offset of backup into MOB.
19181707 *
1919
- * This function prepares for registering a switch of backup buffers
1920
- * in the resource metadata just prior to unreserving. It's basically a wrapper
1921
- * around vmw_cmd_res_switch_backup with a different interface.
1708
+ * This function prepares for registering a switch of backup buffers in the
1709
+ * resource metadata just prior to unreserving. It's basically a wrapper around
1710
+ * vmw_cmd_res_switch_backup with a different interface.
19221711 */
19231712 static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv,
19241713 struct vmw_sw_context *sw_context,
1925
- struct vmw_resource_val_node *val_node,
1926
- uint32_t *buf_id,
1714
+ struct vmw_resource *res, uint32_t *buf_id,
19271715 unsigned long backup_offset)
19281716 {
1929
- struct vmw_buffer_object *dma_buf;
1717
+ struct vmw_buffer_object *vbo;
1718
+ void *info;
19301719 int ret;
19311720
1932
- ret = vmw_translate_mob_ptr(dev_priv, sw_context, buf_id, &dma_buf);
1721
+ info = vmw_execbuf_info_from_res(sw_context, res);
1722
+ if (!info)
1723
+ return -EINVAL;
1724
+
1725
+ ret = vmw_translate_mob_ptr(dev_priv, sw_context, buf_id, &vbo);
19331726 if (ret)
19341727 return ret;
19351728
1936
- val_node->switching_backup = true;
1937
- if (val_node->first_usage)
1938
- val_node->no_buffer_needed = true;
1939
-
1940
- vmw_bo_unreference(&val_node->new_backup);
1941
- val_node->new_backup = dma_buf;
1942
- val_node->new_backup_offset = backup_offset;
1943
-
1729
+ vmw_validation_res_switch_backup(sw_context->ctx, info, vbo,
1730
+ backup_offset);
19441731 return 0;
19451732 }
1946
-
19471733
19481734 /**
19491735 * vmw_cmd_switch_backup - Utility function to handle backup buffer switching
....@@ -1957,34 +1743,31 @@
19571743 * stream.
19581744 * @backup_offset: Offset of backup into MOB.
19591745 *
1960
- * This function prepares for registering a switch of backup buffers
1961
- * in the resource metadata just prior to unreserving. It's basically a wrapper
1962
- * around vmw_cmd_res_switch_backup with a different interface.
1746
+ * This function prepares for registering a switch of backup buffers in the
1747
+ * resource metadata just prior to unreserving. It's basically a wrapper around
1748
+ * vmw_cmd_res_switch_backup with a different interface.
19631749 */
19641750 static int vmw_cmd_switch_backup(struct vmw_private *dev_priv,
19651751 struct vmw_sw_context *sw_context,
19661752 enum vmw_res_type res_type,
19671753 const struct vmw_user_resource_conv
1968
- *converter,
1969
- uint32_t *res_id,
1970
- uint32_t *buf_id,
1754
+ *converter, uint32_t *res_id, uint32_t *buf_id,
19711755 unsigned long backup_offset)
19721756 {
1973
- struct vmw_resource_val_node *val_node;
1757
+ struct vmw_resource *res;
19741758 int ret;
19751759
19761760 ret = vmw_cmd_res_check(dev_priv, sw_context, res_type,
1977
- converter, res_id, &val_node);
1761
+ VMW_RES_DIRTY_NONE, converter, res_id, &res);
19781762 if (ret)
19791763 return ret;
19801764
1981
- return vmw_cmd_res_switch_backup(dev_priv, sw_context, val_node,
1982
- buf_id, backup_offset);
1765
+ return vmw_cmd_res_switch_backup(dev_priv, sw_context, res, buf_id,
1766
+ backup_offset);
19831767 }
19841768
19851769 /**
1986
- * vmw_cmd_bind_gb_surface - Validate an SVGA_3D_CMD_BIND_GB_SURFACE
1987
- * command
1770
+ * vmw_cmd_bind_gb_surface - Validate SVGA_3D_CMD_BIND_GB_SURFACE command
19881771 *
19891772 * @dev_priv: Pointer to a device private struct.
19901773 * @sw_context: The software context being used for this batch.
....@@ -1994,22 +1777,16 @@
19941777 struct vmw_sw_context *sw_context,
19951778 SVGA3dCmdHeader *header)
19961779 {
1997
- struct vmw_bind_gb_surface_cmd {
1998
- SVGA3dCmdHeader header;
1999
- SVGA3dCmdBindGBSurface body;
2000
- } *cmd;
2001
-
2002
- cmd = container_of(header, struct vmw_bind_gb_surface_cmd, header);
1780
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBindGBSurface) =
1781
+ container_of(header, typeof(*cmd), header);
20031782
20041783 return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_surface,
2005
- user_surface_converter,
2006
- &cmd->body.sid, &cmd->body.mobid,
2007
- 0);
1784
+ user_surface_converter, &cmd->body.sid,
1785
+ &cmd->body.mobid, 0);
20081786 }
20091787
20101788 /**
2011
- * vmw_cmd_update_gb_image - Validate an SVGA_3D_CMD_UPDATE_GB_IMAGE
2012
- * command
1789
+ * vmw_cmd_update_gb_image - Validate SVGA_3D_CMD_UPDATE_GB_IMAGE command
20131790 *
20141791 * @dev_priv: Pointer to a device private struct.
20151792 * @sw_context: The software context being used for this batch.
....@@ -2019,21 +1796,16 @@
20191796 struct vmw_sw_context *sw_context,
20201797 SVGA3dCmdHeader *header)
20211798 {
2022
- struct vmw_gb_surface_cmd {
2023
- SVGA3dCmdHeader header;
2024
- SVGA3dCmdUpdateGBImage body;
2025
- } *cmd;
2026
-
2027
- cmd = container_of(header, struct vmw_gb_surface_cmd, header);
1799
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdUpdateGBImage) =
1800
+ container_of(header, typeof(*cmd), header);
20281801
20291802 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2030
- user_surface_converter,
1803
+ VMW_RES_DIRTY_NONE, user_surface_converter,
20311804 &cmd->body.image.sid, NULL);
20321805 }
20331806
20341807 /**
2035
- * vmw_cmd_update_gb_surface - Validate an SVGA_3D_CMD_UPDATE_GB_SURFACE
2036
- * command
1808
+ * vmw_cmd_update_gb_surface - Validate SVGA_3D_CMD_UPDATE_GB_SURFACE command
20371809 *
20381810 * @dev_priv: Pointer to a device private struct.
20391811 * @sw_context: The software context being used for this batch.
....@@ -2043,21 +1815,16 @@
20431815 struct vmw_sw_context *sw_context,
20441816 SVGA3dCmdHeader *header)
20451817 {
2046
- struct vmw_gb_surface_cmd {
2047
- SVGA3dCmdHeader header;
2048
- SVGA3dCmdUpdateGBSurface body;
2049
- } *cmd;
2050
-
2051
- cmd = container_of(header, struct vmw_gb_surface_cmd, header);
1818
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdUpdateGBSurface) =
1819
+ container_of(header, typeof(*cmd), header);
20521820
20531821 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2054
- user_surface_converter,
1822
+ VMW_RES_DIRTY_CLEAR, user_surface_converter,
20551823 &cmd->body.sid, NULL);
20561824 }
20571825
20581826 /**
2059
- * vmw_cmd_readback_gb_image - Validate an SVGA_3D_CMD_READBACK_GB_IMAGE
2060
- * command
1827
+ * vmw_cmd_readback_gb_image - Validate SVGA_3D_CMD_READBACK_GB_IMAGE command
20611828 *
20621829 * @dev_priv: Pointer to a device private struct.
20631830 * @sw_context: The software context being used for this batch.
....@@ -2067,20 +1834,16 @@
20671834 struct vmw_sw_context *sw_context,
20681835 SVGA3dCmdHeader *header)
20691836 {
2070
- struct vmw_gb_surface_cmd {
2071
- SVGA3dCmdHeader header;
2072
- SVGA3dCmdReadbackGBImage body;
2073
- } *cmd;
2074
-
2075
- cmd = container_of(header, struct vmw_gb_surface_cmd, header);
1837
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdReadbackGBImage) =
1838
+ container_of(header, typeof(*cmd), header);
20761839
20771840 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2078
- user_surface_converter,
1841
+ VMW_RES_DIRTY_NONE, user_surface_converter,
20791842 &cmd->body.image.sid, NULL);
20801843 }
20811844
20821845 /**
2083
- * vmw_cmd_readback_gb_surface - Validate an SVGA_3D_CMD_READBACK_GB_SURFACE
1846
+ * vmw_cmd_readback_gb_surface - Validate SVGA_3D_CMD_READBACK_GB_SURFACE
20841847 * command
20851848 *
20861849 * @dev_priv: Pointer to a device private struct.
....@@ -2091,20 +1854,16 @@
20911854 struct vmw_sw_context *sw_context,
20921855 SVGA3dCmdHeader *header)
20931856 {
2094
- struct vmw_gb_surface_cmd {
2095
- SVGA3dCmdHeader header;
2096
- SVGA3dCmdReadbackGBSurface body;
2097
- } *cmd;
2098
-
2099
- cmd = container_of(header, struct vmw_gb_surface_cmd, header);
1857
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdReadbackGBSurface) =
1858
+ container_of(header, typeof(*cmd), header);
21001859
21011860 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2102
- user_surface_converter,
1861
+ VMW_RES_DIRTY_CLEAR, user_surface_converter,
21031862 &cmd->body.sid, NULL);
21041863 }
21051864
21061865 /**
2107
- * vmw_cmd_invalidate_gb_image - Validate an SVGA_3D_CMD_INVALIDATE_GB_IMAGE
1866
+ * vmw_cmd_invalidate_gb_image - Validate SVGA_3D_CMD_INVALIDATE_GB_IMAGE
21081867 * command
21091868 *
21101869 * @dev_priv: Pointer to a device private struct.
....@@ -2115,21 +1874,17 @@
21151874 struct vmw_sw_context *sw_context,
21161875 SVGA3dCmdHeader *header)
21171876 {
2118
- struct vmw_gb_surface_cmd {
2119
- SVGA3dCmdHeader header;
2120
- SVGA3dCmdInvalidateGBImage body;
2121
- } *cmd;
2122
-
2123
- cmd = container_of(header, struct vmw_gb_surface_cmd, header);
1877
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdInvalidateGBImage) =
1878
+ container_of(header, typeof(*cmd), header);
21241879
21251880 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2126
- user_surface_converter,
1881
+ VMW_RES_DIRTY_NONE, user_surface_converter,
21271882 &cmd->body.image.sid, NULL);
21281883 }
21291884
21301885 /**
2131
- * vmw_cmd_invalidate_gb_surface - Validate an
2132
- * SVGA_3D_CMD_INVALIDATE_GB_SURFACE command
1886
+ * vmw_cmd_invalidate_gb_surface - Validate SVGA_3D_CMD_INVALIDATE_GB_SURFACE
1887
+ * command
21331888 *
21341889 * @dev_priv: Pointer to a device private struct.
21351890 * @sw_context: The software context being used for this batch.
....@@ -2139,22 +1894,16 @@
21391894 struct vmw_sw_context *sw_context,
21401895 SVGA3dCmdHeader *header)
21411896 {
2142
- struct vmw_gb_surface_cmd {
2143
- SVGA3dCmdHeader header;
2144
- SVGA3dCmdInvalidateGBSurface body;
2145
- } *cmd;
2146
-
2147
- cmd = container_of(header, struct vmw_gb_surface_cmd, header);
1897
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdInvalidateGBSurface) =
1898
+ container_of(header, typeof(*cmd), header);
21481899
21491900 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2150
- user_surface_converter,
1901
+ VMW_RES_DIRTY_CLEAR, user_surface_converter,
21511902 &cmd->body.sid, NULL);
21521903 }
21531904
2154
-
21551905 /**
2156
- * vmw_cmd_shader_define - Validate an SVGA_3D_CMD_SHADER_DEFINE
2157
- * command
1906
+ * vmw_cmd_shader_define - Validate SVGA_3D_CMD_SHADER_DEFINE command
21581907 *
21591908 * @dev_priv: Pointer to a device private struct.
21601909 * @sw_context: The software context being used for this batch.
....@@ -2164,20 +1913,16 @@
21641913 struct vmw_sw_context *sw_context,
21651914 SVGA3dCmdHeader *header)
21661915 {
2167
- struct vmw_shader_define_cmd {
2168
- SVGA3dCmdHeader header;
2169
- SVGA3dCmdDefineShader body;
2170
- } *cmd;
1916
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDefineShader);
21711917 int ret;
21721918 size_t size;
2173
- struct vmw_resource_val_node *val;
1919
+ struct vmw_resource *ctx;
21741920
2175
- cmd = container_of(header, struct vmw_shader_define_cmd,
2176
- header);
1921
+ cmd = container_of(header, typeof(*cmd), header);
21771922
21781923 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
2179
- user_context_converter, &cmd->body.cid,
2180
- &val);
1924
+ VMW_RES_DIRTY_SET, user_context_converter,
1925
+ &cmd->body.cid, &ctx);
21811926 if (unlikely(ret != 0))
21821927 return ret;
21831928
....@@ -2185,24 +1930,20 @@
21851930 return 0;
21861931
21871932 size = cmd->header.size - sizeof(cmd->body);
2188
- ret = vmw_compat_shader_add(dev_priv,
2189
- vmw_context_res_man(val->res),
2190
- cmd->body.shid, cmd + 1,
2191
- cmd->body.type, size,
2192
- &sw_context->staged_cmd_res);
1933
+ ret = vmw_compat_shader_add(dev_priv, vmw_context_res_man(ctx),
1934
+ cmd->body.shid, cmd + 1, cmd->body.type,
1935
+ size, &sw_context->staged_cmd_res);
21931936 if (unlikely(ret != 0))
21941937 return ret;
21951938
2196
- return vmw_resource_relocation_add(&sw_context->res_relocations,
2197
- NULL,
1939
+ return vmw_resource_relocation_add(sw_context, NULL,
21981940 vmw_ptr_diff(sw_context->buf_start,
21991941 &cmd->header.id),
22001942 vmw_res_rel_nop);
22011943 }
22021944
22031945 /**
2204
- * vmw_cmd_shader_destroy - Validate an SVGA_3D_CMD_SHADER_DESTROY
2205
- * command
1946
+ * vmw_cmd_shader_destroy - Validate SVGA_3D_CMD_SHADER_DESTROY command
22061947 *
22071948 * @dev_priv: Pointer to a device private struct.
22081949 * @sw_context: The software context being used for this batch.
....@@ -2212,42 +1953,34 @@
22121953 struct vmw_sw_context *sw_context,
22131954 SVGA3dCmdHeader *header)
22141955 {
2215
- struct vmw_shader_destroy_cmd {
2216
- SVGA3dCmdHeader header;
2217
- SVGA3dCmdDestroyShader body;
2218
- } *cmd;
1956
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDestroyShader);
22191957 int ret;
2220
- struct vmw_resource_val_node *val;
1958
+ struct vmw_resource *ctx;
22211959
2222
- cmd = container_of(header, struct vmw_shader_destroy_cmd,
2223
- header);
1960
+ cmd = container_of(header, typeof(*cmd), header);
22241961
22251962 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
2226
- user_context_converter, &cmd->body.cid,
2227
- &val);
1963
+ VMW_RES_DIRTY_SET, user_context_converter,
1964
+ &cmd->body.cid, &ctx);
22281965 if (unlikely(ret != 0))
22291966 return ret;
22301967
22311968 if (unlikely(!dev_priv->has_mob))
22321969 return 0;
22331970
2234
- ret = vmw_shader_remove(vmw_context_res_man(val->res),
2235
- cmd->body.shid,
2236
- cmd->body.type,
2237
- &sw_context->staged_cmd_res);
1971
+ ret = vmw_shader_remove(vmw_context_res_man(ctx), cmd->body.shid,
1972
+ cmd->body.type, &sw_context->staged_cmd_res);
22381973 if (unlikely(ret != 0))
22391974 return ret;
22401975
2241
- return vmw_resource_relocation_add(&sw_context->res_relocations,
2242
- NULL,
1976
+ return vmw_resource_relocation_add(sw_context, NULL,
22431977 vmw_ptr_diff(sw_context->buf_start,
22441978 &cmd->header.id),
22451979 vmw_res_rel_nop);
22461980 }
22471981
22481982 /**
2249
- * vmw_cmd_set_shader - Validate an SVGA_3D_CMD_SET_SHADER
2250
- * command
1983
+ * vmw_cmd_set_shader - Validate SVGA_3D_CMD_SET_SHADER command
22511984 *
22521985 * @dev_priv: Pointer to a device private struct.
22531986 * @sw_context: The software context being used for this batch.
....@@ -2257,27 +1990,23 @@
22571990 struct vmw_sw_context *sw_context,
22581991 SVGA3dCmdHeader *header)
22591992 {
2260
- struct vmw_set_shader_cmd {
2261
- SVGA3dCmdHeader header;
2262
- SVGA3dCmdSetShader body;
2263
- } *cmd;
2264
- struct vmw_resource_val_node *ctx_node, *res_node = NULL;
1993
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetShader);
22651994 struct vmw_ctx_bindinfo_shader binding;
2266
- struct vmw_resource *res = NULL;
1995
+ struct vmw_resource *ctx, *res = NULL;
1996
+ struct vmw_ctx_validation_info *ctx_info;
22671997 int ret;
22681998
2269
- cmd = container_of(header, struct vmw_set_shader_cmd,
2270
- header);
1999
+ cmd = container_of(header, typeof(*cmd), header);
22712000
2272
- if (cmd->body.type >= SVGA3D_SHADERTYPE_PREDX_MAX) {
2273
- DRM_ERROR("Illegal shader type %u.\n",
2274
- (unsigned) cmd->body.type);
2001
+ if (!vmw_shadertype_is_valid(VMW_SM_LEGACY, cmd->body.type)) {
2002
+ VMW_DEBUG_USER("Illegal shader type %u.\n",
2003
+ (unsigned int) cmd->body.type);
22752004 return -EINVAL;
22762005 }
22772006
22782007 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
2279
- user_context_converter, &cmd->body.cid,
2280
- &ctx_node);
2008
+ VMW_RES_DIRTY_SET, user_context_converter,
2009
+ &cmd->body.cid, &ctx);
22812010 if (unlikely(ret != 0))
22822011 return ret;
22832012
....@@ -2285,41 +2014,53 @@
22852014 return 0;
22862015
22872016 if (cmd->body.shid != SVGA3D_INVALID_ID) {
2288
- res = vmw_shader_lookup(vmw_context_res_man(ctx_node->res),
2289
- cmd->body.shid,
2290
- cmd->body.type);
2291
-
2017
+ /*
2018
+ * This is the compat shader path - Per device guest-backed
2019
+ * shaders, but user-space thinks it's per context host-
2020
+ * backed shaders.
2021
+ */
2022
+ res = vmw_shader_lookup(vmw_context_res_man(ctx),
2023
+ cmd->body.shid, cmd->body.type);
22922024 if (!IS_ERR(res)) {
2293
- ret = vmw_cmd_res_reloc_add(dev_priv, sw_context,
2294
- &cmd->body.shid, res,
2295
- &res_node);
2296
- vmw_resource_unreference(&res);
2025
+ ret = vmw_execbuf_res_noctx_val_add(sw_context, res,
2026
+ VMW_RES_DIRTY_NONE);
2027
+ if (unlikely(ret != 0))
2028
+ return ret;
2029
+
2030
+ ret = vmw_resource_relocation_add
2031
+ (sw_context, res,
2032
+ vmw_ptr_diff(sw_context->buf_start,
2033
+ &cmd->body.shid),
2034
+ vmw_res_rel_normal);
22972035 if (unlikely(ret != 0))
22982036 return ret;
22992037 }
23002038 }
23012039
2302
- if (!res_node) {
2303
- ret = vmw_cmd_res_check(dev_priv, sw_context,
2304
- vmw_res_shader,
2305
- user_shader_converter,
2306
- &cmd->body.shid, &res_node);
2040
+ if (IS_ERR_OR_NULL(res)) {
2041
+ ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_shader,
2042
+ VMW_RES_DIRTY_NONE,
2043
+ user_shader_converter, &cmd->body.shid,
2044
+ &res);
23072045 if (unlikely(ret != 0))
23082046 return ret;
23092047 }
23102048
2311
- binding.bi.ctx = ctx_node->res;
2312
- binding.bi.res = res_node ? res_node->res : NULL;
2049
+ ctx_info = vmw_execbuf_info_from_res(sw_context, ctx);
2050
+ if (!ctx_info)
2051
+ return -EINVAL;
2052
+
2053
+ binding.bi.ctx = ctx;
2054
+ binding.bi.res = res;
23132055 binding.bi.bt = vmw_ctx_binding_shader;
23142056 binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN;
2315
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
2316
- binding.shader_slot, 0);
2057
+ vmw_binding_add(ctx_info->staged, &binding.bi, binding.shader_slot, 0);
2058
+
23172059 return 0;
23182060 }
23192061
23202062 /**
2321
- * vmw_cmd_set_shader_const - Validate an SVGA_3D_CMD_SET_SHADER_CONST
2322
- * command
2063
+ * vmw_cmd_set_shader_const - Validate SVGA_3D_CMD_SET_SHADER_CONST command
23232064 *
23242065 * @dev_priv: Pointer to a device private struct.
23252066 * @sw_context: The software context being used for this batch.
....@@ -2329,18 +2070,14 @@
23292070 struct vmw_sw_context *sw_context,
23302071 SVGA3dCmdHeader *header)
23312072 {
2332
- struct vmw_set_shader_const_cmd {
2333
- SVGA3dCmdHeader header;
2334
- SVGA3dCmdSetShaderConst body;
2335
- } *cmd;
2073
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetShaderConst);
23362074 int ret;
23372075
2338
- cmd = container_of(header, struct vmw_set_shader_const_cmd,
2339
- header);
2076
+ cmd = container_of(header, typeof(*cmd), header);
23402077
23412078 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
2342
- user_context_converter, &cmd->body.cid,
2343
- NULL);
2079
+ VMW_RES_DIRTY_SET, user_context_converter,
2080
+ &cmd->body.cid, NULL);
23442081 if (unlikely(ret != 0))
23452082 return ret;
23462083
....@@ -2351,8 +2088,7 @@
23512088 }
23522089
23532090 /**
2354
- * vmw_cmd_bind_gb_shader - Validate an SVGA_3D_CMD_BIND_GB_SHADER
2355
- * command
2091
+ * vmw_cmd_bind_gb_shader - Validate SVGA_3D_CMD_BIND_GB_SHADER command
23562092 *
23572093 * @dev_priv: Pointer to a device private struct.
23582094 * @sw_context: The software context being used for this batch.
....@@ -2362,22 +2098,16 @@
23622098 struct vmw_sw_context *sw_context,
23632099 SVGA3dCmdHeader *header)
23642100 {
2365
- struct vmw_bind_gb_shader_cmd {
2366
- SVGA3dCmdHeader header;
2367
- SVGA3dCmdBindGBShader body;
2368
- } *cmd;
2369
-
2370
- cmd = container_of(header, struct vmw_bind_gb_shader_cmd,
2371
- header);
2101
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBindGBShader) =
2102
+ container_of(header, typeof(*cmd), header);
23722103
23732104 return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_shader,
2374
- user_shader_converter,
2375
- &cmd->body.shid, &cmd->body.mobid,
2376
- cmd->body.offsetInBytes);
2105
+ user_shader_converter, &cmd->body.shid,
2106
+ &cmd->body.mobid, cmd->body.offsetInBytes);
23772107 }
23782108
23792109 /**
2380
- * vmw_cmd_dx_set_single_constant_buffer - Validate an
2110
+ * vmw_cmd_dx_set_single_constant_buffer - Validate
23812111 * SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER command.
23822112 *
23832113 * @dev_priv: Pointer to a device private struct.
....@@ -2389,52 +2119,48 @@
23892119 struct vmw_sw_context *sw_context,
23902120 SVGA3dCmdHeader *header)
23912121 {
2392
- struct {
2393
- SVGA3dCmdHeader header;
2394
- SVGA3dCmdDXSetSingleConstantBuffer body;
2395
- } *cmd;
2396
- struct vmw_resource_val_node *res_node = NULL;
2397
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2122
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetSingleConstantBuffer);
2123
+
2124
+ struct vmw_resource *res = NULL;
2125
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
23982126 struct vmw_ctx_bindinfo_cb binding;
23992127 int ret;
24002128
2401
- if (unlikely(ctx_node == NULL)) {
2402
- DRM_ERROR("DX Context not set.\n");
2129
+ if (!ctx_node)
24032130 return -EINVAL;
2404
- }
24052131
24062132 cmd = container_of(header, typeof(*cmd), header);
24072133 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2408
- user_surface_converter,
2409
- &cmd->body.sid, &res_node);
2134
+ VMW_RES_DIRTY_NONE, user_surface_converter,
2135
+ &cmd->body.sid, &res);
24102136 if (unlikely(ret != 0))
24112137 return ret;
24122138
2413
- binding.bi.ctx = ctx_node->res;
2414
- binding.bi.res = res_node ? res_node->res : NULL;
2139
+ if (!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type) ||
2140
+ cmd->body.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
2141
+ VMW_DEBUG_USER("Illegal const buffer shader %u slot %u.\n",
2142
+ (unsigned int) cmd->body.type,
2143
+ (unsigned int) cmd->body.slot);
2144
+ return -EINVAL;
2145
+ }
2146
+
2147
+ binding.bi.ctx = ctx_node->ctx;
2148
+ binding.bi.res = res;
24152149 binding.bi.bt = vmw_ctx_binding_cb;
24162150 binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN;
24172151 binding.offset = cmd->body.offsetInBytes;
24182152 binding.size = cmd->body.sizeInBytes;
24192153 binding.slot = cmd->body.slot;
24202154
2421
- if (binding.shader_slot >= SVGA3D_NUM_SHADERTYPE_DX10 ||
2422
- binding.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
2423
- DRM_ERROR("Illegal const buffer shader %u slot %u.\n",
2424
- (unsigned) cmd->body.type,
2425
- (unsigned) binding.slot);
2426
- return -EINVAL;
2427
- }
2428
-
2429
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
2430
- binding.shader_slot, binding.slot);
2155
+ vmw_binding_add(ctx_node->staged, &binding.bi, binding.shader_slot,
2156
+ binding.slot);
24312157
24322158 return 0;
24332159 }
24342160
24352161 /**
2436
- * vmw_cmd_dx_set_shader_res - Validate an
2437
- * SVGA_3D_CMD_DX_SET_SHADER_RESOURCES command
2162
+ * vmw_cmd_dx_set_shader_res - Validate SVGA_3D_CMD_DX_SET_SHADER_RESOURCES
2163
+ * command
24382164 *
24392165 * @dev_priv: Pointer to a device private struct.
24402166 * @sw_context: The software context being used for this batch.
....@@ -2444,17 +2170,16 @@
24442170 struct vmw_sw_context *sw_context,
24452171 SVGA3dCmdHeader *header)
24462172 {
2447
- struct {
2448
- SVGA3dCmdHeader header;
2449
- SVGA3dCmdDXSetShaderResources body;
2450
- } *cmd = container_of(header, typeof(*cmd), header);
2173
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShaderResources) =
2174
+ container_of(header, typeof(*cmd), header);
2175
+
24512176 u32 num_sr_view = (cmd->header.size - sizeof(cmd->body)) /
24522177 sizeof(SVGA3dShaderResourceViewId);
24532178
24542179 if ((u64) cmd->body.startView + (u64) num_sr_view >
24552180 (u64) SVGA3D_DX_MAX_SRVIEWS ||
2456
- cmd->body.type >= SVGA3D_SHADERTYPE_DX10_MAX) {
2457
- DRM_ERROR("Invalid shader binding.\n");
2181
+ !vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
2182
+ VMW_DEBUG_USER("Invalid shader binding.\n");
24582183 return -EINVAL;
24592184 }
24602185
....@@ -2466,8 +2191,7 @@
24662191 }
24672192
24682193 /**
2469
- * vmw_cmd_dx_set_shader - Validate an SVGA_3D_CMD_DX_SET_SHADER
2470
- * command
2194
+ * vmw_cmd_dx_set_shader - Validate SVGA_3D_CMD_DX_SET_SHADER command
24712195 *
24722196 * @dev_priv: Pointer to a device private struct.
24732197 * @sw_context: The software context being used for this batch.
....@@ -2477,58 +2201,49 @@
24772201 struct vmw_sw_context *sw_context,
24782202 SVGA3dCmdHeader *header)
24792203 {
2480
- struct {
2481
- SVGA3dCmdHeader header;
2482
- SVGA3dCmdDXSetShader body;
2483
- } *cmd;
2204
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShader);
24842205 struct vmw_resource *res = NULL;
2485
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2206
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
24862207 struct vmw_ctx_bindinfo_shader binding;
24872208 int ret = 0;
24882209
2489
- if (unlikely(ctx_node == NULL)) {
2490
- DRM_ERROR("DX Context not set.\n");
2210
+ if (!ctx_node)
24912211 return -EINVAL;
2492
- }
24932212
24942213 cmd = container_of(header, typeof(*cmd), header);
24952214
2496
- if (cmd->body.type >= SVGA3D_SHADERTYPE_DX10_MAX ||
2497
- cmd->body.type < SVGA3D_SHADERTYPE_MIN) {
2498
- DRM_ERROR("Illegal shader type %u.\n",
2499
- (unsigned) cmd->body.type);
2215
+ if (!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
2216
+ VMW_DEBUG_USER("Illegal shader type %u.\n",
2217
+ (unsigned int) cmd->body.type);
25002218 return -EINVAL;
25012219 }
25022220
25032221 if (cmd->body.shaderId != SVGA3D_INVALID_ID) {
25042222 res = vmw_shader_lookup(sw_context->man, cmd->body.shaderId, 0);
25052223 if (IS_ERR(res)) {
2506
- DRM_ERROR("Could not find shader for binding.\n");
2224
+ VMW_DEBUG_USER("Could not find shader for binding.\n");
25072225 return PTR_ERR(res);
25082226 }
25092227
2510
- ret = vmw_resource_val_add(sw_context, res, NULL);
2228
+ ret = vmw_execbuf_res_noctx_val_add(sw_context, res,
2229
+ VMW_RES_DIRTY_NONE);
25112230 if (ret)
2512
- goto out_unref;
2231
+ return ret;
25132232 }
25142233
2515
- binding.bi.ctx = ctx_node->res;
2234
+ binding.bi.ctx = ctx_node->ctx;
25162235 binding.bi.res = res;
25172236 binding.bi.bt = vmw_ctx_binding_dx_shader;
25182237 binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN;
25192238
2520
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
2521
- binding.shader_slot, 0);
2522
-out_unref:
2523
- if (res)
2524
- vmw_resource_unreference(&res);
2239
+ vmw_binding_add(ctx_node->staged, &binding.bi, binding.shader_slot, 0);
25252240
2526
- return ret;
2241
+ return 0;
25272242 }
25282243
25292244 /**
2530
- * vmw_cmd_dx_set_vertex_buffers - Validates an
2531
- * SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS command
2245
+ * vmw_cmd_dx_set_vertex_buffers - Validates SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS
2246
+ * command
25322247 *
25332248 * @dev_priv: Pointer to a device private struct.
25342249 * @sw_context: The software context being used for this batch.
....@@ -2538,9 +2253,9 @@
25382253 struct vmw_sw_context *sw_context,
25392254 SVGA3dCmdHeader *header)
25402255 {
2541
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2256
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
25422257 struct vmw_ctx_bindinfo_vb binding;
2543
- struct vmw_resource_val_node *res_node;
2258
+ struct vmw_resource *res;
25442259 struct {
25452260 SVGA3dCmdHeader header;
25462261 SVGA3dCmdDXSetVertexBuffers body;
....@@ -2548,43 +2263,41 @@
25482263 } *cmd;
25492264 int i, ret, num;
25502265
2551
- if (unlikely(ctx_node == NULL)) {
2552
- DRM_ERROR("DX Context not set.\n");
2266
+ if (!ctx_node)
25532267 return -EINVAL;
2554
- }
25552268
25562269 cmd = container_of(header, typeof(*cmd), header);
25572270 num = (cmd->header.size - sizeof(cmd->body)) /
25582271 sizeof(SVGA3dVertexBuffer);
25592272 if ((u64)num + (u64)cmd->body.startBuffer >
25602273 (u64)SVGA3D_DX_MAX_VERTEXBUFFERS) {
2561
- DRM_ERROR("Invalid number of vertex buffers.\n");
2274
+ VMW_DEBUG_USER("Invalid number of vertex buffers.\n");
25622275 return -EINVAL;
25632276 }
25642277
25652278 for (i = 0; i < num; i++) {
25662279 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2280
+ VMW_RES_DIRTY_NONE,
25672281 user_surface_converter,
2568
- &cmd->buf[i].sid, &res_node);
2282
+ &cmd->buf[i].sid, &res);
25692283 if (unlikely(ret != 0))
25702284 return ret;
25712285
2572
- binding.bi.ctx = ctx_node->res;
2286
+ binding.bi.ctx = ctx_node->ctx;
25732287 binding.bi.bt = vmw_ctx_binding_vb;
2574
- binding.bi.res = ((res_node) ? res_node->res : NULL);
2288
+ binding.bi.res = res;
25752289 binding.offset = cmd->buf[i].offset;
25762290 binding.stride = cmd->buf[i].stride;
25772291 binding.slot = i + cmd->body.startBuffer;
25782292
2579
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
2580
- 0, binding.slot);
2293
+ vmw_binding_add(ctx_node->staged, &binding.bi, 0, binding.slot);
25812294 }
25822295
25832296 return 0;
25842297 }
25852298
25862299 /**
2587
- * vmw_cmd_dx_ia_set_vertex_buffers - Validate an
2300
+ * vmw_cmd_dx_ia_set_vertex_buffers - Validate
25882301 * SVGA_3D_CMD_DX_IA_SET_INDEX_BUFFER command.
25892302 *
25902303 * @dev_priv: Pointer to a device private struct.
....@@ -2595,41 +2308,36 @@
25952308 struct vmw_sw_context *sw_context,
25962309 SVGA3dCmdHeader *header)
25972310 {
2598
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2311
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
25992312 struct vmw_ctx_bindinfo_ib binding;
2600
- struct vmw_resource_val_node *res_node;
2601
- struct {
2602
- SVGA3dCmdHeader header;
2603
- SVGA3dCmdDXSetIndexBuffer body;
2604
- } *cmd;
2313
+ struct vmw_resource *res;
2314
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetIndexBuffer);
26052315 int ret;
26062316
2607
- if (unlikely(ctx_node == NULL)) {
2608
- DRM_ERROR("DX Context not set.\n");
2317
+ if (!ctx_node)
26092318 return -EINVAL;
2610
- }
26112319
26122320 cmd = container_of(header, typeof(*cmd), header);
26132321 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2614
- user_surface_converter,
2615
- &cmd->body.sid, &res_node);
2322
+ VMW_RES_DIRTY_NONE, user_surface_converter,
2323
+ &cmd->body.sid, &res);
26162324 if (unlikely(ret != 0))
26172325 return ret;
26182326
2619
- binding.bi.ctx = ctx_node->res;
2620
- binding.bi.res = ((res_node) ? res_node->res : NULL);
2327
+ binding.bi.ctx = ctx_node->ctx;
2328
+ binding.bi.res = res;
26212329 binding.bi.bt = vmw_ctx_binding_ib;
26222330 binding.offset = cmd->body.offset;
26232331 binding.format = cmd->body.format;
26242332
2625
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi, 0, 0);
2333
+ vmw_binding_add(ctx_node->staged, &binding.bi, 0, 0);
26262334
26272335 return 0;
26282336 }
26292337
26302338 /**
2631
- * vmw_cmd_dx_set_rendertarget - Validate an
2632
- * SVGA_3D_CMD_DX_SET_RENDERTARGETS command
2339
+ * vmw_cmd_dx_set_rendertarget - Validate SVGA_3D_CMD_DX_SET_RENDERTARGETS
2340
+ * command
26332341 *
26342342 * @dev_priv: Pointer to a device private struct.
26352343 * @sw_context: The software context being used for this batch.
....@@ -2639,32 +2347,29 @@
26392347 struct vmw_sw_context *sw_context,
26402348 SVGA3dCmdHeader *header)
26412349 {
2642
- struct {
2643
- SVGA3dCmdHeader header;
2644
- SVGA3dCmdDXSetRenderTargets body;
2645
- } *cmd = container_of(header, typeof(*cmd), header);
2646
- int ret;
2350
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetRenderTargets) =
2351
+ container_of(header, typeof(*cmd), header);
26472352 u32 num_rt_view = (cmd->header.size - sizeof(cmd->body)) /
26482353 sizeof(SVGA3dRenderTargetViewId);
2354
+ int ret;
26492355
26502356 if (num_rt_view > SVGA3D_MAX_SIMULTANEOUS_RENDER_TARGETS) {
2651
- DRM_ERROR("Invalid DX Rendertarget binding.\n");
2357
+ VMW_DEBUG_USER("Invalid DX Rendertarget binding.\n");
26522358 return -EINVAL;
26532359 }
26542360
2655
- ret = vmw_view_bindings_add(sw_context, vmw_view_ds,
2656
- vmw_ctx_binding_ds, 0,
2657
- &cmd->body.depthStencilViewId, 1, 0);
2361
+ ret = vmw_view_bindings_add(sw_context, vmw_view_ds, vmw_ctx_binding_ds,
2362
+ 0, &cmd->body.depthStencilViewId, 1, 0);
26582363 if (ret)
26592364 return ret;
26602365
26612366 return vmw_view_bindings_add(sw_context, vmw_view_rt,
2662
- vmw_ctx_binding_dx_rt, 0,
2663
- (void *)&cmd[1], num_rt_view, 0);
2367
+ vmw_ctx_binding_dx_rt, 0, (void *)&cmd[1],
2368
+ num_rt_view, 0);
26642369 }
26652370
26662371 /**
2667
- * vmw_cmd_dx_clear_rendertarget_view - Validate an
2372
+ * vmw_cmd_dx_clear_rendertarget_view - Validate
26682373 * SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW command
26692374 *
26702375 * @dev_priv: Pointer to a device private struct.
....@@ -2675,17 +2380,18 @@
26752380 struct vmw_sw_context *sw_context,
26762381 SVGA3dCmdHeader *header)
26772382 {
2678
- struct {
2679
- SVGA3dCmdHeader header;
2680
- SVGA3dCmdDXClearRenderTargetView body;
2681
- } *cmd = container_of(header, typeof(*cmd), header);
2383
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXClearRenderTargetView) =
2384
+ container_of(header, typeof(*cmd), header);
2385
+ struct vmw_resource *ret;
26822386
2683
- return vmw_view_id_val_add(sw_context, vmw_view_rt,
2684
- cmd->body.renderTargetViewId);
2387
+ ret = vmw_view_id_val_add(sw_context, vmw_view_rt,
2388
+ cmd->body.renderTargetViewId);
2389
+
2390
+ return PTR_ERR_OR_ZERO(ret);
26852391 }
26862392
26872393 /**
2688
- * vmw_cmd_dx_clear_rendertarget_view - Validate an
2394
+ * vmw_cmd_dx_clear_rendertarget_view - Validate
26892395 * SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW command
26902396 *
26912397 * @dev_priv: Pointer to a device private struct.
....@@ -2696,27 +2402,28 @@
26962402 struct vmw_sw_context *sw_context,
26972403 SVGA3dCmdHeader *header)
26982404 {
2699
- struct {
2700
- SVGA3dCmdHeader header;
2701
- SVGA3dCmdDXClearDepthStencilView body;
2702
- } *cmd = container_of(header, typeof(*cmd), header);
2405
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXClearDepthStencilView) =
2406
+ container_of(header, typeof(*cmd), header);
2407
+ struct vmw_resource *ret;
27032408
2704
- return vmw_view_id_val_add(sw_context, vmw_view_ds,
2705
- cmd->body.depthStencilViewId);
2409
+ ret = vmw_view_id_val_add(sw_context, vmw_view_ds,
2410
+ cmd->body.depthStencilViewId);
2411
+
2412
+ return PTR_ERR_OR_ZERO(ret);
27062413 }
27072414
27082415 static int vmw_cmd_dx_view_define(struct vmw_private *dev_priv,
27092416 struct vmw_sw_context *sw_context,
27102417 SVGA3dCmdHeader *header)
27112418 {
2712
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2713
- struct vmw_resource_val_node *srf_node;
2419
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
2420
+ struct vmw_resource *srf;
27142421 struct vmw_resource *res;
27152422 enum vmw_view_type view_type;
27162423 int ret;
27172424 /*
2718
- * This is based on the fact that all affected define commands have
2719
- * the same initial command body layout.
2425
+ * This is based on the fact that all affected define commands have the
2426
+ * same initial command body layout.
27202427 */
27212428 struct {
27222429 SVGA3dCmdHeader header;
....@@ -2724,44 +2431,37 @@
27242431 uint32 sid;
27252432 } *cmd;
27262433
2727
- if (unlikely(ctx_node == NULL)) {
2728
- DRM_ERROR("DX Context not set.\n");
2434
+ if (!ctx_node)
27292435 return -EINVAL;
2730
- }
27312436
27322437 view_type = vmw_view_cmd_to_type(header->id);
27332438 if (view_type == vmw_view_max)
27342439 return -EINVAL;
2440
+
27352441 cmd = container_of(header, typeof(*cmd), header);
27362442 if (unlikely(cmd->sid == SVGA3D_INVALID_ID)) {
2737
- DRM_ERROR("Invalid surface id.\n");
2443
+ VMW_DEBUG_USER("Invalid surface id.\n");
27382444 return -EINVAL;
27392445 }
27402446 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2741
- user_surface_converter,
2742
- &cmd->sid, &srf_node);
2447
+ VMW_RES_DIRTY_NONE, user_surface_converter,
2448
+ &cmd->sid, &srf);
27432449 if (unlikely(ret != 0))
27442450 return ret;
27452451
2746
- res = vmw_context_cotable(ctx_node->res, vmw_view_cotables[view_type]);
2452
+ res = vmw_context_cotable(ctx_node->ctx, vmw_view_cotables[view_type]);
27472453 ret = vmw_cotable_notify(res, cmd->defined_id);
2748
- vmw_resource_unreference(&res);
27492454 if (unlikely(ret != 0))
27502455 return ret;
27512456
2752
- return vmw_view_add(sw_context->man,
2753
- ctx_node->res,
2754
- srf_node->res,
2755
- view_type,
2756
- cmd->defined_id,
2757
- header,
2457
+ return vmw_view_add(sw_context->man, ctx_node->ctx, srf, view_type,
2458
+ cmd->defined_id, header,
27582459 header->size + sizeof(*header),
27592460 &sw_context->staged_cmd_res);
27602461 }
27612462
27622463 /**
2763
- * vmw_cmd_dx_set_so_targets - Validate an
2764
- * SVGA_3D_CMD_DX_SET_SOTARGETS command.
2464
+ * vmw_cmd_dx_set_so_targets - Validate SVGA_3D_CMD_DX_SET_SOTARGETS command.
27652465 *
27662466 * @dev_priv: Pointer to a device private struct.
27672467 * @sw_context: The software context being used for this batch.
....@@ -2771,9 +2471,9 @@
27712471 struct vmw_sw_context *sw_context,
27722472 SVGA3dCmdHeader *header)
27732473 {
2774
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2775
- struct vmw_ctx_bindinfo_so binding;
2776
- struct vmw_resource_val_node *res_node;
2474
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
2475
+ struct vmw_ctx_bindinfo_so_target binding;
2476
+ struct vmw_resource *res;
27772477 struct {
27782478 SVGA3dCmdHeader header;
27792479 SVGA3dCmdDXSetSOTargets body;
....@@ -2781,36 +2481,33 @@
27812481 } *cmd;
27822482 int i, ret, num;
27832483
2784
- if (unlikely(ctx_node == NULL)) {
2785
- DRM_ERROR("DX Context not set.\n");
2484
+ if (!ctx_node)
27862485 return -EINVAL;
2787
- }
27882486
27892487 cmd = container_of(header, typeof(*cmd), header);
2790
- num = (cmd->header.size - sizeof(cmd->body)) /
2791
- sizeof(SVGA3dSoTarget);
2488
+ num = (cmd->header.size - sizeof(cmd->body)) / sizeof(SVGA3dSoTarget);
27922489
27932490 if (num > SVGA3D_DX_MAX_SOTARGETS) {
2794
- DRM_ERROR("Invalid DX SO binding.\n");
2491
+ VMW_DEBUG_USER("Invalid DX SO binding.\n");
27952492 return -EINVAL;
27962493 }
27972494
27982495 for (i = 0; i < num; i++) {
27992496 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2497
+ VMW_RES_DIRTY_SET,
28002498 user_surface_converter,
2801
- &cmd->targets[i].sid, &res_node);
2499
+ &cmd->targets[i].sid, &res);
28022500 if (unlikely(ret != 0))
28032501 return ret;
28042502
2805
- binding.bi.ctx = ctx_node->res;
2806
- binding.bi.res = ((res_node) ? res_node->res : NULL);
2807
- binding.bi.bt = vmw_ctx_binding_so,
2503
+ binding.bi.ctx = ctx_node->ctx;
2504
+ binding.bi.res = res;
2505
+ binding.bi.bt = vmw_ctx_binding_so_target,
28082506 binding.offset = cmd->targets[i].offset;
28092507 binding.size = cmd->targets[i].sizeInBytes;
28102508 binding.slot = i;
28112509
2812
- vmw_binding_add(ctx_node->staged_bindings, &binding.bi,
2813
- 0, binding.slot);
2510
+ vmw_binding_add(ctx_node->staged, &binding.bi, 0, binding.slot);
28142511 }
28152512
28162513 return 0;
....@@ -2820,7 +2517,7 @@
28202517 struct vmw_sw_context *sw_context,
28212518 SVGA3dCmdHeader *header)
28222519 {
2823
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2520
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
28242521 struct vmw_resource *res;
28252522 /*
28262523 * This is based on the fact that all affected define commands have
....@@ -2833,23 +2530,20 @@
28332530 enum vmw_so_type so_type;
28342531 int ret;
28352532
2836
- if (unlikely(ctx_node == NULL)) {
2837
- DRM_ERROR("DX Context not set.\n");
2533
+ if (!ctx_node)
28382534 return -EINVAL;
2839
- }
28402535
28412536 so_type = vmw_so_cmd_to_type(header->id);
2842
- res = vmw_context_cotable(ctx_node->res, vmw_so_cotables[so_type]);
2537
+ res = vmw_context_cotable(ctx_node->ctx, vmw_so_cotables[so_type]);
28432538 cmd = container_of(header, typeof(*cmd), header);
28442539 ret = vmw_cotable_notify(res, cmd->defined_id);
2845
- vmw_resource_unreference(&res);
28462540
28472541 return ret;
28482542 }
28492543
28502544 /**
2851
- * vmw_cmd_dx_check_subresource - Validate an
2852
- * SVGA_3D_CMD_DX_[X]_SUBRESOURCE command
2545
+ * vmw_cmd_dx_check_subresource - Validate SVGA_3D_CMD_DX_[X]_SUBRESOURCE
2546
+ * command
28532547 *
28542548 * @dev_priv: Pointer to a device private struct.
28552549 * @sw_context: The software context being used for this batch.
....@@ -2877,9 +2571,8 @@
28772571 offsetof(typeof(*cmd), sid));
28782572
28792573 cmd = container_of(header, typeof(*cmd), header);
2880
-
28812574 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
2882
- user_surface_converter,
2575
+ VMW_RES_DIRTY_NONE, user_surface_converter,
28832576 &cmd->sid, NULL);
28842577 }
28852578
....@@ -2887,32 +2580,30 @@
28872580 struct vmw_sw_context *sw_context,
28882581 SVGA3dCmdHeader *header)
28892582 {
2890
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2583
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
28912584
2892
- if (unlikely(ctx_node == NULL)) {
2893
- DRM_ERROR("DX Context not set.\n");
2585
+ if (!ctx_node)
28942586 return -EINVAL;
2895
- }
28962587
28972588 return 0;
28982589 }
28992590
29002591 /**
2901
- * vmw_cmd_dx_view_remove - validate a view remove command and
2902
- * schedule the view resource for removal.
2592
+ * vmw_cmd_dx_view_remove - validate a view remove command and schedule the view
2593
+ * resource for removal.
29032594 *
29042595 * @dev_priv: Pointer to a device private struct.
29052596 * @sw_context: The software context being used for this batch.
29062597 * @header: Pointer to the command header in the command stream.
29072598 *
2908
- * Check that the view exists, and if it was not created using this
2909
- * command batch, conditionally make this command a NOP.
2599
+ * Check that the view exists, and if it was not created using this command
2600
+ * batch, conditionally make this command a NOP.
29102601 */
29112602 static int vmw_cmd_dx_view_remove(struct vmw_private *dev_priv,
29122603 struct vmw_sw_context *sw_context,
29132604 SVGA3dCmdHeader *header)
29142605 {
2915
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2606
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
29162607 struct {
29172608 SVGA3dCmdHeader header;
29182609 union vmw_view_destroy body;
....@@ -2921,15 +2612,11 @@
29212612 struct vmw_resource *view;
29222613 int ret;
29232614
2924
- if (!ctx_node) {
2925
- DRM_ERROR("DX Context not set.\n");
2615
+ if (!ctx_node)
29262616 return -EINVAL;
2927
- }
29282617
2929
- ret = vmw_view_remove(sw_context->man,
2930
- cmd->body.view_id, view_type,
2931
- &sw_context->staged_cmd_res,
2932
- &view);
2618
+ ret = vmw_view_remove(sw_context->man, cmd->body.view_id, view_type,
2619
+ &sw_context->staged_cmd_res, &view);
29332620 if (ret || !view)
29342621 return ret;
29352622
....@@ -2939,16 +2626,14 @@
29392626 * relocation to conditionally make this command a NOP to avoid
29402627 * device errors.
29412628 */
2942
- return vmw_resource_relocation_add(&sw_context->res_relocations,
2943
- view,
2629
+ return vmw_resource_relocation_add(sw_context, view,
29442630 vmw_ptr_diff(sw_context->buf_start,
29452631 &cmd->header.id),
29462632 vmw_res_rel_cond_nop);
29472633 }
29482634
29492635 /**
2950
- * vmw_cmd_dx_define_shader - Validate an SVGA_3D_CMD_DX_DEFINE_SHADER
2951
- * command
2636
+ * vmw_cmd_dx_define_shader - Validate SVGA_3D_CMD_DX_DEFINE_SHADER command
29522637 *
29532638 * @dev_priv: Pointer to a device private struct.
29542639 * @sw_context: The software context being used for this batch.
....@@ -2958,33 +2643,27 @@
29582643 struct vmw_sw_context *sw_context,
29592644 SVGA3dCmdHeader *header)
29602645 {
2961
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2646
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
29622647 struct vmw_resource *res;
2963
- struct {
2964
- SVGA3dCmdHeader header;
2965
- SVGA3dCmdDXDefineShader body;
2966
- } *cmd = container_of(header, typeof(*cmd), header);
2648
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXDefineShader) =
2649
+ container_of(header, typeof(*cmd), header);
29672650 int ret;
29682651
2969
- if (!ctx_node) {
2970
- DRM_ERROR("DX Context not set.\n");
2652
+ if (!ctx_node)
29712653 return -EINVAL;
2972
- }
29732654
2974
- res = vmw_context_cotable(ctx_node->res, SVGA_COTABLE_DXSHADER);
2655
+ res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXSHADER);
29752656 ret = vmw_cotable_notify(res, cmd->body.shaderId);
2976
- vmw_resource_unreference(&res);
29772657 if (ret)
29782658 return ret;
29792659
2980
- return vmw_dx_shader_add(sw_context->man, ctx_node->res,
2660
+ return vmw_dx_shader_add(sw_context->man, ctx_node->ctx,
29812661 cmd->body.shaderId, cmd->body.type,
29822662 &sw_context->staged_cmd_res);
29832663 }
29842664
29852665 /**
2986
- * vmw_cmd_dx_destroy_shader - Validate an SVGA_3D_CMD_DX_DESTROY_SHADER
2987
- * command
2666
+ * vmw_cmd_dx_destroy_shader - Validate SVGA_3D_CMD_DX_DESTROY_SHADER command
29882667 *
29892668 * @dev_priv: Pointer to a device private struct.
29902669 * @sw_context: The software context being used for this batch.
....@@ -2994,29 +2673,22 @@
29942673 struct vmw_sw_context *sw_context,
29952674 SVGA3dCmdHeader *header)
29962675 {
2997
- struct vmw_resource_val_node *ctx_node = sw_context->dx_ctx_node;
2998
- struct {
2999
- SVGA3dCmdHeader header;
3000
- SVGA3dCmdDXDestroyShader body;
3001
- } *cmd = container_of(header, typeof(*cmd), header);
2676
+ struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
2677
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXDestroyShader) =
2678
+ container_of(header, typeof(*cmd), header);
30022679 int ret;
30032680
3004
- if (!ctx_node) {
3005
- DRM_ERROR("DX Context not set.\n");
2681
+ if (!ctx_node)
30062682 return -EINVAL;
3007
- }
30082683
30092684 ret = vmw_shader_remove(sw_context->man, cmd->body.shaderId, 0,
30102685 &sw_context->staged_cmd_res);
3011
- if (ret)
3012
- DRM_ERROR("Could not find shader to remove.\n");
30132686
30142687 return ret;
30152688 }
30162689
30172690 /**
3018
- * vmw_cmd_dx_bind_shader - Validate an SVGA_3D_CMD_DX_BIND_SHADER
3019
- * command
2691
+ * vmw_cmd_dx_bind_shader - Validate SVGA_3D_CMD_DX_BIND_SHADER command
30202692 *
30212693 * @dev_priv: Pointer to a device private struct.
30222694 * @sw_context: The software context being used for this batch.
....@@ -3026,54 +2698,49 @@
30262698 struct vmw_sw_context *sw_context,
30272699 SVGA3dCmdHeader *header)
30282700 {
3029
- struct vmw_resource_val_node *ctx_node;
3030
- struct vmw_resource_val_node *res_node;
2701
+ struct vmw_resource *ctx;
30312702 struct vmw_resource *res;
3032
- struct {
3033
- SVGA3dCmdHeader header;
3034
- SVGA3dCmdDXBindShader body;
3035
- } *cmd = container_of(header, typeof(*cmd), header);
2703
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBindShader) =
2704
+ container_of(header, typeof(*cmd), header);
30362705 int ret;
30372706
30382707 if (cmd->body.cid != SVGA3D_INVALID_ID) {
30392708 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context,
3040
- user_context_converter,
3041
- &cmd->body.cid, &ctx_node);
2709
+ VMW_RES_DIRTY_SET,
2710
+ user_context_converter, &cmd->body.cid,
2711
+ &ctx);
30422712 if (ret)
30432713 return ret;
30442714 } else {
3045
- ctx_node = sw_context->dx_ctx_node;
3046
- if (!ctx_node) {
3047
- DRM_ERROR("DX Context not set.\n");
2715
+ struct vmw_ctx_validation_info *ctx_node =
2716
+ VMW_GET_CTX_NODE(sw_context);
2717
+
2718
+ if (!ctx_node)
30482719 return -EINVAL;
3049
- }
2720
+
2721
+ ctx = ctx_node->ctx;
30502722 }
30512723
3052
- res = vmw_shader_lookup(vmw_context_res_man(ctx_node->res),
3053
- cmd->body.shid, 0);
2724
+ res = vmw_shader_lookup(vmw_context_res_man(ctx), cmd->body.shid, 0);
30542725 if (IS_ERR(res)) {
3055
- DRM_ERROR("Could not find shader to bind.\n");
2726
+ VMW_DEBUG_USER("Could not find shader to bind.\n");
30562727 return PTR_ERR(res);
30572728 }
30582729
3059
- ret = vmw_resource_val_add(sw_context, res, &res_node);
2730
+ ret = vmw_execbuf_res_noctx_val_add(sw_context, res,
2731
+ VMW_RES_DIRTY_NONE);
30602732 if (ret) {
3061
- DRM_ERROR("Error creating resource validation node.\n");
3062
- goto out_unref;
2733
+ VMW_DEBUG_USER("Error creating resource validation node.\n");
2734
+ return ret;
30632735 }
30642736
3065
-
3066
- ret = vmw_cmd_res_switch_backup(dev_priv, sw_context, res_node,
3067
- &cmd->body.mobid,
3068
- cmd->body.offsetInBytes);
3069
-out_unref:
3070
- vmw_resource_unreference(&res);
3071
-
3072
- return ret;
2737
+ return vmw_cmd_res_switch_backup(dev_priv, sw_context, res,
2738
+ &cmd->body.mobid,
2739
+ cmd->body.offsetInBytes);
30732740 }
30742741
30752742 /**
3076
- * vmw_cmd_dx_genmips - Validate an SVGA_3D_CMD_DX_GENMIPS command
2743
+ * vmw_cmd_dx_genmips - Validate SVGA_3D_CMD_DX_GENMIPS command
30772744 *
30782745 * @dev_priv: Pointer to a device private struct.
30792746 * @sw_context: The software context being used for this batch.
....@@ -3083,18 +2750,31 @@
30832750 struct vmw_sw_context *sw_context,
30842751 SVGA3dCmdHeader *header)
30852752 {
3086
- struct {
3087
- SVGA3dCmdHeader header;
3088
- SVGA3dCmdDXGenMips body;
3089
- } *cmd = container_of(header, typeof(*cmd), header);
2753
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXGenMips) =
2754
+ container_of(header, typeof(*cmd), header);
2755
+ struct vmw_resource *view;
2756
+ struct vmw_res_cache_entry *rcache;
30902757
3091
- return vmw_view_id_val_add(sw_context, vmw_view_sr,
2758
+ view = vmw_view_id_val_add(sw_context, vmw_view_sr,
30922759 cmd->body.shaderResourceViewId);
2760
+ if (IS_ERR(view))
2761
+ return PTR_ERR(view);
2762
+
2763
+ /*
2764
+ * Normally the shader-resource view is not gpu-dirtying, but for
2765
+ * this particular command it is...
2766
+ * So mark the last looked-up surface, which is the surface
2767
+ * the view points to, gpu-dirty.
2768
+ */
2769
+ rcache = &sw_context->res_cache[vmw_res_surface];
2770
+ vmw_validation_res_set_dirty(sw_context->ctx, rcache->private,
2771
+ VMW_RES_DIRTY_SET);
2772
+ return 0;
30932773 }
30942774
30952775 /**
3096
- * vmw_cmd_dx_transfer_from_buffer -
3097
- * Validate an SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER command
2776
+ * vmw_cmd_dx_transfer_from_buffer - Validate
2777
+ * SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER command
30982778 *
30992779 * @dev_priv: Pointer to a device private struct.
31002780 * @sw_context: The software context being used for this batch.
....@@ -3104,26 +2784,23 @@
31042784 struct vmw_sw_context *sw_context,
31052785 SVGA3dCmdHeader *header)
31062786 {
3107
- struct {
3108
- SVGA3dCmdHeader header;
3109
- SVGA3dCmdDXTransferFromBuffer body;
3110
- } *cmd = container_of(header, typeof(*cmd), header);
2787
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXTransferFromBuffer) =
2788
+ container_of(header, typeof(*cmd), header);
31112789 int ret;
31122790
31132791 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3114
- user_surface_converter,
2792
+ VMW_RES_DIRTY_NONE, user_surface_converter,
31152793 &cmd->body.srcSid, NULL);
31162794 if (ret != 0)
31172795 return ret;
31182796
31192797 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3120
- user_surface_converter,
2798
+ VMW_RES_DIRTY_SET, user_surface_converter,
31212799 &cmd->body.destSid, NULL);
31222800 }
31232801
31242802 /**
3125
- * vmw_cmd_intra_surface_copy -
3126
- * Validate an SVGA_3D_CMD_INTRA_SURFACE_COPY command
2803
+ * vmw_cmd_intra_surface_copy - Validate SVGA_3D_CMD_INTRA_SURFACE_COPY command
31272804 *
31282805 * @dev_priv: Pointer to a device private struct.
31292806 * @sw_context: The software context being used for this batch.
....@@ -3133,19 +2810,362 @@
31332810 struct vmw_sw_context *sw_context,
31342811 SVGA3dCmdHeader *header)
31352812 {
3136
- struct {
3137
- SVGA3dCmdHeader header;
3138
- SVGA3dCmdIntraSurfaceCopy body;
3139
- } *cmd = container_of(header, typeof(*cmd), header);
2813
+ VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdIntraSurfaceCopy) =
2814
+ container_of(header, typeof(*cmd), header);
31402815
31412816 if (!(dev_priv->capabilities2 & SVGA_CAP2_INTRA_SURFACE_COPY))
31422817 return -EINVAL;
31432818
31442819 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3145
- user_surface_converter,
3146
- &cmd->body.surface.sid, NULL);
2820
+ VMW_RES_DIRTY_SET, user_surface_converter,
2821
+ &cmd->body.surface.sid, NULL);
31472822 }
31482823
2824
+static int vmw_cmd_sm5(struct vmw_private *dev_priv,
2825
+ struct vmw_sw_context *sw_context,
2826
+ SVGA3dCmdHeader *header)
2827
+{
2828
+ if (!has_sm5_context(dev_priv))
2829
+ return -EINVAL;
2830
+
2831
+ return 0;
2832
+}
2833
+
2834
+static int vmw_cmd_sm5_view_define(struct vmw_private *dev_priv,
2835
+ struct vmw_sw_context *sw_context,
2836
+ SVGA3dCmdHeader *header)
2837
+{
2838
+ if (!has_sm5_context(dev_priv))
2839
+ return -EINVAL;
2840
+
2841
+ return vmw_cmd_dx_view_define(dev_priv, sw_context, header);
2842
+}
2843
+
2844
+static int vmw_cmd_sm5_view_remove(struct vmw_private *dev_priv,
2845
+ struct vmw_sw_context *sw_context,
2846
+ SVGA3dCmdHeader *header)
2847
+{
2848
+ if (!has_sm5_context(dev_priv))
2849
+ return -EINVAL;
2850
+
2851
+ return vmw_cmd_dx_view_remove(dev_priv, sw_context, header);
2852
+}
2853
+
2854
+static int vmw_cmd_clear_uav_uint(struct vmw_private *dev_priv,
2855
+ struct vmw_sw_context *sw_context,
2856
+ SVGA3dCmdHeader *header)
2857
+{
2858
+ struct {
2859
+ SVGA3dCmdHeader header;
2860
+ SVGA3dCmdDXClearUAViewUint body;
2861
+ } *cmd = container_of(header, typeof(*cmd), header);
2862
+ struct vmw_resource *ret;
2863
+
2864
+ if (!has_sm5_context(dev_priv))
2865
+ return -EINVAL;
2866
+
2867
+ ret = vmw_view_id_val_add(sw_context, vmw_view_ua,
2868
+ cmd->body.uaViewId);
2869
+
2870
+ return PTR_ERR_OR_ZERO(ret);
2871
+}
2872
+
2873
+static int vmw_cmd_clear_uav_float(struct vmw_private *dev_priv,
2874
+ struct vmw_sw_context *sw_context,
2875
+ SVGA3dCmdHeader *header)
2876
+{
2877
+ struct {
2878
+ SVGA3dCmdHeader header;
2879
+ SVGA3dCmdDXClearUAViewFloat body;
2880
+ } *cmd = container_of(header, typeof(*cmd), header);
2881
+ struct vmw_resource *ret;
2882
+
2883
+ if (!has_sm5_context(dev_priv))
2884
+ return -EINVAL;
2885
+
2886
+ ret = vmw_view_id_val_add(sw_context, vmw_view_ua,
2887
+ cmd->body.uaViewId);
2888
+
2889
+ return PTR_ERR_OR_ZERO(ret);
2890
+}
2891
+
2892
+static int vmw_cmd_set_uav(struct vmw_private *dev_priv,
2893
+ struct vmw_sw_context *sw_context,
2894
+ SVGA3dCmdHeader *header)
2895
+{
2896
+ struct {
2897
+ SVGA3dCmdHeader header;
2898
+ SVGA3dCmdDXSetUAViews body;
2899
+ } *cmd = container_of(header, typeof(*cmd), header);
2900
+ u32 num_uav = (cmd->header.size - sizeof(cmd->body)) /
2901
+ sizeof(SVGA3dUAViewId);
2902
+ int ret;
2903
+
2904
+ if (!has_sm5_context(dev_priv))
2905
+ return -EINVAL;
2906
+
2907
+ if (num_uav > SVGA3D_MAX_UAVIEWS) {
2908
+ VMW_DEBUG_USER("Invalid UAV binding.\n");
2909
+ return -EINVAL;
2910
+ }
2911
+
2912
+ ret = vmw_view_bindings_add(sw_context, vmw_view_ua,
2913
+ vmw_ctx_binding_uav, 0, (void *)&cmd[1],
2914
+ num_uav, 0);
2915
+ if (ret)
2916
+ return ret;
2917
+
2918
+ vmw_binding_add_uav_index(sw_context->dx_ctx_node->staged, 0,
2919
+ cmd->body.uavSpliceIndex);
2920
+
2921
+ return ret;
2922
+}
2923
+
2924
+static int vmw_cmd_set_cs_uav(struct vmw_private *dev_priv,
2925
+ struct vmw_sw_context *sw_context,
2926
+ SVGA3dCmdHeader *header)
2927
+{
2928
+ struct {
2929
+ SVGA3dCmdHeader header;
2930
+ SVGA3dCmdDXSetCSUAViews body;
2931
+ } *cmd = container_of(header, typeof(*cmd), header);
2932
+ u32 num_uav = (cmd->header.size - sizeof(cmd->body)) /
2933
+ sizeof(SVGA3dUAViewId);
2934
+ int ret;
2935
+
2936
+ if (!has_sm5_context(dev_priv))
2937
+ return -EINVAL;
2938
+
2939
+ if (num_uav > SVGA3D_MAX_UAVIEWS) {
2940
+ VMW_DEBUG_USER("Invalid UAV binding.\n");
2941
+ return -EINVAL;
2942
+ }
2943
+
2944
+ ret = vmw_view_bindings_add(sw_context, vmw_view_ua,
2945
+ vmw_ctx_binding_cs_uav, 0, (void *)&cmd[1],
2946
+ num_uav, 0);
2947
+ if (ret)
2948
+ return ret;
2949
+
2950
+ vmw_binding_add_uav_index(sw_context->dx_ctx_node->staged, 1,
2951
+ cmd->body.startIndex);
2952
+
2953
+ return ret;
2954
+}
2955
+
2956
+static int vmw_cmd_dx_define_streamoutput(struct vmw_private *dev_priv,
2957
+ struct vmw_sw_context *sw_context,
2958
+ SVGA3dCmdHeader *header)
2959
+{
2960
+ struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node;
2961
+ struct vmw_resource *res;
2962
+ struct {
2963
+ SVGA3dCmdHeader header;
2964
+ SVGA3dCmdDXDefineStreamOutputWithMob body;
2965
+ } *cmd = container_of(header, typeof(*cmd), header);
2966
+ int ret;
2967
+
2968
+ if (!has_sm5_context(dev_priv))
2969
+ return -EINVAL;
2970
+
2971
+ if (!ctx_node) {
2972
+ DRM_ERROR("DX Context not set.\n");
2973
+ return -EINVAL;
2974
+ }
2975
+
2976
+ res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_STREAMOUTPUT);
2977
+ ret = vmw_cotable_notify(res, cmd->body.soid);
2978
+ if (ret)
2979
+ return ret;
2980
+
2981
+ return vmw_dx_streamoutput_add(sw_context->man, ctx_node->ctx,
2982
+ cmd->body.soid,
2983
+ &sw_context->staged_cmd_res);
2984
+}
2985
+
2986
+static int vmw_cmd_dx_destroy_streamoutput(struct vmw_private *dev_priv,
2987
+ struct vmw_sw_context *sw_context,
2988
+ SVGA3dCmdHeader *header)
2989
+{
2990
+ struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node;
2991
+ struct vmw_resource *res;
2992
+ struct {
2993
+ SVGA3dCmdHeader header;
2994
+ SVGA3dCmdDXDestroyStreamOutput body;
2995
+ } *cmd = container_of(header, typeof(*cmd), header);
2996
+
2997
+ if (!ctx_node) {
2998
+ DRM_ERROR("DX Context not set.\n");
2999
+ return -EINVAL;
3000
+ }
3001
+
3002
+ /*
3003
+ * When device does not support SM5 then streamoutput with mob command is
3004
+ * not available to user-space. Simply return in this case.
3005
+ */
3006
+ if (!has_sm5_context(dev_priv))
3007
+ return 0;
3008
+
3009
+ /*
3010
+ * With SM5 capable device if lookup fails then user-space probably used
3011
+ * old streamoutput define command. Return without an error.
3012
+ */
3013
+ res = vmw_dx_streamoutput_lookup(vmw_context_res_man(ctx_node->ctx),
3014
+ cmd->body.soid);
3015
+ if (IS_ERR(res))
3016
+ return 0;
3017
+
3018
+ return vmw_dx_streamoutput_remove(sw_context->man, cmd->body.soid,
3019
+ &sw_context->staged_cmd_res);
3020
+}
3021
+
3022
+static int vmw_cmd_dx_bind_streamoutput(struct vmw_private *dev_priv,
3023
+ struct vmw_sw_context *sw_context,
3024
+ SVGA3dCmdHeader *header)
3025
+{
3026
+ struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node;
3027
+ struct vmw_resource *res;
3028
+ struct {
3029
+ SVGA3dCmdHeader header;
3030
+ SVGA3dCmdDXBindStreamOutput body;
3031
+ } *cmd = container_of(header, typeof(*cmd), header);
3032
+ int ret;
3033
+
3034
+ if (!has_sm5_context(dev_priv))
3035
+ return -EINVAL;
3036
+
3037
+ if (!ctx_node) {
3038
+ DRM_ERROR("DX Context not set.\n");
3039
+ return -EINVAL;
3040
+ }
3041
+
3042
+ res = vmw_dx_streamoutput_lookup(vmw_context_res_man(ctx_node->ctx),
3043
+ cmd->body.soid);
3044
+ if (IS_ERR(res)) {
3045
+ DRM_ERROR("Could not find streamoutput to bind.\n");
3046
+ return PTR_ERR(res);
3047
+ }
3048
+
3049
+ vmw_dx_streamoutput_set_size(res, cmd->body.sizeInBytes);
3050
+
3051
+ ret = vmw_execbuf_res_noctx_val_add(sw_context, res,
3052
+ VMW_RES_DIRTY_NONE);
3053
+ if (ret) {
3054
+ DRM_ERROR("Error creating resource validation node.\n");
3055
+ return ret;
3056
+ }
3057
+
3058
+ return vmw_cmd_res_switch_backup(dev_priv, sw_context, res,
3059
+ &cmd->body.mobid,
3060
+ cmd->body.offsetInBytes);
3061
+}
3062
+
3063
+static int vmw_cmd_dx_set_streamoutput(struct vmw_private *dev_priv,
3064
+ struct vmw_sw_context *sw_context,
3065
+ SVGA3dCmdHeader *header)
3066
+{
3067
+ struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node;
3068
+ struct vmw_resource *res;
3069
+ struct vmw_ctx_bindinfo_so binding;
3070
+ struct {
3071
+ SVGA3dCmdHeader header;
3072
+ SVGA3dCmdDXSetStreamOutput body;
3073
+ } *cmd = container_of(header, typeof(*cmd), header);
3074
+ int ret;
3075
+
3076
+ if (!ctx_node) {
3077
+ DRM_ERROR("DX Context not set.\n");
3078
+ return -EINVAL;
3079
+ }
3080
+
3081
+ if (cmd->body.soid == SVGA3D_INVALID_ID)
3082
+ return 0;
3083
+
3084
+ /*
3085
+ * When device does not support SM5 then streamoutput with mob command is
3086
+ * not available to user-space. Simply return in this case.
3087
+ */
3088
+ if (!has_sm5_context(dev_priv))
3089
+ return 0;
3090
+
3091
+ /*
3092
+ * With SM5 capable device if lookup fails then user-space probably used
3093
+ * old streamoutput define command. Return without an error.
3094
+ */
3095
+ res = vmw_dx_streamoutput_lookup(vmw_context_res_man(ctx_node->ctx),
3096
+ cmd->body.soid);
3097
+ if (IS_ERR(res)) {
3098
+ return 0;
3099
+ }
3100
+
3101
+ ret = vmw_execbuf_res_noctx_val_add(sw_context, res,
3102
+ VMW_RES_DIRTY_NONE);
3103
+ if (ret) {
3104
+ DRM_ERROR("Error creating resource validation node.\n");
3105
+ return ret;
3106
+ }
3107
+
3108
+ binding.bi.ctx = ctx_node->ctx;
3109
+ binding.bi.res = res;
3110
+ binding.bi.bt = vmw_ctx_binding_so;
3111
+ binding.slot = 0; /* Only one SO set to context at a time. */
3112
+
3113
+ vmw_binding_add(sw_context->dx_ctx_node->staged, &binding.bi, 0,
3114
+ binding.slot);
3115
+
3116
+ return ret;
3117
+}
3118
+
3119
+static int vmw_cmd_indexed_instanced_indirect(struct vmw_private *dev_priv,
3120
+ struct vmw_sw_context *sw_context,
3121
+ SVGA3dCmdHeader *header)
3122
+{
3123
+ struct vmw_draw_indexed_instanced_indirect_cmd {
3124
+ SVGA3dCmdHeader header;
3125
+ SVGA3dCmdDXDrawIndexedInstancedIndirect body;
3126
+ } *cmd = container_of(header, typeof(*cmd), header);
3127
+
3128
+ if (!has_sm5_context(dev_priv))
3129
+ return -EINVAL;
3130
+
3131
+ return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3132
+ VMW_RES_DIRTY_NONE, user_surface_converter,
3133
+ &cmd->body.argsBufferSid, NULL);
3134
+}
3135
+
3136
+static int vmw_cmd_instanced_indirect(struct vmw_private *dev_priv,
3137
+ struct vmw_sw_context *sw_context,
3138
+ SVGA3dCmdHeader *header)
3139
+{
3140
+ struct vmw_draw_instanced_indirect_cmd {
3141
+ SVGA3dCmdHeader header;
3142
+ SVGA3dCmdDXDrawInstancedIndirect body;
3143
+ } *cmd = container_of(header, typeof(*cmd), header);
3144
+
3145
+ if (!has_sm5_context(dev_priv))
3146
+ return -EINVAL;
3147
+
3148
+ return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3149
+ VMW_RES_DIRTY_NONE, user_surface_converter,
3150
+ &cmd->body.argsBufferSid, NULL);
3151
+}
3152
+
3153
+static int vmw_cmd_dispatch_indirect(struct vmw_private *dev_priv,
3154
+ struct vmw_sw_context *sw_context,
3155
+ SVGA3dCmdHeader *header)
3156
+{
3157
+ struct vmw_dispatch_indirect_cmd {
3158
+ SVGA3dCmdHeader header;
3159
+ SVGA3dCmdDXDispatchIndirect body;
3160
+ } *cmd = container_of(header, typeof(*cmd), header);
3161
+
3162
+ if (!has_sm5_context(dev_priv))
3163
+ return -EINVAL;
3164
+
3165
+ return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3166
+ VMW_RES_DIRTY_NONE, user_surface_converter,
3167
+ &cmd->body.argsBufferSid, NULL);
3168
+}
31493169
31503170 static int vmw_cmd_check_not_3d(struct vmw_private *dev_priv,
31513171 struct vmw_sw_context *sw_context,
....@@ -3169,18 +3189,18 @@
31693189 *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdBlitGMRFBToScreen);
31703190 break;
31713191 default:
3172
- DRM_ERROR("Unsupported SVGA command: %u.\n", cmd_id);
3192
+ VMW_DEBUG_USER("Unsupported SVGA command: %u.\n", cmd_id);
31733193 return -EINVAL;
31743194 }
31753195
31763196 if (*size > size_remaining) {
3177
- DRM_ERROR("Invalid SVGA command (size mismatch):"
3178
- " %u.\n", cmd_id);
3197
+ VMW_DEBUG_USER("Invalid SVGA command (size mismatch): %u.\n",
3198
+ cmd_id);
31793199 return -EINVAL;
31803200 }
31813201
31823202 if (unlikely(!sw_context->kernel)) {
3183
- DRM_ERROR("Kernel only SVGA command: %u.\n", cmd_id);
3203
+ VMW_DEBUG_USER("Kernel only SVGA command: %u.\n", cmd_id);
31843204 return -EPERM;
31853205 }
31863206
....@@ -3265,18 +3285,12 @@
32653285 false, false, false),
32663286 VMW_CMD_DEF(SVGA_3D_CMD_DEAD2, &vmw_cmd_invalid,
32673287 false, false, false),
3268
- VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_BITBLT, &vmw_cmd_invalid,
3269
- false, false, false),
3270
- VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_TRANSBLT, &vmw_cmd_invalid,
3271
- false, false, false),
3272
- VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_STRETCHBLT, &vmw_cmd_invalid,
3273
- false, false, false),
3274
- VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_COLORFILL, &vmw_cmd_invalid,
3275
- false, false, false),
3276
- VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_ALPHABLEND, &vmw_cmd_invalid,
3277
- false, false, false),
3278
- VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND, &vmw_cmd_invalid,
3279
- false, false, false),
3288
+ VMW_CMD_DEF(SVGA_3D_CMD_DEAD12, &vmw_cmd_invalid, false, false, false),
3289
+ VMW_CMD_DEF(SVGA_3D_CMD_DEAD13, &vmw_cmd_invalid, false, false, false),
3290
+ VMW_CMD_DEF(SVGA_3D_CMD_DEAD14, &vmw_cmd_invalid, false, false, false),
3291
+ VMW_CMD_DEF(SVGA_3D_CMD_DEAD15, &vmw_cmd_invalid, false, false, false),
3292
+ VMW_CMD_DEF(SVGA_3D_CMD_DEAD16, &vmw_cmd_invalid, false, false, false),
3293
+ VMW_CMD_DEF(SVGA_3D_CMD_DEAD17, &vmw_cmd_invalid, false, false, false),
32803294 VMW_CMD_DEF(SVGA_3D_CMD_SET_OTABLE_BASE, &vmw_cmd_invalid,
32813295 false, false, true),
32823296 VMW_CMD_DEF(SVGA_3D_CMD_READBACK_OTABLE, &vmw_cmd_invalid,
....@@ -3368,9 +3382,7 @@
33683382 VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SURFACE_V2, &vmw_cmd_invalid,
33693383 false, false, true),
33703384
3371
- /*
3372
- * DX commands
3373
- */
3385
+ /* SM commands */
33743386 VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_CONTEXT, &vmw_cmd_invalid,
33753387 false, false, true),
33763388 VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_CONTEXT, &vmw_cmd_invalid,
....@@ -3486,9 +3498,9 @@
34863498 VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT,
34873499 &vmw_cmd_dx_so_define, true, false, true),
34883500 VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT,
3489
- &vmw_cmd_dx_cid_check, true, false, true),
3490
- VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_STREAMOUTPUT, &vmw_cmd_dx_cid_check,
3491
- true, false, true),
3501
+ &vmw_cmd_dx_destroy_streamoutput, true, false, true),
3502
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_STREAMOUTPUT,
3503
+ &vmw_cmd_dx_set_streamoutput, true, false, true),
34923504 VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SOTARGETS,
34933505 &vmw_cmd_dx_set_so_targets, true, false, true),
34943506 VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_INPUT_LAYOUT,
....@@ -3504,6 +3516,37 @@
35043516 true, false, true),
35053517 VMW_CMD_DEF(SVGA_3D_CMD_INTRA_SURFACE_COPY, &vmw_cmd_intra_surface_copy,
35063518 true, false, true),
3519
+
3520
+ /*
3521
+ * SM5 commands
3522
+ */
3523
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_UA_VIEW, &vmw_cmd_sm5_view_define,
3524
+ true, false, true),
3525
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_UA_VIEW, &vmw_cmd_sm5_view_remove,
3526
+ true, false, true),
3527
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_CLEAR_UA_VIEW_UINT, &vmw_cmd_clear_uav_uint,
3528
+ true, false, true),
3529
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_CLEAR_UA_VIEW_FLOAT,
3530
+ &vmw_cmd_clear_uav_float, true, false, true),
3531
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_COPY_STRUCTURE_COUNT, &vmw_cmd_invalid, true,
3532
+ false, true),
3533
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_UA_VIEWS, &vmw_cmd_set_uav, true, false,
3534
+ true),
3535
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED_INDIRECT,
3536
+ &vmw_cmd_indexed_instanced_indirect, true, false, true),
3537
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INSTANCED_INDIRECT,
3538
+ &vmw_cmd_instanced_indirect, true, false, true),
3539
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DISPATCH, &vmw_cmd_sm5, true, false, true),
3540
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DISPATCH_INDIRECT,
3541
+ &vmw_cmd_dispatch_indirect, true, false, true),
3542
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_CS_UA_VIEWS, &vmw_cmd_set_cs_uav, true,
3543
+ false, true),
3544
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW_V2,
3545
+ &vmw_cmd_sm5_view_define, true, false, true),
3546
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB,
3547
+ &vmw_cmd_dx_define_streamoutput, true, false, true),
3548
+ VMW_CMD_DEF(SVGA_3D_CMD_DX_BIND_STREAMOUTPUT,
3549
+ &vmw_cmd_dx_bind_streamoutput, true, false, true),
35073550 };
35083551
35093552 bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd)
....@@ -3552,8 +3595,8 @@
35523595 }
35533596
35543597 static int vmw_cmd_check(struct vmw_private *dev_priv,
3555
- struct vmw_sw_context *sw_context,
3556
- void *buf, uint32_t *size)
3598
+ struct vmw_sw_context *sw_context, void *buf,
3599
+ uint32_t *size)
35573600 {
35583601 uint32_t cmd_id;
35593602 uint32_t size_remaining = *size;
....@@ -3592,31 +3635,33 @@
35923635 goto out_new;
35933636
35943637 ret = entry->func(dev_priv, sw_context, header);
3595
- if (unlikely(ret != 0))
3596
- goto out_invalid;
3638
+ if (unlikely(ret != 0)) {
3639
+ VMW_DEBUG_USER("SVGA3D command: %d failed with error %d\n",
3640
+ cmd_id + SVGA_3D_CMD_BASE, ret);
3641
+ return ret;
3642
+ }
35973643
35983644 return 0;
35993645 out_invalid:
3600
- DRM_ERROR("Invalid SVGA3D command: %d\n",
3601
- cmd_id + SVGA_3D_CMD_BASE);
3646
+ VMW_DEBUG_USER("Invalid SVGA3D command: %d\n",
3647
+ cmd_id + SVGA_3D_CMD_BASE);
36023648 return -EINVAL;
36033649 out_privileged:
3604
- DRM_ERROR("Privileged SVGA3D command: %d\n",
3605
- cmd_id + SVGA_3D_CMD_BASE);
3650
+ VMW_DEBUG_USER("Privileged SVGA3D command: %d\n",
3651
+ cmd_id + SVGA_3D_CMD_BASE);
36063652 return -EPERM;
36073653 out_old:
3608
- DRM_ERROR("Deprecated (disallowed) SVGA3D command: %d\n",
3609
- cmd_id + SVGA_3D_CMD_BASE);
3654
+ VMW_DEBUG_USER("Deprecated (disallowed) SVGA3D command: %d\n",
3655
+ cmd_id + SVGA_3D_CMD_BASE);
36103656 return -EINVAL;
36113657 out_new:
3612
- DRM_ERROR("SVGA3D command: %d not supported by virtual hardware.\n",
3613
- cmd_id + SVGA_3D_CMD_BASE);
3658
+ VMW_DEBUG_USER("SVGA3D command: %d not supported by virtual device.\n",
3659
+ cmd_id + SVGA_3D_CMD_BASE);
36143660 return -EINVAL;
36153661 }
36163662
36173663 static int vmw_cmd_check_all(struct vmw_private *dev_priv,
3618
- struct vmw_sw_context *sw_context,
3619
- void *buf,
3664
+ struct vmw_sw_context *sw_context, void *buf,
36203665 uint32_t size)
36213666 {
36223667 int32_t cur_size = size;
....@@ -3634,7 +3679,7 @@
36343679 }
36353680
36363681 if (unlikely(cur_size != 0)) {
3637
- DRM_ERROR("Command verifier out of sync.\n");
3682
+ VMW_DEBUG_USER("Command verifier out of sync.\n");
36383683 return -EINVAL;
36393684 }
36403685
....@@ -3643,23 +3688,20 @@
36433688
36443689 static void vmw_free_relocations(struct vmw_sw_context *sw_context)
36453690 {
3646
- sw_context->cur_reloc = 0;
3691
+ /* Memory is validation context memory, so no need to free it */
3692
+ INIT_LIST_HEAD(&sw_context->bo_relocations);
36473693 }
36483694
36493695 static void vmw_apply_relocations(struct vmw_sw_context *sw_context)
36503696 {
3651
- uint32_t i;
36523697 struct vmw_relocation *reloc;
3653
- struct ttm_validate_buffer *validate;
36543698 struct ttm_buffer_object *bo;
36553699
3656
- for (i = 0; i < sw_context->cur_reloc; ++i) {
3657
- reloc = &sw_context->relocs[i];
3658
- validate = &sw_context->val_bufs[reloc->index].base;
3659
- bo = validate->bo;
3700
+ list_for_each_entry(reloc, &sw_context->bo_relocations, head) {
3701
+ bo = &reloc->vbo->base;
36603702 switch (bo->mem.mem_type) {
36613703 case TTM_PL_VRAM:
3662
- reloc->location->offset += bo->offset;
3704
+ reloc->location->offset += bo->mem.start << PAGE_SHIFT;
36633705 reloc->location->gmrId = SVGA_GMR_FRAMEBUFFER;
36643706 break;
36653707 case VMW_PL_GMR:
....@@ -3673,110 +3715,6 @@
36733715 }
36743716 }
36753717 vmw_free_relocations(sw_context);
3676
-}
3677
-
3678
-/**
3679
- * vmw_resource_list_unrefererence - Free up a resource list and unreference
3680
- * all resources referenced by it.
3681
- *
3682
- * @list: The resource list.
3683
- */
3684
-static void vmw_resource_list_unreference(struct vmw_sw_context *sw_context,
3685
- struct list_head *list)
3686
-{
3687
- struct vmw_resource_val_node *val, *val_next;
3688
-
3689
- /*
3690
- * Drop references to resources held during command submission.
3691
- */
3692
-
3693
- list_for_each_entry_safe(val, val_next, list, head) {
3694
- list_del_init(&val->head);
3695
- vmw_resource_unreference(&val->res);
3696
-
3697
- if (val->staged_bindings) {
3698
- if (val->staged_bindings != sw_context->staged_bindings)
3699
- vmw_binding_state_free(val->staged_bindings);
3700
- else
3701
- sw_context->staged_bindings_inuse = false;
3702
- val->staged_bindings = NULL;
3703
- }
3704
-
3705
- kfree(val);
3706
- }
3707
-}
3708
-
3709
-static void vmw_clear_validations(struct vmw_sw_context *sw_context)
3710
-{
3711
- struct vmw_validate_buffer *entry, *next;
3712
- struct vmw_resource_val_node *val;
3713
-
3714
- /*
3715
- * Drop references to DMA buffers held during command submission.
3716
- */
3717
- list_for_each_entry_safe(entry, next, &sw_context->validate_nodes,
3718
- base.head) {
3719
- list_del(&entry->base.head);
3720
- ttm_bo_unref(&entry->base.bo);
3721
- (void) drm_ht_remove_item(&sw_context->res_ht, &entry->hash);
3722
- sw_context->cur_val_buf--;
3723
- }
3724
- BUG_ON(sw_context->cur_val_buf != 0);
3725
-
3726
- list_for_each_entry(val, &sw_context->resource_list, head)
3727
- (void) drm_ht_remove_item(&sw_context->res_ht, &val->hash);
3728
-}
3729
-
3730
-int vmw_validate_single_buffer(struct vmw_private *dev_priv,
3731
- struct ttm_buffer_object *bo,
3732
- bool interruptible,
3733
- bool validate_as_mob)
3734
-{
3735
- struct vmw_buffer_object *vbo =
3736
- container_of(bo, struct vmw_buffer_object, base);
3737
- struct ttm_operation_ctx ctx = { interruptible, false };
3738
- int ret;
3739
-
3740
- if (vbo->pin_count > 0)
3741
- return 0;
3742
-
3743
- if (validate_as_mob)
3744
- return ttm_bo_validate(bo, &vmw_mob_placement, &ctx);
3745
-
3746
- /**
3747
- * Put BO in VRAM if there is space, otherwise as a GMR.
3748
- * If there is no space in VRAM and GMR ids are all used up,
3749
- * start evicting GMRs to make room. If the DMA buffer can't be
3750
- * used as a GMR, this will return -ENOMEM.
3751
- */
3752
-
3753
- ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, &ctx);
3754
- if (likely(ret == 0 || ret == -ERESTARTSYS))
3755
- return ret;
3756
-
3757
- /**
3758
- * If that failed, try VRAM again, this time evicting
3759
- * previous contents.
3760
- */
3761
-
3762
- ret = ttm_bo_validate(bo, &vmw_vram_placement, &ctx);
3763
- return ret;
3764
-}
3765
-
3766
-static int vmw_validate_buffers(struct vmw_private *dev_priv,
3767
- struct vmw_sw_context *sw_context)
3768
-{
3769
- struct vmw_validate_buffer *entry;
3770
- int ret;
3771
-
3772
- list_for_each_entry(entry, &sw_context->validate_nodes, base.head) {
3773
- ret = vmw_validate_single_buffer(dev_priv, entry->base.bo,
3774
- true,
3775
- entry->validate_as_mob);
3776
- if (unlikely(ret != 0))
3777
- return ret;
3778
- }
3779
- return 0;
37803718 }
37813719
37823720 static int vmw_resize_cmd_bounce(struct vmw_sw_context *sw_context,
....@@ -3798,7 +3736,7 @@
37983736 sw_context->cmd_bounce = vmalloc(sw_context->cmd_bounce_size);
37993737
38003738 if (sw_context->cmd_bounce == NULL) {
3801
- DRM_ERROR("Failed to allocate command bounce buffer.\n");
3739
+ VMW_DEBUG_USER("Failed to allocate command bounce buffer.\n");
38023740 sw_context->cmd_bounce_size = 0;
38033741 return -ENOMEM;
38043742 }
....@@ -3813,8 +3751,8 @@
38133751 * If this fails for some reason, We sync the fifo and return NULL.
38143752 * It is then safe to fence buffers with a NULL pointer.
38153753 *
3816
- * If @p_handle is not NULL @file_priv must also not be NULL. Creates
3817
- * a userspace handle if @p_handle is not NULL, otherwise not.
3754
+ * If @p_handle is not NULL @file_priv must also not be NULL. Creates a
3755
+ * userspace handle if @p_handle is not NULL, otherwise not.
38183756 */
38193757
38203758 int vmw_execbuf_fence_commands(struct drm_file *file_priv,
....@@ -3831,7 +3769,7 @@
38313769
38323770 ret = vmw_fifo_send_fence(dev_priv, &sequence);
38333771 if (unlikely(ret != 0)) {
3834
- DRM_ERROR("Fence submission error. Syncing.\n");
3772
+ VMW_DEBUG_USER("Fence submission error. Syncing.\n");
38353773 synced = true;
38363774 }
38373775
....@@ -3842,9 +3780,8 @@
38423780 ret = vmw_fence_create(dev_priv->fman, sequence, p_fence);
38433781
38443782 if (unlikely(ret != 0 && !synced)) {
3845
- (void) vmw_fallback_wait(dev_priv, false, false,
3846
- sequence, false,
3847
- VMW_FENCE_WAIT_TIMEOUT);
3783
+ (void) vmw_fallback_wait(dev_priv, false, false, sequence,
3784
+ false, VMW_FENCE_WAIT_TIMEOUT);
38483785 *p_fence = NULL;
38493786 }
38503787
....@@ -3852,34 +3789,31 @@
38523789 }
38533790
38543791 /**
3855
- * vmw_execbuf_copy_fence_user - copy fence object information to
3856
- * user-space.
3792
+ * vmw_execbuf_copy_fence_user - copy fence object information to user-space.
38573793 *
38583794 * @dev_priv: Pointer to a vmw_private struct.
38593795 * @vmw_fp: Pointer to the struct vmw_fpriv representing the calling file.
38603796 * @ret: Return value from fence object creation.
3861
- * @user_fence_rep: User space address of a struct drm_vmw_fence_rep to
3862
- * which the information should be copied.
3797
+ * @user_fence_rep: User space address of a struct drm_vmw_fence_rep to which
3798
+ * the information should be copied.
38633799 * @fence: Pointer to the fenc object.
38643800 * @fence_handle: User-space fence handle.
38653801 * @out_fence_fd: exported file descriptor for the fence. -1 if not used
38663802 * @sync_file: Only used to clean up in case of an error in this function.
38673803 *
3868
- * This function copies fence information to user-space. If copying fails,
3869
- * The user-space struct drm_vmw_fence_rep::error member is hopefully
3870
- * left untouched, and if it's preloaded with an -EFAULT by user-space,
3871
- * the error will hopefully be detected.
3872
- * Also if copying fails, user-space will be unable to signal the fence
3873
- * object so we wait for it immediately, and then unreference the
3874
- * user-space reference.
3804
+ * This function copies fence information to user-space. If copying fails, the
3805
+ * user-space struct drm_vmw_fence_rep::error member is hopefully left
3806
+ * untouched, and if it's preloaded with an -EFAULT by user-space, the error
3807
+ * will hopefully be detected.
3808
+ *
3809
+ * Also if copying fails, user-space will be unable to signal the fence object
3810
+ * so we wait for it immediately, and then unreference the user-space reference.
38753811 */
38763812 int
38773813 vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
3878
- struct vmw_fpriv *vmw_fp,
3879
- int ret,
3814
+ struct vmw_fpriv *vmw_fp, int ret,
38803815 struct drm_vmw_fence_rep __user *user_fence_rep,
3881
- struct vmw_fence_obj *fence,
3882
- uint32_t fence_handle,
3816
+ struct vmw_fence_obj *fence, uint32_t fence_handle,
38833817 int32_t out_fence_fd)
38843818 {
38853819 struct drm_vmw_fence_rep fence_rep;
....@@ -3901,21 +3835,21 @@
39013835 }
39023836
39033837 /*
3904
- * copy_to_user errors will be detected by user space not
3905
- * seeing fence_rep::error filled in. Typically
3906
- * user-space would have pre-set that member to -EFAULT.
3838
+ * copy_to_user errors will be detected by user space not seeing
3839
+ * fence_rep::error filled in. Typically user-space would have pre-set
3840
+ * that member to -EFAULT.
39073841 */
39083842 ret = copy_to_user(user_fence_rep, &fence_rep,
39093843 sizeof(fence_rep));
39103844
39113845 /*
3912
- * User-space lost the fence object. We need to sync
3913
- * and unreference the handle.
3846
+ * User-space lost the fence object. We need to sync and unreference the
3847
+ * handle.
39143848 */
39153849 if (unlikely(ret != 0) && (fence_rep.error == 0)) {
3916
- ttm_ref_object_base_unref(vmw_fp->tfile,
3917
- fence_handle, TTM_REF_USAGE);
3918
- DRM_ERROR("Fence copy error. Syncing.\n");
3850
+ ttm_ref_object_base_unref(vmw_fp->tfile, fence_handle,
3851
+ TTM_REF_USAGE);
3852
+ VMW_DEBUG_USER("Fence copy error. Syncing.\n");
39193853 (void) vmw_fence_obj_wait(fence, false, false,
39203854 VMW_FENCE_WAIT_TIMEOUT);
39213855 }
....@@ -3924,33 +3858,30 @@
39243858 }
39253859
39263860 /**
3927
- * vmw_execbuf_submit_fifo - Patch a command batch and submit it using
3928
- * the fifo.
3861
+ * vmw_execbuf_submit_fifo - Patch a command batch and submit it using the fifo.
39293862 *
39303863 * @dev_priv: Pointer to a device private structure.
39313864 * @kernel_commands: Pointer to the unpatched command batch.
39323865 * @command_size: Size of the unpatched command batch.
39333866 * @sw_context: Structure holding the relocation lists.
39343867 *
3935
- * Side effects: If this function returns 0, then the command batch
3936
- * pointed to by @kernel_commands will have been modified.
3868
+ * Side effects: If this function returns 0, then the command batch pointed to
3869
+ * by @kernel_commands will have been modified.
39373870 */
39383871 static int vmw_execbuf_submit_fifo(struct vmw_private *dev_priv,
3939
- void *kernel_commands,
3940
- u32 command_size,
3872
+ void *kernel_commands, u32 command_size,
39413873 struct vmw_sw_context *sw_context)
39423874 {
39433875 void *cmd;
39443876
39453877 if (sw_context->dx_ctx_node)
3946
- cmd = vmw_fifo_reserve_dx(dev_priv, command_size,
3947
- sw_context->dx_ctx_node->res->id);
3878
+ cmd = VMW_FIFO_RESERVE_DX(dev_priv, command_size,
3879
+ sw_context->dx_ctx_node->ctx->id);
39483880 else
3949
- cmd = vmw_fifo_reserve(dev_priv, command_size);
3950
- if (!cmd) {
3951
- DRM_ERROR("Failed reserving fifo space for commands.\n");
3881
+ cmd = VMW_FIFO_RESERVE(dev_priv, command_size);
3882
+
3883
+ if (!cmd)
39523884 return -ENOMEM;
3953
- }
39543885
39553886 vmw_apply_relocations(sw_context);
39563887 memcpy(cmd, kernel_commands, command_size);
....@@ -3962,26 +3893,26 @@
39623893 }
39633894
39643895 /**
3965
- * vmw_execbuf_submit_cmdbuf - Patch a command batch and submit it using
3966
- * the command buffer manager.
3896
+ * vmw_execbuf_submit_cmdbuf - Patch a command batch and submit it using the
3897
+ * command buffer manager.
39673898 *
39683899 * @dev_priv: Pointer to a device private structure.
39693900 * @header: Opaque handle to the command buffer allocation.
39703901 * @command_size: Size of the unpatched command batch.
39713902 * @sw_context: Structure holding the relocation lists.
39723903 *
3973
- * Side effects: If this function returns 0, then the command buffer
3974
- * represented by @header will have been modified.
3904
+ * Side effects: If this function returns 0, then the command buffer represented
3905
+ * by @header will have been modified.
39753906 */
39763907 static int vmw_execbuf_submit_cmdbuf(struct vmw_private *dev_priv,
39773908 struct vmw_cmdbuf_header *header,
39783909 u32 command_size,
39793910 struct vmw_sw_context *sw_context)
39803911 {
3981
- u32 id = ((sw_context->dx_ctx_node) ? sw_context->dx_ctx_node->res->id :
3912
+ u32 id = ((sw_context->dx_ctx_node) ? sw_context->dx_ctx_node->ctx->id :
39823913 SVGA3D_INVALID_ID);
3983
- void *cmd = vmw_cmdbuf_reserve(dev_priv->cman, command_size,
3984
- id, false, header);
3914
+ void *cmd = vmw_cmdbuf_reserve(dev_priv->cman, command_size, id, false,
3915
+ header);
39853916
39863917 vmw_apply_relocations(sw_context);
39873918 vmw_resource_relocations_apply(cmd, &sw_context->res_relocations);
....@@ -4001,22 +3932,23 @@
40013932 * @header: Out parameter returning the opaque pointer to the command buffer.
40023933 *
40033934 * This function checks whether we can use the command buffer manager for
4004
- * submission and if so, creates a command buffer of suitable size and
4005
- * copies the user data into that buffer.
3935
+ * submission and if so, creates a command buffer of suitable size and copies
3936
+ * the user data into that buffer.
40063937 *
40073938 * On successful return, the function returns a pointer to the data in the
40083939 * command buffer and *@header is set to non-NULL.
4009
- * If command buffers could not be used, the function will return the value
4010
- * of @kernel_commands on function call. That value may be NULL. In that case,
4011
- * the value of *@header will be set to NULL.
3940
+ *
3941
+ * If command buffers could not be used, the function will return the value of
3942
+ * @kernel_commands on function call. That value may be NULL. In that case, the
3943
+ * value of *@header will be set to NULL.
3944
+ *
40123945 * If an error is encountered, the function will return a pointer error value.
40133946 * If the function is interrupted by a signal while sleeping, it will return
40143947 * -ERESTARTSYS casted to a pointer error value.
40153948 */
40163949 static void *vmw_execbuf_cmdbuf(struct vmw_private *dev_priv,
40173950 void __user *user_commands,
4018
- void *kernel_commands,
4019
- u32 command_size,
3951
+ void *kernel_commands, u32 command_size,
40203952 struct vmw_cmdbuf_header **header)
40213953 {
40223954 size_t cmdbuf_size;
....@@ -4024,7 +3956,7 @@
40243956
40253957 *header = NULL;
40263958 if (command_size > SVGA_CB_MAX_SIZE) {
4027
- DRM_ERROR("Command buffer is too large.\n");
3959
+ VMW_DEBUG_USER("Command buffer is too large.\n");
40283960 return ERR_PTR(-EINVAL);
40293961 }
40303962
....@@ -4034,15 +3966,14 @@
40343966 /* If possible, add a little space for fencing. */
40353967 cmdbuf_size = command_size + 512;
40363968 cmdbuf_size = min_t(size_t, cmdbuf_size, SVGA_CB_MAX_SIZE);
4037
- kernel_commands = vmw_cmdbuf_alloc(dev_priv->cman, cmdbuf_size,
4038
- true, header);
3969
+ kernel_commands = vmw_cmdbuf_alloc(dev_priv->cman, cmdbuf_size, true,
3970
+ header);
40393971 if (IS_ERR(kernel_commands))
40403972 return kernel_commands;
40413973
4042
- ret = copy_from_user(kernel_commands, user_commands,
4043
- command_size);
3974
+ ret = copy_from_user(kernel_commands, user_commands, command_size);
40443975 if (ret) {
4045
- DRM_ERROR("Failed copying commands.\n");
3976
+ VMW_DEBUG_USER("Failed copying commands.\n");
40463977 vmw_cmdbuf_header_free(*header);
40473978 *header = NULL;
40483979 return ERR_PTR(-EFAULT);
....@@ -4055,60 +3986,60 @@
40553986 struct vmw_sw_context *sw_context,
40563987 uint32_t handle)
40573988 {
4058
- struct vmw_resource_val_node *ctx_node;
40593989 struct vmw_resource *res;
40603990 int ret;
3991
+ unsigned int size;
40613992
40623993 if (handle == SVGA3D_INVALID_ID)
40633994 return 0;
40643995
4065
- ret = vmw_user_resource_lookup_handle(dev_priv, sw_context->fp->tfile,
4066
- handle, user_context_converter,
4067
- &res);
4068
- if (unlikely(ret != 0)) {
4069
- DRM_ERROR("Could not find or user DX context 0x%08x.\n",
4070
- (unsigned) handle);
3996
+ size = vmw_execbuf_res_size(dev_priv, vmw_res_dx_context);
3997
+ ret = vmw_validation_preload_res(sw_context->ctx, size);
3998
+ if (ret)
40713999 return ret;
4000
+
4001
+ res = vmw_user_resource_noref_lookup_handle
4002
+ (dev_priv, sw_context->fp->tfile, handle,
4003
+ user_context_converter);
4004
+ if (IS_ERR(res)) {
4005
+ VMW_DEBUG_USER("Could not find or user DX context 0x%08x.\n",
4006
+ (unsigned int) handle);
4007
+ return PTR_ERR(res);
40724008 }
40734009
4074
- ret = vmw_resource_val_add(sw_context, res, &ctx_node);
4010
+ ret = vmw_execbuf_res_noref_val_add(sw_context, res, VMW_RES_DIRTY_SET);
40754011 if (unlikely(ret != 0))
4076
- goto out_err;
4012
+ return ret;
40774013
4078
- sw_context->dx_ctx_node = ctx_node;
4014
+ sw_context->dx_ctx_node = vmw_execbuf_info_from_res(sw_context, res);
40794015 sw_context->man = vmw_context_res_man(res);
4080
-out_err:
4081
- vmw_resource_unreference(&res);
4082
- return ret;
4016
+
4017
+ return 0;
40834018 }
40844019
40854020 int vmw_execbuf_process(struct drm_file *file_priv,
40864021 struct vmw_private *dev_priv,
4087
- void __user *user_commands,
4088
- void *kernel_commands,
4089
- uint32_t command_size,
4090
- uint64_t throttle_us,
4022
+ void __user *user_commands, void *kernel_commands,
4023
+ uint32_t command_size, uint64_t throttle_us,
40914024 uint32_t dx_context_handle,
40924025 struct drm_vmw_fence_rep __user *user_fence_rep,
4093
- struct vmw_fence_obj **out_fence,
4094
- uint32_t flags)
4026
+ struct vmw_fence_obj **out_fence, uint32_t flags)
40954027 {
40964028 struct vmw_sw_context *sw_context = &dev_priv->ctx;
40974029 struct vmw_fence_obj *fence = NULL;
4098
- struct vmw_resource *error_resource;
4099
- struct list_head resource_list;
41004030 struct vmw_cmdbuf_header *header;
4101
- struct ww_acquire_ctx ticket;
4102
- uint32_t handle;
4031
+ uint32_t handle = 0;
41034032 int ret;
41044033 int32_t out_fence_fd = -1;
41054034 struct sync_file *sync_file = NULL;
4035
+ DECLARE_VAL_CONTEXT(val_ctx, &sw_context->res_ht, 1);
41064036
4037
+ vmw_validation_set_val_mem(&val_ctx, &dev_priv->vvm);
41074038
41084039 if (flags & DRM_VMW_EXECBUF_FLAG_EXPORT_FENCE_FD) {
41094040 out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
41104041 if (out_fence_fd < 0) {
4111
- DRM_ERROR("Failed to get a fence file descriptor.\n");
4042
+ VMW_DEBUG_USER("Failed to get a fence fd.\n");
41124043 return out_fence_fd;
41134044 }
41144045 }
....@@ -4141,24 +4072,21 @@
41414072 if (unlikely(ret != 0))
41424073 goto out_unlock;
41434074
4144
-
4145
- ret = copy_from_user(sw_context->cmd_bounce,
4146
- user_commands, command_size);
4147
-
4075
+ ret = copy_from_user(sw_context->cmd_bounce, user_commands,
4076
+ command_size);
41484077 if (unlikely(ret != 0)) {
41494078 ret = -EFAULT;
4150
- DRM_ERROR("Failed copying commands.\n");
4079
+ VMW_DEBUG_USER("Failed copying commands.\n");
41514080 goto out_unlock;
41524081 }
4082
+
41534083 kernel_commands = sw_context->cmd_bounce;
4154
- } else if (!header)
4084
+ } else if (!header) {
41554085 sw_context->kernel = true;
4086
+ }
41564087
41574088 sw_context->fp = vmw_fpriv(file_priv);
4158
- sw_context->cur_reloc = 0;
4159
- sw_context->cur_val_buf = 0;
4160
- INIT_LIST_HEAD(&sw_context->resource_list);
4161
- INIT_LIST_HEAD(&sw_context->ctx_resource_list);
4089
+ INIT_LIST_HEAD(&sw_context->ctx_list);
41624090 sw_context->cur_query_bo = dev_priv->pinned_bo;
41634091 sw_context->last_query_ctx = NULL;
41644092 sw_context->needs_post_query_barrier = false;
....@@ -4166,8 +4094,9 @@
41664094 sw_context->dx_query_mob = NULL;
41674095 sw_context->dx_query_ctx = NULL;
41684096 memset(sw_context->res_cache, 0, sizeof(sw_context->res_cache));
4169
- INIT_LIST_HEAD(&sw_context->validate_nodes);
41704097 INIT_LIST_HEAD(&sw_context->res_relocations);
4098
+ INIT_LIST_HEAD(&sw_context->bo_relocations);
4099
+
41714100 if (sw_context->staged_bindings)
41724101 vmw_binding_state_reset(sw_context->staged_bindings);
41734102
....@@ -4175,27 +4104,18 @@
41754104 ret = drm_ht_create(&sw_context->res_ht, VMW_RES_HT_ORDER);
41764105 if (unlikely(ret != 0))
41774106 goto out_unlock;
4107
+
41784108 sw_context->res_ht_initialized = true;
41794109 }
4110
+
41804111 INIT_LIST_HEAD(&sw_context->staged_cmd_res);
4181
- INIT_LIST_HEAD(&resource_list);
4112
+ sw_context->ctx = &val_ctx;
41824113 ret = vmw_execbuf_tie_context(dev_priv, sw_context, dx_context_handle);
4183
- if (unlikely(ret != 0)) {
4184
- list_splice_init(&sw_context->ctx_resource_list,
4185
- &sw_context->resource_list);
4114
+ if (unlikely(ret != 0))
41864115 goto out_err_nores;
4187
- }
41884116
41894117 ret = vmw_cmd_check_all(dev_priv, sw_context, kernel_commands,
41904118 command_size);
4191
- /*
4192
- * Merge the resource lists before checking the return status
4193
- * from vmd_cmd_check_all so that all the open hashtabs will
4194
- * be handled properly even if vmw_cmd_check_all fails.
4195
- */
4196
- list_splice_init(&sw_context->ctx_resource_list,
4197
- &sw_context->resource_list);
4198
-
41994119 if (unlikely(ret != 0))
42004120 goto out_err_nores;
42014121
....@@ -4203,18 +4123,19 @@
42034123 if (unlikely(ret != 0))
42044124 goto out_err_nores;
42054125
4206
- ret = ttm_eu_reserve_buffers(&ticket, &sw_context->validate_nodes,
4207
- true, NULL);
4126
+ ret = vmw_validation_bo_reserve(&val_ctx, true);
42084127 if (unlikely(ret != 0))
42094128 goto out_err_nores;
42104129
4211
- ret = vmw_validate_buffers(dev_priv, sw_context);
4130
+ ret = vmw_validation_bo_validate(&val_ctx, true);
42124131 if (unlikely(ret != 0))
42134132 goto out_err;
42144133
4215
- ret = vmw_resources_validate(sw_context);
4134
+ ret = vmw_validation_res_validate(&val_ctx, true);
42164135 if (unlikely(ret != 0))
42174136 goto out_err;
4137
+
4138
+ vmw_validation_drop_ht(&val_ctx);
42184139
42194140 ret = mutex_lock_interruptible(&dev_priv->binding_mutex);
42204141 if (unlikely(ret != 0)) {
....@@ -4241,40 +4162,35 @@
42414162 goto out_err;
42424163
42434164 vmw_query_bo_switch_commit(dev_priv, sw_context);
4244
- ret = vmw_execbuf_fence_commands(file_priv, dev_priv,
4245
- &fence,
4165
+ ret = vmw_execbuf_fence_commands(file_priv, dev_priv, &fence,
42464166 (user_fence_rep) ? &handle : NULL);
42474167 /*
42484168 * This error is harmless, because if fence submission fails,
42494169 * vmw_fifo_send_fence will sync. The error will be propagated to
42504170 * user-space in @fence_rep
42514171 */
4252
-
42534172 if (ret != 0)
4254
- DRM_ERROR("Fence submission error. Syncing.\n");
4173
+ VMW_DEBUG_USER("Fence submission error. Syncing.\n");
42554174
4256
- vmw_resources_unreserve(sw_context, false);
4175
+ vmw_execbuf_bindings_commit(sw_context, false);
4176
+ vmw_bind_dx_query_mob(sw_context);
4177
+ vmw_validation_res_unreserve(&val_ctx, false);
42574178
4258
- ttm_eu_fence_buffer_objects(&ticket, &sw_context->validate_nodes,
4259
- (void *) fence);
4179
+ vmw_validation_bo_fence(sw_context->ctx, fence);
42604180
4261
- if (unlikely(dev_priv->pinned_bo != NULL &&
4262
- !dev_priv->query_cid_valid))
4181
+ if (unlikely(dev_priv->pinned_bo != NULL && !dev_priv->query_cid_valid))
42634182 __vmw_execbuf_release_pinned_bo(dev_priv, fence);
42644183
4265
- vmw_clear_validations(sw_context);
4266
-
42674184 /*
4268
- * If anything fails here, give up trying to export the fence
4269
- * and do a sync since the user mode will not be able to sync
4270
- * the fence itself. This ensures we are still functionally
4271
- * correct.
4185
+ * If anything fails here, give up trying to export the fence and do a
4186
+ * sync since the user mode will not be able to sync the fence itself.
4187
+ * This ensures we are still functionally correct.
42724188 */
42734189 if (flags & DRM_VMW_EXECBUF_FLAG_EXPORT_FENCE_FD) {
42744190
42754191 sync_file = sync_file_create(&fence->base);
42764192 if (!sync_file) {
4277
- DRM_ERROR("Unable to create sync file for fence\n");
4193
+ VMW_DEBUG_USER("Sync file create failed for fence\n");
42784194 put_unused_fd(out_fence_fd);
42794195 out_fence_fd = -1;
42804196
....@@ -4305,44 +4221,39 @@
43054221 vmw_fence_obj_unreference(&fence);
43064222 }
43074223
4308
- list_splice_init(&sw_context->resource_list, &resource_list);
43094224 vmw_cmdbuf_res_commit(&sw_context->staged_cmd_res);
43104225 mutex_unlock(&dev_priv->cmdbuf_mutex);
43114226
43124227 /*
4313
- * Unreference resources outside of the cmdbuf_mutex to
4314
- * avoid deadlocks in resource destruction paths.
4228
+ * Unreference resources outside of the cmdbuf_mutex to avoid deadlocks
4229
+ * in resource destruction paths.
43154230 */
4316
- vmw_resource_list_unreference(sw_context, &resource_list);
4231
+ vmw_validation_unref_lists(&val_ctx);
43174232
43184233 return ret;
43194234
43204235 out_unlock_binding:
43214236 mutex_unlock(&dev_priv->binding_mutex);
43224237 out_err:
4323
- ttm_eu_backoff_reservation(&ticket, &sw_context->validate_nodes);
4238
+ vmw_validation_bo_backoff(&val_ctx);
43244239 out_err_nores:
4325
- vmw_resources_unreserve(sw_context, true);
4240
+ vmw_execbuf_bindings_commit(sw_context, true);
4241
+ vmw_validation_res_unreserve(&val_ctx, true);
43264242 vmw_resource_relocations_free(&sw_context->res_relocations);
43274243 vmw_free_relocations(sw_context);
4328
- vmw_clear_validations(sw_context);
4329
- if (unlikely(dev_priv->pinned_bo != NULL &&
4330
- !dev_priv->query_cid_valid))
4244
+ if (unlikely(dev_priv->pinned_bo != NULL && !dev_priv->query_cid_valid))
43314245 __vmw_execbuf_release_pinned_bo(dev_priv, NULL);
43324246 out_unlock:
4333
- list_splice_init(&sw_context->resource_list, &resource_list);
4334
- error_resource = sw_context->error_resource;
4335
- sw_context->error_resource = NULL;
43364247 vmw_cmdbuf_res_revert(&sw_context->staged_cmd_res);
4248
+ vmw_validation_drop_ht(&val_ctx);
4249
+ WARN_ON(!list_empty(&sw_context->ctx_list));
43374250 mutex_unlock(&dev_priv->cmdbuf_mutex);
43384251
43394252 /*
4340
- * Unreference resources outside of the cmdbuf_mutex to
4341
- * avoid deadlocks in resource destruction paths.
4253
+ * Unreference resources outside of the cmdbuf_mutex to avoid deadlocks
4254
+ * in resource destruction paths.
43424255 */
4343
- vmw_resource_list_unreference(sw_context, &resource_list);
4344
- if (unlikely(error_resource != NULL))
4345
- vmw_resource_unreference(&error_resource);
4256
+ vmw_validation_unref_lists(&val_ctx);
43464257 out_free_header:
43474258 if (header)
43484259 vmw_cmdbuf_header_free(header);
....@@ -4358,13 +4269,13 @@
43584269 *
43594270 * @dev_priv: The device private structure.
43604271 *
4361
- * This function is called to idle the fifo and unpin the query buffer
4362
- * if the normal way to do this hits an error, which should typically be
4363
- * extremely rare.
4272
+ * This function is called to idle the fifo and unpin the query buffer if the
4273
+ * normal way to do this hits an error, which should typically be extremely
4274
+ * rare.
43644275 */
43654276 static void vmw_execbuf_unpin_panic(struct vmw_private *dev_priv)
43664277 {
4367
- DRM_ERROR("Can't unpin query buffer. Trying to recover.\n");
4278
+ VMW_DEBUG_USER("Can't unpin query buffer. Trying to recover.\n");
43684279
43694280 (void) vmw_fallback_wait(dev_priv, false, true, 0, false, 10*HZ);
43704281 vmw_bo_pin_reserved(dev_priv->pinned_bo, false);
....@@ -4376,65 +4287,57 @@
43764287
43774288
43784289 /**
4379
- * __vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned
4380
- * query bo.
4290
+ * __vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned query
4291
+ * bo.
43814292 *
43824293 * @dev_priv: The device private structure.
4383
- * @fence: If non-NULL should point to a struct vmw_fence_obj issued
4384
- * _after_ a query barrier that flushes all queries touching the current
4385
- * buffer pointed to by @dev_priv->pinned_bo
4294
+ * @fence: If non-NULL should point to a struct vmw_fence_obj issued _after_ a
4295
+ * query barrier that flushes all queries touching the current buffer pointed to
4296
+ * by @dev_priv->pinned_bo
43864297 *
4387
- * This function should be used to unpin the pinned query bo, or
4388
- * as a query barrier when we need to make sure that all queries have
4389
- * finished before the next fifo command. (For example on hardware
4390
- * context destructions where the hardware may otherwise leak unfinished
4391
- * queries).
4298
+ * This function should be used to unpin the pinned query bo, or as a query
4299
+ * barrier when we need to make sure that all queries have finished before the
4300
+ * next fifo command. (For example on hardware context destructions where the
4301
+ * hardware may otherwise leak unfinished queries).
43924302 *
4393
- * This function does not return any failure codes, but make attempts
4394
- * to do safe unpinning in case of errors.
4303
+ * This function does not return any failure codes, but make attempts to do safe
4304
+ * unpinning in case of errors.
43954305 *
4396
- * The function will synchronize on the previous query barrier, and will
4397
- * thus not finish until that barrier has executed.
4306
+ * The function will synchronize on the previous query barrier, and will thus
4307
+ * not finish until that barrier has executed.
43984308 *
4399
- * the @dev_priv->cmdbuf_mutex needs to be held by the current thread
4400
- * before calling this function.
4309
+ * the @dev_priv->cmdbuf_mutex needs to be held by the current thread before
4310
+ * calling this function.
44014311 */
44024312 void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
44034313 struct vmw_fence_obj *fence)
44044314 {
44054315 int ret = 0;
4406
- struct list_head validate_list;
4407
- struct ttm_validate_buffer pinned_val, query_val;
44084316 struct vmw_fence_obj *lfence = NULL;
4409
- struct ww_acquire_ctx ticket;
4317
+ DECLARE_VAL_CONTEXT(val_ctx, NULL, 0);
44104318
44114319 if (dev_priv->pinned_bo == NULL)
44124320 goto out_unlock;
44134321
4414
- INIT_LIST_HEAD(&validate_list);
4415
-
4416
- pinned_val.bo = ttm_bo_reference(&dev_priv->pinned_bo->base);
4417
- pinned_val.shared = false;
4418
- list_add_tail(&pinned_val.head, &validate_list);
4419
-
4420
- query_val.bo = ttm_bo_reference(&dev_priv->dummy_query_bo->base);
4421
- query_val.shared = false;
4422
- list_add_tail(&query_val.head, &validate_list);
4423
-
4424
- ret = ttm_eu_reserve_buffers(&ticket, &validate_list,
4425
- false, NULL);
4426
- if (unlikely(ret != 0)) {
4427
- vmw_execbuf_unpin_panic(dev_priv);
4322
+ ret = vmw_validation_add_bo(&val_ctx, dev_priv->pinned_bo, false,
4323
+ false);
4324
+ if (ret)
44284325 goto out_no_reserve;
4429
- }
4326
+
4327
+ ret = vmw_validation_add_bo(&val_ctx, dev_priv->dummy_query_bo, false,
4328
+ false);
4329
+ if (ret)
4330
+ goto out_no_reserve;
4331
+
4332
+ ret = vmw_validation_bo_reserve(&val_ctx, false);
4333
+ if (ret)
4334
+ goto out_no_reserve;
44304335
44314336 if (dev_priv->query_cid_valid) {
44324337 BUG_ON(fence != NULL);
44334338 ret = vmw_fifo_emit_dummy_query(dev_priv, dev_priv->query_cid);
4434
- if (unlikely(ret != 0)) {
4435
- vmw_execbuf_unpin_panic(dev_priv);
4339
+ if (ret)
44364340 goto out_no_emit;
4437
- }
44384341 dev_priv->query_cid_valid = false;
44394342 }
44404343
....@@ -4448,41 +4351,38 @@
44484351 NULL);
44494352 fence = lfence;
44504353 }
4451
- ttm_eu_fence_buffer_objects(&ticket, &validate_list, (void *) fence);
4354
+ vmw_validation_bo_fence(&val_ctx, fence);
44524355 if (lfence != NULL)
44534356 vmw_fence_obj_unreference(&lfence);
44544357
4455
- ttm_bo_unref(&query_val.bo);
4456
- ttm_bo_unref(&pinned_val.bo);
4358
+ vmw_validation_unref_lists(&val_ctx);
44574359 vmw_bo_unreference(&dev_priv->pinned_bo);
4360
+
44584361 out_unlock:
44594362 return;
4460
-
44614363 out_no_emit:
4462
- ttm_eu_backoff_reservation(&ticket, &validate_list);
4364
+ vmw_validation_bo_backoff(&val_ctx);
44634365 out_no_reserve:
4464
- ttm_bo_unref(&query_val.bo);
4465
- ttm_bo_unref(&pinned_val.bo);
4366
+ vmw_validation_unref_lists(&val_ctx);
4367
+ vmw_execbuf_unpin_panic(dev_priv);
44664368 vmw_bo_unreference(&dev_priv->pinned_bo);
44674369 }
44684370
44694371 /**
4470
- * vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned
4471
- * query bo.
4372
+ * vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned query bo.
44724373 *
44734374 * @dev_priv: The device private structure.
44744375 *
4475
- * This function should be used to unpin the pinned query bo, or
4476
- * as a query barrier when we need to make sure that all queries have
4477
- * finished before the next fifo command. (For example on hardware
4478
- * context destructions where the hardware may otherwise leak unfinished
4479
- * queries).
4376
+ * This function should be used to unpin the pinned query bo, or as a query
4377
+ * barrier when we need to make sure that all queries have finished before the
4378
+ * next fifo command. (For example on hardware context destructions where the
4379
+ * hardware may otherwise leak unfinished queries).
44804380 *
4481
- * This function does not return any failure codes, but make attempts
4482
- * to do safe unpinning in case of errors.
4381
+ * This function does not return any failure codes, but make attempts to do safe
4382
+ * unpinning in case of errors.
44834383 *
4484
- * The function will synchronize on the previous query barrier, and will
4485
- * thus not finish until that barrier has executed.
4384
+ * The function will synchronize on the previous query barrier, and will thus
4385
+ * not finish until that barrier has executed.
44864386 */
44874387 void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv)
44884388 {
....@@ -4492,62 +4392,43 @@
44924392 mutex_unlock(&dev_priv->cmdbuf_mutex);
44934393 }
44944394
4495
-int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
4496
- struct drm_file *file_priv, size_t size)
4395
+int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
4396
+ struct drm_file *file_priv)
44974397 {
44984398 struct vmw_private *dev_priv = vmw_priv(dev);
4499
- struct drm_vmw_execbuf_arg arg;
4399
+ struct drm_vmw_execbuf_arg *arg = data;
45004400 int ret;
4501
- static const size_t copy_offset[] = {
4502
- offsetof(struct drm_vmw_execbuf_arg, context_handle),
4503
- sizeof(struct drm_vmw_execbuf_arg)};
45044401 struct dma_fence *in_fence = NULL;
45054402
4506
- if (unlikely(size < copy_offset[0])) {
4507
- DRM_ERROR("Invalid command size, ioctl %d\n",
4508
- DRM_VMW_EXECBUF);
4509
- return -EINVAL;
4510
- }
4511
-
4512
- if (copy_from_user(&arg, (void __user *) data, copy_offset[0]) != 0)
4513
- return -EFAULT;
4514
-
45154403 /*
4516
- * Extend the ioctl argument while
4517
- * maintaining backwards compatibility:
4518
- * We take different code paths depending on the value of
4519
- * arg.version.
4404
+ * Extend the ioctl argument while maintaining backwards compatibility:
4405
+ * We take different code paths depending on the value of arg->version.
4406
+ *
4407
+ * Note: The ioctl argument is extended and zeropadded by core DRM.
45204408 */
4521
-
4522
- if (unlikely(arg.version > DRM_VMW_EXECBUF_VERSION ||
4523
- arg.version == 0)) {
4524
- DRM_ERROR("Incorrect execbuf version.\n");
4409
+ if (unlikely(arg->version > DRM_VMW_EXECBUF_VERSION ||
4410
+ arg->version == 0)) {
4411
+ VMW_DEBUG_USER("Incorrect execbuf version.\n");
45254412 return -EINVAL;
45264413 }
45274414
4528
- if (arg.version > 1 &&
4529
- copy_from_user(&arg.context_handle,
4530
- (void __user *) (data + copy_offset[0]),
4531
- copy_offset[arg.version - 1] -
4532
- copy_offset[0]) != 0)
4533
- return -EFAULT;
4534
-
4535
- switch (arg.version) {
4415
+ switch (arg->version) {
45364416 case 1:
4537
- arg.context_handle = (uint32_t) -1;
4417
+ /* For v1 core DRM have extended + zeropadded the data */
4418
+ arg->context_handle = (uint32_t) -1;
45384419 break;
45394420 case 2:
45404421 default:
4422
+ /* For v2 and later core DRM would have correctly copied it */
45414423 break;
45424424 }
45434425
4544
-
45454426 /* If imported a fence FD from elsewhere, then wait on it */
4546
- if (arg.flags & DRM_VMW_EXECBUF_FLAG_IMPORT_FENCE_FD) {
4547
- in_fence = sync_file_get_fence(arg.imported_fence_fd);
4427
+ if (arg->flags & DRM_VMW_EXECBUF_FLAG_IMPORT_FENCE_FD) {
4428
+ in_fence = sync_file_get_fence(arg->imported_fence_fd);
45484429
45494430 if (!in_fence) {
4550
- DRM_ERROR("Cannot get imported fence\n");
4431
+ VMW_DEBUG_USER("Cannot get imported fence\n");
45514432 return -EINVAL;
45524433 }
45534434
....@@ -4561,12 +4442,12 @@
45614442 return ret;
45624443
45634444 ret = vmw_execbuf_process(file_priv, dev_priv,
4564
- (void __user *)(unsigned long)arg.commands,
4565
- NULL, arg.command_size, arg.throttle_us,
4566
- arg.context_handle,
4567
- (void __user *)(unsigned long)arg.fence_rep,
4568
- NULL,
4569
- arg.flags);
4445
+ (void __user *)(unsigned long)arg->commands,
4446
+ NULL, arg->command_size, arg->throttle_us,
4447
+ arg->context_handle,
4448
+ (void __user *)(unsigned long)arg->fence_rep,
4449
+ NULL, arg->flags);
4450
+
45704451 ttm_read_unlock(&dev_priv->reservation_sem);
45714452 if (unlikely(ret != 0))
45724453 goto out;