adab529ed3143c9e36ce050b8612803ab1442459
[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  Number of static entries in address translation table.
92  */
93 #define AddrTable_STATIC_COUNT 1
95 /*!
96  *  @brief  Max entries in address translation table.
97  */
98 #define AddrTable_SIZE 32
100 /* Number of IPUs supported */
101 #define NUM_IPUS 2
103 /* Convert procId to IPU # */
104 #define PROCID_TO_IPU(procId) (procId == VAYUIPUCORE0PROC_state.ipu1ProcId ?\
105     0 : 1)
108 /*!
109  *  @brief  VAYUIPUCORE0PROC Module state object
110  */
111 typedef struct VAYUIPUCORE0PROC_ModuleObject_tag {
112     UInt32                     configSize;
113     /*!< Size of configuration structure */
114     VAYUIPUCORE0PROC_Config    cfg;
115     /*!< VAYUIPUCORE0PROC configuration structure */
116     VAYUIPUCORE0PROC_Config    defCfg;
117     /*!< Default module configuration */
118     VAYUIPUCORE0PROC_Params    defInstParams;
119     /*!< Default parameters for the VAYUIPUCORE0PROC instances */
120     Bool                       isSetup;
121     /*!< Indicates whether the VAYUIPUCORE0PROC module is setup. */
122     VAYUIPUCORE0PROC_Handle    procHandles [MultiProc_MAXPROCESSORS];
123     /*!< Processor handle array. */
124     IGateProvider_Handle       gateHandle;
125     /*!< Handle of gate to be used for local thread safety */
126     UInt16                     ipu1ProcId;
127     /*!< MultiProc id of IPU1 (to avoid multiple lookups) */
128 } VAYUIPUCORE0PROC_ModuleObject;
130 /* Memory region counters */
131 static UInt32 AddrTable_count[NUM_IPUS] = {
132     AddrTable_STATIC_COUNT,
133     AddrTable_STATIC_COUNT,
134 };
136 /* static memory regions
137  * CAUTION: AddrTable_STATIC_COUNT must match number of entries below.
138  */
139 static ProcMgr_AddrInfo AddrTable_IPU1[AddrTable_SIZE] =
141     /* L2 RAM */
142     {
143         .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
144         .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
145         .addr[ProcMgr_AddrType_MasterPhys] = 0x55020000u,
146         .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
147         .addr[ProcMgr_AddrType_SlavePhys] = -1u,
148         .size = 0x10000u,
149         .isCached = FALSE,
150         .mapMask = ProcMgr_SLAVEVIRT,
151         .isMapped = TRUE,
152         .refCount = 0u      /* refCount set to 0 for static entry */
153     },
154 };
156 static ProcMgr_AddrInfo AddrTable_IPU2[AddrTable_SIZE] =
158     /* L2 RAM */
159     {
160         .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
161         .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
162         .addr[ProcMgr_AddrType_MasterPhys] = 0x55020000u,
163         .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
164         .addr[ProcMgr_AddrType_SlavePhys] = -1u,
165         .size = 0x10000u,
166         .isCached = FALSE,
167         .mapMask = ProcMgr_SLAVEVIRT,
168         .isMapped = TRUE,
169         .refCount = 0u      /* refCount set to 0 for static entry */
170     },
171 };
173 static ProcMgr_AddrInfo * AddrTable[NUM_IPUS] =
175     AddrTable_IPU1,
176     AddrTable_IPU2
177 };
179 /* =============================================================================
180  *  Globals
181  * =============================================================================
182  */
184 /*!
185  *  @var    VAYUIPUCORE0PROC_state
186  *
187  *  @brief  VAYUIPUCORE0PROC state object variable
188  */
189 #if !defined(SYSLINK_BUILD_DEBUG)
190 static
191 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
192 VAYUIPUCORE0PROC_ModuleObject VAYUIPUCORE0PROC_state =
194     .isSetup = FALSE,
195     .configSize = sizeof(VAYUIPUCORE0PROC_Config),
196     .gateHandle = NULL,
197     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
198 };
200 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
201 extern String ProcMgr_sysLinkCfgParams;
203 /* =============================================================================
204  * APIs directly called by applications
205  * =============================================================================
206  */
207 /*!
208  *  @brief      Function to get the default configuration for the VAYUIPUCORE0PROC
209  *              module.
210  *
211  *              This function can be called by the application to get their
212  *              configuration parameter to VAYUIPUCORE0PROC_setup filled in by the
213  *              VAYUIPUCORE0PROC module with the default parameters. If the user
214  *              does not wish to make any change in the default parameters, this
215  *              API is not required to be called.
216  *
217  *  @param      cfg        Pointer to the VAYUIPUCORE0PROC module configuration
218  *                         structure in which the default config is to be
219  *                         returned.
220  *
221  *  @sa         VAYUIPUCORE0PROC_setup
222  */
223 Void
224 VAYUIPUCORE0PROC_getConfig (VAYUIPUCORE0PROC_Config * cfg)
226     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_getConfig", cfg);
228     GT_assert (curTrace, (cfg != NULL));
230 #if !defined(SYSLINK_BUILD_OPTIMIZE)
231     if (cfg == NULL) {
232         GT_setFailureReason (curTrace,
233                              GT_4CLASS,
234                              "VAYUIPUCORE0PROC_getConfig",
235                              PROCESSOR_E_INVALIDARG,
236                              "Argument of type (VAYUIPUCORE0PROC_Config *) passed "
237                              "is null!");
238     }
239     else {
240 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
241         Memory_copy (cfg,
242                      &(VAYUIPUCORE0PROC_state.defCfg),
243                      sizeof (VAYUIPUCORE0PROC_Config));
244 #if !defined(SYSLINK_BUILD_OPTIMIZE)
245     }
246 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
248     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_getConfig");
252 /*!
253  *  @brief      Function to setup the VAYUIPUCORE0PROC module.
254  *
255  *              This function sets up the VAYUIPUCORE0PROC module. This function
256  *              must be called before any other instance-level APIs can be
257  *              invoked.
258  *              Module-level configuration needs to be provided to this
259  *              function. If the user wishes to change some specific config
260  *              parameters, then VAYUIPUCORE0PROC_getConfig can be called to get the
261  *              configuration filled with the default values. After this, only
262  *              the required configuration values can be changed. If the user
263  *              does not wish to make any change in the default parameters, the
264  *              application can simply call VAYUIPUCORE0PROC_setup with NULL
265  *              parameters. The default parameters would get automatically used.
266  *
267  *  @param      cfg   Optional VAYUIPUCORE0PROC module configuration. If provided as
268  *                    NULL, default configuration is used.
269  *
270  *  @sa         VAYUIPUCORE0PROC_destroy
271  *              GateMutex_create
272  */
273 Int
274 VAYUIPUCORE0PROC_setup (VAYUIPUCORE0PROC_Config * cfg)
276     Int                     status = PROCESSOR_SUCCESS;
277     VAYUIPUCORE0PROC_Config tmpCfg;
278     Error_Block             eb;
280     Error_init(&eb);
282     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_setup", cfg);
284     if (cfg == NULL) {
285         VAYUIPUCORE0PROC_getConfig (&tmpCfg);
286         cfg = &tmpCfg;
287     }
289     /* Create a default gate handle for local module protection. */
290     VAYUIPUCORE0PROC_state.gateHandle = (IGateProvider_Handle)
291                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
292 #if !defined(SYSLINK_BUILD_OPTIMIZE)
293     if (VAYUIPUCORE0PROC_state.gateHandle == NULL) {
294         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
295         status = PROCESSOR_E_FAIL;
296         GT_setFailureReason (curTrace,
297                              GT_4CLASS,
298                              "VAYUIPUCORE0PROC_setup",
299                              status,
300                              "Failed to create GateMutex!");
301     }
302     else {
303 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
304         /* Copy the user provided values into the state object. */
305         Memory_copy (&VAYUIPUCORE0PROC_state.cfg,
306                      cfg,
307                      sizeof (VAYUIPUCORE0PROC_Config));
309         /* Initialize the name to handles mapping array. */
310         Memory_set (&VAYUIPUCORE0PROC_state.procHandles,
311                     0,
312                     (sizeof (VAYUIPUCORE0PROC_Handle) * MultiProc_MAXPROCESSORS));
314         VAYUIPUCORE0PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
315         VAYUIPUCORE0PROC_state.isSetup = TRUE;
316 #if !defined(SYSLINK_BUILD_OPTIMIZE)
317     }
318 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
320     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_setup", status);
322     /*! @retval PROCESSOR_SUCCESS Operation successful */
323     return (status);
327 /*!
328  *  @brief      Function to destroy the VAYUIPUCORE0PROC module.
329  *
330  *              Once this function is called, other VAYUIPUCORE0PROC module APIs,
331  *              except for the VAYUIPUCORE0PROC_getConfig API cannot be called
332  *              anymore.
333  *
334  *  @sa         VAYUIPUCORE0PROC_setup
335  *              GateMutex_delete
336  */
337 Int
338 VAYUIPUCORE0PROC_destroy (Void)
340     Int    status = PROCESSOR_SUCCESS;
341     UInt16 i;
343     GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_destroy");
345     /* Check if any VAYUIPUCORE0PROC instances have not been deleted so far. If not,
346      * delete them.
347      */
348     for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
349         GT_assert (curTrace, (VAYUIPUCORE0PROC_state.procHandles [i] == NULL));
350         if (VAYUIPUCORE0PROC_state.procHandles [i] != NULL) {
351             VAYUIPUCORE0PROC_delete (&(VAYUIPUCORE0PROC_state.procHandles [i]));
352         }
353     }
355     if (VAYUIPUCORE0PROC_state.gateHandle != NULL) {
356         GateMutex_delete ((GateMutex_Handle *)
357                                 &(VAYUIPUCORE0PROC_state.gateHandle));
358     }
360     VAYUIPUCORE0PROC_state.isSetup = FALSE;
362     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_destroy", status);
364     /*! @retval PROCESSOR_SUCCESS Operation successful */
365     return (status);
369 /*!
370  *  @brief      Function to initialize the parameters for this Processor
371  *              instance.
372  *
373  *  @param      params  Configuration parameters to be returned
374  *
375  *  @sa         VAYUIPUCORE0PROC_create
376  */
377 Void
378 VAYUIPUCORE0PROC_Params_init(
379         VAYUIPUCORE0PROC_Handle     handle,
380         VAYUIPUCORE0PROC_Params *   params)
382     VAYUIPUCORE0PROC_Object *procObject = (VAYUIPUCORE0PROC_Object *)handle;
384     GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_Params_init",
385               handle, params);
387     GT_assert(curTrace, (params != NULL));
389 #if !defined(SYSLINK_BUILD_OPTIMIZE)
390     if (params == NULL) {
391         GT_setFailureReason(curTrace, GT_4CLASS,
392                             "VAYUIPUCORE0PROC_Params_init",
393                             PROCESSOR_E_INVALIDARG,
394                             "Argument of type (VAYUIPUCORE0PROC_Params *) "
395                             "passed is null!");
396     }
397     else {
398 #endif
399         if (handle == NULL) {
401             Memory_copy(params, &(VAYUIPUCORE0PROC_state.defInstParams),
402                 sizeof (VAYUIPUCORE0PROC_Params));
403         }
404         else {
405             /* return updated VAYUIPUCORE0PROC instance specific parameters */
406             Memory_copy(params, &(procObject->params),
407                         sizeof(VAYUIPUCORE0PROC_Params));
408         }
409 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
410     }
411 #endif
413     GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_Params_init");
416 /*!
417  *  @brief      Function to create an instance of this Processor.
418  *
419  *  @param      name    Name of the Processor instance.
420  *  @param      params  Configuration parameters.
421  *
422  *  @sa         VAYUIPUCORE0PROC_delete
423  */
424 VAYUIPUCORE0PROC_Handle
425 VAYUIPUCORE0PROC_create (      UInt16                procId,
426                      const VAYUIPUCORE0PROC_Params * params)
428     Int                   status     = PROCESSOR_SUCCESS;
429     Processor_Object *    handle     = NULL;
430     VAYUIPUCORE0PROC_Object * object = NULL;
431     Int i                            = 0;
432     ProcMgr_AddrInfo *ai             = NULL;
433     IArg                  key;
434     List_Params           listParams;
436     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_create", procId, params);
438     GT_assert (curTrace, IS_VALID_PROCID (procId));
439     GT_assert (curTrace, (params != NULL));
441 #if !defined(SYSLINK_BUILD_OPTIMIZE)
442     if (!IS_VALID_PROCID (procId)) {
443         /* Not setting status here since this function does not return status.*/
444         GT_setFailureReason (curTrace,
445                              GT_4CLASS,
446                              "VAYUIPUCORE0PROC_create",
447                              PROCESSOR_E_INVALIDARG,
448                              "Invalid procId specified");
449     }
450     else if (params == NULL) {
451         GT_setFailureReason (curTrace,
452                              GT_4CLASS,
453                              "VAYUIPUCORE0PROC_create",
454                              PROCESSOR_E_INVALIDARG,
455                              "params passed is NULL!");
456     }
457     else {
458 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
459         /* Enter critical section protection. */
460         key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
461 #if !defined(SYSLINK_BUILD_OPTIMIZE)
462         /* Check if the Processor already exists for specified procId. */
463         if (VAYUIPUCORE0PROC_state.procHandles [procId] != NULL) {
464             status = PROCESSOR_E_ALREADYEXIST;
465             GT_setFailureReason (curTrace,
466                               GT_4CLASS,
467                               "VAYUIPUCORE0PROC_create",
468                               status,
469                               "Processor already exists for specified procId!");
470         }
471         else {
472 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
473             /* Allocate memory for the handle */
474             handle = (Processor_Object *) Memory_calloc (NULL,
475                                                       sizeof (Processor_Object),
476                                                       0,
477                                                       NULL);
478             if (handle == NULL) {
479                 GT_setFailureReason (curTrace,
480                                      GT_4CLASS,
481                                      "VAYUIPUCORE0PROC_create",
482                                      PROCESSOR_E_MEMORY,
483                                      "Memory allocation failed for handle!");
484             }
485             else {
486                 /* Populate the handle fields */
487                 handle->procFxnTable.attach        = &VAYUIPUCORE0PROC_attach;
488                 handle->procFxnTable.detach        = &VAYUIPUCORE0PROC_detach;
489                 handle->procFxnTable.start         = &VAYUIPUCORE0PROC_start;
490                 handle->procFxnTable.stop          = &VAYUIPUCORE0PROC_stop;
491                 handle->procFxnTable.read          = &VAYUIPUCORE0PROC_read;
492                 handle->procFxnTable.write         = &VAYUIPUCORE0PROC_write;
493                 handle->procFxnTable.control       = &VAYUIPUCORE0PROC_control;
494                 handle->procFxnTable.map           = &VAYUIPUCORE0PROC_map;
495                 handle->procFxnTable.unmap         = &VAYUIPUCORE0PROC_unmap;
496                 handle->procFxnTable.translateAddr = &VAYUIPUCORE0PROC_translate;
497                 handle->state = ProcMgr_State_Unknown;
499                 /* Allocate memory for the VAYUIPUCORE0PROC handle */
500                 handle->object = Memory_calloc (NULL,
501                                                 sizeof (VAYUIPUCORE0PROC_Object),
502                                                 0,
503                                                 NULL);
504                 if (handle->object == NULL) {
505                     status = PROCESSOR_E_MEMORY;
506                     GT_setFailureReason (curTrace,
507                                 GT_4CLASS,
508                                 "VAYUIPUCORE0PROC_create",
509                                 status,
510                                 "Memory allocation failed for handle->object!");
511                 }
512                 else {
513                     handle->procId = procId;
514                     object = (VAYUIPUCORE0PROC_Object *) handle->object;
515                     object->procHandle = (Processor_Handle)handle;
516                     object->halObject = NULL;
517                     /* Copy params into instance object. */
518                     Memory_copy (&(object->params),
519                                  (Ptr) params,
520                                  sizeof (VAYUIPUCORE0PROC_Params));
522                     /* initialize the translation table */
523                     for (i = AddrTable_count[PROCID_TO_IPU(procId)];
524                         i < AddrTable_SIZE; i++) {
525                         ai = &AddrTable[PROCID_TO_IPU(procId)][i];
526                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
527                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
528                         ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
529                         ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
530                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
531                         ai->size = 0u;
532                         ai->isCached = FALSE;
533                         ai->mapMask = 0u;
534                         ai->isMapped = FALSE;
535                     }
537                     /*
538                      * initialize refCount for all entries
539                      * both static and dynamic
540                      */
541                     for (i = 0; i < AddrTable_SIZE; i++) {
542                         AddrTable[PROCID_TO_IPU(procId)][i].refCount = 0u;
543                     }
544                     Memory_copy((Ptr)(object->params.memEntries),
545                         AddrTable[PROCID_TO_IPU(procId)],
546                         (procId == VAYUIPUCORE0PROC_state.ipu1ProcId ?
547                         sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
549                     /* Set the handle in the state object. */
550                     VAYUIPUCORE0PROC_state.procHandles [procId] =
551                                                  (VAYUIPUCORE0PROC_Handle) object;
552                     /* Initialize the list of listeners */
553                     List_Params_init(&listParams);
554                     handle->registeredNotifiers = List_create(&listParams);
556 #if !defined(SYSLINK_BUILD_OPTIMIZE)
557                     if (handle->registeredNotifiers == NULL) {
558                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
559                         status = PROCESSOR_E_FAIL;
560                         GT_setFailureReason (curTrace,
561                                              GT_4CLASS,
562                                              "VAYUIPUCORE0PROC_create",
563                                              status,
564                                              "List_create failed");
565                     }
566                     else {
567 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
569                         handle->notifiersLock =
570                                  OsalMutex_create(OsalMutex_Type_Interruptible);
572 #if !defined(SYSLINK_BUILD_OPTIMIZE)
573                         if (handle->notifiersLock == NULL) {
574                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
575                             status = PROCESSOR_E_FAIL;
576                             GT_setFailureReason (curTrace,
577                                                  GT_4CLASS,
578                                                  "VAYUIPUCORE0PROC_create",
579                                                  status,
580                                                  "OsalMutex_create failed");
581                         }
582                     }
583 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
584                 }
585             }
586 #if !defined(SYSLINK_BUILD_OPTIMIZE)
587         }
588 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
590         /* Leave critical section protection. */
591         IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
592 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
593     }
594 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
596     if (status < 0) {
597         if (handle !=  NULL) {
598             if (handle->registeredNotifiers != NULL) {
599                 List_delete (&handle->registeredNotifiers);
600             }
601             if (handle->object != NULL) {
602                 Memory_free (NULL,
603                              handle->object,
604                              sizeof (VAYUIPUCORE0PROC_Object));
605             }
606             Memory_free (NULL, handle, sizeof (Processor_Object));
607         }
608         /*! @retval NULL Function failed */
609         handle = NULL;
610     }
612     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_create", handle);
614     /*! @retval Valid-Handle Operation successful */
615     return (VAYUIPUCORE0PROC_Handle) handle;
619 /*!
620  *  @brief      Function to delete an instance of this Processor.
621  *
622  *              The user provided pointer to the handle is reset after
623  *              successful completion of this function.
624  *
625  *  @param      handlePtr  Pointer to Handle to the Processor instance
626  *
627  *  @sa         VAYUIPUCORE0PROC_create
628  */
629 Int
630 VAYUIPUCORE0PROC_delete (VAYUIPUCORE0PROC_Handle * handlePtr)
632     Int                   status = PROCESSOR_SUCCESS;
633     VAYUIPUCORE0PROC_Object * object = NULL;
634     Processor_Object *    handle;
635     IArg                  key;
636     List_Elem *           elem    = NULL;
637     Processor_RegisterElem * regElem = NULL;
639     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_delete", handlePtr);
641     GT_assert (curTrace, (handlePtr != NULL));
642     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
644 #if !defined(SYSLINK_BUILD_OPTIMIZE)
645     if (handlePtr == NULL) {
646         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
647                                          specified*/
648         status = PROCESSOR_E_INVALIDARG;
649         GT_setFailureReason (curTrace,
650                              GT_4CLASS,
651                              "VAYUIPUCORE0PROC_delete",
652                              status,
653                              "Invalid NULL handlePtr pointer specified");
654     }
655     else if (*handlePtr == NULL) {
656         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
657         status = PROCESSOR_E_HANDLE;
658         GT_setFailureReason (curTrace,
659                              GT_4CLASS,
660                              "VAYUIPUCORE0PROC_delete",
661                              status,
662                              "Invalid NULL *handlePtr specified");
663     }
664     else {
665 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
666         handle = (Processor_Object *) (*handlePtr);
667         /* Enter critical section protection. */
668         key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
670         /* Reset handle in PwrMgr handle array. */
671         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
672         VAYUIPUCORE0PROC_state.procHandles [handle->procId] = NULL;
674         /* Free memory used for the VAYUIPUCORE0PROC object. */
675         if (handle->object != NULL) {
676             object = (VAYUIPUCORE0PROC_Object *) handle->object;
677             Memory_free (NULL,
678                          object,
679                          sizeof (VAYUIPUCORE0PROC_Object));
680             handle->object = NULL;
681         }
683         /*
684          * Check the list of listeners to see if any are remaining
685          * and reply to them
686          */
687         OsalMutex_delete(&handle->notifiersLock);
689         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
690             regElem = (Processor_RegisterElem *)elem;
692             /* Check if there is an associated timer and cancel it */
693             if (regElem->timer != -1) {
694                 struct itimerspec value ;
695                 value.it_value.tv_sec = 0;
696                 value.it_value.tv_nsec = 0;
697                 value.it_interval.tv_sec = 0;
698                 value.it_interval.tv_nsec = 0;
699                 timer_settime(regElem->timer, 0, &value, NULL);
701                 timer_delete(regElem->timer);
702                 regElem->timer = -1;
703             }
705             /* Call the callback function so it can clean up. */
706             regElem->info->cbFxn(handle->procId,
707                                  NULL,
708                                  handle->state,
709                                  handle->state,
710                                  ProcMgr_EventStatus_Canceled,
711                                  regElem->info->arg);
712             /* Free the memory */
713             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
714         }
716         /* Delete the list of listeners */
717         List_delete(&handle->registeredNotifiers);
719         /* Free memory used for the Processor object. */
720         Memory_free (NULL, handle, sizeof (Processor_Object));
721         *handlePtr = NULL;
723         /* Leave critical section protection. */
724         IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
725 #if !defined(SYSLINK_BUILD_OPTIMIZE)
726     }
727 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
729     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_delete", status);
731     /*! @retval PROCESSOR_SUCCESS Operation successful */
732     return (status);
736 /*!
737  *  @brief      Function to open a handle to an instance of this Processor. This
738  *              function is called when access to the Processor is required from
739  *              a different process.
740  *
741  *  @param      handlePtr   Handle to the Processor instance
742  *  @param      procId      Processor ID addressed by this Processor instance.
743  *
744  *  @sa         VAYUIPUCORE0PROC_close
745  */
746 Int
747 VAYUIPUCORE0PROC_open (VAYUIPUCORE0PROC_Handle * handlePtr, UInt16 procId)
749     Int status = PROCESSOR_SUCCESS;
751     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_open", handlePtr, procId);
753     GT_assert (curTrace, (handlePtr != NULL));
754     GT_assert (curTrace, IS_VALID_PROCID (procId));
756 #if !defined(SYSLINK_BUILD_OPTIMIZE)
757     if (handlePtr == NULL) {
758         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
759         status = PROCESSOR_E_HANDLE;
760         GT_setFailureReason (curTrace,
761                              GT_4CLASS,
762                              "VAYUIPUCORE0PROC_open",
763                              status,
764                              "Invalid NULL handlePtr specified");
765     }
766     else if (!IS_VALID_PROCID (procId)) {
767         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
768         status = PROCESSOR_E_INVALIDARG;
769         GT_setFailureReason (curTrace,
770                              GT_4CLASS,
771                              "VAYUIPUCORE0PROC_open",
772                              status,
773                              "Invalid procId specified");
774     }
775     else {
776 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
777         /* Initialize return parameter handle. */
778         *handlePtr = NULL;
780         /* Check if the PwrMgr exists and return the handle if found. */
781         if (VAYUIPUCORE0PROC_state.procHandles [procId] == NULL) {
782             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
783             status = PROCESSOR_E_NOTFOUND;
784             GT_setFailureReason (curTrace,
785                              GT_4CLASS,
786                              "VAYUIPUCORE0PROC_open",
787                              status,
788                              "Specified VAYUIPUCORE0PROC instance does not exist!");
789         }
790         else {
791             *handlePtr = VAYUIPUCORE0PROC_state.procHandles [procId];
792         }
793 #if !defined(SYSLINK_BUILD_OPTIMIZE)
794     }
795 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
797     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_open", status);
799     /*! @retval PROCESSOR_SUCCESS Operation successful */
800     return status;
804 /*!
805  *  @brief      Function to close a handle to an instance of this Processor.
806  *
807  *  @param      handlePtr  Pointer to Handle to the Processor instance
808  *
809  *  @sa         VAYUIPUCORE0PROC_open
810  */
811 Int
812 VAYUIPUCORE0PROC_close (VAYUIPUCORE0PROC_Handle * handlePtr)
814     Int status = PROCESSOR_SUCCESS;
816     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_close", handlePtr);
818     GT_assert (curTrace, (handlePtr != NULL));
819     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
821 #if !defined(SYSLINK_BUILD_OPTIMIZE)
822     if (handlePtr == NULL) {
823         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
824                                          specified*/
825         status = PROCESSOR_E_INVALIDARG;
826         GT_setFailureReason (curTrace,
827                              GT_4CLASS,
828                              "VAYUIPUCORE0PROC_close",
829                              status,
830                              "Invalid NULL handlePtr pointer specified");
831     }
832     else if (*handlePtr == NULL) {
833         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
834         status = PROCESSOR_E_HANDLE;
835         GT_setFailureReason (curTrace,
836                              GT_4CLASS,
837                              "VAYUIPUCORE0PROC_close",
838                              status,
839                              "Invalid NULL *handlePtr specified");
840     }
841     else {
842 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
843         /* Nothing to be done for close. */
844 #if !defined(SYSLINK_BUILD_OPTIMIZE)
845     }
846 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
848     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_close", status);
850     /*! @retval PROCESSOR_SUCCESS Operation successful */
851     return status;
855 /* =============================================================================
856  * APIs called by Processor module (part of function table interface)
857  * =============================================================================
858  */
859 /*!
860  *  @brief      Function to initialize the slave processor
861  *
862  *  @param      handle  Handle to the Processor instance
863  *  @param      params  Attach parameters
864  *
865  *  @sa         VAYUIPUCORE0PROC_detach
866  */
867 Int
868 VAYUIPUCORE0PROC_attach(
869         Processor_Handle            handle,
870         Processor_AttachParams *    params)
873     Int                         status = PROCESSOR_SUCCESS;
874     Processor_Object *          procHandle = (Processor_Object *)handle;
875     VAYUIPUCORE0PROC_Object *   object = NULL;
876     UInt32                      i = 0;
877     UInt32                      index = 0;
878     ProcMgr_AddrInfo *          me;
879     SysLink_MemEntry *          entry;
880     SysLink_MemEntry_Block      memBlock;
881     VAYUIPU_HalMmuCtrlArgs_Enable mmuEnableArgs;
882     VAYUIPU_HalParams           halParams;
884     GT_2trace(curTrace, GT_ENTER,
885               "VAYUIPUCORE0PROC_attach", handle, params);
886     GT_assert (curTrace, (handle != NULL));
887     GT_assert (curTrace, (params != NULL));
889 #if !defined(SYSLINK_BUILD_OPTIMIZE)
890     if (handle == NULL) {
891         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
892         status = PROCESSOR_E_HANDLE;
893         GT_setFailureReason (curTrace,
894                              GT_4CLASS,
895                              "VAYUIPUCORE0PROC_attach",
896                              status,
897                              "Invalid handle specified");
898     }
899     else if (params == NULL) {
900             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
901             status = PROCESSOR_E_INVALIDARG;
902             GT_setFailureReason (curTrace,
903                                  GT_4CLASS,
904                                  "VAYUIPUCORE0PROC_attach",
905                                  status,
906                                  "Invalid params specified");
907     }
908     else {
909 #endif
910         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
911         GT_assert (curTrace, (object != NULL));
913         /* Added for Netra Benelli core1 is cortex M4 */
914         params->procArch = Processor_ProcArch_M4;
916         object->pmHandle = params->pmHandle;
917         GT_0trace(curTrace, GT_1CLASS,
918             "VAYUIPUCORE0PROC_attach: Mapping memory regions");
920         /* search for dsp memory map */
921         status = RscTable_process(procHandle->procId,
922                                   TRUE,
923                                   &memBlock.numEntries);
924         if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
925             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
926             status = PROCESSOR_E_INVALIDARG;
927             GT_setFailureReason (curTrace,
928                                  GT_4CLASS,
929                                  "VAYUIPUCORE0PROC_attach",
930                                  status,
931                                  "Failed to process resource table");
932         }
933         else {
934             status = RscTable_getMemEntries(procHandle->procId,
935                                             memBlock.memEntries,
936                                             &memBlock.numEntries);
937             if (status < 0) {
938                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
939                 status = PROCESSOR_E_INVALIDARG;
940                 GT_setFailureReason (curTrace,
941                                      GT_4CLASS,
942                                      "VAYUIPUCORE0PROC_attach",
943                                      status,
944                                      "Failed to get resource table memEntries");
945             }
946         }
948         /* update translation tables with memory map */
949         for (i = 0; (i < memBlock.numEntries)
950             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
952             entry = &memBlock.memEntries[i];
954             if (entry->map == FALSE) {
955                 /* update table with entries which don't require mapping */
956                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
957                    AddrTable_SIZE) {
958                     me = &AddrTable[PROCID_TO_IPU(procHandle->procId)][
959                         AddrTable_count[PROCID_TO_IPU(procHandle->procId)]];
961                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
962                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
963                     me->addr[ProcMgr_AddrType_MasterPhys] =
964                         entry->masterPhysAddr;
965                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
966                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
967                     me->size = entry->size;
968                     me->isCached = entry->isCached;
969                     me->mapMask = entry->mapMask;
971                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
972                 }
973                 else {
974                     status = PROCESSOR_E_FAIL;
975                     GT_setFailureReason(curTrace, GT_4CLASS,
976                         "VAYUIPUCORE0PROC_attach", status,
977                         "AddrTable_SIZE reached!");
978                 }
979             }
980             else if (entry->map == TRUE) {
981                 /* send these entries back to ProcMgr for mapping */
982                 index = object->params.numMemEntries;
984                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
985                     me = &object->params.memEntries[index];
987                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
988                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
989                     me->addr[ProcMgr_AddrType_MasterPhys] =
990                         entry->masterPhysAddr;
991                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
992                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
993                     me->size = entry->size;
994                     me->isCached = entry->isCached;
995                     me->mapMask = entry->mapMask;
997                     object->params.numMemEntries++;
998                 }
999                 else {
1000                     status = PROCESSOR_E_FAIL;
1001                     GT_setFailureReason(curTrace, GT_4CLASS,
1002                                         "VAYUIPUCORE0PROC_attach", status,
1003                                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
1004                 }
1005             }
1006             else {
1007                 status = PROCESSOR_E_INVALIDARG;
1008                 GT_setFailureReason(curTrace, GT_4CLASS,
1009                     "VAYUIPUCORE0PROC_attach", status,
1010                     "Memory map has entry with invalid 'map' value");
1011             }
1012         } /* for (...) */
1014         if (status >= 0) {
1015             /* populate the return params */
1016             params->numMemEntries = object->params.numMemEntries;
1017             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1018                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1020             halParams.procId = procHandle->procId;
1021             status = VAYUIPU_halInit(&(object->halObject), &halParams);
1023 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1024             if (status < 0) {
1025                 GT_setFailureReason(curTrace, GT_4CLASS,
1026                     "VAYUIPUCORE0PROC_attach", status,
1027                     "VAYUIPU_halInit failed");
1028             }
1029             else {
1030 #endif
1031                 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1032                     || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1034 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1035                     if (status < 0) {
1036                         GT_setFailureReason(curTrace, GT_4CLASS,
1037                             "VAYUIPUCORE0PROC_attach", status,
1038                             "Failed to reset the slave processor");
1039                     }
1040                     else {
1041 #endif
1042                         GT_0trace(curTrace, GT_1CLASS,
1043                             "VAYUIPUCORE0PROC_attach: slave is now in reset");
1045                         mmuEnableArgs.numMemEntries = 0;
1046                         status = VAYUIPU_halMmuCtrl(object->halObject,
1047                             Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1048 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1049                         if (status < 0) {
1050                             GT_setFailureReason(curTrace, GT_4CLASS,
1051                                 "VAYUIPUCORE0PROC_attach", status,
1052                                 "Failed to enable the slave MMU");
1053                         }
1054                         else {
1055 #endif
1056                             GT_0trace(curTrace, GT_2CLASS,
1057                                 "VAYUIPUCORE0PROC_attach: Slave MMU "
1058                                 "is configured!");
1059                             /*
1060                              * Pull IPU MMU out of reset to make internal
1061                              * memory "loadable"
1062                              */
1063                             status = VAYUIPUCORE0_halResetCtrl(
1064                                 object->halObject,
1065                                 Processor_ResetCtrlCmd_MMU_Release);
1066                             if (status < 0) {
1067                                 /*! @retval status */
1068                                 GT_setFailureReason(curTrace,
1069                                     GT_4CLASS,
1070                                     "VAYUIPUCORE0_halResetCtrl",
1071                                     status,
1072                                     "Reset MMU_Release failed");
1073                             }
1074 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1075                         }
1076                     }
1077 #endif
1078                 }
1079 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1080             }
1081 #endif
1082         }
1083 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1084     }
1085 #endif
1087     GT_1trace(curTrace, GT_LEAVE,
1088         "VAYUIPUCORE0PROC_attach", status);
1090     /*! @retval PROCESSOR_SUCCESS Operation successful */
1091     return status;
1095 /*!
1096  *  @brief      Function to detach from the Processor.
1097  *
1098  *  @param      handle  Handle to the Processor instance
1099  *
1100  *  @sa         VAYUIPUCORE0PROC_attach
1101  */
1102 Int
1103 VAYUIPUCORE0PROC_detach (Processor_Handle handle)
1105     Int                       status     = PROCESSOR_SUCCESS;
1106     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1107     Processor_Object *        procHandle = (Processor_Object *) handle;
1108     VAYUIPUCORE0PROC_Object * object     = NULL;
1109     Int                       i          = 0;
1110     ProcMgr_AddrInfo *        ai;
1112     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_detach", handle);
1113     GT_assert (curTrace, (handle != NULL));
1115 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1116     if (handle == NULL) {
1117         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1118         status = PROCESSOR_E_HANDLE;
1119         GT_setFailureReason (curTrace,
1120                              GT_4CLASS,
1121                              "VAYUIPUCORE0PROC_detach",
1122                              PROCESSOR_E_HANDLE,
1123                              "Invalid handle specified");
1124     }
1125     else {
1126 #endif
1127         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1128         GT_assert (curTrace, (object != NULL));
1130         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1131             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1133             GT_0trace(curTrace, GT_2CLASS,
1134                 "VAYUIPUCORE0PROC_detach: Disabling Slave MMU ...");
1136             status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1137                 Processor_ResetCtrlCmd_MMU_Reset);
1138 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1139             if (status < 0) {
1140                 /*! @retval status */
1141                 GT_setFailureReason (curTrace,
1142                                      GT_4CLASS,
1143                                      "VAYUIPUCORE0_halResetCtrl",
1144                                      status,
1145                                      "Reset MMU failed");
1146             }
1147 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1149             status = VAYUIPU_halMmuCtrl(object->halObject,
1150                                         Processor_MmuCtrlCmd_Disable, NULL);
1151 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1152             if (status < 0) {
1153                 GT_setFailureReason(curTrace, GT_4CLASS,
1154                     "VAYUIPUCORE0PROC_detach", status,
1155                     "Failed to disable the slave MMU");
1156             }
1157 #endif
1159             /* delete all dynamically added entries */
1160             for (i = AddrTable_STATIC_COUNT; i <
1161                 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1162                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1163                 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1164                 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1165                 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1166                 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1167                 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1168                 ai->size = 0u;
1169                 ai->isCached = FALSE;
1170                 ai->mapMask = 0u;
1171                 ai->isMapped = FALSE;
1172                 ai->refCount = 0u;
1173             }
1174             object->params.numMemEntries = AddrTable_STATIC_COUNT;
1175             AddrTable_count[PROCID_TO_IPU(procHandle->procId)] =
1176                 AddrTable_STATIC_COUNT;
1178             //No need to reset.. that will be done in STOP
1179             /*tmpStatus = VAYUIPUCORE0_halResetCtrl(object->halObject,
1180                 Processor_ResetCtrlCmd_Reset, NULL);
1182             GT_0trace(curTrace, GT_2CLASS,
1183                 "VAYUIPUCORE0PROC_detach: Slave processor is now in reset");*/
1185 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1186             if ((tmpStatus < 0) && (status >= 0)) {
1187                 status = tmpStatus;
1188                 GT_setFailureReason (curTrace,
1189                                      GT_4CLASS,
1190                                      "VAYUIPUCORE0PROC_detach",
1191                                      status,
1192                                      "Failed to reset the slave processor");
1193             }
1194 #endif
1195         }
1197         GT_0trace (curTrace,
1198                    GT_2CLASS,
1199                    "    VAYUIPUCORE0PROC_detach: Unmapping memory regions\n");
1201         tmpStatus = VAYUIPU_halExit (object->halObject);
1202 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1203         if ((tmpStatus < 0) && (status >= 0)) {
1204             status = tmpStatus;
1205             GT_setFailureReason (curTrace,
1206                                  GT_4CLASS,
1207                                  "VAYUIPUCORE0PROC_detach",
1208                                  status,
1209                                  "Failed to finalize HAL object");
1210         }
1211     }
1212 #endif
1214     GT_1trace(curTrace, GT_LEAVE,
1215         "VAYUIPUCORE0PROC_detach", status);
1217     /*! @retval PROCESSOR_SUCCESS Operation successful */
1218     return status;
1222 /*!
1223  *  @brief      Function to start the slave processor
1224  *
1225  *              Start the slave processor running from its entry point.
1226  *              Depending on the boot mode, this involves configuring the boot
1227  *              address and releasing the slave from reset.
1228  *
1229  *  @param      handle    Handle to the Processor instance
1230  *
1231  *  @sa         VAYUIPUCORE0PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE0_halResetCtrl
1232  */
1233 Int
1234 VAYUIPUCORE0PROC_start (Processor_Handle        handle,
1235                         UInt32                  entryPt,
1236                         Processor_StartParams * params)
1238     Int                   status        = PROCESSOR_SUCCESS ;
1239     Processor_Object *    procHandle    = (Processor_Object *) handle;
1240     VAYUIPUCORE0PROC_Object * object    = NULL;
1243     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_start",
1244                handle, entryPt, params);
1246     GT_assert (curTrace, (handle != NULL));
1247     GT_assert (curTrace, (params != NULL));
1249 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1250     if (handle == NULL) {
1251         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1252         status = PROCESSOR_E_HANDLE;
1253         GT_setFailureReason (curTrace,
1254                              GT_4CLASS,
1255                              "VAYUIPUCORE0PROC_start",
1256                              status,
1257                              "Invalid handle specified");
1258     }
1259     else if (params == NULL) {
1260             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1261             status = PROCESSOR_E_INVALIDARG;
1262             GT_setFailureReason (curTrace,
1263                                  GT_4CLASS,
1264                                  "VAYUIPUCORE0PROC_start",
1265                                  status,
1266                                  "Invalid params specified");
1267     }
1268     else {
1269 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1270         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1271         GT_assert (curTrace, (object != NULL));
1272         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1273             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1274             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1275             /* Slave is to be started only for Boot mode and NoLoad mode. */
1276             /* Specify the IPU boot address in the boot config register */
1277             status = VAYUIPU_halBootCtrl (object->halObject,
1278                                           Processor_BootCtrlCmd_SetEntryPoint,
1279                                           (Ptr) entryPt);
1280 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1281             if (status < 0) {
1282                 GT_setFailureReason (curTrace,
1283                                      GT_4CLASS,
1284                                      "VAYUIPUCORE0PROC_start",
1285                                      status,
1286                                      "Failed to set slave boot entry point");
1287             }
1288             else {
1289 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1290                 status = rproc_ipu_setup(object->halObject,
1291                                          object->params.memEntries,
1292                                          object->params.numMemEntries);
1293                 if (status < 0) {
1294                     /*! @retval status */
1295                     GT_setFailureReason (curTrace,
1296                                          GT_4CLASS,
1297                                          "VAYUIPUCORE0_halResetCtrl",
1298                                           status,
1299                                          "rproc_ipu_setup failed");
1300                 }
1301                 /* release the slave cpu from reset */
1302                 if (status >= 0) {
1303                     status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1304                                                 Processor_ResetCtrlCmd_Release);
1305 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1306                     if (status < 0) {
1307                         GT_setFailureReason (curTrace,
1308                                           GT_4CLASS,
1309                                           "VAYUIPUCORE0PROC_start",
1310                                           status,
1311                                           "Failed to release slave from reset");
1312                     }
1313 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1314                 }
1315 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1316             }
1317 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1318         }
1320 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1321     }
1322 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1324     if (status >= 0) {
1325         GT_0trace (curTrace,
1326                    GT_1CLASS,
1327                    "    VAYUIPUCORE0PROC_start: Slave successfully started!\n");
1328     }
1329     else {
1330         GT_0trace (curTrace,
1331                    GT_1CLASS,
1332                    "    VAYUIPUCORE0PROC_start: Slave could not be started!\n");
1333     }
1335     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_start", status);
1337     /*! @retval PROCESSOR_SUCCESS Operation successful */
1338     return status;
1342 /*!
1343  *  @brief      Function to stop the slave processor
1344  *
1345  *              Stop the execution of the slave processor. Depending on the boot
1346  *              mode, this may result in placing the slave processor in reset.
1347  *
1348  *  @param      handle    Handle to the Processor instance
1349  *
1350  *  @sa         VAYUIPUCORE0PROC_start, VAYUIPUCORE0_halResetCtrl
1351  */
1352 Int
1353 VAYUIPUCORE0PROC_stop (Processor_Handle handle)
1355     Int                   status       = PROCESSOR_SUCCESS ;
1356     Processor_Object *    procHandle   = (Processor_Object *) handle;
1357     VAYUIPUCORE0PROC_Object * object       = NULL;
1359     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_stop", handle);
1361     GT_assert (curTrace, (handle != NULL));
1363 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1364     if (handle == NULL) {
1365         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1366         status = PROCESSOR_E_HANDLE;
1367         GT_setFailureReason (curTrace,
1368                              GT_4CLASS,
1369                              "VAYUIPUCORE0PROC_stop",
1370                              status,
1371                              "Invalid handle specified");
1372     }
1373     else {
1374 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1375         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1376         GT_assert (curTrace, (object != NULL));
1377         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1378             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1379             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1380             /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1381             /* Place the slave processor in reset. */
1382             status = VAYUIPUCORE0_halResetCtrl (object->halObject,
1383                                               Processor_ResetCtrlCmd_Reset);
1385             GT_0trace (curTrace,
1386                        GT_1CLASS,
1387                        "    VAYUIPUCORE0PROC_stop: Slave is now in reset!\n");
1388 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1389             if (status < 0) {
1390                 GT_setFailureReason (curTrace,
1391                                      GT_4CLASS,
1392                                      "VAYUIPUCORE0PROC_stop",
1393                                      status,
1394                                      "Failed to place slave in reset");
1395             }
1396 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1397             rproc_ipu_destroy(object->halObject);
1398         }
1399 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1400     }
1401 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1402     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_stop", status);
1404     /*! @retval PROCESSOR_SUCCESS Operation successful */
1405     return status;
1409 /*!
1410  *  @brief      Function to read from the slave processor's memory.
1411  *
1412  *              Read from the slave processor's memory and copy into the
1413  *              provided buffer.
1414  *
1415  *  @param      handle     Handle to the Processor instance
1416  *  @param      procAddr   Address in host processor's address space of the
1417  *                         memory region to read from.
1418  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1419  *                         number of bytes to be read. When the function
1420  *                         returns, this parameter contains the number of bytes
1421  *                         actually read.
1422  *  @param      buffer     User-provided buffer in which the slave processor's
1423  *                         memory contents are to be copied.
1424  *
1425  *  @sa         VAYUIPUCORE0PROC_write
1426  */
1427 Int
1428 VAYUIPUCORE0PROC_read (Processor_Handle   handle,
1429                        UInt32             procAddr,
1430                        UInt32 *           numBytes,
1431                        Ptr                buffer)
1433     Int       status   = PROCESSOR_SUCCESS ;
1434     UInt8  *  procPtr8 = NULL;
1436     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_read",
1437                handle, procAddr, numBytes, buffer);
1439     GT_assert (curTrace, (handle   != NULL));
1440     GT_assert (curTrace, (numBytes != NULL));
1441     GT_assert (curTrace, (buffer   != NULL));
1443 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1444     if (handle == NULL) {
1445         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1446         status = PROCESSOR_E_HANDLE;
1447         GT_setFailureReason (curTrace,
1448                              GT_4CLASS,
1449                              "VAYUIPUCORE0PROC_read",
1450                              status,
1451                              "Invalid handle specified");
1452     }
1453     else if (numBytes == 0) {
1454             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1455             status = PROCESSOR_E_INVALIDARG;
1456             GT_setFailureReason (curTrace,
1457                                  GT_4CLASS,
1458                                  "VAYUIPUCORE0PROC_read",
1459                                  status,
1460                                  "Invalid numBytes specified");
1461     }
1462     else if (buffer == NULL) {
1463             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1464             status = PROCESSOR_E_INVALIDARG;
1465             GT_setFailureReason (curTrace,
1466                                  GT_4CLASS,
1467                                  "VAYUIPUCORE0PROC_read",
1468                                  status,
1469                                  "Invalid buffer specified");
1470     }
1471     else {
1472 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1473         procPtr8 = (UInt8 *) procAddr ;
1474         buffer = memcpy (buffer, procPtr8, *numBytes);
1475         GT_assert (curTrace, (buffer != (UInt32) NULL));
1476 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1477         if (buffer == (UInt32) NULL) {
1478             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1479             status = PROCESSOR_E_FAIL;
1480             GT_setFailureReason (curTrace,
1481                                  GT_4CLASS,
1482                                  "VAYUIPUCORE0PROC_read",
1483                                  status,
1484                                  "Failed in memcpy");
1485             *numBytes = 0;
1486         }
1487     }
1488 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1490     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_read",status);
1492     /*! @retval PROCESSOR_SUCCESS Operation successful */
1493     return status;
1497 /*!
1498  *  @brief      Function to write into the slave processor's memory.
1499  *
1500  *              Read from the provided buffer and copy into the slave
1501  *              processor's memory.
1502  *
1503  *  @param      handle     Handle to the Processor object
1504  *  @param      procAddr   Address in host processor's address space of the
1505  *                         memory region to write into.
1506  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1507  *                         number of bytes to be written. When the function
1508  *                         returns, this parameter contains the number of bytes
1509  *                         actually written.
1510  *  @param      buffer     User-provided buffer from which the data is to be
1511  *                         written into the slave processor's memory.
1512  *
1513  *  @sa         VAYUIPUCORE0PROC_read, VAYUIPUCORE0PROC_translateAddr
1514  */
1515 Int
1516 VAYUIPUCORE0PROC_write (Processor_Handle handle,
1517                         UInt32           procAddr,
1518                         UInt32 *         numBytes,
1519                         Ptr              buffer)
1521     Int                   status       = PROCESSOR_SUCCESS ;
1522     UInt8  *              procPtr8     = NULL;
1523     UInt8                 temp8_1;
1524     UInt8                 temp8_2;
1525     UInt8                 temp8_3;
1526     UInt8                 temp8_4;
1527     UInt32                temp;
1529     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_write",
1530                handle, procAddr, numBytes, buffer);
1532     GT_assert (curTrace, (handle   != NULL));
1533     GT_assert (curTrace, (numBytes != NULL));
1534     GT_assert (curTrace, (buffer   != NULL));
1536 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1537     if (handle == NULL) {
1538         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1539         status = PROCESSOR_E_HANDLE;
1540         GT_setFailureReason (curTrace,
1541                              GT_4CLASS,
1542                              "VAYUIPUCORE0PROC_write",
1543                              status,
1544                              "Invalid handle specified");
1545     }
1546     else if (numBytes == 0) {
1547             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1548             status = PROCESSOR_E_INVALIDARG;
1549             GT_setFailureReason (curTrace,
1550                                  GT_4CLASS,
1551                                  "VAYUIPUCORE0PROC_write",
1552                                  status,
1553                                  "Invalid numBytes specified");
1554     }
1555     else if (buffer == NULL) {
1556             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1557             status = PROCESSOR_E_INVALIDARG;
1558             GT_setFailureReason (curTrace,
1559                                  GT_4CLASS,
1560                                  "VAYUIPUCORE0PROC_write",
1561                                  status,
1562                                  "Invalid buffer specified");
1563     }
1564     else {
1565 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1566         if (*numBytes != sizeof (UInt32)) {
1567             procPtr8 = (UInt8 *) procAddr ;
1568             procAddr = (UInt32) Memory_copy (procPtr8,
1569                                              buffer,
1570                                              *numBytes);
1571             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1572 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1573             if (procAddr == (UInt32) NULL) {
1574                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1575                 status = PROCESSOR_E_FAIL;
1576                 GT_setFailureReason (curTrace,
1577                                      GT_4CLASS,
1578                                      "VAYUIPUCORE0PROC_write",
1579                                      status,
1580                                      "Failed in Memory_copy");
1581                 *numBytes = 0;
1582             }
1583 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1584         }
1585         else  {
1586              /* For 4 bytes, directly write as a UInt32 */
1587             temp8_1 = ((UInt8 *) buffer) [0];
1588             temp8_2 = ((UInt8 *) buffer) [1];
1589             temp8_3 = ((UInt8 *) buffer) [2];
1590             temp8_4 = ((UInt8 *) buffer) [3];
1591             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1592                              |   ((UInt32) temp8_3 << 16)
1593                              |   ((UInt32) temp8_2 << 8)
1594                              |   ((UInt32) temp8_1));
1595             *((UInt32*) procAddr) = temp;
1596         }
1597 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1598     }
1599 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1601     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_write", status);
1603     /*! @retval PROCESSOR_SUCCESS Operation successful */
1604     return status;
1608 /*!
1609  *  @brief      Function to perform device-dependent operations.
1610  *
1611  *              Performs device-dependent control operations as exposed by this
1612  *              implementation of the Processor module.
1613  *
1614  *  @param      handle     Handle to the Processor object
1615  *  @param      cmd        Device specific processor command
1616  *  @param      arg        Arguments specific to the type of command.
1617  *
1618  *  @sa
1619  */
1620 Int
1621 VAYUIPUCORE0PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1623     Int                   status       = PROCESSOR_SUCCESS ;
1625     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_control", handle, cmd, arg);
1627     GT_assert (curTrace, (handle   != NULL));
1628     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1630 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1631     if (handle == NULL) {
1632         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1633         status = PROCESSOR_E_HANDLE;
1634         GT_setFailureReason (curTrace,
1635                              GT_4CLASS,
1636                              "VAYUIPUCORE0PROC_control",
1637                              status,
1638                              "Invalid handle specified");
1639     }
1640     else {
1641 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1642         /* No control operations currently implemented. */
1643         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1644                                              for this device. */
1645         status = PROCESSOR_E_NOTSUPPORTED;
1646 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1647     }
1648 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1649     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_control",status);
1651     /*! @retval PROCESSOR_SUCCESS Operation successful */
1652     return status;
1656 /*!
1657  *  @brief      Translate slave virtual address to master physical address.
1658  *
1659  *  @param      handle     Handle to the Processor object
1660  *  @param      dstAddr    Returned: master physical address.
1661  *  @param      srcAddr    Slave virtual address.
1662  *
1663  *  @sa
1664  */
1665 Int
1666 VAYUIPUCORE0PROC_translate(
1667         Processor_Handle    handle,
1668         UInt32 *            dstAddr,
1669         UInt32              srcAddr)
1671     Int                         status = PROCESSOR_SUCCESS;
1672     Processor_Object *          procHandle= (Processor_Object *)handle;
1673     VAYUIPUCORE0PROC_Object *   object = NULL;
1674     UInt32                      i;
1675     UInt32                      startAddr;
1676     UInt32                      endAddr;
1677     UInt32                      offset;
1678     ProcMgr_AddrInfo *          ai;
1680     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1681               handle, dstAddr, srcAddr);
1683     GT_assert (curTrace, (handle  != NULL));
1684     GT_assert (curTrace, (dstAddr != NULL));
1686 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1687     if (handle == NULL) {
1688         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1689         status = PROCESSOR_E_HANDLE;
1690         GT_setFailureReason (curTrace,
1691                              GT_4CLASS,
1692                              "VAYUIPUCORE0PROC_translate",
1693                              status,
1694                              "Invalid handle specified");
1695     }
1696     else if (dstAddr == NULL) {
1697         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1698         status = PROCESSOR_E_INVALIDARG;
1699         GT_setFailureReason (curTrace,
1700                              GT_4CLASS,
1701                              "VAYUIPUCORE0PROC_translate",
1702                              status,
1703                              "dstAddr provided as NULL");
1704     }
1705     else {
1706 #endif
1707         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1708         GT_assert(curTrace, (object != NULL));
1709         *dstAddr = -1u;
1711         /* search all entries AddrTable */
1712         for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1713             i++) {
1714             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1715             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1716             endAddr = startAddr + ai->size;
1718             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1719                 offset = srcAddr - startAddr;
1720                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1721                 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE0PROC_translate: "
1722                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1723                     i, srcAddr, *dstAddr);
1724                 break;
1725             }
1726         }
1728         if (*dstAddr == -1u) {
1729             /* srcAddr not found in slave address space */
1730             status = PROCESSOR_E_INVALIDARG;
1731             GT_setFailureReason(curTrace, GT_4CLASS,
1732                 "VAYUIPUCORE0PROC_translate", status,
1733                 "srcAddr not found in slave address space");
1734         }
1735 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1736     }
1737 #endif
1738     GT_1trace(curTrace, GT_LEAVE,
1739         "VAYUIPUCORE0PROC_translate: status=0x%x", status);
1741     /*! @retval PROCESSOR_SUCCESS Operation successful */
1742     return status;
1746 /*!
1747  *  @brief      Map the given address translation into the slave mmu
1748  *
1749  *  @param      handle      Handle to the Processor object
1750  *  @param      dstAddr     Base virtual address
1751  *  @param      nSegs       Number of given segments
1752  *  @param      sglist      Segment list
1753  */
1754 Int
1755 VAYUIPUCORE0PROC_map(
1756         Processor_Handle    handle,
1757         UInt32 *            dstAddr,
1758         UInt32              nSegs,
1759         Memory_SGList *     sglist)
1761     Int                         status = PROCESSOR_SUCCESS ;
1762     Processor_Object *          procHandle = (Processor_Object *)handle;
1763     VAYUIPUCORE0PROC_Object *   object = NULL;
1764     Bool                        found = FALSE;
1765     UInt32                      startAddr;
1766     UInt32                      endAddr;
1767     UInt32                      i;
1768     UInt32                      j;
1769     ProcMgr_AddrInfo *          ai = NULL;
1770     VAYUIPU_HalMmuCtrlArgs_AddEntry addEntryArgs;
1772     GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_map:",
1773         handle, *dstAddr, nSegs, sglist);
1775     GT_assert (curTrace, (handle != NULL));
1776     GT_assert (curTrace, (sglist != NULL));
1777     GT_assert (curTrace, (nSegs > 0));
1779 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1780     if (handle == NULL) {
1781         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1782         status = PROCESSOR_E_HANDLE;
1783         GT_setFailureReason (curTrace,
1784                              GT_4CLASS,
1785                              "VAYUIPUCORE0PROC_map",
1786                              status,
1787                              "Invalid handle specified");
1788     }
1789     else if (sglist == NULL) {
1790         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1791         status = PROCESSOR_E_INVALIDARG;
1792         GT_setFailureReason (curTrace,
1793                              GT_4CLASS,
1794                              "VAYUIPUCORE0PROC_map",
1795                              status,
1796                              "sglist provided as NULL");
1797     }
1798     else if (nSegs == 0) {
1799         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1800         status = PROCESSOR_E_INVALIDARG;
1801         GT_setFailureReason (curTrace,
1802                              GT_4CLASS,
1803                              "VAYUIPUCORE0PROC_map",
1804                              status,
1805                              "Number of segments provided is 0");
1806     }
1807     else {
1808 #endif
1809         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1810         GT_assert (curTrace, (object != NULL));
1812         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1813             /* Update the translation table with entries for which mapping
1814              * is required. Add the entry only if the range does not exist
1815              * in the translation table.
1816              */
1818             /* check in static entries first */
1819             for (j = 0; j < AddrTable_STATIC_COUNT; j++) {
1820                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1821                 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1822                 endAddr = startAddr + ai->size;
1824                 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)) {
1825                     found = TRUE;
1826                     /* refCount does not need to be incremented for static entries */
1827                     break;
1828                 }
1829             }
1831             /* if not found in static entries, check in dynamic entries */
1832             if (!found) {
1833                 for (j = AddrTable_STATIC_COUNT;
1834                     j < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; j++) {
1835                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1837                     if (ai->isMapped == TRUE) {
1838                         startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1839                         endAddr = startAddr + ai->size;
1841                         if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1842                             && ((*dstAddr + sglist[i].size) <= endAddr)) {
1843                             found = TRUE;
1844                             ai->refCount++;
1845                             break;
1846                         }
1847                     }
1848                 }
1849             }
1851             /* If not found, add new entry to table. If mmu is disabled,
1852              * the assumption is that the ammu will be used.
1853              */
1854             if (!found) {
1855                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1856                     AddrTable_SIZE) {
1857                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1858                         [AddrTable_count[PROCID_TO_IPU
1859                         (procHandle->procId)]];
1860                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1861                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1862                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1863                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1864                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1865                     ai->size = sglist[i].size;
1866                     ai->isCached = sglist[i].isCached;
1867                     ai->refCount++;
1869                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1870                 }
1871                 else {
1872                     status = PROCESSOR_E_FAIL;
1873                     GT_setFailureReason(curTrace, GT_4CLASS,
1874                         "VAYUIPUCORE0PROC_map", status,
1875                         "AddrTable_SIZE reached!");
1876                 }
1877             }
1879             /* if new entry, map into dsp mmu */
1880             if ((ai != NULL) && (ai->refCount == 1) && (status >= 0)) {
1881                 ai->isMapped = TRUE;
1883                 /* add entry to L2 MMU */
1884                 addEntryArgs.masterPhyAddr = sglist [i].paddr;
1885                 addEntryArgs.size          = sglist [i].size;
1886                 addEntryArgs.slaveVirtAddr = (UInt32)*dstAddr;
1887                 /* TBD: elementSize, endianism, mixedSized are
1888                  * hard coded now, must be configurable later
1889                  */
1890                 addEntryArgs.elementSize   = ELEM_SIZE_16BIT;
1891                 addEntryArgs.endianism     = LITTLE_ENDIAN;
1892                 addEntryArgs.mixedSize     = MMU_TLBES;
1894                 status = VAYUIPU_halMmuCtrl(object->halObject,
1895                     Processor_MmuCtrlCmd_AddEntry, &addEntryArgs);
1897 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1898                 if (status < 0) {
1899                     GT_setFailureReason(curTrace, GT_4CLASS,
1900                         "VAYUIPUCORE0PROC_map", status,
1901                         "Processor_MmuCtrlCmd_AddEntry failed");
1902                 }
1903 #endif
1904             }
1905 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1906             if (status < 0) {
1907                 GT_setFailureReason(curTrace, GT_4CLASS,
1908                     "VAYUIPUCORE0PROC_map", status,
1909                     "IPUCORE0 MMU configuration failed");
1910             }
1911 #endif
1912         }
1913 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1914     }
1915 #endif
1916     GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_map", status);
1918     /*! @retval PROCESSOR_SUCCESS Operation successful */
1919     return status;
1923 /*!
1924  *  @brief      Function to unmap slave address from host address space
1925  *
1926  *  @param      handle      Handle to the Processor object
1927  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1928  *                          address.
1929  *  @param      size        Size of the region to be mapped.
1930  *
1931  *  @sa
1932  */
1933 Int
1934 VAYUIPUCORE0PROC_unmap(
1935         Processor_Handle    handle,
1936         UInt32              addr,
1937         UInt32              size)
1939     Int                         status = PROCESSOR_SUCCESS;
1940     Processor_Object *          procHandle = (Processor_Object *)handle;
1941     VAYUIPUCORE0PROC_Object *   object = NULL;
1942     ProcMgr_AddrInfo *          ai;
1943     Int                         i;
1944     UInt32                      startAddr;
1945     UInt32                      endAddr;
1946     VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1948     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_unmap",
1949                handle, addr, size);
1951     GT_assert (curTrace, (handle != NULL));
1952     GT_assert (curTrace, (size   != 0));
1954 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1955     if (handle == NULL) {
1956         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1957         status = PROCESSOR_E_HANDLE;
1958         GT_setFailureReason (curTrace,
1959                              GT_4CLASS,
1960                              "VAYUIPUCORE0PROC_unmap",
1961                              status,
1962                              "Invalid handle specified");
1963     }
1964     else if (size == 0) {
1965         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1966         status = PROCESSOR_E_INVALIDARG;
1967         GT_setFailureReason (curTrace,
1968                              GT_4CLASS,
1969                              "VAYUIPUCORE0PROC_unmap",
1970                              status,
1971                              "Size provided is zero");
1972     }
1973     else {
1974 #endif
1975         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1976         GT_assert (curTrace, (object != NULL));
1978         /* Delete dynamically added non-default entries from translation
1979          * table only in last unmap called on that entry
1980          */
1981         for (i = AddrTable_STATIC_COUNT;
1982             i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1983             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1985             if (!ai->isMapped) {
1986                 continue;
1987             }
1989             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1990             endAddr = startAddr + ai->size;
1992             if ((startAddr <= addr) && (addr < endAddr)) {
1993                 ai->refCount--;
1995                 if (ai->refCount == 0) {
1996                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1997                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1998                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1999                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2000                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2001                     ai->size = 0u;
2002                     ai->isCached = FALSE;
2003                     ai->mapMask = 0u;
2004                     ai->isMapped = FALSE;
2006                     /* Remove the entry from the IPUCORE0 MMU also */
2007                     deleteEntryArgs.size          = size;
2008                     deleteEntryArgs.slaveVirtAddr = addr;
2009                     /* TBD: elementSize, endianism, mixedSized are
2010                      * hard coded now, must be configurable later
2011                      */
2012                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2013                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
2014                     deleteEntryArgs.mixedSize     = MMU_TLBES;
2016                     status = VAYUIPU_halMmuCtrl(object->halObject,
2017                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2018 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2019                     if (status < 0) {
2020                         GT_setFailureReason(curTrace, GT_4CLASS,
2021                             "VAYUIPUCORE0PROC_unmap", status,
2022                             "IPUCORE0 MMU configuration failed");
2023                     }
2024 #endif
2025                 }
2026             }
2027         }
2028 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2029     }
2030 #endif
2031     GT_1trace(curTrace, GT_LEAVE,
2032         "VAYUIPUCORE0PROC_unmap", status);
2034     /*! @retval PROCESSOR_SUCCESS Operation successful */
2035     return status;
2039 #if defined (__cplusplus)
2041 #endif /* defined (__cplusplus) */