946d91a6b7176085f7f00fe10b3494ac0a7c47bd
1 /*
2 * @file Platform.c
3 *
4 * @brief Implementation of Platform initialization logic.
5 *
6 *
7 * ============================================================================
8 *
9 * Copyright (c) 2013-2014, 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>
87 #include <gptimers.h>
89 #if defined (__cplusplus)
90 extern "C" {
91 #endif
94 /** ============================================================================
95 * Macros.
96 * ============================================================================
97 */
98 /* Hardware spinlocks info */
99 #define HWSPINLOCK_BASE 0x4A0F6000
100 #define HWSPINLOCK_SIZE 0x1000
101 #define HWSPINLOCK_OFFSET 0x800
103 /** ============================================================================
104 * Application specific configuration, please change these value according to
105 * your application's need.
106 * ============================================================================
107 */
108 /*!
109 * @brief Structure defining config parameters for overall System.
110 */
111 typedef struct Platform_Config {
112 MultiProc_Config multiProcConfig;
113 /*!< Multiproc config parameter */
115 MessageQCopy_Config MQCopyConfig;
116 /*!< MessageQCopy config parameter */
118 ProcMgr_Config procMgrConfig;
119 /*!< Processor manager config parameter */
121 ElfLoader_Config elfLoaderConfig;
122 /*!< Elf loader config parameter */
124 GateHWSpinlock_Config gateHWSpinlockConfig;
125 /*!< GateHWSpinlock config parameter */
126 } Platform_Config;
128 /*! @brief structure for platform instance */
129 typedef struct Platform_Object {
130 /*!< Flag to indicate platform initialization status */
131 ProcMgr_Handle pmHandle;
132 /*!< Handle to the ProcMgr instance used */
133 union {
134 struct {
135 VAYUDSPPROC_Handle pHandle;
136 /*!< Handle to the Processor instance used */
137 VAYUDSPPWR_Handle pwrHandle;
138 /*!< Handle to the PwrMgr instance used */
139 ElfLoader_Handle ldrHandle;
140 /*!< Handle to the Loader instance used */
141 } dsp0;
142 struct {
143 VAYUIPUCORE0PROC_Handle pHandle;
144 /*!< Handle to the Processor instance used */
145 VAYUIPUPWR_Handle pwrHandle;
146 /*!< Handle to the PwrMgr instance used */
147 ElfLoader_Handle ldrHandle;
148 /*!< Handle to the Loader instance used */
149 } ipu;
150 } sHandles;
151 /*!< Slave specific handles */
152 } Platform_Object, *Platform_Handle;
155 /*! @brief structure for platform instance */
156 typedef struct Platform_Module_State {
157 Bool multiProcInitFlag;
158 /*!< MultiProc Initialize flag */
159 Bool messageQCopyInitFlag;
160 /*!< MessageQCopy Initialize flag */
161 Bool procMgrInitFlag;
162 /*!< Processor manager Initialize flag */
163 Bool elfLoaderInitFlag;
164 /*!< Elf loader Initialize flag */
165 Bool ipcIntInitFlag;
166 /*!< IpcInt Initialize flag */
167 Bool platformInitFlag;
168 /*!< Flag to indicate platform initialization status */
169 Bool gateHWSpinlockInitFlag;
170 /*!< GateHWSpinlock Initialize flag */
171 Ptr gateHWSpinlockVAddr;
172 /*!< GateHWSpinlock Virtual Address */
173 } Platform_Module_State;
176 /* =============================================================================
177 * GLOBALS
178 * =============================================================================
179 */
180 static Platform_Object Platform_objects [MultiProc_MAXPROCESSORS];
181 static Platform_Module_State Platform_Module_state;
182 static Platform_Module_State * Platform_module = &Platform_Module_state;
184 Int32 _Platform_setup (Ipc_Config * cfg);
185 Int32 _Platform_destroy (void);
187 extern String ProcMgr_sysLinkCfgParams;
189 String Syslink_Override_Params = "ProcMgr.proc[DSP1].mmuEnable=TRUE;"
190 "ProcMgr.proc[DSP1].carveoutAddr0=0xBA300000;"
191 "ProcMgr.proc[DSP1].carveoutSize0=0x5A00000;"
192 "ProcMgr.proc[IPU1].mmuEnable=TRUE;"
193 "ProcMgr.proc[IPU1].carveoutAddr0=0xBA300000;"
194 "ProcMgr.proc[IPU1].carveoutSize0=0x5A00000;"
195 "ProcMgr.proc[IPU2].mmuEnable=TRUE;"
196 "ProcMgr.proc[IPU2].carveoutAddr0=0xBA300000;"
197 "ProcMgr.proc[IPU2].carveoutSize0=0x5A00000;";
199 /** ============================================================================
200 * APIs.
201 * ============================================================================
202 */
203 /* Function to read slave memory */
204 Int32
205 _Platform_readSlaveMemory (UInt16 procId,
206 UInt32 addr,
207 Ptr value,
208 UInt32 * numBytes);
210 /* Function to write slave memory */
211 Int32
212 _Platform_writeSlaveMemory (UInt16 procId,
213 UInt32 addr,
214 Ptr value,
215 UInt32 * numBytes);
216 /*!
217 * @brief Function to get the default values for configurations.
218 *
219 * @param config Configuration values.
220 */
221 Void
222 Platform_getConfig (Platform_Config * config)
223 {
224 GT_1trace (curTrace, GT_ENTER, "Platform_getConfig", config);
226 GT_assert (curTrace, (config != NULL));
228 #if !defined(SYSLINK_BUILD_OPTIMIZE)
229 if (config == NULL) {
230 GT_setFailureReason (curTrace,
231 GT_4CLASS,
232 "Platform_getConfig",
233 Platform_E_INVALIDARG,
234 "Argument of type (Platform_getConfig *) passed "
235 "is null!");
236 }
237 else {
238 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
240 /* Get the gatepeterson default config */
241 MultiProc_getConfig (&config->multiProcConfig);
243 /* Get the PROCMGR default config */
244 ProcMgr_getConfig (&config->procMgrConfig);
246 /* Get the ElfLoader default config */
247 ElfLoader_getConfig (&config->elfLoaderConfig);
249 /* Get the HWSpinlock default config */
250 GateHWSpinlock_getConfig (&config->gateHWSpinlockConfig);
251 #if !defined(SYSLINK_BUILD_OPTIMIZE)
252 }
253 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
255 GT_0trace (curTrace, GT_LEAVE, "Platform_getConfig");
256 }
258 /*!
259 * @brief Function to override the default configuration values.
260 *
261 * @param config Configuration values.
262 */
263 Int32
264 Platform_overrideConfig (Platform_Config * config, Ipc_Config * cfg)
265 {
266 Int32 status = Platform_S_SUCCESS;
267 char * pSL_PARAMS;
269 GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", config);
271 GT_assert (curTrace, (config != NULL));
273 #if !defined(SYSLINK_BUILD_OPTIMIZE)
274 if (config == NULL) {
275 /*! @retval Platform_E_INVALIDARG Argument of type
276 * (Platform_Config *) passed is null*/
277 status = Platform_E_INVALIDARG;
278 GT_setFailureReason (curTrace,
279 GT_4CLASS,
280 "Platform_overrideConfig",
281 status,
282 "Argument of type (Platform_getConfig *) passed "
283 "is null!");
284 }
285 else {
286 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
288 /* assign config->params - overriding with SL_PARAMS env var, if set */
289 pSL_PARAMS = getenv("SL_PARAMS");
290 if (pSL_PARAMS != NULL) {
291 GT_2trace(curTrace, GT_1CLASS, "Overriding SysLink_params \"%s\""
292 " with SL_PARAMS \"%s\"\n", Syslink_Override_Params, pSL_PARAMS);
293 cfg->params = Memory_alloc(NULL, String_len(pSL_PARAMS), 0, NULL);
294 if (cfg->params) {
295 String_cpy(cfg->params, pSL_PARAMS);
296 }
297 }
298 else {
299 cfg->params = Memory_alloc(NULL,
300 String_len(Syslink_Override_Params) + 1, 0,
301 NULL);
302 if (cfg->params) {
303 String_cpy(cfg->params, Syslink_Override_Params);
304 }
305 }
307 _ProcMgr_saveParams(cfg->params, String_len(cfg->params));
309 /* Set the MultiProc config as defined in SystemCfg.c */
310 config->multiProcConfig = _MultiProc_cfg;
312 /* Override the MESSAGEQCOPY default config */
313 config->MQCopyConfig.intId[1] = 173; // 141 + 32
314 config->MQCopyConfig.intId[2] = 168; // 136 + 32
315 config->MQCopyConfig.intId[4] = 168; // 136 + 32
317 #if !defined(SYSLINK_BUILD_OPTIMIZE)
318 }
319 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
321 GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", status);
323 /*! @retval Platform_S_SUCCESS operation was successful */
324 return status;
325 }
327 /*!
328 * @brief Function to setup platform.
329 * TBD: logic would change completely in the final system.
330 */
331 Int32
332 Platform_setup (Ipc_Config * cfg)
333 {
334 Int32 status = Platform_S_SUCCESS;
335 Platform_Config _config;
336 Platform_Config * config;
337 VAYUIpcInt_Config VAYUcfg;
338 Memory_MapInfo minfo;
340 Platform_getConfig (&_config);
341 config = &_config;
343 Platform_overrideConfig (config, cfg);
345 status = MultiProc_setup (&(config->multiProcConfig));
347 #if !defined(SYSLINK_BUILD_OPTIMIZE)
348 if (status < 0) {
349 GT_setFailureReason (curTrace,
350 GT_4CLASS,
351 "Platform_setup",
352 status,
353 "MultiProc_setup failed!");
354 }
355 else {
356 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
357 Platform_module->multiProcInitFlag = TRUE;
358 #if !defined(SYSLINK_BUILD_OPTIMIZE)
359 }
360 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
362 /* Initialize PROCMGR */
363 if (status >= 0) {
364 status = ProcMgr_setup (&(config->procMgrConfig));
365 #if !defined(SYSLINK_BUILD_OPTIMIZE)
366 if (status < 0) {
367 GT_setFailureReason (curTrace,
368 GT_4CLASS,
369 "Platform_setup",
370 status,
371 "ProcMgr_setup failed!");
372 }
373 else {
374 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
375 Platform_module->procMgrInitFlag = TRUE;
376 #if !defined(SYSLINK_BUILD_OPTIMIZE)
377 }
378 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
379 }
381 /* Initialize IpcInt required for VirtQueue/MessageQCopy. */
382 if (status >= 0) {
383 /* Do the IPC interrupts setup for the full platform (cfg is not used) */
384 VAYUIpcInt_setup (&VAYUcfg);
385 Platform_module->ipcIntInitFlag = TRUE;
386 }
389 /* Intialize MESSAGEQCOPY */
390 if (status >= 0) {
391 status = MessageQCopy_setup (&config->MQCopyConfig);
392 #if !defined(SYSLINK_BUILD_OPTIMIZE)
393 if (status < 0) {
394 GT_setFailureReason (curTrace,
395 GT_4CLASS,
396 "Platform_setup",
397 status,
398 "MessageQCopy_setup failed!");
399 }
400 else {
401 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
402 Platform_module->messageQCopyInitFlag = TRUE;
403 #if !defined(SYSLINK_BUILD_OPTIMIZE)
404 }
405 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
406 }
408 /* Intialize Elf loader */
409 if (status >= 0) {
410 status = ElfLoader_setup (&config->elfLoaderConfig);
411 #if !defined(SYSLINK_BUILD_OPTIMIZE)
412 if (status < 0) {
413 GT_setFailureReason (curTrace,
414 GT_4CLASS,
415 "Platform_setup",
416 status,
417 "ElfLoader_setup failed!");
418 }
419 else {
420 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
421 Platform_module->elfLoaderInitFlag = TRUE;
422 #if !defined(SYSLINK_BUILD_OPTIMIZE)
423 }
424 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
425 }
427 if (status >= 0) {
428 Memory_set (Platform_objects,
429 0,
430 (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
431 }
433 if (status >= 0) {
434 status = _Platform_setup (cfg);
435 #if !defined(SYSLINK_BUILD_OPTIMIZE)
436 if (status < 0) {
437 GT_setFailureReason (curTrace,
438 GT_4CLASS,
439 "Platform_setup",
440 status,
441 "_Platform_setup failed!");
442 }
443 else {
444 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
445 Platform_module->platformInitFlag = TRUE;
446 #if !defined(SYSLINK_BUILD_OPTIMIZE)
447 }
448 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
449 }
450 if (status >= 0) {
451 minfo.src = HWSPINLOCK_BASE;
452 minfo.size = HWSPINLOCK_SIZE;
453 minfo.isCached = FALSE;
454 status = Memory_map (&minfo);
455 if (status < 0) {
456 GT_setFailureReason (curTrace,
457 GT_4CLASS,
458 "Platform_setup",
459 status,
460 "Memory_map failed!");
461 }
462 else {
463 Platform_module->gateHWSpinlockVAddr = (Ptr)minfo.dst;
464 config->gateHWSpinlockConfig.numLocks = 32;
465 config->gateHWSpinlockConfig.baseAddr = minfo.dst + HWSPINLOCK_OFFSET;
466 status = GateHWSpinlock_setup (&config->gateHWSpinlockConfig);
467 #if !defined(SYSLINK_BUILD_OPTIMIZE)
468 if (status < 0) {
469 GT_setFailureReason (curTrace,
470 GT_4CLASS,
471 "Platform_setup",
472 status,
473 "GateHWSpinlock_setup failed!");
474 }
475 else {
476 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
477 status = GateHWSpinlock_start();
478 if (status < 0) {
479 GT_setFailureReason (curTrace,
480 GT_4CLASS,
481 "Platform_setup",
482 status,
483 "GateHWSpinlock_start failed!");
484 }
485 else {
486 Platform_module->gateHWSpinlockInitFlag = TRUE;
487 }
488 #if !defined(SYSLINK_BUILD_OPTIMIZE)
489 }
490 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
491 }
492 }
494 /* Enable GP timers */
495 if (status >= 0) {
496 status = gpt_setup();
497 if (status < 0) {
498 GT_setFailureReason(curTrace, GT_4CLASS, "Platform_setup",
499 status, "gpt_setup failed!");
500 }
501 }
503 if (status < 0) {
504 Platform_destroy();
505 }
506 return status;
507 }
510 /*!
511 * @brief Function to destroy the System.
512 *
513 * @sa Platform_setup
514 */
515 Int32
516 Platform_destroy (void)
517 {
518 Int32 status = Platform_S_SUCCESS;
519 Memory_UnmapInfo minfo;
521 GT_0trace (curTrace, GT_ENTER, "Platform_destroy");
523 /* Finalize Platform-specific destroy */
524 if (Platform_module->platformInitFlag == TRUE) {
525 status = _Platform_destroy ();
526 #if !defined(SYSLINK_BUILD_OPTIMIZE)
527 if (status < 0) {
528 GT_setFailureReason (curTrace,
529 GT_4CLASS,
530 "Platform_destroy",
531 status,
532 "Platform_destroy failed!");
533 }
534 else {
535 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
536 Platform_module->platformInitFlag = FALSE;
537 #if !defined(SYSLINK_BUILD_OPTIMIZE)
538 }
539 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
540 }
542 /* disable GP timers */
543 gpt_destroy();
545 /* Finalize elf loader */
546 if (Platform_module->elfLoaderInitFlag == TRUE) {
547 status = ElfLoader_destroy ();
548 #if !defined(SYSLINK_BUILD_OPTIMIZE)
549 if (status < 0) {
550 GT_setFailureReason (curTrace,
551 GT_4CLASS,
552 "Platform_destroy",
553 status,
554 "ElfLoader_destroy failed!");
555 }
556 else {
557 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
558 Platform_module->elfLoaderInitFlag = FALSE;
559 #if !defined(SYSLINK_BUILD_OPTIMIZE)
560 }
561 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
562 }
564 /* Finalize MESSAGEQCOPY */
565 if (Platform_module->messageQCopyInitFlag == TRUE) {
566 status = MessageQCopy_destroy ();
567 #if !defined(SYSLINK_BUILD_OPTIMIZE)
568 if (status < 0) {
569 GT_setFailureReason (curTrace,
570 GT_4CLASS,
571 "Platform_destroy",
572 status,
573 "MessageQCopy_destroy failed!");
574 }
575 else {
576 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
577 Platform_module->messageQCopyInitFlag = FALSE;
578 #if !defined(SYSLINK_BUILD_OPTIMIZE)
579 }
580 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
581 }
584 if (Platform_module->ipcIntInitFlag == TRUE) {
585 VAYUIpcInt_destroy ();
586 Platform_module->ipcIntInitFlag = FALSE;
587 }
589 /* Finalize PROCMGR */
590 if (Platform_module->procMgrInitFlag == TRUE) {
591 status = ProcMgr_destroy ();
592 #if !defined(SYSLINK_BUILD_OPTIMIZE)
593 if (status < 0) {
594 GT_setFailureReason (curTrace,
595 GT_4CLASS,
596 "Platform_destroy",
597 status,
598 "ProcMgr_destroy failed!");
599 }
600 else {
601 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
602 Platform_module->procMgrInitFlag = FALSE;
603 #if !defined(SYSLINK_BUILD_OPTIMIZE)
604 }
605 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
606 }
608 /* Finalize MultiProc */
609 if (Platform_module->multiProcInitFlag == TRUE) {
610 status = MultiProc_destroy ();
611 #if !defined(SYSLINK_BUILD_OPTIMIZE)
612 if (status < 0) {
613 GT_setFailureReason (curTrace,
614 GT_4CLASS,
615 "Platform_destroy",
616 status,
617 "MultiProc_destroy failed!");
618 }
619 else {
620 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
621 Platform_module->multiProcInitFlag = FALSE;
622 #if !defined(SYSLINK_BUILD_OPTIMIZE)
623 }
624 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
625 }
627 if (status >= 0) {
628 Memory_set (Platform_objects,
629 0,
630 (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
631 }
633 if (Platform_module->gateHWSpinlockInitFlag == TRUE) {
634 status = GateHWSpinlock_stop();
635 if (status < 0) {
636 GT_setFailureReason (curTrace,
637 GT_4CLASS,
638 "Platform_destroy",
639 status,
640 "GateHWSpinlock_stop failed!");
641 }
642 else {
643 status = GateHWSpinlock_destroy();
644 #if !defined(SYSLINK_BUILD_OPTIMIZE)
645 if (status < 0) {
646 GT_setFailureReason (curTrace,
647 GT_4CLASS,
648 "Platform_destroy",
649 status,
650 "GateHWSpinlock_destroy failed!");
651 }
652 else {
653 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
654 Platform_module->gateHWSpinlockInitFlag = FALSE;
655 }
656 #if !defined(SYSLINK_BUILD_OPTIMIZE)
657 }
658 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
659 }
661 if (Platform_module->gateHWSpinlockVAddr) {
662 minfo.addr = (UInt32)Platform_module->gateHWSpinlockVAddr;
663 minfo.size = HWSPINLOCK_SIZE;
664 minfo.isCached = FALSE;
665 status = Memory_unmap(&minfo);
666 #if !defined(SYSLINK_BUILD_OPTIMIZE)
667 if (status < 0) {
668 GT_setFailureReason (curTrace,
669 GT_4CLASS,
670 "Platform_destroy",
671 status,
672 "Memory_unmap failed!");
673 }
674 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
675 Platform_module->gateHWSpinlockVAddr = NULL;
676 }
678 GT_1trace (curTrace, GT_LEAVE, "Platform_destroy", status);
680 /*! @retval Platform_S_SUCCESS Operation successful */
681 return status;
682 }
684 /*
685 * union _Platform_setup_Local exists so that we don't waste stack or
686 * alloc'ed memory on storage for things that exist for just a few
687 * statements of the function _Platform_setup(). The *PROC_Params
688 * elements are large and variably sized, depending on the macro
689 * ProcMgr_MAX_MEMORY_REGIONS.
690 */
691 typedef union _Platform_setup_Local {
692 ProcMgr_Params params;
693 VAYUDSPPROC_Config dspProcConfig;
694 VAYUIPUCORE0PROC_Config ipuProcConfig;
695 VAYUDSPPWR_Config dspPwrConfig;
696 VAYUIPUPWR_Config ipuPwrConfig;
697 VAYUDSPPROC_Params dspProcParams;
698 VAYUIPUCORE0PROC_Params ipuProcParams;
699 VAYUDSPPWR_Params dspPwrParams;
700 VAYUIPUPWR_Params ipuPwrParams;
701 ElfLoader_Params elfLoaderParams;
702 } _Platform_setup_Local;
705 /*!
706 * @brief Function to setup platform.
707 * TBD: logic would change completely in the final system.
708 */
709 Int32
710 _Platform_setup (Ipc_Config * cfg)
711 {
712 Int32 status = Platform_S_SUCCESS;
713 _Platform_setup_Local *lv;
714 UInt16 procId;
715 Platform_Handle handle;
717 GT_0trace (curTrace, GT_ENTER, "_Platform_setup");
719 lv = Memory_alloc(NULL, sizeof(_Platform_setup_Local), 0, NULL);
720 if (lv == NULL) {
721 status = Platform_E_FAIL;
722 GT_setFailureReason (curTrace,
723 GT_4CLASS,
724 "_Platform_setup",
725 status,
726 "Memory_alloc failed");
727 goto ret;
728 }
729 if (status >= 0) {
730 /* Get MultiProc ID by name. */
731 procId = MultiProc_getId ("IPU1");
733 handle = &Platform_objects [procId];
734 VAYUIPUCORE0PROC_getConfig (&lv->ipuProcConfig);
735 status = VAYUIPUCORE0PROC_setup (&lv->ipuProcConfig);
736 if (status < 0) {
737 GT_setFailureReason (curTrace,
738 GT_4CLASS,
739 "_Platform_setup",
740 status,
741 "VAYUIPUCORE0PROC_setup failed!");
742 }
743 else {
744 VAYUIPUPWR_getConfig (&lv->ipuPwrConfig);
745 status = VAYUIPUPWR_setup (&lv->ipuPwrConfig);
746 if (status < 0) {
747 GT_setFailureReason (curTrace,
748 GT_4CLASS,
749 "_Platform_setup",
750 status,
751 "VAYUIPUPWR_setup failed!");
752 }
753 }
755 if (status >= 0) {
756 /* Create an instance of the Processor object for
757 * VAYUIPUCORE0 */
758 VAYUIPUCORE0PROC_Params_init (NULL, &lv->ipuProcParams);
759 handle->sHandles.ipu.pHandle = VAYUIPUCORE0PROC_create (procId,
760 &lv->ipuProcParams);
762 /* Create an instance of the ELF Loader object */
763 ElfLoader_Params_init (NULL, &lv->elfLoaderParams);
764 handle->sHandles.ipu.ldrHandle = ElfLoader_create (procId,
765 &lv->elfLoaderParams);
767 /* Create an instance of the PwrMgr object for VAYUIPUCORE0 */
768 VAYUIPUPWR_Params_init (&lv->ipuPwrParams);
769 handle->sHandles.ipu.pwrHandle = VAYUIPUPWR_create (
770 procId,
771 &lv->ipuPwrParams);
773 if (handle->sHandles.ipu.pHandle == NULL) {
774 status = Platform_E_FAIL;
775 GT_setFailureReason (curTrace,
776 GT_4CLASS,
777 "_Platform_setup",
778 status,
779 "VAYUIPUCORE0PROC_create failed!");
780 }
781 else if (handle->sHandles.ipu.ldrHandle == NULL) {
782 status = Platform_E_FAIL;
783 GT_setFailureReason (curTrace,
784 GT_4CLASS,
785 "_Platform_setup",
786 status,
787 "Failed to create loader instance!");
788 }
789 else if (handle->sHandles.ipu.pwrHandle == NULL) {
790 status = Platform_E_FAIL;
791 GT_setFailureReason (curTrace,
792 GT_4CLASS,
793 "_Platform_setup",
794 status,
795 "VAYUIPUPWR_create failed!");
796 }
797 else {
798 /* Initialize parameters */
799 ProcMgr_Params_init (NULL, &lv->params);
800 lv->params.procHandle = handle->sHandles.ipu.pHandle;
801 lv->params.loaderHandle = handle->sHandles.ipu.ldrHandle;
802 lv->params.pwrHandle = handle->sHandles.ipu.pwrHandle;
803 handle->pmHandle = ProcMgr_create (procId, &lv->params);
804 if (handle->pmHandle == NULL) {
805 status = Platform_E_FAIL;
806 GT_setFailureReason (curTrace,
807 GT_4CLASS,
808 "_Platform_setup",
809 status,
810 "ProcMgr_create failed!");
811 }
812 }
813 }
814 }
816 if (status >= 0) {
817 /* Get MultiProc ID by name. */
818 procId = MultiProc_getId ("IPU2");
820 handle = &Platform_objects [procId];
822 if (status >= 0) {
823 /* Create an instance of the Processor object for
824 * VAYUIPUCORE0 */
825 VAYUIPUCORE0PROC_Params_init (NULL, &lv->ipuProcParams);
826 handle->sHandles.ipu.pHandle = VAYUIPUCORE0PROC_create (procId,
827 &lv->ipuProcParams);
829 /* Create an instance of the ELF Loader object */
830 ElfLoader_Params_init (NULL, &lv->elfLoaderParams);
831 handle->sHandles.ipu.ldrHandle = ElfLoader_create (procId,
832 &lv->elfLoaderParams);
834 /* Create an instance of the PwrMgr object for VAYUIPUCORE0 */
835 VAYUIPUPWR_Params_init (&lv->ipuPwrParams);
836 handle->sHandles.ipu.pwrHandle = VAYUIPUPWR_create (
837 procId,
838 &lv->ipuPwrParams);
840 if (handle->sHandles.ipu.pHandle == NULL) {
841 status = Platform_E_FAIL;
842 GT_setFailureReason (curTrace,
843 GT_4CLASS,
844 "_Platform_setup",
845 status,
846 "VAYUIPUCORE0PROC_create failed!");
847 }
848 else if (handle->sHandles.ipu.ldrHandle == NULL) {
849 status = Platform_E_FAIL;
850 GT_setFailureReason (curTrace,
851 GT_4CLASS,
852 "_Platform_setup",
853 status,
854 "Failed to create loader instance!");
855 }
856 else if (handle->sHandles.ipu.pwrHandle == NULL) {
857 status = Platform_E_FAIL;
858 GT_setFailureReason (curTrace,
859 GT_4CLASS,
860 "_Platform_setup",
861 status,
862 "VAYUIPUPWR_create failed!");
863 }
864 else {
865 /* Initialize parameters */
866 ProcMgr_Params_init (NULL, &lv->params);
867 lv->params.procHandle = handle->sHandles.ipu.pHandle;
868 lv->params.loaderHandle = handle->sHandles.ipu.ldrHandle;
869 lv->params.pwrHandle = handle->sHandles.ipu.pwrHandle;
870 handle->pmHandle = ProcMgr_create (procId, &lv->params);
871 if (handle->pmHandle == NULL) {
872 status = Platform_E_FAIL;
873 GT_setFailureReason (curTrace,
874 GT_4CLASS,
875 "_Platform_setup",
876 status,
877 "ProcMgr_create failed!");
878 }
879 }
880 }
881 }
883 if (status >= 0) {
884 /* Get MultiProc ID by name. */
885 procId = MultiProc_getId ("DSP1");
887 handle = &Platform_objects [procId];
888 VAYUDSPPROC_getConfig (&lv->dspProcConfig);
889 status = VAYUDSPPROC_setup (&lv->dspProcConfig);
890 if (status < 0) {
891 GT_setFailureReason (curTrace,
892 GT_4CLASS,
893 "_Platform_setup",
894 status,
895 "VAYUDSPPROC_setup failed!");
896 }
897 else {
898 VAYUDSPPWR_getConfig (&lv->dspPwrConfig);
899 status = VAYUDSPPWR_setup (&lv->dspPwrConfig);
900 if (status < 0) {
901 GT_setFailureReason (curTrace,
902 GT_4CLASS,
903 "_Platform_setup",
904 status,
905 "VAYUDSPPWR_setup failed!");
906 }
907 }
909 if (status >= 0) {
910 /* Create an instance of the Processor object for
911 * VAYUDSP */
912 VAYUDSPPROC_Params_init (NULL, &lv->dspProcParams);
913 handle->sHandles.dsp0.pHandle = VAYUDSPPROC_create (procId,
914 &lv->dspProcParams);
916 /* Create an instance of the ELF Loader object */
917 ElfLoader_Params_init (NULL, &lv->elfLoaderParams);
918 handle->sHandles.dsp0.ldrHandle =
919 ElfLoader_create (procId,
920 &lv->elfLoaderParams);
921 /* Create an instance of the PwrMgr object for VAYUDSP */
922 VAYUDSPPWR_Params_init (&lv->dspPwrParams);
923 handle->sHandles.dsp0.pwrHandle = VAYUDSPPWR_create (procId,
924 &lv->dspPwrParams);
926 if (handle->sHandles.dsp0.pHandle == NULL) {
927 status = Platform_E_FAIL;
928 GT_setFailureReason (curTrace,
929 GT_4CLASS,
930 "_Platform_setup",
931 status,
932 "VAYUDSPPROC_create failed!");
933 }
934 else if (handle->sHandles.dsp0.ldrHandle == NULL) {
935 status = Platform_E_FAIL;
936 GT_setFailureReason (curTrace,
937 GT_4CLASS,
938 "_Platform_setup",
939 status,
940 "Failed to create loader instance!");
941 }
942 else if (handle->sHandles.dsp0.pwrHandle == NULL) {
943 status = Platform_E_FAIL;
944 GT_setFailureReason (curTrace,
945 GT_4CLASS,
946 "_Platform_setup",
947 status,
948 "VAYUDSPPWR_create failed!");
949 }
950 else {
951 /* Initialize parameters */
952 ProcMgr_Params_init (NULL, &lv->params);
953 lv->params.procHandle = handle->sHandles.dsp0.pHandle;
954 lv->params.loaderHandle = handle->sHandles.dsp0.ldrHandle;
955 lv->params.pwrHandle = handle->sHandles.dsp0.pwrHandle;
956 handle->pmHandle = ProcMgr_create (procId, &lv->params);
957 if (handle->pmHandle == NULL) {
958 status = Platform_E_FAIL;
959 GT_setFailureReason (curTrace,
960 GT_4CLASS,
961 "_Platform_setup",
962 status,
963 "ProcMgr_create failed!");
964 }
965 }
966 }
967 }
969 Memory_free(NULL, lv, sizeof(_Platform_setup_Local));
971 ret:
972 GT_1trace (curTrace, GT_LEAVE, "_Platform_setup", status);
974 /*! @retval Platform_S_SUCCESS operation was successful */
975 return status;
976 }
979 /*!
980 * @brief Function to setup platform.
981 * TBD: logic would change completely in the final system.
982 */
983 Int32
984 _Platform_destroy (void)
985 {
986 Int32 status = Platform_S_SUCCESS;
987 Int32 tmpStatus = Platform_S_SUCCESS;
988 Platform_Handle handle;
990 GT_0trace (curTrace, GT_ENTER, "_Platform_destroy");
992 /* ------------------------- DSP cleanup -------------------------------- */
993 handle = &Platform_objects [MultiProc_getId ("DSP1")];
994 if (handle->pmHandle != NULL) {
995 status = ProcMgr_delete (&handle->pmHandle);
996 GT_assert (curTrace, (status >= 0));
997 #if !defined(SYSLINK_BUILD_OPTIMIZE)
998 if (status < 0) {
999 GT_setFailureReason (curTrace,
1000 GT_4CLASS,
1001 "_Platform_destroy",
1002 status,
1003 "ProcMgr_delete failed!");
1004 }
1005 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1006 }
1008 /* Delete the Processor, Loader and PwrMgr instances */
1009 if (handle->sHandles.dsp0.pwrHandle != NULL) {
1010 tmpStatus = VAYUDSPPWR_delete (&handle->sHandles.dsp0.pwrHandle);
1011 GT_assert (curTrace, (tmpStatus >= 0));
1012 if ((status >= 0) && (tmpStatus < 0)) {
1013 status = tmpStatus;
1014 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1015 GT_setFailureReason (curTrace,
1016 GT_4CLASS,
1017 "_Platform_destroy",
1018 status,
1019 "VAYUDSPPWR_delete failed!");
1020 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1021 }
1022 }
1024 if (handle->sHandles.dsp0.ldrHandle != NULL) {
1025 tmpStatus = ElfLoader_delete (&handle->sHandles.dsp0.ldrHandle);
1026 GT_assert (curTrace, (tmpStatus >= 0));
1027 if ((status >= 0) && (tmpStatus < 0)) {
1028 status = tmpStatus;
1029 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1030 GT_setFailureReason (curTrace,
1031 GT_4CLASS,
1032 "_Platform_destroy",
1033 status,
1034 "Failed to delete loader instance!");
1035 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1036 }
1037 }
1039 if (handle->sHandles.dsp0.pHandle != NULL) {
1040 tmpStatus = VAYUDSPPROC_delete (&handle->sHandles.dsp0.pHandle);
1041 GT_assert (curTrace, (tmpStatus >= 0));
1042 if ((status >= 0) && (tmpStatus < 0)) {
1043 status = tmpStatus;
1044 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1045 GT_setFailureReason (curTrace,
1046 GT_4CLASS,
1047 "_Platform_destroy",
1048 status,
1049 "VAYUDSPPROC_delete failed!");
1050 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1051 }
1052 }
1054 tmpStatus = VAYUDSPPWR_destroy ();
1055 GT_assert (curTrace, (tmpStatus >= 0));
1056 if ((status >= 0) && (tmpStatus < 0)) {
1057 status = tmpStatus;
1058 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1059 GT_setFailureReason (curTrace,
1060 GT_4CLASS,
1061 "_Platform_destroy",
1062 status,
1063 "VAYUDSPPWR_destroy failed!");
1064 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1065 }
1067 tmpStatus = VAYUDSPPROC_destroy ();
1068 GT_assert (curTrace, (tmpStatus >= 0));
1069 if ((status >= 0) && (tmpStatus < 0)) {
1070 status = tmpStatus;
1071 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1072 GT_setFailureReason (curTrace,
1073 GT_4CLASS,
1074 "_Platform_destroy",
1075 status,
1076 "VAYUDSPPROC_destroy failed!");
1077 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1078 }
1080 /* ------------------------- IPU1 cleanup ------------------------------- */
1081 handle = &Platform_objects [MultiProc_getId ("IPU1")];
1082 if (handle->pmHandle != NULL) {
1083 tmpStatus = ProcMgr_delete (&handle->pmHandle);
1084 GT_assert (curTrace, (tmpStatus >= 0));
1085 if ((status >= 0) && (tmpStatus < 0)) {
1086 status = tmpStatus;
1087 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1088 GT_setFailureReason (curTrace,
1089 GT_4CLASS,
1090 "_Platform_destroy",
1091 status,
1092 "ProcMgr_delete failed!");
1093 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1094 }
1095 }
1097 /* Delete the Processor, Loader and PwrMgr instances */
1098 if (handle->sHandles.ipu.pwrHandle != NULL) {
1099 tmpStatus = VAYUIPUPWR_delete (&handle->sHandles.ipu.pwrHandle);
1100 GT_assert (curTrace, (tmpStatus >= 0));
1101 if ((status >= 0) && (tmpStatus < 0)) {
1102 status = tmpStatus;
1103 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1104 GT_setFailureReason (curTrace,
1105 GT_4CLASS,
1106 "_Platform_destroy",
1107 status,
1108 "VAYUIPUPWR_delete failed!");
1109 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1110 }
1111 }
1113 if (handle->sHandles.ipu.ldrHandle != NULL) {
1114 tmpStatus = ElfLoader_delete (&handle->sHandles.ipu.ldrHandle);
1115 GT_assert (curTrace, (tmpStatus >= 0));
1116 if ((status >= 0) && (tmpStatus < 0)) {
1117 status = tmpStatus;
1118 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1119 GT_setFailureReason (curTrace,
1120 GT_4CLASS,
1121 "_Platform_destroy",
1122 status,
1123 "Failed to delete loader instance!");
1124 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1125 }
1126 }
1128 if (handle->sHandles.ipu.pHandle != NULL) {
1129 tmpStatus = VAYUIPUCORE0PROC_delete (&handle->sHandles.ipu.pHandle);
1130 GT_assert (curTrace, (tmpStatus >= 0));
1131 if ((status >= 0) && (tmpStatus < 0)) {
1132 status = tmpStatus;
1133 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1134 GT_setFailureReason (curTrace,
1135 GT_4CLASS,
1136 "_Platform_destroy",
1137 status,
1138 "VAYUIPUCORE0PROC_delete failed!");
1139 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1140 }
1141 }
1143 /* ------------------------- IPU2 cleanup ------------------------------- */
1144 handle = &Platform_objects [MultiProc_getId ("IPU2")];
1145 if (handle->pmHandle != NULL) {
1146 tmpStatus = ProcMgr_delete (&handle->pmHandle);
1147 GT_assert (curTrace, (tmpStatus >= 0));
1148 if ((status >= 0) && (tmpStatus < 0)) {
1149 status = tmpStatus;
1150 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1151 GT_setFailureReason (curTrace,
1152 GT_4CLASS,
1153 "_Platform_destroy",
1154 status,
1155 "ProcMgr_delete failed!");
1156 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1157 }
1158 }
1160 /* Delete the Processor, Loader and PwrMgr instances */
1161 if (handle->sHandles.ipu.pwrHandle != NULL) {
1162 tmpStatus = VAYUIPUPWR_delete (&handle->sHandles.ipu.pwrHandle);
1163 GT_assert (curTrace, (tmpStatus >= 0));
1164 if ((status >= 0) && (tmpStatus < 0)) {
1165 status = tmpStatus;
1166 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1167 GT_setFailureReason (curTrace,
1168 GT_4CLASS,
1169 "_Platform_destroy",
1170 status,
1171 "VAYUIPUPWR_delete failed!");
1172 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1173 }
1174 }
1176 if (handle->sHandles.ipu.ldrHandle != NULL) {
1177 tmpStatus = ElfLoader_delete (&handle->sHandles.ipu.ldrHandle);
1178 GT_assert (curTrace, (tmpStatus >= 0));
1179 if ((status >= 0) && (tmpStatus < 0)) {
1180 status = tmpStatus;
1181 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1182 GT_setFailureReason (curTrace,
1183 GT_4CLASS,
1184 "_Platform_destroy",
1185 status,
1186 "Failed to delete loader instance!");
1187 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1188 }
1189 }
1191 if (handle->sHandles.ipu.pHandle != NULL) {
1192 tmpStatus = VAYUIPUCORE0PROC_delete (&handle->sHandles.ipu.pHandle);
1193 GT_assert (curTrace, (tmpStatus >= 0));
1194 if ((status >= 0) && (tmpStatus < 0)) {
1195 status = tmpStatus;
1196 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1197 GT_setFailureReason (curTrace,
1198 GT_4CLASS,
1199 "_Platform_destroy",
1200 status,
1201 "VAYUIPUCORE0PROC_delete failed!");
1202 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1203 }
1204 }
1206 tmpStatus = VAYUIPUPWR_destroy ();
1207 GT_assert (curTrace, (tmpStatus >= 0));
1208 if ((status >= 0) && (tmpStatus < 0)) {
1209 status = tmpStatus;
1210 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1211 GT_setFailureReason (curTrace,
1212 GT_4CLASS,
1213 "_Platform_destroy",
1214 status,
1215 "VAYUIPUPWR_destroy failed!");
1216 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1217 }
1219 tmpStatus = VAYUIPUCORE0PROC_destroy ();
1220 GT_assert (curTrace, (tmpStatus >= 0));
1221 if ((status >= 0) && (tmpStatus < 0)) {
1222 status = tmpStatus;
1223 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1224 GT_setFailureReason (curTrace,
1225 GT_4CLASS,
1226 "_Platform_destroy",
1227 status,
1228 "VAYUIPUCORE0PROC_destroy failed!");
1229 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1230 }
1232 GT_1trace (curTrace, GT_LEAVE, "_Platform_destroy", status);
1234 /*! @retval Platform_S_SUCCESS operation was successful */
1235 return status;
1236 }
1239 #if defined (__cplusplus)
1240 }
1241 #endif