GateMP: Introduce support for GateMP on QNX
[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>
86 #include <GateHWSpinlock.h>
88 #if defined (__cplusplus)
89 extern "C" {
90 #endif
93 /** ============================================================================
94  *  Macros.
95  *  ============================================================================
96  */
97 /* Hardware spinlocks info */
98 #define HWSPINLOCK_BASE             0x4A0F6000
99 #define HWSPINLOCK_SIZE             0x1000
100 #define HWSPINLOCK_OFFSET           0x800
102 /** ============================================================================
103  *  Application specific configuration, please change these value according to
104  *  your application's need.
105  *  ============================================================================
106  */
107 /*!
108  *  @brief  Structure defining config parameters for overall System.
109  */
110 typedef struct Platform_Config {
111     MultiProc_Config                multiProcConfig;
112     /*!< Multiproc config parameter */
114     MessageQCopy_Config             MQCopyConfig;
115     /*!< MessageQCopy config parameter */
117     ProcMgr_Config                  procMgrConfig;
118     /*!< Processor manager config parameter */
120     ElfLoader_Config                elfLoaderConfig;
121     /*!< Elf loader config parameter */
123     GateHWSpinlock_Config           gateHWSpinlockConfig;
124     /*!< GateHWSpinlock config parameter */
125 } Platform_Config;
127 /*! @brief structure for platform instance */
128 typedef struct Platform_Object {
129     /*!< Flag to indicate platform initialization status */
130     ProcMgr_Handle                pmHandle;
131     /*!< Handle to the ProcMgr instance used */
132     union {
133         struct {
134             VAYUDSPPROC_Handle pHandle;
135             /*!< Handle to the Processor instance used */
136             VAYUDSPPWR_Handle  pwrHandle;
137             /*!< Handle to the PwrMgr instance used */
138             ElfLoader_Handle   ldrHandle;
139             /*!< Handle to the Loader instance used */
140         } dsp0;
141         struct {
142             VAYUIPUCORE0PROC_Handle pHandle;
143             /*!< Handle to the Processor instance used */
144             VAYUIPUPWR_Handle       pwrHandle;
145             /*!< Handle to the PwrMgr instance used */
146             ElfLoader_Handle        ldrHandle;
147             /*!< Handle to the Loader instance used */
148         } ipu1;
149     } sHandles;
150     /*!< Slave specific handles */
151 } Platform_Object, *Platform_Handle;
154 /*! @brief structure for platform instance */
155 typedef struct Platform_Module_State {
156     Bool              multiProcInitFlag;
157     /*!< MultiProc Initialize flag */
158     Bool              messageQCopyInitFlag;
159     /*!< MessageQCopy Initialize flag */
160     Bool              procMgrInitFlag;
161     /*!< Processor manager Initialize flag */
162     Bool              elfLoaderInitFlag;
163     /*!< Elf loader Initialize flag */
164     Bool              ipcIntInitFlag;
165     /*!< IpcInt Initialize flag */
166     Bool              platformInitFlag;
167     /*!< Flag to indicate platform initialization status */
168     Bool              gateHWSpinlockInitFlag;
169     /*!< GateHWSpinlock Initialize flag */
170     Ptr               gateHWSpinlockVAddr;
171     /*!< GateHWSpinlock Virtual Address */
172 } Platform_Module_State;
175 /* =============================================================================
176  * GLOBALS
177  * =============================================================================
178  */
179 static Platform_Object Platform_objects [MultiProc_MAXPROCESSORS];
180 static Platform_Module_State Platform_Module_state;
181 static Platform_Module_State * Platform_module = &Platform_Module_state;
183 Int32 _Platform_setup  (Ipc_Config * cfg);
184 Int32 _Platform_destroy (void);
186 extern String ProcMgr_sysLinkCfgParams;
188 String Syslink_Override_Params = "ProcMgr.proc[DSP1].mmuEnable=TRUE;"
189                                  "ProcMgr.proc[DSP1].carveoutAddr0=0xBA300000;"
190                                  "ProcMgr.proc[DSP1].carveoutSize0=0x5A00000;"
191                                  "ProcMgr.proc[IPU2].mmuEnable=TRUE;"
192                                  "ProcMgr.proc[IPU2].carveoutAddr0=0xBA300000;"
193                                  "ProcMgr.proc[IPU2].carveoutSize0=0x5A00000;";
195 /** ============================================================================
196  *  APIs.
197  *  ============================================================================
198  */
199 /* Function to read slave memory */
200 Int32
201 _Platform_readSlaveMemory (UInt16   procId,
202                            UInt32   addr,
203                            Ptr      value,
204                            UInt32 * numBytes);
206 /* Function to write slave memory */
207 Int32
208 _Platform_writeSlaveMemory (UInt16   procId,
209                             UInt32   addr,
210                             Ptr      value,
211                             UInt32 * numBytes);
212 /*!
213  *  @brief      Function to get the default values for configurations.
214  *
215  *  @param      config   Configuration values.
216  */
217 Void
218 Platform_getConfig (Platform_Config * config)
220     GT_1trace (curTrace, GT_ENTER, "Platform_getConfig", config);
222     GT_assert (curTrace, (config != NULL));
224 #if !defined(SYSLINK_BUILD_OPTIMIZE)
225     if (config == NULL) {
226         GT_setFailureReason (curTrace,
227                              GT_4CLASS,
228                              "Platform_getConfig",
229                              Platform_E_INVALIDARG,
230                              "Argument of type (Platform_getConfig *) passed "
231                              "is null!");
232     }
233     else {
234 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
236         /* Get the gatepeterson default config */
237         MultiProc_getConfig (&config->multiProcConfig);
239         /* Get the PROCMGR default config */
240         ProcMgr_getConfig (&config->procMgrConfig);
242         /* Get the ElfLoader default config */
243         ElfLoader_getConfig (&config->elfLoaderConfig);
245         /* Get the HWSpinlock default config */
246         GateHWSpinlock_getConfig (&config->gateHWSpinlockConfig);
247 #if !defined(SYSLINK_BUILD_OPTIMIZE)
248     }
249 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
251     GT_0trace (curTrace, GT_LEAVE, "Platform_getConfig");
254 /*!
255  *  @brief      Function to override the default configuration values.
256  *
257  *  @param      config   Configuration values.
258  */
259 Int32
260 Platform_overrideConfig (Platform_Config * config, Ipc_Config * cfg)
262     Int32  status = Platform_S_SUCCESS;
263     char * pSL_PARAMS;
265     GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", config);
267     GT_assert (curTrace, (config != NULL));
269 #if !defined(SYSLINK_BUILD_OPTIMIZE)
270     if (config == NULL) {
271         /*! @retval Platform_E_INVALIDARG Argument of type
272          *  (Platform_Config *) passed is null*/
273         status = Platform_E_INVALIDARG;
274         GT_setFailureReason (curTrace,
275                              GT_4CLASS,
276                              "Platform_overrideConfig",
277                              status,
278                              "Argument of type (Platform_getConfig *) passed "
279                              "is null!");
280     }
281     else {
282 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
284         /* assign config->params - overriding with SL_PARAMS env var, if set */
285         pSL_PARAMS = getenv("SL_PARAMS");
286         if (pSL_PARAMS != NULL) {
287             GT_2trace(curTrace, GT_1CLASS, "Overriding SysLink_params \"%s\""
288                     " with SL_PARAMS \"%s\"\n", Syslink_Override_Params, pSL_PARAMS);
289             cfg->params = Memory_alloc(NULL, String_len(pSL_PARAMS), 0, NULL);
290             if (cfg->params) {
291                 String_cpy(cfg->params, pSL_PARAMS);
292             }
293         }
294         else {
295             cfg->params = Memory_alloc(NULL,
296                                        String_len(Syslink_Override_Params) + 1, 0,
297                                        NULL);
298             if (cfg->params) {
299                 String_cpy(cfg->params, Syslink_Override_Params);
300             }
301         }
303         _ProcMgr_saveParams(cfg->params, String_len(cfg->params));
305         /* Set the MultiProc config as defined in SystemCfg.c */
306         config->multiProcConfig = _MultiProc_cfg;
308         /* Override the MESSAGEQCOPY default config */
309         config->MQCopyConfig.intId[1] = 173; // 141 + 32
310         config->MQCopyConfig.intId[4] = 168; // 136 + 32
312 #if !defined(SYSLINK_BUILD_OPTIMIZE)
313     }
314 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
316     GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", status);
318     /*! @retval Platform_S_SUCCESS operation was successful */
319     return status;
322 /*!
323  *  @brief      Function to setup platform.
324  *              TBD: logic would change completely in the final system.
325  */
326 Int32
327 Platform_setup (Ipc_Config * cfg)
329     Int32             status = Platform_S_SUCCESS;
330     Platform_Config   _config;
331     Platform_Config * config;
332     VAYUIpcInt_Config VAYUcfg;
333     Memory_MapInfo    minfo;
335     Platform_getConfig (&_config);
336     config = &_config;
338     Platform_overrideConfig (config, cfg);
340     status = MultiProc_setup (&(config->multiProcConfig));
342 #if !defined(SYSLINK_BUILD_OPTIMIZE)
343     if (status < 0) {
344         GT_setFailureReason (curTrace,
345                              GT_4CLASS,
346                              "Platform_setup",
347                              status,
348                              "MultiProc_setup failed!");
349     }
350     else {
351 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
352             Platform_module->multiProcInitFlag = TRUE;
353 #if !defined(SYSLINK_BUILD_OPTIMIZE)
354     }
355 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
357 /* Initialize PROCMGR */
358     if (status >= 0) {
359         status = ProcMgr_setup (&(config->procMgrConfig));
360 #if !defined(SYSLINK_BUILD_OPTIMIZE)
361         if (status < 0) {
362             GT_setFailureReason (curTrace,
363                                  GT_4CLASS,
364                                  "Platform_setup",
365                                  status,
366                                  "ProcMgr_setup failed!");
367         }
368         else {
369 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
370             Platform_module->procMgrInitFlag = TRUE;
371 #if !defined(SYSLINK_BUILD_OPTIMIZE)
372         }
373 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
374     }
376     /* Initialize IpcInt required for VirtQueue/MessageQCopy. */
377     if (status >= 0) {
378         /* Do the IPC interrupts setup for the full platform (cfg is not used) */
379         VAYUIpcInt_setup (&VAYUcfg);
380         Platform_module->ipcIntInitFlag = TRUE;
381     }
384 /* Intialize MESSAGEQCOPY */
385     if (status >= 0) {
386         status = MessageQCopy_setup (&config->MQCopyConfig);
387 #if !defined(SYSLINK_BUILD_OPTIMIZE)
388         if (status < 0) {
389             GT_setFailureReason (curTrace,
390                                  GT_4CLASS,
391                                  "Platform_setup",
392                                  status,
393                                  "MessageQCopy_setup failed!");
394         }
395         else {
396 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
397             Platform_module->messageQCopyInitFlag = TRUE;
398 #if !defined(SYSLINK_BUILD_OPTIMIZE)
399         }
400 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
401     }
403 /* Intialize Elf loader */
404     if (status >= 0) {
405         status = ElfLoader_setup (&config->elfLoaderConfig);
406 #if !defined(SYSLINK_BUILD_OPTIMIZE)
407         if (status < 0) {
408             GT_setFailureReason (curTrace,
409                                  GT_4CLASS,
410                                  "Platform_setup",
411                                  status,
412                                  "ElfLoader_setup failed!");
413         }
414         else {
415 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
416             Platform_module->elfLoaderInitFlag = TRUE;
417 #if !defined(SYSLINK_BUILD_OPTIMIZE)
418         }
419 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
420     }
422     if (status >= 0) {
423         Memory_set (Platform_objects,
424                     0,
425                     (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
426     }
428     if (status >= 0) {
429         status = _Platform_setup (cfg);
430 #if !defined(SYSLINK_BUILD_OPTIMIZE)
431         if (status < 0) {
432             GT_setFailureReason (curTrace,
433                                  GT_4CLASS,
434                                  "Platform_setup",
435                                  status,
436                                  "_Platform_setup failed!");
437         }
438         else {
439 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
440             Platform_module->platformInitFlag = TRUE;
441 #if !defined(SYSLINK_BUILD_OPTIMIZE)
442         }
443 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
444     }
445     if (status >= 0) {
446         minfo.src  = HWSPINLOCK_BASE;
447         minfo.size = HWSPINLOCK_SIZE;
448         minfo.isCached = FALSE;
449         status = Memory_map (&minfo);
450         if (status < 0) {
451            GT_setFailureReason (curTrace,
452                                 GT_4CLASS,
453                                 "Platform_setup",
454                                 status,
455                                 "Memory_map failed!");
456         }
457         else {
458             Platform_module->gateHWSpinlockVAddr = (Ptr)minfo.dst;
459             config->gateHWSpinlockConfig.numLocks = 32;
460             config->gateHWSpinlockConfig.baseAddr = minfo.dst  + HWSPINLOCK_OFFSET;
461             status = GateHWSpinlock_setup (&config->gateHWSpinlockConfig);
462 #if !defined(SYSLINK_BUILD_OPTIMIZE)
463             if (status < 0) {
464                 GT_setFailureReason (curTrace,
465                                      GT_4CLASS,
466                                      "Platform_setup",
467                                      status,
468                                      "GateHWSpinlock_setup failed!");
469             }
470             else {
471 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
472                 status = GateHWSpinlock_start();
473                 if (status < 0) {
474                     GT_setFailureReason (curTrace,
475                                      GT_4CLASS,
476                                      "Platform_setup",
477                                      status,
478                                      "GateHWSpinlock_start failed!");
479                 }
480                 else {
481                     Platform_module->gateHWSpinlockInitFlag = TRUE;
482                 }
483 #if !defined(SYSLINK_BUILD_OPTIMIZE)
484             }
485 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
486         }
487     }
489     if (status < 0) {
490         Platform_destroy();
491     }
492     return status;
496 /*!
497  *  @brief      Function to destroy the System.
498  *
499  *  @sa         Platform_setup
500  */
501 Int32
502 Platform_destroy (void)
504     Int32  status = Platform_S_SUCCESS;
505     Memory_UnmapInfo minfo;
507     GT_0trace (curTrace, GT_ENTER, "Platform_destroy");
509     /* Finalize Platform-specific destroy */
510     if (Platform_module->platformInitFlag == TRUE) {
511         status = _Platform_destroy ();
512 #if !defined(SYSLINK_BUILD_OPTIMIZE)
513         if (status < 0) {
514             GT_setFailureReason (curTrace,
515                                  GT_4CLASS,
516                                  "Platform_destroy",
517                                  status,
518                                  "Platform_destroy failed!");
519         }
520         else {
521 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
522             Platform_module->platformInitFlag = FALSE;
523 #if !defined(SYSLINK_BUILD_OPTIMIZE)
524         }
525 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
526     }
528     /* Finalize elf loader */
529     if (Platform_module->elfLoaderInitFlag == TRUE) {
530         status = ElfLoader_destroy ();
531 #if !defined(SYSLINK_BUILD_OPTIMIZE)
532         if (status < 0) {
533             GT_setFailureReason (curTrace,
534                                  GT_4CLASS,
535                                  "Platform_destroy",
536                                  status,
537                                  "ElfLoader_destroy failed!");
538         }
539         else {
540 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
541             Platform_module->elfLoaderInitFlag = FALSE;
542 #if !defined(SYSLINK_BUILD_OPTIMIZE)
543         }
544 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
545     }
547     /* Finalize MESSAGEQCOPY */
548     if (Platform_module->messageQCopyInitFlag == TRUE) {
549         status = MessageQCopy_destroy ();
550 #if !defined(SYSLINK_BUILD_OPTIMIZE)
551         if (status < 0) {
552             GT_setFailureReason (curTrace,
553                                  GT_4CLASS,
554                                  "Platform_destroy",
555                                  status,
556                                  "MessageQCopy_destroy failed!");
557         }
558         else {
559 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
560             Platform_module->messageQCopyInitFlag = FALSE;
561 #if !defined(SYSLINK_BUILD_OPTIMIZE)
562         }
563 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
564     }
567     if (Platform_module->ipcIntInitFlag == TRUE) {
568         VAYUIpcInt_destroy ();
569         Platform_module->ipcIntInitFlag = FALSE;
570     }
572     /* Finalize PROCMGR */
573     if (Platform_module->procMgrInitFlag == TRUE) {
574         status = ProcMgr_destroy ();
575 #if !defined(SYSLINK_BUILD_OPTIMIZE)
576         if (status < 0) {
577             GT_setFailureReason (curTrace,
578                                  GT_4CLASS,
579                                  "Platform_destroy",
580                                  status,
581                                  "ProcMgr_destroy failed!");
582         }
583         else {
584 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
585             Platform_module->procMgrInitFlag = FALSE;
586 #if !defined(SYSLINK_BUILD_OPTIMIZE)
587         }
588 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
589     }
591     /* Finalize MultiProc */
592     if (Platform_module->multiProcInitFlag == TRUE) {
593         status = MultiProc_destroy ();
594 #if !defined(SYSLINK_BUILD_OPTIMIZE)
595     if (status < 0) {
596         GT_setFailureReason (curTrace,
597                              GT_4CLASS,
598                              "Platform_destroy",
599                              status,
600                              "MultiProc_destroy failed!");
601     }
602         else {
603 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
604             Platform_module->multiProcInitFlag = FALSE;
605 #if !defined(SYSLINK_BUILD_OPTIMIZE)
606         }
607 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
608     }
610     if (status >= 0) {
611         Memory_set (Platform_objects,
612                     0,
613                     (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
614     }
616     if (Platform_module->gateHWSpinlockInitFlag == TRUE) {
617         status = GateHWSpinlock_stop();
618         if (status < 0) {
619             GT_setFailureReason (curTrace,
620                                  GT_4CLASS,
621                                  "Platform_destroy",
622                                  status,
623                                  "GateHWSpinlock_stop failed!");
624         }
625         else {
626             status = GateHWSpinlock_destroy();
627 #if !defined(SYSLINK_BUILD_OPTIMIZE)
628             if (status < 0) {
629                 GT_setFailureReason (curTrace,
630                                  GT_4CLASS,
631                                  "Platform_destroy",
632                                  status,
633                                  "GateHWSpinlock_destroy failed!");
634             }
635             else {
636 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
637                 Platform_module->gateHWSpinlockInitFlag = FALSE;
638             }
639 #if !defined(SYSLINK_BUILD_OPTIMIZE)
640         }
641 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
642     }
644     if (Platform_module->gateHWSpinlockVAddr) {
645         minfo.addr = (UInt32)Platform_module->gateHWSpinlockVAddr;
646         minfo.size = HWSPINLOCK_SIZE;
647         minfo.isCached = FALSE;
648         status = Memory_unmap(&minfo);
649 #if !defined(SYSLINK_BUILD_OPTIMIZE)
650         if (status < 0) {
651             GT_setFailureReason (curTrace,
652                                  GT_4CLASS,
653                                  "Platform_destroy",
654                                  status,
655                                  "Memory_unmap failed!");
656         }
657 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
658         Platform_module->gateHWSpinlockVAddr = NULL;
659     }
661     GT_1trace (curTrace, GT_LEAVE, "Platform_destroy", status);
663     /*! @retval Platform_S_SUCCESS Operation successful */
664     return status;
667 /*
668  * union _Platform_setup_Local exists so that we don't waste stack or
669  * alloc'ed memory on storage for things that exist for just a few
670  * statements of the function _Platform_setup().  The *PROC_Params
671  * elements are large and variably sized, depending on the macro
672  * ProcMgr_MAX_MEMORY_REGIONS.
673  */
674 typedef union _Platform_setup_Local {
675     ProcMgr_Params          params;
676     VAYUDSPPROC_Config      dspProcConfig;
677     VAYUIPUCORE1PROC_Config videoProcConfig;
678     VAYUIPUCORE0PROC_Config vpssProcConfig;
679     VAYUDSPPWR_Config       dspPwrConfig;
680     VAYUIPUPWR_Config       videoPwrConfig;
681     VAYUIPUPWR_Config       vpssPwrConfig;
682     VAYUDSPPROC_Params      dspProcParams;
683     VAYUIPUCORE1PROC_Params videoProcParams;
684     VAYUIPUCORE0PROC_Params vpssProcParams;
685     VAYUDSPPWR_Params       dspPwrParams;
686     VAYUIPUPWR_Params       videoPwrParams;
687     VAYUIPUPWR_Params       vpssPwrParams;
688     ElfLoader_Params        elfLoaderParams;
689 } _Platform_setup_Local;
692 /*!
693  *  @brief      Function to setup platform.
694  *              TBD: logic would change completely in the final system.
695  */
696 Int32
697 _Platform_setup (Ipc_Config * cfg)
699     Int32                   status = Platform_S_SUCCESS;
700     _Platform_setup_Local   *lv;
701     UInt16                  procId;
702     Platform_Handle         handle;
704     GT_0trace (curTrace, GT_ENTER, "_Platform_setup");
706     lv = Memory_alloc(NULL, sizeof(_Platform_setup_Local), 0, NULL);
707     if (lv == NULL) {
708         status = Platform_E_FAIL;
709         GT_setFailureReason (curTrace,
710                                 GT_4CLASS,
711                                 "_Platform_setup",
712                                 status,
713                                 "Memory_alloc failed");
714         goto ret;
715     }
716     if (status >= 0) {
717         /* Get MultiProc ID by name. */
718         procId = MultiProc_getId ("IPU2");
720         handle = &Platform_objects [procId];
721         VAYUIPUCORE0PROC_getConfig (&lv->vpssProcConfig);
722         status = VAYUIPUCORE0PROC_setup (&lv->vpssProcConfig);
723         if (status < 0) {
724             GT_setFailureReason (curTrace,
725                                  GT_4CLASS,
726                                  "_Platform_setup",
727                                  status,
728                                  "VAYUIPUCORE0PROC_setup failed!");
729         }
730         else {
731             VAYUIPUPWR_getConfig (&lv->vpssPwrConfig);
732             status = VAYUIPUPWR_setup (&lv->vpssPwrConfig);
733             if (status < 0) {
734                 GT_setFailureReason (curTrace,
735                                      GT_4CLASS,
736                                      "_Platform_setup",
737                                      status,
738                                      "VAYUIPUPWR_setup failed!");
739             }
740         }
742         if (status >= 0) {
743             /* Create an instance of the Processor object for
744              * VAYUIPUCORE0 */
745             VAYUIPUCORE0PROC_Params_init (NULL, &lv->vpssProcParams);
746             handle->sHandles.ipu1.pHandle = VAYUIPUCORE0PROC_create (procId,
747                                                          &lv->vpssProcParams);
749             /* Create an instance of the ELF Loader object */
750             ElfLoader_Params_init (NULL, &lv->elfLoaderParams);
751             handle->sHandles.ipu1.ldrHandle = ElfLoader_create (procId,
752                                                         &lv->elfLoaderParams);
754             /* Create an instance of the PwrMgr object for VAYUIPUCORE0 */
755             VAYUIPUPWR_Params_init (&lv->vpssPwrParams);
756             handle->sHandles.ipu1.pwrHandle = VAYUIPUPWR_create (
757                                                            procId,
758                                                            &lv->vpssPwrParams);
760             if (handle->sHandles.ipu1.pHandle == NULL) {
761                 status = Platform_E_FAIL;
762                 GT_setFailureReason (curTrace,
763                                      GT_4CLASS,
764                                      "_Platform_setup",
765                                      status,
766                                      "VAYUIPUCORE0PROC_create failed!");
767             }
768             else if (handle->sHandles.ipu1.ldrHandle ==  NULL) {
769                 status = Platform_E_FAIL;
770                 GT_setFailureReason (curTrace,
771                                      GT_4CLASS,
772                                      "_Platform_setup",
773                                      status,
774                                      "Failed to create loader instance!");
775             }
776             else if (handle->sHandles.ipu1.pwrHandle ==  NULL) {
777                 status = Platform_E_FAIL;
778                 GT_setFailureReason (curTrace,
779                                      GT_4CLASS,
780                                      "_Platform_setup",
781                                      status,
782                                      "VAYUIPUPWR_create failed!");
783             }
784             else {
785                 /* Initialize parameters */
786                 ProcMgr_Params_init (NULL, &lv->params);
787                 lv->params.procHandle = handle->sHandles.ipu1.pHandle;
788                 lv->params.loaderHandle = handle->sHandles.ipu1.ldrHandle;
789                 lv->params.pwrHandle = handle->sHandles.ipu1.pwrHandle;
790                 handle->pmHandle = ProcMgr_create (procId, &lv->params);
791                 if (handle->pmHandle == NULL) {
792                     status = Platform_E_FAIL;
793                     GT_setFailureReason (curTrace,
794                                          GT_4CLASS,
795                                          "_Platform_setup",
796                                          status,
797                                          "ProcMgr_create failed!");
798                 }
799             }
800         }
801     }
803     if (status >= 0) {
804         /* Get MultiProc ID by name. */
805         procId = MultiProc_getId ("DSP1");
807         handle = &Platform_objects [procId];
808         VAYUDSPPROC_getConfig (&lv->dspProcConfig);
809         status = VAYUDSPPROC_setup (&lv->dspProcConfig);
810         if (status < 0) {
811             GT_setFailureReason (curTrace,
812                                  GT_4CLASS,
813                                  "_Platform_setup",
814                                  status,
815                                  "VAYUDSPPROC_setup failed!");
816         }
817         else {
818             VAYUDSPPWR_getConfig (&lv->dspPwrConfig);
819             status = VAYUDSPPWR_setup (&lv->dspPwrConfig);
820             if (status < 0) {
821                 GT_setFailureReason (curTrace,
822                                      GT_4CLASS,
823                                      "_Platform_setup",
824                                      status,
825                                      "VAYUDSPPWR_setup failed!");
826             }
827         }
829         if (status >= 0) {
830             /* Create an instance of the Processor object for
831              * VAYUDSP */
832             VAYUDSPPROC_Params_init (NULL, &lv->dspProcParams);
833             handle->sHandles.dsp0.pHandle = VAYUDSPPROC_create (procId,
834                                                               &lv->dspProcParams);
836             /* Create an instance of the ELF Loader object */
837             ElfLoader_Params_init (NULL, &lv->elfLoaderParams);
838             handle->sHandles.dsp0.ldrHandle =
839                                            ElfLoader_create (procId,
840                                                              &lv->elfLoaderParams);
841             /* Create an instance of the PwrMgr object for VAYUDSP */
842             VAYUDSPPWR_Params_init (&lv->dspPwrParams);
843             handle->sHandles.dsp0.pwrHandle = VAYUDSPPWR_create (procId,
844                                                     &lv->dspPwrParams);
846             if (handle->sHandles.dsp0.pHandle == NULL) {
847                 status = Platform_E_FAIL;
848                 GT_setFailureReason (curTrace,
849                                      GT_4CLASS,
850                                      "_Platform_setup",
851                                      status,
852                                      "VAYUDSPPROC_create failed!");
853             }
854             else if (handle->sHandles.dsp0.ldrHandle ==  NULL) {
855                 status = Platform_E_FAIL;
856                 GT_setFailureReason (curTrace,
857                                      GT_4CLASS,
858                                      "_Platform_setup",
859                                      status,
860                                      "Failed to create loader instance!");
861             }
862             else if (handle->sHandles.dsp0.pwrHandle ==  NULL) {
863                 status = Platform_E_FAIL;
864                 GT_setFailureReason (curTrace,
865                                      GT_4CLASS,
866                                      "_Platform_setup",
867                                      status,
868                                      "VAYUDSPPWR_create failed!");
869             }
870             else {
871                 /* Initialize parameters */
872                 ProcMgr_Params_init (NULL, &lv->params);
873                 lv->params.procHandle = handle->sHandles.dsp0.pHandle;
874                 lv->params.loaderHandle = handle->sHandles.dsp0.ldrHandle;
875                 lv->params.pwrHandle = handle->sHandles.dsp0.pwrHandle;
876                 handle->pmHandle = ProcMgr_create (procId, &lv->params);
877                 if (handle->pmHandle == NULL) {
878                     status = Platform_E_FAIL;
879                     GT_setFailureReason (curTrace,
880                                          GT_4CLASS,
881                                          "_Platform_setup",
882                                          status,
883                                          "ProcMgr_create failed!");
884                 }
885             }
886         }
887     }
889     Memory_free(NULL, lv, sizeof(_Platform_setup_Local));
891 ret:
892     GT_1trace (curTrace, GT_LEAVE, "_Platform_setup", status);
894     /*! @retval Platform_S_SUCCESS operation was successful */
895     return status;
899 /*!
900  *  @brief      Function to setup platform.
901  *              TBD: logic would change completely in the final system.
902  */
903 Int32
904 _Platform_destroy (void)
906     Int32           status    = Platform_S_SUCCESS;
907     Int32           tmpStatus = Platform_S_SUCCESS;
908     Platform_Handle handle;
910     GT_0trace (curTrace, GT_ENTER, "_Platform_destroy");
912     /* ------------------------- DSP cleanup -------------------------------- */
913     handle = &Platform_objects [MultiProc_getId ("DSP1")];
914     if (handle->pmHandle != NULL) {
915         status = ProcMgr_delete (&handle->pmHandle);
916         GT_assert (curTrace, (status >= 0));
917 #if !defined(SYSLINK_BUILD_OPTIMIZE)
918         if (status < 0) {
919             GT_setFailureReason (curTrace,
920                                  GT_4CLASS,
921                                  "_Platform_destroy",
922                                  status,
923                                  "ProcMgr_delete failed!");
924         }
925 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
926     }
928     /* Delete the Processor, Loader and PwrMgr instances */
929     if (handle->sHandles.dsp0.pwrHandle != NULL) {
930         tmpStatus = VAYUDSPPWR_delete (&handle->sHandles.dsp0.pwrHandle);
931         GT_assert (curTrace, (tmpStatus >= 0));
932         if ((status >= 0) && (tmpStatus < 0)) {
933             status = tmpStatus;
934 #if !defined(SYSLINK_BUILD_OPTIMIZE)
935             GT_setFailureReason (curTrace,
936                                  GT_4CLASS,
937                                  "_Platform_destroy",
938                                  status,
939                                  "VAYUDSPPWR_delete failed!");
940 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
941         }
942     }
944     if (handle->sHandles.dsp0.ldrHandle != NULL) {
945         tmpStatus = ElfLoader_delete (&handle->sHandles.dsp0.ldrHandle);
946         GT_assert (curTrace, (tmpStatus >= 0));
947         if ((status >= 0) && (tmpStatus < 0)) {
948             status = tmpStatus;
949 #if !defined(SYSLINK_BUILD_OPTIMIZE)
950             GT_setFailureReason (curTrace,
951                                  GT_4CLASS,
952                                  "_Platform_destroy",
953                                  status,
954                                  "Failed to delete loader instance!");
955 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
956         }
957     }
959     if (handle->sHandles.dsp0.pHandle != NULL) {
960         tmpStatus = VAYUDSPPROC_delete (&handle->sHandles.dsp0.pHandle);
961         GT_assert (curTrace, (tmpStatus >= 0));
962         if ((status >= 0) && (tmpStatus < 0)) {
963             status = tmpStatus;
964 #if !defined(SYSLINK_BUILD_OPTIMIZE)
965             GT_setFailureReason (curTrace,
966                                  GT_4CLASS,
967                                  "_Platform_destroy",
968                                  status,
969                                  "VAYUDSPPROC_delete failed!");
970 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
971         }
972     }
974     tmpStatus = VAYUDSPPWR_destroy ();
975     GT_assert (curTrace, (tmpStatus >= 0));
976     if ((status >= 0) && (tmpStatus < 0)) {
977         status = tmpStatus;
978 #if !defined(SYSLINK_BUILD_OPTIMIZE)
979         GT_setFailureReason (curTrace,
980                              GT_4CLASS,
981                              "_Platform_destroy",
982                              status,
983                              "VAYUDSPPWR_destroy failed!");
984 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
985     }
987     tmpStatus = VAYUDSPPROC_destroy ();
988     GT_assert (curTrace, (tmpStatus >= 0));
989     if ((status >= 0) && (tmpStatus < 0)) {
990         status = tmpStatus;
991 #if !defined(SYSLINK_BUILD_OPTIMIZE)
992         GT_setFailureReason (curTrace,
993                              GT_4CLASS,
994                              "_Platform_destroy",
995                              status,
996                              "VAYUDSPPROC_destroy failed!");
997 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
998     }
1000     /* ------------------------- IPU1 cleanup ------------------------------- */
1001     handle = &Platform_objects [MultiProc_getId ("IPU2")];
1002     if (handle->pmHandle != NULL) {
1003         tmpStatus = ProcMgr_delete (&handle->pmHandle);
1004         GT_assert (curTrace, (tmpStatus >= 0));
1005         if ((status >= 0) && (tmpStatus < 0)) {
1006             status = tmpStatus;
1007 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1008             GT_setFailureReason (curTrace,
1009                                  GT_4CLASS,
1010                                  "_Platform_destroy",
1011                                  status,
1012                                  "ProcMgr_delete failed!");
1013 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1014         }
1015     }
1017     /* Delete the Processor, Loader and PwrMgr instances */
1018     if (handle->sHandles.ipu1.pwrHandle != NULL) {
1019         tmpStatus = VAYUIPUPWR_delete (&handle->sHandles.ipu1.pwrHandle);
1020         GT_assert (curTrace, (tmpStatus >= 0));
1021         if ((status >= 0) && (tmpStatus < 0)) {
1022             status = tmpStatus;
1023 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1024             GT_setFailureReason (curTrace,
1025                                  GT_4CLASS,
1026                                  "_Platform_destroy",
1027                                  status,
1028                                  "VAYUIPUPWR_delete failed!");
1029 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1030         }
1031     }
1033     if (handle->sHandles.ipu1.ldrHandle != NULL) {
1034         tmpStatus = ElfLoader_delete (&handle->sHandles.ipu1.ldrHandle);
1035         GT_assert (curTrace, (tmpStatus >= 0));
1036         if ((status >= 0) && (tmpStatus < 0)) {
1037             status = tmpStatus;
1038 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1039             GT_setFailureReason (curTrace,
1040                                  GT_4CLASS,
1041                                  "_Platform_destroy",
1042                                  status,
1043                                  "Failed to delete loader instance!");
1044 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1045         }
1046     }
1048     if (handle->sHandles.ipu1.pHandle != NULL) {
1049         tmpStatus = VAYUIPUCORE0PROC_delete (&handle->sHandles.ipu1.pHandle);
1050         GT_assert (curTrace, (tmpStatus >= 0));
1051         if ((status >= 0) && (tmpStatus < 0)) {
1052             status = tmpStatus;
1053 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1054             GT_setFailureReason (curTrace,
1055                                  GT_4CLASS,
1056                                  "_Platform_destroy",
1057                                  status,
1058                                  "VAYUIPUCORE0PROC_delete failed!");
1059 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1060         }
1061     }
1063     tmpStatus = VAYUIPUPWR_destroy ();
1064     GT_assert (curTrace, (tmpStatus >= 0));
1065     if ((status >= 0) && (tmpStatus < 0)) {
1066         status = tmpStatus;
1067 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1068         GT_setFailureReason (curTrace,
1069                              GT_4CLASS,
1070                              "_Platform_destroy",
1071                              status,
1072                              "VAYUIPUPWR_destroy failed!");
1073 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1074     }
1076     tmpStatus = VAYUIPUCORE0PROC_destroy ();
1077     GT_assert (curTrace, (tmpStatus >= 0));
1078     if ((status >= 0) && (tmpStatus < 0)) {
1079         status = tmpStatus;
1080 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1081         GT_setFailureReason (curTrace,
1082                              GT_4CLASS,
1083                              "_Platform_destroy",
1084                              status,
1085                              "VAYUIPUCORE0PROC_destroy failed!");
1086 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1087     }
1089     GT_1trace (curTrace, GT_LEAVE, "_Platform_destroy", status);
1091     /*! @retval Platform_S_SUCCESS operation was successful */
1092     return status;
1096 #if defined (__cplusplus)
1098 #endif