forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
....@@ -36,7 +36,7 @@
3636 struct vmw_resource res;
3737 struct vmw_ctx_binding_state *cbs;
3838 struct vmw_cmdbuf_res_manager *man;
39
- struct vmw_resource *cotables[SVGA_COTABLE_DX10_MAX];
39
+ struct vmw_resource *cotables[SVGA_COTABLE_MAX];
4040 spinlock_t cotable_lock;
4141 struct vmw_buffer_object *dx_query_mob;
4242 };
....@@ -88,6 +88,8 @@
8888 .res_type = vmw_res_context,
8989 .needs_backup = true,
9090 .may_evict = true,
91
+ .prio = 3,
92
+ .dirty_prio = 3,
9193 .type_name = "guest backed contexts",
9294 .backup_placement = &vmw_mob_placement,
9395 .create = vmw_gb_context_create,
....@@ -100,6 +102,8 @@
100102 .res_type = vmw_res_dx_context,
101103 .needs_backup = true,
102104 .may_evict = true,
105
+ .prio = 3,
106
+ .dirty_prio = 3,
103107 .type_name = "dx contexts",
104108 .backup_placement = &vmw_mob_placement,
105109 .create = vmw_dx_context_create,
....@@ -112,12 +116,15 @@
112116 * Context management:
113117 */
114118
115
-static void vmw_context_cotables_unref(struct vmw_user_context *uctx)
119
+static void vmw_context_cotables_unref(struct vmw_private *dev_priv,
120
+ struct vmw_user_context *uctx)
116121 {
117122 struct vmw_resource *res;
118123 int i;
124
+ u32 cotable_max = has_sm5_context(dev_priv) ?
125
+ SVGA_COTABLE_MAX : SVGA_COTABLE_DX10_MAX;
119126
120
- for (i = 0; i < SVGA_COTABLE_DX10_MAX; ++i) {
127
+ for (i = 0; i < cotable_max; ++i) {
121128 spin_lock(&uctx->cotable_lock);
122129 res = uctx->cotables[i];
123130 uctx->cotables[i] = NULL;
....@@ -151,17 +158,14 @@
151158 !dev_priv->query_cid_valid)
152159 __vmw_execbuf_release_pinned_bo(dev_priv, NULL);
153160 mutex_unlock(&dev_priv->cmdbuf_mutex);
154
- vmw_context_cotables_unref(uctx);
161
+ vmw_context_cotables_unref(dev_priv, uctx);
155162 return;
156163 }
157164
158165 vmw_execbuf_release_pinned_bo(dev_priv);
159
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
160
- if (unlikely(cmd == NULL)) {
161
- DRM_ERROR("Failed reserving FIFO space for surface "
162
- "destruction.\n");
166
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
167
+ if (unlikely(cmd == NULL))
163168 return;
164
- }
165169
166170 cmd->header.id = SVGA_3D_CMD_CONTEXT_DESTROY;
167171 cmd->header.size = sizeof(cmd->body);
....@@ -207,23 +211,23 @@
207211 spin_lock_init(&uctx->cotable_lock);
208212
209213 if (dx) {
210
- for (i = 0; i < SVGA_COTABLE_DX10_MAX; ++i) {
214
+ u32 cotable_max = has_sm5_context(dev_priv) ?
215
+ SVGA_COTABLE_MAX : SVGA_COTABLE_DX10_MAX;
216
+ for (i = 0; i < cotable_max; ++i) {
211217 uctx->cotables[i] = vmw_cotable_alloc(dev_priv,
212218 &uctx->res, i);
213
- if (unlikely(IS_ERR(uctx->cotables[i]))) {
219
+ if (IS_ERR(uctx->cotables[i])) {
214220 ret = PTR_ERR(uctx->cotables[i]);
215221 goto out_cotables;
216222 }
217223 }
218224 }
219225
220
-
221
-
222
- vmw_resource_activate(res, vmw_hw_context_destroy);
226
+ res->hw_destroy = vmw_hw_context_destroy;
223227 return 0;
224228
225229 out_cotables:
226
- vmw_context_cotables_unref(uctx);
230
+ vmw_context_cotables_unref(dev_priv, uctx);
227231 out_err:
228232 if (res_free)
229233 res_free(res);
....@@ -261,9 +265,8 @@
261265 return -ENOMEM;
262266 }
263267
264
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
268
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
265269 if (unlikely(cmd == NULL)) {
266
- DRM_ERROR("Fifo reserve failed.\n");
267270 vmw_resource_unreference(&res);
268271 return -ENOMEM;
269272 }
....@@ -274,7 +277,7 @@
274277
275278 vmw_fifo_commit(dev_priv, sizeof(*cmd));
276279 vmw_fifo_resource_inc(dev_priv);
277
- vmw_resource_activate(res, vmw_hw_context_destroy);
280
+ res->hw_destroy = vmw_hw_context_destroy;
278281 return 0;
279282
280283 out_early:
....@@ -313,10 +316,8 @@
313316 goto out_no_fifo;
314317 }
315318
316
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
319
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
317320 if (unlikely(cmd == NULL)) {
318
- DRM_ERROR("Failed reserving FIFO space for context "
319
- "creation.\n");
320321 ret = -ENOMEM;
321322 goto out_no_fifo;
322323 }
....@@ -347,12 +348,10 @@
347348
348349 BUG_ON(bo->mem.mem_type != VMW_PL_MOB);
349350
350
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
351
- if (unlikely(cmd == NULL)) {
352
- DRM_ERROR("Failed reserving FIFO space for context "
353
- "binding.\n");
351
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
352
+ if (unlikely(cmd == NULL))
354353 return -ENOMEM;
355
- }
354
+
356355 cmd->header.id = SVGA_3D_CMD_BIND_GB_CONTEXT;
357356 cmd->header.size = sizeof(cmd->body);
358357 cmd->body.cid = res->id;
....@@ -393,10 +392,8 @@
393392
394393 submit_size = sizeof(*cmd2) + (readback ? sizeof(*cmd1) : 0);
395394
396
- cmd = vmw_fifo_reserve(dev_priv, submit_size);
395
+ cmd = VMW_FIFO_RESERVE(dev_priv, submit_size);
397396 if (unlikely(cmd == NULL)) {
398
- DRM_ERROR("Failed reserving FIFO space for context "
399
- "unbinding.\n");
400397 mutex_unlock(&dev_priv->binding_mutex);
401398 return -ENOMEM;
402399 }
....@@ -443,12 +440,9 @@
443440 if (likely(res->id == -1))
444441 return 0;
445442
446
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
447
- if (unlikely(cmd == NULL)) {
448
- DRM_ERROR("Failed reserving FIFO space for context "
449
- "destruction.\n");
443
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
444
+ if (unlikely(cmd == NULL))
450445 return -ENOMEM;
451
- }
452446
453447 cmd->header.id = SVGA_3D_CMD_DESTROY_GB_CONTEXT;
454448 cmd->header.size = sizeof(cmd->body);
....@@ -489,10 +483,8 @@
489483 goto out_no_fifo;
490484 }
491485
492
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
486
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
493487 if (unlikely(cmd == NULL)) {
494
- DRM_ERROR("Failed reserving FIFO space for context "
495
- "creation.\n");
496488 ret = -ENOMEM;
497489 goto out_no_fifo;
498490 }
....@@ -523,12 +515,9 @@
523515
524516 BUG_ON(bo->mem.mem_type != VMW_PL_MOB);
525517
526
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
527
- if (unlikely(cmd == NULL)) {
528
- DRM_ERROR("Failed reserving FIFO space for context "
529
- "binding.\n");
518
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
519
+ if (unlikely(cmd == NULL))
530520 return -ENOMEM;
531
- }
532521
533522 cmd->header.id = SVGA_3D_CMD_DX_BIND_CONTEXT;
534523 cmd->header.size = sizeof(cmd->body);
....@@ -561,10 +550,12 @@
561550 {
562551 struct vmw_user_context *uctx =
563552 container_of(ctx, struct vmw_user_context, res);
553
+ u32 cotable_max = has_sm5_context(ctx->dev_priv) ?
554
+ SVGA_COTABLE_MAX : SVGA_COTABLE_DX10_MAX;
564555 int i;
565556
566557 vmw_binding_state_scrub(uctx->cbs);
567
- for (i = 0; i < SVGA_COTABLE_DX10_MAX; ++i) {
558
+ for (i = 0; i < cotable_max; ++i) {
568559 struct vmw_resource *res;
569560
570561 /* Avoid racing with ongoing cotable destruction. */
....@@ -617,10 +608,8 @@
617608
618609 submit_size = sizeof(*cmd2) + (readback ? sizeof(*cmd1) : 0);
619610
620
- cmd = vmw_fifo_reserve(dev_priv, submit_size);
611
+ cmd = VMW_FIFO_RESERVE(dev_priv, submit_size);
621612 if (unlikely(cmd == NULL)) {
622
- DRM_ERROR("Failed reserving FIFO space for context "
623
- "unbinding.\n");
624613 mutex_unlock(&dev_priv->binding_mutex);
625614 return -ENOMEM;
626615 }
....@@ -667,12 +656,9 @@
667656 if (likely(res->id == -1))
668657 return 0;
669658
670
- cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
671
- if (unlikely(cmd == NULL)) {
672
- DRM_ERROR("Failed reserving FIFO space for context "
673
- "destruction.\n");
659
+ cmd = VMW_FIFO_RESERVE(dev_priv, sizeof(*cmd));
660
+ if (unlikely(cmd == NULL))
674661 return -ENOMEM;
675
- }
676662
677663 cmd->header.id = SVGA_3D_CMD_DX_DESTROY_CONTEXT;
678664 cmd->header.size = sizeof(cmd->body);
....@@ -752,19 +738,15 @@
752738 };
753739 int ret;
754740
755
- if (!dev_priv->has_dx && dx) {
756
- DRM_ERROR("DX contexts not supported by device.\n");
741
+ if (!has_sm4_context(dev_priv) && dx) {
742
+ VMW_DEBUG_USER("DX contexts not supported by device.\n");
757743 return -EINVAL;
758744 }
759745
760
- /*
761
- * Approximate idr memory usage with 128 bytes. It will be limited
762
- * by maximum number_of contexts anyway.
763
- */
764
-
765746 if (unlikely(vmw_user_context_size == 0))
766
- vmw_user_context_size = ttm_round_pot(sizeof(*ctx)) + 128 +
767
- ((dev_priv->has_mob) ? vmw_cmdbuf_res_man_size() : 0);
747
+ vmw_user_context_size = ttm_round_pot(sizeof(*ctx)) +
748
+ ((dev_priv->has_mob) ? vmw_cmdbuf_res_man_size() : 0) +
749
+ + VMW_IDA_ACC_SIZE + TTM_OBJ_EXTRA_SIZE;
768750
769751 ret = ttm_read_lock(&dev_priv->reservation_sem, true);
770752 if (unlikely(ret != 0))
....@@ -809,7 +791,7 @@
809791 goto out_err;
810792 }
811793
812
- arg->cid = ctx->base.hash.key;
794
+ arg->cid = ctx->base.handle;
813795 out_err:
814796 vmw_resource_unreference(&res);
815797 out_unlock:
....@@ -864,12 +846,14 @@
864846 struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
865847 SVGACOTableType cotable_type)
866848 {
867
- if (cotable_type >= SVGA_COTABLE_DX10_MAX)
849
+ u32 cotable_max = has_sm5_context(ctx->dev_priv) ?
850
+ SVGA_COTABLE_MAX : SVGA_COTABLE_DX10_MAX;
851
+
852
+ if (cotable_type >= cotable_max)
868853 return ERR_PTR(-EINVAL);
869854
870
- return vmw_resource_reference
871
- (container_of(ctx, struct vmw_user_context, res)->
872
- cotables[cotable_type]);
855
+ return container_of(ctx, struct vmw_user_context, res)->
856
+ cotables[cotable_type];
873857 }
874858
875859 /**