blob: ff2b8dd5a677f802c66a3caef3cae4c7b4bf630c [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"
Mitchel Humpherysaf2e5c52012-09-06 12:16:36 -070021#include <linux/msm_ion.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070022
23struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data)
24{
25 struct ion_heap *heap = NULL;
26
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070027 switch ((int) heap_data->type) {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070028 case ION_HEAP_TYPE_SYSTEM_CONTIG:
29 heap = ion_system_contig_heap_create(heap_data);
30 break;
31 case ION_HEAP_TYPE_SYSTEM:
32 heap = ion_system_heap_create(heap_data);
33 break;
34 case ION_HEAP_TYPE_CARVEOUT:
35 heap = ion_carveout_heap_create(heap_data);
36 break;
Laura Abbott8c017362011-09-22 20:59:12 -070037 case ION_HEAP_TYPE_IOMMU:
38 heap = ion_iommu_heap_create(heap_data);
39 break;
Olav Haugan0a852512012-01-09 10:20:55 -080040 case ION_HEAP_TYPE_CP:
41 heap = ion_cp_heap_create(heap_data);
42 break;
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070043#ifdef CONFIG_CMA
44 case ION_HEAP_TYPE_DMA:
45 heap = ion_cma_heap_create(heap_data);
46 break;
Laura Abbotta8c373f2013-02-15 09:25:35 -080047
48 case ION_HEAP_TYPE_SECURE_DMA:
49 heap = ion_secure_cma_heap_create(heap_data);
50 break;
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070051#endif
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070052 default:
53 pr_err("%s: Invalid heap type %d\n", __func__,
54 heap_data->type);
55 return ERR_PTR(-EINVAL);
56 }
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090057
58 if (IS_ERR_OR_NULL(heap)) {
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070059 pr_err("%s: error creating heap %s type %d base %lu size %u\n",
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070060 __func__, heap_data->name, heap_data->type,
61 heap_data->base, heap_data->size);
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090062 return ERR_PTR(-EINVAL);
63 }
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070064
65 heap->name = heap_data->name;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070066 heap->id = heap_data->id;
Benjamin Gaignard8dff0a62012-06-25 15:30:18 -070067 heap->priv = heap_data->priv;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070068 return heap;
69}
70
71void ion_heap_destroy(struct ion_heap *heap)
72{
73 if (!heap)
74 return;
75
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070076 switch ((int) heap->type) {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070077 case ION_HEAP_TYPE_SYSTEM_CONTIG:
78 ion_system_contig_heap_destroy(heap);
79 break;
80 case ION_HEAP_TYPE_SYSTEM:
81 ion_system_heap_destroy(heap);
82 break;
83 case ION_HEAP_TYPE_CARVEOUT:
84 ion_carveout_heap_destroy(heap);
85 break;
Olav Haugan5e560212011-12-13 14:57:57 -080086 case ION_HEAP_TYPE_IOMMU:
87 ion_iommu_heap_destroy(heap);
88 break;
Olav Haugan0a852512012-01-09 10:20:55 -080089 case ION_HEAP_TYPE_CP:
90 ion_cp_heap_destroy(heap);
91 break;
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070092#ifdef CONFIG_CMA
93 case ION_HEAP_TYPE_DMA:
94 ion_cma_heap_destroy(heap);
95 break;
Laura Abbotta8c373f2013-02-15 09:25:35 -080096 case ION_HEAP_TYPE_SECURE_DMA:
97 ion_secure_cma_heap_destroy(heap);
98 break;
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070099#endif
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700100 default:
101 pr_err("%s: Invalid heap type %d\n", __func__,
102 heap->type);
103 }
104}