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