Skip to content

Commit 0db5753

Browse files
Hillf Dantonogabbay
authored andcommitted
habanalabs: make use of dma_mmap_coherent
Add dma_mmap_coherent() for goya and gaudi to match their use of dma_alloc_coherent(), see the Link tag for why. Link: https://lore.kernel.org/lkml/20200609091727.GA23814@lst.de/ Cc: Christoph Hellwig <hch@lst.de> Cc: Zhang Li <li.zhang@bitmain.com> Cc: Ding Z Nan <oshack@hotmail.com> Signed-off-by: Hillf Danton <hdanton@sina.com> Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com> Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
1 parent c5e0ec6 commit 0db5753

4 files changed

Lines changed: 9 additions & 16 deletions

File tree

‎drivers/misc/habanalabs/common/command_buffer.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma)
300300
{
301301
struct hl_device *hdev = hpriv->hdev;
302302
struct hl_cb *cb;
303-
phys_addr_t address;
304303
u32 handle, user_cb_size;
305304
int rc;
306305

@@ -360,12 +359,8 @@ int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma)
360359

361360
vma->vm_private_data = cb;
362361

363-
/* Calculate address for CB */
364-
address = virt_to_phys((void *) (uintptr_t) cb->kernel_address);
365-
366-
rc = hdev->asic_funcs->cb_mmap(hdev, vma, cb->kernel_address,
367-
address, cb->size);
368-
362+
rc = hdev->asic_funcs->cb_mmap(hdev, vma, (void *) cb->kernel_address,
363+
cb->bus_address, cb->size);
369364
if (rc) {
370365
spin_lock(&cb->lock);
371366
cb->mmap = false;

‎drivers/misc/habanalabs/common/habanalabs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ struct hl_asic_funcs {
710710
int (*suspend)(struct hl_device *hdev);
711711
int (*resume)(struct hl_device *hdev);
712712
int (*cb_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
713-
u64 kaddress, phys_addr_t paddress, u32 size);
713+
void *cpu_addr, dma_addr_t dma_addr, size_t size);
714714
void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
715715
void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
716716
struct hl_bd *bd);

‎drivers/misc/habanalabs/gaudi/gaudi.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,17 +3091,16 @@ static int gaudi_resume(struct hl_device *hdev)
30913091
}
30923092

30933093
static int gaudi_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
3094-
u64 kaddress, phys_addr_t paddress, u32 size)
3094+
void *cpu_addr, dma_addr_t dma_addr, size_t size)
30953095
{
30963096
int rc;
30973097

30983098
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
30993099
VM_DONTCOPY | VM_NORESERVE;
31003100

3101-
rc = remap_pfn_range(vma, vma->vm_start, paddress >> PAGE_SHIFT,
3102-
size, vma->vm_page_prot);
3101+
rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr, dma_addr, size);
31033102
if (rc)
3104-
dev_err(hdev->dev, "remap_pfn_range error %d", rc);
3103+
dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
31053104

31063105
return rc;
31073106
}

‎drivers/misc/habanalabs/goya/goya.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,17 +2661,16 @@ int goya_resume(struct hl_device *hdev)
26612661
}
26622662

26632663
static int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
2664-
u64 kaddress, phys_addr_t paddress, u32 size)
2664+
void *cpu_addr, dma_addr_t dma_addr, size_t size)
26652665
{
26662666
int rc;
26672667

26682668
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
26692669
VM_DONTCOPY | VM_NORESERVE;
26702670

2671-
rc = remap_pfn_range(vma, vma->vm_start, paddress >> PAGE_SHIFT,
2672-
size, vma->vm_page_prot);
2671+
rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr, dma_addr, size);
26732672
if (rc)
2674-
dev_err(hdev->dev, "remap_pfn_range error %d", rc);
2673+
dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
26752674

26762675
return rc;
26772676
}

0 commit comments

Comments
 (0)