Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: k230: Modify the vpu memory allocation area to cma #182

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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