blob: 98c1a8c3d68293dcfdb965e8271fd25f55e0d59e [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.
Duy Truong790f06d2013-02-13 16:38:12 -08005 * Copyright (c) 2011-2012, 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;
47#endif
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070048 default:
49 pr_err("%s: Invalid heap type %d\n", __func__,
50 heap_data->type);
51 return ERR_PTR(-EINVAL);
52 }
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090053
54 if (IS_ERR_OR_NULL(heap)) {
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070055 pr_err("%s: error creating heap %s type %d base %lu size %u\n",
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070056 __func__, heap_data->name, heap_data->type,
57 heap_data->base, heap_data->size);
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090058 return ERR_PTR(-EINVAL);
59 }
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070060
61 heap->name = heap_data->name;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070062 heap->id = heap_data->id;
Benjamin Gaignard8dff0a62012-06-25 15:30:18 -070063 heap->priv = heap_data->priv;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070064 return heap;
65}
66
67void ion_heap_destroy(struct ion_heap *heap)
68{
69 if (!heap)
70 return;
71
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070072 switch ((int) heap->type) {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070073 case ION_HEAP_TYPE_SYSTEM_CONTIG:
74 ion_system_contig_heap_destroy(heap);
75 break;
76 case ION_HEAP_TYPE_SYSTEM:
77 ion_system_heap_destroy(heap);
78 break;
79 case ION_HEAP_TYPE_CARVEOUT:
80 ion_carveout_heap_destroy(heap);
81 break;
Olav Haugan5e560212011-12-13 14:57:57 -080082 case ION_HEAP_TYPE_IOMMU:
83 ion_iommu_heap_destroy(heap);
84 break;
Olav Haugan0a852512012-01-09 10:20:55 -080085 case ION_HEAP_TYPE_CP:
86 ion_cp_heap_destroy(heap);
87 break;
Benjamin Gaignard07b590e2012-08-15 10:55:10 -070088#ifdef CONFIG_CMA
89 case ION_HEAP_TYPE_DMA:
90 ion_cma_heap_destroy(heap);
91 break;
92#endif
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070093 default:
94 pr_err("%s: Invalid heap type %d\n", __func__,
95 heap->type);
96 }
97}