• Tomer Tayar's avatar
    habanalabs: add support for dma-buf exporter · db1a8dd9
    Tomer Tayar authored
    Implement the calls to the dma-buf kernel api to create a dma-buf
    object backed by FD.
    
    We block the option to mmap the DMA-BUF object because we don't support
    DIRECT_IO and implicit P2P. We only implement support for explicit P2P
    through importing the FD of the DMA-BUF.
    
    In the export phase, we provide to the DMA-BUF object an array of pages
    that represent the device's memory area. During the map callback,
    we convert the array of pages into an SGT. We split/merge the pages
    according to the dma max segment size of the importer.
    
    To get the DMA address of the PCI bar, we use the dma_map_resources()
    kernel API, because our device memory is not backed by page struct
    and this API doesn't need page struct to map the physical address to
    a DMA address.
    
    We set the orig_nents member of the SGT to be 0, to indicate to other
    drivers that we don't support CPU mappings.
    
    Note that in Habanalabs's ASICs, the device memory is pinned and
    immutable. Therefore, there is no need for dynamic mappings and pinning
    callbacks.
    
    Also note that in GAUDI we don't have an MMU towards the device memory
    and the user works on physical addresses. Therefore, the user doesn't
    pass through the kernel driver to allocate memory there. As a result,
    only for GAUDI we receive from the user a device memory physical address
    (instead of a handle) and a size.
    
    We check the p2p distance using pci_p2pdma_distance_many() and refusing
    to map dmabuf in case the distance doesn't allow p2p.
    Signed-off-by: default avatarTomer Tayar <ttayar@habana.ai>
    Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
    Reviewed-by: default avatarGal Pressman <galpress@amazon.com>
    Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
    Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
    db1a8dd9
memory.c 73.9 KB