Skip to content

Commit 27e2e9b

Browse files
committed
Merge branch 'dma-contig-for-7.1-modules-prep-v4' into dma-mapping-for-next
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
2 parents ed73412 + 7e72a8f commit 27e2e9b

5 files changed

Lines changed: 71 additions & 47 deletions

File tree

drivers/dma-buf/heaps/cma_heap.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <linux/cma.h>
1616
#include <linux/dma-buf.h>
17-
#include <linux/dma-buf/heaps/cma.h>
1817
#include <linux/dma-heap.h>
1918
#include <linux/dma-map-ops.h>
2019
#include <linux/err.h>
@@ -30,19 +29,6 @@
3029

3130
#define DEFAULT_CMA_NAME "default_cma_region"
3231

33-
static struct cma *dma_areas[MAX_CMA_AREAS] __initdata;
34-
static unsigned int dma_areas_num __initdata;
35-
36-
int __init dma_heap_cma_register_heap(struct cma *cma)
37-
{
38-
if (dma_areas_num >= ARRAY_SIZE(dma_areas))
39-
return -EINVAL;
40-
41-
dma_areas[dma_areas_num++] = cma;
42-
43-
return 0;
44-
}
45-
4632
struct cma_heap {
4733
struct dma_heap *heap;
4834
struct cma *cma;
@@ -414,6 +400,7 @@ static int __init __add_cma_heap(struct cma *cma, const char *name)
414400
static int __init add_cma_heaps(void)
415401
{
416402
struct cma *default_cma = dev_get_cma_area(NULL);
403+
struct cma *cma;
417404
unsigned int i;
418405
int ret;
419406

@@ -423,9 +410,7 @@ static int __init add_cma_heaps(void)
423410
return ret;
424411
}
425412

426-
for (i = 0; i < dma_areas_num; i++) {
427-
struct cma *cma = dma_areas[i];
428-
413+
for (i = 0; (cma = dma_contiguous_get_area_by_idx(i)) != NULL; i++) {
429414
ret = __add_cma_heap(cma, cma_get_name(cma));
430415
if (ret) {
431416
pr_warn("Failed to add CMA heap %s", cma_get_name(cma));

include/linux/dma-buf/heaps/cma.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

include/linux/dma-map-ops.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,8 @@ static inline void set_dma_ops(struct device *dev,
9191
#endif /* CONFIG_ARCH_HAS_DMA_OPS */
9292

9393
#ifdef CONFIG_DMA_CMA
94-
extern struct cma *dma_contiguous_default_area;
95-
96-
static inline struct cma *dev_get_cma_area(struct device *dev)
97-
{
98-
if (dev && dev->cma_area)
99-
return dev->cma_area;
100-
return dma_contiguous_default_area;
101-
}
94+
struct cma *dev_get_cma_area(struct device *dev);
95+
struct cma *dma_contiguous_get_area_by_idx(unsigned int idx);
10296

10397
void dma_contiguous_reserve(phys_addr_t addr_limit);
10498
int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
@@ -117,6 +111,10 @@ static inline struct cma *dev_get_cma_area(struct device *dev)
117111
{
118112
return NULL;
119113
}
114+
static inline struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
115+
{
116+
return NULL;
117+
}
120118
static inline void dma_contiguous_reserve(phys_addr_t limit)
121119
{
122120
}

kernel/dma/contiguous.c

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include <linux/memblock.h>
4343
#include <linux/err.h>
4444
#include <linux/sizes.h>
45-
#include <linux/dma-buf/heaps/cma.h>
4645
#include <linux/dma-map-ops.h>
4746
#include <linux/cma.h>
4847
#include <linux/nospec.h>
@@ -53,7 +52,38 @@
5352
#define CMA_SIZE_MBYTES 0
5453
#endif
5554

56-
struct cma *dma_contiguous_default_area;
55+
static struct cma *dma_contiguous_areas[MAX_CMA_AREAS];
56+
static unsigned int dma_contiguous_areas_num;
57+
58+
static int dma_contiguous_insert_area(struct cma *cma)
59+
{
60+
if (dma_contiguous_areas_num >= ARRAY_SIZE(dma_contiguous_areas))
61+
return -EINVAL;
62+
63+
dma_contiguous_areas[dma_contiguous_areas_num++] = cma;
64+
65+
return 0;
66+
}
67+
68+
/**
69+
* dma_contiguous_get_area_by_idx() - Get contiguous area at given index
70+
* @idx: index of the area we query
71+
*
72+
* Queries for the contiguous area located at index @idx.
73+
*
74+
* Returns:
75+
* A pointer to the requested contiguous area, or NULL otherwise.
76+
*/
77+
struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
78+
{
79+
if (idx >= dma_contiguous_areas_num)
80+
return NULL;
81+
82+
return dma_contiguous_areas[idx];
83+
}
84+
EXPORT_SYMBOL_GPL(dma_contiguous_get_area_by_idx);
85+
86+
static struct cma *dma_contiguous_default_area;
5787

5888
/*
5989
* Default global CMA area size can be defined in kernel's .config.
@@ -91,6 +121,15 @@ static int __init early_cma(char *p)
91121
}
92122
early_param("cma", early_cma);
93123

124+
struct cma *dev_get_cma_area(struct device *dev)
125+
{
126+
if (dev && dev->cma_area)
127+
return dev->cma_area;
128+
129+
return dma_contiguous_default_area;
130+
}
131+
EXPORT_SYMBOL_GPL(dev_get_cma_area);
132+
94133
#ifdef CONFIG_DMA_NUMA_CMA
95134

96135
static struct cma *dma_contiguous_numa_area[MAX_NUMNODES];
@@ -254,9 +293,24 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
254293
if (ret)
255294
return;
256295

257-
ret = dma_heap_cma_register_heap(dma_contiguous_default_area);
296+
/*
297+
* We need to insert the new area in our list to avoid
298+
* any inconsistencies between having the default area
299+
* listed in the DT or not.
300+
*
301+
* The DT case is handled by rmem_cma_setup() and will
302+
* always insert all its areas in our list. However, if
303+
* it didn't run (because OF_RESERVED_MEM isn't set, or
304+
* there's no DT region specified), then we don't have a
305+
* default area yet, and no area in our list.
306+
*
307+
* This block creates the default area in such a case,
308+
* but we also need to insert it in our list to avoid
309+
* having a default area but an empty list.
310+
*/
311+
ret = dma_contiguous_insert_area(dma_contiguous_default_area);
258312
if (ret)
259-
pr_warn("Couldn't register default CMA heap.");
313+
pr_warn("Couldn't queue default CMA region for heap creation.");
260314
}
261315
}
262316

@@ -529,9 +583,9 @@ static int __init rmem_cma_setup(unsigned long node, struct reserved_mem *rmem)
529583
pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n",
530584
&rmem->base, (unsigned long)rmem->size / SZ_1M);
531585

532-
ret = dma_heap_cma_register_heap(cma);
586+
ret = dma_contiguous_insert_area(cma);
533587
if (ret)
534-
pr_warn("Couldn't register CMA heap.");
588+
pr_warn("Couldn't store CMA reserved area.");
535589

536590
return 0;
537591
}

mm/cma.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const char *cma_get_name(const struct cma *cma)
5252
{
5353
return cma->name;
5454
}
55+
EXPORT_SYMBOL_GPL(cma_get_name);
5556

5657
static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
5758
unsigned int align_order)
@@ -951,6 +952,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
951952

952953
return page;
953954
}
955+
EXPORT_SYMBOL_GPL(cma_alloc);
954956

955957
static struct cma_memrange *find_cma_memrange(struct cma *cma,
956958
const struct page *pages, unsigned long count)
@@ -1027,6 +1029,7 @@ bool cma_release(struct cma *cma, const struct page *pages,
10271029

10281030
return true;
10291031
}
1032+
EXPORT_SYMBOL_GPL(cma_release);
10301033

10311034
bool cma_release_frozen(struct cma *cma, const struct page *pages,
10321035
unsigned long count)

0 commit comments

Comments
 (0)