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.
Showing the changes to include/uapi (1 of 1 file). Show all
Unified · Split
| @@ -960,6 +960,10 @@ union hl_wait_cs_args { · 959 unmodified lines | ||
| 960 | 960 | #define HL_MEM_OP_UNMAP 3 |
| 961 | 961 | /* Opcode to map a hw block */ |
| 962 | 962 | #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 | |
| 963 | 967 | |
| 964 | 968 | /* Memory flags */ |
| 965 | 969 | #define HL_MEM_CONTIGUOUS 0x1 |
| @@ -1031,11 +1035,26 @@ struct hl_mem_in { · 65 unmodified lines | ||
| 1031 | 1035 | /* Virtual address returned from HL_MEM_OP_MAP */ |
| 1032 | 1036 | __u64 device_virt_addr; |
| 1033 | 1037 | } 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; | |
| 1034 | 1050 | }; |
| 1035 | 1051 | |
| 1036 | 1052 | /* HL_MEM_OP_* */ |
| 1037 | 1053 | __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 | + */ | |
| 1039 | 1058 | __u32 flags; |
| 1040 | 1059 | /* Context ID - Currently not in use */ |
| 1041 | 1060 | __u32 ctx_id; |
| @@ -1072,6 +1091,13 @@ struct hl_mem_out { · 30 unmodified lines | ||
| 1072 | 1091 | |
| 1073 | 1092 | __u32 pad; |
| 1074 | 1093 | }; |
| 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; | |
| 1075 | 1101 | }; |
| 1076 | 1102 | }; |
| 1077 | 1103 | |