]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - qnx/src/ipc3x_dev/ti/syslink/family/omap5430/ipu/omap5430BenelliProc.c
Moved files from the ipc3x_dev branch in syslink_qnx repository into direct
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / omap5430 / ipu / omap5430BenelliProc.c
1 /*
2  *  @file   omap5430BenelliProc.c
3  *
4  * @brief       Processor implementation for OMAP5430BENELLI.
5  *
6  *              This module is responsible for taking care of device-specific
7  *              operations for the processor. This module can be used
8  *              stand-alone or as part of ProcMgr.
9  *              The implementation is specific to OMAP5430BENELLI.
10  *
11  *
12  *  @ver        02.00.00.44_pre-alpha3
13  *
14  *  ============================================================================
15  *
16  *  Copyright (c) 2010-2011, Texas Instruments Incorporated
17  *
18  *  Redistribution and use in source and binary forms, with or without
19  *  modification, are permitted provided that the following conditions
20  *  are met:
21  *
22  *  *  Redistributions of source code must retain the above copyright
23  *     notice, this list of conditions and the following disclaimer.
24  *
25  *  *  Redistributions in binary form must reproduce the above copyright
26  *     notice, this list of conditions and the following disclaimer in the
27  *     documentation and/or other materials provided with the distribution.
28  *
29  *  *  Neither the name of Texas Instruments Incorporated nor the names of
30  *     its contributors may be used to endorse or promote products derived
31  *     from this software without specific prior written permission.
32  *
33  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
35  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
40  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
41  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
42  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  *  Contact information for paper mail:
45  *  Texas Instruments
46  *  Post Office Box 655303
47  *  Dallas, Texas 75265
48  *  Contact information:
49  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
50  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
51  *  ============================================================================
52  *
53  */
56 /* Standard headers */
57 #include <ti/syslink/Std.h>
59 /* OSAL & Utils headers */
60 #include <ti/syslink/utils/IGateProvider.h>
61 #include <ti/syslink/utils/GateMutex.h>
62 #include <ti/syslink/utils/Trace.h>
63 #include <ti/syslink/utils/Cfg.h>
65 /* Module level headers */
66 #include <ProcDefs.h>
67 #include <Processor.h>
68 #include <OMAP5430BenelliHal.h>
69 #include <OMAP5430BenelliHalReset.h>
70 #include <OMAP5430BenelliHalMmu.h>
71 #include <OMAP5430BenelliProc.h>
72 #include <OMAP5430BenelliEnabler.h>
73 #include <_MultiProc.h>
74 #include <hw/inout.h>
75 #include <RscTable.h>
77 #if defined (__cplusplus)
78 extern "C" {
79 #endif
81 #define INREG32(x) in32(x)
82 #define OUTREG32(x, y) out32(x, y)
85 /* =============================================================================
86  *  Macros and types
87  * =============================================================================
88  */
90 /*!
91  *  @brief  Checks if a value lies in given range.
92  */
93 #define IS_RANGE_VALID(x,min,max) (((x) < (max)) && ((x) >= (min)))
96 /*!
97  *  @brief  Number of static entries in address translation table.
98  */
99 #define AddrTable_STATIC_COUNT 0
101 /*!
102  *  @brief  max entries in translation table.
103  */
104 #define AddrTable_SIZE 32
106 /* number of carveouts */
107 #define NumCarveouts 1
109 /* config param for core0 mmu */
110 #define PARAMS_mmuEnable "ProcMgr.proc[CORE0].mmuEnable="
111 #define PARAMS_carveoutAddr0 "ProcMgr.proc[CORE0].carveoutAddr0="
112 #define PARAMS_carveoutSize0 "ProcMgr.proc[CORE0].carveoutSize0="
113 #define PARAMS_carveoutAddr1 "ProcMgr.proc[CORE0].carveoutAddr1="
114 #define PARAMS_carveoutSize1 "ProcMgr.proc[CORE0].carveoutSize1="
115 #define PARAMS_mmuEnableDSP "ProcMgr.proc[DSP].mmuEnable="
116 #define PARAMS_carveoutAddr0DSP "ProcMgr.proc[DSP].carveoutAddr0="
117 #define PARAMS_carveoutSize0DSP "ProcMgr.proc[DSP].carveoutSize0="
118 #define PARAMS_carveoutAddr1DSP "ProcMgr.proc[DSP].carveoutAddr1="
119 #define PARAMS_carveoutSize1DSP "ProcMgr.proc[DSP].carveoutSize1="
122 /*!
123  *  @brief  OMAP5430BENELLIPROC Module state object
124  */
127 /*OMAP5430 Module state object */
128 typedef struct OMAP5430BENELLIPROC_module_object_tag {
129     UINT32 config_size;
130     /* Size of configuration structure */
131     struct OMAP5430BENELLIPROC_Config cfg;
132     /* OMAP5430 configuration structure */
133     struct OMAP5430BENELLIPROC_Config defCfg;
134     /* Default module configuration */
135     OMAP5430BENELLIPROC_Params      defInstParams;
136     /*!< Default parameters for the OMAP5430BENELLIPROC instances */
137     Bool                    isSetup;
138     /* Flag to indicate if module is setup */
139     OMAP5430BENELLIPROC_Handle procHandle;
140     /* Processor handle array. */
141     IGateProvider_Handle gateHandle;
142     /* void * of gate to be used for local thread safety */
143 }OMAP5430BENELLIPROC_ModuleObject;
145 typedef struct OMAP5430TESLAPROC_module_object_tag {
146     UINT32 config_size;
147     /* Size of configuration structure */
148     struct OMAP5430TESLAPROC_Config cfg;
149     /* OMAP5430 configuration structure */
150     struct OMAP5430TESLAPROC_Config defCfg;
151     /* Default module configuration */
152     OMAP5430BENELLIPROC_Params      defInstParams;
153     /*!< Default parameters for the OMAP5430TESLAPROC instances */
154     Bool                    isSetup;
155     /* Default parameters for the OMAP5430 instances */
156     OMAP5430BENELLIPROC_Handle procHandle;
157     /* Processor handle array. */
158     IGateProvider_Handle gateHandle;
159     /* void * of gate to be used for local thread safety */
160 }OMAP5430TESLAPROC_ModuleObject;
163 /* Default memory regions */
164 static UInt32 AddrTable_count = AddrTable_STATIC_COUNT;
166 /* Default memory regions */
167 static ProcMgr_AddrInfo OMAP5430BENELLIPROC_defaultMemRegions [AddrTable_SIZE] =
169 };
171 /* Default memory regions for DSP */
172 static ProcMgr_AddrInfo OMAP5430TESLAPROC_defaultMemRegions [AddrTable_SIZE] =
174 };
176 /* =============================================================================
177  *  Globals
178  * =============================================================================
179  */
180 /*!
181  *  @var    OMAP5430BENELLIPROC_state
182  *
183  *  @brief  OMAP5430BENELLIPROC state object variable
184  */
185 #if !defined(SYSLINK_BUILD_DEBUG)
186 static
187 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
188 OMAP5430BENELLIPROC_ModuleObject OMAP5430IPU0PROC_state =
190     .config_size = sizeof (OMAP5430BENELLIPROC_Config),
191     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
192     .isSetup = FALSE,
193     .procHandle = NULL,
194     .gateHandle = NULL
195 };
197 #ifndef SYSLINK_SYSBIOS_SMP
198 #if !defined(SYSLINK_BUILD_DEBUG)
199 static
200 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
201 OMAP5430BENELLIPROC_ModuleObject OMAP5430IPU1PROC_state =
203     .config_size = sizeof (OMAP5430BENELLIPROC_Config),
204     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
205     .isSetup = FALSE,
206     .procHandle = NULL,
207     .gateHandle = NULL
208 };
209 #endif
211 #if !defined(SYSLINK_BUILD_DEBUG)
212 static
213 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
214 OMAP5430TESLAPROC_ModuleObject OMAP5430DSPPROC_state =
216     .config_size = sizeof (OMAP5430TESLAPROC_Config),
217     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
218     .isSetup = FALSE,
219     .procHandle = NULL,
220     .gateHandle = NULL
221 };
223 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
224 extern String ProcMgr_sysLinkCfgParams;
227 /* =============================================================================
228  * APIs directly called by applications
229  * =============================================================================
230  */
231 /*!
232  *  @brief      Function to get the default configuration for the
233  *              OMAP5430BENELLIPROC module.
234  *
235  *              This function can be called by the application to get their
236  *              configuration parameter to OMAP5430BENELLIPROC_setup filled in by
237  *              the OMAP5430BENELLIPROC module with the default parameters. If
238  *              the user does not wish to make any change in the default
239  *              parameters, this API is not required to be called.
240  *
241  *  @param      cfg        Pointer to the OMAP5430BENELLIPROC module
242  *                         configuration structure in which the default config
243  *                         is to be returned.
244  *
245  *  @sa         OMAP5430BENELLIPROC_setup
246  */
247 Void
248 OMAP5430BENELLIPROC_get_config (OMAP5430BENELLIPROC_Config * cfg, Int ProcType)
250     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_get_config", cfg);
252     GT_assert (curTrace, (cfg != NULL));
254 #if !defined(SYSLINK_BUILD_OPTIMIZE)
255     if (cfg == NULL) {
256         GT_setFailureReason (curTrace,
257                              GT_4CLASS,
258                              "OMAP5430BENELLIPROC_get_config",
259                              PROCESSOR_E_INVALIDARG,
260                              "Argument of type (OMAP5430BENELLIPROC_Config *) "
261                              "passed is null!");
262     }
263     else {
264 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
265         switch (ProcType)
266         {
267             case PROCTYPE_IPU0:
268                 Memory_copy (cfg,
269                              &(OMAP5430IPU0PROC_state.defCfg),
270                              sizeof (OMAP5430BENELLIPROC_Config));
271                 break;
272 #ifndef SYSLINK_SYSBIOS_SMP
273             case PROCTYPE_IPU1:
274                 Memory_copy (cfg,
275                              &(OMAP5430IPU1PROC_state.defCfg),
276                              sizeof (OMAP5430BENELLIPROC_Config));
277             break;
278 #endif
279             case PROCTYPE_DSP:
280                 Memory_copy (cfg,
281                              &(OMAP5430DSPPROC_state.defCfg),
282                              sizeof (OMAP5430TESLAPROC_Config));
283             break;
284         }
285 #if !defined(SYSLINK_BUILD_OPTIMIZE)
286     }
287 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
289     GT_0trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_get_config");
293 /*!
294  *  @brief      Function to setup the OMAP5430BENELLIPROC module.
295  *
296  *              This function sets up the OMAP5430BENELLIPROC module. This
297  *              function must be called before any other instance-level APIs
298  *              can be invoked.
299  *              Module-level configuration needs to be provided to this
300  *              function. If the user wishes to change some specific config
301  *              parameters, then OMAP5430BENELLIPROC_getConfig can be called to
302  *              get the configuration filled with the default values. After
303  *              this, only the required configuration values can be changed. If
304  *              the user does not wish to make any change in the default
305  *              parameters, the application can simply call
306  *              OMAP5430BENELLIPROC_setup with NULL parameters. The default
307  *              parameters would get automatically used.
308  *
309  *  @param      cfg   Optional OMAP5430BENELLIPROC module configuration. If
310  *                    provided as NULL, default configuration is used.
311  *
312  *  @sa         OMAP5430BENELLIPROC_destroy
313  *              GateMutex_create
314  */
315 Int
316 OMAP5430BENELLIPROC_setup (OMAP5430BENELLIPROC_Config * cfg, Int ProcType)
318     Int                                 status  = PROCESSOR_SUCCESS;
319     OMAP5430BENELLIPROC_Config          tmpCfg;
320     OMAP5430BENELLIPROC_ModuleObject *  pState = NULL;
321     Error_Block                         eb;
323     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_setup", cfg);
325     Error_init(&eb);
327     if (cfg == NULL) {
328         OMAP5430BENELLIPROC_get_config (&tmpCfg,ProcType );
329         cfg = &tmpCfg;
330     }
332     switch (ProcType)
333     {
334         case PROCTYPE_IPU0:
335             pState = &OMAP5430IPU0PROC_state;
336             break;
337 #ifndef SYSLINK_SYSBIOS_SMP
338         case PROCTYPE_IPU1:
339             pState = &OMAP5430IPU1PROC_state;
340             break;
341 #endif
342         case PROCTYPE_DSP:
343             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
344             break;
345     }
347     if (pState == NULL) {
348         GT_setFailureReason (curTrace,
349                              GT_4CLASS,
350                              "OMAP5430BENELLIPROC_setup",
351                              PROCESSOR_E_INVALIDARG,
352                              "Unsupported procType");
353         return PROCESSOR_E_INVALIDARG;
354     }
356     /* Create a default gate handle for local module protection. */
357     pState->gateHandle = (IGateProvider_Handle)
358                                GateMutex_create ((GateMutex_Params *)NULL, &eb);
359 #if !defined(SYSLINK_BUILD_OPTIMIZE)
360     if (pState->gateHandle == NULL) {
361         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
362         status = PROCESSOR_E_FAIL;
363         GT_setFailureReason (curTrace,
364                              GT_4CLASS,
365                              "OMAP5430BENELLIPROC_setup",
366                              status,
367                              "Failed to create GateMutex!");
368     }
369     else {
370 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
371         /* Copy the user provided values into the state object. */
372         Memory_copy (&pState->cfg,
373                      cfg,
374                      sizeof (OMAP5430BENELLIPROC_Config));
376         /* Initialize the name to handles mapping array. */
377         pState->procHandle = NULL;
379         pState->isSetup = TRUE;
380 #if !defined(SYSLINK_BUILD_OPTIMIZE)
381     }
382 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
384     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_setup", status);
386     /*! @retval PROCESSOR_SUCCESS Operation successful */
387     return (status);
391 /*!
392  *  @brief      Function to destroy the OMAP5430BENELLIPROC module.
393  *
394  *              Once this function is called, other OMAP5430BENELLIPROC module
395  *              APIs, except for the OMAP5430BENELLIPROC_getConfig API cannot be
396  *              called anymore.
397  *
398  *  @sa         OMAP5430BENELLIPROC_setup
399  *              GateMutex_delete
400  */
401 Int
402 OMAP5430BENELLIPROC_destroy (Int ProcType)
404     Int                                 status  = PROCESSOR_SUCCESS;
405     OMAP5430BENELLIPROC_ModuleObject *  pState = NULL;
407     GT_0trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_destroy");
409     switch(ProcType)
410     {
411         case PROCTYPE_IPU0:
412             pState = &OMAP5430IPU0PROC_state;
413             break;
414 #ifndef SYSLINK_SYSBIOS_SMP
415         case PROCTYPE_IPU1:
416             pState = &OMAP5430IPU1PROC_state;
417             break;
418 #endif
419         case PROCTYPE_DSP:
420             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
421             break;
422     }
424     if (pState == NULL) {
425         GT_setFailureReason (curTrace,
426                              GT_4CLASS,
427                              "OMAP5430BENELLIPROC_setup",
428                              PROCESSOR_E_INVALIDARG,
429                              "Unsupported procType");
430         return PROCESSOR_E_INVALIDARG;
431     }
433     /* Check if any OMAP5430BENELLIPROC instances have not been deleted so far.
434      * If not, delete them.
435      */
436     if (pState->procHandle != NULL) {
437         OMAP5430BENELLIPROC_delete(&pState->procHandle);
438     }
440     if (pState->gateHandle != NULL) {
441         GateMutex_delete ((GateMutex_Handle *)
442                                 &(pState->gateHandle));
443     }
445     pState->isSetup = FALSE;
447     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_destroy", status);
449     /*! @retval PROCESSOR_SUCCESS Operation successful */
450     return (status);
454 /*!
455  *  @brief      Function to initialize the parameters for this Processor
456  *              instance.
457  *
458  *  @param      params  Configuration parameters to be returned
459  *
460  *  @sa         OMAP5430BENELLIPROC_create
461  */
462 Void
463 OMAP5430BENELLIPROC_Params_init (OMAP5430BENELLIPROC_Handle  handle,
464                                 OMAP5430BENELLIPROC_Params * params,
465                                 Int ProcType)
467     OMAP5430BENELLIPROC_Object * procObject =
468                                           (OMAP5430BENELLIPROC_Object *) handle;
469     UInt32                      numMemEntries   = 0;
470     ProcMgr_AddrInfo *          pMemRegn        = NULL;
472     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_Params_init",
473                handle, params);
475     GT_assert (curTrace, (params != NULL));
476     switch(ProcType)
477     {
478         case PROCTYPE_IPU0:
479             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
480             numMemEntries = AddrTable_count;
481             break;
482 #ifndef SYSLINK_SYSBIOS_SMP
483         case PROCTYPE_IPU1:
484             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
485             numMemEntries = AddrTable_count;
486             break;
487 #endif
488         case PROCTYPE_DSP:
489             pMemRegn = OMAP5430TESLAPROC_defaultMemRegions;
490             numMemEntries = AddrTable_count;
491             break;
492     }
494 #if !defined(SYSLINK_BUILD_OPTIMIZE)
495     if (params == NULL) {
496         GT_setFailureReason (curTrace,
497                              GT_4CLASS,
498                              "OMAP5430BENELLIPROC_Params_init",
499                              PROCESSOR_E_INVALIDARG,
500                              "Argument of type (OMAP5430BENELLIPROC_Params *) "
501                              "passed is null!");
502     }
503     else {
504 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
505         if (handle == NULL) {
506             params->numMemEntries =  numMemEntries;
507             Memory_copy ((Ptr) params->memEntries,
508                          pMemRegn,
509                          (sizeof(ProcMgr_AddrInfo) * params->numMemEntries));
510         }
511         else {
512             /* Return updated OMAP5430BENELLIPROC instance specific parameters. */
513             Memory_copy (params,
514                          &(procObject->params),
515                          sizeof (OMAP5430BENELLIPROC_Params));
516         }
517 #if !defined(SYSLINK_BUILD_OPTIMIZE)
518     }
519 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
521     GT_0trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_Params_init");
524 /*!
525  *  @brief      Function to create an instance of this Processor.
526  *
527  *  @param      name    Name of the Processor instance.
528  *  @param      params  Configuration parameters.
529  *
530  *  @sa         OMAP5430BENELLIPROC_delete
531  */
533 OMAP5430BENELLIPROC_Handle
534 OMAP5430BENELLIPROC_create (UInt16 procId,
535                             const OMAP5430BENELLIPROC_Params * params)
537 #if !defined(SYSLINK_BUILD_OPTIMIZE)
538     Int                                 status    = PROCESSOR_SUCCESS;
539 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
540     Processor_Object *                  handle    = NULL;
541     OMAP5430BENELLIPROC_Object *        object    = NULL;
542     IArg                                key;
543     OMAP5430BENELLIPROC_ModuleObject *  pState    = NULL;
544     List_Params                         listParams;
546     switch(procId)
547     {
548         case PROCTYPE_IPU0:
549             pState = &OMAP5430IPU0PROC_state;
550             break;
551 #ifndef SYSLINK_SYSBIOS_SMP
552         case PROCTYPE_IPU1:
553             pState = &OMAP5430IPU1PROC_state;
554             break;
555 #endif
556         case PROCTYPE_DSP:
557             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
558             break;
559     }
561     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_create", procId, params);
563     GT_assert (curTrace, IS_VALID_PROCID (procId));
564     GT_assert (curTrace, (params != NULL));
566 #if !defined(SYSLINK_BUILD_OPTIMIZE)
567     if (pState == NULL) {
568         /* Not setting status here since this function does not return status.*/
569         GT_setFailureReason (curTrace,
570                              GT_4CLASS,
571                              "OMAP5430BENELLIPROC_create",
572                              PROCESSOR_E_INVALIDARG,
573                              "Invalid procId specified");
574     }
575     else if (params == NULL) {
576         GT_setFailureReason (curTrace,
577                              GT_4CLASS,
578                              "OMAP5430BENELLIPROC_create",
579                              PROCESSOR_E_INVALIDARG,
580                              "params passed is NULL!");
581     }
582     else {
583 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
584         /* Enter critical section protection. */
585         key = IGateProvider_enter (pState->gateHandle);
586 #if !defined(SYSLINK_BUILD_OPTIMIZE)
587         /* Check if the Processor already exists for specified procId. */
588         if (pState->procHandle!= NULL) {
589             status = PROCESSOR_E_ALREADYEXIST;
590             GT_setFailureReason (curTrace,
591                               GT_4CLASS,
592                               "OMAP5430BENELLIPROC_create",
593                               status,
594                               "Processor already exists for specified procId!");
595         }
596         else {
597 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
598             /* Allocate memory for the handle */
599             handle = (Processor_Object *) Memory_calloc (NULL,
600                                                       sizeof (Processor_Object),
601                                                       0,
602                                                       NULL);
603 #if !defined(SYSLINK_BUILD_OPTIMIZE)
604             if (handle == NULL) {
605                 GT_setFailureReason (curTrace,
606                                      GT_4CLASS,
607                                      "OMAP5430BENELLIPROC_create",
608                                      PROCESSOR_E_MEMORY,
609                                      "Memory allocation failed for handle!");
610             }
611             else {
612 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
613                 /* Populate the handle fields */
614                 handle->procFxnTable.attach      = &OMAP5430BENELLIPROC_attach;
615                 handle->procFxnTable.detach      = &OMAP5430BENELLIPROC_detach;
616                 handle->procFxnTable.start       = &OMAP5430BENELLIPROC_start;
617                 handle->procFxnTable.stop        = &OMAP5430BENELLIPROC_stop;
618                 handle->procFxnTable.read        = &OMAP5430BENELLIPROC_read;
619                 handle->procFxnTable.write       = &OMAP5430BENELLIPROC_write;
620                 handle->procFxnTable.control     = &OMAP5430BENELLIPROC_control;
621                 handle->procFxnTable.map         = &OMAP5430BENELLIPROC_map;
622                 handle->procFxnTable.unmap       = &OMAP5430BENELLIPROC_unmap;
623                 handle->procFxnTable.translateAddr = &OMAP5430BENELLIPROC_translate;
624                 handle->procFxnTable.virtToPhys  = &OMAP5430BENELLI_virtToPhys;
625                 handle->procFxnTable.getProcInfo = &OMAP5430BENELLIPROC_procInfo;
626                 handle->state = ProcMgr_State_Unknown;
628                 /* Allocate memory for the OMAP5430BENELLIPROC handle */
629                 handle->object = Memory_calloc (NULL,
630                                              sizeof (OMAP5430BENELLIPROC_Object),
631                                              0,
632                                              NULL);
633 #if !defined(SYSLINK_BUILD_OPTIMIZE)
634                 if (handle->object == NULL) {
635                     status = PROCESSOR_E_MEMORY;
636                     GT_setFailureReason (curTrace,
637                                 GT_4CLASS,
638                                 "OMAP5430BENELLIPROC_create",
639                                 status,
640                                 "Memory allocation failed for handle->object!");
641                 }
642                 else {
643 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
644                     handle->procId = procId;
645                     object = (OMAP5430BENELLIPROC_Object *) handle->object;
646                     object->halObject = NULL;
647                     object->procHandle = (Processor_Handle)handle;
648                     /* Copy params into instance object. */
649                     Memory_copy (&(object->params),
650                                  (Ptr) params,
651                                  sizeof (OMAP5430BENELLIPROC_Params));
652                     object->params.procHandle = object->procHandle;
654                     /* Set the handle in the state object. */
655                     pState->procHandle = handle->object;
657                     /* Initialize the list of listeners */
658                     List_Params_init(&listParams);
659                     handle->registeredNotifiers = List_create(&listParams);
661 #if !defined(SYSLINK_BUILD_OPTIMIZE)
662                     if (handle->registeredNotifiers == NULL) {
663                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
664                         status = PROCESSOR_E_FAIL;
665                         GT_setFailureReason (curTrace,
666                                              GT_4CLASS,
667                                              "OMAP5430BENELLIPROC_create",
668                                              status,
669                                              "List_create failed");
670                     }
671                     else {
672 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
674                         handle->notifiersLock =
675                                  OsalMutex_create(OsalMutex_Type_Interruptible);
677 #if !defined(SYSLINK_BUILD_OPTIMIZE)
678                         if (handle->notifiersLock == NULL) {
679                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
680                             status = PROCESSOR_E_FAIL;
681                             GT_setFailureReason (curTrace,
682                                                  GT_4CLASS,
683                                                  "OMAP5430BENELLIPROC_create",
684                                                  status,
685                                                  "OsalMutex_create failed");
686                         }
687                     }
688                 }
689             }
690         }
691 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
693         /* Leave critical section protection. */
694         IGateProvider_leave (pState->gateHandle, key);
695 #if !defined(SYSLINK_BUILD_OPTIMIZE)
696     }
697 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
699 #if !defined(SYSLINK_BUILD_OPTIMIZE)
700     if (status < 0) {
701         if (handle !=  NULL) {
702             if (handle->registeredNotifiers != NULL) {
703                 List_delete (&handle->registeredNotifiers);
704             }
705             if (handle->object != NULL) {
706                 Memory_free (NULL,
707                              handle->object,
708                              sizeof (OMAP5430BENELLIPROC_Object));
709             }
710             Memory_free (NULL, handle, sizeof (Processor_Object));
711         }
712         /*! @retval NULL Function failed */
713         handle = NULL;
714     }
715 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
717     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_create", handle);
719     /*! @retval Valid-Handle Operation successful */
720     return (void*) handle;
724 /*!
725  *  @brief      Function to delete an instance of this Processor.
726  *
727  *              The user provided pointer to the handle is reset after
728  *              successful completion of this function.
729  *
730  *  @param      handlePtr  Pointer to Handle to the Processor instance
731  *
732  *  @sa         OMAP5430BENELLIPROC_create
733  */
734 Int
735 OMAP5430BENELLIPROC_delete (OMAP5430BENELLIPROC_Handle * handlePtr)
737     Int                                 status  = PROCESSOR_SUCCESS;
738     OMAP5430BENELLIPROC_Object *        object  = NULL;
739     Processor_Object *                  handle  = NULL;
740     IArg                                key     = NULL;
741     OMAP5430BENELLIPROC_ModuleObject *  pState  = NULL;
742     List_Elem *                         elem    = NULL;
743     Processor_RegisterElem *            regElem = NULL;
746     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_delete", handlePtr);
748     GT_assert (curTrace, (handlePtr != NULL));
749     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
751 #if !defined(SYSLINK_BUILD_OPTIMIZE)
752     if (handlePtr == NULL) {
753         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
754                                          specified*/
755         status = PROCESSOR_E_INVALIDARG;
756         GT_setFailureReason (curTrace,
757                              GT_4CLASS,
758                              "OMAP5430BENELLIPROC_delete",
759                              status,
760                              "Invalid NULL handlePtr pointer specified");
761     }
762     else if (*handlePtr == NULL) {
763         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
764         status = PROCESSOR_E_HANDLE;
765         GT_setFailureReason (curTrace,
766                              GT_4CLASS,
767                              "OMAP5430BENELLIPROC_delete",
768                              status,
769                              "Invalid NULL *handlePtr specified");
770     }
771     else {
772 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
773         handle = (Processor_Object *) (*handlePtr);
774         /* Enter critical section protection. */
775         if (handle->object != NULL) {
776             object = (OMAP5430BENELLIPROC_Object *) handle->object;
777             switch (handle->procId)
778             {
779                 case PROCTYPE_IPU0:
780                     pState = &OMAP5430IPU0PROC_state;
781                     break;
782 #ifndef SYSLINK_SYSBIOS_SMP
783                 case PROCTYPE_IPU1:
784                     pState = &OMAP5430IPU1PROC_state;
785                     break;
786 #endif
787                 case PROCTYPE_DSP:
788                     pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
789                     break;
790             }
791         }
792 #if !defined(SYSLINK_BUILD_OPTIMIZE)
793         if (pState == NULL) {
794             GT_setFailureReason (curTrace,
795                                  GT_4CLASS,
796                                  "OMAP5430BENELLIPROC_delete",
797                                  PROCESSOR_E_INVALIDARG,
798                                  "Unsupported procType");
799             return PROCESSOR_E_INVALIDARG;
800         }
801 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
803         key = IGateProvider_enter (pState->gateHandle);
805         /* Reset handle in PwrMgr handle array. */
806         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
807         pState->procHandle = NULL;
809         /* Free memory used for the PROC object. */
810         Memory_free (NULL,
811                      handle->object,
812                      sizeof (Ptr));
813         handle->object = NULL;
815         /*
816          * Check the list of listeners to see if any are remaining
817          * and reply to them
818          */
819         OsalMutex_delete(&handle->notifiersLock);
821         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
822             regElem = (Processor_RegisterElem *)elem;
824             /* Check if there is an associated timer and cancel it */
825             if (regElem->timer != -1) {
826                 struct itimerspec value ;
827                 value.it_value.tv_sec = 0;
828                 value.it_value.tv_nsec = 0;
829                 value.it_interval.tv_sec = 0;
830                 value.it_interval.tv_nsec = 0;
831                 timer_settime(regElem->timer, 0, &value, NULL);
833                 timer_delete(regElem->timer);
834                 regElem->timer = -1;
835             }
837             /* Call the callback function so it can clean up. */
838             regElem->info->cbFxn(handle->procId,
839                                  NULL,
840                                  handle->state,
841                                  handle->state,
842                                  ProcMgr_EventStatus_Canceled,
843                                  regElem->info->arg);
844             /* Free the memory */
845             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
846         }
848         /* Delete the list of listeners */
849         List_delete(&handle->registeredNotifiers);
851         /* Free memory used for the Processor object. */
852         Memory_free (NULL, handle, sizeof (Processor_Object));
853         *handlePtr = NULL;
855         /* Leave critical section protection. */
856         IGateProvider_leave (pState->gateHandle, key);
857 #if !defined(SYSLINK_BUILD_OPTIMIZE)
858     }
859 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
861     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_delete", status);
863     /*! @retval PROCESSOR_SUCCESS Operation successful */
864     return (status);
868 /*!
869  *  @brief      Function to open a handle to an instance of this Processor. This
870  *              function is called when access to the Processor is required from
871  *              a different process.
872  *
873  *  @param      handlePtr   Handle to the Processor instance
874  *  @param      procId      Processor ID addressed by this Processor instance.
875  *
876  *  @sa         OMAP5430BENELLIPROC_close
877  */
878 Int
879 OMAP5430BENELLIPROC_open (OMAP5430BENELLIPROC_Handle * handlePtr, UInt16 procId)
881     Int                                 status  = PROCESSOR_SUCCESS;
882     OMAP5430BENELLIPROC_ModuleObject *  pState  = NULL;
884     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_open",
885                handlePtr, procId);
887     GT_assert (curTrace, (handlePtr != NULL));
888     GT_assert (curTrace, IS_VALID_PROCID (procId));
890     switch(procId)
891     {
892         case PROCTYPE_IPU0:
893             pState = &OMAP5430IPU0PROC_state;
894             break;
895 #ifndef SYSLINK_SYSBIOS_SMP
896         case PROCTYPE_IPU1:
897             pState = &OMAP5430IPU1PROC_state;
898             break;
899 #endif
900         case PROCTYPE_DSP:
901             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
902             break;
903     }
905 #if !defined(SYSLINK_BUILD_OPTIMIZE)
906     if (handlePtr == NULL) {
907         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
908         status = PROCESSOR_E_HANDLE;
909         GT_setFailureReason (curTrace,
910                              GT_4CLASS,
911                              "OMAP5430BENELLIPROC_open",
912                              status,
913                              "Invalid NULL handlePtr specified");
914     }
915     else if (pState == NULL) {
916         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
917         status = PROCESSOR_E_INVALIDARG;
918         GT_setFailureReason (curTrace,
919                              GT_4CLASS,
920                              "OMAP5430BENELLIPROC_open",
921                              status,
922                              "Invalid procId specified");
923     }
924     else {
925 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
926         /* Initialize return parameter handle. */
927         *handlePtr = NULL;
929         /* Check if the PwrMgr exists and return the handle if found. */
930         if (pState->procHandle == NULL) {
931             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
932             status = PROCESSOR_E_NOTFOUND;
933             GT_setFailureReason (curTrace,
934                              GT_4CLASS,
935                              "OMAP5430BENELLIPROC_open",
936                              status,
937                              "Specified instance does not exist!");
938         }
939         else {
940             *handlePtr = pState->procHandle;
941         }
942 #if !defined(SYSLINK_BUILD_OPTIMIZE)
943     }
944 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
946     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_open", status);
948     /*! @retval PROCESSOR_SUCCESS Operation successful */
949     return status;
953 /*!
954  *  @brief      Function to close a handle to an instance of this Processor.
955  *
956  *  @param      handlePtr  Pointer to Handle to the Processor instance
957  *
958  *  @sa         OMAP5430BENELLIPROC_open
959  */
960 Int
961 OMAP5430BENELLIPROC_close (OMAP5430BENELLIPROC_Handle * handlePtr)
963     Int status = PROCESSOR_SUCCESS;
965     GT_1trace (curTrace, GT_ENTER, "OMAP5430M3VIDEOPROC_close", handlePtr);
967     GT_assert (curTrace, (handlePtr != NULL));
968     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
970 #if !defined(SYSLINK_BUILD_OPTIMIZE)
971     if (handlePtr == NULL) {
972         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
973                                          specified*/
974         status = PROCESSOR_E_INVALIDARG;
975         GT_setFailureReason (curTrace,
976                              GT_4CLASS,
977                              "OMAP5430BENELLIPROC_close",
978                              status,
979                              "Invalid NULL handlePtr pointer specified");
980     }
981     else if (*handlePtr == NULL) {
982         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
983         status = PROCESSOR_E_HANDLE;
984         GT_setFailureReason (curTrace,
985                              GT_4CLASS,
986                              "OMAP5430BENELLIPROC_close",
987                              status,
988                              "Invalid NULL *handlePtr specified");
989     }
990     else {
991 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
992         /* Nothing to be done for close. */
993 #if !defined(SYSLINK_BUILD_OPTIMIZE)
994     }
995 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
997     GT_1trace (curTrace, GT_LEAVE, "OMAP5430M3VIDEOPROC_close", status);
999     /*! @retval PROCESSOR_SUCCESS Operation successful */
1000     return status;
1004 /* =============================================================================
1005  * APIs called by Processor module (part of function table interface)
1006  * =============================================================================
1007  */
1008 /*!
1009  *  @brief      Function to initialize the slave processor
1010  *
1011  *  @param      handle  Handle to the Processor instance
1012  *  @param      params  Attach parameters
1013  *
1014  *  @sa         OMAP5430BENELLIPROC_detach
1015  */
1016 Int
1017 OMAP5430BENELLIPROC_attach (Processor_Handle        handle,
1018                            Processor_AttachParams * params)
1021     Int                            status       = PROCESSOR_SUCCESS ;
1022     Processor_Object *             procHandle   = (Processor_Object *) handle;
1023     OMAP5430BENELLIPROC_Object *   object       = NULL;
1024     ProcMgr_AddrInfo *             me;
1025     OMAP5430BENELLIPROC_ModuleObject *      pState;
1026     OMAP5430BENELLI_HalMmuCtrlArgs_Enable   enableArgs;
1027     UInt32                      i = 0;
1028     UInt32                      index = 0;
1029     SysLink_MemEntry *          entry;
1030     SysLink_MemEntry_Block      memBlock;
1031     Char                        configProp[SYSLINK_MAX_NAMELENGTH];
1032     ProcMgr_AddrInfo *          pMemRegn        = NULL;
1034     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_attach", handle, params);
1036     GT_assert (curTrace, (handle != NULL));
1037     GT_assert (curTrace, (params != NULL));
1039     switch(procHandle->procId)
1040     {
1041         case PROCTYPE_IPU0:
1042             pState = &OMAP5430IPU0PROC_state;
1043             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1044             break;
1045 #ifndef SYSLINK_SYSBIOS_SMP
1046         case PROCTYPE_IPU1:
1047             pState = &OMAP5430IPU1PROC_state;
1048             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1049             break;
1050 #endif
1051         case PROCTYPE_DSP:
1052             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
1053             pMemRegn = OMAP5430TESLAPROC_defaultMemRegions;
1054             break;
1055     }
1057 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1058     if (handle == NULL) {
1059         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1060         status = PROCESSOR_E_HANDLE;
1061         GT_setFailureReason (curTrace,
1062                              GT_4CLASS,
1063                              "OMAP5430BENELLIPROC_attach",
1064                              status,
1065                              "Invalid handle specified");
1066     }
1067     else if (params == NULL) {
1068             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1069             status = PROCESSOR_E_INVALIDARG;
1070             GT_setFailureReason (curTrace,
1071                                  GT_4CLASS,
1072                                  "OMAP5430BENELLIPROC_attach",
1073                                  status,
1074                                  "Invalid params specified");
1075     }
1076     else {
1077 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1078         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1079         GT_assert (curTrace, (object != NULL));
1081         /* Added for Netra Benelli core0 is cortex M3 */
1082         params->procArch = Processor_ProcArch_M3;
1083         GT_0trace (curTrace,
1084                    GT_2CLASS,
1085                    "    OMAP5430BENELLIPROC_attach: Mapping memory regions");
1087         /* check for carveout params override */
1088         if (procHandle->procId == PROCTYPE_DSP) {
1089             Cfg_prop(PARAMS_carveoutAddr0DSP, ProcMgr_sysLinkCfgParams, configProp);
1090             object->params.carveoutAddr[0] = strtoul(configProp, 0, 16);
1091             Cfg_prop(PARAMS_carveoutSize0DSP, ProcMgr_sysLinkCfgParams, configProp);
1092             object->params.carveoutSize[0] = strtoul(configProp, 0, 16);
1093         }
1094         else {
1095             Cfg_prop(PARAMS_carveoutAddr0, ProcMgr_sysLinkCfgParams, configProp);
1096             object->params.carveoutAddr[0] = strtoul(configProp, 0, 16);
1097             Cfg_prop(PARAMS_carveoutSize0, ProcMgr_sysLinkCfgParams, configProp);
1098             object->params.carveoutSize[0] = strtoul(configProp, 0, 16);
1099         }
1101         object->pmHandle = params->pmHandle;
1102         GT_0trace(curTrace, GT_1CLASS,
1103             "OMAP5430BENELLIPROC_attach: Mapping memory regions");
1105         /* search for dsp memory map */
1106         status = RscTable_process(procHandle->procId, TRUE, NumCarveouts,
1107                                   (Ptr)object->params.carveoutAddr,
1108                                   object->params.carveoutSize, TRUE,
1109                                   &memBlock.numEntries);
1110         if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
1111             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1112             status = PROCESSOR_E_INVALIDARG;
1113             GT_setFailureReason (curTrace,
1114                                  GT_4CLASS,
1115                                  "OMAP5430BENELLIPROC_attach",
1116                                  status,
1117                                  "Failed to process resource table");
1118         }
1119         else {
1120             status = RscTable_getMemEntries(procHandle->procId,
1121                                             memBlock.memEntries,
1122                                             &memBlock.numEntries);
1123             if (status < 0) {
1124                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1125                 status = PROCESSOR_E_INVALIDARG;
1126                 GT_setFailureReason (curTrace,
1127                                      GT_4CLASS,
1128                                      "OMAP5430BENELLIPROC_attach",
1129                                      status,
1130                                      "Failed to get resource table memEntries");
1131             }
1132         }
1134         /* update translation tables with memory map */
1135         for (i = 0; (i < memBlock.numEntries)
1136             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
1138             entry = &memBlock.memEntries[i];
1140             if (entry->map == FALSE) {
1141                 /* update table with entries which don't require mapping */
1142                 if (AddrTable_count != AddrTable_SIZE) {
1143                     me = &pMemRegn[AddrTable_count];
1145                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1146                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1147                     me->addr[ProcMgr_AddrType_MasterPhys] =
1148                             entry->masterPhysAddr;
1149                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1150                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1151                     me->size = entry->size;
1152                     me->isCached = entry->isCached;
1153                     me->mapMask = entry->mapMask;
1155                     AddrTable_count++;
1156                 }
1157                 else {
1158                     status = PROCESSOR_E_FAIL;
1159                     GT_setFailureReason(curTrace, GT_4CLASS,
1160                         "OMAP5430BENELLIPROC_attach", status,
1161                         "AddrTable_SIZE reached!");
1162                 }
1163             }
1164             else if (entry->map == TRUE) {
1165                 /* send these entries back to ProcMgr for mapping */
1166                 index = object->params.numMemEntries;
1168                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
1169                     me = &object->params.memEntries[index];
1171                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1172                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1173                     me->addr[ProcMgr_AddrType_MasterPhys] =
1174                             entry->masterPhysAddr;
1175                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1176                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1177                     me->size = entry->size;
1178                     me->isCached = entry->isCached;
1179                     me->mapMask = entry->mapMask;
1181                     object->params.numMemEntries++;
1182                 }
1183                 else {
1184                     status = PROCESSOR_E_FAIL;
1185                     GT_setFailureReason(curTrace, GT_4CLASS,
1186                         "OMAP5430BENELLIPROC_attach", status,
1187                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
1188                 }
1189             }
1190             else {
1191                 status = PROCESSOR_E_INVALIDARG;
1192                 GT_setFailureReason(curTrace, GT_4CLASS,
1193                     "OMAP5430BENELLIPROC_attach", status,
1194                     "Memory map has entry with invalid 'map' value");
1195             }
1196         } /* for (...) */
1198         if (status >= 0) {
1199             /* populate the return params */
1200             params->numMemEntries = object->params.numMemEntries;
1201             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1202                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1204             status = OMAP5430BENELLI_halInit (&(object->halObject),
1205                                               &object->params,
1206                                               procHandle->procId);
1207 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1208             if (status < 0) {
1209                 GT_setFailureReason (curTrace,
1210                                      GT_4CLASS,
1211                                      "OMAP5430BENELLIPROC_attach",
1212                                      status,
1213                                      "OMAP5430BENELLI_halInit failed");
1214             }
1215             else {
1216 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1218                 if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1219                     ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1221 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1222                     if (status < 0) {
1223                         GT_setFailureReason (curTrace,
1224                                              GT_4CLASS,
1225                                              "OMAP5430BENELLIPROC_attach",
1226                                              status,
1227                                          "Failed to reset the slave processor");
1228                     }
1229                     else {
1230 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1231                         GT_0trace (curTrace,
1232                                  GT_1CLASS,
1233                                  "    OMAP5430BENELLIPROC_attach: Slave is now "
1234                                  "in reset!");
1236                         if (procHandle->procId == PROCTYPE_IPU0) {
1237                             /* Enable MMU */
1238                             GT_0trace (curTrace,
1239                                        GT_2CLASS,
1240                                        "OMAP5430BENELLIPROC_attach: "
1241                                        "Enabling Slave MMU ...");
1242                             enableArgs.memEntries = NULL;
1243                             enableArgs.numMemEntries = 0;
1244                             status = OMAP5430BENELLI_halMmuCtrl (
1245                                                     object->halObject,
1246                                                     Processor_MmuCtrlCmd_Enable,
1247                                                     &enableArgs);
1248 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1249                             if (status < 0) {
1250                                 GT_setFailureReason (curTrace,
1251                                               GT_4CLASS,
1252                                               "OMAP5430BENELLIPROC_attach",
1253                                               status,
1254                                               "Failed to enable the slave MMU");
1255                             }
1256                         }
1257                     }
1258 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1259                 }
1260             }
1261 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1262         }
1263     }
1264 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1266     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_attach",status);
1268     /*! @retval PROCESSOR_SUCCESS Operation successful */
1269     return status;
1274 /*!
1275  *  @brief      Function to detach from the Processor.
1276  *
1277  *  @param      handle  Handle to the Processor instance
1278  *
1279  *  @sa         OMAP5430BENELLIPROC_attach
1280  */
1281 Int
1282 OMAP5430BENELLIPROC_detach (Processor_Handle handle)
1284     Int                       status     = PROCESSOR_SUCCESS;
1285     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1286     Processor_Object *        procHandle = (Processor_Object *) handle;
1287     OMAP5430BENELLIPROC_Object * object   = NULL;
1288     Int i                              = 0;
1289     ProcMgr_AddrInfo *    ai;
1290     ProcMgr_AddrInfo *          pMemRegn        = NULL;
1292     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_detach", handle);
1294     GT_assert (curTrace, (handle != NULL));
1296     switch(procHandle->procId)
1297     {
1298         case PROCTYPE_IPU0:
1299             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1300             break;
1301 #ifndef SYSLINK_SYSBIOS_SMP
1302         case PROCTYPE_IPU1:
1303             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1304             break;
1305 #endif
1306         case PROCTYPE_DSP:
1307             pMemRegn = OMAP5430TESLAPROC_defaultMemRegions;
1308             break;
1309     }
1311 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1312     if (handle == NULL) {
1313         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1314         status = PROCESSOR_E_HANDLE;
1315         GT_setFailureReason (curTrace,
1316                              GT_4CLASS,
1317                              "OMAP5430BENELLIPROC_detach",
1318                              PROCESSOR_E_HANDLE,
1319                              "Invalid handle specified");
1320     }
1321     else {
1322 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1323         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1324         GT_assert (curTrace, (object != NULL));
1326         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1327             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1328             if (procHandle->procId == PROCTYPE_IPU0) {
1329                 /* Disable MMU */
1330                 GT_0trace (curTrace,
1331                            GT_2CLASS,
1332                            "    OMAP5430BENELLIPROC_detach: "
1333                            "Disabling Slave MMU ...");
1334                 status = OMAP5430BENELLI_halMmuCtrl (object->halObject,
1335                                                    Processor_MmuCtrlCmd_Disable,
1336                                                    NULL);
1337 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1338                 if (status < 0) {
1339                     GT_setFailureReason (curTrace,
1340                                          GT_4CLASS,
1341                                          "OMAP5430BENELLIPROC_detach",
1342                                          status,
1343                                          "Failed to disable the slave MMU");
1344                 }
1345 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1346             }
1348             /* delete all dynamically added entries */
1349             for (i = AddrTable_STATIC_COUNT; i < AddrTable_count; i++) {
1350                 ai = &pMemRegn[i];
1351                 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1352                 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1353                 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1354                 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1355                 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1356                 ai->size = 0u;
1357                 ai->isCached = FALSE;
1358                 ai->mapMask = 0u;
1359                 ai->isMapped = FALSE;
1360                 ai->refCount = 0u;
1361             }
1362             object->params.numMemEntries = AddrTable_STATIC_COUNT;
1363             AddrTable_count = AddrTable_STATIC_COUNT;
1365             //No need to reset.. that will be done in STOP
1366            /* tmpStatus = OMAP5430BENELLI_halResetCtrl (object->halObject,
1367                                                    Processor_ResetCtrlCmd_Reset,
1368                                                    NULL);
1369             GT_0trace (curTrace,
1370                        GT_2CLASS,
1371                        "    OMAP5430BENELLIPROC_detach: Slave processor is "
1372                        "now in reset");*/
1373 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1374             if ((tmpStatus < 0) && (status >= 0)) {
1375                 status = tmpStatus;
1376                 GT_setFailureReason (curTrace,
1377                                      GT_4CLASS,
1378                                      "OMAP5430BENELLIPROC_detach",
1379                                      status,
1380                                      "Failed to reset the slave processor");
1381             }
1382 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1383         }
1385         GT_0trace (curTrace,
1386                    GT_2CLASS,
1387                    "    OMAP5430BENELLIPROC_detach: Unmapping memory regions");
1389         tmpStatus = OMAP5430BENELLI_halExit(object->halObject, &object->params);
1390 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1391         if ((tmpStatus < 0) && (status >= 0)) {
1392             status = tmpStatus;
1393             GT_setFailureReason (curTrace,
1394                                  GT_4CLASS,
1395                                  "OMAP5430BENELLIPROC_detach",
1396                                  status,
1397                                  "Failed to finalize HAL object");
1398         }
1399     }
1400 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1402     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_detach", status);
1404     /*! @retval PROCESSOR_SUCCESS Operation successful */
1405     return status;
1409 /*!
1410  *  @brief      Function to start the slave processor
1411  *
1412  *              Start the slave processor running from its entry point.
1413  *              Depending on the boot mode, this involves configuring the boot
1414  *              address and releasing the slave from reset.
1415  *
1416  *  @param      handle    Handle to the Processor instance
1417  *
1418  *  @sa         OMAP5430BENELLIPROC_stop, OMAP5430BENELLIPROC_halBootCtrl,
1419  *              OMAP5430BENELLIPROC_halResetCtrl
1420  */
1421 Int
1422 OMAP5430BENELLIPROC_start (Processor_Handle        handle,
1423                            UInt32                  entryPt,
1424                            Processor_StartParams * params)
1426     Int                           status       = PROCESSOR_SUCCESS ;
1427     Processor_Object *            procHandle   = (Processor_Object *) handle;
1428     OMAP5430BENELLIPROC_Object  * object       = procHandle->object;
1429     Memory_MapInfo        sysCtrlMapInfo;
1430     Memory_UnmapInfo      sysCtrlUnmapInfo;
1432     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_start",
1433                handle, entryPt, params);
1435     GT_assert (curTrace, (handle != NULL));
1436     GT_assert (curTrace, (params != NULL));
1438 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1439     if (handle == NULL) {
1440         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1441         status = PROCESSOR_E_HANDLE;
1442         GT_setFailureReason (curTrace,
1443                              GT_4CLASS,
1444                              "OMAP5430BENELLIPROC_start",
1445                              status,
1446                              "Invalid handle specified");
1447     }
1448     else if (params == NULL) {
1449             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1450             status = PROCESSOR_E_INVALIDARG;
1451             GT_setFailureReason (curTrace,
1452                                  GT_4CLASS,
1453                                  "OMAP5430BENELLIPROC_start",
1454                                  status,
1455                                  "Invalid params specified");
1456     }
1457     else {
1458 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1459         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1460                                              Processor_ResetCtrlCmd_MMU_Release,
1461                                              entryPt);
1462         if (status < 0) {
1463             /*! @retval status */
1464             GT_setFailureReason (curTrace,
1465                                  GT_4CLASS,
1466                                  "OMAP5430BENELLI_halResetCtrl",
1467                                  status,
1468                                  "Reset MMU_Release failed");
1469         }
1470         else {
1471             if(handle->procId != MultiProc_getId("DSP"))
1472                 status = ipu_setup(object->halObject, object->params.memEntries,
1473                                    object->params.numMemEntries);
1474             else
1475                 status = tesla_setup(object->halObject,
1476                                      object->params.memEntries,
1477                                      object->params.numMemEntries);
1478             if (status < 0) {
1479                 /*! @retval status */
1480                 GT_setFailureReason (curTrace,
1481                                      GT_4CLASS,
1482                                      "OMAP5430BENELLI_halResetCtrl",
1483                                      status,
1484                                      "ipu_setup failed");
1485             }
1486             else {
1487                 if (handle->procId == MultiProc_getId("DSP")) {
1488                     /* Get the user virtual address of the PRM base */
1489                     sysCtrlMapInfo.src  = 0x4A002000;
1490                     sysCtrlMapInfo.size = 0x1000;
1491                     sysCtrlMapInfo.isCached = FALSE;
1493                     status = Memory_map (&sysCtrlMapInfo);
1494                     if (status < 0) {
1495                         status = PROCESSOR_E_FAIL;
1496                         GT_setFailureReason (curTrace,
1497                                              GT_4CLASS,
1498                                              "ProcMgr_load",
1499                                               status,
1500                                               "Memory_map failed");
1501                     }
1502                     else {
1503                         *(UInt32 *)(sysCtrlMapInfo.dst + 0x304) = entryPt;
1505                         sysCtrlUnmapInfo.addr = sysCtrlMapInfo.dst;
1506                         sysCtrlUnmapInfo.size = sysCtrlMapInfo.size;
1507                         sysCtrlUnmapInfo.isCached = FALSE;
1508                         Memory_unmap (&sysCtrlUnmapInfo);
1509                     }
1510                 }
1511                 if (status >= 0) {
1512                     status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1513                                                  Processor_ResetCtrlCmd_Release,
1514                                                  entryPt);
1515                 }
1516                 if (status < 0) {
1517                     /*! @retval status */
1518                     GT_setFailureReason (curTrace,
1519                                          GT_4CLASS,
1520                                          "OMAP5430BENELLI_halResetCtrl",
1521                                          status,
1522                                          "Reset Release failed");
1523                 }
1524             }
1525         }
1526 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1527     }
1528 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1529         return status;
1533 /*!
1534  *  @brief      Function to stop the slave processor
1535  *
1536  *              Stop the execution of the slave processor. Depending on the boot
1537  *              mode, this may result in placing the slave processor in reset.
1538  *
1539  *  @param      handle    Handle to the Processor instance
1540  *
1541  *  @sa         OMAP5430BENELLIPROC_start, OMAP5430BENELLIPROC_halResetCtrl
1542  */
1543 Int
1544 OMAP5430BENELLIPROC_stop (Processor_Handle handle)
1546     Int                         status       = PROCESSOR_SUCCESS ;
1547     Processor_Object *          procHandle   = (Processor_Object *) handle;
1548     OMAP5430BENELLIPROC_Object * object      = procHandle->object;
1550     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_stop", handle);
1552     GT_assert (curTrace, (handle != NULL));
1554 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1555     if (handle == NULL) {
1556         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1557         status = PROCESSOR_E_HANDLE;
1558         GT_setFailureReason (curTrace,
1559                              GT_4CLASS,
1560                              "OMAP5430BENELLIPROC_stop",
1561                              status,
1562                              "Invalid handle specified");
1563     }
1564     else {
1565 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1566         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1567                                              Processor_ResetCtrlCmd_Reset,
1568                                              0);
1569         if (status < 0) {
1570             /*! @retval status */
1571             GT_setFailureReason (curTrace,
1572                                  GT_4CLASS,
1573                                  "OMAP5430BENELLI_halResetCtrl",
1574                                  status,
1575                                  "Reset failed");
1576         }
1578         ipu_destroy(object->halObject);
1579         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1580                                              Processor_ResetCtrlCmd_MMU_Reset,
1581                                              0);
1582         if (status < 0) {
1583             /*! @retval status */
1584             GT_setFailureReason (curTrace,
1585                                  GT_4CLASS,
1586                                  "OMAP5430BENELLI_halResetCtrl",
1587                                  status,
1588                                  "Reset MMU failed");
1589         }
1591 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1592     }
1593 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1595     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_stop", status);
1597     /*! @retval PROCESSOR_SUCCESS Operation successful */
1598     return status;
1602 /*!
1603  *  @brief      Function to read from the slave processor's memory.
1604  *
1605  *              Read from the slave processor's memory and copy into the
1606  *              provided buffer.
1607  *
1608  *  @param      handle     Handle to the Processor instance
1609  *  @param      procAddr   Address in host processor's address space of the
1610  *                         memory region to read from.
1611  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1612  *                         number of bytes to be read. When the function
1613  *                         returns, this parameter contains the number of bytes
1614  *                         actually read.
1615  *  @param      buffer     User-provided buffer in which the slave processor's
1616  *                         memory contents are to be copied.
1617  *
1618  *  @sa         OMAP5430BENELLIPROC_write
1619  */
1620 Int
1621 OMAP5430BENELLIPROC_read (Processor_Handle   handle,
1622                           UInt32             procAddr,
1623                           UInt32 *           numBytes,
1624                           Ptr                buffer)
1626     Int       status   = PROCESSOR_SUCCESS ;
1627     UInt8  *  procPtr8 = NULL;
1629     GT_4trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_read",
1630                handle, procAddr, numBytes, buffer);
1632     GT_assert (curTrace, (handle   != NULL));
1633     GT_assert (curTrace, (numBytes != NULL));
1634     GT_assert (curTrace, (buffer   != NULL));
1636 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1637     if (handle == NULL) {
1638         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1639         status = PROCESSOR_E_HANDLE;
1640         GT_setFailureReason (curTrace,
1641                              GT_4CLASS,
1642                              "OMAP5430BENELLIPROC_read",
1643                              status,
1644                              "Invalid handle specified");
1645     }
1646     else if (numBytes == 0) {
1647             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1648             status = PROCESSOR_E_INVALIDARG;
1649             GT_setFailureReason (curTrace,
1650                                  GT_4CLASS,
1651                                  "OMAP5430BENELLIPROC_read",
1652                                  status,
1653                                  "Invalid numBytes specified");
1654     }
1655     else if (buffer == NULL) {
1656             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1657             status = PROCESSOR_E_INVALIDARG;
1658             GT_setFailureReason (curTrace,
1659                                  GT_4CLASS,
1660                                  "OMAP5430BENELLIPROC_read",
1661                                  status,
1662                                  "Invalid buffer specified");
1663     }
1664     else {
1665 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1666         procPtr8 = (UInt8 *) procAddr ;
1667         buffer = Memory_copy (buffer, procPtr8, *numBytes);
1668         GT_assert (curTrace, (buffer != (UInt32) NULL));
1669 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1670         if (buffer == (UInt32) NULL) {
1671             /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1672             status = PROCESSOR_E_FAIL;
1673             GT_setFailureReason (curTrace,
1674                                  GT_4CLASS,
1675                                  "OMAP5430BENELLIPROC_read",
1676                                  status,
1677                                  "Failed in Memory_copy");
1678             *numBytes = 0;
1679         }
1680     }
1681 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1683     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_read",status);
1685     /*! @retval PROCESSOR_SUCCESS Operation successful */
1686     return status;
1690 /*!
1691  *  @brief      Function to write into the slave processor's memory.
1692  *
1693  *              Read from the provided buffer and copy into the slave
1694  *              processor's memory.
1695  *
1696  *  @param      handle     Handle to the Processor object
1697  *  @param      procAddr   Address in host processor's address space of the
1698  *                         memory region to write into.
1699  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1700  *                         number of bytes to be written. When the function
1701  *                         returns, this parameter contains the number of bytes
1702  *                         actually written.
1703  *  @param      buffer     User-provided buffer from which the data is to be
1704  *                         written into the slave processor's memory.
1705  *
1706  *  @sa         OMAP5430BENELLIPROC_read
1707  */
1708 Int
1709 OMAP5430BENELLIPROC_write (Processor_Handle handle,
1710                            UInt32           procAddr,
1711                            UInt32 *         numBytes,
1712                            Ptr              buffer)
1714     Int                   status       = PROCESSOR_SUCCESS ;
1715     Processor_Object *    procHandle   = (Processor_Object *) handle;
1716     OMAP5430BENELLIPROC_Object * object = NULL;
1717     UInt8  *              procPtr8     = NULL;
1718     UInt8                 temp8_1;
1719     UInt8                 temp8_2;
1720     UInt8                 temp8_3;
1721     UInt8                 temp8_4;
1722     UInt32                temp;
1724     GT_4trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_write",
1725                handle, procAddr, numBytes, buffer);
1727     GT_assert (curTrace, (handle   != NULL));
1728     GT_assert (curTrace, (numBytes != NULL));
1729     GT_assert (curTrace, (buffer   != NULL));
1731 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1732     if (handle == NULL) {
1733         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1734         status = PROCESSOR_E_HANDLE;
1735         GT_setFailureReason (curTrace,
1736                              GT_4CLASS,
1737                              "OMAP5430BENELLIPROC_write",
1738                              status,
1739                              "Invalid handle specified");
1740     }
1741     else if (numBytes == 0) {
1742             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1743             status = PROCESSOR_E_INVALIDARG;
1744             GT_setFailureReason (curTrace,
1745                                  GT_4CLASS,
1746                                  "OMAP5430BENELLIPROC_write",
1747                                  status,
1748                                  "Invalid numBytes specified");
1749     }
1750     else if (buffer == NULL) {
1751             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1752             status = PROCESSOR_E_INVALIDARG;
1753             GT_setFailureReason (curTrace,
1754                                  GT_4CLASS,
1755                                  "OMAP5430BENELLIPROC_write",
1756                                  status,
1757                                  "Invalid buffer specified");
1758     }
1759     else {
1760 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1761         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1762         GT_assert (curTrace, (object != NULL));
1763         if (*numBytes != sizeof (UInt32)) {
1764             procPtr8 = (UInt8 *) procAddr ;
1765             procAddr = (UInt32) Memory_copy (procPtr8,
1766                                              buffer,
1767                                              *numBytes);
1768             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1769 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1770             if (procAddr == (UInt32) NULL) {
1771                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1772                 status = PROCESSOR_E_FAIL;
1773                 GT_setFailureReason (curTrace,
1774                                      GT_4CLASS,
1775                                      "OMAP5430BENELLIPROC_write",
1776                                      status,
1777                                      "Failed in Memory_copy");
1778                 *numBytes = 0;
1779             }
1780 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1781         }
1782         else  {
1783              /* For 4 bytes, directly write as a UInt32 */
1784             temp8_1 = ((UInt8 *) buffer) [0];
1785             temp8_2 = ((UInt8 *) buffer) [1];
1786             temp8_3 = ((UInt8 *) buffer) [2];
1787             temp8_4 = ((UInt8 *) buffer) [3];
1788             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1789                              |   ((UInt32) temp8_3 << 16)
1790                              |   ((UInt32) temp8_2 << 8)
1791                              |   ((UInt32) temp8_1));
1792             *((UInt32*) procAddr) = temp;
1793         }
1794 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1795     }
1796 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1798     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_write", status);
1800     /*! @retval PROCESSOR_SUCCESS Operation successful */
1801     return status;
1805 /*!
1806  *  @brief      Function to perform device-dependent operations.
1807  *
1808  *              Performs device-dependent control operations as exposed by this
1809  *              implementation of the Processor module.
1810  *
1811  *  @param      handle     Handle to the Processor object
1812  *  @param      cmd        Device specific processor command
1813  *  @param      arg        Arguments specific to the type of command.
1814  *
1815  *  @sa
1816  */
1817 Int
1818 OMAP5430BENELLIPROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1820     Int                          status       = PROCESSOR_SUCCESS ;
1821     Processor_Object *           procHandle   = (Processor_Object *) handle;
1822     OMAP5430BENELLIPROC_Object * object       = NULL;
1824     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_control",
1825                handle, cmd, arg);
1827     GT_assert (curTrace, (handle != NULL));
1828     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1830 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1831     if (handle == NULL) {
1832         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1833         status = PROCESSOR_E_HANDLE;
1834         GT_setFailureReason (curTrace,
1835                              GT_4CLASS,
1836                              "OMAP5430BENELLIPROC_control",
1837                              status,
1838                              "Invalid handle specified");
1839     }
1840     else {
1841 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1842         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1843         GT_assert (curTrace, (object != NULL));
1844         /* No control operations currently implemented. */
1845         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1846                                              for this device. */
1848         switch (cmd) {
1849             case Omap5430BenelliProc_CtrlCmd_Suspend:
1850                 if (procHandle->state == ProcMgr_State_Running) {
1851                     if (procHandle->procId == PROCTYPE_IPU0) {
1852                         status = save_mmu_ctxt(object->halObject,
1853                                                procHandle->procId);
1854                     }
1855                     if (status < 0) {
1856                         GT_setFailureReason(curTrace, GT_4CLASS,
1857                                             "OMAP5430BENELLIPROC_control",
1858                                             status,
1859                                             "Error while saving the MMU context");
1860                     }
1861                     else {
1862                         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1863                                                        Processor_ResetCtrlCmd_Reset,
1864                                                        0);
1865                         if (status < 0) {
1866                             GT_setFailureReason(curTrace, GT_4CLASS,
1867                                                 "OMAP5430BENELLIPROC_control",
1868                                                 status,
1869                                                 "Error while Resetting proc");
1870                         }
1871                         else {
1872                             status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1873                                                    Processor_ResetCtrlCmd_MMU_Reset,
1874                                                    0);
1875                             if (status < 0) {
1876                                 GT_setFailureReason(curTrace, GT_4CLASS,
1877                                                     "OMAP5430BENELLIPROC_control",
1878                                                     status,
1879                                                     "Error while Resetting MMU");
1880                             }
1881                             else {
1882                                 Processor_setState(handle, ProcMgr_State_Suspended);
1883                             }
1884                         }
1885                     }
1886                 }
1887                 else {
1888                     status = PROCESSOR_E_INVALIDSTATE;
1889                     GT_setFailureReason(curTrace, GT_4CLASS,
1890                                         "OMAP5430BENELLIPROC_control",
1891                                         status,
1892                                         "Processor not is correct state to Suspend");
1893                 }
1894                 break;
1895             case Omap5430BenelliProc_CtrlCmd_Resume:
1896                 if (procHandle->state == ProcMgr_State_Suspended) {
1897                     status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1898                                                  Processor_ResetCtrlCmd_MMU_Release,
1899                                                  0);
1900                     if (status < 0) {
1901                         GT_setFailureReason(curTrace, GT_4CLASS,
1902                                             "OMAP5430BENELLIPROC_control",
1903                                             status,
1904                                             "Error while releasing proc MMU reset");
1905                     }
1906                     else {
1907                         if (procHandle->procId == PROCTYPE_IPU0) {
1908                             status = restore_mmu_ctxt(object->halObject,
1909                                                       procHandle->procId);
1910                         }
1911                         if (status < 0) {
1912                             GT_setFailureReason(curTrace, GT_4CLASS,
1913                                                "OMAP5430BENELLIPROC_control",
1914                                                status,
1915                                                "Error while restoring MMU context");
1916                         }
1917                         else {
1918                             status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1919                                                      Processor_ResetCtrlCmd_Release,
1920                                                      0);
1921                             if (status < 0) {
1922                                 GT_setFailureReason(curTrace, GT_4CLASS,
1923                                                     "OMAP5430BENELLIPROC_control",
1924                                                     status,
1925                                                     "Error while releasing reset");
1926                             }
1927                             else {
1928                                 Processor_setState(handle, ProcMgr_State_Running);
1929                             }
1930                         }
1931                     }
1932                 }
1933                 else {
1934                     status = PROCESSOR_E_INVALIDSTATE;
1935                     GT_setFailureReason(curTrace, GT_4CLASS,
1936                                         "OMAP5430BENELLIPROC_control",
1937                                         status,
1938                                         "Processor not is correct state to Resume");
1939                 }
1940                 break;
1941             default:
1942                 status = PROCESSOR_E_NOTSUPPORTED;
1943         }
1945 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1946     }
1947 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1948     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_control",status);
1950     /*! @retval PROCESSOR_SUCCESS Operation successful */
1951     return status;
1955 /*!
1956  *  @brief      Function to translate slave physical address to master physical
1957  *              address.
1958  *
1959  *  @param      handle     Handle to the Processor object
1960  *  @param      dstAddr    Returned: master physical address.
1961  *  @param      srcAddr    Slave physical address.
1962  *
1963  *  @sa
1964  */
1965 Int
1966 OMAP5430BENELLIPROC_translate (Processor_Handle handle,
1967                                UInt32 *         dstAddr,
1968                                UInt32           srcAddr)
1970     Int                         status       = PROCESSOR_SUCCESS ;
1971     Processor_Object *          procHandle   = (Processor_Object *) handle;
1972     OMAP5430BENELLIPROC_Object * object      = NULL;
1973     UInt32                      i;
1974     ProcMgr_AddrInfo *          ai;
1975     ProcMgr_AddrInfo *          pMemRegn     = NULL;
1976     UInt32                      nRegions     = 0;
1978     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_translate",
1979                handle, dstAddr, srcAddr);
1981     GT_assert (curTrace, (handle  != NULL));
1982     GT_assert (curTrace, (dstAddr != NULL));
1984     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_Params_init", handle);
1986 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1987     if (handle == NULL) {
1988         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1989         status = PROCESSOR_E_HANDLE;
1990         GT_setFailureReason (curTrace,
1991                              GT_4CLASS,
1992                              "OMAP5430BENELLIPROC_translate",
1993                              status,
1994                              "Invalid handle specified");
1995     }
1996     else if (dstAddr == NULL) {
1997         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1998         status = PROCESSOR_E_INVALIDARG;
1999         GT_setFailureReason (curTrace,
2000                              GT_4CLASS,
2001                              "OMAP5430BENELLIPROC_translate",
2002                              status,
2003                              "dstAddr provided as NULL");
2004     }
2005     else {
2006 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2007         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
2008         GT_assert (curTrace, (object != NULL));
2010         pMemRegn = object->params.memEntries;
2011         nRegions = object->params.numMemEntries;
2013         *dstAddr = -1u;
2014         for (i = 0;i < nRegions;i++)
2015         {
2016              ai = &pMemRegn [i];
2017              if (   (srcAddr >= ai->addr [ProcMgr_AddrType_SlaveVirt])
2018                  && (srcAddr < (  ai->addr [ProcMgr_AddrType_SlaveVirt]
2019                                 + ai->size))) {
2020                  *dstAddr =   ai->addr [ProcMgr_AddrType_MasterPhys]
2021                             + (srcAddr - ai->addr [ProcMgr_AddrType_SlaveVirt]);
2022                  break;
2023              }
2024         }
2026         if (*dstAddr == -1u) {
2027             /*! @retval PROCESSOR_E_FAIL srcAddr not found in slave address
2028              *          space */
2029             status = PROCESSOR_E_INVALIDARG;
2030             GT_setFailureReason (curTrace,
2031                                  GT_4CLASS,
2032                                  "OMAP5430BENELLIPROC_translate",
2033                                  status,
2034                                  "srcAddr not found in slave address space");
2035         }
2037 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2038     }
2039 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2040     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_translate",status);
2042     /*! @retval PROCESSOR_SUCCESS Operation successful */
2043     return status;
2047 /*!
2048  *  @brief      Function to map slave address to host address space
2049  *
2050  *              Map the provided slave address to master address space. This
2051  *              function also maps the specified address to slave MMU space.
2052  *
2053  *  @param      handle      Handle to the Processor object
2054  *  @param      mapType     Type of mapping to be performed.
2055  *  @param      addrInfo    Structure containing map info.
2056  *  @param      srcAddrType Source address type.
2057  *
2058  *  @sa
2059  */
2060 Int
2061 OMAP5430BENELLIPROC_map (Processor_Handle handle,
2062                          UInt32 *         dstAddr,
2063                          UInt32           nSegs,
2064                          Memory_SGList *  sglist)
2066     Int                          status       = PROCESSOR_SUCCESS ;
2067     Processor_Object *           procHandle   = (Processor_Object *) handle;
2068     OMAP5430BENELLIPROC_Object * object       = NULL;
2069     UInt32                       i;
2070     OMAP5430BENELLI_HalMmuCtrlArgs_AddEntry addEntryArgs;
2072     GT_4trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_map",
2073                handle, dstAddr, nSegs, sglist);
2075     GT_assert (curTrace, (handle != NULL));
2076     GT_assert (curTrace, (sglist != NULL));
2077     GT_assert (curTrace, (nSegs > 0));
2079 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2080     if (handle == NULL) {
2081         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
2082         status = PROCESSOR_E_HANDLE;
2083         GT_setFailureReason (curTrace,
2084                              GT_4CLASS,
2085                              "OMAP5430BENELLIPROC_map",
2086                              status,
2087                              "Invalid handle specified");
2088     }
2089     else if (sglist == NULL) {
2090         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
2091         status = PROCESSOR_E_INVALIDARG;
2092         GT_setFailureReason (curTrace,
2093                              GT_4CLASS,
2094                              "OMAP5430BENELLIPROC_map",
2095                              status,
2096                              "sglist provided as NULL");
2097     }
2098     else if (nSegs == 0) {
2099         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
2100         status = PROCESSOR_E_INVALIDARG;
2101         GT_setFailureReason (curTrace,
2102                              GT_4CLASS,
2103                              "OMAP5430BENELLIPROC_map",
2104                              status,
2105                              "Number of segments provided is 0");
2106     }
2107     else {
2108 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2109         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
2110         GT_assert (curTrace, (object != NULL));
2111         /* Program the mmu with the sglist */
2112         /* Program the DSP MMU also */
2113         for (i = 0; (i < nSegs) && (status >= 0); i++)
2114         {
2115             addEntryArgs.masterPhyAddr = sglist [i].paddr;
2116             addEntryArgs.size          = sglist [i].size;
2117             addEntryArgs.slaveVirtAddr = (UInt32)*dstAddr;
2118             /*TBD : elementSize, endianism, mixedSized are hard coded now,
2119              *      must be configurable later*/
2120             addEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2121             addEntryArgs.endianism     = LITTLE_ENDIAN;
2122             addEntryArgs.mixedSize     = MMU_TLBES;
2123             addEntryArgs.slaveVirtAddr = get_BenelliVirtAdd(object->halObject,
2124                                                     addEntryArgs.masterPhyAddr);
2125             *(dstAddr) = addEntryArgs.slaveVirtAddr;
2126             if(addEntryArgs.slaveVirtAddr == 0) {
2127                 status = OMAP5430BENELLI_halMmuCtrl (object->halObject,
2128                                                   Processor_MmuCtrlCmd_AddEntry,
2129                                                   &addEntryArgs);
2131             }
2132 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2133             if (status < 0) {
2134                 GT_setFailureReason (curTrace,
2135                                  GT_4CLASS,
2136                                  "OMAP5430BENELLIPROC_map",
2137                                  status,
2138                                  "DSP MMU configuration failed");
2139             }
2140 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2141         }
2142 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2143     }
2144 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2145     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_map",status);
2147     /*! @retval PROCESSOR_SUCCESS Operation successful */
2148     return status;
2152 /*!
2153  *  @brief      Function to unmap slave address from host address space
2154  *
2155  *  @param      handle      Handle to the Processor object
2156  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
2157  *                          address.
2158  *  @param      size        Size of the region to be mapped.
2159 s *
2160  *  @sa
2161  */
2162 Int
2163 OMAP5430BENELLIPROC_unmap (Processor_Handle handle,
2164                            UInt32           addr,
2165                            UInt32           size)
2167     Int                          status       = PROCESSOR_SUCCESS ;
2168     Processor_Object *           procHandle   = (Processor_Object *) handle;
2169     OMAP5430BENELLIPROC_Object * object       = NULL;
2170     OMAP5430BENELLI_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
2172     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_unmap",
2173                handle, addr, size);
2175     GT_assert (curTrace, (handle != NULL));
2176     GT_assert (curTrace, (size   != 0));
2178 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2179     if (handle == NULL) {
2180         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
2181         status = PROCESSOR_E_HANDLE;
2182         GT_setFailureReason (curTrace,
2183                              GT_4CLASS,
2184                              "OMAP5430BENELLIPROC_unmap",
2185                              status,
2186                              "Invalid handle specified");
2187     }
2188     else if (size == 0) {
2189         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
2190         status = PROCESSOR_E_INVALIDARG;
2191         GT_setFailureReason (curTrace,
2192                              GT_4CLASS,
2193                              "OMAP5430BENELLIPROC_unmap",
2194                              status,
2195                              "Size provided is zero");
2196     }
2197     else {
2198 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2199         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
2200         GT_assert (curTrace, (object != NULL));
2201         /* Remove the entry from the DSP MMU also */
2203         deleteEntryArgs.size          = size;
2204         deleteEntryArgs.slaveVirtAddr = addr;
2205         /*TBD : elementSize, endianism, mixedSized are hard coded now,
2206          *        must be configurable later*/
2207         deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2208         deleteEntryArgs.endianism     = LITTLE_ENDIAN;
2209         deleteEntryArgs.mixedSize     = MMU_TLBES;
2211         status = OMAP5430BENELLI_halMmuCtrl(object->halObject,
2212                                             Processor_MmuCtrlCmd_DeleteEntry,
2213                                             &deleteEntryArgs);
2214 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2215         if (status < 0) {
2216             GT_setFailureReason (curTrace,
2217                              GT_4CLASS,
2218                              "OMAP5430BENELLIPROC_unmap",
2219                              status,
2220                              "DSP MMU configuration failed");
2221         }
2222 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2224 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2225     }
2226 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2227     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_unmap",status);
2229     /*! @retval PROCESSOR_SUCCESS Operation successful */
2230     return status;
2233 Int
2234 OMAP5430BENELLIPROC_procInfo (Processor_Handle   handle,
2235                               ProcMgr_ProcInfo * procInfo)
2237     Processor_Object *              procHandle  = NULL;
2238     OMAP5430BENELLIPROC_Object *    object      = NULL;
2239     ProcMgr_AddrInfo *              entry       = NULL;
2240     Int                             i           = 0;
2242     procHandle = (Processor_Object *)handle;
2243     object = procHandle->object;
2244     for (i = 0; i < object->params.numMemEntries; i++) {
2245         entry = &object->params.memEntries[i];
2247         procInfo->memEntries[i].info.addr[ProcMgr_AddrType_MasterKnlVirt] =
2248             entry->addr[ProcMgr_AddrType_MasterKnlVirt];
2250         procInfo->memEntries[i].info.addr[ProcMgr_AddrType_SlaveVirt] =
2251             entry->addr[ProcMgr_AddrType_SlaveVirt];
2254     }
2255     procInfo->numMemEntries = object->params.numMemEntries;
2256     return 0;
2259 Int
2260 OMAP5430BENELLI_virtToPhys (Processor_Handle handle,
2261                             UInt32           da,
2262                             UInt32 *         mappedEntries,
2263                             UInt32           numEntries)
2265     if(!handle || !mappedEntries || !numEntries) {
2266         return -1;
2267     }
2268     return 0;
2272 #if defined (__cplusplus)
2274 #endif /* defined (__cplusplus) */