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