1 /*************************************************************************/ /*!
3 @Title Linux specific per process data functions
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @License Dual MIT/GPLv2
7 The contents of this file are subject to the MIT license as set out below.
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:
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
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.
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.
31 This License is also included in this distribution in the file called
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 */ /**************************************************************************/
43 #include "connection_server.h"
44 #include "osconnection_server.h"
46 #include "env_connection.h"
48 #include "pvr_debug.h"
50 #include <linux/sched.h>
52 #if defined (SUPPORT_ION)
53 #include <linux/err.h>
54 #include PVR_ANDROID_ION_HEADER
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
64 #define SUPPORT_ROCKCHIP_ION (1)
65 #if SUPPORT_ROCKCHIP_ION
66 struct ion_client *rockchip_ion_client_create(const char *name);
69 PVRSRV_ERROR OSConnectionPrivateDataInit(IMG_HANDLE *phOsPrivateData, void *pvOSData)
71 ENV_CONNECTION_PRIVATE_DATA *psPrivData = pvOSData;
72 ENV_CONNECTION_DATA *psEnvConnection;
73 #if defined(SUPPORT_ION)
74 ENV_ION_CONNECTION_DATA *psIonConnection;
77 *phOsPrivateData = OSAllocZMem(sizeof(ENV_CONNECTION_DATA));
79 if (*phOsPrivateData == NULL)
81 PVR_DPF((PVR_DBG_ERROR, "%s: OSAllocMem failed", __FUNCTION__));
82 return PVRSRV_ERROR_OUT_OF_MEMORY;
85 psEnvConnection = (ENV_CONNECTION_DATA *)*phOsPrivateData;
87 psEnvConnection->owner = current->tgid;
89 /* Save the pointer to our struct file */
90 psEnvConnection->psFile = psPrivData->psFile;
91 psEnvConnection->psDevNode = psPrivData->psDevNode;
93 #if defined(SUPPORT_ION)
94 psIonConnection = (ENV_ION_CONNECTION_DATA *)OSAllocZMem(sizeof(ENV_ION_CONNECTION_DATA));
95 if (psIonConnection == NULL)
97 PVR_DPF((PVR_DBG_ERROR, "%s: OSAllocMem failed", __FUNCTION__));
98 return PVRSRV_ERROR_OUT_OF_MEMORY;
101 psEnvConnection->psIonData = psIonConnection;
103 We can have more then one connection per process so we need more then
104 the PID to have a unique name
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);
112 psEnvConnection->psIonData->psIonClient =
113 ion_client_create(psEnvConnection->psIonData->psIonDev,
114 psEnvConnection->psIonData->azIonClientName);
116 if (IS_ERR_OR_NULL(psEnvConnection->psIonData->psIonClient))
118 PVR_DPF((PVR_DBG_ERROR, "OSConnectionPrivateDataInit: Couldn't create "
119 "ion client for per connection data"));
120 return PVRSRV_ERROR_OUT_OF_MEMORY;
122 psEnvConnection->psIonData->ui32IonClientRefCount = 1;
123 #endif /* SUPPORT_ION */
127 PVRSRV_ERROR OSConnectionPrivateDataDeInit(IMG_HANDLE hOsPrivateData)
129 ENV_CONNECTION_DATA *psEnvConnection;
131 if (hOsPrivateData == NULL)
136 psEnvConnection = hOsPrivateData;
138 #if defined(SUPPORT_ION)
139 EnvDataIonClientRelease(psEnvConnection->psIonData);
142 OSFreeMem(hOsPrivateData);
143 /*not nulling pointer, copy on stack*/
149 PVRSRV_DEVICE_NODE *OSGetDevData(CONNECTION_DATA *psConnection)
151 ENV_CONNECTION_DATA *psEnvConnection;
153 psEnvConnection = PVRSRVConnectionPrivateData(psConnection);
154 PVR_ASSERT(psEnvConnection);
156 return psEnvConnection->psDevNode;