RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / services / server / devices / rgx / rgxsync.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          RGX sync kick routines
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    RGX sync kick 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 "srvkm.h"
45 #include "pdump_km.h"
46 #include "pvr_debug.h"
47 #include "rgxutils.h"
48 #include "rgxfwutils.h"
49 #include "rgxmem.h"
50 #include "allocmem.h"
51 #include "devicemem.h"
52 #include "devicemem_pdump.h"
53 #include "osfunc.h"
54 #include "rgxccb.h"
55
56 #include "sync_server.h"
57 #include "sync_internal.h"
58
59 #include "rgxsync.h"
60
61 PVRSRV_ERROR RGXKickSyncKM(PVRSRV_DEVICE_NODE        *psDeviceNode,
62                            RGX_SERVER_COMMON_CONTEXT *psServerCommonContext,
63                                                    RGXFWIF_DM                eDM,
64                                                    IMG_CHAR                  *pszCommandName,
65                            IMG_UINT32                ui32ClientFenceCount,
66                            PRGXFWIF_UFO_ADDR         *pauiClientFenceUFOAddress,
67                            IMG_UINT32                *paui32ClientFenceValue,
68                            IMG_UINT32                ui32ClientUpdateCount,
69                            PRGXFWIF_UFO_ADDR         *pauiClientUpdateUFOAddress,
70                            IMG_UINT32                *paui32ClientUpdateValue,
71                            IMG_UINT32                ui32ServerSyncPrims,
72                            IMG_UINT32                *paui32ServerSyncFlags,
73                            SERVER_SYNC_PRIMITIVE     **pasServerSyncs,
74                            IMG_BOOL                  bPDumpContinuous)
75 {
76         RGXFWIF_KCCB_CMD                sCmpKCCBCmd;
77         RGX_CCB_CMD_HELPER_DATA asCmdHelperData[1];
78         IMG_BOOL                                bKickRequired;
79         PVRSRV_ERROR                    eError;
80         PVRSRV_ERROR                    eError2;
81         IMG_UINT32                              i;
82
83         /* Sanity check the server fences */
84         for (i=0;i<ui32ServerSyncPrims;i++)
85         {
86                 if (!(paui32ServerSyncFlags[i] & PVRSRV_CLIENT_SYNC_PRIM_OP_CHECK))
87                 {
88                         PVR_DPF((PVR_DBG_ERROR, "%s: Server fence (on %s) must fence", __FUNCTION__, pszCommandName));
89                         return PVRSRV_ERROR_INVALID_SYNC_PRIM_OP;
90                 }
91         }
92
93         eError = RGXCmdHelperInitCmdCCB(FWCommonContextGetClientCCB(psServerCommonContext),
94                                                                           ui32ClientFenceCount,
95                                                                           pauiClientFenceUFOAddress,
96                                                                           paui32ClientFenceValue,
97                                                                           ui32ClientUpdateCount,
98                                                                           pauiClientUpdateUFOAddress,
99                                                                           paui32ClientUpdateValue,
100                                                                           ui32ServerSyncPrims,
101                                                                           paui32ServerSyncFlags,
102                                                                           pasServerSyncs,
103                                                                           0,         /* ui32CmdSize */
104                                                                           IMG_NULL,  /* pui8DMCmd */
105                                                                           IMG_NULL,  /* ppPreAddr */
106                                                                           IMG_NULL,  /* ppPostAddr */
107                                                                           IMG_NULL,  /* ppRMWUFOAddr */
108                                                                           RGXFWIF_CCB_CMD_TYPE_NULL,
109                                                                           bPDumpContinuous,
110                                                                           pszCommandName,
111                                                                           asCmdHelperData);
112         if (eError != PVRSRV_OK)
113         {
114                 goto fail_cmdinit;
115         }
116
117         eError = RGXCmdHelperAcquireCmdCCB(IMG_ARR_NUM_ELEMS(asCmdHelperData),
118                                            asCmdHelperData, &bKickRequired);
119         if ((eError != PVRSRV_OK) && (!bKickRequired))
120         {
121                 /*
122                         Only bail if no new data was submitted into the client CCB, we might
123                         have already submitted a padding packet which we should flush through
124                         the FW.
125                 */
126                 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to create client CCB command", __FUNCTION__));
127                 goto fail_cmdaquire;
128         }
129
130
131         /*
132                 We should reserved space in the kernel CCB here and fill in the command
133                 directly.
134                 This is so if there isn't space in the kernel CCB we can return with
135                 retry back to services client before we take any operations
136         */
137
138         /*
139                 We might only be kicking for flush out a padding packet so only submit
140                 the command if the create was successful
141         */
142         if (eError == PVRSRV_OK)
143         {
144                 /*
145                         All the required resources are ready at this point, we can't fail so
146                         take the required server sync operations and commit all the resources
147                 */
148                 RGXCmdHelperReleaseCmdCCB(1, asCmdHelperData, pszCommandName, FWCommonContextGetFWAddress(psServerCommonContext).ui32Addr);
149         }
150
151         /* Construct the kernel compute CCB command. */
152         sCmpKCCBCmd.eCmdType = RGXFWIF_KCCB_CMD_KICK;
153         sCmpKCCBCmd.uCmdData.sCmdKickData.psContext = FWCommonContextGetFWAddress(psServerCommonContext);
154         sCmpKCCBCmd.uCmdData.sCmdKickData.ui32CWoffUpdate = RGXGetHostWriteOffsetCCB(FWCommonContextGetClientCCB(psServerCommonContext));
155         sCmpKCCBCmd.uCmdData.sCmdKickData.ui32NumCleanupCtl = 0;
156
157         /*
158          * Submit the compute command to the firmware.
159          */
160         LOOP_UNTIL_TIMEOUT(MAX_HW_TIME_US)
161         {
162                 eError2 = RGXScheduleCommand(psDeviceNode->pvDevice,
163                                                                         eDM,
164                                                                         &sCmpKCCBCmd,
165                                                                         sizeof(sCmpKCCBCmd),
166                                                                         bPDumpContinuous);
167                 if (eError2 != PVRSRV_ERROR_RETRY)
168                 {
169                         break;
170                 }
171                 OSWaitus(MAX_HW_TIME_US/WAIT_TRY_COUNT);
172         } END_LOOP_UNTIL_TIMEOUT();
173         
174         if (eError2 != PVRSRV_OK)
175         {
176                 PVR_DPF((PVR_DBG_ERROR, "%s failed to schedule kernel CCB command. (0x%x)", __FUNCTION__, eError));
177         }
178         /*
179          * Now check eError (which may have returned an error from our earlier call
180          * to RGXCmdHelperAcquireCmdCCB) - we needed to process any flush command first
181          * so we check it now...
182          */
183         if (eError != PVRSRV_OK )
184         {
185                 goto fail_cmdaquire;
186         }
187
188         return PVRSRV_OK;
189
190 fail_cmdaquire:
191 fail_cmdinit:
192
193         return eError;
194 }
195
196 /******************************************************************************
197  End of file (rgxsync.c)
198 ******************************************************************************/