summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTerje Bergstrom <tbergstrom@nvidia.com>2018-01-25 16:35:22 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2018-02-01 16:54:08 -0500
commit9e283f9f40be0d357e90a355eae6d3b183073184 (patch)
treecd120793463ee1d52bb17859a9bc665844bac08e
parent8ca1a765ee066b9f04f39c69d8f3678c06557257 (diff)
gpu: nvgpu: Add tracking of dma_buf_attachment
VM and CDE code assumes that dma_buf_attachment is stored as a pointer in the private dma_buf_drvdata, so it is not tracked. In Linux trees without dma_buf_*_drvdata() support this is not true, so change the code to explicitly track dma_buf_attachment. JIRA NVGPU-4 Change-Id: I692f05a19a6469195d5444a7e5ff6e92f77ae272 Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1648004 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
-rw-r--r--drivers/gpu/nvgpu/common/linux/cde.c9
-rw-r--r--drivers/gpu/nvgpu/common/linux/dmabuf.c6
-rw-r--r--drivers/gpu/nvgpu/common/linux/dmabuf.h4
-rw-r--r--drivers/gpu/nvgpu/common/linux/vm.c17
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/linux/vm.h4
5 files changed, 29 insertions, 11 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/cde.c b/drivers/gpu/nvgpu/common/linux/cde.c
index 040a4e3d..894e776d 100644
--- a/drivers/gpu/nvgpu/common/linux/cde.c
+++ b/drivers/gpu/nvgpu/common/linux/cde.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Color decompression engine support 2 * Color decompression engine support
3 * 3 *
4 * Copyright (c) 2014-2017, NVIDIA Corporation. All rights reserved. 4 * Copyright (c) 2014-2018, NVIDIA Corporation. All rights reserved.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License, 7 * under the terms and conditions of the GNU General Public License,
@@ -984,6 +984,7 @@ __releases(&l->cde_app->mutex)
984 struct gk20a_comptags comptags; 984 struct gk20a_comptags comptags;
985 struct nvgpu_os_buffer os_buf = { 985 struct nvgpu_os_buffer os_buf = {
986 compbits_scatter_buf, 986 compbits_scatter_buf,
987 NULL,
987 dev_from_gk20a(g) 988 dev_from_gk20a(g)
988 }; 989 };
989 u64 mapped_compbits_offset = 0; 990 u64 mapped_compbits_offset = 0;
@@ -999,6 +1000,7 @@ __releases(&l->cde_app->mutex)
999 int err, i; 1000 int err, i;
1000 const s16 compbits_kind = 0; 1001 const s16 compbits_kind = 0;
1001 u32 submit_op; 1002 u32 submit_op;
1003 struct dma_buf_attachment *attachment;
1002 1004
1003 gk20a_dbg(gpu_dbg_cde, "compbits_byte_offset=%llu scatterbuffer_byte_offset=%llu", 1005 gk20a_dbg(gpu_dbg_cde, "compbits_byte_offset=%llu scatterbuffer_byte_offset=%llu",
1004 compbits_byte_offset, scatterbuffer_byte_offset); 1006 compbits_byte_offset, scatterbuffer_byte_offset);
@@ -1093,7 +1095,8 @@ __releases(&l->cde_app->mutex)
1093 1095
1094 gk20a_dbg(gpu_dbg_cde, "surface=0x%p scatterBuffer=0x%p", 1096 gk20a_dbg(gpu_dbg_cde, "surface=0x%p scatterBuffer=0x%p",
1095 surface, scatter_buffer); 1097 surface, scatter_buffer);
1096 sgt = gk20a_mm_pin(dev_from_gk20a(g), compbits_scatter_buf); 1098 sgt = gk20a_mm_pin(dev_from_gk20a(g), compbits_scatter_buf,
1099 &attachment);
1097 if (IS_ERR(sgt)) { 1100 if (IS_ERR(sgt)) {
1098 nvgpu_warn(g, 1101 nvgpu_warn(g,
1099 "mm_pin failed"); 1102 "mm_pin failed");
@@ -1106,7 +1109,7 @@ __releases(&l->cde_app->mutex)
1106 WARN_ON(err); 1109 WARN_ON(err);
1107 1110
1108 gk20a_mm_unpin(dev_from_gk20a(g), compbits_scatter_buf, 1111 gk20a_mm_unpin(dev_from_gk20a(g), compbits_scatter_buf,
1109 sgt); 1112 attachment, sgt);
1110 if (err) 1113 if (err)
1111 goto exit_unmap_surface; 1114 goto exit_unmap_surface;
1112 } 1115 }
diff --git a/drivers/gpu/nvgpu/common/linux/dmabuf.c b/drivers/gpu/nvgpu/common/linux/dmabuf.c
index 580dfcae..129739f0 100644
--- a/drivers/gpu/nvgpu/common/linux/dmabuf.c
+++ b/drivers/gpu/nvgpu/common/linux/dmabuf.c
@@ -83,7 +83,8 @@ enum nvgpu_aperture gk20a_dmabuf_aperture(struct gk20a *g,
83 } 83 }
84} 84}
85 85
86struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf) 86struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf,
87 struct dma_buf_attachment **attachment)
87{ 88{
88 struct gk20a_dmabuf_priv *priv; 89 struct gk20a_dmabuf_priv *priv;
89 90
@@ -111,10 +112,12 @@ struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf)
111 112
112 priv->pin_count++; 113 priv->pin_count++;
113 nvgpu_mutex_release(&priv->lock); 114 nvgpu_mutex_release(&priv->lock);
115 *attachment = priv->attach;
114 return priv->sgt; 116 return priv->sgt;
115} 117}
116 118
117void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf, 119void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf,
120 struct dma_buf_attachment *attachment,
118 struct sg_table *sgt) 121 struct sg_table *sgt)
119{ 122{
120 struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev); 123 struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev);
@@ -125,6 +128,7 @@ void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf,
125 128
126 nvgpu_mutex_acquire(&priv->lock); 129 nvgpu_mutex_acquire(&priv->lock);
127 WARN_ON(priv->sgt != sgt); 130 WARN_ON(priv->sgt != sgt);
131 WARN_ON(priv->attach != attachment);
128 priv->pin_count--; 132 priv->pin_count--;
129 WARN_ON(priv->pin_count < 0); 133 WARN_ON(priv->pin_count < 0);
130 dma_addr = sg_dma_address(priv->sgt->sgl); 134 dma_addr = sg_dma_address(priv->sgt->sgl);
diff --git a/drivers/gpu/nvgpu/common/linux/dmabuf.h b/drivers/gpu/nvgpu/common/linux/dmabuf.h
index d30ff5a5..8399eaaf 100644
--- a/drivers/gpu/nvgpu/common/linux/dmabuf.h
+++ b/drivers/gpu/nvgpu/common/linux/dmabuf.h
@@ -48,8 +48,10 @@ struct gk20a_dmabuf_priv {
48 u64 buffer_id; 48 u64 buffer_id;
49}; 49};
50 50
51struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf); 51struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf,
52 struct dma_buf_attachment **attachment);
52void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf, 53void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf,
54 struct dma_buf_attachment *attachment,
53 struct sg_table *sgt); 55 struct sg_table *sgt);
54 56
55int gk20a_dmabuf_alloc_drvdata(struct dma_buf *dmabuf, struct device *dev); 57int gk20a_dmabuf_alloc_drvdata(struct dma_buf *dmabuf, struct device *dev);
diff --git a/drivers/gpu/nvgpu/common/linux/vm.c b/drivers/gpu/nvgpu/common/linux/vm.c
index 4529a322..e3ca4eda 100644
--- a/drivers/gpu/nvgpu/common/linux/vm.c
+++ b/drivers/gpu/nvgpu/common/linux/vm.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. 2 * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License, 5 * under the terms and conditions of the GNU General Public License,
@@ -150,7 +150,8 @@ struct nvgpu_mapped_buf *nvgpu_vm_find_mapping(struct vm_gk20a *vm,
150 * If we find the mapping here then that means we have mapped it already 150 * If we find the mapping here then that means we have mapped it already
151 * and the prior pin and get must be undone. 151 * and the prior pin and get must be undone.
152 */ 152 */
153 gk20a_mm_unpin(os_buf->dev, os_buf->dmabuf, mapped_buffer->os_priv.sgt); 153 gk20a_mm_unpin(os_buf->dev, os_buf->dmabuf, os_buf->attachment,
154 mapped_buffer->os_priv.sgt);
154 dma_buf_put(os_buf->dmabuf); 155 dma_buf_put(os_buf->dmabuf);
155 156
156 nvgpu_log(g, gpu_dbg_map, 157 nvgpu_log(g, gpu_dbg_map,
@@ -184,21 +185,25 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
184{ 185{
185 struct gk20a *g = gk20a_from_vm(vm); 186 struct gk20a *g = gk20a_from_vm(vm);
186 struct device *dev = dev_from_gk20a(g); 187 struct device *dev = dev_from_gk20a(g);
187 struct nvgpu_os_buffer os_buf = { dmabuf, dev }; 188 struct nvgpu_os_buffer os_buf;
188 struct sg_table *sgt; 189 struct sg_table *sgt;
189 struct nvgpu_sgt *nvgpu_sgt = NULL; 190 struct nvgpu_sgt *nvgpu_sgt = NULL;
190 struct nvgpu_mapped_buf *mapped_buffer = NULL; 191 struct nvgpu_mapped_buf *mapped_buffer = NULL;
192 struct dma_buf_attachment *attachment;
191 u64 map_addr = 0ULL; 193 u64 map_addr = 0ULL;
192 int err = 0; 194 int err = 0;
193 195
194 if (flags & NVGPU_VM_MAP_FIXED_OFFSET) 196 if (flags & NVGPU_VM_MAP_FIXED_OFFSET)
195 map_addr = offset_align; 197 map_addr = offset_align;
196 198
197 sgt = gk20a_mm_pin(dev, dmabuf); 199 sgt = gk20a_mm_pin(dev, dmabuf, &attachment);
198 if (IS_ERR(sgt)) { 200 if (IS_ERR(sgt)) {
199 nvgpu_warn(g, "Failed to pin dma_buf!"); 201 nvgpu_warn(g, "Failed to pin dma_buf!");
200 return PTR_ERR(sgt); 202 return PTR_ERR(sgt);
201 } 203 }
204 os_buf.dmabuf = dmabuf;
205 os_buf.attachment = attachment;
206 os_buf.dev = dev;
202 207
203 if (gk20a_dmabuf_aperture(g, dmabuf) == APERTURE_INVALID) { 208 if (gk20a_dmabuf_aperture(g, dmabuf) == APERTURE_INVALID) {
204 err = -EINVAL; 209 err = -EINVAL;
@@ -232,13 +237,14 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm,
232 } 237 }
233 238
234 mapped_buffer->os_priv.dmabuf = dmabuf; 239 mapped_buffer->os_priv.dmabuf = dmabuf;
240 mapped_buffer->os_priv.attachment = attachment;
235 mapped_buffer->os_priv.sgt = sgt; 241 mapped_buffer->os_priv.sgt = sgt;
236 242
237 *gpu_va = mapped_buffer->addr; 243 *gpu_va = mapped_buffer->addr;
238 return 0; 244 return 0;
239 245
240clean_up: 246clean_up:
241 gk20a_mm_unpin(dev, dmabuf, sgt); 247 gk20a_mm_unpin(dev, dmabuf, attachment, sgt);
242 248
243 return err; 249 return err;
244} 250}
@@ -316,6 +322,7 @@ void nvgpu_vm_unmap_system(struct nvgpu_mapped_buf *mapped_buffer)
316 struct vm_gk20a *vm = mapped_buffer->vm; 322 struct vm_gk20a *vm = mapped_buffer->vm;
317 323
318 gk20a_mm_unpin(dev_from_vm(vm), mapped_buffer->os_priv.dmabuf, 324 gk20a_mm_unpin(dev_from_vm(vm), mapped_buffer->os_priv.dmabuf,
325 mapped_buffer->os_priv.attachment,
319 mapped_buffer->os_priv.sgt); 326 mapped_buffer->os_priv.sgt);
320 327
321 dma_buf_put(mapped_buffer->os_priv.dmabuf); 328 dma_buf_put(mapped_buffer->os_priv.dmabuf);
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h
index d9f082af..97b8334b 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. 2 * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License, 5 * under the terms and conditions of the GNU General Public License,
@@ -41,11 +41,13 @@ struct nvgpu_vm_area;
41 41
42struct nvgpu_os_buffer { 42struct nvgpu_os_buffer {
43 struct dma_buf *dmabuf; 43 struct dma_buf *dmabuf;
44 struct dma_buf_attachment *attachment;
44 struct device *dev; 45 struct device *dev;
45}; 46};
46 47
47struct nvgpu_mapped_buf_priv { 48struct nvgpu_mapped_buf_priv {
48 struct dma_buf *dmabuf; 49 struct dma_buf *dmabuf;
50 struct dma_buf_attachment *attachment;
49 struct sg_table *sgt; 51 struct sg_table *sgt;
50}; 52};
51 53