forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c
....@@ -3,26 +3,25 @@
33 * Copyright (C) 2017-2018 Etnaviv Project
44 */
55
6
+#include <linux/dma-mapping.h>
7
+
68 #include <drm/drm_mm.h>
79
810 #include "etnaviv_cmdbuf.h"
11
+#include "etnaviv_gem.h"
912 #include "etnaviv_gpu.h"
1013 #include "etnaviv_mmu.h"
1114 #include "etnaviv_perfmon.h"
1215
13
-#define SUBALLOC_SIZE SZ_256K
16
+#define SUBALLOC_SIZE SZ_512K
1417 #define SUBALLOC_GRANULE SZ_4K
1518 #define SUBALLOC_GRANULES (SUBALLOC_SIZE / SUBALLOC_GRANULE)
1619
1720 struct etnaviv_cmdbuf_suballoc {
1821 /* suballocated dma buffer properties */
19
- struct etnaviv_gpu *gpu;
22
+ struct device *dev;
2023 void *vaddr;
2124 dma_addr_t paddr;
22
-
23
- /* GPU mapping */
24
- u32 iova;
25
- struct drm_mm_node vram_node; /* only used on MMUv2 */
2625
2726 /* allocation management */
2827 struct mutex lock;
....@@ -32,7 +31,7 @@
3231 };
3332
3433 struct etnaviv_cmdbuf_suballoc *
35
-etnaviv_cmdbuf_suballoc_new(struct etnaviv_gpu * gpu)
34
+etnaviv_cmdbuf_suballoc_new(struct device *dev)
3635 {
3736 struct etnaviv_cmdbuf_suballoc *suballoc;
3837 int ret;
....@@ -41,36 +40,44 @@
4140 if (!suballoc)
4241 return ERR_PTR(-ENOMEM);
4342
44
- suballoc->gpu = gpu;
43
+ suballoc->dev = dev;
4544 mutex_init(&suballoc->lock);
4645 init_waitqueue_head(&suballoc->free_event);
4746
48
- suballoc->vaddr = dma_alloc_wc(gpu->dev, SUBALLOC_SIZE,
47
+ BUILD_BUG_ON(ETNAVIV_SOFTPIN_START_ADDRESS < SUBALLOC_SIZE);
48
+ suballoc->vaddr = dma_alloc_wc(dev, SUBALLOC_SIZE,
4949 &suballoc->paddr, GFP_KERNEL);
50
- if (!suballoc->vaddr)
50
+ if (!suballoc->vaddr) {
51
+ ret = -ENOMEM;
5152 goto free_suballoc;
52
-
53
- ret = etnaviv_iommu_get_suballoc_va(gpu, suballoc->paddr,
54
- &suballoc->vram_node, SUBALLOC_SIZE,
55
- &suballoc->iova);
56
- if (ret)
57
- goto free_dma;
53
+ }
5854
5955 return suballoc;
6056
61
-free_dma:
62
- dma_free_wc(gpu->dev, SUBALLOC_SIZE, suballoc->vaddr, suballoc->paddr);
6357 free_suballoc:
6458 kfree(suballoc);
6559
66
- return NULL;
60
+ return ERR_PTR(ret);
61
+}
62
+
63
+int etnaviv_cmdbuf_suballoc_map(struct etnaviv_cmdbuf_suballoc *suballoc,
64
+ struct etnaviv_iommu_context *context,
65
+ struct etnaviv_vram_mapping *mapping,
66
+ u32 memory_base)
67
+{
68
+ return etnaviv_iommu_get_suballoc_va(context, mapping, memory_base,
69
+ suballoc->paddr, SUBALLOC_SIZE);
70
+}
71
+
72
+void etnaviv_cmdbuf_suballoc_unmap(struct etnaviv_iommu_context *context,
73
+ struct etnaviv_vram_mapping *mapping)
74
+{
75
+ etnaviv_iommu_put_suballoc_va(context, mapping);
6776 }
6877
6978 void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc)
7079 {
71
- etnaviv_iommu_put_suballoc_va(suballoc->gpu, &suballoc->vram_node,
72
- SUBALLOC_SIZE, suballoc->iova);
73
- dma_free_wc(suballoc->gpu->dev, SUBALLOC_SIZE, suballoc->vaddr,
80
+ dma_free_wc(suballoc->dev, SUBALLOC_SIZE, suballoc->vaddr,
7481 suballoc->paddr);
7582 kfree(suballoc);
7683 }
....@@ -95,7 +102,7 @@
95102 suballoc->free_space,
96103 msecs_to_jiffies(10 * 1000));
97104 if (!ret) {
98
- dev_err(suballoc->gpu->dev,
105
+ dev_err(suballoc->dev,
99106 "Timeout waiting for cmdbuf space\n");
100107 return -ETIMEDOUT;
101108 }
....@@ -123,9 +130,10 @@
123130 wake_up_all(&suballoc->free_event);
124131 }
125132
126
-u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf)
133
+u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf,
134
+ struct etnaviv_vram_mapping *mapping)
127135 {
128
- return buf->suballoc->iova + buf->suballoc_offset;
136
+ return mapping->iova + buf->suballoc_offset;
129137 }
130138
131139 dma_addr_t etnaviv_cmdbuf_get_pa(struct etnaviv_cmdbuf *buf)