1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: System Services -- general functions
25 Desc: Source code for System Services startup and general
30 *********************************************************************21*/
33 /* header include files (.h) */
37 #include "envopt.h" /* environment options */
38 #include "envdep.h" /* environment dependent */
39 #include "envind.h" /* environment independent */
41 #include "gen.h" /* general layer */
42 #include "ssi.h" /* system services */
44 #include "ss_err.h" /* errors */
45 #include "ss_dep.h" /* implementation-specific */
46 #include "ss_queue.h" /* queues */
47 #include "ss_task.h" /* tasking */
48 #include "ss_msg.h" /* messaging */
49 #include "ss_mem.h" /* memory management interface */
50 #include "ss_gen.h" /* general */
51 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
52 #ifdef SS_FBSED_TSK_REG
54 #endif /* SS_FBSED_TSK_REG */
57 /* ss001.301: additions */
58 #include "cm_mem.h" /* memory management */
60 /* header/extern include files (.x) */
62 #include "gen.x" /* general layer */
63 #include "ssi.x" /* system services */
65 #include "ss_dep.x" /* implementation-specific */
66 #include "ss_queue.x" /* queues */
67 #include "ss_task.x" /* tasking */
68 #include "ss_timer.x" /* timers */
69 #include "ss_strm.x" /* STREAMS */
70 #include "ss_msg.x" /* messaging */
71 #include "ss_mem.x" /* memory management interface */
72 #include "ss_drvr.x" /* driver tasks */
73 #ifdef SS_LOCKLESS_MEMORY
76 #include "cm_mem_wl.x" /* common memory manager */
78 #include "cm_mem.x" /* common memory manager */
79 #endif /* SS_LOCKLESS_MEMORY */
80 #include "ss_gen.x" /* general */
81 /* ss001.301: additions */
82 #ifdef SS_LOGGER_SUPPORT
84 #endif /* SS_LOGGER_SUPPORT */
85 #ifdef SS_MULTICORE_SUPPORT
89 #include "cm_mem_wl.x"
93 /* Cavium Changes:ss004.301 */
95 #include "cvmx-config.h"
97 #endif /* SS_SEUM_CAVIUM */
99 /*ss011.301 : RMIOS release related changes*/
103 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
104 #ifdef SS_FBSED_TSK_REG
106 #endif /* SS_FBSED_TSK_REG */
109 /* public variable declarations */
111 /*ss014.301: SSI-4GMX related changes*/
113 volatile SsOs osCp; /* common OS control point */
115 SsOs osCp; /* common OS control point */
120 SsRegCfg cfgRegInfo[SS_MAX_REGS];
123 /* ss029.103: modification: multiple procId related changes */
124 #ifdef SS_MULTIPLE_PROCS
125 /* static functions */
126 static S16 SInsProcId ARGS((ProcId proc));
127 static S16 SRemProcId ARGS((ProcId proc));
128 static S16 SLockOsCp ARGS((Void));
129 static S16 SULockOsCp ARGS((Void));
130 #endif /* SS_MULTIPLE_PROCS */
132 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
133 static void InitializeForStaticMemLeak ARGS((void));
134 static void InitializeStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo));
135 uint32_t GetNextFreeIdx ARGS((StaticMemAllocInfo * memAllocInfo));
136 void FreeIdx ARGS((uint8_t* ptr, uint32_t idx, StaticMemAllocInfo* memAllocInfo,uint32_t size, char*
137 file, uint32_t line));
138 void LogForStaticMemLeak ARGS((StaticMemAllocInfo* memAllocInfo, char* file,
139 uint32_t line, uint32_t size, void* ptr, uint32_t idx));
140 static void PrintStaticMemAllocInfo ARGS((StaticMemAllocInfo* memAllocInfo, FILE
143 /* ss001.301: additions */
145 void DumpSSIDemandQDebugInformation()
148 RTLIN_DUMP_DEBUG("Demand Q Information\n");
149 RTLIN_DUMP_DEBUG("====================\n");
150 for(i = 0; i < osCp.numSTsks; i++)
152 SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
154 for(j = 0; j < SS_MAX_NUM_DQ; j++)
157 RTLIN_DUMP_DEBUG("Task[%lu] Q[%lu] QSize = %lu region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
159 RTLIN_DUMP_DEBUG("Task[%u] Q[%u] QSize = %u region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
165 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
166 pthread_mutex_t dumpingLock = PTHREAD_MUTEX_INITIALIZER;
168 Void mtSigSegvHndlr()
172 printf("Backtrace for thread Id (%lu) total threads = %d\n", (unsigned long) pthread_self(), osCp.numSTsks);
174 for(i = 0; i < osCp.numSTsks; i++)
176 SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
177 if((tskEntry->dep.tId != pthread_self()) && (tskEntry->dep.tId != 0))
179 pthread_kill(tskEntry->dep.tId, SIGUSR2);
186 Void mtSigUsr2Hndlr()
188 printf("Backtrace for thread Id (%lu) cause:SIGUSR2(%d)\n",(unsigned long) pthread_self(),SIGUSR2);
190 pthread_mutex_lock(&dumpingLock);
192 pthread_mutex_unlock(&dumpingLock);
204 * Fun: System Services initialization function
206 * Desc: This is the general initialization function for
207 * all System Services implementations. It initializes
208 * all the common global data structures and calls the
209 * implementation-specific initialization and start
236 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
237 Txt prntBufLoc[1000];
238 #ifdef SS_DRVR_SUPPORT
239 SsDrvrTskEntry *drvrTsk;
241 /* ss002.301 : Modications */
243 osCp.configFilePath = "/mnt/tmp/configFile";
245 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
247 /* ss019.103 - Modified for correct initialization of OS control point */
248 /* start initializing OS control point */
249 /* ss029.103: modification: multiple procId related changes */
250 #ifndef SS_MULTIPLE_PROCS
251 /* ss004.301: Cavium changes */
252 #ifdef SS_SEUM_CAVIUM
253 osCp.procId = cvmx_get_core_num();
255 osCp.procId = SS_PROC_ID;
256 #endif /* SS_SEUM_CAVIUM */
257 #else /* SS_MULTIPLE_PROCS */
258 for (i = 0; i < SS_MAX_PROCS; i++)
259 osCp.procLst.procId[i] = PROCNC;
261 osCp.procLst.free = SS_MAX_PROCS;
262 #endif /* SS_MULTIPLE_PROCS */
264 #ifdef SS_THR_REG_MAP
265 memset(osCp.threadMemoryRegionMap, SS_INVALID_THREAD_REG_MAP,
266 (sizeof(Region) * SS_MAX_THREAD_REGION_MAP));
270 /* implementation specific general initialization */
274 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
275 sprintf(prntBufLoc,"\n SInit(): ssdInitGen failed to initialize\
276 implementation specific general information \n");
277 SDisplay(1,prntBufLoc);
281 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
282 InitializeForStaticMemLeak();
284 /* initialize memory information */
287 for (i = 0; i < SS_MAX_REGS; i++)
289 reg = &osCp.regionTbl[i];
300 /* ss007.301 initializing the per region mBufRefLock */
301 SInitLock(®->mBufRefLock, SS_LOCK_MUTEX);
303 /* zero the pool information */
305 for (j = 0; j < SS_MAX_POOLS_PER_REG; j++)
306 reg->poolTbl[j].type = SS_POOL_UND;
308 /* find this region ID in the region configuration structure */
309 for (j = 0; j < cfgNumRegs; j++)
310 if (cfgRegInfo[j].region == i)
313 /* this region is not configured */
317 /* Load the configuration information into the region table.
318 * Note, the region still has to be registered, for it to
321 for (k = 0; k < cfgRegInfo[j].numPools; k++)
323 reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
324 if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
325 reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
329 /* Initialization of dynamic regions */
330 for (i = 0; i < SS_MAX_REGS; i++)
332 reg = &osCp.dynRegionTbl[i];
343 /* ss007.301 initializing the per region mBufRefLock */
344 SInitLock(®->mBufRefLock, SS_LOCK_MUTEX);
346 /* zero the pool information */
348 for (j = 0; j < SS_MAX_POOLS_PER_REG; j++)
349 reg->poolTbl[j].type = SS_POOL_UND;
351 /* find this region ID in the region configuration structure */
352 for (j = 0; j < cfgNumRegs; j++)
353 if (cfgRegInfo[j].region == i)
356 /* this region is not configured */
360 /* Load the configuration information into the region table.
361 * Note, the region still has to be registered, for it to
364 for (k = 0; k < cfgRegInfo[j].numPools; k++)
366 reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
367 if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
368 reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
372 ret = ssInitSema(&osCp.regionTblSem, SS_MAX_STSKS);
375 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
376 sprintf(prntBufLoc,"\n SInit(): Could not initialize the region Table Semaphore \n");
377 SDisplay(1,prntBufLoc);
381 /* implementation specific memory initialization */
385 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
386 sprintf(prntBufLoc,"\n SInit(): Memory initialization failed \n");
387 SDisplay(1,prntBufLoc);
392 /* initialize TAPA and system task information */
393 /* ss029.103: modification: multiple procId related changes */
394 #ifndef SS_MULTIPLE_PROCS
395 for (i = 0; i < SS_MAX_ENT; i++)
396 for (j = 0; j < SS_MAX_INST; j++)
397 osCp.tTskIds[i][j] = SS_TSKNC;
398 #else /* SS_MULTIPLE_PROCS */
399 for (i = 0; i < SS_MAX_PROCS; i++)
400 for (j = 0; j < SS_MAX_ENT; j++)
401 for (k = 0; k < SS_MAX_INST; k++)
402 osCp.tTskIds[i][j][k] = SS_TSKNC;
403 #endif /* SS_MULTIPLE_PROCS */
405 for (i = 0; i < SS_MAX_TTSKS; i++)
407 tTsk = &osCp.tTskTbl[i];
412 tTsk->tskType = TTUND;
414 tTsk->initTsk = NULLP;
415 tTsk->actvTsk = NULLP;
417 /* ss029.103: addition: TAPA task control block added */
418 #ifdef SS_MULTIPLE_PROCS
420 #endif /* SS_MULTIPLE_PROCS */
426 osCp.nxtTTskEntry = 0;
428 ret = ssInitSema(&osCp.tTskTblSem, SS_MAX_STSKS);
431 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
432 sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
433 SDisplay(1,prntBufLoc);
437 #ifdef SS_MULTICORE_SUPPORT
438 /* check whether number of system tasks is
439 * equal to number of (regions-1).
440 * The last region is meant for timer task
441 * which under the current feature has as entry
442 * in system task table.
444 if(SS_MAX_STSKS > SS_MAX_REGS)
446 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
451 /* initialize system task information */
452 for (i = 0; i < SS_MAX_STSKS; i++)
454 sTsk = &osCp.sTskTbl[i];
457 sTsk->termPend = FALSE;
459 for (j = 0; j < SS_MAX_TTSKS; j++)
460 sTsk->tTsks[j] = SS_INVALID_IDX;
464 /* ss002.301 : Modifications */
465 #ifdef SS_MULTICORE_SUPPORT
468 sTsk->region = (SS_MAX_REGS - 1);
478 osCp.nxtSTskEntry = 0;
480 ret = SInitLock(&osCp.sTskTblLock, SS_STSKTBL_LOCK);
483 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
484 sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
485 SDisplay(1,prntBufLoc);
489 /* ss028.103 - Addition of lock for mBuf reference count */
490 /* ss007.301 moving the mBufRefLock from common to per region */
491 /* SInitLock(&osCp.mBufRefLock, SS_LOCK_MUTEX);*/
493 /* implementation specific task initialization */
497 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
498 sprintf(prntBufLoc,"\n SInit(): implementation specific task initialization Failed \n");
499 SDisplay(1,prntBufLoc);
503 #ifdef SS_DRVR_SUPPORT
504 /* initialize driver task information */
505 for (i = 0; i < SS_MAX_DRVRTSKS; i++)
507 drvrTsk = &osCp.drvrTskTbl[i];
509 drvrTsk->used = FALSE;
511 drvrTsk->channel = 0;
512 drvrTsk->actvTsk = NULLP;
513 drvrTsk->isTsk = NULLP;
518 osCp.numDrvrTsks = 0;
520 /* implementation specific driver initialization */
524 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
525 sprintf(prntBufLoc,"\n SInit(): ssdInitDrvr failed \n");
526 SDisplay(1,prntBufLoc);
531 /*ss004.301: Cavium Changes */
532 #ifdef SS_SEUM_CAVIUM
533 ret = ssInitRcvWork();
536 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
539 #endif /* SS_SEUM_CAVIUM */
542 /* initialize the demand queue lookup table */
543 osCp.dmndQLookupTbl[0] = 255;
544 osCp.dmndQLookupTbl[1] = 0;
545 osCp.dmndQLookupTbl[2] = 1;
546 osCp.dmndQLookupTbl[3] = 1;
547 for (i = 4; i < 256; i++)
549 if (i >= 128 && i <= 255)
550 osCp.dmndQLookupTbl[i] = 7;
551 if (i >= 64 && i <= 127)
552 osCp.dmndQLookupTbl[i] = 6;
553 if (i >= 32 && i <= 63)
554 osCp.dmndQLookupTbl[i] = 5;
555 if (i >= 16 && i <= 31)
556 osCp.dmndQLookupTbl[i] = 4;
557 if (i >= 8 && i <= 15)
558 osCp.dmndQLookupTbl[i] = 3;
559 if (i >= 4 && i <= 7)
560 osCp.dmndQLookupTbl[i] = 2;
564 /* initialize timer information */
565 for (i = 0; i < SS_MAX_TMRS; i++)
567 tmr = &osCp.tmrTbl[i];
571 tmr->ownerEnt = ENTNC;
572 tmr->ownerInst = INSTNC;
575 * ss015.301 - Modifed in initialization as timer activation
576 * functions enclosed in a union. Also initialized the mtFlag
579 tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
580 #ifndef SS_MULTIPLE_PROCS
582 tmr->ssTmrActvFn.mtFlag = FALSE;
583 tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
590 osCp.nxtTmrEntry = 0;
592 ret = SInitLock(&osCp.tmrTblLock, SS_TMRTBL_LOCK);
595 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
599 /* implementation specific timer initialization */
603 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
604 sprintf(prntBufLoc,"\n SInit(): Could not initialize the timer \n");
605 SDisplay(1,prntBufLoc);
609 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
610 /* ss005.201: Initialize logging streams */
611 /* implementation specific logging initialization */
615 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
616 sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logging streams \n");
617 SDisplay(1,prntBufLoc);
621 #ifdef SS_LOGGER_SUPPORT /* ss001.301: additions */
622 /* Initialize the lock, return on failure */
623 if( SInitLock(&(osCp.logger.bufLock),SS_LOCK_MUTEX) != ROK)
625 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
626 sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logger Buffer Lock \n");
627 SDisplay(1,prntBufLoc);
631 /* Initialize the logger configuration flag */
632 osCp.logger.configured = FALSE;
633 /* Ss002.301 : Initialised */
634 osCp.logger.started = FALSE;
635 #endif /* SS_LOGGER_SUPPORT */
636 /* ss001.301: additions */
638 #ifdef SS_HISTOGRAM_SUPPORT
639 /* Here we are filling all the tapa entity Ids, which will be
640 * helpful to get the entity Id using file name. */
642 #endif /* SS_HISTOGRAM_SUPPORT */
645 #ifdef SS_FBSED_TSK_REG
646 /* Configure task registration based on the configuration */
647 /*ss013.301 : Fixed warnings for 32/64 bit compilation*/
648 cmCfgrTskReg((uint8_t *)"task_info.t");
649 #endif /* SS_FBSED_TSK_REG */
651 /*ss011.301 : RMIOS release related changes*/
656 /* call tst() function */
660 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
665 /* call implementation-specific starter function */
673 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
675 #ifdef SS_LOGGER_SUPPORT
676 /* ss005.301: Deinitialize the logging at the end */
677 SDestroyLock(&(osCp.logger.bufLock));
678 /*ss013.301 : Fix for compile time warning*/
680 #endif /* SS_LOGGER_SUPPORT */
685 SDestroyLock(&osCp.tmrTblLock);
688 #ifdef SS_DRVR_SUPPORT
694 SDestroyLock(&osCp.sTskTblLock);
696 if ( (ssDestroySema(&osCp.tTskTblSem)) != ROK)
698 #if (ERRCLASS & ERRCLS_DEBUG)
699 SSLOGERROR(ERRCLS_DEBUG, ESS012, ERRZERO,
700 "Could not destroy the Semaphore");
701 /* ss005.301: Changes, clean the threads and exit */
708 /* ss007.301 destroying the per region mBufRefLock */
709 for (i= 0;i<SS_MAX_REGS;i++)
711 SDestroyLock(&osCp.regionTbl[i].mBufRefLock);
713 /* ss006.13: addition */
714 if ( (ssDestroySema(&osCp.regionTblSem)) != ROK)
716 #if (ERRCLASS & ERRCLS_DEBUG)
717 SSLOGERROR(ERRCLS_DEBUG, ESS013, ERRZERO,
718 "Could not destroy the Semaphore");
719 /* ss005.301: Changes, clean the threads and exit */
730 /* ss033.103: Added SDeInit API to free all the resources */
733 * Fun: System Services de-initialization function
735 * Desc: This is the de-initialization function for System
736 * Services implementations. It releases all the common
737 * global data structures.
760 SDestroyLock(&osCp.tmrTblLock);
762 #ifdef SS_DRVR_SUPPORT
767 SDestroyLock(&osCp.sTskTblLock);
769 if ((ssDestroySema(&osCp.tTskTblSem)) != ROK)
771 #if (ERRCLASS & ERRCLS_DEBUG)
772 SSLOGERROR(ERRCLS_DEBUG, ESS014, ERRZERO,
773 "Could not destroy the Semaphore");
781 if ((ssDestroySema(&osCp.regionTblSem)) != ROK)
783 #if (ERRCLASS & ERRCLS_DEBUG)
784 SSLOGERROR(ERRCLS_DEBUG, ESS015, ERRZERO,
785 "Could not destroy the Semaphore");
792 /* ss007.301 destroying the per region mBufRefLock */
793 for (regCnt = 0; regCnt < SS_MAX_REGS; regCnt++)
795 SDestroyLock(&osCp.regionTbl[regCnt].mBufRefLock);
798 /* ss005.301: Deinitialize the logging at the end */
799 #ifdef SS_LOGGER_SUPPORT
800 SDestroyLock(&(osCp.logger.bufLock));
801 #endif /* SS_LOGGER_SUPPORT */
806 /* ss001.301: additions */
807 #ifdef SS_LOGGER_SUPPORT
811 Txt *buf /* buffer */
815 Txt *buf; /* buffer */
819 /* buffer synchronisation*/
820 bufSz = cmStrlen((uint8_t *)buf);
821 SLock(&osCp.logger.bufLock);
822 if(osCp.logger.started == FALSE)
824 (Void)SUnlock(&(osCp.logger.bufLock));
828 * Append the buffer to the global buffer
829 * and increment the current buffer size of the global buffer
831 if(((osCp.logger.curBufSiz) + bufSz) >= osCp.logger.maxBufSiz)
833 SFlushBufToLog(osCp.logger.buffer);
834 osCp.logger.curBufSiz = 0;
835 memset(osCp.logger.buffer, '\0', osCp.logger.maxBufSiz);
836 sprintf(osCp.logger.buffer, "%s", buf);
837 osCp.logger.curBufSiz += bufSz;
841 strcat(osCp.logger.buffer,buf);
842 osCp.logger.curBufSiz += bufSz;
844 (Void)SUnlock(&(osCp.logger.bufLock));
847 #endif /* SS_LOGGER_SUPPORT */
852 * Desc: Print a string.
854 * This function should be used for debugging only.
858 * Notes: Text buffer should be null terminated.
860 * SDisplay will replace SPrint.
862 * Typical usage consists of a call to sprintf to
863 * format the string into a buffer followed by a
872 Txt *buf /* buffer */
876 Txt *buf; /* buffer */
880 /* ss001.301: additions */
882 #ifdef SS_LOGGER_SUPPORT
884 #endif /* SS_LOGGER_SUPPORT */
888 } /* end of SPrint */
895 * Desc: Invoked by layer when an unrecoverable
896 * software error is detected. This function should
909 Seq seq, /* sequence */
910 Reason reason /* reason */
913 S16 SError(seq, reason)
914 Seq seq; /* sequence */
915 Reason reason; /* reason */
923 sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
924 (int)dt.month,(int)dt.day,(int)dt.year + 1900,
925 (int)dt.hour,(int)dt.min,(int)dt.sec);
929 ret = ssdError(seq, reason);
940 * Desc: Invoked by layer to log an error.
952 Ent ent, /* Calling layer's entity id */
953 Inst inst, /* Calling layer's instance id */
954 ProcId procId, /* Calling layer's processor id */
955 Txt *file, /* file name where error occured */
956 S32 line, /* line in file where error occured */
957 ErrCls errCls, /* error class */
958 ErrCode errCode, /* layer unique error code */
959 ErrVal errVal, /* error value */
960 Txt *errDesc /* description of error */
963 Void SLogError(ent, inst, procId, file, line,
964 errCls, errCode, errVal, errDesc)
965 Ent ent; /* Calling layer's entity id */
966 Inst inst; /* Calling layer's instance id */
967 ProcId procId; /* Calling layer's processor id */
968 Txt *file; /* file name where error occured */
969 S32 line; /* line in file where error occured */
970 ErrCls errCls; /* error class */
971 ErrCode errCode; /* layer unique error code */
972 ErrVal errVal; /* error value */
973 Txt *errDesc; /* description of error */
980 /*ss014.301: SSI-4GMX related changes*/
981 #ifndef SS_4GMX_LCORE
983 sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
984 (int)dt.month,(int)dt.day,(int)dt.year + 1900,
985 (int)dt.hour,(int)dt.min,(int)dt.sec);
989 /* ss001.301: additions */
990 #ifdef SS_LOGGER_SUPPORT
992 #endif /* SS_LOGGER_SUPPORT */
994 ssdLogError(ent, inst, procId, file, line,
995 errCls, errCode, errVal, errDesc);
1001 /* ss029.103: modification:
1002 SFndProcId function is not supported with multiple procIds */
1003 #ifndef SS_MULTIPLE_PROCS
1009 * Desc: This function finds the local processor ID.
1011 * Ret: local processor id
1028 return (osCp.procId);
1029 } /* end of SFndProcId */
1036 * Desc: This function stores the local processor ID.
1051 Void SSetProcId(procId)
1056 osCp.procId = procId;
1061 #endif /* SS_MULTIPLE_PROCS */
1063 /* ss029.103: addition: New SSI functions with multiple proc support */
1064 #ifdef SS_MULTIPLE_PROCS
1068 * Fun: SGetProcIdIdx
1070 * Desc: This function finds index of procId in the process id table
1080 uint16_t SGetProcIdIdx
1085 uint16_t SGetProcIdIdx(proc)
1092 idx = SS_HASH_IDX(proc);
1094 for (i = idx; i < SS_MAX_PROCS; i++)
1095 if (osCp.procLst.procId[i] == proc)
1098 /* search upto idx */
1099 for (i = 0; i < idx; i++)
1100 if (osCp.procLst.procId[i] == proc)
1103 return (SS_INV_PROCID_IDX);
1104 } /* SGetProcIdIdx */
1111 * Desc: This function inserts procId in the process id table
1121 static S16 SInsProcId
1126 static S16 SInsProcId(proc)
1134 idx = SS_HASH_IDX(proc);
1136 for (i = idx; i < SS_MAX_PROCS; i++)
1137 if (osCp.procLst.procId[i] == SS_INV_PROCID)
1139 osCp.procLst.procId[i] = proc;
1140 osCp.procLst.free--;
1144 /* search for free entry upto idx */
1145 for (i = 0; i < idx; i++)
1146 if (osCp.procLst.procId[i] == SS_INV_PROCID)
1148 osCp.procLst.procId[i] = proc;
1149 osCp.procLst.free--;
1161 * Desc: This function inserts procId in the process id table
1171 static S16 SRemProcId
1176 static S16 SRemProcId(proc)
1184 idx = SS_HASH_IDX(proc);
1186 for (i = idx; i < SS_MAX_PROCS; i++)
1187 if (osCp.procLst.procId[i] == proc)
1189 osCp.procLst.procId[i] = SS_INV_PROCID;
1190 osCp.procLst.free++;
1194 /* search upto idx */
1195 for (i = 0; i < idx; i++)
1196 if (osCp.procLst.procId[i] == proc)
1198 osCp.procLst.procId[i] = SS_INV_PROCID;
1199 osCp.procLst.free++;
1211 * Desc: This function locks OsCp
1221 static S16 SLockOsCp
1226 static S16 SLockOsCp(Void)
1232 ret = SLock(&osCp.sTskTblLock);
1235 SSLOGERROR(ERRCLS_DEBUG, ESS016, ERRZERO,
1236 "Could not lock system task table");
1240 SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
1244 #if (ERRCLASS & ERRCLS_DEBUG)
1245 SSLOGERROR(ERRCLS_DEBUG, ESS017, ERRZERO,
1246 "Could not lock TAPA task table");
1249 if ( SUnlock(&osCp.sTskTblLock) != ROK)
1251 #if (ERRCLASS & ERRCLS_DEBUG)
1252 SSLOGERROR(ERRCLS_DEBUG, ESS018, ERRZERO,
1253 "Could not give the Semaphore");
1270 * Desc: This function locks OsCp
1280 static S16 SULockOsCp
1285 static S16 SULockOsCp(Void)
1289 /* unlock the table */
1290 SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1292 if ( SUnlock(&osCp.sTskTblLock) != ROK)
1294 #if (ERRCLASS & ERRCLS_DEBUG)
1295 SSLOGERROR(ERRCLS_DEBUG, ESS019, ERRZERO,
1296 "Could not give the Semaphore");
1309 * Fun: SAddProcIdLst
1311 * Desc: This function adds given proc ids to the list
1327 S16 SAddProcIdLst(numPIds, pIdLst)
1336 #if (ERRCLASS & ERRCLS_INT_PAR)
1338 if (numPIds > SS_MAX_PROCS)
1340 SSLOGERROR(ERRCLS_INT_PAR, ESS020, ERRZERO, "number of proc Ids exceeds\
1345 /* find if the entry exist in the table */
1346 for (i = 0; i < numPIds; i++)
1348 if (pIdLst[i] == SS_INV_PROCID)
1350 SSLOGERROR(ERRCLS_INT_PAR, ESS021, ERRZERO, "Invalid proc Ids");
1357 if (SLockOsCp() != ROK)
1360 #if (ERRCLASS & ERRCLS_INT_PAR)
1361 for (i = 0; i < numPIds; i++)
1362 if (SGetProcIdIdx(pIdLst[i]) != SS_INV_PROCID_IDX)
1364 SSLOGERROR(ERRCLS_INT_PAR, ESS022, ERRZERO, "Duplicate proc id");
1365 (Void) SULockOsCp();
1369 if (numPIds > osCp.procLst.free)
1371 SSLOGERROR(ERRCLS_INT_PAR, ESS023, ERRZERO, "Total number of proc id \
1373 (Void) SULockOsCp();
1378 /* insert the entries in the table */
1381 for (i = 0; i < numPIds; i++)
1383 if (SInsProcId(pIdLst[i]) == RFAILED)
1385 #if (ERRCLASS & ERRCLS_DEBUG)
1386 SSLOGERROR(ERRCLS_DEBUG, ESS024, ERRZERO,
1387 "Could not insert the proc id");
1389 (Void) SULockOsCp();
1394 /* unlock the table */
1395 if (SULockOsCp() != ROK)
1399 } /* SAddProcIdLst */
1404 * Fun: SRemProcIdLst
1406 * Desc: This function adds given proc ids to the list
1422 S16 SRemProcIdLst(numPIds, pIdLst)
1430 #if (ERRCLASS & ERRCLS_INT_PAR)
1432 if (numPIds > SS_MAX_PROCS)
1436 if (SLockOsCp() != ROK)
1439 if (numPIds > (SS_MAX_PROCS - osCp.procLst.free))
1441 (Void) SULockOsCp();
1445 /* find if the entry exist in the table */
1446 for (i = 0; i < numPIds; i++)
1448 if (SGetProcIdIdx(pIdLst[i]) == SS_INV_PROCID_IDX)
1450 (Void) SULockOsCp();
1455 /* insert the entries in the table */
1456 for (i = 0; i < numPIds; i++)
1457 SRemProcId(pIdLst[i]);
1459 if (SULockOsCp() != ROK)
1463 } /* SRemProcIdLst */
1468 * Fun: SGetProcIdLst
1470 * Desc: This function retrieves proc Id list
1486 S16 SGetProcIdLst(numPIds, pIdLst)
1495 #if (ERRCLASS & ERRCLS_INT_PAR)
1496 if ((numPIds == NULLP) || (pIdLst == NULLP))
1498 SSLOGERROR(ERRCLS_INT_PAR, ESS025, ERRZERO, "Invalid numPIds/pIdLst");
1503 if (SLockOsCp() != ROK)
1506 for (i = 0; i < SS_MAX_PROCS; i++)
1508 if (osCp.procLst.procId[i] != PROCNC)
1509 pIdLst[count++] = osCp.procLst.procId[i];
1514 if (SULockOsCp() != ROK)
1521 } /* SGetProcIdLst */
1528 * Desc: This function retrieves protocol layer control block for given proc,
1547 S16 SGetXxCb(proc, ent, inst, xxCb)
1558 #if (ERRCLASS & ERRCLS_INT_PAR)
1559 if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) || (inst >= SS_MAX_INST))
1561 SSLOGERROR(ERRCLS_INT_PAR, ESS026, ERRZERO, "Invalid proc/entity/instance");
1567 * ss030.103: delete: locking/unlocking removed as it causes
1568 * deadlock/blockage in some cases
1571 procIdIdx = SGetProcIdIdx(proc);
1573 if (procIdIdx == SS_INV_PROCID_IDX)
1575 #if (ERRCLASS & ERRCLS_INT_PAR)
1576 SSLOGERROR(ERRCLS_INT_PAR, ESS027, ERRZERO, "Could not get proc table idx");
1581 idx = osCp.tTskIds[procIdIdx][ent][inst];
1582 if (idx == SS_TSKNC)
1588 *xxCb = osCp.tTskTbl[idx].xxCb;
1589 /*ss032.103 added a check for NULLP */
1596 #endif /* SS_MULTIPLE_PROCS */
1598 /* ss001.301: additions */
1599 #ifdef SS_HISTOGRAM_SUPPORT
1604 * Desc: It is static data base contains all entity Ids of tapa task.
1605 * This Data base is used to find the entity id using two letter
1606 * prifix product code.
1621 S16 SFillEntIds(Void)
1625 uint8_t entInfo[26][26] = {
1626 /* A B C D E F G H I J K *
1627 L M N O P Q R S T U V *
1629 {ENTAA, ENTAB, ENTAC, ENTNC, ENTAE, ENTAF, ENTNC, ENTAH, ENTNC, ENTNC, ENTNC,
1630 /* A */ ENTAL, ENTAM, ENTNC, ENTNC, ENTAP, ENTAQ, ENTAR, ENTAS, ENTNC, ENTAU, ENTNC,
1631 ENTAW, ENTNC, ENTNC, ENTNC},
1633 /* A B C D E F G H I J K *
1634 L M N O P Q R S T U V *
1636 {ENTNC, ENTNC, ENTNC, ENTBD, ENTNC, ENTNC, ENTNC, ENTNC, ENTBI, ENTNC, ENTNC,
1637 /* B */ ENTNC, ENTBM, ENTNC, ENTNC, ENTNC, ENTNC, ENTBR, ENTBS, ENTNC, ENTNC, ENTBV,
1638 ENTBW, ENTNC, ENTNC, ENTNC},
1639 /* A B C D E F G H I J K *
1640 L M N O P Q R S T U V *
1642 {ENTNC, ENTNC, ENTCC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCH, ENTNC, ENTNC, ENTNC,
1643 /* C */ ENTCL, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCS, ENTNC, ENTCU, ENTCV,
1644 ENTNC, ENTNC, ENTNC, ENTNC},
1645 /* A B C D E F G H I J K *
1646 L M N O P Q R S T U V *
1648 {ENTNC, ENTDB, ENTNC, ENTNC, ENTNC, ENTNC, ENTDG, ENTNC, ENTDI, ENTNC, ENTDK,
1649 /* D */ ENTNC, ENTDM, ENTDN, ENTNC, ENTDP, ENTNC, ENTNC, ENTNC, ENTDT, ENTDU, ENTDV,
1650 ENTNC, ENTNC, ENTNC, ENTNC},
1651 /* A B C D E F G H I J K *
1652 L M N O P Q R S T U V *
1654 {ENTNC, ENTNC, ENTNC, ENTNC, ENTEC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1655 /* E */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTER, ENTES, ENTNC, ENTNC, ENTEV,
1656 ENTNC, ENTNC, ENTNC, ENTNC},
1657 /* A B C D E F G H I J K *
1658 L M N O P Q R S T U V *
1660 {ENTFA, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1661 /* F */ ENTNC, ENTFM, ENTFN, ENTNC, ENTFP, ENTNC, ENTFR, ENTNC, ENTNC, ENTFU, ENTNC,
1662 ENTFW, ENTNC, ENTNC, ENTNC},
1663 /* A B C D E F G H I J K *
1664 L M N O P Q R S T U V *
1666 {ENTGA, ENTGB, ENTGC, ENTGD, ENTGE, ENTGF, ENTGG, ENTGH, ENTGI, ENTNC, ENTNC,
1667 /* G */ ENTGL, ENTGM, ENTGN, ENTGO, ENTGP, ENTNC, ENTGR, ENTGS, ENTGT, ENTGU, ENTNC,
1668 ENTGW, ENTGX, ENTGY, ENTGZ},
1669 /* A B C D E F G H I J K *
1670 L M N O P Q R S T U V *
1672 {ENTNC, ENTNC, ENTHC, ENTNC, ENTHE, ENTNC, ENTHG, ENTNC, ENTHI, ENTNC, ENTNC,
1673 /* H */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTHR, ENTHS, ENTNC, ENTHU, ENTNC,
1674 ENTNC, ENTNC, ENTNC, ENTNC},
1675 /* A B C D E F G H I J K *
1676 L M N O P Q R S T U V *
1678 {ENTIA, ENTIB, ENTNC, ENTID, ENTIE, ENTNC, ENTNC, ENTNC, ENTII, ENTNC, ENTNC,
1679 /* I */ ENTNC, ENTIM, ENTIN, ENTNC, ENTNC, ENTIQ, ENTNC, ENTIS, ENTIT, ENTIU, ENTNC,
1680 ENTIW, ENTIX, ENTNC, ENTNC},
1681 /* A B C D E F G H I J K *
1682 L M N O P Q R S T U V *
1684 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1685 /* J */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1686 ENTNC, ENTNC, ENTNC, ENTNC},
1687 /* A B C D E F G H I J K *
1688 L M N O P Q R S T U V *
1690 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1691 /* K */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1692 ENTRLC, ENTNC, ENTNC, ENTNC},
1693 /* A B C D E F G H I J K *
1694 L M N O P Q R S T U V *
1696 {ENTLA, ENTLB, ENTLC, ENTLD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTLK,
1697 /* L */ ENTNC, ENTLM, ENTLN, ENTNC, ENTNC, ENTNC, ENTLR, ENTNC, ENTLT, ENTLU, ENTLV,
1698 ENTNC, ENTLX, ENTNC, ENTNC},
1699 /* A B C D E F G H I J K *
1700 L M N O P Q R S T U V *
1702 {ENTMA, ENTNC, ENTMC, ENTMD, ENTME, ENTNC, ENTMG, ENTNC, ENTNC, ENTNC, ENTMK,
1703 /* M */ ENTML, ENTMM, ENTNC, ENTNC, ENTNC, ENTNC, ENTMR, ENTMS, ENTMT, ENTMU, ENTMV,
1704 ENTMW, ENTMX, ENTNC, ENTMZ},
1705 /* A B C D E F G H I J K *
1706 L M N O P Q R S T U V *
1708 {ENTNC, ENTNC, ENTNC, ENTND, ENTNC, ENTNF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1709 /* N */ ENTNC, ENTNM, ENTNC, ENTNC, ENTNP, ENTNC, ENTNC, ENTNS, ENTNC, ENTNC, ENTNV,
1710 ENTNW, ENTNC, ENTNC, ENTNC},
1711 /* A B C D E F G H I J K *
1712 L M N O P Q R S T U V *
1714 {ENTNC, ENTNC, ENTNC, ENTOD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1715 /* O */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1716 ENTNC, ENTNC, ENTNC, ENTNC},
1717 /* A B C D E F G H I J K *
1718 L M N O P Q R S T U V *
1720 {ENTPA, ENTNC, ENTNC, ENTPD, ENTNC, ENTNC, ENTNC, ENTPH, ENTNC, ENTNC, ENTNC,
1721 /* P */ ENTPL, ENTNC, ENTPN, ENTNC, ENTPN, ENTPQ, ENTPR, ENTNC, ENTNC, ENTPU, ENTPV,
1722 ENTNC, ENTNC, ENTNC, ENTNC},
1723 /* A B C D E F G H I J K *
1724 L M N O P Q R S T U V *
1726 {ENTNC, ENTNC, ENTQC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTQI, ENTNC, ENTNC,
1727 /* Q */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1728 ENTQW, ENTNC, ENTNC, ENTNC},
1729 /* A B C D E F G H I J K *
1730 L M N O P Q R S T U V *
1732 {ENTRA, ENTNC, ENTNC, ENTRD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1733 /* R */ ENTRL, ENTRM, ENTRN, ENTNC, ENTRP, ENTNC, ENTRR, ENTNC, ENTRT, ENTRU, ENTNC,
1734 ENTNC, ENTRX, ENTRY, ENTNC},
1735 /* A B C D E F G H I J K *
1736 L M N O P Q R S T U V *
1738 {ENTSA, ENTSB, ENTSC, ENTSD, ENTSE, ENTSF, ENTSG, ENTSH, ENTSI, ENTNC, ENTNC,
1739 /* S */ ENTNC, ENTSM, ENTSN, ENTSO, ENTSP, ENTNC, ENTSR, ENTSS, ENTST, ENTSU, ENTSV,
1740 ENTNC, ENTNC, ENTNC, ENTSZ},
1741 /* A B C D E F G H I J K *
1742 L M N O P Q R S T U V *
1744 {ENTNC, ENTNC, ENTTC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1745 /* T */ ENTNC, ENTTM, ENTNC, ENTNC, ENTTP, ENTNC, ENTNC, ENTTS, ENTTT, ENTTU, ENTNC,
1746 ENTNC, ENTNC, ENTNC, ENTNC},
1747 /* A B C D E F G H I J K *
1748 L M N O P Q R S T U V *
1750 {ENTNC, ENTNC, ENTNC, ENTUD, ENTNC, ENTNC, ENTNC, ENTUH, ENTNC, ENTNC, ENTNC,
1751 /* U */ ENTUL, ENTUM, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTUS, ENTNC, ENTNC, ENTNC,
1752 ENTNC, ENTNC, ENTNC, ENTUZ},
1753 /* A B C D E F G H I J K *
1754 L M N O P Q R S T U V *
1756 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1757 /* V */ ENTNC, ENTVM, ENTNC, ENTVO, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVU, ENTNC,
1758 ENTNC, ENTNC, ENTNC, ENTNC},
1759 /* A B C D E F G H I J K *
1760 L M N O P Q R S T U V *
1762 {ENTNC, ENTNC, ENTWC, ENTWD, ENTNC, ENTNC, ENTNC, ENTNC, ENTWI, ENTNC, ENTNC,
1763 /* W */ ENTNC, ENTNC, ENTWN, ENTNC, ENTNC, ENTNC, ENTNC, ENTWS, ENTNC, ENTWU, ENTNC,
1764 ENTNC, ENTNC, ENTNC, ENTNC},
1765 /* A B C D E F G H I J K *
1766 L M N O P Q R S T U V *
1768 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXG, ENTNC, ENTXI, ENTNC, ENTNC,
1769 /* X */ ENTNC, ENTXM, ENTXN, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXU, ENTNC,
1770 ENTNC, ENTXX, ENTXY, ENTNC},
1771 /* A B C D E F G H I J K *
1772 L M N O P Q R S T U V *
1774 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1775 /* Y */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1776 ENTNC, ENTNC, ENTNC, ENTNC},
1777 /* A B C D E F G H I J K *
1778 L M N O P Q R S T U V *
1780 {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1781 /* Z */ ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1782 ENTNC, ENTNC, ENTNC, ENTNC}
1785 /*ss013.301 :Adding TRC MACRO*/
1786 memcpy(osCp.entId, entInfo, sizeof(entInfo));
1796 * Desc: This function gives the entity Id depending in the
1797 * file name. This function uses the first two letter
1798 * of file name to find the entity id.
1803 * RFAILED Region not registered
1814 S16 SGetEntInd(entId, fileName)
1821 uint8_t *letter = NULLP;
1822 /* ss002.301 Additions */
1823 S8 *strippedName = NULLP;
1825 uint8_t tempIdx = 0;
1826 uint8_t firstIdx = 0;
1827 uint8_t secondIdx = 0;
1830 /* ss002.301 Additions */
1831 if ((strippedName = strrchr((const char *)fileName, '/')))
1833 fileName = (uint8_t *)strippedName + 1;
1836 if(fileName[0] =='l' && fileName[3] == '.')
1838 /* Usally layer manager interface files starts
1839 * with l. so leave the first letter and take
1841 * Eg. Layer manger inteface file name for TUCL is lhi.c.
1842 * so here we leave l and we take hi to get the entity Id. */
1843 letter = ++fileName;
1848 /* Handle exceptional file names */
1852 if (letter[1] == 'g' && letter[2] == 'u')
1864 /* here first two charactes of file name should be alphabets.
1865 * if any one of the letter is non alphabet then we return ENTNC
1866 * as an entity Id */
1867 /* Eg. In fileName l4_ptui.c, second letter is numeral. so we consider
1868 * this file belogs to entity Id ENTNC. */
1869 for(count = 0; count < 2; count++)
1871 /* ss002.301 - Optimizations */
1872 if(letter[count] < 'a' || letter[count] > 'z')
1879 tempIdx = letter[count] - 'a';
1887 secondIdx = tempIdx;
1890 /* First two letter of file name are alphabets the get the
1891 * entity id from the static data base which is loaded in sFillEntIds() */
1892 *entId = osCp.entId[firstIdx][secondIdx];
1896 #endif /* SS_HISTOGRAM_SUPPORT */
1897 #ifdef SS_LOCK_SUPPORT
1898 /* ss002.301 Readwrite lock additions */
1903 * Desc: This function is used to aquire the read write lock
1920 S16 SLockNew(lockId, lockType)
1928 if((retVal = ssdLockNew(lockId, lockType)) != ROK)
1930 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SLockNew(): Failed to aquire the lock\n");
1940 * Desc: This function is used to aquire the read write lock
1956 S16 SInitLockNew(lockId, lockType)
1964 if((retVal = ssdInitLockNew(lockId, lockType)) != ROK)
1966 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SInitLockNew(): Initialization of lock Failed\n");
1976 * Desc: This function is used to Unlock the read write lock
1992 S16 SUnlockNew(lockId, lockType)
2000 if((retVal = ssdUnlockNew(lockId, lockType)) != ROK)
2002 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SUnlockNew(): Failed to release the lock\n");
2010 * Fun: SDestroyLockNew
2012 * Desc: This function is used to destroy the read write lock
2028 S16 SDestroyLockNew(lockId, lockType)
2036 if((retVal = ssdDestroyLockNew(lockId, lockType)) != ROK)
2038 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SDestroyLockNew(): Failed to destroy the lock\n");
2043 #endif /* SS_LOCK_SUPPORT */
2045 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
2046 /* Static memory leak detection changes */
2047 static uint32_t StaticMemLeakAge;
2048 static uint32_t StaticMemLeakIntCount = 1;
2050 void PrintStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo, FILE *opFile)
2054 fprintf(opFile, "Current Time = %ld\n",StaticMemLeakAge);
2056 for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
2058 if(memAllocInfo->allocations[i].ptr)
2060 fprintf(opFile, "p = %p f = %s l = %ld s = %ld a = %ld\n",
2061 memAllocInfo->allocations[i].ptr,
2062 memAllocInfo->allocations[i].file,
2063 memAllocInfo->allocations[i].lineNo,
2064 memAllocInfo->allocations[i].size,
2065 memAllocInfo->allocations[i].age);
2072 void InitializeStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo)
2075 /* index 0 is not used; nextIdx as 0 means end of list */
2076 memAllocInfo->nextFreeIdx = 1;
2078 for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
2080 memAllocInfo->allocations[i].listInfo.nextIdx = i + 1;
2081 memAllocInfo->allocations[i].ptr = 0;
2084 /* override the last one to point to 0 meaning end of list */
2085 memAllocInfo->allocations[MAX_MEM_ALLOCATIONS - 1].listInfo.nextIdx = 0;
2088 uint32_t GetNextFreeIdx(StaticMemAllocInfo * memAllocInfo)
2090 uint32_t toBeReturned = memAllocInfo->nextFreeIdx;
2092 uint32_t newNextFreeIdx = memAllocInfo->allocations[memAllocInfo->nextFreeIdx].listInfo.nextIdx;
2094 if(newNextFreeIdx == 0 || newNextFreeIdx >= MAX_MEM_ALLOCATIONS)
2096 printf("Something wrong in GetNextFreeIdx newNextIdx = %ld\n",newNextFreeIdx);
2099 memAllocInfo->nextFreeIdx = newNextFreeIdx;
2101 return toBeReturned;
2104 #define CRASH_ENB {int *p = 0; *p = 100;}
2105 void FreeIdx(uint8_t* ptr, uint32_t idx, StaticMemAllocInfo* memAllocInfo,uint32_t size, char* file, uint32_t line)
2107 if(idx == 0 || idx >= MAX_MEM_ALLOCATIONS)
2109 printf("Something wrong in FreeIdx... idx = %ld called from %s:%ld\n",idx,file,line);
2112 /*printf("FreeIdx... idx = %d nexFree = %d\n",idx, memAllocInfo->nextFreeIdx);*/
2113 memAllocInfo->allocations[idx].listInfo.nextIdx = memAllocInfo->nextFreeIdx;
2114 if((ptr != memAllocInfo->allocations[idx].ptr) ||
2115 (size != memAllocInfo->allocations[idx].size))
2117 #ifdef XEON_SPECIFIC_CHANGES
2121 printf("Freeing wrong ptr stored = %p trying to free %p freeing size (%ld)"
2122 "allocated size(%ld) from %s:%ld\n",
2123 memAllocInfo->allocations[idx].ptr,
2126 memAllocInfo->allocations[idx].size,
2129 printf("Allocation was done from %s:%ld\n",memAllocInfo->allocations[idx].file, memAllocInfo->allocations[idx].lineNo);
2130 printf("***********************************************************\n");
2134 memAllocInfo->allocations[idx].ptr = 0;
2136 memAllocInfo->nextFreeIdx = idx;
2140 void LogForStaticMemLeak(StaticMemAllocInfo* memAllocInfo, char* file, uint32_t line, uint32_t size, void* ptr, uint32_t idx)
2143 memAllocInfo->allocations[idx].file = file;
2144 memAllocInfo->allocations[idx].lineNo = line;
2145 memAllocInfo->allocations[idx].size = size;
2146 memAllocInfo->allocations[idx].ptr = ptr;
2147 memAllocInfo->allocations[idx].age = StaticMemLeakAge;
2149 if(StaticMemLeakIntCount++ % 256 == 0)
2155 void InitializeForStaticMemLeak()
2159 StaticMemLeakFileArr[0] = fopen("region0.log","w");
2160 StaticMemLeakFileArr[1] = fopen("region1.log","w");
2161 StaticMemLeakFileArr[2] = fopen("region2.log","w");
2162 StaticMemLeakFileArr[3] = fopen("region3.log","w");
2164 if(StaticMemLeakFileArr[0] == NULL ||
2165 StaticMemLeakFileArr[1] == NULL ||
2166 StaticMemLeakFileArr[2] == NULL ||
2167 StaticMemLeakFileArr[3] == NULL)
2170 printf("Could not open files for Static Mem Leak detection logging :( crashing...\n");
2174 for(i = 0; i < 4; i++)
2176 InitializeStaticMemAllocInfo(&SMemLeakInfo[i]);
2180 void DumpStaticMemLeakFiles()
2184 for(i = 0; i < 4; i++)
2186 PrintStaticMemAllocInfo(&SMemLeakInfo[i], StaticMemLeakFileArr[i]);
2189 /* Static memory leak detection changes */
2194 * Fun: ssRegMainThread
2196 * Desc: This function is used to add the memory region
2197 * mapping for the main thread.
2199 * Ret: VOID (Always successful)
2216 Txt prntBuf[PRNTSZE];
2218 sprintf(prntBuf, "\n SReInitTmr(): ReStarting the Tmr\n");
2219 SDisplay(1,prntBuf);
2220 ret = ssdReInitTmr();
2223 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
2224 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SReInitTmr(): Failed to Restart the Tmr\n");
2232 * Fun: SGetConfigPath
2234 * Desc: This function is used to Get config files path
2236 * Ret: S8* config file Path
2243 S8* SGetConfigPath(Void)
2245 return osCp.configFilePath;
2248 /**********************************************************************
2250 **********************************************************************/