Add INTMEM resource type support in QNX
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayuipu / vayucore0 / VAYUIpuCore0Proc.c
1 /*
2  *  @file   VAYUIpuCore0Proc.c
3  *
4  * @brief       Processor implementation for VAYUIPUCORE0.
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 VAYUIPUCORE0.
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 <VAYUIpuCore0Proc.h>
70 #include <_VAYUIpuCore0Proc.h>
71 #include <VAYUIpuHal.h>
72 #include <VAYUIpuCore0HalReset.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 == VAYUIPUCORE0PROC_state.ipu1ProcId ?\
100     0 : 1)
103 /*!
104  *  @brief  VAYUIPUCORE0PROC Module state object
105  */
106 typedef struct VAYUIPUCORE0PROC_ModuleObject_tag {
107     UInt32                     configSize;
108     /*!< Size of configuration structure */
109     VAYUIPUCORE0PROC_Config    cfg;
110     /*!< VAYUIPUCORE0PROC configuration structure */
111     VAYUIPUCORE0PROC_Config    defCfg;
112     /*!< Default module configuration */
113     VAYUIPUCORE0PROC_Params    defInstParams;
114     /*!< Default parameters for the VAYUIPUCORE0PROC instances */
115     Bool                       isSetup;
116     /*!< Indicates whether the VAYUIPUCORE0PROC module is setup. */
117     VAYUIPUCORE0PROC_Handle    procHandles [MultiProc_MAXPROCESSORS];
118     /*!< Processor handle array. */
119     IGateProvider_Handle       gateHandle;
120     /*!< Handle of gate to be used for local thread safety */
121     UInt16                     ipu1ProcId;
122     /*!< MultiProc id of IPU1 (to avoid multiple lookups) */
123 } VAYUIPUCORE0PROC_ModuleObject;
125 /* Memory region counters */
126 static UInt32 AddrTable_count[NUM_IPUS] = {
127     0,
128     0
129 };
131 /*
132  * Address translation tables
133  */
134 static ProcMgr_AddrInfo AddrTable_IPU1[AddrTable_SIZE];
135 static ProcMgr_AddrInfo AddrTable_IPU2[AddrTable_SIZE];
137 static ProcMgr_AddrInfo * AddrTable[NUM_IPUS] =
139     AddrTable_IPU1,
140     AddrTable_IPU2
141 };
143 /* =============================================================================
144  *  Globals
145  * =============================================================================
146  */
148 /*!
149  *  @var    VAYUIPUCORE0PROC_state
150  *
151  *  @brief  VAYUIPUCORE0PROC state object variable
152  */
153 #if !defined(SYSLINK_BUILD_DEBUG)
154 static
155 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
156 VAYUIPUCORE0PROC_ModuleObject VAYUIPUCORE0PROC_state =
158     .isSetup = FALSE,
159     .configSize = sizeof(VAYUIPUCORE0PROC_Config),
160     .gateHandle = NULL,
161     .defInstParams.numMemEntries = 0,
162 };
164 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
165 extern String ProcMgr_sysLinkCfgParams;
167 /* =============================================================================
168  * APIs directly called by applications
169  * =============================================================================
170  */
171 /*!
172  *  @brief      Function to get the default configuration for the VAYUIPUCORE0PROC
173  *              module.
174  *
175  *              This function can be called by the application to get their
176  *              configuration parameter to VAYUIPUCORE0PROC_setup filled in by the
177  *              VAYUIPUCORE0PROC module with the default parameters. If the user
178  *              does not wish to make any change in the default parameters, this
179  *              API is not required to be called.
180  *
181  *  @param      cfg        Pointer to the VAYUIPUCORE0PROC module configuration
182  *                         structure in which the default config is to be
183  *                         returned.
184  *
185  *  @sa         VAYUIPUCORE0PROC_setup
186  */
187 Void
188 VAYUIPUCORE0PROC_getConfig (VAYUIPUCORE0PROC_Config * cfg)
190     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_getConfig", cfg);
192     GT_assert (curTrace, (cfg != NULL));
194 #if !defined(SYSLINK_BUILD_OPTIMIZE)
195     if (cfg == NULL) {
196         GT_setFailureReason (curTrace,
197                              GT_4CLASS,
198                              "VAYUIPUCORE0PROC_getConfig",
199                              PROCESSOR_E_INVALIDARG,
200                              "Argument of type (VAYUIPUCORE0PROC_Config *) passed "
201                              "is null!");
202     }
203     else {
204 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
205         Memory_copy (cfg,
206                      &(VAYUIPUCORE0PROC_state.defCfg),
207                      sizeof (VAYUIPUCORE0PROC_Config));
208 #if !defined(SYSLINK_BUILD_OPTIMIZE)
209     }
210 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
212     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_getConfig");
216 /*!
217  *  @brief      Function to setup the VAYUIPUCORE0PROC module.
218  *
219  *              This function sets up the VAYUIPUCORE0PROC module. This function
220  *              must be called before any other instance-level APIs can be
221  *              invoked.
222  *              Module-level configuration needs to be provided to this
223  *              function. If the user wishes to change some specific config
224  *              parameters, then VAYUIPUCORE0PROC_getConfig can be called to get the
225  *              configuration filled with the default values. After this, only
226  *              the required configuration values can be changed. If the user
227  *              does not wish to make any change in the default parameters, the
228  *              application can simply call VAYUIPUCORE0PROC_setup with NULL
229  *              parameters. The default parameters would get automatically used.
230  *
231  *  @param      cfg   Optional VAYUIPUCORE0PROC module configuration. If provided as
232  *                    NULL, default configuration is used.
233  *
234  *  @sa         VAYUIPUCORE0PROC_destroy
235  *              GateMutex_create
236  */
237 Int
238 VAYUIPUCORE0PROC_setup (VAYUIPUCORE0PROC_Config * cfg)
240     Int                     status = PROCESSOR_SUCCESS;
241     VAYUIPUCORE0PROC_Config tmpCfg;
242     Error_Block             eb;
244     Error_init(&eb);
246     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_setup", cfg);
248     if (cfg == NULL) {
249         VAYUIPUCORE0PROC_getConfig (&tmpCfg);
250         cfg = &tmpCfg;
251     }
253     /* Create a default gate handle for local module protection. */
254     VAYUIPUCORE0PROC_state.gateHandle = (IGateProvider_Handle)
255                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
256 #if !defined(SYSLINK_BUILD_OPTIMIZE)
257     if (VAYUIPUCORE0PROC_state.gateHandle == NULL) {
258         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
259         status = PROCESSOR_E_FAIL;
260         GT_setFailureReason (curTrace,
261                              GT_4CLASS,
262                              "VAYUIPUCORE0PROC_setup",
263                              status,
264                              "Failed to create GateMutex!");
265     }
266     else {
267 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
268         /* Copy the user provided values into the state object. */
269         Memory_copy (&VAYUIPUCORE0PROC_state.cfg,
270                      cfg,
271                      sizeof (VAYUIPUCORE0PROC_Config));
273         /* Initialize the name to handles mapping array. */
274         Memory_set (&VAYUIPUCORE0PROC_state.procHandles,
275                     0,
276                     (sizeof (VAYUIPUCORE0PROC_Handle) * MultiProc_MAXPROCESSORS));
278         VAYUIPUCORE0PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
279         VAYUIPUCORE0PROC_state.isSetup = TRUE;
280 #if !defined(SYSLINK_BUILD_OPTIMIZE)
281     }
282 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
284     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_setup", status);
286     /*! @retval PROCESSOR_SUCCESS Operation successful */
287     return (status);
291 /*!
292  *  @brief      Function to destroy the VAYUIPUCORE0PROC module.
293  *
294  *              Once this function is called, other VAYUIPUCORE0PROC module APIs,
295  *              except for the VAYUIPUCORE0PROC_getConfig API cannot be called
296  *              anymore.
297  *
298  *  @sa         VAYUIPUCORE0PROC_setup
299  *              GateMutex_delete
300  */
301 Int
302 VAYUIPUCORE0PROC_destroy (Void)
304     Int    status = PROCESSOR_SUCCESS;
305     UInt16 i;
307     GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_destroy");
309     /* Check if any VAYUIPUCORE0PROC instances have not been deleted so far. If not,
310      * delete them.
311      */
312     for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
313         GT_assert (curTrace, (VAYUIPUCORE0PROC_state.procHandles [i] == NULL));
314         if (VAYUIPUCORE0PROC_state.procHandles [i] != NULL) {
315             VAYUIPUCORE0PROC_delete (&(VAYUIPUCORE0PROC_state.procHandles [i]));
316         }
317     }
319     if (VAYUIPUCORE0PROC_state.gateHandle != NULL) {
320         GateMutex_delete ((GateMutex_Handle *)
321                                 &(VAYUIPUCORE0PROC_state.gateHandle));
322     }
324     VAYUIPUCORE0PROC_state.isSetup = FALSE;
326     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_destroy", status);
328     /*! @retval PROCESSOR_SUCCESS Operation successful */
329     return (status);
333 /*!
334  *  @brief      Function to initialize the parameters for this Processor
335  *              instance.
336  *
337  *  @param      params  Configuration parameters to be returned
338  *
339  *  @sa         VAYUIPUCORE0PROC_create
340  */
341 Void
342 VAYUIPUCORE0PROC_Params_init(
343         VAYUIPUCORE0PROC_Handle     handle,
344         VAYUIPUCORE0PROC_Params *   params)
346     VAYUIPUCORE0PROC_Object *procObject = (VAYUIPUCORE0PROC_Object *)handle;
348     GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_Params_init",
349               handle, params);
351     GT_assert(curTrace, (params != NULL));
353 #if !defined(SYSLINK_BUILD_OPTIMIZE)
354     if (params == NULL) {
355         GT_setFailureReason(curTrace, GT_4CLASS,
356                             "VAYUIPUCORE0PROC_Params_init",
357                             PROCESSOR_E_INVALIDARG,
358                             "Argument of type (VAYUIPUCORE0PROC_Params *) "
359                             "passed is null!");
360     }
361     else {
362 #endif
363         if (handle == NULL) {
365             Memory_copy(params, &(VAYUIPUCORE0PROC_state.defInstParams),
366                 sizeof (VAYUIPUCORE0PROC_Params));
367         }
368         else {
369             /* return updated VAYUIPUCORE0PROC instance specific parameters */
370             Memory_copy(params, &(procObject->params),
371                         sizeof(VAYUIPUCORE0PROC_Params));
372         }
373 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
374     }
375 #endif
377     GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_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         VAYUIPUCORE0PROC_delete
387  */
388 VAYUIPUCORE0PROC_Handle
389 VAYUIPUCORE0PROC_create (      UInt16                procId,
390                      const VAYUIPUCORE0PROC_Params * params)
392     Int                   status     = PROCESSOR_SUCCESS;
393     Processor_Object *    handle     = NULL;
394     VAYUIPUCORE0PROC_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, "VAYUIPUCORE0PROC_create", procId, params);
402     GT_assert (curTrace, IS_VALID_PROCID (procId));
403     GT_assert (curTrace, (params != NULL));
405 #if !defined(SYSLINK_BUILD_OPTIMIZE)
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                              "VAYUIPUCORE0PROC_create",
411                              PROCESSOR_E_INVALIDARG,
412                              "Invalid procId specified");
413     }
414     else if (params == NULL) {
415         GT_setFailureReason (curTrace,
416                              GT_4CLASS,
417                              "VAYUIPUCORE0PROC_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 (VAYUIPUCORE0PROC_state.gateHandle);
425 #if !defined(SYSLINK_BUILD_OPTIMIZE)
426         /* Check if the Processor already exists for specified procId. */
427         if (VAYUIPUCORE0PROC_state.procHandles [procId] != NULL) {
428             status = PROCESSOR_E_ALREADYEXIST;
429             GT_setFailureReason (curTrace,
430                               GT_4CLASS,
431                               "VAYUIPUCORE0PROC_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                                      "VAYUIPUCORE0PROC_create",
446                                      PROCESSOR_E_MEMORY,
447                                      "Memory allocation failed for handle!");
448             }
449             else {
450                 /* Populate the handle fields */
451                 handle->procFxnTable.attach        = &VAYUIPUCORE0PROC_attach;
452                 handle->procFxnTable.detach        = &VAYUIPUCORE0PROC_detach;
453                 handle->procFxnTable.start         = &VAYUIPUCORE0PROC_start;
454                 handle->procFxnTable.stop          = &VAYUIPUCORE0PROC_stop;
455                 handle->procFxnTable.read          = &VAYUIPUCORE0PROC_read;
456                 handle->procFxnTable.write         = &VAYUIPUCORE0PROC_write;
457                 handle->procFxnTable.control       = &VAYUIPUCORE0PROC_control;
458                 handle->procFxnTable.map           = &VAYUIPUCORE0PROC_map;
459                 handle->procFxnTable.unmap         = &VAYUIPUCORE0PROC_unmap;
460                 handle->procFxnTable.translateAddr = &VAYUIPUCORE0PROC_translate;
461                 handle->state = ProcMgr_State_Unknown;
463                 /* Allocate memory for the VAYUIPUCORE0PROC handle */
464                 handle->object = Memory_calloc (NULL,
465                                                 sizeof (VAYUIPUCORE0PROC_Object),
466                                                 0,
467                                                 NULL);
468                 if (handle->object == NULL) {
469                     status = PROCESSOR_E_MEMORY;
470                     GT_setFailureReason (curTrace,
471                                 GT_4CLASS,
472                                 "VAYUIPUCORE0PROC_create",
473                                 status,
474                                 "Memory allocation failed for handle->object!");
475                 }
476                 else {
477                     handle->procId = procId;
478                     object = (VAYUIPUCORE0PROC_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 (VAYUIPUCORE0PROC_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 == VAYUIPUCORE0PROC_state.ipu1ProcId ?
510                         sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
512                     /* Set the handle in the state object. */
513                     VAYUIPUCORE0PROC_state.procHandles [procId] =
514                                                  (VAYUIPUCORE0PROC_Handle) object;
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                                              "VAYUIPUCORE0PROC_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                                                  "VAYUIPUCORE0PROC_create",
542                                                  status,
543                                                  "OsalMutex_create failed");
544                         }
545                     }
546 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
547                 }
548             }
549 #if !defined(SYSLINK_BUILD_OPTIMIZE)
550         }
551 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
553         /* Leave critical section protection. */
554         IGateProvider_leave (VAYUIPUCORE0PROC_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 (VAYUIPUCORE0PROC_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, "VAYUIPUCORE0PROC_create", handle);
577     /*! @retval Valid-Handle Operation successful */
578     return (VAYUIPUCORE0PROC_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         VAYUIPUCORE0PROC_create
591  */
592 Int
593 VAYUIPUCORE0PROC_delete (VAYUIPUCORE0PROC_Handle * handlePtr)
595     Int                   status = PROCESSOR_SUCCESS;
596     VAYUIPUCORE0PROC_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, "VAYUIPUCORE0PROC_delete", handlePtr);
604     GT_assert (curTrace, (handlePtr != NULL));
605     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
607 #if !defined(SYSLINK_BUILD_OPTIMIZE)
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                              "VAYUIPUCORE0PROC_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                              "VAYUIPUCORE0PROC_delete",
624                              status,
625                              "Invalid NULL *handlePtr specified");
626     }
627     else {
628 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
629         handle = (Processor_Object *) (*handlePtr);
630         /* Enter critical section protection. */
631         key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
633         /* Reset handle in PwrMgr handle array. */
634         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
635         VAYUIPUCORE0PROC_state.procHandles [handle->procId] = NULL;
637         /* Free memory used for the VAYUIPUCORE0PROC object. */
638         if (handle->object != NULL) {
639             object = (VAYUIPUCORE0PROC_Object *) handle->object;
640             Memory_free (NULL,
641                          object,
642                          sizeof (VAYUIPUCORE0PROC_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 (VAYUIPUCORE0PROC_state.gateHandle, key);
688 #if !defined(SYSLINK_BUILD_OPTIMIZE)
689     }
690 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
692     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_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         VAYUIPUCORE0PROC_close
708  */
709 Int
710 VAYUIPUCORE0PROC_open (VAYUIPUCORE0PROC_Handle * handlePtr, UInt16 procId)
712     Int status = PROCESSOR_SUCCESS;
714     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_open", handlePtr, procId);
716     GT_assert (curTrace, (handlePtr != NULL));
717     GT_assert (curTrace, IS_VALID_PROCID (procId));
719 #if !defined(SYSLINK_BUILD_OPTIMIZE)
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                              "VAYUIPUCORE0PROC_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                              "VAYUIPUCORE0PROC_open",
735                              status,
736                              "Invalid procId specified");
737     }
738     else {
739 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
740         /* Initialize return parameter handle. */
741         *handlePtr = NULL;
743         /* Check if the PwrMgr exists and return the handle if found. */
744         if (VAYUIPUCORE0PROC_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                              "VAYUIPUCORE0PROC_open",
750                              status,
751                              "Specified VAYUIPUCORE0PROC instance does not exist!");
752         }
753         else {
754             *handlePtr = VAYUIPUCORE0PROC_state.procHandles [procId];
755         }
756 #if !defined(SYSLINK_BUILD_OPTIMIZE)
757     }
758 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
760     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_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         VAYUIPUCORE0PROC_open
773  */
774 Int
775 VAYUIPUCORE0PROC_close (VAYUIPUCORE0PROC_Handle * handlePtr)
777     Int status = PROCESSOR_SUCCESS;
779     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_close", handlePtr);
781     GT_assert (curTrace, (handlePtr != NULL));
782     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
784 #if !defined(SYSLINK_BUILD_OPTIMIZE)
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                              "VAYUIPUCORE0PROC_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                              "VAYUIPUCORE0PROC_close",
801                              status,
802                              "Invalid NULL *handlePtr specified");
803     }
804     else {
805 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
806         /* Nothing to be done for close. */
807 #if !defined(SYSLINK_BUILD_OPTIMIZE)
808     }
809 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
811     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_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         VAYUIPUCORE0PROC_detach
829  */
830 Int
831 VAYUIPUCORE0PROC_attach(
832         Processor_Handle            handle,
833         Processor_AttachParams *    params)
836     Int                         status = PROCESSOR_SUCCESS;
837     Processor_Object *          procHandle = (Processor_Object *)handle;
838     VAYUIPUCORE0PROC_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               "VAYUIPUCORE0PROC_attach", handle, params);
849     GT_assert (curTrace, (handle != NULL));
850     GT_assert (curTrace, (params != NULL));
852 #if !defined(SYSLINK_BUILD_OPTIMIZE)
853     if (handle == NULL) {
854         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
855         status = PROCESSOR_E_HANDLE;
856         GT_setFailureReason (curTrace,
857                              GT_4CLASS,
858                              "VAYUIPUCORE0PROC_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                                  "VAYUIPUCORE0PROC_attach",
868                                  status,
869                                  "Invalid params specified");
870     }
871     else {
872 #endif
873         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
874         GT_assert (curTrace, (object != NULL));
876         /* Added for Netra Benelli core1 is cortex M4 */
877         params->procArch = Processor_ProcArch_M4;
879         object->pmHandle = params->pmHandle;
880         GT_0trace(curTrace, GT_1CLASS,
881             "VAYUIPUCORE0PROC_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                                  "VAYUIPUCORE0PROC_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                                      "VAYUIPUCORE0PROC_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                         "VAYUIPUCORE0PROC_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                                         "VAYUIPUCORE0PROC_attach", status,
966                                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
967                 }
968             }
969             else {
970                 status = PROCESSOR_E_INVALIDARG;
971                 GT_setFailureReason(curTrace, GT_4CLASS,
972                     "VAYUIPUCORE0PROC_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)
987             if (status < 0) {
988                 GT_setFailureReason(curTrace, GT_4CLASS,
989                     "VAYUIPUCORE0PROC_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                             "VAYUIPUCORE0PROC_attach", status,
1001                             "Failed to reset the slave processor");
1002                     }
1003                     else {
1004 #endif
1005                         GT_0trace(curTrace, GT_1CLASS,
1006                             "VAYUIPUCORE0PROC_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                                 "VAYUIPUCORE0PROC_attach", status,
1015                                 "Failed to enable the slave MMU");
1016                         }
1017                         else {
1018 #endif
1019                             GT_0trace(curTrace, GT_2CLASS,
1020                                 "VAYUIPUCORE0PROC_attach: Slave MMU "
1021                                 "is configured!");
1022                             /*
1023                              * Pull IPU MMU out of reset to make internal
1024                              * memory "loadable"
1025                              */
1026                             status = VAYUIPUCORE0_halResetCtrl(
1027                                 object->halObject,
1028                                 Processor_ResetCtrlCmd_MMU_Release);
1029                             if (status < 0) {
1030                                 /*! @retval status */
1031                                 GT_setFailureReason(curTrace,
1032                                     GT_4CLASS,
1033                                     "VAYUIPUCORE0_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)
1043             }
1044 #endif
1045         }
1046 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1047     }
1048 #endif
1050     GT_1trace(curTrace, GT_LEAVE,
1051         "VAYUIPUCORE0PROC_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         VAYUIPUCORE0PROC_attach
1064  */
1065 Int
1066 VAYUIPUCORE0PROC_detach (Processor_Handle handle)
1068     Int                       status     = PROCESSOR_SUCCESS;
1069     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1070     Processor_Object *        procHandle = (Processor_Object *) handle;
1071     VAYUIPUCORE0PROC_Object * object     = NULL;
1072     Int                       i          = 0;
1073     ProcMgr_AddrInfo *        ai;
1075     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_detach", handle);
1076     GT_assert (curTrace, (handle != NULL));
1078 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1079     if (handle == NULL) {
1080         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1081         status = PROCESSOR_E_HANDLE;
1082         GT_setFailureReason (curTrace,
1083                              GT_4CLASS,
1084                              "VAYUIPUCORE0PROC_detach",
1085                              PROCESSOR_E_HANDLE,
1086                              "Invalid handle specified");
1087     }
1088     else {
1089 #endif
1090         object = (VAYUIPUCORE0PROC_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                 "VAYUIPUCORE0PROC_detach: Disabling Slave MMU ...");
1099             status = VAYUIPUCORE0_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                                      "VAYUIPUCORE0_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)
1115             if (status < 0) {
1116                 GT_setFailureReason(curTrace, GT_4CLASS,
1117                     "VAYUIPUCORE0PROC_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 = VAYUIPUCORE0_halResetCtrl(object->halObject,
1142                 Processor_ResetCtrlCmd_Reset, NULL);
1144             GT_0trace(curTrace, GT_2CLASS,
1145                 "VAYUIPUCORE0PROC_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                                      "VAYUIPUCORE0PROC_detach",
1153                                      status,
1154                                      "Failed to reset the slave processor");
1155             }
1156 #endif
1157         }
1159         GT_0trace (curTrace,
1160                    GT_2CLASS,
1161                    "    VAYUIPUCORE0PROC_detach: Unmapping memory regions\n");
1163         tmpStatus = VAYUIPU_halExit (object->halObject);
1164 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1165         if ((tmpStatus < 0) && (status >= 0)) {
1166             status = tmpStatus;
1167             GT_setFailureReason (curTrace,
1168                                  GT_4CLASS,
1169                                  "VAYUIPUCORE0PROC_detach",
1170                                  status,
1171                                  "Failed to finalize HAL object");
1172         }
1173     }
1174 #endif
1176     GT_1trace(curTrace, GT_LEAVE,
1177         "VAYUIPUCORE0PROC_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         VAYUIPUCORE0PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE0_halResetCtrl
1194  */
1195 Int
1196 VAYUIPUCORE0PROC_start (Processor_Handle        handle,
1197                         UInt32                  entryPt,
1198                         Processor_StartParams * params)
1200     Int                   status        = PROCESSOR_SUCCESS ;
1201     Processor_Object *    procHandle    = (Processor_Object *) handle;
1202     VAYUIPUCORE0PROC_Object * object    = NULL;
1205     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_start",
1206                handle, entryPt, params);
1208     GT_assert (curTrace, (handle != NULL));
1209     GT_assert (curTrace, (params != NULL));
1211 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1212     if (handle == NULL) {
1213         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1214         status = PROCESSOR_E_HANDLE;
1215         GT_setFailureReason (curTrace,
1216                              GT_4CLASS,
1217                              "VAYUIPUCORE0PROC_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                                  "VAYUIPUCORE0PROC_start",
1227                                  status,
1228                                  "Invalid params specified");
1229     }
1230     else {
1231 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1232         object = (VAYUIPUCORE0PROC_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 IPU 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)
1243             if (status < 0) {
1244                 GT_setFailureReason (curTrace,
1245                                      GT_4CLASS,
1246                                      "VAYUIPUCORE0PROC_start",
1247                                      status,
1248                                      "Failed to set slave boot entry point");
1249             }
1250             else {
1251 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1252                 status = rproc_ipu_setup(object->halObject,
1253                                          object->params.memEntries,
1254                                          object->params.numMemEntries);
1255                 if (status < 0) {
1256                     /*! @retval status */
1257                     GT_setFailureReason (curTrace,
1258                                          GT_4CLASS,
1259                                          "VAYUIPUCORE0_halResetCtrl",
1260                                           status,
1261                                          "rproc_ipu_setup failed");
1262                 }
1263                 /* release the slave cpu from reset */
1264                 if (status >= 0) {
1265                     status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1266                                                 Processor_ResetCtrlCmd_Release);
1267 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1268                     if (status < 0) {
1269                         GT_setFailureReason (curTrace,
1270                                           GT_4CLASS,
1271                                           "VAYUIPUCORE0PROC_start",
1272                                           status,
1273                                           "Failed to release slave from reset");
1274                     }
1275 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1276                 }
1277 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1278             }
1279 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1280         }
1282 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1283     }
1284 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1286     if (status >= 0) {
1287         GT_0trace (curTrace,
1288                    GT_1CLASS,
1289                    "    VAYUIPUCORE0PROC_start: Slave successfully started!\n");
1290     }
1291     else {
1292         GT_0trace (curTrace,
1293                    GT_1CLASS,
1294                    "    VAYUIPUCORE0PROC_start: Slave could not be started!\n");
1295     }
1297     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_start", status);
1299     /*! @retval PROCESSOR_SUCCESS Operation successful */
1300     return status;
1304 /*!
1305  *  @brief      Function to stop the slave processor
1306  *
1307  *              Stop the execution of the slave processor. Depending on the boot
1308  *              mode, this may result in placing the slave processor in reset.
1309  *
1310  *  @param      handle    Handle to the Processor instance
1311  *
1312  *  @sa         VAYUIPUCORE0PROC_start, VAYUIPUCORE0_halResetCtrl
1313  */
1314 Int
1315 VAYUIPUCORE0PROC_stop (Processor_Handle handle)
1317     Int                   status       = PROCESSOR_SUCCESS ;
1318     Processor_Object *    procHandle   = (Processor_Object *) handle;
1319     VAYUIPUCORE0PROC_Object * object       = NULL;
1321     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_stop", handle);
1323     GT_assert (curTrace, (handle != NULL));
1325 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1326     if (handle == NULL) {
1327         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1328         status = PROCESSOR_E_HANDLE;
1329         GT_setFailureReason (curTrace,
1330                              GT_4CLASS,
1331                              "VAYUIPUCORE0PROC_stop",
1332                              status,
1333                              "Invalid handle specified");
1334     }
1335     else {
1336 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1337         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1338         GT_assert (curTrace, (object != NULL));
1339         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1340             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1341             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1342             /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1343             /* Place the slave processor in reset. */
1344             status = VAYUIPUCORE0_halResetCtrl (object->halObject,
1345                                               Processor_ResetCtrlCmd_Reset);
1347             GT_0trace (curTrace,
1348                        GT_1CLASS,
1349                        "    VAYUIPUCORE0PROC_stop: Slave is now in reset!\n");
1350 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1351             if (status < 0) {
1352                 GT_setFailureReason (curTrace,
1353                                      GT_4CLASS,
1354                                      "VAYUIPUCORE0PROC_stop",
1355                                      status,
1356                                      "Failed to place slave in reset");
1357             }
1358 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1359             rproc_ipu_destroy(object->halObject);
1360         }
1361 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1362     }
1363 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1364     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_stop", status);
1366     /*! @retval PROCESSOR_SUCCESS Operation successful */
1367     return status;
1371 /*!
1372  *  @brief      Function to read from the slave processor's memory.
1373  *
1374  *              Read from the slave processor's memory and copy into the
1375  *              provided buffer.
1376  *
1377  *  @param      handle     Handle to the Processor instance
1378  *  @param      procAddr   Address in host processor's address space of the
1379  *                         memory region to read from.
1380  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1381  *                         number of bytes to be read. When the function
1382  *                         returns, this parameter contains the number of bytes
1383  *                         actually read.
1384  *  @param      buffer     User-provided buffer in which the slave processor's
1385  *                         memory contents are to be copied.
1386  *
1387  *  @sa         VAYUIPUCORE0PROC_write
1388  */
1389 Int
1390 VAYUIPUCORE0PROC_read (Processor_Handle   handle,
1391                        UInt32             procAddr,
1392                        UInt32 *           numBytes,
1393                        Ptr                buffer)
1395     Int       status   = PROCESSOR_SUCCESS ;
1396     UInt8  *  procPtr8 = NULL;
1398     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_read",
1399                handle, procAddr, numBytes, buffer);
1401     GT_assert (curTrace, (handle   != NULL));
1402     GT_assert (curTrace, (numBytes != NULL));
1403     GT_assert (curTrace, (buffer   != NULL));
1405 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1406     if (handle == NULL) {
1407         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1408         status = PROCESSOR_E_HANDLE;
1409         GT_setFailureReason (curTrace,
1410                              GT_4CLASS,
1411                              "VAYUIPUCORE0PROC_read",
1412                              status,
1413                              "Invalid handle specified");
1414     }
1415     else if (numBytes == 0) {
1416             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1417             status = PROCESSOR_E_INVALIDARG;
1418             GT_setFailureReason (curTrace,
1419                                  GT_4CLASS,
1420                                  "VAYUIPUCORE0PROC_read",
1421                                  status,
1422                                  "Invalid numBytes specified");
1423     }
1424     else if (buffer == NULL) {
1425             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1426             status = PROCESSOR_E_INVALIDARG;
1427             GT_setFailureReason (curTrace,
1428                                  GT_4CLASS,
1429                                  "VAYUIPUCORE0PROC_read",
1430                                  status,
1431                                  "Invalid buffer specified");
1432     }
1433     else {
1434 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1435         procPtr8 = (UInt8 *) procAddr ;
1436         buffer = memcpy (buffer, procPtr8, *numBytes);
1437         GT_assert (curTrace, (buffer != (UInt32) NULL));
1438 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1439         if (buffer == (UInt32) NULL) {
1440             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1441             status = PROCESSOR_E_FAIL;
1442             GT_setFailureReason (curTrace,
1443                                  GT_4CLASS,
1444                                  "VAYUIPUCORE0PROC_read",
1445                                  status,
1446                                  "Failed in memcpy");
1447             *numBytes = 0;
1448         }
1449     }
1450 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1452     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_read",status);
1454     /*! @retval PROCESSOR_SUCCESS Operation successful */
1455     return status;
1459 /*!
1460  *  @brief      Function to write into the slave processor's memory.
1461  *
1462  *              Read from the provided buffer and copy into the slave
1463  *              processor's memory.
1464  *
1465  *  @param      handle     Handle to the Processor object
1466  *  @param      procAddr   Address in host processor's address space of the
1467  *                         memory region to write into.
1468  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1469  *                         number of bytes to be written. When the function
1470  *                         returns, this parameter contains the number of bytes
1471  *                         actually written.
1472  *  @param      buffer     User-provided buffer from which the data is to be
1473  *                         written into the slave processor's memory.
1474  *
1475  *  @sa         VAYUIPUCORE0PROC_read, VAYUIPUCORE0PROC_translateAddr
1476  */
1477 Int
1478 VAYUIPUCORE0PROC_write (Processor_Handle handle,
1479                         UInt32           procAddr,
1480                         UInt32 *         numBytes,
1481                         Ptr              buffer)
1483     Int                   status       = PROCESSOR_SUCCESS ;
1484     UInt8  *              procPtr8     = NULL;
1485     UInt8                 temp8_1;
1486     UInt8                 temp8_2;
1487     UInt8                 temp8_3;
1488     UInt8                 temp8_4;
1489     UInt32                temp;
1491     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_write",
1492                handle, procAddr, numBytes, buffer);
1494     GT_assert (curTrace, (handle   != NULL));
1495     GT_assert (curTrace, (numBytes != NULL));
1496     GT_assert (curTrace, (buffer   != NULL));
1498 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1499     if (handle == NULL) {
1500         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1501         status = PROCESSOR_E_HANDLE;
1502         GT_setFailureReason (curTrace,
1503                              GT_4CLASS,
1504                              "VAYUIPUCORE0PROC_write",
1505                              status,
1506                              "Invalid handle specified");
1507     }
1508     else if (numBytes == 0) {
1509             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1510             status = PROCESSOR_E_INVALIDARG;
1511             GT_setFailureReason (curTrace,
1512                                  GT_4CLASS,
1513                                  "VAYUIPUCORE0PROC_write",
1514                                  status,
1515                                  "Invalid numBytes specified");
1516     }
1517     else if (buffer == NULL) {
1518             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1519             status = PROCESSOR_E_INVALIDARG;
1520             GT_setFailureReason (curTrace,
1521                                  GT_4CLASS,
1522                                  "VAYUIPUCORE0PROC_write",
1523                                  status,
1524                                  "Invalid buffer specified");
1525     }
1526     else {
1527 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1528         if (*numBytes != sizeof (UInt32)) {
1529             procPtr8 = (UInt8 *) procAddr ;
1530             procAddr = (UInt32) Memory_copy (procPtr8,
1531                                              buffer,
1532                                              *numBytes);
1533             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1534 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1535             if (procAddr == (UInt32) NULL) {
1536                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1537                 status = PROCESSOR_E_FAIL;
1538                 GT_setFailureReason (curTrace,
1539                                      GT_4CLASS,
1540                                      "VAYUIPUCORE0PROC_write",
1541                                      status,
1542                                      "Failed in Memory_copy");
1543                 *numBytes = 0;
1544             }
1545 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1546         }
1547         else  {
1548              /* For 4 bytes, directly write as a UInt32 */
1549             temp8_1 = ((UInt8 *) buffer) [0];
1550             temp8_2 = ((UInt8 *) buffer) [1];
1551             temp8_3 = ((UInt8 *) buffer) [2];
1552             temp8_4 = ((UInt8 *) buffer) [3];
1553             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1554                              |   ((UInt32) temp8_3 << 16)
1555                              |   ((UInt32) temp8_2 << 8)
1556                              |   ((UInt32) temp8_1));
1557             *((UInt32*) procAddr) = temp;
1558         }
1559 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1560     }
1561 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1563     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_write", status);
1565     /*! @retval PROCESSOR_SUCCESS Operation successful */
1566     return status;
1570 /*!
1571  *  @brief      Function to perform device-dependent operations.
1572  *
1573  *              Performs device-dependent control operations as exposed by this
1574  *              implementation of the Processor module.
1575  *
1576  *  @param      handle     Handle to the Processor object
1577  *  @param      cmd        Device specific processor command
1578  *  @param      arg        Arguments specific to the type of command.
1579  *
1580  *  @sa
1581  */
1582 Int
1583 VAYUIPUCORE0PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1585     Int                   status       = PROCESSOR_SUCCESS ;
1587     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_control", handle, cmd, arg);
1589     GT_assert (curTrace, (handle   != NULL));
1590     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1592 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1593     if (handle == NULL) {
1594         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1595         status = PROCESSOR_E_HANDLE;
1596         GT_setFailureReason (curTrace,
1597                              GT_4CLASS,
1598                              "VAYUIPUCORE0PROC_control",
1599                              status,
1600                              "Invalid handle specified");
1601     }
1602     else {
1603 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1604         /* No control operations currently implemented. */
1605         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1606                                              for this device. */
1607         status = PROCESSOR_E_NOTSUPPORTED;
1608 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1609     }
1610 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1611     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_control",status);
1613     /*! @retval PROCESSOR_SUCCESS Operation successful */
1614     return status;
1618 /*!
1619  *  @brief      Translate slave virtual address to master physical address.
1620  *
1621  *  @param      handle     Handle to the Processor object
1622  *  @param      dstAddr    Returned: master physical address.
1623  *  @param      srcAddr    Slave virtual address.
1624  *
1625  *  @sa
1626  */
1627 Int
1628 VAYUIPUCORE0PROC_translate(
1629         Processor_Handle    handle,
1630         UInt32 *            dstAddr,
1631         UInt32              srcAddr)
1633     Int                         status = PROCESSOR_SUCCESS;
1634     Processor_Object *          procHandle= (Processor_Object *)handle;
1635     VAYUIPUCORE0PROC_Object *   object = NULL;
1636     UInt32                      i;
1637     UInt32                      startAddr;
1638     UInt32                      endAddr;
1639     UInt32                      offset;
1640     ProcMgr_AddrInfo *          ai;
1642     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1643               handle, dstAddr, srcAddr);
1645     GT_assert (curTrace, (handle  != NULL));
1646     GT_assert (curTrace, (dstAddr != NULL));
1648 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1649     if (handle == NULL) {
1650         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1651         status = PROCESSOR_E_HANDLE;
1652         GT_setFailureReason (curTrace,
1653                              GT_4CLASS,
1654                              "VAYUIPUCORE0PROC_translate",
1655                              status,
1656                              "Invalid handle specified");
1657     }
1658     else if (dstAddr == NULL) {
1659         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1660         status = PROCESSOR_E_INVALIDARG;
1661         GT_setFailureReason (curTrace,
1662                              GT_4CLASS,
1663                              "VAYUIPUCORE0PROC_translate",
1664                              status,
1665                              "dstAddr provided as NULL");
1666     }
1667     else {
1668 #endif
1669         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1670         GT_assert(curTrace, (object != NULL));
1671         *dstAddr = -1u;
1673         /* search all entries AddrTable */
1674         for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1675             i++) {
1676             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1677             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1678             endAddr = startAddr + ai->size;
1680             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1681                 offset = srcAddr - startAddr;
1682                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1683                 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE0PROC_translate: "
1684                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1685                     i, srcAddr, *dstAddr);
1686                 break;
1687             }
1688         }
1690         if (*dstAddr == -1u) {
1691             /* srcAddr not found in slave address space */
1692             status = PROCESSOR_E_INVALIDARG;
1693             GT_setFailureReason(curTrace, GT_4CLASS,
1694                 "VAYUIPUCORE0PROC_translate", status,
1695                 "srcAddr not found in slave address space");
1696         }
1697 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1698     }
1699 #endif
1700     GT_1trace(curTrace, GT_LEAVE,
1701         "VAYUIPUCORE0PROC_translate: status=0x%x", status);
1703     /*! @retval PROCESSOR_SUCCESS Operation successful */
1704     return status;
1708 /*!
1709  *  @brief      Map the given address translation into the slave mmu
1710  *
1711  *  @param      handle      Handle to the Processor object
1712  *  @param      dstAddr     Base virtual address
1713  *  @param      nSegs       Number of given segments
1714  *  @param      sglist      Segment list
1715  */
1716 Int
1717 VAYUIPUCORE0PROC_map(
1718         Processor_Handle    handle,
1719         UInt32 *            dstAddr,
1720         UInt32              nSegs,
1721         Memory_SGList *     sglist)
1723     Int                         status = PROCESSOR_SUCCESS ;
1724     Processor_Object *          procHandle = (Processor_Object *)handle;
1725     VAYUIPUCORE0PROC_Object *   object = NULL;
1726     Bool                        found = FALSE;
1727     UInt32                      startAddr;
1728     UInt32                      endAddr;
1729     UInt32                      i;
1730     UInt32                      j;
1731     ProcMgr_AddrInfo *          ai = NULL;
1733     GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_map:",
1734         handle, *dstAddr, nSegs, sglist);
1736     GT_assert (curTrace, (handle != NULL));
1737     GT_assert (curTrace, (sglist != NULL));
1738     GT_assert (curTrace, (nSegs > 0));
1740 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1741     if (handle == NULL) {
1742         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1743         status = PROCESSOR_E_HANDLE;
1744         GT_setFailureReason (curTrace,
1745                              GT_4CLASS,
1746                              "VAYUIPUCORE0PROC_map",
1747                              status,
1748                              "Invalid handle specified");
1749     }
1750     else if (sglist == NULL) {
1751         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1752         status = PROCESSOR_E_INVALIDARG;
1753         GT_setFailureReason (curTrace,
1754                              GT_4CLASS,
1755                              "VAYUIPUCORE0PROC_map",
1756                              status,
1757                              "sglist provided as NULL");
1758     }
1759     else if (nSegs == 0) {
1760         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1761         status = PROCESSOR_E_INVALIDARG;
1762         GT_setFailureReason (curTrace,
1763                              GT_4CLASS,
1764                              "VAYUIPUCORE0PROC_map",
1765                              status,
1766                              "Number of segments provided is 0");
1767     }
1768     else {
1769 #endif
1770         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1771         GT_assert (curTrace, (object != NULL));
1773         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1774             /* Update the translation table with entries for which mapping
1775              * is required. Add the entry only if the range does not exist
1776              * in the translation table.
1777              */
1778             for (j = 0;
1779                 j < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; j++) {
1780                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1782                 if (ai->isMapped == TRUE) {
1783                     startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1784                     endAddr = startAddr + ai->size;
1786                     if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1787                         && ((*dstAddr + sglist[i].size) <= endAddr)) {
1788                         found = TRUE;
1789                         ai->refCount++;
1790                         break;
1791                     }
1792                 }
1793             }
1795             /* If not found, add new entry to table. If mmu is disabled,
1796              * the assumption is that the ammu will be used.
1797              */
1798             if (!found) {
1799                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1800                     AddrTable_SIZE) {
1801                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1802                         [AddrTable_count[PROCID_TO_IPU
1803                         (procHandle->procId)]];
1804                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1805                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1806                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1807                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1808                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1809                     ai->size = sglist[i].size;
1810                     ai->isCached = sglist[i].isCached;
1811                     ai->refCount++;
1812                     ai->isMapped = TRUE;
1814                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1815                 }
1816                 else {
1817                     status = PROCESSOR_E_FAIL;
1818                     GT_setFailureReason(curTrace, GT_4CLASS,
1819                         "VAYUIPUCORE0PROC_map", status,
1820                         "AddrTable_SIZE reached!");
1821                 }
1822             }
1823         }
1824 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1825     }
1826 #endif
1827     GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_map", status);
1829     /*! @retval PROCESSOR_SUCCESS Operation successful */
1830     return status;
1834 /*!
1835  *  @brief      Function to unmap slave address from host address space
1836  *
1837  *  @param      handle      Handle to the Processor object
1838  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1839  *                          address.
1840  *  @param      size        Size of the region to be mapped.
1841  *
1842  *  @sa
1843  */
1844 Int
1845 VAYUIPUCORE0PROC_unmap(
1846         Processor_Handle    handle,
1847         UInt32              addr,
1848         UInt32              size)
1850     Int                         status = PROCESSOR_SUCCESS;
1851     Processor_Object *          procHandle = (Processor_Object *)handle;
1852     VAYUIPUCORE0PROC_Object *   object = NULL;
1853     ProcMgr_AddrInfo *          ai;
1854     Int                         i;
1855     UInt32                      startAddr;
1856     UInt32                      endAddr;
1857     VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1859     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_unmap",
1860                handle, addr, size);
1862     GT_assert (curTrace, (handle != NULL));
1863     GT_assert (curTrace, (size   != 0));
1865 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1866     if (handle == NULL) {
1867         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1868         status = PROCESSOR_E_HANDLE;
1869         GT_setFailureReason (curTrace,
1870                              GT_4CLASS,
1871                              "VAYUIPUCORE0PROC_unmap",
1872                              status,
1873                              "Invalid handle specified");
1874     }
1875     else if (size == 0) {
1876         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1877         status = PROCESSOR_E_INVALIDARG;
1878         GT_setFailureReason (curTrace,
1879                              GT_4CLASS,
1880                              "VAYUIPUCORE0PROC_unmap",
1881                              status,
1882                              "Size provided is zero");
1883     }
1884     else {
1885 #endif
1886         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1887         GT_assert (curTrace, (object != NULL));
1889         /* Delete added entries from translation
1890          * table only in last unmap called on that entry
1891          */
1892         for (i = 0;
1893             i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1894             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1896             if (!ai->isMapped) {
1897                 continue;
1898             }
1900             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1901             endAddr = startAddr + ai->size;
1903             if ((startAddr <= addr) && (addr < endAddr)) {
1904                 ai->refCount--;
1906                 if (ai->refCount == 0) {
1907                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1908                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1909                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1910                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1911                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1912                     ai->size = 0u;
1913                     ai->isCached = FALSE;
1914                     ai->mapMask = 0u;
1915                     ai->isMapped = FALSE;
1917                     /* Remove the entry from the IPUCORE0 MMU also */
1918                     deleteEntryArgs.size          = size;
1919                     deleteEntryArgs.slaveVirtAddr = addr;
1920                     /* TBD: elementSize, endianism, mixedSized are
1921                      * hard coded now, must be configurable later
1922                      */
1923                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
1924                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
1925                     deleteEntryArgs.mixedSize     = MMU_TLBES;
1927                     status = VAYUIPU_halMmuCtrl(object->halObject,
1928                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
1929 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1930                     if (status < 0) {
1931                         GT_setFailureReason(curTrace, GT_4CLASS,
1932                             "VAYUIPUCORE0PROC_unmap", status,
1933                             "IPUCORE0 MMU configuration failed");
1934                     }
1935 #endif
1936                 }
1937             }
1938         }
1939 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1940     }
1941 #endif
1942     GT_1trace(curTrace, GT_LEAVE,
1943         "VAYUIPUCORE0PROC_unmap", status);
1945     /*! @retval PROCESSOR_SUCCESS Operation successful */
1946     return status;
1950 #if defined (__cplusplus)
1952 #endif /* defined (__cplusplus) */