aboutsummaryrefslogtreecommitdiffstats
path: root/include/uapi/misc
diff options
context:
space:
mode:
authorOmer Shpigelman <oshpigelman@habana.ai>2019-02-15 17:39:22 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-02-18 03:46:46 -0500
commit0feaf86d4e69507ab9b2af7dcc63a6886352d5db (patch)
tree9340f1c492c53b9c92dc0753f9b9c15402fa406f /include/uapi/misc
parenteff6f4a0e70b7bcf4674f471a768860a74e638a6 (diff)
habanalabs: add virtual memory and MMU modules
This patch adds the Virtual Memory and MMU modules. Goya has an internal MMU which provides process isolation on the internal DDR. The internal MMU also performs translations for transactions that go from Goya to the Host. The driver is responsible for allocating and freeing memory on the DDR upon user request. It also provides an interface to map and unmap DDR and Host memory to the device address space. The MMU in Goya supports 3-level and 4-level page tables. With 3-level, the size of each page is 2MB, while with 4-level the size of each page is 4KB. In the DDR, the physical pages are always 2MB. Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Omer Shpigelman <oshpigelman@habana.ai> Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/uapi/misc')
-rw-r--r--include/uapi/misc/habanalabs.h122
1 files changed, 121 insertions, 1 deletions
diff --git a/include/uapi/misc/habanalabs.h b/include/uapi/misc/habanalabs.h
index fba49417f607..9015043887d1 100644
--- a/include/uapi/misc/habanalabs.h
+++ b/include/uapi/misc/habanalabs.h
@@ -162,6 +162,108 @@ union hl_wait_cs_args {
162 struct hl_wait_cs_out out; 162 struct hl_wait_cs_out out;
163}; 163};
164 164
165/* Opcode to alloc device memory */
166#define HL_MEM_OP_ALLOC 0
167/* Opcode to free previously allocated device memory */
168#define HL_MEM_OP_FREE 1
169/* Opcode to map host memory */
170#define HL_MEM_OP_MAP 2
171/* Opcode to unmap previously mapped host memory */
172#define HL_MEM_OP_UNMAP 3
173
174/* Memory flags */
175#define HL_MEM_CONTIGUOUS 0x1
176#define HL_MEM_SHARED 0x2
177#define HL_MEM_USERPTR 0x4
178
179struct hl_mem_in {
180 union {
181 /* HL_MEM_OP_ALLOC- allocate device memory */
182 struct {
183 /* Size to alloc */
184 __u32 mem_size;
185 __u32 pad;
186 } alloc;
187
188 /* HL_MEM_OP_FREE - free device memory */
189 struct {
190 /* Handle returned from HL_MEM_OP_ALLOC */
191 __u64 handle;
192 } free;
193
194 /* HL_MEM_OP_MAP - map device memory */
195 struct {
196 /*
197 * Requested virtual address of mapped memory.
198 * KMD will try to map the requested region to this
199 * hint address, as long as the address is valid and
200 * not already mapped. The user should check the
201 * returned address of the IOCTL to make sure he got
202 * the hint address. Passing 0 here means that KMD
203 * will choose the address itself.
204 */
205 __u64 hint_addr;
206 /* Handle returned from HL_MEM_OP_ALLOC */
207 __u64 handle;
208 } map_device;
209
210 /* HL_MEM_OP_MAP - map host memory */
211 struct {
212 /* Address of allocated host memory */
213 __u64 host_virt_addr;
214 /*
215 * Requested virtual address of mapped memory.
216 * KMD will try to map the requested region to this
217 * hint address, as long as the address is valid and
218 * not already mapped. The user should check the
219 * returned address of the IOCTL to make sure he got
220 * the hint address. Passing 0 here means that KMD
221 * will choose the address itself.
222 */
223 __u64 hint_addr;
224 /* Size of allocated host memory */
225 __u32 mem_size;
226 __u32 pad;
227 } map_host;
228
229 /* HL_MEM_OP_UNMAP - unmap host memory */
230 struct {
231 /* Virtual address returned from HL_MEM_OP_MAP */
232 __u64 device_virt_addr;
233 } unmap;
234 };
235
236 /* HL_MEM_OP_* */
237 __u32 op;
238 /* HL_MEM_* flags */
239 __u32 flags;
240 /* Context ID - Currently not in use */
241 __u32 ctx_id;
242 __u32 pad;
243};
244
245struct hl_mem_out {
246 union {
247 /*
248 * Used for HL_MEM_OP_MAP as the virtual address that was
249 * assigned in the device VA space.
250 * A value of 0 means the requested operation failed.
251 */
252 __u64 device_virt_addr;
253
254 /*
255 * Used for HL_MEM_OP_ALLOC. This is the assigned
256 * handle for the allocated memory
257 */
258 __u64 handle;
259 };
260};
261
262union hl_mem_args {
263 struct hl_mem_in in;
264 struct hl_mem_out out;
265};
266
165/* 267/*
166 * Command Buffer 268 * Command Buffer
167 * - Request a Command Buffer 269 * - Request a Command Buffer
@@ -245,7 +347,25 @@ union hl_wait_cs_args {
245#define HL_IOCTL_WAIT_CS \ 347#define HL_IOCTL_WAIT_CS \
246 _IOWR('H', 0x04, union hl_wait_cs_args) 348 _IOWR('H', 0x04, union hl_wait_cs_args)
247 349
350/*
351 * Memory
352 * - Map host memory to device MMU
353 * - Unmap host memory from device MMU
354 *
355 * This IOCTL allows the user to map host memory to the device MMU
356 *
357 * For host memory, the IOCTL doesn't allocate memory. The user is supposed
358 * to allocate the memory in user-space (malloc/new). The driver pins the
359 * physical pages (up to the allowed limit by the OS), assigns a virtual
360 * address in the device VA space and initializes the device MMU.
361 *
362 * There is an option for the user to specify the requested virtual address.
363 *
364 */
365#define HL_IOCTL_MEMORY \
366 _IOWR('H', 0x05, union hl_mem_args)
367
248#define HL_COMMAND_START 0x02 368#define HL_COMMAND_START 0x02
249#define HL_COMMAND_END 0x05 369#define HL_COMMAND_END 0x06
250 370
251#endif /* HABANALABS_H_ */ 371#endif /* HABANALABS_H_ */