Add INTMEM resource type support in 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  Max entries in address translation table.
92  */
93 #define AddrTable_SIZE 32
95 /* Number of IPUs supported */
96 #define NUM_IPUS 2
98 /* Convert procId to IPU # */
99 #define PROCID_TO_IPU(procId) (procId == VAYUIPUCORE1PROC_state.ipu1ProcId ?\
100     0 : 1)
104 /*!
105  *  @brief  VAYUIPUCORE1PROC Module state object
106  */
107 typedef struct VAYUIPUCORE1PROC_ModuleObject_tag {
108     UInt32                  configSize;
109     /*!< Size of configuration structure */
110     VAYUIPUCORE1PROC_Config cfg;
111     /*!< VAYUIPUCORE1PROC configuration structure */
112     VAYUIPUCORE1PROC_Config defCfg;
113     /*!< Default module configuration */
114     VAYUIPUCORE1PROC_Params      defInstParams;
115     /*!< Default parameters for the VAYUIPUCORE1PROC instances */
116     Bool                    isSetup;
117     /*!< Indicates whether the VAYUIPUCORE1PROC module is setup. */
118     VAYUIPUCORE1PROC_Handle procHandles [MultiProc_MAXPROCESSORS];
119     /*!< Processor handle array. */
120     IGateProvider_Handle             gateHandle;
121     /*!< Handle of gate to be used for local thread safety */
122     UInt16                     ipu1ProcId;
123     /*!< MultiProc id of IPU1 (to avoid multiple lookups) */
124 } VAYUIPUCORE1PROC_ModuleObject;
126 /* Memory region counters */
127 static UInt32 AddrTable_count[NUM_IPUS] = {
128     0,
129     0,
130 };
132 /* Address translation table */
133 static ProcMgr_AddrInfo AddrTable_IPU1[AddrTable_SIZE];
134 static ProcMgr_AddrInfo AddrTable_IPU2[AddrTable_SIZE];
136 static ProcMgr_AddrInfo * AddrTable[NUM_IPUS] =
138     AddrTable_IPU1,
139     AddrTable_IPU2
140 };
142 /* =============================================================================
143  *  Globals
144  * =============================================================================
145  */
147 /*!
148  *  @var    VAYUIPUCORE1PROC_state
149  *
150  *  @brief  VAYUIPUCORE1PROC state object variable
151  */
152 #if !defined(SYSLINK_BUILD_DEBUG)
153 static
154 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
155 VAYUIPUCORE1PROC_ModuleObject VAYUIPUCORE1PROC_state =
157     .isSetup = FALSE,
158     .configSize = sizeof (VAYUIPUCORE1PROC_Config),
159     .gateHandle = NULL,
160     .defInstParams.numMemEntries = 0,
161 };
163 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
164 extern String ProcMgr_sysLinkCfgParams;
166 /* =============================================================================
167  * APIs directly called by applications
168  * =============================================================================
169  */
170 /*!
171  *  @brief      Function to get the default configuration for the VAYUIPUCORE1PROC
172  *              module.
173  *
174  *              This function can be called by the application to get their
175  *              configuration parameter to VAYUIPUCORE1PROC_setup filled in by the
176  *              VAYUIPUCORE1PROC module with the default parameters. If the user
177  *              does not wish to make any change in the default parameters, this
178  *              API is not required to be called.
179  *
180  *  @param      cfg        Pointer to the VAYUIPUCORE1PROC module configuration
181  *                         structure in which the default config is to be
182  *                         returned.
183  *
184  *  @sa         VAYUIPUCORE1PROC_setup
185  */
186 Void
187 VAYUIPUCORE1PROC_getConfig (VAYUIPUCORE1PROC_Config * cfg)
189     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_getConfig", cfg);
191     GT_assert (curTrace, (cfg != NULL));
193 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
194     if (cfg == NULL) {
195         GT_setFailureReason (curTrace,
196                              GT_4CLASS,
197                              "VAYUIPUCORE1PROC_getConfig",
198                              PROCESSOR_E_INVALIDARG,
199                              "Argument of type (VAYUIPUCORE1PROC_Config *) passed "
200                              "is null!");
201     }
202     else {
203 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
204         Memory_copy (cfg,
205                      &(VAYUIPUCORE1PROC_state.defCfg),
206                      sizeof (VAYUIPUCORE1PROC_Config));
207 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
208     }
209 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
211     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_getConfig");
215 /*!
216  *  @brief      Function to setup the VAYUIPUCORE1PROC module.
217  *
218  *              This function sets up the VAYUIPUCORE1PROC module. This function
219  *              must be called before any other instance-level APIs can be
220  *              invoked.
221  *              Module-level configuration needs to be provided to this
222  *              function. If the user wishes to change some specific config
223  *              parameters, then VAYUIPUCORE1PROC_getConfig can be called to get the
224  *              configuration filled with the default values. After this, only
225  *              the required configuration values can be changed. If the user
226  *              does not wish to make any change in the default parameters, the
227  *              application can simply call VAYUIPUCORE1PROC_setup with NULL
228  *              parameters. The default parameters would get automatically used.
229  *
230  *  @param      cfg   Optional VAYUIPUCORE1PROC module configuration. If provided as
231  *                    NULL, default configuration is used.
232  *
233  *  @sa         VAYUIPUCORE1PROC_destroy
234  *              GateMutex_create
235  */
236 Int
237 VAYUIPUCORE1PROC_setup (VAYUIPUCORE1PROC_Config * cfg)
239     Int                     status = PROCESSOR_SUCCESS;
240     VAYUIPUCORE1PROC_Config tmpCfg;
241     Error_Block             eb;
243     Error_init(&eb);
245     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_setup", cfg);
247     if (cfg == NULL) {
248         VAYUIPUCORE1PROC_getConfig (&tmpCfg);
249         cfg = &tmpCfg;
250     }
252     /* Create a default gate handle for local module protection. */
253     VAYUIPUCORE1PROC_state.gateHandle = (IGateProvider_Handle)
254                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
255 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
256     if (VAYUIPUCORE1PROC_state.gateHandle == NULL) {
257         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
258         status = PROCESSOR_E_FAIL;
259         GT_setFailureReason (curTrace,
260                              GT_4CLASS,
261                              "VAYUIPUCORE1PROC_setup",
262                              status,
263                              "Failed to create GateMutex!");
264     }
265     else {
266 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
267         /* Copy the user provided values into the state object. */
268         Memory_copy (&VAYUIPUCORE1PROC_state.cfg,
269                      cfg,
270                      sizeof (VAYUIPUCORE1PROC_Config));
272         /* Initialize the name to handles mapping array. */
273         Memory_set (&VAYUIPUCORE1PROC_state.procHandles,
274                     0,
275                     (sizeof (VAYUIPUCORE1PROC_Handle) * MultiProc_MAXPROCESSORS));
277         VAYUIPUCORE1PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
278         VAYUIPUCORE1PROC_state.isSetup = TRUE;
279 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
280     }
281 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
283     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_setup", status);
285     /*! @retval PROCESSOR_SUCCESS Operation successful */
286     return (status);
290 /*!
291  *  @brief      Function to destroy the VAYUIPUCORE1PROC module.
292  *
293  *              Once this function is called, other VAYUIPUCORE1PROC module APIs,
294  *              except for the VAYUIPUCORE1PROC_getConfig API cannot be called
295  *              anymore.
296  *
297  *  @sa         VAYUIPUCORE1PROC_setup
298  *              GateMutex_delete
299  */
300 Int
301 VAYUIPUCORE1PROC_destroy (Void)
303     Int    status = PROCESSOR_SUCCESS;
304     UInt16 i;
306     GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_destroy");
308     /* Check if any VAYUIPUCORE1PROC instances have not been deleted so far. If not,
309      * delete them.
310      */
311     for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
312         GT_assert (curTrace, (VAYUIPUCORE1PROC_state.procHandles [i] == NULL));
313         if (VAYUIPUCORE1PROC_state.procHandles [i] != NULL) {
314             VAYUIPUCORE1PROC_delete (&(VAYUIPUCORE1PROC_state.procHandles [i]));
315         }
316     }
318     if (VAYUIPUCORE1PROC_state.gateHandle != NULL) {
319         GateMutex_delete ((GateMutex_Handle *)
320                                 &(VAYUIPUCORE1PROC_state.gateHandle));
321     }
323     VAYUIPUCORE1PROC_state.isSetup = FALSE;
325     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_destroy", status);
327     /*! @retval PROCESSOR_SUCCESS Operation successful */
328     return (status);
332 /*!
333  *  @brief      Function to initialize the parameters for this Processor
334  *              instance.
335  *
336  *  @param      params  Configuration parameters to be returned
337  *
338  *  @sa         VAYUIPUCORE1PROC_create
339  */
340 Void
341 VAYUIPUCORE1PROC_Params_init(
342         VAYUIPUCORE1PROC_Handle    handle,
343         VAYUIPUCORE1PROC_Params *  params)
345     VAYUIPUCORE1PROC_Object * procObject = (VAYUIPUCORE1PROC_Object *) handle;
347     GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE1PROC_Params_init",
348               handle, params);
350     GT_assert(curTrace, (params != NULL));
352 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
353     if (params == NULL) {
354         GT_setFailureReason(curTrace, GT_4CLASS,
355                             "VAYUIPUCORE1PROC_Params_init",
356                             PROCESSOR_E_INVALIDARG,
357                             "Argument of type (VAYUIPUCORE1PROC_Params *) "
358                             "passed is null!");
359     }
360     else {
361 #endif
362         if (handle == NULL) {
364             Memory_copy(params, &(VAYUIPUCORE1PROC_state.defInstParams),
365                 sizeof(VAYUIPUCORE1PROC_Params));
367         }
368         else {
369             /* return updated VAYUIPUCORE1PROC instance specific parameters */
370             Memory_copy(params, &(procObject->params),
371                         sizeof (VAYUIPUCORE1PROC_Params));
372         }
373 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
374     }
375 #endif
377     GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_Params_init");
380 /*!
381  *  @brief      Function to create an instance of this Processor.
382  *
383  *  @param      name    Name of the Processor instance.
384  *  @param      params  Configuration parameters.
385  *
386  *  @sa         VAYUIPUCORE1PROC_delete
387  */
388 VAYUIPUCORE1PROC_Handle
389 VAYUIPUCORE1PROC_create (      UInt16                procId,
390                      const VAYUIPUCORE1PROC_Params * params)
392     Int                   status    = PROCESSOR_SUCCESS;
393     Processor_Object *    handle    = NULL;
394     VAYUIPUCORE1PROC_Object * object    = NULL;
395     Int i                            = 0;
396     ProcMgr_AddrInfo *ai             = NULL;
397     IArg                  key;
398     List_Params           listParams;
400     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_create", procId, params);
402     GT_assert (curTrace, IS_VALID_PROCID (procId));
403     GT_assert (curTrace, (params != NULL));
405 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
406     if (!IS_VALID_PROCID (procId)) {
407         /* Not setting status here since this function does not return status.*/
408         GT_setFailureReason (curTrace,
409                              GT_4CLASS,
410                              "VAYUIPUCORE1PROC_create",
411                              PROCESSOR_E_INVALIDARG,
412                              "Invalid procId specified");
413     }
414     else if (params == NULL) {
415         GT_setFailureReason (curTrace,
416                              GT_4CLASS,
417                              "VAYUIPUCORE1PROC_create",
418                              PROCESSOR_E_INVALIDARG,
419                              "params passed is NULL!");
420     }
421     else {
422 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
423         /* Enter critical section protection. */
424         key = IGateProvider_enter (VAYUIPUCORE1PROC_state.gateHandle);
425 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
426         /* Check if the Processor already exists for specified procId. */
427         if (VAYUIPUCORE1PROC_state.procHandles [procId] != NULL) {
428             status = PROCESSOR_E_ALREADYEXIST;
429             GT_setFailureReason (curTrace,
430                               GT_4CLASS,
431                               "VAYUIPUCORE1PROC_create",
432                               status,
433                               "Processor already exists for specified procId!");
434         }
435         else {
436 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
437             /* Allocate memory for the handle */
438             handle = (Processor_Object *) Memory_calloc (NULL,
439                                                       sizeof (Processor_Object),
440                                                       0,
441                                                       NULL);
442             if (handle == NULL) {
443                 GT_setFailureReason (curTrace,
444                                      GT_4CLASS,
445                                      "VAYUIPUCORE1PROC_create",
446                                      PROCESSOR_E_MEMORY,
447                                      "Memory allocation failed for handle!");
448             }
449             else {
450                 /* Populate the handle fields */
451                 handle->procFxnTable.attach      = &VAYUIPUCORE1PROC_attach;
452                 handle->procFxnTable.detach      = &VAYUIPUCORE1PROC_detach;
453                 handle->procFxnTable.start       = &VAYUIPUCORE1PROC_start;
454                 handle->procFxnTable.stop        = &VAYUIPUCORE1PROC_stop;
455                 handle->procFxnTable.read        = &VAYUIPUCORE1PROC_read;
456                 handle->procFxnTable.write       = &VAYUIPUCORE1PROC_write;
457                 handle->procFxnTable.control     = &VAYUIPUCORE1PROC_control;
458                 handle->procFxnTable.map         = &VAYUIPUCORE1PROC_map;
459                 handle->procFxnTable.unmap       = &VAYUIPUCORE1PROC_unmap;
460                 handle->procFxnTable.translateAddr = &VAYUIPUCORE1PROC_translate;
461                 handle->state = ProcMgr_State_Unknown;
463                 /* Allocate memory for the VAYUIPUCORE1PROC handle */
464                 handle->object = Memory_calloc (NULL,
465                                                 sizeof (VAYUIPUCORE1PROC_Object),
466                                                 0,
467                                                 NULL);
468                 if (handle->object == NULL) {
469                     status = PROCESSOR_E_MEMORY;
470                     GT_setFailureReason (curTrace,
471                                 GT_4CLASS,
472                                 "VAYUIPUCORE1PROC_create",
473                                 status,
474                                 "Memory allocation failed for handle->object!");
475                 }
476                 else {
477                     handle->procId = procId;
478                     object = (VAYUIPUCORE1PROC_Object *) handle->object;
479                     object->procHandle = (Processor_Handle)handle;
480                     object->halObject = NULL;
481                     /* Copy params into instance object. */
482                     Memory_copy (&(object->params),
483                                  (Ptr) params,
484                                  sizeof (VAYUIPUCORE1PROC_Params));
486                     /* initialize the translation table */
487                     for (i = AddrTable_count[PROCID_TO_IPU(procId)];
488                         i < AddrTable_SIZE; i++) {
489                         ai = &AddrTable[PROCID_TO_IPU(procId)][i];
490                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
491                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
492                         ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
493                         ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
494                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
495                         ai->size = 0u;
496                         ai->isCached = FALSE;
497                         ai->mapMask = 0u;
498                         ai->isMapped = FALSE;
499                     }
501                     /*
502                      * initialize refCount for all entries
503                      */
504                     for (i = 0; i < AddrTable_SIZE; i++) {
505                         AddrTable[PROCID_TO_IPU(procId)][i].refCount = 0u;
506                     }
507                     Memory_copy((Ptr)(object->params.memEntries),
508                         AddrTable[PROCID_TO_IPU(procId)],
509                         (procId == VAYUIPUCORE1PROC_state.ipu1ProcId ?
510                         sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
512                     /* Set the handle in the state object. */
513                     VAYUIPUCORE1PROC_state.procHandles [procId] =
514                                                (VAYUIPUCORE1PROC_Handle) handle;
515                     /* Initialize the list of listeners */
516                     List_Params_init(&listParams);
517                     handle->registeredNotifiers = List_create(&listParams);
519 #if !defined(SYSLINK_BUILD_OPTIMIZE)
520                     if (handle->registeredNotifiers == NULL) {
521                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
522                         status = PROCESSOR_E_FAIL;
523                         GT_setFailureReason (curTrace,
524                                              GT_4CLASS,
525                                              "VAYUIPUCORE1PROC_create",
526                                              status,
527                                              "List_create failed");
528                     }
529                     else {
530 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
532                         handle->notifiersLock =
533                                  OsalMutex_create(OsalMutex_Type_Interruptible);
535 #if !defined(SYSLINK_BUILD_OPTIMIZE)
536                         if (handle->notifiersLock == NULL) {
537                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
538                             status = PROCESSOR_E_FAIL;
539                             GT_setFailureReason (curTrace,
540                                                  GT_4CLASS,
541                                                  "VAYUIPUCORE1PROC_create",
542                                                  status,
543                                                  "OsalMutex_create failed");
544                         }
545                     }
546 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
547                 }
548             }
549 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
550         }
551 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
553         /* Leave critical section protection. */
554         IGateProvider_leave (VAYUIPUCORE1PROC_state.gateHandle, key);
555 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
556     }
557 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
559     if (status < 0) {
560         if (handle !=  NULL) {
561             if (handle->registeredNotifiers != NULL) {
562                 List_delete (&handle->registeredNotifiers);
563             }
564             if (handle->object != NULL) {
565                 Memory_free (NULL,
566                              handle->object,
567                              sizeof (VAYUIPUCORE1PROC_Object));
568             }
569             Memory_free (NULL, handle, sizeof (Processor_Object));
570         }
571         /*! @retval NULL Function failed */
572         handle = NULL;
573     }
575     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_create", handle);
577     /*! @retval Valid-Handle Operation successful */
578     return (VAYUIPUCORE1PROC_Handle) handle;
582 /*!
583  *  @brief      Function to delete an instance of this Processor.
584  *
585  *              The user provided pointer to the handle is reset after
586  *              successful completion of this function.
587  *
588  *  @param      handlePtr  Pointer to Handle to the Processor instance
589  *
590  *  @sa         VAYUIPUCORE1PROC_create
591  */
592 Int
593 VAYUIPUCORE1PROC_delete (VAYUIPUCORE1PROC_Handle * handlePtr)
595     Int                   status = PROCESSOR_SUCCESS;
596     VAYUIPUCORE1PROC_Object * object = NULL;
597     Processor_Object *    handle;
598     IArg                  key;
599     List_Elem *           elem    = NULL;
600     Processor_RegisterElem * regElem = NULL;
602     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_delete", handlePtr);
604     GT_assert (curTrace, (handlePtr != NULL));
605     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
607 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
608     if (handlePtr == NULL) {
609         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
610                                          specified*/
611         status = PROCESSOR_E_INVALIDARG;
612         GT_setFailureReason (curTrace,
613                              GT_4CLASS,
614                              "VAYUIPUCORE1PROC_delete",
615                              status,
616                              "Invalid NULL handlePtr pointer specified");
617     }
618     else if (*handlePtr == NULL) {
619         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
620         status = PROCESSOR_E_HANDLE;
621         GT_setFailureReason (curTrace,
622                              GT_4CLASS,
623                              "VAYUIPUCORE1PROC_delete",
624                              status,
625                              "Invalid NULL *handlePtr specified");
626     }
627     else {
628 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
629         handle = (Processor_Object *) (*handlePtr);
630         /* Enter critical section protection. */
631         key = IGateProvider_enter (VAYUIPUCORE1PROC_state.gateHandle);
633         /* Reset handle in PwrMgr handle array. */
634         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
635         VAYUIPUCORE1PROC_state.procHandles [handle->procId] = NULL;
637         /* Free memory used for the VAYUIPUCORE1PROC object. */
638         if (handle->object != NULL) {
639             object = (VAYUIPUCORE1PROC_Object *) handle->object;
640             Memory_free (NULL,
641                          object,
642                          sizeof (VAYUIPUCORE1PROC_Object));
643             handle->object = NULL;
644         }
646         /*
647          * Check the list of listeners to see if any are remaining
648          * and reply to them
649          */
650         OsalMutex_delete(&handle->notifiersLock);
652         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
653             regElem = (Processor_RegisterElem *)elem;
655             /* Check if there is an associated timer and cancel it */
656             if (regElem->timer != -1) {
657                 struct itimerspec value ;
658                 value.it_value.tv_sec = 0;
659                 value.it_value.tv_nsec = 0;
660                 value.it_interval.tv_sec = 0;
661                 value.it_interval.tv_nsec = 0;
662                 timer_settime(regElem->timer, 0, &value, NULL);
664                 timer_delete(regElem->timer);
665                 regElem->timer = -1;
666             }
668             /* Call the callback function so it can clean up. */
669             regElem->info->cbFxn(handle->procId,
670                                  NULL,
671                                  handle->state,
672                                  handle->state,
673                                  ProcMgr_EventStatus_Canceled,
674                                  regElem->info->arg);
675             /* Free the memory */
676             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
677         }
679         /* Delete the list of listeners */
680         List_delete(&handle->registeredNotifiers);
682         /* Free memory used for the Processor object. */
683         Memory_free (NULL, handle, sizeof (Processor_Object));
684         *handlePtr = NULL;
686         /* Leave critical section protection. */
687         IGateProvider_leave (VAYUIPUCORE1PROC_state.gateHandle, key);
688 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
689     }
690 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
692     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_delete", status);
694     /*! @retval PROCESSOR_SUCCESS Operation successful */
695     return (status);
699 /*!
700  *  @brief      Function to open a handle to an instance of this Processor. This
701  *              function is called when access to the Processor is required from
702  *              a different process.
703  *
704  *  @param      handlePtr   Handle to the Processor instance
705  *  @param      procId      Processor ID addressed by this Processor instance.
706  *
707  *  @sa         VAYUIPUCORE1PROC_close
708  */
709 Int
710 VAYUIPUCORE1PROC_open (VAYUIPUCORE1PROC_Handle * handlePtr, UInt16 procId)
712     Int status = PROCESSOR_SUCCESS;
714     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_open", handlePtr, procId);
716     GT_assert (curTrace, (handlePtr != NULL));
717     GT_assert (curTrace, IS_VALID_PROCID (procId));
719 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
720     if (handlePtr == NULL) {
721         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
722         status = PROCESSOR_E_HANDLE;
723         GT_setFailureReason (curTrace,
724                              GT_4CLASS,
725                              "VAYUIPUCORE1PROC_open",
726                              status,
727                              "Invalid NULL handlePtr specified");
728     }
729     else if (!IS_VALID_PROCID (procId)) {
730         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
731         status = PROCESSOR_E_INVALIDARG;
732         GT_setFailureReason (curTrace,
733                              GT_4CLASS,
734                              "VAYUIPUCORE1PROC_open",
735                              status,
736                              "Invalid procId specified");
737     }
738     else {
739 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
740         /* Initialize return parameter handle. */
741         *handlePtr = NULL;
743         /* Check if the PwrMgr exists and return the handle if found. */
744         if (VAYUIPUCORE1PROC_state.procHandles [procId] == NULL) {
745             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
746             status = PROCESSOR_E_NOTFOUND;
747             GT_setFailureReason (curTrace,
748                              GT_4CLASS,
749                              "VAYUIPUCORE1PROC_open",
750                              status,
751                              "Specified VAYUIPUCORE1PROC instance does not exist!");
752         }
753         else {
754             *handlePtr = VAYUIPUCORE1PROC_state.procHandles [procId];
755         }
756 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
757     }
758 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
760     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_open", status);
762     /*! @retval PROCESSOR_SUCCESS Operation successful */
763     return status;
767 /*!
768  *  @brief      Function to close a handle to an instance of this Processor.
769  *
770  *  @param      handlePtr  Pointer to Handle to the Processor instance
771  *
772  *  @sa         VAYUIPUCORE1PROC_open
773  */
774 Int
775 VAYUIPUCORE1PROC_close (VAYUIPUCORE1PROC_Handle * handlePtr)
777     Int status = PROCESSOR_SUCCESS;
779     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_close", handlePtr);
781     GT_assert (curTrace, (handlePtr != NULL));
782     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
784 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
785     if (handlePtr == NULL) {
786         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
787                                          specified*/
788         status = PROCESSOR_E_INVALIDARG;
789         GT_setFailureReason (curTrace,
790                              GT_4CLASS,
791                              "VAYUIPUCORE1PROC_close",
792                              status,
793                              "Invalid NULL handlePtr pointer specified");
794     }
795     else if (*handlePtr == NULL) {
796         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
797         status = PROCESSOR_E_HANDLE;
798         GT_setFailureReason (curTrace,
799                              GT_4CLASS,
800                              "VAYUIPUCORE1PROC_close",
801                              status,
802                              "Invalid NULL *handlePtr specified");
803     }
804     else {
805 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
806         /* Nothing to be done for close. */
807 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
808     }
809 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
811     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_close", status);
813     /*! @retval PROCESSOR_SUCCESS Operation successful */
814     return status;
818 /* =============================================================================
819  * APIs called by Processor module (part of function table interface)
820  * =============================================================================
821  */
822 /*!
823  *  @brief      Function to initialize the slave processor
824  *
825  *  @param      handle  Handle to the Processor instance
826  *  @param      params  Attach parameters
827  *
828  *  @sa         VAYUIPUCORE1PROC_detach
829  */
830 Int
831 VAYUIPUCORE1PROC_attach(
832         Processor_Handle            handle,
833         Processor_AttachParams *    params)
836     Int                         status = PROCESSOR_SUCCESS ;
837     Processor_Object *          procHandle = (Processor_Object *)handle;
838     VAYUIPUCORE1PROC_Object *  object = NULL;
839     UInt32                      i = 0;
840     UInt32                      index = 0;
841     ProcMgr_AddrInfo *          me;
842     SysLink_MemEntry *          entry;
843     SysLink_MemEntry_Block      memBlock;
844     VAYUIPU_HalMmuCtrlArgs_Enable mmuEnableArgs;
845     VAYUIPU_HalParams           halParams;
847     GT_2trace(curTrace, GT_ENTER,
848               "VAYUIPUCORE1PROC_attach", handle, params);
849     GT_assert (curTrace, (handle != NULL));
850     GT_assert (curTrace, (params != NULL));
852 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
853     if (handle == NULL) {
854         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
855         status = PROCESSOR_E_HANDLE;
856         GT_setFailureReason (curTrace,
857                              GT_4CLASS,
858                              "VAYUIPUCORE1PROC_attach",
859                              status,
860                              "Invalid handle specified");
861     }
862     else if (params == NULL) {
863             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
864             status = PROCESSOR_E_INVALIDARG;
865             GT_setFailureReason (curTrace,
866                                  GT_4CLASS,
867                                  "VAYUIPUCORE1PROC_attach",
868                                  status,
869                                  "Invalid params specified");
870     }
871     else {
872 #endif
873         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
874         GT_assert (curTrace, (object != NULL));
876         /* Added for Netra Benelli core0 is cortex M4 */
877         params->procArch = Processor_ProcArch_M4;
879         object->pmHandle = params->pmHandle;
880         GT_0trace(curTrace, GT_1CLASS,
881             "VAYUIPUCORE1PROC_attach: Mapping memory regions");
883         /* search for dsp memory map */
884         status = RscTable_process(procHandle->procId,
885                                   TRUE,
886                                   &memBlock.numEntries);
887         if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
888             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
889             status = PROCESSOR_E_INVALIDARG;
890             GT_setFailureReason (curTrace,
891                                  GT_4CLASS,
892                                  "VAYUIPUCORE1PROC_attach",
893                                  status,
894                                  "Failed to process resource table");
895         }
896         else {
897             status = RscTable_getMemEntries(procHandle->procId,
898                                             memBlock.memEntries,
899                                             &memBlock.numEntries);
900             if (status < 0) {
901                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
902                 status = PROCESSOR_E_INVALIDARG;
903                 GT_setFailureReason (curTrace,
904                                      GT_4CLASS,
905                                      "VAYUIPUCORE1PROC_attach",
906                                      status,
907                                      "Failed to get resource table memEntries");
908             }
909         }
911         /* update translation tables with memory map */
912         for (i = 0; (i < memBlock.numEntries)
913             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
915             entry = &memBlock.memEntries[i];
917             if (entry->map == FALSE) {
918                 /* update table with entries which don't require mapping */
919                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
920                    AddrTable_SIZE) {
921                     me = &AddrTable[PROCID_TO_IPU(procHandle->procId)][
922                         AddrTable_count[PROCID_TO_IPU(procHandle->procId)]];
924                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
925                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
926                     me->addr[ProcMgr_AddrType_MasterPhys] =
927                         entry->masterPhysAddr;
928                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
929                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
930                     me->size = entry->size;
931                     me->isCached = entry->isCached;
932                     me->mapMask = entry->mapMask;
934                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
935                 }
936                 else {
937                     status = PROCESSOR_E_FAIL;
938                     GT_setFailureReason(curTrace, GT_4CLASS,
939                         "VAYUIPUCORE1PROC_attach", status,
940                         "AddrTable_SIZE reached!");
941                 }
942             }
943             else if (entry->map == TRUE) {
944                 /* send these entries back to ProcMgr for mapping */
945                 index = object->params.numMemEntries;
947                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
948                     me = &object->params.memEntries[index];
950                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
951                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
952                     me->addr[ProcMgr_AddrType_MasterPhys] =
953                         entry->masterPhysAddr;
954                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
955                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
956                     me->size = entry->size;
957                     me->isCached = entry->isCached;
958                     me->mapMask = entry->mapMask;
960                     object->params.numMemEntries++;
961                 }
962                 else {
963                     status = PROCESSOR_E_FAIL;
964                     GT_setFailureReason(curTrace, GT_4CLASS,
965                                         "VAYUIPUCORE1PROC_attach", status,
966                                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
967                 }
968             }
969             else {
970                 status = PROCESSOR_E_INVALIDARG;
971                 GT_setFailureReason(curTrace, GT_4CLASS,
972                     "VAYUIPUCORE1PROC_attach", status,
973                     "Memory map has entry with invalid 'map' value");
974             }
975         } /* for (...) */
977         if (status >= 0) {
978             /* populate the return params */
979             params->numMemEntries = object->params.numMemEntries;
980             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
981                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
983             halParams.procId = procHandle->procId;
984             status = VAYUIPU_halInit(&(object->halObject), &halParams);
986 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)
987             if (status < 0) {
988                 GT_setFailureReason(curTrace, GT_4CLASS,
989                     "VAYUIPUCORE1PROC_attach", status,
990                     "VAYUIPU_halInit failed");
991             }
992             else {
993 #endif
994                 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
995                     || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
997 #if !defined(SYSLINK_BUILD_OPTIMIZE)
998                     if (status < 0) {
999                         GT_setFailureReason(curTrace, GT_4CLASS,
1000                             "VAYUIPUCORE1PROC_attach", status,
1001                             "Failed to reset the slave processor");
1002                     }
1003                     else {
1004 #endif
1005                         GT_0trace(curTrace, GT_1CLASS,
1006                             "VAYUIPUCORE1PROC_attach: slave is now in reset");
1008                         mmuEnableArgs.numMemEntries = 0;
1009                         status = VAYUIPU_halMmuCtrl(object->halObject,
1010                             Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1011 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1012                         if (status < 0) {
1013                             GT_setFailureReason(curTrace, GT_4CLASS,
1014                                 "VAYUIPUCORE1PROC_attach", status,
1015                                 "Failed to enable the slave MMU");
1016                         }
1017                         else {
1018 #endif
1019                             GT_0trace(curTrace, GT_2CLASS,
1020                                 "VAYUIPUCORE1PROC_attach: Slave MMU "
1021                                 "is configured!");
1022                             /*
1023                              * Pull IPU MMU out of reset to make internal
1024                              * memory "loadable"
1025                              */
1026                             status = VAYUIPUCORE1_halResetCtrl(
1027                                 object->halObject,
1028                                 Processor_ResetCtrlCmd_MMU_Release);
1029                             if (status < 0) {
1030                                 /*! @retval status */
1031                                 GT_setFailureReason(curTrace,
1032                                     GT_4CLASS,
1033                                     "VAYUIPUCORE1_halResetCtrl",
1034                                     status,
1035                                     "Reset MMU_Release failed");
1036                             }
1037 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1038                         }
1039                     }
1040 #endif
1041                 }
1042 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1043             }
1044 #endif
1045         }
1046 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1047     }
1048 #endif
1050     GT_1trace(curTrace, GT_LEAVE,
1051         "VAYUIPUCORE1PROC_attach", status);
1053     /*! @retval PROCESSOR_SUCCESS Operation successful */
1054     return status;
1058 /*!
1059  *  @brief      Function to detach from the Processor.
1060  *
1061  *  @param      handle  Handle to the Processor instance
1062  *
1063  *  @sa         VAYUIPUCORE1PROC_attach
1064  */
1065 Int
1066 VAYUIPUCORE1PROC_detach (Processor_Handle handle)
1068     Int                       status     = PROCESSOR_SUCCESS;
1069     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1070     Processor_Object *        procHandle = (Processor_Object *) handle;
1071     VAYUIPUCORE1PROC_Object * object     = NULL;
1072     Int                       i          = 0;
1073     ProcMgr_AddrInfo *        ai;
1075     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_detach", handle);
1076     GT_assert (curTrace, (handle != NULL));
1078 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1079     if (handle == NULL) {
1080         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1081         status = PROCESSOR_E_HANDLE;
1082         GT_setFailureReason (curTrace,
1083                              GT_4CLASS,
1084                              "VAYUIPUCORE1PROC_detach",
1085                              PROCESSOR_E_HANDLE,
1086                              "Invalid handle specified");
1087     }
1088     else {
1089 #endif
1090         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1091         GT_assert (curTrace, (object != NULL));
1093         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1094             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1096             GT_0trace(curTrace, GT_2CLASS,
1097                 "VAYUIPUCORE1PROC_detach: Disabling Slave MMU ...");
1099             status = VAYUIPUCORE1_halResetCtrl(object->halObject,
1100                 Processor_ResetCtrlCmd_MMU_Reset);
1101 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1102             if (status < 0) {
1103                 /*! @retval status */
1104                 GT_setFailureReason (curTrace,
1105                                      GT_4CLASS,
1106                                      "VAYUIPUCORE1_halResetCtrl",
1107                                      status,
1108                                      "Reset MMU failed");
1109             }
1110 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1112             status = VAYUIPU_halMmuCtrl(object->halObject,
1113                 Processor_MmuCtrlCmd_Disable, NULL);
1114 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1115             if (status < 0) {
1116                 GT_setFailureReason(curTrace, GT_4CLASS,
1117                     "VAYUIPUCORE1PROC_detach", status,
1118                     "Failed to disable the slave MMU");
1119             }
1120 #endif
1122             /* delete all dynamically added entries */
1123             for (i = 0; i <
1124                 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1125                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1126                 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1127                 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1128                 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1129                 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1130                 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1131                 ai->size = 0u;
1132                 ai->isCached = FALSE;
1133                 ai->mapMask = 0u;
1134                 ai->isMapped = FALSE;
1135                 ai->refCount = 0u;
1136             }
1137             object->params.numMemEntries = 0;
1138             AddrTable_count[PROCID_TO_IPU(procHandle->procId)] = 0;
1140             //No need to reset.. that will be done in STOP
1141             /*tmpStatus = VAYUIPUCORE1_halResetCtrl(object->halObject,
1142                 Processor_ResetCtrlCmd_Reset, NULL);
1144             GT_0trace(curTrace, GT_2CLASS,
1145                 "VAYUIPUCORE1PROC_detach: Slave processor is now in reset");*/
1147 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1148             if ((tmpStatus < 0) && (status >= 0)) {
1149                 status = tmpStatus;
1150                 GT_setFailureReason (curTrace,
1151                                      GT_4CLASS,
1152                                      "VAYUIPUCORE1PROC_detach",
1153                                      status,
1154                                      "Failed to reset the slave processor");
1155             }
1156 #endif
1157         }
1159         GT_0trace (curTrace,
1160                    GT_2CLASS,
1161                    "    VAYUIPUCORE1PROC_detach: Unmapping memory regions\n");
1163         tmpStatus = VAYUIPU_halExit (object->halObject);
1164 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1165         if ((tmpStatus < 0) && (status >= 0)) {
1166             status = tmpStatus;
1167             GT_setFailureReason (curTrace,
1168                                  GT_4CLASS,
1169                                  "VAYUIPUCORE1PROC_detach",
1170                                  status,
1171                                  "Failed to finalize HAL object");
1172         }
1173     }
1174 #endif
1176     GT_1trace(curTrace, GT_LEAVE,
1177         "VAYUIPUCORE1PROC_detach", status);
1179     /*! @retval PROCESSOR_SUCCESS Operation successful */
1180     return status;
1184 /*!
1185  *  @brief      Function to start the slave processor
1186  *
1187  *              Start the slave processor running from its entry point.
1188  *              Depending on the boot mode, this involves configuring the boot
1189  *              address and releasing the slave from reset.
1190  *
1191  *  @param      handle    Handle to the Processor instance
1192  *
1193  *  @sa         VAYUIPUCORE1PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE1_halResetCtrl
1194  */
1195 Int
1196 VAYUIPUCORE1PROC_start (Processor_Handle        handle,
1197                         UInt32                  entryPt,
1198                         Processor_StartParams * params)
1200     Int                   status        = PROCESSOR_SUCCESS ;
1201     Processor_Object *    procHandle    = (Processor_Object *) handle;
1202     VAYUIPUCORE1PROC_Object * object    = NULL;
1205     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_start",
1206                handle, entryPt, params);
1208     GT_assert (curTrace, (handle != NULL));
1209     GT_assert (curTrace, (params != NULL));
1211 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1212     if (handle == NULL) {
1213         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1214         status = PROCESSOR_E_HANDLE;
1215         GT_setFailureReason (curTrace,
1216                              GT_4CLASS,
1217                              "VAYUIPUCORE1PROC_start",
1218                              status,
1219                              "Invalid handle specified");
1220     }
1221     else if (params == NULL) {
1222             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1223             status = PROCESSOR_E_INVALIDARG;
1224             GT_setFailureReason (curTrace,
1225                                  GT_4CLASS,
1226                                  "VAYUIPUCORE1PROC_start",
1227                                  status,
1228                                  "Invalid params specified");
1229     }
1230     else {
1231 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1232         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1233         GT_assert (curTrace, (object != NULL));
1234         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1235             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1236             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1237             /* Slave is to be started only for Boot mode and NoLoad mode. */
1238             /* Specify the IPUCORE1 boot address in the boot config register */
1239             status = VAYUIPU_halBootCtrl (object->halObject,
1240                                           Processor_BootCtrlCmd_SetEntryPoint,
1241                                           (Ptr) entryPt);
1242 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1243             if (status < 0) {
1244                 GT_setFailureReason (curTrace,
1245                                      GT_4CLASS,
1246                                      "VAYUIPUCORE1PROC_start",
1247                                      status,
1248                                      "Failed to set slave boot entry point");
1249             }
1250             else {
1251 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1253                 /* release the slave cpu from reset */
1254                 if (status >= 0) {
1255                     status = VAYUIPUCORE1_halResetCtrl(object->halObject,
1256                                                 Processor_ResetCtrlCmd_Release);
1257 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1258                     if (status < 0) {
1259                         GT_setFailureReason (curTrace,
1260                                           GT_4CLASS,
1261                                           "VAYUIPUCORE1PROC_start",
1262                                           status,
1263                                           "Failed to release slave from reset");
1264                     }
1265 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1266                 }
1267 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1268             }
1269 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1270         }
1272 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1273     }
1274 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1276     if (status >= 0) {
1277         GT_0trace (curTrace,
1278                    GT_1CLASS,
1279                    "    VAYUIPUCORE1PROC_start: Slave successfully started!\n");
1280     }
1281     else {
1282         GT_0trace (curTrace,
1283                    GT_1CLASS,
1284                    "    VAYUIPUCORE1PROC_start: Slave could not be started!\n");
1285     }
1287     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_start", status);
1289     /*! @retval PROCESSOR_SUCCESS Operation successful */
1290     return status;
1294 /*!
1295  *  @brief      Function to stop the slave processor
1296  *
1297  *              Stop the execution of the slave processor. Depending on the boot
1298  *              mode, this may result in placing the slave processor in reset.
1299  *
1300  *  @param      handle    Handle to the Processor instance
1301  *
1302  *  @sa         VAYUIPUCORE1PROC_start, VAYUIPUCORE1_halResetCtrl
1303  */
1304 Int
1305 VAYUIPUCORE1PROC_stop (Processor_Handle handle)
1307     Int                   status       = PROCESSOR_SUCCESS ;
1308     Processor_Object *    procHandle   = (Processor_Object *) handle;
1309     VAYUIPUCORE1PROC_Object * object       = NULL;
1311     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_stop", handle);
1313     GT_assert (curTrace, (handle != NULL));
1315 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1316     if (handle == NULL) {
1317         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1318         status = PROCESSOR_E_HANDLE;
1319         GT_setFailureReason (curTrace,
1320                              GT_4CLASS,
1321                              "VAYUIPUCORE1PROC_stop",
1322                              status,
1323                              "Invalid handle specified");
1324     }
1325     else {
1326 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1327         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1328         GT_assert (curTrace, (object != NULL));
1329         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1330             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1331             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1332             /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1333             /* Place the slave processor in reset. */
1334             status = VAYUIPUCORE1_halResetCtrl (object->halObject,
1335                                           Processor_ResetCtrlCmd_Reset);
1337             GT_0trace (curTrace,
1338                        GT_1CLASS,
1339                        "    VAYUIPUCORE1PROC_stop: Slave is now in reset!\n");
1340 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1341             if (status < 0) {
1342                 GT_setFailureReason (curTrace,
1343                                      GT_4CLASS,
1344                                      "VAYUIPUCORE1PROC_stop",
1345                                      status,
1346                                      "Failed to place slave in reset");
1347             }
1348 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1350         }
1351 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1352     }
1353 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1354     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_stop", status);
1356     /*! @retval PROCESSOR_SUCCESS Operation successful */
1357     return status;
1361 /*!
1362  *  @brief      Function to read from the slave processor's memory.
1363  *
1364  *              Read from the slave processor's memory and copy into the
1365  *              provided buffer.
1366  *
1367  *  @param      handle     Handle to the Processor instance
1368  *  @param      procAddr   Address in host processor's address space of the
1369  *                         memory region to read from.
1370  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1371  *                         number of bytes to be read. When the function
1372  *                         returns, this parameter contains the number of bytes
1373  *                         actually read.
1374  *  @param      buffer     User-provided buffer in which the slave processor's
1375  *                         memory contents are to be copied.
1376  *
1377  *  @sa         VAYUIPUCORE1PROC_write
1378  */
1379 Int
1380 VAYUIPUCORE1PROC_read (Processor_Handle   handle,
1381                        UInt32             procAddr,
1382                        UInt32 *           numBytes,
1383                        Ptr                buffer)
1385     Int       status   = PROCESSOR_SUCCESS ;
1386     UInt8  *  procPtr8 = NULL;
1388     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_read",
1389                handle, procAddr, numBytes, buffer);
1391     GT_assert (curTrace, (handle   != NULL));
1392     GT_assert (curTrace, (numBytes != NULL));
1393     GT_assert (curTrace, (buffer   != NULL));
1395 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1396     if (handle == NULL) {
1397         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1398         status = PROCESSOR_E_HANDLE;
1399         GT_setFailureReason (curTrace,
1400                              GT_4CLASS,
1401                              "VAYUIPUCORE1PROC_read",
1402                              status,
1403                              "Invalid handle specified");
1404     }
1405     else if (numBytes == 0) {
1406             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1407             status = PROCESSOR_E_INVALIDARG;
1408             GT_setFailureReason (curTrace,
1409                                  GT_4CLASS,
1410                                  "VAYUIPUCORE1PROC_read",
1411                                  status,
1412                                  "Invalid numBytes specified");
1413     }
1414     else if (buffer == NULL) {
1415             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1416             status = PROCESSOR_E_INVALIDARG;
1417             GT_setFailureReason (curTrace,
1418                                  GT_4CLASS,
1419                                  "VAYUIPUCORE1PROC_read",
1420                                  status,
1421                                  "Invalid buffer specified");
1422     }
1423     else {
1424 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1425         procPtr8 = (UInt8 *) procAddr ;
1426         buffer = memcpy (buffer, procPtr8, *numBytes);
1427         GT_assert (curTrace, (buffer != (UInt32) NULL));
1428 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1429         if (buffer == (UInt32) NULL) {
1430             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1431             status = PROCESSOR_E_FAIL;
1432             GT_setFailureReason (curTrace,
1433                                  GT_4CLASS,
1434                                  "VAYUIPUCORE1PROC_read",
1435                                  status,
1436                                  "Failed in memcpy");
1437             *numBytes = 0;
1438         }
1439     }
1440 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1442     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_read",status);
1444     /*! @retval PROCESSOR_SUCCESS Operation successful */
1445     return status;
1449 /*!
1450  *  @brief      Function to write into the slave processor's memory.
1451  *
1452  *              Read from the provided buffer and copy into the slave
1453  *              processor's memory.
1454  *
1455  *  @param      handle     Handle to the Processor object
1456  *  @param      procAddr   Address in host processor's address space of the
1457  *                         memory region to write into.
1458  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1459  *                         number of bytes to be written. When the function
1460  *                         returns, this parameter contains the number of bytes
1461  *                         actually written.
1462  *  @param      buffer     User-provided buffer from which the data is to be
1463  *                         written into the slave processor's memory.
1464  *
1465  *  @sa         VAYUIPUCORE1PROC_read, VAYUIPUCORE1PROC_translateAddr
1466  */
1467 Int
1468 VAYUIPUCORE1PROC_write (Processor_Handle handle,
1469                         UInt32           procAddr,
1470                         UInt32 *         numBytes,
1471                         Ptr              buffer)
1473     Int                   status       = PROCESSOR_SUCCESS ;
1474     UInt8  *              procPtr8     = NULL;
1475     UInt8                 temp8_1;
1476     UInt8                 temp8_2;
1477     UInt8                 temp8_3;
1478     UInt8                 temp8_4;
1479     UInt32                temp;
1481     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_write",
1482                handle, procAddr, numBytes, buffer);
1484     GT_assert (curTrace, (handle   != NULL));
1485     GT_assert (curTrace, (numBytes != NULL));
1486     GT_assert (curTrace, (buffer   != NULL));
1488 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1489     if (handle == NULL) {
1490         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1491         status = PROCESSOR_E_HANDLE;
1492         GT_setFailureReason (curTrace,
1493                              GT_4CLASS,
1494                              "VAYUIPUCORE1PROC_write",
1495                              status,
1496                              "Invalid handle specified");
1497     }
1498     else if (numBytes == 0) {
1499             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1500             status = PROCESSOR_E_INVALIDARG;
1501             GT_setFailureReason (curTrace,
1502                                  GT_4CLASS,
1503                                  "VAYUIPUCORE1PROC_write",
1504                                  status,
1505                                  "Invalid numBytes specified");
1506     }
1507     else if (buffer == NULL) {
1508             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1509             status = PROCESSOR_E_INVALIDARG;
1510             GT_setFailureReason (curTrace,
1511                                  GT_4CLASS,
1512                                  "VAYUIPUCORE1PROC_write",
1513                                  status,
1514                                  "Invalid buffer specified");
1515     }
1516     else {
1517 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1518         if (*numBytes != sizeof (UInt32)) {
1519             procPtr8 = (UInt8 *) procAddr ;
1520             procAddr = (UInt32) Memory_copy (procPtr8,
1521                                              buffer,
1522                                              *numBytes);
1523             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1524 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1525             if (procAddr == (UInt32) NULL) {
1526                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1527                 status = PROCESSOR_E_FAIL;
1528                 GT_setFailureReason (curTrace,
1529                                      GT_4CLASS,
1530                                      "VAYUIPUCORE1PROC_write",
1531                                      status,
1532                                      "Failed in Memory_copy");
1533                 *numBytes = 0;
1534             }
1535 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1536         }
1537         else  {
1538              /* For 4 bytes, directly write as a UInt32 */
1539             temp8_1 = ((UInt8 *) buffer) [0];
1540             temp8_2 = ((UInt8 *) buffer) [1];
1541             temp8_3 = ((UInt8 *) buffer) [2];
1542             temp8_4 = ((UInt8 *) buffer) [3];
1543             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1544                              |   ((UInt32) temp8_3 << 16)
1545                              |   ((UInt32) temp8_2 << 8)
1546                              |   ((UInt32) temp8_1));
1547             *((UInt32*) procAddr) = temp;
1548         }
1549 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1550     }
1551 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1553     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_write", status);
1555     /*! @retval PROCESSOR_SUCCESS Operation successful */
1556     return status;
1560 /*!
1561  *  @brief      Function to perform device-dependent operations.
1562  *
1563  *              Performs device-dependent control operations as exposed by this
1564  *              implementation of the Processor module.
1565  *
1566  *  @param      handle     Handle to the Processor object
1567  *  @param      cmd        Device specific processor command
1568  *  @param      arg        Arguments specific to the type of command.
1569  *
1570  *  @sa
1571  */
1572 Int
1573 VAYUIPUCORE1PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1575     Int                   status       = PROCESSOR_SUCCESS ;
1577     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_control", handle, cmd, arg);
1579     GT_assert (curTrace, (handle   != NULL));
1580     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1582 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1583     if (handle == NULL) {
1584         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1585         status = PROCESSOR_E_HANDLE;
1586         GT_setFailureReason (curTrace,
1587                              GT_4CLASS,
1588                              "VAYUIPUCORE1PROC_control",
1589                              status,
1590                              "Invalid handle specified");
1591     }
1592     else {
1593 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1594         /* No control operations currently implemented. */
1595         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1596                                              for this device. */
1597         status = PROCESSOR_E_NOTSUPPORTED;
1598 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1599     }
1600 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1601     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_control",status);
1603     /*! @retval PROCESSOR_SUCCESS Operation successful */
1604     return status;
1608 /*!
1609  *  @brief      Translate slave virtual address to master physical address.
1610  *
1611  *  @param      handle     Handle to the Processor object
1612  *  @param      dstAddr    Returned: master physical address.
1613  *  @param      srcAddr    Slave virtual address.
1614  *
1615  *  @sa
1616  */
1617 Int
1618 VAYUIPUCORE1PROC_translate(
1619         Processor_Handle    handle,
1620         UInt32 *            dstAddr,
1621         UInt32              srcAddr)
1623     Int                         status = PROCESSOR_SUCCESS;
1624     Processor_Object *          procHandle= (Processor_Object *)handle;
1625     VAYUIPUCORE1PROC_Object *   object = NULL;
1626     UInt32                      i;
1627     UInt32                      startAddr;
1628     UInt32                      endAddr;
1629     UInt32                      offset;
1630     ProcMgr_AddrInfo *          ai;
1632     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1633               handle, dstAddr, srcAddr);
1635     GT_assert (curTrace, (handle  != NULL));
1636     GT_assert (curTrace, (dstAddr != NULL));
1638 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1639     if (handle == NULL) {
1640         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1641         status = PROCESSOR_E_HANDLE;
1642         GT_setFailureReason (curTrace,
1643                              GT_4CLASS,
1644                              "VAYUIPUCORE1PROC_translate",
1645                              status,
1646                              "Invalid handle specified");
1647     }
1648     else if (dstAddr == NULL) {
1649         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1650         status = PROCESSOR_E_INVALIDARG;
1651         GT_setFailureReason (curTrace,
1652                              GT_4CLASS,
1653                              "VAYUIPUCORE1PROC_translate",
1654                              status,
1655                              "dstAddr provided as NULL");
1656     }
1657     else {
1658 #endif
1659         object = (VAYUIPUCORE1PROC_Object *)procHandle->object;
1660         GT_assert(curTrace, (object != NULL));
1661         *dstAddr = -1u;
1663         /* search all entries AddrTable */
1664         for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1665             i++) {
1666             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1667             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1668             endAddr = startAddr + ai->size;
1670             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1671                 offset = srcAddr - startAddr;
1672                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1673                 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE1PROC_translate: "
1674                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1675                     i, srcAddr, *dstAddr);
1676                 break;
1677             }
1678         }
1680         if (*dstAddr == -1u) {
1681             /* srcAddr not found in slave address space */
1682             status = PROCESSOR_E_INVALIDARG;
1683             GT_setFailureReason(curTrace, GT_4CLASS,
1684                 "VAYUIPUCORE1PROC_translate", status,
1685                 "srcAddr not found in slave address space");
1686         }
1687 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1688     }
1689 #endif
1690     GT_1trace(curTrace, GT_LEAVE,
1691         "VAYUIPUCORE1PROC_translate: status=0x%x", status);
1693     /*! @retval PROCESSOR_SUCCESS Operation successful */
1694     return status;
1698 /*!
1699  *  @brief      Map the given address translation into the slave mmu
1700  *
1701  *  @param      handle      Handle to the Processor object
1702  *  @param      dstAddr     Base virtual address
1703  *  @param      nSegs       Number of given segments
1704  *  @param      sglist      Segment list
1705  */
1706 Int
1707 VAYUIPUCORE1PROC_map(
1708         Processor_Handle    handle,
1709         UInt32 *            dstAddr,
1710         UInt32              nSegs,
1711         Memory_SGList *     sglist)
1713     Int                         status = PROCESSOR_SUCCESS ;
1714     Processor_Object *          procHandle = (Processor_Object *)handle;
1715     VAYUIPUCORE1PROC_Object *   object = NULL;
1716     Bool                        found = FALSE;
1717     UInt32                      startAddr;
1718     UInt32                      endAddr;
1719     UInt32                      i;
1720     UInt32                      j;
1721     ProcMgr_AddrInfo *          ai = NULL;
1723     GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE1PROC_map:",
1724         handle, *dstAddr, nSegs, sglist);
1726     GT_assert (curTrace, (handle != NULL));
1727     GT_assert (curTrace, (sglist != NULL));
1728     GT_assert (curTrace, (nSegs > 0));
1730 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1731     if (handle == NULL) {
1732         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1733         status = PROCESSOR_E_HANDLE;
1734         GT_setFailureReason (curTrace,
1735                              GT_4CLASS,
1736                              "VAYUIPUCORE1PROC_map",
1737                              status,
1738                              "Invalid handle specified");
1739     }
1740     else if (sglist == NULL) {
1741         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1742         status = PROCESSOR_E_INVALIDARG;
1743         GT_setFailureReason (curTrace,
1744                              GT_4CLASS,
1745                              "VAYUIPUCORE1PROC_map",
1746                              status,
1747                              "sglist provided as NULL");
1748     }
1749     else if (nSegs == 0) {
1750         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1751         status = PROCESSOR_E_INVALIDARG;
1752         GT_setFailureReason (curTrace,
1753                              GT_4CLASS,
1754                              "VAYUIPUCORE1PROC_map",
1755                              status,
1756                              "Number of segments provided is 0");
1757     }
1758     else {
1759 #endif
1760         object = (VAYUIPUCORE1PROC_Object *)procHandle->object;
1761         GT_assert (curTrace, (object != NULL));
1763         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1764             /* Update the translation table with entries for which mapping
1765              * is required. Add the entry only if the range does not exist
1766              * in the translation table.
1767              */
1768             for (j = 0;
1769                 j < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; j++) {
1770                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1772                 if (ai->isMapped == TRUE) {
1773                     startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1774                     endAddr = startAddr + ai->size;
1776                     if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1777                         && ((*dstAddr + sglist[i].size) <= endAddr)) {
1778                         found = TRUE;
1779                         ai->refCount++;
1780                         break;
1781                     }
1782                 }
1783             }
1785             /* If not found, add new entry to table. If mmu is disabled,
1786              * the assumption is that the ammu will be used.
1787              */
1788             if (!found) {
1789                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1790                     AddrTable_SIZE) {
1791                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1792                         [AddrTable_count[PROCID_TO_IPU
1793                         (procHandle->procId)]];
1794                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1795                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1796                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1797                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1798                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1799                     ai->size = sglist[i].size;
1800                     ai->isCached = sglist[i].isCached;
1801                     ai->refCount++;
1802                     ai->isMapped = TRUE;
1804                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1805                 }
1806                 else {
1807                     status = PROCESSOR_E_FAIL;
1808                     GT_setFailureReason(curTrace, GT_4CLASS,
1809                         "VAYUIPUCORE1PROC_map", status,
1810                         "AddrTable_SIZE reached!");
1811                 }
1812             }
1813         }
1814 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1815     }
1816 #endif
1817     GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_map", status);
1819     /*! @retval PROCESSOR_SUCCESS Operation successful */
1820     return status;
1824 /*!
1825  *  @brief      Function to unmap slave address from host address space
1826  *
1827  *  @param      handle      Handle to the Processor object
1828  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1829  *                          address.
1830  *  @param      size        Size of the region to be mapped.
1831  *
1832  *  @sa
1833  */
1834 Int
1835 VAYUIPUCORE1PROC_unmap(
1836         Processor_Handle    handle,
1837         UInt32              addr,
1838         UInt32              size)
1840     Int                         status = PROCESSOR_SUCCESS;
1841     Processor_Object *          procHandle = (Processor_Object *)handle;
1842     VAYUIPUCORE1PROC_Object *   object = NULL;
1843     ProcMgr_AddrInfo *          ai;
1844     Int                         i;
1845     UInt32                      startAddr;
1846     UInt32                      endAddr;
1847     VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1849     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_unmap",
1850                handle, addr, size);
1852     GT_assert (curTrace, (handle != NULL));
1853     GT_assert (curTrace, (size   != 0));
1855 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1856     if (handle == NULL) {
1857         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1858         status = PROCESSOR_E_HANDLE;
1859         GT_setFailureReason (curTrace,
1860                              GT_4CLASS,
1861                              "VAYUIPUCORE1PROC_unmap",
1862                              status,
1863                              "Invalid handle specified");
1864     }
1865     else if (size == 0) {
1866         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1867         status = PROCESSOR_E_INVALIDARG;
1868         GT_setFailureReason (curTrace,
1869                              GT_4CLASS,
1870                              "VAYUIPUCORE1PROC_unmap",
1871                              status,
1872                              "Size provided is zero");
1873     }
1874     else {
1875 #endif
1876         object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1877         GT_assert (curTrace, (object != NULL));
1879         /* Delete entries from translation
1880          * table only in last unmap called on that entry
1881          */
1882         for (i = 0;
1883             i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1884             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1886             if (!ai->isMapped) {
1887                 continue;
1888             }
1890             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1891             endAddr = startAddr + ai->size;
1893             if ((startAddr <= addr) && (addr < endAddr)) {
1894                 ai->refCount--;
1896                 if (ai->refCount == 0) {
1897                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1898                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1899                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1900                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1901                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1902                     ai->size = 0u;
1903                     ai->isCached = FALSE;
1904                     ai->mapMask = 0u;
1905                     ai->isMapped = FALSE;
1907                     /* Remove the entry from the IPUCORE1 MMU also */
1908                     deleteEntryArgs.size          = size;
1909                     deleteEntryArgs.slaveVirtAddr = addr;
1910                     /* TBD: elementSize, endianism, mixedSized are
1911                      * hard coded now, must be configurable later
1912                      */
1913                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
1914                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
1915                     deleteEntryArgs.mixedSize     = MMU_TLBES;
1917                     status = VAYUIPU_halMmuCtrl(object->halObject,
1918                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
1919 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1920                     if (status < 0) {
1921                         GT_setFailureReason(curTrace, GT_4CLASS,
1922                             "VAYUIPUCORE1PROC_unmap", status,
1923                             "IPUCORE1 MMU configuration failed");
1924                     }
1925 #endif
1926                 }
1927             }
1928         }
1929 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1930     }
1931 #endif
1932     GT_1trace(curTrace, GT_LEAVE,
1933     "VAYUIPUCORE1PROC_unmap", status);
1935     /*! @retval PROCESSOR_SUCCESS Operation successful */
1936     return status;
1940 #if defined (__cplusplus)
1942 #endif /* defined (__cplusplus) */