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