Skip to content

Commit a9d4ef6

Browse files
committed
habanalabs: fix dma_addr passed to dma_mmap_coherent
When doing dma_alloc_coherent in the driver, we add a certain hard-coded offset to the DMA address before returning to the callee function. This offset is needed when our device use this DMA address to perform outbound transactions to the host. However, if we want to map the DMA'able memory to the user via dma_mmap_coherent(), we need to pass the original dma address, without this offset. Otherwise, we will get erronouos mapping. Signed-off-by: Oded Gabbay <[email protected]>
1 parent f970d1d commit a9d4ef6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

drivers/misc/habanalabs/gaudi/gaudi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4002,7 +4002,8 @@ static int gaudi_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
40024002
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
40034003
VM_DONTCOPY | VM_NORESERVE;
40044004

4005-
rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr, dma_addr, size);
4005+
rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr,
4006+
(dma_addr - HOST_PHYS_BASE), size);
40064007
if (rc)
40074008
dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
40084009

drivers/misc/habanalabs/goya/goya.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,8 @@ static int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
27192719
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
27202720
VM_DONTCOPY | VM_NORESERVE;
27212721

2722-
rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr, dma_addr, size);
2722+
rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr,
2723+
(dma_addr - HOST_PHYS_BASE), size);
27232724
if (rc)
27242725
dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
27252726

0 commit comments

Comments
 (0)