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