RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / apollo / ion_support_generic.c
1 /*************************************************************************/ /*!
2 @File           ion_support.c
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
11
12 The contents of this file are subject to the MIT license as set out below.
13
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:
20
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
23
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.
27
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.
35
36 This License is also included in this distribution in the file called
37 "MIT-COPYING".
38
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 */ /**************************************************************************/
47
48 #include "pvrsrv_error.h"
49 #include "img_types.h"
50 #include "pvr_debug.h"
51 #include "ion_support.h"
52 #include "ion_sys.h"
53
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>
59
60 /* Just the system heaps are used by the generic implementation */
61 static struct ion_platform_data generic_config = {
62         .nr = 2,
63         .heaps =
64 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,39))
65                 (struct ion_platform_heap [])
66 #endif
67                 {
68                         {
69                                 .type = ION_HEAP_TYPE_SYSTEM_CONTIG,
70                                 .name = "system_contig",
71                                 .id = ION_HEAP_TYPE_SYSTEM_CONTIG,
72                         },
73                         {
74                                 .type = ION_HEAP_TYPE_SYSTEM,
75                                 .name = "system",
76                                 .id = ION_HEAP_TYPE_SYSTEM,
77                         }
78                 }
79 };
80
81 struct ion_heap **g_apsIonHeaps;
82 struct ion_device *g_psIonDev;
83
84 PVRSRV_ERROR IonInit(void *phPrivateData)
85 {
86         int uiHeapCount = generic_config.nr;
87         int uiError;
88         int i;
89
90         PVR_UNREFERENCED_PARAMETER(phPrivateData);
91
92         g_apsIonHeaps = kzalloc(sizeof(struct ion_heap *) * uiHeapCount, GFP_KERNEL);
93
94         /* Create the ion devicenode */
95         g_psIonDev = ion_device_create(NULL);
96         if (IS_ERR_OR_NULL(g_psIonDev)) {
97                 kfree(g_apsIonHeaps);
98                 return PVRSRV_ERROR_OUT_OF_MEMORY;
99         }
100
101         /* Register all the heaps */
102         for (i = 0; i < generic_config.nr; i++)
103         {
104                 struct ion_platform_heap *psPlatHeapData = &generic_config.heaps[i];
105
106                 g_apsIonHeaps[i] = ion_heap_create(psPlatHeapData);
107                 if (IS_ERR_OR_NULL(g_apsIonHeaps[i]))
108                 {
109                         uiError = PTR_ERR(g_apsIonHeaps[i]);
110                         goto failHeapCreate;
111                 }
112                 ion_device_add_heap(g_psIonDev, g_apsIonHeaps[i]);
113         }
114
115         return PVRSRV_OK;
116
117 failHeapCreate:
118         for (i = 0; i < uiHeapCount; i++) {
119                 if (g_apsIonHeaps[i])
120                 {
121                                 ion_heap_destroy(g_apsIonHeaps[i]);
122                 }
123         }
124         kfree(g_apsIonHeaps);
125         ion_device_destroy(g_psIonDev);
126
127         return PVRSRV_ERROR_OUT_OF_MEMORY;
128 }
129
130 struct ion_device *IonDevAcquire(void)
131 {
132         return g_psIonDev;
133 }
134
135 void IonDevRelease(struct ion_device *psIonDev)
136 {
137         /* Nothing to do, sanity check the pointer we're passed back */
138         PVR_ASSERT(psIonDev == g_psIonDev);
139 }
140
141 void IonDeinit(void)
142 {
143         int uiHeapCount = generic_config.nr;
144         int i;
145
146         for (i = 0; i < uiHeapCount; i++) {
147                 if (g_apsIonHeaps[i])
148                 {
149                                 ion_heap_destroy(g_apsIonHeaps[i]);
150                 }
151         }
152         kfree(g_apsIonHeaps);
153         ion_device_destroy(g_psIonDev);
154 }
155