235 lines
8.2 KiB
Diff
235 lines
8.2 KiB
Diff
From 546f68140522237730d7c9fad775f4df90646a7d Mon Sep 17 00:00:00 2001
|
|
From: zouxiaojun <zouxiaojun@eswincomputing.com>
|
|
Date: Tue, 10 Sep 2024 10:55:04 +0800
|
|
Subject: [PATCH 260/416] WIN2030-16035:fix(enc&dec):fix dma heap error for d2d
|
|
|
|
Changelogs:
|
|
fix dma heap error for d2d.
|
|
|
|
Change-Id: Ie1c4575ce7e8df18e2bbcef515f2d76b55c70f74
|
|
Signed-off-by: zouxiaojun <zouxiaojun@eswincomputing.com>
|
|
---
|
|
drivers/staging/media/eswin/vdec/hantro_dec.c | 19 ++++++++++-
|
|
.../media/eswin/venc/vc8000_vcmd_driver.c | 32 +++++++++++++++++--
|
|
2 files changed, 47 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/drivers/staging/media/eswin/vdec/hantro_dec.c b/drivers/staging/media/eswin/vdec/hantro_dec.c
|
|
index 47ef2f26489a..24ceb91b868a 100644
|
|
--- a/drivers/staging/media/eswin/vdec/hantro_dec.c
|
|
+++ b/drivers/staging/media/eswin/vdec/hantro_dec.c
|
|
@@ -332,6 +332,10 @@ int is_clk_on;
|
|
struct timer_list timer;
|
|
#endif
|
|
|
|
+#ifdef SUPPORT_DMA_HEAP
|
|
+static struct mutex dmaheap_mutex;
|
|
+#endif /**SUPPORT_DMA_HEAP*/
|
|
+
|
|
/* for dma_alloc_coherent to allocate mmu &
|
|
* vcmd linear buffers for non-pcie env
|
|
*/
|
|
@@ -2396,8 +2400,10 @@ static long hantrodec_ioctl(struct file *filp, unsigned int cmd,
|
|
|
|
/* map the pha to dma addr(iova)*/
|
|
/* syscoherent <-> false, flush one time when import; sys,cma <-> true, no fush */
|
|
+ mutex_lock(&dmaheap_mutex);
|
|
hmem = common_dmabuf_heap_import_from_user(&fp_priv->root, dbcfg.dmabuf_fd);
|
|
if(IS_ERR(hmem)) {
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("dmabuf-heap alloc from userspace failed\n");
|
|
return -ENOMEM;
|
|
}
|
|
@@ -2408,6 +2414,7 @@ static long hantrodec_ioctl(struct file *filp, unsigned int cmd,
|
|
hmem_d1 = common_dmabuf_heap_import_from_user(&fp_priv->root_d1, dbcfg.dmabuf_fd);
|
|
if(IS_ERR(hmem_d1)) {
|
|
common_dmabuf_heap_release(hmem);
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("dmabuf-heap alloc from userspace failed for d1\n");
|
|
return -ENOMEM;
|
|
}
|
|
@@ -2420,7 +2427,7 @@ static long hantrodec_ioctl(struct file *filp, unsigned int cmd,
|
|
common_dmabuf_heap_release(hmem);
|
|
if (platformdev_d1)
|
|
common_dmabuf_heap_release(hmem_d1);
|
|
-
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
@@ -2437,6 +2444,7 @@ static long hantrodec_ioctl(struct file *filp, unsigned int cmd,
|
|
if (dbcfg.iova != iova_d1) {
|
|
common_dmabuf_heap_release(hmem);
|
|
common_dmabuf_heap_release(hmem_d1);
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("IOVA addrs of d0 and d1 are not the same, 0x%lx != 0x%lx, %d\n", dbcfg.iova, iova_d1, __LINE__);
|
|
return -EFAULT;
|
|
}
|
|
@@ -2447,9 +2455,11 @@ static long hantrodec_ioctl(struct file *filp, unsigned int cmd,
|
|
common_dmabuf_heap_release(hmem);
|
|
if (platformdev_d1)
|
|
common_dmabuf_heap_release(hmem_d1);
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("%s %d: copy_from_user failed, returned %li\n", __func__, __LINE__, tmp);
|
|
return -EFAULT;
|
|
}
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
|
|
return 0;
|
|
}
|
|
@@ -2470,9 +2480,11 @@ static long hantrodec_ioctl(struct file *filp, unsigned int cmd,
|
|
return -ENOMEM;
|
|
}
|
|
|
|
+ mutex_lock(&dmaheap_mutex);
|
|
if (platformdev_d1) {
|
|
hmem_d1 = common_dmabuf_lookup_heapobj_by_fd(&fp_priv->root_d1, dmabuf_fd);
|
|
if (IS_ERR(hmem_d1)) {
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("cannot find dmabuf-heap for dmabuf_fd %d on d1\n", dmabuf_fd);
|
|
return -EFAULT;
|
|
}
|
|
@@ -2481,6 +2493,7 @@ static long hantrodec_ioctl(struct file *filp, unsigned int cmd,
|
|
//LOG_INFO("release dmabuf_fd = %d, hmem=%px, filp=%px, platformdev_d1=%px\n", dmabuf_fd, hmem, filp,
|
|
// platformdev_d1);
|
|
common_dmabuf_heap_release(hmem);
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
|
|
return 0;
|
|
}
|
|
@@ -4039,6 +4052,9 @@ static int hantro_vdec_probe(struct platform_device *pdev)
|
|
return 0;
|
|
}
|
|
|
|
+#ifdef SUPPORT_DMA_HEAP
|
|
+ mutex_init(&dmaheap_mutex);
|
|
+#endif
|
|
ret = hantrodec_init();
|
|
if (ret) {
|
|
LOG_NOTICE("load driver %s failed\n", DEC_DEV_NAME);
|
|
@@ -4081,6 +4097,7 @@ static int hantro_vdec_remove(struct platform_device *pdev)
|
|
LOG_ERR("vdec tbu power down failed\n");
|
|
return -1;
|
|
}
|
|
+ mutex_destroy(&dmaheap_mutex);
|
|
#endif
|
|
vcrt = platform_get_drvdata(pdev);
|
|
vdec_hardware_reset(vcrt);
|
|
diff --git a/drivers/staging/media/eswin/venc/vc8000_vcmd_driver.c b/drivers/staging/media/eswin/venc/vc8000_vcmd_driver.c
|
|
index 66cf710ff470..44d3f79ce197 100644
|
|
--- a/drivers/staging/media/eswin/venc/vc8000_vcmd_driver.c
|
|
+++ b/drivers/staging/media/eswin/venc/vc8000_vcmd_driver.c
|
|
@@ -249,6 +249,10 @@ struct hantrovcmd_dev {
|
|
#define VCMD_HW_ID 0x4342
|
|
|
|
|
|
+#ifdef SUPPORT_DMA_HEAP
|
|
+static struct mutex dmaheap_mutex;
|
|
+#endif /**SUPPORT_DMA_HEAP*/
|
|
+
|
|
static struct noncache_mem vcmd_buf_mem_pool;
|
|
static struct noncache_mem vcmd_status_buf_mem_pool;
|
|
static struct noncache_mem vcmd_registers_mem_pool;
|
|
@@ -2084,9 +2088,11 @@ static long hantrovcmd_ioctl(struct file *filp, unsigned int cmd,
|
|
|
|
LOG_DBG("import dmabuf_fd = %d\n", dbcfg.dmabuf_fd);
|
|
|
|
+ mutex_lock(&dmaheap_mutex);
|
|
/* map the pha to dma addr(iova)*/
|
|
hmem = common_dmabuf_heap_import_from_user(&fp_priv->root, dbcfg.dmabuf_fd);
|
|
if(IS_ERR(hmem)) {
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("dmabuf-heap import from userspace failed\n");
|
|
return -ENOMEM;
|
|
}
|
|
@@ -2095,6 +2101,7 @@ static long hantrovcmd_ioctl(struct file *filp, unsigned int cmd,
|
|
hmem_d1 = common_dmabuf_heap_import_from_user(&fp_priv->root_d1, dbcfg.dmabuf_fd);
|
|
if(IS_ERR(hmem_d1)) {
|
|
common_dmabuf_heap_release(hmem);
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("dmabuf-heap alloc from userspace failed for d1\n");
|
|
return -ENOMEM;
|
|
}
|
|
@@ -2102,8 +2109,12 @@ static long hantrovcmd_ioctl(struct file *filp, unsigned int cmd,
|
|
|
|
/* get the size of the dmabuf allocated by dmabuf_heap */
|
|
buf_size = common_dmabuf_heap_get_size(hmem);
|
|
- LOG_DBG("dmabuf info: CPU VA:0x%lx, PA:0x%lx, DMA addr(iova):0x%lx, size=0x%lx\n",
|
|
- (unsigned long)hmem->vaddr, (unsigned long)sg_phys(hmem->sgt->sgl), (unsigned long)sg_dma_address(hmem->sgt->sgl), (unsigned long)buf_size);
|
|
+ LOG_DBG("fd = %d, dmabuf info: CPU VA:0x%lx, PA:0x%lx, DMA addr(iova):0x%lx, size=0x%lx\n"
|
|
+ , dbcfg.dmabuf_fd
|
|
+ , (unsigned long)hmem->vaddr
|
|
+ , (unsigned long)sg_phys(hmem->sgt->sgl)
|
|
+ , (unsigned long)sg_dma_address(hmem->sgt->sgl)
|
|
+ , (unsigned long)buf_size);
|
|
|
|
dbcfg.iova = (unsigned long)sg_dma_address(hmem->sgt->sgl);
|
|
if (venc_pdev_d1) {
|
|
@@ -2113,7 +2124,9 @@ static long hantrovcmd_ioctl(struct file *filp, unsigned int cmd,
|
|
if (dbcfg.iova != iova_d1) {
|
|
common_dmabuf_heap_release(hmem);
|
|
common_dmabuf_heap_release(hmem_d1);
|
|
- LOG_ERR("VENC_VCMD: IOVA addrs of d0 and d1 are not the same\n");
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
+ LOG_ERR("VENC_VCMD: IOVA addrs of d0 and d1 are not the same, 0x%lx vs 0x%lx\n"
|
|
+ , dbcfg.iova, iova_d1);
|
|
return -EFAULT;
|
|
}
|
|
}
|
|
@@ -2125,9 +2138,11 @@ static long hantrovcmd_ioctl(struct file *filp, unsigned int cmd,
|
|
common_dmabuf_heap_release(hmem);
|
|
if (venc_pdev_d1)
|
|
common_dmabuf_heap_release(hmem_d1);
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_DBG("copy_to_user failed, returned %li\n", retval);
|
|
return -EFAULT;
|
|
}
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
|
|
return 0;
|
|
}
|
|
@@ -2148,9 +2163,11 @@ static long hantrovcmd_ioctl(struct file *filp, unsigned int cmd,
|
|
return -ENOMEM;
|
|
}
|
|
|
|
+ mutex_lock(&dmaheap_mutex);
|
|
if (venc_pdev_d1) {
|
|
hmem_d1 = common_dmabuf_lookup_heapobj_by_fd(&fp_priv->root_d1, dmabuf_fd);
|
|
if (IS_ERR(hmem_d1)) {
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
LOG_ERR("cannot find dmabuf-heap for dmabuf_fd %d on d1\n", dmabuf_fd);
|
|
return -EFAULT;
|
|
}
|
|
@@ -2158,6 +2175,7 @@ static long hantrovcmd_ioctl(struct file *filp, unsigned int cmd,
|
|
}
|
|
|
|
common_dmabuf_heap_release(hmem);
|
|
+ mutex_unlock(&dmaheap_mutex);
|
|
return 0;
|
|
}
|
|
#endif
|
|
@@ -3592,6 +3610,10 @@ int vcmd_mem_init(void)
|
|
dma_addr_t dma_handle = 0;
|
|
dma_addr_t dma_handle_d1 = 0;
|
|
|
|
+#ifdef SUPPORT_DMA_HEAP
|
|
+ mutex_init(&dmaheap_mutex);
|
|
+#endif /**SUPPORT_DMA_HEAP*/
|
|
+
|
|
vcmd_buf_mem_pool.size = CMDBUF_POOL_TOTAL_SIZE;
|
|
|
|
/* command buffer */
|
|
@@ -3698,6 +3720,10 @@ void vcmd_mem_cleanup(void)
|
|
dma_unmap_page(&venc_pdev_d1->dev,
|
|
(dma_addr_t)vcmd_registers_mem_pool.busAddress, vcmd_registers_mem_pool.size, DMA_BIDIRECTIONAL);
|
|
}
|
|
+
|
|
+#ifdef SUPPORT_DMA_HEAP
|
|
+ mutex_destroy(&dmaheap_mutex);
|
|
+#endif /**SUPPORT_DMA_HEAP*/
|
|
}
|
|
|
|
int hantroenc_vcmd_init(void)
|
|
--
|
|
2.47.0
|
|
|