diff --git a/target/linux/rockchip/patches-6.6/803-dma-heap-track-device.patch b/target/linux/rockchip/patches-6.6/803-dma-heap-track-device.patch new file mode 100644 index 0000000000..3fe762f3a4 --- /dev/null +++ b/target/linux/rockchip/patches-6.6/803-dma-heap-track-device.patch @@ -0,0 +1,113 @@ +From dbc83cb984d0e9d10892e52b7342c3687bf7a62c Mon Sep 17 00:00:00 2001 +From: John Stultz +Date: Thu, 7 May 2020 20:08:13 +0000 +Subject: [PATCH] FROMLIST: dma-buf: dma-heap: Keep track of the heap device + struct + +Keep track of the heap device struct. + +This will be useful for special DMA allocations +and actions. + +Signed-off-by: John Stultz +Link: https://lore.kernel.org/lkml/20201110034934.70898-7-john.stultz@linaro.org/ +Bug: 170887642 +Change-Id: I55b8df5fd9fd46795a8f0171318895297d2dd379 +Signed-off-by: Hridya Valsaraju +(cherry picked from commit 2501fd6245d8a1a408c7871c0fc8eb9e0116c944) +Signed-off-by: Palmer Dabbelt +--- + drivers/dma-buf/dma-heap.c | 24 ++++++++++++++++++++---- + include/linux/dma-heap.h | 9 +++++++++ + 2 files changed, 29 insertions(+), 4 deletions(-) + +diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c +index 84ae708fa..ec4414894 100644 +--- a/drivers/dma-buf/dma-heap.c ++++ b/drivers/dma-buf/dma-heap.c +@@ -31,6 +31,7 @@ + * @heap_devt heap device node + * @list list head connecting to list of heaps + * @heap_cdev heap char device ++ * @heap_dev heap device struct + * + * Represents a heap of memory from which buffers can be made. + */ +@@ -41,6 +42,7 @@ struct dma_heap { + dev_t heap_devt; + struct list_head list; + struct cdev heap_cdev; ++ struct device *heap_dev; + }; + + static LIST_HEAD(heap_list); +@@ -216,10 +218,21 @@ const char *dma_heap_get_name(struct dma_heap *heap) + return heap->name; + } + ++/** ++ * dma_heap_get_dev() - get device struct for the heap ++ * @heap: DMA-Heap to retrieve device struct from ++ * ++ * Returns: ++ * The device struct for the heap. ++ */ ++struct device *dma_heap_get_dev(struct dma_heap *heap) ++{ ++ return heap->heap_dev; ++} ++ + struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) + { + struct dma_heap *heap, *h, *err_ret; +- struct device *dev_ret; + unsigned int minor; + int ret; + +@@ -261,17 +274,20 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info) + goto err1; + } + +- dev_ret = device_create(dma_heap_class, ++ heap->heap_dev = device_create(dma_heap_class, + NULL, + heap->heap_devt, + NULL, + heap->name); +- if (IS_ERR(dev_ret)) { ++ if (IS_ERR(heap->heap_dev)) { + pr_err("dma_heap: Unable to create device\n"); +- err_ret = ERR_CAST(dev_ret); ++ err_ret = ERR_CAST(heap->heap_dev); + goto err2; + } + ++ /* Make sure it doesn't disappear on us */ ++ heap->heap_dev = get_device(heap->heap_dev); ++ + mutex_lock(&heap_list_lock); + /* check the name is unique */ + list_for_each_entry(h, &heap_list, list) { +diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h +index 0c05561ca..ca83d0e7f 100644 +--- a/include/linux/dma-heap.h ++++ b/include/linux/dma-heap.h +@@ -59,6 +59,15 @@ void *dma_heap_get_drvdata(struct dma_heap *heap); + */ + const char *dma_heap_get_name(struct dma_heap *heap); + ++/** ++ * dma_heap_get_dev() - get device struct for the heap ++ * @heap: DMA-Heap to retrieve device struct from ++ * ++ * Returns: ++ * The device struct for the heap. ++ */ ++struct device *dma_heap_get_dev(struct dma_heap *heap); ++ + /** + * dma_heap_add - adds a heap to dmabuf heaps + * @exp_info: information needed to register this heap +-- +2.46.0 + diff --git a/target/linux/rockchip/patches-6.6/804-1-dma-heap-fix-rk-heaps-build.patch b/target/linux/rockchip/patches-6.6/804-1-dma-heap-fix-rk-heaps-build.patch new file mode 100644 index 0000000000..60c87df2b0 --- /dev/null +++ b/target/linux/rockchip/patches-6.6/804-1-dma-heap-fix-rk-heaps-build.patch @@ -0,0 +1,149 @@ +From d9acd0718ccf0c455b73cf44d2a0fb805c520fe7 Mon Sep 17 00:00:00 2001 +From: jjm2473 +Date: Wed, 19 Mar 2025 12:47:47 +0800 +Subject: [PATCH] dma_buf/heaps: fix rk heaps build + +--- + drivers/dma-buf/heaps/rk_cma_heap.c | 8 ++++---- + drivers/dma-buf/heaps/rk_system_heap.c | 22 +++++++++++++++------- + 2 files changed, 19 insertions(+), 11 deletions(-) + +diff --git a/drivers/dma-buf/heaps/rk_cma_heap.c b/drivers/dma-buf/heaps/rk_cma_heap.c +index 5d8581f53..3e9ae0fda 100644 +--- a/drivers/dma-buf/heaps/rk_cma_heap.c ++++ b/drivers/dma-buf/heaps/rk_cma_heap.c +@@ -107,7 +107,7 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme + { + struct dma_heap_attachment *a = attachment->priv; + struct sg_table *table = &a->table; +- int attrs = attachment->dma_map_attrs; ++ int attrs = 0; //attachment->dma_map_attrs; + int ret; + + if (a->uncached) +@@ -125,7 +125,7 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, + enum dma_data_direction direction) + { + struct dma_heap_attachment *a = attachment->priv; +- int attrs = attachment->dma_map_attrs; ++ int attrs = 0; //attachment->dma_map_attrs; + + a->mapped = false; + +@@ -595,11 +595,11 @@ static int __add_cma_heap(struct cma *cma, void *data) + return 0; + + put_uncached_cma_heap: +- dma_heap_put(cma_uncached_heap->heap); ++ //dma_heap_put(cma_uncached_heap->heap); + free_uncached_cma_heap: + kfree(cma_uncached_heap); + put_cma_heap: +- dma_heap_put(cma_heap->heap); ++ //dma_heap_put(cma_heap->heap); + free_cma_heap: + kfree(cma_heap); + +diff --git a/drivers/dma-buf/heaps/rk_system_heap.c b/drivers/dma-buf/heaps/rk_system_heap.c +index 91b682805..35b7b12e9 100644 +--- a/drivers/dma-buf/heaps/rk_system_heap.c ++++ b/drivers/dma-buf/heaps/rk_system_heap.c +@@ -22,9 +22,12 @@ + #include + #include + #include ++#if IS_REACHABLE(CONFIG_ROCKCHIP_SIP) + #include ++#endif ++#if defined(CONFIG_CPU_RK3568) + #include +- ++#endif + #include "page_pool.h" + + static struct dma_heap *sys_heap; +@@ -150,7 +153,7 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac + { + struct dma_heap_attachment *a = attachment->priv; + struct sg_table *table = a->table; +- int attr = attachment->dma_map_attrs; ++ int attr = 0; // attachment->dma_map_attrs; + int ret; + + if (a->uncached) +@@ -169,7 +172,7 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, + enum dma_data_direction direction) + { + struct dma_heap_attachment *a = attachment->priv; +- int attr = attachment->dma_map_attrs; ++ int attr = 0; // attachment->dma_map_attrs; + + if (a->uncached) + attr |= DMA_ATTR_SKIP_CPU_SYNC; +@@ -644,6 +647,7 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, + return system_heap_do_allocate(heap, len, fd_flags, heap_flags, false, soc_need_dma32); + } + ++/* + static long system_get_pool_size(struct dma_heap *heap) + { + unsigned long num_bytes = 0; +@@ -655,10 +659,11 @@ static long system_get_pool_size(struct dma_heap *heap) + + return num_bytes; + } ++*/ + + static const struct dma_heap_ops system_heap_ops = { + .allocate = system_heap_allocate, +- .get_pool_size = system_get_pool_size, ++ //.get_pool_size = system_get_pool_size, + }; + + static struct dma_buf *system_heap_dma32_allocate(struct dma_heap *heap, +@@ -671,7 +676,7 @@ static struct dma_buf *system_heap_dma32_allocate(struct dma_heap *heap, + + static const struct dma_heap_ops system_dma32_heap_ops = { + .allocate = system_heap_dma32_allocate, +- .get_pool_size = system_get_pool_size, ++ //.get_pool_size = system_get_pool_size, + }; + + static struct dma_buf *system_uncached_heap_allocate(struct dma_heap *heap, +@@ -739,8 +744,9 @@ static int system_heap_create(void) + { + struct dma_heap_export_info exp_info; + int i, err = 0; ++#if IS_REACHABLE(CONFIG_ROCKCHIP_SIP) + struct dram_addrmap_info *ddr_map_info; +- ++#endif + /* + * Since swiotlb has memory size limitation, this will calculate + * the maximum size locally. +@@ -751,7 +757,7 @@ static int system_heap_create(void) + * + * FIX: fix the orders[] as a workaround. + */ +- if (swiotlb_max_segment()) { ++ if (is_swiotlb_allocated()) { + unsigned int max_size = (1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; + int max_order = MAX_ORDER; + int i; +@@ -841,11 +847,13 @@ static int system_heap_create(void) + system_uncached_heap_ops.allocate = system_uncached_heap_allocate; + system_uncached_dma32_heap_ops.allocate = system_uncached_heap_dma32_allocate; + ++#if IS_REACHABLE(CONFIG_ROCKCHIP_SIP) + ddr_map_info = sip_smc_get_dram_map(); + if (ddr_map_info) { + bank_bit_first = ddr_map_info->bank_bit_first; + bank_bit_mask = ddr_map_info->bank_bit_mask; + } ++#endif + + return 0; + err_dma32_pool: +-- +2.46.0 + diff --git a/target/linux/rockchip/patches-6.6/804-2-dma-heaps-switch-to-rk-heaps.patch b/target/linux/rockchip/patches-6.6/804-2-dma-heaps-switch-to-rk-heaps.patch new file mode 100644 index 0000000000..1b0bf7d86d --- /dev/null +++ b/target/linux/rockchip/patches-6.6/804-2-dma-heaps-switch-to-rk-heaps.patch @@ -0,0 +1,29 @@ +From a850eac461f879fd1b506872194c9305b5e40726 Mon Sep 17 00:00:00 2001 +From: jjm2473 +Date: Wed, 19 Mar 2025 13:23:59 +0800 +Subject: [PATCH] dma_buf/heaps: switch to rk heaps + +--- + drivers/dma-buf/heaps/Makefile | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/drivers/dma-buf/heaps/Makefile b/drivers/dma-buf/heaps/Makefile +index ba782394f..ee9a10fbe 100644 +--- a/drivers/dma-buf/heaps/Makefile ++++ b/drivers/dma-buf/heaps/Makefile +@@ -1,8 +1,8 @@ + # SPDX-License-Identifier: GPL-2.0 + ifeq ($(CONFIG_DMA_SHARED_BUFFER),y) +-obj-$(CONFIG_DMABUF_HEAPS_SYSTEM) += system_heap.o +-obj-$(CONFIG_DMABUF_HEAPS_CMA) += cma_heap.o ++obj-$(CONFIG_DMABUF_HEAPS_SYSTEM) += rk_system_heap.o page_pool.o ++obj-$(CONFIG_DMABUF_HEAPS_CMA) += rk_cma_heap.o + else +-dma-buf-objs-$(CONFIG_DMABUF_HEAPS_SYSTEM) += system_heap.o +-dma-buf-objs-$(CONFIG_DMABUF_HEAPS_CMA) += cma_heap.o ++dma-buf-objs-$(CONFIG_DMABUF_HEAPS_SYSTEM) += rk_system_heap.o page_pool.o ++dma-buf-objs-$(CONFIG_DMABUF_HEAPS_CMA) += rk_cma_heap.o + endif +-- +2.46.0 +