forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/vc4/vc4_gem.c
....@@ -29,6 +29,8 @@
2929 #include <linux/sched/signal.h>
3030 #include <linux/dma-fence-array.h>
3131
32
+#include <drm/drm_syncobj.h>
33
+
3234 #include "uapi/drm/vc4_drm.h"
3335 #include "vc4_drv.h"
3436 #include "vc4_regs.h"
....@@ -56,7 +58,7 @@
5658 unsigned int i;
5759
5860 for (i = 0; i < state->user_state.bo_count; i++)
59
- drm_gem_object_put_unlocked(state->bo[i]);
61
+ drm_gem_object_put(state->bo[i]);
6062
6163 kfree(state);
6264 }
....@@ -73,6 +75,11 @@
7375 unsigned long irqflags;
7476 u32 i;
7577 int ret = 0;
78
+
79
+ if (!vc4->v3d) {
80
+ DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
81
+ return -ENODEV;
82
+ }
7683
7784 spin_lock_irqsave(&vc4->job_lock, irqflags);
7885 kernel_state = vc4->hang_state;
....@@ -307,16 +314,16 @@
307314 struct vc4_dev *vc4 =
308315 container_of(work, struct vc4_dev, hangcheck.reset_work);
309316
310
- vc4_save_hang_state(vc4->dev);
317
+ vc4_save_hang_state(&vc4->base);
311318
312
- vc4_reset(vc4->dev);
319
+ vc4_reset(&vc4->base);
313320 }
314321
315322 static void
316323 vc4_hangcheck_elapsed(struct timer_list *t)
317324 {
318325 struct vc4_dev *vc4 = from_timer(vc4, t, hangcheck.timer);
319
- struct drm_device *dev = vc4->dev;
326
+ struct drm_device *dev = &vc4->base;
320327 uint32_t ct0ca, ct1ca;
321328 unsigned long irqflags;
322329 struct vc4_exec_info *bin_exec, *render_exec;
....@@ -536,7 +543,7 @@
536543 bo = to_vc4_bo(&exec->bo[i]->base);
537544 bo->seqno = seqno;
538545
539
- reservation_object_add_shared_fence(bo->resv, exec->fence);
546
+ dma_resv_add_shared_fence(bo->base.base.resv, exec->fence);
540547 }
541548
542549 list_for_each_entry(bo, &exec->unref_list, unref_head) {
....@@ -547,7 +554,7 @@
547554 bo = to_vc4_bo(&exec->rcl_write_bo[i]->base);
548555 bo->write_seqno = seqno;
549556
550
- reservation_object_add_excl_fence(bo->resv, exec->fence);
557
+ dma_resv_add_excl_fence(bo->base.base.resv, exec->fence);
551558 }
552559 }
553560
....@@ -559,9 +566,9 @@
559566 int i;
560567
561568 for (i = 0; i < exec->bo_count; i++) {
562
- struct vc4_bo *bo = to_vc4_bo(&exec->bo[i]->base);
569
+ struct drm_gem_object *bo = &exec->bo[i]->base;
563570
564
- ww_mutex_unlock(&bo->resv->lock);
571
+ dma_resv_unlock(bo->resv);
565572 }
566573
567574 ww_acquire_fini(acquire_ctx);
....@@ -581,15 +588,14 @@
581588 {
582589 int contended_lock = -1;
583590 int i, ret;
584
- struct vc4_bo *bo;
591
+ struct drm_gem_object *bo;
585592
586593 ww_acquire_init(acquire_ctx, &reservation_ww_class);
587594
588595 retry:
589596 if (contended_lock != -1) {
590
- bo = to_vc4_bo(&exec->bo[contended_lock]->base);
591
- ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
592
- acquire_ctx);
597
+ bo = &exec->bo[contended_lock]->base;
598
+ ret = dma_resv_lock_slow_interruptible(bo->resv, acquire_ctx);
593599 if (ret) {
594600 ww_acquire_done(acquire_ctx);
595601 return ret;
....@@ -600,21 +606,21 @@
600606 if (i == contended_lock)
601607 continue;
602608
603
- bo = to_vc4_bo(&exec->bo[i]->base);
609
+ bo = &exec->bo[i]->base;
604610
605
- ret = ww_mutex_lock_interruptible(&bo->resv->lock, acquire_ctx);
611
+ ret = dma_resv_lock_interruptible(bo->resv, acquire_ctx);
606612 if (ret) {
607613 int j;
608614
609615 for (j = 0; j < i; j++) {
610
- bo = to_vc4_bo(&exec->bo[j]->base);
611
- ww_mutex_unlock(&bo->resv->lock);
616
+ bo = &exec->bo[j]->base;
617
+ dma_resv_unlock(bo->resv);
612618 }
613619
614620 if (contended_lock != -1 && contended_lock >= i) {
615
- bo = to_vc4_bo(&exec->bo[contended_lock]->base);
621
+ bo = &exec->bo[contended_lock]->base;
616622
617
- ww_mutex_unlock(&bo->resv->lock);
623
+ dma_resv_unlock(bo->resv);
618624 }
619625
620626 if (ret == -EDEADLK) {
....@@ -633,9 +639,9 @@
633639 * before we commit the CL to the hardware.
634640 */
635641 for (i = 0; i < exec->bo_count; i++) {
636
- bo = to_vc4_bo(&exec->bo[i]->base);
642
+ bo = &exec->bo[i]->base;
637643
638
- ret = reservation_object_reserve_shared(bo->resv);
644
+ ret = dma_resv_reserve_shared(bo->resv, 1);
639645 if (ret) {
640646 vc4_unlock_bo_reservations(dev, exec, acquire_ctx);
641647 return ret;
....@@ -802,7 +808,7 @@
802808 fail_put_bo:
803809 /* Release any reference to acquired objects. */
804810 for (i = 0; i < exec->bo_count && exec->bo[i]; i++)
805
- drm_gem_object_put_unlocked(&exec->bo[i]->base);
811
+ drm_gem_object_put(&exec->bo[i]->base);
806812
807813 fail:
808814 kvfree(handles);
....@@ -815,6 +821,7 @@
815821 vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)
816822 {
817823 struct drm_vc4_submit_cl *args = exec->args;
824
+ struct vc4_dev *vc4 = to_vc4_dev(dev);
818825 void *temp = NULL;
819826 void *bin;
820827 int ret = 0;
....@@ -913,6 +920,12 @@
913920 if (ret)
914921 goto fail;
915922
923
+ if (exec->found_tile_binning_mode_config_packet) {
924
+ ret = vc4_v3d_bin_bo_get(vc4, &exec->bin_bo_used);
925
+ if (ret)
926
+ goto fail;
927
+ }
928
+
916929 /* Block waiting on any previous rendering into the CS's VBO,
917930 * IB, or textures, so that pixels are actually written by the
918931 * time we try to read them.
....@@ -944,7 +957,7 @@
944957 struct vc4_bo *bo = to_vc4_bo(&exec->bo[i]->base);
945958
946959 vc4_bo_dec_usecnt(bo);
947
- drm_gem_object_put_unlocked(&exec->bo[i]->base);
960
+ drm_gem_object_put(&exec->bo[i]->base);
948961 }
949962 kvfree(exec->bo);
950963 }
....@@ -953,7 +966,7 @@
953966 struct vc4_bo *bo = list_first_entry(&exec->unref_list,
954967 struct vc4_bo, unref_head);
955968 list_del(&bo->unref_head);
956
- drm_gem_object_put_unlocked(&bo->base.base);
969
+ drm_gem_object_put(&bo->base.base);
957970 }
958971
959972 /* Free up the allocation of any bin slots we used. */
....@@ -961,15 +974,14 @@
961974 vc4->bin_alloc_used &= ~exec->bin_slots;
962975 spin_unlock_irqrestore(&vc4->job_lock, irqflags);
963976
977
+ /* Release the reference on the binner BO if needed. */
978
+ if (exec->bin_bo_used)
979
+ vc4_v3d_bin_bo_put(vc4);
980
+
964981 /* Release the reference we had on the perf monitor. */
965982 vc4_perfmon_put(exec->perfmon);
966983
967
- mutex_lock(&vc4->power_lock);
968
- if (--vc4->power_refcount == 0) {
969
- pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
970
- pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
971
- }
972
- mutex_unlock(&vc4->power_lock);
984
+ vc4_v3d_pm_put(vc4);
973985
974986 kfree(exec);
975987 }
....@@ -988,7 +1000,7 @@
9881000 list_del(&exec->head);
9891001
9901002 spin_unlock_irqrestore(&vc4->job_lock, irqflags);
991
- vc4_complete_exec(vc4->dev, exec);
1003
+ vc4_complete_exec(&vc4->base, exec);
9921004 spin_lock_irqsave(&vc4->job_lock, irqflags);
9931005 }
9941006
....@@ -1095,7 +1107,7 @@
10951107 ret = vc4_wait_for_seqno_ioctl_helper(dev, bo->seqno,
10961108 &args->timeout_ns);
10971109
1098
- drm_gem_object_put_unlocked(gem_obj);
1110
+ drm_gem_object_put(gem_obj);
10991111 return ret;
11001112 }
11011113
....@@ -1124,6 +1136,11 @@
11241136 struct dma_fence *in_fence;
11251137 int ret = 0;
11261138
1139
+ if (!vc4->v3d) {
1140
+ DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
1141
+ return -ENODEV;
1142
+ }
1143
+
11271144 if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
11281145 VC4_SUBMIT_CL_FIXED_RCL_ORDER |
11291146 VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
....@@ -1143,17 +1160,11 @@
11431160 return -ENOMEM;
11441161 }
11451162
1146
- mutex_lock(&vc4->power_lock);
1147
- if (vc4->power_refcount++ == 0) {
1148
- ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
1149
- if (ret < 0) {
1150
- mutex_unlock(&vc4->power_lock);
1151
- vc4->power_refcount--;
1152
- kfree(exec);
1153
- return ret;
1154
- }
1163
+ ret = vc4_v3d_pm_get(vc4);
1164
+ if (ret) {
1165
+ kfree(exec);
1166
+ return ret;
11551167 }
1156
- mutex_unlock(&vc4->power_lock);
11571168
11581169 exec->args = args;
11591170 INIT_LIST_HEAD(&exec->unref_list);
....@@ -1173,7 +1184,7 @@
11731184
11741185 if (args->in_sync) {
11751186 ret = drm_syncobj_find_fence(file_priv, args->in_sync,
1176
- &in_fence);
1187
+ 0, 0, &in_fence);
11771188 if (ret)
11781189 goto fail;
11791190
....@@ -1247,13 +1258,13 @@
12471258 return 0;
12481259
12491260 fail:
1250
- vc4_complete_exec(vc4->dev, exec);
1261
+ vc4_complete_exec(&vc4->base, exec);
12511262
12521263 return ret;
12531264 }
12541265
1255
-void
1256
-vc4_gem_init(struct drm_device *dev)
1266
+static void vc4_gem_destroy(struct drm_device *dev, void *unused);
1267
+int vc4_gem_init(struct drm_device *dev)
12571268 {
12581269 struct vc4_dev *vc4 = to_vc4_dev(dev);
12591270
....@@ -1274,10 +1285,11 @@
12741285
12751286 INIT_LIST_HEAD(&vc4->purgeable.list);
12761287 mutex_init(&vc4->purgeable.lock);
1288
+
1289
+ return drmm_add_action_or_reset(dev, vc4_gem_destroy, NULL);
12771290 }
12781291
1279
-void
1280
-vc4_gem_destroy(struct drm_device *dev)
1292
+static void vc4_gem_destroy(struct drm_device *dev, void *unused)
12811293 {
12821294 struct vc4_dev *vc4 = to_vc4_dev(dev);
12831295
....@@ -1290,7 +1302,7 @@
12901302 * the overflow allocation registers. Now free the object.
12911303 */
12921304 if (vc4->bin_bo) {
1293
- drm_gem_object_put_unlocked(&vc4->bin_bo->base.base);
1305
+ drm_gem_object_put(&vc4->bin_bo->base.base);
12941306 vc4->bin_bo = NULL;
12951307 }
12961308
....@@ -1371,7 +1383,7 @@
13711383 ret = 0;
13721384
13731385 out_put_gem:
1374
- drm_gem_object_put_unlocked(gem_obj);
1386
+ drm_gem_object_put(gem_obj);
13751387
13761388 return ret;
13771389 }