blob: 6ea49dbd0f6488c99434d78a0dfd10cd8fab0b0e [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.
Olav Haugan0a852512012-01-09 10:20:55 -08005 * Copyright (c) 2011-2012, Code Aurora Forum. 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
26 switch (heap_data->type) {
27 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;
Laura Abbott8c017362011-09-22 20:59:12 -070036 case ION_HEAP_TYPE_IOMMU:
37 heap = ion_iommu_heap_create(heap_data);
38 break;
Olav Haugan0a852512012-01-09 10:20:55 -080039 case ION_HEAP_TYPE_CP:
40 heap = ion_cp_heap_create(heap_data);
41 break;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070042 default:
43 pr_err("%s: Invalid heap type %d\n", __func__,
44 heap_data->type);
45 return ERR_PTR(-EINVAL);
46 }
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090047
48 if (IS_ERR_OR_NULL(heap)) {
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070049 pr_err("%s: error creating heap %s type %d base %lu size %u\n",
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070050 __func__, heap_data->name, heap_data->type,
51 heap_data->base, heap_data->size);
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090052 return ERR_PTR(-EINVAL);
53 }
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070054
55 heap->name = heap_data->name;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070056 heap->id = heap_data->id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070057 return heap;
58}
59
60void ion_heap_destroy(struct ion_heap *heap)
61{
62 if (!heap)
63 return;
64
65 switch (heap->type) {
66 case ION_HEAP_TYPE_SYSTEM_CONTIG:
67 ion_system_contig_heap_destroy(heap);
68 break;
69 case ION_HEAP_TYPE_SYSTEM:
70 ion_system_heap_destroy(heap);
71 break;
72 case ION_HEAP_TYPE_CARVEOUT:
73 ion_carveout_heap_destroy(heap);
74 break;
Olav Haugan5e560212011-12-13 14:57:57 -080075 case ION_HEAP_TYPE_IOMMU:
76 ion_iommu_heap_destroy(heap);
77 break;
Olav Haugan0a852512012-01-09 10:20:55 -080078 case ION_HEAP_TYPE_CP:
79 ion_cp_heap_destroy(heap);
80 break;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070081 default:
82 pr_err("%s: Invalid heap type %d\n", __func__,
83 heap->type);
84 }
85}