Eliminate need to specify Syslink_Override_Params on QNX
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayuipu / vayucore1 / VAYUIpuCore1Proc.c
1 /*
2  *  @file   VAYUIpuCore1Proc.c
3  *
4  * @brief       Processor implementation for VAYUIPUCORE1.
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 VAYUIPUCORE1.
10  *
11  *
12  *  ============================================================================
13  *
14  *  Copyright (c) 2013-2014, Texas Instruments Incorporated
15  *
16  *  Redistribution and use in source and binary forms, with or without
17  *  modification, are permitted provided that the following conditions
18  *  are met:
19  *
20  *  *  Redistributions of source code must retain the above copyright
21  *     notice, this list of conditions and the following disclaimer.
22  *
23  *  *  Redistributions in binary form must reproduce the above copyright
24  *     notice, this list of conditions and the following disclaimer in the
25  *     documentation and/or other materials provided with the distribution.
26  *
27  *  *  Neither the name of Texas Instruments Incorporated nor the names of
28  *     its contributors may be used to endorse or promote products derived
29  *     from this software without specific prior written permission.
30  *
31  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *  Contact information for paper mail:
43  *  Texas Instruments
44  *  Post Office Box 655303
45  *  Dallas, Texas 75265
46  *  Contact information:
47  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
48  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
49  *  ============================================================================
50  *
51  */
55 #include <ti/syslink/Std.h>
56 /* OSAL & Utils headers */
57 #include <ti/syslink/utils/Cfg.h>
58 #include <ti/syslink/utils/String.h>
59 #include <ti/syslink/utils/IGateProvider.h>
60 #include <ti/syslink/utils/GateMutex.h>
61 #include <ti/syslink/utils/Memory.h>
63 #include <string.h>
65 #include <ti/syslink/utils/Trace.h>
66 /* Module level headers */
67 #include <ProcDefs.h>
68 #include <Processor.h>
69 #include <VAYUIpuCore1Proc.h>
70 #include <_VAYUIpuCore1Proc.h>
71 #include <VAYUIpuHal.h>
72 #include <VAYUIpuCore1HalReset.h>
73 #include <VAYUIpuHalBoot.h>
74 #include <VAYUIpuEnabler.h>
75 #include <ti/ipc/MultiProc.h>
76 #include <_MultiProc.h>
77 #include <RscTable.h>
80 #if defined (__cplusplus)
81 extern "C" {
82 #endif
85 /* =============================================================================
86  *  Macros and types
87  * =============================================================================
88  */
90 /*!
91  *  @brief  Number of static entries in address translation table.
92  */
93 #define AddrTable_STATIC_COUNT 1
95 /*!
96  *  @brief  Max entries in address translation table.
97  */
98 #define AddrTable_SIZE 32
100 /* Number of IPUs supported */
101 #define NUM_IPUS 2
103 /* Convert procId to IPU # */
104 #define PROCID_TO_IPU(procId) (procId == VAYUIPUCORE1PROC_state.ipu1ProcId ?\
105     0 : 1)
107 /* Config param for L2MMU. This is not a typo, we are using the
108  * same name (IPU1) because both Benelli M4 processors use the
109  * same L2MMU. The docs expose IPUx but not the IPUx Core1 processor.
110  */
111 #define PARAMS_mmuEnable1 "ProcMgr.proc[IPU1].mmuEnable="
112 #define PARAMS_mmuEnable2 "ProcMgr.proc[IPU2].mmuEnable="
115 /*!
116  *  @brief  VAYUIPUCORE1PROC Module state object
117  */
118 typedef struct VAYUIPUCORE1PROC_ModuleObject_tag {
119     UInt32                  configSize;
120     /*!< Size of configuration structure */
121     VAYUIPUCORE1PROC_Config cfg;
122     /*!< VAYUIPUCORE1PROC configuration structure */
123     VAYUIPUCORE1PROC_Config defCfg;
124     /*!< Default module configuration */
125     VAYUIPUCORE1PROC_Params      defInstParams;
126     /*!< Default parameters for the VAYUIPUCORE1PROC instances */
127     Bool                    isSetup;
128     /*!< Indicates whether the VAYUIPUCORE1PROC module is setup. */
129     VAYUIPUCORE1PROC_Handle procHandles [MultiProc_MAXPROCESSORS];
130     /*!< Processor handle array. */
131     IGateProvider_Handle             gateHandle;
132     /*!< Handle of gate to be used for local thread safety */
133     UInt16                     ipu1ProcId;
134     /*!< MultiProc id of IPU1 (to avoid multiple lookups) */
135 } VAYUIPUCORE1PROC_ModuleObject;
137 /* Memory region counters */
138 static UInt32 AddrTable_count[NUM_IPUS] = {
139     AddrTable_STATIC_COUNT,
140     AddrTable_STATIC_COUNT,
141 };
143 /* static memory regions
144  * CAUTION: AddrTable_STATIC_COUNT must match number of entries below.
145  */
146 static ProcMgr_AddrInfo AddrTable_IPU1[AddrTable_SIZE] =
148     /* L2 RAM */
149     {
150         .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
151         .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
152         .addr[ProcMgr_AddrType_MasterPhys] = 0x55020000u,
153         .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
154         .addr[ProcMgr_AddrType_SlavePhys] = -1u,
155         .size = 0x10000u,
156         .isCached = FALSE,
157         .mapMask = ProcMgr_SLAVEVIRT,
158         .isMapped = TRUE,
159         .refCount = 0u      /* refCount set to 0 for static entry */
160     },
161 };
163 static ProcMgr_AddrInfo AddrTable_IPU2[AddrTable_SIZE] =
165     /* L2 RAM */
166     {
167         .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
168         .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
169         .addr[ProcMgr_AddrType_MasterPhys] = 0x55020000u,
170         .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
171         .addr[ProcMgr_AddrType_SlavePhys] = -1u,
172         .size = 0x10000u,
173         .isCached = FALSE,
174         .mapMask = ProcMgr_SLAVEVIRT,
175         .isMapped = TRUE,
176         .refCount = 0u      /* refCount set to 0 for static entry */
177     },
178 };
180 static ProcMgr_AddrInfo * AddrTable[NUM_IPUS] =
182     AddrTable_IPU1,
183     AddrTable_IPU2
184 };
186 /* =============================================================================
187  *  Globals
188  * =============================================================================
189  */
191 /*!
192  *  @var    VAYUIPUCORE1PROC_state
193  *
194  *  @brief  VAYUIPUCORE1PROC state object variable
195  */
196 #if !defined(SYSLINK_BUILD_DEBUG)
197 static
198 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
199 VAYUIPUCORE1PROC_ModuleObject VAYUIPUCORE1PROC_state =
201     .isSetup = FALSE,
202     .configSize = sizeof (VAYUIPUCORE1PROC_Config),
203     .gateHandle = NULL,
204     .defInstParams.mmuEnable = TRUE,
205     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
206 };
208 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
209 extern String ProcMgr_sysLinkCfgParams;
211 /* =============================================================================
212  * APIs directly called by applications
213  * =============================================================================
214  */
215 /*!
216  *  @brief      Function to get the default configuration for the VAYUIPUCORE1PROC
217  *              module.
218  *
219  *              This function can be called by the application to get their
220  *              configuration parameter to VAYUIPUCORE1PROC_setup filled in by the
221  *              VAYUIPUCORE1PROC module with the default parameters. If the user
222  *              does not wish to make any change in the default parameters, this
223  *              API is not required to be called.
224  *
225  *  @param      cfg        Pointer to the VAYUIPUCORE1PROC module configuration
226  *                         structure in which the default config is to be
227  *                         returned.
228  *
229  *  @sa         VAYUIPUCORE1PROC_setup
230  */
231 Void
232 VAYUIPUCORE1PROC_getConfig (VAYUIPUCORE1PROC_Config * cfg)
234     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_getConfig", cfg);
236     GT_assert (curTrace, (cfg != NULL));
238 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
239     if (cfg == NULL) {
240         GT_setFailureReason (curTrace,
241                              GT_4CLASS,
242                              "VAYUIPUCORE1PROC_getConfig",
243                              PROCESSOR_E_INVALIDARG,
244                              "Argument of type (VAYUIPUCORE1PROC_Config *) passed "
245                              "is null!");
246     }
247     else {
248 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
249         Memory_copy (cfg,
250                      &(VAYUIPUCORE1PROC_state.defCfg),
251                      sizeof (VAYUIPUCORE1PROC_Config));
252 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
253     }
254 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
256     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_getConfig");
260 /*!
261  *  @brief      Function to setup the VAYUIPUCORE1PROC module.
262  *
263  *              This function sets up the VAYUIPUCORE1PROC module. This function
264  *              must be called before any other instance-level APIs can be
265  *              invoked.
266  *              Module-level configuration needs to be provided to this
267  *              function. If the user wishes to change some specific config
268  *              parameters, then VAYUIPUCORE1PROC_getConfig can be called to get the
269  *              configuration filled with the default values. After this, only
270  *              the required configuration values can be changed. If the user
271  *              does not wish to make any change in the default parameters, the
272  *              application can simply call VAYUIPUCORE1PROC_setup with NULL
273  *              parameters. The default parameters would get automatically used.
274  *
275  *  @param      cfg   Optional VAYUIPUCORE1PROC module configuration. If provided as
276  *                    NULL, default configuration is used.
277  *
278  *  @sa         VAYUIPUCORE1PROC_destroy
279  *              GateMutex_create
280  */
281 Int
282 VAYUIPUCORE1PROC_setup (VAYUIPUCORE1PROC_Config * cfg)
284     Int                     status = PROCESSOR_SUCCESS;
285     VAYUIPUCORE1PROC_Config tmpCfg;
286     Error_Block             eb;
288     Error_init(&eb);
290     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_setup", cfg);
292     if (cfg == NULL) {
293         VAYUIPUCORE1PROC_getConfig (&tmpCfg);
294         cfg = &tmpCfg;
295     }
297     /* Create a default gate handle for local module protection. */
298     VAYUIPUCORE1PROC_state.gateHandle = (IGateProvider_Handle)
299                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
300 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
301     if (VAYUIPUCORE1PROC_state.gateHandle == NULL) {
302         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
303         status = PROCESSOR_E_FAIL;
304         GT_setFailureReason (curTrace,
305                              GT_4CLASS,
306                              "VAYUIPUCORE1PROC_setup",
307                              status,
308                              "Failed to create GateMutex!");
309     }
310     else {
311 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
312         /* Copy the user provided values into the state object. */
313         Memory_copy (&VAYUIPUCORE1PROC_state.cfg,
314                      cfg,
315                      sizeof (VAYUIPUCORE1PROC_Config));
317         /* Initialize the name to handles mapping array. */
318         Memory_set (&VAYUIPUCORE1PROC_state.procHandles,
319                     0,
320                     (sizeof (VAYUIPUCORE1PROC_Handle) * MultiProc_MAXPROCESSORS));
322         VAYUIPUCORE1PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
323         VAYUIPUCORE1PROC_state.isSetup = TRUE;
324 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
325     }
326 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
328     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_setup", status);
330     /*! @retval PROCESSOR_SUCCESS Operation successful */
331     return (status);
335 /*!
336  *  @brief      Function to destroy the VAYUIPUCORE1PROC module.
337  *
338  *              Once this function is called, other VAYUIPUCORE1PROC module APIs,
339  *              except for the VAYUIPUCORE1PROC_getConfig API cannot be called
340  *              anymore.
341  *
342  *  @sa         VAYUIPUCORE1PROC_setup
343  *              GateMutex_delete
344  */
345 Int
346 VAYUIPUCORE1PROC_destroy (Void)
348     Int    status = PROCESSOR_SUCCESS;
349     UInt16 i;
351     GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_destroy");
353     /* Check if any VAYUIPUCORE1PROC instances have not been deleted so far. If not,
354      * delete them.
355      */
356     for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
357         GT_assert (curTrace, (VAYUIPUCORE1PROC_state.procHandles [i] == NULL));
358         if (VAYUIPUCORE1PROC_state.procHandles [i] != NULL) {
359             VAYUIPUCORE1PROC_delete (&(VAYUIPUCORE1PROC_state.procHandles [i]));
360         }
361     }
363     if (VAYUIPUCORE1PROC_state.gateHandle != NULL) {
364         GateMutex_delete ((GateMutex_Handle *)
365                                 &(VAYUIPUCORE1PROC_state.gateHandle));
366     }
368     VAYUIPUCORE1PROC_state.isSetup = FALSE;
370     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_destroy", status);
372     /*! @retval PROCESSOR_SUCCESS Operation successful */
373     return (status);
377 /*!
378  *  @brief      Function to initialize the parameters for this Processor
379  *              instance.
380  *
381  *  @param      params  Configuration parameters to be returned
382  *
383  *  @sa         VAYUIPUCORE1PROC_create
384  */
385 Void
386 VAYUIPUCORE1PROC_Params_init(
387         VAYUIPUCORE1PROC_Handle    handle,
388         VAYUIPUCORE1PROC_Params *  params)
390     VAYUIPUCORE1PROC_Object * procObject = (VAYUIPUCORE1PROC_Object *) handle;
392     GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE1PROC_Params_init",
393               handle, params);
395     GT_assert(curTrace, (params != NULL));
397 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
398     if (params == NULL) {
399         GT_setFailureReason(curTrace, GT_4CLASS,
400                             "VAYUIPUCORE1PROC_Params_init",
401                             PROCESSOR_E_INVALIDARG,
402                             "Argument of type (VAYUIPUCORE1PROC_Params *) "
403                             "passed is null!");
404     }
405     else {
406 #endif
407         if (handle == NULL) {
409             Memory_copy(params, &(VAYUIPUCORE1PROC_state.defInstParams),
410                 sizeof(VAYUIPUCORE1PROC_Params));
412         }
413         else {
414             /* return updated VAYUIPUCORE1PROC instance specific parameters */
415             Memory_copy(params, &(procObject->params),
416                         sizeof (VAYUIPUCORE1PROC_Params));
417         }
418 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
419     }
420 #endif
422     GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_Params_init");
425 /*!
426  *  @brief      Function to create an instance of this Processor.
427  *
428  *  @param      name    Name of the Processor instance.
429  *  @param      params  Configuration parameters.
430  *
431  *  @sa         VAYUIPUCORE1PROC_delete
432  */
433 VAYUIPUCORE1PROC_Handle
434 VAYUIPUCORE1PROC_create (      UInt16                procId,
435                      const VAYUIPUCORE1PROC_Params * params)
437     Int                   status    = PROCESSOR_SUCCESS;
438     Processor_Object *    handle    = NULL;
439     VAYUIPUCORE1PROC_Object * object    = NULL;
440     Int i                            = 0;
441     ProcMgr_AddrInfo *ai             = NULL;
442     IArg                  key;
443     List_Params           listParams;
445     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_create", procId, params);
447     GT_assert (curTrace, IS_VALID_PROCID (procId));
448     GT_assert (curTrace, (params != NULL));
450 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
451     if (!IS_VALID_PROCID (procId)) {
452         /* Not setting status here since this function does not return status.*/
453         GT_setFailureReason (curTrace,
454                              GT_4CLASS,
455                              "VAYUIPUCORE1PROC_create",
456                              PROCESSOR_E_INVALIDARG,
457                              "Invalid procId specified");
458     }
459     else if (params == NULL) {
460         GT_setFailureReason (curTrace,
461                              GT_4CLASS,
462                              "VAYUIPUCORE1PROC_create",
463                              PROCESSOR_E_INVALIDARG,
464                              "params passed is NULL!");
465     }
466     else {
467 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
468         /* Enter critical section protection. */
469         key = IGateProvider_enter (VAYUIPUCORE1PROC_state.gateHandle);
470 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
471         /* Check if the Processor already exists for specified procId. */
472         if (VAYUIPUCORE1PROC_state.procHandles [procId] != NULL) {
473             status = PROCESSOR_E_ALREADYEXIST;
474             GT_setFailureReason (curTrace,
475                               GT_4CLASS,
476                               "VAYUIPUCORE1PROC_create",
477                               status,
478                               "Processor already exists for specified procId!");
479         }
480         else {
481 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
482             /* Allocate memory for the handle */
483             handle = (Processor_Object *) Memory_calloc (NULL,
484                                                       sizeof (Processor_Object),
485                                                       0,
486                                                       NULL);
487             if (handle == NULL) {
488                 GT_setFailureReason (curTrace,
489                                      GT_4CLASS,
490                                      "VAYUIPUCORE1PROC_create",
491                                      PROCESSOR_E_MEMORY,
492                                      "Memory allocation failed for handle!");
493             }
494             else {
495                 /* Populate the handle fields */
496                 handle->procFxnTable.attach      = &VAYUIPUCORE1PROC_attach;
497                 handle->procFxnTable.detach      = &VAYUIPUCORE1PROC_detach;
498                 handle->procFxnTable.start       = &VAYUIPUCORE1PROC_start;
499                 handle->procFxnTable.stop        = &VAYUIPUCORE1PROC_stop;
500                 handle->procFxnTable.read        = &VAYUIPUCORE1PROC_read;
501                 handle->procFxnTable.write       = &VAYUIPUCORE1PROC_write;
502                 handle->procFxnTable.control     = &VAYUIPUCORE1PROC_control;
503                 handle->procFxnTable.map         = &VAYUIPUCORE1PROC_map;
504                 handle->procFxnTable.unmap       = &VAYUIPUCORE1PROC_unmap;
505                 handle->procFxnTable.translateAddr = &VAYUIPUCORE1PROC_translate;
506                 handle->state = ProcMgr_State_Unknown;
508                 /* Allocate memory for the VAYUIPUCORE1PROC handle */
509                 handle->object = Memory_calloc (NULL,
510                                                 sizeof (VAYUIPUCORE1PROC_Object),
511                                                 0,
512                                                 NULL);
513                 if (handle->object == NULL) {
514                     status = PROCESSOR_E_MEMORY;
515                     GT_setFailureReason (curTrace,
516                                 GT_4CLASS,
517                                 "VAYUIPUCORE1PROC_create",
518                                 status,
519                                 "Memory allocation failed for handle->object!");
520                 }
521                 else {
522                     handle->procId = procId;
523                     object = (VAYUIPUCORE1PROC_Object *) handle->object;
524                     object->procHandle = (Processor_Handle)handle;
525                     object->halObject = NULL;
526                     /* Copy params into instance object. */
527                     Memory_copy (&(object->params),
528                                  (Ptr) params,
529                                  sizeof (VAYUIPUCORE1PROC_Params));
531                     /* initialize the translation table */
532                     for (i = AddrTable_count[PROCID_TO_IPU(procId)];
533                         i < AddrTable_SIZE; i++) {
534                         ai = &AddrTable[PROCID_TO_IPU(procId)][i];
535                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
536                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
537                         ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
538                         ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
539                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
540                         ai->size = 0u;
541                         ai->isCached = FALSE;
542                         ai->mapMask = 0u;
543                         ai->isMapped = FALSE;
544                     }
546                     /*
547                      * initialize refCount for all entries
548                      * both static and dynamic
549                      */
550                     for (i = 0; i < AddrTable_SIZE; i++) {
551                         AddrTable[PROCID_TO_IPU(procId)][i].refCount = 0u;
552                     }
553                     Memory_copy((Ptr)(object->params.memEntries),
554                         AddrTable[PROCID_TO_IPU(procId)],
555                         (procId == VAYUIPUCORE1PROC_state.ipu1ProcId ?
556                         sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
558                     /* Set the handle in the state object. */
559                     VAYUIPUCORE1PROC_state.procHandles [procId] =
560                                                (VAYUIPUCORE1PROC_Handle) handle;
561                     /* Initialize the list of listeners */
562                     List_Params_init(&listParams);
563                     handle->registeredNotifiers = List_create(&listParams);
565 #if !defined(SYSLINK_BUILD_OPTIMIZE)
566                     if (handle->registeredNotifiers == NULL) {
567                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
568                         status = PROCESSOR_E_FAIL;
569                         GT_setFailureReason (curTrace,
570                                              GT_4CLASS,
571                                              "VAYUIPUCORE1PROC_create",
572                                              status,
573                                              "List_create failed");
574                     }
575                     else {
576 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
578                         handle->notifiersLock =
579                                  OsalMutex_create(OsalMutex_Type_Interruptible);
581 #if !defined(SYSLINK_BUILD_OPTIMIZE)
582                         if (handle->notifiersLock == NULL) {
583                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
584                             status = PROCESSOR_E_FAIL;
585                             GT_setFailureReason (curTrace,
586                                                  GT_4CLASS,
587                                                  "VAYUIPUCORE1PROC_create",
588                                                  status,
589                                                  "OsalMutex_create failed");
590                         }
591                     }
592 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
593                 }
594             }
595 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
596         }
597 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
599         /* Leave critical section protection. */
600         IGateProvider_leave (VAYUIPUCORE1PROC_state.gateHandle, key);
601 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
602     }
603 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
605     if (status < 0) {
606         if (handle !=  NULL) {
607             if (handle->registeredNotifiers != NULL) {
608                 List_delete (&handle->registeredNotifiers);
609             }
610             if (handle->object != NULL) {
611                 Memory_free (NULL,
612                              handle->object,
613                              sizeof (VAYUIPUCORE1PROC_Object));
614             }
615             Memory_free (NULL, handle, sizeof (Processor_Object));
616         }
617         /*! @retval NULL Function failed */
618         handle = NULL;
619     }
621     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_create", handle);
623     /*! @retval Valid-Handle Operation successful */
624     return (VAYUIPUCORE1PROC_Handle) handle;
628 /*!
629  *  @brief      Function to delete an instance of this Processor.
630  *
631  *              The user provided pointer to the handle is reset after
632  *              successful completion of this function.
633  *
634  *  @param      handlePtr  Pointer to Handle to the Processor instance
635  *
636  *  @sa         VAYUIPUCORE1PROC_create
637  */
638 Int
639 VAYUIPUCORE1PROC_delete (VAYUIPUCORE1PROC_Handle * handlePtr)
641     Int                   status = PROCESSOR_SUCCESS;
642     VAYUIPUCORE1PROC_Object * object = NULL;
643     Processor_Object *    handle;
644     IArg                  key;
645     List_Elem *           elem    = NULL;
646     Processor_RegisterElem * regElem = NULL;
648     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_delete", handlePtr);
650     GT_assert (curTrace, (handlePtr != NULL));
651     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
653 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
654     if (handlePtr == NULL) {
655         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
656                                          specified*/
657         status = PROCESSOR_E_INVALIDARG;
658         GT_setFailureReason (curTrace,
659                              GT_4CLASS,
660                              "VAYUIPUCORE1PROC_delete",
661                              status,
662                              "Invalid NULL handlePtr pointer specified");
663     }
664     else if (*handlePtr == NULL) {
665         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
666         status = PROCESSOR_E_HANDLE;
667         GT_setFailureReason (curTrace,
668                              GT_4CLASS,
669                              "VAYUIPUCORE1PROC_delete",
670                              status,
671                              "Invalid NULL *handlePtr specified");
672     }
673     else {
674 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
675         handle = (Processor_Object *) (*handlePtr);
676         /* Enter critical section protection. */
677         key = IGateProvider_enter (VAYUIPUCORE1PROC_state.gateHandle);
679         /* Reset handle in PwrMgr handle array. */
680         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
681         VAYUIPUCORE1PROC_state.procHandles [handle->procId] = NULL;
683         /* Free memory used for the VAYUIPUCORE1PROC object. */
684         if (handle->object != NULL) {
685             object = (VAYUIPUCORE1PROC_Object *) handle->object;
686             Memory_free (NULL,
687                          object,
688                          sizeof (VAYUIPUCORE1PROC_Object));
689             handle->object = NULL;
690         }
692         /*
693          * Check the list of listeners to see if any are remaining
694          * and reply to them
695          */
696         OsalMutex_delete(&handle->notifiersLock);
698         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
699             regElem = (Processor_RegisterElem *)elem;
701             /* Check if there is an associated timer and cancel it */
702             if (regElem->timer != -1) {
703                 struct itimerspec value ;
704                 value.it_value.tv_sec = 0;
705                 value.it_value.tv_nsec = 0;
706                 value.it_interval.tv_sec = 0;
707                 value.it_interval.tv_nsec = 0;
708                 timer_settime(regElem->timer, 0, &value, NULL);
710                 timer_delete(regElem->timer);
711                 regElem->timer = -1;
712             }
714             /* Call the callback function so it can clean up. */
715             regElem->info->cbFxn(handle->procId,
716                                  NULL,
717                                  handle->state,
718                                  handle->state,
719                                  ProcMgr_EventStatus_Canceled,
720                                  regElem->info->arg);
721             /* Free the memory */
722             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
723         }
725         /* Delete the list of listeners */
726         List_delete(&handle->registeredNotifiers);
728         /* Free memory used for the Processor object. */
729         Memory_free (NULL, handle, sizeof (Processor_Object));
730         *handlePtr = NULL;
732         /* Leave critical section protection. */
733         IGateProvider_leave (VAYUIPUCORE1PROC_state.gateHandle, key);
734 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
735     }
736 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
738     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_delete", status);
740     /*! @retval PROCESSOR_SUCCESS Operation successful */
741     return (status);
745 /*!
746  *  @brief      Function to open a handle to an instance of this Processor. This
747  *              function is called when access to the Processor is required from
748  *              a different process.
749  *
750  *  @param      handlePtr   Handle to the Processor instance
751  *  @param      procId      Processor ID addressed by this Processor instance.
752  *
753  *  @sa         VAYUIPUCORE1PROC_close
754  */
755 Int
756 VAYUIPUCORE1PROC_open (VAYUIPUCORE1PROC_Handle * handlePtr, UInt16 procId)
758     Int status = PROCESSOR_SUCCESS;
760     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_open", handlePtr, procId);
762     GT_assert (curTrace, (handlePtr != NULL));
763     GT_assert (curTrace, IS_VALID_PROCID (procId));
765 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
766     if (handlePtr == NULL) {
767         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
768         status = PROCESSOR_E_HANDLE;
769         GT_setFailureReason (curTrace,
770                              GT_4CLASS,
771                              "VAYUIPUCORE1PROC_open",
772                              status,
773                              "Invalid NULL handlePtr specified");
774     }
775     else if (!IS_VALID_PROCID (procId)) {
776         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
777         status = PROCESSOR_E_INVALIDARG;
778         GT_setFailureReason (curTrace,
779                              GT_4CLASS,
780                              "VAYUIPUCORE1PROC_open",
781                              status,
782                              "Invalid procId specified");
783     }
784     else {
785 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
786         /* Initialize return parameter handle. */
787         *handlePtr = NULL;
789         /* Check if the PwrMgr exists and return the handle if found. */
790         if (VAYUIPUCORE1PROC_state.procHandles [procId] == NULL) {
791             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
792             status = PROCESSOR_E_NOTFOUND;
793             GT_setFailureReason (curTrace,
794                              GT_4CLASS,
795                              "VAYUIPUCORE1PROC_open",
796                              status,
797                              "Specified VAYUIPUCORE1PROC instance does not exist!");
798         }
799         else {
800             *handlePtr = VAYUIPUCORE1PROC_state.procHandles [procId];
801         }
802 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
803     }
804 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
806     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_open", status);
808     /*! @retval PROCESSOR_SUCCESS Operation successful */
809     return status;
813 /*!
814  *  @brief      Function to close a handle to an instance of this Processor.
815  *
816  *  @param      handlePtr  Pointer to Handle to the Processor instance
817  *
818  *  @sa         VAYUIPUCORE1PROC_open
819  */
820 Int
821 VAYUIPUCORE1PROC_close (VAYUIPUCORE1PROC_Handle * handlePtr)
823     Int status = PROCESSOR_SUCCESS;
825     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_close", handlePtr);
827     GT_assert (curTrace, (handlePtr != NULL));
828     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
830 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
831     if (handlePtr == NULL) {
832         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
833                                          specified*/
834         status = PROCESSOR_E_INVALIDARG;
835         GT_setFailureReason (curTrace,
836                              GT_4CLASS,
837                              "VAYUIPUCORE1PROC_close",
838                              status,
839                              "Invalid NULL handlePtr pointer specified");
840     }
841     else if (*handlePtr == NULL) {
842         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
843         status = PROCESSOR_E_HANDLE;
844         GT_setFailureReason (curTrace,
845                              GT_4CLASS,
846                              "VAYUIPUCORE1PROC_close",
847                              status,
848                              "Invalid NULL *handlePtr specified");
849     }
850     else {
851 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
852         /* Nothing to be done for close. */
853 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
854     }
855 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
857     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_close", status);
859     /*! @retval PROCESSOR_SUCCESS Operation successful */
860     return status;
864 /* =============================================================================
865  * APIs called by Processor module (part of function table interface)
866  * =============================================================================
867  */
868 /*!
869  *  @brief      Function to initialize the slave processor
870  *
871  *  @param      handle  Handle to the Processor instance
872  *  @param      params  Attach parameters
873  *
874  *  @sa         VAYUIPUCORE1PROC_detach
875  */
876 Int
877 VAYUIPUCORE1PROC_attach(
878         Processor_Handle            handle,
879         Processor_AttachParams *    params)
882     Int                         status = PROCESSOR_SUCCESS ;
883     Processor_Object *          procHandle = (Processor_Object *)handle;
884     VAYUIPUCORE1PROC_Object *  object = NULL;
885     UInt32                      i = 0;
886     UInt32                      index = 0;
887     ProcMgr_AddrInfo *          me;
888     SysLink_MemEntry *          entry;
889     SysLink_MemEntry_Block      memBlock;
890     VAYUIPU_HalMmuCtrlArgs_Enable mmuEnableArgs;
891     VAYUIPU_HalParams           halParams;
893     GT_2trace(curTrace, GT_ENTER,
894               "VAYUIPUCORE1PROC_attach", handle, params);
895     GT_assert (curTrace, (handle != NULL));
896     GT_assert (curTrace, (params != NULL));
898 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
899     if (handle == NULL) {
900         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
901         status = PROCESSOR_E_HANDLE;
902         GT_setFailureReason (curTrace,
903                              GT_4CLASS,
904                              "VAYUIPUCORE1PROC_attach",
905                              status,
906                              "Invalid handle specified");
907     }
908     else if (params == NULL) {
909             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
910             status = PROCESSOR_E_INVALIDARG;
911             GT_setFailureReason (curTrace,
912                                  GT_4CLASS,
913                                  "VAYUIPUCORE1PROC_attach",
914                                  status,
915                                  "Invalid params specified");
916     }
917     else {
918 #endif
919         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
920         GT_assert (curTrace, (object != NULL));
922         /* Added for Netra Benelli core0 is cortex M4 */
923         params->procArch = Processor_ProcArch_M4;
925         /* check for instance params override */
926         if (VAYUIPUCORE1PROC_state.ipu1ProcId == procHandle->procId) {
927             Cfg_propBool(PARAMS_mmuEnable1, ProcMgr_sysLinkCfgParams,
928                 &(object->params.mmuEnable));
929         }
930         else {
931             Cfg_propBool(PARAMS_mmuEnable2, ProcMgr_sysLinkCfgParams,
932                 &(object->params.mmuEnable));
933         }
935         object->pmHandle = params->pmHandle;
936         GT_0trace(curTrace, GT_1CLASS,
937             "VAYUIPUCORE1PROC_attach: Mapping memory regions");
939         /* search for dsp memory map */
940         status = RscTable_process(procHandle->procId, object->params.mmuEnable,
941                                   TRUE,
942                                   &memBlock.numEntries);
943         if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
944             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
945             status = PROCESSOR_E_INVALIDARG;
946             GT_setFailureReason (curTrace,
947                                  GT_4CLASS,
948                                  "VAYUIPUCORE1PROC_attach",
949                                  status,
950                                  "Failed to process resource table");
951         }
952         else {
953             status = RscTable_getMemEntries(procHandle->procId,
954                                             memBlock.memEntries,
955                                             &memBlock.numEntries);
956             if (status < 0) {
957                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
958                 status = PROCESSOR_E_INVALIDARG;
959                 GT_setFailureReason (curTrace,
960                                      GT_4CLASS,
961                                      "VAYUIPUCORE1PROC_attach",
962                                      status,
963                                      "Failed to get resource table memEntries");
964             }
965         }
967         /* update translation tables with memory map */
968         for (i = 0; (i < memBlock.numEntries)
969             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
971             entry = &memBlock.memEntries[i];
973             if (entry->map == FALSE) {
974                 /* update table with entries which don't require mapping */
975                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
976                    AddrTable_SIZE) {
977                     me = &AddrTable[PROCID_TO_IPU(procHandle->procId)][
978                         AddrTable_count[PROCID_TO_IPU(procHandle->procId)]];
980                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
981                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
982                     me->addr[ProcMgr_AddrType_MasterPhys] =
983                         entry->masterPhysAddr;
984                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
985                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
986                     me->size = entry->size;
987                     me->isCached = entry->isCached;
988                     me->mapMask = entry->mapMask;
990                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
991                 }
992                 else {
993                     status = PROCESSOR_E_FAIL;
994                     GT_setFailureReason(curTrace, GT_4CLASS,
995                         "VAYUIPUCORE1PROC_attach", status,
996                         "AddrTable_SIZE reached!");
997                 }
998             }
999             else if (entry->map == TRUE) {
1000                 /* send these entries back to ProcMgr for mapping */
1001                 index = object->params.numMemEntries;
1003                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
1004                     me = &object->params.memEntries[index];
1006                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1007                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1008                     me->addr[ProcMgr_AddrType_MasterPhys] =
1009                         entry->masterPhysAddr;
1010                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1011                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1012                     me->size = entry->size;
1013                     me->isCached = entry->isCached;
1014                     me->mapMask = entry->mapMask;
1016                     object->params.numMemEntries++;
1017                 }
1018                 else {
1019                     status = PROCESSOR_E_FAIL;
1020                     GT_setFailureReason(curTrace, GT_4CLASS,
1021                                         "VAYUIPUCORE1PROC_attach", status,
1022                                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
1023                 }
1024             }
1025             else {
1026                 status = PROCESSOR_E_INVALIDARG;
1027                 GT_setFailureReason(curTrace, GT_4CLASS,
1028                     "VAYUIPUCORE1PROC_attach", status,
1029                     "Memory map has entry with invalid 'map' value");
1030             }
1031         } /* for (...) */
1033         if (status >= 0) {
1034             /* populate the return params */
1035             params->numMemEntries = object->params.numMemEntries;
1036             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1037                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1039             halParams.procId = procHandle->procId;
1040             status = VAYUIPU_halInit(&(object->halObject), &halParams);
1042 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)
1043             if (status < 0) {
1044                 GT_setFailureReason(curTrace, GT_4CLASS,
1045                     "VAYUIPUCORE1PROC_attach", status,
1046                     "VAYUIPU_halInit failed");
1047             }
1048             else {
1049 #endif
1050                 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1051                     || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1053 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1054                     if (status < 0) {
1055                         GT_setFailureReason(curTrace, GT_4CLASS,
1056                             "VAYUIPUCORE1PROC_attach", status,
1057                             "Failed to reset the slave processor");
1058                     }
1059                     else {
1060 #endif
1061                         GT_0trace(curTrace, GT_1CLASS,
1062                             "VAYUIPUCORE1PROC_attach: slave is now in reset");
1064                         if (object->params.mmuEnable) {
1065                             mmuEnableArgs.numMemEntries = 0;
1066                             status = VAYUIPU_halMmuCtrl(object->halObject,
1067                                 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1068 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1069                             if (status < 0) {
1070                                 GT_setFailureReason(curTrace, GT_4CLASS,
1071                                     "VAYUIPUCORE1PROC_attach", status,
1072                                     "Failed to enable the slave MMU");
1073                             }
1074                             else {
1075 #endif
1076                                 GT_0trace(curTrace, GT_2CLASS,
1077                                     "VAYUIPUCORE1PROC_attach: Slave MMU "
1078                                     "is configured!");
1079                                 /*
1080                                  * Pull IPU MMU out of reset to make internal
1081                                  * memory "loadable"
1082                                  */
1083                                 status = VAYUIPUCORE1_halResetCtrl(
1084                                     object->halObject,
1085                                     Processor_ResetCtrlCmd_MMU_Release);
1086                                 if (status < 0) {
1087                                     /*! @retval status */
1088                                     GT_setFailureReason(curTrace,
1089                                         GT_4CLASS,
1090                                         "VAYUIPUCORE1_halResetCtrl",
1091                                         status,
1092                                         "Reset MMU_Release failed");
1093                                 }
1094 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1095                              }
1096 #endif
1097                         }
1098 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1099                     }
1100 #endif
1101                 }
1102 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1103             }
1104 #endif
1105         }
1106 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1107     }
1108 #endif
1110     GT_1trace(curTrace, GT_LEAVE,
1111         "VAYUIPUCORE1PROC_attach", status);
1113     /*! @retval PROCESSOR_SUCCESS Operation successful */
1114     return status;
1118 /*!
1119  *  @brief      Function to detach from the Processor.
1120  *
1121  *  @param      handle  Handle to the Processor instance
1122  *
1123  *  @sa         VAYUIPUCORE1PROC_attach
1124  */
1125 Int
1126 VAYUIPUCORE1PROC_detach (Processor_Handle handle)
1128     Int                       status     = PROCESSOR_SUCCESS;
1129     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1130     Processor_Object *        procHandle = (Processor_Object *) handle;
1131     VAYUIPUCORE1PROC_Object * object     = NULL;
1132     Int                       i          = 0;
1133     ProcMgr_AddrInfo *        ai;
1135     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_detach", handle);
1136     GT_assert (curTrace, (handle != NULL));
1138 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1139     if (handle == NULL) {
1140         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1141         status = PROCESSOR_E_HANDLE;
1142         GT_setFailureReason (curTrace,
1143                              GT_4CLASS,
1144                              "VAYUIPUCORE1PROC_detach",
1145                              PROCESSOR_E_HANDLE,
1146                              "Invalid handle specified");
1147     }
1148     else {
1149 #endif
1150         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1151         GT_assert (curTrace, (object != NULL));
1153         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1154             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1156             if (object->params.mmuEnable) {
1157                 GT_0trace(curTrace, GT_2CLASS,
1158                     "VAYUIPUCORE1PROC_detach: Disabling Slave MMU ...");
1160                 status = VAYUIPUCORE1_halResetCtrl(object->halObject,
1161                     Processor_ResetCtrlCmd_MMU_Reset);
1162 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1163                 if (status < 0) {
1164                     /*! @retval status */
1165                     GT_setFailureReason (curTrace,
1166                                          GT_4CLASS,
1167                                          "VAYUIPUCORE1_halResetCtrl",
1168                                          status,
1169                                          "Reset MMU failed");
1170                 }
1171 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1173                 status = VAYUIPU_halMmuCtrl(object->halObject,
1174                     Processor_MmuCtrlCmd_Disable, NULL);
1175 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1176                 if (status < 0) {
1177                     GT_setFailureReason(curTrace, GT_4CLASS,
1178                         "VAYUIPUCORE1PROC_detach", status,
1179                         "Failed to disable the slave MMU");
1180                 }
1181 #endif
1182             }
1184             /* delete all dynamically added entries */
1185             for (i = AddrTable_STATIC_COUNT; i <
1186                 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1187                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1188                 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1189                 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1190                 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1191                 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1192                 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1193                 ai->size = 0u;
1194                 ai->isCached = FALSE;
1195                 ai->mapMask = 0u;
1196                 ai->isMapped = FALSE;
1197                 ai->refCount = 0u;
1198             }
1199             object->params.numMemEntries = AddrTable_STATIC_COUNT;
1200             AddrTable_count[PROCID_TO_IPU(procHandle->procId)] =
1201                 AddrTable_STATIC_COUNT;
1203             //No need to reset.. that will be done in STOP
1204             /*tmpStatus = VAYUIPUCORE1_halResetCtrl(object->halObject,
1205                 Processor_ResetCtrlCmd_Reset, NULL);
1207             GT_0trace(curTrace, GT_2CLASS,
1208                 "VAYUIPUCORE1PROC_detach: Slave processor is now in reset");*/
1210 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1211             if ((tmpStatus < 0) && (status >= 0)) {
1212                 status = tmpStatus;
1213                 GT_setFailureReason (curTrace,
1214                                      GT_4CLASS,
1215                                      "VAYUIPUCORE1PROC_detach",
1216                                      status,
1217                                      "Failed to reset the slave processor");
1218             }
1219 #endif
1220         }
1222         GT_0trace (curTrace,
1223                    GT_2CLASS,
1224                    "    VAYUIPUCORE1PROC_detach: Unmapping memory regions\n");
1226         tmpStatus = VAYUIPU_halExit (object->halObject);
1227 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1228         if ((tmpStatus < 0) && (status >= 0)) {
1229             status = tmpStatus;
1230             GT_setFailureReason (curTrace,
1231                                  GT_4CLASS,
1232                                  "VAYUIPUCORE1PROC_detach",
1233                                  status,
1234                                  "Failed to finalize HAL object");
1235         }
1236     }
1237 #endif
1239     GT_1trace(curTrace, GT_LEAVE,
1240         "VAYUIPUCORE1PROC_detach", status);
1242     /*! @retval PROCESSOR_SUCCESS Operation successful */
1243     return status;
1247 /*!
1248  *  @brief      Function to start the slave processor
1249  *
1250  *              Start the slave processor running from its entry point.
1251  *              Depending on the boot mode, this involves configuring the boot
1252  *              address and releasing the slave from reset.
1253  *
1254  *  @param      handle    Handle to the Processor instance
1255  *
1256  *  @sa         VAYUIPUCORE1PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE1_halResetCtrl
1257  */
1258 Int
1259 VAYUIPUCORE1PROC_start (Processor_Handle        handle,
1260                         UInt32                  entryPt,
1261                         Processor_StartParams * params)
1263     Int                   status        = PROCESSOR_SUCCESS ;
1264     Processor_Object *    procHandle    = (Processor_Object *) handle;
1265     VAYUIPUCORE1PROC_Object * object    = NULL;
1268     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_start",
1269                handle, entryPt, params);
1271     GT_assert (curTrace, (handle != NULL));
1272     GT_assert (curTrace, (params != NULL));
1274 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1275     if (handle == NULL) {
1276         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1277         status = PROCESSOR_E_HANDLE;
1278         GT_setFailureReason (curTrace,
1279                              GT_4CLASS,
1280                              "VAYUIPUCORE1PROC_start",
1281                              status,
1282                              "Invalid handle specified");
1283     }
1284     else if (params == NULL) {
1285             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1286             status = PROCESSOR_E_INVALIDARG;
1287             GT_setFailureReason (curTrace,
1288                                  GT_4CLASS,
1289                                  "VAYUIPUCORE1PROC_start",
1290                                  status,
1291                                  "Invalid params specified");
1292     }
1293     else {
1294 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1295         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1296         GT_assert (curTrace, (object != NULL));
1297         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1298             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1299             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1300             /* Slave is to be started only for Boot mode and NoLoad mode. */
1301             /* Specify the IPUCORE1 boot address in the boot config register */
1302             status = VAYUIPU_halBootCtrl (object->halObject,
1303                                           Processor_BootCtrlCmd_SetEntryPoint,
1304                                           (Ptr) entryPt);
1305 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1306             if (status < 0) {
1307                 GT_setFailureReason (curTrace,
1308                                      GT_4CLASS,
1309                                      "VAYUIPUCORE1PROC_start",
1310                                      status,
1311                                      "Failed to set slave boot entry point");
1312             }
1313             else {
1314 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1316                 /* release the slave cpu from reset */
1317                 if (status >= 0) {
1318                     status = VAYUIPUCORE1_halResetCtrl(object->halObject,
1319                                                 Processor_ResetCtrlCmd_Release);
1320 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1321                     if (status < 0) {
1322                         GT_setFailureReason (curTrace,
1323                                           GT_4CLASS,
1324                                           "VAYUIPUCORE1PROC_start",
1325                                           status,
1326                                           "Failed to release slave from reset");
1327                     }
1328 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1329                 }
1330 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1331             }
1332 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1333         }
1335 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1336     }
1337 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1339     if (status >= 0) {
1340         GT_0trace (curTrace,
1341                    GT_1CLASS,
1342                    "    VAYUIPUCORE1PROC_start: Slave successfully started!\n");
1343     }
1344     else {
1345         GT_0trace (curTrace,
1346                    GT_1CLASS,
1347                    "    VAYUIPUCORE1PROC_start: Slave could not be started!\n");
1348     }
1350     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_start", status);
1352     /*! @retval PROCESSOR_SUCCESS Operation successful */
1353     return status;
1357 /*!
1358  *  @brief      Function to stop the slave processor
1359  *
1360  *              Stop the execution of the slave processor. Depending on the boot
1361  *              mode, this may result in placing the slave processor in reset.
1362  *
1363  *  @param      handle    Handle to the Processor instance
1364  *
1365  *  @sa         VAYUIPUCORE1PROC_start, VAYUIPUCORE1_halResetCtrl
1366  */
1367 Int
1368 VAYUIPUCORE1PROC_stop (Processor_Handle handle)
1370     Int                   status       = PROCESSOR_SUCCESS ;
1371     Processor_Object *    procHandle   = (Processor_Object *) handle;
1372     VAYUIPUCORE1PROC_Object * object       = NULL;
1374     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_stop", handle);
1376     GT_assert (curTrace, (handle != NULL));
1378 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1379     if (handle == NULL) {
1380         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1381         status = PROCESSOR_E_HANDLE;
1382         GT_setFailureReason (curTrace,
1383                              GT_4CLASS,
1384                              "VAYUIPUCORE1PROC_stop",
1385                              status,
1386                              "Invalid handle specified");
1387     }
1388     else {
1389 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1390         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1391         GT_assert (curTrace, (object != NULL));
1392         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1393             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1394             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1395             /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1396             /* Place the slave processor in reset. */
1397             status = VAYUIPUCORE1_halResetCtrl (object->halObject,
1398                                           Processor_ResetCtrlCmd_Reset);
1400             GT_0trace (curTrace,
1401                        GT_1CLASS,
1402                        "    VAYUIPUCORE1PROC_stop: Slave is now in reset!\n");
1403 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1404             if (status < 0) {
1405                 GT_setFailureReason (curTrace,
1406                                      GT_4CLASS,
1407                                      "VAYUIPUCORE1PROC_stop",
1408                                      status,
1409                                      "Failed to place slave in reset");
1410             }
1411 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1413         }
1414 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1415     }
1416 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1417     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_stop", status);
1419     /*! @retval PROCESSOR_SUCCESS Operation successful */
1420     return status;
1424 /*!
1425  *  @brief      Function to read from the slave processor's memory.
1426  *
1427  *              Read from the slave processor's memory and copy into the
1428  *              provided buffer.
1429  *
1430  *  @param      handle     Handle to the Processor instance
1431  *  @param      procAddr   Address in host processor's address space of the
1432  *                         memory region to read from.
1433  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1434  *                         number of bytes to be read. When the function
1435  *                         returns, this parameter contains the number of bytes
1436  *                         actually read.
1437  *  @param      buffer     User-provided buffer in which the slave processor's
1438  *                         memory contents are to be copied.
1439  *
1440  *  @sa         VAYUIPUCORE1PROC_write
1441  */
1442 Int
1443 VAYUIPUCORE1PROC_read (Processor_Handle   handle,
1444                        UInt32             procAddr,
1445                        UInt32 *           numBytes,
1446                        Ptr                buffer)
1448     Int       status   = PROCESSOR_SUCCESS ;
1449     UInt8  *  procPtr8 = NULL;
1451     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_read",
1452                handle, procAddr, numBytes, buffer);
1454     GT_assert (curTrace, (handle   != NULL));
1455     GT_assert (curTrace, (numBytes != NULL));
1456     GT_assert (curTrace, (buffer   != NULL));
1458 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1459     if (handle == NULL) {
1460         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1461         status = PROCESSOR_E_HANDLE;
1462         GT_setFailureReason (curTrace,
1463                              GT_4CLASS,
1464                              "VAYUIPUCORE1PROC_read",
1465                              status,
1466                              "Invalid handle specified");
1467     }
1468     else if (numBytes == 0) {
1469             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1470             status = PROCESSOR_E_INVALIDARG;
1471             GT_setFailureReason (curTrace,
1472                                  GT_4CLASS,
1473                                  "VAYUIPUCORE1PROC_read",
1474                                  status,
1475                                  "Invalid numBytes specified");
1476     }
1477     else if (buffer == NULL) {
1478             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1479             status = PROCESSOR_E_INVALIDARG;
1480             GT_setFailureReason (curTrace,
1481                                  GT_4CLASS,
1482                                  "VAYUIPUCORE1PROC_read",
1483                                  status,
1484                                  "Invalid buffer specified");
1485     }
1486     else {
1487 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1488         procPtr8 = (UInt8 *) procAddr ;
1489         buffer = memcpy (buffer, procPtr8, *numBytes);
1490         GT_assert (curTrace, (buffer != (UInt32) NULL));
1491 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1492         if (buffer == (UInt32) NULL) {
1493             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1494             status = PROCESSOR_E_FAIL;
1495             GT_setFailureReason (curTrace,
1496                                  GT_4CLASS,
1497                                  "VAYUIPUCORE1PROC_read",
1498                                  status,
1499                                  "Failed in memcpy");
1500             *numBytes = 0;
1501         }
1502     }
1503 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1505     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_read",status);
1507     /*! @retval PROCESSOR_SUCCESS Operation successful */
1508     return status;
1512 /*!
1513  *  @brief      Function to write into the slave processor's memory.
1514  *
1515  *              Read from the provided buffer and copy into the slave
1516  *              processor's memory.
1517  *
1518  *  @param      handle     Handle to the Processor object
1519  *  @param      procAddr   Address in host processor's address space of the
1520  *                         memory region to write into.
1521  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1522  *                         number of bytes to be written. When the function
1523  *                         returns, this parameter contains the number of bytes
1524  *                         actually written.
1525  *  @param      buffer     User-provided buffer from which the data is to be
1526  *                         written into the slave processor's memory.
1527  *
1528  *  @sa         VAYUIPUCORE1PROC_read, VAYUIPUCORE1PROC_translateAddr
1529  */
1530 Int
1531 VAYUIPUCORE1PROC_write (Processor_Handle handle,
1532                         UInt32           procAddr,
1533                         UInt32 *         numBytes,
1534                         Ptr              buffer)
1536     Int                   status       = PROCESSOR_SUCCESS ;
1537     UInt8  *              procPtr8     = NULL;
1538     UInt8                 temp8_1;
1539     UInt8                 temp8_2;
1540     UInt8                 temp8_3;
1541     UInt8                 temp8_4;
1542     UInt32                temp;
1544     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_write",
1545                handle, procAddr, numBytes, buffer);
1547     GT_assert (curTrace, (handle   != NULL));
1548     GT_assert (curTrace, (numBytes != NULL));
1549     GT_assert (curTrace, (buffer   != NULL));
1551 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1552     if (handle == NULL) {
1553         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1554         status = PROCESSOR_E_HANDLE;
1555         GT_setFailureReason (curTrace,
1556                              GT_4CLASS,
1557                              "VAYUIPUCORE1PROC_write",
1558                              status,
1559                              "Invalid handle specified");
1560     }
1561     else if (numBytes == 0) {
1562             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1563             status = PROCESSOR_E_INVALIDARG;
1564             GT_setFailureReason (curTrace,
1565                                  GT_4CLASS,
1566                                  "VAYUIPUCORE1PROC_write",
1567                                  status,
1568                                  "Invalid numBytes specified");
1569     }
1570     else if (buffer == NULL) {
1571             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1572             status = PROCESSOR_E_INVALIDARG;
1573             GT_setFailureReason (curTrace,
1574                                  GT_4CLASS,
1575                                  "VAYUIPUCORE1PROC_write",
1576                                  status,
1577                                  "Invalid buffer specified");
1578     }
1579     else {
1580 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1581         if (*numBytes != sizeof (UInt32)) {
1582             procPtr8 = (UInt8 *) procAddr ;
1583             procAddr = (UInt32) Memory_copy (procPtr8,
1584                                              buffer,
1585                                              *numBytes);
1586             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1587 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1588             if (procAddr == (UInt32) NULL) {
1589                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1590                 status = PROCESSOR_E_FAIL;
1591                 GT_setFailureReason (curTrace,
1592                                      GT_4CLASS,
1593                                      "VAYUIPUCORE1PROC_write",
1594                                      status,
1595                                      "Failed in Memory_copy");
1596                 *numBytes = 0;
1597             }
1598 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1599         }
1600         else  {
1601              /* For 4 bytes, directly write as a UInt32 */
1602             temp8_1 = ((UInt8 *) buffer) [0];
1603             temp8_2 = ((UInt8 *) buffer) [1];
1604             temp8_3 = ((UInt8 *) buffer) [2];
1605             temp8_4 = ((UInt8 *) buffer) [3];
1606             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1607                              |   ((UInt32) temp8_3 << 16)
1608                              |   ((UInt32) temp8_2 << 8)
1609                              |   ((UInt32) temp8_1));
1610             *((UInt32*) procAddr) = temp;
1611         }
1612 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1613     }
1614 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1616     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_write", status);
1618     /*! @retval PROCESSOR_SUCCESS Operation successful */
1619     return status;
1623 /*!
1624  *  @brief      Function to perform device-dependent operations.
1625  *
1626  *              Performs device-dependent control operations as exposed by this
1627  *              implementation of the Processor module.
1628  *
1629  *  @param      handle     Handle to the Processor object
1630  *  @param      cmd        Device specific processor command
1631  *  @param      arg        Arguments specific to the type of command.
1632  *
1633  *  @sa
1634  */
1635 Int
1636 VAYUIPUCORE1PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1638     Int                   status       = PROCESSOR_SUCCESS ;
1640     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_control", handle, cmd, arg);
1642     GT_assert (curTrace, (handle   != NULL));
1643     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1645 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1646     if (handle == NULL) {
1647         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1648         status = PROCESSOR_E_HANDLE;
1649         GT_setFailureReason (curTrace,
1650                              GT_4CLASS,
1651                              "VAYUIPUCORE1PROC_control",
1652                              status,
1653                              "Invalid handle specified");
1654     }
1655     else {
1656 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1657         /* No control operations currently implemented. */
1658         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1659                                              for this device. */
1660         status = PROCESSOR_E_NOTSUPPORTED;
1661 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1662     }
1663 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1664     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_control",status);
1666     /*! @retval PROCESSOR_SUCCESS Operation successful */
1667     return status;
1671 /*!
1672  *  @brief      Translate slave virtual address to master physical address.
1673  *
1674  *  @param      handle     Handle to the Processor object
1675  *  @param      dstAddr    Returned: master physical address.
1676  *  @param      srcAddr    Slave virtual address.
1677  *
1678  *  @sa
1679  */
1680 Int
1681 VAYUIPUCORE1PROC_translate(
1682         Processor_Handle    handle,
1683         UInt32 *            dstAddr,
1684         UInt32              srcAddr)
1686     Int                         status = PROCESSOR_SUCCESS;
1687     Processor_Object *          procHandle= (Processor_Object *)handle;
1688     VAYUIPUCORE1PROC_Object *   object = NULL;
1689     UInt32                      i;
1690     UInt32                      startAddr;
1691     UInt32                      endAddr;
1692     UInt32                      offset;
1693     ProcMgr_AddrInfo *          ai;
1695     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1696               handle, dstAddr, srcAddr);
1698     GT_assert (curTrace, (handle  != NULL));
1699     GT_assert (curTrace, (dstAddr != NULL));
1701 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1702     if (handle == NULL) {
1703         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1704         status = PROCESSOR_E_HANDLE;
1705         GT_setFailureReason (curTrace,
1706                              GT_4CLASS,
1707                              "VAYUIPUCORE1PROC_translate",
1708                              status,
1709                              "Invalid handle specified");
1710     }
1711     else if (dstAddr == NULL) {
1712         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1713         status = PROCESSOR_E_INVALIDARG;
1714         GT_setFailureReason (curTrace,
1715                              GT_4CLASS,
1716                              "VAYUIPUCORE1PROC_translate",
1717                              status,
1718                              "dstAddr provided as NULL");
1719     }
1720     else {
1721 #endif
1722         object = (VAYUIPUCORE1PROC_Object *)procHandle->object;
1723         GT_assert(curTrace, (object != NULL));
1724         *dstAddr = -1u;
1726         /* search all entries AddrTable */
1727         for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1728             i++) {
1729             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1730             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1731             endAddr = startAddr + ai->size;
1733             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1734                 offset = srcAddr - startAddr;
1735                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1736                 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE1PROC_translate: "
1737                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1738                     i, srcAddr, *dstAddr);
1739                 break;
1740             }
1741         }
1743         if (*dstAddr == -1u) {
1744             if (!object->params.mmuEnable) {
1745                 /* default to direct mapping (i.e. v=p) */
1746                 *dstAddr = srcAddr;
1747                 GT_2trace(curTrace, GT_1CLASS, "VAYUIPUCORE1PROC_translate: "
1748                     "(default) srcAddr=0x%x --> dstAddr=0x%x",
1749                     srcAddr, *dstAddr);
1750             }
1751             else {
1752                 /* srcAddr not found in slave address space */
1753                 status = PROCESSOR_E_INVALIDARG;
1754                 GT_setFailureReason(curTrace, GT_4CLASS,
1755                     "VAYUIPUCORE1PROC_translate", status,
1756                     "srcAddr not found in slave address space");
1757             }
1758         }
1759 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1760     }
1761 #endif
1762     GT_1trace(curTrace, GT_LEAVE,
1763         "VAYUIPUCORE1PROC_translate: status=0x%x", status);
1765     /*! @retval PROCESSOR_SUCCESS Operation successful */
1766     return status;
1770 /*!
1771  *  @brief      Map the given address translation into the slave mmu
1772  *
1773  *  @param      handle      Handle to the Processor object
1774  *  @param      dstAddr     Base virtual address
1775  *  @param      nSegs       Number of given segments
1776  *  @param      sglist      Segment list
1777  */
1778 Int
1779 VAYUIPUCORE1PROC_map(
1780         Processor_Handle    handle,
1781         UInt32 *            dstAddr,
1782         UInt32              nSegs,
1783         Memory_SGList *     sglist)
1785     Int                         status = PROCESSOR_SUCCESS ;
1786     Processor_Object *          procHandle = (Processor_Object *)handle;
1787     VAYUIPUCORE1PROC_Object *   object = NULL;
1788     Bool                        found = FALSE;
1789     UInt32                      startAddr;
1790     UInt32                      endAddr;
1791     UInt32                      i;
1792     UInt32                      j;
1793     ProcMgr_AddrInfo *          ai = NULL;
1794     VAYUIPU_HalMmuCtrlArgs_AddEntry addEntryArgs;
1796     GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE1PROC_map:",
1797         handle, *dstAddr, nSegs, sglist);
1799     GT_assert (curTrace, (handle != NULL));
1800     GT_assert (curTrace, (sglist != NULL));
1801     GT_assert (curTrace, (nSegs > 0));
1803 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1804     if (handle == NULL) {
1805         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1806         status = PROCESSOR_E_HANDLE;
1807         GT_setFailureReason (curTrace,
1808                              GT_4CLASS,
1809                              "VAYUIPUCORE1PROC_map",
1810                              status,
1811                              "Invalid handle specified");
1812     }
1813     else if (sglist == NULL) {
1814         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1815         status = PROCESSOR_E_INVALIDARG;
1816         GT_setFailureReason (curTrace,
1817                              GT_4CLASS,
1818                              "VAYUIPUCORE1PROC_map",
1819                              status,
1820                              "sglist provided as NULL");
1821     }
1822     else if (nSegs == 0) {
1823         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1824         status = PROCESSOR_E_INVALIDARG;
1825         GT_setFailureReason (curTrace,
1826                              GT_4CLASS,
1827                              "VAYUIPUCORE1PROC_map",
1828                              status,
1829                              "Number of segments provided is 0");
1830     }
1831     else {
1832 #endif
1833         object = (VAYUIPUCORE1PROC_Object *)procHandle->object;
1834         GT_assert (curTrace, (object != NULL));
1836         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1837             /* Update the translation table with entries for which mapping
1838              * is required. Add the entry only if the range does not exist
1839              * in the translation table.
1840              */
1842             /* check in static entries first */
1843             for (j = 0; j < AddrTable_STATIC_COUNT; j++) {
1844                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1845                 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1846                 endAddr = startAddr + ai->size;
1848                 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)) {
1849                     found = TRUE;
1850                     /* refCount does not need to be incremented for static entries */
1851                     break;
1852                 }
1853             }
1855             /* if not found in static entries, check in dynamic entries */
1856             if (!found) {
1857                 for (j = AddrTable_STATIC_COUNT;
1858                     j < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; j++) {
1859                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1861                     if (ai->isMapped == TRUE) {
1862                         startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1863                         endAddr = startAddr + ai->size;
1865                         if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1866                             && ((*dstAddr + sglist[i].size) <= endAddr)) {
1867                             found = TRUE;
1868                             ai->refCount++;
1869                             break;
1870                         }
1871                     }
1872                 }
1873             }
1875             /* If not found, add new entry to table. If mmu is disabled,
1876              * the assumption is that the ammu will be used.
1877              */
1878             if (!found) {
1879                 if (object->params.mmuEnable) {
1880                     if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1881                         AddrTable_SIZE) {
1882                         ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1883                             [AddrTable_count[PROCID_TO_IPU
1884                             (procHandle->procId)]];
1885                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1886                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1887                         ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1888                         ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1889                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1890                         ai->size = sglist[i].size;
1891                         ai->isCached = sglist[i].isCached;
1892                         ai->refCount++;
1894                         AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1895                     }
1896                     else {
1897                         status = PROCESSOR_E_FAIL;
1898                         GT_setFailureReason(curTrace, GT_4CLASS,
1899                             "VAYUIPUCORE1PROC_map", status,
1900                             "AddrTable_SIZE reached!");
1901                     }
1902                 }
1903                 else {
1904                     /* if mmu disabled, AddrTable not updated */
1905                     ai = NULL;
1906                 }
1907             }
1909             /* if new entry, map into dsp mmu */
1910             if ((ai != NULL) && (ai->refCount == 1) && (status >= 0)) {
1911                 ai->isMapped = TRUE;
1913                 if (object->params.mmuEnable) {
1914                     /* add entry to L2 MMU */
1915                     addEntryArgs.masterPhyAddr = sglist [i].paddr;
1916                     addEntryArgs.size          = sglist [i].size;
1917                     addEntryArgs.slaveVirtAddr = (UInt32)*dstAddr;
1918                     /* TBD: elementSize, endianism, mixedSized are
1919                      * hard coded now, must be configurable later
1920                      */
1921                     addEntryArgs.elementSize   = ELEM_SIZE_16BIT;
1922                     addEntryArgs.endianism     = LITTLE_ENDIAN;
1923                     addEntryArgs.mixedSize     = MMU_TLBES;
1925                     status = VAYUIPU_halMmuCtrl(object->halObject,
1926                         Processor_MmuCtrlCmd_AddEntry, &addEntryArgs);
1928 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1929                     if (status < 0) {
1930                         GT_setFailureReason(curTrace, GT_4CLASS,
1931                             "VAYUIPUCORE1PROC_map", status,
1932                             "Processor_MmuCtrlCmd_AddEntry failed");
1933                     }
1934 #endif
1935                 }
1936             }
1937 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1938             if (status < 0) {
1939                 GT_setFailureReason(curTrace, GT_4CLASS,
1940                     "VAYUIPUCORE1PROC_map", status,
1941                     "IPUCORE1 MMU configuration failed");
1942             }
1943 #endif
1944         }
1945 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1946     }
1947 #endif
1948     GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_map", status);
1950     /*! @retval PROCESSOR_SUCCESS Operation successful */
1951     return status;
1955 /*!
1956  *  @brief      Function to unmap slave address from host address space
1957  *
1958  *  @param      handle      Handle to the Processor object
1959  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1960  *                          address.
1961  *  @param      size        Size of the region to be mapped.
1962  *
1963  *  @sa
1964  */
1965 Int
1966 VAYUIPUCORE1PROC_unmap(
1967         Processor_Handle    handle,
1968         UInt32              addr,
1969         UInt32              size)
1971     Int                         status = PROCESSOR_SUCCESS;
1972     Processor_Object *          procHandle = (Processor_Object *)handle;
1973     VAYUIPUCORE1PROC_Object *   object = NULL;
1974     ProcMgr_AddrInfo *          ai;
1975     Int                         i;
1976     UInt32                      startAddr;
1977     UInt32                      endAddr;
1978     VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1980     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_unmap",
1981                handle, addr, size);
1983     GT_assert (curTrace, (handle != NULL));
1984     GT_assert (curTrace, (size   != 0));
1986 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1987     if (handle == NULL) {
1988         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1989         status = PROCESSOR_E_HANDLE;
1990         GT_setFailureReason (curTrace,
1991                              GT_4CLASS,
1992                              "VAYUIPUCORE1PROC_unmap",
1993                              status,
1994                              "Invalid handle specified");
1995     }
1996     else if (size == 0) {
1997         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1998         status = PROCESSOR_E_INVALIDARG;
1999         GT_setFailureReason (curTrace,
2000                              GT_4CLASS,
2001                              "VAYUIPUCORE1PROC_unmap",
2002                              status,
2003                              "Size provided is zero");
2004     }
2005     else {
2006 #endif
2007         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
2008         GT_assert (curTrace, (object != NULL));
2010         /* Delete dynamically added non-default entries from translation
2011          * table only in last unmap called on that entry
2012          */
2013         for (i = AddrTable_STATIC_COUNT;
2014             i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
2015             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
2017             if (!ai->isMapped) {
2018                 continue;
2019             }
2021             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
2022             endAddr = startAddr + ai->size;
2024             if ((startAddr <= addr) && (addr < endAddr)) {
2025                 ai->refCount--;
2027                 if (ai->refCount == 0) {
2028                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
2029                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
2030                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
2031                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2032                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2033                     ai->size = 0u;
2034                     ai->isCached = FALSE;
2035                     ai->mapMask = 0u;
2036                     ai->isMapped = FALSE;
2038                     if (object->params.mmuEnable) {
2039                         /* Remove the entry from the IPUCORE1 MMU also */
2040                         deleteEntryArgs.size          = size;
2041                         deleteEntryArgs.slaveVirtAddr = addr;
2042                         /* TBD: elementSize, endianism, mixedSized are
2043                          * hard coded now, must be configurable later
2044                          */
2045                         deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2046                         deleteEntryArgs.endianism     = LITTLE_ENDIAN;
2047                         deleteEntryArgs.mixedSize     = MMU_TLBES;
2049                         status = VAYUIPU_halMmuCtrl(object->halObject,
2050                             Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2051 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2052                         if (status < 0) {
2053                             GT_setFailureReason(curTrace, GT_4CLASS,
2054                                 "VAYUIPUCORE1PROC_unmap", status,
2055                                 "IPUCORE1 MMU configuration failed");
2056                         }
2057 #endif
2058                     }
2059                 }
2060             }
2061         }
2062 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
2063     }
2064 #endif
2065     GT_1trace(curTrace, GT_LEAVE,
2066     "VAYUIPUCORE1PROC_unmap", status);
2068     /*! @retval PROCESSOR_SUCCESS Operation successful */
2069     return status;
2073 #if defined (__cplusplus)
2075 #endif /* defined (__cplusplus) */