e2b337e3578abb093c2ee403e3e77f206a9106d2
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / vayu / Platform.c
1 /*
2  *  @file   Platform.c
3  *
4  *  @brief      Implementation of Platform initialization logic.
5  *
6  *
7  *  ============================================================================
8  *
9  *  Copyright (c) 2013, Texas Instruments Incorporated
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *  *  Redistributions of source code must retain the above copyright
16  *     notice, this list of conditions and the following disclaimer.
17  *
18  *  *  Redistributions in binary form must reproduce the above copyright
19  *     notice, this list of conditions and the following disclaimer in the
20  *     documentation and/or other materials provided with the distribution.
21  *
22  *  *  Neither the name of Texas Instruments Incorporated nor the names of
23  *     its contributors may be used to endorse or promote products derived
24  *     from this software without specific prior written permission.
25  *
26  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *  Contact information for paper mail:
38  *  Texas Instruments
39  *  Post Office Box 655303
40  *  Dallas, Texas 75265
41  *  Contact information:
42  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
43  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
44  *  ============================================================================
45  *
46  */
49 /* Standard header files */
50 #include <ti/syslink/Std.h>
52 /* Utilities & Osal headers */
53 #include <ti/syslink/utils/Gate.h>
54 #include <ti/syslink/utils/GateMutex.h>
55 #include <ti/syslink/utils/Memory.h>
56 #include <ti/syslink/utils/Trace.h>
57 #include <ti/ipc/MultiProc.h>
58 #include <ti/syslink/utils/OsalPrint.h>
59 #include <ti/syslink/inc/knl/OsalThread.h>
60 #include <ti/syslink/utils/String.h>
61 #include <ti/syslink/utils/Cfg.h>
63 /* SysLink device specific headers */
64 #include <VAYUIpcInt.h>
65 #include <VAYUDspPwr.h>
66 #include <VAYUDspProc.h>
67 #include <VAYUIpuCore1Proc.h>
68 #include <VAYUIpuCore0Proc.h>
69 #include <VAYUIpuPwr.h>
71 /* Module level headers */
72 #include <_MessageQCopy.h>
73 #include <ti/ipc/MessageQCopy.h>
74 #include <_MessageQCopyDefs.h>
76 #include <ti/syslink/ProcMgr.h>
77 #include <_ProcMgr.h>
78 #include <ti/syslink/inc/knl/Platform.h>
79 #include <ElfLoader.h>
81 #include <ti/ipc/Ipc.h>
82 #include <_Ipc.h>
83 #include <_MultiProc.h>
84 #include <IpcKnl.h>
85 #include <sys/mman.h>
87 #if defined (__cplusplus)
88 extern "C" {
89 #endif
92 /** ============================================================================
93  *  Macros.
94  *  ============================================================================
95  */
97 /** ============================================================================
98  *  Application specific configuration, please change these value according to
99  *  your application's need.
100  *  ============================================================================
101  */
102 /*!
103  *  @brief  Structure defining config parameters for overall System.
104  */
105 typedef struct Platform_Config {
106     MultiProc_Config                multiProcConfig;
107     /*!< Multiproc config parameter */
109     MessageQCopy_Config             MQCopyConfig;
110     /*!< MessageQCopy config parameter */
112     ProcMgr_Config                  procMgrConfig;
113     /*!< Processor manager config parameter */
115     ElfLoader_Config                elfLoaderConfig;
116     /*!< Elf loader config parameter */
117 } Platform_Config;
119 /*! @brief structure for platform instance */
120 typedef struct Platform_Object {
121     /*!< Flag to indicate platform initialization status */
122     ProcMgr_Handle                pmHandle;
123     /*!< Handle to the ProcMgr instance used */
124     union {
125         struct {
126             VAYUDSPPROC_Handle pHandle;
127             /*!< Handle to the Processor instance used */
128             VAYUDSPPWR_Handle  pwrHandle;
129             /*!< Handle to the PwrMgr instance used */
130             ElfLoader_Handle   ldrHandle;
131             /*!< Handle to the Loader instance used */
132         } dsp0;
133         struct {
134             VAYUIPUCORE0PROC_Handle pHandle;
135             /*!< Handle to the Processor instance used */
136             VAYUIPUPWR_Handle       pwrHandle;
137             /*!< Handle to the PwrMgr instance used */
138             ElfLoader_Handle        ldrHandle;
139             /*!< Handle to the Loader instance used */
140         } ipu1;
141     } sHandles;
142     /*!< Slave specific handles */
143 } Platform_Object, *Platform_Handle;
146 /*! @brief structure for platform instance */
147 typedef struct Platform_Module_State {
148     Bool              multiProcInitFlag;
149     /*!< MultiProc Initialize flag */
150     Bool              messageQCopyInitFlag;
151     /*!< MessageQCopy Initialize flag */
152     Bool              procMgrInitFlag;
153     /*!< Processor manager Initialize flag */
154     Bool              elfLoaderInitFlag;
155     /*!< Elf loader Initialize flag */
156     Bool              ipcIntInitFlag;
157     /*!< IpcInt Initialize flag */
158     Bool              platformInitFlag;
159     /*!< Flag to indicate platform initialization status */
160 } Platform_Module_State;
163 /* =============================================================================
164  * GLOBALS
165  * =============================================================================
166  */
167 static Platform_Object Platform_objects [MultiProc_MAXPROCESSORS];
168 static Platform_Module_State Platform_Module_state;
169 static Platform_Module_State * Platform_module = &Platform_Module_state;
171 Int32 _Platform_setup  (Ipc_Config * cfg);
172 Int32 _Platform_destroy (void);
174 extern String ProcMgr_sysLinkCfgParams;
176 String Syslink_Override_Params = "ProcMgr.proc[DSP1].mmuEnable=TRUE;"
177                                  "ProcMgr.proc[DSP1].carveoutAddr0=0xBA300000;"
178                                  "ProcMgr.proc[DSP1].carveoutSize0=0x5A00000;"
179                                  "ProcMgr.proc[IPU2].mmuEnable=TRUE;"
180                                  "ProcMgr.proc[IPU2].carveoutAddr0=0xBA300000;"
181                                  "ProcMgr.proc[IPU2].carveoutSize0=0x5A00000;";
183 /** ============================================================================
184  *  APIs.
185  *  ============================================================================
186  */
187 /* Function to read slave memory */
188 Int32
189 _Platform_readSlaveMemory (UInt16   procId,
190                            UInt32   addr,
191                            Ptr      value,
192                            UInt32 * numBytes);
194 /* Function to write slave memory */
195 Int32
196 _Platform_writeSlaveMemory (UInt16   procId,
197                             UInt32   addr,
198                             Ptr      value,
199                             UInt32 * numBytes);
200 /*!
201  *  @brief      Function to get the default values for configurations.
202  *
203  *  @param      config   Configuration values.
204  */
205 Void
206 Platform_getConfig (Platform_Config * config)
208     GT_1trace (curTrace, GT_ENTER, "Platform_getConfig", config);
210     GT_assert (curTrace, (config != NULL));
212 #if !defined(SYSLINK_BUILD_OPTIMIZE)
213     if (config == NULL) {
214         GT_setFailureReason (curTrace,
215                              GT_4CLASS,
216                              "Platform_getConfig",
217                              Platform_E_INVALIDARG,
218                              "Argument of type (Platform_getConfig *) passed "
219                              "is null!");
220     }
221     else {
222 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
224         /* Get the gatepeterson default config */
225         MultiProc_getConfig (&config->multiProcConfig);
227         /* Get the PROCMGR default config */
228         ProcMgr_getConfig (&config->procMgrConfig);
230         /* Get the ElfLoader default config */
231         ElfLoader_getConfig (&config->elfLoaderConfig);
232 #if !defined(SYSLINK_BUILD_OPTIMIZE)
233     }
234 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
236     GT_0trace (curTrace, GT_LEAVE, "Platform_getConfig");
239 /*!
240  *  @brief      Function to override the default configuration values.
241  *
242  *  @param      config   Configuration values.
243  */
244 Int32
245 Platform_overrideConfig (Platform_Config * config, Ipc_Config * cfg)
247     Int32  status = Platform_S_SUCCESS;
248     char * pSL_PARAMS;
250     GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", config);
252     GT_assert (curTrace, (config != NULL));
254 #if !defined(SYSLINK_BUILD_OPTIMIZE)
255     if (config == NULL) {
256         /*! @retval Platform_E_INVALIDARG Argument of type
257          *  (Platform_Config *) passed is null*/
258         status = Platform_E_INVALIDARG;
259         GT_setFailureReason (curTrace,
260                              GT_4CLASS,
261                              "Platform_overrideConfig",
262                              status,
263                              "Argument of type (Platform_getConfig *) passed "
264                              "is null!");
265     }
266     else {
267 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
269         /* assign config->params - overriding with SL_PARAMS env var, if set */
270         pSL_PARAMS = getenv("SL_PARAMS");
271         if (pSL_PARAMS != NULL) {
272             GT_2trace(curTrace, GT_1CLASS, "Overriding SysLink_params \"%s\""
273                     " with SL_PARAMS \"%s\"\n", Syslink_Override_Params, pSL_PARAMS);
274             cfg->params = Memory_alloc(NULL, String_len(pSL_PARAMS), 0, NULL);
275             if (cfg->params) {
276                 String_cpy(cfg->params, pSL_PARAMS);
277             }
278         }
279         else {
280             cfg->params = Memory_alloc(NULL,
281                                        String_len(Syslink_Override_Params) + 1, 0,
282                                        NULL);
283             if (cfg->params) {
284                 String_cpy(cfg->params, Syslink_Override_Params);
285             }
286         }
288         _ProcMgr_saveParams(cfg->params, String_len(cfg->params));
290         /* Set the MultiProc config as defined in SystemCfg.c */
291         config->multiProcConfig = _MultiProc_cfg;
293         /* Override the MESSAGEQCOPY default config */
294         config->MQCopyConfig.intId[1] = 173; // 141 + 32
295         config->MQCopyConfig.intId[4] = 168; // 136 + 32
297 #if !defined(SYSLINK_BUILD_OPTIMIZE)
298     }
299 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
301     GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", status);
303     /*! @retval Platform_S_SUCCESS operation was successful */
304     return status;
307 /*!
308  *  @brief      Function to setup platform.
309  *              TBD: logic would change completely in the final system.
310  */
311 Int32
312 Platform_setup (Ipc_Config * cfg)
314     Int32             status = Platform_S_SUCCESS;
315     Platform_Config   _config;
316     Platform_Config * config;
317     VAYUIpcInt_Config VAYUcfg;
319     Platform_getConfig (&_config);
320     config = &_config;
322     Platform_overrideConfig (config, cfg);
324     status = MultiProc_setup (&(config->multiProcConfig));
326 #if !defined(SYSLINK_BUILD_OPTIMIZE)
327     if (status < 0) {
328         GT_setFailureReason (curTrace,
329                              GT_4CLASS,
330                              "Platform_setup",
331                              status,
332                              "MultiProc_setup failed!");
333     }
334     else {
335 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
336             Platform_module->multiProcInitFlag = TRUE;
337 #if !defined(SYSLINK_BUILD_OPTIMIZE)
338     }
339 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
341 /* Initialize PROCMGR */
342     if (status >= 0) {
343         status = ProcMgr_setup (&(config->procMgrConfig));
344 #if !defined(SYSLINK_BUILD_OPTIMIZE)
345         if (status < 0) {
346             GT_setFailureReason (curTrace,
347                                  GT_4CLASS,
348                                  "Platform_setup",
349                                  status,
350                                  "ProcMgr_setup failed!");
351         }
352         else {
353 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
354             Platform_module->procMgrInitFlag = TRUE;
355 #if !defined(SYSLINK_BUILD_OPTIMIZE)
356         }
357 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
358     }
360     /* Initialize IpcInt required for VirtQueue/MessageQCopy. */
361     if (status >= 0) {
362         /* Do the IPC interrupts setup for the full platform (cfg is not used) */
363         VAYUIpcInt_setup (&VAYUcfg);
364         Platform_module->ipcIntInitFlag = TRUE;
365     }
368 /* Intialize MESSAGEQCOPY */
369     if (status >= 0) {
370         status = MessageQCopy_setup (&config->MQCopyConfig);
371 #if !defined(SYSLINK_BUILD_OPTIMIZE)
372         if (status < 0) {
373             GT_setFailureReason (curTrace,
374                                  GT_4CLASS,
375                                  "Platform_setup",
376                                  status,
377                                  "MessageQCopy_setup failed!");
378         }
379         else {
380 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
381             Platform_module->messageQCopyInitFlag = TRUE;
382 #if !defined(SYSLINK_BUILD_OPTIMIZE)
383         }
384 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
385     }
387 /* Intialize Elf loader */
388     if (status >= 0) {
389         status = ElfLoader_setup (&config->elfLoaderConfig);
390 #if !defined(SYSLINK_BUILD_OPTIMIZE)
391         if (status < 0) {
392             GT_setFailureReason (curTrace,
393                                  GT_4CLASS,
394                                  "Platform_setup",
395                                  status,
396                                  "ElfLoader_setup failed!");
397         }
398         else {
399 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
400             Platform_module->elfLoaderInitFlag = TRUE;
401 #if !defined(SYSLINK_BUILD_OPTIMIZE)
402         }
403 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
404     }
406     if (status >= 0) {
407         Memory_set (Platform_objects,
408                     0,
409                     (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
410     }
412     if (status >= 0) {
413         status = _Platform_setup (cfg);
414 #if !defined(SYSLINK_BUILD_OPTIMIZE)
415         if (status < 0) {
416             GT_setFailureReason (curTrace,
417                                  GT_4CLASS,
418                                  "Platform_setup",
419                                  status,
420                                  "_Platform_setup failed!");
421         }
422         else {
423 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
424             Platform_module->platformInitFlag = TRUE;
425 #if !defined(SYSLINK_BUILD_OPTIMIZE)
426         }
427 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
428     }
430     if (status < 0) {
431         Platform_destroy();
432     }
433     return status;
437 /*!
438  *  @brief      Function to destroy the System.
439  *
440  *  @sa         Platform_setup
441  */
442 Int32
443 Platform_destroy (void)
445     Int32  status = Platform_S_SUCCESS;
447     GT_0trace (curTrace, GT_ENTER, "Platform_destroy");
449     /* Finalize Platform-specific destroy */
450     if (Platform_module->platformInitFlag == TRUE) {
451         status = _Platform_destroy ();
452 #if !defined(SYSLINK_BUILD_OPTIMIZE)
453         if (status < 0) {
454             GT_setFailureReason (curTrace,
455                                  GT_4CLASS,
456                                  "Platform_destroy",
457                                  status,
458                                  "Platform_destroy failed!");
459         }
460         else {
461 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
462             Platform_module->platformInitFlag = FALSE;
463 #if !defined(SYSLINK_BUILD_OPTIMIZE)
464         }
465 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
466     }
468     /* Finalize elf loader */
469     if (Platform_module->elfLoaderInitFlag == TRUE) {
470         status = ElfLoader_destroy ();
471 #if !defined(SYSLINK_BUILD_OPTIMIZE)
472         if (status < 0) {
473             GT_setFailureReason (curTrace,
474                                  GT_4CLASS,
475                                  "Platform_destroy",
476                                  status,
477                                  "ElfLoader_destroy failed!");
478         }
479         else {
480 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
481             Platform_module->elfLoaderInitFlag = FALSE;
482 #if !defined(SYSLINK_BUILD_OPTIMIZE)
483         }
484 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
485     }
487     /* Finalize MESSAGEQCOPY */
488     if (Platform_module->messageQCopyInitFlag == TRUE) {
489         status = MessageQCopy_destroy ();
490 #if !defined(SYSLINK_BUILD_OPTIMIZE)
491         if (status < 0) {
492             GT_setFailureReason (curTrace,
493                                  GT_4CLASS,
494                                  "Platform_destroy",
495                                  status,
496                                  "MessageQCopy_destroy failed!");
497         }
498         else {
499 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
500             Platform_module->messageQCopyInitFlag = FALSE;
501 #if !defined(SYSLINK_BUILD_OPTIMIZE)
502         }
503 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
504     }
507     if (Platform_module->ipcIntInitFlag == TRUE) {
508         VAYUIpcInt_destroy ();
509         Platform_module->ipcIntInitFlag = FALSE;
510     }
512     /* Finalize PROCMGR */
513     if (Platform_module->procMgrInitFlag == TRUE) {
514         status = ProcMgr_destroy ();
515 #if !defined(SYSLINK_BUILD_OPTIMIZE)
516         if (status < 0) {
517             GT_setFailureReason (curTrace,
518                                  GT_4CLASS,
519                                  "Platform_destroy",
520                                  status,
521                                  "ProcMgr_destroy failed!");
522         }
523         else {
524 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
525             Platform_module->procMgrInitFlag = FALSE;
526 #if !defined(SYSLINK_BUILD_OPTIMIZE)
527         }
528 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
529     }
531     /* Finalize MultiProc */
532     if (Platform_module->multiProcInitFlag == TRUE) {
533         status = MultiProc_destroy ();
534 #if !defined(SYSLINK_BUILD_OPTIMIZE)
535     if (status < 0) {
536         GT_setFailureReason (curTrace,
537                              GT_4CLASS,
538                              "Platform_destroy",
539                              status,
540                              "MultiProc_destroy failed!");
541     }
542         else {
543 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
544             Platform_module->multiProcInitFlag = FALSE;
545 #if !defined(SYSLINK_BUILD_OPTIMIZE)
546         }
547 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
548     }
550     if (status >= 0) {
551         Memory_set (Platform_objects,
552                     0,
553                     (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
554     }
556     GT_1trace (curTrace, GT_LEAVE, "Platform_destroy", status);
558     /*! @retval Platform_S_SUCCESS Operation successful */
559     return status;
562 /*
563  * union _Platform_setup_Local exists so that we don't waste stack or
564  * alloc'ed memory on storage for things that exist for just a few
565  * statements of the function _Platform_setup().  The *PROC_Params
566  * elements are large and variably sized, depending on the macro
567  * ProcMgr_MAX_MEMORY_REGIONS.
568  */
569 typedef union _Platform_setup_Local {
570     ProcMgr_Params          params;
571     VAYUDSPPROC_Config      dspProcConfig;
572     VAYUIPUCORE1PROC_Config videoProcConfig;
573     VAYUIPUCORE0PROC_Config vpssProcConfig;
574     VAYUDSPPWR_Config       dspPwrConfig;
575     VAYUIPUPWR_Config       videoPwrConfig;
576     VAYUIPUPWR_Config       vpssPwrConfig;
577     VAYUDSPPROC_Params      dspProcParams;
578     VAYUIPUCORE1PROC_Params videoProcParams;
579     VAYUIPUCORE0PROC_Params vpssProcParams;
580     VAYUDSPPWR_Params       dspPwrParams;
581     VAYUIPUPWR_Params       videoPwrParams;
582     VAYUIPUPWR_Params       vpssPwrParams;
583     ElfLoader_Params        elfLoaderParams;
584 } _Platform_setup_Local;
587 /*!
588  *  @brief      Function to setup platform.
589  *              TBD: logic would change completely in the final system.
590  */
591 Int32
592 _Platform_setup (Ipc_Config * cfg)
594     Int32                   status = Platform_S_SUCCESS;
595     _Platform_setup_Local   *lv;
596     UInt16                  procId;
597     Platform_Handle         handle;
599     GT_0trace (curTrace, GT_ENTER, "_Platform_setup");
601     lv = Memory_alloc(NULL, sizeof(_Platform_setup_Local), 0, NULL);
602     if (lv == NULL) {
603         status = Platform_E_FAIL;
604         GT_setFailureReason (curTrace,
605                                 GT_4CLASS,
606                                 "_Platform_setup",
607                                 status,
608                                 "Memory_alloc failed");
609         goto ret;
610     }
611     if (status >= 0) {
612         /* Get MultiProc ID by name. */
613         procId = MultiProc_getId ("IPU2");
615         handle = &Platform_objects [procId];
616         VAYUIPUCORE0PROC_getConfig (&lv->vpssProcConfig);
617         status = VAYUIPUCORE0PROC_setup (&lv->vpssProcConfig);
618         if (status < 0) {
619             GT_setFailureReason (curTrace,
620                                  GT_4CLASS,
621                                  "_Platform_setup",
622                                  status,
623                                  "VAYUIPUCORE0PROC_setup failed!");
624         }
625         else {
626             VAYUIPUPWR_getConfig (&lv->vpssPwrConfig);
627             status = VAYUIPUPWR_setup (&lv->vpssPwrConfig);
628             if (status < 0) {
629                 GT_setFailureReason (curTrace,
630                                      GT_4CLASS,
631                                      "_Platform_setup",
632                                      status,
633                                      "VAYUIPUPWR_setup failed!");
634             }
635         }
637         if (status >= 0) {
638             /* Create an instance of the Processor object for
639              * VAYUIPUCORE0 */
640             VAYUIPUCORE0PROC_Params_init (NULL, &lv->vpssProcParams);
641             handle->sHandles.ipu1.pHandle = VAYUIPUCORE0PROC_create (procId,
642                                                          &lv->vpssProcParams);
644             /* Create an instance of the ELF Loader object */
645             ElfLoader_Params_init (NULL, &lv->elfLoaderParams);
646             handle->sHandles.ipu1.ldrHandle = ElfLoader_create (procId,
647                                                         &lv->elfLoaderParams);
649             /* Create an instance of the PwrMgr object for VAYUIPUCORE0 */
650             VAYUIPUPWR_Params_init (&lv->vpssPwrParams);
651             handle->sHandles.ipu1.pwrHandle = VAYUIPUPWR_create (
652                                                            procId,
653                                                            &lv->vpssPwrParams);
655             if (handle->sHandles.ipu1.pHandle == NULL) {
656                 status = Platform_E_FAIL;
657                 GT_setFailureReason (curTrace,
658                                      GT_4CLASS,
659                                      "_Platform_setup",
660                                      status,
661                                      "VAYUIPUCORE0PROC_create failed!");
662             }
663             else if (handle->sHandles.ipu1.ldrHandle ==  NULL) {
664                 status = Platform_E_FAIL;
665                 GT_setFailureReason (curTrace,
666                                      GT_4CLASS,
667                                      "_Platform_setup",
668                                      status,
669                                      "Failed to create loader instance!");
670             }
671             else if (handle->sHandles.ipu1.pwrHandle ==  NULL) {
672                 status = Platform_E_FAIL;
673                 GT_setFailureReason (curTrace,
674                                      GT_4CLASS,
675                                      "_Platform_setup",
676                                      status,
677                                      "VAYUIPUPWR_create failed!");
678             }
679             else {
680                 /* Initialize parameters */
681                 ProcMgr_Params_init (NULL, &lv->params);
682                 lv->params.procHandle = handle->sHandles.ipu1.pHandle;
683                 lv->params.loaderHandle = handle->sHandles.ipu1.ldrHandle;
684                 lv->params.pwrHandle = handle->sHandles.ipu1.pwrHandle;
685                 handle->pmHandle = ProcMgr_create (procId, &lv->params);
686                 if (handle->pmHandle == NULL) {
687                     status = Platform_E_FAIL;
688                     GT_setFailureReason (curTrace,
689                                          GT_4CLASS,
690                                          "_Platform_setup",
691                                          status,
692                                          "ProcMgr_create failed!");
693                 }
694             }
695         }
696     }
698     if (status >= 0) {
699         /* Get MultiProc ID by name. */
700         procId = MultiProc_getId ("DSP1");
702         handle = &Platform_objects [procId];
703         VAYUDSPPROC_getConfig (&lv->dspProcConfig);
704         status = VAYUDSPPROC_setup (&lv->dspProcConfig);
705         if (status < 0) {
706             GT_setFailureReason (curTrace,
707                                  GT_4CLASS,
708                                  "_Platform_setup",
709                                  status,
710                                  "VAYUDSPPROC_setup failed!");
711         }
712         else {
713             VAYUDSPPWR_getConfig (&lv->dspPwrConfig);
714             status = VAYUDSPPWR_setup (&lv->dspPwrConfig);
715             if (status < 0) {
716                 GT_setFailureReason (curTrace,
717                                      GT_4CLASS,
718                                      "_Platform_setup",
719                                      status,
720                                      "VAYUDSPPWR_setup failed!");
721             }
722         }
724         if (status >= 0) {
725             /* Create an instance of the Processor object for
726              * VAYUDSP */
727             VAYUDSPPROC_Params_init (NULL, &lv->dspProcParams);
728             handle->sHandles.dsp0.pHandle = VAYUDSPPROC_create (procId,
729                                                               &lv->dspProcParams);
731             /* Create an instance of the ELF Loader object */
732             ElfLoader_Params_init (NULL, &lv->elfLoaderParams);
733             handle->sHandles.dsp0.ldrHandle =
734                                            ElfLoader_create (procId,
735                                                              &lv->elfLoaderParams);
736             /* Create an instance of the PwrMgr object for VAYUDSP */
737             VAYUDSPPWR_Params_init (&lv->dspPwrParams);
738             handle->sHandles.dsp0.pwrHandle = VAYUDSPPWR_create (procId,
739                                                     &lv->dspPwrParams);
741             if (handle->sHandles.dsp0.pHandle == NULL) {
742                 status = Platform_E_FAIL;
743                 GT_setFailureReason (curTrace,
744                                      GT_4CLASS,
745                                      "_Platform_setup",
746                                      status,
747                                      "VAYUDSPPROC_create failed!");
748             }
749             else if (handle->sHandles.dsp0.ldrHandle ==  NULL) {
750                 status = Platform_E_FAIL;
751                 GT_setFailureReason (curTrace,
752                                      GT_4CLASS,
753                                      "_Platform_setup",
754                                      status,
755                                      "Failed to create loader instance!");
756             }
757             else if (handle->sHandles.dsp0.pwrHandle ==  NULL) {
758                 status = Platform_E_FAIL;
759                 GT_setFailureReason (curTrace,
760                                      GT_4CLASS,
761                                      "_Platform_setup",
762                                      status,
763                                      "VAYUDSPPWR_create failed!");
764             }
765             else {
766                 /* Initialize parameters */
767                 ProcMgr_Params_init (NULL, &lv->params);
768                 lv->params.procHandle = handle->sHandles.dsp0.pHandle;
769                 lv->params.loaderHandle = handle->sHandles.dsp0.ldrHandle;
770                 lv->params.pwrHandle = handle->sHandles.dsp0.pwrHandle;
771                 handle->pmHandle = ProcMgr_create (procId, &lv->params);
772                 if (handle->pmHandle == NULL) {
773                     status = Platform_E_FAIL;
774                     GT_setFailureReason (curTrace,
775                                          GT_4CLASS,
776                                          "_Platform_setup",
777                                          status,
778                                          "ProcMgr_create failed!");
779                 }
780             }
781         }
782     }
784     Memory_free(NULL, lv, sizeof(_Platform_setup_Local));
786 ret:
787     GT_1trace (curTrace, GT_LEAVE, "_Platform_setup", status);
789     /*! @retval Platform_S_SUCCESS operation was successful */
790     return status;
794 /*!
795  *  @brief      Function to setup platform.
796  *              TBD: logic would change completely in the final system.
797  */
798 Int32
799 _Platform_destroy (void)
801     Int32           status    = Platform_S_SUCCESS;
802     Int32           tmpStatus = Platform_S_SUCCESS;
803     Platform_Handle handle;
805     GT_0trace (curTrace, GT_ENTER, "_Platform_destroy");
807     /* ------------------------- DSP cleanup -------------------------------- */
808     handle = &Platform_objects [MultiProc_getId ("DSP1")];
809     if (handle->pmHandle != NULL) {
810         status = ProcMgr_delete (&handle->pmHandle);
811         GT_assert (curTrace, (status >= 0));
812 #if !defined(SYSLINK_BUILD_OPTIMIZE)
813         if (status < 0) {
814             GT_setFailureReason (curTrace,
815                                  GT_4CLASS,
816                                  "_Platform_destroy",
817                                  status,
818                                  "ProcMgr_delete failed!");
819         }
820 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
821     }
823     /* Delete the Processor, Loader and PwrMgr instances */
824     if (handle->sHandles.dsp0.pwrHandle != NULL) {
825         tmpStatus = VAYUDSPPWR_delete (&handle->sHandles.dsp0.pwrHandle);
826         GT_assert (curTrace, (tmpStatus >= 0));
827         if ((status >= 0) && (tmpStatus < 0)) {
828             status = tmpStatus;
829 #if !defined(SYSLINK_BUILD_OPTIMIZE)
830             GT_setFailureReason (curTrace,
831                                  GT_4CLASS,
832                                  "_Platform_destroy",
833                                  status,
834                                  "VAYUDSPPWR_delete failed!");
835 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
836         }
837     }
839     if (handle->sHandles.dsp0.ldrHandle != NULL) {
840         tmpStatus = ElfLoader_delete (&handle->sHandles.dsp0.ldrHandle);
841         GT_assert (curTrace, (tmpStatus >= 0));
842         if ((status >= 0) && (tmpStatus < 0)) {
843             status = tmpStatus;
844 #if !defined(SYSLINK_BUILD_OPTIMIZE)
845             GT_setFailureReason (curTrace,
846                                  GT_4CLASS,
847                                  "_Platform_destroy",
848                                  status,
849                                  "Failed to delete loader instance!");
850 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
851         }
852     }
854     if (handle->sHandles.dsp0.pHandle != NULL) {
855         tmpStatus = VAYUDSPPROC_delete (&handle->sHandles.dsp0.pHandle);
856         GT_assert (curTrace, (tmpStatus >= 0));
857         if ((status >= 0) && (tmpStatus < 0)) {
858             status = tmpStatus;
859 #if !defined(SYSLINK_BUILD_OPTIMIZE)
860             GT_setFailureReason (curTrace,
861                                  GT_4CLASS,
862                                  "_Platform_destroy",
863                                  status,
864                                  "VAYUDSPPROC_delete failed!");
865 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
866         }
867     }
869     tmpStatus = VAYUDSPPWR_destroy ();
870     GT_assert (curTrace, (tmpStatus >= 0));
871     if ((status >= 0) && (tmpStatus < 0)) {
872         status = tmpStatus;
873 #if !defined(SYSLINK_BUILD_OPTIMIZE)
874         GT_setFailureReason (curTrace,
875                              GT_4CLASS,
876                              "_Platform_destroy",
877                              status,
878                              "VAYUDSPPWR_destroy failed!");
879 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
880     }
882     tmpStatus = VAYUDSPPROC_destroy ();
883     GT_assert (curTrace, (tmpStatus >= 0));
884     if ((status >= 0) && (tmpStatus < 0)) {
885         status = tmpStatus;
886 #if !defined(SYSLINK_BUILD_OPTIMIZE)
887         GT_setFailureReason (curTrace,
888                              GT_4CLASS,
889                              "_Platform_destroy",
890                              status,
891                              "VAYUDSPPROC_destroy failed!");
892 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
893     }
895     /* ------------------------- IPU1 cleanup ------------------------------- */
896     handle = &Platform_objects [MultiProc_getId ("IPU2")];
897     if (handle->pmHandle != NULL) {
898         tmpStatus = ProcMgr_delete (&handle->pmHandle);
899         GT_assert (curTrace, (tmpStatus >= 0));
900         if ((status >= 0) && (tmpStatus < 0)) {
901             status = tmpStatus;
902 #if !defined(SYSLINK_BUILD_OPTIMIZE)
903             GT_setFailureReason (curTrace,
904                                  GT_4CLASS,
905                                  "_Platform_destroy",
906                                  status,
907                                  "ProcMgr_delete failed!");
908 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
909         }
910     }
912     /* Delete the Processor, Loader and PwrMgr instances */
913     if (handle->sHandles.ipu1.pwrHandle != NULL) {
914         tmpStatus = VAYUIPUPWR_delete (&handle->sHandles.ipu1.pwrHandle);
915         GT_assert (curTrace, (tmpStatus >= 0));
916         if ((status >= 0) && (tmpStatus < 0)) {
917             status = tmpStatus;
918 #if !defined(SYSLINK_BUILD_OPTIMIZE)
919             GT_setFailureReason (curTrace,
920                                  GT_4CLASS,
921                                  "_Platform_destroy",
922                                  status,
923                                  "VAYUIPUPWR_delete failed!");
924 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
925         }
926     }
928     if (handle->sHandles.ipu1.ldrHandle != NULL) {
929         tmpStatus = ElfLoader_delete (&handle->sHandles.ipu1.ldrHandle);
930         GT_assert (curTrace, (tmpStatus >= 0));
931         if ((status >= 0) && (tmpStatus < 0)) {
932             status = tmpStatus;
933 #if !defined(SYSLINK_BUILD_OPTIMIZE)
934             GT_setFailureReason (curTrace,
935                                  GT_4CLASS,
936                                  "_Platform_destroy",
937                                  status,
938                                  "Failed to delete loader instance!");
939 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
940         }
941     }
943     if (handle->sHandles.ipu1.pHandle != NULL) {
944         tmpStatus = VAYUIPUCORE0PROC_delete (&handle->sHandles.ipu1.pHandle);
945         GT_assert (curTrace, (tmpStatus >= 0));
946         if ((status >= 0) && (tmpStatus < 0)) {
947             status = tmpStatus;
948 #if !defined(SYSLINK_BUILD_OPTIMIZE)
949             GT_setFailureReason (curTrace,
950                                  GT_4CLASS,
951                                  "_Platform_destroy",
952                                  status,
953                                  "VAYUIPUCORE0PROC_delete failed!");
954 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
955         }
956     }
958     tmpStatus = VAYUIPUPWR_destroy ();
959     GT_assert (curTrace, (tmpStatus >= 0));
960     if ((status >= 0) && (tmpStatus < 0)) {
961         status = tmpStatus;
962 #if !defined(SYSLINK_BUILD_OPTIMIZE)
963         GT_setFailureReason (curTrace,
964                              GT_4CLASS,
965                              "_Platform_destroy",
966                              status,
967                              "VAYUIPUPWR_destroy failed!");
968 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
969     }
971     tmpStatus = VAYUIPUCORE0PROC_destroy ();
972     GT_assert (curTrace, (tmpStatus >= 0));
973     if ((status >= 0) && (tmpStatus < 0)) {
974         status = tmpStatus;
975 #if !defined(SYSLINK_BUILD_OPTIMIZE)
976         GT_setFailureReason (curTrace,
977                              GT_4CLASS,
978                              "_Platform_destroy",
979                              status,
980                              "VAYUIPUCORE0PROC_destroy failed!");
981 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
982     }
984     GT_1trace (curTrace, GT_LEAVE, "_Platform_destroy", status);
986     /*! @retval Platform_S_SUCCESS operation was successful */
987     return status;
991 #if defined (__cplusplus)
993 #endif