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