misc: rockchip: pcie-rkep: Use the matching dma_mmap_coherent

The memory allocated by dma_alloc_coherent can be mapped using the
matching dma_mmap_coherent interface.

Change-Id: I7289d490771a86985ec5ed19af5c3cbbfb9810c2
Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
This commit is contained in:
Jon Lin
2025-08-29 14:45:44 +08:00
committed by Tao Huang
parent 3d0138ac35
commit 6d1a9ac5db

View File

@@ -396,6 +396,18 @@ static int rkep_mem_continuous_buffer_free(struct pcie_file *pcie_file,
return ret;
}
static void *rkep_mem_continuous_buffer_to_virt(struct pcie_file *pcie_file, uint64_t dma_addr)
{
struct pcie_ep_continuous_buffer_req *buffer_req, *tmp;
list_for_each_entry_safe(buffer_req, tmp, &pcie_file->cont_buffer_list, cont_buffer_list) {
if (buffer_req->dma_addr == dma_addr)
return buffer_req->vir_addr;
}
return NULL;
}
static int pcie_rkep_open(struct inode *inode, struct file *file)
{
struct miscdevice *miscdev = file->private_data;
@@ -696,15 +708,21 @@ static int pcie_rkep_mmap(struct file *file, struct vm_area_struct *vma)
return -EINVAL;
}
if (pcie_file->cur_mmap_res == PCIE_EP_MMAP_RESOURCE_USER_MEM ||
pcie_file->cur_mmap_res == PCIE_EP_MMAP_RESOURCE_CONTINUOUS_BUFFER)
if (pcie_file->cur_mmap_res == PCIE_EP_MMAP_RESOURCE_USER_MEM) {
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
else
err = remap_pfn_range(vma, vma->vm_start,
__phys_to_pfn(addr),
size, vma->vm_page_prot);
} else if (pcie_file->cur_mmap_res == PCIE_EP_MMAP_RESOURCE_CONTINUOUS_BUFFER) {
err = dma_mmap_coherent(&pcie_rkep->pdev->dev, vma,
rkep_mem_continuous_buffer_to_virt(pcie_file, addr),
addr, size);
} else {
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
err = remap_pfn_range(vma, vma->vm_start,
__phys_to_pfn(addr),
size, vma->vm_page_prot);
err = remap_pfn_range(vma, vma->vm_start,
__phys_to_pfn(addr),
size, vma->vm_page_prot);
}
if (err)
return -EAGAIN;