aboutsummaryrefslogtreecommitdiffstats
path: root/include/nvgpu/dma.h
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2023-06-28 18:24:25 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2023-06-28 18:24:25 -0400
commit01e6fac4d61fdd7fff5433942ec93fc2ea1e4df1 (patch)
tree4ef34501728a087be24f4ba0af90f91486bf780b /include/nvgpu/dma.h
parent306a03d18b305e4e573be3b2931978fa10679eb9 (diff)
Include nvgpu headers
These are needed to build on NVIDIA's Jetson boards for the time being. Only a couple structs are required, so it should be fairly easy to remove this dependency at some point in the future.
Diffstat (limited to 'include/nvgpu/dma.h')
-rw-r--r--include/nvgpu/dma.h361
1 files changed, 361 insertions, 0 deletions
diff --git a/include/nvgpu/dma.h b/include/nvgpu/dma.h
new file mode 100644
index 0000000..cbb829b
--- /dev/null
+++ b/include/nvgpu/dma.h
@@ -0,0 +1,361 @@
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 */