88b1e694282706278a99ed1bc4a462adbf5552fa
[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 #ifndef SYSLINK_SYSBIOS_SMP
111 #define PARAMS_mmuEnable "ProcMgr.proc[CORE0].mmuEnable="
112 #define PARAMS_carveoutAddr0 "ProcMgr.proc[CORE0].carveoutAddr0="
113 #define PARAMS_carveoutSize0 "ProcMgr.proc[CORE0].carveoutSize0="
114 #define PARAMS_carveoutAddr1 "ProcMgr.proc[CORE0].carveoutAddr1="
115 #define PARAMS_carveoutSize1 "ProcMgr.proc[CORE0].carveoutSize1="
116 #else
117 #define PARAMS_mmuEnable "ProcMgr.proc[IPU].mmuEnable="
118 #define PARAMS_carveoutAddr0 "ProcMgr.proc[IPU].carveoutAddr0="
119 #define PARAMS_carveoutSize0 "ProcMgr.proc[IPU].carveoutSize0="
120 #define PARAMS_carveoutAddr1 "ProcMgr.proc[IPU].carveoutAddr1="
121 #define PARAMS_carveoutSize1 "ProcMgr.proc[IPU].carveoutSize1="
122 #endif
123 #define PARAMS_mmuEnableDSP "ProcMgr.proc[DSP].mmuEnable="
124 #define PARAMS_carveoutAddr0DSP "ProcMgr.proc[DSP].carveoutAddr0="
125 #define PARAMS_carveoutSize0DSP "ProcMgr.proc[DSP].carveoutSize0="
126 #define PARAMS_carveoutAddr1DSP "ProcMgr.proc[DSP].carveoutAddr1="
127 #define PARAMS_carveoutSize1DSP "ProcMgr.proc[DSP].carveoutSize1="
130 /*!
131  *  @brief  OMAP5430BENELLIPROC Module state object
132  */
135 /*OMAP5430 Module state object */
136 typedef struct OMAP5430BENELLIPROC_module_object_tag {
137     UINT32 config_size;
138     /* Size of configuration structure */
139     struct OMAP5430BENELLIPROC_Config cfg;
140     /* OMAP5430 configuration structure */
141     struct OMAP5430BENELLIPROC_Config defCfg;
142     /* Default module configuration */
143     OMAP5430BENELLIPROC_Params      defInstParams;
144     /*!< Default parameters for the OMAP5430BENELLIPROC instances */
145     Bool                    isSetup;
146     /* Flag to indicate if module is setup */
147     OMAP5430BENELLIPROC_Handle procHandle;
148     /* Processor handle array. */
149     IGateProvider_Handle gateHandle;
150     /* void * of gate to be used for local thread safety */
151 }OMAP5430BENELLIPROC_ModuleObject;
153 typedef struct OMAP5430TESLAPROC_module_object_tag {
154     UINT32 config_size;
155     /* Size of configuration structure */
156     struct OMAP5430TESLAPROC_Config cfg;
157     /* OMAP5430 configuration structure */
158     struct OMAP5430TESLAPROC_Config defCfg;
159     /* Default module configuration */
160     OMAP5430BENELLIPROC_Params      defInstParams;
161     /*!< Default parameters for the OMAP5430TESLAPROC instances */
162     Bool                    isSetup;
163     /* Default parameters for the OMAP5430 instances */
164     OMAP5430BENELLIPROC_Handle procHandle;
165     /* Processor handle array. */
166     IGateProvider_Handle gateHandle;
167     /* void * of gate to be used for local thread safety */
168 }OMAP5430TESLAPROC_ModuleObject;
171 /* Default memory regions */
172 static UInt32 AddrTable_count = AddrTable_STATIC_COUNT;
174 /* Default memory regions */
175 static ProcMgr_AddrInfo OMAP5430BENELLIPROC_defaultMemRegions [AddrTable_SIZE] =
177 };
179 /* Default memory regions for DSP */
180 static ProcMgr_AddrInfo OMAP5430TESLAPROC_defaultMemRegions [AddrTable_SIZE] =
182 };
184 /* =============================================================================
185  *  Globals
186  * =============================================================================
187  */
188 /*!
189  *  @var    OMAP5430BENELLIPROC_state
190  *
191  *  @brief  OMAP5430BENELLIPROC state object variable
192  */
193 #if !defined(SYSLINK_BUILD_DEBUG)
194 static
195 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
196 OMAP5430BENELLIPROC_ModuleObject OMAP5430IPU0PROC_state =
198     .config_size = sizeof (OMAP5430BENELLIPROC_Config),
199     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
200     .isSetup = FALSE,
201     .procHandle = NULL,
202     .gateHandle = NULL
203 };
205 #ifndef SYSLINK_SYSBIOS_SMP
206 #if !defined(SYSLINK_BUILD_DEBUG)
207 static
208 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
209 OMAP5430BENELLIPROC_ModuleObject OMAP5430IPU1PROC_state =
211     .config_size = sizeof (OMAP5430BENELLIPROC_Config),
212     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
213     .isSetup = FALSE,
214     .procHandle = NULL,
215     .gateHandle = NULL
216 };
217 #endif
219 #if !defined(SYSLINK_BUILD_DEBUG)
220 static
221 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
222 OMAP5430TESLAPROC_ModuleObject OMAP5430DSPPROC_state =
224     .config_size = sizeof (OMAP5430TESLAPROC_Config),
225     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
226     .isSetup = FALSE,
227     .procHandle = NULL,
228     .gateHandle = NULL
229 };
231 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
232 extern String ProcMgr_sysLinkCfgParams;
235 /* =============================================================================
236  * APIs directly called by applications
237  * =============================================================================
238  */
239 /*!
240  *  @brief      Function to get the default configuration for the
241  *              OMAP5430BENELLIPROC module.
242  *
243  *              This function can be called by the application to get their
244  *              configuration parameter to OMAP5430BENELLIPROC_setup filled in by
245  *              the OMAP5430BENELLIPROC module with the default parameters. If
246  *              the user does not wish to make any change in the default
247  *              parameters, this API is not required to be called.
248  *
249  *  @param      cfg        Pointer to the OMAP5430BENELLIPROC module
250  *                         configuration structure in which the default config
251  *                         is to be returned.
252  *
253  *  @sa         OMAP5430BENELLIPROC_setup
254  */
255 Void
256 OMAP5430BENELLIPROC_get_config (OMAP5430BENELLIPROC_Config * cfg, Int ProcType)
258     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_get_config", cfg);
260     GT_assert (curTrace, (cfg != NULL));
262 #if !defined(SYSLINK_BUILD_OPTIMIZE)
263     if (cfg == NULL) {
264         GT_setFailureReason (curTrace,
265                              GT_4CLASS,
266                              "OMAP5430BENELLIPROC_get_config",
267                              PROCESSOR_E_INVALIDARG,
268                              "Argument of type (OMAP5430BENELLIPROC_Config *) "
269                              "passed is null!");
270     }
271     else {
272 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
273         switch (ProcType)
274         {
275             case PROCTYPE_IPU0:
276                 Memory_copy (cfg,
277                              &(OMAP5430IPU0PROC_state.defCfg),
278                              sizeof (OMAP5430BENELLIPROC_Config));
279                 break;
280 #ifndef SYSLINK_SYSBIOS_SMP
281             case PROCTYPE_IPU1:
282                 Memory_copy (cfg,
283                              &(OMAP5430IPU1PROC_state.defCfg),
284                              sizeof (OMAP5430BENELLIPROC_Config));
285             break;
286 #endif
287             case PROCTYPE_DSP:
288                 Memory_copy (cfg,
289                              &(OMAP5430DSPPROC_state.defCfg),
290                              sizeof (OMAP5430TESLAPROC_Config));
291             break;
292         }
293 #if !defined(SYSLINK_BUILD_OPTIMIZE)
294     }
295 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
297     GT_0trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_get_config");
301 /*!
302  *  @brief      Function to setup the OMAP5430BENELLIPROC module.
303  *
304  *              This function sets up the OMAP5430BENELLIPROC module. This
305  *              function must be called before any other instance-level APIs
306  *              can be invoked.
307  *              Module-level configuration needs to be provided to this
308  *              function. If the user wishes to change some specific config
309  *              parameters, then OMAP5430BENELLIPROC_getConfig can be called to
310  *              get the configuration filled with the default values. After
311  *              this, only the required configuration values can be changed. If
312  *              the user does not wish to make any change in the default
313  *              parameters, the application can simply call
314  *              OMAP5430BENELLIPROC_setup with NULL parameters. The default
315  *              parameters would get automatically used.
316  *
317  *  @param      cfg   Optional OMAP5430BENELLIPROC module configuration. If
318  *                    provided as NULL, default configuration is used.
319  *
320  *  @sa         OMAP5430BENELLIPROC_destroy
321  *              GateMutex_create
322  */
323 Int
324 OMAP5430BENELLIPROC_setup (OMAP5430BENELLIPROC_Config * cfg, Int ProcType)
326     Int                                 status  = PROCESSOR_SUCCESS;
327     OMAP5430BENELLIPROC_Config          tmpCfg;
328     OMAP5430BENELLIPROC_ModuleObject *  pState = NULL;
329     Error_Block                         eb;
331     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_setup", cfg);
333     Error_init(&eb);
335     if (cfg == NULL) {
336         OMAP5430BENELLIPROC_get_config (&tmpCfg,ProcType );
337         cfg = &tmpCfg;
338     }
340     switch (ProcType)
341     {
342         case PROCTYPE_IPU0:
343             pState = &OMAP5430IPU0PROC_state;
344             break;
345 #ifndef SYSLINK_SYSBIOS_SMP
346         case PROCTYPE_IPU1:
347             pState = &OMAP5430IPU1PROC_state;
348             break;
349 #endif
350         case PROCTYPE_DSP:
351             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
352             break;
353     }
355     if (pState == NULL) {
356         GT_setFailureReason (curTrace,
357                              GT_4CLASS,
358                              "OMAP5430BENELLIPROC_setup",
359                              PROCESSOR_E_INVALIDARG,
360                              "Unsupported procType");
361         return PROCESSOR_E_INVALIDARG;
362     }
364     /* Create a default gate handle for local module protection. */
365     pState->gateHandle = (IGateProvider_Handle)
366                                GateMutex_create ((GateMutex_Params *)NULL, &eb);
367 #if !defined(SYSLINK_BUILD_OPTIMIZE)
368     if (pState->gateHandle == NULL) {
369         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
370         status = PROCESSOR_E_FAIL;
371         GT_setFailureReason (curTrace,
372                              GT_4CLASS,
373                              "OMAP5430BENELLIPROC_setup",
374                              status,
375                              "Failed to create GateMutex!");
376     }
377     else {
378 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
379         /* Copy the user provided values into the state object. */
380         Memory_copy (&pState->cfg,
381                      cfg,
382                      sizeof (OMAP5430BENELLIPROC_Config));
384         /* Initialize the name to handles mapping array. */
385         pState->procHandle = NULL;
387         pState->isSetup = TRUE;
388 #if !defined(SYSLINK_BUILD_OPTIMIZE)
389     }
390 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
392     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_setup", status);
394     /*! @retval PROCESSOR_SUCCESS Operation successful */
395     return (status);
399 /*!
400  *  @brief      Function to destroy the OMAP5430BENELLIPROC module.
401  *
402  *              Once this function is called, other OMAP5430BENELLIPROC module
403  *              APIs, except for the OMAP5430BENELLIPROC_getConfig API cannot be
404  *              called anymore.
405  *
406  *  @sa         OMAP5430BENELLIPROC_setup
407  *              GateMutex_delete
408  */
409 Int
410 OMAP5430BENELLIPROC_destroy (Int ProcType)
412     Int                                 status  = PROCESSOR_SUCCESS;
413     OMAP5430BENELLIPROC_ModuleObject *  pState = NULL;
415     GT_0trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_destroy");
417     switch(ProcType)
418     {
419         case PROCTYPE_IPU0:
420             pState = &OMAP5430IPU0PROC_state;
421             break;
422 #ifndef SYSLINK_SYSBIOS_SMP
423         case PROCTYPE_IPU1:
424             pState = &OMAP5430IPU1PROC_state;
425             break;
426 #endif
427         case PROCTYPE_DSP:
428             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
429             break;
430     }
432     if (pState == NULL) {
433         GT_setFailureReason (curTrace,
434                              GT_4CLASS,
435                              "OMAP5430BENELLIPROC_setup",
436                              PROCESSOR_E_INVALIDARG,
437                              "Unsupported procType");
438         return PROCESSOR_E_INVALIDARG;
439     }
441     /* Check if any OMAP5430BENELLIPROC instances have not been deleted so far.
442      * If not, delete them.
443      */
444     if (pState->procHandle != NULL) {
445         OMAP5430BENELLIPROC_delete(&pState->procHandle);
446     }
448     if (pState->gateHandle != NULL) {
449         GateMutex_delete ((GateMutex_Handle *)
450                                 &(pState->gateHandle));
451     }
453     pState->isSetup = FALSE;
455     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_destroy", status);
457     /*! @retval PROCESSOR_SUCCESS Operation successful */
458     return (status);
462 /*!
463  *  @brief      Function to initialize the parameters for this Processor
464  *              instance.
465  *
466  *  @param      params  Configuration parameters to be returned
467  *
468  *  @sa         OMAP5430BENELLIPROC_create
469  */
470 Void
471 OMAP5430BENELLIPROC_Params_init (OMAP5430BENELLIPROC_Handle  handle,
472                                 OMAP5430BENELLIPROC_Params * params,
473                                 Int ProcType)
475     OMAP5430BENELLIPROC_Object * procObject =
476                                           (OMAP5430BENELLIPROC_Object *) handle;
477     UInt32                      numMemEntries   = 0;
478     ProcMgr_AddrInfo *          pMemRegn        = NULL;
480     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_Params_init",
481                handle, params);
483     GT_assert (curTrace, (params != NULL));
484     switch(ProcType)
485     {
486         case PROCTYPE_IPU0:
487             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
488             numMemEntries = AddrTable_count;
489             break;
490 #ifndef SYSLINK_SYSBIOS_SMP
491         case PROCTYPE_IPU1:
492             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
493             numMemEntries = AddrTable_count;
494             break;
495 #endif
496         case PROCTYPE_DSP:
497             pMemRegn = OMAP5430TESLAPROC_defaultMemRegions;
498             numMemEntries = AddrTable_count;
499             break;
500     }
502 #if !defined(SYSLINK_BUILD_OPTIMIZE)
503     if (params == NULL) {
504         GT_setFailureReason (curTrace,
505                              GT_4CLASS,
506                              "OMAP5430BENELLIPROC_Params_init",
507                              PROCESSOR_E_INVALIDARG,
508                              "Argument of type (OMAP5430BENELLIPROC_Params *) "
509                              "passed is null!");
510     }
511     else {
512 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
513         if (handle == NULL) {
514             params->numMemEntries =  numMemEntries;
515             Memory_copy ((Ptr) params->memEntries,
516                          pMemRegn,
517                          (sizeof(ProcMgr_AddrInfo) * params->numMemEntries));
518         }
519         else {
520             /* Return updated OMAP5430BENELLIPROC instance specific parameters. */
521             Memory_copy (params,
522                          &(procObject->params),
523                          sizeof (OMAP5430BENELLIPROC_Params));
524         }
525 #if !defined(SYSLINK_BUILD_OPTIMIZE)
526     }
527 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
529     GT_0trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_Params_init");
532 /*!
533  *  @brief      Function to create an instance of this Processor.
534  *
535  *  @param      name    Name of the Processor instance.
536  *  @param      params  Configuration parameters.
537  *
538  *  @sa         OMAP5430BENELLIPROC_delete
539  */
541 OMAP5430BENELLIPROC_Handle
542 OMAP5430BENELLIPROC_create (UInt16 procId,
543                             const OMAP5430BENELLIPROC_Params * params)
545 #if !defined(SYSLINK_BUILD_OPTIMIZE)
546     Int                                 status    = PROCESSOR_SUCCESS;
547 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
548     Processor_Object *                  handle    = NULL;
549     OMAP5430BENELLIPROC_Object *        object    = NULL;
550     IArg                                key;
551     OMAP5430BENELLIPROC_ModuleObject *  pState    = NULL;
552     List_Params                         listParams;
554     switch(procId)
555     {
556         case PROCTYPE_IPU0:
557             pState = &OMAP5430IPU0PROC_state;
558             break;
559 #ifndef SYSLINK_SYSBIOS_SMP
560         case PROCTYPE_IPU1:
561             pState = &OMAP5430IPU1PROC_state;
562             break;
563 #endif
564         case PROCTYPE_DSP:
565             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
566             break;
567     }
569     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_create", procId, params);
571     GT_assert (curTrace, IS_VALID_PROCID (procId));
572     GT_assert (curTrace, (params != NULL));
574 #if !defined(SYSLINK_BUILD_OPTIMIZE)
575     if (pState == NULL) {
576         /* Not setting status here since this function does not return status.*/
577         GT_setFailureReason (curTrace,
578                              GT_4CLASS,
579                              "OMAP5430BENELLIPROC_create",
580                              PROCESSOR_E_INVALIDARG,
581                              "Invalid procId specified");
582     }
583     else if (params == NULL) {
584         GT_setFailureReason (curTrace,
585                              GT_4CLASS,
586                              "OMAP5430BENELLIPROC_create",
587                              PROCESSOR_E_INVALIDARG,
588                              "params passed is NULL!");
589     }
590     else {
591 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
592         /* Enter critical section protection. */
593         key = IGateProvider_enter (pState->gateHandle);
594 #if !defined(SYSLINK_BUILD_OPTIMIZE)
595         /* Check if the Processor already exists for specified procId. */
596         if (pState->procHandle!= NULL) {
597             status = PROCESSOR_E_ALREADYEXIST;
598             GT_setFailureReason (curTrace,
599                               GT_4CLASS,
600                               "OMAP5430BENELLIPROC_create",
601                               status,
602                               "Processor already exists for specified procId!");
603         }
604         else {
605 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
606             /* Allocate memory for the handle */
607             handle = (Processor_Object *) Memory_calloc (NULL,
608                                                       sizeof (Processor_Object),
609                                                       0,
610                                                       NULL);
611 #if !defined(SYSLINK_BUILD_OPTIMIZE)
612             if (handle == NULL) {
613                 GT_setFailureReason (curTrace,
614                                      GT_4CLASS,
615                                      "OMAP5430BENELLIPROC_create",
616                                      PROCESSOR_E_MEMORY,
617                                      "Memory allocation failed for handle!");
618             }
619             else {
620 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
621                 /* Populate the handle fields */
622                 handle->procFxnTable.attach      = &OMAP5430BENELLIPROC_attach;
623                 handle->procFxnTable.detach      = &OMAP5430BENELLIPROC_detach;
624                 handle->procFxnTable.start       = &OMAP5430BENELLIPROC_start;
625                 handle->procFxnTable.stop        = &OMAP5430BENELLIPROC_stop;
626                 handle->procFxnTable.read        = &OMAP5430BENELLIPROC_read;
627                 handle->procFxnTable.write       = &OMAP5430BENELLIPROC_write;
628                 handle->procFxnTable.control     = &OMAP5430BENELLIPROC_control;
629                 handle->procFxnTable.map         = &OMAP5430BENELLIPROC_map;
630                 handle->procFxnTable.unmap       = &OMAP5430BENELLIPROC_unmap;
631                 handle->procFxnTable.translateAddr = &OMAP5430BENELLIPROC_translate;
632                 handle->procFxnTable.virtToPhys  = &OMAP5430BENELLI_virtToPhys;
633                 handle->procFxnTable.getProcInfo = &OMAP5430BENELLIPROC_procInfo;
634                 handle->state = ProcMgr_State_Unknown;
636                 /* Allocate memory for the OMAP5430BENELLIPROC handle */
637                 handle->object = Memory_calloc (NULL,
638                                              sizeof (OMAP5430BENELLIPROC_Object),
639                                              0,
640                                              NULL);
641 #if !defined(SYSLINK_BUILD_OPTIMIZE)
642                 if (handle->object == NULL) {
643                     status = PROCESSOR_E_MEMORY;
644                     GT_setFailureReason (curTrace,
645                                 GT_4CLASS,
646                                 "OMAP5430BENELLIPROC_create",
647                                 status,
648                                 "Memory allocation failed for handle->object!");
649                 }
650                 else {
651 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
652                     handle->procId = procId;
653                     object = (OMAP5430BENELLIPROC_Object *) handle->object;
654                     object->halObject = NULL;
655                     object->procHandle = (Processor_Handle)handle;
656                     /* Copy params into instance object. */
657                     Memory_copy (&(object->params),
658                                  (Ptr) params,
659                                  sizeof (OMAP5430BENELLIPROC_Params));
660                     object->params.procHandle = object->procHandle;
662                     /* Set the handle in the state object. */
663                     pState->procHandle = handle->object;
665                     /* Initialize the list of listeners */
666                     List_Params_init(&listParams);
667                     handle->registeredNotifiers = List_create(&listParams);
669 #if !defined(SYSLINK_BUILD_OPTIMIZE)
670                     if (handle->registeredNotifiers == NULL) {
671                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
672                         status = PROCESSOR_E_FAIL;
673                         GT_setFailureReason (curTrace,
674                                              GT_4CLASS,
675                                              "OMAP5430BENELLIPROC_create",
676                                              status,
677                                              "List_create failed");
678                     }
679                     else {
680 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
682                         handle->notifiersLock =
683                                  OsalMutex_create(OsalMutex_Type_Interruptible);
685 #if !defined(SYSLINK_BUILD_OPTIMIZE)
686                         if (handle->notifiersLock == NULL) {
687                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
688                             status = PROCESSOR_E_FAIL;
689                             GT_setFailureReason (curTrace,
690                                                  GT_4CLASS,
691                                                  "OMAP5430BENELLIPROC_create",
692                                                  status,
693                                                  "OsalMutex_create failed");
694                         }
695                     }
696                 }
697             }
698         }
699 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
701         /* Leave critical section protection. */
702         IGateProvider_leave (pState->gateHandle, key);
703 #if !defined(SYSLINK_BUILD_OPTIMIZE)
704     }
705 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
707 #if !defined(SYSLINK_BUILD_OPTIMIZE)
708     if (status < 0) {
709         if (handle !=  NULL) {
710             if (handle->registeredNotifiers != NULL) {
711                 List_delete (&handle->registeredNotifiers);
712             }
713             if (handle->object != NULL) {
714                 Memory_free (NULL,
715                              handle->object,
716                              sizeof (OMAP5430BENELLIPROC_Object));
717             }
718             Memory_free (NULL, handle, sizeof (Processor_Object));
719         }
720         /*! @retval NULL Function failed */
721         handle = NULL;
722     }
723 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
725     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_create", handle);
727     /*! @retval Valid-Handle Operation successful */
728     return (void*) handle;
732 /*!
733  *  @brief      Function to delete an instance of this Processor.
734  *
735  *              The user provided pointer to the handle is reset after
736  *              successful completion of this function.
737  *
738  *  @param      handlePtr  Pointer to Handle to the Processor instance
739  *
740  *  @sa         OMAP5430BENELLIPROC_create
741  */
742 Int
743 OMAP5430BENELLIPROC_delete (OMAP5430BENELLIPROC_Handle * handlePtr)
745     Int                                 status  = PROCESSOR_SUCCESS;
746     OMAP5430BENELLIPROC_Object *        object  = NULL;
747     Processor_Object *                  handle  = NULL;
748     IArg                                key     = NULL;
749     OMAP5430BENELLIPROC_ModuleObject *  pState  = NULL;
750     List_Elem *                         elem    = NULL;
751     Processor_RegisterElem *            regElem = NULL;
754     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_delete", handlePtr);
756     GT_assert (curTrace, (handlePtr != NULL));
757     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
759 #if !defined(SYSLINK_BUILD_OPTIMIZE)
760     if (handlePtr == NULL) {
761         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
762                                          specified*/
763         status = PROCESSOR_E_INVALIDARG;
764         GT_setFailureReason (curTrace,
765                              GT_4CLASS,
766                              "OMAP5430BENELLIPROC_delete",
767                              status,
768                              "Invalid NULL handlePtr pointer specified");
769     }
770     else if (*handlePtr == NULL) {
771         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
772         status = PROCESSOR_E_HANDLE;
773         GT_setFailureReason (curTrace,
774                              GT_4CLASS,
775                              "OMAP5430BENELLIPROC_delete",
776                              status,
777                              "Invalid NULL *handlePtr specified");
778     }
779     else {
780 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
781         handle = (Processor_Object *) (*handlePtr);
782         /* Enter critical section protection. */
783         if (handle->object != NULL) {
784             object = (OMAP5430BENELLIPROC_Object *) handle->object;
785             switch (handle->procId)
786             {
787                 case PROCTYPE_IPU0:
788                     pState = &OMAP5430IPU0PROC_state;
789                     break;
790 #ifndef SYSLINK_SYSBIOS_SMP
791                 case PROCTYPE_IPU1:
792                     pState = &OMAP5430IPU1PROC_state;
793                     break;
794 #endif
795                 case PROCTYPE_DSP:
796                     pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
797                     break;
798             }
799         }
800 #if !defined(SYSLINK_BUILD_OPTIMIZE)
801         if (pState == NULL) {
802             GT_setFailureReason (curTrace,
803                                  GT_4CLASS,
804                                  "OMAP5430BENELLIPROC_delete",
805                                  PROCESSOR_E_INVALIDARG,
806                                  "Unsupported procType");
807             return PROCESSOR_E_INVALIDARG;
808         }
809 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
811         key = IGateProvider_enter (pState->gateHandle);
813         /* Reset handle in PwrMgr handle array. */
814         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
815         pState->procHandle = NULL;
817         /* Free memory used for the PROC object. */
818         Memory_free (NULL,
819                      handle->object,
820                      sizeof (Ptr));
821         handle->object = NULL;
823         /*
824          * Check the list of listeners to see if any are remaining
825          * and reply to them
826          */
827         OsalMutex_delete(&handle->notifiersLock);
829         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
830             regElem = (Processor_RegisterElem *)elem;
832             /* Check if there is an associated timer and cancel it */
833             if (regElem->timer != -1) {
834                 struct itimerspec value ;
835                 value.it_value.tv_sec = 0;
836                 value.it_value.tv_nsec = 0;
837                 value.it_interval.tv_sec = 0;
838                 value.it_interval.tv_nsec = 0;
839                 timer_settime(regElem->timer, 0, &value, NULL);
841                 timer_delete(regElem->timer);
842                 regElem->timer = -1;
843             }
845             /* Call the callback function so it can clean up. */
846             regElem->info->cbFxn(handle->procId,
847                                  NULL,
848                                  handle->state,
849                                  handle->state,
850                                  ProcMgr_EventStatus_Canceled,
851                                  regElem->info->arg);
852             /* Free the memory */
853             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
854         }
856         /* Delete the list of listeners */
857         List_delete(&handle->registeredNotifiers);
859         /* Free memory used for the Processor object. */
860         Memory_free (NULL, handle, sizeof (Processor_Object));
861         *handlePtr = NULL;
863         /* Leave critical section protection. */
864         IGateProvider_leave (pState->gateHandle, key);
865 #if !defined(SYSLINK_BUILD_OPTIMIZE)
866     }
867 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
869     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_delete", status);
871     /*! @retval PROCESSOR_SUCCESS Operation successful */
872     return (status);
876 /*!
877  *  @brief      Function to open a handle to an instance of this Processor. This
878  *              function is called when access to the Processor is required from
879  *              a different process.
880  *
881  *  @param      handlePtr   Handle to the Processor instance
882  *  @param      procId      Processor ID addressed by this Processor instance.
883  *
884  *  @sa         OMAP5430BENELLIPROC_close
885  */
886 Int
887 OMAP5430BENELLIPROC_open (OMAP5430BENELLIPROC_Handle * handlePtr, UInt16 procId)
889     Int                                 status  = PROCESSOR_SUCCESS;
890     OMAP5430BENELLIPROC_ModuleObject *  pState  = NULL;
892     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_open",
893                handlePtr, procId);
895     GT_assert (curTrace, (handlePtr != NULL));
896     GT_assert (curTrace, IS_VALID_PROCID (procId));
898     switch(procId)
899     {
900         case PROCTYPE_IPU0:
901             pState = &OMAP5430IPU0PROC_state;
902             break;
903 #ifndef SYSLINK_SYSBIOS_SMP
904         case PROCTYPE_IPU1:
905             pState = &OMAP5430IPU1PROC_state;
906             break;
907 #endif
908         case PROCTYPE_DSP:
909             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
910             break;
911     }
913 #if !defined(SYSLINK_BUILD_OPTIMIZE)
914     if (handlePtr == NULL) {
915         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
916         status = PROCESSOR_E_HANDLE;
917         GT_setFailureReason (curTrace,
918                              GT_4CLASS,
919                              "OMAP5430BENELLIPROC_open",
920                              status,
921                              "Invalid NULL handlePtr specified");
922     }
923     else if (pState == NULL) {
924         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
925         status = PROCESSOR_E_INVALIDARG;
926         GT_setFailureReason (curTrace,
927                              GT_4CLASS,
928                              "OMAP5430BENELLIPROC_open",
929                              status,
930                              "Invalid procId specified");
931     }
932     else {
933 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
934         /* Initialize return parameter handle. */
935         *handlePtr = NULL;
937         /* Check if the PwrMgr exists and return the handle if found. */
938         if (pState->procHandle == NULL) {
939             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
940             status = PROCESSOR_E_NOTFOUND;
941             GT_setFailureReason (curTrace,
942                              GT_4CLASS,
943                              "OMAP5430BENELLIPROC_open",
944                              status,
945                              "Specified instance does not exist!");
946         }
947         else {
948             *handlePtr = pState->procHandle;
949         }
950 #if !defined(SYSLINK_BUILD_OPTIMIZE)
951     }
952 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
954     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_open", status);
956     /*! @retval PROCESSOR_SUCCESS Operation successful */
957     return status;
961 /*!
962  *  @brief      Function to close a handle to an instance of this Processor.
963  *
964  *  @param      handlePtr  Pointer to Handle to the Processor instance
965  *
966  *  @sa         OMAP5430BENELLIPROC_open
967  */
968 Int
969 OMAP5430BENELLIPROC_close (OMAP5430BENELLIPROC_Handle * handlePtr)
971     Int status = PROCESSOR_SUCCESS;
973     GT_1trace (curTrace, GT_ENTER, "OMAP5430M3VIDEOPROC_close", handlePtr);
975     GT_assert (curTrace, (handlePtr != NULL));
976     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
978 #if !defined(SYSLINK_BUILD_OPTIMIZE)
979     if (handlePtr == NULL) {
980         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
981                                          specified*/
982         status = PROCESSOR_E_INVALIDARG;
983         GT_setFailureReason (curTrace,
984                              GT_4CLASS,
985                              "OMAP5430BENELLIPROC_close",
986                              status,
987                              "Invalid NULL handlePtr pointer specified");
988     }
989     else if (*handlePtr == NULL) {
990         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
991         status = PROCESSOR_E_HANDLE;
992         GT_setFailureReason (curTrace,
993                              GT_4CLASS,
994                              "OMAP5430BENELLIPROC_close",
995                              status,
996                              "Invalid NULL *handlePtr specified");
997     }
998     else {
999 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1000         /* Nothing to be done for close. */
1001 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1002     }
1003 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1005     GT_1trace (curTrace, GT_LEAVE, "OMAP5430M3VIDEOPROC_close", status);
1007     /*! @retval PROCESSOR_SUCCESS Operation successful */
1008     return status;
1012 /* =============================================================================
1013  * APIs called by Processor module (part of function table interface)
1014  * =============================================================================
1015  */
1016 /*!
1017  *  @brief      Function to initialize the slave processor
1018  *
1019  *  @param      handle  Handle to the Processor instance
1020  *  @param      params  Attach parameters
1021  *
1022  *  @sa         OMAP5430BENELLIPROC_detach
1023  */
1024 Int
1025 OMAP5430BENELLIPROC_attach (Processor_Handle        handle,
1026                            Processor_AttachParams * params)
1029     Int                            status       = PROCESSOR_SUCCESS ;
1030     Processor_Object *             procHandle   = (Processor_Object *) handle;
1031     OMAP5430BENELLIPROC_Object *   object       = NULL;
1032     ProcMgr_AddrInfo *             me;
1033     OMAP5430BENELLIPROC_ModuleObject *      pState;
1034     OMAP5430BENELLI_HalMmuCtrlArgs_Enable   enableArgs;
1035     UInt32                      i = 0;
1036     UInt32                      index = 0;
1037     SysLink_MemEntry *          entry;
1038     SysLink_MemEntry_Block      memBlock;
1039     Char                        configProp[SYSLINK_MAX_NAMELENGTH];
1040     ProcMgr_AddrInfo *          pMemRegn        = NULL;
1042     GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_attach", handle, params);
1044     GT_assert (curTrace, (handle != NULL));
1045     GT_assert (curTrace, (params != NULL));
1047     switch(procHandle->procId)
1048     {
1049         case PROCTYPE_IPU0:
1050             pState = &OMAP5430IPU0PROC_state;
1051             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1052             break;
1053 #ifndef SYSLINK_SYSBIOS_SMP
1054         case PROCTYPE_IPU1:
1055             pState = &OMAP5430IPU1PROC_state;
1056             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1057             break;
1058 #endif
1059         case PROCTYPE_DSP:
1060             pState = (OMAP5430BENELLIPROC_ModuleObject *)&OMAP5430DSPPROC_state;
1061             pMemRegn = OMAP5430TESLAPROC_defaultMemRegions;
1062             break;
1063     }
1065 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1066     if (handle == NULL) {
1067         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1068         status = PROCESSOR_E_HANDLE;
1069         GT_setFailureReason (curTrace,
1070                              GT_4CLASS,
1071                              "OMAP5430BENELLIPROC_attach",
1072                              status,
1073                              "Invalid handle specified");
1074     }
1075     else if (params == NULL) {
1076             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1077             status = PROCESSOR_E_INVALIDARG;
1078             GT_setFailureReason (curTrace,
1079                                  GT_4CLASS,
1080                                  "OMAP5430BENELLIPROC_attach",
1081                                  status,
1082                                  "Invalid params specified");
1083     }
1084     else {
1085 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1086         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1087         GT_assert (curTrace, (object != NULL));
1089         /* Added for Netra Benelli core0 is cortex M3 */
1090         params->procArch = Processor_ProcArch_M3;
1091         GT_0trace (curTrace,
1092                    GT_2CLASS,
1093                    "    OMAP5430BENELLIPROC_attach: Mapping memory regions");
1095         /* check for carveout params override */
1096         if (procHandle->procId == PROCTYPE_DSP) {
1097             Cfg_prop(PARAMS_carveoutAddr0DSP, ProcMgr_sysLinkCfgParams, configProp);
1098             object->params.carveoutAddr[0] = strtoul(configProp, 0, 16);
1099             Cfg_prop(PARAMS_carveoutSize0DSP, ProcMgr_sysLinkCfgParams, configProp);
1100             object->params.carveoutSize[0] = strtoul(configProp, 0, 16);
1101         }
1102         else {
1103             Cfg_prop(PARAMS_carveoutAddr0, ProcMgr_sysLinkCfgParams, configProp);
1104             object->params.carveoutAddr[0] = strtoul(configProp, 0, 16);
1105             Cfg_prop(PARAMS_carveoutSize0, ProcMgr_sysLinkCfgParams, configProp);
1106             object->params.carveoutSize[0] = strtoul(configProp, 0, 16);
1107         }
1109         object->pmHandle = params->pmHandle;
1110         GT_0trace(curTrace, GT_1CLASS,
1111             "OMAP5430BENELLIPROC_attach: Mapping memory regions");
1113         /* search for dsp memory map */
1114         status = RscTable_process(procHandle->procId, TRUE, NumCarveouts,
1115                                   (Ptr)object->params.carveoutAddr,
1116                                   object->params.carveoutSize, TRUE,
1117                                   &memBlock.numEntries);
1118         if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
1119             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1120             status = PROCESSOR_E_INVALIDARG;
1121             GT_setFailureReason (curTrace,
1122                                  GT_4CLASS,
1123                                  "OMAP5430BENELLIPROC_attach",
1124                                  status,
1125                                  "Failed to process resource table");
1126         }
1127         else {
1128             status = RscTable_getMemEntries(procHandle->procId,
1129                                             memBlock.memEntries,
1130                                             &memBlock.numEntries);
1131             if (status < 0) {
1132                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1133                 status = PROCESSOR_E_INVALIDARG;
1134                 GT_setFailureReason (curTrace,
1135                                      GT_4CLASS,
1136                                      "OMAP5430BENELLIPROC_attach",
1137                                      status,
1138                                      "Failed to get resource table memEntries");
1139             }
1140         }
1142         /* update translation tables with memory map */
1143         for (i = 0; (i < memBlock.numEntries)
1144             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
1146             entry = &memBlock.memEntries[i];
1148             if (entry->map == FALSE) {
1149                 /* update table with entries which don't require mapping */
1150                 if (AddrTable_count != AddrTable_SIZE) {
1151                     me = &pMemRegn[AddrTable_count];
1153                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1154                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1155                     me->addr[ProcMgr_AddrType_MasterPhys] =
1156                             entry->masterPhysAddr;
1157                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1158                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1159                     me->size = entry->size;
1160                     me->isCached = entry->isCached;
1161                     me->mapMask = entry->mapMask;
1163                     AddrTable_count++;
1164                 }
1165                 else {
1166                     status = PROCESSOR_E_FAIL;
1167                     GT_setFailureReason(curTrace, GT_4CLASS,
1168                         "OMAP5430BENELLIPROC_attach", status,
1169                         "AddrTable_SIZE reached!");
1170                 }
1171             }
1172             else if (entry->map == TRUE) {
1173                 /* send these entries back to ProcMgr for mapping */
1174                 index = object->params.numMemEntries;
1176                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
1177                     me = &object->params.memEntries[index];
1179                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1180                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1181                     me->addr[ProcMgr_AddrType_MasterPhys] =
1182                             entry->masterPhysAddr;
1183                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1184                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1185                     me->size = entry->size;
1186                     me->isCached = entry->isCached;
1187                     me->mapMask = entry->mapMask;
1189                     object->params.numMemEntries++;
1190                 }
1191                 else {
1192                     status = PROCESSOR_E_FAIL;
1193                     GT_setFailureReason(curTrace, GT_4CLASS,
1194                         "OMAP5430BENELLIPROC_attach", status,
1195                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
1196                 }
1197             }
1198             else {
1199                 status = PROCESSOR_E_INVALIDARG;
1200                 GT_setFailureReason(curTrace, GT_4CLASS,
1201                     "OMAP5430BENELLIPROC_attach", status,
1202                     "Memory map has entry with invalid 'map' value");
1203             }
1204         } /* for (...) */
1206         if (status >= 0) {
1207             /* populate the return params */
1208             params->numMemEntries = object->params.numMemEntries;
1209             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1210                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1212             status = OMAP5430BENELLI_halInit (&(object->halObject),
1213                                               &object->params,
1214                                               procHandle->procId);
1215 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1216             if (status < 0) {
1217                 GT_setFailureReason (curTrace,
1218                                      GT_4CLASS,
1219                                      "OMAP5430BENELLIPROC_attach",
1220                                      status,
1221                                      "OMAP5430BENELLI_halInit failed");
1222             }
1223             else {
1224 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1226                 if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1227                     ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1229 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1230                     if (status < 0) {
1231                         GT_setFailureReason (curTrace,
1232                                              GT_4CLASS,
1233                                              "OMAP5430BENELLIPROC_attach",
1234                                              status,
1235                                          "Failed to reset the slave processor");
1236                     }
1237                     else {
1238 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1239                         GT_0trace (curTrace,
1240                                  GT_1CLASS,
1241                                  "    OMAP5430BENELLIPROC_attach: Slave is now "
1242                                  "in reset!");
1244                         if (procHandle->procId == PROCTYPE_IPU0 ||
1245                             procHandle->procId == PROCTYPE_DSP) {
1246                             /* Enable MMU */
1247                             GT_0trace (curTrace,
1248                                        GT_2CLASS,
1249                                        "OMAP5430BENELLIPROC_attach: "
1250                                        "Enabling Slave MMU ...");
1251                             enableArgs.memEntries = NULL;
1252                             enableArgs.numMemEntries = 0;
1253                             status = OMAP5430BENELLI_halMmuCtrl (
1254                                                     object->halObject,
1255                                                     Processor_MmuCtrlCmd_Enable,
1256                                                     &enableArgs);
1257 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1258                             if (status < 0) {
1259                                 GT_setFailureReason (curTrace,
1260                                               GT_4CLASS,
1261                                               "OMAP5430BENELLIPROC_attach",
1262                                               status,
1263                                               "Failed to enable the slave MMU");
1264                             }
1265                         }
1266                     }
1267 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1268                 }
1269             }
1270 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1271         }
1272     }
1273 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1275     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_attach",status);
1277     /*! @retval PROCESSOR_SUCCESS Operation successful */
1278     return status;
1283 /*!
1284  *  @brief      Function to detach from the Processor.
1285  *
1286  *  @param      handle  Handle to the Processor instance
1287  *
1288  *  @sa         OMAP5430BENELLIPROC_attach
1289  */
1290 Int
1291 OMAP5430BENELLIPROC_detach (Processor_Handle handle)
1293     Int                       status     = PROCESSOR_SUCCESS;
1294     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1295     Processor_Object *        procHandle = (Processor_Object *) handle;
1296     OMAP5430BENELLIPROC_Object * object   = NULL;
1297     Int i                              = 0;
1298     ProcMgr_AddrInfo *    ai;
1299     ProcMgr_AddrInfo *          pMemRegn        = NULL;
1301     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_detach", handle);
1303     GT_assert (curTrace, (handle != NULL));
1305     switch(procHandle->procId)
1306     {
1307         case PROCTYPE_IPU0:
1308             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1309             break;
1310 #ifndef SYSLINK_SYSBIOS_SMP
1311         case PROCTYPE_IPU1:
1312             pMemRegn = OMAP5430BENELLIPROC_defaultMemRegions;
1313             break;
1314 #endif
1315         case PROCTYPE_DSP:
1316             pMemRegn = OMAP5430TESLAPROC_defaultMemRegions;
1317             break;
1318     }
1320 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1321     if (handle == NULL) {
1322         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1323         status = PROCESSOR_E_HANDLE;
1324         GT_setFailureReason (curTrace,
1325                              GT_4CLASS,
1326                              "OMAP5430BENELLIPROC_detach",
1327                              PROCESSOR_E_HANDLE,
1328                              "Invalid handle specified");
1329     }
1330     else {
1331 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1332         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1333         GT_assert (curTrace, (object != NULL));
1335         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1336             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1337             if (procHandle->procId == PROCTYPE_IPU0 ||
1338                 procHandle->procId == PROCTYPE_DSP) {
1339                 /* Disable MMU */
1340                 GT_0trace (curTrace,
1341                            GT_2CLASS,
1342                            "    OMAP5430BENELLIPROC_detach: "
1343                            "Disabling Slave MMU ...");
1344                 status = OMAP5430BENELLI_halMmuCtrl (object->halObject,
1345                                                    Processor_MmuCtrlCmd_Disable,
1346                                                    NULL);
1347 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1348                 if (status < 0) {
1349                     GT_setFailureReason (curTrace,
1350                                          GT_4CLASS,
1351                                          "OMAP5430BENELLIPROC_detach",
1352                                          status,
1353                                          "Failed to disable the slave MMU");
1354                 }
1355 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1356             }
1358             /* delete all dynamically added entries */
1359             for (i = AddrTable_STATIC_COUNT; i < AddrTable_count; i++) {
1360                 ai = &pMemRegn[i];
1361                 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1362                 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1363                 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1364                 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1365                 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1366                 ai->size = 0u;
1367                 ai->isCached = FALSE;
1368                 ai->mapMask = 0u;
1369                 ai->isMapped = FALSE;
1370                 ai->refCount = 0u;
1371             }
1372             object->params.numMemEntries = AddrTable_STATIC_COUNT;
1373             AddrTable_count = AddrTable_STATIC_COUNT;
1375             //No need to reset.. that will be done in STOP
1376            /* tmpStatus = OMAP5430BENELLI_halResetCtrl (object->halObject,
1377                                                    Processor_ResetCtrlCmd_Reset,
1378                                                    NULL);
1379             GT_0trace (curTrace,
1380                        GT_2CLASS,
1381                        "    OMAP5430BENELLIPROC_detach: Slave processor is "
1382                        "now in reset");*/
1383 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1384             if ((tmpStatus < 0) && (status >= 0)) {
1385                 status = tmpStatus;
1386                 GT_setFailureReason (curTrace,
1387                                      GT_4CLASS,
1388                                      "OMAP5430BENELLIPROC_detach",
1389                                      status,
1390                                      "Failed to reset the slave processor");
1391             }
1392 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1393         }
1395         GT_0trace (curTrace,
1396                    GT_2CLASS,
1397                    "    OMAP5430BENELLIPROC_detach: Unmapping memory regions");
1399         tmpStatus = OMAP5430BENELLI_halExit(object->halObject, &object->params);
1400 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1401         if ((tmpStatus < 0) && (status >= 0)) {
1402             status = tmpStatus;
1403             GT_setFailureReason (curTrace,
1404                                  GT_4CLASS,
1405                                  "OMAP5430BENELLIPROC_detach",
1406                                  status,
1407                                  "Failed to finalize HAL object");
1408         }
1409     }
1410 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1412     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_detach", status);
1414     /*! @retval PROCESSOR_SUCCESS Operation successful */
1415     return status;
1419 /*!
1420  *  @brief      Function to start the slave processor
1421  *
1422  *              Start the slave processor running from its entry point.
1423  *              Depending on the boot mode, this involves configuring the boot
1424  *              address and releasing the slave from reset.
1425  *
1426  *  @param      handle    Handle to the Processor instance
1427  *
1428  *  @sa         OMAP5430BENELLIPROC_stop, OMAP5430BENELLIPROC_halBootCtrl,
1429  *              OMAP5430BENELLIPROC_halResetCtrl
1430  */
1431 Int
1432 OMAP5430BENELLIPROC_start (Processor_Handle        handle,
1433                            UInt32                  entryPt,
1434                            Processor_StartParams * params)
1436     Int                           status       = PROCESSOR_SUCCESS ;
1437     Processor_Object *            procHandle   = (Processor_Object *) handle;
1438     OMAP5430BENELLIPROC_Object  * object       = procHandle->object;
1439     Memory_MapInfo        sysCtrlMapInfo;
1440     Memory_UnmapInfo      sysCtrlUnmapInfo;
1442     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_start",
1443                handle, entryPt, params);
1445     GT_assert (curTrace, (handle != NULL));
1446     GT_assert (curTrace, (params != NULL));
1448 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1449     if (handle == NULL) {
1450         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1451         status = PROCESSOR_E_HANDLE;
1452         GT_setFailureReason (curTrace,
1453                              GT_4CLASS,
1454                              "OMAP5430BENELLIPROC_start",
1455                              status,
1456                              "Invalid handle specified");
1457     }
1458     else if (params == NULL) {
1459             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1460             status = PROCESSOR_E_INVALIDARG;
1461             GT_setFailureReason (curTrace,
1462                                  GT_4CLASS,
1463                                  "OMAP5430BENELLIPROC_start",
1464                                  status,
1465                                  "Invalid params specified");
1466     }
1467     else {
1468 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1469         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1470                                              Processor_ResetCtrlCmd_MMU_Release,
1471                                              entryPt);
1472         if (status < 0) {
1473             /*! @retval status */
1474             GT_setFailureReason (curTrace,
1475                                  GT_4CLASS,
1476                                  "OMAP5430BENELLI_halResetCtrl",
1477                                  status,
1478                                  "Reset MMU_Release failed");
1479         }
1480         else {
1481             if(handle->procId != MultiProc_getId("DSP"))
1482                 status = ipu_setup(object->halObject, object->params.memEntries,
1483                                    object->params.numMemEntries);
1484             else
1485                 status = tesla_setup(object->halObject,
1486                                      object->params.memEntries,
1487                                      object->params.numMemEntries);
1488             if (status < 0) {
1489                 /*! @retval status */
1490                 GT_setFailureReason (curTrace,
1491                                      GT_4CLASS,
1492                                      "OMAP5430BENELLI_halResetCtrl",
1493                                      status,
1494                                      "ipu_setup failed");
1495             }
1496             else {
1497                 if (handle->procId == MultiProc_getId("DSP")) {
1498                     /* Get the user virtual address of the PRM base */
1499                     sysCtrlMapInfo.src  = 0x4A002000;
1500                     sysCtrlMapInfo.size = 0x1000;
1501                     sysCtrlMapInfo.isCached = FALSE;
1503                     status = Memory_map (&sysCtrlMapInfo);
1504                     if (status < 0) {
1505                         status = PROCESSOR_E_FAIL;
1506                         GT_setFailureReason (curTrace,
1507                                              GT_4CLASS,
1508                                              "ProcMgr_load",
1509                                               status,
1510                                               "Memory_map failed");
1511                     }
1512                     else {
1513                         *(UInt32 *)(sysCtrlMapInfo.dst + 0x304) = entryPt;
1515                         sysCtrlUnmapInfo.addr = sysCtrlMapInfo.dst;
1516                         sysCtrlUnmapInfo.size = sysCtrlMapInfo.size;
1517                         sysCtrlUnmapInfo.isCached = FALSE;
1518                         Memory_unmap (&sysCtrlUnmapInfo);
1519                     }
1520                 }
1521                 if (status >= 0) {
1522                     status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1523                                                  Processor_ResetCtrlCmd_Release,
1524                                                  entryPt);
1525                 }
1526                 if (status < 0) {
1527                     /*! @retval status */
1528                     GT_setFailureReason (curTrace,
1529                                          GT_4CLASS,
1530                                          "OMAP5430BENELLI_halResetCtrl",
1531                                          status,
1532                                          "Reset Release failed");
1533                 }
1534             }
1535         }
1536 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1537     }
1538 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1539         return status;
1543 /*!
1544  *  @brief      Function to stop the slave processor
1545  *
1546  *              Stop the execution of the slave processor. Depending on the boot
1547  *              mode, this may result in placing the slave processor in reset.
1548  *
1549  *  @param      handle    Handle to the Processor instance
1550  *
1551  *  @sa         OMAP5430BENELLIPROC_start, OMAP5430BENELLIPROC_halResetCtrl
1552  */
1553 Int
1554 OMAP5430BENELLIPROC_stop (Processor_Handle handle)
1556     Int                         status       = PROCESSOR_SUCCESS ;
1557     Processor_Object *          procHandle   = (Processor_Object *) handle;
1558     OMAP5430BENELLIPROC_Object * object      = procHandle->object;
1560     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_stop", handle);
1562     GT_assert (curTrace, (handle != NULL));
1564 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1565     if (handle == NULL) {
1566         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1567         status = PROCESSOR_E_HANDLE;
1568         GT_setFailureReason (curTrace,
1569                              GT_4CLASS,
1570                              "OMAP5430BENELLIPROC_stop",
1571                              status,
1572                              "Invalid handle specified");
1573     }
1574     else {
1575 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1576         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1577                                              Processor_ResetCtrlCmd_Reset,
1578                                              0);
1579         if (status < 0) {
1580             /*! @retval status */
1581             GT_setFailureReason (curTrace,
1582                                  GT_4CLASS,
1583                                  "OMAP5430BENELLI_halResetCtrl",
1584                                  status,
1585                                  "Reset failed");
1586         }
1588         ipu_destroy(object->halObject);
1589         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1590                                              Processor_ResetCtrlCmd_MMU_Reset,
1591                                              0);
1592         if (status < 0) {
1593             /*! @retval status */
1594             GT_setFailureReason (curTrace,
1595                                  GT_4CLASS,
1596                                  "OMAP5430BENELLI_halResetCtrl",
1597                                  status,
1598                                  "Reset MMU failed");
1599         }
1601 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1602     }
1603 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1605     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_stop", status);
1607     /*! @retval PROCESSOR_SUCCESS Operation successful */
1608     return status;
1612 /*!
1613  *  @brief      Function to read from the slave processor's memory.
1614  *
1615  *              Read from the slave processor's memory and copy into the
1616  *              provided buffer.
1617  *
1618  *  @param      handle     Handle to the Processor instance
1619  *  @param      procAddr   Address in host processor's address space of the
1620  *                         memory region to read from.
1621  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1622  *                         number of bytes to be read. When the function
1623  *                         returns, this parameter contains the number of bytes
1624  *                         actually read.
1625  *  @param      buffer     User-provided buffer in which the slave processor's
1626  *                         memory contents are to be copied.
1627  *
1628  *  @sa         OMAP5430BENELLIPROC_write
1629  */
1630 Int
1631 OMAP5430BENELLIPROC_read (Processor_Handle   handle,
1632                           UInt32             procAddr,
1633                           UInt32 *           numBytes,
1634                           Ptr                buffer)
1636     Int       status   = PROCESSOR_SUCCESS ;
1637     UInt8  *  procPtr8 = NULL;
1639     GT_4trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_read",
1640                handle, procAddr, numBytes, buffer);
1642     GT_assert (curTrace, (handle   != NULL));
1643     GT_assert (curTrace, (numBytes != NULL));
1644     GT_assert (curTrace, (buffer   != NULL));
1646 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1647     if (handle == NULL) {
1648         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1649         status = PROCESSOR_E_HANDLE;
1650         GT_setFailureReason (curTrace,
1651                              GT_4CLASS,
1652                              "OMAP5430BENELLIPROC_read",
1653                              status,
1654                              "Invalid handle specified");
1655     }
1656     else if (numBytes == 0) {
1657             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1658             status = PROCESSOR_E_INVALIDARG;
1659             GT_setFailureReason (curTrace,
1660                                  GT_4CLASS,
1661                                  "OMAP5430BENELLIPROC_read",
1662                                  status,
1663                                  "Invalid numBytes specified");
1664     }
1665     else if (buffer == NULL) {
1666             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1667             status = PROCESSOR_E_INVALIDARG;
1668             GT_setFailureReason (curTrace,
1669                                  GT_4CLASS,
1670                                  "OMAP5430BENELLIPROC_read",
1671                                  status,
1672                                  "Invalid buffer specified");
1673     }
1674     else {
1675 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1676         procPtr8 = (UInt8 *) procAddr ;
1677         buffer = Memory_copy (buffer, procPtr8, *numBytes);
1678         GT_assert (curTrace, (buffer != (UInt32) NULL));
1679 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1680         if (buffer == (UInt32) NULL) {
1681             /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1682             status = PROCESSOR_E_FAIL;
1683             GT_setFailureReason (curTrace,
1684                                  GT_4CLASS,
1685                                  "OMAP5430BENELLIPROC_read",
1686                                  status,
1687                                  "Failed in Memory_copy");
1688             *numBytes = 0;
1689         }
1690     }
1691 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1693     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_read",status);
1695     /*! @retval PROCESSOR_SUCCESS Operation successful */
1696     return status;
1700 /*!
1701  *  @brief      Function to write into the slave processor's memory.
1702  *
1703  *              Read from the provided buffer and copy into the slave
1704  *              processor's memory.
1705  *
1706  *  @param      handle     Handle to the Processor object
1707  *  @param      procAddr   Address in host processor's address space of the
1708  *                         memory region to write into.
1709  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1710  *                         number of bytes to be written. When the function
1711  *                         returns, this parameter contains the number of bytes
1712  *                         actually written.
1713  *  @param      buffer     User-provided buffer from which the data is to be
1714  *                         written into the slave processor's memory.
1715  *
1716  *  @sa         OMAP5430BENELLIPROC_read
1717  */
1718 Int
1719 OMAP5430BENELLIPROC_write (Processor_Handle handle,
1720                            UInt32           procAddr,
1721                            UInt32 *         numBytes,
1722                            Ptr              buffer)
1724     Int                   status       = PROCESSOR_SUCCESS ;
1725     Processor_Object *    procHandle   = (Processor_Object *) handle;
1726     OMAP5430BENELLIPROC_Object * object = NULL;
1727     UInt8  *              procPtr8     = NULL;
1728     UInt8                 temp8_1;
1729     UInt8                 temp8_2;
1730     UInt8                 temp8_3;
1731     UInt8                 temp8_4;
1732     UInt32                temp;
1734     GT_4trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_write",
1735                handle, procAddr, numBytes, buffer);
1737     GT_assert (curTrace, (handle   != NULL));
1738     GT_assert (curTrace, (numBytes != NULL));
1739     GT_assert (curTrace, (buffer   != NULL));
1741 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1742     if (handle == NULL) {
1743         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1744         status = PROCESSOR_E_HANDLE;
1745         GT_setFailureReason (curTrace,
1746                              GT_4CLASS,
1747                              "OMAP5430BENELLIPROC_write",
1748                              status,
1749                              "Invalid handle specified");
1750     }
1751     else if (numBytes == 0) {
1752             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1753             status = PROCESSOR_E_INVALIDARG;
1754             GT_setFailureReason (curTrace,
1755                                  GT_4CLASS,
1756                                  "OMAP5430BENELLIPROC_write",
1757                                  status,
1758                                  "Invalid numBytes specified");
1759     }
1760     else if (buffer == NULL) {
1761             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1762             status = PROCESSOR_E_INVALIDARG;
1763             GT_setFailureReason (curTrace,
1764                                  GT_4CLASS,
1765                                  "OMAP5430BENELLIPROC_write",
1766                                  status,
1767                                  "Invalid buffer specified");
1768     }
1769     else {
1770 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1771         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1772         GT_assert (curTrace, (object != NULL));
1773         if (*numBytes != sizeof (UInt32)) {
1774             procPtr8 = (UInt8 *) procAddr ;
1775             procAddr = (UInt32) Memory_copy (procPtr8,
1776                                              buffer,
1777                                              *numBytes);
1778             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1779 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1780             if (procAddr == (UInt32) NULL) {
1781                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1782                 status = PROCESSOR_E_FAIL;
1783                 GT_setFailureReason (curTrace,
1784                                      GT_4CLASS,
1785                                      "OMAP5430BENELLIPROC_write",
1786                                      status,
1787                                      "Failed in Memory_copy");
1788                 *numBytes = 0;
1789             }
1790 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1791         }
1792         else  {
1793              /* For 4 bytes, directly write as a UInt32 */
1794             temp8_1 = ((UInt8 *) buffer) [0];
1795             temp8_2 = ((UInt8 *) buffer) [1];
1796             temp8_3 = ((UInt8 *) buffer) [2];
1797             temp8_4 = ((UInt8 *) buffer) [3];
1798             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1799                              |   ((UInt32) temp8_3 << 16)
1800                              |   ((UInt32) temp8_2 << 8)
1801                              |   ((UInt32) temp8_1));
1802             *((UInt32*) procAddr) = temp;
1803         }
1804 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1805     }
1806 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1808     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_write", status);
1810     /*! @retval PROCESSOR_SUCCESS Operation successful */
1811     return status;
1815 /*!
1816  *  @brief      Function to perform device-dependent operations.
1817  *
1818  *              Performs device-dependent control operations as exposed by this
1819  *              implementation of the Processor module.
1820  *
1821  *  @param      handle     Handle to the Processor object
1822  *  @param      cmd        Device specific processor command
1823  *  @param      arg        Arguments specific to the type of command.
1824  *
1825  *  @sa
1826  */
1827 Int
1828 OMAP5430BENELLIPROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1830     Int                          status       = PROCESSOR_SUCCESS ;
1831     Processor_Object *           procHandle   = (Processor_Object *) handle;
1832     OMAP5430BENELLIPROC_Object * object       = NULL;
1834     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_control",
1835                handle, cmd, arg);
1837     GT_assert (curTrace, (handle != NULL));
1838     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1840 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1841     if (handle == NULL) {
1842         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1843         status = PROCESSOR_E_HANDLE;
1844         GT_setFailureReason (curTrace,
1845                              GT_4CLASS,
1846                              "OMAP5430BENELLIPROC_control",
1847                              status,
1848                              "Invalid handle specified");
1849     }
1850     else {
1851 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1852         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
1853         GT_assert (curTrace, (object != NULL));
1854         /* No control operations currently implemented. */
1855         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1856                                              for this device. */
1858         switch (cmd) {
1859             case Omap5430BenelliProc_CtrlCmd_Suspend:
1860                 if (procHandle->state == ProcMgr_State_Running) {
1861                     if (procHandle->procId == PROCTYPE_IPU0) {
1862                         status = save_mmu_ctxt(object->halObject,
1863                                                procHandle->procId);
1864                     }
1865                     if (status < 0) {
1866                         GT_setFailureReason(curTrace, GT_4CLASS,
1867                                             "OMAP5430BENELLIPROC_control",
1868                                             status,
1869                                             "Error while saving the MMU context");
1870                     }
1871                     else {
1872                         status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1873                                                        Processor_ResetCtrlCmd_Reset,
1874                                                        0);
1875                         if (status < 0) {
1876                             GT_setFailureReason(curTrace, GT_4CLASS,
1877                                                 "OMAP5430BENELLIPROC_control",
1878                                                 status,
1879                                                 "Error while Resetting proc");
1880                         }
1881                         else {
1882                             status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1883                                                    Processor_ResetCtrlCmd_MMU_Reset,
1884                                                    0);
1885                             if (status < 0) {
1886                                 GT_setFailureReason(curTrace, GT_4CLASS,
1887                                                     "OMAP5430BENELLIPROC_control",
1888                                                     status,
1889                                                     "Error while Resetting MMU");
1890                             }
1891                             else {
1892                                 Processor_setState(handle, ProcMgr_State_Suspended);
1893                             }
1894                         }
1895                     }
1896                 }
1897                 else {
1898                     status = PROCESSOR_E_INVALIDSTATE;
1899                     GT_setFailureReason(curTrace, GT_4CLASS,
1900                                         "OMAP5430BENELLIPROC_control",
1901                                         status,
1902                                         "Processor not is correct state to Suspend");
1903                 }
1904                 break;
1905             case Omap5430BenelliProc_CtrlCmd_Resume:
1906                 if (procHandle->state == ProcMgr_State_Suspended) {
1907                     status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1908                                                  Processor_ResetCtrlCmd_MMU_Release,
1909                                                  0);
1910                     if (status < 0) {
1911                         GT_setFailureReason(curTrace, GT_4CLASS,
1912                                             "OMAP5430BENELLIPROC_control",
1913                                             status,
1914                                             "Error while releasing proc MMU reset");
1915                     }
1916                     else {
1917                         if (procHandle->procId == PROCTYPE_IPU0) {
1918                             status = restore_mmu_ctxt(object->halObject,
1919                                                       procHandle->procId);
1920                         }
1921                         if (status < 0) {
1922                             GT_setFailureReason(curTrace, GT_4CLASS,
1923                                                "OMAP5430BENELLIPROC_control",
1924                                                status,
1925                                                "Error while restoring MMU context");
1926                         }
1927                         else {
1928                             status = OMAP5430BENELLI_halResetCtrl(object->halObject,
1929                                                      Processor_ResetCtrlCmd_Release,
1930                                                      0);
1931                             if (status < 0) {
1932                                 GT_setFailureReason(curTrace, GT_4CLASS,
1933                                                     "OMAP5430BENELLIPROC_control",
1934                                                     status,
1935                                                     "Error while releasing reset");
1936                             }
1937                             else {
1938                                 Processor_setState(handle, ProcMgr_State_Running);
1939                             }
1940                         }
1941                     }
1942                 }
1943                 else {
1944                     status = PROCESSOR_E_INVALIDSTATE;
1945                     GT_setFailureReason(curTrace, GT_4CLASS,
1946                                         "OMAP5430BENELLIPROC_control",
1947                                         status,
1948                                         "Processor not is correct state to Resume");
1949                 }
1950                 break;
1951             default:
1952                 status = PROCESSOR_E_NOTSUPPORTED;
1953         }
1955 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1956     }
1957 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
1958     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_control",status);
1960     /*! @retval PROCESSOR_SUCCESS Operation successful */
1961     return status;
1965 /*!
1966  *  @brief      Function to translate slave physical address to master physical
1967  *              address.
1968  *
1969  *  @param      handle     Handle to the Processor object
1970  *  @param      dstAddr    Returned: master physical address.
1971  *  @param      srcAddr    Slave physical address.
1972  *
1973  *  @sa
1974  */
1975 Int
1976 OMAP5430BENELLIPROC_translate (Processor_Handle handle,
1977                                UInt32 *         dstAddr,
1978                                UInt32           srcAddr)
1980     Int                         status       = PROCESSOR_SUCCESS ;
1981     Processor_Object *          procHandle   = (Processor_Object *) handle;
1982     OMAP5430BENELLIPROC_Object * object      = NULL;
1983     UInt32                      i;
1984     ProcMgr_AddrInfo *          ai;
1985     ProcMgr_AddrInfo *          pMemRegn     = NULL;
1986     UInt32                      nRegions     = 0;
1988     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_translate",
1989                handle, dstAddr, srcAddr);
1991     GT_assert (curTrace, (handle  != NULL));
1992     GT_assert (curTrace, (dstAddr != NULL));
1994     GT_1trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_Params_init", handle);
1996 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1997     if (handle == NULL) {
1998         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1999         status = PROCESSOR_E_HANDLE;
2000         GT_setFailureReason (curTrace,
2001                              GT_4CLASS,
2002                              "OMAP5430BENELLIPROC_translate",
2003                              status,
2004                              "Invalid handle specified");
2005     }
2006     else if (dstAddr == NULL) {
2007         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
2008         status = PROCESSOR_E_INVALIDARG;
2009         GT_setFailureReason (curTrace,
2010                              GT_4CLASS,
2011                              "OMAP5430BENELLIPROC_translate",
2012                              status,
2013                              "dstAddr provided as NULL");
2014     }
2015     else {
2016 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2017         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
2018         GT_assert (curTrace, (object != NULL));
2020         pMemRegn = object->params.memEntries;
2021         nRegions = object->params.numMemEntries;
2023         *dstAddr = -1u;
2024         for (i = 0;i < nRegions;i++)
2025         {
2026              ai = &pMemRegn [i];
2027              if (   (srcAddr >= ai->addr [ProcMgr_AddrType_SlaveVirt])
2028                  && (srcAddr < (  ai->addr [ProcMgr_AddrType_SlaveVirt]
2029                                 + ai->size))) {
2030                  *dstAddr =   ai->addr [ProcMgr_AddrType_MasterPhys]
2031                             + (srcAddr - ai->addr [ProcMgr_AddrType_SlaveVirt]);
2032                  break;
2033              }
2034         }
2036         if (*dstAddr == -1u) {
2037             /*! @retval PROCESSOR_E_FAIL srcAddr not found in slave address
2038              *          space */
2039             status = PROCESSOR_E_INVALIDARG;
2040             GT_setFailureReason (curTrace,
2041                                  GT_4CLASS,
2042                                  "OMAP5430BENELLIPROC_translate",
2043                                  status,
2044                                  "srcAddr not found in slave address space");
2045         }
2047 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2048     }
2049 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2050     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_translate",status);
2052     /*! @retval PROCESSOR_SUCCESS Operation successful */
2053     return status;
2057 /*!
2058  *  @brief      Function to map slave address to host address space
2059  *
2060  *              Map the provided slave address to master address space. This
2061  *              function also maps the specified address to slave MMU space.
2062  *
2063  *  @param      handle      Handle to the Processor object
2064  *  @param      mapType     Type of mapping to be performed.
2065  *  @param      addrInfo    Structure containing map info.
2066  *  @param      srcAddrType Source address type.
2067  *
2068  *  @sa
2069  */
2070 Int
2071 OMAP5430BENELLIPROC_map (Processor_Handle handle,
2072                          UInt32 *         dstAddr,
2073                          UInt32           nSegs,
2074                          Memory_SGList *  sglist)
2076     Int                          status       = PROCESSOR_SUCCESS ;
2077     Processor_Object *           procHandle   = (Processor_Object *) handle;
2078     OMAP5430BENELLIPROC_Object * object       = NULL;
2079     UInt32                       i;
2080     OMAP5430BENELLI_HalMmuCtrlArgs_AddEntry addEntryArgs;
2082     GT_4trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_map",
2083                handle, dstAddr, nSegs, sglist);
2085     GT_assert (curTrace, (handle != NULL));
2086     GT_assert (curTrace, (sglist != NULL));
2087     GT_assert (curTrace, (nSegs > 0));
2089 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2090     if (handle == NULL) {
2091         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
2092         status = PROCESSOR_E_HANDLE;
2093         GT_setFailureReason (curTrace,
2094                              GT_4CLASS,
2095                              "OMAP5430BENELLIPROC_map",
2096                              status,
2097                              "Invalid handle specified");
2098     }
2099     else if (sglist == NULL) {
2100         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
2101         status = PROCESSOR_E_INVALIDARG;
2102         GT_setFailureReason (curTrace,
2103                              GT_4CLASS,
2104                              "OMAP5430BENELLIPROC_map",
2105                              status,
2106                              "sglist provided as NULL");
2107     }
2108     else if (nSegs == 0) {
2109         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
2110         status = PROCESSOR_E_INVALIDARG;
2111         GT_setFailureReason (curTrace,
2112                              GT_4CLASS,
2113                              "OMAP5430BENELLIPROC_map",
2114                              status,
2115                              "Number of segments provided is 0");
2116     }
2117     else {
2118 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2119         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
2120         GT_assert (curTrace, (object != NULL));
2121         /* Program the mmu with the sglist */
2122         /* Program the DSP MMU also */
2123         for (i = 0; (i < nSegs) && (status >= 0); i++)
2124         {
2125             addEntryArgs.masterPhyAddr = sglist [i].paddr;
2126             addEntryArgs.size          = sglist [i].size;
2127             addEntryArgs.slaveVirtAddr = (UInt32)*dstAddr;
2128             /*TBD : elementSize, endianism, mixedSized are hard coded now,
2129              *      must be configurable later*/
2130             addEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2131             addEntryArgs.endianism     = LITTLE_ENDIAN;
2132             addEntryArgs.mixedSize     = MMU_TLBES;
2133             addEntryArgs.slaveVirtAddr = get_BenelliVirtAdd(object->halObject,
2134                                                     addEntryArgs.masterPhyAddr);
2135             *(dstAddr) = addEntryArgs.slaveVirtAddr;
2136             if(addEntryArgs.slaveVirtAddr == 0) {
2137                 status = OMAP5430BENELLI_halMmuCtrl (object->halObject,
2138                                                   Processor_MmuCtrlCmd_AddEntry,
2139                                                   &addEntryArgs);
2141             }
2142 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2143             if (status < 0) {
2144                 GT_setFailureReason (curTrace,
2145                                  GT_4CLASS,
2146                                  "OMAP5430BENELLIPROC_map",
2147                                  status,
2148                                  "DSP MMU configuration failed");
2149             }
2150 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2151         }
2152 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2153     }
2154 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2155     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_map",status);
2157     /*! @retval PROCESSOR_SUCCESS Operation successful */
2158     return status;
2162 /*!
2163  *  @brief      Function to unmap slave address from host address space
2164  *
2165  *  @param      handle      Handle to the Processor object
2166  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
2167  *                          address.
2168  *  @param      size        Size of the region to be mapped.
2169 s *
2170  *  @sa
2171  */
2172 Int
2173 OMAP5430BENELLIPROC_unmap (Processor_Handle handle,
2174                            UInt32           addr,
2175                            UInt32           size)
2177     Int                          status       = PROCESSOR_SUCCESS ;
2178     Processor_Object *           procHandle   = (Processor_Object *) handle;
2179     OMAP5430BENELLIPROC_Object * object       = NULL;
2180     OMAP5430BENELLI_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
2182     GT_3trace (curTrace, GT_ENTER, "OMAP5430BENELLIPROC_unmap",
2183                handle, addr, size);
2185     GT_assert (curTrace, (handle != NULL));
2186     GT_assert (curTrace, (size   != 0));
2188 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2189     if (handle == NULL) {
2190         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
2191         status = PROCESSOR_E_HANDLE;
2192         GT_setFailureReason (curTrace,
2193                              GT_4CLASS,
2194                              "OMAP5430BENELLIPROC_unmap",
2195                              status,
2196                              "Invalid handle specified");
2197     }
2198     else if (size == 0) {
2199         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
2200         status = PROCESSOR_E_INVALIDARG;
2201         GT_setFailureReason (curTrace,
2202                              GT_4CLASS,
2203                              "OMAP5430BENELLIPROC_unmap",
2204                              status,
2205                              "Size provided is zero");
2206     }
2207     else {
2208 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2209         object = (OMAP5430BENELLIPROC_Object *) procHandle->object;
2210         GT_assert (curTrace, (object != NULL));
2211         /* Remove the entry from the DSP MMU also */
2213         deleteEntryArgs.size          = size;
2214         deleteEntryArgs.slaveVirtAddr = addr;
2215         /*TBD : elementSize, endianism, mixedSized are hard coded now,
2216          *        must be configurable later*/
2217         deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2218         deleteEntryArgs.endianism     = LITTLE_ENDIAN;
2219         deleteEntryArgs.mixedSize     = MMU_TLBES;
2221         status = OMAP5430BENELLI_halMmuCtrl(object->halObject,
2222                                             Processor_MmuCtrlCmd_DeleteEntry,
2223                                             &deleteEntryArgs);
2224 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2225         if (status < 0) {
2226             GT_setFailureReason (curTrace,
2227                              GT_4CLASS,
2228                              "OMAP5430BENELLIPROC_unmap",
2229                              status,
2230                              "DSP MMU configuration failed");
2231         }
2232 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2234 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2235     }
2236 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
2237     GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLIPROC_unmap",status);
2239     /*! @retval PROCESSOR_SUCCESS Operation successful */
2240     return status;
2243 Int
2244 OMAP5430BENELLIPROC_procInfo (Processor_Handle   handle,
2245                               ProcMgr_ProcInfo * procInfo)
2247     Processor_Object *              procHandle  = NULL;
2248     OMAP5430BENELLIPROC_Object *    object      = NULL;
2249     ProcMgr_AddrInfo *              entry       = NULL;
2250     Int                             i           = 0;
2252     procHandle = (Processor_Object *)handle;
2253     object = procHandle->object;
2254     for (i = 0; i < object->params.numMemEntries; i++) {
2255         entry = &object->params.memEntries[i];
2257         procInfo->memEntries[i].info.addr[ProcMgr_AddrType_MasterKnlVirt] =
2258             entry->addr[ProcMgr_AddrType_MasterKnlVirt];
2260         procInfo->memEntries[i].info.addr[ProcMgr_AddrType_SlaveVirt] =
2261             entry->addr[ProcMgr_AddrType_SlaveVirt];
2264     }
2265     procInfo->numMemEntries = object->params.numMemEntries;
2266     return 0;
2269 Int
2270 OMAP5430BENELLI_virtToPhys (Processor_Handle handle,
2271                             UInt32           da,
2272                             UInt32 *         mappedEntries,
2273                             UInt32           numEntries)
2275     if(!handle || !mappedEntries || !numEntries) {
2276         return -1;
2277     }
2278     return 0;
2282 #if defined (__cplusplus)
2284 #endif /* defined (__cplusplus) */