ion_dummy_driver.c revision 1184ead84d6c1019f5c1d31a73ef3bace90fb54a
1/*
2 * drivers/gpu/ion/ion_dummy_driver.c
3 *
4 * Copyright (C) 2013 Linaro, Inc
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/err.h>
18#include <linux/platform_device.h>
19#include <linux/slab.h>
20#include <linux/bootmem.h>
21#include <linux/memblock.h>
22#include <linux/sizes.h>
23#include "ion.h"
24#include "ion_priv.h"
25
26struct ion_device *idev;
27struct ion_heap **heaps;
28
29struct ion_platform_heap dummy_heaps[] = {
30		{
31			.id	= ION_HEAP_TYPE_SYSTEM,
32			.type	= ION_HEAP_TYPE_SYSTEM,
33			.name	= "system",
34		},
35		{
36			.id	= ION_HEAP_TYPE_SYSTEM_CONTIG,
37			.type	= ION_HEAP_TYPE_SYSTEM_CONTIG,
38			.name	= "system contig",
39		},
40};
41
42struct ion_platform_data dummy_ion_pdata = {
43	.nr = 2,
44	.heaps = dummy_heaps,
45};
46
47static int __init ion_dummy_init(void)
48{
49	int i, err;
50
51	idev = ion_device_create(NULL);
52	heaps = kzalloc(sizeof(struct ion_heap *) * dummy_ion_pdata.nr,
53			GFP_KERNEL);
54	if (!heaps)
55		return PTR_ERR(heaps);
56
57	for (i = 0; i < dummy_ion_pdata.nr; i++) {
58		struct ion_platform_heap *heap_data = &dummy_ion_pdata.heaps[i];
59
60		heaps[i] = ion_heap_create(heap_data);
61		if (IS_ERR_OR_NULL(heaps[i])) {
62			err = PTR_ERR(heaps[i]);
63			goto err;
64		}
65		ion_device_add_heap(idev, heaps[i]);
66	}
67	return 0;
68err:
69	for (i = 0; i < dummy_ion_pdata.nr; i++) {
70		if (heaps[i])
71			ion_heap_destroy(heaps[i]);
72	}
73	kfree(heaps);
74
75	return err;
76}
77
78static void __exit ion_dummy_exit(void)
79{
80	int i;
81
82	ion_device_destroy(idev);
83
84	for (i = 0; i < dummy_ion_pdata.nr; i++)
85		ion_heap_destroy(heaps[i]);
86	kfree(heaps);
87
88	return;
89}
90
91module_init(ion_dummy_init);
92module_exit(ion_dummy_exit);
93
94