blob: 0684cae45b4e87d2ef7d74d8886b7267cfc3bf5a [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 Humpherys0dd75a42012-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 Humpherysdc4d01d2012-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;
Benjamin Gaignard0085c1a2012-06-25 15:30:18 -070058 heap->priv = heap_data->priv;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070059 return heap;
60}
61
62void ion_heap_destroy(struct ion_heap *heap)
63{
64 if (!heap)
65 return;
66
Mitchel Humpherysdc4d01d2012-09-13 10:53:22 -070067 switch ((int) heap->type) {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070068 case ION_HEAP_TYPE_SYSTEM_CONTIG:
69 ion_system_contig_heap_destroy(heap);
70 break;
71 case ION_HEAP_TYPE_SYSTEM:
72 ion_system_heap_destroy(heap);
73 break;
74 case ION_HEAP_TYPE_CARVEOUT:
75 ion_carveout_heap_destroy(heap);
76 break;
Olav Haugan5e560212011-12-13 14:57:57 -080077 case ION_HEAP_TYPE_IOMMU:
78 ion_iommu_heap_destroy(heap);
79 break;
Olav Haugan0a852512012-01-09 10:20:55 -080080 case ION_HEAP_TYPE_CP:
81 ion_cp_heap_destroy(heap);
82 break;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070083 default:
84 pr_err("%s: Invalid heap type %d\n", __func__,
85 heap->type);
86 }
87}