History

habanalabs: define uAPI to export FD for DMA-BUF

User process might want to share the device memory with another driver/device, and to allow it to access it over PCIe (P2P). To enable this, we utilize the dma-buf mechanism and add a dma-buf exporter support, so the other driver can import the device memory and access it. The device memory is allocated using our existing allocation uAPI, where the user will get a handle that represents the allocation. The user will then need to call the new uAPI (HL_MEM_OP_EXPORT_DMABUF_FD) and give the handle as a parameter. The driver will return a FD that represents the DMA-BUF object that was created to match that allocation.

Oded Gabbay committed 5 years ago

Commit a9498ee1 parent 81f85821 file · +27 −1Browse files

Showing the changes to include/uapi (1 of 1 file). Show all

Unified · Split

include/uapi/misc/habanalabs.h+27−1
@@ -960,6 +960,10 @@ union hl_wait_cs_args { · 959 unmodified lines
960960 #define HL_MEM_OP_UNMAP 3
961961 /* Opcode to map a hw block */
962962 #define HL_MEM_OP_MAP_BLOCK 4
963+/* Opcode to create DMA-BUF object for an existing device memory allocation
964+ * and to export an FD of that DMA-BUF back to the caller
965+ */
966+#define HL_MEM_OP_EXPORT_DMABUF_FD 5
963967
964968 /* Memory flags */
965969 #define HL_MEM_CONTIGUOUS 0x1
@@ -1031,11 +1035,26 @@ struct hl_mem_in { · 65 unmodified lines
10311035 /* Virtual address returned from HL_MEM_OP_MAP */
10321036 __u64 device_virt_addr;
10331037 } unmap;
1038+
1039+ /* HL_MEM_OP_EXPORT_DMABUF_FD */
1040+ struct {
1041+ /* Handle returned from HL_MEM_OP_ALLOC. In Gaudi,
1042+ * where we don't have MMU for the device memory, the
1043+ * driver expects a physical address (instead of
1044+ * a handle) in the device memory space.
1045+ */
1046+ __u64 handle;
1047+ /* Size of memory allocation. Relevant only for GAUDI */
1048+ __u64 mem_size;
1049+ } export_dmabuf_fd;
10341050 };
10351051
10361052 /* HL_MEM_OP_* */
10371053 __u32 op;
1038− /* HL_MEM_* flags */
1054+ /* HL_MEM_* flags.
1055+ * For the HL_MEM_OP_EXPORT_DMABUF_FD opcode, this field holds the
1056+ * DMA-BUF file/FD flags.
1057+ */
10391058 __u32 flags;
10401059 /* Context ID - Currently not in use */
10411060 __u32 ctx_id;
@@ -1072,6 +1091,13 @@ struct hl_mem_out { · 30 unmodified lines
10721091
10731092 __u32 pad;
10741093 };
1094+
1095+ /* Returned in HL_MEM_OP_EXPORT_DMABUF_FD. Represents the
1096+ * DMA-BUF object that was created to describe a memory
1097+ * allocation on the device's memory space. The FD should be
1098+ * passed to the importer driver
1099+ */
1100+ __s32 fd;
10751101 };
10761102 };
10771103