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