Commit 27e2e9b9 authored by Marek Szyprowski's avatar Marek Szyprowski
Browse files

Merge branch 'dma-contig-for-7.1-modules-prep-v4' into dma-mapping-for-next

parents ed734125 7e72a8f8
Loading
Loading
Loading
Loading
+2 −17
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@

#include <linux/cma.h>
#include <linux/dma-buf.h>
#include <linux/dma-buf/heaps/cma.h>
#include <linux/dma-heap.h>
#include <linux/dma-map-ops.h>
#include <linux/err.h>
@@ -30,19 +29,6 @@

#define DEFAULT_CMA_NAME "default_cma_region"

static struct cma *dma_areas[MAX_CMA_AREAS] __initdata;
static unsigned int dma_areas_num __initdata;

int __init dma_heap_cma_register_heap(struct cma *cma)
{
	if (dma_areas_num >= ARRAY_SIZE(dma_areas))
		return -EINVAL;

	dma_areas[dma_areas_num++] = cma;

	return 0;
}

struct cma_heap {
	struct dma_heap *heap;
	struct cma *cma;
@@ -414,6 +400,7 @@ static int __init __add_cma_heap(struct cma *cma, const char *name)
static int __init add_cma_heaps(void)
{
	struct cma *default_cma = dev_get_cma_area(NULL);
	struct cma *cma;
	unsigned int i;
	int ret;

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

	for (i = 0; i < dma_areas_num; i++) {
		struct cma *cma = dma_areas[i];

	for (i = 0; (cma = dma_contiguous_get_area_by_idx(i)) != NULL; i++) {
		ret = __add_cma_heap(cma, cma_get_name(cma));
		if (ret) {
			pr_warn("Failed to add CMA heap %s", cma_get_name(cma));

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

deleted100644 → 0
+0 −16
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef DMA_BUF_HEAP_CMA_H_
#define DMA_BUF_HEAP_CMA_H_

struct cma;

#ifdef CONFIG_DMABUF_HEAPS_CMA
int dma_heap_cma_register_heap(struct cma *cma);
#else
static inline int dma_heap_cma_register_heap(struct cma *cma)
{
	return 0;
}
#endif // CONFIG_DMABUF_HEAPS_CMA

#endif // DMA_BUF_HEAP_CMA_H_
+6 −8
Original line number Diff line number Diff line
@@ -91,14 +91,8 @@ static inline void set_dma_ops(struct device *dev,
#endif /* CONFIG_ARCH_HAS_DMA_OPS */

#ifdef CONFIG_DMA_CMA
extern struct cma *dma_contiguous_default_area;

static inline struct cma *dev_get_cma_area(struct device *dev)
{
	if (dev && dev->cma_area)
		return dev->cma_area;
	return dma_contiguous_default_area;
}
struct cma *dev_get_cma_area(struct device *dev);
struct cma *dma_contiguous_get_area_by_idx(unsigned int idx);

void dma_contiguous_reserve(phys_addr_t addr_limit);
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)
{
	return NULL;
}
static inline struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
{
	return NULL;
}
static inline void dma_contiguous_reserve(phys_addr_t limit)
{
}
+60 −6
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@
#include <linux/memblock.h>
#include <linux/err.h>
#include <linux/sizes.h>
#include <linux/dma-buf/heaps/cma.h>
#include <linux/dma-map-ops.h>
#include <linux/cma.h>
#include <linux/nospec.h>
@@ -53,7 +52,38 @@
#define CMA_SIZE_MBYTES 0
#endif

struct cma *dma_contiguous_default_area;
static struct cma *dma_contiguous_areas[MAX_CMA_AREAS];
static unsigned int dma_contiguous_areas_num;

static int dma_contiguous_insert_area(struct cma *cma)
{
	if (dma_contiguous_areas_num >= ARRAY_SIZE(dma_contiguous_areas))
		return -EINVAL;

	dma_contiguous_areas[dma_contiguous_areas_num++] = cma;

	return 0;
}

/**
 * dma_contiguous_get_area_by_idx() - Get contiguous area at given index
 * @idx: index of the area we query
 *
 * Queries for the contiguous area located at index @idx.
 *
 * Returns:
 * A pointer to the requested contiguous area, or NULL otherwise.
 */
struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
{
	if (idx >= dma_contiguous_areas_num)
		return NULL;

	return dma_contiguous_areas[idx];
}
EXPORT_SYMBOL_GPL(dma_contiguous_get_area_by_idx);

static struct cma *dma_contiguous_default_area;

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

struct cma *dev_get_cma_area(struct device *dev)
{
	if (dev && dev->cma_area)
		return dev->cma_area;

	return dma_contiguous_default_area;
}
EXPORT_SYMBOL_GPL(dev_get_cma_area);

#ifdef CONFIG_DMA_NUMA_CMA

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

		ret = dma_heap_cma_register_heap(dma_contiguous_default_area);
		/*
		 * We need to insert the new area in our list to avoid
		 * any inconsistencies between having the default area
		 * listed in the DT or not.
		 *
		 * The DT case is handled by rmem_cma_setup() and will
		 * always insert all its areas in our list. However, if
		 * it didn't run (because OF_RESERVED_MEM isn't set, or
		 * there's no DT region specified), then we don't have a
		 * default area yet, and no area in our list.
		 *
		 * This block creates the default area in such a case,
		 * but we also need to insert it in our list to avoid
		 * having a default area but an empty list.
		 */
		ret = dma_contiguous_insert_area(dma_contiguous_default_area);
		if (ret)
			pr_warn("Couldn't register default CMA heap.");
			pr_warn("Couldn't queue default CMA region for heap creation.");
	}
}

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

	ret = dma_heap_cma_register_heap(cma);
	ret = dma_contiguous_insert_area(cma);
	if (ret)
		pr_warn("Couldn't register CMA heap.");
		pr_warn("Couldn't store CMA reserved area.");

	return 0;
}
+3 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ const char *cma_get_name(const struct cma *cma)
{
	return cma->name;
}
EXPORT_SYMBOL_GPL(cma_get_name);

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

	return page;
}
EXPORT_SYMBOL_GPL(cma_alloc);

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

	return true;
}
EXPORT_SYMBOL_GPL(cma_release);

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