Add INTMEM resource type support in QNX
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayudsp / VAYUDspProc.c
1 /*
2  *  @file   VAYUDspProc.c
3  *
4  * @brief       Processor implementation for VAYUDSP.
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 VAYUDSP.
10  *
11  *
12  *  ============================================================================
13  *
14  *  Copyright (c) 2013-2014, Texas Instruments Incorporated
15  *
16  *  Redistribution and use in source and binary forms, with or without
17  *  modification, are permitted provided that the following conditions
18  *  are met:
19  *
20  *  *  Redistributions of source code must retain the above copyright
21  *     notice, this list of conditions and the following disclaimer.
22  *
23  *  *  Redistributions in binary form must reproduce the above copyright
24  *     notice, this list of conditions and the following disclaimer in the
25  *     documentation and/or other materials provided with the distribution.
26  *
27  *  *  Neither the name of Texas Instruments Incorporated nor the names of
28  *     its contributors may be used to endorse or promote products derived
29  *     from this software without specific prior written permission.
30  *
31  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *  Contact information for paper mail:
43  *  Texas Instruments
44  *  Post Office Box 655303
45  *  Dallas, Texas 75265
46  *  Contact information:
47  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
48  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
49  *  ============================================================================
50  *
51  */
55 #include <ti/syslink/Std.h>
56 /* OSAL & Utils headers */
57 #include <ti/syslink/utils/Cfg.h>
58 #include <ti/syslink/utils/String.h>
59 #include <ti/syslink/utils/IGateProvider.h>
60 #include <ti/syslink/utils/GateMutex.h>
61 #include <ti/syslink/utils/Memory.h>
63 #include <string.h>
65 #include <ti/syslink/utils/Trace.h>
66 /* Module level headers */
67 #include <ProcDefs.h>
68 #include <Processor.h>
69 #include <VAYUDspProc.h>
70 #include <_VAYUDspProc.h>
71 #include <VAYUDspHal.h>
72 #include <VAYUDspHalReset.h>
73 #include <VAYUDspHalBoot.h>
74 #include <VAYUDspEnabler.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  */
91 /*!
92  *  @brief  Max entries in address translation table.
93  */
94 #define AddrTable_SIZE 32
97 /*!
98  *  @brief  VAYUDSPPROC Module state object
99  */
100 typedef struct VAYUDSPPROC_ModuleObject_tag {
101     UInt32              configSize;
102     /*!< Size of configuration structure */
103     VAYUDSPPROC_Config cfg;
104     /*!< VAYUDSPPROC configuration structure */
105     VAYUDSPPROC_Config defCfg;
106     /*!< Default module configuration */
107     VAYUDSPPROC_Params      defInstParams;
108     /*!< Default parameters for the VAYUDSPPROC instances */
109     Bool                isSetup;
110     /*!< Indicates whether the VAYUDSPPROC module is setup. */
111     VAYUDSPPROC_Handle procHandles [MultiProc_MAXPROCESSORS];
112     /*!< Processor handle array. */
113     IGateProvider_Handle         gateHandle;
114     /*!< Handle of gate to be used for local thread safety */
115 } VAYUDSPPROC_ModuleObject;
117 /* Default memory regions */
118 static UInt32 AddrTable_count = 0;
120 /*
121  * Address translation table
122  */
123 static ProcMgr_AddrInfo AddrTable[AddrTable_SIZE];
125 /* =============================================================================
126  *  Globals
127  * =============================================================================
128  */
130 /*!
131  *  @var    VAYUDSPPROC_state
132  *
133  *  @brief  VAYUDSPPROC state object variable
134  */
135 #if !defined(SYSLINK_BUILD_DEBUG)
136 static
137 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
138 VAYUDSPPROC_ModuleObject VAYUDSPPROC_state =
140     .isSetup = FALSE,
141     .configSize = sizeof(VAYUDSPPROC_Config),
142     .gateHandle = NULL,
143     .defInstParams.numMemEntries = 0
144 };
146 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
147 extern String ProcMgr_sysLinkCfgParams;
149 /* =============================================================================
150  * APIs directly called by applications
151  * =============================================================================
152  */
153 /*!
154  *  @brief      Function to get the default configuration for the VAYUDSPPROC
155  *              module.
156  *
157  *              This function can be called by the application to get their
158  *              configuration parameter to VAYUDSPPROC_setup filled in by the
159  *              VAYUDSPPROC module with the default parameters. If the user
160  *              does not wish to make any change in the default parameters, this
161  *              API is not required to be called.
162  *
163  *  @param      cfg        Pointer to the VAYUDSPPROC module configuration
164  *                         structure in which the default config is to be
165  *                         returned.
166  *
167  *  @sa         VAYUDSPPROC_setup
168  */
169 Void
170 VAYUDSPPROC_getConfig (VAYUDSPPROC_Config * cfg)
172     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_getConfig", cfg);
174     GT_assert (curTrace, (cfg != NULL));
176 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
177     if (cfg == NULL) {
178         GT_setFailureReason (curTrace,
179                              GT_4CLASS,
180                              "VAYUDSPPROC_getConfig",
181                              PROCESSOR_E_INVALIDARG,
182                              "Argument of type (VAYUDSPPROC_Config *) passed "
183                              "is null!");
184     }
185     else {
186 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
187         Memory_copy (cfg,
188                      &(VAYUDSPPROC_state.defCfg),
189                      sizeof (VAYUDSPPROC_Config));
190 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
191     }
192 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
194     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_getConfig");
198 /*!
199  *  @brief      Function to setup the VAYUDSPPROC module.
200  *
201  *              This function sets up the VAYUDSPPROC module. This function
202  *              must be called before any other instance-level APIs can be
203  *              invoked.
204  *              Module-level configuration needs to be provided to this
205  *              function. If the user wishes to change some specific config
206  *              parameters, then VAYUDSPPROC_getConfig can be called to get the
207  *              configuration filled with the default values. After this, only
208  *              the required configuration values can be changed. If the user
209  *              does not wish to make any change in the default parameters, the
210  *              application can simply call VAYUDSPPROC_setup with NULL
211  *              parameters. The default parameters would get automatically used.
212  *
213  *  @param      cfg   Optional VAYUDSPPROC module configuration. If provided as
214  *                    NULL, default configuration is used.
215  *
216  *  @sa         VAYUDSPPROC_destroy
217  *              GateMutex_create
218  */
219 Int
220 VAYUDSPPROC_setup (VAYUDSPPROC_Config * cfg)
222     Int                  status = PROCESSOR_SUCCESS;
223     VAYUDSPPROC_Config   tmpCfg;
224     Error_Block          eb;
226     Error_init(&eb);
228     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_setup", cfg);
230     if (cfg == NULL) {
231         VAYUDSPPROC_getConfig (&tmpCfg);
232         cfg = &tmpCfg;
233     }
235     /* Create a default gate handle for local module protection. */
236     VAYUDSPPROC_state.gateHandle = (IGateProvider_Handle)
237                                GateMutex_create ((GateMutex_Params *)NULL, &eb);
238 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
239     if (VAYUDSPPROC_state.gateHandle == NULL) {
240         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
241         status = PROCESSOR_E_FAIL;
242         GT_setFailureReason (curTrace,
243                              GT_4CLASS,
244                              "VAYUDSPPROC_setup",
245                              status,
246                              "Failed to create GateMutex!");
247     }
248     else {
249 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
250         /* Copy the user provided values into the state object. */
251         Memory_copy (&VAYUDSPPROC_state.cfg,
252                      cfg,
253                      sizeof (VAYUDSPPROC_Config));
255         /* Initialize the name to handles mapping array. */
256         Memory_set (&VAYUDSPPROC_state.procHandles,
257                     0,
258                     (sizeof (VAYUDSPPROC_Handle) * MultiProc_MAXPROCESSORS));
259         VAYUDSPPROC_state.isSetup = TRUE;
260 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
261     }
262 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
264     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_setup", status);
266     /*! @retval PROCESSOR_SUCCESS Operation successful */
267     return (status);
271 /*!
272  *  @brief      Function to destroy the VAYUDSPPROC module.
273  *
274  *              Once this function is called, other VAYUDSPPROC module APIs,
275  *              except for the VAYUDSPPROC_getConfig API cannot be called
276  *              anymore.
277  *
278  *  @sa         VAYUDSPPROC_setup
279  *              GateMutex_delete
280  */
281 Int
282 VAYUDSPPROC_destroy (Void)
284     Int    status = PROCESSOR_SUCCESS;
285     UInt16 i;
287     GT_0trace (curTrace, GT_ENTER, "VAYUDSPPROC_destroy");
289     /* Check if any VAYUDSPPROC instances have not been deleted so far. If not,
290      * delete them.
291      */
292     for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
293         GT_assert (curTrace, (VAYUDSPPROC_state.procHandles [i] == NULL));
294         if (VAYUDSPPROC_state.procHandles [i] != NULL) {
295             VAYUDSPPROC_delete (&(VAYUDSPPROC_state.procHandles [i]));
296         }
297     }
299     if (VAYUDSPPROC_state.gateHandle != NULL) {
300         GateMutex_delete ((GateMutex_Handle *)
301                                 &(VAYUDSPPROC_state.gateHandle));
302     }
304     VAYUDSPPROC_state.isSetup = FALSE;
306     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_destroy", status);
308     /*! @retval PROCESSOR_SUCCESS Operation successful */
309     return (status);
313 /*!
314  *  @brief      Function to initialize the parameters for this Processor
315  *              instance.
316  *
317  *  @param      params  Configuration parameters to be returned
318  *
319  *  @sa         VAYUDSPPROC_create
320  */
321 Void
322 VAYUDSPPROC_Params_init(
323         VAYUDSPPROC_Handle    handle,
324         VAYUDSPPROC_Params *  params)
326     VAYUDSPPROC_Object * procObject = (VAYUDSPPROC_Object *) handle;
327     Int                    i          = 0;
328     ProcMgr_AddrInfo *     ai         = NULL;
330     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_Params_init", handle, params);
332     GT_assert (curTrace, (params != NULL));
334 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
335     if (params == NULL) {
336         GT_setFailureReason (curTrace,
337                              GT_4CLASS,
338                              "VAYUDSPPROC_Params_init",
339                              PROCESSOR_E_INVALIDARG,
340                              "Argument of type (VAYUDSPPROC_Params *) "
341                              "passed is null!");
342     }
343     else {
344 #endif
345         if (handle == NULL) {
347             Memory_copy(params, &(VAYUDSPPROC_state.defInstParams),
348                 sizeof(VAYUDSPPROC_Params));
350             /* initialize the translation table */
351             for (i = AddrTable_count; i < AddrTable_SIZE; i++) {
352                 ai = &AddrTable[i];
353                 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
354                 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
355                 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
356                 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
357                 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
358                 ai->size = 0u;
359                 ai->isCached = FALSE;
360                 ai->mapMask = 0u;
361                 ai->isMapped = FALSE;
362             }
364             /* initialize refCount for all entries */
365             for(i = 0; i < AddrTable_SIZE; i++) {
366                 AddrTable[i].refCount = 0u;
367             }
368             Memory_copy((Ptr)params->memEntries, AddrTable, sizeof(AddrTable));
369         }
370         else {
371             /* return updated VAYUDSPPROC instance specific parameters */
372             Memory_copy(params, &(procObject->params), sizeof(VAYUDSPPROC_Params));
373         }
374 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
375     }
376 #endif
378     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_Params_init");
381 /*!
382  *  @brief      Function to create an instance of this Processor.
383  *
384  *  @param      name    Name of the Processor instance.
385  *  @param      params  Configuration parameters.
386  *
387  *  @sa         VAYUDSPPROC_delete
388  */
389 VAYUDSPPROC_Handle
390 VAYUDSPPROC_create (      UInt16                procId,
391                      const VAYUDSPPROC_Params * params)
393     Int                   status    = PROCESSOR_SUCCESS;
394     Processor_Object *    handle    = NULL;
395     VAYUDSPPROC_Object *  object    = NULL;
396     IArg                  key;
397     List_Params           listParams;
399     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_create", procId, params);
401     GT_assert (curTrace, IS_VALID_PROCID (procId));
402     GT_assert (curTrace, (params != NULL));
404 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
405     if (!IS_VALID_PROCID (procId)) {
406         /* Not setting status here since this function does not return status.*/
407         GT_setFailureReason (curTrace,
408                              GT_4CLASS,
409                              "VAYUDSPPROC_create",
410                              PROCESSOR_E_INVALIDARG,
411                              "Invalid procId specified");
412     }
413     else if (params == NULL) {
414         GT_setFailureReason (curTrace,
415                              GT_4CLASS,
416                              "VAYUDSPPROC_create",
417                              PROCESSOR_E_INVALIDARG,
418                              "params passed is NULL!");
419     }
420     else {
421 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
422         /* Enter critical section protection. */
423         key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
424 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
425         /* Check if the Processor already exists for specified procId. */
426         if (VAYUDSPPROC_state.procHandles [procId] != NULL) {
427             status = PROCESSOR_E_ALREADYEXIST;
428             GT_setFailureReason (curTrace,
429                               GT_4CLASS,
430                               "VAYUDSPPROC_create",
431                               status,
432                               "Processor already exists for specified procId!");
433         }
434         else {
435 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
436             /* Allocate memory for the handle */
437             handle = (Processor_Object *) Memory_calloc (NULL,
438                                                       sizeof (Processor_Object),
439                                                       0,
440                                                       NULL);
441             if (handle == NULL) {
442                 GT_setFailureReason (curTrace,
443                                      GT_4CLASS,
444                                      "VAYUDSPPROC_create",
445                                      PROCESSOR_E_MEMORY,
446                                      "Memory allocation failed for handle!");
447             }
448             else {
449                 /* Populate the handle fields */
450                 handle->procFxnTable.attach        = &VAYUDSPPROC_attach;
451                 handle->procFxnTable.detach        = &VAYUDSPPROC_detach;
452                 handle->procFxnTable.start         = &VAYUDSPPROC_start;
453                 handle->procFxnTable.stop          = &VAYUDSPPROC_stop;
454                 handle->procFxnTable.read          = &VAYUDSPPROC_read;
455                 handle->procFxnTable.write         = &VAYUDSPPROC_write;
456                 handle->procFxnTable.control       = &VAYUDSPPROC_control;
457                 handle->procFxnTable.map           = &VAYUDSPPROC_map;
458                 handle->procFxnTable.unmap         = &VAYUDSPPROC_unmap;
459                 handle->procFxnTable.translateAddr = &VAYUDSPPROC_translate;
460                 handle->state = ProcMgr_State_Unknown;
462                 /* Allocate memory for the VAYUDSPPROC handle */
463                 handle->object = Memory_calloc (NULL,
464                                                 sizeof (VAYUDSPPROC_Object),
465                                                 0,
466                                                 NULL);
467                 if (handle->object == NULL) {
468                     status = PROCESSOR_E_MEMORY;
469                     GT_setFailureReason (curTrace,
470                                 GT_4CLASS,
471                                 "VAYUDSPPROC_create",
472                                 status,
473                                 "Memory allocation failed for handle->object!");
474                 }
475                 else {
476                     handle->procId = procId;
477                     object = (VAYUDSPPROC_Object *) handle->object;
478                     object->halObject = NULL;
479                     object->procHandle = (Processor_Handle)handle;
480                     /* Copy params into instance object. */
481                     Memory_copy (&(object->params),
482                                  (Ptr) params,
483                                  sizeof (VAYUDSPPROC_Params));
484                     /* Set the handle in the state object. */
485                     VAYUDSPPROC_state.procHandles [procId] =
486                                                      (VAYUDSPPROC_Handle) object;
487                     /* Initialize the list of listeners */
488                     List_Params_init(&listParams);
489                     handle->registeredNotifiers = List_create(&listParams);
491 #if !defined(SYSLINK_BUILD_OPTIMIZE)
492                     if (handle->registeredNotifiers == NULL) {
493                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
494                         status = PROCESSOR_E_FAIL;
495                         GT_setFailureReason (curTrace,
496                                              GT_4CLASS,
497                                              "VAYUDSPPROC_create",
498                                              status,
499                                              "List_create failed");
500                     }
501                     else {
502 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
504                         handle->notifiersLock =
505                                  OsalMutex_create(OsalMutex_Type_Interruptible);
507 #if !defined(SYSLINK_BUILD_OPTIMIZE)
508                         if (handle->notifiersLock == NULL) {
509                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
510                             status = PROCESSOR_E_FAIL;
511                             GT_setFailureReason (curTrace,
512                                                  GT_4CLASS,
513                                                  "VAYUDSPPROC_create",
514                                                  status,
515                                                  "OsalMutex_create failed");
516                         }
517                     }
518 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
519                 }
520             }
521 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
522         }
523 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
525         /* Leave critical section protection. */
526         IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
527 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
528     }
529 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
531     if (status < 0) {
532         if (handle !=  NULL) {
533             if (handle->registeredNotifiers != NULL) {
534                 List_delete (&handle->registeredNotifiers);
535             }
536             if (handle->object != NULL) {
537                 Memory_free (NULL,
538                              handle->object,
539                              sizeof (VAYUDSPPROC_Object));
540             }
541             Memory_free (NULL, handle, sizeof (Processor_Object));
542         }
543         /*! @retval NULL Function failed */
544         handle = NULL;
545     }
546     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_create", handle);
548     /*! @retval Valid-Handle Operation successful */
549     return (VAYUDSPPROC_Handle) handle;
553 /*!
554  *  @brief      Function to delete an instance of this Processor.
555  *
556  *              The user provided pointer to the handle is reset after
557  *              successful completion of this function.
558  *
559  *  @param      handlePtr  Pointer to Handle to the Processor instance
560  *
561  *  @sa         VAYUDSPPROC_create
562  */
563 Int
564 VAYUDSPPROC_delete (VAYUDSPPROC_Handle * handlePtr)
566     Int                   status = PROCESSOR_SUCCESS;
567     VAYUDSPPROC_Object *  object = NULL;
568     Processor_Object *    handle;
569     IArg                  key;
570     List_Elem *           elem    = NULL;
571     Processor_RegisterElem * regElem = NULL;
573     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_delete", handlePtr);
575     GT_assert (curTrace, (handlePtr != NULL));
576     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
578 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
579     if (handlePtr == NULL) {
580         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
581                                          specified*/
582         status = PROCESSOR_E_INVALIDARG;
583         GT_setFailureReason (curTrace,
584                              GT_4CLASS,
585                              "VAYUDSPPROC_delete",
586                              status,
587                              "Invalid NULL handlePtr pointer specified");
588     }
589     else if (*handlePtr == NULL) {
590         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
591         status = PROCESSOR_E_HANDLE;
592         GT_setFailureReason (curTrace,
593                              GT_4CLASS,
594                              "VAYUDSPPROC_delete",
595                              status,
596                              "Invalid NULL *handlePtr specified");
597     }
598     else {
599 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
600         handle = (Processor_Object *) (*handlePtr);
601         /* Enter critical section protection. */
602         key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
604         /* Reset handle in PwrMgr handle array. */
605         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
606         VAYUDSPPROC_state.procHandles [handle->procId] = NULL;
608         /* Free memory used for the VAYUDSPPROC object. */
609         if (handle->object != NULL) {
610             object = (VAYUDSPPROC_Object *) handle->object;
611             Memory_free (NULL,
612                          object,
613                          sizeof (VAYUDSPPROC_Object));
614             handle->object = NULL;
615         }
617         /*
618          * Check the list of listeners to see if any are remaining
619          * and reply to them
620          */
621         OsalMutex_delete(&handle->notifiersLock);
623         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
624             regElem = (Processor_RegisterElem *)elem;
626             /* Check if there is an associated timer and cancel it */
627             if (regElem->timer != -1) {
628                 struct itimerspec value ;
629                 value.it_value.tv_sec = 0;
630                 value.it_value.tv_nsec = 0;
631                 value.it_interval.tv_sec = 0;
632                 value.it_interval.tv_nsec = 0;
633                 timer_settime(regElem->timer, 0, &value, NULL);
635                 timer_delete(regElem->timer);
636                 regElem->timer = -1;
637             }
639             /* Call the callback function so it can clean up. */
640             regElem->info->cbFxn(handle->procId,
641                                  NULL,
642                                  handle->state,
643                                  handle->state,
644                                  ProcMgr_EventStatus_Canceled,
645                                  regElem->info->arg);
646             /* Free the memory */
647             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
648         }
650         /* Delete the list of listeners */
651         List_delete(&handle->registeredNotifiers);
653         /* Free memory used for the Processor object. */
654         Memory_free (NULL, handle, sizeof (Processor_Object));
655         *handlePtr = NULL;
657         /* Leave critical section protection. */
658         IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
659 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
660     }
661 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
663     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_delete", status);
665     /*! @retval PROCESSOR_SUCCESS Operation successful */
666     return (status);
670 /*!
671  *  @brief      Function to open a handle to an instance of this Processor. This
672  *              function is called when access to the Processor is required from
673  *              a different process.
674  *
675  *  @param      handlePtr   Handle to the Processor instance
676  *  @param      procId      Processor ID addressed by this Processor instance.
677  *
678  *  @sa         VAYUDSPPROC_close
679  */
680 Int
681 VAYUDSPPROC_open (VAYUDSPPROC_Handle * handlePtr, UInt16 procId)
683     Int status = PROCESSOR_SUCCESS;
685     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_open", handlePtr, procId);
687     GT_assert (curTrace, (handlePtr != NULL));
688     GT_assert (curTrace, IS_VALID_PROCID (procId));
690 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
691     if (handlePtr == NULL) {
692         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
693         status = PROCESSOR_E_HANDLE;
694         GT_setFailureReason (curTrace,
695                              GT_4CLASS,
696                              "VAYUDSPPROC_open",
697                              status,
698                              "Invalid NULL handlePtr specified");
699     }
700     else if (!IS_VALID_PROCID (procId)) {
701         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
702         status = PROCESSOR_E_INVALIDARG;
703         GT_setFailureReason (curTrace,
704                              GT_4CLASS,
705                              "VAYUDSPPROC_open",
706                              status,
707                              "Invalid procId specified");
708     }
709     else {
710 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
711         /* Initialize return parameter handle. */
712         *handlePtr = NULL;
714         /* Check if the PwrMgr exists and return the handle if found. */
715         if (VAYUDSPPROC_state.procHandles [procId] == NULL) {
716             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
717             status = PROCESSOR_E_NOTFOUND;
718             GT_setFailureReason (curTrace,
719                              GT_4CLASS,
720                              "VAYUDSPPROC_open",
721                              status,
722                              "Specified VAYUDSPPROC instance does not exist!");
723         }
724         else {
725             *handlePtr = VAYUDSPPROC_state.procHandles [procId];
726         }
727 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
728     }
729 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
731     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_open", status);
733     /*! @retval PROCESSOR_SUCCESS Operation successful */
734     return status;
738 /*!
739  *  @brief      Function to close a handle to an instance of this Processor.
740  *
741  *  @param      handlePtr  Pointer to Handle to the Processor instance
742  *
743  *  @sa         VAYUDSPPROC_open
744  */
745 Int
746 VAYUDSPPROC_close (VAYUDSPPROC_Handle * handlePtr)
748     Int status = PROCESSOR_SUCCESS;
750     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_close", handlePtr);
752     GT_assert (curTrace, (handlePtr != NULL));
753     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
755 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
756     if (handlePtr == NULL) {
757         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
758                                          specified*/
759         status = PROCESSOR_E_INVALIDARG;
760         GT_setFailureReason (curTrace,
761                              GT_4CLASS,
762                              "VAYUDSPPROC_close",
763                              status,
764                              "Invalid NULL handlePtr pointer specified");
765     }
766     else if (*handlePtr == NULL) {
767         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
768         status = PROCESSOR_E_HANDLE;
769         GT_setFailureReason (curTrace,
770                              GT_4CLASS,
771                              "VAYUDSPPROC_close",
772                              status,
773                              "Invalid NULL *handlePtr specified");
774     }
775     else {
776 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
777         /* Nothing to be done for close. */
778 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
779     }
780 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
782     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_close", status);
784     /*! @retval PROCESSOR_SUCCESS Operation successful */
785     return status;
789 /* =============================================================================
790  * APIs called by Processor module (part of function table interface)
791  * =============================================================================
792  */
793 /*!
794  *  @brief      Function to initialize the slave processor
795  *
796  *  @param      handle  Handle to the Processor instance
797  *  @param      params  Attach parameters
798  *
799  *  @sa         VAYUDSPPROC_detach
800  */
801 Int
802 VAYUDSPPROC_attach(
803         Processor_Handle            handle,
804         Processor_AttachParams *    params)
807     Int                         status = PROCESSOR_SUCCESS;
808     Processor_Object *          procHandle = (Processor_Object *)handle;
809     VAYUDSPPROC_Object *        object = NULL;
810     UInt32                      i = 0;
811     UInt32                      index = 0;
812     ProcMgr_AddrInfo *          me;
813     SysLink_MemEntry *          entry;
814     SysLink_MemEntry_Block      memBlock;
815     VAYUDSP_HalMmuCtrlArgs_Enable mmuEnableArgs;
816     VAYUDSP_HalParams           halParams;
818     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_attach", handle, params);
819     GT_assert (curTrace, (handle != NULL));
820     GT_assert (curTrace, (params != NULL));
822 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
823     if (handle == NULL) {
824         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
825         status = PROCESSOR_E_HANDLE;
826         GT_setFailureReason (curTrace,
827                              GT_4CLASS,
828                              "VAYUDSPPROC_attach",
829                              status,
830                              "Invalid handle specified");
831     }
832     else if (params == NULL) {
833             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
834             status = PROCESSOR_E_INVALIDARG;
835             GT_setFailureReason (curTrace,
836                                  GT_4CLASS,
837                                  "VAYUDSPPROC_attach",
838                                  status,
839                                  "Invalid params specified");
840     }
841     else {
842 #endif
843         object = (VAYUDSPPROC_Object *) procHandle->object;
844         GT_assert (curTrace, (object != NULL));
846         params->procArch = Processor_ProcArch_C66x;
848         object->pmHandle = params->pmHandle;
849         GT_0trace(curTrace, GT_1CLASS,
850             "VAYUDSPPROC_attach: Mapping memory regions");
852         /* search for dsp memory map */
853         status = RscTable_process(procHandle->procId,
854                                   TRUE,
855                                   &memBlock.numEntries);
856         if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
857             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
858             status = PROCESSOR_E_INVALIDARG;
859             GT_setFailureReason (curTrace,
860                                  GT_4CLASS,
861                                  "VAYUDSPPROC_attach",
862                                  status,
863                                  "Failed to process resource table");
864         }
865         else {
866             status = RscTable_getMemEntries(procHandle->procId,
867                                             memBlock.memEntries,
868                                             &memBlock.numEntries);
869             if (status < 0) {
870                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
871                 status = PROCESSOR_E_INVALIDARG;
872                 GT_setFailureReason (curTrace,
873                                      GT_4CLASS,
874                                      "VAYUDSPPROC_attach",
875                                      status,
876                                      "Failed to get resource table memEntries");
877             }
878         }
880         /* update translation tables with memory map */
881         for (i = 0; (i < memBlock.numEntries)
882             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
884             entry = &memBlock.memEntries[i];
886             if (entry->map == FALSE) {
887                 /* update table with entries which don't require mapping */
888                 if (AddrTable_count != AddrTable_SIZE) {
889                     me = &AddrTable[AddrTable_count];
891                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
892                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
893                     me->addr[ProcMgr_AddrType_MasterPhys] =
894                             entry->masterPhysAddr;
895                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
896                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
897                     me->size = entry->size;
898                     me->isCached = entry->isCached;
899                     me->mapMask = entry->mapMask;
901                     AddrTable_count++;
902                 }
903                 else {
904                     status = PROCESSOR_E_FAIL;
905                     GT_setFailureReason(curTrace, GT_4CLASS,
906                         "VAYUDSPPROC_attach", status,
907                         "AddrTable_SIZE reached!");
908                 }
909             }
910             else if (entry->map == TRUE) {
911                 /* send these entries back to ProcMgr for mapping */
912                 index = object->params.numMemEntries;
914                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
915                     me = &object->params.memEntries[index];
917                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
918                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
919                     me->addr[ProcMgr_AddrType_MasterPhys] =
920                             entry->masterPhysAddr;
921                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
922                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
923                     me->size = entry->size;
924                     me->isCached = entry->isCached;
925                     me->mapMask = entry->mapMask;
927                     object->params.numMemEntries++;
928                 }
929                 else {
930                     status = PROCESSOR_E_FAIL;
931                     GT_setFailureReason(curTrace, GT_4CLASS,
932                         "VAYUDSPPROC_attach", status,
933                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
934                 }
935             }
936             else {
937                 status = PROCESSOR_E_INVALIDARG;
938                 GT_setFailureReason(curTrace, GT_4CLASS,
939                     "VAYUDSPPROC_attach", status,
940                     "Memory map has entry with invalid 'map' value");
941             }
942         } /* for (...) */
944         if (status >= 0) {
945             /* populate the return params */
946             params->numMemEntries = object->params.numMemEntries;
947             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
948                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
950             halParams.procId = procHandle->procId;
951             status = VAYUDSP_halInit(&(object->halObject), &halParams);
953 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
954             if (status < 0) {
955                 GT_setFailureReason(curTrace, GT_4CLASS,
956                     "VAYUDSPPROC_attach", status,
957                     "VAYUDSP_halInit failed");
958             }
959             else {
960 #endif
961                 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
962                     || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
964 #if !defined(SYSLINK_BUILD_OPTIMIZE)
965                     if (status < 0) {
966                         GT_setFailureReason(curTrace, GT_4CLASS,
967                             "VAYUDSPPROC_attach", status,
968                             "Failed to reset the slave processor");
969                     }
970                     else {
971 #endif
972                         GT_0trace(curTrace, GT_3CLASS,
973                             "VAYUDSPPROC_attach: slave is now in reset");
975                         mmuEnableArgs.numMemEntries = 0;
976                         status = VAYUDSP_halMmuCtrl(object->halObject,
977                             Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
979 #if !defined(SYSLINK_BUILD_OPTIMIZE)
980                         if (status < 0) {
981                             GT_setFailureReason(curTrace, GT_4CLASS,
982                                 "VAYUDSPPROC_attach", status,
983                                 "Failed to enable the slave MMU");
984                         }
985                         else {
986 #endif
987                             GT_0trace(curTrace, GT_2CLASS,
988                                 "VAYUDSPPROC_attach: Slave MMU "
989                                 "is configured!");
991                             /*
992                              * Pull DSP MMU out of reset to make internal
993                              * memory "loadable"
994                              */
995                             status = VAYUDSP_halResetCtrl(object->halObject,
996                                 Processor_ResetCtrlCmd_MMU_Release);
997                             if (status < 0) {
998                                 /*! @retval status */
999                                 GT_setFailureReason(curTrace,
1000                                     GT_4CLASS,
1001                                     "VAYUDSP_halResetCtrl",
1002                                         status,
1003                                     "Reset MMU_Release failed");
1004                             }
1005 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1006                          }
1007                     }
1008 #endif
1009                 }
1010 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1011             }
1012 #endif
1013         }
1014 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1015     }
1016 #endif
1018     GT_1trace(curTrace, GT_LEAVE,
1019         "VAYUDSPPROC_attach", status);
1021     /*! @retval PROCESSOR_SUCCESS Operation successful */
1022     return status;
1026 /*!
1027  *  @brief      Function to detach from the Processor.
1028  *
1029  *  @param      handle  Handle to the Processor instance
1030  *
1031  *  @sa         VAYUDSPPROC_attach
1032  */
1033 Int
1034 VAYUDSPPROC_detach (Processor_Handle handle)
1036     Int                   status       = PROCESSOR_SUCCESS;
1037     Int                   tmpStatus    = PROCESSOR_SUCCESS;
1038     Processor_Object *    procHandle   = (Processor_Object *) handle;
1039     VAYUDSPPROC_Object * object       = NULL;
1040     Int i                              = 0;
1041     ProcMgr_AddrInfo *    ai;
1043     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_detach", handle);
1045     GT_assert (curTrace, (handle != NULL));
1047 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1048     if (handle == NULL) {
1049         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1050         status = PROCESSOR_E_HANDLE;
1051         GT_setFailureReason (curTrace,
1052                              GT_4CLASS,
1053                              "VAYUDSPPROC_detach",
1054                              PROCESSOR_E_HANDLE,
1055                              "Invalid handle specified");
1056     }
1057     else {
1058 #endif
1059         object = (VAYUDSPPROC_Object *) procHandle->object;
1060         GT_assert (curTrace, (object != NULL));
1062         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1063             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1065             GT_0trace(curTrace, GT_2CLASS,
1066                 "VAYUDSPPROC_detach: Disabling Slave MMU ...");
1068             status = VAYUDSP_halResetCtrl(object->halObject,
1069                 Processor_ResetCtrlCmd_MMU_Reset);
1070 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1071             if (status < 0) {
1072                 /*! @retval status */
1073                 GT_setFailureReason (curTrace,
1074                                      GT_4CLASS,
1075                                      "VAYUDSP_halResetCtrl",
1076                                      status,
1077                                      "Reset MMU failed");
1078             }
1079 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1081             status = VAYUDSP_halMmuCtrl(object->halObject,
1082                 Processor_MmuCtrlCmd_Disable, NULL);
1084 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1085             if (status < 0) {
1086                 GT_setFailureReason(curTrace, GT_4CLASS,
1087                     "VAYUDSPPROC_detach", status,
1088                     "Failed to disable the slave MMU");
1089             }
1090 #endif
1092             /* delete all dynamically added entries */
1093             for (i = 0; i < AddrTable_count; i++) {
1094                 ai = &AddrTable[i];
1095                 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1096                 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1097                 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1098                 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1099                 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1100                 ai->size = 0u;
1101                 ai->isCached = FALSE;
1102                 ai->mapMask = 0u;
1103                 ai->isMapped = FALSE;
1104                 ai->refCount = 0u;
1105             }
1106             object->params.numMemEntries = 0;
1107             AddrTable_count = 0;
1109             //No need to reset.. that will be done in STOP
1110             /*tmpStatus = VAYUDSP_halResetCtrl(object->halObject,
1111                 VAYUDspHal_Reset_Detach);
1113             GT_0trace(curTrace, GT_2CLASS,
1114                 "VAYUDSPPROC_detach: Slave processor is now in reset");*/
1116 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1117             if ((tmpStatus < 0) && (status >= 0)) {
1118                 status = tmpStatus;
1119                 GT_setFailureReason(curTrace,
1120                                      GT_4CLASS,
1121                                      "VAYUDSPPROC_detach",
1122                                      status,
1123                                      "Failed to reset the slave processor");
1124             }
1125 #endif
1126         }
1128         GT_0trace (curTrace,
1129                    GT_2CLASS,
1130                    "    VAYUDSPPROC_detach: Unmapping memory regions\n");
1132         tmpStatus = VAYUDSP_halExit (object->halObject);
1133 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1134         if ((tmpStatus < 0) && (status >= 0)) {
1135             status = tmpStatus;
1136             GT_setFailureReason (curTrace,
1137                                  GT_4CLASS,
1138                                  "VAYUDSPPROC_detach",
1139                                  status,
1140                                  "Failed to finalize HAL object");
1141         }
1142     }
1143 #endif
1145     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_detach", status);
1147     /*! @retval PROCESSOR_SUCCESS Operation successful */
1148     return status;
1152 /*!
1153  *  @brief      Function to start the slave processor
1154  *
1155  *              Start the slave processor running from its entry point.
1156  *              Depending on the boot mode, this involves configuring the boot
1157  *              address and releasing the slave from reset.
1158  *
1159  *  @param      handle    Handle to the Processor instance
1160  *
1161  *  @sa         VAYUDSPPROC_stop, VAYUDSP_halBootCtrl, VAYUDSP_halResetCtrl
1162  */
1163 Int
1164 VAYUDSPPROC_start (Processor_Handle        handle,
1165                    UInt32                  entryPt,
1166                    Processor_StartParams * params)
1168     Int                   status        = PROCESSOR_SUCCESS ;
1169     Processor_Object *    procHandle    = (Processor_Object *) handle;
1170     VAYUDSPPROC_Object *  object        = NULL;
1172     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_start",
1173                handle, entryPt, params);
1175     GT_assert (curTrace, (handle != NULL));
1176     GT_assert (curTrace, (params != NULL));
1178 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1179     if (handle == NULL) {
1180         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1181         status = PROCESSOR_E_HANDLE;
1182         GT_setFailureReason (curTrace,
1183                              GT_4CLASS,
1184                              "VAYUDSPPROC_start",
1185                              status,
1186                              "Invalid handle specified");
1187     }
1188     else if (params == NULL) {
1189             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1190             status = PROCESSOR_E_INVALIDARG;
1191             GT_setFailureReason (curTrace,
1192                                  GT_4CLASS,
1193                                  "VAYUDSPPROC_start",
1194                                  status,
1195                                  "Invalid params specified");
1196     }
1197     else {
1198 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1199         object = (VAYUDSPPROC_Object *) procHandle->object;
1200         GT_assert (curTrace, (object != NULL));
1201         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1202             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1203             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1204             /* Slave is to be started only for Boot mode and NoLoad mode. */
1205             /* Specify the DSP boot address in the boot config register */
1206             status = VAYUDSP_halBootCtrl (object->halObject,
1207                                         Processor_BootCtrlCmd_SetEntryPoint,
1208                                         (Ptr) entryPt);
1209 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1210             if (status < 0) {
1211                 GT_setFailureReason (curTrace,
1212                                      GT_4CLASS,
1213                                      "VAYUDSPPROC_start",
1214                                      status,
1215                                      "Failed to set slave boot entry point");
1216             }
1217             else {
1218 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1219                 status = rproc_dsp_setup(object->halObject,
1220                                          object->params.memEntries,
1221                                          object->params.numMemEntries);
1222                 if (status < 0) {
1223                     /*! @retval status */
1224                     GT_setFailureReason (curTrace,
1225                                          GT_4CLASS,
1226                                          "VAYUDSP_halResetCtrl",
1227                                          status,
1228                                          "rproc_dsp_setup failed");
1229                 }
1230                 /* release the slave cpu from reset */
1231                 if (status >= 0) {
1232                     status = VAYUDSP_halResetCtrl(object->halObject,
1233                                                 Processor_ResetCtrlCmd_Release);
1234 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1235                     if (status < 0) {
1236                         GT_setFailureReason (curTrace,
1237                                          GT_4CLASS,
1238                                          "VAYUDSPPROC_start",
1239                                          status,
1240                                          "Failed to release slave from reset");
1241                     }
1242 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1243                 }
1244 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1245             }
1246 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1247         }
1249 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1250     }
1251 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1253     if (status >= 0) {
1254         GT_0trace (curTrace,
1255                    GT_1CLASS,
1256                    "    VAYUDSPPROC_start: Slave successfully started!\n");
1257     }
1258     else {
1259         GT_0trace (curTrace,
1260                    GT_1CLASS,
1261                    "    VAYUDSPPROC_start: Slave could not be started!\n");
1262     }
1264     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_start", status);
1266     /*! @retval PROCESSOR_SUCCESS Operation successful */
1267     return status;
1271 /*!
1272  *  @brief      Function to stop the slave processor
1273  *
1274  *              Stop the execution of the slave processor. Depending on the boot
1275  *              mode, this may result in placing the slave processor in reset.
1276  *
1277  *  @param      handle    Handle to the Processor instance
1278  *
1279  *  @sa         VAYUDSPPROC_start, VAYUDSP_halResetCtrl
1280  */
1281 Int
1282 VAYUDSPPROC_stop (Processor_Handle handle)
1284     Int                   status       = PROCESSOR_SUCCESS ;
1285     Processor_Object *    procHandle   = (Processor_Object *) handle;
1286     VAYUDSPPROC_Object * object        = NULL;
1288     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_stop", handle);
1290     GT_assert (curTrace, (handle != NULL));
1292 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1293     if (handle == NULL) {
1294         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1295         status = PROCESSOR_E_HANDLE;
1296         GT_setFailureReason (curTrace,
1297                              GT_4CLASS,
1298                              "VAYUDSPPROC_stop",
1299                              status,
1300                              "Invalid handle specified");
1301     }
1302     else {
1303 #endif
1304         object = (VAYUDSPPROC_Object *) procHandle->object;
1305         GT_assert (curTrace, (object != NULL));
1307         /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1308         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1309             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1310             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1311             status = VAYUDSP_halResetCtrl(object->halObject,
1312                                           Processor_ResetCtrlCmd_Reset);
1314             GT_0trace (curTrace,
1315                        GT_1CLASS,
1316                        "    VAYUDSPPROC_stop: Slave is now in reset!\n");
1317 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1318             if (status < 0) {
1319                 GT_setFailureReason (curTrace,
1320                                      GT_4CLASS,
1321                                      "VAYUDSPPROC_stop",
1322                                      status,
1323                                      "Failed to place slave in reset");
1324             }
1325 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1326             rproc_dsp_destroy(object->halObject);
1327         }
1328 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1329     }
1330 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1331     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_stop", status);
1333     /*! @retval PROCESSOR_SUCCESS Operation successful */
1334     return status;
1338 /*!
1339  *  @brief      Function to read from the slave processor's memory.
1340  *
1341  *              Read from the slave processor's memory and copy into the
1342  *              provided buffer.
1343  *
1344  *  @param      handle     Handle to the Processor instance
1345  *  @param      procAddr   Address in host processor's address space of the
1346  *                         memory region to read from.
1347  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1348  *                         number of bytes to be read. When the function
1349  *                         returns, this parameter contains the number of bytes
1350  *                         actually read.
1351  *  @param      buffer     User-provided buffer in which the slave processor's
1352  *                         memory contents are to be copied.
1353  *
1354  *  @sa         VAYUDSPPROC_write
1355  */
1356 Int
1357 VAYUDSPPROC_read (Processor_Handle   handle,
1358                   UInt32             procAddr,
1359                   UInt32 *           numBytes,
1360                   Ptr                buffer)
1362     Int       status   = PROCESSOR_SUCCESS ;
1363     UInt8  *  procPtr8 = NULL;
1365     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_read",
1366                handle, procAddr, numBytes, buffer);
1368     GT_assert (curTrace, (handle   != NULL));
1369     GT_assert (curTrace, (numBytes != NULL));
1370     GT_assert (curTrace, (buffer   != NULL));
1372 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1373     if (handle == NULL) {
1374         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1375         status = PROCESSOR_E_HANDLE;
1376         GT_setFailureReason (curTrace,
1377                              GT_4CLASS,
1378                              "VAYUDSPPROC_read",
1379                              status,
1380                              "Invalid handle specified");
1381     }
1382     else if (numBytes == 0) {
1383             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1384             status = PROCESSOR_E_INVALIDARG;
1385             GT_setFailureReason (curTrace,
1386                                  GT_4CLASS,
1387                                  "VAYUDSPPROC_read",
1388                                  status,
1389                                  "Invalid numBytes specified");
1390     }
1391     else if (buffer == NULL) {
1392             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1393             status = PROCESSOR_E_INVALIDARG;
1394             GT_setFailureReason (curTrace,
1395                                  GT_4CLASS,
1396                                  "VAYUDSPPROC_read",
1397                                  status,
1398                                  "Invalid buffer specified");
1399     }
1400     else {
1401 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1402         procPtr8 = (UInt8 *) procAddr ;
1403         buffer = Memory_copy (buffer, procPtr8, *numBytes);
1404         GT_assert (curTrace, (buffer != (UInt32) NULL));
1405 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1406         if (buffer == (UInt32) NULL) {
1407             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1408             status = PROCESSOR_E_FAIL;
1409             GT_setFailureReason (curTrace,
1410                                  GT_4CLASS,
1411                                  "VAYUDSPPROC_read",
1412                                  status,
1413                                  "Failed in Memory_copy");
1414             *numBytes = 0;
1415         }
1416     }
1417 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1419     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_read",status);
1421     /*! @retval PROCESSOR_SUCCESS Operation successful */
1422     return status;
1426 /*!
1427  *  @brief      Function to write into the slave processor's memory.
1428  *
1429  *              Read from the provided buffer and copy into the slave
1430  *              processor's memory.
1431  *
1432  *  @param      handle     Handle to the Processor object
1433  *  @param      procAddr   Address in host processor's address space of the
1434  *                         memory region to write into.
1435  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1436  *                         number of bytes to be written. When the function
1437  *                         returns, this parameter contains the number of bytes
1438  *                         actually written.
1439  *  @param      buffer     User-provided buffer from which the data is to be
1440  *                         written into the slave processor's memory.
1441  *
1442  *  @sa         VAYUDSPPROC_read, VAYUDSPPROC_translateAddr
1443  */
1444 Int
1445 VAYUDSPPROC_write (Processor_Handle handle,
1446                    UInt32           procAddr,
1447                    UInt32 *         numBytes,
1448                    Ptr              buffer)
1450     Int                   status       = PROCESSOR_SUCCESS ;
1451     UInt8  *              procPtr8     = NULL;
1452     UInt8                 temp8_1;
1453     UInt8                 temp8_2;
1454     UInt8                 temp8_3;
1455     UInt8                 temp8_4;
1456     UInt32                temp;
1458     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_write",
1459                handle, procAddr, numBytes, buffer);
1461     GT_assert (curTrace, (handle   != NULL));
1462     GT_assert (curTrace, (numBytes != NULL));
1463     GT_assert (curTrace, (buffer   != NULL));
1465 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1466     if (handle == NULL) {
1467         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1468         status = PROCESSOR_E_HANDLE;
1469         GT_setFailureReason (curTrace,
1470                              GT_4CLASS,
1471                              "VAYUDSPPROC_write",
1472                              status,
1473                              "Invalid handle specified");
1474     }
1475     else if (numBytes == 0) {
1476             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1477             status = PROCESSOR_E_INVALIDARG;
1478             GT_setFailureReason (curTrace,
1479                                  GT_4CLASS,
1480                                  "VAYUDSPPROC_write",
1481                                  status,
1482                                  "Invalid numBytes specified");
1483     }
1484     else if (buffer == NULL) {
1485             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1486             status = PROCESSOR_E_INVALIDARG;
1487             GT_setFailureReason (curTrace,
1488                                  GT_4CLASS,
1489                                  "VAYUDSPPROC_write",
1490                                  status,
1491                                  "Invalid buffer specified");
1492     }
1493     else {
1494 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1495         if (*numBytes != sizeof (UInt32)) {
1496             procPtr8 = (UInt8 *) procAddr ;
1497             procAddr = (UInt32) Memory_copy (procPtr8,
1498                                              buffer,
1499                                              *numBytes);
1500             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1501 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1502             if (procAddr == (UInt32) NULL) {
1503                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1504                 status = PROCESSOR_E_FAIL;
1505                 GT_setFailureReason (curTrace,
1506                                      GT_4CLASS,
1507                                      "VAYUDSPPROC_write",
1508                                      status,
1509                                      "Failed in Memory_copy");
1510                 *numBytes = 0;
1511             }
1512 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1513         }
1514         else  {
1515              /* For 4 bytes, directly write as a UInt32 */
1516             temp8_1 = ((UInt8 *) buffer) [0];
1517             temp8_2 = ((UInt8 *) buffer) [1];
1518             temp8_3 = ((UInt8 *) buffer) [2];
1519             temp8_4 = ((UInt8 *) buffer) [3];
1520             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1521                              |   ((UInt32) temp8_3 << 16)
1522                              |   ((UInt32) temp8_2 << 8)
1523                              |   ((UInt32) temp8_1));
1524             *((UInt32*) procAddr) = temp;
1525         }
1526 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1527     }
1528 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1530     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_write",status);
1532     /*! @retval PROCESSOR_SUCCESS Operation successful */
1533     return status;
1537 /*!
1538  *  @brief      Function to perform device-dependent operations.
1539  *
1540  *              Performs device-dependent control operations as exposed by this
1541  *              implementation of the Processor module.
1542  *
1543  *  @param      handle     Handle to the Processor object
1544  *  @param      cmd        Device specific processor command
1545  *  @param      arg        Arguments specific to the type of command.
1546  *
1547  *  @sa
1548  */
1549 Int
1550 VAYUDSPPROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1552     Int                   status       = PROCESSOR_SUCCESS ;
1554     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_control", handle, cmd, arg);
1556     GT_assert (curTrace, (handle   != NULL));
1557     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1559 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1560     if (handle == NULL) {
1561         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1562         status = PROCESSOR_E_HANDLE;
1563         GT_setFailureReason (curTrace,
1564                              GT_4CLASS,
1565                              "VAYUDSPPROC_control",
1566                              status,
1567                              "Invalid handle specified");
1568     }
1569     else {
1570 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1571         /* No control operations currently implemented. */
1572         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1573                                              for this device. */
1574         status = PROCESSOR_E_NOTSUPPORTED;
1575 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1576     }
1577 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1578     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_control",status);
1580     /*! @retval PROCESSOR_SUCCESS Operation successful */
1581     return status;
1585 /*!
1586  *  @brief      Translate slave virtual address to master physical address.
1587  *
1588  *  @param      handle     Handle to the Processor object
1589  *  @param      dstAddr    Returned: master physical address.
1590  *  @param      srcAddr    Slave virtual address.
1591  *
1592  *  @sa
1593  */
1594 Int
1595 VAYUDSPPROC_translate(
1596         Processor_Handle    handle,
1597         UInt32 *            dstAddr,
1598         UInt32              srcAddr)
1600     Int                         status = PROCESSOR_SUCCESS;
1601     Processor_Object *          procHandle= (Processor_Object *)handle;
1602     VAYUDSPPROC_Object *        object = NULL;
1603     UInt32                      i;
1604     UInt32                      startAddr;
1605     UInt32                      endAddr;
1606     UInt32                      offset;
1607     ProcMgr_AddrInfo *          ai;
1609     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1610               handle, dstAddr, srcAddr);
1612     GT_assert (curTrace, (handle != NULL));
1613     GT_assert (curTrace, (dstAddr != NULL));
1615 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1616     if (handle == NULL) {
1617         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1618         status = PROCESSOR_E_HANDLE;
1619         GT_setFailureReason (curTrace,
1620                              GT_4CLASS,
1621                              "VAYUDSPPROC_translate",
1622                              status,
1623                              "Invalid handle specified");
1624     }
1625     else if (dstAddr == NULL) {
1626         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1627         status = PROCESSOR_E_INVALIDARG;
1628         GT_setFailureReason (curTrace,
1629                              GT_4CLASS,
1630                              "VAYUDSPPROC_translate",
1631                              status,
1632                              "dstAddr provided as NULL");
1633     }
1634     else {
1635 #endif
1636         object = (VAYUDSPPROC_Object *)procHandle->object;
1637         GT_assert(curTrace, (object != NULL));
1638         *dstAddr = -1u;
1640         for (i = 0; i < AddrTable_count; i++) {
1641             ai = &AddrTable[i];
1642             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1643             endAddr = startAddr + ai->size;
1645             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1646                 offset = srcAddr - startAddr;
1647                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1648                 break;
1649             }
1650         }
1652         if (*dstAddr == -1u) {
1653             /* srcAddr not found in slave address space */
1654             status = PROCESSOR_E_INVALIDARG;
1655             GT_setFailureReason(curTrace, GT_4CLASS,
1656                 "VAYUDSPPROC_translate", status,
1657                 "srcAddr not found in slave address space");
1658         }
1659 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1660     }
1661 #endif
1662     GT_1trace(curTrace, GT_LEAVE,
1663         "VAYUDSPPROC_translate: status=0x%x", status);
1665     /*! @retval PROCESSOR_SUCCESS Operation successful */
1666     return status;
1670 /*!
1671  *  @brief      Map the given address translation into the slave mmu
1672  *
1673  *  @param      handle      Handle to the Processor object
1674  *  @param      dstAddr     Base virtual address
1675  *  @param      nSegs       Number of given segments
1676  *  @param      sglist      Segment list
1677  */
1678 Int
1679 VAYUDSPPROC_map(
1680         Processor_Handle    handle,
1681         UInt32 *            dstAddr,
1682         UInt32              nSegs,
1683         Memory_SGList *     sglist)
1685     Int                         status = PROCESSOR_SUCCESS;
1686     Processor_Object *          procHandle = (Processor_Object *)handle;
1687     VAYUDSPPROC_Object *        object = NULL;
1688     Bool                        found = FALSE;
1689     UInt32                      startAddr;
1690     UInt32                      endAddr;
1691     UInt32                      i;
1692     UInt32                      j;
1693     ProcMgr_AddrInfo *          ai = NULL;
1695     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_map",
1696                handle, dstAddr, nSegs, sglist);
1698     GT_assert (curTrace, (handle != NULL));
1699     GT_assert (curTrace, (sglist != NULL));
1700     GT_assert (curTrace, (nSegs > 0));
1702 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1703     if (handle == NULL) {
1704         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1705         status = PROCESSOR_E_HANDLE;
1706         GT_setFailureReason (curTrace,
1707                              GT_4CLASS,
1708                              "VAYUDSPPROC_map",
1709                              status,
1710                              "Invalid handle specified");
1711     }
1712     else if (sglist == NULL) {
1713         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1714         status = PROCESSOR_E_INVALIDARG;
1715         GT_setFailureReason (curTrace,
1716                              GT_4CLASS,
1717                              "VAYUDSPPROC_map",
1718                              status,
1719                              "sglist provided as NULL");
1720     }
1721     else if (nSegs == 0) {
1722         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1723         status = PROCESSOR_E_INVALIDARG;
1724         GT_setFailureReason (curTrace,
1725                              GT_4CLASS,
1726                              "VAYUDSPPROC_map",
1727                              status,
1728                              "Number of segments provided is 0");
1729     }
1730     else {
1731 #endif
1732         object = (VAYUDSPPROC_Object *)procHandle->object;
1733         GT_assert (curTrace, (object != NULL));
1735         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1736             /* Update the translation table with entries for which mapping
1737              * is required. Add the entry only if the range does not exist
1738              * in the translation table.
1739              */
1740             for (j = 0; j < AddrTable_count; j++) {
1741                 ai = &AddrTable [j];
1743                 if (ai->isMapped == TRUE) {
1744                     startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1745                     endAddr = startAddr + ai->size;
1747                     if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1748                         && ((*dstAddr + sglist[i].size) <= endAddr)) {
1749                         found = TRUE;
1750                         ai->refCount++;
1751                         break;
1752                     }
1753                 }
1754             }
1756             /* if not found and mmu is enabled, add new entry to table */
1757             if (!found) {
1758                 if (AddrTable_count != AddrTable_SIZE) {
1759                     ai = &AddrTable[AddrTable_count];
1761                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1762                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1763                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1764                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1765                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1766                     ai->size = sglist[i].size;
1767                     ai->isCached = sglist[i].isCached;
1768                     ai->refCount++;
1769                     ai->isMapped = TRUE;
1771                     AddrTable_count++;
1772                 }
1773                 else {
1774                     status = PROCESSOR_E_FAIL;
1775                     GT_setFailureReason(curTrace, GT_4CLASS,
1776                         "VAYUDSPPROC_map", status,
1777                         "AddrTable_SIZE reached!");
1778                 }
1779             }
1780         }
1781 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1782     }
1783 #endif
1784     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_map", status);
1786     /*! @retval PROCESSOR_SUCCESS Operation successful */
1787     return status;
1791 /*!
1792  *  @brief      Function to unmap slave address from host address space
1793  *
1794  *  @param      handle      Handle to the Processor object
1795  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1796  *                          address.
1797  *  @param      size        Size of the region to be mapped.
1798  *
1799  *  @sa
1800  */
1801 Int
1802 VAYUDSPPROC_unmap(
1803         Processor_Handle    handle,
1804         UInt32              addr,
1805         UInt32              size)
1807     Int                         status = PROCESSOR_SUCCESS;
1808     Processor_Object *          procHandle = (Processor_Object *)handle;
1809     VAYUDSPPROC_Object *        object = NULL;
1810     ProcMgr_AddrInfo *          ai;
1811     Int                         i;
1812     UInt32                      startAddr;
1813     UInt32                      endAddr;
1814     VAYUDSP_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1816     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_unmap",
1817                handle, addr, size);
1819     GT_assert (curTrace, (handle != NULL));
1820     GT_assert (curTrace, (size   != 0));
1822 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1823     if (handle == NULL) {
1824         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1825         status = PROCESSOR_E_HANDLE;
1826         GT_setFailureReason (curTrace,
1827                              GT_4CLASS,
1828                              "VAYUDSPPROC_unmap",
1829                              status,
1830                              "Invalid handle specified");
1831     }
1832     else if (size == 0) {
1833         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1834         status = PROCESSOR_E_INVALIDARG;
1835         GT_setFailureReason (curTrace,
1836                              GT_4CLASS,
1837                              "VAYUDSPPROC_unmap",
1838                              status,
1839                              "Size provided is zero");
1840     }
1841     else {
1842 #endif
1843         object = (VAYUDSPPROC_Object *) procHandle->object;
1844         GT_assert (curTrace, (object != NULL));
1846         /* Delete entries from translation
1847          * table only in last unmap called on that entry
1848          */
1849         for (i = 0; i < AddrTable_count; i++) {
1850             ai = &AddrTable[i];
1852             if (!ai->isMapped) {
1853                 continue;
1854             }
1856             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1857             endAddr = startAddr + ai->size;
1859             if ((startAddr <= addr) && (addr < endAddr)) {
1860                 ai->refCount--;
1862                 if (ai->refCount == 0) {
1863                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1864                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1865                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1866                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1867                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1868                     ai->size = 0u;
1869                     ai->isCached = FALSE;
1870                     ai->mapMask = 0u;
1871                     ai->isMapped = FALSE;
1873                     /* Remove the entry from the DSP MMU also */
1874                     deleteEntryArgs.size          = size;
1875                     deleteEntryArgs.slaveVirtAddr = addr;
1876                     /* TBD: elementSize, endianism, mixedSized are
1877                      * hard coded now, must be configurable later
1878                      */
1879                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
1880                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
1881                     deleteEntryArgs.mixedSize     = MMU_TLBES;
1883                     status = VAYUDSP_halMmuCtrl(object->halObject,
1884                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
1885 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1886                     if (status < 0) {
1887                         GT_setFailureReason(curTrace, GT_4CLASS,
1888                             "VAYUDSPPROC_unmap", status,
1889                             "DSP MMU configuration failed");
1890                     }
1891 #endif
1892                 }
1893             }
1894         }
1895 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1896     }
1897 #endif
1898     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_unmap", status);
1900     /*! @retval PROCESSOR_SUCCESS Operation successful */
1901     return status;
1905 #if defined (__cplusplus)
1907 #endif /* defined (__cplusplus) */