1 /*************************************************************************/ /*!
3 @Title Generic Ion support
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description This file does the Ion initialisation and De-initialistion for
6 systems that don't already have Ion.
7 For systems that do have Ion it's expected they they init Ion
8 as per their requirements and then implement IonDevAcquire and
9 IonDevRelease which provides access to the ion device.
10 @License Dual MIT/GPLv2
12 The contents of this file are subject to the MIT license as set out below.
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
24 Alternatively, the contents of this file may be used under the terms of
25 the GNU General Public License Version 2 ("GPL") in which case the provisions
26 of GPL are applicable instead of those above.
28 If you wish to allow use of your version of this file only under the terms of
29 GPL, and not to allow others to use your version of this file under the terms
30 of the MIT license, indicate your decision by deleting the provisions above
31 and replace them with the notice and other provisions required by GPL as set
32 out in the file called "GPL-COPYING" included in this distribution. If you do
33 not delete the provisions above, a recipient may use your version of this file
34 under the terms of either the MIT license or GPL.
36 This License is also included in this distribution in the file called
39 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
40 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
41 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
42 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
43 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
44 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
45 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 */ /**************************************************************************/
48 #include "pvrsrv_error.h"
49 #include "img_types.h"
50 #include "pvr_debug.h"
51 #include "ion_support.h"
54 #include <linux/version.h>
55 #include PVR_ANDROID_ION_HEADER
56 #include PVR_ANDROID_ION_PRIV_HEADER
57 #include <linux/err.h>
58 #include <linux/slab.h>
60 /* Just the system heaps are used by the generic implementation */
61 static struct ion_platform_data generic_config = {
64 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,39))
66 (struct ion_platform_heap [])
70 .type = ION_HEAP_TYPE_SYSTEM_CONTIG,
71 .name = "system_contig",
72 .id = ION_HEAP_TYPE_SYSTEM_CONTIG,
75 .type = ION_HEAP_TYPE_SYSTEM,
77 .id = ION_HEAP_TYPE_SYSTEM,
82 struct ion_heap **g_apsIonHeaps;
83 struct ion_device *g_psIonDev;
85 PVRSRV_ERROR IonInit(void *phPrivateData)
87 int uiHeapCount = generic_config.nr;
91 PVR_UNREFERENCED_PARAMETER(phPrivateData);
93 g_apsIonHeaps = kzalloc(sizeof(struct ion_heap *) * uiHeapCount, GFP_KERNEL);
95 /* Create the ion devicenode */
96 g_psIonDev = ion_device_create(NULL);
97 if (IS_ERR_OR_NULL(g_psIonDev)) {
99 return PVRSRV_ERROR_OUT_OF_MEMORY;
102 /* Register all the heaps */
103 for (i = 0; i < generic_config.nr; i++)
105 struct ion_platform_heap *psPlatHeapData = &generic_config.heaps[i];
107 g_apsIonHeaps[i] = ion_heap_create(psPlatHeapData);
108 if (IS_ERR_OR_NULL(g_apsIonHeaps[i]))
110 uiError = PTR_ERR(g_apsIonHeaps[i]);
113 ion_device_add_heap(g_psIonDev, g_apsIonHeaps[i]);
119 for (i = 0; i < uiHeapCount; i++) {
120 if (g_apsIonHeaps[i])
122 ion_heap_destroy(g_apsIonHeaps[i]);
125 kfree(g_apsIonHeaps);
126 ion_device_destroy(g_psIonDev);
128 return PVRSRV_ERROR_OUT_OF_MEMORY;
131 struct ion_device *IonDevAcquire(IMG_VOID)
136 IMG_VOID IonDevRelease(struct ion_device *psIonDev)
138 /* Nothing to do, sanity check the pointer we're passed back */
139 PVR_ASSERT(psIonDev == g_psIonDev);
142 IMG_UINT32 IonPhysHeapID(IMG_VOID)
147 IMG_VOID IonDeinit(IMG_VOID)
149 int uiHeapCount = generic_config.nr;
152 for (i = 0; i < uiHeapCount; i++) {
153 if (g_apsIonHeaps[i])
155 ion_heap_destroy(g_apsIonHeaps[i]);
158 kfree(g_apsIonHeaps);
159 ion_device_destroy(g_psIonDev);