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