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