Support a seperate address translation table for DSP2
[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
96 /* Number of DSPs supported */
97 #define NUM_DSPS 2
99 /* Convert procId to DSP # */
100 #define PROCID_TO_DSP(procId) (procId == VAYUDSPPROC_state.dsp1ProcId ?\
101     0 : 1)
104 /*!
105  *  @brief  VAYUDSPPROC Module state object
106  */
107 typedef struct VAYUDSPPROC_ModuleObject_tag {
108     UInt32              configSize;
109     /*!< Size of configuration structure */
110     VAYUDSPPROC_Config cfg;
111     /*!< VAYUDSPPROC configuration structure */
112     VAYUDSPPROC_Config defCfg;
113     /*!< Default module configuration */
114     VAYUDSPPROC_Params      defInstParams;
115     /*!< Default parameters for the VAYUDSPPROC instances */
116     Bool                isSetup;
117     /*!< Indicates whether the VAYUDSPPROC module is setup. */
118     VAYUDSPPROC_Handle procHandles [MultiProc_MAXPROCESSORS];
119     /*!< Processor handle array. */
120     IGateProvider_Handle         gateHandle;
121     /*!< Handle of gate to be used for local thread safety */
122     UInt16                     dsp1ProcId;
123     /*!< MultiProc id of DSP1 (to avoid multiple lookups) */
124 } VAYUDSPPROC_ModuleObject;
126 /* Memory region counters */
127 static UInt32 AddrTable_count[NUM_DSPS] = {
128     0,
129     0
130 };
132 /*
133  * Address translation table
134  */
135 static ProcMgr_AddrInfo AddrTable_DSP1[AddrTable_SIZE];
136 static ProcMgr_AddrInfo AddrTable_DSP2[AddrTable_SIZE];
138 static ProcMgr_AddrInfo * AddrTable[NUM_DSPS] =
140     AddrTable_DSP1,
141     AddrTable_DSP2
142 };
144 /* =============================================================================
145  *  Globals
146  * =============================================================================
147  */
149 /*!
150  *  @var    VAYUDSPPROC_state
151  *
152  *  @brief  VAYUDSPPROC state object variable
153  */
154 #if !defined(IPC_BUILD_DEBUG)
155 static
156 #endif /* if !defined(IPC_BUILD_DEBUG) */
157 VAYUDSPPROC_ModuleObject VAYUDSPPROC_state =
159     .isSetup = FALSE,
160     .configSize = sizeof(VAYUDSPPROC_Config),
161     .gateHandle = NULL,
162     .defInstParams.numMemEntries = 0
163 };
166 /* =============================================================================
167  * APIs directly called by applications
168  * =============================================================================
169  */
170 /*!
171  *  @brief      Function to get the default configuration for the VAYUDSPPROC
172  *              module.
173  *
174  *              This function can be called by the application to get their
175  *              configuration parameter to VAYUDSPPROC_setup filled in by the
176  *              VAYUDSPPROC module with the default parameters. If the user
177  *              does not wish to make any change in the default parameters, this
178  *              API is not required to be called.
179  *
180  *  @param      cfg        Pointer to the VAYUDSPPROC module configuration
181  *                         structure in which the default config is to be
182  *                         returned.
183  *
184  *  @sa         VAYUDSPPROC_setup
185  */
186 Void
187 VAYUDSPPROC_getConfig (VAYUDSPPROC_Config * cfg)
189     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_getConfig", cfg);
191     GT_assert (curTrace, (cfg != NULL));
193 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
194     if (cfg == NULL) {
195         GT_setFailureReason (curTrace,
196                              GT_4CLASS,
197                              "VAYUDSPPROC_getConfig",
198                              PROCESSOR_E_INVALIDARG,
199                              "Argument of type (VAYUDSPPROC_Config *) passed "
200                              "is null!");
201     }
202     else {
203 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
204         Memory_copy (cfg,
205                      &(VAYUDSPPROC_state.defCfg),
206                      sizeof (VAYUDSPPROC_Config));
207 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
208     }
209 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
211     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_getConfig");
215 /*!
216  *  @brief      Function to setup the VAYUDSPPROC module.
217  *
218  *              This function sets up the VAYUDSPPROC module. This function
219  *              must be called before any other instance-level APIs can be
220  *              invoked.
221  *              Module-level configuration needs to be provided to this
222  *              function. If the user wishes to change some specific config
223  *              parameters, then VAYUDSPPROC_getConfig can be called to get the
224  *              configuration filled with the default values. After this, only
225  *              the required configuration values can be changed. If the user
226  *              does not wish to make any change in the default parameters, the
227  *              application can simply call VAYUDSPPROC_setup with NULL
228  *              parameters. The default parameters would get automatically used.
229  *
230  *  @param      cfg   Optional VAYUDSPPROC module configuration. If provided as
231  *                    NULL, default configuration is used.
232  *
233  *  @sa         VAYUDSPPROC_destroy
234  *              GateMutex_create
235  */
236 Int
237 VAYUDSPPROC_setup (VAYUDSPPROC_Config * cfg)
239     Int                  status = PROCESSOR_SUCCESS;
240     VAYUDSPPROC_Config   tmpCfg;
241     Error_Block          eb;
243     Error_init(&eb);
245     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_setup", cfg);
247     if (cfg == NULL) {
248         VAYUDSPPROC_getConfig (&tmpCfg);
249         cfg = &tmpCfg;
250     }
252     /* Create a default gate handle for local module protection. */
253     VAYUDSPPROC_state.gateHandle = (IGateProvider_Handle)
254                                GateMutex_create ((GateMutex_Params *)NULL, &eb);
255 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
256     if (VAYUDSPPROC_state.gateHandle == NULL) {
257         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
258         status = PROCESSOR_E_FAIL;
259         GT_setFailureReason (curTrace,
260                              GT_4CLASS,
261                              "VAYUDSPPROC_setup",
262                              status,
263                              "Failed to create GateMutex!");
264     }
265     else {
266 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
267         /* Copy the user provided values into the state object. */
268         Memory_copy (&VAYUDSPPROC_state.cfg,
269                      cfg,
270                      sizeof (VAYUDSPPROC_Config));
272         /* Initialize the name to handles mapping array. */
273         Memory_set (&VAYUDSPPROC_state.procHandles,
274                     0,
275                     (sizeof (VAYUDSPPROC_Handle) * MultiProc_MAXPROCESSORS));
277         VAYUDSPPROC_state.dsp1ProcId = MultiProc_getId("DSP1");
278         VAYUDSPPROC_state.isSetup = TRUE;
279 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
280     }
281 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
283     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_setup", status);
285     /*! @retval PROCESSOR_SUCCESS Operation successful */
286     return (status);
290 /*!
291  *  @brief      Function to destroy the VAYUDSPPROC module.
292  *
293  *              Once this function is called, other VAYUDSPPROC module APIs,
294  *              except for the VAYUDSPPROC_getConfig API cannot be called
295  *              anymore.
296  *
297  *  @sa         VAYUDSPPROC_setup
298  *              GateMutex_delete
299  */
300 Int
301 VAYUDSPPROC_destroy (Void)
303     Int    status = PROCESSOR_SUCCESS;
304     UInt16 i;
306     GT_0trace (curTrace, GT_ENTER, "VAYUDSPPROC_destroy");
308     /* Check if any VAYUDSPPROC instances have not been deleted so far. If not,
309      * delete them.
310      */
311     for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
312         GT_assert (curTrace, (VAYUDSPPROC_state.procHandles [i] == NULL));
313         if (VAYUDSPPROC_state.procHandles [i] != NULL) {
314             VAYUDSPPROC_delete (&(VAYUDSPPROC_state.procHandles [i]));
315         }
316     }
318     if (VAYUDSPPROC_state.gateHandle != NULL) {
319         GateMutex_delete ((GateMutex_Handle *)
320                                 &(VAYUDSPPROC_state.gateHandle));
321     }
323     VAYUDSPPROC_state.isSetup = FALSE;
325     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_destroy", status);
327     /*! @retval PROCESSOR_SUCCESS Operation successful */
328     return (status);
332 /*!
333  *  @brief      Function to initialize the parameters for this Processor
334  *              instance.
335  *
336  *  @param      params  Configuration parameters to be returned
337  *
338  *  @sa         VAYUDSPPROC_create
339  */
340 Void
341 VAYUDSPPROC_Params_init(
342         VAYUDSPPROC_Handle    handle,
343         VAYUDSPPROC_Params *  params)
345     VAYUDSPPROC_Object * procObject = (VAYUDSPPROC_Object *) handle;
347     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_Params_init", handle, params);
349     GT_assert (curTrace, (params != NULL));
351 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
352     if (params == NULL) {
353         GT_setFailureReason (curTrace,
354                              GT_4CLASS,
355                              "VAYUDSPPROC_Params_init",
356                              PROCESSOR_E_INVALIDARG,
357                              "Argument of type (VAYUDSPPROC_Params *) "
358                              "passed is null!");
359     }
360     else {
361 #endif
362         if (handle == NULL) {
364             Memory_copy(params, &(VAYUDSPPROC_state.defInstParams),
365                 sizeof(VAYUDSPPROC_Params));
366         }
367         else {
368             /* return updated VAYUDSPPROC instance specific parameters */
369             Memory_copy(params, &(procObject->params), sizeof(VAYUDSPPROC_Params));
370         }
371 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
372     }
373 #endif
375     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_Params_init");
378 /*!
379  *  @brief      Function to create an instance of this Processor.
380  *
381  *  @param      name    Name of the Processor instance.
382  *  @param      params  Configuration parameters.
383  *
384  *  @sa         VAYUDSPPROC_delete
385  */
386 VAYUDSPPROC_Handle
387 VAYUDSPPROC_create (      UInt16                procId,
388                      const VAYUDSPPROC_Params * params)
390     Int                   status    = PROCESSOR_SUCCESS;
391     Processor_Object *    handle    = NULL;
392     VAYUDSPPROC_Object *  object    = NULL;
393     Int i                            = 0;
394     ProcMgr_AddrInfo *ai             = NULL;
395     IArg                  key;
396     List_Params           listParams;
398     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_create", procId, params);
400     GT_assert (curTrace, IS_VALID_PROCID (procId));
401     GT_assert (curTrace, (params != NULL));
403 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
404     if (!IS_VALID_PROCID (procId)) {
405         /* Not setting status here since this function does not return status.*/
406         GT_setFailureReason (curTrace,
407                              GT_4CLASS,
408                              "VAYUDSPPROC_create",
409                              PROCESSOR_E_INVALIDARG,
410                              "Invalid procId specified");
411     }
412     else if (params == NULL) {
413         GT_setFailureReason (curTrace,
414                              GT_4CLASS,
415                              "VAYUDSPPROC_create",
416                              PROCESSOR_E_INVALIDARG,
417                              "params passed is NULL!");
418     }
419     else {
420 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
421         /* Enter critical section protection. */
422         key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
423 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
424         /* Check if the Processor already exists for specified procId. */
425         if (VAYUDSPPROC_state.procHandles [procId] != NULL) {
426             status = PROCESSOR_E_ALREADYEXIST;
427             GT_setFailureReason (curTrace,
428                               GT_4CLASS,
429                               "VAYUDSPPROC_create",
430                               status,
431                               "Processor already exists for specified procId!");
432         }
433         else {
434 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
435             /* Allocate memory for the handle */
436             handle = (Processor_Object *) Memory_calloc (NULL,
437                                                       sizeof (Processor_Object),
438                                                       0,
439                                                       NULL);
440             if (handle == NULL) {
441                 GT_setFailureReason (curTrace,
442                                      GT_4CLASS,
443                                      "VAYUDSPPROC_create",
444                                      PROCESSOR_E_MEMORY,
445                                      "Memory allocation failed for handle!");
446             }
447             else {
448                 /* Populate the handle fields */
449                 handle->procFxnTable.attach        = &VAYUDSPPROC_attach;
450                 handle->procFxnTable.detach        = &VAYUDSPPROC_detach;
451                 handle->procFxnTable.start         = &VAYUDSPPROC_start;
452                 handle->procFxnTable.stop          = &VAYUDSPPROC_stop;
453                 handle->procFxnTable.read          = &VAYUDSPPROC_read;
454                 handle->procFxnTable.write         = &VAYUDSPPROC_write;
455                 handle->procFxnTable.control       = &VAYUDSPPROC_control;
456                 handle->procFxnTable.map           = &VAYUDSPPROC_map;
457                 handle->procFxnTable.unmap         = &VAYUDSPPROC_unmap;
458                 handle->procFxnTable.translateAddr = &VAYUDSPPROC_translate;
459                 handle->procFxnTable.translateFromPte = NULL;
461                 handle->state = ProcMgr_State_Unknown;
463                 /* Allocate memory for the VAYUDSPPROC handle */
464                 handle->object = Memory_calloc (NULL,
465                                                 sizeof (VAYUDSPPROC_Object),
466                                                 0,
467                                                 NULL);
468                 if (handle->object == NULL) {
469                     status = PROCESSOR_E_MEMORY;
470                     GT_setFailureReason (curTrace,
471                                 GT_4CLASS,
472                                 "VAYUDSPPROC_create",
473                                 status,
474                                 "Memory allocation failed for handle->object!");
475                 }
476                 else {
477                     handle->procId = procId;
478                     object = (VAYUDSPPROC_Object *) handle->object;
479                     object->halObject = NULL;
480                     object->procHandle = (Processor_Handle)handle;
481                     /* Copy params into instance object. */
482                     Memory_copy (&(object->params),
483                                  (Ptr) params,
484                                  sizeof (VAYUDSPPROC_Params));
486                     /* initialize the translation table */
487                     for (i = AddrTable_count[PROCID_TO_DSP(procId)];
488                         i < AddrTable_SIZE; i++) {
489                         ai = &AddrTable[PROCID_TO_DSP(procId)][i];
490                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
491                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
492                         ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
493                         ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
494                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
495                         ai->size = 0u;
496                         ai->isCached = FALSE;
497                         ai->mapMask = 0u;
498                         ai->isMapped = FALSE;
499                     }
501                     /*
502                      * initialize refCount for all entries
503                      */
504                     for (i = 0; i < AddrTable_SIZE; i++) {
505                         AddrTable[PROCID_TO_DSP(procId)][i].refCount = 0u;
506                     }
507                     Memory_copy((Ptr)(object->params.memEntries),
508                         AddrTable[PROCID_TO_DSP(procId)],
509                         (procId == VAYUDSPPROC_state.dsp1ProcId ?
510                         sizeof(AddrTable_DSP1) : sizeof(AddrTable_DSP2)));
512                     /* Set the handle in the state object. */
513                     VAYUDSPPROC_state.procHandles [procId] =
514                                                      (VAYUDSPPROC_Handle) object;
515                     /* Initialize the list of listeners */
516                     List_Params_init(&listParams);
517                     handle->registeredNotifiers = List_create(&listParams);
519 #if !defined(IPC_BUILD_OPTIMIZE)
520                     if (handle->registeredNotifiers == NULL) {
521                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
522                         status = PROCESSOR_E_FAIL;
523                         GT_setFailureReason (curTrace,
524                                              GT_4CLASS,
525                                              "VAYUDSPPROC_create",
526                                              status,
527                                              "List_create failed");
528                     }
529                     else {
530 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
532                         handle->notifiersLock =
533                                  OsalMutex_create(OsalMutex_Type_Interruptible);
535 #if !defined(IPC_BUILD_OPTIMIZE)
536                         if (handle->notifiersLock == NULL) {
537                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
538                             status = PROCESSOR_E_FAIL;
539                             GT_setFailureReason (curTrace,
540                                                  GT_4CLASS,
541                                                  "VAYUDSPPROC_create",
542                                                  status,
543                                                  "OsalMutex_create failed");
544                         }
545                     }
546 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
547                 }
548             }
549 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
550         }
551 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
553         /* Leave critical section protection. */
554         IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
555 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
556     }
557 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
559     if (status < 0) {
560         if (handle !=  NULL) {
561             if (handle->registeredNotifiers != NULL) {
562                 List_delete (&handle->registeredNotifiers);
563             }
564             if (handle->object != NULL) {
565                 Memory_free (NULL,
566                              handle->object,
567                              sizeof (VAYUDSPPROC_Object));
568             }
569             Memory_free (NULL, handle, sizeof (Processor_Object));
570         }
571         /*! @retval NULL Function failed */
572         handle = NULL;
573     }
574     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_create", handle);
576     /*! @retval Valid-Handle Operation successful */
577     return (VAYUDSPPROC_Handle) handle;
581 /*!
582  *  @brief      Function to delete an instance of this Processor.
583  *
584  *              The user provided pointer to the handle is reset after
585  *              successful completion of this function.
586  *
587  *  @param      handlePtr  Pointer to Handle to the Processor instance
588  *
589  *  @sa         VAYUDSPPROC_create
590  */
591 Int
592 VAYUDSPPROC_delete (VAYUDSPPROC_Handle * handlePtr)
594     Int                   status = PROCESSOR_SUCCESS;
595     VAYUDSPPROC_Object *  object = NULL;
596     Processor_Object *    handle;
597     IArg                  key;
598     List_Elem *           elem    = NULL;
599     Processor_RegisterElem * regElem = NULL;
601     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_delete", handlePtr);
603     GT_assert (curTrace, (handlePtr != NULL));
604     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
606 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
607     if (handlePtr == NULL) {
608         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
609                                          specified*/
610         status = PROCESSOR_E_INVALIDARG;
611         GT_setFailureReason (curTrace,
612                              GT_4CLASS,
613                              "VAYUDSPPROC_delete",
614                              status,
615                              "Invalid NULL handlePtr pointer specified");
616     }
617     else if (*handlePtr == NULL) {
618         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
619         status = PROCESSOR_E_HANDLE;
620         GT_setFailureReason (curTrace,
621                              GT_4CLASS,
622                              "VAYUDSPPROC_delete",
623                              status,
624                              "Invalid NULL *handlePtr specified");
625     }
626     else {
627 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
628         handle = (Processor_Object *) (*handlePtr);
629         /* Enter critical section protection. */
630         key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
632         /* Reset handle in PwrMgr handle array. */
633         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
634         VAYUDSPPROC_state.procHandles [handle->procId] = NULL;
636         /* Free memory used for the VAYUDSPPROC object. */
637         if (handle->object != NULL) {
638             object = (VAYUDSPPROC_Object *) handle->object;
639             Memory_free (NULL,
640                          object,
641                          sizeof (VAYUDSPPROC_Object));
642             handle->object = NULL;
643         }
645         /*
646          * Check the list of listeners to see if any are remaining
647          * and reply to them
648          */
649         OsalMutex_delete(&handle->notifiersLock);
651         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
652             regElem = (Processor_RegisterElem *)elem;
654             /* Check if there is an associated timer and cancel it */
655             if (regElem->timer != -1) {
656                 struct itimerspec value ;
657                 value.it_value.tv_sec = 0;
658                 value.it_value.tv_nsec = 0;
659                 value.it_interval.tv_sec = 0;
660                 value.it_interval.tv_nsec = 0;
661                 timer_settime(regElem->timer, 0, &value, NULL);
663                 timer_delete(regElem->timer);
664                 regElem->timer = -1;
665             }
667             /* Call the callback function so it can clean up. */
668             regElem->info->cbFxn(handle->procId,
669                                  NULL,
670                                  handle->state,
671                                  handle->state,
672                                  ProcMgr_EventStatus_Canceled,
673                                  regElem->info->arg);
674             /* Free the memory */
675             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
676         }
678         /* Delete the list of listeners */
679         List_delete(&handle->registeredNotifiers);
681         /* Free memory used for the Processor object. */
682         Memory_free (NULL, handle, sizeof (Processor_Object));
683         *handlePtr = NULL;
685         /* Leave critical section protection. */
686         IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
687 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
688     }
689 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
691     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_delete", status);
693     /*! @retval PROCESSOR_SUCCESS Operation successful */
694     return (status);
698 /*!
699  *  @brief      Function to open a handle to an instance of this Processor. This
700  *              function is called when access to the Processor is required from
701  *              a different process.
702  *
703  *  @param      handlePtr   Handle to the Processor instance
704  *  @param      procId      Processor ID addressed by this Processor instance.
705  *
706  *  @sa         VAYUDSPPROC_close
707  */
708 Int
709 VAYUDSPPROC_open (VAYUDSPPROC_Handle * handlePtr, UInt16 procId)
711     Int status = PROCESSOR_SUCCESS;
713     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_open", handlePtr, procId);
715     GT_assert (curTrace, (handlePtr != NULL));
716     GT_assert (curTrace, IS_VALID_PROCID (procId));
718 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
719     if (handlePtr == NULL) {
720         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
721         status = PROCESSOR_E_HANDLE;
722         GT_setFailureReason (curTrace,
723                              GT_4CLASS,
724                              "VAYUDSPPROC_open",
725                              status,
726                              "Invalid NULL handlePtr specified");
727     }
728     else if (!IS_VALID_PROCID (procId)) {
729         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
730         status = PROCESSOR_E_INVALIDARG;
731         GT_setFailureReason (curTrace,
732                              GT_4CLASS,
733                              "VAYUDSPPROC_open",
734                              status,
735                              "Invalid procId specified");
736     }
737     else {
738 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
739         /* Initialize return parameter handle. */
740         *handlePtr = NULL;
742         /* Check if the PwrMgr exists and return the handle if found. */
743         if (VAYUDSPPROC_state.procHandles [procId] == NULL) {
744             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
745             status = PROCESSOR_E_NOTFOUND;
746             GT_setFailureReason (curTrace,
747                              GT_4CLASS,
748                              "VAYUDSPPROC_open",
749                              status,
750                              "Specified VAYUDSPPROC instance does not exist!");
751         }
752         else {
753             *handlePtr = VAYUDSPPROC_state.procHandles [procId];
754         }
755 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
756     }
757 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
759     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_open", status);
761     /*! @retval PROCESSOR_SUCCESS Operation successful */
762     return status;
766 /*!
767  *  @brief      Function to close a handle to an instance of this Processor.
768  *
769  *  @param      handlePtr  Pointer to Handle to the Processor instance
770  *
771  *  @sa         VAYUDSPPROC_open
772  */
773 Int
774 VAYUDSPPROC_close (VAYUDSPPROC_Handle * handlePtr)
776     Int status = PROCESSOR_SUCCESS;
778     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_close", handlePtr);
780     GT_assert (curTrace, (handlePtr != NULL));
781     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
783 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
784     if (handlePtr == NULL) {
785         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
786                                          specified*/
787         status = PROCESSOR_E_INVALIDARG;
788         GT_setFailureReason (curTrace,
789                              GT_4CLASS,
790                              "VAYUDSPPROC_close",
791                              status,
792                              "Invalid NULL handlePtr pointer specified");
793     }
794     else if (*handlePtr == NULL) {
795         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
796         status = PROCESSOR_E_HANDLE;
797         GT_setFailureReason (curTrace,
798                              GT_4CLASS,
799                              "VAYUDSPPROC_close",
800                              status,
801                              "Invalid NULL *handlePtr specified");
802     }
803     else {
804 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
805         /* Nothing to be done for close. */
806 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
807     }
808 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
810     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_close", status);
812     /*! @retval PROCESSOR_SUCCESS Operation successful */
813     return status;
817 /* =============================================================================
818  * APIs called by Processor module (part of function table interface)
819  * =============================================================================
820  */
821 /*!
822  *  @brief      Function to initialize the slave processor
823  *
824  *  @param      handle  Handle to the Processor instance
825  *  @param      params  Attach parameters
826  *
827  *  @sa         VAYUDSPPROC_detach
828  */
829 Int
830 VAYUDSPPROC_attach(
831         Processor_Handle            handle,
832         Processor_AttachParams *    params)
835     Int                         status = PROCESSOR_SUCCESS;
836     Processor_Object *          procHandle = (Processor_Object *)handle;
837     VAYUDSPPROC_Object *        object = NULL;
838     UInt32                      i = 0;
839     UInt32                      index = 0;
840     ProcMgr_AddrInfo *          me;
841     Ipc_MemEntry *              entry;
842     Ipc_MemEntry_Block          memBlock;
843     VAYUDSP_HalMmuCtrlArgs_Enable mmuEnableArgs;
844     VAYUDSP_HalParams           halParams;
846     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_attach", handle, params);
847     GT_assert (curTrace, (handle != NULL));
848     GT_assert (curTrace, (params != NULL));
850 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
851     if (handle == NULL) {
852         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
853         status = PROCESSOR_E_HANDLE;
854         GT_setFailureReason (curTrace,
855                              GT_4CLASS,
856                              "VAYUDSPPROC_attach",
857                              status,
858                              "Invalid handle specified");
859     }
860     else if (params == NULL) {
861             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
862             status = PROCESSOR_E_INVALIDARG;
863             GT_setFailureReason (curTrace,
864                                  GT_4CLASS,
865                                  "VAYUDSPPROC_attach",
866                                  status,
867                                  "Invalid params specified");
868     }
869     else {
870 #endif
871         object = (VAYUDSPPROC_Object *) procHandle->object;
872         GT_assert (curTrace, (object != NULL));
874         /* Initialize halObject */
875         halParams.procId = procHandle->procId;
876         status = VAYUDSP_halInit(&(object->halObject), &halParams);
878         if (status < 0) {
879             GT_setFailureReason(curTrace, GT_4CLASS,
880                 "VAYUDSPPROC_attach", status,
881                 "VAYUDSP_halInit failed");
882         }
883         params->procArch = Processor_ProcArch_C66x;
885         object->pmHandle = params->pmHandle;
886         GT_0trace(curTrace, GT_1CLASS,
887             "VAYUDSPPROC_attach: Mapping memory regions");
889         /* search for dsp memory map */
890         status = RscTable_process(procHandle->procId,
891                                   TRUE,
892                                   &memBlock.numEntries,
893                                   procHandle,
894                                   procHandle->bootMode);
895         if (status < 0 || memBlock.numEntries > IPC_MAX_MEMENTRIES) {
896             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
897             status = PROCESSOR_E_INVALIDARG;
898             GT_setFailureReason (curTrace,
899                                  GT_4CLASS,
900                                  "VAYUDSPPROC_attach",
901                                  status,
902                                  "Failed to process resource table");
903         }
904         else {
905             status = RscTable_getMemEntries(procHandle->procId,
906                                             memBlock.memEntries,
907                                             &memBlock.numEntries);
908             if (status < 0) {
909                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
910                 status = PROCESSOR_E_INVALIDARG;
911                 GT_setFailureReason (curTrace,
912                                      GT_4CLASS,
913                                      "VAYUDSPPROC_attach",
914                                      status,
915                                      "Failed to get resource table memEntries");
916             }
917         }
919         /* update translation tables with memory map */
920         for (i = 0; (i < memBlock.numEntries)
921             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
923             entry = &memBlock.memEntries[i];
925             if (entry->map == FALSE) {
926                 /* update table with entries which don't require mapping */
927                 if (AddrTable_count[PROCID_TO_DSP(procHandle->procId)] !=
928                    AddrTable_SIZE) {
929                     me = &AddrTable[PROCID_TO_DSP(procHandle->procId)][
930                         AddrTable_count[PROCID_TO_DSP(procHandle->procId)]];
932                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
933                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
934                     me->addr[ProcMgr_AddrType_MasterPhys] =
935                         entry->masterPhysAddr;
936                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
937                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
938                     me->size = entry->size;
939                     me->isCached = entry->isCached;
940                     me->mapMask = entry->mapMask;
942                     AddrTable_count[PROCID_TO_DSP(procHandle->procId)]++;
943                 }
944                 else {
945                     status = PROCESSOR_E_FAIL;
946                     GT_setFailureReason(curTrace, GT_4CLASS,
947                         "VAYUDSPPROC_attach", status,
948                         "AddrTable_SIZE reached!");
949                 }
950             }
951             else if (entry->map == TRUE) {
952                 /* send these entries back to ProcMgr for mapping */
953                 index = object->params.numMemEntries;
955                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
956                     me = &object->params.memEntries[index];
958                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
959                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
960                     me->addr[ProcMgr_AddrType_MasterPhys] =
961                         entry->masterPhysAddr;
962                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
963                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
964                     me->size = entry->size;
965                     me->isCached = entry->isCached;
966                     me->mapMask = entry->mapMask;
968                     object->params.numMemEntries++;
969                 }
970                 else {
971                     status = PROCESSOR_E_FAIL;
972                     GT_setFailureReason(curTrace, GT_4CLASS,
973                         "VAYUDSPPROC_attach", status,
974                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
975                 }
976             }
977             else {
978                 status = PROCESSOR_E_INVALIDARG;
979                 GT_setFailureReason(curTrace, GT_4CLASS,
980                     "VAYUDSPPROC_attach", status,
981                     "Memory map has entry with invalid 'map' value");
982             }
983         } /* for (...) */
985         if (status >= 0) {
986             /* populate the return params */
987             params->numMemEntries = object->params.numMemEntries;
988             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
989                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
992             /* Setup the xbar for MMU fault interrupts */
993             GT_0trace(curTrace, GT_3CLASS,
994                 "VAYUDSPPROC_attach: slave is now in reset");
996             mmuEnableArgs.numMemEntries = 0;
997             status = VAYUDSP_halMmuCtrl(object->halObject,
998                 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1000             if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1001                 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1002 #if !defined(IPC_BUILD_OPTIMIZE)
1003                 if (status < 0) {
1004                     GT_setFailureReason(curTrace, GT_4CLASS,
1005                         "VAYUDSPPROC_attach", status,
1006                         "Failed to enable the slave MMU");
1007                 }
1008                 else {
1009 #endif
1010                     GT_0trace(curTrace, GT_2CLASS,
1011                         "VAYUDSPPROC_attach: Slave MMU "
1012                         "is configured!");
1014                     /*
1015                      * Pull DSP MMU out of reset to make internal
1016                      * memory "loadable"
1017                      */
1018                     status = VAYUDSP_halResetCtrl(
1019                         object->halObject,
1020                         Processor_ResetCtrlCmd_MMU_Release);
1021                     if (status < 0) {
1022                         /*! @retval status */
1023                         GT_setFailureReason(curTrace,
1024                             GT_4CLASS,
1025                             "VAYUDSP_halResetCtrl",
1026                             status,
1027                             "Reset MMU_Release failed");
1028                     }
1029 #if !defined(IPC_BUILD_OPTIMIZE)
1030                 }
1031 #endif
1032             }
1034         }
1035 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1036     }
1037 #endif
1039     GT_1trace(curTrace, GT_LEAVE,
1040         "VAYUDSPPROC_attach", status);
1042     /*! @retval PROCESSOR_SUCCESS Operation successful */
1043     return status;
1047 /*!
1048  *  @brief      Function to detach from the Processor.
1049  *
1050  *  @param      handle  Handle to the Processor instance
1051  *
1052  *  @sa         VAYUDSPPROC_attach
1053  */
1054 Int
1055 VAYUDSPPROC_detach (Processor_Handle handle)
1057     Int                   status       = PROCESSOR_SUCCESS;
1058     Int                   tmpStatus    = PROCESSOR_SUCCESS;
1059     Processor_Object *    procHandle   = (Processor_Object *) handle;
1060     VAYUDSPPROC_Object * object       = NULL;
1061     Int i                              = 0;
1062     ProcMgr_AddrInfo *    ai;
1064     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_detach", handle);
1066     GT_assert (curTrace, (handle != NULL));
1068 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1069     if (handle == NULL) {
1070         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1071         status = PROCESSOR_E_HANDLE;
1072         GT_setFailureReason (curTrace,
1073                              GT_4CLASS,
1074                              "VAYUDSPPROC_detach",
1075                              PROCESSOR_E_HANDLE,
1076                              "Invalid handle specified");
1077     }
1078     else {
1079 #endif
1080         object = (VAYUDSPPROC_Object *) procHandle->object;
1081         GT_assert (curTrace, (object != NULL));
1083         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1084             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1086             GT_0trace(curTrace, GT_2CLASS,
1087                 "VAYUDSPPROC_detach: Disabling Slave MMU ...");
1089             status = VAYUDSP_halResetCtrl(object->halObject,
1090                 Processor_ResetCtrlCmd_MMU_Reset);
1091 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1092             if (status < 0) {
1093                 /*! @retval status */
1094                 GT_setFailureReason (curTrace,
1095                                      GT_4CLASS,
1096                                      "VAYUDSP_halResetCtrl",
1097                                      status,
1098                                      "Reset MMU failed");
1099             }
1100 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1102             status = VAYUDSP_halMmuCtrl(object->halObject,
1103                 Processor_MmuCtrlCmd_Disable, NULL);
1105 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1106             if (status < 0) {
1107                 GT_setFailureReason(curTrace, GT_4CLASS,
1108                     "VAYUDSPPROC_detach", status,
1109                     "Failed to disable the slave MMU");
1110             }
1111 #endif
1112         }
1114         /* delete all dynamically added entries */
1115         for (i = 0; i <
1116             AddrTable_count[PROCID_TO_DSP(procHandle->procId)]; i++) {
1117             ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][i];
1118             ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1119             ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1120             ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1121             ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1122             ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1123             ai->size = 0u;
1124             ai->isCached = FALSE;
1125             ai->mapMask = 0u;
1126             ai->isMapped = FALSE;
1127             ai->refCount = 0u;
1128         }
1129         object->params.numMemEntries = 0;
1130         AddrTable_count[PROCID_TO_DSP(procHandle->procId)] = 0;
1132         //No need to reset.. that will be done in STOP
1133         /*tmpStatus = VAYUDSP_halResetCtrl(object->halObject,
1134             VAYUDspHal_Reset_Detach);
1136         GT_0trace(curTrace, GT_2CLASS,
1137             "VAYUDSPPROC_detach: Slave processor is now in reset");*/
1139 #if !defined(IPC_BUILD_OPTIMIZE)
1140         if ((tmpStatus < 0) && (status >= 0)) {
1141             status = tmpStatus;
1142             GT_setFailureReason (curTrace,
1143                                  GT_4CLASS,
1144                                  "VAYUDSPPROC_detach",
1145                                  status,
1146                                  "Failed to reset the slave processor");
1147         }
1148 #endif
1150         GT_0trace (curTrace,
1151                    GT_2CLASS,
1152                    "    VAYUDSPPROC_detach: Unmapping memory regions\n");
1154         tmpStatus = VAYUDSP_halExit (object->halObject);
1155 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1156         if ((tmpStatus < 0) && (status >= 0)) {
1157             status = tmpStatus;
1158             GT_setFailureReason (curTrace,
1159                                  GT_4CLASS,
1160                                  "VAYUDSPPROC_detach",
1161                                  status,
1162                                  "Failed to finalize HAL object");
1163         }
1164     }
1165 #endif
1167     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_detach", status);
1169     /*! @retval PROCESSOR_SUCCESS Operation successful */
1170     return status;
1174 /*!
1175  *  @brief      Function to start the slave processor
1176  *
1177  *              Start the slave processor running from its entry point.
1178  *              Depending on the boot mode, this involves configuring the boot
1179  *              address and releasing the slave from reset.
1180  *
1181  *  @param      handle    Handle to the Processor instance
1182  *
1183  *  @sa         VAYUDSPPROC_stop, VAYUDSP_halBootCtrl, VAYUDSP_halResetCtrl
1184  */
1185 Int
1186 VAYUDSPPROC_start (Processor_Handle        handle,
1187                    UInt32                  entryPt,
1188                    Processor_StartParams * params)
1190     Int                   status        = PROCESSOR_SUCCESS ;
1191     Processor_Object *    procHandle    = (Processor_Object *) handle;
1192     VAYUDSPPROC_Object *  object        = NULL;
1194     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_start",
1195                handle, entryPt, params);
1197     GT_assert (curTrace, (handle != NULL));
1198     GT_assert (curTrace, (params != NULL));
1200 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1201     if (handle == NULL) {
1202         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1203         status = PROCESSOR_E_HANDLE;
1204         GT_setFailureReason (curTrace,
1205                              GT_4CLASS,
1206                              "VAYUDSPPROC_start",
1207                              status,
1208                              "Invalid handle specified");
1209     }
1210     else if (params == NULL) {
1211             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1212             status = PROCESSOR_E_INVALIDARG;
1213             GT_setFailureReason (curTrace,
1214                                  GT_4CLASS,
1215                                  "VAYUDSPPROC_start",
1216                                  status,
1217                                  "Invalid params specified");
1218     }
1219     else {
1220 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1221         object = (VAYUDSPPROC_Object *) procHandle->object;
1222         GT_assert (curTrace, (object != NULL));
1223         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1224             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1225             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1226             /* Slave is to be started only for Boot mode and NoLoad mode. */
1227             /* Specify the DSP boot address in the boot config register */
1228             status = VAYUDSP_halBootCtrl (object->halObject,
1229                                         Processor_BootCtrlCmd_SetEntryPoint,
1230                                         (Ptr) entryPt);
1231 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1232             if (status < 0) {
1233                 GT_setFailureReason (curTrace,
1234                                      GT_4CLASS,
1235                                      "VAYUDSPPROC_start",
1236                                      status,
1237                                      "Failed to set slave boot entry point");
1238             }
1239             else {
1240 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1241                 status = rproc_dsp_setup(object->halObject,
1242                                          object->params.memEntries,
1243                                          object->params.numMemEntries);
1244                 if (status < 0) {
1245                     /*! @retval status */
1246                     GT_setFailureReason (curTrace,
1247                                          GT_4CLASS,
1248                                          "VAYUDSP_halResetCtrl",
1249                                          status,
1250                                          "rproc_dsp_setup failed");
1251                 }
1252                 /* release the slave cpu from reset */
1253                 if (status >= 0) {
1254                     status = VAYUDSP_halResetCtrl(object->halObject,
1255                                                 Processor_ResetCtrlCmd_Release);
1256 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1257                     if (status < 0) {
1258                         GT_setFailureReason (curTrace,
1259                                          GT_4CLASS,
1260                                          "VAYUDSPPROC_start",
1261                                          status,
1262                                          "Failed to release slave from reset");
1263                     }
1264 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1265                 }
1266 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1267             }
1268 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1269         }
1271 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1272     }
1273 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1275     if (status >= 0) {
1276         GT_0trace (curTrace,
1277                    GT_1CLASS,
1278                    "    VAYUDSPPROC_start: Slave successfully started!\n");
1279     }
1280     else {
1281         GT_0trace (curTrace,
1282                    GT_1CLASS,
1283                    "    VAYUDSPPROC_start: Slave could not be started!\n");
1284     }
1286     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_start", status);
1288     /*! @retval PROCESSOR_SUCCESS Operation successful */
1289     return status;
1293 /*!
1294  *  @brief      Function to stop the slave processor
1295  *
1296  *              Stop the execution of the slave processor. Depending on the boot
1297  *              mode, this may result in placing the slave processor in reset.
1298  *
1299  *  @param      handle    Handle to the Processor instance
1300  *
1301  *  @sa         VAYUDSPPROC_start, VAYUDSP_halResetCtrl
1302  */
1303 Int
1304 VAYUDSPPROC_stop (Processor_Handle handle)
1306     Int                   status       = PROCESSOR_SUCCESS ;
1307     Processor_Object *    procHandle   = (Processor_Object *) handle;
1308     VAYUDSPPROC_Object * object        = NULL;
1310     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_stop", handle);
1312     GT_assert (curTrace, (handle != NULL));
1314 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1315     if (handle == NULL) {
1316         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1317         status = PROCESSOR_E_HANDLE;
1318         GT_setFailureReason (curTrace,
1319                              GT_4CLASS,
1320                              "VAYUDSPPROC_stop",
1321                              status,
1322                              "Invalid handle specified");
1323     }
1324     else {
1325 #endif
1326         object = (VAYUDSPPROC_Object *) procHandle->object;
1327         GT_assert (curTrace, (object != NULL));
1329         /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1330         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1331             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1332             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1333             status = VAYUDSP_halResetCtrl(object->halObject,
1334                                           Processor_ResetCtrlCmd_Reset);
1336             GT_0trace (curTrace,
1337                        GT_1CLASS,
1338                        "    VAYUDSPPROC_stop: Slave is now in reset!\n");
1339 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1340             if (status < 0) {
1341                 GT_setFailureReason (curTrace,
1342                                      GT_4CLASS,
1343                                      "VAYUDSPPROC_stop",
1344                                      status,
1345                                      "Failed to place slave in reset");
1346             }
1347 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1348             rproc_dsp_destroy(object->halObject);
1349         }
1350 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1351     }
1352 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1353     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_stop", status);
1355     /*! @retval PROCESSOR_SUCCESS Operation successful */
1356     return status;
1360 /*!
1361  *  @brief      Function to read from the slave processor's memory.
1362  *
1363  *              Read from the slave processor's memory and copy into the
1364  *              provided buffer.
1365  *
1366  *  @param      handle     Handle to the Processor instance
1367  *  @param      procAddr   Address in host processor's address space of the
1368  *                         memory region to read from.
1369  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1370  *                         number of bytes to be read. When the function
1371  *                         returns, this parameter contains the number of bytes
1372  *                         actually read.
1373  *  @param      buffer     User-provided buffer in which the slave processor's
1374  *                         memory contents are to be copied.
1375  *
1376  *  @sa         VAYUDSPPROC_write
1377  */
1378 Int
1379 VAYUDSPPROC_read (Processor_Handle   handle,
1380                   UInt32             procAddr,
1381                   UInt32 *           numBytes,
1382                   Ptr                buffer)
1384     Int       status   = PROCESSOR_SUCCESS ;
1385     UInt8  *  procPtr8 = NULL;
1387     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_read",
1388                handle, procAddr, numBytes, buffer);
1390     GT_assert (curTrace, (handle   != NULL));
1391     GT_assert (curTrace, (numBytes != NULL));
1392     GT_assert (curTrace, (buffer   != NULL));
1394 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1395     if (handle == NULL) {
1396         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1397         status = PROCESSOR_E_HANDLE;
1398         GT_setFailureReason (curTrace,
1399                              GT_4CLASS,
1400                              "VAYUDSPPROC_read",
1401                              status,
1402                              "Invalid handle specified");
1403     }
1404     else if (numBytes == 0) {
1405             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1406             status = PROCESSOR_E_INVALIDARG;
1407             GT_setFailureReason (curTrace,
1408                                  GT_4CLASS,
1409                                  "VAYUDSPPROC_read",
1410                                  status,
1411                                  "Invalid numBytes specified");
1412     }
1413     else if (buffer == NULL) {
1414             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1415             status = PROCESSOR_E_INVALIDARG;
1416             GT_setFailureReason (curTrace,
1417                                  GT_4CLASS,
1418                                  "VAYUDSPPROC_read",
1419                                  status,
1420                                  "Invalid buffer specified");
1421     }
1422     else {
1423 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1424         procPtr8 = (UInt8 *) procAddr ;
1425         buffer = Memory_copy (buffer, procPtr8, *numBytes);
1426         GT_assert (curTrace, (buffer != (UInt32) NULL));
1427 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1428         if (buffer == (UInt32) NULL) {
1429             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1430             status = PROCESSOR_E_FAIL;
1431             GT_setFailureReason (curTrace,
1432                                  GT_4CLASS,
1433                                  "VAYUDSPPROC_read",
1434                                  status,
1435                                  "Failed in Memory_copy");
1436             *numBytes = 0;
1437         }
1438     }
1439 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1441     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_read",status);
1443     /*! @retval PROCESSOR_SUCCESS Operation successful */
1444     return status;
1448 /*!
1449  *  @brief      Function to write into the slave processor's memory.
1450  *
1451  *              Read from the provided buffer and copy into the slave
1452  *              processor's memory.
1453  *
1454  *  @param      handle     Handle to the Processor object
1455  *  @param      procAddr   Address in host processor's address space of the
1456  *                         memory region to write into.
1457  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1458  *                         number of bytes to be written. When the function
1459  *                         returns, this parameter contains the number of bytes
1460  *                         actually written.
1461  *  @param      buffer     User-provided buffer from which the data is to be
1462  *                         written into the slave processor's memory.
1463  *
1464  *  @sa         VAYUDSPPROC_read, VAYUDSPPROC_translateAddr
1465  */
1466 Int
1467 VAYUDSPPROC_write (Processor_Handle handle,
1468                    UInt32           procAddr,
1469                    UInt32 *         numBytes,
1470                    Ptr              buffer)
1472     Int                   status       = PROCESSOR_SUCCESS ;
1473     UInt8  *              procPtr8     = NULL;
1474     UInt8                 temp8_1;
1475     UInt8                 temp8_2;
1476     UInt8                 temp8_3;
1477     UInt8                 temp8_4;
1478     UInt32                temp;
1480     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_write",
1481                handle, procAddr, numBytes, buffer);
1483     GT_assert (curTrace, (handle   != NULL));
1484     GT_assert (curTrace, (numBytes != NULL));
1485     GT_assert (curTrace, (buffer   != NULL));
1487 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1488     if (handle == NULL) {
1489         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1490         status = PROCESSOR_E_HANDLE;
1491         GT_setFailureReason (curTrace,
1492                              GT_4CLASS,
1493                              "VAYUDSPPROC_write",
1494                              status,
1495                              "Invalid handle specified");
1496     }
1497     else if (numBytes == 0) {
1498             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1499             status = PROCESSOR_E_INVALIDARG;
1500             GT_setFailureReason (curTrace,
1501                                  GT_4CLASS,
1502                                  "VAYUDSPPROC_write",
1503                                  status,
1504                                  "Invalid numBytes specified");
1505     }
1506     else if (buffer == NULL) {
1507             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1508             status = PROCESSOR_E_INVALIDARG;
1509             GT_setFailureReason (curTrace,
1510                                  GT_4CLASS,
1511                                  "VAYUDSPPROC_write",
1512                                  status,
1513                                  "Invalid buffer specified");
1514     }
1515     else {
1516 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1517         if (*numBytes != sizeof (UInt32)) {
1518             procPtr8 = (UInt8 *) procAddr ;
1519             procAddr = (UInt32) Memory_copy (procPtr8,
1520                                              buffer,
1521                                              *numBytes);
1522             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1523 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1524             if (procAddr == (UInt32) NULL) {
1525                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1526                 status = PROCESSOR_E_FAIL;
1527                 GT_setFailureReason (curTrace,
1528                                      GT_4CLASS,
1529                                      "VAYUDSPPROC_write",
1530                                      status,
1531                                      "Failed in Memory_copy");
1532                 *numBytes = 0;
1533             }
1534 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1535         }
1536         else  {
1537              /* For 4 bytes, directly write as a UInt32 */
1538             temp8_1 = ((UInt8 *) buffer) [0];
1539             temp8_2 = ((UInt8 *) buffer) [1];
1540             temp8_3 = ((UInt8 *) buffer) [2];
1541             temp8_4 = ((UInt8 *) buffer) [3];
1542             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1543                              |   ((UInt32) temp8_3 << 16)
1544                              |   ((UInt32) temp8_2 << 8)
1545                              |   ((UInt32) temp8_1));
1546             *((UInt32*) procAddr) = temp;
1547         }
1548 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1549     }
1550 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1552     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_write",status);
1554     /*! @retval PROCESSOR_SUCCESS Operation successful */
1555     return status;
1559 /*!
1560  *  @brief      Function to perform device-dependent operations.
1561  *
1562  *              Performs device-dependent control operations as exposed by this
1563  *              implementation of the Processor module.
1564  *
1565  *  @param      handle     Handle to the Processor object
1566  *  @param      cmd        Device specific processor command
1567  *  @param      arg        Arguments specific to the type of command.
1568  *
1569  *  @sa
1570  */
1571 Int
1572 VAYUDSPPROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1574     Int                   status       = PROCESSOR_SUCCESS ;
1576     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_control", handle, cmd, arg);
1578     GT_assert (curTrace, (handle   != NULL));
1579     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1581 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1582     if (handle == NULL) {
1583         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1584         status = PROCESSOR_E_HANDLE;
1585         GT_setFailureReason (curTrace,
1586                              GT_4CLASS,
1587                              "VAYUDSPPROC_control",
1588                              status,
1589                              "Invalid handle specified");
1590     }
1591     else {
1592 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1593         /* No control operations currently implemented. */
1594         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1595                                              for this device. */
1596         status = PROCESSOR_E_NOTSUPPORTED;
1597 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1598     }
1599 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1600     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_control",status);
1602     /*! @retval PROCESSOR_SUCCESS Operation successful */
1603     return status;
1607 /*!
1608  *  @brief      Translate slave virtual address to master physical address.
1609  *
1610  *  @param      handle     Handle to the Processor object
1611  *  @param      dstAddr    Returned: master physical address.
1612  *  @param      srcAddr    Slave virtual address.
1613  *
1614  *  @sa
1615  */
1616 Int
1617 VAYUDSPPROC_translate(
1618         Processor_Handle    handle,
1619         UInt32 *            dstAddr,
1620         UInt32              srcAddr)
1622     Int                         status = PROCESSOR_SUCCESS;
1623     Processor_Object *          procHandle= (Processor_Object *)handle;
1624     VAYUDSPPROC_Object *        object = NULL;
1625     UInt32                      i;
1626     UInt32                      startAddr;
1627     UInt32                      endAddr;
1628     UInt32                      offset;
1629     ProcMgr_AddrInfo *          ai;
1631     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1632               handle, dstAddr, srcAddr);
1634     GT_assert (curTrace, (handle != NULL));
1635     GT_assert (curTrace, (dstAddr != NULL));
1637 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1638     if (handle == NULL) {
1639         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1640         status = PROCESSOR_E_HANDLE;
1641         GT_setFailureReason (curTrace,
1642                              GT_4CLASS,
1643                              "VAYUDSPPROC_translate",
1644                              status,
1645                              "Invalid handle specified");
1646     }
1647     else if (dstAddr == NULL) {
1648         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1649         status = PROCESSOR_E_INVALIDARG;
1650         GT_setFailureReason (curTrace,
1651                              GT_4CLASS,
1652                              "VAYUDSPPROC_translate",
1653                              status,
1654                              "dstAddr provided as NULL");
1655     }
1656     else {
1657 #endif
1658         object = (VAYUDSPPROC_Object *)procHandle->object;
1659         GT_assert(curTrace, (object != NULL));
1660         *dstAddr = -1u;
1662         /* search all entries AddrTable */
1663         for (i = 0; i < AddrTable_count[PROCID_TO_DSP(procHandle->procId)];
1664             i++) {
1665             ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][i];
1666             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1667             endAddr = startAddr + ai->size;
1669             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1670                 offset = srcAddr - startAddr;
1671                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1672                 GT_3trace(curTrace, GT_1CLASS, "VAYUDSPPROC_translate: "
1673                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1674                     i, srcAddr, *dstAddr);
1675                 break;
1676             }
1677         }
1679         if (*dstAddr == -1u) {
1680             /* srcAddr not found in slave address space */
1681             status = PROCESSOR_E_INVALIDARG;
1682             GT_setFailureReason(curTrace, GT_4CLASS,
1683                 "VAYUDSPPROC_translate", status,
1684                 "srcAddr not found in slave address space");
1685         }
1686 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1687     }
1688 #endif
1689     GT_1trace(curTrace, GT_LEAVE,
1690         "VAYUDSPPROC_translate: status=0x%x", status);
1692     /*! @retval PROCESSOR_SUCCESS Operation successful */
1693     return status;
1696 /*!
1697  *  @brief      Map the given address translation into the slave mmu
1698  *
1699  *  @param      handle      Handle to the Processor object
1700  *  @param      dstAddr     Base virtual address
1701  *  @param      nSegs       Number of given segments
1702  *  @param      sglist      Segment list
1703  */
1704 Int
1705 VAYUDSPPROC_map(
1706         Processor_Handle    handle,
1707         UInt32 *            dstAddr,
1708         UInt32              nSegs,
1709         Memory_SGList *     sglist)
1711     Int                         status = PROCESSOR_SUCCESS;
1712     Processor_Object *          procHandle = (Processor_Object *)handle;
1713     VAYUDSPPROC_Object *        object = NULL;
1714     Bool                        found = FALSE;
1715     UInt32                      startAddr;
1716     UInt32                      endAddr;
1717     UInt32                      i;
1718     UInt32                      j;
1719     ProcMgr_AddrInfo *          ai = NULL;
1721     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_map",
1722                handle, dstAddr, nSegs, sglist);
1724     GT_assert (curTrace, (handle != NULL));
1725     GT_assert (curTrace, (sglist != NULL));
1726     GT_assert (curTrace, (nSegs > 0));
1728 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1729     if (handle == NULL) {
1730         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1731         status = PROCESSOR_E_HANDLE;
1732         GT_setFailureReason (curTrace,
1733                              GT_4CLASS,
1734                              "VAYUDSPPROC_map",
1735                              status,
1736                              "Invalid handle specified");
1737     }
1738     else if (sglist == NULL) {
1739         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1740         status = PROCESSOR_E_INVALIDARG;
1741         GT_setFailureReason (curTrace,
1742                              GT_4CLASS,
1743                              "VAYUDSPPROC_map",
1744                              status,
1745                              "sglist provided as NULL");
1746     }
1747     else if (nSegs == 0) {
1748         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1749         status = PROCESSOR_E_INVALIDARG;
1750         GT_setFailureReason (curTrace,
1751                              GT_4CLASS,
1752                              "VAYUDSPPROC_map",
1753                              status,
1754                              "Number of segments provided is 0");
1755     }
1756     else {
1757 #endif
1758         object = (VAYUDSPPROC_Object *)procHandle->object;
1759         GT_assert (curTrace, (object != NULL));
1761         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1762             /* Update the translation table with entries for which mapping
1763              * is required. Add the entry only if the range does not exist
1764              * in the translation table.
1765              */
1766             for (j = 0;
1767                 j < AddrTable_count[PROCID_TO_DSP(procHandle->procId)]; j++) {
1768                 ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][j];
1770                 if (ai->isMapped == TRUE) {
1771                     startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1772                     endAddr = startAddr + ai->size;
1774                     if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1775                         && ((*dstAddr + sglist[i].size) <= endAddr)) {
1776                         found = TRUE;
1777                         ai->refCount++;
1778                         break;
1779                     }
1780                 }
1781             }
1783             /* if not found and mmu is enabled, add new entry to table */
1784             if (!found) {
1785                 if (AddrTable_count[PROCID_TO_DSP(procHandle->procId)] !=
1786                     AddrTable_SIZE) {
1787                     ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)]
1788                         [AddrTable_count[PROCID_TO_DSP
1789                         (procHandle->procId)]];
1790                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1791                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1792                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1793                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1794                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1795                     ai->size = sglist[i].size;
1796                     ai->isCached = sglist[i].isCached;
1797                     ai->refCount++;
1798                     ai->isMapped = TRUE;
1800                     AddrTable_count[PROCID_TO_DSP(procHandle->procId)]++;
1801                 }
1802                 else {
1803                     status = PROCESSOR_E_FAIL;
1804                     GT_setFailureReason(curTrace, GT_4CLASS,
1805                         "VAYUDSPPROC_map", status,
1806                         "AddrTable_SIZE reached!");
1807                 }
1808             }
1809         }
1810 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1811     }
1812 #endif
1813     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_map", status);
1815     /*! @retval PROCESSOR_SUCCESS Operation successful */
1816     return status;
1820 /*!
1821  *  @brief      Function to unmap slave address from host address space
1822  *
1823  *  @param      handle      Handle to the Processor object
1824  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1825  *                          address.
1826  *  @param      size        Size of the region to be mapped.
1827  *
1828  *  @sa
1829  */
1830 Int
1831 VAYUDSPPROC_unmap(
1832         Processor_Handle    handle,
1833         UInt32              addr,
1834         UInt32              size)
1836     Int                         status = PROCESSOR_SUCCESS;
1837     Processor_Object *          procHandle = (Processor_Object *)handle;
1838     VAYUDSPPROC_Object *        object = NULL;
1839     ProcMgr_AddrInfo *          ai;
1840     Int                         i;
1841     UInt32                      startAddr;
1842     UInt32                      endAddr;
1843     VAYUDSP_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1845     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_unmap",
1846                handle, addr, size);
1848     GT_assert (curTrace, (handle != NULL));
1849     GT_assert (curTrace, (size   != 0));
1851 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1852     if (handle == NULL) {
1853         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1854         status = PROCESSOR_E_HANDLE;
1855         GT_setFailureReason (curTrace,
1856                              GT_4CLASS,
1857                              "VAYUDSPPROC_unmap",
1858                              status,
1859                              "Invalid handle specified");
1860     }
1861     else if (size == 0) {
1862         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1863         status = PROCESSOR_E_INVALIDARG;
1864         GT_setFailureReason (curTrace,
1865                              GT_4CLASS,
1866                              "VAYUDSPPROC_unmap",
1867                              status,
1868                              "Size provided is zero");
1869     }
1870     else {
1871 #endif
1872         object = (VAYUDSPPROC_Object *) procHandle->object;
1873         GT_assert (curTrace, (object != NULL));
1875         /* Delete entries from translation
1876          * table only in last unmap called on that entry
1877          */
1878         for (i = 0;
1879             i < AddrTable_count[PROCID_TO_DSP(procHandle->procId)]; i++) {
1880             ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][i];
1882             if (!ai->isMapped) {
1883                 continue;
1884             }
1886             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1887             endAddr = startAddr + ai->size;
1889             if ((startAddr <= addr) && (addr < endAddr)) {
1890                 ai->refCount--;
1892                 if (ai->refCount == 0) {
1893                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1894                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1895                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1896                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1897                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1898                     ai->size = 0u;
1899                     ai->isCached = FALSE;
1900                     ai->mapMask = 0u;
1901                     ai->isMapped = FALSE;
1903                     /* Remove the entry from the DSP MMU also */
1904                     deleteEntryArgs.size          = size;
1905                     deleteEntryArgs.slaveVirtAddr = addr;
1906                     /* TBD: elementSize, endianism, mixedSized are
1907                      * hard coded now, must be configurable later
1908                      */
1909                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
1910                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
1911                     deleteEntryArgs.mixedSize     = MMU_TLBES;
1913                     status = VAYUDSP_halMmuCtrl(object->halObject,
1914                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
1915 #if !defined(IPC_BUILD_OPTIMIZE)
1916                     if (status < 0) {
1917                         GT_setFailureReason(curTrace, GT_4CLASS,
1918                             "VAYUDSPPROC_unmap", status,
1919                             "DSP MMU configuration failed");
1920                     }
1921 #endif
1922                 }
1923             }
1924         }
1925 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1926     }
1927 #endif
1928     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_unmap", status);
1930     /*! @retval PROCESSOR_SUCCESS Operation successful */
1931     return status;
1935 #if defined (__cplusplus)
1937 #endif /* defined (__cplusplus) */