dma-contiguous: remove dma_contiguous_set_default
[linux-2.6-microblaze.git] / include / linux / dma-contiguous.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef __LINUX_CMA_H
3 #define __LINUX_CMA_H
4
5 /*
6  * Contiguous Memory Allocator for DMA mapping framework
7  * Copyright (c) 2010-2011 by Samsung Electronics.
8  * Written by:
9  *      Marek Szyprowski <m.szyprowski@samsung.com>
10  *      Michal Nazarewicz <mina86@mina86.com>
11  */
12
13 /*
14  * Contiguous Memory Allocator
15  *
16  *   The Contiguous Memory Allocator (CMA) makes it possible to
17  *   allocate big contiguous chunks of memory after the system has
18  *   booted.
19  *
20  * Why is it needed?
21  *
22  *   Various devices on embedded systems have no scatter-getter and/or
23  *   IO map support and require contiguous blocks of memory to
24  *   operate.  They include devices such as cameras, hardware video
25  *   coders, etc.
26  *
27  *   Such devices often require big memory buffers (a full HD frame
28  *   is, for instance, more then 2 mega pixels large, i.e. more than 6
29  *   MB of memory), which makes mechanisms such as kmalloc() or
30  *   alloc_page() ineffective.
31  *
32  *   At the same time, a solution where a big memory region is
33  *   reserved for a device is suboptimal since often more memory is
34  *   reserved then strictly required and, moreover, the memory is
35  *   inaccessible to page system even if device drivers don't use it.
36  *
37  *   CMA tries to solve this issue by operating on memory regions
38  *   where only movable pages can be allocated from.  This way, kernel
39  *   can use the memory for pagecache and when device driver requests
40  *   it, allocated pages can be migrated.
41  *
42  * Driver usage
43  *
44  *   CMA should not be used by the device drivers directly. It is
45  *   only a helper framework for dma-mapping subsystem.
46  *
47  *   For more information, see kernel-docs in kernel/dma/contiguous.c
48  */
49
50 #ifdef __KERNEL__
51
52 #include <linux/device.h>
53 #include <linux/mm.h>
54
55 struct cma;
56 struct page;
57
58 #ifdef CONFIG_DMA_CMA
59
60 extern struct cma *dma_contiguous_default_area;
61
62 static inline struct cma *dev_get_cma_area(struct device *dev)
63 {
64         if (dev && dev->cma_area)
65                 return dev->cma_area;
66         return dma_contiguous_default_area;
67 }
68
69 void dma_contiguous_reserve(phys_addr_t addr_limit);
70
71 int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
72                                        phys_addr_t limit, struct cma **res_cma,
73                                        bool fixed);
74
75 struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
76                                        unsigned int order, bool no_warn);
77 bool dma_release_from_contiguous(struct device *dev, struct page *pages,
78                                  int count);
79 struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp);
80 void dma_free_contiguous(struct device *dev, struct page *page, size_t size);
81
82 #else
83
84 static inline struct cma *dev_get_cma_area(struct device *dev)
85 {
86         return NULL;
87 }
88
89 static inline void dma_contiguous_reserve(phys_addr_t limit) { }
90
91 static inline int dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
92                                        phys_addr_t limit, struct cma **res_cma,
93                                        bool fixed)
94 {
95         return -ENOSYS;
96 }
97
98 static inline
99 struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
100                                        unsigned int order, bool no_warn)
101 {
102         return NULL;
103 }
104
105 static inline
106 bool dma_release_from_contiguous(struct device *dev, struct page *pages,
107                                  int count)
108 {
109         return false;
110 }
111
112 /* Use fallback alloc() and free() when CONFIG_DMA_CMA=n */
113 static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
114                 gfp_t gfp)
115 {
116         return NULL;
117 }
118
119 static inline void dma_free_contiguous(struct device *dev, struct page *page,
120                 size_t size)
121 {
122         __free_pages(page, get_order(size));
123 }
124
125 #endif
126
127 #ifdef CONFIG_DMA_PERNUMA_CMA
128 void dma_pernuma_cma_reserve(void);
129 #else
130 static inline void dma_pernuma_cma_reserve(void) { }
131 #endif
132
133 #endif
134
135 #endif