Remove references to SysLink in QNX code base
[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-2015, 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(IPC_BUILD_DEBUG)
154 static
155 #endif /* if !defined(IPC_BUILD_DEBUG) */
156 VAYUIPUCORE0PROC_ModuleObject VAYUIPUCORE0PROC_state =
158     .isSetup = FALSE,
159     .configSize = sizeof(VAYUIPUCORE0PROC_Config),
160     .gateHandle = NULL,
161     .defInstParams.numMemEntries = 0,
162 };
165 /* =============================================================================
166  * APIs directly called by applications
167  * =============================================================================
168  */
169 /*!
170  *  @brief      Function to get the default configuration for the VAYUIPUCORE0PROC
171  *              module.
172  *
173  *              This function can be called by the application to get their
174  *              configuration parameter to VAYUIPUCORE0PROC_setup filled in by the
175  *              VAYUIPUCORE0PROC module with the default parameters. If the user
176  *              does not wish to make any change in the default parameters, this
177  *              API is not required to be called.
178  *
179  *  @param      cfg        Pointer to the VAYUIPUCORE0PROC module configuration
180  *                         structure in which the default config is to be
181  *                         returned.
182  *
183  *  @sa         VAYUIPUCORE0PROC_setup
184  */
185 Void
186 VAYUIPUCORE0PROC_getConfig (VAYUIPUCORE0PROC_Config * cfg)
188     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_getConfig", cfg);
190     GT_assert (curTrace, (cfg != NULL));
192 #if !defined(IPC_BUILD_OPTIMIZE)
193     if (cfg == NULL) {
194         GT_setFailureReason (curTrace,
195                              GT_4CLASS,
196                              "VAYUIPUCORE0PROC_getConfig",
197                              PROCESSOR_E_INVALIDARG,
198                              "Argument of type (VAYUIPUCORE0PROC_Config *) passed "
199                              "is null!");
200     }
201     else {
202 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
203         Memory_copy (cfg,
204                      &(VAYUIPUCORE0PROC_state.defCfg),
205                      sizeof (VAYUIPUCORE0PROC_Config));
206 #if !defined(IPC_BUILD_OPTIMIZE)
207     }
208 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
210     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_getConfig");
214 /*!
215  *  @brief      Function to setup the VAYUIPUCORE0PROC module.
216  *
217  *              This function sets up the VAYUIPUCORE0PROC module. This function
218  *              must be called before any other instance-level APIs can be
219  *              invoked.
220  *              Module-level configuration needs to be provided to this
221  *              function. If the user wishes to change some specific config
222  *              parameters, then VAYUIPUCORE0PROC_getConfig can be called to get the
223  *              configuration filled with the default values. After this, only
224  *              the required configuration values can be changed. If the user
225  *              does not wish to make any change in the default parameters, the
226  *              application can simply call VAYUIPUCORE0PROC_setup with NULL
227  *              parameters. The default parameters would get automatically used.
228  *
229  *  @param      cfg   Optional VAYUIPUCORE0PROC module configuration. If provided as
230  *                    NULL, default configuration is used.
231  *
232  *  @sa         VAYUIPUCORE0PROC_destroy
233  *              GateMutex_create
234  */
235 Int
236 VAYUIPUCORE0PROC_setup (VAYUIPUCORE0PROC_Config * cfg)
238     Int                     status = PROCESSOR_SUCCESS;
239     VAYUIPUCORE0PROC_Config tmpCfg;
240     Error_Block             eb;
242     Error_init(&eb);
244     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_setup", cfg);
246     if (cfg == NULL) {
247         VAYUIPUCORE0PROC_getConfig (&tmpCfg);
248         cfg = &tmpCfg;
249     }
251     /* Create a default gate handle for local module protection. */
252     VAYUIPUCORE0PROC_state.gateHandle = (IGateProvider_Handle)
253                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
254 #if !defined(IPC_BUILD_OPTIMIZE)
255     if (VAYUIPUCORE0PROC_state.gateHandle == NULL) {
256         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
257         status = PROCESSOR_E_FAIL;
258         GT_setFailureReason (curTrace,
259                              GT_4CLASS,
260                              "VAYUIPUCORE0PROC_setup",
261                              status,
262                              "Failed to create GateMutex!");
263     }
264     else {
265 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
266         /* Copy the user provided values into the state object. */
267         Memory_copy (&VAYUIPUCORE0PROC_state.cfg,
268                      cfg,
269                      sizeof (VAYUIPUCORE0PROC_Config));
271         /* Initialize the name to handles mapping array. */
272         Memory_set (&VAYUIPUCORE0PROC_state.procHandles,
273                     0,
274                     (sizeof (VAYUIPUCORE0PROC_Handle) * MultiProc_MAXPROCESSORS));
276         VAYUIPUCORE0PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
277         VAYUIPUCORE0PROC_state.isSetup = TRUE;
278 #if !defined(IPC_BUILD_OPTIMIZE)
279     }
280 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
282     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_setup", status);
284     /*! @retval PROCESSOR_SUCCESS Operation successful */
285     return (status);
289 /*!
290  *  @brief      Function to destroy the VAYUIPUCORE0PROC module.
291  *
292  *              Once this function is called, other VAYUIPUCORE0PROC module APIs,
293  *              except for the VAYUIPUCORE0PROC_getConfig API cannot be called
294  *              anymore.
295  *
296  *  @sa         VAYUIPUCORE0PROC_setup
297  *              GateMutex_delete
298  */
299 Int
300 VAYUIPUCORE0PROC_destroy (Void)
302     Int    status = PROCESSOR_SUCCESS;
303     UInt16 i;
305     GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_destroy");
307     /* Check if any VAYUIPUCORE0PROC instances have not been deleted so far. If not,
308      * delete them.
309      */
310     for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
311         GT_assert (curTrace, (VAYUIPUCORE0PROC_state.procHandles [i] == NULL));
312         if (VAYUIPUCORE0PROC_state.procHandles [i] != NULL) {
313             VAYUIPUCORE0PROC_delete (&(VAYUIPUCORE0PROC_state.procHandles [i]));
314         }
315     }
317     if (VAYUIPUCORE0PROC_state.gateHandle != NULL) {
318         GateMutex_delete ((GateMutex_Handle *)
319                                 &(VAYUIPUCORE0PROC_state.gateHandle));
320     }
322     VAYUIPUCORE0PROC_state.isSetup = FALSE;
324     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_destroy", status);
326     /*! @retval PROCESSOR_SUCCESS Operation successful */
327     return (status);
331 /*!
332  *  @brief      Function to initialize the parameters for this Processor
333  *              instance.
334  *
335  *  @param      params  Configuration parameters to be returned
336  *
337  *  @sa         VAYUIPUCORE0PROC_create
338  */
339 Void
340 VAYUIPUCORE0PROC_Params_init(
341         VAYUIPUCORE0PROC_Handle     handle,
342         VAYUIPUCORE0PROC_Params *   params)
344     VAYUIPUCORE0PROC_Object *procObject = (VAYUIPUCORE0PROC_Object *)handle;
346     GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_Params_init",
347               handle, params);
349     GT_assert(curTrace, (params != NULL));
351 #if !defined(IPC_BUILD_OPTIMIZE)
352     if (params == NULL) {
353         GT_setFailureReason(curTrace, GT_4CLASS,
354                             "VAYUIPUCORE0PROC_Params_init",
355                             PROCESSOR_E_INVALIDARG,
356                             "Argument of type (VAYUIPUCORE0PROC_Params *) "
357                             "passed is null!");
358     }
359     else {
360 #endif
361         if (handle == NULL) {
363             Memory_copy(params, &(VAYUIPUCORE0PROC_state.defInstParams),
364                 sizeof (VAYUIPUCORE0PROC_Params));
365         }
366         else {
367             /* return updated VAYUIPUCORE0PROC instance specific parameters */
368             Memory_copy(params, &(procObject->params),
369                         sizeof(VAYUIPUCORE0PROC_Params));
370         }
371 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
372     }
373 #endif
375     GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_Params_init");
378 /*!
379  *  @brief      Function to create an instance of this Processor.
380  *
381  *  @param      name    Name of the Processor instance.
382  *  @param      params  Configuration parameters.
383  *
384  *  @sa         VAYUIPUCORE0PROC_delete
385  */
386 VAYUIPUCORE0PROC_Handle
387 VAYUIPUCORE0PROC_create (      UInt16                procId,
388                      const VAYUIPUCORE0PROC_Params * params)
390     Int                   status     = PROCESSOR_SUCCESS;
391     Processor_Object *    handle     = NULL;
392     VAYUIPUCORE0PROC_Object * object = NULL;
393     Int i                            = 0;
394     ProcMgr_AddrInfo *ai             = NULL;
395     IArg                  key;
396     List_Params           listParams;
398     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_create", procId, params);
400     GT_assert (curTrace, IS_VALID_PROCID (procId));
401     GT_assert (curTrace, (params != NULL));
403 #if !defined(IPC_BUILD_OPTIMIZE)
404     if (!IS_VALID_PROCID (procId)) {
405         /* Not setting status here since this function does not return status.*/
406         GT_setFailureReason (curTrace,
407                              GT_4CLASS,
408                              "VAYUIPUCORE0PROC_create",
409                              PROCESSOR_E_INVALIDARG,
410                              "Invalid procId specified");
411     }
412     else if (params == NULL) {
413         GT_setFailureReason (curTrace,
414                              GT_4CLASS,
415                              "VAYUIPUCORE0PROC_create",
416                              PROCESSOR_E_INVALIDARG,
417                              "params passed is NULL!");
418     }
419     else {
420 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
421         /* Enter critical section protection. */
422         key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
423 #if !defined(IPC_BUILD_OPTIMIZE)
424         /* Check if the Processor already exists for specified procId. */
425         if (VAYUIPUCORE0PROC_state.procHandles [procId] != NULL) {
426             status = PROCESSOR_E_ALREADYEXIST;
427             GT_setFailureReason (curTrace,
428                               GT_4CLASS,
429                               "VAYUIPUCORE0PROC_create",
430                               status,
431                               "Processor already exists for specified procId!");
432         }
433         else {
434 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
435             /* Allocate memory for the handle */
436             handle = (Processor_Object *) Memory_calloc (NULL,
437                                                       sizeof (Processor_Object),
438                                                       0,
439                                                       NULL);
440             if (handle == NULL) {
441                 GT_setFailureReason (curTrace,
442                                      GT_4CLASS,
443                                      "VAYUIPUCORE0PROC_create",
444                                      PROCESSOR_E_MEMORY,
445                                      "Memory allocation failed for handle!");
446             }
447             else {
448                 /* Populate the handle fields */
449                 handle->procFxnTable.attach        = &VAYUIPUCORE0PROC_attach;
450                 handle->procFxnTable.detach        = &VAYUIPUCORE0PROC_detach;
451                 handle->procFxnTable.start         = &VAYUIPUCORE0PROC_start;
452                 handle->procFxnTable.stop          = &VAYUIPUCORE0PROC_stop;
453                 handle->procFxnTable.read          = &VAYUIPUCORE0PROC_read;
454                 handle->procFxnTable.write         = &VAYUIPUCORE0PROC_write;
455                 handle->procFxnTable.control       = &VAYUIPUCORE0PROC_control;
456                 handle->procFxnTable.map           = &VAYUIPUCORE0PROC_map;
457                 handle->procFxnTable.unmap         = &VAYUIPUCORE0PROC_unmap;
458                 handle->procFxnTable.translateAddr = &VAYUIPUCORE0PROC_translate;
459                 handle->procFxnTable.translateFromPte =
460                     &VAYUIPUCORE0PROC_translateFromPte;
461                 handle->state = ProcMgr_State_Unknown;
463                 /* Allocate memory for the VAYUIPUCORE0PROC handle */
464                 handle->object = Memory_calloc (NULL,
465                                                 sizeof (VAYUIPUCORE0PROC_Object),
466                                                 0,
467                                                 NULL);
468                 if (handle->object == NULL) {
469                     status = PROCESSOR_E_MEMORY;
470                     GT_setFailureReason (curTrace,
471                                 GT_4CLASS,
472                                 "VAYUIPUCORE0PROC_create",
473                                 status,
474                                 "Memory allocation failed for handle->object!");
475                 }
476                 else {
477                     handle->procId = procId;
478                     object = (VAYUIPUCORE0PROC_Object *) handle->object;
479                     object->procHandle = (Processor_Handle)handle;
480                     object->halObject = NULL;
481                     /* Copy params into instance object. */
482                     Memory_copy (&(object->params),
483                                  (Ptr) params,
484                                  sizeof (VAYUIPUCORE0PROC_Params));
486                     /* initialize the translation table */
487                     for (i = AddrTable_count[PROCID_TO_IPU(procId)];
488                         i < AddrTable_SIZE; i++) {
489                         ai = &AddrTable[PROCID_TO_IPU(procId)][i];
490                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
491                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
492                         ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
493                         ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
494                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
495                         ai->size = 0u;
496                         ai->isCached = FALSE;
497                         ai->mapMask = 0u;
498                         ai->isMapped = FALSE;
499                     }
501                     /*
502                      * initialize refCount for all entries
503                      */
504                     for (i = 0; i < AddrTable_SIZE; i++) {
505                         AddrTable[PROCID_TO_IPU(procId)][i].refCount = 0u;
506                     }
507                     Memory_copy((Ptr)(object->params.memEntries),
508                         AddrTable[PROCID_TO_IPU(procId)],
509                         (procId == VAYUIPUCORE0PROC_state.ipu1ProcId ?
510                         sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
512                     /* Set the handle in the state object. */
513                     VAYUIPUCORE0PROC_state.procHandles [procId] =
514                                                  (VAYUIPUCORE0PROC_Handle) object;
515                     /* Initialize the list of listeners */
516                     List_Params_init(&listParams);
517                     handle->registeredNotifiers = List_create(&listParams);
519 #if !defined(IPC_BUILD_OPTIMIZE)
520                     if (handle->registeredNotifiers == NULL) {
521                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
522                         status = PROCESSOR_E_FAIL;
523                         GT_setFailureReason (curTrace,
524                                              GT_4CLASS,
525                                              "VAYUIPUCORE0PROC_create",
526                                              status,
527                                              "List_create failed");
528                     }
529                     else {
530 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
532                         handle->notifiersLock =
533                                  OsalMutex_create(OsalMutex_Type_Interruptible);
535 #if !defined(IPC_BUILD_OPTIMIZE)
536                         if (handle->notifiersLock == NULL) {
537                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
538                             status = PROCESSOR_E_FAIL;
539                             GT_setFailureReason (curTrace,
540                                                  GT_4CLASS,
541                                                  "VAYUIPUCORE0PROC_create",
542                                                  status,
543                                                  "OsalMutex_create failed");
544                         }
545                     }
546 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
547                 }
548             }
549 #if !defined(IPC_BUILD_OPTIMIZE)
550         }
551 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
553         /* Leave critical section protection. */
554         IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
555 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
556     }
557 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
559     if (status < 0) {
560         if (handle !=  NULL) {
561             if (handle->registeredNotifiers != NULL) {
562                 List_delete (&handle->registeredNotifiers);
563             }
564             if (handle->object != NULL) {
565                 Memory_free (NULL,
566                              handle->object,
567                              sizeof (VAYUIPUCORE0PROC_Object));
568             }
569             Memory_free (NULL, handle, sizeof (Processor_Object));
570         }
571         /*! @retval NULL Function failed */
572         handle = NULL;
573     }
575     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_create", handle);
577     /*! @retval Valid-Handle Operation successful */
578     return (VAYUIPUCORE0PROC_Handle) handle;
582 /*!
583  *  @brief      Function to delete an instance of this Processor.
584  *
585  *              The user provided pointer to the handle is reset after
586  *              successful completion of this function.
587  *
588  *  @param      handlePtr  Pointer to Handle to the Processor instance
589  *
590  *  @sa         VAYUIPUCORE0PROC_create
591  */
592 Int
593 VAYUIPUCORE0PROC_delete (VAYUIPUCORE0PROC_Handle * handlePtr)
595     Int                   status = PROCESSOR_SUCCESS;
596     VAYUIPUCORE0PROC_Object * object = NULL;
597     Processor_Object *    handle;
598     IArg                  key;
599     List_Elem *           elem    = NULL;
600     Processor_RegisterElem * regElem = NULL;
602     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_delete", handlePtr);
604     GT_assert (curTrace, (handlePtr != NULL));
605     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
607 #if !defined(IPC_BUILD_OPTIMIZE)
608     if (handlePtr == NULL) {
609         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
610                                          specified*/
611         status = PROCESSOR_E_INVALIDARG;
612         GT_setFailureReason (curTrace,
613                              GT_4CLASS,
614                              "VAYUIPUCORE0PROC_delete",
615                              status,
616                              "Invalid NULL handlePtr pointer specified");
617     }
618     else if (*handlePtr == NULL) {
619         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
620         status = PROCESSOR_E_HANDLE;
621         GT_setFailureReason (curTrace,
622                              GT_4CLASS,
623                              "VAYUIPUCORE0PROC_delete",
624                              status,
625                              "Invalid NULL *handlePtr specified");
626     }
627     else {
628 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
629         handle = (Processor_Object *) (*handlePtr);
630         /* Enter critical section protection. */
631         key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
633         /* Reset handle in PwrMgr handle array. */
634         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
635         VAYUIPUCORE0PROC_state.procHandles [handle->procId] = NULL;
637         /* Free memory used for the VAYUIPUCORE0PROC object. */
638         if (handle->object != NULL) {
639             object = (VAYUIPUCORE0PROC_Object *) handle->object;
640             Memory_free (NULL,
641                          object,
642                          sizeof (VAYUIPUCORE0PROC_Object));
643             handle->object = NULL;
644         }
646         /*
647          * Check the list of listeners to see if any are remaining
648          * and reply to them
649          */
650         OsalMutex_delete(&handle->notifiersLock);
652         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
653             regElem = (Processor_RegisterElem *)elem;
655             /* Check if there is an associated timer and cancel it */
656             if (regElem->timer != -1) {
657                 struct itimerspec value ;
658                 value.it_value.tv_sec = 0;
659                 value.it_value.tv_nsec = 0;
660                 value.it_interval.tv_sec = 0;
661                 value.it_interval.tv_nsec = 0;
662                 timer_settime(regElem->timer, 0, &value, NULL);
664                 timer_delete(regElem->timer);
665                 regElem->timer = -1;
666             }
668             /* Call the callback function so it can clean up. */
669             regElem->info->cbFxn(handle->procId,
670                                  NULL,
671                                  handle->state,
672                                  handle->state,
673                                  ProcMgr_EventStatus_Canceled,
674                                  regElem->info->arg);
675             /* Free the memory */
676             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
677         }
679         /* Delete the list of listeners */
680         List_delete(&handle->registeredNotifiers);
682         /* Free memory used for the Processor object. */
683         Memory_free (NULL, handle, sizeof (Processor_Object));
684         *handlePtr = NULL;
686         /* Leave critical section protection. */
687         IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
688 #if !defined(IPC_BUILD_OPTIMIZE)
689     }
690 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
692     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_delete", status);
694     /*! @retval PROCESSOR_SUCCESS Operation successful */
695     return (status);
699 /*!
700  *  @brief      Function to open a handle to an instance of this Processor. This
701  *              function is called when access to the Processor is required from
702  *              a different process.
703  *
704  *  @param      handlePtr   Handle to the Processor instance
705  *  @param      procId      Processor ID addressed by this Processor instance.
706  *
707  *  @sa         VAYUIPUCORE0PROC_close
708  */
709 Int
710 VAYUIPUCORE0PROC_open (VAYUIPUCORE0PROC_Handle * handlePtr, UInt16 procId)
712     Int status = PROCESSOR_SUCCESS;
714     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_open", handlePtr, procId);
716     GT_assert (curTrace, (handlePtr != NULL));
717     GT_assert (curTrace, IS_VALID_PROCID (procId));
719 #if !defined(IPC_BUILD_OPTIMIZE)
720     if (handlePtr == NULL) {
721         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
722         status = PROCESSOR_E_HANDLE;
723         GT_setFailureReason (curTrace,
724                              GT_4CLASS,
725                              "VAYUIPUCORE0PROC_open",
726                              status,
727                              "Invalid NULL handlePtr specified");
728     }
729     else if (!IS_VALID_PROCID (procId)) {
730         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
731         status = PROCESSOR_E_INVALIDARG;
732         GT_setFailureReason (curTrace,
733                              GT_4CLASS,
734                              "VAYUIPUCORE0PROC_open",
735                              status,
736                              "Invalid procId specified");
737     }
738     else {
739 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
740         /* Initialize return parameter handle. */
741         *handlePtr = NULL;
743         /* Check if the PwrMgr exists and return the handle if found. */
744         if (VAYUIPUCORE0PROC_state.procHandles [procId] == NULL) {
745             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
746             status = PROCESSOR_E_NOTFOUND;
747             GT_setFailureReason (curTrace,
748                              GT_4CLASS,
749                              "VAYUIPUCORE0PROC_open",
750                              status,
751                              "Specified VAYUIPUCORE0PROC instance does not exist!");
752         }
753         else {
754             *handlePtr = VAYUIPUCORE0PROC_state.procHandles [procId];
755         }
756 #if !defined(IPC_BUILD_OPTIMIZE)
757     }
758 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
760     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_open", status);
762     /*! @retval PROCESSOR_SUCCESS Operation successful */
763     return status;
767 /*!
768  *  @brief      Function to close a handle to an instance of this Processor.
769  *
770  *  @param      handlePtr  Pointer to Handle to the Processor instance
771  *
772  *  @sa         VAYUIPUCORE0PROC_open
773  */
774 Int
775 VAYUIPUCORE0PROC_close (VAYUIPUCORE0PROC_Handle * handlePtr)
777     Int status = PROCESSOR_SUCCESS;
779     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_close", handlePtr);
781     GT_assert (curTrace, (handlePtr != NULL));
782     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
784 #if !defined(IPC_BUILD_OPTIMIZE)
785     if (handlePtr == NULL) {
786         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
787                                          specified*/
788         status = PROCESSOR_E_INVALIDARG;
789         GT_setFailureReason (curTrace,
790                              GT_4CLASS,
791                              "VAYUIPUCORE0PROC_close",
792                              status,
793                              "Invalid NULL handlePtr pointer specified");
794     }
795     else if (*handlePtr == NULL) {
796         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
797         status = PROCESSOR_E_HANDLE;
798         GT_setFailureReason (curTrace,
799                              GT_4CLASS,
800                              "VAYUIPUCORE0PROC_close",
801                              status,
802                              "Invalid NULL *handlePtr specified");
803     }
804     else {
805 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
806         /* Nothing to be done for close. */
807 #if !defined(IPC_BUILD_OPTIMIZE)
808     }
809 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
811     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_close", status);
813     /*! @retval PROCESSOR_SUCCESS Operation successful */
814     return status;
818 /* =============================================================================
819  * APIs called by Processor module (part of function table interface)
820  * =============================================================================
821  */
822 /*!
823  *  @brief      Function to initialize the slave processor
824  *
825  *  @param      handle  Handle to the Processor instance
826  *  @param      params  Attach parameters
827  *
828  *  @sa         VAYUIPUCORE0PROC_detach
829  */
830 Int
831 VAYUIPUCORE0PROC_attach(
832         Processor_Handle            handle,
833         Processor_AttachParams *    params)
836     Int                         status = PROCESSOR_SUCCESS;
837     Processor_Object *          procHandle = (Processor_Object *)handle;
838     VAYUIPUCORE0PROC_Object *   object = NULL;
839     UInt32                      i = 0;
840     UInt32                      index = 0;
841     ProcMgr_AddrInfo *          me;
842     Ipc_MemEntry *              entry;
843     Ipc_MemEntry_Block          memBlock;
844     VAYUIPU_HalMmuCtrlArgs_Enable mmuEnableArgs;
845     VAYUIPU_HalParams           halParams;
847     GT_2trace(curTrace, GT_ENTER,
848               "VAYUIPUCORE0PROC_attach", handle, params);
849     GT_assert (curTrace, (handle != NULL));
850     GT_assert (curTrace, (params != NULL));
852 #if !defined(IPC_BUILD_OPTIMIZE)
853     if (handle == NULL) {
854         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
855         status = PROCESSOR_E_HANDLE;
856         GT_setFailureReason (curTrace,
857                              GT_4CLASS,
858                              "VAYUIPUCORE0PROC_attach",
859                              status,
860                              "Invalid handle specified");
861     }
862     else if (params == NULL) {
863             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
864             status = PROCESSOR_E_INVALIDARG;
865             GT_setFailureReason (curTrace,
866                                  GT_4CLASS,
867                                  "VAYUIPUCORE0PROC_attach",
868                                  status,
869                                  "Invalid params specified");
870     }
871     else {
872 #endif
873         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
874         GT_assert (curTrace, (object != NULL));
876         /* Initialize halObject for Processor_translateFromPte to work */
877         halParams.procId = procHandle->procId;
878         status = VAYUIPU_halInit(&(object->halObject), &halParams);
880         if (status < 0) {
881             GT_setFailureReason(curTrace, GT_4CLASS,
882                 "VAYUIPUCORE0PROC_attach", status,
883                 "VAYUIPU_halInit failed");
884         }
886         /* Added for Netra Benelli core1 is cortex M4 */
887         params->procArch = Processor_ProcArch_M4;
889         object->pmHandle = params->pmHandle;
890         GT_0trace(curTrace, GT_1CLASS,
891             "VAYUIPUCORE0PROC_attach: Mapping memory regions");
893         if (status >= 0) {
894             /* search for dsp memory map */
895             status = RscTable_process(procHandle->procId,
896                                   TRUE,
897                                   &memBlock.numEntries,
898                                   procHandle,
899                                   procHandle->bootMode);
900             if (status < 0 || memBlock.numEntries > IPC_MAX_MEMENTRIES) {
901                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
902                 status = PROCESSOR_E_INVALIDARG;
903                 GT_setFailureReason (curTrace,
904                                  GT_4CLASS,
905                                  "VAYUIPUCORE0PROC_attach",
906                                  status,
907                                  "Failed to process resource table");
908             }
909             else {
910                 status = RscTable_getMemEntries(procHandle->procId,
911                                             memBlock.memEntries,
912                                             &memBlock.numEntries);
913                 if (status < 0) {
914                     /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
915                     status = PROCESSOR_E_INVALIDARG;
916                     GT_setFailureReason (curTrace,
917                                      GT_4CLASS,
918                                      "VAYUIPUCORE0PROC_attach",
919                                      status,
920                                      "Failed to get resource table memEntries");
921                 }
922             }
923         }
925         /* update translation tables with memory map */
926         for (i = 0; (i < memBlock.numEntries)
927             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
929             entry = &memBlock.memEntries[i];
931             if (entry->map == FALSE) {
932                 /* update table with entries which don't require mapping */
933                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
934                    AddrTable_SIZE) {
935                     me = &AddrTable[PROCID_TO_IPU(procHandle->procId)][
936                         AddrTable_count[PROCID_TO_IPU(procHandle->procId)]];
938                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
939                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
940                     me->addr[ProcMgr_AddrType_MasterPhys] =
941                         entry->masterPhysAddr;
942                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
943                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
944                     me->size = entry->size;
945                     me->isCached = entry->isCached;
946                     me->mapMask = entry->mapMask;
948                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
949                 }
950                 else {
951                     status = PROCESSOR_E_FAIL;
952                     GT_setFailureReason(curTrace, GT_4CLASS,
953                         "VAYUIPUCORE0PROC_attach", status,
954                         "AddrTable_SIZE reached!");
955                 }
956             }
957             else if (entry->map == TRUE) {
958                 /* send these entries back to ProcMgr for mapping */
959                 index = object->params.numMemEntries;
961                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
962                     me = &object->params.memEntries[index];
964                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
965                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
966                     me->addr[ProcMgr_AddrType_MasterPhys] =
967                         entry->masterPhysAddr;
968                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
969                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
970                     me->size = entry->size;
971                     me->isCached = entry->isCached;
972                     me->mapMask = entry->mapMask;
974                     object->params.numMemEntries++;
975                 }
976                 else {
977                     status = PROCESSOR_E_FAIL;
978                     GT_setFailureReason(curTrace, GT_4CLASS,
979                                         "VAYUIPUCORE0PROC_attach", status,
980                                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
981                 }
982             }
983             else {
984                 status = PROCESSOR_E_INVALIDARG;
985                 GT_setFailureReason(curTrace, GT_4CLASS,
986                     "VAYUIPUCORE0PROC_attach", status,
987                     "Memory map has entry with invalid 'map' value");
988             }
989         } /* for (...) */
991         if (status >= 0) {
992             /* populate the return params */
993             params->numMemEntries = object->params.numMemEntries;
994             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
995                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
998             /* Setup the xbar for MMU fault interrupts */
999             mmuEnableArgs.numMemEntries = 0;
1000             status = VAYUIPU_halMmuCtrl(object->halObject,
1001                 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1003             if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1004                 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1006 #if !defined(IPC_BUILD_OPTIMIZE)
1007                 if (status < 0) {
1008                     GT_setFailureReason(curTrace, GT_4CLASS,
1009                         "VAYUIPUCORE0PROC_attach", status,
1010                         "Failed to enable the slave MMU");
1011                 }
1012                 else {
1013 #endif
1014                     GT_0trace(curTrace, GT_2CLASS,
1015                         "VAYUIPUCORE0PROC_attach: Slave MMU "
1016                         "is configured!");
1018                     /*
1019                      * Pull IPU MMU out of reset to make internal
1020                      * memory "loadable"
1021                      */
1022                     status = VAYUIPUCORE0_halResetCtrl(
1023                         object->halObject,
1024                         Processor_ResetCtrlCmd_MMU_Release);
1025                     if (status < 0) {
1026                         /*! @retval status */
1027                         GT_setFailureReason(curTrace,
1028                             GT_4CLASS,
1029                             "VAYUIPUCORE0_halResetCtrl",
1030                             status,
1031                             "Reset MMU_Release failed");
1032                     }
1033 #if !defined(IPC_BUILD_OPTIMIZE)
1034                 }
1035 #endif
1036             }
1037             else {
1038                 /* NoBoot, late-attach */
1039                 /*
1040                  * Setup MMU fault interrupt now since we won't have a chance
1041                  * to do it in ProcMgr_start
1042                  */
1043                 rproc_enable_fault_interrupt(object->halObject);
1045 #if !defined(IPC_BUILD_OPTIMIZE)
1046                 if (status < 0) {
1047                     GT_setFailureReason(curTrace, GT_4CLASS,
1048                         "VAYUIPUCORE0PROC_attach", status,
1049                         "Failed to enable the slave MMU");
1050                 }
1051                 else {
1052 #endif
1053                     GT_0trace(curTrace, GT_1CLASS,
1054                         "VAYUIPUCORE0PROC_attach: Slave MMU interrupt is "
1055                         "configured");
1056 #if !defined(IPC_BUILD_OPTIMIZE)
1057                 }
1058 #endif
1059             }
1060         }
1061 #if !defined(IPC_BUILD_OPTIMIZE)
1062     }
1063 #endif
1065     GT_1trace(curTrace, GT_LEAVE,
1066         "VAYUIPUCORE0PROC_attach", status);
1068     /*! @retval PROCESSOR_SUCCESS Operation successful */
1069     return status;
1073 /*!
1074  *  @brief      Function to detach from the Processor.
1075  *
1076  *  @param      handle  Handle to the Processor instance
1077  *
1078  *  @sa         VAYUIPUCORE0PROC_attach
1079  */
1080 Int
1081 VAYUIPUCORE0PROC_detach (Processor_Handle handle)
1083     Int                       status     = PROCESSOR_SUCCESS;
1084     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1085     Processor_Object *        procHandle = (Processor_Object *) handle;
1086     VAYUIPUCORE0PROC_Object * object     = NULL;
1087     Int                       i          = 0;
1088     ProcMgr_AddrInfo *        ai;
1090     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_detach", handle);
1091     GT_assert (curTrace, (handle != NULL));
1093 #if !defined(IPC_BUILD_OPTIMIZE)
1094     if (handle == NULL) {
1095         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1096         status = PROCESSOR_E_HANDLE;
1097         GT_setFailureReason (curTrace,
1098                              GT_4CLASS,
1099                              "VAYUIPUCORE0PROC_detach",
1100                              PROCESSOR_E_HANDLE,
1101                              "Invalid handle specified");
1102     }
1103     else {
1104 #endif
1105         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1106         GT_assert (curTrace, (object != NULL));
1108         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1109             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1111             GT_0trace(curTrace, GT_2CLASS,
1112                 "VAYUIPUCORE0PROC_detach: Disabling Slave MMU ...");
1114             status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1115                 Processor_ResetCtrlCmd_MMU_Reset);
1116 #if !defined(IPC_BUILD_OPTIMIZE)
1117             if (status < 0) {
1118                 /*! @retval status */
1119                 GT_setFailureReason (curTrace,
1120                                      GT_4CLASS,
1121                                      "VAYUIPUCORE0PROC_detach",
1122                                      status,
1123                                      "Reset MMU failed");
1124             }
1125 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1126         }
1127         else {
1128             status = rproc_disable_fault_interrupt(object->halObject);
1129 #if !defined(IPC_BUILD_OPTIMIZE)
1130             if (status < 0) {
1131                 /*! @retval status */
1132                 GT_setFailureReason (curTrace,
1133                                      GT_4CLASS,
1134                                      "VAYUIPUCORE0PROC_detach",
1135                                      status,
1136                                      "rproc_disable_fault_interrupt failed");
1137             }
1138 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1139         }
1141         if (status >= 0) {
1142              status = VAYUIPU_halMmuCtrl(object->halObject,
1143                                     Processor_MmuCtrlCmd_Disable, NULL);
1144 #if !defined(IPC_BUILD_OPTIMIZE)
1145             if (status < 0) {
1146                 GT_setFailureReason(curTrace, GT_4CLASS,
1147                     "VAYUIPUCORE0PROC_detach", status,
1148                     "Failed to disable the slave MMU");
1149             }
1150 #endif
1151         }
1153         /* delete all dynamically added entries */
1154         for (i = 0; i <
1155             AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1156             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1157             ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1158             ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1159             ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1160             ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1161             ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1162             ai->size = 0u;
1163             ai->isCached = FALSE;
1164             ai->mapMask = 0u;
1165             ai->isMapped = FALSE;
1166             ai->refCount = 0u;
1167         }
1168         object->params.numMemEntries = 0;
1169         AddrTable_count[PROCID_TO_IPU(procHandle->procId)] = 0;
1171         //No need to reset.. that will be done in STOP
1172         /*tmpStatus = VAYUIPUCORE0_halResetCtrl(object->halObject,
1173             Processor_ResetCtrlCmd_Reset, NULL);
1175         GT_0trace(curTrace, GT_2CLASS,
1176             "VAYUIPUCORE0PROC_detach: Slave processor is now in reset");*/
1178 #if !defined(IPC_BUILD_OPTIMIZE)
1179         if ((tmpStatus < 0) && (status >= 0)) {
1180             status = tmpStatus;
1181             GT_setFailureReason (curTrace,
1182                                  GT_4CLASS,
1183                                  "VAYUIPUCORE0PROC_detach",
1184                                  status,
1185                                  "Failed to reset the slave processor");
1186         }
1187 #endif
1189         GT_0trace (curTrace,
1190                    GT_2CLASS,
1191                    "    VAYUIPUCORE0PROC_detach: Unmapping memory regions\n");
1193         tmpStatus = VAYUIPU_halExit (object->halObject);
1194 #if !defined(IPC_BUILD_OPTIMIZE)
1195         if ((tmpStatus < 0) && (status >= 0)) {
1196             status = tmpStatus;
1197             GT_setFailureReason (curTrace,
1198                                  GT_4CLASS,
1199                                  "VAYUIPUCORE0PROC_detach",
1200                                  status,
1201                                  "Failed to finalize HAL object");
1202         }
1203     }
1204 #endif
1206     GT_1trace(curTrace, GT_LEAVE,
1207         "VAYUIPUCORE0PROC_detach", status);
1209     /*! @retval PROCESSOR_SUCCESS Operation successful */
1210     return status;
1214 /*!
1215  *  @brief      Function to start the slave processor
1216  *
1217  *              Start the slave processor running from its entry point.
1218  *              Depending on the boot mode, this involves configuring the boot
1219  *              address and releasing the slave from reset.
1220  *
1221  *  @param      handle    Handle to the Processor instance
1222  *
1223  *  @sa         VAYUIPUCORE0PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE0_halResetCtrl
1224  */
1225 Int
1226 VAYUIPUCORE0PROC_start (Processor_Handle        handle,
1227                         UInt32                  entryPt,
1228                         Processor_StartParams * params)
1230     Int                   status        = PROCESSOR_SUCCESS ;
1231     Processor_Object *    procHandle    = (Processor_Object *) handle;
1232     VAYUIPUCORE0PROC_Object * object    = NULL;
1235     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_start",
1236                handle, entryPt, params);
1238     GT_assert (curTrace, (handle != NULL));
1239     GT_assert (curTrace, (params != NULL));
1241 #if !defined(IPC_BUILD_OPTIMIZE)
1242     if (handle == NULL) {
1243         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1244         status = PROCESSOR_E_HANDLE;
1245         GT_setFailureReason (curTrace,
1246                              GT_4CLASS,
1247                              "VAYUIPUCORE0PROC_start",
1248                              status,
1249                              "Invalid handle specified");
1250     }
1251     else if (params == NULL) {
1252             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1253             status = PROCESSOR_E_INVALIDARG;
1254             GT_setFailureReason (curTrace,
1255                                  GT_4CLASS,
1256                                  "VAYUIPUCORE0PROC_start",
1257                                  status,
1258                                  "Invalid params specified");
1259     }
1260     else {
1261 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1262         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1263         GT_assert (curTrace, (object != NULL));
1264         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1265             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1266             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1267             /* Slave is to be started only for Boot mode and NoLoad mode. */
1268             /* Specify the IPU boot address in the boot config register */
1269             status = VAYUIPU_halBootCtrl (object->halObject,
1270                                           Processor_BootCtrlCmd_SetEntryPoint,
1271                                           (Ptr) entryPt);
1272 #if !defined(IPC_BUILD_OPTIMIZE)
1273             if (status < 0) {
1274                 GT_setFailureReason (curTrace,
1275                                      GT_4CLASS,
1276                                      "VAYUIPUCORE0PROC_start",
1277                                      status,
1278                                      "Failed to set slave boot entry point");
1279             }
1280             else {
1281 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1282                 status = rproc_ipu_setup(object->halObject,
1283                                          object->params.memEntries,
1284                                          object->params.numMemEntries);
1285                 if (status < 0) {
1286                     /*! @retval status */
1287                     GT_setFailureReason (curTrace,
1288                                          GT_4CLASS,
1289                                          "VAYUIPUCORE0_halResetCtrl",
1290                                           status,
1291                                          "rproc_ipu_setup failed");
1292                 }
1293                 /* release the slave cpu from reset */
1294                 if (status >= 0) {
1295                     status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1296                                                 Processor_ResetCtrlCmd_Release);
1297 #if !defined(IPC_BUILD_OPTIMIZE)
1298                     if (status < 0) {
1299                         GT_setFailureReason (curTrace,
1300                                           GT_4CLASS,
1301                                           "VAYUIPUCORE0PROC_start",
1302                                           status,
1303                                           "Failed to release slave from reset");
1304                     }
1305 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1306                 }
1307 #if !defined(IPC_BUILD_OPTIMIZE)
1308             }
1309 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1310         }
1312 #if !defined(IPC_BUILD_OPTIMIZE)
1313     }
1314 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1316     if (status >= 0) {
1317         GT_0trace (curTrace,
1318                    GT_1CLASS,
1319                    "    VAYUIPUCORE0PROC_start: Slave successfully started!\n");
1320     }
1321     else {
1322         GT_0trace (curTrace,
1323                    GT_1CLASS,
1324                    "    VAYUIPUCORE0PROC_start: Slave could not be started!\n");
1325     }
1327     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_start", status);
1329     /*! @retval PROCESSOR_SUCCESS Operation successful */
1330     return status;
1334 /*!
1335  *  @brief      Function to stop the slave processor
1336  *
1337  *              Stop the execution of the slave processor. Depending on the boot
1338  *              mode, this may result in placing the slave processor in reset.
1339  *
1340  *  @param      handle    Handle to the Processor instance
1341  *
1342  *  @sa         VAYUIPUCORE0PROC_start, VAYUIPUCORE0_halResetCtrl
1343  */
1344 Int
1345 VAYUIPUCORE0PROC_stop (Processor_Handle handle)
1347     Int                   status       = PROCESSOR_SUCCESS ;
1348     Processor_Object *    procHandle   = (Processor_Object *) handle;
1349     VAYUIPUCORE0PROC_Object * object       = NULL;
1351     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_stop", handle);
1353     GT_assert (curTrace, (handle != NULL));
1355 #if !defined(IPC_BUILD_OPTIMIZE)
1356     if (handle == NULL) {
1357         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1358         status = PROCESSOR_E_HANDLE;
1359         GT_setFailureReason (curTrace,
1360                              GT_4CLASS,
1361                              "VAYUIPUCORE0PROC_stop",
1362                              status,
1363                              "Invalid handle specified");
1364     }
1365     else {
1366 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1367         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1368         GT_assert (curTrace, (object != NULL));
1369         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1370             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1371             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1372             /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1373             /* Place the slave processor in reset. */
1374             status = VAYUIPUCORE0_halResetCtrl (object->halObject,
1375                                               Processor_ResetCtrlCmd_Reset);
1377             GT_0trace (curTrace,
1378                        GT_1CLASS,
1379                        "    VAYUIPUCORE0PROC_stop: Slave is now in reset!\n");
1380 #if !defined(IPC_BUILD_OPTIMIZE)
1381             if (status < 0) {
1382                 GT_setFailureReason (curTrace,
1383                                      GT_4CLASS,
1384                                      "VAYUIPUCORE0PROC_stop",
1385                                      status,
1386                                      "Failed to place slave in reset");
1387             }
1388 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1389             rproc_ipu_destroy(object->halObject);
1390         }
1391 #if !defined(IPC_BUILD_OPTIMIZE)
1392     }
1393 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1394     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_stop", status);
1396     /*! @retval PROCESSOR_SUCCESS Operation successful */
1397     return status;
1401 /*!
1402  *  @brief      Function to read from the slave processor's memory.
1403  *
1404  *              Read from the slave processor's memory and copy into the
1405  *              provided buffer.
1406  *
1407  *  @param      handle     Handle to the Processor instance
1408  *  @param      procAddr   Address in host processor's address space of the
1409  *                         memory region to read from.
1410  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1411  *                         number of bytes to be read. When the function
1412  *                         returns, this parameter contains the number of bytes
1413  *                         actually read.
1414  *  @param      buffer     User-provided buffer in which the slave processor's
1415  *                         memory contents are to be copied.
1416  *
1417  *  @sa         VAYUIPUCORE0PROC_write
1418  */
1419 Int
1420 VAYUIPUCORE0PROC_read (Processor_Handle   handle,
1421                        UInt32             procAddr,
1422                        UInt32 *           numBytes,
1423                        Ptr                buffer)
1425     Int       status   = PROCESSOR_SUCCESS ;
1426     UInt8  *  procPtr8 = NULL;
1428     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_read",
1429                handle, procAddr, numBytes, buffer);
1431     GT_assert (curTrace, (handle   != NULL));
1432     GT_assert (curTrace, (numBytes != NULL));
1433     GT_assert (curTrace, (buffer   != NULL));
1435 #if !defined(IPC_BUILD_OPTIMIZE)
1436     if (handle == NULL) {
1437         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1438         status = PROCESSOR_E_HANDLE;
1439         GT_setFailureReason (curTrace,
1440                              GT_4CLASS,
1441                              "VAYUIPUCORE0PROC_read",
1442                              status,
1443                              "Invalid handle specified");
1444     }
1445     else if (numBytes == 0) {
1446             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1447             status = PROCESSOR_E_INVALIDARG;
1448             GT_setFailureReason (curTrace,
1449                                  GT_4CLASS,
1450                                  "VAYUIPUCORE0PROC_read",
1451                                  status,
1452                                  "Invalid numBytes specified");
1453     }
1454     else if (buffer == NULL) {
1455             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1456             status = PROCESSOR_E_INVALIDARG;
1457             GT_setFailureReason (curTrace,
1458                                  GT_4CLASS,
1459                                  "VAYUIPUCORE0PROC_read",
1460                                  status,
1461                                  "Invalid buffer specified");
1462     }
1463     else {
1464 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1465         procPtr8 = (UInt8 *) procAddr ;
1466         buffer = memcpy (buffer, procPtr8, *numBytes);
1467         GT_assert (curTrace, (buffer != (UInt32) NULL));
1468 #if !defined(IPC_BUILD_OPTIMIZE)
1469         if (buffer == (UInt32) NULL) {
1470             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1471             status = PROCESSOR_E_FAIL;
1472             GT_setFailureReason (curTrace,
1473                                  GT_4CLASS,
1474                                  "VAYUIPUCORE0PROC_read",
1475                                  status,
1476                                  "Failed in memcpy");
1477             *numBytes = 0;
1478         }
1479     }
1480 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1482     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_read",status);
1484     /*! @retval PROCESSOR_SUCCESS Operation successful */
1485     return status;
1489 /*!
1490  *  @brief      Function to write into the slave processor's memory.
1491  *
1492  *              Read from the provided buffer and copy into the slave
1493  *              processor's memory.
1494  *
1495  *  @param      handle     Handle to the Processor object
1496  *  @param      procAddr   Address in host processor's address space of the
1497  *                         memory region to write into.
1498  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1499  *                         number of bytes to be written. When the function
1500  *                         returns, this parameter contains the number of bytes
1501  *                         actually written.
1502  *  @param      buffer     User-provided buffer from which the data is to be
1503  *                         written into the slave processor's memory.
1504  *
1505  *  @sa         VAYUIPUCORE0PROC_read, VAYUIPUCORE0PROC_translateAddr
1506  */
1507 Int
1508 VAYUIPUCORE0PROC_write (Processor_Handle handle,
1509                         UInt32           procAddr,
1510                         UInt32 *         numBytes,
1511                         Ptr              buffer)
1513     Int                   status       = PROCESSOR_SUCCESS ;
1514     UInt8  *              procPtr8     = NULL;
1515     UInt8                 temp8_1;
1516     UInt8                 temp8_2;
1517     UInt8                 temp8_3;
1518     UInt8                 temp8_4;
1519     UInt32                temp;
1521     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_write",
1522                handle, procAddr, numBytes, buffer);
1524     GT_assert (curTrace, (handle   != NULL));
1525     GT_assert (curTrace, (numBytes != NULL));
1526     GT_assert (curTrace, (buffer   != NULL));
1528 #if !defined(IPC_BUILD_OPTIMIZE)
1529     if (handle == NULL) {
1530         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1531         status = PROCESSOR_E_HANDLE;
1532         GT_setFailureReason (curTrace,
1533                              GT_4CLASS,
1534                              "VAYUIPUCORE0PROC_write",
1535                              status,
1536                              "Invalid handle specified");
1537     }
1538     else if (numBytes == 0) {
1539             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1540             status = PROCESSOR_E_INVALIDARG;
1541             GT_setFailureReason (curTrace,
1542                                  GT_4CLASS,
1543                                  "VAYUIPUCORE0PROC_write",
1544                                  status,
1545                                  "Invalid numBytes specified");
1546     }
1547     else if (buffer == NULL) {
1548             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1549             status = PROCESSOR_E_INVALIDARG;
1550             GT_setFailureReason (curTrace,
1551                                  GT_4CLASS,
1552                                  "VAYUIPUCORE0PROC_write",
1553                                  status,
1554                                  "Invalid buffer specified");
1555     }
1556     else {
1557 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1558         if (*numBytes != sizeof (UInt32)) {
1559             procPtr8 = (UInt8 *) procAddr ;
1560             procAddr = (UInt32) Memory_copy (procPtr8,
1561                                              buffer,
1562                                              *numBytes);
1563             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1564 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1565             if (procAddr == (UInt32) NULL) {
1566                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1567                 status = PROCESSOR_E_FAIL;
1568                 GT_setFailureReason (curTrace,
1569                                      GT_4CLASS,
1570                                      "VAYUIPUCORE0PROC_write",
1571                                      status,
1572                                      "Failed in Memory_copy");
1573                 *numBytes = 0;
1574             }
1575 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1576         }
1577         else  {
1578              /* For 4 bytes, directly write as a UInt32 */
1579             temp8_1 = ((UInt8 *) buffer) [0];
1580             temp8_2 = ((UInt8 *) buffer) [1];
1581             temp8_3 = ((UInt8 *) buffer) [2];
1582             temp8_4 = ((UInt8 *) buffer) [3];
1583             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1584                              |   ((UInt32) temp8_3 << 16)
1585                              |   ((UInt32) temp8_2 << 8)
1586                              |   ((UInt32) temp8_1));
1587             *((UInt32*) procAddr) = temp;
1588         }
1589 #if !defined(IPC_BUILD_OPTIMIZE)
1590     }
1591 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1593     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_write", status);
1595     /*! @retval PROCESSOR_SUCCESS Operation successful */
1596     return status;
1600 /*!
1601  *  @brief      Function to perform device-dependent operations.
1602  *
1603  *              Performs device-dependent control operations as exposed by this
1604  *              implementation of the Processor module.
1605  *
1606  *  @param      handle     Handle to the Processor object
1607  *  @param      cmd        Device specific processor command
1608  *  @param      arg        Arguments specific to the type of command.
1609  *
1610  *  @sa
1611  */
1612 Int
1613 VAYUIPUCORE0PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1615     Int                   status       = PROCESSOR_SUCCESS ;
1617     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_control", handle, cmd, arg);
1619     GT_assert (curTrace, (handle   != NULL));
1620     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1622 #if !defined(IPC_BUILD_OPTIMIZE)
1623     if (handle == NULL) {
1624         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1625         status = PROCESSOR_E_HANDLE;
1626         GT_setFailureReason (curTrace,
1627                              GT_4CLASS,
1628                              "VAYUIPUCORE0PROC_control",
1629                              status,
1630                              "Invalid handle specified");
1631     }
1632     else {
1633 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1634         /* No control operations currently implemented. */
1635         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1636                                              for this device. */
1637         status = PROCESSOR_E_NOTSUPPORTED;
1638 #if !defined(IPC_BUILD_OPTIMIZE)
1639     }
1640 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1641     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_control",status);
1643     /*! @retval PROCESSOR_SUCCESS Operation successful */
1644     return status;
1648 /*!
1649  *  @brief      Translate slave virtual address to master physical address.
1650  *
1651  *  @param      handle     Handle to the Processor object
1652  *  @param      dstAddr    Returned: master physical address.
1653  *  @param      srcAddr    Slave virtual address.
1654  *
1655  *  @sa
1656  */
1657 Int
1658 VAYUIPUCORE0PROC_translate(
1659         Processor_Handle    handle,
1660         UInt32 *            dstAddr,
1661         UInt32              srcAddr)
1663     Int                         status = PROCESSOR_SUCCESS;
1664     Processor_Object *          procHandle= (Processor_Object *)handle;
1665     VAYUIPUCORE0PROC_Object *   object = NULL;
1666     UInt32                      i;
1667     UInt32                      startAddr;
1668     UInt32                      endAddr;
1669     UInt32                      offset;
1670     ProcMgr_AddrInfo *          ai;
1672     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1673               handle, dstAddr, srcAddr);
1675     GT_assert (curTrace, (handle  != NULL));
1676     GT_assert (curTrace, (dstAddr != NULL));
1678 #if !defined(IPC_BUILD_OPTIMIZE)
1679     if (handle == NULL) {
1680         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1681         status = PROCESSOR_E_HANDLE;
1682         GT_setFailureReason (curTrace,
1683                              GT_4CLASS,
1684                              "VAYUIPUCORE0PROC_translate",
1685                              status,
1686                              "Invalid handle specified");
1687     }
1688     else if (dstAddr == NULL) {
1689         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1690         status = PROCESSOR_E_INVALIDARG;
1691         GT_setFailureReason (curTrace,
1692                              GT_4CLASS,
1693                              "VAYUIPUCORE0PROC_translate",
1694                              status,
1695                              "dstAddr provided as NULL");
1696     }
1697     else {
1698 #endif
1699         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1700         GT_assert(curTrace, (object != NULL));
1701         *dstAddr = -1u;
1703         /* search all entries AddrTable */
1704         for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1705             i++) {
1706             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1707             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1708             endAddr = startAddr + ai->size;
1710             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1711                 offset = srcAddr - startAddr;
1712                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1713                 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE0PROC_translate: "
1714                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1715                     i, srcAddr, *dstAddr);
1716                 break;
1717             }
1718         }
1720         if (*dstAddr == -1u) {
1721             /* srcAddr not found in slave address space */
1722             status = PROCESSOR_E_INVALIDARG;
1723             GT_setFailureReason(curTrace, GT_4CLASS,
1724                 "VAYUIPUCORE0PROC_translate", status,
1725                 "srcAddr not found in slave address space");
1726         }
1727 #if !defined(IPC_BUILD_OPTIMIZE)
1728     }
1729 #endif
1730     GT_1trace(curTrace, GT_LEAVE,
1731         "VAYUIPUCORE0PROC_translate: status=0x%x", status);
1733     /*! @retval PROCESSOR_SUCCESS Operation successful */
1734     return status;
1737 /*!
1738  *  @brief      Translate slave virtual address to master physical address
1739  *              by inspecting page table entries.
1740  *
1741  *  @param      handle     Handle to the Processor object
1742  *  @param      dstAddr    Returned: master physical address.
1743  *  @param      srcAddr    Slave virtual address.
1744  *
1745  *  @sa
1746  */
1747 Int
1748 VAYUIPUCORE0PROC_translateFromPte(
1749         Processor_Handle    handle,
1750         UInt32 *            dstAddr,
1751         UInt32              srcAddr)
1753     Int                         status = PROCESSOR_SUCCESS;
1754     Processor_Object *          procHandle= (Processor_Object *)handle;
1755     VAYUIPUCORE0PROC_Object *   object = NULL;
1757     GT_3trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_translateFromPte",
1758               handle, dstAddr, srcAddr);
1760     GT_assert (curTrace, (handle  != NULL));
1761     GT_assert (curTrace, (dstAddr != NULL));
1763 #if !defined(IPC_BUILD_OPTIMIZE)
1764     if (handle == NULL) {
1765         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1766         status = PROCESSOR_E_HANDLE;
1767         GT_setFailureReason (curTrace,
1768                              GT_4CLASS,
1769                              "VAYUIPUCORE0PROC_translateFromPte",
1770                              status,
1771                              "Invalid handle specified");
1772     }
1773     else if (dstAddr == NULL) {
1774         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1775         status = PROCESSOR_E_INVALIDARG;
1776         GT_setFailureReason (curTrace,
1777                              GT_4CLASS,
1778                              "VAYUIPUCORE0PROC_translateFromPte",
1779                              status,
1780                              "dstAddr provided as NULL");
1781     }
1782     else {
1783 #endif
1784         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1785         GT_assert(curTrace, (object != NULL));
1786         *dstAddr = -1u;
1788         status = rproc_mem_lookup(object->halObject, srcAddr, dstAddr);
1790         if (status < 0) {
1791             /* srcAddr not found in slave address space */
1792             status = PROCESSOR_E_INVALIDARG;
1793             GT_setFailureReason(curTrace, GT_4CLASS,
1794                 "VAYUIPUCORE0PROC_translateFromPte", status,
1795                 "srcAddr not found in slave address space");
1796         }
1797 #if !defined(IPC_BUILD_OPTIMIZE)
1798     }
1799 #endif
1800     GT_1trace(curTrace, GT_LEAVE,
1801         "VAYUIPUCORE0PROC_translateFromPte: status=0x%x", status);
1803     /*! @retval PROCESSOR_SUCCESS Operation successful */
1804     return status;
1809 /*!
1810  *  @brief      Map the given address translation into the slave mmu
1811  *
1812  *  @param      handle      Handle to the Processor object
1813  *  @param      dstAddr     Base virtual address
1814  *  @param      nSegs       Number of given segments
1815  *  @param      sglist      Segment list
1816  */
1817 Int
1818 VAYUIPUCORE0PROC_map(
1819         Processor_Handle    handle,
1820         UInt32 *            dstAddr,
1821         UInt32              nSegs,
1822         Memory_SGList *     sglist)
1824     Int                         status = PROCESSOR_SUCCESS ;
1825     Processor_Object *          procHandle = (Processor_Object *)handle;
1826     VAYUIPUCORE0PROC_Object *   object = NULL;
1827     Bool                        found = FALSE;
1828     UInt32                      startAddr;
1829     UInt32                      endAddr;
1830     UInt32                      i;
1831     UInt32                      j;
1832     ProcMgr_AddrInfo *          ai = NULL;
1834     GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_map:",
1835         handle, *dstAddr, nSegs, sglist);
1837     GT_assert (curTrace, (handle != NULL));
1838     GT_assert (curTrace, (sglist != NULL));
1839     GT_assert (curTrace, (nSegs > 0));
1841 #if !defined(IPC_BUILD_OPTIMIZE)
1842     if (handle == NULL) {
1843         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1844         status = PROCESSOR_E_HANDLE;
1845         GT_setFailureReason (curTrace,
1846                              GT_4CLASS,
1847                              "VAYUIPUCORE0PROC_map",
1848                              status,
1849                              "Invalid handle specified");
1850     }
1851     else if (sglist == NULL) {
1852         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1853         status = PROCESSOR_E_INVALIDARG;
1854         GT_setFailureReason (curTrace,
1855                              GT_4CLASS,
1856                              "VAYUIPUCORE0PROC_map",
1857                              status,
1858                              "sglist provided as NULL");
1859     }
1860     else if (nSegs == 0) {
1861         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1862         status = PROCESSOR_E_INVALIDARG;
1863         GT_setFailureReason (curTrace,
1864                              GT_4CLASS,
1865                              "VAYUIPUCORE0PROC_map",
1866                              status,
1867                              "Number of segments provided is 0");
1868     }
1869     else {
1870 #endif
1871         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1872         GT_assert (curTrace, (object != NULL));
1874         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1875             /* Update the translation table with entries for which mapping
1876              * is required. Add the entry only if the range does not exist
1877              * in the translation table.
1878              */
1879             for (j = 0;
1880                 j < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; j++) {
1881                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1883                 if (ai->isMapped == TRUE) {
1884                     startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1885                     endAddr = startAddr + ai->size;
1887                     if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1888                         && ((*dstAddr + sglist[i].size) <= endAddr)) {
1889                         found = TRUE;
1890                         ai->refCount++;
1891                         break;
1892                     }
1893                 }
1894             }
1896             /* If not found, add new entry to table. If mmu is disabled,
1897              * the assumption is that the ammu will be used.
1898              */
1899             if (!found) {
1900                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1901                     AddrTable_SIZE) {
1902                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1903                         [AddrTable_count[PROCID_TO_IPU
1904                         (procHandle->procId)]];
1905                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1906                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1907                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1908                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1909                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1910                     ai->size = sglist[i].size;
1911                     ai->isCached = sglist[i].isCached;
1912                     ai->refCount++;
1913                     ai->isMapped = TRUE;
1915                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1916                 }
1917                 else {
1918                     status = PROCESSOR_E_FAIL;
1919                     GT_setFailureReason(curTrace, GT_4CLASS,
1920                         "VAYUIPUCORE0PROC_map", status,
1921                         "AddrTable_SIZE reached!");
1922                 }
1923             }
1924         }
1925 #if !defined(IPC_BUILD_OPTIMIZE)
1926     }
1927 #endif
1928     GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_map", status);
1930     /*! @retval PROCESSOR_SUCCESS Operation successful */
1931     return status;
1935 /*!
1936  *  @brief      Function to unmap slave address from host address space
1937  *
1938  *  @param      handle      Handle to the Processor object
1939  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1940  *                          address.
1941  *  @param      size        Size of the region to be mapped.
1942  *
1943  *  @sa
1944  */
1945 Int
1946 VAYUIPUCORE0PROC_unmap(
1947         Processor_Handle    handle,
1948         UInt32              addr,
1949         UInt32              size)
1951     Int                         status = PROCESSOR_SUCCESS;
1952     Processor_Object *          procHandle = (Processor_Object *)handle;
1953     VAYUIPUCORE0PROC_Object *   object = NULL;
1954     ProcMgr_AddrInfo *          ai;
1955     Int                         i;
1956     UInt32                      startAddr;
1957     UInt32                      endAddr;
1958     VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1960     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_unmap",
1961                handle, addr, size);
1963     GT_assert (curTrace, (handle != NULL));
1964     GT_assert (curTrace, (size   != 0));
1966 #if !defined(IPC_BUILD_OPTIMIZE)
1967     if (handle == NULL) {
1968         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1969         status = PROCESSOR_E_HANDLE;
1970         GT_setFailureReason (curTrace,
1971                              GT_4CLASS,
1972                              "VAYUIPUCORE0PROC_unmap",
1973                              status,
1974                              "Invalid handle specified");
1975     }
1976     else if (size == 0) {
1977         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1978         status = PROCESSOR_E_INVALIDARG;
1979         GT_setFailureReason (curTrace,
1980                              GT_4CLASS,
1981                              "VAYUIPUCORE0PROC_unmap",
1982                              status,
1983                              "Size provided is zero");
1984     }
1985     else {
1986 #endif
1987         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1988         GT_assert (curTrace, (object != NULL));
1990         /* Delete added entries from translation
1991          * table only in last unmap called on that entry
1992          */
1993         for (i = 0;
1994             i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1995             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1997             if (!ai->isMapped) {
1998                 continue;
1999             }
2001             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
2002             endAddr = startAddr + ai->size;
2004             if ((startAddr <= addr) && (addr < endAddr)) {
2005                 ai->refCount--;
2007                 if (ai->refCount == 0) {
2008                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
2009                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
2010                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
2011                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2012                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2013                     ai->size = 0u;
2014                     ai->isCached = FALSE;
2015                     ai->mapMask = 0u;
2016                     ai->isMapped = FALSE;
2018                     /* Remove the entry from the IPUCORE0 MMU also */
2019                     deleteEntryArgs.size          = size;
2020                     deleteEntryArgs.slaveVirtAddr = addr;
2021                     /* TBD: elementSize, endianism, mixedSized are
2022                      * hard coded now, must be configurable later
2023                      */
2024                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2025                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
2026                     deleteEntryArgs.mixedSize     = MMU_TLBES;
2028                     status = VAYUIPU_halMmuCtrl(object->halObject,
2029                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2030 #if !defined(IPC_BUILD_OPTIMIZE)
2031                     if (status < 0) {
2032                         GT_setFailureReason(curTrace, GT_4CLASS,
2033                             "VAYUIPUCORE0PROC_unmap", status,
2034                             "IPUCORE0 MMU configuration failed");
2035                     }
2036 #endif
2037                 }
2038             }
2039         }
2040 #if !defined(IPC_BUILD_OPTIMIZE)
2041     }
2042 #endif
2043     GT_1trace(curTrace, GT_LEAVE,
2044         "VAYUIPUCORE0PROC_unmap", status);
2046     /*! @retval PROCESSOR_SUCCESS Operation successful */
2047     return status;
2051 #if defined (__cplusplus)
2053 #endif /* defined (__cplusplus) */