diff options
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c | 8 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/vidmem.c | 80 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/vm.c | 1 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/mm/vidmem.c | 80 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c | 3 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h | 60 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/vidmem.h | 70 |
7 files changed, 221 insertions, 81 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c index 7180256a..30988462 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c | |||
@@ -26,6 +26,9 @@ | |||
26 | #include <nvgpu/bug.h> | 26 | #include <nvgpu/bug.h> |
27 | #include <nvgpu/bus.h> | 27 | #include <nvgpu/bus.h> |
28 | #include <nvgpu/vidmem.h> | 28 | #include <nvgpu/vidmem.h> |
29 | #include <nvgpu/log.h> | ||
30 | |||
31 | #include <nvgpu/linux/vidmem.h> | ||
29 | 32 | ||
30 | #include "ioctl_ctrl.h" | 33 | #include "ioctl_ctrl.h" |
31 | #include "ioctl_tsg.h" | 34 | #include "ioctl_tsg.h" |
@@ -33,9 +36,8 @@ | |||
33 | #include "gk20a/gk20a.h" | 36 | #include "gk20a/gk20a.h" |
34 | #include "gk20a/platform_gk20a.h" | 37 | #include "gk20a/platform_gk20a.h" |
35 | #include "gk20a/fence_gk20a.h" | 38 | #include "gk20a/fence_gk20a.h" |
36 | #include "os_linux.h" | ||
37 | 39 | ||
38 | #include <nvgpu/log.h> | 40 | #include "os_linux.h" |
39 | 41 | ||
40 | #define HZ_TO_MHZ(a) ((a > 0xF414F9CD7ULL) ? 0xffff : (a >> 32) ? \ | 42 | #define HZ_TO_MHZ(a) ((a > 0xF414F9CD7ULL) ? 0xffff : (a >> 32) ? \ |
41 | (u32) ((a * 0x10C8ULL) >> 32) : (u16) ((u32) a/MHZ)) | 43 | (u32) ((a * 0x10C8ULL) >> 32) : (u16) ((u32) a/MHZ)) |
@@ -693,7 +695,7 @@ static int nvgpu_gpu_alloc_vidmem(struct gk20a *g, | |||
693 | return -EINVAL; | 695 | return -EINVAL; |
694 | } | 696 | } |
695 | 697 | ||
696 | fd = nvgpu_vidmem_buf_alloc(g, args->in.size); | 698 | fd = nvgpu_vidmem_export_linux(g, args->in.size); |
697 | if (fd < 0) | 699 | if (fd < 0) |
698 | return fd; | 700 | return fd; |
699 | 701 | ||
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, | |||
73 | static void gk20a_vidbuf_release(struct dma_buf *dmabuf) | 74 | static 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 | ||
86 | static void *gk20a_vidbuf_kmap(struct dma_buf *dmabuf, unsigned long page_num) | 89 | static 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 | ||
123 | static const struct dma_buf_ops gk20a_vidbuf_ops = { | 128 | static 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 | ||
156 | int nvgpu_vidmem_buf_alloc(struct gk20a *g, size_t bytes) | 161 | int 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 | ||
210 | err_bfree: | 197 | fail: |
211 | nvgpu_dma_free(g, buf->mem); | 198 | nvgpu_kfree(g, priv); |
212 | err_memfree: | 199 | nvgpu_vidmem_buf_free(g, buf); |
213 | nvgpu_kfree(g, buf->mem); | ||
214 | err_kfree: | ||
215 | nvgpu_kfree(g, buf); | ||
216 | return err; | 200 | return err; |
217 | } | 201 | } |
218 | 202 | ||
diff --git a/drivers/gpu/nvgpu/common/linux/vm.c b/drivers/gpu/nvgpu/common/linux/vm.c index d0f87148..45058321 100644 --- a/drivers/gpu/nvgpu/common/linux/vm.c +++ b/drivers/gpu/nvgpu/common/linux/vm.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <nvgpu/vidmem.h> | 26 | #include <nvgpu/vidmem.h> |
27 | #include <nvgpu/enabled.h> | 27 | #include <nvgpu/enabled.h> |
28 | 28 | ||
29 | #include <nvgpu/linux/vidmem.h> | ||
29 | #include <nvgpu/linux/nvgpu_mem.h> | 30 | #include <nvgpu/linux/nvgpu_mem.h> |
30 | 31 | ||
31 | #include "gk20a/gk20a.h" | 32 | #include "gk20a/gk20a.h" |
diff --git a/drivers/gpu/nvgpu/common/mm/vidmem.c b/drivers/gpu/nvgpu/common/mm/vidmem.c index c95cedec..18f46c03 100644 --- a/drivers/gpu/nvgpu/common/mm/vidmem.c +++ b/drivers/gpu/nvgpu/common/mm/vidmem.c | |||
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | #include <linux/scatterlist.h> | 23 | #include <linux/scatterlist.h> |
24 | 24 | ||
25 | #include <nvgpu/dma.h> | ||
25 | #include <nvgpu/vidmem.h> | 26 | #include <nvgpu/vidmem.h> |
26 | #include <nvgpu/page_allocator.h> | 27 | #include <nvgpu/page_allocator.h> |
27 | 28 | ||
@@ -34,7 +35,7 @@ void nvgpu_vidmem_destroy(struct gk20a *g) | |||
34 | nvgpu_alloc_destroy(&g->mm.vidmem.allocator); | 35 | nvgpu_alloc_destroy(&g->mm.vidmem.allocator); |
35 | } | 36 | } |
36 | 37 | ||
37 | int nvgpu_vidmem_clear_all(struct gk20a *g) | 38 | static int __nvgpu_vidmem_do_clear_all(struct gk20a *g) |
38 | { | 39 | { |
39 | struct mm_gk20a *mm = &g->mm; | 40 | struct mm_gk20a *mm = &g->mm; |
40 | struct gk20a_fence *gk20a_fence_out = NULL; | 41 | struct gk20a_fence *gk20a_fence_out = NULL; |
@@ -257,3 +258,80 @@ struct nvgpu_mem *nvgpu_vidmem_get_pending_alloc(struct mm_gk20a *mm) | |||
257 | 258 | ||
258 | return mem; | 259 | return mem; |
259 | } | 260 | } |
261 | |||
262 | static int nvgpu_vidmem_clear_all(struct gk20a *g) | ||
263 | { | ||
264 | int err; | ||
265 | |||
266 | if (g->mm.vidmem.cleared) | ||
267 | return 0; | ||
268 | |||
269 | nvgpu_mutex_acquire(&g->mm.vidmem.first_clear_mutex); | ||
270 | if (!g->mm.vidmem.cleared) { | ||
271 | err = __nvgpu_vidmem_do_clear_all(g); | ||
272 | if (err) { | ||
273 | nvgpu_mutex_release(&g->mm.vidmem.first_clear_mutex); | ||
274 | nvgpu_err(g, "failed to clear whole vidmem"); | ||
275 | return err; | ||
276 | } | ||
277 | } | ||
278 | nvgpu_mutex_release(&g->mm.vidmem.first_clear_mutex); | ||
279 | |||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | struct nvgpu_vidmem_buf *nvgpu_vidmem_user_alloc(struct gk20a *g, size_t bytes) | ||
284 | { | ||
285 | struct nvgpu_vidmem_buf *buf; | ||
286 | int err; | ||
287 | |||
288 | err = nvgpu_vidmem_clear_all(g); | ||
289 | if (err) | ||
290 | return NULL; | ||
291 | |||
292 | buf = nvgpu_kzalloc(g, sizeof(*buf)); | ||
293 | if (!buf) | ||
294 | return NULL; | ||
295 | |||
296 | buf->g = g; | ||
297 | buf->mem = nvgpu_kzalloc(g, sizeof(*buf->mem)); | ||
298 | if (!buf->mem) | ||
299 | goto fail; | ||
300 | |||
301 | err = nvgpu_dma_alloc_vid(g, bytes, buf->mem); | ||
302 | if (err) | ||
303 | goto fail; | ||
304 | |||
305 | /* | ||
306 | * Alerts the DMA API that when we free this vidmem buf we have to | ||
307 | * clear it to avoid leaking data to userspace. | ||
308 | */ | ||
309 | buf->mem->mem_flags |= NVGPU_MEM_FLAG_USER_MEM; | ||
310 | |||
311 | return buf; | ||
312 | |||
313 | fail: | ||
314 | /* buf will never be NULL here. */ | ||
315 | nvgpu_kfree(g, buf->mem); | ||
316 | nvgpu_kfree(g, buf); | ||
317 | return NULL; | ||
318 | } | ||
319 | |||
320 | void nvgpu_vidmem_buf_free(struct gk20a *g, struct nvgpu_vidmem_buf *buf) | ||
321 | { | ||
322 | /* | ||
323 | * In some error paths it's convenient to be able to "free" a NULL buf. | ||
324 | */ | ||
325 | if (!buf) | ||
326 | return; | ||
327 | |||
328 | nvgpu_dma_free(g, buf->mem); | ||
329 | |||
330 | /* | ||
331 | * We don't free buf->mem here. This is handled by nvgpu_dma_free()! | ||
332 | * Since these buffers are cleared in the background the nvgpu_mem | ||
333 | * struct must live on through that. We transfer ownership here to the | ||
334 | * DMA API and let the DMA API free the buffer. | ||
335 | */ | ||
336 | nvgpu_kfree(g, buf); | ||
337 | } | ||
diff --git a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c index 83bd0156..c2885807 100644 --- a/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/dbg_gpu_gk20a.c | |||
@@ -33,7 +33,8 @@ | |||
33 | #include <nvgpu/log.h> | 33 | #include <nvgpu/log.h> |
34 | #include <nvgpu/vm.h> | 34 | #include <nvgpu/vm.h> |
35 | #include <nvgpu/atomic.h> | 35 | #include <nvgpu/atomic.h> |
36 | #include <nvgpu/vidmem.h> | 36 | |
37 | #include <nvgpu/linux/vidmem.h> | ||
37 | 38 | ||
38 | #include "gk20a.h" | 39 | #include "gk20a.h" |
39 | #include "gk20a/platform_gk20a.h" | 40 | #include "gk20a/platform_gk20a.h" |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h b/drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h new file mode 100644 index 00000000..76bbb05b --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
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, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #ifndef __NVGPU_LINUX_VIDMEM_H__ | ||
18 | #define __NVGPU_LINUX_VIDMEM_H__ | ||
19 | |||
20 | #include <nvgpu/types.h> | ||
21 | |||
22 | struct dma_buf; | ||
23 | |||
24 | struct gk20a; | ||
25 | |||
26 | #ifdef CONFIG_GK20A_VIDMEM | ||
27 | struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf); | ||
28 | int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes); | ||
29 | |||
30 | int nvgpu_vidmem_buf_access_memory(struct gk20a *g, struct dma_buf *dmabuf, | ||
31 | void *buffer, u64 offset, u64 size, u32 cmd); | ||
32 | |||
33 | #else /* !CONFIG_GK20A_VIDMEM */ | ||
34 | static inline struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf) | ||
35 | { | ||
36 | return NULL; | ||
37 | } | ||
38 | |||
39 | static inline int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes) | ||
40 | { | ||
41 | return -ENOSYS; | ||
42 | } | ||
43 | |||
44 | static inline int nvgpu_vidmem_buf_access_memory(struct gk20a *g, | ||
45 | struct dma_buf *dmabuf, | ||
46 | void *buffer, u64 offset, | ||
47 | u64 size, u32 cmd) | ||
48 | { | ||
49 | return -ENOSYS; | ||
50 | } | ||
51 | |||
52 | #endif | ||
53 | |||
54 | struct nvgpu_vidmem_linux { | ||
55 | struct dma_buf *dmabuf; | ||
56 | void *dmabuf_priv; | ||
57 | void (*dmabuf_priv_delete)(void *); | ||
58 | }; | ||
59 | |||
60 | #endif | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/vidmem.h b/drivers/gpu/nvgpu/include/nvgpu/vidmem.h index 1b250f90..b89c710d 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/vidmem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/vidmem.h | |||
@@ -25,9 +25,9 @@ | |||
25 | 25 | ||
26 | #include <nvgpu/types.h> | 26 | #include <nvgpu/types.h> |
27 | #include <nvgpu/errno.h> | 27 | #include <nvgpu/errno.h> |
28 | #include <nvgpu/nvgpu_mem.h> | ||
28 | 29 | ||
29 | struct scatterlist; | 30 | struct scatterlist; |
30 | struct dma_buf; | ||
31 | struct work_struct; | 31 | struct work_struct; |
32 | 32 | ||
33 | struct gk20a; | 33 | struct gk20a; |
@@ -35,37 +35,58 @@ struct mm_gk20a; | |||
35 | struct nvgpu_mem; | 35 | struct nvgpu_mem; |
36 | 36 | ||
37 | struct nvgpu_vidmem_buf { | 37 | struct nvgpu_vidmem_buf { |
38 | struct gk20a *g; | 38 | /* |
39 | struct nvgpu_mem *mem; | 39 | * Must be a pointer since control of this mem is passed over to the |
40 | struct dma_buf *dmabuf; | 40 | * vidmem background clearing thread when the vidmem buf is freed. |
41 | void *dmabuf_priv; | 41 | */ |
42 | void (*dmabuf_priv_delete)(void *); | 42 | struct nvgpu_mem *mem; |
43 | |||
44 | struct gk20a *g; | ||
45 | |||
46 | /* | ||
47 | * Filled in by each OS - this holds the necessary data to export this | ||
48 | * buffer to userspace. This will eventually be replaced by a struct | ||
49 | * which shall be defined in the OS specific vidmem.h header file. | ||
50 | */ | ||
51 | void *priv; | ||
43 | }; | 52 | }; |
44 | 53 | ||
45 | #if defined(CONFIG_GK20A_VIDMEM) | 54 | #if defined(CONFIG_GK20A_VIDMEM) |
46 | 55 | ||
56 | /** | ||
57 | * nvgpu_vidmem_user_alloc - Allocates a vidmem buffer for userspace | ||
58 | * | ||
59 | * @g - The GPU. | ||
60 | * @bytes - Size of the buffer in bytes. | ||
61 | * | ||
62 | * Allocate a generic (OS agnostic) vidmem buffer. This does not allocate the OS | ||
63 | * specific interfacing for userspace sharing. Instead is is expected that the | ||
64 | * OS specific code will allocate that OS specific data and add it to this | ||
65 | * buffer. | ||
66 | * | ||
67 | * The buffer allocated here is intended to use used by userspace, hence the | ||
68 | * extra struct over nvgpu_mem. If a vidmem buffer is needed by the kernel | ||
69 | * driver only then a simple nvgpu_dma_alloc_vid() or the like is sufficient. | ||
70 | * | ||
71 | * Returns a pointer to a vidmem buffer on success, 0 otherwise. | ||
72 | */ | ||
73 | struct nvgpu_vidmem_buf *nvgpu_vidmem_user_alloc(struct gk20a *g, size_t bytes); | ||
74 | |||
75 | void nvgpu_vidmem_buf_free(struct gk20a *g, struct nvgpu_vidmem_buf *buf); | ||
76 | |||
47 | struct nvgpu_page_alloc *nvgpu_vidmem_get_page_alloc(struct scatterlist *sgl); | 77 | struct nvgpu_page_alloc *nvgpu_vidmem_get_page_alloc(struct scatterlist *sgl); |
48 | void nvgpu_vidmem_set_page_alloc(struct scatterlist *sgl, u64 addr); | 78 | void nvgpu_vidmem_set_page_alloc(struct scatterlist *sgl, u64 addr); |
49 | bool nvgpu_addr_is_vidmem_page_alloc(u64 addr); | 79 | bool nvgpu_addr_is_vidmem_page_alloc(u64 addr); |
50 | int nvgpu_vidmem_buf_alloc(struct gk20a *g, size_t bytes); | ||
51 | int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space); | 80 | int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space); |
52 | 81 | ||
53 | struct nvgpu_mem *nvgpu_vidmem_get_pending_alloc(struct mm_gk20a *mm); | 82 | struct nvgpu_mem *nvgpu_vidmem_get_pending_alloc(struct mm_gk20a *mm); |
54 | 83 | ||
55 | void nvgpu_vidmem_destroy(struct gk20a *g); | 84 | void nvgpu_vidmem_destroy(struct gk20a *g); |
56 | int nvgpu_vidmem_init(struct mm_gk20a *mm); | 85 | int nvgpu_vidmem_init(struct mm_gk20a *mm); |
57 | int nvgpu_vidmem_clear_all(struct gk20a *g); | ||
58 | 86 | ||
59 | void nvgpu_vidmem_clear_mem_worker(struct work_struct *work); | 87 | void nvgpu_vidmem_clear_mem_worker(struct work_struct *work); |
60 | int nvgpu_vidmem_clear(struct gk20a *g, struct nvgpu_mem *mem); | 88 | int nvgpu_vidmem_clear(struct gk20a *g, struct nvgpu_mem *mem); |
61 | 89 | ||
62 | /* | ||
63 | * Will need to be moved later on once we have the Linux vidmem.h file. | ||
64 | */ | ||
65 | struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf); | ||
66 | int nvgpu_vidmem_buf_access_memory(struct gk20a *g, struct dma_buf *dmabuf, | ||
67 | void *buffer, u64 offset, u64 size, u32 cmd); | ||
68 | |||
69 | #else /* !defined(CONFIG_GK20A_VIDMEM) */ | 90 | #else /* !defined(CONFIG_GK20A_VIDMEM) */ |
70 | 91 | ||
71 | /* | 92 | /* |
@@ -91,6 +112,12 @@ static inline int nvgpu_vidmem_buf_alloc(struct gk20a *g, size_t bytes) | |||
91 | { | 112 | { |
92 | return -ENOSYS; | 113 | return -ENOSYS; |
93 | } | 114 | } |
115 | |||
116 | static inline void nvgpu_vidmem_buf_free(struct gk20a *g, | ||
117 | struct nvgpu_vidmem_buf *buf) | ||
118 | { | ||
119 | } | ||
120 | |||
94 | static inline int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space) | 121 | static inline int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space) |
95 | { | 122 | { |
96 | return -ENOSYS; | 123 | return -ENOSYS; |
@@ -121,19 +148,6 @@ static inline int nvgpu_vidmem_clear(struct gk20a *g, | |||
121 | return -ENOSYS; | 148 | return -ENOSYS; |
122 | } | 149 | } |
123 | 150 | ||
124 | static inline struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf) | ||
125 | { | ||
126 | return NULL; | ||
127 | } | ||
128 | |||
129 | static inline int nvgpu_vidmem_buf_access_memory(struct gk20a *g, | ||
130 | struct dma_buf *dmabuf, | ||
131 | void *buffer, u64 offset, | ||
132 | u64 size, u32 cmd) | ||
133 | { | ||
134 | return -ENOSYS; | ||
135 | } | ||
136 | |||
137 | #endif /* !defined(CONFIG_GK20A_VIDMEM) */ | 151 | #endif /* !defined(CONFIG_GK20A_VIDMEM) */ |
138 | 152 | ||
139 | #endif /* __NVGPU_VIDMEM_H__ */ | 153 | #endif /* __NVGPU_VIDMEM_H__ */ |