RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / rgxregconfig.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          RGX Register configuration
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    RGX Regconfig routines
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43
44 #include "rgxregconfig.h"
45 #include "pvr_debug.h"
46 #include "rgxutils.h"
47 #include "rgxfwutils.h"
48 #include "device.h"
49 #include "sync_internal.h"
50 #include "pdump_km.h"
51 #include "pvrsrv.h"
52 PVRSRV_ERROR PVRSRVRGXSetRegConfigTypeKM(CONNECTION_DATA * psDevConnection,
53                                          PVRSRV_DEVICE_NODE      *psDeviceNode,
54                                          IMG_UINT8           ui8RegCfgType)
55 {       
56 #if defined(SUPPORT_USER_REGISTER_CONFIGURATION)
57         PVRSRV_ERROR          eError       = PVRSRV_OK;
58         PVRSRV_RGXDEV_INFO        *psDevInfo   = psDeviceNode->pvDevice;
59         RGX_REG_CONFIG        *psRegCfg    = &psDevInfo->sRegCongfig;
60         RGXFWIF_REG_CFG_TYPE  eRegCfgType  = (RGXFWIF_REG_CFG_TYPE) ui8RegCfgType;
61
62         PVR_UNREFERENCED_PARAMETER(psDevConnection);
63
64         if (eRegCfgType < psRegCfg->eRegCfgTypeToPush)
65         {
66                 PVR_DPF((PVR_DBG_ERROR, 
67                          "PVRSRVRGXSetRegConfigTypeKM: Register configuration requested (%d) is not valid since it has to be at least %d."
68                                  " Configurations of different types need to go in order",
69                                  eRegCfgType,
70                                  psRegCfg->eRegCfgTypeToPush));
71                 return PVRSRV_ERROR_REG_CONFIG_INVALID_TYPE;
72         }
73
74         psRegCfg->eRegCfgTypeToPush = eRegCfgType;
75
76         return eError;
77 #else
78         PVR_UNREFERENCED_PARAMETER(psDevConnection);
79                 
80         PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXSetRegConfigTypeKM: Feature disabled. Compile with SUPPORT_USER_REGISTER_CONFIGURATION"));
81         return PVRSRV_ERROR_FEATURE_DISABLED;
82 #endif
83 }
84
85 PVRSRV_ERROR PVRSRVRGXAddRegConfigKM(CONNECTION_DATA * psConnection,
86                                      PVRSRV_DEVICE_NODE *psDeviceNode,
87                                      IMG_UINT32         ui32RegAddr,
88                                      IMG_UINT64         ui64RegValue,
89                                      IMG_UINT64         ui64RegMask)
90 {
91 #if defined(SUPPORT_USER_REGISTER_CONFIGURATION)
92         PVRSRV_ERROR            eError = PVRSRV_OK;
93         RGXFWIF_KCCB_CMD        sRegCfgCmd;
94         PVRSRV_RGXDEV_INFO      *psDevInfo = psDeviceNode->pvDevice;
95         RGX_REG_CONFIG          *psRegCfg = &psDevInfo->sRegCongfig;
96
97         PVR_UNREFERENCED_PARAMETER(psConnection);
98         
99         if (psRegCfg->bEnabled)
100         {
101                 PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXAddRegConfigKM: Cannot add record whilst register configuration active."));
102                 return PVRSRV_ERROR_REG_CONFIG_ENABLED;
103         }
104         if (psRegCfg->ui32NumRegRecords == RGXFWIF_REG_CFG_MAX_SIZE)
105         {
106                 PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXAddRegConfigKM: Register configuration full."));
107                 return PVRSRV_ERROR_REG_CONFIG_FULL;
108         }
109
110         sRegCfgCmd.eCmdType = RGXFWIF_KCCB_CMD_REGCONFIG;
111         sRegCfgCmd.uCmdData.sRegConfigData.sRegConfig.ui64Addr = (IMG_UINT64) ui32RegAddr;
112         sRegCfgCmd.uCmdData.sRegConfigData.sRegConfig.ui64Value = ui64RegValue;
113         sRegCfgCmd.uCmdData.sRegConfigData.sRegConfig.ui64Mask = ui64RegMask;
114         sRegCfgCmd.uCmdData.sRegConfigData.eRegConfigType = psRegCfg->eRegCfgTypeToPush;
115         sRegCfgCmd.uCmdData.sRegConfigData.eCmdType = RGXFWIF_REGCFG_CMD_ADD;
116
117         eError = RGXScheduleCommand(psDeviceNode->pvDevice,
118                                 RGXFWIF_DM_GP,
119                                 &sRegCfgCmd,
120                                 sizeof(sRegCfgCmd),
121                                 0,
122                                 PDUMP_FLAGS_CONTINUOUS);
123         if (eError != PVRSRV_OK)
124         {
125                 PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXAddRegConfigKM: RGXScheduleCommand failed. Error:%u", eError));
126                 return eError;
127         }
128
129         psRegCfg->ui32NumRegRecords++;
130
131         return eError;
132 #else
133         PVR_UNREFERENCED_PARAMETER(psConnection);
134         
135         PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXSetRegConfigPIKM: Feature disabled. Compile with SUPPORT_USER_REGISTER_CONFIGURATION"));
136         return PVRSRV_ERROR_FEATURE_DISABLED;
137 #endif
138 }
139
140 PVRSRV_ERROR PVRSRVRGXClearRegConfigKM(CONNECTION_DATA * psConnection,
141                                        PVRSRV_DEVICE_NODE       *psDeviceNode)
142 {
143 #if defined(SUPPORT_USER_REGISTER_CONFIGURATION)
144         PVRSRV_ERROR            eError = PVRSRV_OK;
145         RGXFWIF_KCCB_CMD        sRegCfgCmd;
146         PVRSRV_RGXDEV_INFO      *psDevInfo = psDeviceNode->pvDevice;
147         RGX_REG_CONFIG          *psRegCfg = &psDevInfo->sRegCongfig;
148
149         PVR_UNREFERENCED_PARAMETER(psConnection);
150         
151         if (psRegCfg->bEnabled)
152         {
153                 PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXClearRegConfigKM: Attempt to clear register configuration whilst active."));
154                 return PVRSRV_ERROR_REG_CONFIG_ENABLED;
155         }
156
157         sRegCfgCmd.eCmdType = RGXFWIF_KCCB_CMD_REGCONFIG;
158         sRegCfgCmd.uCmdData.sRegConfigData.eCmdType = RGXFWIF_REGCFG_CMD_CLEAR;
159
160         eError = RGXScheduleCommand(psDeviceNode->pvDevice,
161                                 RGXFWIF_DM_GP,
162                                 &sRegCfgCmd,
163                                 sizeof(sRegCfgCmd),
164                                 0,
165                                 PDUMP_FLAGS_CONTINUOUS);
166         if (eError != PVRSRV_OK)
167         {
168                 PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXClearRegConfigKM: RGXScheduleCommand failed. Error:%u", eError));
169                 return eError;
170         }
171
172         psRegCfg->ui32NumRegRecords = 0;
173         psRegCfg->eRegCfgTypeToPush = RGXFWIF_REG_CFG_TYPE_PWR_ON; 
174
175         return eError;
176 #else
177         PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXClearRegConfigKM: Feature disabled. Compile with SUPPORT_USER_REGISTER_CONFIGURATION"));
178
179         PVR_UNREFERENCED_PARAMETER(psConnection);
180         
181         return PVRSRV_ERROR_FEATURE_DISABLED;
182 #endif
183 }
184
185 PVRSRV_ERROR PVRSRVRGXEnableRegConfigKM(CONNECTION_DATA * psConnection,
186                                         PVRSRV_DEVICE_NODE      *psDeviceNode)
187 {
188 #if defined(SUPPORT_USER_REGISTER_CONFIGURATION)
189         PVRSRV_ERROR            eError = PVRSRV_OK;
190         RGXFWIF_KCCB_CMD        sRegCfgCmd;
191         PVRSRV_RGXDEV_INFO      *psDevInfo = psDeviceNode->pvDevice;
192         RGX_REG_CONFIG          *psRegCfg = &psDevInfo->sRegCongfig;
193
194         PVR_UNREFERENCED_PARAMETER(psConnection);
195         
196         sRegCfgCmd.eCmdType = RGXFWIF_KCCB_CMD_REGCONFIG;
197         sRegCfgCmd.uCmdData.sRegConfigData.eCmdType = RGXFWIF_REGCFG_CMD_ENABLE;
198
199         eError = RGXScheduleCommand(psDeviceNode->pvDevice,
200                                 RGXFWIF_DM_GP,
201                                 &sRegCfgCmd,
202                                 sizeof(sRegCfgCmd),
203                                 0,
204                                 PDUMP_FLAGS_CONTINUOUS);
205         if (eError != PVRSRV_OK)
206         {
207                 PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXEnableRegConfigKM: RGXScheduleCommand failed. Error:%u", eError));
208                 return eError;
209         }
210
211         psRegCfg->bEnabled = IMG_TRUE;
212
213         return eError;
214 #else
215         PVR_UNREFERENCED_PARAMETER(psConnection);
216         
217         PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXEnableRegConfigKM: Feature disabled. Compile with SUPPORT_USER_REGISTER_CONFIGURATION"));
218         return PVRSRV_ERROR_FEATURE_DISABLED;
219 #endif
220 }
221
222 PVRSRV_ERROR PVRSRVRGXDisableRegConfigKM(CONNECTION_DATA * psConnection,
223                                          PVRSRV_DEVICE_NODE     *psDeviceNode)
224 {
225 #if defined(SUPPORT_USER_REGISTER_CONFIGURATION)
226         PVRSRV_ERROR            eError = PVRSRV_OK;
227         RGXFWIF_KCCB_CMD        sRegCfgCmd;
228         PVRSRV_RGXDEV_INFO      *psDevInfo = psDeviceNode->pvDevice;
229         RGX_REG_CONFIG          *psRegCfg = &psDevInfo->sRegCongfig;
230         
231         PVR_UNREFERENCED_PARAMETER(psConnection);
232         
233         sRegCfgCmd.eCmdType = RGXFWIF_KCCB_CMD_REGCONFIG;
234         sRegCfgCmd.uCmdData.sRegConfigData.eCmdType = RGXFWIF_REGCFG_CMD_DISABLE;
235
236         eError = RGXScheduleCommand(psDeviceNode->pvDevice,
237                                 RGXFWIF_DM_GP,
238                                 &sRegCfgCmd,
239                                 sizeof(sRegCfgCmd),
240                                 0,
241                                 PDUMP_FLAGS_CONTINUOUS);
242         if (eError != PVRSRV_OK)
243         {
244                 PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXDisableRegConfigKM: RGXScheduleCommand failed. Error:%u", eError));
245                 return eError;
246         }
247
248         psRegCfg->bEnabled = IMG_FALSE;
249
250         return eError;
251 #else
252         PVR_DPF((PVR_DBG_ERROR, "PVRSRVRGXDisableRegConfigKM: Feature disabled. Compile with SUPPORT_USER_REGISTER_CONFIGURATION"));
253         PVR_UNREFERENCED_PARAMETER(psConnection);
254                 
255         return PVRSRV_ERROR_FEATURE_DISABLED;
256 #endif
257 }
258
259
260 /******************************************************************************
261  End of file (rgxregconfig.c)
262 ******************************************************************************/