blob: 510b9ce50b516140d9e5904bb22f2c5e75e4509b [file] [log] [blame]
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07001/*
2 * drivers/gpu/ion/ion_heap.c
3 *
4 * Copyright (C) 2011 Google, Inc.
Laura Abbotta8c373f2013-02-15 09:25:35 -08005 * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07006 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/err.h>
19#include <linux/ion.h>
20#include "ion_priv.h"
21
22struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data)
23{
24 struct ion_heap *heap = NULL;
25
Laura Abbott3c6da802013-03-21 10:47:24 -070026 switch (heap_data->type) {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070027 case ION_HEAP_TYPE_SYSTEM_CONTIG:
28 heap = ion_system_contig_heap_create(heap_data);
29 break;
30 case ION_HEAP_TYPE_SYSTEM:
31 heap = ion_system_heap_create(heap_data);
32 break;
33 case ION_HEAP_TYPE_CARVEOUT:
34 heap = ion_carveout_heap_create(heap_data);
35 break;
36 default:
37 pr_err("%s: Invalid heap type %d\n", __func__,
38 heap_data->type);
39 return ERR_PTR(-EINVAL);
40 }
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090041
42 if (IS_ERR_OR_NULL(heap)) {
Laura Abbott1135c9e2013-03-13 15:33:40 -070043 pr_err("%s: error creating heap %s type %d base %pa size %u\n",
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070044 __func__, heap_data->name, heap_data->type,
Laura Abbott1135c9e2013-03-13 15:33:40 -070045 &heap_data->base, heap_data->size);
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090046 return ERR_PTR(-EINVAL);
47 }
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070048
49 heap->name = heap_data->name;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070050 heap->id = heap_data->id;
Benjamin Gaignard8dff0a62012-06-25 15:30:18 -070051 heap->priv = heap_data->priv;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070052 return heap;
53}
54
55void ion_heap_destroy(struct ion_heap *heap)
56{
57 if (!heap)
58 return;
59
Laura Abbott3c6da802013-03-21 10:47:24 -070060 switch (heap->type) {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070061 case ION_HEAP_TYPE_SYSTEM_CONTIG:
62 ion_system_contig_heap_destroy(heap);
63 break;
64 case ION_HEAP_TYPE_SYSTEM:
65 ion_system_heap_destroy(heap);
66 break;
67 case ION_HEAP_TYPE_CARVEOUT:
68 ion_carveout_heap_destroy(heap);
69 break;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070070 default:
71 pr_err("%s: Invalid heap type %d\n", __func__,
72 heap->type);
73 }
74}