blob: 4f7caa87bca98fd8b97c195519e8f02472adedd7 [file] [log] [blame]
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -08001/*
2 * drivers/staging/android/ion/ion_heap.c
3 *
4 * Copyright (C) 2011 Google, 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 "ion.h"
19#include "ion_priv.h"
20
21struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data)
22{
23 struct ion_heap *heap = NULL;
24
25 switch (heap_data->type) {
26 case ION_HEAP_TYPE_SYSTEM_CONTIG:
27 heap = ion_system_contig_heap_create(heap_data);
28 break;
29 case ION_HEAP_TYPE_SYSTEM:
30 heap = ion_system_heap_create(heap_data);
31 break;
32 case ION_HEAP_TYPE_CARVEOUT:
33 heap = ion_carveout_heap_create(heap_data);
34 break;
35 default:
36 pr_err("%s: Invalid heap type %d\n", __func__,
37 heap_data->type);
38 return ERR_PTR(-EINVAL);
39 }
40
41 if (IS_ERR_OR_NULL(heap)) {
42 pr_err("%s: error creating heap %s type %d base %lu size %u\n",
43 __func__, heap_data->name, heap_data->type,
44 heap_data->base, heap_data->size);
45 return ERR_PTR(-EINVAL);
46 }
47
48 heap->name = heap_data->name;
49 heap->id = heap_data->id;
50 return heap;
51}
52
53void ion_heap_destroy(struct ion_heap *heap)
54{
55 if (!heap)
56 return;
57
58 switch (heap->type) {
59 case ION_HEAP_TYPE_SYSTEM_CONTIG:
60 ion_system_contig_heap_destroy(heap);
61 break;
62 case ION_HEAP_TYPE_SYSTEM:
63 ion_system_heap_destroy(heap);
64 break;
65 case ION_HEAP_TYPE_CARVEOUT:
66 ion_carveout_heap_destroy(heap);
67 break;
68 default:
69 pr_err("%s: Invalid heap type %d\n", __func__,
70 heap->type);
71 }
72}