summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/include
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/include
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/include')
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h60
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/vidmem.h70
2 files changed, 102 insertions, 28 deletions
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
22struct dma_buf;
23
24struct gk20a;
25
26#ifdef CONFIG_GK20A_VIDMEM
27struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf);
28int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes);
29
30int 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 */
34static inline struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf)
35{
36 return NULL;
37}
38
39static inline int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes)
40{
41 return -ENOSYS;
42}
43
44static 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
54struct 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
29struct scatterlist; 30struct scatterlist;
30struct dma_buf;
31struct work_struct; 31struct work_struct;
32 32
33struct gk20a; 33struct gk20a;
@@ -35,37 +35,58 @@ struct mm_gk20a;
35struct nvgpu_mem; 35struct nvgpu_mem;
36 36
37struct nvgpu_vidmem_buf { 37struct 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 */
73struct nvgpu_vidmem_buf *nvgpu_vidmem_user_alloc(struct gk20a *g, size_t bytes);
74
75void nvgpu_vidmem_buf_free(struct gk20a *g, struct nvgpu_vidmem_buf *buf);
76
47struct nvgpu_page_alloc *nvgpu_vidmem_get_page_alloc(struct scatterlist *sgl); 77struct nvgpu_page_alloc *nvgpu_vidmem_get_page_alloc(struct scatterlist *sgl);
48void nvgpu_vidmem_set_page_alloc(struct scatterlist *sgl, u64 addr); 78void nvgpu_vidmem_set_page_alloc(struct scatterlist *sgl, u64 addr);
49bool nvgpu_addr_is_vidmem_page_alloc(u64 addr); 79bool nvgpu_addr_is_vidmem_page_alloc(u64 addr);
50int nvgpu_vidmem_buf_alloc(struct gk20a *g, size_t bytes);
51int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space); 80int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space);
52 81
53struct nvgpu_mem *nvgpu_vidmem_get_pending_alloc(struct mm_gk20a *mm); 82struct nvgpu_mem *nvgpu_vidmem_get_pending_alloc(struct mm_gk20a *mm);
54 83
55void nvgpu_vidmem_destroy(struct gk20a *g); 84void nvgpu_vidmem_destroy(struct gk20a *g);
56int nvgpu_vidmem_init(struct mm_gk20a *mm); 85int nvgpu_vidmem_init(struct mm_gk20a *mm);
57int nvgpu_vidmem_clear_all(struct gk20a *g);
58 86
59void nvgpu_vidmem_clear_mem_worker(struct work_struct *work); 87void nvgpu_vidmem_clear_mem_worker(struct work_struct *work);
60int nvgpu_vidmem_clear(struct gk20a *g, struct nvgpu_mem *mem); 88int 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 */
65struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf);
66int 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
116static inline void nvgpu_vidmem_buf_free(struct gk20a *g,
117 struct nvgpu_vidmem_buf *buf)
118{
119}
120
94static inline int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space) 121static 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
124static inline struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf)
125{
126 return NULL;
127}
128
129static 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__ */