Skip to content

Commit

Permalink
drivers: k230: Modify the vpu memory allocation area to cma
Browse files Browse the repository at this point in the history
Signed-off-by: wycwyhwyq <[email protected]>
  • Loading branch information
wycwyhwyq authored and RevySR committed Oct 18, 2024
1 parent a597154 commit 3c3f406
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions drivers/media/platform/canaan/vpu/mvx_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/debugfs.h>
#include <linux/dma-buf.h>
#include <linux/dma-mapping.h>
#include <linux/dma-map-ops.h>
#include <linux/gfp.h>
#include <linux/list.h>
#include <linux/sched.h>
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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)
Expand All @@ -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;

Expand All @@ -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;
}

Expand All @@ -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,
Expand Down

0 comments on commit 3c3f406

Please sign in to comment.