forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/video/rockchip/rga3/rga_dma_buf.c
....@@ -206,12 +206,11 @@
206206 struct rga_iommu_dma_cookie *cookie = domain->iova_cookie;
207207 struct iova_domain *iovad = &cookie->iovad;
208208 unsigned long shift, iova_len, iova = 0;
209
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
210
- dma_addr_t limit;
211
-#endif
212209
213210 shift = iova_shift(iovad);
214211 iova_len = size >> shift;
212
+
213
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
215214 /*
216215 * Freeing non-power-of-two-sized allocations back into the IOVA caches
217216 * will come back to bite us badly, so we have to waste a bit of space
....@@ -220,6 +219,7 @@
220219 */
221220 if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
222221 iova_len = roundup_pow_of_two(iova_len);
222
+#endif
223223
224224 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
225225 dma_limit = min_not_zero(dma_limit, dev->bus_dma_limit);
....@@ -231,12 +231,13 @@
231231 if (domain->geometry.force_aperture)
232232 dma_limit = min(dma_limit, (u64)domain->geometry.aperture_end);
233233
234
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0))
235
- iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift, true);
234
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(4, 19, 111) && \
235
+ LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
236
+ iova = alloc_iova_fast(iovad, iova_len,
237
+ min_t(dma_addr_t, dma_limit >> shift, iovad->end_pfn),
238
+ true);
236239 #else
237
- limit = min_t(dma_addr_t, dma_limit >> shift, iovad->end_pfn);
238
-
239
- iova = alloc_iova_fast(iovad, iova_len, limit, true);
240
+ iova = alloc_iova_fast(iovad, iova_len, dma_limit >> shift, true);
240241 #endif
241242
242243 return (dma_addr_t)iova << shift;
....@@ -424,21 +425,21 @@
424425 if (dma_buf != NULL) {
425426 get_dma_buf(dma_buf);
426427 } else {
427
- pr_err("dma_buf is Invalid[%p]\n", dma_buf);
428
+ pr_err("dma_buf is invalid[%p]\n", dma_buf);
428429 return -EINVAL;
429430 }
430431
431432 attach = dma_buf_attach(dma_buf, rga_dev);
432433 if (IS_ERR(attach)) {
433
- pr_err("Failed to attach dma_buf\n");
434
- ret = -EINVAL;
434
+ ret = PTR_ERR(attach);
435
+ pr_err("Failed to attach dma_buf, ret[%d]\n", ret);
435436 goto err_get_attach;
436437 }
437438
438439 sgt = dma_buf_map_attachment(attach, dir);
439440 if (IS_ERR(sgt)) {
440
- pr_err("Failed to map src attachment\n");
441
- ret = -EINVAL;
441
+ ret = PTR_ERR(sgt);
442
+ pr_err("Failed to map attachment, ret[%d]\n", ret);
442443 goto err_get_sgt;
443444 }
444445
....@@ -474,22 +475,22 @@
474475
475476 dma_buf = dma_buf_get(fd);
476477 if (IS_ERR(dma_buf)) {
477
- pr_err("dma_buf_get fail fd[%d]\n", fd);
478
- ret = -EINVAL;
478
+ ret = PTR_ERR(dma_buf);
479
+ pr_err("Fail to get dma_buf from fd[%d], ret[%d]\n", fd, ret);
479480 return ret;
480481 }
481482
482483 attach = dma_buf_attach(dma_buf, rga_dev);
483484 if (IS_ERR(attach)) {
484
- pr_err("Failed to attach dma_buf\n");
485
- ret = -EINVAL;
485
+ ret = PTR_ERR(attach);
486
+ pr_err("Failed to attach dma_buf, ret[%d]\n", ret);
486487 goto err_get_attach;
487488 }
488489
489490 sgt = dma_buf_map_attachment(attach, dir);
490491 if (IS_ERR(sgt)) {
491
- pr_err("Failed to map src attachment\n");
492
- ret = -EINVAL;
492
+ ret = PTR_ERR(sgt);
493
+ pr_err("Failed to map attachment, ret[%d]\n", ret);
493494 goto err_get_sgt;
494495 }
495496