d7ef85650fa5d199c9410431ff3547ff4757443b
[o-du/l2.git] / src / mt / ss_gen.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18 \f
19 /********************************************************************20**
20  
21      Name:     System Services -- general functions
22  
23      Type:     C source file
24  
25      Desc:     Source code for System Services startup and general
26                System Services.
27  
28      File:     ss_gen.c
29  
30 *********************************************************************21*/
31
32 \f
33 /* header include files (.h) */
34
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include "envopt.h"        /* environment options */
38 #include "envdep.h"        /* environment dependent */
39 #include "envind.h"        /* environment independent */
40   
41 #include "gen.h"           /* general layer */
42 #include "ssi.h"           /* system services */
43
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
53 #include "cm_task.h"
54 #endif /* SS_FBSED_TSK_REG */
55 #include "cm_llist.h"
56 #include "cm_hash.h"
57 /* ss001.301: additions */
58 #include "cm_mem.h"        /* memory management */
59
60 /* header/extern include files (.x) */
61
62 #include "gen.x"           /* general layer */
63 #include "ssi.x"           /* system services */
64
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
74 #include "cm_llist.x"
75 #include "cm_hash.x"
76 #include "cm_mem_wl.x"        /* common memory manager */
77 #else
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 
83 #include "cm_lib.x"
84 #endif /* SS_LOGGER_SUPPORT  */
85 #ifdef SS_MULTICORE_SUPPORT
86 #include "cm_llist.x"
87 #include "cm_hash.x"
88 #include "cm_mem.h"
89 #include "cm_mem_wl.x"
90 #include "cm_lib.x"
91 #endif
92
93 /* Cavium Changes:ss004.301 */
94 #ifdef SS_SEUM_CAVIUM
95 #include "cvmx-config.h"
96 #include "cvmx.h"
97 #endif /* SS_SEUM_CAVIUM */
98
99 /*ss011.301 : RMIOS release related changes*/
100 #ifdef SS_RMIOS
101 #include "mt_msgr.x"
102 #endif
103 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
104 #ifdef SS_FBSED_TSK_REG
105 #include "cm_task.x"
106 #endif /* SS_FBSED_TSK_REG */
107 #include <signal.h>
108 \f
109 /* public variable declarations */
110
111 /*ss014.301: SSI-4GMX related changes*/
112 #ifdef SS_4GMX_LCORE
113 volatile SsOs     osCp;           /* common OS control point */
114 #else
115 SsOs     osCp;           /* common OS control point */
116 #endif
117
118  
119 Cntr     cfgNumRegs;
120 SsRegCfg cfgRegInfo[SS_MAX_REGS];
121
122 \f
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 */
131
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
141       *opFile));
142 #endif
143 /* ss001.301: additions */
144
145 void DumpSSIDemandQDebugInformation()
146 {
147    uint32_t i,j;
148    RTLIN_DUMP_DEBUG("Demand Q Information\n");
149    RTLIN_DUMP_DEBUG("====================\n");
150    for(i = 0; i < osCp.numSTsks; i++)
151    {
152       SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
153       
154       for(j = 0; j < SS_MAX_NUM_DQ; j++)
155       {
156 #ifndef ALIGN_64BIT
157          RTLIN_DUMP_DEBUG("Task[%lu] Q[%lu] QSize = %lu region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
158 #else
159          RTLIN_DUMP_DEBUG("Task[%u] Q[%u] QSize = %u region=%d\n", i, j, tskEntry->dQ.queue[j].crntSize,tskEntry->region);
160 #endif
161       }
162    }
163 }
164
165 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
166 pthread_mutex_t dumpingLock = PTHREAD_MUTEX_INITIALIZER;
167
168 Void mtSigSegvHndlr()
169 {
170    int i;
171
172    printf("\nBacktrace for thread Id (%lu) total threads = %d\n", (unsigned long) pthread_self(), osCp.numSTsks);   
173    ysPrntBkTrace();
174    for(i = 0; i < osCp.numSTsks; i++)
175    {
176       SsSTskEntry* tskEntry = &(osCp.sTskTbl[i]);
177       if((tskEntry->dep.tId != pthread_self()) && (tskEntry->dep.tId != 0))
178       {
179           pthread_kill(tskEntry->dep.tId, SIGUSR2);
180       }
181    }
182
183    sleep(5);
184 }
185
186 Void mtSigUsr2Hndlr()
187 {
188    printf("\nBacktrace for thread Id (%lu) cause:SIGUSR2(%d)\n",(unsigned long) pthread_self(),SIGUSR2);   
189
190    pthread_mutex_lock(&dumpingLock);  
191    ysPrntBkTrace();
192    pthread_mutex_unlock(&dumpingLock);  
193
194    sleep(5);
195    
196    exit(0);
197 }
198
199 #endif
200
201 \f
202 /*
203 *
204 *       Fun:   System Services initialization function
205 *
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
210 *              functions.
211 *
212 *       Ret:   Void
213 *
214 *       Notes: 
215 *
216 *       File:  ss_gen.c
217 *
218 */
219 S16 SInit(void)
220 {
221    S16 ret;
222    REG1 S16 i;
223    REG2 S16 j;
224    REG3 S16 k;
225    SsTTskEntry *tTsk;
226    SsSTskEntry *sTsk;
227    SsTmrEntry *tmr;
228    SsRegionEntry *reg;
229    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
230    Txt prntBufLoc[1000];
231 #ifdef SS_DRVR_SUPPORT
232    SsDrvrTskEntry *drvrTsk;
233 #endif
234 /* ss002.301 : Modications */
235
236    osCp.configFilePath = "/mnt/tmp/configFile";
237
238    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
239  
240    /* ss019.103 - Modified for correct initialization of OS control point */
241    /* start initializing OS control point */
242 /* ss029.103: modification: multiple procId related changes */ 
243 #ifndef SS_MULTIPLE_PROCS
244 /* ss004.301: Cavium changes */
245 #ifdef SS_SEUM_CAVIUM
246                   osCp.procId = cvmx_get_core_num();
247 #else
248                   osCp.procId = SS_PROC_ID;
249 #endif /* SS_SEUM_CAVIUM */
250 #else /* SS_MULTIPLE_PROCS */
251    for (i = 0; i < SS_MAX_PROCS; i++)
252       osCp.procLst.procId[i] = PROCNC;
253
254    osCp.procLst.free = SS_MAX_PROCS;
255 #endif /* SS_MULTIPLE_PROCS */
256
257 #ifdef SS_THR_REG_MAP
258    memset(osCp.threadMemoryRegionMap, SS_INVALID_THREAD_REG_MAP, 
259             (sizeof(Region) * SS_MAX_THREAD_REGION_MAP));
260    ssRegMainThread();
261 #endif
262
263    /* implementation specific general initialization */
264    ret = ssdInitGen();
265    if (ret != ROK)
266         {
267    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
268           sprintf(prntBufLoc,"\n SInit(): ssdInitGen failed to initialize\
269                                                                 implementation specific general information \n");
270       SDisplay(1,prntBufLoc);
271       return RFAILED;
272         }
273  
274 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
275    InitializeForStaticMemLeak();
276 #endif
277    /* initialize memory information */
278    osCp.numRegions = 0;
279
280    for (i = 0;  i < SS_MAX_REGS;  i++)
281    {
282       reg = &osCp.regionTbl[i];
283
284       reg->used = FALSE;
285
286       reg->start = NULLP;
287       reg->size = 0;
288       reg->regCb = NULLP;
289       reg->flags = 0;
290       reg->alloc = NULLP;
291       reg->free = NULLP;
292       reg->ctl = NULLP;
293       /* ss007.301 initializing the per region mBufRefLock */
294       SInitLock(&reg->mBufRefLock, SS_LOCK_MUTEX);
295
296       /* zero the pool information */
297       reg->numPools = 0;
298       for (j = 0;  j < SS_MAX_POOLS_PER_REG;  j++)
299          reg->poolTbl[j].type = SS_POOL_UND;
300
301       /* find this region ID in the region configuration structure */
302       for (j = 0;  j < cfgNumRegs;  j++)
303          if (cfgRegInfo[j].region == i)
304             break;
305
306       /* this region is not configured */
307       if (j == cfgNumRegs)
308          continue;
309
310       /* Load the configuration information into the region table.
311        *  Note, the region still has to be registered, for it to
312        *  be usable.
313        */
314       for (k = 0;  k < cfgRegInfo[j].numPools;  k++)
315       {
316          reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
317          if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
318             reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
319       }
320    }
321
322    /* Initialization of dynamic regions */
323    for (i = 0;  i < SS_MAX_REGS;  i++)
324    {
325       reg = &osCp.dynRegionTbl[i];
326
327       reg->used = FALSE;
328
329       reg->start = NULLP;
330       reg->size = 0;
331       reg->regCb = NULLP;
332       reg->flags = 0;
333       reg->alloc = NULLP;
334       reg->free = NULLP;
335       reg->ctl = NULLP;
336       /* ss007.301 initializing the per region mBufRefLock */
337       SInitLock(&reg->mBufRefLock, SS_LOCK_MUTEX);
338
339       /* zero the pool information */
340       reg->numPools = 0;
341       for (j = 0;  j < SS_MAX_POOLS_PER_REG;  j++)
342          reg->poolTbl[j].type = SS_POOL_UND;
343
344       /* find this region ID in the region configuration structure */
345       for (j = 0;  j < cfgNumRegs;  j++)
346          if (cfgRegInfo[j].region == i)
347             break;
348
349       /* this region is not configured */
350       if (j == cfgNumRegs)
351          continue;
352
353       /* Load the configuration information into the region table.
354        *  Note, the region still has to be registered, for it to
355        *  be usable.
356        */
357       for (k = 0;  k < cfgRegInfo[j].numPools;  k++)
358       {
359          reg->poolTbl[k].type = cfgRegInfo[j].pools[k].type;
360          if (reg->poolTbl[k].type == SS_POOL_DYNAMIC)
361             reg->poolTbl[k].u.dpool.size = cfgRegInfo[j].pools[k].size;
362       }
363    }
364
365    ret = ssInitSema(&osCp.regionTblSem, SS_MAX_STSKS);
366    if (ret != ROK)
367         {
368     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
369           sprintf(prntBufLoc,"\n SInit(): Could not initialize the region Table Semaphore \n");
370       SDisplay(1,prntBufLoc);
371           goto cleanup0;
372         }
373
374    /* implementation specific memory initialization */
375    ret = ssdInitMem();
376    if (ret != ROK)
377         {
378     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
379           sprintf(prntBufLoc,"\n SInit(): Memory initialization failed \n");
380       SDisplay(1,prntBufLoc);
381           goto cleanup1;
382         }
383
384
385    /* initialize TAPA and system task information */
386 /* ss029.103: modification: multiple procId related changes */ 
387 #ifndef SS_MULTIPLE_PROCS
388    for (i = 0;  i < SS_MAX_ENT;  i++)
389       for (j = 0;  j < SS_MAX_INST;  j++)
390          osCp.tTskIds[i][j] = SS_TSKNC;
391 #else /* SS_MULTIPLE_PROCS */
392    for (i = 0;  i < SS_MAX_PROCS;  i++)
393       for (j = 0;  j < SS_MAX_ENT;  j++)
394          for (k = 0;  k < SS_MAX_INST;  k++)
395             osCp.tTskIds[i][j][k] = SS_TSKNC;
396 #endif /* SS_MULTIPLE_PROCS */
397
398    for (i = 0;  i < SS_MAX_TTSKS;  i++)
399    {
400       tTsk = &osCp.tTskTbl[i];
401
402       tTsk->used = FALSE;
403       tTsk->ent = ENTNC;
404       tTsk->inst = INSTNC;
405       tTsk->tskType = TTUND;
406       tTsk->tskPrior = 0;
407       tTsk->initTsk = NULLP;
408       tTsk->actvTsk = NULLP;
409       tTsk->sTsk = NULLP;
410 /* ss029.103: addition: TAPA task control block added */
411 #ifdef SS_MULTIPLE_PROCS
412       tTsk->xxCb = NULLP;
413 #endif /* SS_MULTIPLE_PROCS */
414
415       tTsk->nxt = i + 1;
416    }
417
418    osCp.numTTsks = 0;
419    osCp.nxtTTskEntry = 0;
420
421    ret = ssInitSema(&osCp.tTskTblSem, SS_MAX_STSKS);
422    if (ret != ROK)
423         {
424     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
425           sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
426       SDisplay(1,prntBufLoc);
427           goto cleanup2;
428         }
429
430 #ifdef SS_MULTICORE_SUPPORT
431   /* check whether number of system tasks is
432    * equal to number of (regions-1).
433    * The last region is meant for timer task
434    * which under the current feature has as entry
435    * in system task table.
436    */
437   if(SS_MAX_STSKS > SS_MAX_REGS)
438   {
439     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
440       goto cleanup3;
441   }
442 #endif
443
444    /* initialize system task information */
445    for (i = 0;  i < SS_MAX_STSKS;  i++)
446    {
447       sTsk = &osCp.sTskTbl[i];
448
449       sTsk->used = FALSE;
450       sTsk->termPend = FALSE;
451       sTsk->tskPrior = 0;
452       for (j = 0;  j < SS_MAX_TTSKS;  j++)
453          sTsk->tTsks[j] = SS_INVALID_IDX;
454       sTsk->numTTsks = 0;
455
456       sTsk->nxt = i + 1;
457 /* ss002.301 : Modifications */
458 #ifdef SS_MULTICORE_SUPPORT
459       if(i == 0)
460       {
461          sTsk->region = (SS_MAX_REGS - 1);
462       }
463       else
464       {
465          sTsk->region = i-1;
466       }
467 #endif
468    }
469
470    osCp.numSTsks = 0;
471    osCp.nxtSTskEntry = 0;
472
473    ret = SInitLock(&osCp.sTskTblLock, SS_STSKTBL_LOCK);
474    if (ret != ROK)
475    {
476     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
477           sprintf(prntBufLoc,"\n SInit(): Could not initialize the tTask table Semaphore \n");
478       SDisplay(1,prntBufLoc);
479       goto cleanup3;
480    }
481
482         /* ss028.103 - Addition of lock for mBuf reference count */
483         /* ss007.301 moving the mBufRefLock from common to per region */
484         /* SInitLock(&osCp.mBufRefLock, SS_LOCK_MUTEX);*/
485
486    /* implementation specific task initialization */
487    ret = ssdInitTsk();
488    if (ret != ROK)
489    {
490     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
491           sprintf(prntBufLoc,"\n SInit(): implementation specific task initialization Failed \n");
492       SDisplay(1,prntBufLoc);
493       goto cleanup4;
494    }
495
496 #ifdef SS_DRVR_SUPPORT
497    /* initialize driver task information */
498    for (i = 0;  i < SS_MAX_DRVRTSKS;  i++)
499    {
500       drvrTsk = &osCp.drvrTskTbl[i];
501
502       drvrTsk->used = FALSE;
503
504       drvrTsk->channel = 0;
505       drvrTsk->actvTsk = NULLP;
506       drvrTsk->isTsk = NULLP;
507       drvrTsk->low = 0;
508       drvrTsk->high = 0;
509    }
510
511    osCp.numDrvrTsks = 0;
512
513    /* implementation specific driver initialization */
514    ret = ssdInitDrvr();
515    if (ret != ROK)
516         {
517     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
518           sprintf(prntBufLoc,"\n SInit(): ssdInitDrvr failed \n");
519       SDisplay(1,prntBufLoc);
520           goto cleanup5;
521         }
522 #endif
523
524         /*ss004.301: Cavium Changes */
525 #ifdef SS_SEUM_CAVIUM
526         ret = ssInitRcvWork();
527         if (ret != ROK)
528         {
529     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
530           goto cleanup6;
531         }
532 #endif /* SS_SEUM_CAVIUM */
533
534
535    /* initialize the demand queue lookup table */
536    osCp.dmndQLookupTbl[0] = 255;
537    osCp.dmndQLookupTbl[1] = 0;
538    osCp.dmndQLookupTbl[2] = 1;
539    osCp.dmndQLookupTbl[3] = 1;
540    for (i = 4;  i < 256;  i++)
541    {
542       if (i >= 128  &&  i <= 255)
543          osCp.dmndQLookupTbl[i] = 7;
544       if (i >= 64  &&  i <= 127)
545          osCp.dmndQLookupTbl[i] = 6;
546       if (i >= 32  &&  i <= 63)
547          osCp.dmndQLookupTbl[i] = 5;
548       if (i >= 16  &&  i <= 31)
549          osCp.dmndQLookupTbl[i] = 4;
550       if (i >= 8  &&  i <= 15)
551          osCp.dmndQLookupTbl[i] = 3;
552       if (i >= 4  &&  i <= 7)
553          osCp.dmndQLookupTbl[i] = 2;
554    }
555
556
557    /* initialize timer information */
558    for (i = 0;  i < SS_MAX_TMRS;  i++)
559    {
560       tmr = &osCp.tmrTbl[i];
561
562       tmr->used = FALSE;
563       tmr->tmrId = 0;
564       tmr->ownerEnt = ENTNC;
565       tmr->ownerInst = INSTNC;
566       tmr->interval = 0;
567       /*
568        *  ss015.301 - Modifed in initialization as timer activation 
569        *  functions enclosed in a union. Also initialized the mtFlag
570        *  to FALSE 
571        */
572       tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
573 #ifndef SS_MULTIPLE_PROCS
574 #ifdef SS_MT_TMR
575       tmr->ssTmrActvFn.mtFlag = FALSE; 
576       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
577 #endif
578 #endif
579       tmr->nxt = i + 1;
580    }
581
582    osCp.numTmrs = 0;
583    osCp.nxtTmrEntry = 0;
584
585    ret = SInitLock(&osCp.tmrTblLock, SS_TMRTBL_LOCK);
586    if (ret != ROK)
587    {
588     /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
589        goto cleanup6;
590    }
591
592    /* implementation specific timer initialization */
593    ret = ssdInitTmr();
594    if (ret != ROK)
595    {
596        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
597        sprintf(prntBufLoc,"\n SInit(): Could not initialize the timer \n");
598        SDisplay(1,prntBufLoc);
599        goto cleanup7;
600    }
601
602    /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
603    /* ss005.201: Initialize logging streams */
604    /* implementation specific logging initialization */
605    ret = ssdInitLog();
606    if (ret != ROK)
607    {
608        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
609        sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logging streams \n");
610        SDisplay(1,prntBufLoc);
611        goto cleanup8;
612    }
613
614 #ifdef SS_LOGGER_SUPPORT /* ss001.301: additions */
615    /* Initialize the lock, return on failure */
616    if( SInitLock(&(osCp.logger.bufLock),SS_LOCK_MUTEX) != ROK)
617    {
618        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
619        sprintf(prntBufLoc,"\n SInit(): Could not initialize the Logger Buffer Lock  \n");
620        SDisplay(1,prntBufLoc);
621        goto cleanup9;
622    } /* if */
623    
624    /* Initialize the logger configuration flag */
625    osCp.logger.configured = FALSE;
626    /* Ss002.301 : Initialised */
627    osCp.logger.started = FALSE;
628 #endif /* SS_LOGGER_SUPPORT */
629 /* ss001.301: additions */
630
631 #ifdef SS_HISTOGRAM_SUPPORT
632    /* Here we are filling all the tapa entity Ids, which will be
633     * helpful to get the entity Id using file name. */
634    ret = SFillEntIds();
635 #endif /* SS_HISTOGRAM_SUPPORT */
636
637
638 #ifdef SS_FBSED_TSK_REG
639    /* Configure task registration based on the configuration */
640    /*ss013.301 : Fixed warnings for 32/64 bit compilation*/
641    cmCfgrTskReg((uint8_t *)"task_info.t");
642 #endif /* SS_FBSED_TSK_REG  */
643
644 /*ss011.301 : RMIOS release related changes*/
645 #ifdef SS_RMIOS
646    spInit();
647 #endif
648
649    /* call tst() function */
650    ret = tst();
651    if (ret != ROK)
652    {
653        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
654       goto cleanup10;
655    }
656
657
658    /* call implementation-specific starter function */
659    ssdStart();
660
661
662    return ROK;
663
664
665 /* clean up code */
666 /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
667 cleanup10:
668 #ifdef SS_LOGGER_SUPPORT 
669    /* ss005.301: Deinitialize the logging at the end */
670    SDestroyLock(&(osCp.logger.bufLock));
671    /*ss013.301 : Fix for compile time warning*/
672 cleanup9:
673 #endif /* SS_LOGGER_SUPPORT */
674    ssdDeinitLog();
675 cleanup8:
676    ssdDeinitTmr();
677 cleanup7:
678    SDestroyLock(&osCp.tmrTblLock);
679
680 cleanup6:
681 #ifdef SS_DRVR_SUPPORT
682    ssdDeinitDrvr();
683 cleanup5:
684 #endif
685    ssdDeinitTsk();
686 cleanup4:
687    SDestroyLock(&osCp.sTskTblLock);
688 cleanup3:
689    if ( (ssDestroySema(&osCp.tTskTblSem)) != ROK)
690       {
691 #if (ERRCLASS & ERRCLS_DEBUG)
692          SSLOGERROR(ERRCLS_DEBUG, ESS012, ERRZERO,
693                          "Could not destroy the Semaphore");
694         /* ss005.301: Changes, clean the threads and exit */
695 #endif
696       }
697
698 cleanup2:
699    ssdDeinitMem();
700 cleanup1:
701         /* ss007.301 destroying the per region mBufRefLock */
702         for (i= 0;i<SS_MAX_REGS;i++)
703         {
704           SDestroyLock(&osCp.regionTbl[i].mBufRefLock);
705         }
706    /* ss006.13: addition */
707    if ( (ssDestroySema(&osCp.regionTblSem)) != ROK)
708    {
709 #if (ERRCLASS & ERRCLS_DEBUG)
710          SSLOGERROR(ERRCLS_DEBUG, ESS013, ERRZERO,
711                "Could not destroy the Semaphore");
712        /* ss005.301: Changes, clean the threads and exit */
713 #endif
714    }
715 cleanup0:
716    ssdDeinitGen();
717
718
719    return RFAILED;
720 }
721
722 \f
723 /* ss033.103: Added SDeInit API to free all the resources */
724 /*
725 *
726 *       Fun:   System Services de-initialization function
727 *
728 *       Desc:  This is the de-initialization function for System 
729 *              Services implementations. It releases all the common
730 *              global data structures.
731 *
732 *       Ret:   Void
733 *
734 *       Notes: 
735 *
736 *       File:  ss_gen.c
737 *
738 */
739 S16 SDeInit(void)
740 {
741   /* ss007.301 */
742   uint16_t    regCnt;
743
744
745    ssdDeinitTmr();
746    SDestroyLock(&osCp.tmrTblLock);
747
748 #ifdef SS_DRVR_SUPPORT
749    ssdDeinitDrvr();
750 #endif
751
752    ssdDeinitTsk();
753    SDestroyLock(&osCp.sTskTblLock);
754
755    if ((ssDestroySema(&osCp.tTskTblSem)) != ROK)
756    {
757 #if (ERRCLASS & ERRCLS_DEBUG)
758     SSLOGERROR(ERRCLS_DEBUG, ESS014, ERRZERO,
759                       "Could not destroy the Semaphore");
760     return RFAILED;
761
762 #endif
763    }
764
765    ssdDeinitMem();
766
767    if ((ssDestroySema(&osCp.regionTblSem)) != ROK)
768    {
769 #if (ERRCLASS & ERRCLS_DEBUG)
770       SSLOGERROR(ERRCLS_DEBUG, ESS015, ERRZERO,
771                       "Could not destroy the Semaphore");
772       return RFAILED;
773
774 #endif
775    }
776
777         ssdDeinitGen();
778         /* ss007.301 destroying the per region mBufRefLock */
779         for (regCnt = 0;  regCnt < SS_MAX_REGS;  regCnt++)
780         {
781           SDestroyLock(&osCp.regionTbl[regCnt].mBufRefLock);
782         }
783
784         /* ss005.301: Deinitialize the logging at the end */
785 #ifdef SS_LOGGER_SUPPORT 
786    SDestroyLock(&(osCp.logger.bufLock));
787 #endif /* SS_LOGGER_SUPPORT */
788    ssdDeinitLog();
789    return ROK;
790
791 }
792 /* ss001.301: additions */
793 #ifdef SS_LOGGER_SUPPORT 
794 S16 SWrtLogBuf
795 (
796 Txt *buf                        /* buffer */
797 )
798 {
799    S16 bufSz;
800    /* buffer synchronisation*/
801    bufSz = cmStrlen((uint8_t *)buf);
802    SLock(&osCp.logger.bufLock);
803    if(osCp.logger.started == FALSE)
804    {
805       (Void)SUnlock(&(osCp.logger.bufLock));
806       return ROK;
807    }
808    /*
809     * Append the buffer to the global buffer
810     * and increment the current buffer size of the global buffer
811     */
812    if(((osCp.logger.curBufSiz) + bufSz) >= osCp.logger.maxBufSiz)
813    {
814       SFlushBufToLog(osCp.logger.buffer);
815       osCp.logger.curBufSiz = 0;
816       memset(osCp.logger.buffer, '\0', osCp.logger.maxBufSiz);
817       sprintf(osCp.logger.buffer, "%s", buf);
818       osCp.logger.curBufSiz += bufSz;
819    }
820    else
821    {
822       strcat(osCp.logger.buffer,buf);
823       osCp.logger.curBufSiz += bufSz;
824    }
825    (Void)SUnlock(&(osCp.logger.bufLock));
826    return ROK;
827 }
828 #endif /* SS_LOGGER_SUPPORT  */
829 /*
830 *
831 *       Fun:   SPrint
832 *
833 *       Desc:  Print a string.
834 *
835 *              This function should be used for debugging only.
836 *
837 *       Ret:   ROK      - ok
838 *
839 *       Notes: Text buffer should be null terminated.
840 *
841 *              SDisplay will replace SPrint.
842 *
843 *              Typical usage consists of a call to sprintf to
844 *              format the string into a buffer followed by a
845 *              call to SPrint
846 *
847 *       File:  ss_gen.c
848 *
849 */
850 S16 SPrint
851 (
852 Txt *buf                        /* buffer */
853 )
854 {
855
856 /* ss001.301: additions */
857    SDisplay(0, buf);
858 #ifdef SS_LOGGER_SUPPORT 
859    SWrtLogBuf(buf);
860 #endif /* SS_LOGGER_SUPPORT  */
861
862    return ROK;
863
864 } /* end of SPrint */
865
866 \f
867 /*
868 *
869 *       Fun:   SError
870 *
871 *       Desc:  Invoked by layer when an unrecoverable
872 *              software error is detected. This function should
873 *              never return.
874 *
875 *       Ret:   None
876 *
877 *       Notes: None
878 *
879 *       File:  ss_gen.c
880 *
881 */
882 S16 SError
883 (
884 Seq seq,                    /* sequence */
885 Reason reason               /* reason */
886 )
887 {
888    S16 ret;
889    DateTime dt;
890    Txt errBuf[256];
891
892    SGetDateTime(&dt);
893    sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
894           (int)dt.month,(int)dt.day,(int)dt.year + 1900,
895           (int)dt.hour,(int)dt.min,(int)dt.sec);
896    SPrint(errBuf);
897
898
899    ret = ssdError(seq, reason);
900
901
902    return (ret);
903 }
904
905 \f
906 /*
907 *
908 *       Fun:   SLogError
909 *
910 *       Desc:  Invoked by layer to log an error.
911 *
912 *       Ret:   None
913 *
914 *       Notes: None
915 *
916 *       File:  ss_gen.c
917 *
918 */
919 Void SLogError
920 (
921 Ent ent,                    /* Calling layer's entity id */
922 Inst inst,                  /* Calling layer's instance id */
923 ProcId procId,              /* Calling layer's processor id */
924 Txt *file,                  /* file name where error occured */
925 S32 line,                   /* line in file where error occured */
926 ErrCls errCls,              /* error class */
927 ErrCode errCode,            /* layer unique error code */
928 ErrVal errVal,              /* error value */
929 Txt *errDesc                /* description of error */
930 )
931 {
932    DateTime dt;
933    Txt errBuf[512];
934
935
936 /*ss014.301: SSI-4GMX related changes*/
937 #ifndef SS_4GMX_LCORE
938    SGetDateTime(&dt);
939    sprintf(errBuf, "\n\ndate: %02d/%02d/%04d time: %02d:%02d:%02d\n",
940           (int)dt.month,(int)dt.day,(int)dt.year + 1900,
941           (int)dt.hour,(int)dt.min,(int)dt.sec);
942    SDisplay(0,errBuf);
943 #endif
944
945 /* ss001.301: additions */
946 #ifdef SS_LOGGER_SUPPORT 
947    SWrtLogBuf(errBuf);
948 #endif /* SS_LOGGER_SUPPORT  */
949
950    ssdLogError(ent, inst, procId, file, line,
951                      errCls, errCode, errVal, errDesc);
952
953
954    return;
955 }
956
957 /* ss029.103: modification: 
958    SFndProcId function is not supported with multiple procIds */ 
959 #ifndef SS_MULTIPLE_PROCS
960 \f
961 /*
962 *
963 *       Fun:   SFndProcId
964 *
965 *       Desc:  This function finds the local processor ID.
966 *
967 *       Ret:   local processor id
968 *
969 *       Notes:
970 *
971 *       File:  ss_gen.c
972 *
973 */
974 ProcId SFndProcId(void)
975 {
976
977    return (osCp.procId);
978 } /* end of SFndProcId */
979
980 \f
981 /*
982 *
983 *       Fun:   SSetProcId
984 *
985 *       Desc:  This function stores the local processor ID.
986 *
987 *       Ret:   Void
988 *
989 *       Notes: 
990 *
991 *       File:  ss_gen.c
992 *
993 */
994 Void SSetProcId(ProcId procId)
995 {
996
997    osCp.procId = procId;
998
999    return;
1000 }
1001
1002 #endif /* SS_MULTIPLE_PROCS */
1003
1004 /* ss029.103: addition: New SSI functions with multiple proc support */ 
1005 #ifdef SS_MULTIPLE_PROCS
1006 \f
1007 /*
1008 *
1009 *       Fun:   SGetProcIdIdx
1010 *
1011 *       Desc:  This function finds index of procId in the process id table 
1012 *
1013 *       Ret:   ROK/RFAILED 
1014 *
1015 *       Notes: 
1016 *
1017 *       File:  ss_gen.c
1018 *
1019 */
1020 uint16_t SGetProcIdIdx(ProcId proc)
1021 {
1022    uint16_t i;
1023    uint16_t idx;
1024
1025    idx = SS_HASH_IDX(proc);
1026
1027    for (i = idx; i < SS_MAX_PROCS; i++)
1028       if (osCp.procLst.procId[i] == proc)
1029          return i;
1030
1031    /* search upto idx */
1032    for (i = 0; i < idx; i++)
1033       if (osCp.procLst.procId[i] == proc)
1034          return i;
1035
1036    return (SS_INV_PROCID_IDX);
1037 } /* SGetProcIdIdx */
1038
1039 \f
1040 /*
1041 *
1042 *       Fun:   SInsProcId
1043 *
1044 *       Desc:  This function inserts procId in the process id table 
1045 *
1046 *       Ret:   ROK/RFAILED 
1047 *
1048 *       Notes: 
1049 *
1050 *       File:  ss_gen.c
1051 *
1052 */
1053 static S16 SInsProcId(ProcId proc)
1054 {
1055    uint16_t i;
1056    uint16_t idx;
1057
1058
1059    idx = SS_HASH_IDX(proc);
1060
1061    for (i = idx; i < SS_MAX_PROCS; i++)
1062       if (osCp.procLst.procId[i] == SS_INV_PROCID)
1063       {
1064          osCp.procLst.procId[i] = proc;
1065          osCp.procLst.free--;
1066          return ROK;
1067       }
1068
1069    /* search for free entry upto idx */
1070    for (i = 0; i < idx; i++)
1071       if (osCp.procLst.procId[i] == SS_INV_PROCID)
1072       {
1073          osCp.procLst.procId[i] = proc;
1074          osCp.procLst.free--;
1075          return ROK;
1076       }
1077
1078    return RFAILED;
1079 } /* SInsProcId */
1080
1081 \f
1082 /*
1083 *
1084 *       Fun:   SRemProcId
1085 *
1086 *       Desc:  This function inserts procId in the process id table 
1087 *
1088 *       Ret:   ROK/RFAILED 
1089 *
1090 *       Notes: 
1091 *
1092 *       File:  ss_gen.c
1093 *
1094 */
1095 static S16 SRemProcId(ProcId proc)
1096 {
1097    uint16_t i;
1098    uint16_t idx;
1099
1100
1101    idx = SS_HASH_IDX(proc);
1102
1103    for (i = idx; i < SS_MAX_PROCS; i++)
1104       if (osCp.procLst.procId[i] == proc)
1105       {
1106          osCp.procLst.procId[i] = SS_INV_PROCID;
1107          osCp.procLst.free++;
1108          return ROK;
1109       }
1110
1111    /* search upto idx */
1112    for (i = 0; i < idx; i++)
1113       if (osCp.procLst.procId[i] == proc)
1114       {
1115          osCp.procLst.procId[i] = SS_INV_PROCID;
1116          osCp.procLst.free++;
1117          return ROK;
1118       }
1119
1120    return RFAILED;
1121 } /* SRemProcId */
1122
1123 \f
1124 /*
1125 *
1126 *       Fun:   SLockOsCp
1127 *
1128 *       Desc:  This function locks OsCp 
1129 *
1130 *       Ret:   ROK/RFAILED 
1131 *
1132 *       Notes: 
1133 *
1134 *       File:  ss_gen.c
1135 *
1136 */
1137 static S16 SLockOsCp(void)
1138 {
1139    S16 ret;
1140
1141
1142    ret = SLock(&osCp.sTskTblLock);
1143    if (ret != ROK)
1144    {
1145       SSLOGERROR(ERRCLS_DEBUG, ESS016, ERRZERO,
1146                      "Could not lock system task table");
1147       return RFAILED;
1148    }
1149
1150    SS_ACQUIRE_ALL_SEMA(&osCp.tTskTblSem, ret);
1151    if (ret != ROK)
1152    {
1153
1154 #if (ERRCLASS & ERRCLS_DEBUG)
1155       SSLOGERROR(ERRCLS_DEBUG, ESS017, ERRZERO,
1156                      "Could not lock TAPA task table");
1157 #endif
1158
1159       if ( SUnlock(&osCp.sTskTblLock) != ROK)
1160       {
1161 #if (ERRCLASS & ERRCLS_DEBUG)
1162          SSLOGERROR(ERRCLS_DEBUG, ESS018, ERRZERO,
1163                       "Could not give the Semaphore");
1164          return RFAILED;
1165 #endif
1166       }
1167
1168       return RFAILED;
1169    }
1170
1171    return ROK;
1172
1173 } /* SLockOsCp */
1174
1175 \f
1176 /*
1177 *
1178 *       Fun:   SULockOsCp
1179 *
1180 *       Desc:  This function locks OsCp 
1181 *
1182 *       Ret:   ROK/RFAILED 
1183 *
1184 *       Notes: 
1185 *
1186 *       File:  ss_gen.c
1187 *
1188 */
1189 static S16 SULockOsCp(Void)
1190 {
1191
1192    /* unlock the table */
1193    SS_RELEASE_ALL_SEMA(&osCp.tTskTblSem);
1194
1195    if ( SUnlock(&osCp.sTskTblLock) != ROK)
1196    {
1197 #if (ERRCLASS & ERRCLS_DEBUG)
1198       SSLOGERROR(ERRCLS_DEBUG, ESS019, ERRZERO,
1199                       "Could not give the Semaphore");
1200       return RFAILED;
1201 #endif
1202    }
1203
1204    return ROK;
1205
1206 } /* SULockOsCp */
1207
1208
1209 \f
1210 /*
1211 *
1212 *       Fun:   SAddProcIdLst
1213 *
1214 *       Desc:  This function adds given proc ids to the list 
1215 *
1216 *       Ret:   ROK/RFAILED 
1217 *
1218 *       Notes: 
1219 *
1220 *       File:  ss_gen.c
1221 *
1222 */
1223 S16 SAddProcIdLst(uint16_t numPIds,ProcId *pIdLst)
1224 {
1225    uint16_t i;
1226    S16 ret;
1227
1228
1229 #if (ERRCLASS & ERRCLS_INT_PAR)
1230    /* range check */
1231    if (numPIds > SS_MAX_PROCS)
1232    {
1233       SSLOGERROR(ERRCLS_INT_PAR, ESS020, ERRZERO, "number of proc Ids exceeds\
1234  limit");
1235       return RFAILED;
1236    }
1237
1238    /* find if the entry exist in the table */
1239    for (i = 0; i < numPIds; i++)
1240    {
1241       if (pIdLst[i] == SS_INV_PROCID)
1242       {
1243          SSLOGERROR(ERRCLS_INT_PAR, ESS021, ERRZERO, "Invalid proc Ids");
1244          return RFAILED;
1245       }
1246    }
1247
1248 #endif
1249    
1250    if (SLockOsCp() != ROK)
1251       return RFAILED;
1252
1253 #if (ERRCLASS & ERRCLS_INT_PAR)
1254    for (i = 0; i < numPIds; i++)
1255       if (SGetProcIdIdx(pIdLst[i]) != SS_INV_PROCID_IDX)
1256       {
1257          SSLOGERROR(ERRCLS_INT_PAR, ESS022, ERRZERO, "Duplicate proc id");
1258          (Void) SULockOsCp();
1259          return RFAILED;
1260       }
1261
1262    if (numPIds > osCp.procLst.free)
1263    {
1264       SSLOGERROR(ERRCLS_INT_PAR, ESS023, ERRZERO, "Total number of proc id \
1265 exceeds");
1266       (Void) SULockOsCp();
1267       return RFAILED;
1268    }
1269 #endif 
1270
1271    /* insert the entries in the table */
1272    ret = ROK;
1273
1274    for (i = 0; i < numPIds; i++)
1275    {
1276       if (SInsProcId(pIdLst[i]) == RFAILED)
1277       {
1278 #if (ERRCLASS & ERRCLS_DEBUG)
1279          SSLOGERROR(ERRCLS_DEBUG, ESS024, ERRZERO,
1280                       "Could not insert the proc id");
1281 #endif
1282          (Void) SULockOsCp();
1283          return RFAILED;
1284       }
1285    }
1286
1287    /* unlock the table */
1288    if (SULockOsCp() != ROK)
1289       return RFAILED;
1290
1291    return (ret);
1292 } /* SAddProcIdLst */
1293
1294 \f
1295 /*
1296 *
1297 *       Fun:   SRemProcIdLst
1298 *
1299 *       Desc:  This function adds given proc ids to the list 
1300 *
1301 *       Ret:   ROK/RFAILED 
1302 *
1303 *       Notes: 
1304 *
1305 *       File:  ss_gen.c
1306 *
1307 */
1308 S16 SRemProcIdLst(uint16_t numPIds,ProcId *pIdLst)
1309 {
1310    uint16_t i;
1311
1312
1313 #if (ERRCLASS & ERRCLS_INT_PAR)
1314    /* range check */
1315    if (numPIds > SS_MAX_PROCS)
1316       return RFAILED;
1317 #endif
1318
1319    if (SLockOsCp() != ROK)
1320       return RFAILED;
1321
1322    if (numPIds > (SS_MAX_PROCS - osCp.procLst.free))
1323    {
1324       (Void) SULockOsCp();
1325       return RFAILED;
1326    }
1327
1328    /* find if the entry exist in the table */
1329    for (i = 0; i < numPIds; i++)
1330    {
1331       if (SGetProcIdIdx(pIdLst[i]) == SS_INV_PROCID_IDX)
1332       {
1333          (Void) SULockOsCp();
1334          return RFAILED;
1335       }
1336    }
1337
1338    /* insert the entries in the table */
1339    for (i = 0; i < numPIds; i++)
1340       SRemProcId(pIdLst[i]);
1341
1342    if (SULockOsCp() != ROK)
1343       return RFAILED;
1344
1345    return ROK;
1346 } /* SRemProcIdLst */
1347
1348 \f
1349 /*
1350 *
1351 *       Fun:   SGetProcIdLst
1352 *
1353 *       Desc:  This function retrieves proc Id list 
1354 *
1355 *       Ret:   ROK/RFAILED 
1356 *
1357 *       Notes: 
1358 *
1359 *       File:  ss_gen.c
1360 *
1361 */
1362 S16 SGetProcIdLst(uint16_t *numPIds,ProcId *pIdLst)
1363 {
1364    uint16_t i;
1365    uint16_t count = 0;
1366
1367
1368 #if (ERRCLASS & ERRCLS_INT_PAR)
1369    if ((numPIds == NULLP) || (pIdLst == NULLP))
1370    {
1371       SSLOGERROR(ERRCLS_INT_PAR, ESS025, ERRZERO, "Invalid numPIds/pIdLst");
1372       return RFAILED;
1373    }
1374 #endif 
1375
1376    if (SLockOsCp() != ROK)
1377       return RFAILED;
1378
1379    for (i = 0; i < SS_MAX_PROCS; i++)
1380    {
1381       if (osCp.procLst.procId[i] != PROCNC)
1382          pIdLst[count++] = osCp.procLst.procId[i];
1383    }
1384
1385    *numPIds = count;
1386
1387    if (SULockOsCp() != ROK)
1388       return RFAILED;
1389
1390    if (count == 0)
1391       return RFAILED;
1392
1393    return ROK;
1394 } /* SGetProcIdLst */
1395
1396 \f
1397 /*
1398 *
1399 *       Fun:   SGetXxCb
1400 *
1401 *       Desc:  This function retrieves protocol layer control block for given proc,
1402 *              ent and inst IDs
1403 *
1404 *       Ret:   ROK/RFAILED 
1405 *
1406 *       Notes: 
1407 *
1408 *       File:  ss_gen.c
1409 *
1410 */
1411 S16 SGetXxCb
1412 (
1413 ProcId proc,
1414 Ent ent,
1415 Inst inst,
1416 Void **xxCb
1417 )
1418 {
1419    uint16_t procIdIdx;
1420    SsIdx idx;
1421
1422
1423 #if (ERRCLASS & ERRCLS_INT_PAR)
1424    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
1425    {
1426       SSLOGERROR(ERRCLS_INT_PAR, ESS026, ERRZERO, "Invalid proc/entity/instance");
1427       return RFAILED;
1428    }
1429 #endif 
1430    
1431    /* 
1432     * ss030.103: delete: locking/unlocking removed as it causes
1433     * deadlock/blockage in some cases
1434     */
1435
1436    procIdIdx = SGetProcIdIdx(proc);
1437
1438    if (procIdIdx == SS_INV_PROCID_IDX)
1439    {
1440 #if (ERRCLASS & ERRCLS_INT_PAR)
1441       SSLOGERROR(ERRCLS_INT_PAR, ESS027, ERRZERO, "Could not get proc table idx");
1442 #endif
1443       return RFAILED;
1444    }
1445
1446    idx = osCp.tTskIds[procIdIdx][ent][inst];
1447    if (idx == SS_TSKNC)
1448    {
1449       return RFAILED;
1450    }
1451
1452    /* update the CB */
1453    *xxCb = osCp.tTskTbl[idx].xxCb;
1454    /*ss032.103 added a check for NULLP */
1455    if (*xxCb == NULLP)
1456       return RFAILED;
1457
1458    return ROK;
1459 } /* SGetXxCb */
1460
1461 #endif /* SS_MULTIPLE_PROCS */
1462
1463 /* ss001.301: additions */
1464 #ifdef SS_HISTOGRAM_SUPPORT 
1465 /*
1466 *
1467 *       Fun:   SFillEntIds
1468 *
1469 *       Desc:  It is static data base contains all entity Ids of tapa task.
1470 *              This Data base is used to find the entity id using two letter
1471 *              prifix product code.
1472 *
1473 *       Ret:   ROK/RFAILED
1474 *
1475 *       Notes:
1476 *
1477 *       File:  ss_gen.c
1478 *
1479 */
1480 S16 SFillEntIds(Void)
1481 {
1482
1483    uint8_t entInfo[26][26] = {
1484                            /* A      B      C      D      E      F      G      H      I      J      K  *
1485                               L      M      N      O      P      Q      R      S      T      U      V  *
1486                               W      X      Y      Z */
1487                            {ENTAA, ENTAB, ENTAC, ENTNC, ENTAE, ENTAF, ENTNC, ENTAH, ENTNC, ENTNC, ENTNC,
1488                   /* A */   ENTAL, ENTAM, ENTNC, ENTNC, ENTAP, ENTAQ, ENTAR, ENTAS, ENTNC, ENTAU, ENTNC,
1489                             ENTAW, ENTNC, ENTNC, ENTNC},
1490
1491                            /* A      B      C      D      E      F      G      H      I      J      K  *
1492                               L      M      N      O      P      Q      R      S      T      U      V  *
1493                               W      X      Y      Z */
1494                            {ENTNC, ENTNC, ENTNC, ENTBD, ENTNC, ENTNC, ENTNC, ENTNC, ENTBI, ENTNC, ENTNC,
1495                   /* B */   ENTNC, ENTBM, ENTNC, ENTNC, ENTNC, ENTNC, ENTBR, ENTBS, ENTNC, ENTNC, ENTBV,
1496                             ENTBW, ENTNC, ENTNC, ENTNC},
1497                            /* A      B      C      D      E      F      G      H      I      J      K  *
1498                               L      M      N      O      P      Q      R      S      T      U      V  *
1499                               W      X      Y      Z */
1500                            {ENTNC, ENTNC, ENTCC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCH, ENTNC, ENTNC, ENTNC,
1501                   /* C */   ENTCL, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTCS, ENTNC, ENTCU, ENTCV,
1502                             ENTNC, ENTNC, ENTNC, ENTNC},
1503                            /* A      B      C      D      E      F      G      H      I      J      K  *
1504                               L      M      N      O      P      Q      R      S      T      U      V  *
1505                               W      X      Y      Z */
1506                            {ENTNC, ENTDB, ENTNC, ENTNC, ENTNC, ENTNC, ENTDG, ENTNC, ENTDI, ENTNC, ENTDK,
1507                   /* D */   ENTNC, ENTDM, ENTDN, ENTNC, ENTDP, ENTNC, ENTNC, ENTNC, ENTDT, ENTDU, ENTDV,
1508                             ENTNC, ENTNC, ENTNC, ENTNC},
1509                            /* A      B      C      D      E      F      G      H      I      J      K  *
1510                               L      M      N      O      P      Q      R      S      T      U      V  *
1511                               W      X      Y      Z */
1512                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTEC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1513                   /* E */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTER, ENTES, ENTNC, ENTNC, ENTEV,
1514                             ENTNC, ENTNC, ENTNC, ENTNC},
1515                            /* A      B      C      D      E      F      G      H      I      J      K  *
1516                               L      M      N      O      P      Q      R      S      T      U      V  *
1517                               W      X      Y      Z */
1518                            {ENTFA, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1519                   /* F */   ENTNC, ENTFM, ENTFN, ENTNC, ENTFP, ENTNC, ENTFR, ENTNC, ENTNC, ENTFU, ENTNC,
1520                             ENTFW, ENTNC, ENTNC, ENTNC},
1521                            /* A      B      C      D      E      F      G      H      I      J      K  *
1522                               L      M      N      O      P      Q      R      S      T      U      V  *
1523                               W      X      Y      Z */
1524                            {ENTGA, ENTGB, ENTGC, ENTGD, ENTGE, ENTGF, ENTGG, ENTGH, ENTGI, ENTNC, ENTNC,
1525                   /* G */   ENTGL, ENTGM, ENTGN, ENTGO, ENTGP, ENTNC, ENTGR, ENTGS, ENTGT, ENTGU, ENTNC,
1526                             ENTGW, ENTGX, ENTGY, ENTGZ},
1527                            /* A      B      C      D      E      F      G      H      I      J      K  *
1528                               L      M      N      O      P      Q      R      S      T      U      V  *
1529                               W      X      Y      Z */
1530                            {ENTNC, ENTNC, ENTHC, ENTNC, ENTHE, ENTNC, ENTHG, ENTNC, ENTHI, ENTNC, ENTNC,
1531                   /* H */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTHR, ENTHS, ENTNC, ENTHU, ENTNC,
1532                             ENTNC, ENTNC, ENTNC, ENTNC},
1533                            /* A      B      C      D      E      F      G      H      I      J      K  *
1534                               L      M      N      O      P      Q      R      S      T      U      V  *
1535                               W      X      Y      Z */
1536                            {ENTIA, ENTIB, ENTNC, ENTID, ENTIE, ENTNC, ENTNC, ENTNC, ENTII, ENTNC, ENTNC,
1537                   /* I */   ENTNC, ENTIM, ENTIN, ENTNC, ENTNC, ENTIQ, ENTNC, ENTIS, ENTIT, ENTIU, ENTNC,
1538                             ENTIW, ENTIX, ENTNC, ENTNC},
1539                            /* A      B      C      D      E      F      G      H      I      J      K  *
1540                               L      M      N      O      P      Q      R      S      T      U      V  *
1541                               W      X      Y      Z */
1542                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1543                   /* J */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1544                             ENTNC, ENTNC, ENTNC, ENTNC},
1545                            /* A      B      C      D      E      F      G      H      I      J      K  *
1546                               L      M      N      O      P      Q      R      S      T      U      V  *
1547                               W      X      Y      Z */
1548                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1549                   /* K */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1550                             ENTRLC, ENTNC, ENTNC, ENTNC},
1551                            /* A      B      C      D      E      F      G      H      I      J      K  *
1552                               L      M      N      O      P      Q      R      S      T      U      V  *
1553                               W      X      Y      Z */
1554                            {ENTLA, ENTLB, ENTLC, ENTLD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTLK,
1555                   /* L */   ENTNC, ENTLM, ENTLN, ENTNC, ENTNC, ENTNC, ENTLR, ENTNC, ENTLT, ENTLU, ENTLV,
1556                             ENTNC, ENTLX, ENTNC, ENTNC},
1557                            /* A      B      C      D      E      F      G      H      I      J      K  *
1558                               L      M      N      O      P      Q      R      S      T      U      V  *
1559                               W      X      Y      Z */
1560                            {ENTMA, ENTNC, ENTMC, ENTMD, ENTME, ENTNC, ENTMG, ENTNC, ENTNC, ENTNC, ENTMK,
1561                   /* M */   ENTML, ENTMM, ENTNC, ENTNC, ENTNC, ENTNC, ENTMR, ENTMS, ENTMT, ENTMU, ENTMV,
1562                             ENTMW, ENTMX, ENTNC, ENTMZ},
1563                            /* A      B      C      D      E      F      G      H      I      J      K  *
1564                               L      M      N      O      P      Q      R      S      T      U      V  *
1565                               W      X      Y      Z */
1566                            {ENTNC, ENTNC, ENTNC, ENTND, ENTNC, ENTNF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1567                   /* N */   ENTNC, ENTNM, ENTNC, ENTNC, ENTNP, ENTNC, ENTNC, ENTNS, ENTNC, ENTNC, ENTNV,
1568                             ENTNW, ENTNC, ENTNC, ENTNC},
1569                            /* A      B      C      D      E      F      G      H      I      J      K  *
1570                               L      M      N      O      P      Q      R      S      T      U      V  *
1571                               W      X      Y      Z */
1572                            {ENTNC, ENTNC, ENTNC, ENTOD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1573                   /* O */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1574                             ENTNC, ENTNC, ENTNC, ENTNC},
1575                            /* A      B      C      D      E      F      G      H      I      J      K  *
1576                               L      M      N      O      P      Q      R      S      T      U      V  *
1577                               W      X      Y      Z */
1578                            {ENTPA, ENTNC, ENTNC, ENTPD, ENTNC, ENTNC, ENTNC, ENTPH, ENTNC, ENTNC, ENTNC,
1579                   /* P */   ENTPL, ENTNC, ENTPN, ENTNC, ENTPN, ENTPQ, ENTPR, ENTNC, ENTNC, ENTPU, ENTPV,
1580                             ENTNC, ENTNC, ENTNC, ENTNC},
1581                            /* A      B      C      D      E      F      G      H      I      J      K  *
1582                               L      M      N      O      P      Q      R      S      T      U      V  *
1583                               W      X      Y      Z */
1584                            {ENTNC, ENTNC, ENTQC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTQI, ENTNC, ENTNC,
1585                   /* Q */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1586                             ENTQW, ENTNC, ENTNC, ENTNC},
1587                            /* A      B      C      D      E      F      G      H      I      J      K  *
1588                               L      M      N      O      P      Q      R      S      T      U      V  *
1589                               W      X      Y      Z */
1590                            {ENTRA, ENTNC, ENTNC, ENTRD, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1591                   /* R */   ENTRL, ENTRM, ENTRN, ENTNC, ENTRP, ENTNC, ENTRR, ENTNC, ENTRT, ENTRU, ENTNC,
1592                             ENTNC, ENTRX, ENTRY, ENTNC},
1593                            /* A      B      C      D      E      F      G      H      I      J      K  *
1594                               L      M      N      O      P      Q      R      S      T      U      V  *
1595                               W      X      Y      Z */
1596                            {ENTSA, ENTSB, ENTSC, ENTSD, ENTSE, ENTSF, ENTSG, ENTSH, ENTSI, ENTNC, ENTNC,
1597                   /* S */   ENTNC, ENTSM, ENTSN, ENTSO, ENTSP, ENTNC, ENTSR, ENTSS, ENTST, ENTSU, ENTSV,
1598                             ENTNC, ENTNC, ENTNC, ENTSZ},
1599                            /* A      B      C      D      E      F      G      H      I      J      K  *
1600                               L      M      N      O      P      Q      R      S      T      U      V  *
1601                               W      X      Y      Z */
1602                            {ENTNC, ENTNC, ENTTC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1603                   /* T */   ENTNC, ENTTM, ENTNC, ENTNC, ENTTP, ENTNC, ENTNC, ENTTS, ENTTT, ENTTU, ENTNC,
1604                             ENTNC, ENTNC, ENTNC, ENTNC},
1605                            /* A      B      C      D      E      F      G      H      I      J      K  *
1606                               L      M      N      O      P      Q      R      S      T      U      V  *
1607                               W      X      Y      Z */
1608                            {ENTNC, ENTNC, ENTNC, ENTUD, ENTNC, ENTNC, ENTNC, ENTUH, ENTNC, ENTNC, ENTNC,
1609                   /* U */   ENTUL, ENTUM, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTUS, ENTNC, ENTNC, ENTNC,
1610                             ENTNC, ENTNC, ENTNC, ENTUZ},
1611                            /* A      B      C      D      E      F      G      H      I      J      K  *
1612                               L      M      N      O      P      Q      R      S      T      U      V  *
1613                               W      X      Y      Z */
1614                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVF, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1615                   /* V */   ENTNC, ENTVM, ENTNC, ENTVO, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTVU, ENTNC,
1616                             ENTNC, ENTNC, ENTNC, ENTNC},
1617                            /* A      B      C      D      E      F      G      H      I      J      K  *
1618                               L      M      N      O      P      Q      R      S      T      U      V  *
1619                               W      X      Y      Z */
1620                            {ENTNC, ENTNC, ENTWC, ENTWD, ENTNC, ENTNC, ENTNC, ENTNC, ENTWI, ENTNC, ENTNC,
1621                   /* W */   ENTNC, ENTNC, ENTWN, ENTNC, ENTNC, ENTNC, ENTNC, ENTWS, ENTNC, ENTWU, ENTNC,
1622                             ENTNC, ENTNC, ENTNC, ENTNC},
1623                            /* A      B      C      D      E      F      G      H      I      J      K  *
1624                               L      M      N      O      P      Q      R      S      T      U      V  *
1625                               W      X      Y      Z */
1626                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXG, ENTNC, ENTXI, ENTNC, ENTNC,
1627                   /* X */   ENTNC, ENTXM, ENTXN, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTXU, ENTNC,
1628                             ENTNC, ENTXX, ENTXY, ENTNC},
1629                            /* A      B      C      D      E      F      G      H      I      J      K  *
1630                               L      M      N      O      P      Q      R      S      T      U      V  *
1631                               W      X      Y      Z */
1632                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1633                   /* Y */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1634                             ENTNC, ENTNC, ENTNC, ENTNC},
1635                            /* A      B      C      D      E      F      G      H      I      J      K  *
1636                               L      M      N      O      P      Q      R      S      T      U      V  *
1637                               W      X      Y      Z */
1638                            {ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1639                   /* Z */   ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC, ENTNC,
1640                             ENTNC, ENTNC, ENTNC, ENTNC}
1641                         };
1642
1643    /*ss013.301 :Adding  TRC MACRO*/
1644             memcpy(osCp.entId, entInfo, sizeof(entInfo));
1645
1646    return ROK;
1647 } /* SFillEntIds */
1648
1649
1650 /*
1651 *
1652 *       Fun:   SGetEntInd 
1653 *
1654 *       Desc:  This function gives the entity Id depending in the 
1655 *              file name. This function uses the first two letter
1656 *              of file name to find the entity id. 
1657 *              
1658 *              
1659 *
1660 *       Ret:   ROK              OK
1661 *              RFAILED          Region not registered
1662 *
1663 *
1664 */
1665 S16 SGetEntInd(Ent *entId,uint8_t *fileName)
1666 {
1667
1668
1669         uint8_t   *letter = NULLP;
1670    /* ss002.301 Additions */
1671         S8   *strippedName = NULLP;
1672         uint8_t   count = 0;
1673         uint8_t   tempIdx = 0;
1674         uint8_t   firstIdx = 0;
1675         uint8_t   secondIdx = 0;
1676
1677
1678    /* ss002.301 Additions */
1679         if ((strippedName = strrchr((const char *)fileName, '/')))
1680         {
1681            fileName = (uint8_t *)strippedName + 1;
1682         }
1683
1684         if(fileName[0] =='l' && fileName[3] == '.')
1685    { 
1686            /* Usally layer manager interface files starts
1687                  * with l. so leave the first letter and take
1688                  * other two letter.
1689                  * Eg. Layer manger inteface file name for TUCL is lhi.c.
1690                  * so here we leave l and we take hi to get the entity Id. */
1691       letter = ++fileName; 
1692         } 
1693         else
1694         { 
1695            letter = fileName;
1696            /* Handle exceptional file names */
1697            switch(letter[0])
1698            {
1699               case 'g':
1700                      if (letter[1] == 'g' && letter[2] == 'u')
1701                      {
1702                         *entId = ENTGT;
1703                              return ROK;
1704                      }
1705                    default: 
1706                              break;
1707
1708            }
1709         }
1710
1711
1712    /* here first two charactes of file name should be alphabets.
1713          * if any one of the letter is non alphabet then we return ENTNC 
1714          * as an entity Id */
1715    /* Eg. In fileName l4_ptui.c, second letter is numeral. so we consider
1716          * this file belogs to entity Id ENTNC. */
1717         for(count = 0; count < 2; count++)
1718         {
1719                 /* ss002.301 - Optimizations */
1720             if(letter[count] < 'a' || letter[count] > 'z')
1721             {
1722                    *entId = ENTNC;
1723                    return ROK;
1724             }
1725             else
1726             {
1727                    tempIdx = letter[count] - 'a';
1728             }
1729                  if(count == 0)
1730                  {
1731                         firstIdx = tempIdx;
1732                  }/* End of if */
1733                  else
1734                  {
1735                         secondIdx = tempIdx;
1736                  }/* End of else */
1737         } /* End of for */
1738         /* First two letter of file name are alphabets the get the 
1739          * entity id from the static data base which is loaded in sFillEntIds() */
1740         *entId = osCp.entId[firstIdx][secondIdx];
1741         return ROK;
1742 } /* SGetEntInd */
1743
1744 #endif /* SS_HISTOGRAM_SUPPORT */
1745 #ifdef SS_LOCK_SUPPORT
1746 /* ss002.301 Readwrite lock additions */
1747 /*
1748 *
1749 *       Fun:   SLockNew 
1750 *
1751 *       Desc:  This function is used to aquire the read write lock
1752 *
1753 *       Ret:   ROK   OK
1754 *
1755 *       Notes:
1756 *
1757 *       File:  mt_ss.c
1758 *
1759 */
1760 S16 SLockNew(SLockInfo *lockId,uint8_t lockType)
1761 {
1762    S16    retVal = ROK;
1763
1764
1765   if((retVal = ssdLockNew(lockId, lockType)) != ROK) 
1766   {
1767     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SLockNew(): Failed to aquire the lock\n");
1768     return RFAILED;
1769   }
1770    return ROK;
1771 }
1772
1773 /*
1774 *
1775 *       Fun:   SInitLockNew 
1776 *
1777 *       Desc:  This function is used to aquire the read write lock
1778 *
1779 *       Ret:   ROK   OK
1780 *
1781 *       Notes:
1782 *
1783 *       File:  mt_ss.c
1784 *
1785 */
1786 S16 SInitLockNew(SLockInfo *lockId,uint8_t  lockType)
1787 {
1788    S16    retVal = ROK;
1789
1790
1791   if((retVal = ssdInitLockNew(lockId, lockType)) != ROK) 
1792   {
1793     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SInitLockNew(): Initialization of lock Failed\n");
1794     return RFAILED;
1795   }
1796    return ROK;
1797 }
1798
1799 /*
1800 *
1801 *       Fun:   SUnlockNew 
1802 *
1803 *       Desc:  This function is used to Unlock the read write lock 
1804 *
1805 *       Ret:   ROK   OK
1806 *
1807 *       Notes:
1808 *
1809 *       File:  mt_ss.c
1810 *
1811 */
1812 S16 SUnlockNew(SLockInfo *lockId,uint8_t lockType)
1813 {
1814    S16    retVal = ROK;
1815
1816
1817   if((retVal = ssdUnlockNew(lockId, lockType)) != ROK) 
1818   {
1819     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SUnlockNew(): Failed to release the lock\n");
1820     return RFAILED;
1821   }
1822    return ROK;
1823 }
1824
1825 /*
1826 *
1827 *       Fun:   SDestroyLockNew 
1828 *
1829 *       Desc:  This function is used to destroy the read write lock 
1830 *
1831 *       Ret:   ROK   OK
1832 *
1833 *       Notes:
1834 *
1835 *       File:  mt_ss.c
1836 *
1837 */
1838 S16 SDestroyLockNew(SLockInfo *lockId,uint8_t lockType)
1839 {
1840    S16    retVal = ROK;
1841
1842
1843   if((retVal = ssdDestroyLockNew(lockId, lockType)) != ROK) 
1844   {
1845     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SDestroyLockNew(): Failed to destroy the lock\n");
1846     return RFAILED;
1847   }
1848    return ROK;
1849 }
1850 #endif /* SS_LOCK_SUPPORT */
1851
1852 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1853 /* Static memory leak detection changes */
1854 static uint32_t StaticMemLeakAge;
1855 static uint32_t StaticMemLeakIntCount = 1;
1856
1857 void PrintStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo, FILE *opFile)
1858 {
1859    int i;
1860
1861    fprintf(opFile, "Current Time = %ld\n",StaticMemLeakAge);
1862
1863    for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
1864    {
1865       if(memAllocInfo->allocations[i].ptr)
1866       {
1867          fprintf(opFile, "p = %p f = %s l = %ld s = %ld a = %ld\n",
1868                           memAllocInfo->allocations[i].ptr, 
1869                           memAllocInfo->allocations[i].file, 
1870                           memAllocInfo->allocations[i].lineNo, 
1871                           memAllocInfo->allocations[i].size, 
1872                           memAllocInfo->allocations[i].age);
1873       }
1874    }
1875
1876    fclose(opFile);
1877 }
1878
1879 void InitializeStaticMemAllocInfo(StaticMemAllocInfo* memAllocInfo)
1880 {
1881    uint32_t i;
1882    /* index 0 is not used; nextIdx as 0 means end of list */
1883    memAllocInfo->nextFreeIdx = 1;
1884
1885    for(i = 1; i < MAX_MEM_ALLOCATIONS; i++)
1886    {
1887       memAllocInfo->allocations[i].listInfo.nextIdx = i + 1;
1888       memAllocInfo->allocations[i].ptr = 0;
1889    }
1890
1891    /* override the last one to point to 0 meaning end of list */
1892    memAllocInfo->allocations[MAX_MEM_ALLOCATIONS - 1].listInfo.nextIdx = 0;
1893 }
1894
1895 uint32_t GetNextFreeIdx(StaticMemAllocInfo * memAllocInfo)
1896 {
1897    uint32_t toBeReturned = memAllocInfo->nextFreeIdx;
1898
1899    uint32_t newNextFreeIdx = memAllocInfo->allocations[memAllocInfo->nextFreeIdx].listInfo.nextIdx;
1900
1901    if(newNextFreeIdx == 0 || newNextFreeIdx >= MAX_MEM_ALLOCATIONS)
1902    {
1903       printf("\nSomething wrong in GetNextFreeIdx newNextIdx = %ld\n",newNextFreeIdx);
1904    }
1905
1906    memAllocInfo->nextFreeIdx = newNextFreeIdx;
1907    
1908    return toBeReturned;
1909 }
1910
1911 #define CRASH_ENB {int *p = 0; *p = 100;}
1912 void FreeIdx(uint8_t* ptr, uint32_t idx, StaticMemAllocInfo* memAllocInfo,uint32_t size, char* file, uint32_t line)
1913 {
1914    if(idx == 0 || idx >= MAX_MEM_ALLOCATIONS)
1915    {
1916       printf("Something wrong in FreeIdx... idx = %ld called from %s:%ld\n",idx,file,line);
1917       CRASH_ENB
1918    }
1919    /*printf("FreeIdx... idx = %d nexFree = %d\n",idx, memAllocInfo->nextFreeIdx);*/
1920    memAllocInfo->allocations[idx].listInfo.nextIdx = memAllocInfo->nextFreeIdx;
1921    if((ptr != memAllocInfo->allocations[idx].ptr) ||
1922       (size != memAllocInfo->allocations[idx].size))
1923    {
1924 #ifdef XEON_SPECIFIC_CHANGES
1925 CRASH_ENB
1926 #endif   
1927       
1928       printf("\nFreeing wrong ptr stored = %p trying to free %p freeing size (%ld)"
1929             "allocated size(%ld) from %s:%ld\n",
1930               memAllocInfo->allocations[idx].ptr, 
1931               ptr,
1932               size,
1933               memAllocInfo->allocations[idx].size,
1934               file,
1935               line);
1936       printf("\nAllocation was done from %s:%ld\n",memAllocInfo->allocations[idx].file, memAllocInfo->allocations[idx].lineNo);
1937       printf("\n***********************************************************\n");
1938       CRASH_ENB
1939    }
1940
1941    memAllocInfo->allocations[idx].ptr = 0;
1942
1943    memAllocInfo->nextFreeIdx = idx;
1944 }
1945
1946
1947 void LogForStaticMemLeak(StaticMemAllocInfo* memAllocInfo, char* file, uint32_t line, uint32_t size, void* ptr, uint32_t idx)
1948 {
1949
1950    memAllocInfo->allocations[idx].file = file;
1951    memAllocInfo->allocations[idx].lineNo = line;
1952    memAllocInfo->allocations[idx].size = size;
1953    memAllocInfo->allocations[idx].ptr = ptr;
1954    memAllocInfo->allocations[idx].age = StaticMemLeakAge;
1955
1956    if(StaticMemLeakIntCount++ % 256 == 0)
1957    {
1958       StaticMemLeakAge++;
1959    }
1960 }
1961
1962 void InitializeForStaticMemLeak()
1963 {
1964    int i;
1965
1966    StaticMemLeakFileArr[0] = fopen("region0.log","w");
1967    StaticMemLeakFileArr[1] = fopen("region1.log","w");
1968    StaticMemLeakFileArr[2] = fopen("region2.log","w");
1969    StaticMemLeakFileArr[3] = fopen("region3.log","w");
1970
1971    if(StaticMemLeakFileArr[0] == NULL ||
1972          StaticMemLeakFileArr[1] == NULL ||
1973          StaticMemLeakFileArr[2] == NULL ||
1974          StaticMemLeakFileArr[3] == NULL)
1975    {
1976       int *p = 0;
1977       printf("\nCould not open files for Static Mem Leak detection logging :( crashing...\n");
1978       *p = 100;
1979    }
1980
1981    for(i = 0; i < 4; i++)
1982    {
1983       InitializeStaticMemAllocInfo(&SMemLeakInfo[i]);
1984    }
1985 }
1986
1987 void DumpStaticMemLeakFiles()
1988 {
1989    int i;
1990
1991    for(i = 0; i < 4; i++)
1992    {
1993       PrintStaticMemAllocInfo(&SMemLeakInfo[i], StaticMemLeakFileArr[i]);
1994    }
1995 }
1996 /* Static memory leak detection changes */
1997 #endif
1998
1999 /*
2000  *
2001  *       Fun:   ssRegMainThread
2002  *
2003  *       Desc:  This function is used to add the memory region
2004  *              mapping for the main thread.
2005  *
2006  *       Ret:   VOID (Always successful)
2007  *
2008  *       Notes:
2009  *
2010  *       File: mt_ss.c
2011  *
2012  */
2013 S16 SReInitTmr(void)
2014 {
2015    uint8_t ret = ROK;
2016    Txt prntBuf[PRNTSZE];
2017
2018    sprintf(prntBuf, "\n SReInitTmr(): ReStarting the Tmr\n");
2019    SDisplay(1,prntBuf);
2020    ret = ssdReInitTmr();
2021    if (ret != ROK)
2022    {
2023        /*ss012.301 : Fix log related issue to suite MT and NS implementations*/
2024     SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SReInitTmr(): Failed to Restart the Tmr\n");
2025     return RFAILED;
2026    }
2027    return ROK;
2028 }
2029
2030 /*
2031  *
2032  *       Fun:   SGetConfigPath 
2033  *
2034  *       Desc:  This function is used to Get config files path
2035  *
2036  *       Ret:   S8* config file Path
2037  *
2038  *       Notes:
2039  *
2040  *       File: ss_gen.c
2041  *
2042  */
2043 S8* SGetConfigPath(Void)
2044 {
2045    return osCp.configFilePath;
2046 }
2047
2048 /**********************************************************************
2049          End of file
2050  **********************************************************************/