OpenCloudOS-Kernel/kernel/dma
Nicolin Chen b1d2dc009d 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>
2019-06-03 16:00:07 +02:00
..
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile dma-mapping: improve selection of dma_declare_coherent availability 2019-02-20 07:26:35 -07:00
coherent.c dma-mapping: remove the DMA_MEMORY_EXCLUSIVE flag 2019-02-20 07:27:00 -07:00
contiguous.c dma-contiguous: add dma_{alloc,free}_contiguous() helpers 2019-06-03 16:00:07 +02:00
debug.c dma/debug: Simplify stracktrace retrieval 2019-04-29 12:37:50 +02:00
direct.c dma-contiguous: add dma_{alloc,free}_contiguous() helpers 2019-06-03 16:00:07 +02:00
dummy.c dma-mapping: factor out dummy DMA ops 2018-12-13 21:06:12 +01:00
mapping.c dma-mapping: remove an unnecessary NULL check 2019-04-24 16:28:13 +02:00
remap.c dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING for remapped allocations 2019-01-05 08:28:29 +01:00
swiotlb.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
virt.c dma-mapping: zero memory returned from dma_alloc_* 2018-12-20 08:13:52 +01:00