forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/drm/nouveau/nouveau_sgdma.c
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+// SPDX-License-Identifier: MIT
22 #include <linux/pagemap.h>
33 #include <linux/slab.h>
44
....@@ -14,87 +14,64 @@
1414 struct nouveau_mem *mem;
1515 };
1616
17
-static void
18
-nouveau_sgdma_destroy(struct ttm_tt *ttm)
17
+void
18
+nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
1919 {
2020 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
2121
2222 if (ttm) {
23
+ nouveau_sgdma_unbind(bdev, ttm);
24
+ ttm_tt_destroy_common(bdev, ttm);
2325 ttm_dma_tt_fini(&nvbe->ttm);
2426 kfree(nvbe);
2527 }
2628 }
2729
28
-static int
29
-nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *reg)
30
+int
31
+nouveau_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
3032 {
3133 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
34
+ struct nouveau_drm *drm = nouveau_bdev(bdev);
3235 struct nouveau_mem *mem = nouveau_mem(reg);
3336 int ret;
37
+
38
+ if (nvbe->mem)
39
+ return 0;
3440
3541 ret = nouveau_mem_host(reg, &nvbe->ttm);
3642 if (ret)
3743 return ret;
3844
39
- ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
40
- if (ret) {
41
- nouveau_mem_fini(mem);
42
- return ret;
45
+ if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
46
+ ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
47
+ if (ret) {
48
+ nouveau_mem_fini(mem);
49
+ return ret;
50
+ }
4351 }
4452
4553 nvbe->mem = mem;
4654 return 0;
4755 }
4856
49
-static int
50
-nv04_sgdma_unbind(struct ttm_tt *ttm)
57
+void
58
+nouveau_sgdma_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
5159 {
5260 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
53
- nouveau_mem_fini(nvbe->mem);
54
- return 0;
61
+ if (nvbe->mem) {
62
+ nouveau_mem_fini(nvbe->mem);
63
+ nvbe->mem = NULL;
64
+ }
5565 }
56
-
57
-static struct ttm_backend_func nv04_sgdma_backend = {
58
- .bind = nv04_sgdma_bind,
59
- .unbind = nv04_sgdma_unbind,
60
- .destroy = nouveau_sgdma_destroy
61
-};
62
-
63
-static int
64
-nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *reg)
65
-{
66
- struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
67
- struct nouveau_mem *mem = nouveau_mem(reg);
68
- int ret;
69
-
70
- ret = nouveau_mem_host(reg, &nvbe->ttm);
71
- if (ret)
72
- return ret;
73
-
74
- nvbe->mem = mem;
75
- return 0;
76
-}
77
-
78
-static struct ttm_backend_func nv50_sgdma_backend = {
79
- .bind = nv50_sgdma_bind,
80
- .unbind = nv04_sgdma_unbind,
81
- .destroy = nouveau_sgdma_destroy
82
-};
8366
8467 struct ttm_tt *
8568 nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
8669 {
87
- struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
8870 struct nouveau_sgdma_be *nvbe;
8971
9072 nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
9173 if (!nvbe)
9274 return NULL;
93
-
94
- if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA)
95
- nvbe->ttm.ttm.func = &nv04_sgdma_backend;
96
- else
97
- nvbe->ttm.ttm.func = &nv50_sgdma_backend;
9875
9976 if (ttm_dma_tt_init(&nvbe->ttm, bo, page_flags)) {
10077 kfree(nvbe);