diff options
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h | 60 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/vidmem.h | 70 |
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 | |||
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__ */ |