From 3c3f4061b727e6d0e2293357a7475b578d688d92 Mon Sep 17 00:00:00 2001 From: wycwyhwyq <5f20.6d9b@gmail.com> Date: Thu, 17 Oct 2024 18:28:16 +0800 Subject: [PATCH] drivers: k230: Modify the vpu memory allocation area to cma Signed-off-by: wycwyhwyq <5f20.6d9b@gmail.com> --- drivers/media/platform/canaan/vpu/mvx_mmu.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/canaan/vpu/mvx_mmu.c b/drivers/media/platform/canaan/vpu/mvx_mmu.c index 4ec7d5c8be939..622597973d6bd 100644 --- a/drivers/media/platform/canaan/vpu/mvx_mmu.c +++ b/drivers/media/platform/canaan/vpu/mvx_mmu.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -615,7 +616,7 @@ phys_addr_t mvx_mmu_alloc_page(struct device *dev) phys_addr_t pa; dma_addr_t dma_handle; - page = alloc_page(GFP_KERNEL | __GFP_ZERO | __GFP_NORETRY); + page = dma_alloc_from_contiguous(dev, 1, 0, 0); if (page == NULL) return 0; @@ -628,13 +629,14 @@ phys_addr_t mvx_mmu_alloc_page(struct device *dev) } pa = (phys_addr_t)dma_handle; + memset(page_address(page), 0, PAGE_SIZE); dma_sync_single_for_device(dev, pa, PAGE_SIZE, DMA_TO_DEVICE); return pa; free_page: - __free_page(page); + dma_release_from_contiguous(dev, page, 1); return 0; } @@ -649,7 +651,7 @@ void mvx_mmu_free_contiguous_pages(struct device *dev, phys_addr_t pa, page = phys_to_page(pa); dma_unmap_page(dev, pa, npages << PAGE_SHIFT, DMA_BIDIRECTIONAL); - __free_pages(page, get_order(npages << PAGE_SHIFT)); + dma_release_from_contiguous(dev, page, npages); } phys_addr_t mvx_mmu_alloc_contiguous_pages(struct device *dev, size_t npages) @@ -659,8 +661,7 @@ phys_addr_t mvx_mmu_alloc_contiguous_pages(struct device *dev, size_t npages) dma_addr_t dma_handle; size_t size = (npages << PAGE_SHIFT); - page = alloc_pages(GFP_KERNEL | __GFP_ZERO | __GFP_NORETRY, - get_order(size)); + page = dma_alloc_from_contiguous(dev, npages, 0, 0); if (page == NULL) return 0; @@ -673,13 +674,14 @@ phys_addr_t mvx_mmu_alloc_contiguous_pages(struct device *dev, size_t npages) } pa = (phys_addr_t)dma_handle; + memset(page_address(page), 0, size); dma_sync_single_for_device(dev, pa, size, DMA_TO_DEVICE); return pa; free_pages: - __free_pages(page, get_order(size)); + dma_release_from_contiguous(dev, page, npages); return 0; } @@ -693,7 +695,7 @@ void mvx_mmu_free_page(struct device *dev, phys_addr_t pa) page = phys_to_page(pa); dma_unmap_page(dev, pa, PAGE_SIZE, DMA_BIDIRECTIONAL); - __free_page(page); + dma_release_from_contiguous(dev, page, 1); } struct mvx_mmu_pages *mvx_mmu_alloc_pages(struct device *dev, size_t count,