QNX: IPC: Handle Internal Memory Loading outside of Resource Table
[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-2016, 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)
108 /*!
109  *  @brief  VAYUIPUCORE0PROC Module state object
110  */
111 typedef struct VAYUIPUCORE0PROC_ModuleObject_tag {
112     UInt32                     configSize;
113     /*!< Size of configuration structure */
114     VAYUIPUCORE0PROC_Config    cfg;
115     /*!< VAYUIPUCORE0PROC configuration structure */
116     VAYUIPUCORE0PROC_Config    defCfg;
117     /*!< Default module configuration */
118     VAYUIPUCORE0PROC_Params    defInstParams;
119     /*!< Default parameters for the VAYUIPUCORE0PROC instances */
120     Bool                       isSetup;
121     /*!< Indicates whether the VAYUIPUCORE0PROC module is setup. */
122     VAYUIPUCORE0PROC_Handle    procHandles [MultiProc_MAXPROCESSORS];
123     /*!< Processor handle array. */
124     IGateProvider_Handle       gateHandle;
125     /*!< Handle of gate to be used for local thread safety */
126     UInt16                     ipu1ProcId;
127     /*!< MultiProc id of IPU1 (to avoid multiple lookups) */
128 } VAYUIPUCORE0PROC_ModuleObject;
130 /* Memory region counters */
131 static UInt32 AddrTable_count[NUM_IPUS] = {
132     AddrTable_STATIC_COUNT,
133     AddrTable_STATIC_COUNT,
134 };
136 /*
137  * Address translation tables
138  * CAUTION: AddrTable_STATIC_COUNT must match number of entries below.
139  */
140 static ProcMgr_AddrInfo AddrTable_IPU1[AddrTable_SIZE] =
142     /* L2 RAM */
143     {
144         .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
145         .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
146         .addr[ProcMgr_AddrType_MasterPhys] = 0x58820000u,
147         .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
148         .addr[ProcMgr_AddrType_SlavePhys] = -1u,
149         .size = 0x10000u,
150         .isCached = FALSE,
151         .mapMask = ProcMgr_SLAVEVIRT,
152         .isMapped = TRUE,
153         .refCount = 0u      /* refCount set to 0 for static entry */
154     },
155 };
157 static ProcMgr_AddrInfo AddrTable_IPU2[AddrTable_SIZE] =
159     /* L2 RAM */
160     {
161         .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
162         .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
163         .addr[ProcMgr_AddrType_MasterPhys] = 0x55020000u,
164         .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
165         .addr[ProcMgr_AddrType_SlavePhys] = -1u,
166         .size = 0x10000u,
167         .isCached = FALSE,
168         .mapMask = ProcMgr_SLAVEVIRT,
169         .isMapped = TRUE,
170         .refCount = 0u      /* refCount set to 0 for static entry */
171     },
172 };
174 static ProcMgr_AddrInfo * AddrTable[NUM_IPUS] =
176     AddrTable_IPU1,
177     AddrTable_IPU2
178 };
180 /* =============================================================================
181  *  Globals
182  * =============================================================================
183  */
185 /*!
186  *  @var    VAYUIPUCORE0PROC_state
187  *
188  *  @brief  VAYUIPUCORE0PROC state object variable
189  */
190 #if !defined(IPC_BUILD_DEBUG)
191 static
192 #endif /* if !defined(IPC_BUILD_DEBUG) */
193 VAYUIPUCORE0PROC_ModuleObject VAYUIPUCORE0PROC_state =
195     .isSetup = FALSE,
196     .configSize = sizeof(VAYUIPUCORE0PROC_Config),
197     .gateHandle = NULL,
198     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
199 };
202 /* =============================================================================
203  * APIs directly called by applications
204  * =============================================================================
205  */
206 /*!
207  *  @brief      Function to get the default configuration for the VAYUIPUCORE0PROC
208  *              module.
209  *
210  *              This function can be called by the application to get their
211  *              configuration parameter to VAYUIPUCORE0PROC_setup filled in by the
212  *              VAYUIPUCORE0PROC module with the default parameters. If the user
213  *              does not wish to make any change in the default parameters, this
214  *              API is not required to be called.
215  *
216  *  @param      cfg        Pointer to the VAYUIPUCORE0PROC module configuration
217  *                         structure in which the default config is to be
218  *                         returned.
219  *
220  *  @sa         VAYUIPUCORE0PROC_setup
221  */
222 Void
223 VAYUIPUCORE0PROC_getConfig (VAYUIPUCORE0PROC_Config * cfg)
225     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_getConfig", cfg);
227     GT_assert (curTrace, (cfg != NULL));
229 #if !defined(IPC_BUILD_OPTIMIZE)
230     if (cfg == NULL) {
231         GT_setFailureReason (curTrace,
232                              GT_4CLASS,
233                              "VAYUIPUCORE0PROC_getConfig",
234                              PROCESSOR_E_INVALIDARG,
235                              "Argument of type (VAYUIPUCORE0PROC_Config *) passed "
236                              "is null!");
237     }
238     else {
239 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
240         Memory_copy (cfg,
241                      &(VAYUIPUCORE0PROC_state.defCfg),
242                      sizeof (VAYUIPUCORE0PROC_Config));
243 #if !defined(IPC_BUILD_OPTIMIZE)
244     }
245 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
247     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_getConfig");
251 /*!
252  *  @brief      Function to setup the VAYUIPUCORE0PROC module.
253  *
254  *              This function sets up the VAYUIPUCORE0PROC module. This function
255  *              must be called before any other instance-level APIs can be
256  *              invoked.
257  *              Module-level configuration needs to be provided to this
258  *              function. If the user wishes to change some specific config
259  *              parameters, then VAYUIPUCORE0PROC_getConfig can be called to get the
260  *              configuration filled with the default values. After this, only
261  *              the required configuration values can be changed. If the user
262  *              does not wish to make any change in the default parameters, the
263  *              application can simply call VAYUIPUCORE0PROC_setup with NULL
264  *              parameters. The default parameters would get automatically used.
265  *
266  *  @param      cfg   Optional VAYUIPUCORE0PROC module configuration. If provided as
267  *                    NULL, default configuration is used.
268  *
269  *  @sa         VAYUIPUCORE0PROC_destroy
270  *              GateMutex_create
271  */
272 Int
273 VAYUIPUCORE0PROC_setup (VAYUIPUCORE0PROC_Config * cfg)
275     Int                     status = PROCESSOR_SUCCESS;
276     VAYUIPUCORE0PROC_Config tmpCfg;
277     Error_Block             eb;
279     Error_init(&eb);
281     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_setup", cfg);
283     if (cfg == NULL) {
284         VAYUIPUCORE0PROC_getConfig (&tmpCfg);
285         cfg = &tmpCfg;
286     }
288     /* Create a default gate handle for local module protection. */
289     VAYUIPUCORE0PROC_state.gateHandle = (IGateProvider_Handle)
290                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
291 #if !defined(IPC_BUILD_OPTIMIZE)
292     if (VAYUIPUCORE0PROC_state.gateHandle == NULL) {
293         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
294         status = PROCESSOR_E_FAIL;
295         GT_setFailureReason (curTrace,
296                              GT_4CLASS,
297                              "VAYUIPUCORE0PROC_setup",
298                              status,
299                              "Failed to create GateMutex!");
300     }
301     else {
302 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
303         /* Copy the user provided values into the state object. */
304         Memory_copy (&VAYUIPUCORE0PROC_state.cfg,
305                      cfg,
306                      sizeof (VAYUIPUCORE0PROC_Config));
308         /* Initialize the name to handles mapping array. */
309         Memory_set (&VAYUIPUCORE0PROC_state.procHandles,
310                     0,
311                     (sizeof (VAYUIPUCORE0PROC_Handle) * MultiProc_MAXPROCESSORS));
313         VAYUIPUCORE0PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
314         VAYUIPUCORE0PROC_state.isSetup = TRUE;
315 #if !defined(IPC_BUILD_OPTIMIZE)
316     }
317 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
319     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_setup", status);
321     /*! @retval PROCESSOR_SUCCESS Operation successful */
322     return (status);
326 /*!
327  *  @brief      Function to destroy the VAYUIPUCORE0PROC module.
328  *
329  *              Once this function is called, other VAYUIPUCORE0PROC module APIs,
330  *              except for the VAYUIPUCORE0PROC_getConfig API cannot be called
331  *              anymore.
332  *
333  *  @sa         VAYUIPUCORE0PROC_setup
334  *              GateMutex_delete
335  */
336 Int
337 VAYUIPUCORE0PROC_destroy (Void)
339     Int    status = PROCESSOR_SUCCESS;
340     UInt16 i;
342     GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_destroy");
344     /* Check if any VAYUIPUCORE0PROC instances have not been deleted so far. If not,
345      * delete them.
346      */
347     for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
348         GT_assert (curTrace, (VAYUIPUCORE0PROC_state.procHandles [i] == NULL));
349         if (VAYUIPUCORE0PROC_state.procHandles [i] != NULL) {
350             VAYUIPUCORE0PROC_delete (&(VAYUIPUCORE0PROC_state.procHandles [i]));
351         }
352     }
354     if (VAYUIPUCORE0PROC_state.gateHandle != NULL) {
355         GateMutex_delete ((GateMutex_Handle *)
356                                 &(VAYUIPUCORE0PROC_state.gateHandle));
357     }
359     VAYUIPUCORE0PROC_state.isSetup = FALSE;
361     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_destroy", status);
363     /*! @retval PROCESSOR_SUCCESS Operation successful */
364     return (status);
368 /*!
369  *  @brief      Function to initialize the parameters for this Processor
370  *              instance.
371  *
372  *  @param      params  Configuration parameters to be returned
373  *
374  *  @sa         VAYUIPUCORE0PROC_create
375  */
376 Void
377 VAYUIPUCORE0PROC_Params_init(
378         VAYUIPUCORE0PROC_Handle     handle,
379         VAYUIPUCORE0PROC_Params *   params)
381     VAYUIPUCORE0PROC_Object *procObject = (VAYUIPUCORE0PROC_Object *)handle;
383     GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_Params_init",
384               handle, params);
386     GT_assert(curTrace, (params != NULL));
388 #if !defined(IPC_BUILD_OPTIMIZE)
389     if (params == NULL) {
390         GT_setFailureReason(curTrace, GT_4CLASS,
391                             "VAYUIPUCORE0PROC_Params_init",
392                             PROCESSOR_E_INVALIDARG,
393                             "Argument of type (VAYUIPUCORE0PROC_Params *) "
394                             "passed is null!");
395     }
396     else {
397 #endif
398         if (handle == NULL) {
400             Memory_copy(params, &(VAYUIPUCORE0PROC_state.defInstParams),
401                 sizeof (VAYUIPUCORE0PROC_Params));
402         }
403         else {
404             /* return updated VAYUIPUCORE0PROC instance specific parameters */
405             Memory_copy(params, &(procObject->params),
406                         sizeof(VAYUIPUCORE0PROC_Params));
407         }
408 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
409     }
410 #endif
412     GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_Params_init");
415 /*!
416  *  @brief      Function to create an instance of this Processor.
417  *
418  *  @param      name    Name of the Processor instance.
419  *  @param      params  Configuration parameters.
420  *
421  *  @sa         VAYUIPUCORE0PROC_delete
422  */
423 VAYUIPUCORE0PROC_Handle
424 VAYUIPUCORE0PROC_create (      UInt16                procId,
425                      const VAYUIPUCORE0PROC_Params * params)
427     Int                   status     = PROCESSOR_SUCCESS;
428     Processor_Object *    handle     = NULL;
429     VAYUIPUCORE0PROC_Object * object = NULL;
430     Int i                            = 0;
431     ProcMgr_AddrInfo *ai             = NULL;
432     IArg                  key;
433     List_Params           listParams;
435     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_create", procId, params);
437     GT_assert (curTrace, IS_VALID_PROCID (procId));
438     GT_assert (curTrace, (params != NULL));
440 #if !defined(IPC_BUILD_OPTIMIZE)
441     if (!IS_VALID_PROCID (procId)) {
442         /* Not setting status here since this function does not return status.*/
443         GT_setFailureReason (curTrace,
444                              GT_4CLASS,
445                              "VAYUIPUCORE0PROC_create",
446                              PROCESSOR_E_INVALIDARG,
447                              "Invalid procId specified");
448     }
449     else if (params == NULL) {
450         GT_setFailureReason (curTrace,
451                              GT_4CLASS,
452                              "VAYUIPUCORE0PROC_create",
453                              PROCESSOR_E_INVALIDARG,
454                              "params passed is NULL!");
455     }
456     else {
457 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
458         /* Enter critical section protection. */
459         key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
460 #if !defined(IPC_BUILD_OPTIMIZE)
461         /* Check if the Processor already exists for specified procId. */
462         if (VAYUIPUCORE0PROC_state.procHandles [procId] != NULL) {
463             status = PROCESSOR_E_ALREADYEXIST;
464             GT_setFailureReason (curTrace,
465                               GT_4CLASS,
466                               "VAYUIPUCORE0PROC_create",
467                               status,
468                               "Processor already exists for specified procId!");
469         }
470         else {
471 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
472             /* Allocate memory for the handle */
473             handle = (Processor_Object *) Memory_calloc (NULL,
474                                                       sizeof (Processor_Object),
475                                                       0,
476                                                       NULL);
477             if (handle == NULL) {
478                 GT_setFailureReason (curTrace,
479                                      GT_4CLASS,
480                                      "VAYUIPUCORE0PROC_create",
481                                      PROCESSOR_E_MEMORY,
482                                      "Memory allocation failed for handle!");
483             }
484             else {
485                 /* Populate the handle fields */
486                 handle->procFxnTable.attach        = &VAYUIPUCORE0PROC_attach;
487                 handle->procFxnTable.detach        = &VAYUIPUCORE0PROC_detach;
488                 handle->procFxnTable.start         = &VAYUIPUCORE0PROC_start;
489                 handle->procFxnTable.stop          = &VAYUIPUCORE0PROC_stop;
490                 handle->procFxnTable.read          = &VAYUIPUCORE0PROC_read;
491                 handle->procFxnTable.write         = &VAYUIPUCORE0PROC_write;
492                 handle->procFxnTable.control       = &VAYUIPUCORE0PROC_control;
493                 handle->procFxnTable.map           = &VAYUIPUCORE0PROC_map;
494                 handle->procFxnTable.unmap         = &VAYUIPUCORE0PROC_unmap;
495                 handle->procFxnTable.translateAddr = &VAYUIPUCORE0PROC_translate;
496                 handle->procFxnTable.translateFromPte =
497                     &VAYUIPUCORE0PROC_translateFromPte;
498                 handle->state = ProcMgr_State_Unknown;
500                 /* Allocate memory for the VAYUIPUCORE0PROC handle */
501                 handle->object = Memory_calloc (NULL,
502                                                 sizeof (VAYUIPUCORE0PROC_Object),
503                                                 0,
504                                                 NULL);
505                 if (handle->object == NULL) {
506                     status = PROCESSOR_E_MEMORY;
507                     GT_setFailureReason (curTrace,
508                                 GT_4CLASS,
509                                 "VAYUIPUCORE0PROC_create",
510                                 status,
511                                 "Memory allocation failed for handle->object!");
512                 }
513                 else {
514                     handle->procId = procId;
515                     object = (VAYUIPUCORE0PROC_Object *) handle->object;
516                     object->procHandle = (Processor_Handle)handle;
517                     object->halObject = NULL;
518                     /* Copy params into instance object. */
519                     Memory_copy (&(object->params),
520                                  (Ptr) params,
521                                  sizeof (VAYUIPUCORE0PROC_Params));
523                     /* initialize the translation table */
524                     for (i = AddrTable_count[PROCID_TO_IPU(procId)];
525                         i < AddrTable_SIZE; i++) {
526                         ai = &AddrTable[PROCID_TO_IPU(procId)][i];
527                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
528                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
529                         ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
530                         ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
531                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
532                         ai->size = 0u;
533                         ai->isCached = FALSE;
534                         ai->mapMask = 0u;
535                         ai->isMapped = FALSE;
536                     }
538                     /*
539                      * initialize refCount for all entries
540                      */
541                     for (i = 0; i < AddrTable_SIZE; i++) {
542                         AddrTable[PROCID_TO_IPU(procId)][i].refCount = 0u;
543                     }
544                     Memory_copy((Ptr)(object->params.memEntries),
545                         AddrTable[PROCID_TO_IPU(procId)],
546                         (procId == VAYUIPUCORE0PROC_state.ipu1ProcId ?
547                         sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
549                     /* Set the handle in the state object. */
550                     VAYUIPUCORE0PROC_state.procHandles [procId] =
551                                                  (VAYUIPUCORE0PROC_Handle) object;
552                     /* Initialize the list of listeners */
553                     List_Params_init(&listParams);
554                     handle->registeredNotifiers = List_create(&listParams);
556 #if !defined(IPC_BUILD_OPTIMIZE)
557                     if (handle->registeredNotifiers == NULL) {
558                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
559                         status = PROCESSOR_E_FAIL;
560                         GT_setFailureReason (curTrace,
561                                              GT_4CLASS,
562                                              "VAYUIPUCORE0PROC_create",
563                                              status,
564                                              "List_create failed");
565                     }
566                     else {
567 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
569                         handle->notifiersLock =
570                                  OsalMutex_create(OsalMutex_Type_Interruptible);
572 #if !defined(IPC_BUILD_OPTIMIZE)
573                         if (handle->notifiersLock == NULL) {
574                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
575                             status = PROCESSOR_E_FAIL;
576                             GT_setFailureReason (curTrace,
577                                                  GT_4CLASS,
578                                                  "VAYUIPUCORE0PROC_create",
579                                                  status,
580                                                  "OsalMutex_create failed");
581                         }
582                     }
583 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
584                 }
585             }
586 #if !defined(IPC_BUILD_OPTIMIZE)
587         }
588 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
590         /* Leave critical section protection. */
591         IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
592 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
593     }
594 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
596     if (status < 0) {
597         if (handle !=  NULL) {
598             if (handle->registeredNotifiers != NULL) {
599                 List_delete (&handle->registeredNotifiers);
600             }
601             if (handle->object != NULL) {
602                 Memory_free (NULL,
603                              handle->object,
604                              sizeof (VAYUIPUCORE0PROC_Object));
605             }
606             Memory_free (NULL, handle, sizeof (Processor_Object));
607         }
608         /*! @retval NULL Function failed */
609         handle = NULL;
610     }
612     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_create", handle);
614     /*! @retval Valid-Handle Operation successful */
615     return (VAYUIPUCORE0PROC_Handle) handle;
619 /*!
620  *  @brief      Function to delete an instance of this Processor.
621  *
622  *              The user provided pointer to the handle is reset after
623  *              successful completion of this function.
624  *
625  *  @param      handlePtr  Pointer to Handle to the Processor instance
626  *
627  *  @sa         VAYUIPUCORE0PROC_create
628  */
629 Int
630 VAYUIPUCORE0PROC_delete (VAYUIPUCORE0PROC_Handle * handlePtr)
632     Int                   status = PROCESSOR_SUCCESS;
633     VAYUIPUCORE0PROC_Object * object = NULL;
634     Processor_Object *    handle;
635     IArg                  key;
636     List_Elem *           elem    = NULL;
637     Processor_RegisterElem * regElem = NULL;
639     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_delete", handlePtr);
641     GT_assert (curTrace, (handlePtr != NULL));
642     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
644 #if !defined(IPC_BUILD_OPTIMIZE)
645     if (handlePtr == NULL) {
646         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
647                                          specified*/
648         status = PROCESSOR_E_INVALIDARG;
649         GT_setFailureReason (curTrace,
650                              GT_4CLASS,
651                              "VAYUIPUCORE0PROC_delete",
652                              status,
653                              "Invalid NULL handlePtr pointer specified");
654     }
655     else if (*handlePtr == NULL) {
656         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
657         status = PROCESSOR_E_HANDLE;
658         GT_setFailureReason (curTrace,
659                              GT_4CLASS,
660                              "VAYUIPUCORE0PROC_delete",
661                              status,
662                              "Invalid NULL *handlePtr specified");
663     }
664     else {
665 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
666         handle = (Processor_Object *) (*handlePtr);
667         /* Enter critical section protection. */
668         key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
670         /* Reset handle in PwrMgr handle array. */
671         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
672         VAYUIPUCORE0PROC_state.procHandles [handle->procId] = NULL;
674         /* Free memory used for the VAYUIPUCORE0PROC object. */
675         if (handle->object != NULL) {
676             object = (VAYUIPUCORE0PROC_Object *) handle->object;
677             Memory_free (NULL,
678                          object,
679                          sizeof (VAYUIPUCORE0PROC_Object));
680             handle->object = NULL;
681         }
683         /*
684          * Check the list of listeners to see if any are remaining
685          * and reply to them
686          */
687         OsalMutex_delete(&handle->notifiersLock);
689         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
690             regElem = (Processor_RegisterElem *)elem;
692             /* Check if there is an associated timer and cancel it */
693             if (regElem->timer != -1) {
694                 struct itimerspec value ;
695                 value.it_value.tv_sec = 0;
696                 value.it_value.tv_nsec = 0;
697                 value.it_interval.tv_sec = 0;
698                 value.it_interval.tv_nsec = 0;
699                 timer_settime(regElem->timer, 0, &value, NULL);
701                 timer_delete(regElem->timer);
702                 regElem->timer = -1;
703             }
705             /* Call the callback function so it can clean up. */
706             regElem->info->cbFxn(handle->procId,
707                                  NULL,
708                                  handle->state,
709                                  handle->state,
710                                  ProcMgr_EventStatus_Canceled,
711                                  regElem->info->arg);
712             /* Free the memory */
713             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
714         }
716         /* Delete the list of listeners */
717         List_delete(&handle->registeredNotifiers);
719         /* Free memory used for the Processor object. */
720         Memory_free (NULL, handle, sizeof (Processor_Object));
721         *handlePtr = NULL;
723         /* Leave critical section protection. */
724         IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
725 #if !defined(IPC_BUILD_OPTIMIZE)
726     }
727 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
729     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_delete", status);
731     /*! @retval PROCESSOR_SUCCESS Operation successful */
732     return (status);
736 /*!
737  *  @brief      Function to open a handle to an instance of this Processor. This
738  *              function is called when access to the Processor is required from
739  *              a different process.
740  *
741  *  @param      handlePtr   Handle to the Processor instance
742  *  @param      procId      Processor ID addressed by this Processor instance.
743  *
744  *  @sa         VAYUIPUCORE0PROC_close
745  */
746 Int
747 VAYUIPUCORE0PROC_open (VAYUIPUCORE0PROC_Handle * handlePtr, UInt16 procId)
749     Int status = PROCESSOR_SUCCESS;
751     GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_open", handlePtr, procId);
753     GT_assert (curTrace, (handlePtr != NULL));
754     GT_assert (curTrace, IS_VALID_PROCID (procId));
756 #if !defined(IPC_BUILD_OPTIMIZE)
757     if (handlePtr == NULL) {
758         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
759         status = PROCESSOR_E_HANDLE;
760         GT_setFailureReason (curTrace,
761                              GT_4CLASS,
762                              "VAYUIPUCORE0PROC_open",
763                              status,
764                              "Invalid NULL handlePtr specified");
765     }
766     else if (!IS_VALID_PROCID (procId)) {
767         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
768         status = PROCESSOR_E_INVALIDARG;
769         GT_setFailureReason (curTrace,
770                              GT_4CLASS,
771                              "VAYUIPUCORE0PROC_open",
772                              status,
773                              "Invalid procId specified");
774     }
775     else {
776 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
777         /* Initialize return parameter handle. */
778         *handlePtr = NULL;
780         /* Check if the PwrMgr exists and return the handle if found. */
781         if (VAYUIPUCORE0PROC_state.procHandles [procId] == NULL) {
782             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
783             status = PROCESSOR_E_NOTFOUND;
784             GT_setFailureReason (curTrace,
785                              GT_4CLASS,
786                              "VAYUIPUCORE0PROC_open",
787                              status,
788                              "Specified VAYUIPUCORE0PROC instance does not exist!");
789         }
790         else {
791             *handlePtr = VAYUIPUCORE0PROC_state.procHandles [procId];
792         }
793 #if !defined(IPC_BUILD_OPTIMIZE)
794     }
795 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
797     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_open", status);
799     /*! @retval PROCESSOR_SUCCESS Operation successful */
800     return status;
804 /*!
805  *  @brief      Function to close a handle to an instance of this Processor.
806  *
807  *  @param      handlePtr  Pointer to Handle to the Processor instance
808  *
809  *  @sa         VAYUIPUCORE0PROC_open
810  */
811 Int
812 VAYUIPUCORE0PROC_close (VAYUIPUCORE0PROC_Handle * handlePtr)
814     Int status = PROCESSOR_SUCCESS;
816     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_close", handlePtr);
818     GT_assert (curTrace, (handlePtr != NULL));
819     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
821 #if !defined(IPC_BUILD_OPTIMIZE)
822     if (handlePtr == NULL) {
823         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
824                                          specified*/
825         status = PROCESSOR_E_INVALIDARG;
826         GT_setFailureReason (curTrace,
827                              GT_4CLASS,
828                              "VAYUIPUCORE0PROC_close",
829                              status,
830                              "Invalid NULL handlePtr pointer specified");
831     }
832     else if (*handlePtr == NULL) {
833         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
834         status = PROCESSOR_E_HANDLE;
835         GT_setFailureReason (curTrace,
836                              GT_4CLASS,
837                              "VAYUIPUCORE0PROC_close",
838                              status,
839                              "Invalid NULL *handlePtr specified");
840     }
841     else {
842 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
843         /* Nothing to be done for close. */
844 #if !defined(IPC_BUILD_OPTIMIZE)
845     }
846 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
848     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_close", status);
850     /*! @retval PROCESSOR_SUCCESS Operation successful */
851     return status;
855 /* =============================================================================
856  * APIs called by Processor module (part of function table interface)
857  * =============================================================================
858  */
859 /*!
860  *  @brief      Function to initialize the slave processor
861  *
862  *  @param      handle  Handle to the Processor instance
863  *  @param      params  Attach parameters
864  *
865  *  @sa         VAYUIPUCORE0PROC_detach
866  */
867 Int
868 VAYUIPUCORE0PROC_attach(
869         Processor_Handle            handle,
870         Processor_AttachParams *    params)
873     Int                         status = PROCESSOR_SUCCESS;
874     Processor_Object *          procHandle = (Processor_Object *)handle;
875     VAYUIPUCORE0PROC_Object *   object = NULL;
876     UInt32                      i = 0;
877     UInt32                      index = 0;
878     ProcMgr_AddrInfo *          me;
879     Ipc_MemEntry *              entry;
880     Ipc_MemEntry_Block          memBlock;
881     VAYUIPU_HalMmuCtrlArgs_Enable mmuEnableArgs;
882     VAYUIPU_HalParams           halParams;
884     GT_2trace(curTrace, GT_ENTER,
885               "VAYUIPUCORE0PROC_attach", handle, params);
886     GT_assert (curTrace, (handle != NULL));
887     GT_assert (curTrace, (params != NULL));
889 #if !defined(IPC_BUILD_OPTIMIZE)
890     if (handle == NULL) {
891         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
892         status = PROCESSOR_E_HANDLE;
893         GT_setFailureReason (curTrace,
894                              GT_4CLASS,
895                              "VAYUIPUCORE0PROC_attach",
896                              status,
897                              "Invalid handle specified");
898     }
899     else if (params == NULL) {
900             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
901             status = PROCESSOR_E_INVALIDARG;
902             GT_setFailureReason (curTrace,
903                                  GT_4CLASS,
904                                  "VAYUIPUCORE0PROC_attach",
905                                  status,
906                                  "Invalid params specified");
907     }
908     else {
909 #endif
910         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
911         GT_assert (curTrace, (object != NULL));
913         /* Initialize halObject for Processor_translateFromPte to work */
914         halParams.procId = procHandle->procId;
915         status = VAYUIPU_halInit(&(object->halObject), &halParams);
917         if (status < 0) {
918             GT_setFailureReason(curTrace, GT_4CLASS,
919                 "VAYUIPUCORE0PROC_attach", status,
920                 "VAYUIPU_halInit failed");
921         }
923         /* Added for Netra Benelli core1 is cortex M4 */
924         params->procArch = Processor_ProcArch_M4;
926         object->pmHandle = params->pmHandle;
927         GT_0trace(curTrace, GT_1CLASS,
928             "VAYUIPUCORE0PROC_attach: Mapping memory regions");
930         if (status >= 0) {
931             /* search for dsp memory map */
932             status = RscTable_process(procHandle->procId,
933                                   TRUE,
934                                   &memBlock.numEntries,
935                                   procHandle,
936                                   procHandle->bootMode);
937             if (status < 0 || memBlock.numEntries > IPC_MAX_MEMENTRIES) {
938                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
939                 status = PROCESSOR_E_INVALIDARG;
940                 GT_setFailureReason (curTrace,
941                                  GT_4CLASS,
942                                  "VAYUIPUCORE0PROC_attach",
943                                  status,
944                                  "Failed to process resource table");
945             }
946             else {
947                 status = RscTable_getMemEntries(procHandle->procId,
948                                             memBlock.memEntries,
949                                             &memBlock.numEntries);
950                 if (status < 0) {
951                     /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
952                     status = PROCESSOR_E_INVALIDARG;
953                     GT_setFailureReason (curTrace,
954                                      GT_4CLASS,
955                                      "VAYUIPUCORE0PROC_attach",
956                                      status,
957                                      "Failed to get resource table memEntries");
958                 }
959             }
960         }
962         /* update translation tables with memory map */
963         for (i = 0; (i < memBlock.numEntries)
964             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
966             entry = &memBlock.memEntries[i];
968             if (entry->map == FALSE) {
969                 /* update table with entries which don't require mapping */
970                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
971                    AddrTable_SIZE) {
972                     me = &AddrTable[PROCID_TO_IPU(procHandle->procId)][
973                         AddrTable_count[PROCID_TO_IPU(procHandle->procId)]];
975                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
976                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
977                     me->addr[ProcMgr_AddrType_MasterPhys] =
978                         entry->masterPhysAddr;
979                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
980                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
981                     me->size = entry->size;
982                     me->isCached = entry->isCached;
983                     me->mapMask = entry->mapMask;
985                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
986                 }
987                 else {
988                     status = PROCESSOR_E_FAIL;
989                     GT_setFailureReason(curTrace, GT_4CLASS,
990                         "VAYUIPUCORE0PROC_attach", status,
991                         "AddrTable_SIZE reached!");
992                 }
993             }
994             else if (entry->map == TRUE) {
995                 /* send these entries back to ProcMgr for mapping */
996                 index = object->params.numMemEntries;
998                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
999                     me = &object->params.memEntries[index];
1001                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1002                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1003                     me->addr[ProcMgr_AddrType_MasterPhys] =
1004                         entry->masterPhysAddr;
1005                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1006                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1007                     me->size = entry->size;
1008                     me->isCached = entry->isCached;
1009                     me->mapMask = entry->mapMask;
1011                     object->params.numMemEntries++;
1012                 }
1013                 else {
1014                     status = PROCESSOR_E_FAIL;
1015                     GT_setFailureReason(curTrace, GT_4CLASS,
1016                                         "VAYUIPUCORE0PROC_attach", status,
1017                                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
1018                 }
1019             }
1020             else {
1021                 status = PROCESSOR_E_INVALIDARG;
1022                 GT_setFailureReason(curTrace, GT_4CLASS,
1023                     "VAYUIPUCORE0PROC_attach", status,
1024                     "Memory map has entry with invalid 'map' value");
1025             }
1026         } /* for (...) */
1028         if (status >= 0) {
1029             /* populate the return params */
1030             params->numMemEntries = object->params.numMemEntries;
1031             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1032                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1035             /* Setup the xbar for MMU fault interrupts */
1036             mmuEnableArgs.numMemEntries = 0;
1037             status = VAYUIPU_halMmuCtrl(object->halObject,
1038                 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1040             if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1041                 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1043 #if !defined(IPC_BUILD_OPTIMIZE)
1044                 if (status < 0) {
1045                     GT_setFailureReason(curTrace, GT_4CLASS,
1046                         "VAYUIPUCORE0PROC_attach", status,
1047                         "Failed to enable the slave MMU");
1048                 }
1049                 else {
1050 #endif
1051                     GT_0trace(curTrace, GT_2CLASS,
1052                         "VAYUIPUCORE0PROC_attach: Slave MMU "
1053                         "is configured!");
1055                     /*
1056                      * Pull IPU MMU out of reset to make internal
1057                      * memory "loadable"
1058                      */
1059                     status = VAYUIPUCORE0_halResetCtrl(
1060                         object->halObject,
1061                         Processor_ResetCtrlCmd_MMU_Release);
1062                     if (status < 0) {
1063                         /*! @retval status */
1064                         GT_setFailureReason(curTrace,
1065                             GT_4CLASS,
1066                             "VAYUIPUCORE0_halResetCtrl",
1067                             status,
1068                             "Reset MMU_Release failed");
1069                     }
1070 #if !defined(IPC_BUILD_OPTIMIZE)
1071                 }
1072 #endif
1073             }
1074             else {
1075                 /* NoBoot, late-attach */
1076                 /*
1077                  * Setup MMU fault interrupt now since we won't have a chance
1078                  * to do it in ProcMgr_start
1079                  */
1080                 rproc_enable_fault_interrupt(object->halObject);
1082 #if !defined(IPC_BUILD_OPTIMIZE)
1083                 if (status < 0) {
1084                     GT_setFailureReason(curTrace, GT_4CLASS,
1085                         "VAYUIPUCORE0PROC_attach", status,
1086                         "Failed to enable the slave MMU");
1087                 }
1088                 else {
1089 #endif
1090                     GT_0trace(curTrace, GT_1CLASS,
1091                         "VAYUIPUCORE0PROC_attach: Slave MMU interrupt is "
1092                         "configured");
1093 #if !defined(IPC_BUILD_OPTIMIZE)
1094                 }
1095 #endif
1096             }
1097         }
1098 #if !defined(IPC_BUILD_OPTIMIZE)
1099     }
1100 #endif
1102     GT_1trace(curTrace, GT_LEAVE,
1103         "VAYUIPUCORE0PROC_attach", status);
1105     /*! @retval PROCESSOR_SUCCESS Operation successful */
1106     return status;
1110 /*!
1111  *  @brief      Function to detach from the Processor.
1112  *
1113  *  @param      handle  Handle to the Processor instance
1114  *
1115  *  @sa         VAYUIPUCORE0PROC_attach
1116  */
1117 Int
1118 VAYUIPUCORE0PROC_detach (Processor_Handle handle)
1120     Int                       status     = PROCESSOR_SUCCESS;
1121     Int                       tmpStatus  = PROCESSOR_SUCCESS;
1122     Processor_Object *        procHandle = (Processor_Object *) handle;
1123     VAYUIPUCORE0PROC_Object * object     = NULL;
1124     Int                       i          = 0;
1125     ProcMgr_AddrInfo *        ai;
1127     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_detach", handle);
1128     GT_assert (curTrace, (handle != NULL));
1130 #if !defined(IPC_BUILD_OPTIMIZE)
1131     if (handle == NULL) {
1132         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1133         status = PROCESSOR_E_HANDLE;
1134         GT_setFailureReason (curTrace,
1135                              GT_4CLASS,
1136                              "VAYUIPUCORE0PROC_detach",
1137                              PROCESSOR_E_HANDLE,
1138                              "Invalid handle specified");
1139     }
1140     else {
1141 #endif
1142         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1143         GT_assert (curTrace, (object != NULL));
1145         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1146             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1148             GT_0trace(curTrace, GT_2CLASS,
1149                 "VAYUIPUCORE0PROC_detach: Disabling Slave MMU ...");
1151             status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1152                 Processor_ResetCtrlCmd_MMU_Reset);
1153 #if !defined(IPC_BUILD_OPTIMIZE)
1154             if (status < 0) {
1155                 /*! @retval status */
1156                 GT_setFailureReason (curTrace,
1157                                      GT_4CLASS,
1158                                      "VAYUIPUCORE0_halResetCtrl",
1159                                      status,
1160                                      "Reset MMU failed");
1161             }
1162 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1163         }
1164         else {
1165             status = rproc_disable_fault_interrupt(object->halObject);
1166 #if !defined(IPC_BUILD_OPTIMIZE)
1167             if (status < 0) {
1168                 /*! @retval status */
1169                 GT_setFailureReason (curTrace,
1170                                      GT_4CLASS,
1171                                      "VAYUIPUCORE0PROC_detach",
1172                                      status,
1173                                      "rproc_disable_fault_interrupt failed");
1174             }
1175 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1176         }
1178         if (status >= 0) {
1179              status = VAYUIPU_halMmuCtrl(object->halObject,
1180                                     Processor_MmuCtrlCmd_Disable, NULL);
1181 #if !defined(IPC_BUILD_OPTIMIZE)
1182             if (status < 0) {
1183                 GT_setFailureReason(curTrace, GT_4CLASS,
1184                     "VAYUIPUCORE0PROC_detach", status,
1185                     "Failed to disable the slave MMU");
1186             }
1187 #endif
1188         }
1190         /* delete all dynamically added entries */
1191         for (i = AddrTable_STATIC_COUNT; i <
1192             AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1193             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1194             ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1195             ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1196             ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1197             ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1198             ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1199             ai->size = 0u;
1200             ai->isCached = FALSE;
1201             ai->mapMask = 0u;
1202             ai->isMapped = FALSE;
1203             ai->refCount = 0u;
1204         }
1205         object->params.numMemEntries = AddrTable_STATIC_COUNT;
1206         AddrTable_count[PROCID_TO_IPU(procHandle->procId)] =
1207             AddrTable_STATIC_COUNT;
1209         //No need to reset.. that will be done in STOP
1210         /*tmpStatus = VAYUIPUCORE0_halResetCtrl(object->halObject,
1211             Processor_ResetCtrlCmd_Reset, NULL);
1213         GT_0trace(curTrace, GT_2CLASS,
1214             "VAYUIPUCORE0PROC_detach: Slave processor is now in reset");*/
1216 #if !defined(IPC_BUILD_OPTIMIZE)
1217         if ((tmpStatus < 0) && (status >= 0)) {
1218             status = tmpStatus;
1219             GT_setFailureReason (curTrace,
1220                                  GT_4CLASS,
1221                                  "VAYUIPUCORE0PROC_detach",
1222                                  status,
1223                                  "Failed to reset the slave processor");
1224         }
1225 #endif
1227         GT_0trace (curTrace,
1228                    GT_2CLASS,
1229                    "    VAYUIPUCORE0PROC_detach: Unmapping memory regions\n");
1231         tmpStatus = VAYUIPU_halExit (object->halObject);
1232 #if !defined(IPC_BUILD_OPTIMIZE)
1233         if ((tmpStatus < 0) && (status >= 0)) {
1234             status = tmpStatus;
1235             GT_setFailureReason (curTrace,
1236                                  GT_4CLASS,
1237                                  "VAYUIPUCORE0PROC_detach",
1238                                  status,
1239                                  "Failed to finalize HAL object");
1240         }
1241     }
1242 #endif
1244     GT_1trace(curTrace, GT_LEAVE,
1245         "VAYUIPUCORE0PROC_detach", status);
1247     /*! @retval PROCESSOR_SUCCESS Operation successful */
1248     return status;
1252 /*!
1253  *  @brief      Function to start the slave processor
1254  *
1255  *              Start the slave processor running from its entry point.
1256  *              Depending on the boot mode, this involves configuring the boot
1257  *              address and releasing the slave from reset.
1258  *
1259  *  @param      handle    Handle to the Processor instance
1260  *
1261  *  @sa         VAYUIPUCORE0PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE0_halResetCtrl
1262  */
1263 Int
1264 VAYUIPUCORE0PROC_start (Processor_Handle        handle,
1265                         UInt32                  entryPt,
1266                         Processor_StartParams * params)
1268     Int                   status        = PROCESSOR_SUCCESS ;
1269     Processor_Object *    procHandle    = (Processor_Object *) handle;
1270     VAYUIPUCORE0PROC_Object * object    = NULL;
1273     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_start",
1274                handle, entryPt, params);
1276     GT_assert (curTrace, (handle != NULL));
1277     GT_assert (curTrace, (params != NULL));
1279 #if !defined(IPC_BUILD_OPTIMIZE)
1280     if (handle == NULL) {
1281         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1282         status = PROCESSOR_E_HANDLE;
1283         GT_setFailureReason (curTrace,
1284                              GT_4CLASS,
1285                              "VAYUIPUCORE0PROC_start",
1286                              status,
1287                              "Invalid handle specified");
1288     }
1289     else if (params == NULL) {
1290             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1291             status = PROCESSOR_E_INVALIDARG;
1292             GT_setFailureReason (curTrace,
1293                                  GT_4CLASS,
1294                                  "VAYUIPUCORE0PROC_start",
1295                                  status,
1296                                  "Invalid params specified");
1297     }
1298     else {
1299 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1300         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1301         GT_assert (curTrace, (object != NULL));
1302         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1303             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1304             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1305             /* Slave is to be started only for Boot mode and NoLoad mode. */
1306             /* Specify the IPU boot address in the boot config register */
1307             status = VAYUIPU_halBootCtrl (object->halObject,
1308                                           Processor_BootCtrlCmd_SetEntryPoint,
1309                                           (Ptr) entryPt);
1310 #if !defined(IPC_BUILD_OPTIMIZE)
1311             if (status < 0) {
1312                 GT_setFailureReason (curTrace,
1313                                      GT_4CLASS,
1314                                      "VAYUIPUCORE0PROC_start",
1315                                      status,
1316                                      "Failed to set slave boot entry point");
1317             }
1318             else {
1319 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1320                 status = rproc_ipu_setup(object->halObject,
1321                                          object->params.memEntries,
1322                                          object->params.numMemEntries);
1323                 if (status < 0) {
1324                     /*! @retval status */
1325                     GT_setFailureReason (curTrace,
1326                                          GT_4CLASS,
1327                                          "VAYUIPUCORE0_halResetCtrl",
1328                                           status,
1329                                          "rproc_ipu_setup failed");
1330                 }
1331                 /* release the slave cpu from reset */
1332                 if (status >= 0) {
1333                     status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1334                                                 Processor_ResetCtrlCmd_Release);
1335 #if !defined(IPC_BUILD_OPTIMIZE)
1336                     if (status < 0) {
1337                         GT_setFailureReason (curTrace,
1338                                           GT_4CLASS,
1339                                           "VAYUIPUCORE0PROC_start",
1340                                           status,
1341                                           "Failed to release slave from reset");
1342                     }
1343 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1344                 }
1345 #if !defined(IPC_BUILD_OPTIMIZE)
1346             }
1347 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1348         }
1350 #if !defined(IPC_BUILD_OPTIMIZE)
1351     }
1352 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1354     if (status >= 0) {
1355         GT_0trace (curTrace,
1356                    GT_1CLASS,
1357                    "    VAYUIPUCORE0PROC_start: Slave successfully started!\n");
1358     }
1359     else {
1360         GT_0trace (curTrace,
1361                    GT_1CLASS,
1362                    "    VAYUIPUCORE0PROC_start: Slave could not be started!\n");
1363     }
1365     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_start", status);
1367     /*! @retval PROCESSOR_SUCCESS Operation successful */
1368     return status;
1372 /*!
1373  *  @brief      Function to stop the slave processor
1374  *
1375  *              Stop the execution of the slave processor. Depending on the boot
1376  *              mode, this may result in placing the slave processor in reset.
1377  *
1378  *  @param      handle    Handle to the Processor instance
1379  *
1380  *  @sa         VAYUIPUCORE0PROC_start, VAYUIPUCORE0_halResetCtrl
1381  */
1382 Int
1383 VAYUIPUCORE0PROC_stop (Processor_Handle handle)
1385     Int                   status       = PROCESSOR_SUCCESS ;
1386     Processor_Object *    procHandle   = (Processor_Object *) handle;
1387     VAYUIPUCORE0PROC_Object * object       = NULL;
1389     GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_stop", handle);
1391     GT_assert (curTrace, (handle != NULL));
1393 #if !defined(IPC_BUILD_OPTIMIZE)
1394     if (handle == NULL) {
1395         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1396         status = PROCESSOR_E_HANDLE;
1397         GT_setFailureReason (curTrace,
1398                              GT_4CLASS,
1399                              "VAYUIPUCORE0PROC_stop",
1400                              status,
1401                              "Invalid handle specified");
1402     }
1403     else {
1404 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1405         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1406         GT_assert (curTrace, (object != NULL));
1407         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1408             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1409             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1410             /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1411             /* Place the slave processor in reset. */
1412             status = VAYUIPUCORE0_halResetCtrl (object->halObject,
1413                                               Processor_ResetCtrlCmd_Reset);
1415             GT_0trace (curTrace,
1416                        GT_1CLASS,
1417                        "    VAYUIPUCORE0PROC_stop: Slave is now in reset!\n");
1418 #if !defined(IPC_BUILD_OPTIMIZE)
1419             if (status < 0) {
1420                 GT_setFailureReason (curTrace,
1421                                      GT_4CLASS,
1422                                      "VAYUIPUCORE0PROC_stop",
1423                                      status,
1424                                      "Failed to place slave in reset");
1425             }
1426 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1427             rproc_ipu_destroy(object->halObject);
1428         }
1429 #if !defined(IPC_BUILD_OPTIMIZE)
1430     }
1431 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1432     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_stop", status);
1434     /*! @retval PROCESSOR_SUCCESS Operation successful */
1435     return status;
1439 /*!
1440  *  @brief      Function to read from the slave processor's memory.
1441  *
1442  *              Read from the slave processor's memory and copy into the
1443  *              provided buffer.
1444  *
1445  *  @param      handle     Handle to the Processor instance
1446  *  @param      procAddr   Address in host processor's address space of the
1447  *                         memory region to read from.
1448  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1449  *                         number of bytes to be read. When the function
1450  *                         returns, this parameter contains the number of bytes
1451  *                         actually read.
1452  *  @param      buffer     User-provided buffer in which the slave processor's
1453  *                         memory contents are to be copied.
1454  *
1455  *  @sa         VAYUIPUCORE0PROC_write
1456  */
1457 Int
1458 VAYUIPUCORE0PROC_read (Processor_Handle   handle,
1459                        UInt32             procAddr,
1460                        UInt32 *           numBytes,
1461                        Ptr                buffer)
1463     Int       status   = PROCESSOR_SUCCESS ;
1464     UInt8  *  procPtr8 = NULL;
1466     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_read",
1467                handle, procAddr, numBytes, buffer);
1469     GT_assert (curTrace, (handle   != NULL));
1470     GT_assert (curTrace, (numBytes != NULL));
1471     GT_assert (curTrace, (buffer   != NULL));
1473 #if !defined(IPC_BUILD_OPTIMIZE)
1474     if (handle == NULL) {
1475         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1476         status = PROCESSOR_E_HANDLE;
1477         GT_setFailureReason (curTrace,
1478                              GT_4CLASS,
1479                              "VAYUIPUCORE0PROC_read",
1480                              status,
1481                              "Invalid handle specified");
1482     }
1483     else if (numBytes == 0) {
1484             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1485             status = PROCESSOR_E_INVALIDARG;
1486             GT_setFailureReason (curTrace,
1487                                  GT_4CLASS,
1488                                  "VAYUIPUCORE0PROC_read",
1489                                  status,
1490                                  "Invalid numBytes specified");
1491     }
1492     else if (buffer == NULL) {
1493             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1494             status = PROCESSOR_E_INVALIDARG;
1495             GT_setFailureReason (curTrace,
1496                                  GT_4CLASS,
1497                                  "VAYUIPUCORE0PROC_read",
1498                                  status,
1499                                  "Invalid buffer specified");
1500     }
1501     else {
1502 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1503         procPtr8 = (UInt8 *) procAddr ;
1504         buffer = memcpy (buffer, procPtr8, *numBytes);
1505         GT_assert (curTrace, (buffer != (UInt32) NULL));
1506 #if !defined(IPC_BUILD_OPTIMIZE)
1507         if (buffer == (UInt32) NULL) {
1508             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1509             status = PROCESSOR_E_FAIL;
1510             GT_setFailureReason (curTrace,
1511                                  GT_4CLASS,
1512                                  "VAYUIPUCORE0PROC_read",
1513                                  status,
1514                                  "Failed in memcpy");
1515             *numBytes = 0;
1516         }
1517     }
1518 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1520     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_read",status);
1522     /*! @retval PROCESSOR_SUCCESS Operation successful */
1523     return status;
1527 /*!
1528  *  @brief      Function to write into the slave processor's memory.
1529  *
1530  *              Read from the provided buffer and copy into the slave
1531  *              processor's memory.
1532  *
1533  *  @param      handle     Handle to the Processor object
1534  *  @param      procAddr   Address in host processor's address space of the
1535  *                         memory region to write into.
1536  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1537  *                         number of bytes to be written. When the function
1538  *                         returns, this parameter contains the number of bytes
1539  *                         actually written.
1540  *  @param      buffer     User-provided buffer from which the data is to be
1541  *                         written into the slave processor's memory.
1542  *
1543  *  @sa         VAYUIPUCORE0PROC_read, VAYUIPUCORE0PROC_translateAddr
1544  */
1545 Int
1546 VAYUIPUCORE0PROC_write (Processor_Handle handle,
1547                         UInt32           procAddr,
1548                         UInt32 *         numBytes,
1549                         Ptr              buffer)
1551     Int                   status       = PROCESSOR_SUCCESS ;
1552     UInt8  *              procPtr8     = NULL;
1553     UInt8                 temp8_1;
1554     UInt8                 temp8_2;
1555     UInt8                 temp8_3;
1556     UInt8                 temp8_4;
1557     UInt32                temp;
1559     GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_write",
1560                handle, procAddr, numBytes, buffer);
1562     GT_assert (curTrace, (handle   != NULL));
1563     GT_assert (curTrace, (numBytes != NULL));
1564     GT_assert (curTrace, (buffer   != NULL));
1566 #if !defined(IPC_BUILD_OPTIMIZE)
1567     if (handle == NULL) {
1568         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1569         status = PROCESSOR_E_HANDLE;
1570         GT_setFailureReason (curTrace,
1571                              GT_4CLASS,
1572                              "VAYUIPUCORE0PROC_write",
1573                              status,
1574                              "Invalid handle specified");
1575     }
1576     else if (numBytes == 0) {
1577             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1578             status = PROCESSOR_E_INVALIDARG;
1579             GT_setFailureReason (curTrace,
1580                                  GT_4CLASS,
1581                                  "VAYUIPUCORE0PROC_write",
1582                                  status,
1583                                  "Invalid numBytes specified");
1584     }
1585     else if (buffer == NULL) {
1586             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1587             status = PROCESSOR_E_INVALIDARG;
1588             GT_setFailureReason (curTrace,
1589                                  GT_4CLASS,
1590                                  "VAYUIPUCORE0PROC_write",
1591                                  status,
1592                                  "Invalid buffer specified");
1593     }
1594     else {
1595 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1596         if (*numBytes != sizeof (UInt32)) {
1597             procPtr8 = (UInt8 *) procAddr ;
1598             procAddr = (UInt32) Memory_copy (procPtr8,
1599                                              buffer,
1600                                              *numBytes);
1601             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1602 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1603             if (procAddr == (UInt32) NULL) {
1604                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1605                 status = PROCESSOR_E_FAIL;
1606                 GT_setFailureReason (curTrace,
1607                                      GT_4CLASS,
1608                                      "VAYUIPUCORE0PROC_write",
1609                                      status,
1610                                      "Failed in Memory_copy");
1611                 *numBytes = 0;
1612             }
1613 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1614         }
1615         else  {
1616              /* For 4 bytes, directly write as a UInt32 */
1617             temp8_1 = ((UInt8 *) buffer) [0];
1618             temp8_2 = ((UInt8 *) buffer) [1];
1619             temp8_3 = ((UInt8 *) buffer) [2];
1620             temp8_4 = ((UInt8 *) buffer) [3];
1621             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1622                              |   ((UInt32) temp8_3 << 16)
1623                              |   ((UInt32) temp8_2 << 8)
1624                              |   ((UInt32) temp8_1));
1625             *((UInt32*) procAddr) = temp;
1626         }
1627 #if !defined(IPC_BUILD_OPTIMIZE)
1628     }
1629 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1631     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_write", status);
1633     /*! @retval PROCESSOR_SUCCESS Operation successful */
1634     return status;
1638 /*!
1639  *  @brief      Function to perform device-dependent operations.
1640  *
1641  *              Performs device-dependent control operations as exposed by this
1642  *              implementation of the Processor module.
1643  *
1644  *  @param      handle     Handle to the Processor object
1645  *  @param      cmd        Device specific processor command
1646  *  @param      arg        Arguments specific to the type of command.
1647  *
1648  *  @sa
1649  */
1650 Int
1651 VAYUIPUCORE0PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1653     Int                   status       = PROCESSOR_SUCCESS ;
1655     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_control", handle, cmd, arg);
1657     GT_assert (curTrace, (handle   != NULL));
1658     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1660 #if !defined(IPC_BUILD_OPTIMIZE)
1661     if (handle == NULL) {
1662         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1663         status = PROCESSOR_E_HANDLE;
1664         GT_setFailureReason (curTrace,
1665                              GT_4CLASS,
1666                              "VAYUIPUCORE0PROC_control",
1667                              status,
1668                              "Invalid handle specified");
1669     }
1670     else {
1671 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1672         /* No control operations currently implemented. */
1673         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1674                                              for this device. */
1675         status = PROCESSOR_E_NOTSUPPORTED;
1676 #if !defined(IPC_BUILD_OPTIMIZE)
1677     }
1678 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) */
1679     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_control",status);
1681     /*! @retval PROCESSOR_SUCCESS Operation successful */
1682     return status;
1686 /*!
1687  *  @brief      Translate slave virtual address to master physical address.
1688  *
1689  *  @param      handle     Handle to the Processor object
1690  *  @param      dstAddr    Returned: master physical address.
1691  *  @param      srcAddr    Slave virtual address.
1692  *
1693  *  @sa
1694  */
1695 Int
1696 VAYUIPUCORE0PROC_translate(
1697         Processor_Handle    handle,
1698         UInt32 *            dstAddr,
1699         UInt32              srcAddr)
1701     Int                         status = PROCESSOR_SUCCESS;
1702     Processor_Object *          procHandle= (Processor_Object *)handle;
1703     VAYUIPUCORE0PROC_Object *   object = NULL;
1704     UInt32                      i;
1705     UInt32                      startAddr;
1706     UInt32                      endAddr;
1707     UInt32                      offset;
1708     ProcMgr_AddrInfo *          ai;
1710     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1711               handle, dstAddr, srcAddr);
1713     GT_assert (curTrace, (handle  != NULL));
1714     GT_assert (curTrace, (dstAddr != NULL));
1716 #if !defined(IPC_BUILD_OPTIMIZE)
1717     if (handle == NULL) {
1718         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1719         status = PROCESSOR_E_HANDLE;
1720         GT_setFailureReason (curTrace,
1721                              GT_4CLASS,
1722                              "VAYUIPUCORE0PROC_translate",
1723                              status,
1724                              "Invalid handle specified");
1725     }
1726     else if (dstAddr == NULL) {
1727         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1728         status = PROCESSOR_E_INVALIDARG;
1729         GT_setFailureReason (curTrace,
1730                              GT_4CLASS,
1731                              "VAYUIPUCORE0PROC_translate",
1732                              status,
1733                              "dstAddr provided as NULL");
1734     }
1735     else {
1736 #endif
1737         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1738         GT_assert(curTrace, (object != NULL));
1739         *dstAddr = -1u;
1741         /* search all entries AddrTable */
1742         for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1743             i++) {
1744             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1745             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1746             endAddr = startAddr + ai->size;
1748             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1749                 offset = srcAddr - startAddr;
1750                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1751                 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE0PROC_translate: "
1752                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1753                     i, srcAddr, *dstAddr);
1754                 break;
1755             }
1756         }
1758         if (*dstAddr == -1u) {
1759             /* srcAddr not found in slave address space */
1760             status = PROCESSOR_E_INVALIDARG;
1761             GT_setFailureReason(curTrace, GT_4CLASS,
1762                 "VAYUIPUCORE0PROC_translate", status,
1763                 "srcAddr not found in slave address space");
1764         }
1765 #if !defined(IPC_BUILD_OPTIMIZE)
1766     }
1767 #endif
1768     GT_1trace(curTrace, GT_LEAVE,
1769         "VAYUIPUCORE0PROC_translate: status=0x%x", status);
1771     /*! @retval PROCESSOR_SUCCESS Operation successful */
1772     return status;
1775 /*!
1776  *  @brief      Translate slave virtual address to master physical address
1777  *              by inspecting page table entries.
1778  *
1779  *  @param      handle     Handle to the Processor object
1780  *  @param      dstAddr    Returned: master physical address.
1781  *  @param      srcAddr    Slave virtual address.
1782  *
1783  *  @sa
1784  */
1785 Int
1786 VAYUIPUCORE0PROC_translateFromPte(
1787         Processor_Handle    handle,
1788         UInt32 *            dstAddr,
1789         UInt32              srcAddr)
1791     Int                         status = PROCESSOR_SUCCESS;
1792     Processor_Object *          procHandle= (Processor_Object *)handle;
1793     VAYUIPUCORE0PROC_Object *   object = NULL;
1795     GT_3trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_translateFromPte",
1796               handle, dstAddr, srcAddr);
1798     GT_assert (curTrace, (handle  != NULL));
1799     GT_assert (curTrace, (dstAddr != NULL));
1801 #if !defined(IPC_BUILD_OPTIMIZE)
1802     if (handle == NULL) {
1803         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1804         status = PROCESSOR_E_HANDLE;
1805         GT_setFailureReason (curTrace,
1806                              GT_4CLASS,
1807                              "VAYUIPUCORE0PROC_translateFromPte",
1808                              status,
1809                              "Invalid handle specified");
1810     }
1811     else if (dstAddr == NULL) {
1812         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1813         status = PROCESSOR_E_INVALIDARG;
1814         GT_setFailureReason (curTrace,
1815                              GT_4CLASS,
1816                              "VAYUIPUCORE0PROC_translateFromPte",
1817                              status,
1818                              "dstAddr provided as NULL");
1819     }
1820     else {
1821 #endif
1822         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1823         GT_assert(curTrace, (object != NULL));
1824         *dstAddr = -1u;
1826         status = rproc_mem_lookup(object->halObject, srcAddr, dstAddr);
1828         if (status < 0) {
1829             /* srcAddr not found in slave address space */
1830             status = PROCESSOR_E_INVALIDARG;
1831             GT_setFailureReason(curTrace, GT_4CLASS,
1832                 "VAYUIPUCORE0PROC_translateFromPte", status,
1833                 "srcAddr not found in slave address space");
1834         }
1835 #if !defined(IPC_BUILD_OPTIMIZE)
1836     }
1837 #endif
1838     GT_1trace(curTrace, GT_LEAVE,
1839         "VAYUIPUCORE0PROC_translateFromPte: status=0x%x", status);
1841     /*! @retval PROCESSOR_SUCCESS Operation successful */
1842     return status;
1847 /*!
1848  *  @brief      Map the given address translation into the slave mmu
1849  *
1850  *  @param      handle      Handle to the Processor object
1851  *  @param      dstAddr     Base virtual address
1852  *  @param      nSegs       Number of given segments
1853  *  @param      sglist      Segment list
1854  */
1855 Int
1856 VAYUIPUCORE0PROC_map(
1857         Processor_Handle    handle,
1858         UInt32 *            dstAddr,
1859         UInt32              nSegs,
1860         Memory_SGList *     sglist)
1862     Int                         status = PROCESSOR_SUCCESS ;
1863     Processor_Object *          procHandle = (Processor_Object *)handle;
1864     VAYUIPUCORE0PROC_Object *   object = NULL;
1865     Bool                        found = FALSE;
1866     UInt32                      startAddr;
1867     UInt32                      endAddr;
1868     UInt32                      i;
1869     UInt32                      j;
1870     ProcMgr_AddrInfo *          ai = NULL;
1872     GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_map:",
1873         handle, *dstAddr, nSegs, sglist);
1875     GT_assert (curTrace, (handle != NULL));
1876     GT_assert (curTrace, (sglist != NULL));
1877     GT_assert (curTrace, (nSegs > 0));
1879 #if !defined(IPC_BUILD_OPTIMIZE)
1880     if (handle == NULL) {
1881         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1882         status = PROCESSOR_E_HANDLE;
1883         GT_setFailureReason (curTrace,
1884                              GT_4CLASS,
1885                              "VAYUIPUCORE0PROC_map",
1886                              status,
1887                              "Invalid handle specified");
1888     }
1889     else if (sglist == NULL) {
1890         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1891         status = PROCESSOR_E_INVALIDARG;
1892         GT_setFailureReason (curTrace,
1893                              GT_4CLASS,
1894                              "VAYUIPUCORE0PROC_map",
1895                              status,
1896                              "sglist provided as NULL");
1897     }
1898     else if (nSegs == 0) {
1899         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1900         status = PROCESSOR_E_INVALIDARG;
1901         GT_setFailureReason (curTrace,
1902                              GT_4CLASS,
1903                              "VAYUIPUCORE0PROC_map",
1904                              status,
1905                              "Number of segments provided is 0");
1906     }
1907     else {
1908 #endif
1909         object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1910         GT_assert (curTrace, (object != NULL));
1912         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1913             /* Update the translation table with entries for which mapping
1914              * is required. Add the entry only if the range does not exist
1915              * in the translation table.
1916              */
1917             /* check in static entries first */
1918             for (j = 0; j < AddrTable_STATIC_COUNT; j++) {
1919                 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1920                 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1921                 endAddr = startAddr + ai->size;
1923                 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)) {
1924                     found = TRUE;
1925                     /* refCount does not need to be incremented for static entries */
1926                     break;
1927                 }
1928             }
1930             /* if not found in static entries, check in dynamic entries */
1931             if (!found) {
1932                 for (j = AddrTable_STATIC_COUNT;
1933                     j < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; j++) {
1934                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1936                     if (ai->isMapped == TRUE) {
1937                         startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1938                         endAddr = startAddr + ai->size;
1940                         if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1941                             && ((*dstAddr + sglist[i].size) <= endAddr)) {
1942                             found = TRUE;
1943                             ai->refCount++;
1944                             break;
1945                         }
1946                     }
1947                 }
1948             }
1950             /* If not found, add new entry to table. If mmu is disabled,
1951              * the assumption is that the ammu will be used.
1952              */
1953             if (!found) {
1954                 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1955                     AddrTable_SIZE) {
1956                     ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1957                         [AddrTable_count[PROCID_TO_IPU
1958                         (procHandle->procId)]];
1959                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1960                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1961                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1962                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1963                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1964                     ai->size = sglist[i].size;
1965                     ai->isCached = sglist[i].isCached;
1966                     ai->refCount++;
1967                     ai->isMapped = TRUE;
1969                     AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1970                 }
1971                 else {
1972                     status = PROCESSOR_E_FAIL;
1973                     GT_setFailureReason(curTrace, GT_4CLASS,
1974                         "VAYUIPUCORE0PROC_map", status,
1975                         "AddrTable_SIZE reached!");
1976                 }
1977             }
1978         }
1979 #if !defined(IPC_BUILD_OPTIMIZE)
1980     }
1981 #endif
1982     GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_map", status);
1984     /*! @retval PROCESSOR_SUCCESS Operation successful */
1985     return status;
1989 /*!
1990  *  @brief      Function to unmap slave address from host address space
1991  *
1992  *  @param      handle      Handle to the Processor object
1993  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1994  *                          address.
1995  *  @param      size        Size of the region to be mapped.
1996  *
1997  *  @sa
1998  */
1999 Int
2000 VAYUIPUCORE0PROC_unmap(
2001         Processor_Handle    handle,
2002         UInt32              addr,
2003         UInt32              size)
2005     Int                         status = PROCESSOR_SUCCESS;
2006     Processor_Object *          procHandle = (Processor_Object *)handle;
2007     VAYUIPUCORE0PROC_Object *   object = NULL;
2008     ProcMgr_AddrInfo *          ai;
2009     Int                         i;
2010     UInt32                      startAddr;
2011     UInt32                      endAddr;
2012     VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
2014     GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_unmap",
2015                handle, addr, size);
2017     GT_assert (curTrace, (handle != NULL));
2018     GT_assert (curTrace, (size   != 0));
2020 #if !defined(IPC_BUILD_OPTIMIZE)
2021     if (handle == NULL) {
2022         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
2023         status = PROCESSOR_E_HANDLE;
2024         GT_setFailureReason (curTrace,
2025                              GT_4CLASS,
2026                              "VAYUIPUCORE0PROC_unmap",
2027                              status,
2028                              "Invalid handle specified");
2029     }
2030     else if (size == 0) {
2031         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
2032         status = PROCESSOR_E_INVALIDARG;
2033         GT_setFailureReason (curTrace,
2034                              GT_4CLASS,
2035                              "VAYUIPUCORE0PROC_unmap",
2036                              status,
2037                              "Size provided is zero");
2038     }
2039     else {
2040 #endif
2041         object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
2042         GT_assert (curTrace, (object != NULL));
2044         /* Delete added entries from translation
2045          * table only in last unmap called on that entry
2046          */
2047         for (i = AddrTable_STATIC_COUNT;
2048             i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
2049             ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
2051             if (!ai->isMapped) {
2052                 continue;
2053             }
2055             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
2056             endAddr = startAddr + ai->size;
2058             if ((startAddr <= addr) && (addr < endAddr)) {
2059                 ai->refCount--;
2061                 if (ai->refCount == 0) {
2062                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
2063                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
2064                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
2065                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2066                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2067                     ai->size = 0u;
2068                     ai->isCached = FALSE;
2069                     ai->mapMask = 0u;
2070                     ai->isMapped = FALSE;
2072                     /* Remove the entry from the IPUCORE0 MMU also */
2073                     deleteEntryArgs.size          = size;
2074                     deleteEntryArgs.slaveVirtAddr = addr;
2075                     /* TBD: elementSize, endianism, mixedSized are
2076                      * hard coded now, must be configurable later
2077                      */
2078                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2079                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
2080                     deleteEntryArgs.mixedSize     = MMU_TLBES;
2082                     status = VAYUIPU_halMmuCtrl(object->halObject,
2083                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2084 #if !defined(IPC_BUILD_OPTIMIZE)
2085                     if (status < 0) {
2086                         GT_setFailureReason(curTrace, GT_4CLASS,
2087                             "VAYUIPUCORE0PROC_unmap", status,
2088                             "IPUCORE0 MMU configuration failed");
2089                     }
2090 #endif
2091                 }
2092             }
2093         }
2094 #if !defined(IPC_BUILD_OPTIMIZE)
2095     }
2096 #endif
2097     GT_1trace(curTrace, GT_LEAVE,
2098         "VAYUIPUCORE0PROC_unmap", status);
2100     /*! @retval PROCESSOR_SUCCESS Operation successful */
2101     return status;
2105 #if defined (__cplusplus)
2107 #endif /* defined (__cplusplus) */