aboutsummaryrefslogtreecommitdiffstats
path: root/include/nvgpu/dma.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/nvgpu/dma.h')
-rw-r--r--include/nvgpu/dma.h361
1 files changed, 0 insertions, 361 deletions
diff --git a/include/nvgpu/dma.h b/include/nvgpu/dma.h
deleted file mode 100644
index cbb829b..0000000
--- a/include/nvgpu/dma.h
+++ /dev/null
@@ -1,361 +0,0 @@
1/*
2 * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef NVGPU_DMA_H
24#define NVGPU_DMA_H
25
26#include <nvgpu/types.h>
27
28struct gk20a;
29struct vm_gk20a;
30struct nvgpu_mem;
31
32/*
33 * Flags for the below nvgpu_dma_{alloc,alloc_map}_flags*
34 */
35
36/*
37 * Don't create a virtual kernel mapping for the buffer but only allocate it;
38 * this may save some resources. The buffer can be mapped later explicitly.
39 */
40#define NVGPU_DMA_NO_KERNEL_MAPPING BIT32(0)
41
42/*
43 * Don't allow building the buffer from individual pages but require a
44 * physically contiguous block.
45 */
46#define NVGPU_DMA_FORCE_CONTIGUOUS BIT32(1)
47
48/*
49 * Make the mapping read-only.
50 */
51#define NVGPU_DMA_READ_ONLY BIT32(2)
52
53/**
54 * nvgpu_iommuable - Check if GPU is behind IOMMU
55 *
56 * @g - The GPU.
57 *
58 * Returns true if the passed GPU is behind an IOMMU; false otherwise. If the
59 * GPU is iommuable then the DMA address in nvgpu_mem_sgl is valid.
60 *
61 * Note that even if a GPU is behind an IOMMU that does not necessarily mean the
62 * GPU _must_ use DMA addresses. GPUs may still use physical addresses if it
63 * makes sense.
64 */
65bool nvgpu_iommuable(struct gk20a *g);
66
67/**
68 * nvgpu_dma_alloc - Allocate DMA memory
69 *
70 * @g - The GPU.
71 * @size - Size of the allocation in bytes.
72 * @mem - Struct for storing the allocation information.
73 *
74 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
75 * Returns 0 on success and a suitable error code when there's an error. This
76 * memory can be either placed in VIDMEM or SYSMEM, which ever is more
77 * convenient for the driver.
78 */
79int nvgpu_dma_alloc(struct gk20a *g, size_t size, struct nvgpu_mem *mem);
80
81/**
82 * nvgpu_dma_alloc_flags - Allocate DMA memory
83 *
84 * @g - The GPU.
85 * @flags - Flags modifying the operation of the DMA allocation.
86 * @size - Size of the allocation in bytes.
87 * @mem - Struct for storing the allocation information.
88 *
89 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
90 * Returns 0 on success and a suitable error code when there's an error. This
91 * memory can be either placed in VIDMEM or SYSMEM, which ever is more
92 * convenient for the driver.
93 *
94 * The following flags are accepted:
95 *
96 * %NVGPU_DMA_NO_KERNEL_MAPPING
97 * %NVGPU_DMA_FORCE_CONTIGUOUS
98 * %NVGPU_DMA_READ_ONLY
99 */
100int nvgpu_dma_alloc_flags(struct gk20a *g, unsigned long flags, size_t size,
101 struct nvgpu_mem *mem);
102
103/**
104 * nvgpu_dma_alloc_sys - Allocate DMA memory
105 *
106 * @g - The GPU.
107 * @size - Size of the allocation in bytes.
108 * @mem - Struct for storing the allocation information.
109 *
110 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
111 * Returns 0 on success and a suitable error code when there's an error. This
112 * allocates memory specifically in SYSMEM.
113 */
114int nvgpu_dma_alloc_sys(struct gk20a *g, size_t size, struct nvgpu_mem *mem);
115
116/**
117 * nvgpu_dma_alloc_flags_sys - Allocate DMA memory
118 *
119 * @g - The GPU.
120 * @flags - Flags modifying the operation of the DMA allocation.
121 * @size - Size of the allocation in bytes.
122 * @mem - Struct for storing the allocation information.
123 *
124 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
125 * Returns 0 on success and a suitable error code when there's an error. This
126 * allocates memory specifically in SYSMEM.
127 *
128 * The following flags are accepted:
129 *
130 * %NVGPU_DMA_NO_KERNEL_MAPPING
131 * %NVGPU_DMA_FORCE_CONTIGUOUS
132 * %NVGPU_DMA_READ_ONLY
133 */
134int nvgpu_dma_alloc_flags_sys(struct gk20a *g, unsigned long flags,
135 size_t size, struct nvgpu_mem *mem);
136
137/**
138 * nvgpu_dma_alloc_vid - Allocate DMA memory
139 *
140 * @g - The GPU.
141 * @size - Size of the allocation in bytes.
142 * @mem - Struct for storing the allocation information.
143 *
144 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
145 * Returns 0 on success and a suitable error code when there's an error. This
146 * allocates memory specifically in VIDMEM.
147 */
148int nvgpu_dma_alloc_vid(struct gk20a *g, size_t size, struct nvgpu_mem *mem);
149
150/**
151 * nvgpu_dma_alloc_flags_vid - Allocate DMA memory
152 *
153 * @g - The GPU.
154 * @flags - Flags modifying the operation of the DMA allocation.
155 * @size - Size of the allocation in bytes.
156 * @mem - Struct for storing the allocation information.
157 *
158 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
159 * Returns 0 on success and a suitable error code when there's an error. This
160 * allocates memory specifically in VIDMEM.
161 *
162 * Only the following flags are accepted:
163 *
164 * %NVGPU_DMA_NO_KERNEL_MAPPING
165 *
166 */
167int nvgpu_dma_alloc_flags_vid(struct gk20a *g, unsigned long flags,
168 size_t size, struct nvgpu_mem *mem);
169
170
171/**
172 * nvgpu_dma_alloc_flags_vid_at - Allocate DMA memory
173 *
174 * @g - The GPU.
175 * @size - Size of the allocation in bytes.
176 * @mem - Struct for storing the allocation information.
177 * @at - A specific location to attempt to allocate memory from or 0 if the
178 * caller does not care what the address is.
179 *
180 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
181 * Returns 0 on success and a suitable error code when there's an error. This
182 * allocates memory specifically in VIDMEM.
183 *
184 */
185int nvgpu_dma_alloc_vid_at(struct gk20a *g,
186 size_t size, struct nvgpu_mem *mem, u64 at);
187
188/**
189 * nvgpu_dma_alloc_flags_vid_at - Allocate DMA memory
190 *
191 * @g - The GPU.
192 * @flags - Flags modifying the operation of the DMA allocation.
193 * @size - Size of the allocation in bytes.
194 * @mem - Struct for storing the allocation information.
195 * @at - A specific location to attempt to allocate memory from or 0 if the
196 * caller does not care what the address is.
197 *
198 * Allocate memory suitable for doing DMA. Store the allocation info in @mem.
199 * Returns 0 on success and a suitable error code when there's an error. This
200 * allocates memory specifically in VIDMEM.
201 *
202 * Only the following flags are accepted:
203 *
204 * %NVGPU_DMA_NO_KERNEL_MAPPING
205 */
206int nvgpu_dma_alloc_flags_vid_at(struct gk20a *g, unsigned long flags,
207 size_t size, struct nvgpu_mem *mem, u64 at);
208
209/**
210 * nvgpu_dma_free - Free a DMA allocation
211 *
212 * @g - The GPU.
213 * @mem - An allocation to free.
214 *
215 * Free memory created with any of:
216 *
217 * nvgpu_dma_alloc()
218 * nvgpu_dma_alloc_flags()
219 * nvgpu_dma_alloc_sys()
220 * nvgpu_dma_alloc_flags_sys()
221 * nvgpu_dma_alloc_vid()
222 * nvgpu_dma_alloc_flags_vid()
223 * nvgpu_dma_alloc_flags_vid_at()
224 */
225void nvgpu_dma_free(struct gk20a *g, struct nvgpu_mem *mem);
226
227/**
228 * nvgpu_dma_alloc_map - Allocate DMA memory and map into GMMU.
229 *
230 * @vm - VM context for GMMU mapping.
231 * @size - Size of the allocation in bytes.
232 * @mem - Struct for storing the allocation information.
233 *
234 * Allocate memory suitable for doing DMA and map that memory into the GMMU.
235 * Note this is different than mapping it into the CPU. This memory can be
236 * either placed in VIDMEM or SYSMEM, which ever is more convenient for the
237 * driver.
238 *
239 * Note: currently a bug exists in the nvgpu_dma_alloc_map*() routines: you
240 * cannot use nvgpu_gmmu_map() on said buffer - it will overwrite the necessary
241 * information for the DMA unmap routines to actually unmap the buffer. You
242 * will either leak mappings or see GMMU faults.
243 */
244int nvgpu_dma_alloc_map(struct vm_gk20a *vm, size_t size,
245 struct nvgpu_mem *mem);
246
247/**
248 * nvgpu_dma_alloc_map_flags - Allocate DMA memory and map into GMMU.
249 *
250 * @vm - VM context for GMMU mapping.
251 * @flags - Flags modifying the operation of the DMA allocation.
252 * @size - Size of the allocation in bytes.
253 * @mem - Struct for storing the allocation information.
254 *
255 * Allocate memory suitable for doing DMA and map that memory into the GMMU.
256 * Note this is different than mapping it into the CPU. This memory can be
257 * either placed in VIDMEM or SYSMEM, which ever is more convenient for the
258 * driver.
259 *
260 * This version passes @flags on to the underlying DMA allocation. The accepted
261 * flags are:
262 *
263 * %NVGPU_DMA_NO_KERNEL_MAPPING
264 * %NVGPU_DMA_FORCE_CONTIGUOUS
265 * %NVGPU_DMA_READ_ONLY
266 */
267int nvgpu_dma_alloc_map_flags(struct vm_gk20a *vm, unsigned long flags,
268 size_t size, struct nvgpu_mem *mem);
269
270/**
271 * nvgpu_dma_alloc_map_sys - Allocate DMA memory and map into GMMU.
272 *
273 * @vm - VM context for GMMU mapping.
274 * @size - Size of the allocation in bytes.
275 * @mem - Struct for storing the allocation information.
276 *
277 * Allocate memory suitable for doing DMA and map that memory into the GMMU.
278 * This memory will be placed in SYSMEM.
279 */
280int nvgpu_dma_alloc_map_sys(struct vm_gk20a *vm, size_t size,
281 struct nvgpu_mem *mem);
282
283/**
284 * nvgpu_dma_alloc_map_flags_sys - Allocate DMA memory and map into GMMU.
285 *
286 * @vm - VM context for GMMU mapping.
287 * @flags - Flags modifying the operation of the DMA allocation.
288 * @size - Size of the allocation in bytes.
289 * @mem - Struct for storing the allocation information.
290 *
291 * Allocate memory suitable for doing DMA and map that memory into the GMMU.
292 * This memory will be placed in SYSMEM.
293 *
294 * This version passes @flags on to the underlying DMA allocation. The accepted
295 * flags are:
296 *
297 * %NVGPU_DMA_NO_KERNEL_MAPPING
298 * %NVGPU_DMA_FORCE_CONTIGUOUS
299 * %NVGPU_DMA_READ_ONLY
300 */
301int nvgpu_dma_alloc_map_flags_sys(struct vm_gk20a *vm, unsigned long flags,
302 size_t size, struct nvgpu_mem *mem);
303
304/**
305 * nvgpu_dma_alloc_map_vid - Allocate DMA memory and map into GMMU.
306 *
307 * @vm - VM context for GMMU mapping.
308 * @size - Size of the allocation in bytes.
309 * @mem - Struct for storing the allocation information.
310 *
311 * Allocate memory suitable for doing DMA and map that memory into the GMMU.
312 * This memory will be placed in VIDMEM.
313 */
314int nvgpu_dma_alloc_map_vid(struct vm_gk20a *vm, size_t size,
315 struct nvgpu_mem *mem);
316
317/**
318 * nvgpu_dma_alloc_map_flags_vid - Allocate DMA memory and map into GMMU.
319 *
320 * @vm - VM context for GMMU mapping.
321 * @flags - Flags modifying the operation of the DMA allocation.
322 * @size - Size of the allocation in bytes.
323 * @mem - Struct for storing the allocation information.
324 *
325 * Allocate memory suitable for doing DMA and map that memory into the GMMU.
326 * This memory will be placed in VIDMEM.
327 *
328 * This version passes @flags on to the underlying DMA allocation. The accepted
329 * flags are:
330 *
331 * %NVGPU_DMA_NO_KERNEL_MAPPING
332 * %NVGPU_DMA_FORCE_CONTIGUOUS
333 * %NVGPU_DMA_READ_ONLY
334 */
335int nvgpu_dma_alloc_map_flags_vid(struct vm_gk20a *vm, unsigned long flags,
336 size_t size, struct nvgpu_mem *mem);
337
338/**
339 * nvgpu_dma_unmap_free - Free a DMA allocation
340 *
341 * @g - The GPU.
342 * @mem - An allocation to free.
343 *
344 * Free memory created with any of:
345 *
346 * nvgpu_dma_alloc_map()
347 * nvgpu_dma_alloc_map_flags()
348 * nvgpu_dma_alloc_map_sys()
349 * nvgpu_dma_alloc_map_flags_sys()
350 * nvgpu_dma_alloc_map_vid()
351 * nvgpu_dma_alloc_map_flags_vid()
352 */
353void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem);
354
355/*
356 * Don't use these directly. Instead use nvgpu_dma_free().
357 */
358void nvgpu_dma_free_sys(struct gk20a *g, struct nvgpu_mem *mem);
359void nvgpu_dma_free_vid(struct gk20a *g, struct nvgpu_mem *mem);
360
361#endif /* NVGPU_DMA_H */