Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a3d87671 authored by Sandeep Patil's avatar Sandeep Patil
Browse files

ANDROID: staging: ion: make cma heap a module



Add all cma areas that we can find as cma heaps.

Bug: 133508579
Test: build and insmod ion_cma_heap

Change-Id: I3cf1884c8d8914ae31d55e2f2770104347844036
Signed-off-by: default avatarSandeep Patil <sspatil@google.com>
parent 716306e8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ config ION_SYSTEM_CONTIG_HEAP
	  contiguous. If in doubt, say Y.

config ION_CMA_HEAP
	bool "Ion CMA heap support"
	tristate "Ion CMA heap support"
	depends on ION && DMA_CMA
	help
	  Choose this option to enable CMA heaps with Ion. This heap is backed
+35 −21
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
struct ion_cma_heap {
	struct ion_heap heap;
	struct cma *cma;
};
} cma_heaps[MAX_CMA_AREAS];

#define to_cma_heap(x) container_of(x, struct ion_cma_heap, heap)

@@ -97,38 +97,52 @@ static struct ion_heap_ops ion_cma_ops = {
	.free = ion_cma_free,
};

static struct ion_heap *__ion_cma_heap_create(struct cma *cma)
static int __ion_add_cma_heap(struct cma *cma, void *data)
{
	int *cma_nr = data;
	struct ion_cma_heap *cma_heap;
	int ret;

	cma_heap = kzalloc(sizeof(*cma_heap), GFP_KERNEL);

	if (!cma_heap)
		return ERR_PTR(-ENOMEM);
	if (*cma_nr >= MAX_CMA_AREAS)
		return -EINVAL;

	cma_heap = &cma_heaps[*cma_nr];
	cma_heap->heap.ops = &ion_cma_ops;
	cma_heap->cma = cma;
	cma_heap->heap.type = ION_HEAP_TYPE_DMA;
	return &cma_heap->heap;
	cma_heap->heap.name = cma_get_name(cma);

	ret = ion_device_add_heap(&cma_heap->heap);
	if (ret)
		goto out;

	cma_heap->cma = cma;
	*cma_nr += 1;
out:
	return 0;
}

static int __ion_add_cma_heaps(struct cma *cma, void *data)
static int __init ion_cma_heap_init(void)
{
	struct ion_heap *heap;

	heap = __ion_cma_heap_create(cma);
	if (IS_ERR(heap))
		return PTR_ERR(heap);
	int ret;
	int nr = 0;

	heap->name = cma_get_name(cma);
	ret = cma_for_each_area(__ion_add_cma_heap, &nr);
	if (ret) {
		for (nr = 0; nr < MAX_CMA_AREAS && cma_heaps[nr].cma; nr++)
			ion_device_remove_heap(&cma_heaps[nr].heap);
	}

	ion_device_add_heap(heap);
	return 0;
	return ret;
}

static int ion_add_cma_heaps(void)
static void __exit ion_cma_heap_exit(void)
{
	cma_for_each_area(__ion_add_cma_heaps, NULL);
	return 0;
	int nr;

	for (nr = 0; nr < MAX_CMA_AREAS && cma_heaps[nr].cma; nr++)
		ion_device_remove_heap(&cma_heaps[nr].heap);
}
device_initcall(ion_add_cma_heaps);

module_init(ion_cma_heap_init);
module_exit(ion_cma_heap_exit);
MODULE_LICENSE("GPL v2");