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