1 /*
2 * @file Platform.c
3 *
4 * @brief Implementation of Platform initialization logic.
5 *
6 * ============================================================================
7 *
8 * Copyright (c) 2010-2014, Texas Instruments Incorporated
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Contact information for paper mail:
37 * Texas Instruments
38 * Post Office Box 655303
39 * Dallas, Texas 75265
40 * Contact information:
41 * http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
42 * DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
43 * ============================================================================
44 *
45 */
48 /* Standard header files */
49 #include <ti/syslink/Std.h>
51 /* Utilities & Osal headers */
52 #include <ti/syslink/utils/Gate.h>
53 #include <ti/syslink/utils/GateMutex.h>
54 #include <ti/syslink/utils/Memory.h>
55 #include <ti/syslink/utils/Trace.h>
56 #include <ti/ipc/MultiProc.h>
57 #include <_MultiProc.h>
58 #include <ti/syslink/utils/OsalPrint.h>
59 #include <ti/syslink/utils/String.h>
61 /* SysLink device specific headers */
62 #include <ProcDefs.h>
63 #include <Processor.h>
64 #include <OMAP5430BenelliHal.h>
65 #include <OMAP5430BenelliHalReset.h>
66 #include <OMAP5430BenelliHalMmu.h>
67 #include <OMAP5430BenelliProc.h>
68 #include <Omap5430IpcInt.h>
70 /* Module level headers */
71 #include <_MessageQCopy.h>
72 #include <ti/ipc/MessageQCopy.h>
73 #include <_MessageQCopyDefs.h>
75 #include <ti/syslink/ProcMgr.h>
76 #include <_ProcMgr.h>
77 #include <ti/syslink/inc/knl/Platform.h>
78 #include <ElfLoader.h>
80 #include <ti/ipc/Ipc.h>
81 #include <_Ipc.h>
82 #include <_MultiProc.h>
83 #include <IpcKnl.h>
84 #include <ipu_pm.h>
85 #include <GateHWSpinlock.h>
87 #if defined (__cplusplus)
88 extern "C" {
89 #endif
92 /** ============================================================================
93 * Macros.
94 * ============================================================================
95 */
96 #define RESETVECTOR_SYMBOL "_Ipc_ResetVector"
98 #define IPC_MEM_VRING0 0xA0000000
99 #define IPC_MEM_VRING1 0xA0004000
100 #define IPC_MEM_VRING2 0xA0008000
101 #define IPC_MEM_VRING3 0xA000c000
103 #define HWSPINLOCK_BASE 0x4A0F6000
104 #define HWSPINLOCK_SIZE 0x1000
105 #define HWSPINLOCK_OFFSET 0x800
107 #ifndef SYSLINK_SYSBIOS_SMP
108 #define CORE0 "CORE0"
109 #else
110 #define CORE0 "IPU"
111 #endif
113 /** ============================================================================
114 * Application specific configuration, please change these value according to
115 * your application's need.
116 * ============================================================================
117 */
118 /*!
119 * @brief Structure defining config parameters for overall System.
120 */
121 typedef struct Platform_Config {
122 MultiProc_Config multiProcConfig;
123 /*!< Multiproc config parameter */
125 MessageQCopy_Config MQCopyConfig;
126 /*!< Notify config parameter */
128 ProcMgr_Config procMgrConfig;
129 /*!< Processor manager config parameter */
131 ipu_pm_config ipu_pm_config;
132 /* ipu_pm config parameter */
134 ElfLoader_Config elfLoaderConfig;
135 /*!< Elf loader config parameter */
137 GateHWSpinlock_Config gateHWSpinlockConfig;
138 /*!< GateHWSpinlock config parameter */
139 } Platform_Config;
142 /* Struct embedded into slave binary */
143 typedef struct Platform_SlaveConfig {
144 UInt32 cacheLineSize;
145 UInt32 brOffset;
146 } Platform_SlaveConfig;
148 typedef struct Platform_SlaveSRConfig {
149 UInt32 entryBase;
150 UInt32 entryLen;
151 UInt32 ownerProcId;
152 UInt32 id;
153 UInt32 createHeap;
154 UInt32 cacheLineSize;
155 } Platform_SlaveSRConfig;
157 /* Shared region configuration information for host side. */
158 typedef struct Platform_HostSRConfig {
159 UInt16 refCount;
160 } Platform_HostSRConfig;
162 /*! @brief structure for platform instance */
163 typedef struct Platform_Object {
164 /*!< Flag to indicate platform initialization status */
165 ProcMgr_Handle pmHandle;
166 /*!< Handle to the ProcMgr instance used */
167 union{
168 struct {
169 OMAP5430BENELLIPROC_Handle pHandle;
170 /*!< Handle to the Processor instance used */
171 /*!< Handle to the PwrMgr instance used */
172 ElfLoader_Handle ldrHandle;
173 /*!< Handle to the Loader instance used */
174 UInt32 fileId;
175 /*!< File ID of loaded image, needed for un-loading */
176 } ipu0;
177 #ifndef SYSLINK_SYSBIOS_SMP
178 struct {
179 OMAP5430BENELLIPROC_Handle pHandle;
180 /*!< Handle to the Processor instance used */
181 /*!< Handle to the PwrMgr instance used */
182 /* NOTE: no loader used for ipu1, both cores loaded at once */
183 /*!< Handle to the Loader instance used */
184 } ipu1;
185 #endif
186 struct {
187 OMAP5430BENELLIPROC_Handle pHandle;
188 /*!< Handle to the Processor instance used */
189 /*!< Handle to the PwrMgr instance used */
190 ElfLoader_Handle ldrHandle;
191 /*!< Handle to the Loader instance used */
192 } dsp;
193 } sHandles;
194 /*!< Slave specific handles */
195 Platform_SlaveConfig slaveCfg;
196 /*!< Slave embedded config */
197 Platform_SlaveSRConfig * slaveSRCfg;
198 /*!< Shared region details from slave */
199 } Platform_Object, *Platform_Handle;
202 /*! @brief structure for platform instance */
203 typedef struct Platform_Module_State {
204 Bool multiProcInitFlag;
205 /*!< MultiProc Initialize flag */
206 Bool ipu_pm_init_flag;
207 /*!< ipu_pm Initialize flag */
208 Bool procMgrInitFlag;
209 /*!< Processor manager Initialize flag */
210 Bool elfLoaderInitFlag;
211 /*!< Elf loader Initialize flag */
212 Bool ipcIntInitFlag;
213 /*!< IpcInt Initialize flag */
214 Bool platformInitFlag;
215 /*!< Flag to indicate platform initialization status */
216 Bool mqcopyInitFlag;
217 /*!< MQCopy Initialize flag */
218 Bool platform_mem_init_flag;
219 /*!< Flag to indicate platform initialization status */
220 Bool gateHWSpinlockInitFlag;
221 /*!< GateHWSpinlock Initialize flag */
222 Ptr gateHWSpinlockVAddr;
223 /*!< GateHWSpinlock Virtual Address */
224 } Platform_Module_State;
227 /* =============================================================================
228 * GLOBALS
229 * =============================================================================
230 */
231 static Platform_Object Platform_objects [MultiProc_MAXPROCESSORS];
232 static Platform_Module_State Platform_Module_state;
233 static Platform_Module_State * Platform_module = &Platform_Module_state;
235 Int32 _Platform_setup (Ipc_Config * cfg);
236 Int32 _Platform_destroy (void);
238 extern unsigned int syslink_ipu_mem_size;
239 extern unsigned int syslink_dsp_mem_size;
242 /** ============================================================================
243 * APIs.
244 * ============================================================================
245 */
246 /* Function to read slave memory */
247 Int32
248 _Platform_readSlaveMemory (UInt16 procId,
249 UInt32 addr,
250 Ptr value,
251 UInt32 * numBytes);
253 /* Function to write slave memory */
254 Int32
255 _Platform_writeSlaveMemory (UInt16 procId,
256 UInt32 addr,
257 Ptr value,
258 UInt32 * numBytes);
259 /*!
260 * @brief Function to get the default values for configurations.
261 *
262 * @param config Configuration values.
263 */
264 Void
265 Platform_getConfig (Platform_Config * config)
266 {
267 GT_1trace (curTrace, GT_ENTER, "Platform_getConfig", config);
269 GT_assert (curTrace, (config != NULL));
271 #if !defined(SYSLINK_BUILD_OPTIMIZE)
272 if (config == NULL) {
273 GT_setFailureReason (curTrace,
274 GT_4CLASS,
275 "Platform_getConfig",
276 Platform_E_INVALIDARG,
277 "Argument of type (Platform_getConfig *) passed "
278 "is null!");
279 }
280 else {
281 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
283 /* Get the gatepeterson default config */
284 MultiProc_getConfig (&config->multiProcConfig);
286 /* Get the PROCMGR default config */
287 ProcMgr_getConfig (&config->procMgrConfig);
289 /* Get the ElfLoader default config */
290 ElfLoader_getConfig(&config->elfLoaderConfig);
292 /* Get the HWSpinlock default config */
293 GateHWSpinlock_getConfig (&config->gateHWSpinlockConfig);
294 #if !defined(SYSLINK_BUILD_OPTIMIZE)
295 }
296 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
298 GT_0trace (curTrace, GT_LEAVE, "Platform_getConfig");
299 }
301 /*!
302 * @brief Function to override the default confiuration values.
303 *
304 * @param config Configuration values.
305 */
306 Int32
307 Platform_overrideConfig (Platform_Config * config, Ipc_Config * cfg)
308 {
309 Int32 status = Platform_S_SUCCESS;
310 /*Char hexString[16];*/
312 GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", config);
314 GT_assert (curTrace, (config != NULL));
316 #if !defined(SYSLINK_BUILD_OPTIMIZE)
317 if (config == NULL) {
318 /*! @retval Platform_E_INVALIDARG Argument of type
319 * (Platform_Config *) passed is null*/
320 status = Platform_E_INVALIDARG;
321 GT_setFailureReason (curTrace,
322 GT_4CLASS,
323 "Platform_overrideConfig",
324 status,
325 "Argument of type (Platform_getConfig *) passed "
326 "is null!");
327 }
328 else {
329 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
331 /* Set the MultiProc config as defined in SystemCfg.c */
332 config->multiProcConfig = _MultiProc_cfg;
334 /* Override the PROCMGR default config */
336 /* Override the MessageQCopy default config */
337 config->MQCopyConfig.intId[1] = 58;
338 config->MQCopyConfig.intId[2] = 58;
339 config->MQCopyConfig.intId[3] = 58;
341 config->ipu_pm_config.int_id = 58;
342 #ifdef SYSLINK_SYSBIOS_SMP
343 config->ipu_pm_config.num_procs = 2;
344 config->ipu_pm_config.proc_ids[0] = 1; // IPU is set as 1 above
345 config->ipu_pm_config.proc_ids[1] = 2; // DSP is set as 2 above
346 #else
347 config->ipu_pm_config.num_procs = 3;
348 config->ipu_pm_config.proc_ids[0] = 1; // CORE0 is set as 1 above
349 config->ipu_pm_config.proc_ids[1] = 2; // CORE1 is set as 2 above
350 config->ipu_pm_config.proc_ids[2] = 3; // DSP is set as 3 above
351 #endif
353 #if !defined(SYSLINK_BUILD_OPTIMIZE)
354 }
355 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
357 GT_1trace (curTrace, GT_ENTER, "Platform_overrideConfig", status);
359 /*! @retval Platform_S_SUCCESS operation was successful */
360 return status;
361 }
363 /*!
364 * @brief Function to setup platform.
365 * TBD: logic would change completely in the final system.
366 */
367 Int32
368 Platform_setup (Ipc_Config * cfg)
369 {
370 Int32 status = Platform_S_SUCCESS;
371 Platform_Config _config;
372 Platform_Config * config;
373 Omap5430IpcInt_Config omap5430cfg;
374 Memory_MapInfo minfo;
376 Platform_getConfig (&_config);
377 config = &_config;
379 /* Initialize PlatformMem */
380 status = MemoryOS_setup();
381 #if !defined(SYSLINK_BUILD_OPTIMIZE)
382 if (status < 0) {
383 GT_setFailureReason (curTrace,
384 GT_4CLASS,
385 "Platform_setup",
386 status,
387 "platform_mem_setup!");
388 } else {
389 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
390 Platform_module->platform_mem_init_flag = TRUE;
391 #if !defined(SYSLINK_BUILD_OPTIMIZE)
392 }
393 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
395 Platform_overrideConfig (config, cfg);
397 status = MultiProc_setup (&(config->multiProcConfig));
398 #if !defined(SYSLINK_BUILD_OPTIMIZE)
399 if (status < 0) {
400 GT_setFailureReason (curTrace,
401 GT_4CLASS,
402 "Platform_setup",
403 status,
404 "MultiProc_setup failed!");
405 }
406 else {
407 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
408 Platform_module->multiProcInitFlag = TRUE;
409 #if !defined(SYSLINK_BUILD_OPTIMIZE)
410 }
411 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
413 /* Initialize PROCMGR */
414 if (status >= 0) {
415 status = ProcMgr_setup (&(config->procMgrConfig));
416 #if !defined(SYSLINK_BUILD_OPTIMIZE)
417 if (status < 0) {
418 GT_setFailureReason (curTrace,
419 GT_4CLASS,
420 "Platform_setup",
421 status,
422 "ProcMgr_setup failed!");
423 }
424 else {
425 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
426 Platform_module->procMgrInitFlag = TRUE;
427 #if !defined(SYSLINK_BUILD_OPTIMIZE)
428 }
429 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
430 }
432 /* Initialize IpcInt required for VirtQueue/MessageQCopy. */
433 if (status >= 0) {
434 /* Do the IPC interrupt setup for the full platform (cfg is not used) */
435 Omap5430IpcInt_setup(&omap5430cfg);
436 Platform_module->ipcIntInitFlag = TRUE;
437 }
439 /* Initialize Elf loader */
440 if (status >= 0) {
441 status = ElfLoader_setup (&config->elfLoaderConfig);
442 #if !defined(SYSLINK_BUILD_OPTIMIZE)
443 if (status < 0) {
444 GT_setFailureReason (curTrace,
445 GT_4CLASS,
446 "Platform_setup",
447 status,
448 "ElfLoader_setup failed!");
449 }
450 else {
451 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
452 Platform_module->elfLoaderInitFlag = TRUE;
453 #if !defined(SYSLINK_BUILD_OPTIMIZE)
454 }
455 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
456 }
458 /* Initialize ipu_pm */
459 if (status >= 0) {
460 status = ipu_pm_setup (&config->ipu_pm_config);
461 #if !defined(SYSLINK_BUILD_OPTIMIZE)
462 if (status < 0) {
463 GT_setFailureReason (curTrace,
464 GT_4CLASS,
465 "Platform_setup",
466 status,
467 "ipu_pm_setup failed!");
468 }
469 else {
470 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
471 Platform_module->ipu_pm_init_flag = TRUE;
472 #if !defined(SYSLINK_BUILD_OPTIMIZE)
473 }
474 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
475 }
477 /* Initialize MessageQCopy */
478 if (status >= 0) {
479 status = MessageQCopy_setup (&config->MQCopyConfig);
480 #if !defined(SYSLINK_BUILD_OPTIMIZE)
481 if (status < 0) {
482 GT_setFailureReason (curTrace,
483 GT_4CLASS,
484 "Platform_setup",
485 status,
486 "MessageQCopy_setup failed!");
487 }
488 else {
489 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
490 Platform_module->mqcopyInitFlag = TRUE;
491 #if !defined(SYSLINK_BUILD_OPTIMIZE)
492 }
493 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
494 }
496 if (status >= 0) {
497 Memory_set (Platform_objects,
498 0,
499 (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
500 }
502 if (status >= 0) {
503 /* Doing per remote-proc init stuff */
504 status = _Platform_setup (cfg);
505 #if !defined(SYSLINK_BUILD_OPTIMIZE)
506 if (status < 0) {
507 GT_setFailureReason (curTrace,
508 GT_4CLASS,
509 "Platform_setup",
510 status,
511 "_Platform_setup failed!");
512 }
513 else {
514 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
515 Platform_module->platformInitFlag = TRUE;
516 #if !defined(SYSLINK_BUILD_OPTIMIZE)
517 }
518 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
519 }
520 if (status >= 0) {
521 minfo.src = HWSPINLOCK_BASE;
522 minfo.size = HWSPINLOCK_SIZE;
523 minfo.isCached = FALSE;
524 status = Memory_map (&minfo);
525 if (status < 0) {
526 GT_setFailureReason (curTrace,
527 GT_4CLASS,
528 "Platform_setup",
529 status,
530 "Memory_map failed!");
531 }
532 else {
533 Platform_module->gateHWSpinlockVAddr = (Ptr)minfo.dst;
534 config->gateHWSpinlockConfig.numLocks = 32;
535 config->gateHWSpinlockConfig.baseAddr = minfo.dst + HWSPINLOCK_OFFSET;
536 status = GateHWSpinlock_setup (&config->gateHWSpinlockConfig);
537 #if !defined(SYSLINK_BUILD_OPTIMIZE)
538 if (status < 0) {
539 GT_setFailureReason (curTrace,
540 GT_4CLASS,
541 "Platform_setup",
542 status,
543 "GateHWSpinlock_setup failed!");
544 }
545 else {
546 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
547 Platform_module->gateHWSpinlockInitFlag = TRUE;
548 #if !defined(SYSLINK_BUILD_OPTIMIZE)
549 }
550 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
551 }
552 }
554 if (status < 0) {
555 Platform_destroy();
556 }
558 return status;
559 }
562 /*!
563 * @brief Function to destroy the System.
564 *
565 * @sa Platform_setup
566 */
567 Int32
568 Platform_destroy (void)
569 {
570 Int32 status = Platform_S_SUCCESS;
571 Memory_UnmapInfo minfo;
573 GT_0trace (curTrace, GT_ENTER, "Platform_destroy");
575 /* Finalize Platform-specific destroy */
576 if (Platform_module->platformInitFlag == TRUE) {
577 status = _Platform_destroy ();
578 #if !defined(SYSLINK_BUILD_OPTIMIZE)
579 if (status < 0) {
580 GT_setFailureReason (curTrace,
581 GT_4CLASS,
582 "Platform_destroy",
583 status,
584 "Platform_destroy failed!");
585 }
586 else {
587 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
588 Platform_module->platformInitFlag = FALSE;
589 #if !defined(SYSLINK_BUILD_OPTIMIZE)
590 }
591 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
592 }
594 /* Finalize MessageQCopy */
595 if (Platform_module->mqcopyInitFlag == TRUE) {
596 status = MessageQCopy_destroy ();
597 #if !defined(SYSLINK_BUILD_OPTIMIZE)
598 if (status < 0) {
599 GT_setFailureReason (curTrace,
600 GT_4CLASS,
601 "Platform_destroy",
602 status,
603 "MessageQCopy_destroy failed!");
604 }
605 else {
606 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
607 Platform_module->mqcopyInitFlag = FALSE;
608 #if !defined(SYSLINK_BUILD_OPTIMIZE)
609 }
610 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
611 }
613 /* Finalize ipu_pm */
614 if (Platform_module->ipu_pm_init_flag == TRUE) {
615 status = ipu_pm_destroy ();
616 #if !defined(SYSLINK_BUILD_OPTIMIZE)
617 if (status < 0) {
618 GT_setFailureReason (curTrace,
619 GT_4CLASS,
620 "Platform_destroy",
621 status,
622 "ipu_pm_destroy failed!");
623 }
624 else {
625 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
626 Platform_module->ipu_pm_init_flag = FALSE;
627 #if !defined(SYSLINK_BUILD_OPTIMIZE)
628 }
629 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
630 }
632 /* Finalize Elf loader */
633 if (Platform_module->elfLoaderInitFlag == TRUE) {
634 status = ElfLoader_destroy ();
635 #if !defined(SYSLINK_BUILD_OPTIMIZE)
636 if (status < 0) {
637 GT_setFailureReason (curTrace,
638 GT_4CLASS,
639 "Platform_destroy",
640 status,
641 "ElfLoader_destroy failed!");
642 }
643 else {
644 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
645 Platform_module->elfLoaderInitFlag = FALSE;
646 #if !defined(SYSLINK_BUILD_OPTIMIZE)
647 }
648 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
649 }
651 if (Platform_module->ipcIntInitFlag == TRUE) {
652 Omap5430IpcInt_destroy ();
653 Platform_module->ipcIntInitFlag = FALSE;
654 }
656 /* Finalize PROCMGR */
657 if (Platform_module->procMgrInitFlag == TRUE) {
658 status = ProcMgr_destroy ();
659 #if !defined(SYSLINK_BUILD_OPTIMIZE)
660 if (status < 0) {
661 GT_setFailureReason (curTrace,
662 GT_4CLASS,
663 "Platform_destroy",
664 status,
665 "ProcMgr_destroy failed!");
666 }
667 else {
668 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
669 Platform_module->procMgrInitFlag = FALSE;
670 #if !defined(SYSLINK_BUILD_OPTIMIZE)
671 }
672 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
673 }
675 /* Finalize MultiProc */
676 if (Platform_module->multiProcInitFlag == TRUE) {
677 status = MultiProc_destroy ();
678 #if !defined(SYSLINK_BUILD_OPTIMIZE)
679 if (status < 0) {
680 GT_setFailureReason (curTrace,
681 GT_4CLASS,
682 "Platform_destroy",
683 status,
684 "MultiProc_destroy failed!");
685 }
686 else {
687 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
688 Platform_module->multiProcInitFlag = FALSE;
689 #if !defined(SYSLINK_BUILD_OPTIMIZE)
690 }
691 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
692 }
694 if (status >= 0) {
695 Memory_set (Platform_objects,
696 0,
697 (sizeof (Platform_Object) * MultiProc_getNumProcessors()));
698 }
700 if (Platform_module->gateHWSpinlockInitFlag == TRUE) {
701 status = GateHWSpinlock_destroy();
702 #if !defined(SYSLINK_BUILD_OPTIMIZE)
703 if (status < 0) {
704 GT_setFailureReason (curTrace,
705 GT_4CLASS,
706 "Platform_destroy",
707 status,
708 "GateHWSpinlock_destroy failed!");
709 }
710 else {
711 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
712 Platform_module->gateHWSpinlockInitFlag = FALSE;
713 #if !defined(SYSLINK_BUILD_OPTIMIZE)
714 }
715 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
716 }
718 if (Platform_module->gateHWSpinlockVAddr) {
719 minfo.addr = (UInt32)Platform_module->gateHWSpinlockVAddr;
720 minfo.size = HWSPINLOCK_SIZE;
721 minfo.isCached = FALSE;
722 status = Memory_unmap(&minfo);
723 #if !defined(SYSLINK_BUILD_OPTIMIZE)
724 if (status < 0) {
725 GT_setFailureReason (curTrace,
726 GT_4CLASS,
727 "Platform_destroy",
728 status,
729 "Memory_unmap failed!");
730 }
731 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
732 Platform_module->gateHWSpinlockVAddr = NULL;
733 }
735 if (Platform_module->platform_mem_init_flag == TRUE) {
736 status = MemoryOS_destroy();
737 #if !defined(SYSLINK_BUILD_OPTIMIZE)
738 if (status < 0) {
739 GT_setFailureReason (curTrace,
740 GT_4CLASS,
741 "Platform_destroy",
742 status,
743 "MemoryOS_destroy failed!");
744 }
745 else {
746 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
747 Platform_module->platform_mem_init_flag = FALSE;
748 #if !defined(SYSLINK_BUILD_OPTIMIZE)
749 }
750 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
751 }
753 GT_1trace (curTrace, GT_LEAVE, "Platform_destroy", status);
755 /*! @retval Platform_S_SUCCESS Operation successful */
756 return status;
757 }
759 /*!
760 * @brief Function to setup platform.
761 * TBD: logic would change completely in the final system.
762 */
763 Int32
764 _Platform_setup (Ipc_Config * cfg)
765 {
766 Int32 status = Platform_S_SUCCESS;
767 ProcMgr_Params params;
768 OMAP5430BENELLIPROC_Config ipu0ProcConfig;
769 #ifndef SYSLINK_SYSBIOS_SMP
770 OMAP5430BENELLIPROC_Config ipu1ProcConfig;
771 #endif
772 OMAP5430BENELLIPROC_Config dspProcConfig;
773 OMAP5430BENELLIPROC_Params ipu0ProcParams;
774 #ifndef SYSLINK_SYSBIOS_SMP
775 OMAP5430BENELLIPROC_Params ipu1ProcParams;
776 #endif
777 OMAP5430BENELLIPROC_Params dspProcParams;
778 ElfLoader_Params elfLoaderParams;
779 ElfLoader_Handle ldrHandle;
780 UInt16 procId;
781 Platform_Handle handle;
782 Bool core0Setup = FALSE;
783 #ifndef SYSLINK_SYSBIOS_SMP
784 Bool core1Setup = FALSE;
785 #endif
786 Bool dspSetup = FALSE;
788 GT_0trace (curTrace, GT_ENTER, "_Platform_setup");
790 /* Get MultiProc ID by name. */
791 procId = MultiProc_getId (CORE0);
793 handle = &Platform_objects [procId];
795 OMAP5430BENELLIPROC_get_config(&ipu0ProcConfig, procId );
796 status = OMAP5430BENELLIPROC_setup (&ipu0ProcConfig, procId);
797 if (status < 0) {
798 GT_setFailureReason (curTrace,
799 GT_4CLASS,
800 "_Platform_setup",
801 status,
802 "OMAP5430PROC_setup failed!");
803 }
804 else {
805 core0Setup = TRUE;
806 /* Create an instance of the Processor object for
807 * OMAP5430 */
808 OMAP5430BENELLIPROC_Params_init (NULL, &ipu0ProcParams, procId);
810 handle->sHandles.ipu0.pHandle = OMAP5430BENELLIPROC_create (
811 procId,
812 &ipu0ProcParams);
814 /* Create an instance of the Elf Loader object */
815 ElfLoader_Params_init (NULL, &elfLoaderParams);
816 handle->sHandles.ipu0.ldrHandle = ElfLoader_create (procId,
817 &elfLoaderParams);
819 if (handle->sHandles.ipu0.pHandle == NULL) {
820 status = Platform_E_FAIL;
821 GT_setFailureReason (curTrace,
822 GT_4CLASS,
823 "_Platform_setup",
824 status,
825 "OMAP5430PROC_create failed!");
826 }
827 else if (handle->sHandles.ipu0.ldrHandle == NULL) {
828 status = Platform_E_FAIL;
829 GT_setFailureReason (curTrace,
830 GT_4CLASS,
831 "_Platform_setup",
832 status,
833 "Failed to create loader instance!");
834 }
835 else {
836 /* Initialize parameters */
837 ProcMgr_Params_init (NULL, ¶ms);
838 params.procHandle = handle->sHandles.ipu0.pHandle;
839 params.loaderHandle = handle->sHandles.ipu0.ldrHandle;
840 ldrHandle = params.loaderHandle;
841 String_cpy (params.rstVectorSectionName,
842 RESETVECTOR_SYMBOL);
843 handle->pmHandle = ProcMgr_create (procId, ¶ms);
844 if (handle->pmHandle == NULL) {
845 status = Platform_E_FAIL;
846 GT_setFailureReason (curTrace,
847 GT_4CLASS,
848 "_Platform_setup",
849 status,
850 "ProcMgr_create failed!");
851 }
852 }
853 }
855 #ifndef SYSLINK_SYSBIOS_SMP
856 if (status >= 0) {
857 /* Get MultiProc ID by name. */
858 procId = MultiProc_getId ("CORE1");
860 handle = &Platform_objects [procId];
861 OMAP5430BENELLIPROC_get_config (&ipu1ProcConfig, procId );
862 status = OMAP5430BENELLIPROC_setup (&ipu1ProcConfig, procId);
863 if (status < 0) {
864 GT_setFailureReason (curTrace,
865 GT_4CLASS,
866 "_Platform_setup",
867 status,
868 "OMAP5430PROC_setup failed!");
869 }
870 else {
871 core1Setup = TRUE;
872 /* Create an instance of the Processor object for
873 * OMAP5430 */
874 OMAP5430BENELLIPROC_Params_init(NULL, &ipu1ProcParams,procId);
876 handle->sHandles.ipu1.pHandle = OMAP5430BENELLIPROC_create(procId,
877 &ipu1ProcParams);
879 /* Don't create an instance of the Elf Loader - not needed */
881 if (handle->sHandles.ipu1.pHandle == NULL) {
882 status = Platform_E_FAIL;
883 GT_setFailureReason (curTrace,
884 GT_4CLASS,
885 "_Platform_setup",
886 status,
887 "OMAP5430PROC_create failed!");
888 }
889 else {
890 /* Initialize parameters */
891 ProcMgr_Params_init (NULL, ¶ms);
892 params.procHandle = handle->sHandles.ipu1.pHandle;
893 /* Use the same loader handle as ipu0 to avoid ProcMgr errors */
894 params.loaderHandle = ldrHandle;
895 String_cpy (params.rstVectorSectionName,
896 RESETVECTOR_SYMBOL);
897 handle->pmHandle = ProcMgr_create (procId, ¶ms);
898 if (handle->pmHandle == NULL) {
899 status = Platform_E_FAIL;
900 GT_setFailureReason (curTrace,
901 GT_4CLASS,
902 "_Platform_setup",
903 status,
904 "ProcMgr_create failed!");
905 }
906 }
907 }
908 }
909 #endif
911 if (status >= 0) {
912 /* Get MultiProc ID by name. */
913 procId = MultiProc_getId ("DSP");
915 handle = &Platform_objects [procId];
916 OMAP5430BENELLIPROC_get_config(&dspProcConfig, procId);
917 status = OMAP5430BENELLIPROC_setup (&dspProcConfig, procId);
918 if (status < 0) {
919 GT_setFailureReason (curTrace,
920 GT_4CLASS,
921 "_Platform_setup",
922 status,
923 "OMAP5430PROC_setup failed!");
924 }
925 else {
926 dspSetup = TRUE;
927 /* Create an instance of the Processor object for
928 * OMAP5430 */
929 OMAP5430BENELLIPROC_Params_init (NULL, &dspProcParams, procId);
931 handle->sHandles.dsp.pHandle = OMAP5430BENELLIPROC_create (
932 procId,
933 &dspProcParams);
935 /* Create an instance of the Elf Loader object */
936 ElfLoader_Params_init (NULL, &elfLoaderParams);
937 handle->sHandles.dsp.ldrHandle = ElfLoader_create (procId,
938 &elfLoaderParams);
940 if (handle->sHandles.dsp.pHandle == NULL) {
941 status = Platform_E_FAIL;
942 GT_setFailureReason (curTrace,
943 GT_4CLASS,
944 "_Platform_setup",
945 status,
946 "OMAP5430PROC_create failed!");
947 }
948 else if (handle->sHandles.dsp.ldrHandle == NULL) {
949 status = Platform_E_FAIL;
950 GT_setFailureReason (curTrace,
951 GT_4CLASS,
952 "_Platform_setup",
953 status,
954 "Failed to create loader instance!");
955 }
956 else {
957 /* Initialize parameters */
958 ProcMgr_Params_init (NULL, ¶ms);
959 params.procHandle = handle->sHandles.dsp.pHandle;
960 params.loaderHandle = handle->sHandles.dsp.ldrHandle;
961 String_cpy (params.rstVectorSectionName,
962 RESETVECTOR_SYMBOL);
963 handle->pmHandle = ProcMgr_create (procId, ¶ms);
964 if (handle->pmHandle == NULL) {
965 status = Platform_E_FAIL;
966 GT_setFailureReason (curTrace,
967 GT_4CLASS,
968 "_Platform_setup",
969 status,
970 "ProcMgr_create failed!");
971 }
972 }
973 }
974 }
976 if (status < 0) {
977 /* Cleanup in case of error */
978 #ifndef SYSLINK_SYSBIOS_SMP
979 procId = MultiProc_getId ("CORE1");
980 handle = &Platform_objects [procId];
981 if (handle->pmHandle) {
982 ProcMgr_delete(&handle->pmHandle);
983 handle->pmHandle = NULL;
984 }
985 if (handle->sHandles.ipu1.pHandle) {
986 OMAP5430BENELLIPROC_delete(&handle->sHandles.ipu1.pHandle);
987 handle->sHandles.ipu1.pHandle = NULL;
988 }
989 if (core1Setup)
990 OMAP5430BENELLIPROC_destroy(procId);
991 #endif
993 procId = MultiProc_getId (CORE0);
995 handle = &Platform_objects [procId];
996 if (handle->pmHandle) {
997 ProcMgr_delete(&handle->pmHandle);
998 handle->pmHandle = NULL;
999 }
1000 if (handle->sHandles.ipu0.ldrHandle) {
1001 ElfLoader_delete(&handle->sHandles.ipu0.ldrHandle);
1002 handle->sHandles.ipu0.ldrHandle = NULL;
1003 }
1004 if (handle->sHandles.ipu0.pHandle) {
1005 OMAP5430BENELLIPROC_delete(&handle->sHandles.ipu0.pHandle);
1006 handle->sHandles.ipu0.pHandle = NULL;
1007 }
1008 if (core0Setup)
1009 OMAP5430BENELLIPROC_destroy(procId);
1011 procId = MultiProc_getId ("DSP");
1012 handle = &Platform_objects [procId];
1013 if (handle->pmHandle) {
1014 ProcMgr_delete(&handle->pmHandle);
1015 handle->pmHandle = NULL;
1016 }
1017 if (handle->sHandles.dsp.ldrHandle) {
1018 ElfLoader_delete(&handle->sHandles.dsp.ldrHandle);
1019 handle->sHandles.dsp.ldrHandle = NULL;
1020 }
1021 if (handle->sHandles.dsp.pHandle) {
1022 OMAP5430BENELLIPROC_delete(&handle->sHandles.dsp.pHandle);
1023 handle->sHandles.dsp.pHandle = NULL;
1024 }
1025 if (dspSetup)
1026 OMAP5430BENELLIPROC_destroy(procId);
1027 }
1028 GT_1trace (curTrace, GT_LEAVE, "_Platform_setup", status);
1030 /*! @retval Platform_S_SUCCESS operation was successful */
1031 return status;
1032 }
1035 /*!
1036 * @brief Function to setup platform.
1037 * TBD: logic would change completely in the final system.
1038 */
1039 Int32
1040 _Platform_destroy (void)
1041 {
1042 Int32 status = Platform_S_SUCCESS;
1043 Int32 tmpStatus = Platform_S_SUCCESS;
1044 Platform_Handle handle;
1045 /*UInt16 procId;*/
1047 /* Get MultiProc ID by name. */
1049 GT_0trace (curTrace, GT_ENTER, "_Platform_destroy");
1051 #ifndef SYSLINK_SYSBIOS_SMP
1052 /* ------------------------- ipu1 cleanup ------------------------------- */
1053 handle = &Platform_objects [MultiProc_getId ("CORE1")];
1054 if (handle->pmHandle != NULL) {
1055 tmpStatus = ProcMgr_delete (&handle->pmHandle);
1056 GT_assert (curTrace, (tmpStatus >= 0));
1057 if ((status >= 0) && (tmpStatus < 0)) {
1058 status = tmpStatus;
1059 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1060 GT_setFailureReason (curTrace,
1061 GT_4CLASS,
1062 "_Platform_destroy",
1063 status,
1064 "ProcMgr_delete failed!");
1065 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1066 }
1067 }
1069 /* Delete the Processor, Loader and PwrMgr instances */
1071 if (handle->sHandles.ipu1.pHandle != NULL) {
1072 tmpStatus = OMAP5430BENELLIPROC_delete (&handle->sHandles.ipu1.pHandle);
1073 GT_assert (curTrace, (tmpStatus >= 0));
1074 if ((status >= 0) && (tmpStatus < 0)) {
1075 status = tmpStatus;
1076 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1077 GT_setFailureReason (curTrace,
1078 GT_4CLASS,
1079 "_Platform_destroy",
1080 status,
1081 "OMAP5430PROC_delete failed!");
1082 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1083 }
1084 }
1086 tmpStatus = OMAP5430BENELLIPROC_destroy (MultiProc_getId ("CORE1"));
1087 GT_assert (curTrace, (tmpStatus >= 0));
1088 if ((status >= 0) && (tmpStatus < 0)) {
1089 status = tmpStatus;
1090 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1091 GT_setFailureReason (curTrace,
1092 GT_4CLASS,
1093 "_Platform_destroy",
1094 status,
1095 "OMAP5430PROC_destroy failed!");
1096 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1097 }
1098 #endif
1100 /* ------------------------- ipu0 cleanup ------------------------------- */
1101 handle = &Platform_objects [MultiProc_getId (CORE0)];
1102 if (handle->pmHandle != NULL) {
1103 tmpStatus = ProcMgr_delete (&handle->pmHandle);
1104 GT_assert (curTrace, (tmpStatus >= 0));
1105 if ((status >= 0) && (tmpStatus < 0)) {
1106 status = tmpStatus;
1107 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1108 GT_setFailureReason (curTrace,
1109 GT_4CLASS,
1110 "_Platform_destroy",
1111 status,
1112 "ProcMgr_delete failed!");
1113 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1114 }
1115 }
1117 /* Delete the Processor, Loader and PwrMgr instances */
1119 if (handle->sHandles.ipu0.ldrHandle != NULL) {
1120 tmpStatus = ElfLoader_delete (&handle->sHandles.ipu0.ldrHandle);
1121 GT_assert (curTrace, (tmpStatus >= 0));
1122 if ((status >= 0) && (tmpStatus < 0)) {
1123 status = tmpStatus;
1124 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1125 GT_setFailureReason (curTrace,
1126 GT_4CLASS,
1127 "_Platform_destroy",
1128 status,
1129 "Failed to delete loader instance!");
1130 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1131 }
1132 }
1134 if (handle->sHandles.ipu0.pHandle != NULL) {
1135 tmpStatus = OMAP5430BENELLIPROC_delete (&handle->sHandles.ipu0.pHandle);
1136 GT_assert (curTrace, (tmpStatus >= 0));
1137 if ((status >= 0) && (tmpStatus < 0)) {
1138 status = tmpStatus;
1139 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1140 GT_setFailureReason (curTrace,
1141 GT_4CLASS,
1142 "_Platform_destroy",
1143 status,
1144 "OMAP5430PROC_delete failed!");
1145 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1146 }
1147 }
1149 tmpStatus = OMAP5430BENELLIPROC_destroy (MultiProc_getId (CORE0));
1150 GT_assert (curTrace, (tmpStatus >= 0));
1151 if ((status >= 0) && (tmpStatus < 0)) {
1152 status = tmpStatus;
1153 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1154 GT_setFailureReason (curTrace,
1155 GT_4CLASS,
1156 "_Platform_destroy",
1157 status,
1158 "OMAP5430PROC_destroy failed!");
1159 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1160 }
1162 /* ------------------------- dsp cleanup ------------------------------- */
1163 handle = &Platform_objects [MultiProc_getId ("DSP")];
1164 if (handle->pmHandle != NULL) {
1165 tmpStatus = ProcMgr_delete (&handle->pmHandle);
1166 GT_assert (curTrace, (tmpStatus >= 0));
1167 if ((status >= 0) && (tmpStatus < 0)) {
1168 status = tmpStatus;
1169 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1170 GT_setFailureReason (curTrace,
1171 GT_4CLASS,
1172 "_Platform_destroy",
1173 status,
1174 "ProcMgr_delete failed!");
1175 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1176 }
1177 }
1179 /* Delete the Processor, Loader and PwrMgr instances */
1181 if (handle->sHandles.dsp.ldrHandle != NULL) {
1182 tmpStatus = ElfLoader_delete (&handle->sHandles.dsp.ldrHandle);
1183 GT_assert (curTrace, (tmpStatus >= 0));
1184 if ((status >= 0) && (tmpStatus < 0)) {
1185 status = tmpStatus;
1186 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1187 GT_setFailureReason (curTrace,
1188 GT_4CLASS,
1189 "_Platform_destroy",
1190 status,
1191 "Failed to delete loader instance!");
1192 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1193 }
1194 }
1196 if (handle->sHandles.dsp.pHandle != NULL) {
1197 tmpStatus = OMAP5430BENELLIPROC_delete (&handle->sHandles.dsp.pHandle);
1198 GT_assert (curTrace, (tmpStatus >= 0));
1199 if ((status >= 0) && (tmpStatus < 0)) {
1200 status = tmpStatus;
1201 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1202 GT_setFailureReason (curTrace,
1203 GT_4CLASS,
1204 "_Platform_destroy",
1205 status,
1206 "OMAP5430PROC_delete failed!");
1207 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1208 }
1209 }
1211 tmpStatus = OMAP5430BENELLIPROC_destroy (MultiProc_getId ("DSP"));
1212 GT_assert (curTrace, (tmpStatus >= 0));
1213 if ((status >= 0) && (tmpStatus < 0)) {
1214 status = tmpStatus;
1215 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1216 GT_setFailureReason (curTrace,
1217 GT_4CLASS,
1218 "_Platform_destroy",
1219 status,
1220 "OMAP5430PROC_destroy failed!");
1221 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1222 }
1224 GT_1trace (curTrace, GT_LEAVE, "_Platform_destroy", status);
1226 /*! @retval Platform_S_SUCCESS operation was successful */
1227 return status;
1228 }
1231 #if defined (__cplusplus)
1232 }
1233 #endif /* defined (__cplusplus) */