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