summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/vidmem.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-08-17 19:16:49 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-10-13 18:19:28 -0400
commit59e4089278bd052b440293356605ce524e4944db (patch)
treee9c48f09561f913db919bf8bbd4b39205c7bf606 /drivers/gpu/nvgpu/common/linux/vidmem.c
parent88d5f6b4154d6803ecf3b0dee7208f9f1f10a793 (diff)
gpu: nvgpu: Separate vidmem alloc from Linux code
Split the core vidmem allocation from the Linux component of vidmem allocation. The core vidmem allocation allocates the nvgpu_mem struct that defines the vidmem buffer in the core MM code. The Linux code now allocates some Linux specific stuff (dma_buf, etc) and also allocates the core vidmem buf. JIRA NVGPU-30 JIRA NVGPU-138 Change-Id: I88e87e0abd5ec714610eacc6eac17e148bcee3ce Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1540708 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/vidmem.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/vidmem.c80
1 files changed, 32 insertions, 48 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/vidmem.c b/drivers/gpu/nvgpu/common/linux/vidmem.c
index 5d47c858..ea8e552f 100644
--- a/drivers/gpu/nvgpu/common/linux/vidmem.c
+++ b/drivers/gpu/nvgpu/common/linux/vidmem.c
@@ -25,6 +25,7 @@
25#include <nvgpu/page_allocator.h> 25#include <nvgpu/page_allocator.h>
26 26
27#include <nvgpu/linux/dma.h> 27#include <nvgpu/linux/dma.h>
28#include <nvgpu/linux/vidmem.h>
28 29
29#include "gk20a/gk20a.h" 30#include "gk20a/gk20a.h"
30#include "gk20a/mm_gk20a.h" 31#include "gk20a/mm_gk20a.h"
@@ -73,14 +74,16 @@ static void gk20a_vidbuf_unmap_dma_buf(struct dma_buf_attachment *attach,
73static void gk20a_vidbuf_release(struct dma_buf *dmabuf) 74static void gk20a_vidbuf_release(struct dma_buf *dmabuf)
74{ 75{
75 struct nvgpu_vidmem_buf *buf = dmabuf->priv; 76 struct nvgpu_vidmem_buf *buf = dmabuf->priv;
77 struct nvgpu_vidmem_linux *linux_buf = buf->priv;
78 struct gk20a *g = buf->g;
76 79
77 gk20a_dbg_fn(""); 80 gk20a_dbg_fn("");
78 81
79 if (buf->dmabuf_priv) 82 if (linux_buf && linux_buf->dmabuf_priv_delete)
80 buf->dmabuf_priv_delete(buf->dmabuf_priv); 83 linux_buf->dmabuf_priv_delete(linux_buf->dmabuf_priv);
81 84
82 nvgpu_dma_free(buf->g, buf->mem); 85 nvgpu_kfree(g, linux_buf);
83 nvgpu_kfree(buf->g, buf); 86 nvgpu_vidmem_buf_free(g, buf);
84} 87}
85 88
86static void *gk20a_vidbuf_kmap(struct dma_buf *dmabuf, unsigned long page_num) 89static void *gk20a_vidbuf_kmap(struct dma_buf *dmabuf, unsigned long page_num)
@@ -105,9 +108,10 @@ static int gk20a_vidbuf_set_private(struct dma_buf *dmabuf,
105 struct device *dev, void *priv, void (*delete)(void *priv)) 108 struct device *dev, void *priv, void (*delete)(void *priv))
106{ 109{
107 struct nvgpu_vidmem_buf *buf = dmabuf->priv; 110 struct nvgpu_vidmem_buf *buf = dmabuf->priv;
111 struct nvgpu_vidmem_linux *linux_buf = buf->priv;
108 112
109 buf->dmabuf_priv = priv; 113 linux_buf->dmabuf_priv = priv;
110 buf->dmabuf_priv_delete = delete; 114 linux_buf->dmabuf_priv_delete = delete;
111 115
112 return 0; 116 return 0;
113} 117}
@@ -116,8 +120,9 @@ static void *gk20a_vidbuf_get_private(struct dma_buf *dmabuf,
116 struct device *dev) 120 struct device *dev)
117{ 121{
118 struct nvgpu_vidmem_buf *buf = dmabuf->priv; 122 struct nvgpu_vidmem_buf *buf = dmabuf->priv;
123 struct nvgpu_vidmem_linux *linux_buf = buf->priv;
119 124
120 return buf->dmabuf_priv; 125 return linux_buf->dmabuf_priv;
121} 126}
122 127
123static const struct dma_buf_ops gk20a_vidbuf_ops = { 128static const struct dma_buf_ops gk20a_vidbuf_ops = {
@@ -153,66 +158,45 @@ struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf)
153 return buf->g; 158 return buf->g;
154} 159}
155 160
156int nvgpu_vidmem_buf_alloc(struct gk20a *g, size_t bytes) 161int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes)
157{ 162{
158 struct nvgpu_vidmem_buf *buf; 163 struct nvgpu_vidmem_buf *buf;
159 int err = 0, fd; 164 struct nvgpu_vidmem_linux *priv;
165 int err, fd;
160 166
161 gk20a_dbg_fn(""); 167 priv = nvgpu_kzalloc(g, sizeof(*priv));
162 168 if (!priv)
163 buf = nvgpu_kzalloc(g, sizeof(*buf));
164 if (!buf)
165 return -ENOMEM; 169 return -ENOMEM;
166 170
167 buf->g = g; 171 buf = nvgpu_vidmem_user_alloc(g, bytes);
168 172 if (!buf) {
169 if (!g->mm.vidmem.cleared) { 173 err = -ENOMEM;
170 nvgpu_mutex_acquire(&g->mm.vidmem.first_clear_mutex); 174 goto fail;
171 if (!g->mm.vidmem.cleared) {
172 err = nvgpu_vidmem_clear_all(g);
173 if (err) {
174 nvgpu_err(g,
175 "failed to clear whole vidmem");
176 goto err_kfree;
177 }
178 }
179 nvgpu_mutex_release(&g->mm.vidmem.first_clear_mutex);
180 } 175 }
181 176
182 buf->mem = nvgpu_kzalloc(g, sizeof(struct nvgpu_mem)); 177 priv->dmabuf = gk20a_vidbuf_export(buf);
183 if (!buf->mem) 178 if (IS_ERR(priv->dmabuf)) {
184 goto err_kfree; 179 err = PTR_ERR(priv->dmabuf);
185 180 goto fail;
186 buf->mem->mem_flags |= NVGPU_MEM_FLAG_USER_MEM;
187
188 err = nvgpu_dma_alloc_vid(g, bytes, buf->mem);
189 if (err)
190 goto err_memfree;
191
192 buf->dmabuf = gk20a_vidbuf_export(buf);
193 if (IS_ERR(buf->dmabuf)) {
194 err = PTR_ERR(buf->dmabuf);
195 goto err_bfree;
196 } 181 }
197 182
183 buf->priv = priv;
184
198 fd = tegra_alloc_fd(current->files, 1024, O_RDWR); 185 fd = tegra_alloc_fd(current->files, 1024, O_RDWR);
199 if (fd < 0) { 186 if (fd < 0) {
200 /* ->release frees what we have done */ 187 /* ->release frees what we have done */
201 dma_buf_put(buf->dmabuf); 188 dma_buf_put(priv->dmabuf);
202 return fd; 189 return fd;
203 } 190 }
204 191
205 /* fclose() on this drops one ref, freeing the dma buf */ 192 /* fclose() on this drops one ref, freeing the dma buf */
206 fd_install(fd, buf->dmabuf->file); 193 fd_install(fd, priv->dmabuf->file);
207 194
208 return fd; 195 return fd;
209 196
210err_bfree: 197fail:
211 nvgpu_dma_free(g, buf->mem); 198 nvgpu_kfree(g, priv);
212err_memfree: 199 nvgpu_vidmem_buf_free(g, buf);
213 nvgpu_kfree(g, buf->mem);
214err_kfree:
215 nvgpu_kfree(g, buf);
216 return err; 200 return err;
217} 201}
218 202