summaryrefslogtreecommitdiffstats
path: root/include/linux/dma-contiguous.h
diff options
context:
space:
mode:
authorNicolin Chen2019-05-24 06:06:32 +0200
committerChristoph Hellwig2019-06-03 16:00:07 +0200
commitb1d2dc009dece4cd7e629419b52266ba51960a6b (patch)
treea31a473e64a10c54420e767337fd288753b7d6e3 /include/linux/dma-contiguous.h
parentiommu/dma: Fix condition check in iommu_dma_unmap_sg (diff)
downloadkernel-qcow2-linux-b1d2dc009dece4cd7e629419b52266ba51960a6b.tar.gz
kernel-qcow2-linux-b1d2dc009dece4cd7e629419b52266ba51960a6b.tar.xz
kernel-qcow2-linux-b1d2dc009dece4cd7e629419b52266ba51960a6b.zip
dma-contiguous: add dma_{alloc,free}_contiguous() helpers
Both dma_alloc_from_contiguous() and dma_release_from_contiguous() are very simply implemented, but requiring callers to pass certain parameters like count and align, and taking a boolean parameter to check __GFP_NOWARN in the allocation flags. So every function call duplicates similar work: unsigned long order = get_order(size); size_t count = size >> PAGE_SHIFT; page = dma_alloc_from_contiguous(dev, count, order, gfp & __GFP_NOWARN); [...] dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT); Additionally, as CMA can be used only in the context which permits sleeping, most of callers do a gfpflags_allow_blocking() check and a corresponding fallback allocation of normal pages upon any false result: if (gfpflags_allow_blocking(flag)) page = dma_alloc_from_contiguous(); if (!page) page = alloc_pages(); [...] if (!dma_release_from_contiguous(dev, page, count)) __free_pages(page, get_order(size)); So this patch simplifies those function calls by abstracting these operations into the two new functions: dma_{alloc,free}_contiguous. As some callers of dma_{alloc,release}_from_contiguous() might be complicated, this patch just implements these two new functions to kernel/dma/direct.c only as an initial step. Suggested-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Tested-by: dann frazier <dann.frazier@canonical.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'include/linux/dma-contiguous.h')
-rw-r--r--include/linux/dma-contiguous.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/dma-contiguous.h b/include/linux/dma-contiguous.h
index 6665fa03c0d1..428f3b7b1c42 100644
--- a/include/linux/dma-contiguous.h
+++ b/include/linux/dma-contiguous.h
@@ -111,6 +111,8 @@ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
unsigned int order, bool no_warn);
bool dma_release_from_contiguous(struct device *dev, struct page *pages,
int count);
+struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp);
+void dma_free_contiguous(struct device *dev, struct page *page, size_t size);
#else
@@ -153,6 +155,17 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
return false;
}
+static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
+ gfp_t gfp)
+{
+ return NULL;
+}
+
+static inline void dma_free_contiguous(struct device *dev, struct page *page,
+ size_t size)
+{
+}
+
#endif
#endif