aboutsummaryrefslogtreecommitdiffstats
path: root/meta-v1000/recipes-kernel/linux/linux-yocto-4.14.71/1212-drm-amdgpu-kfd2kgd-Use-dma_buf-instead-of-dma_buf_fd.patch
blob: 82cc0aec1495846251891e80913e8b6ad5e1e0f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
From d0e8b610532dd2875f1f21aec8f3401e7079cf32 Mon Sep 17 00:00:00 2001
From: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Date: Tue, 29 Nov 2016 17:45:17 -0500
Subject: [PATCH 1212/4131] drm/amdgpu: kfd2kgd: Use dma_buf instead of
 dma_buf_fd

For kfd2kgd import_dmabuf and export_dmabuf interfaces use struct
dma_buf* instead of dma_buf_fd. This avoids taking unncessary references
to dma_buf_fd.

Change-Id: Ib7718e0bf0f7950ca8157d4353c32ff6baad86fa
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_ipc.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_ipc.c b/drivers/gpu/drm/amd/amdkfd/kfd_ipc.c
index edd2d43..5391f8a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_ipc.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_ipc.c
@@ -185,7 +185,7 @@ int kfd_ipc_init(void)
 
 static int kfd_import_dmabuf_create_kfd_bo(struct kfd_dev *dev,
 			  struct kfd_process *p,
-			  uint32_t gpu_id, int dmabuf_fd,
+			  uint32_t gpu_id, struct dma_buf *dmabuf,
 			  uint64_t va_addr, uint64_t *handle,
 			  uint64_t *mmap_offset,
 			  struct kfd_ipc_obj *ipc_obj)
@@ -210,7 +210,7 @@ static int kfd_import_dmabuf_create_kfd_bo(struct kfd_dev *dev,
 	if (IS_ERR(pdd) < 0)
 		return PTR_ERR(pdd);
 
-	r = dev->kfd2kgd->import_dmabuf(dev->kgd, dmabuf_fd,
+	r = dev->kfd2kgd->import_dmabuf(dev->kgd, dmabuf,
 					va_addr, pdd->vm,
 					(struct kgd_mem **)&mem, &size,
 					mmap_offset);
@@ -243,9 +243,17 @@ int kfd_ipc_import_dmabuf(struct kfd_dev *dev,
 					   uint64_t va_addr, uint64_t *handle,
 					   uint64_t *mmap_offset)
 {
-	return kfd_import_dmabuf_create_kfd_bo(dev, p, gpu_id, dmabuf_fd,
-					       va_addr, handle, mmap_offset,
-					       NULL);
+	int r;
+	struct dma_buf *dmabuf = dma_buf_get(dmabuf_fd);
+
+	if (dmabuf == NULL)
+		return -EINVAL;
+
+	r = kfd_import_dmabuf_create_kfd_bo(dev, p, gpu_id, dmabuf,
+					    va_addr, handle, mmap_offset,
+					    NULL);
+	dma_buf_put(dmabuf);
+	return r;
 }
 
 int kfd_ipc_import_handle(struct kfd_dev *dev, struct kfd_process *p,
@@ -254,7 +262,6 @@ int kfd_ipc_import_handle(struct kfd_dev *dev, struct kfd_process *p,
 			  uint64_t *mmap_offset)
 {
 	int r;
-	int dmabuf_fd;
 	struct kfd_ipc_obj *found;
 
 	found = assoc_array_find(&ipc_handles,
@@ -266,8 +273,7 @@ int kfd_ipc_import_handle(struct kfd_dev *dev, struct kfd_process *p,
 
 	pr_debug("ipc: found ipc_dma_buf: %p\n", found->data);
 
-	dmabuf_fd = dma_buf_fd(found->data, 0);
-	r = kfd_import_dmabuf_create_kfd_bo(dev, p, gpu_id, dmabuf_fd,
+	r = kfd_import_dmabuf_create_kfd_bo(dev, p, gpu_id, found->data,
 					    va_addr, handle, mmap_offset,
 					    found);
 	if (r)
@@ -286,7 +292,7 @@ int kfd_ipc_export_as_handle(struct kfd_dev *dev, struct kfd_process *p,
 	struct kfd_process_device *pdd = NULL;
 	struct kfd_ipc_obj *obj;
 	struct kfd_bo *kfd_bo = NULL;
-	int dmabuf_fd;
+	struct dma_buf *dmabuf;
 	int r;
 
 	if (!dev || !ipc_handle)
@@ -317,11 +323,11 @@ int kfd_ipc_export_as_handle(struct kfd_dev *dev, struct kfd_process *p,
 
 	r = dev->kfd2kgd->export_dmabuf(dev->kgd, pdd->vm,
 					(struct kgd_mem *)kfd_bo->mem,
-					&dmabuf_fd);
+					&dmabuf);
 	if (r)
 		goto err;
 
-	r = ipc_store_insert(dma_buf_get(dmabuf_fd), ipc_handle, &obj);
+	r = ipc_store_insert(dmabuf, ipc_handle, &obj);
 	if (r)
 		goto err;
 
-- 
2.7.4