提交 0db57535 编写于 作者: H Hillf Danton 提交者: Oded Gabbay

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: NHillf Danton <hdanton@sina.com>
Reviewed-by: NOded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: NOded Gabbay <oded.gabbay@gmail.com>
上级 c5e0ec66
...@@ -300,7 +300,6 @@ int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma) ...@@ -300,7 +300,6 @@ int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma)
{ {
struct hl_device *hdev = hpriv->hdev; struct hl_device *hdev = hpriv->hdev;
struct hl_cb *cb; struct hl_cb *cb;
phys_addr_t address;
u32 handle, user_cb_size; u32 handle, user_cb_size;
int rc; int rc;
...@@ -360,12 +359,8 @@ int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma) ...@@ -360,12 +359,8 @@ int hl_cb_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma)
vma->vm_private_data = cb; vma->vm_private_data = cb;
/* Calculate address for CB */ rc = hdev->asic_funcs->cb_mmap(hdev, vma, (void *) cb->kernel_address,
address = virt_to_phys((void *) (uintptr_t) cb->kernel_address); cb->bus_address, cb->size);
rc = hdev->asic_funcs->cb_mmap(hdev, vma, cb->kernel_address,
address, cb->size);
if (rc) { if (rc) {
spin_lock(&cb->lock); spin_lock(&cb->lock);
cb->mmap = false; cb->mmap = false;
......
...@@ -710,7 +710,7 @@ struct hl_asic_funcs { ...@@ -710,7 +710,7 @@ struct hl_asic_funcs {
int (*suspend)(struct hl_device *hdev); int (*suspend)(struct hl_device *hdev);
int (*resume)(struct hl_device *hdev); int (*resume)(struct hl_device *hdev);
int (*cb_mmap)(struct hl_device *hdev, struct vm_area_struct *vma, int (*cb_mmap)(struct hl_device *hdev, struct vm_area_struct *vma,
u64 kaddress, phys_addr_t paddress, u32 size); void *cpu_addr, dma_addr_t dma_addr, size_t size);
void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi); void (*ring_doorbell)(struct hl_device *hdev, u32 hw_queue_id, u32 pi);
void (*pqe_write)(struct hl_device *hdev, __le64 *pqe, void (*pqe_write)(struct hl_device *hdev, __le64 *pqe,
struct hl_bd *bd); struct hl_bd *bd);
......
...@@ -3091,17 +3091,16 @@ static int gaudi_resume(struct hl_device *hdev) ...@@ -3091,17 +3091,16 @@ static int gaudi_resume(struct hl_device *hdev)
} }
static int gaudi_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma, static int gaudi_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
u64 kaddress, phys_addr_t paddress, u32 size) void *cpu_addr, dma_addr_t dma_addr, size_t size)
{ {
int rc; int rc;
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
VM_DONTCOPY | VM_NORESERVE; VM_DONTCOPY | VM_NORESERVE;
rc = remap_pfn_range(vma, vma->vm_start, paddress >> PAGE_SHIFT, rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr, dma_addr, size);
size, vma->vm_page_prot);
if (rc) if (rc)
dev_err(hdev->dev, "remap_pfn_range error %d", rc); dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
return rc; return rc;
} }
......
...@@ -2661,17 +2661,16 @@ int goya_resume(struct hl_device *hdev) ...@@ -2661,17 +2661,16 @@ int goya_resume(struct hl_device *hdev)
} }
static int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma, static int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
u64 kaddress, phys_addr_t paddress, u32 size) void *cpu_addr, dma_addr_t dma_addr, size_t size)
{ {
int rc; int rc;
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
VM_DONTCOPY | VM_NORESERVE; VM_DONTCOPY | VM_NORESERVE;
rc = remap_pfn_range(vma, vma->vm_start, paddress >> PAGE_SHIFT, rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr, dma_addr, size);
size, vma->vm_page_prot);
if (rc) if (rc)
dev_err(hdev->dev, "remap_pfn_range error %d", rc); dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
return rc; return rc;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册