65bd52ac1760beb3455a385d5cdad06feb37461c
[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-2016, Texas Instruments Incorporated
15  *
16  *  Redistribution and use in source and binary forms, with or without
17  *  modification, are permitted provided that the following conditions
18  *  are met:
19  *
20  *  *  Redistributions of source code must retain the above copyright
21  *     notice, this list of conditions and the following disclaimer.
22  *
23  *  *  Redistributions in binary form must reproduce the above copyright
24  *     notice, this list of conditions and the following disclaimer in the
25  *     documentation and/or other materials provided with the distribution.
26  *
27  *  *  Neither the name of Texas Instruments Incorporated nor the names of
28  *     its contributors may be used to endorse or promote products derived
29  *     from this software without specific prior written permission.
30  *
31  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *  Contact information for paper mail:
43  *  Texas Instruments
44  *  Post Office Box 655303
45  *  Dallas, Texas 75265
46  *  Contact information:
47  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
48  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
49  *  ============================================================================
50  *
51  */
55 #include <ti/syslink/Std.h>
56 /* OSAL & Utils headers */
57 #include <ti/syslink/utils/Cfg.h>
58 #include <ti/syslink/utils/String.h>
59 #include <ti/syslink/utils/IGateProvider.h>
60 #include <ti/syslink/utils/GateMutex.h>
61 #include <ti/syslink/utils/Memory.h>
63 #include <string.h>
65 #include <ti/syslink/utils/Trace.h>
66 /* Module level headers */
67 #include <ProcDefs.h>
68 #include <Processor.h>
69 #include <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  */
90 /*!
91  *  @brief  Number of static entries in address translation table.
92  */
93 #define AddrTable_STATIC_COUNT 3
95 /*!
96  *  @brief  Max entries in address translation table.
97  */
98 #define AddrTable_SIZE 32
100 /* Number of DSPs supported */
101 #define NUM_DSPS 2
103 /* Convert procId to DSP # */
104 #define PROCID_TO_DSP(procId) (procId == VAYUDSPPROC_state.dsp1ProcId ?\
105     0 : 1)
108 /*!
109  *  @brief  VAYUDSPPROC Module state object
110  */
111 typedef struct VAYUDSPPROC_ModuleObject_tag {
112     UInt32              configSize;
113     /*!< Size of configuration structure */
114     VAYUDSPPROC_Config cfg;
115     /*!< VAYUDSPPROC configuration structure */
116     VAYUDSPPROC_Config defCfg;
117     /*!< Default module configuration */
118     VAYUDSPPROC_Params      defInstParams;
119     /*!< Default parameters for the VAYUDSPPROC instances */
120     Bool                isSetup;
121     /*!< Indicates whether the VAYUDSPPROC module is setup. */
122     VAYUDSPPROC_Handle procHandles [MultiProc_MAXPROCESSORS];
123     /*!< Processor handle array. */
124     IGateProvider_Handle         gateHandle;
125     /*!< Handle of gate to be used for local thread safety */
126     UInt16                     dsp1ProcId;
127     /*!< MultiProc id of DSP1 (to avoid multiple lookups) */
128 } VAYUDSPPROC_ModuleObject;
130 /* Default memory regions */
131 static UInt32 AddrTable_count[NUM_DSPS] = {
132     AddrTable_STATIC_COUNT,
133     AddrTable_STATIC_COUNT
134 };
136 /*
137  * Address translation table
138  * static memory regions
139  * CAUTION: AddrTable_STATIC_COUNT must match number of entries below.
140  */
141 static ProcMgr_AddrInfo AddrTable_DSP1[AddrTable_SIZE] =
142     {
143         /* L2 RAM */
144         {
145             .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
146             .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
147             .addr[ProcMgr_AddrType_MasterPhys] = 0x40800000u,
148             .addr[ProcMgr_AddrType_SlaveVirt] = 0x800000u,
149             .addr[ProcMgr_AddrType_SlavePhys] = -1u,
150             .size = 0x40000u,
151             .isCached = FALSE,
152             .mapMask = ProcMgr_SLAVEVIRT,
153             .isMapped = TRUE,
154             .refCount = 0u      /* refCount set to 0 for static entry */
155         },
157         /* L1P RAM */
158         {
159             .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
160             .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
161             .addr[ProcMgr_AddrType_MasterPhys] = 0x40E00000u,
162             .addr[ProcMgr_AddrType_SlaveVirt] = 0xE00000u,
163             .addr[ProcMgr_AddrType_SlavePhys] = -1u,
164             .size = 0x8000u,
165             .isCached = FALSE,
166             .mapMask = ProcMgr_SLAVEVIRT,
167             .isMapped = TRUE,
168             .refCount = 0u      /* refCount set to 0 for static entry */
169         },
171         /* L1D RAM */
172         {
173             .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
174             .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
175             .addr[ProcMgr_AddrType_MasterPhys] = 0x40F00000u,
176             .addr[ProcMgr_AddrType_SlaveVirt] = 0xF00000u,
177             .addr[ProcMgr_AddrType_SlavePhys] = -1u,
178             .size = 0x8000u,
179             .isCached = FALSE,
180             .mapMask = ProcMgr_SLAVEVIRT,
181             .isMapped = TRUE,
182             .refCount = 0u      /* refCount set to 0 for static entry */
183         },
184     };
186 static ProcMgr_AddrInfo AddrTable_DSP2[AddrTable_SIZE] =
187     {
188         /* L2 RAM */
189         {
190             .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
191             .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
192             .addr[ProcMgr_AddrType_MasterPhys] = 0x41000000u,
193             .addr[ProcMgr_AddrType_SlaveVirt] = 0x800000u,
194             .addr[ProcMgr_AddrType_SlavePhys] = -1u,
195             .size = 0x40000u,
196             .isCached = FALSE,
197             .mapMask = ProcMgr_SLAVEVIRT,
198             .isMapped = TRUE,
199             .refCount = 0u      /* refCount set to 0 for static entry */
200         },
202         /* L1P RAM */
203         {
204             .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
205             .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
206             .addr[ProcMgr_AddrType_MasterPhys] = 0x41600000u,
207             .addr[ProcMgr_AddrType_SlaveVirt] = 0xE00000u,
208             .addr[ProcMgr_AddrType_SlavePhys] = -1u,
209             .size = 0x8000u,
210             .isCached = FALSE,
211             .mapMask = ProcMgr_SLAVEVIRT,
212             .isMapped = TRUE,
213             .refCount = 0u      /* refCount set to 0 for static entry */
214         },
216         /* L1D RAM */
217         {
218             .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
219             .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
220             .addr[ProcMgr_AddrType_MasterPhys] = 0x41700000u,
221             .addr[ProcMgr_AddrType_SlaveVirt] = 0xF00000u,
222             .addr[ProcMgr_AddrType_SlavePhys] = -1u,
223             .size = 0x8000u,
224             .isCached = FALSE,
225             .mapMask = ProcMgr_SLAVEVIRT,
226             .isMapped = TRUE,
227             .refCount = 0u      /* refCount set to 0 for static entry */
228         },
229     };
231 static ProcMgr_AddrInfo * AddrTable[NUM_DSPS] =
233     AddrTable_DSP1,
234     AddrTable_DSP2
235 };
237 /* =============================================================================
238  *  Globals
239  * =============================================================================
240  */
242 /*!
243  *  @var    VAYUDSPPROC_state
244  *
245  *  @brief  VAYUDSPPROC state object variable
246  */
247 #if !defined(IPC_BUILD_DEBUG)
248 static
249 #endif /* if !defined(IPC_BUILD_DEBUG) */
250 VAYUDSPPROC_ModuleObject VAYUDSPPROC_state =
252     .isSetup = FALSE,
253     .configSize = sizeof(VAYUDSPPROC_Config),
254     .gateHandle = NULL,
255     .defInstParams.numMemEntries = AddrTable_STATIC_COUNT
256 };
259 /* =============================================================================
260  * APIs directly called by applications
261  * =============================================================================
262  */
263 /*!
264  *  @brief      Function to get the default configuration for the VAYUDSPPROC
265  *              module.
266  *
267  *              This function can be called by the application to get their
268  *              configuration parameter to VAYUDSPPROC_setup filled in by the
269  *              VAYUDSPPROC module with the default parameters. If the user
270  *              does not wish to make any change in the default parameters, this
271  *              API is not required to be called.
272  *
273  *  @param      cfg        Pointer to the VAYUDSPPROC module configuration
274  *                         structure in which the default config is to be
275  *                         returned.
276  *
277  *  @sa         VAYUDSPPROC_setup
278  */
279 Void
280 VAYUDSPPROC_getConfig (VAYUDSPPROC_Config * cfg)
282     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_getConfig", cfg);
284     GT_assert (curTrace, (cfg != NULL));
286 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
287     if (cfg == NULL) {
288         GT_setFailureReason (curTrace,
289                              GT_4CLASS,
290                              "VAYUDSPPROC_getConfig",
291                              PROCESSOR_E_INVALIDARG,
292                              "Argument of type (VAYUDSPPROC_Config *) passed "
293                              "is null!");
294     }
295     else {
296 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
297         Memory_copy (cfg,
298                      &(VAYUDSPPROC_state.defCfg),
299                      sizeof (VAYUDSPPROC_Config));
300 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
301     }
302 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
304     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_getConfig");
308 /*!
309  *  @brief      Function to setup the VAYUDSPPROC module.
310  *
311  *              This function sets up the VAYUDSPPROC module. This function
312  *              must be called before any other instance-level APIs can be
313  *              invoked.
314  *              Module-level configuration needs to be provided to this
315  *              function. If the user wishes to change some specific config
316  *              parameters, then VAYUDSPPROC_getConfig can be called to get the
317  *              configuration filled with the default values. After this, only
318  *              the required configuration values can be changed. If the user
319  *              does not wish to make any change in the default parameters, the
320  *              application can simply call VAYUDSPPROC_setup with NULL
321  *              parameters. The default parameters would get automatically used.
322  *
323  *  @param      cfg   Optional VAYUDSPPROC module configuration. If provided as
324  *                    NULL, default configuration is used.
325  *
326  *  @sa         VAYUDSPPROC_destroy
327  *              GateMutex_create
328  */
329 Int
330 VAYUDSPPROC_setup (VAYUDSPPROC_Config * cfg)
332     Int                  status = PROCESSOR_SUCCESS;
333     VAYUDSPPROC_Config   tmpCfg;
334     Error_Block          eb;
336     Error_init(&eb);
338     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_setup", cfg);
340     if (cfg == NULL) {
341         VAYUDSPPROC_getConfig (&tmpCfg);
342         cfg = &tmpCfg;
343     }
345     /* Create a default gate handle for local module protection. */
346     VAYUDSPPROC_state.gateHandle = (IGateProvider_Handle)
347                                GateMutex_create ((GateMutex_Params *)NULL, &eb);
348 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
349     if (VAYUDSPPROC_state.gateHandle == NULL) {
350         /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
351         status = PROCESSOR_E_FAIL;
352         GT_setFailureReason (curTrace,
353                              GT_4CLASS,
354                              "VAYUDSPPROC_setup",
355                              status,
356                              "Failed to create GateMutex!");
357     }
358     else {
359 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
360         /* Copy the user provided values into the state object. */
361         Memory_copy (&VAYUDSPPROC_state.cfg,
362                      cfg,
363                      sizeof (VAYUDSPPROC_Config));
365         /* Initialize the name to handles mapping array. */
366         Memory_set (&VAYUDSPPROC_state.procHandles,
367                     0,
368                     (sizeof (VAYUDSPPROC_Handle) * MultiProc_MAXPROCESSORS));
370         VAYUDSPPROC_state.dsp1ProcId = MultiProc_getId("DSP1");
371         VAYUDSPPROC_state.isSetup = TRUE;
372 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
373     }
374 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
376     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_setup", status);
378     /*! @retval PROCESSOR_SUCCESS Operation successful */
379     return (status);
383 /*!
384  *  @brief      Function to destroy the VAYUDSPPROC module.
385  *
386  *              Once this function is called, other VAYUDSPPROC module APIs,
387  *              except for the VAYUDSPPROC_getConfig API cannot be called
388  *              anymore.
389  *
390  *  @sa         VAYUDSPPROC_setup
391  *              GateMutex_delete
392  */
393 Int
394 VAYUDSPPROC_destroy (Void)
396     Int    status = PROCESSOR_SUCCESS;
397     UInt16 i;
399     GT_0trace (curTrace, GT_ENTER, "VAYUDSPPROC_destroy");
401     /* Check if any VAYUDSPPROC instances have not been deleted so far. If not,
402      * delete them.
403      */
404     for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
405         GT_assert (curTrace, (VAYUDSPPROC_state.procHandles [i] == NULL));
406         if (VAYUDSPPROC_state.procHandles [i] != NULL) {
407             VAYUDSPPROC_delete (&(VAYUDSPPROC_state.procHandles [i]));
408         }
409     }
411     if (VAYUDSPPROC_state.gateHandle != NULL) {
412         GateMutex_delete ((GateMutex_Handle *)
413                                 &(VAYUDSPPROC_state.gateHandle));
414     }
416     VAYUDSPPROC_state.isSetup = FALSE;
418     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_destroy", status);
420     /*! @retval PROCESSOR_SUCCESS Operation successful */
421     return (status);
425 /*!
426  *  @brief      Function to initialize the parameters for this Processor
427  *              instance.
428  *
429  *  @param      params  Configuration parameters to be returned
430  *
431  *  @sa         VAYUDSPPROC_create
432  */
433 Void
434 VAYUDSPPROC_Params_init(
435         VAYUDSPPROC_Handle    handle,
436         VAYUDSPPROC_Params *  params)
438     VAYUDSPPROC_Object * procObject = (VAYUDSPPROC_Object *) handle;
440     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_Params_init", handle, params);
442     GT_assert (curTrace, (params != NULL));
444 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
445     if (params == NULL) {
446         GT_setFailureReason (curTrace,
447                              GT_4CLASS,
448                              "VAYUDSPPROC_Params_init",
449                              PROCESSOR_E_INVALIDARG,
450                              "Argument of type (VAYUDSPPROC_Params *) "
451                              "passed is null!");
452     }
453     else {
454 #endif
455         if (handle == NULL) {
457             Memory_copy(params, &(VAYUDSPPROC_state.defInstParams),
458                 sizeof(VAYUDSPPROC_Params));
459         }
460         else {
461             /* return updated VAYUDSPPROC instance specific parameters */
462             Memory_copy(params, &(procObject->params), sizeof(VAYUDSPPROC_Params));
463         }
464 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
465     }
466 #endif
468     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_Params_init");
471 /*!
472  *  @brief      Function to create an instance of this Processor.
473  *
474  *  @param      name    Name of the Processor instance.
475  *  @param      params  Configuration parameters.
476  *
477  *  @sa         VAYUDSPPROC_delete
478  */
479 VAYUDSPPROC_Handle
480 VAYUDSPPROC_create (      UInt16                procId,
481                      const VAYUDSPPROC_Params * params)
483     Int                   status    = PROCESSOR_SUCCESS;
484     Processor_Object *    handle    = NULL;
485     VAYUDSPPROC_Object *  object    = NULL;
486     Int i                            = 0;
487     ProcMgr_AddrInfo *ai             = NULL;
488     IArg                  key;
489     List_Params           listParams;
491     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_create", procId, params);
493     GT_assert (curTrace, IS_VALID_PROCID (procId));
494     GT_assert (curTrace, (params != NULL));
496 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
497     if (!IS_VALID_PROCID (procId)) {
498         /* Not setting status here since this function does not return status.*/
499         GT_setFailureReason (curTrace,
500                              GT_4CLASS,
501                              "VAYUDSPPROC_create",
502                              PROCESSOR_E_INVALIDARG,
503                              "Invalid procId specified");
504     }
505     else if (params == NULL) {
506         GT_setFailureReason (curTrace,
507                              GT_4CLASS,
508                              "VAYUDSPPROC_create",
509                              PROCESSOR_E_INVALIDARG,
510                              "params passed is NULL!");
511     }
512     else {
513 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
514         /* Enter critical section protection. */
515         key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
516 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
517         /* Check if the Processor already exists for specified procId. */
518         if (VAYUDSPPROC_state.procHandles [procId] != NULL) {
519             status = PROCESSOR_E_ALREADYEXIST;
520             GT_setFailureReason (curTrace,
521                               GT_4CLASS,
522                               "VAYUDSPPROC_create",
523                               status,
524                               "Processor already exists for specified procId!");
525         }
526         else {
527 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
528             /* Allocate memory for the handle */
529             handle = (Processor_Object *) Memory_calloc (NULL,
530                                                       sizeof (Processor_Object),
531                                                       0,
532                                                       NULL);
533             if (handle == NULL) {
534                 GT_setFailureReason (curTrace,
535                                      GT_4CLASS,
536                                      "VAYUDSPPROC_create",
537                                      PROCESSOR_E_MEMORY,
538                                      "Memory allocation failed for handle!");
539             }
540             else {
541                 /* Populate the handle fields */
542                 handle->procFxnTable.attach        = &VAYUDSPPROC_attach;
543                 handle->procFxnTable.detach        = &VAYUDSPPROC_detach;
544                 handle->procFxnTable.start         = &VAYUDSPPROC_start;
545                 handle->procFxnTable.stop          = &VAYUDSPPROC_stop;
546                 handle->procFxnTable.read          = &VAYUDSPPROC_read;
547                 handle->procFxnTable.write         = &VAYUDSPPROC_write;
548                 handle->procFxnTable.control       = &VAYUDSPPROC_control;
549                 handle->procFxnTable.map           = &VAYUDSPPROC_map;
550                 handle->procFxnTable.unmap         = &VAYUDSPPROC_unmap;
551                 handle->procFxnTable.translateAddr = &VAYUDSPPROC_translate;
552                 handle->procFxnTable.translateFromPte = NULL;
554                 handle->state = ProcMgr_State_Unknown;
556                 /* Allocate memory for the VAYUDSPPROC handle */
557                 handle->object = Memory_calloc (NULL,
558                                                 sizeof (VAYUDSPPROC_Object),
559                                                 0,
560                                                 NULL);
561                 if (handle->object == NULL) {
562                     status = PROCESSOR_E_MEMORY;
563                     GT_setFailureReason (curTrace,
564                                 GT_4CLASS,
565                                 "VAYUDSPPROC_create",
566                                 status,
567                                 "Memory allocation failed for handle->object!");
568                 }
569                 else {
570                     handle->procId = procId;
571                     object = (VAYUDSPPROC_Object *) handle->object;
572                     object->halObject = NULL;
573                     object->procHandle = (Processor_Handle)handle;
574                     /* Copy params into instance object. */
575                     Memory_copy (&(object->params),
576                                  (Ptr) params,
577                                  sizeof (VAYUDSPPROC_Params));
579                     /* initialize the translation table */
580                     for (i = AddrTable_count[PROCID_TO_DSP(procId)];
581                         i < AddrTable_SIZE; i++) {
582                         ai = &AddrTable[PROCID_TO_DSP(procId)][i];
583                         ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
584                         ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
585                         ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
586                         ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
587                         ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
588                         ai->size = 0u;
589                         ai->isCached = FALSE;
590                         ai->mapMask = 0u;
591                         ai->isMapped = FALSE;
592                     }
594                     /*
595                      * initialize refCount for all entries
596                      */
597                     for (i = 0; i < AddrTable_SIZE; i++) {
598                         AddrTable[PROCID_TO_DSP(procId)][i].refCount = 0u;
599                     }
600                     Memory_copy((Ptr)(object->params.memEntries),
601                         AddrTable[PROCID_TO_DSP(procId)],
602                         (procId == VAYUDSPPROC_state.dsp1ProcId ?
603                         sizeof(AddrTable_DSP1) : sizeof(AddrTable_DSP2)));
605                     /* Set the handle in the state object. */
606                     VAYUDSPPROC_state.procHandles [procId] =
607                                                      (VAYUDSPPROC_Handle) object;
608                     /* Initialize the list of listeners */
609                     List_Params_init(&listParams);
610                     handle->registeredNotifiers = List_create(&listParams);
612 #if !defined(IPC_BUILD_OPTIMIZE)
613                     if (handle->registeredNotifiers == NULL) {
614                         /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
615                         status = PROCESSOR_E_FAIL;
616                         GT_setFailureReason (curTrace,
617                                              GT_4CLASS,
618                                              "VAYUDSPPROC_create",
619                                              status,
620                                              "List_create failed");
621                     }
622                     else {
623 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
625                         handle->notifiersLock =
626                                  OsalMutex_create(OsalMutex_Type_Interruptible);
628 #if !defined(IPC_BUILD_OPTIMIZE)
629                         if (handle->notifiersLock == NULL) {
630                             /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
631                             status = PROCESSOR_E_FAIL;
632                             GT_setFailureReason (curTrace,
633                                                  GT_4CLASS,
634                                                  "VAYUDSPPROC_create",
635                                                  status,
636                                                  "OsalMutex_create failed");
637                         }
638                     }
639 #endif /* if !defined(IPC_BUILD_OPTIMIZE) */
640                 }
641             }
642 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
643         }
644 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
646         /* Leave critical section protection. */
647         IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
648 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
649     }
650 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
652     if (status < 0) {
653         if (handle !=  NULL) {
654             if (handle->registeredNotifiers != NULL) {
655                 List_delete (&handle->registeredNotifiers);
656             }
657             if (handle->object != NULL) {
658                 Memory_free (NULL,
659                              handle->object,
660                              sizeof (VAYUDSPPROC_Object));
661             }
662             Memory_free (NULL, handle, sizeof (Processor_Object));
663         }
664         /*! @retval NULL Function failed */
665         handle = NULL;
666     }
667     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_create", handle);
669     /*! @retval Valid-Handle Operation successful */
670     return (VAYUDSPPROC_Handle) handle;
674 /*!
675  *  @brief      Function to delete an instance of this Processor.
676  *
677  *              The user provided pointer to the handle is reset after
678  *              successful completion of this function.
679  *
680  *  @param      handlePtr  Pointer to Handle to the Processor instance
681  *
682  *  @sa         VAYUDSPPROC_create
683  */
684 Int
685 VAYUDSPPROC_delete (VAYUDSPPROC_Handle * handlePtr)
687     Int                   status = PROCESSOR_SUCCESS;
688     VAYUDSPPROC_Object *  object = NULL;
689     Processor_Object *    handle;
690     IArg                  key;
691     List_Elem *           elem    = NULL;
692     Processor_RegisterElem * regElem = NULL;
694     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_delete", handlePtr);
696     GT_assert (curTrace, (handlePtr != NULL));
697     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
699 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
700     if (handlePtr == NULL) {
701         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
702                                          specified*/
703         status = PROCESSOR_E_INVALIDARG;
704         GT_setFailureReason (curTrace,
705                              GT_4CLASS,
706                              "VAYUDSPPROC_delete",
707                              status,
708                              "Invalid NULL handlePtr pointer specified");
709     }
710     else if (*handlePtr == NULL) {
711         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
712         status = PROCESSOR_E_HANDLE;
713         GT_setFailureReason (curTrace,
714                              GT_4CLASS,
715                              "VAYUDSPPROC_delete",
716                              status,
717                              "Invalid NULL *handlePtr specified");
718     }
719     else {
720 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
721         handle = (Processor_Object *) (*handlePtr);
722         /* Enter critical section protection. */
723         key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
725         /* Reset handle in PwrMgr handle array. */
726         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
727         VAYUDSPPROC_state.procHandles [handle->procId] = NULL;
729         /* Free memory used for the VAYUDSPPROC object. */
730         if (handle->object != NULL) {
731             object = (VAYUDSPPROC_Object *) handle->object;
732             Memory_free (NULL,
733                          object,
734                          sizeof (VAYUDSPPROC_Object));
735             handle->object = NULL;
736         }
738         /*
739          * Check the list of listeners to see if any are remaining
740          * and reply to them
741          */
742         OsalMutex_delete(&handle->notifiersLock);
744         while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
745             regElem = (Processor_RegisterElem *)elem;
747             /* Check if there is an associated timer and cancel it */
748             if (regElem->timer != -1) {
749                 struct itimerspec value ;
750                 value.it_value.tv_sec = 0;
751                 value.it_value.tv_nsec = 0;
752                 value.it_interval.tv_sec = 0;
753                 value.it_interval.tv_nsec = 0;
754                 timer_settime(regElem->timer, 0, &value, NULL);
756                 timer_delete(regElem->timer);
757                 regElem->timer = -1;
758             }
760             /* Call the callback function so it can clean up. */
761             regElem->info->cbFxn(handle->procId,
762                                  NULL,
763                                  handle->state,
764                                  handle->state,
765                                  ProcMgr_EventStatus_Canceled,
766                                  regElem->info->arg);
767             /* Free the memory */
768             Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
769         }
771         /* Delete the list of listeners */
772         List_delete(&handle->registeredNotifiers);
774         /* Free memory used for the Processor object. */
775         Memory_free (NULL, handle, sizeof (Processor_Object));
776         *handlePtr = NULL;
778         /* Leave critical section protection. */
779         IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
780 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
781     }
782 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
784     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_delete", status);
786     /*! @retval PROCESSOR_SUCCESS Operation successful */
787     return (status);
791 /*!
792  *  @brief      Function to open a handle to an instance of this Processor. This
793  *              function is called when access to the Processor is required from
794  *              a different process.
795  *
796  *  @param      handlePtr   Handle to the Processor instance
797  *  @param      procId      Processor ID addressed by this Processor instance.
798  *
799  *  @sa         VAYUDSPPROC_close
800  */
801 Int
802 VAYUDSPPROC_open (VAYUDSPPROC_Handle * handlePtr, UInt16 procId)
804     Int status = PROCESSOR_SUCCESS;
806     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_open", handlePtr, procId);
808     GT_assert (curTrace, (handlePtr != NULL));
809     GT_assert (curTrace, IS_VALID_PROCID (procId));
811 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
812     if (handlePtr == NULL) {
813         /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
814         status = PROCESSOR_E_HANDLE;
815         GT_setFailureReason (curTrace,
816                              GT_4CLASS,
817                              "VAYUDSPPROC_open",
818                              status,
819                              "Invalid NULL handlePtr specified");
820     }
821     else if (!IS_VALID_PROCID (procId)) {
822         /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
823         status = PROCESSOR_E_INVALIDARG;
824         GT_setFailureReason (curTrace,
825                              GT_4CLASS,
826                              "VAYUDSPPROC_open",
827                              status,
828                              "Invalid procId specified");
829     }
830     else {
831 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
832         /* Initialize return parameter handle. */
833         *handlePtr = NULL;
835         /* Check if the PwrMgr exists and return the handle if found. */
836         if (VAYUDSPPROC_state.procHandles [procId] == NULL) {
837             /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
838             status = PROCESSOR_E_NOTFOUND;
839             GT_setFailureReason (curTrace,
840                              GT_4CLASS,
841                              "VAYUDSPPROC_open",
842                              status,
843                              "Specified VAYUDSPPROC instance does not exist!");
844         }
845         else {
846             *handlePtr = VAYUDSPPROC_state.procHandles [procId];
847         }
848 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
849     }
850 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
852     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_open", status);
854     /*! @retval PROCESSOR_SUCCESS Operation successful */
855     return status;
859 /*!
860  *  @brief      Function to close a handle to an instance of this Processor.
861  *
862  *  @param      handlePtr  Pointer to Handle to the Processor instance
863  *
864  *  @sa         VAYUDSPPROC_open
865  */
866 Int
867 VAYUDSPPROC_close (VAYUDSPPROC_Handle * handlePtr)
869     Int status = PROCESSOR_SUCCESS;
871     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_close", handlePtr);
873     GT_assert (curTrace, (handlePtr != NULL));
874     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
876 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
877     if (handlePtr == NULL) {
878         /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
879                                          specified*/
880         status = PROCESSOR_E_INVALIDARG;
881         GT_setFailureReason (curTrace,
882                              GT_4CLASS,
883                              "VAYUDSPPROC_close",
884                              status,
885                              "Invalid NULL handlePtr pointer specified");
886     }
887     else if (*handlePtr == NULL) {
888         /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
889         status = PROCESSOR_E_HANDLE;
890         GT_setFailureReason (curTrace,
891                              GT_4CLASS,
892                              "VAYUDSPPROC_close",
893                              status,
894                              "Invalid NULL *handlePtr specified");
895     }
896     else {
897 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
898         /* Nothing to be done for close. */
899 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
900     }
901 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
903     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_close", status);
905     /*! @retval PROCESSOR_SUCCESS Operation successful */
906     return status;
910 /* =============================================================================
911  * APIs called by Processor module (part of function table interface)
912  * =============================================================================
913  */
914 /*!
915  *  @brief      Function to initialize the slave processor
916  *
917  *  @param      handle  Handle to the Processor instance
918  *  @param      params  Attach parameters
919  *
920  *  @sa         VAYUDSPPROC_detach
921  */
922 Int
923 VAYUDSPPROC_attach(
924         Processor_Handle            handle,
925         Processor_AttachParams *    params)
928     Int                         status = PROCESSOR_SUCCESS;
929     Processor_Object *          procHandle = (Processor_Object *)handle;
930     VAYUDSPPROC_Object *        object = NULL;
931     UInt32                      i = 0;
932     UInt32                      index = 0;
933     ProcMgr_AddrInfo *          me;
934     Ipc_MemEntry *              entry;
935     Ipc_MemEntry_Block          memBlock;
936     VAYUDSP_HalMmuCtrlArgs_Enable mmuEnableArgs;
937     VAYUDSP_HalParams           halParams;
939     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_attach", handle, params);
940     GT_assert (curTrace, (handle != NULL));
941     GT_assert (curTrace, (params != NULL));
943 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
944     if (handle == NULL) {
945         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
946         status = PROCESSOR_E_HANDLE;
947         GT_setFailureReason (curTrace,
948                              GT_4CLASS,
949                              "VAYUDSPPROC_attach",
950                              status,
951                              "Invalid handle specified");
952     }
953     else if (params == NULL) {
954             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
955             status = PROCESSOR_E_INVALIDARG;
956             GT_setFailureReason (curTrace,
957                                  GT_4CLASS,
958                                  "VAYUDSPPROC_attach",
959                                  status,
960                                  "Invalid params specified");
961     }
962     else {
963 #endif
964         object = (VAYUDSPPROC_Object *) procHandle->object;
965         GT_assert (curTrace, (object != NULL));
967         /* Initialize halObject */
968         halParams.procId = procHandle->procId;
969         status = VAYUDSP_halInit(&(object->halObject), &halParams);
971         if (status < 0) {
972             GT_setFailureReason(curTrace, GT_4CLASS,
973                 "VAYUDSPPROC_attach", status,
974                 "VAYUDSP_halInit failed");
975         }
976         params->procArch = Processor_ProcArch_C66x;
978         object->pmHandle = params->pmHandle;
979         GT_0trace(curTrace, GT_1CLASS,
980             "VAYUDSPPROC_attach: Mapping memory regions");
982         /* search for dsp memory map */
983         status = RscTable_process(procHandle->procId,
984                                   TRUE,
985                                   &memBlock.numEntries,
986                                   procHandle,
987                                   procHandle->bootMode);
988         if (status < 0 || memBlock.numEntries > IPC_MAX_MEMENTRIES) {
989             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
990             status = PROCESSOR_E_INVALIDARG;
991             GT_setFailureReason (curTrace,
992                                  GT_4CLASS,
993                                  "VAYUDSPPROC_attach",
994                                  status,
995                                  "Failed to process resource table");
996         }
997         else {
998             status = RscTable_getMemEntries(procHandle->procId,
999                                             memBlock.memEntries,
1000                                             &memBlock.numEntries);
1001             if (status < 0) {
1002                 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1003                 status = PROCESSOR_E_INVALIDARG;
1004                 GT_setFailureReason (curTrace,
1005                                      GT_4CLASS,
1006                                      "VAYUDSPPROC_attach",
1007                                      status,
1008                                      "Failed to get resource table memEntries");
1009             }
1010         }
1012         /* update translation tables with memory map */
1013         for (i = 0; (i < memBlock.numEntries)
1014             && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
1016             entry = &memBlock.memEntries[i];
1018             if (entry->map == FALSE) {
1019                 /* update table with entries which don't require mapping */
1020                 if (AddrTable_count[PROCID_TO_DSP(procHandle->procId)] !=
1021                    AddrTable_SIZE) {
1022                     me = &AddrTable[PROCID_TO_DSP(procHandle->procId)][
1023                         AddrTable_count[PROCID_TO_DSP(procHandle->procId)]];
1025                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1026                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1027                     me->addr[ProcMgr_AddrType_MasterPhys] =
1028                         entry->masterPhysAddr;
1029                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1030                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1031                     me->size = entry->size;
1032                     me->isCached = entry->isCached;
1033                     me->mapMask = entry->mapMask;
1035                     AddrTable_count[PROCID_TO_DSP(procHandle->procId)]++;
1036                 }
1037                 else {
1038                     status = PROCESSOR_E_FAIL;
1039                     GT_setFailureReason(curTrace, GT_4CLASS,
1040                         "VAYUDSPPROC_attach", status,
1041                         "AddrTable_SIZE reached!");
1042                 }
1043             }
1044             else if (entry->map == TRUE) {
1045                 /* send these entries back to ProcMgr for mapping */
1046                 index = object->params.numMemEntries;
1048                 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
1049                     me = &object->params.memEntries[index];
1051                     me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1052                     me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1053                     me->addr[ProcMgr_AddrType_MasterPhys] =
1054                         entry->masterPhysAddr;
1055                     me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1056                     me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1057                     me->size = entry->size;
1058                     me->isCached = entry->isCached;
1059                     me->mapMask = entry->mapMask;
1061                     object->params.numMemEntries++;
1062                 }
1063                 else {
1064                     status = PROCESSOR_E_FAIL;
1065                     GT_setFailureReason(curTrace, GT_4CLASS,
1066                         "VAYUDSPPROC_attach", status,
1067                         "ProcMgr_MAX_MEMORY_REGIONS reached!");
1068                 }
1069             }
1070             else {
1071                 status = PROCESSOR_E_INVALIDARG;
1072                 GT_setFailureReason(curTrace, GT_4CLASS,
1073                     "VAYUDSPPROC_attach", status,
1074                     "Memory map has entry with invalid 'map' value");
1075             }
1076         } /* for (...) */
1078         if (status >= 0) {
1079             /* populate the return params */
1080             params->numMemEntries = object->params.numMemEntries;
1081             memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1082                 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1085             /* Setup the xbar for MMU fault interrupts */
1086             GT_0trace(curTrace, GT_3CLASS,
1087                 "VAYUDSPPROC_attach: slave is now in reset");
1089             mmuEnableArgs.numMemEntries = 0;
1090             status = VAYUDSP_halMmuCtrl(object->halObject,
1091                 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1093             if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1094                 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1095 #if !defined(IPC_BUILD_OPTIMIZE)
1096                 if (status < 0) {
1097                     GT_setFailureReason(curTrace, GT_4CLASS,
1098                         "VAYUDSPPROC_attach", status,
1099                         "Failed to enable the slave MMU");
1100                 }
1101                 else {
1102 #endif
1103                     GT_0trace(curTrace, GT_2CLASS,
1104                         "VAYUDSPPROC_attach: Slave MMU "
1105                         "is configured!");
1107                     /*
1108                      * Pull DSP MMU out of reset to make internal
1109                      * memory "loadable"
1110                      */
1111                     status = VAYUDSP_halResetCtrl(
1112                         object->halObject,
1113                         Processor_ResetCtrlCmd_MMU_Release);
1114                     if (status < 0) {
1115                         /*! @retval status */
1116                         GT_setFailureReason(curTrace,
1117                             GT_4CLASS,
1118                             "VAYUDSP_halResetCtrl",
1119                             status,
1120                             "Reset MMU_Release failed");
1121                     }
1122 #if !defined(IPC_BUILD_OPTIMIZE)
1123                 }
1124 #endif
1125             }
1127         }
1128 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1129     }
1130 #endif
1132     GT_1trace(curTrace, GT_LEAVE,
1133         "VAYUDSPPROC_attach", status);
1135     /*! @retval PROCESSOR_SUCCESS Operation successful */
1136     return status;
1140 /*!
1141  *  @brief      Function to detach from the Processor.
1142  *
1143  *  @param      handle  Handle to the Processor instance
1144  *
1145  *  @sa         VAYUDSPPROC_attach
1146  */
1147 Int
1148 VAYUDSPPROC_detach (Processor_Handle handle)
1150     Int                   status       = PROCESSOR_SUCCESS;
1151     Int                   tmpStatus    = PROCESSOR_SUCCESS;
1152     Processor_Object *    procHandle   = (Processor_Object *) handle;
1153     VAYUDSPPROC_Object * object       = NULL;
1154     Int i                              = 0;
1155     ProcMgr_AddrInfo *    ai;
1157     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_detach", handle);
1159     GT_assert (curTrace, (handle != NULL));
1161 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1162     if (handle == NULL) {
1163         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1164         status = PROCESSOR_E_HANDLE;
1165         GT_setFailureReason (curTrace,
1166                              GT_4CLASS,
1167                              "VAYUDSPPROC_detach",
1168                              PROCESSOR_E_HANDLE,
1169                              "Invalid handle specified");
1170     }
1171     else {
1172 #endif
1173         object = (VAYUDSPPROC_Object *) procHandle->object;
1174         GT_assert (curTrace, (object != NULL));
1176         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1177             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1179             GT_0trace(curTrace, GT_2CLASS,
1180                 "VAYUDSPPROC_detach: Disabling Slave MMU ...");
1182             status = VAYUDSP_halResetCtrl(object->halObject,
1183                 Processor_ResetCtrlCmd_MMU_Reset);
1184 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1185             if (status < 0) {
1186                 /*! @retval status */
1187                 GT_setFailureReason (curTrace,
1188                                      GT_4CLASS,
1189                                      "VAYUDSP_halResetCtrl",
1190                                      status,
1191                                      "Reset MMU failed");
1192             }
1193 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1195             status = VAYUDSP_halMmuCtrl(object->halObject,
1196                 Processor_MmuCtrlCmd_Disable, NULL);
1198 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1199             if (status < 0) {
1200                 GT_setFailureReason(curTrace, GT_4CLASS,
1201                     "VAYUDSPPROC_detach", status,
1202                     "Failed to disable the slave MMU");
1203             }
1204 #endif
1205         }
1207         /* delete all dynamically added entries */
1208         for (i = AddrTable_STATIC_COUNT; i <
1209             AddrTable_count[PROCID_TO_DSP(procHandle->procId)]; i++) {
1210             ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][i];
1211             ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1212             ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1213             ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1214             ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1215             ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1216             ai->size = 0u;
1217             ai->isCached = FALSE;
1218             ai->mapMask = 0u;
1219             ai->isMapped = FALSE;
1220             ai->refCount = 0u;
1221         }
1222         object->params.numMemEntries = AddrTable_STATIC_COUNT;
1223         AddrTable_count[PROCID_TO_DSP(procHandle->procId)] = AddrTable_STATIC_COUNT;
1225         //No need to reset.. that will be done in STOP
1226         /*tmpStatus = VAYUDSP_halResetCtrl(object->halObject,
1227             VAYUDspHal_Reset_Detach);
1229         GT_0trace(curTrace, GT_2CLASS,
1230             "VAYUDSPPROC_detach: Slave processor is now in reset");*/
1232 #if !defined(IPC_BUILD_OPTIMIZE)
1233         if ((tmpStatus < 0) && (status >= 0)) {
1234             status = tmpStatus;
1235             GT_setFailureReason (curTrace,
1236                                  GT_4CLASS,
1237                                  "VAYUDSPPROC_detach",
1238                                  status,
1239                                  "Failed to reset the slave processor");
1240         }
1241 #endif
1243         GT_0trace (curTrace,
1244                    GT_2CLASS,
1245                    "    VAYUDSPPROC_detach: Unmapping memory regions\n");
1247         tmpStatus = VAYUDSP_halExit (object->halObject);
1248 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1249         if ((tmpStatus < 0) && (status >= 0)) {
1250             status = tmpStatus;
1251             GT_setFailureReason (curTrace,
1252                                  GT_4CLASS,
1253                                  "VAYUDSPPROC_detach",
1254                                  status,
1255                                  "Failed to finalize HAL object");
1256         }
1257     }
1258 #endif
1260     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_detach", status);
1262     /*! @retval PROCESSOR_SUCCESS Operation successful */
1263     return status;
1267 /*!
1268  *  @brief      Function to start the slave processor
1269  *
1270  *              Start the slave processor running from its entry point.
1271  *              Depending on the boot mode, this involves configuring the boot
1272  *              address and releasing the slave from reset.
1273  *
1274  *  @param      handle    Handle to the Processor instance
1275  *
1276  *  @sa         VAYUDSPPROC_stop, VAYUDSP_halBootCtrl, VAYUDSP_halResetCtrl
1277  */
1278 Int
1279 VAYUDSPPROC_start (Processor_Handle        handle,
1280                    UInt32                  entryPt,
1281                    Processor_StartParams * params)
1283     Int                   status        = PROCESSOR_SUCCESS ;
1284     Processor_Object *    procHandle    = (Processor_Object *) handle;
1285     VAYUDSPPROC_Object *  object        = NULL;
1287     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_start",
1288                handle, entryPt, params);
1290     GT_assert (curTrace, (handle != NULL));
1291     GT_assert (curTrace, (params != 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_start",
1300                              status,
1301                              "Invalid handle specified");
1302     }
1303     else if (params == NULL) {
1304             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1305             status = PROCESSOR_E_INVALIDARG;
1306             GT_setFailureReason (curTrace,
1307                                  GT_4CLASS,
1308                                  "VAYUDSPPROC_start",
1309                                  status,
1310                                  "Invalid params specified");
1311     }
1312     else {
1313 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1314         object = (VAYUDSPPROC_Object *) procHandle->object;
1315         GT_assert (curTrace, (object != NULL));
1316         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1317             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1318             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1319             /* Slave is to be started only for Boot mode and NoLoad mode. */
1320             /* Specify the DSP boot address in the boot config register */
1321             status = VAYUDSP_halBootCtrl (object->halObject,
1322                                         Processor_BootCtrlCmd_SetEntryPoint,
1323                                         (Ptr) entryPt);
1324 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1325             if (status < 0) {
1326                 GT_setFailureReason (curTrace,
1327                                      GT_4CLASS,
1328                                      "VAYUDSPPROC_start",
1329                                      status,
1330                                      "Failed to set slave boot entry point");
1331             }
1332             else {
1333 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1334                 status = rproc_dsp_setup(object->halObject,
1335                                          object->params.memEntries,
1336                                          object->params.numMemEntries);
1337                 if (status < 0) {
1338                     /*! @retval status */
1339                     GT_setFailureReason (curTrace,
1340                                          GT_4CLASS,
1341                                          "VAYUDSP_halResetCtrl",
1342                                          status,
1343                                          "rproc_dsp_setup failed");
1344                 }
1345                 /* release the slave cpu from reset */
1346                 if (status >= 0) {
1347                     status = VAYUDSP_halResetCtrl(object->halObject,
1348                                                 Processor_ResetCtrlCmd_Release);
1349 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1350                     if (status < 0) {
1351                         GT_setFailureReason (curTrace,
1352                                          GT_4CLASS,
1353                                          "VAYUDSPPROC_start",
1354                                          status,
1355                                          "Failed to release slave from reset");
1356                     }
1357 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1358                 }
1359 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1360             }
1361 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1362         }
1364 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1365     }
1366 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1368     if (status >= 0) {
1369         GT_0trace (curTrace,
1370                    GT_1CLASS,
1371                    "    VAYUDSPPROC_start: Slave successfully started!\n");
1372     }
1373     else {
1374         GT_0trace (curTrace,
1375                    GT_1CLASS,
1376                    "    VAYUDSPPROC_start: Slave could not be started!\n");
1377     }
1379     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_start", status);
1381     /*! @retval PROCESSOR_SUCCESS Operation successful */
1382     return status;
1386 /*!
1387  *  @brief      Function to stop the slave processor
1388  *
1389  *              Stop the execution of the slave processor. Depending on the boot
1390  *              mode, this may result in placing the slave processor in reset.
1391  *
1392  *  @param      handle    Handle to the Processor instance
1393  *
1394  *  @sa         VAYUDSPPROC_start, VAYUDSP_halResetCtrl
1395  */
1396 Int
1397 VAYUDSPPROC_stop (Processor_Handle handle)
1399     Int                   status       = PROCESSOR_SUCCESS ;
1400     Processor_Object *    procHandle   = (Processor_Object *) handle;
1401     VAYUDSPPROC_Object * object        = NULL;
1403     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_stop", handle);
1405     GT_assert (curTrace, (handle != NULL));
1407 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1408     if (handle == NULL) {
1409         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1410         status = PROCESSOR_E_HANDLE;
1411         GT_setFailureReason (curTrace,
1412                              GT_4CLASS,
1413                              "VAYUDSPPROC_stop",
1414                              status,
1415                              "Invalid handle specified");
1416     }
1417     else {
1418 #endif
1419         object = (VAYUDSPPROC_Object *) procHandle->object;
1420         GT_assert (curTrace, (object != NULL));
1422         /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1423         if (    (procHandle->bootMode == ProcMgr_BootMode_Boot)
1424             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1425             ||  (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1426             status = VAYUDSP_halResetCtrl(object->halObject,
1427                                           Processor_ResetCtrlCmd_Reset);
1429             GT_0trace (curTrace,
1430                        GT_1CLASS,
1431                        "    VAYUDSPPROC_stop: Slave is now in reset!\n");
1432 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1433             if (status < 0) {
1434                 GT_setFailureReason (curTrace,
1435                                      GT_4CLASS,
1436                                      "VAYUDSPPROC_stop",
1437                                      status,
1438                                      "Failed to place slave in reset");
1439             }
1440 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1441             rproc_dsp_destroy(object->halObject);
1442         }
1443 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1444     }
1445 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1446     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_stop", status);
1448     /*! @retval PROCESSOR_SUCCESS Operation successful */
1449     return status;
1453 /*!
1454  *  @brief      Function to read from the slave processor's memory.
1455  *
1456  *              Read from the slave processor's memory and copy into the
1457  *              provided buffer.
1458  *
1459  *  @param      handle     Handle to the Processor instance
1460  *  @param      procAddr   Address in host processor's address space of the
1461  *                         memory region to read from.
1462  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1463  *                         number of bytes to be read. When the function
1464  *                         returns, this parameter contains the number of bytes
1465  *                         actually read.
1466  *  @param      buffer     User-provided buffer in which the slave processor's
1467  *                         memory contents are to be copied.
1468  *
1469  *  @sa         VAYUDSPPROC_write
1470  */
1471 Int
1472 VAYUDSPPROC_read (Processor_Handle   handle,
1473                   UInt32             procAddr,
1474                   UInt32 *           numBytes,
1475                   Ptr                buffer)
1477     Int       status   = PROCESSOR_SUCCESS ;
1478     UInt8  *  procPtr8 = NULL;
1480     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_read",
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_read",
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_read",
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_read",
1512                                  status,
1513                                  "Invalid buffer specified");
1514     }
1515     else {
1516 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1517         procPtr8 = (UInt8 *) procAddr ;
1518         buffer = Memory_copy (buffer, procPtr8, *numBytes);
1519         GT_assert (curTrace, (buffer != (UInt32) NULL));
1520 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1521         if (buffer == (UInt32) NULL) {
1522             /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1523             status = PROCESSOR_E_FAIL;
1524             GT_setFailureReason (curTrace,
1525                                  GT_4CLASS,
1526                                  "VAYUDSPPROC_read",
1527                                  status,
1528                                  "Failed in Memory_copy");
1529             *numBytes = 0;
1530         }
1531     }
1532 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1534     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_read",status);
1536     /*! @retval PROCESSOR_SUCCESS Operation successful */
1537     return status;
1541 /*!
1542  *  @brief      Function to write into the slave processor's memory.
1543  *
1544  *              Read from the provided buffer and copy into the slave
1545  *              processor's memory.
1546  *
1547  *  @param      handle     Handle to the Processor object
1548  *  @param      procAddr   Address in host processor's address space of the
1549  *                         memory region to write into.
1550  *  @param      numBytes   IN/OUT parameter. As an IN-parameter, it takes in the
1551  *                         number of bytes to be written. When the function
1552  *                         returns, this parameter contains the number of bytes
1553  *                         actually written.
1554  *  @param      buffer     User-provided buffer from which the data is to be
1555  *                         written into the slave processor's memory.
1556  *
1557  *  @sa         VAYUDSPPROC_read, VAYUDSPPROC_translateAddr
1558  */
1559 Int
1560 VAYUDSPPROC_write (Processor_Handle handle,
1561                    UInt32           procAddr,
1562                    UInt32 *         numBytes,
1563                    Ptr              buffer)
1565     Int                   status       = PROCESSOR_SUCCESS ;
1566     UInt8  *              procPtr8     = NULL;
1567     UInt8                 temp8_1;
1568     UInt8                 temp8_2;
1569     UInt8                 temp8_3;
1570     UInt8                 temp8_4;
1571     UInt32                temp;
1573     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_write",
1574                handle, procAddr, numBytes, buffer);
1576     GT_assert (curTrace, (handle   != NULL));
1577     GT_assert (curTrace, (numBytes != NULL));
1578     GT_assert (curTrace, (buffer   != NULL));
1580 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1581     if (handle == NULL) {
1582         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1583         status = PROCESSOR_E_HANDLE;
1584         GT_setFailureReason (curTrace,
1585                              GT_4CLASS,
1586                              "VAYUDSPPROC_write",
1587                              status,
1588                              "Invalid handle specified");
1589     }
1590     else if (numBytes == 0) {
1591             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1592             status = PROCESSOR_E_INVALIDARG;
1593             GT_setFailureReason (curTrace,
1594                                  GT_4CLASS,
1595                                  "VAYUDSPPROC_write",
1596                                  status,
1597                                  "Invalid numBytes specified");
1598     }
1599     else if (buffer == NULL) {
1600             /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1601             status = PROCESSOR_E_INVALIDARG;
1602             GT_setFailureReason (curTrace,
1603                                  GT_4CLASS,
1604                                  "VAYUDSPPROC_write",
1605                                  status,
1606                                  "Invalid buffer specified");
1607     }
1608     else {
1609 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1610         if (*numBytes != sizeof (UInt32)) {
1611             procPtr8 = (UInt8 *) procAddr ;
1612             procAddr = (UInt32) Memory_copy (procPtr8,
1613                                              buffer,
1614                                              *numBytes);
1615             GT_assert (curTrace, (procAddr != (UInt32) NULL));
1616 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1617             if (procAddr == (UInt32) NULL) {
1618                 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1619                 status = PROCESSOR_E_FAIL;
1620                 GT_setFailureReason (curTrace,
1621                                      GT_4CLASS,
1622                                      "VAYUDSPPROC_write",
1623                                      status,
1624                                      "Failed in Memory_copy");
1625                 *numBytes = 0;
1626             }
1627 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1628         }
1629         else  {
1630              /* For 4 bytes, directly write as a UInt32 */
1631             temp8_1 = ((UInt8 *) buffer) [0];
1632             temp8_2 = ((UInt8 *) buffer) [1];
1633             temp8_3 = ((UInt8 *) buffer) [2];
1634             temp8_4 = ((UInt8 *) buffer) [3];
1635             temp = (UInt32) (    ((UInt32) temp8_4 << 24)
1636                              |   ((UInt32) temp8_3 << 16)
1637                              |   ((UInt32) temp8_2 << 8)
1638                              |   ((UInt32) temp8_1));
1639             *((UInt32*) procAddr) = temp;
1640         }
1641 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1642     }
1643 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1645     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_write",status);
1647     /*! @retval PROCESSOR_SUCCESS Operation successful */
1648     return status;
1652 /*!
1653  *  @brief      Function to perform device-dependent operations.
1654  *
1655  *              Performs device-dependent control operations as exposed by this
1656  *              implementation of the Processor module.
1657  *
1658  *  @param      handle     Handle to the Processor object
1659  *  @param      cmd        Device specific processor command
1660  *  @param      arg        Arguments specific to the type of command.
1661  *
1662  *  @sa
1663  */
1664 Int
1665 VAYUDSPPROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1667     Int                   status       = PROCESSOR_SUCCESS ;
1669     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_control", handle, cmd, arg);
1671     GT_assert (curTrace, (handle   != NULL));
1672     /* cmd and arg can be 0/NULL, so cannot check for validity. */
1674 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1675     if (handle == NULL) {
1676         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1677         status = PROCESSOR_E_HANDLE;
1678         GT_setFailureReason (curTrace,
1679                              GT_4CLASS,
1680                              "VAYUDSPPROC_control",
1681                              status,
1682                              "Invalid handle specified");
1683     }
1684     else {
1685 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1686         /* No control operations currently implemented. */
1687         /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1688                                              for this device. */
1689         status = PROCESSOR_E_NOTSUPPORTED;
1690 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1691     }
1692 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1693     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_control",status);
1695     /*! @retval PROCESSOR_SUCCESS Operation successful */
1696     return status;
1700 /*!
1701  *  @brief      Translate slave virtual address to master physical address.
1702  *
1703  *  @param      handle     Handle to the Processor object
1704  *  @param      dstAddr    Returned: master physical address.
1705  *  @param      srcAddr    Slave virtual address.
1706  *
1707  *  @sa
1708  */
1709 Int
1710 VAYUDSPPROC_translate(
1711         Processor_Handle    handle,
1712         UInt32 *            dstAddr,
1713         UInt32              srcAddr)
1715     Int                         status = PROCESSOR_SUCCESS;
1716     Processor_Object *          procHandle= (Processor_Object *)handle;
1717     VAYUDSPPROC_Object *        object = NULL;
1718     UInt32                      i;
1719     UInt32                      startAddr;
1720     UInt32                      endAddr;
1721     UInt32                      offset;
1722     ProcMgr_AddrInfo *          ai;
1724     GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1725               handle, dstAddr, srcAddr);
1727     GT_assert (curTrace, (handle != NULL));
1728     GT_assert (curTrace, (dstAddr != NULL));
1730 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1731     if (handle == NULL) {
1732         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1733         status = PROCESSOR_E_HANDLE;
1734         GT_setFailureReason (curTrace,
1735                              GT_4CLASS,
1736                              "VAYUDSPPROC_translate",
1737                              status,
1738                              "Invalid handle specified");
1739     }
1740     else if (dstAddr == NULL) {
1741         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1742         status = PROCESSOR_E_INVALIDARG;
1743         GT_setFailureReason (curTrace,
1744                              GT_4CLASS,
1745                              "VAYUDSPPROC_translate",
1746                              status,
1747                              "dstAddr provided as NULL");
1748     }
1749     else {
1750 #endif
1751         object = (VAYUDSPPROC_Object *)procHandle->object;
1752         GT_assert(curTrace, (object != NULL));
1753         *dstAddr = -1u;
1755         /* search all entries AddrTable */
1756         for (i = 0; i < AddrTable_count[PROCID_TO_DSP(procHandle->procId)];
1757             i++) {
1758             ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][i];
1759             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1760             endAddr = startAddr + ai->size;
1762             if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1763                 offset = srcAddr - startAddr;
1764                 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1765                 GT_3trace(curTrace, GT_1CLASS, "VAYUDSPPROC_translate: "
1766                     "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1767                     i, srcAddr, *dstAddr);
1768                 break;
1769             }
1770         }
1772         if (*dstAddr == -1u) {
1773             /* srcAddr not found in slave address space */
1774             status = PROCESSOR_E_INVALIDARG;
1775             GT_setFailureReason(curTrace, GT_4CLASS,
1776                 "VAYUDSPPROC_translate", status,
1777                 "srcAddr not found in slave address space");
1778         }
1779 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1780     }
1781 #endif
1782     GT_1trace(curTrace, GT_LEAVE,
1783         "VAYUDSPPROC_translate: status=0x%x", status);
1785     /*! @retval PROCESSOR_SUCCESS Operation successful */
1786     return status;
1789 /*!
1790  *  @brief      Map the given address translation into the slave mmu
1791  *
1792  *  @param      handle      Handle to the Processor object
1793  *  @param      dstAddr     Base virtual address
1794  *  @param      nSegs       Number of given segments
1795  *  @param      sglist      Segment list
1796  */
1797 Int
1798 VAYUDSPPROC_map(
1799         Processor_Handle    handle,
1800         UInt32 *            dstAddr,
1801         UInt32              nSegs,
1802         Memory_SGList *     sglist)
1804     Int                         status = PROCESSOR_SUCCESS;
1805     Processor_Object *          procHandle = (Processor_Object *)handle;
1806     VAYUDSPPROC_Object *        object = NULL;
1807     Bool                        found = FALSE;
1808     UInt32                      startAddr;
1809     UInt32                      endAddr;
1810     UInt32                      i;
1811     UInt32                      j;
1812     ProcMgr_AddrInfo *          ai = NULL;
1814     GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_map",
1815                handle, dstAddr, nSegs, sglist);
1817     GT_assert (curTrace, (handle != NULL));
1818     GT_assert (curTrace, (sglist != NULL));
1819     GT_assert (curTrace, (nSegs > 0));
1821 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1822     if (handle == NULL) {
1823         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1824         status = PROCESSOR_E_HANDLE;
1825         GT_setFailureReason (curTrace,
1826                              GT_4CLASS,
1827                              "VAYUDSPPROC_map",
1828                              status,
1829                              "Invalid handle specified");
1830     }
1831     else if (sglist == NULL) {
1832         /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1833         status = PROCESSOR_E_INVALIDARG;
1834         GT_setFailureReason (curTrace,
1835                              GT_4CLASS,
1836                              "VAYUDSPPROC_map",
1837                              status,
1838                              "sglist provided as NULL");
1839     }
1840     else if (nSegs == 0) {
1841         /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1842         status = PROCESSOR_E_INVALIDARG;
1843         GT_setFailureReason (curTrace,
1844                              GT_4CLASS,
1845                              "VAYUDSPPROC_map",
1846                              status,
1847                              "Number of segments provided is 0");
1848     }
1849     else {
1850 #endif
1851         object = (VAYUDSPPROC_Object *)procHandle->object;
1852         GT_assert (curTrace, (object != NULL));
1854         for (i = 0; (i < nSegs) && (status >= 0); i++) {
1855             /* Update the translation table with entries for which mapping
1856              * is required. Add the entry only if the range does not exist
1857              * in the translation table.
1858              */
1859             /* check in static entries first */
1860             for (j = 0;
1861                 j < AddrTable_STATIC_COUNT; j++) {
1862                 ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][j];
1863                 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1864                 endAddr = startAddr + ai->size;
1866                 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)) {
1867                     found = TRUE;
1869                     /* refCount does not need to be incremented for static entries */
1871                     break;
1872                  }
1873             }
1875             /* if not found in static entries, check in dynamic entries */
1876             if (!found) {
1877                 for (j = AddrTable_STATIC_COUNT;
1878                     j < AddrTable_count[PROCID_TO_DSP(procHandle->procId)]; j++) {
1879                     ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][j];
1881                     if (ai->isMapped == TRUE) {
1882                         startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1883                         endAddr = startAddr + ai->size;
1885                         if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1886                             && ((*dstAddr + sglist[i].size) <= endAddr)) {
1887                             found = TRUE;
1888                             ai->refCount++;
1889                             break;
1890                         }
1891                     }
1892                 }
1893             }
1895             /* if not found and mmu is enabled, add new entry to table */
1896             if (!found) {
1897                 if (AddrTable_count[PROCID_TO_DSP(procHandle->procId)] !=
1898                     AddrTable_SIZE) {
1899                     ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)]
1900                         [AddrTable_count[PROCID_TO_DSP
1901                         (procHandle->procId)]];
1902                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1903                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1904                     ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1905                     ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1906                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1907                     ai->size = sglist[i].size;
1908                     ai->isCached = sglist[i].isCached;
1909                     ai->refCount++;
1910                     ai->isMapped = TRUE;
1912                     AddrTable_count[PROCID_TO_DSP(procHandle->procId)]++;
1913                 }
1914                 else {
1915                     status = PROCESSOR_E_FAIL;
1916                     GT_setFailureReason(curTrace, GT_4CLASS,
1917                         "VAYUDSPPROC_map", status,
1918                         "AddrTable_SIZE reached!");
1919                 }
1920             }
1921         }
1922 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1923     }
1924 #endif
1925     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_map", status);
1927     /*! @retval PROCESSOR_SUCCESS Operation successful */
1928     return status;
1932 /*!
1933  *  @brief      Function to unmap slave address from host address space
1934  *
1935  *  @param      handle      Handle to the Processor object
1936  *  @param      dstAddr     Return parameter: Pointer to receive the mapped
1937  *                          address.
1938  *  @param      size        Size of the region to be mapped.
1939  *
1940  *  @sa
1941  */
1942 Int
1943 VAYUDSPPROC_unmap(
1944         Processor_Handle    handle,
1945         UInt32              addr,
1946         UInt32              size)
1948     Int                         status = PROCESSOR_SUCCESS;
1949     Processor_Object *          procHandle = (Processor_Object *)handle;
1950     VAYUDSPPROC_Object *        object = NULL;
1951     ProcMgr_AddrInfo *          ai;
1952     Int                         i;
1953     UInt32                      startAddr;
1954     UInt32                      endAddr;
1955     VAYUDSP_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1957     GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_unmap",
1958                handle, addr, size);
1960     GT_assert (curTrace, (handle != NULL));
1961     GT_assert (curTrace, (size   != 0));
1963 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1964     if (handle == NULL) {
1965         /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1966         status = PROCESSOR_E_HANDLE;
1967         GT_setFailureReason (curTrace,
1968                              GT_4CLASS,
1969                              "VAYUDSPPROC_unmap",
1970                              status,
1971                              "Invalid handle specified");
1972     }
1973     else if (size == 0) {
1974         /*! @retval  PROCESSOR_E_INVALIDARG Size provided is zero */
1975         status = PROCESSOR_E_INVALIDARG;
1976         GT_setFailureReason (curTrace,
1977                              GT_4CLASS,
1978                              "VAYUDSPPROC_unmap",
1979                              status,
1980                              "Size provided is zero");
1981     }
1982     else {
1983 #endif
1984         object = (VAYUDSPPROC_Object *) procHandle->object;
1985         GT_assert (curTrace, (object != NULL));
1987         /* Delete entries from translation
1988          * table only in last unmap called on that entry
1989          */
1990         for (i = 0;
1991             i < AddrTable_count[PROCID_TO_DSP(procHandle->procId)]; i++) {
1992             ai = &AddrTable[PROCID_TO_DSP(procHandle->procId)][i];
1994             if (!ai->isMapped) {
1995                 continue;
1996             }
1998             startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1999             endAddr = startAddr + ai->size;
2001             if ((startAddr <= addr) && (addr < endAddr)) {
2002                 ai->refCount--;
2004                 if (ai->refCount == 0) {
2005                     ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
2006                     ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
2007                     ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
2008                     ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2009                     ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2010                     ai->size = 0u;
2011                     ai->isCached = FALSE;
2012                     ai->mapMask = 0u;
2013                     ai->isMapped = FALSE;
2015                     /* Remove the entry from the DSP MMU also */
2016                     deleteEntryArgs.size          = size;
2017                     deleteEntryArgs.slaveVirtAddr = addr;
2018                     /* TBD: elementSize, endianism, mixedSized are
2019                      * hard coded now, must be configurable later
2020                      */
2021                     deleteEntryArgs.elementSize   = ELEM_SIZE_16BIT;
2022                     deleteEntryArgs.endianism     = LITTLE_ENDIAN;
2023                     deleteEntryArgs.mixedSize     = MMU_TLBES;
2025                     status = VAYUDSP_halMmuCtrl(object->halObject,
2026                         Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2027 #if !defined(IPC_BUILD_OPTIMIZE)
2028                     if (status < 0) {
2029                         GT_setFailureReason(curTrace, GT_4CLASS,
2030                             "VAYUDSPPROC_unmap", status,
2031                             "DSP MMU configuration failed");
2032                     }
2033 #endif
2034                 }
2035             }
2036         }
2037 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
2038     }
2039 #endif
2040     GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_unmap", status);
2042     /*! @retval PROCESSOR_SUCCESS Operation successful */
2043     return status;
2047 #if defined (__cplusplus)
2049 #endif /* defined (__cplusplus) */