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