1 /*************************************************************************/ /*!
3 @Title Services script routines used at initialisation time
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description Device specific functions
6 @License Dual MIT/GPLv2
8 The contents of this file are subject to the MIT license as set out below.
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:
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
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.
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.
32 This License is also included in this distribution in the file called
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 */ /**************************************************************************/
44 #include "rgxsrvinit_script.h"
45 #include "srvinit_osfunc.h"
46 #include "pvr_debug.h"
50 *******************************************************************************
52 @Function OutOfScriptSpace
54 @Description Checks for script space failure
60 ******************************************************************************/
61 static IMG_BOOL OutOfScriptSpace(RGX_SCRIPT_BUILD *psScript)
63 if (psScript->ui32CurrComm >= psScript->ui32MaxLen)
65 psScript->bOutOfSpace = IMG_TRUE;
68 return psScript->bOutOfSpace;
73 *******************************************************************************
75 @Function NextScriptCommand
77 @Description Gets next script command to populate
83 ******************************************************************************/
84 static RGX_INIT_COMMAND* NextScriptCommand(RGX_SCRIPT_BUILD *psScript)
86 if (OutOfScriptSpace(psScript))
88 PVR_DPF((PVR_DBG_ERROR, "NextScriptCommand: Out of space for commands (%d)",
89 psScript->ui32MaxLen));
93 return &psScript->psCommands[psScript->ui32CurrComm++];
97 IMG_BOOL ScriptWriteRGXReg(RGX_SCRIPT_BUILD *psScript,
98 IMG_UINT32 ui32Offset,
101 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
105 psComm->sWriteHWReg.eOp = RGX_INIT_OP_WRITE_HW_REG;
106 psComm->sWriteHWReg.ui32Offset = ui32Offset;
107 psComm->sWriteHWReg.ui32Value = ui32Value;
116 IMG_BOOL ScriptPoll64RGXReg(RGX_SCRIPT_BUILD *psScript,
117 IMG_UINT32 ui32Offset,
118 IMG_UINT64 ui64Value,
119 IMG_UINT64 ui64PollMask)
121 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
125 psComm->sPoll64HWReg.eOp = RGX_INIT_OP_POLL_64_HW_REG;
126 psComm->sPoll64HWReg.ui32Offset = ui32Offset;
127 psComm->sPoll64HWReg.ui64Value = ui64Value;
128 psComm->sPoll64HWReg.ui64Mask = ui64PollMask;
136 IMG_BOOL ScriptPollRGXReg(RGX_SCRIPT_BUILD *psScript,
137 IMG_UINT32 ui32Offset,
138 IMG_UINT32 ui32Value,
139 IMG_UINT32 ui32PollMask)
141 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
145 psComm->sPollHWReg.eOp = RGX_INIT_OP_POLL_HW_REG;
146 psComm->sPollHWReg.ui32Offset = ui32Offset;
147 psComm->sPollHWReg.ui32Value = ui32Value;
148 psComm->sPollHWReg.ui32Mask = ui32PollMask;
156 IMG_BOOL ScriptDBGReadRGXReg(RGX_SCRIPT_BUILD *psScript,
157 RGX_INIT_OPERATION eOp,
158 IMG_UINT32 ui32Offset,
161 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
163 PVR_ASSERT(strlen(pszName) < RGX_DBG_CMD_NAME_SIZE);
167 PVR_ASSERT((eOp == RGX_INIT_OP_DBG_READ32_HW_REG) ||
168 (eOp == RGX_INIT_OP_DBG_READ64_HW_REG));
170 psComm->sDBGReadHWReg.eOp = eOp;
171 psComm->sDBGReadHWReg.ui32Offset = ui32Offset;
173 strcpy(&psComm->sDBGReadHWReg.aszName[0], pszName);
182 IMG_BOOL ScriptDBGCalc(RGX_SCRIPT_BUILD *psScript,
183 RGX_INIT_OPERATION eOp,
184 IMG_UINT32 ui32Offset1,
185 IMG_UINT32 ui32Offset2,
186 IMG_UINT32 ui32Offset3,
189 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
191 PVR_ASSERT(strlen(pszName) < RGX_DBG_CMD_NAME_SIZE);
195 PVR_ASSERT(eOp == RGX_INIT_OP_DBG_CALC);
197 psComm->sDBGCalc.eOp = eOp;
198 psComm->sDBGCalc.ui32Offset1 = ui32Offset1;
199 psComm->sDBGCalc.ui32Offset2 = ui32Offset2;
200 psComm->sDBGCalc.ui32Offset3 = ui32Offset3;
201 strcpy(&psComm->sDBGCalc.aszName[0], pszName);
210 #if defined(RGX_FEATURE_META) || defined(SUPPORT_KERNEL_SRVINIT)
211 IMG_BOOL ScriptWriteRGXRegPDUMPOnly(RGX_SCRIPT_BUILD *psScript,
212 IMG_UINT32 ui32Offset,
213 IMG_UINT32 ui32Value)
215 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
219 psComm->sPDumpHWReg.eOp = RGX_INIT_OP_PDUMP_HW_REG;
220 psComm->sPDumpHWReg.ui32Offset = ui32Offset;
221 psComm->sPDumpHWReg.ui32Value = ui32Value;
231 *******************************************************************************
233 @Function ScriptPrepareReadMetaRegThroughSP
235 @Description Add script entries for reading a reg through Meta slave port
242 ******************************************************************************/
243 static IMG_BOOL ScriptPrepareReadMetaRegThroughSP(RGX_SCRIPT_BUILD *psScript,
244 IMG_UINT32 ui32RegAddr)
246 IMG_BOOL bCmdAdded = IMG_FALSE;
248 /* Wait for Slave Port to be Ready */
249 bCmdAdded = ScriptPollRGXReg(psScript,
250 RGX_CR_META_SP_MSLVCTRL1,
251 RGX_CR_META_SP_MSLVCTRL1_READY_EN |
252 RGX_CR_META_SP_MSLVCTRL1_GBLPORT_IDLE_EN,
253 RGX_CR_META_SP_MSLVCTRL1_READY_EN |
254 RGX_CR_META_SP_MSLVCTRL1_GBLPORT_IDLE_EN);
255 if (!bCmdAdded) return IMG_FALSE;
258 bCmdAdded = ScriptWriteRGXReg(psScript,
259 RGX_CR_META_SP_MSLVCTRL0,
260 ui32RegAddr | RGX_CR_META_SP_MSLVCTRL0_RD_EN);
261 if (!bCmdAdded) return IMG_FALSE;
263 /* Wait for Slave Port to be Ready: read complete */
264 bCmdAdded = ScriptPollRGXReg(psScript,
265 RGX_CR_META_SP_MSLVCTRL1,
266 RGX_CR_META_SP_MSLVCTRL1_READY_EN |
267 RGX_CR_META_SP_MSLVCTRL1_GBLPORT_IDLE_EN,
268 RGX_CR_META_SP_MSLVCTRL1_READY_EN |
269 RGX_CR_META_SP_MSLVCTRL1_GBLPORT_IDLE_EN);
275 IMG_BOOL ScriptDBGReadMetaRegThroughSP(RGX_SCRIPT_BUILD *psScript,
276 IMG_UINT32 ui32RegAddr,
279 IMG_BOOL bCmdsAdded = IMG_FALSE;
282 bCmdsAdded = ScriptPrepareReadMetaRegThroughSP(psScript, ui32RegAddr);
283 if (!bCmdsAdded) return IMG_FALSE;
286 bCmdsAdded = ScriptDBGReadRGXReg(psScript,
287 RGX_INIT_OP_DBG_READ32_HW_REG,
288 RGX_CR_META_SP_MSLVDATAX,
296 *******************************************************************************
298 @Function ScriptCondPollRGXReg
300 @Description Sets up a script entry for a conditional register poll
303 @Input ui32CondOffset
305 @Input ui32CondPollMask
312 ******************************************************************************/
313 static IMG_BOOL ScriptCondPollRGXReg(RGX_SCRIPT_BUILD *psScript,
314 IMG_UINT32 ui32CondOffset,
315 IMG_UINT32 ui32CondValue,
316 IMG_UINT32 ui32CondPollMask,
317 IMG_UINT32 ui32Offset,
318 IMG_UINT32 ui32Value,
319 IMG_UINT32 ui32PollMask)
321 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
325 psComm->sCondPollHWReg.eOp = RGX_INIT_OP_COND_POLL_HW_REG;
326 psComm->sCondPollHWReg.ui32CondOffset = ui32CondOffset;
327 psComm->sCondPollHWReg.ui32CondValue = ui32CondValue;
328 psComm->sCondPollHWReg.ui32CondMask = ui32CondPollMask;
329 psComm->sCondPollHWReg.ui32Offset = ui32Offset;
330 psComm->sCondPollHWReg.ui32Value = ui32Value;
331 psComm->sCondPollHWReg.ui32Mask = ui32PollMask;
339 IMG_BOOL ScriptMetaRegCondPollRGXReg(RGX_SCRIPT_BUILD *psScript,
340 IMG_UINT32 ui32MetaRegAddr,
341 IMG_UINT32 ui32MetaRegValue,
342 IMG_UINT32 ui32MetaRegMask,
343 IMG_UINT32 ui32RegAddr,
344 IMG_UINT32 ui32RegValue,
345 IMG_UINT32 ui32RegMask)
347 IMG_BOOL bCmdsAdded = IMG_FALSE;
350 bCmdsAdded = ScriptPrepareReadMetaRegThroughSP(psScript, ui32MetaRegAddr);
351 if (!bCmdsAdded) return IMG_FALSE;
354 bCmdsAdded = ScriptCondPollRGXReg(psScript,
355 RGX_CR_META_SP_MSLVDATAX,
366 IMG_BOOL ScriptWriteMetaRegThroughSP(RGX_SCRIPT_BUILD *psScript,
367 IMG_UINT32 ui32RegAddr,
368 IMG_UINT32 ui32RegValue)
370 IMG_BOOL bCmdAdded = IMG_FALSE;
372 /* Wait for Slave Port to be Ready */
373 bCmdAdded = ScriptPollRGXReg(psScript,
374 RGX_CR_META_SP_MSLVCTRL1,
375 RGX_CR_META_SP_MSLVCTRL1_READY_EN |
376 RGX_CR_META_SP_MSLVCTRL1_GBLPORT_IDLE_EN,
377 RGX_CR_META_SP_MSLVCTRL1_READY_EN |
378 RGX_CR_META_SP_MSLVCTRL1_GBLPORT_IDLE_EN);
379 if (!bCmdAdded) return IMG_FALSE;
382 bCmdAdded = ScriptWriteRGXReg(psScript,
383 RGX_CR_META_SP_MSLVCTRL0,
385 if (!bCmdAdded) return IMG_FALSE;
387 bCmdAdded = ScriptWriteRGXReg(psScript,
388 RGX_CR_META_SP_MSLVDATAT,
391 /* Wait for complete to be done on the next attempt to read/write */
398 *******************************************************************************
400 @Function ScriptInsertLoopPoint
402 @Description Inserts a loop point in the startup script
408 ******************************************************************************/
409 static IMG_BOOL ScriptInsertLoopPoint(RGX_SCRIPT_BUILD *psScript)
411 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
415 psComm->eOp = RGX_INIT_OP_LOOP_POINT;
424 *******************************************************************************
426 @Function ScriptConditionalBranchOnReg
428 @Description Conditionally branches back to the last loop point in the script.
429 Condition is satisfied by the contents of a register
438 ******************************************************************************/
439 static IMG_BOOL ScriptConditionalBranchOnReg(RGX_SCRIPT_BUILD *psScript,
440 IMG_UINT32 ui32Offset,
441 IMG_UINT32 ui32Value,
444 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
448 psComm->eOp = RGX_INIT_OP_COND_BRANCH;
449 psComm->sConditionalBranchPoint.ui32Offset = ui32Offset;
450 psComm->sConditionalBranchPoint.ui32Value = ui32Value;
451 psComm->sConditionalBranchPoint.ui32Mask = ui32Mask;
459 IMG_BOOL ScriptPollMetaRegThroughSP(RGX_SCRIPT_BUILD *psScript,
460 IMG_UINT32 ui32Offset,
461 IMG_UINT32 ui32PollValue,
462 IMG_UINT32 ui32PollMask)
464 IMG_BOOL bCmdsAdded = IMG_FALSE;
466 bCmdsAdded = ScriptInsertLoopPoint(psScript);
467 if (!bCmdsAdded) return IMG_FALSE;
469 bCmdsAdded = ScriptPrepareReadMetaRegThroughSP(psScript, ui32Offset);
470 if (!bCmdsAdded) return IMG_FALSE;
472 bCmdsAdded = ScriptConditionalBranchOnReg(psScript,
473 RGX_CR_META_SP_MSLVDATAX,
480 IMG_BOOL ScriptDBGReadMetaCoreReg(RGX_SCRIPT_BUILD *psScript,
481 IMG_UINT32 ui32RegAddr,
484 IMG_BOOL bCmdsAdded = IMG_FALSE;
486 /* Core Read Ready? */
487 bCmdsAdded = ScriptPollMetaRegThroughSP(psScript,
488 META_CR_TXUXXRXRQ_OFFSET,
489 META_CR_TXUXXRXRQ_DREADY_BIT,
490 META_CR_TXUXXRXRQ_DREADY_BIT);
492 /* Set the reg we are interested in reading */
493 bCmdsAdded = ScriptWriteMetaRegThroughSP(psScript,
494 META_CR_TXUXXRXRQ_OFFSET,
495 ui32RegAddr | META_CR_TXUXXRXRQ_RDnWR_BIT);
496 if (!bCmdsAdded) return IMG_FALSE;
498 /* Core Read Done? */
499 bCmdsAdded = ScriptPollMetaRegThroughSP(psScript,
500 META_CR_TXUXXRXRQ_OFFSET,
501 META_CR_TXUXXRXRQ_DREADY_BIT,
502 META_CR_TXUXXRXRQ_DREADY_BIT);
505 ScriptDBGReadMetaRegThroughSP(psScript, META_CR_TXUXXRXDT_OFFSET, pszName);
510 #endif /* RGX_FEATURE_META */
513 IMG_BOOL ScriptDBGString(RGX_SCRIPT_BUILD *psScript,
514 const IMG_CHAR *aszString)
516 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
520 psComm->sDBGString.eOp = RGX_INIT_OP_DBG_STRING;
521 strcpy(psComm->sDBGString.aszString, aszString);
522 if (strlen(aszString) >= (sizeof(psComm->sDBGString.aszString) - 2))
524 psComm->sDBGString.aszString[RGX_DBG_CMD_NAME_SIZE-1] = '\0';
533 IMG_BOOL ScriptHalt(RGX_SCRIPT_BUILD *psScript)
535 RGX_INIT_COMMAND *psComm = NextScriptCommand(psScript);
539 psComm->eOp = RGX_INIT_OP_HALT;
547 /******************************************************************************
548 End of file (rgxsrvinit_script.c)
549 ******************************************************************************/