blob: 98c1a8c3d68293dcfdb965e8271fd25f55e0d59e [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001/*
2 * drivers/gpu/ion/ion_heap.c
3 *
4 * Copyright (C) 2011 Google, Inc.
Flemmard9fc10142013-04-10 15:59:59 +02005 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01006 *
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"
Flemmard9fc10142013-04-10 15:59:59 +020021#include <linux/msm_ion.h>
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010022
23struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data)
24{
25 struct ion_heap *heap = NULL;
26
Flemmard9fc10142013-04-10 15:59:59 +020027 switch ((int) heap_data->type) {
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010028 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;
37 case ION_HEAP_TYPE_IOMMU:
38 heap = ion_iommu_heap_create(heap_data);
39 break;
40 case ION_HEAP_TYPE_CP:
41 heap = ion_cp_heap_create(heap_data);
42 break;
Flemmard9fc10142013-04-10 15:59:59 +020043#ifdef CONFIG_CMA
44 case ION_HEAP_TYPE_DMA:
45 heap = ion_cma_heap_create(heap_data);
46 break;
47#endif
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010048 default:
49 pr_err("%s: Invalid heap type %d\n", __func__,
50 heap_data->type);
51 return ERR_PTR(-EINVAL);
52 }
53
54 if (IS_ERR_OR_NULL(heap)) {
55 pr_err("%s: error creating heap %s type %d base %lu size %u\n",
56 __func__, heap_data->name, heap_data->type,
57 heap_data->base, heap_data->size);
58 return ERR_PTR(-EINVAL);
59 }
60
61 heap->name = heap_data->name;
62 heap->id = heap_data->id;
Flemmard9fc10142013-04-10 15:59:59 +020063 heap->priv = heap_data->priv;
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010064 return heap;
65}
66
67void ion_heap_destroy(struct ion_heap *heap)
68{
69 if (!heap)
70 return;
71
Flemmard9fc10142013-04-10 15:59:59 +020072 switch ((int) heap->type) {
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010073 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;
82 case ION_HEAP_TYPE_IOMMU:
83 ion_iommu_heap_destroy(heap);
84 break;
85 case ION_HEAP_TYPE_CP:
86 ion_cp_heap_destroy(heap);
87 break;
Flemmard9fc10142013-04-10 15:59:59 +020088#ifdef CONFIG_CMA
89 case ION_HEAP_TYPE_DMA:
90 ion_cma_heap_destroy(heap);
91 break;
92#endif
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010093 default:
94 pr_err("%s: Invalid heap type %d\n", __func__,
95 heap->type);
96 }
97}