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