RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / system / common / 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 #else
66                 (struct ion_platform_heap [])
67 #endif
68                 {
69                         {
70                                 .type = ION_HEAP_TYPE_SYSTEM_CONTIG,
71                                 .name = "system_contig",
72                                 .id = ION_HEAP_TYPE_SYSTEM_CONTIG,
73                         },
74                         {
75                                 .type = ION_HEAP_TYPE_SYSTEM,
76                                 .name = "system",
77                                 .id = ION_HEAP_TYPE_SYSTEM,
78                         }
79                 }
80 };
81
82 struct ion_heap **g_apsIonHeaps;
83 struct ion_device *g_psIonDev;
84
85 PVRSRV_ERROR IonInit(void *phPrivateData)
86 {
87         int uiHeapCount = generic_config.nr;
88         int uiError;
89         int i;
90
91         PVR_UNREFERENCED_PARAMETER(phPrivateData);
92
93         g_apsIonHeaps = kzalloc(sizeof(struct ion_heap *) * uiHeapCount, GFP_KERNEL);
94
95         /* Create the ion devicenode */
96         g_psIonDev = ion_device_create(NULL);
97         if (IS_ERR_OR_NULL(g_psIonDev)) {
98                 kfree(g_apsIonHeaps);
99                 return PVRSRV_ERROR_OUT_OF_MEMORY;
100         }
101
102         /* Register all the heaps */
103         for (i = 0; i < generic_config.nr; i++)
104         {
105                 struct ion_platform_heap *psPlatHeapData = &generic_config.heaps[i];
106
107                 g_apsIonHeaps[i] = ion_heap_create(psPlatHeapData);
108                 if (IS_ERR_OR_NULL(g_apsIonHeaps[i]))
109                 {
110                         uiError = PTR_ERR(g_apsIonHeaps[i]);
111                         goto failHeapCreate;
112                 }
113                 ion_device_add_heap(g_psIonDev, g_apsIonHeaps[i]);
114         }
115
116         return PVRSRV_OK;
117
118 failHeapCreate:
119         for (i = 0; i < uiHeapCount; i++) {
120                 if (g_apsIonHeaps[i])
121                 {
122                                 ion_heap_destroy(g_apsIonHeaps[i]);
123                 }
124         }
125         kfree(g_apsIonHeaps);
126         ion_device_destroy(g_psIonDev);
127
128         return PVRSRV_ERROR_OUT_OF_MEMORY;
129 }
130
131 struct ion_device *IonDevAcquire(IMG_VOID)
132 {
133         return g_psIonDev;
134 }
135
136 IMG_VOID IonDevRelease(struct ion_device *psIonDev)
137 {
138         /* Nothing to do, sanity check the pointer we're passed back */
139         PVR_ASSERT(psIonDev == g_psIonDev);
140 }
141
142 IMG_UINT32 IonPhysHeapID(IMG_VOID)
143 {
144         return 0;
145 }
146
147 IMG_VOID IonDeinit(IMG_VOID)
148 {
149         int uiHeapCount = generic_config.nr;
150         int i;
151
152         for (i = 0; i < uiHeapCount; i++) {
153                 if (g_apsIonHeaps[i])
154                 {
155                                 ion_heap_destroy(g_apsIonHeaps[i]);
156                 }
157         }
158         kfree(g_apsIonHeaps);
159         ion_device_destroy(g_psIonDev);
160 }
161