2 * drivers/gpu/ion/ion_dummy_driver.c
4 * Copyright (C) 2013 Linaro, Inc
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.
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.
17 #include <linux/err.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
20 #include <linux/init.h>
21 #include <linux/bootmem.h>
22 #include <linux/memblock.h>
23 #include <linux/sizes.h>
28 static struct ion_device *idev;
29 static struct ion_heap **heaps;
31 static void *carveout_ptr;
32 static void *chunk_ptr;
34 static struct ion_platform_heap dummy_heaps[] = {
36 .id = ION_HEAP_TYPE_SYSTEM,
37 .type = ION_HEAP_TYPE_SYSTEM,
41 .id = ION_HEAP_TYPE_SYSTEM_CONTIG,
42 .type = ION_HEAP_TYPE_SYSTEM_CONTIG,
43 .name = "system contig",
46 .id = ION_HEAP_TYPE_CARVEOUT,
47 .type = ION_HEAP_TYPE_CARVEOUT,
52 .id = ION_HEAP_TYPE_CHUNK,
53 .type = ION_HEAP_TYPE_CHUNK,
57 .priv = (void *)(SZ_16K),
61 static struct ion_platform_data dummy_ion_pdata = {
62 .nr = ARRAY_SIZE(dummy_heaps),
66 static int __init ion_dummy_init(void)
70 idev = ion_device_create(NULL);
71 heaps = kcalloc(dummy_ion_pdata.nr, sizeof(struct ion_heap *),
77 /* Allocate a dummy carveout heap */
78 carveout_ptr = alloc_pages_exact(
79 dummy_heaps[ION_HEAP_TYPE_CARVEOUT].size,
82 dummy_heaps[ION_HEAP_TYPE_CARVEOUT].base =
83 virt_to_phys(carveout_ptr);
85 pr_err("ion_dummy: Could not allocate carveout\n");
87 /* Allocate a dummy chunk heap */
88 chunk_ptr = alloc_pages_exact(
89 dummy_heaps[ION_HEAP_TYPE_CHUNK].size,
92 dummy_heaps[ION_HEAP_TYPE_CHUNK].base = virt_to_phys(chunk_ptr);
94 pr_err("ion_dummy: Could not allocate chunk\n");
96 for (i = 0; i < dummy_ion_pdata.nr; i++) {
97 struct ion_platform_heap *heap_data = &dummy_ion_pdata.heaps[i];
99 if (heap_data->type == ION_HEAP_TYPE_CARVEOUT &&
103 if (heap_data->type == ION_HEAP_TYPE_CHUNK && !heap_data->base)
106 heaps[i] = ion_heap_create(heap_data);
107 if (IS_ERR_OR_NULL(heaps[i])) {
108 err = PTR_ERR(heaps[i]);
111 ion_device_add_heap(idev, heaps[i]);
115 for (i = 0; i < dummy_ion_pdata.nr; ++i)
116 ion_heap_destroy(heaps[i]);
120 free_pages_exact(carveout_ptr,
121 dummy_heaps[ION_HEAP_TYPE_CARVEOUT].size);
125 free_pages_exact(chunk_ptr,
126 dummy_heaps[ION_HEAP_TYPE_CHUNK].size);
131 device_initcall(ion_dummy_init);
133 static void __exit ion_dummy_exit(void)
137 ion_device_destroy(idev);
139 for (i = 0; i < dummy_ion_pdata.nr; i++)
140 ion_heap_destroy(heaps[i]);
144 free_pages_exact(carveout_ptr,
145 dummy_heaps[ION_HEAP_TYPE_CARVEOUT].size);
149 free_pages_exact(chunk_ptr,
150 dummy_heaps[ION_HEAP_TYPE_CHUNK].size);
154 __exitcall(ion_dummy_exit);