RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / osconnection_server.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          Linux specific per process data functions
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @License        Dual MIT/GPLv2
6
7 The contents of this file are subject to the MIT license as set out below.
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 Alternatively, the contents of this file may be used under the terms of
20 the GNU General Public License Version 2 ("GPL") in which case the provisions
21 of GPL are applicable instead of those above.
22
23 If you wish to allow use of your version of this file only under the terms of
24 GPL, and not to allow others to use your version of this file under the terms
25 of the MIT license, indicate your decision by deleting the provisions above
26 and replace them with the notice and other provisions required by GPL as set
27 out in the file called "GPL-COPYING" included in this distribution. If you do
28 not delete the provisions above, a recipient may use your version of this file
29 under the terms of either the MIT license or GPL.
30
31 This License is also included in this distribution in the file called
32 "MIT-COPYING".
33
34 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
35 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
36 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
38 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
39 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 */ /**************************************************************************/
42
43 #include "connection_server.h"
44 #include "osconnection_server.h"
45
46 #include "env_connection.h"
47 #include "allocmem.h"
48 #include "pvr_debug.h"
49
50 #include <linux/sched.h>
51
52 #if defined (SUPPORT_ION)
53 #include <linux/err.h>
54 #include PVR_ANDROID_ION_HEADER
55
56 /*
57         The ion device (the base object for all requests)
58         gets created by the system and we acquire it via
59         linux specific functions provided by the system layer
60 */
61 #include "ion_sys.h"
62 #endif
63
64 #define SUPPORT_ROCKCHIP_ION  (1)
65 #if SUPPORT_ROCKCHIP_ION
66 struct ion_client *rockchip_ion_client_create(const char *name);
67 #endif
68
69 PVRSRV_ERROR OSConnectionPrivateDataInit(IMG_HANDLE *phOsPrivateData, void *pvOSData)
70 {
71         ENV_CONNECTION_PRIVATE_DATA *psPrivData = pvOSData;
72         ENV_CONNECTION_DATA *psEnvConnection;
73 #if defined(SUPPORT_ION)
74         ENV_ION_CONNECTION_DATA *psIonConnection;
75 #endif
76
77         *phOsPrivateData = OSAllocZMem(sizeof(ENV_CONNECTION_DATA));
78
79         if (*phOsPrivateData == NULL)
80         {
81                 PVR_DPF((PVR_DBG_ERROR, "%s: OSAllocMem failed", __FUNCTION__));
82                 return PVRSRV_ERROR_OUT_OF_MEMORY;
83         }
84
85         psEnvConnection = (ENV_CONNECTION_DATA *)*phOsPrivateData;
86
87         psEnvConnection->owner = current->tgid;
88
89         /* Save the pointer to our struct file */
90         psEnvConnection->psFile = psPrivData->psFile;
91         psEnvConnection->psDevNode = psPrivData->psDevNode;
92
93 #if defined(SUPPORT_ION)
94         psIonConnection = (ENV_ION_CONNECTION_DATA *)OSAllocZMem(sizeof(ENV_ION_CONNECTION_DATA));
95         if (psIonConnection == NULL)
96         {
97                 PVR_DPF((PVR_DBG_ERROR, "%s: OSAllocMem failed", __FUNCTION__));
98                 return PVRSRV_ERROR_OUT_OF_MEMORY;
99         }
100
101         psEnvConnection->psIonData = psIonConnection;
102         /*
103                 We can have more then one connection per process so we need more then
104                 the PID to have a unique name
105         */
106         psEnvConnection->psIonData->psIonDev = IonDevAcquire();
107         OSSNPrintf(psEnvConnection->psIonData->azIonClientName, ION_CLIENT_NAME_SIZE, "pvr_ion_client-%p-%d", *phOsPrivateData, OSGetCurrentClientProcessIDKM());
108 #if SUPPORT_ROCKCHIP_ION
109         psEnvConnection->psIonData->psIonClient =
110                 rockchip_ion_client_create(psEnvConnection->psIonData->azIonClientName);
111 #else
112         psEnvConnection->psIonData->psIonClient =
113                 ion_client_create(psEnvConnection->psIonData->psIonDev,
114                                                   psEnvConnection->psIonData->azIonClientName);
115 #endif
116         if (IS_ERR_OR_NULL(psEnvConnection->psIonData->psIonClient))
117         {
118                 PVR_DPF((PVR_DBG_ERROR, "OSConnectionPrivateDataInit: Couldn't create "
119                                                                 "ion client for per connection data"));
120                 return PVRSRV_ERROR_OUT_OF_MEMORY;
121         }
122         psEnvConnection->psIonData->ui32IonClientRefCount = 1;
123 #endif /* SUPPORT_ION */
124         return PVRSRV_OK;
125 }
126
127 PVRSRV_ERROR OSConnectionPrivateDataDeInit(IMG_HANDLE hOsPrivateData)
128 {
129         ENV_CONNECTION_DATA *psEnvConnection; 
130
131         if (hOsPrivateData == NULL)
132         {
133                 return PVRSRV_OK;
134         }
135
136         psEnvConnection = hOsPrivateData;
137
138 #if defined(SUPPORT_ION)
139         EnvDataIonClientRelease(psEnvConnection->psIonData);
140 #endif
141
142         OSFreeMem(hOsPrivateData);
143         /*not nulling pointer, copy on stack*/
144
145         return PVRSRV_OK;
146 }
147
148
149 PVRSRV_DEVICE_NODE *OSGetDevData(CONNECTION_DATA *psConnection)
150 {
151         ENV_CONNECTION_DATA *psEnvConnection;
152
153         psEnvConnection = PVRSRVConnectionPrivateData(psConnection);
154         PVR_ASSERT(psEnvConnection);
155
156         return psEnvConnection->psDevNode;
157 }