blob: 4c83d753260f8f0f3bcc17cd6fd0fb1419b03273 [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"
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;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070043 default:
44 pr_err("%s: Invalid heap type %d\n", __func__,
45 heap_data->type);
46 return ERR_PTR(-EINVAL);
47 }
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090048
49 if (IS_ERR_OR_NULL(heap)) {
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070050 pr_err("%s: error creating heap %s type %d base %lu size %u\n",
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070051 __func__, heap_data->name, heap_data->type,
52 heap_data->base, heap_data->size);
Choi, Jong-Hwan42c5a072011-07-07 09:07:04 +090053 return ERR_PTR(-EINVAL);
54 }
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070055
56 heap->name = heap_data->name;
Rebecca Schultz Zavine6ee1242011-06-30 12:19:55 -070057 heap->id = heap_data->id;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070058 return heap;
59}
60
61void ion_heap_destroy(struct ion_heap *heap)
62{
63 if (!heap)
64 return;
65
Mitchel Humpherys362b52b2012-09-13 10:53:22 -070066 switch ((int) heap->type) {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070067 case ION_HEAP_TYPE_SYSTEM_CONTIG:
68 ion_system_contig_heap_destroy(heap);
69 break;
70 case ION_HEAP_TYPE_SYSTEM:
71 ion_system_heap_destroy(heap);
72 break;
73 case ION_HEAP_TYPE_CARVEOUT:
74 ion_carveout_heap_destroy(heap);
75 break;
Olav Haugan5e560212011-12-13 14:57:57 -080076 case ION_HEAP_TYPE_IOMMU:
77 ion_iommu_heap_destroy(heap);
78 break;
Olav Haugan0a852512012-01-09 10:20:55 -080079 case ION_HEAP_TYPE_CP:
80 ion_cp_heap_destroy(heap);
81 break;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070082 default:
83 pr_err("%s: Invalid heap type %d\n", __func__,
84 heap->type);
85 }
86}