summaryrefslogtreecommitdiffstats
path: root/include/linux/dma-contiguous.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/dma-contiguous.h')
-rw-r--r--include/linux/dma-contiguous.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/include/linux/dma-contiguous.h b/include/linux/dma-contiguous.h
index f247e8aa5e3d..c05d4e661489 100644
--- a/include/linux/dma-contiguous.h
+++ b/include/linux/dma-contiguous.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef __LINUX_CMA_H
#define __LINUX_CMA_H
@@ -7,11 +8,6 @@
* Written by:
* Marek Szyprowski <m.szyprowski@samsung.com>
* Michal Nazarewicz <mina86@mina86.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License or (at your optional) any later version of the license.
*/
/*
@@ -54,6 +50,7 @@
#ifdef __KERNEL__
#include <linux/device.h>
+#include <linux/mm.h>
struct cma;
struct page;
@@ -115,6 +112,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
@@ -157,6 +156,22 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
return false;
}
+/* Use fallback alloc() and free() when CONFIG_DMA_CMA=n */
+static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
+ gfp_t gfp)
+{
+ int node = dev ? dev_to_node(dev) : NUMA_NO_NODE;
+ size_t align = get_order(PAGE_ALIGN(size));
+
+ return alloc_pages_node(node, gfp, align);
+}
+
+static inline void dma_free_contiguous(struct device *dev, struct page *page,
+ size_t size)
+{
+ __free_pages(page, get_order(size));
+}
+
#endif
#endif