From 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Mon, 11 Dec 2023 02:46:07 +0000
Subject: [PATCH] add audio

---
 kernel/drivers/video/rockchip/rga3/rga_dma_buf.c |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/kernel/drivers/video/rockchip/rga3/rga_dma_buf.c b/kernel/drivers/video/rockchip/rga3/rga_dma_buf.c
index b5b0dd0..7180100 100644
--- a/kernel/drivers/video/rockchip/rga3/rga_dma_buf.c
+++ b/kernel/drivers/video/rockchip/rga3/rga_dma_buf.c
@@ -206,12 +206,11 @@
 	struct rga_iommu_dma_cookie *cookie = domain->iova_cookie;
 	struct iova_domain *iovad = &cookie->iovad;
 	unsigned long shift, iova_len, iova = 0;
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
-	dma_addr_t limit;
-#endif
 
 	shift = iova_shift(iovad);
 	iova_len = size >> shift;
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
 	/*
 	 * Freeing non-power-of-two-sized allocations back into the IOVA caches
 	 * will come back to bite us badly, so we have to waste a bit of space
@@ -220,6 +219,7 @@
 	 */
 	if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
 		iova_len = roundup_pow_of_two(iova_len);
+#endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
 	dma_limit = min_not_zero(dma_limit, dev->bus_dma_limit);
@@ -231,12 +231,13 @@
 	if (domain->geometry.force_aperture)
 		dma_limit = min(dma_limit, (u64)domain->geometry.aperture_end);
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0))
-	iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift, true);
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(4, 19, 111) && \
+     LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
+	iova = alloc_iova_fast(iovad, iova_len,
+			       min_t(dma_addr_t, dma_limit >> shift, iovad->end_pfn),
+			       true);
 #else
-	limit = min_t(dma_addr_t, dma_limit >> shift, iovad->end_pfn);
-
-	iova = alloc_iova_fast(iovad, iova_len, limit, true);
+	iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift, true);
 #endif
 
 	return (dma_addr_t)iova << shift;
@@ -424,21 +425,21 @@
 	if (dma_buf != NULL) {
 		get_dma_buf(dma_buf);
 	} else {
-		pr_err("dma_buf is Invalid[%p]\n", dma_buf);
+		pr_err("dma_buf is invalid[%p]\n", dma_buf);
 		return -EINVAL;
 	}
 
 	attach = dma_buf_attach(dma_buf, rga_dev);
 	if (IS_ERR(attach)) {
-		pr_err("Failed to attach dma_buf\n");
-		ret = -EINVAL;
+		ret = PTR_ERR(attach);
+		pr_err("Failed to attach dma_buf, ret[%d]\n", ret);
 		goto err_get_attach;
 	}
 
 	sgt = dma_buf_map_attachment(attach, dir);
 	if (IS_ERR(sgt)) {
-		pr_err("Failed to map src attachment\n");
-		ret = -EINVAL;
+		ret = PTR_ERR(sgt);
+		pr_err("Failed to map attachment, ret[%d]\n", ret);
 		goto err_get_sgt;
 	}
 
@@ -474,22 +475,22 @@
 
 	dma_buf = dma_buf_get(fd);
 	if (IS_ERR(dma_buf)) {
-		pr_err("dma_buf_get fail fd[%d]\n", fd);
-		ret = -EINVAL;
+		ret = PTR_ERR(dma_buf);
+		pr_err("Fail to get dma_buf from fd[%d], ret[%d]\n", fd, ret);
 		return ret;
 	}
 
 	attach = dma_buf_attach(dma_buf, rga_dev);
 	if (IS_ERR(attach)) {
-		pr_err("Failed to attach dma_buf\n");
-		ret = -EINVAL;
+		ret = PTR_ERR(attach);
+		pr_err("Failed to attach dma_buf, ret[%d]\n", ret);
 		goto err_get_attach;
 	}
 
 	sgt = dma_buf_map_attachment(attach, dir);
 	if (IS_ERR(sgt)) {
-		pr_err("Failed to map src attachment\n");
-		ret = -EINVAL;
+		ret = PTR_ERR(sgt);
+		pr_err("Failed to map attachment, ret[%d]\n", ret);
 		goto err_get_sgt;
 	}
 

--
Gitblit v1.6.2