5dea43f7fa694dbd23aeb706d547785ef9f24b47
[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, 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_MAX_NAMELENGTH 64
102 #define PARAMS_mmuEnable "ProcMgr.proc[DSP1].mmuEnable="
103 #define PARAMS_carveoutAddr "ProcMgr.proc[DSP1].carveoutAddr"
104 #define PARAMS_carveoutSize "ProcMgr.proc[DSP1].carveoutSize"
107 /*!
108 * @brief VAYUDSPPROC Module state object
109 */
110 typedef struct VAYUDSPPROC_ModuleObject_tag {
111 UInt32 configSize;
112 /*!< Size of configuration structure */
113 VAYUDSPPROC_Config cfg;
114 /*!< VAYUDSPPROC configuration structure */
115 VAYUDSPPROC_Config defCfg;
116 /*!< Default module configuration */
117 VAYUDSPPROC_Params defInstParams;
118 /*!< Default parameters for the VAYUDSPPROC instances */
119 Bool isSetup;
120 /*!< Indicates whether the VAYUDSPPROC module is setup. */
121 VAYUDSPPROC_Handle procHandles [MultiProc_MAXPROCESSORS];
122 /*!< Processor handle array. */
123 IGateProvider_Handle gateHandle;
124 /*!< Handle of gate to be used for local thread safety */
125 } VAYUDSPPROC_ModuleObject;
127 /* Default memory regions */
128 static UInt32 AddrTable_count = AddrTable_STATIC_COUNT;
130 /* static memory regions
131 * CAUTION: AddrTable_STATIC_COUNT must match number of entries below.
132 */
133 static ProcMgr_AddrInfo AddrTable[AddrTable_SIZE] =
134 {
135 /* L2 RAM */
136 {
137 .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
138 .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
139 .addr[ProcMgr_AddrType_MasterPhys] = 0x40800000u,
140 .addr[ProcMgr_AddrType_SlaveVirt] = 0x800000u,
141 .addr[ProcMgr_AddrType_SlavePhys] = -1u,
142 .size = 0x40000u,
143 .isCached = FALSE,
144 .mapMask = ProcMgr_SLAVEVIRT,
145 .isMapped = TRUE,
146 .refCount = 0u /* refCount set to 0 for static entry */
147 },
149 /* L1P RAM */
150 {
151 .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
152 .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
153 .addr[ProcMgr_AddrType_MasterPhys] = 0x40E00000u,
154 .addr[ProcMgr_AddrType_SlaveVirt] = 0xE00000u,
155 .addr[ProcMgr_AddrType_SlavePhys] = -1u,
156 .size = 0x8000u,
157 .isCached = FALSE,
158 .mapMask = ProcMgr_SLAVEVIRT,
159 .isMapped = TRUE,
160 .refCount = 0u /* refCount set to 0 for static entry */
161 },
163 /* L1D RAM */
164 {
165 .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
166 .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
167 .addr[ProcMgr_AddrType_MasterPhys] = 0x40F00000u,
168 .addr[ProcMgr_AddrType_SlaveVirt] = 0xF00000u,
169 .addr[ProcMgr_AddrType_SlavePhys] = -1u,
170 .size = 0x8000u,
171 .isCached = FALSE,
172 .mapMask = ProcMgr_SLAVEVIRT,
173 .isMapped = TRUE,
174 .refCount = 0u /* refCount set to 0 for static entry */
175 },
176 };
178 /* =============================================================================
179 * Globals
180 * =============================================================================
181 */
183 /*!
184 * @var VAYUDSPPROC_state
185 *
186 * @brief VAYUDSPPROC state object variable
187 */
188 #if !defined(SYSLINK_BUILD_DEBUG)
189 static
190 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
191 VAYUDSPPROC_ModuleObject VAYUDSPPROC_state =
192 {
193 .isSetup = FALSE,
194 .configSize = sizeof(VAYUDSPPROC_Config),
195 .gateHandle = NULL,
196 .defInstParams.mmuEnable = FALSE,
197 .defInstParams.numMemEntries = AddrTable_STATIC_COUNT
198 };
200 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
201 extern String ProcMgr_sysLinkCfgParams;
203 /* =============================================================================
204 * APIs directly called by applications
205 * =============================================================================
206 */
207 /*!
208 * @brief Function to get the default configuration for the VAYUDSPPROC
209 * module.
210 *
211 * This function can be called by the application to get their
212 * configuration parameter to VAYUDSPPROC_setup filled in by the
213 * VAYUDSPPROC module with the default parameters. If the user
214 * does not wish to make any change in the default parameters, this
215 * API is not required to be called.
216 *
217 * @param cfg Pointer to the VAYUDSPPROC module configuration
218 * structure in which the default config is to be
219 * returned.
220 *
221 * @sa VAYUDSPPROC_setup
222 */
223 Void
224 VAYUDSPPROC_getConfig (VAYUDSPPROC_Config * cfg)
225 {
226 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_getConfig", cfg);
228 GT_assert (curTrace, (cfg != NULL));
230 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
231 if (cfg == NULL) {
232 GT_setFailureReason (curTrace,
233 GT_4CLASS,
234 "VAYUDSPPROC_getConfig",
235 PROCESSOR_E_INVALIDARG,
236 "Argument of type (VAYUDSPPROC_Config *) passed "
237 "is null!");
238 }
239 else {
240 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
241 Memory_copy (cfg,
242 &(VAYUDSPPROC_state.defCfg),
243 sizeof (VAYUDSPPROC_Config));
244 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
245 }
246 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
248 GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_getConfig");
249 }
252 /*!
253 * @brief Function to setup the VAYUDSPPROC module.
254 *
255 * This function sets up the VAYUDSPPROC module. This function
256 * must be called before any other instance-level APIs can be
257 * invoked.
258 * Module-level configuration needs to be provided to this
259 * function. If the user wishes to change some specific config
260 * parameters, then VAYUDSPPROC_getConfig can be called to get the
261 * configuration filled with the default values. After this, only
262 * the required configuration values can be changed. If the user
263 * does not wish to make any change in the default parameters, the
264 * application can simply call VAYUDSPPROC_setup with NULL
265 * parameters. The default parameters would get automatically used.
266 *
267 * @param cfg Optional VAYUDSPPROC module configuration. If provided as
268 * NULL, default configuration is used.
269 *
270 * @sa VAYUDSPPROC_destroy
271 * GateMutex_create
272 */
273 Int
274 VAYUDSPPROC_setup (VAYUDSPPROC_Config * cfg)
275 {
276 Int status = PROCESSOR_SUCCESS;
277 VAYUDSPPROC_Config tmpCfg;
278 Error_Block eb;
280 Error_init(&eb);
282 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_setup", cfg);
284 if (cfg == NULL) {
285 VAYUDSPPROC_getConfig (&tmpCfg);
286 cfg = &tmpCfg;
287 }
289 /* Create a default gate handle for local module protection. */
290 VAYUDSPPROC_state.gateHandle = (IGateProvider_Handle)
291 GateMutex_create ((GateMutex_Params *)NULL, &eb);
292 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
293 if (VAYUDSPPROC_state.gateHandle == NULL) {
294 /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
295 status = PROCESSOR_E_FAIL;
296 GT_setFailureReason (curTrace,
297 GT_4CLASS,
298 "VAYUDSPPROC_setup",
299 status,
300 "Failed to create GateMutex!");
301 }
302 else {
303 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
304 /* Copy the user provided values into the state object. */
305 Memory_copy (&VAYUDSPPROC_state.cfg,
306 cfg,
307 sizeof (VAYUDSPPROC_Config));
309 /* Initialize the name to handles mapping array. */
310 Memory_set (&VAYUDSPPROC_state.procHandles,
311 0,
312 (sizeof (VAYUDSPPROC_Handle) * MultiProc_MAXPROCESSORS));
313 VAYUDSPPROC_state.isSetup = TRUE;
314 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
315 }
316 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
318 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_setup", status);
320 /*! @retval PROCESSOR_SUCCESS Operation successful */
321 return (status);
322 }
325 /*!
326 * @brief Function to destroy the VAYUDSPPROC module.
327 *
328 * Once this function is called, other VAYUDSPPROC module APIs,
329 * except for the VAYUDSPPROC_getConfig API cannot be called
330 * anymore.
331 *
332 * @sa VAYUDSPPROC_setup
333 * GateMutex_delete
334 */
335 Int
336 VAYUDSPPROC_destroy (Void)
337 {
338 Int status = PROCESSOR_SUCCESS;
339 UInt16 i;
341 GT_0trace (curTrace, GT_ENTER, "VAYUDSPPROC_destroy");
343 /* Check if any VAYUDSPPROC instances have not been deleted so far. If not,
344 * delete them.
345 */
346 for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
347 GT_assert (curTrace, (VAYUDSPPROC_state.procHandles [i] == NULL));
348 if (VAYUDSPPROC_state.procHandles [i] != NULL) {
349 VAYUDSPPROC_delete (&(VAYUDSPPROC_state.procHandles [i]));
350 }
351 }
353 if (VAYUDSPPROC_state.gateHandle != NULL) {
354 GateMutex_delete ((GateMutex_Handle *)
355 &(VAYUDSPPROC_state.gateHandle));
356 }
358 VAYUDSPPROC_state.isSetup = FALSE;
360 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_destroy", status);
362 /*! @retval PROCESSOR_SUCCESS Operation successful */
363 return (status);
364 }
367 /*!
368 * @brief Function to initialize the parameters for this Processor
369 * instance.
370 *
371 * @param params Configuration parameters to be returned
372 *
373 * @sa VAYUDSPPROC_create
374 */
375 Void
376 VAYUDSPPROC_Params_init(
377 VAYUDSPPROC_Handle handle,
378 VAYUDSPPROC_Params * params)
379 {
380 VAYUDSPPROC_Object * procObject = (VAYUDSPPROC_Object *) handle;
381 Int i = 0;
382 ProcMgr_AddrInfo * ai = NULL;
384 GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_Params_init", handle, params);
386 GT_assert (curTrace, (params != NULL));
388 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
389 if (params == NULL) {
390 GT_setFailureReason (curTrace,
391 GT_4CLASS,
392 "VAYUDSPPROC_Params_init",
393 PROCESSOR_E_INVALIDARG,
394 "Argument of type (VAYUDSPPROC_Params *) "
395 "passed is null!");
396 }
397 else {
398 #endif
399 if (handle == NULL) {
401 /* check for instance params override */
402 Cfg_propBool(PARAMS_mmuEnable, ProcMgr_sysLinkCfgParams,
403 &(VAYUDSPPROC_state.defInstParams.mmuEnable));
405 Memory_copy(params, &(VAYUDSPPROC_state.defInstParams),
406 sizeof(VAYUDSPPROC_Params));
408 /* initialize the translation table */
409 for (i = AddrTable_count; i < AddrTable_SIZE; i++) {
410 ai = &AddrTable[i];
411 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
412 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
413 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
414 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
415 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
416 ai->size = 0u;
417 ai->isCached = FALSE;
418 ai->mapMask = 0u;
419 ai->isMapped = FALSE;
420 }
422 /* initialize refCount for all entries - both static and dynamic */
423 for(i = 0; i < AddrTable_SIZE; i++) {
424 AddrTable[i].refCount = 0u;
425 }
426 Memory_copy((Ptr)params->memEntries, AddrTable, sizeof(AddrTable));
427 }
428 else {
429 /* return updated VAYUDSPPROC instance specific parameters */
430 Memory_copy(params, &(procObject->params), sizeof(VAYUDSPPROC_Params));
431 }
432 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
433 }
434 #endif
436 GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPROC_Params_init");
437 }
439 /*!
440 * @brief Function to create an instance of this Processor.
441 *
442 * @param name Name of the Processor instance.
443 * @param params Configuration parameters.
444 *
445 * @sa VAYUDSPPROC_delete
446 */
447 VAYUDSPPROC_Handle
448 VAYUDSPPROC_create ( UInt16 procId,
449 const VAYUDSPPROC_Params * params)
450 {
451 Int status = PROCESSOR_SUCCESS;
452 Processor_Object * handle = NULL;
453 VAYUDSPPROC_Object * object = NULL;
454 IArg key;
455 List_Params listParams;
457 GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_create", procId, params);
459 GT_assert (curTrace, IS_VALID_PROCID (procId));
460 GT_assert (curTrace, (params != NULL));
462 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
463 if (!IS_VALID_PROCID (procId)) {
464 /* Not setting status here since this function does not return status.*/
465 GT_setFailureReason (curTrace,
466 GT_4CLASS,
467 "VAYUDSPPROC_create",
468 PROCESSOR_E_INVALIDARG,
469 "Invalid procId specified");
470 }
471 else if (params == NULL) {
472 GT_setFailureReason (curTrace,
473 GT_4CLASS,
474 "VAYUDSPPROC_create",
475 PROCESSOR_E_INVALIDARG,
476 "params passed is NULL!");
477 }
478 else {
479 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
480 /* Enter critical section protection. */
481 key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
482 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
483 /* Check if the Processor already exists for specified procId. */
484 if (VAYUDSPPROC_state.procHandles [procId] != NULL) {
485 status = PROCESSOR_E_ALREADYEXIST;
486 GT_setFailureReason (curTrace,
487 GT_4CLASS,
488 "VAYUDSPPROC_create",
489 status,
490 "Processor already exists for specified procId!");
491 }
492 else {
493 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
494 /* Allocate memory for the handle */
495 handle = (Processor_Object *) Memory_calloc (NULL,
496 sizeof (Processor_Object),
497 0,
498 NULL);
499 if (handle == NULL) {
500 GT_setFailureReason (curTrace,
501 GT_4CLASS,
502 "VAYUDSPPROC_create",
503 PROCESSOR_E_MEMORY,
504 "Memory allocation failed for handle!");
505 }
506 else {
507 /* Populate the handle fields */
508 handle->procFxnTable.attach = &VAYUDSPPROC_attach;
509 handle->procFxnTable.detach = &VAYUDSPPROC_detach;
510 handle->procFxnTable.start = &VAYUDSPPROC_start;
511 handle->procFxnTable.stop = &VAYUDSPPROC_stop;
512 handle->procFxnTable.read = &VAYUDSPPROC_read;
513 handle->procFxnTable.write = &VAYUDSPPROC_write;
514 handle->procFxnTable.control = &VAYUDSPPROC_control;
515 handle->procFxnTable.map = &VAYUDSPPROC_map;
516 handle->procFxnTable.unmap = &VAYUDSPPROC_unmap;
517 handle->procFxnTable.translateAddr = &VAYUDSPPROC_translate;
518 handle->state = ProcMgr_State_Unknown;
520 /* Allocate memory for the VAYUDSPPROC handle */
521 handle->object = Memory_calloc (NULL,
522 sizeof (VAYUDSPPROC_Object),
523 0,
524 NULL);
525 if (handle->object == NULL) {
526 status = PROCESSOR_E_MEMORY;
527 GT_setFailureReason (curTrace,
528 GT_4CLASS,
529 "VAYUDSPPROC_create",
530 status,
531 "Memory allocation failed for handle->object!");
532 }
533 else {
534 handle->procId = procId;
535 object = (VAYUDSPPROC_Object *) handle->object;
536 object->halObject = NULL;
537 object->procHandle = (Processor_Handle)handle;
538 /* Copy params into instance object. */
539 Memory_copy (&(object->params),
540 (Ptr) params,
541 sizeof (VAYUDSPPROC_Params));
542 /* Set the handle in the state object. */
543 VAYUDSPPROC_state.procHandles [procId] =
544 (VAYUDSPPROC_Handle) object;
545 /* Initialize the list of listeners */
546 List_Params_init(&listParams);
547 handle->registeredNotifiers = List_create(&listParams);
549 #if !defined(SYSLINK_BUILD_OPTIMIZE)
550 if (handle->registeredNotifiers == NULL) {
551 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
552 status = PROCESSOR_E_FAIL;
553 GT_setFailureReason (curTrace,
554 GT_4CLASS,
555 "VAYUDSPPROC_create",
556 status,
557 "List_create failed");
558 }
559 else {
560 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
562 handle->notifiersLock =
563 OsalMutex_create(OsalMutex_Type_Interruptible);
565 #if !defined(SYSLINK_BUILD_OPTIMIZE)
566 if (handle->notifiersLock == NULL) {
567 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
568 status = PROCESSOR_E_FAIL;
569 GT_setFailureReason (curTrace,
570 GT_4CLASS,
571 "VAYUDSPPROC_create",
572 status,
573 "OsalMutex_create failed");
574 }
575 }
576 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
577 }
578 }
579 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
580 }
581 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
583 /* Leave critical section protection. */
584 IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
585 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
586 }
587 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
589 if (status < 0) {
590 if (handle != NULL) {
591 if (handle->registeredNotifiers != NULL) {
592 List_delete (&handle->registeredNotifiers);
593 }
594 if (handle->object != NULL) {
595 Memory_free (NULL,
596 handle->object,
597 sizeof (VAYUDSPPROC_Object));
598 }
599 Memory_free (NULL, handle, sizeof (Processor_Object));
600 }
601 /*! @retval NULL Function failed */
602 handle = NULL;
603 }
604 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_create", handle);
606 /*! @retval Valid-Handle Operation successful */
607 return (VAYUDSPPROC_Handle) handle;
608 }
611 /*!
612 * @brief Function to delete an instance of this Processor.
613 *
614 * The user provided pointer to the handle is reset after
615 * successful completion of this function.
616 *
617 * @param handlePtr Pointer to Handle to the Processor instance
618 *
619 * @sa VAYUDSPPROC_create
620 */
621 Int
622 VAYUDSPPROC_delete (VAYUDSPPROC_Handle * handlePtr)
623 {
624 Int status = PROCESSOR_SUCCESS;
625 VAYUDSPPROC_Object * object = NULL;
626 Processor_Object * handle;
627 IArg key;
628 List_Elem * elem = NULL;
629 Processor_RegisterElem * regElem = NULL;
631 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_delete", handlePtr);
633 GT_assert (curTrace, (handlePtr != NULL));
634 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
636 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
637 if (handlePtr == NULL) {
638 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
639 specified*/
640 status = PROCESSOR_E_INVALIDARG;
641 GT_setFailureReason (curTrace,
642 GT_4CLASS,
643 "VAYUDSPPROC_delete",
644 status,
645 "Invalid NULL handlePtr pointer specified");
646 }
647 else if (*handlePtr == NULL) {
648 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
649 status = PROCESSOR_E_HANDLE;
650 GT_setFailureReason (curTrace,
651 GT_4CLASS,
652 "VAYUDSPPROC_delete",
653 status,
654 "Invalid NULL *handlePtr specified");
655 }
656 else {
657 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
658 handle = (Processor_Object *) (*handlePtr);
659 /* Enter critical section protection. */
660 key = IGateProvider_enter (VAYUDSPPROC_state.gateHandle);
662 /* Reset handle in PwrMgr handle array. */
663 GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
664 VAYUDSPPROC_state.procHandles [handle->procId] = NULL;
666 /* Free memory used for the VAYUDSPPROC object. */
667 if (handle->object != NULL) {
668 object = (VAYUDSPPROC_Object *) handle->object;
669 Memory_free (NULL,
670 object,
671 sizeof (VAYUDSPPROC_Object));
672 handle->object = NULL;
673 }
675 /*
676 * Check the list of listeners to see if any are remaining
677 * and reply to them
678 */
679 OsalMutex_delete(&handle->notifiersLock);
681 while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
682 regElem = (Processor_RegisterElem *)elem;
684 /* Check if there is an associated timer and cancel it */
685 if (regElem->timer != -1) {
686 struct itimerspec value ;
687 value.it_value.tv_sec = 0;
688 value.it_value.tv_nsec = 0;
689 value.it_interval.tv_sec = 0;
690 value.it_interval.tv_nsec = 0;
691 timer_settime(regElem->timer, 0, &value, NULL);
693 timer_delete(regElem->timer);
694 regElem->timer = -1;
695 }
697 /* Call the callback function so it can clean up. */
698 regElem->info->cbFxn(handle->procId,
699 NULL,
700 handle->state,
701 handle->state,
702 ProcMgr_EventStatus_Canceled,
703 regElem->info->arg);
704 /* Free the memory */
705 Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
706 }
708 /* Delete the list of listeners */
709 List_delete(&handle->registeredNotifiers);
711 /* Free memory used for the Processor object. */
712 Memory_free (NULL, handle, sizeof (Processor_Object));
713 *handlePtr = NULL;
715 /* Leave critical section protection. */
716 IGateProvider_leave (VAYUDSPPROC_state.gateHandle, key);
717 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
718 }
719 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
721 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_delete", status);
723 /*! @retval PROCESSOR_SUCCESS Operation successful */
724 return (status);
725 }
728 /*!
729 * @brief Function to open a handle to an instance of this Processor. This
730 * function is called when access to the Processor is required from
731 * a different process.
732 *
733 * @param handlePtr Handle to the Processor instance
734 * @param procId Processor ID addressed by this Processor instance.
735 *
736 * @sa VAYUDSPPROC_close
737 */
738 Int
739 VAYUDSPPROC_open (VAYUDSPPROC_Handle * handlePtr, UInt16 procId)
740 {
741 Int status = PROCESSOR_SUCCESS;
743 GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_open", handlePtr, procId);
745 GT_assert (curTrace, (handlePtr != NULL));
746 GT_assert (curTrace, IS_VALID_PROCID (procId));
748 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
749 if (handlePtr == NULL) {
750 /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
751 status = PROCESSOR_E_HANDLE;
752 GT_setFailureReason (curTrace,
753 GT_4CLASS,
754 "VAYUDSPPROC_open",
755 status,
756 "Invalid NULL handlePtr specified");
757 }
758 else if (!IS_VALID_PROCID (procId)) {
759 /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
760 status = PROCESSOR_E_INVALIDARG;
761 GT_setFailureReason (curTrace,
762 GT_4CLASS,
763 "VAYUDSPPROC_open",
764 status,
765 "Invalid procId specified");
766 }
767 else {
768 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
769 /* Initialize return parameter handle. */
770 *handlePtr = NULL;
772 /* Check if the PwrMgr exists and return the handle if found. */
773 if (VAYUDSPPROC_state.procHandles [procId] == NULL) {
774 /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
775 status = PROCESSOR_E_NOTFOUND;
776 GT_setFailureReason (curTrace,
777 GT_4CLASS,
778 "VAYUDSPPROC_open",
779 status,
780 "Specified VAYUDSPPROC instance does not exist!");
781 }
782 else {
783 *handlePtr = VAYUDSPPROC_state.procHandles [procId];
784 }
785 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
786 }
787 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
789 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_open", status);
791 /*! @retval PROCESSOR_SUCCESS Operation successful */
792 return status;
793 }
796 /*!
797 * @brief Function to close a handle to an instance of this Processor.
798 *
799 * @param handlePtr Pointer to Handle to the Processor instance
800 *
801 * @sa VAYUDSPPROC_open
802 */
803 Int
804 VAYUDSPPROC_close (VAYUDSPPROC_Handle * handlePtr)
805 {
806 Int status = PROCESSOR_SUCCESS;
808 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_close", handlePtr);
810 GT_assert (curTrace, (handlePtr != NULL));
811 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
813 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
814 if (handlePtr == NULL) {
815 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
816 specified*/
817 status = PROCESSOR_E_INVALIDARG;
818 GT_setFailureReason (curTrace,
819 GT_4CLASS,
820 "VAYUDSPPROC_close",
821 status,
822 "Invalid NULL handlePtr pointer specified");
823 }
824 else if (*handlePtr == NULL) {
825 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
826 status = PROCESSOR_E_HANDLE;
827 GT_setFailureReason (curTrace,
828 GT_4CLASS,
829 "VAYUDSPPROC_close",
830 status,
831 "Invalid NULL *handlePtr specified");
832 }
833 else {
834 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
835 /* Nothing to be done for close. */
836 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
837 }
838 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
840 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_close", status);
842 /*! @retval PROCESSOR_SUCCESS Operation successful */
843 return status;
844 }
847 /* =============================================================================
848 * APIs called by Processor module (part of function table interface)
849 * =============================================================================
850 */
851 /*!
852 * @brief Function to initialize the slave processor
853 *
854 * @param handle Handle to the Processor instance
855 * @param params Attach parameters
856 *
857 * @sa VAYUDSPPROC_detach
858 */
859 Int
860 VAYUDSPPROC_attach(
861 Processor_Handle handle,
862 Processor_AttachParams * params)
863 {
865 Int status = PROCESSOR_SUCCESS;
866 Processor_Object * procHandle = (Processor_Object *)handle;
867 VAYUDSPPROC_Object * object = NULL;
868 UInt32 i = 0;
869 UInt32 index = 0;
870 ProcMgr_AddrInfo * me;
871 SysLink_MemEntry * entry;
872 SysLink_MemEntry_Block memBlock;
873 Char prop[PARAMS_MAX_NAMELENGTH];
874 Char configProp[PARAMS_MAX_NAMELENGTH];
875 UInt32 numCarveouts = 0;
876 VAYUDSP_HalMmuCtrlArgs_Enable mmuEnableArgs;
877 VAYUDSP_HalParams halParams;
879 GT_2trace (curTrace, GT_ENTER, "VAYUDSPPROC_attach", handle, params);
880 GT_assert (curTrace, (handle != NULL));
881 GT_assert (curTrace, (params != NULL));
883 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
884 if (handle == NULL) {
885 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
886 status = PROCESSOR_E_HANDLE;
887 GT_setFailureReason (curTrace,
888 GT_4CLASS,
889 "VAYUDSPPROC_attach",
890 status,
891 "Invalid handle specified");
892 }
893 else if (params == NULL) {
894 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
895 status = PROCESSOR_E_INVALIDARG;
896 GT_setFailureReason (curTrace,
897 GT_4CLASS,
898 "VAYUDSPPROC_attach",
899 status,
900 "Invalid params specified");
901 }
902 else {
903 #endif
904 object = (VAYUDSPPROC_Object *) procHandle->object;
905 GT_assert (curTrace, (object != NULL));
907 params->procArch = Processor_ProcArch_C66x;
909 /* check for instance params override */
910 Cfg_propBool(PARAMS_mmuEnable, ProcMgr_sysLinkCfgParams,
911 &(object->params.mmuEnable));
913 /* check for carveout params override */
914 for (i = 0; i < ProcMgr_MAX_MEMORY_REGIONS; i++) {
915 snprintf (prop, PARAMS_MAX_NAMELENGTH, PARAMS_carveoutAddr"%d", i);
916 strcat(prop, "=");
917 if (!Cfg_prop(prop, ProcMgr_sysLinkCfgParams, configProp))
918 break;
919 object->params.carveoutAddr[i] = strtoul(configProp, 0, 16);
920 snprintf (prop, PARAMS_MAX_NAMELENGTH, PARAMS_carveoutSize"%d", i);
921 strcat(prop, "=");
922 if (!Cfg_prop(prop, ProcMgr_sysLinkCfgParams, configProp))
923 break;
924 object->params.carveoutSize[i] = strtoul(configProp, 0, 16);
925 numCarveouts++;
926 }
928 object->pmHandle = params->pmHandle;
929 GT_0trace(curTrace, GT_1CLASS,
930 "VAYUDSPPROC_attach: Mapping memory regions");
932 /* search for dsp memory map */
933 status = RscTable_process(procHandle->procId, object->params.mmuEnable,
934 numCarveouts,
935 (Ptr)object->params.carveoutAddr,
936 object->params.carveoutSize, TRUE,
937 &memBlock.numEntries);
938 if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
939 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
940 status = PROCESSOR_E_INVALIDARG;
941 GT_setFailureReason (curTrace,
942 GT_4CLASS,
943 "VAYUDSPPROC_attach",
944 status,
945 "Failed to process resource table");
946 }
947 else {
948 status = RscTable_getMemEntries(procHandle->procId,
949 memBlock.memEntries,
950 &memBlock.numEntries);
951 if (status < 0) {
952 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
953 status = PROCESSOR_E_INVALIDARG;
954 GT_setFailureReason (curTrace,
955 GT_4CLASS,
956 "VAYUDSPPROC_attach",
957 status,
958 "Failed to get resource table memEntries");
959 }
960 }
962 /* update translation tables with memory map */
963 for (i = 0; (i < memBlock.numEntries)
964 && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
966 entry = &memBlock.memEntries[i];
968 if (entry->map == FALSE) {
969 /* update table with entries which don't require mapping */
970 if (AddrTable_count != AddrTable_SIZE) {
971 me = &AddrTable[AddrTable_count];
973 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
974 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
975 me->addr[ProcMgr_AddrType_MasterPhys] =
976 entry->masterPhysAddr;
977 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
978 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
979 me->size = entry->size;
980 me->isCached = entry->isCached;
981 me->mapMask = entry->mapMask;
983 AddrTable_count++;
984 }
985 else {
986 status = PROCESSOR_E_FAIL;
987 GT_setFailureReason(curTrace, GT_4CLASS,
988 "VAYUDSPPROC_attach", status,
989 "AddrTable_SIZE reached!");
990 }
991 }
992 else if (entry->map == TRUE) {
993 /* send these entries back to ProcMgr for mapping */
994 index = object->params.numMemEntries;
996 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
997 me = &object->params.memEntries[index];
999 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1000 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1001 me->addr[ProcMgr_AddrType_MasterPhys] =
1002 entry->masterPhysAddr;
1003 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1004 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1005 me->size = entry->size;
1006 me->isCached = entry->isCached;
1007 me->mapMask = entry->mapMask;
1009 object->params.numMemEntries++;
1010 }
1011 else {
1012 status = PROCESSOR_E_FAIL;
1013 GT_setFailureReason(curTrace, GT_4CLASS,
1014 "VAYUDSPPROC_attach", status,
1015 "ProcMgr_MAX_MEMORY_REGIONS reached!");
1016 }
1017 }
1018 else {
1019 status = PROCESSOR_E_INVALIDARG;
1020 GT_setFailureReason(curTrace, GT_4CLASS,
1021 "VAYUDSPPROC_attach", status,
1022 "Memory map has entry with invalid 'map' value");
1023 }
1024 } /* for (...) */
1026 if (status >= 0) {
1027 /* populate the return params */
1028 params->numMemEntries = object->params.numMemEntries;
1029 memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1030 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1032 halParams.procId = procHandle->procId;
1033 status = VAYUDSP_halInit(&(object->halObject), &halParams);
1035 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1036 if (status < 0) {
1037 GT_setFailureReason(curTrace, GT_4CLASS,
1038 "VAYUDSPPROC_attach", status,
1039 "VAYUDSP_halInit failed");
1040 }
1041 else {
1042 #endif
1043 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1044 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1046 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1047 if (status < 0) {
1048 GT_setFailureReason(curTrace, GT_4CLASS,
1049 "VAYUDSPPROC_attach", status,
1050 "Failed to reset the slave processor");
1051 }
1052 else {
1053 #endif
1054 GT_0trace(curTrace, GT_3CLASS,
1055 "VAYUDSPPROC_attach: slave is now in reset");
1057 if (object->params.mmuEnable) {
1058 mmuEnableArgs.numMemEntries = 0;
1059 status = VAYUDSP_halMmuCtrl(object->halObject,
1060 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1062 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1063 if (status < 0) {
1064 GT_setFailureReason(curTrace, GT_4CLASS,
1065 "VAYUDSPPROC_attach", status,
1066 "Failed to enable the slave MMU");
1067 }
1068 else {
1069 #endif
1070 GT_0trace(curTrace, GT_2CLASS,
1071 "VAYUDSPPROC_attach: Slave MMU "
1072 "is configured!");
1074 /*
1075 * Pull DSP MMU out of reset to make internal
1076 * memory "loadable"
1077 */
1078 status = VAYUDSP_halResetCtrl(object->halObject,
1079 Processor_ResetCtrlCmd_MMU_Release);
1080 if (status < 0) {
1081 /*! @retval status */
1082 GT_setFailureReason(curTrace,
1083 GT_4CLASS,
1084 "VAYUDSP_halResetCtrl",
1085 status,
1086 "Reset MMU_Release failed");
1087 }
1088 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1089 }
1090 #endif
1091 }
1092 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1093 }
1094 #endif
1095 }
1096 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1097 }
1098 #endif
1099 }
1100 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1101 }
1102 #endif
1104 GT_1trace(curTrace, GT_LEAVE,
1105 "VAYUDSPPROC_attach", status);
1107 /*! @retval PROCESSOR_SUCCESS Operation successful */
1108 return status;
1109 }
1112 /*!
1113 * @brief Function to detach from the Processor.
1114 *
1115 * @param handle Handle to the Processor instance
1116 *
1117 * @sa VAYUDSPPROC_attach
1118 */
1119 Int
1120 VAYUDSPPROC_detach (Processor_Handle handle)
1121 {
1122 Int status = PROCESSOR_SUCCESS;
1123 Int tmpStatus = PROCESSOR_SUCCESS;
1124 Processor_Object * procHandle = (Processor_Object *) handle;
1125 VAYUDSPPROC_Object * object = NULL;
1126 Int i = 0;
1127 ProcMgr_AddrInfo * ai;
1129 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_detach", handle);
1131 GT_assert (curTrace, (handle != NULL));
1133 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1134 if (handle == NULL) {
1135 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1136 status = PROCESSOR_E_HANDLE;
1137 GT_setFailureReason (curTrace,
1138 GT_4CLASS,
1139 "VAYUDSPPROC_detach",
1140 PROCESSOR_E_HANDLE,
1141 "Invalid handle specified");
1142 }
1143 else {
1144 #endif
1145 object = (VAYUDSPPROC_Object *) procHandle->object;
1146 GT_assert (curTrace, (object != NULL));
1148 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1149 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1151 if (object->params.mmuEnable) {
1152 GT_0trace(curTrace, GT_2CLASS,
1153 "VAYUDSPPROC_detach: Disabling Slave MMU ...");
1155 status = VAYUDSP_halResetCtrl(object->halObject,
1156 Processor_ResetCtrlCmd_MMU_Reset);
1157 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1158 if (status < 0) {
1159 /*! @retval status */
1160 GT_setFailureReason (curTrace,
1161 GT_4CLASS,
1162 "VAYUDSP_halResetCtrl",
1163 status,
1164 "Reset MMU failed");
1165 }
1166 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1168 status = VAYUDSP_halMmuCtrl(object->halObject,
1169 Processor_MmuCtrlCmd_Disable, NULL);
1171 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1172 if (status < 0) {
1173 GT_setFailureReason(curTrace, GT_4CLASS,
1174 "VAYUDSPPROC_detach", status,
1175 "Failed to disable the slave MMU");
1176 }
1177 #endif
1178 }
1180 /* delete all dynamically added entries */
1181 for (i = AddrTable_STATIC_COUNT; i < AddrTable_count; i++) {
1182 ai = &AddrTable[i];
1183 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1184 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1185 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1186 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1187 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1188 ai->size = 0u;
1189 ai->isCached = FALSE;
1190 ai->mapMask = 0u;
1191 ai->isMapped = FALSE;
1192 ai->refCount = 0u;
1193 }
1194 object->params.numMemEntries = AddrTable_STATIC_COUNT;
1195 AddrTable_count = AddrTable_STATIC_COUNT;
1197 //No need to reset.. that will be done in STOP
1198 /*tmpStatus = VAYUDSP_halResetCtrl(object->halObject,
1199 VAYUDspHal_Reset_Detach);
1201 GT_0trace(curTrace, GT_2CLASS,
1202 "VAYUDSPPROC_detach: Slave processor is now in reset");*/
1204 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1205 if ((tmpStatus < 0) && (status >= 0)) {
1206 status = tmpStatus;
1207 GT_setFailureReason(curTrace,
1208 GT_4CLASS,
1209 "VAYUDSPPROC_detach",
1210 status,
1211 "Failed to reset the slave processor");
1212 }
1213 #endif
1214 }
1216 GT_0trace (curTrace,
1217 GT_2CLASS,
1218 " VAYUDSPPROC_detach: Unmapping memory regions\n");
1220 tmpStatus = VAYUDSP_halExit (object->halObject);
1221 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1222 if ((tmpStatus < 0) && (status >= 0)) {
1223 status = tmpStatus;
1224 GT_setFailureReason (curTrace,
1225 GT_4CLASS,
1226 "VAYUDSPPROC_detach",
1227 status,
1228 "Failed to finalize HAL object");
1229 }
1230 }
1231 #endif
1233 GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_detach", status);
1235 /*! @retval PROCESSOR_SUCCESS Operation successful */
1236 return status;
1237 }
1240 /*!
1241 * @brief Function to start the slave processor
1242 *
1243 * Start the slave processor running from its entry point.
1244 * Depending on the boot mode, this involves configuring the boot
1245 * address and releasing the slave from reset.
1246 *
1247 * @param handle Handle to the Processor instance
1248 *
1249 * @sa VAYUDSPPROC_stop, VAYUDSP_halBootCtrl, VAYUDSP_halResetCtrl
1250 */
1251 Int
1252 VAYUDSPPROC_start (Processor_Handle handle,
1253 UInt32 entryPt,
1254 Processor_StartParams * params)
1255 {
1256 Int status = PROCESSOR_SUCCESS ;
1257 Processor_Object * procHandle = (Processor_Object *) handle;
1258 VAYUDSPPROC_Object * object = NULL;
1260 GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_start",
1261 handle, entryPt, params);
1263 GT_assert (curTrace, (handle != NULL));
1264 GT_assert (curTrace, (params != NULL));
1266 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1267 if (handle == NULL) {
1268 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1269 status = PROCESSOR_E_HANDLE;
1270 GT_setFailureReason (curTrace,
1271 GT_4CLASS,
1272 "VAYUDSPPROC_start",
1273 status,
1274 "Invalid handle specified");
1275 }
1276 else if (params == NULL) {
1277 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1278 status = PROCESSOR_E_INVALIDARG;
1279 GT_setFailureReason (curTrace,
1280 GT_4CLASS,
1281 "VAYUDSPPROC_start",
1282 status,
1283 "Invalid params specified");
1284 }
1285 else {
1286 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1287 object = (VAYUDSPPROC_Object *) procHandle->object;
1288 GT_assert (curTrace, (object != NULL));
1289 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1290 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1291 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1292 /* Slave is to be started only for Boot mode and NoLoad mode. */
1293 /* Specify the DSP boot address in the boot config register */
1294 status = VAYUDSP_halBootCtrl (object->halObject,
1295 Processor_BootCtrlCmd_SetEntryPoint,
1296 (Ptr) entryPt);
1297 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1298 if (status < 0) {
1299 GT_setFailureReason (curTrace,
1300 GT_4CLASS,
1301 "VAYUDSPPROC_start",
1302 status,
1303 "Failed to set slave boot entry point");
1304 }
1305 else {
1306 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1307 if (object->params.mmuEnable) {
1308 status = rproc_dsp_setup(object->halObject,
1309 object->params.memEntries,
1310 object->params.numMemEntries);
1311 if (status < 0) {
1312 /*! @retval status */
1313 GT_setFailureReason (curTrace,
1314 GT_4CLASS,
1315 "VAYUDSP_halResetCtrl",
1316 status,
1317 "rproc_dsp_setup failed");
1318 }
1319 }
1320 /* release the slave cpu from reset */
1321 if (status >= 0) {
1322 status = VAYUDSP_halResetCtrl(object->halObject,
1323 Processor_ResetCtrlCmd_Release);
1324 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1325 if (status < 0) {
1326 GT_setFailureReason (curTrace,
1327 GT_4CLASS,
1328 "VAYUDSPPROC_start",
1329 status,
1330 "Failed to release slave from reset");
1331 }
1332 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1333 }
1334 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1335 }
1336 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1337 }
1339 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1340 }
1341 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1343 if (status >= 0) {
1344 GT_0trace (curTrace,
1345 GT_1CLASS,
1346 " VAYUDSPPROC_start: Slave successfully started!\n");
1347 }
1348 else {
1349 GT_0trace (curTrace,
1350 GT_1CLASS,
1351 " VAYUDSPPROC_start: Slave could not be started!\n");
1352 }
1354 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_start", status);
1356 /*! @retval PROCESSOR_SUCCESS Operation successful */
1357 return status;
1358 }
1361 /*!
1362 * @brief Function to stop the slave processor
1363 *
1364 * Stop the execution of the slave processor. Depending on the boot
1365 * mode, this may result in placing the slave processor in reset.
1366 *
1367 * @param handle Handle to the Processor instance
1368 *
1369 * @sa VAYUDSPPROC_start, VAYUDSP_halResetCtrl
1370 */
1371 Int
1372 VAYUDSPPROC_stop (Processor_Handle handle)
1373 {
1374 Int status = PROCESSOR_SUCCESS ;
1375 Processor_Object * procHandle = (Processor_Object *) handle;
1376 VAYUDSPPROC_Object * object = NULL;
1378 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPROC_stop", handle);
1380 GT_assert (curTrace, (handle != NULL));
1382 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1383 if (handle == NULL) {
1384 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1385 status = PROCESSOR_E_HANDLE;
1386 GT_setFailureReason (curTrace,
1387 GT_4CLASS,
1388 "VAYUDSPPROC_stop",
1389 status,
1390 "Invalid handle specified");
1391 }
1392 else {
1393 #endif
1394 object = (VAYUDSPPROC_Object *) procHandle->object;
1395 GT_assert (curTrace, (object != NULL));
1397 /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1398 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1399 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1400 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1401 status = VAYUDSP_halResetCtrl(object->halObject,
1402 Processor_ResetCtrlCmd_Reset);
1404 GT_0trace (curTrace,
1405 GT_1CLASS,
1406 " VAYUDSPPROC_stop: Slave is now in reset!\n");
1407 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1408 if (status < 0) {
1409 GT_setFailureReason (curTrace,
1410 GT_4CLASS,
1411 "VAYUDSPPROC_stop",
1412 status,
1413 "Failed to place slave in reset");
1414 }
1415 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1416 if (object->params.mmuEnable) {
1417 rproc_dsp_destroy(object->halObject);
1418 }
1419 }
1420 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1421 }
1422 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1423 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_stop", status);
1425 /*! @retval PROCESSOR_SUCCESS Operation successful */
1426 return status;
1427 }
1430 /*!
1431 * @brief Function to read from the slave processor's memory.
1432 *
1433 * Read from the slave processor's memory and copy into the
1434 * provided buffer.
1435 *
1436 * @param handle Handle to the Processor instance
1437 * @param procAddr Address in host processor's address space of the
1438 * memory region to read from.
1439 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1440 * number of bytes to be read. When the function
1441 * returns, this parameter contains the number of bytes
1442 * actually read.
1443 * @param buffer User-provided buffer in which the slave processor's
1444 * memory contents are to be copied.
1445 *
1446 * @sa VAYUDSPPROC_write
1447 */
1448 Int
1449 VAYUDSPPROC_read (Processor_Handle handle,
1450 UInt32 procAddr,
1451 UInt32 * numBytes,
1452 Ptr buffer)
1453 {
1454 Int status = PROCESSOR_SUCCESS ;
1455 UInt8 * procPtr8 = NULL;
1457 GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_read",
1458 handle, procAddr, numBytes, buffer);
1460 GT_assert (curTrace, (handle != NULL));
1461 GT_assert (curTrace, (numBytes != NULL));
1462 GT_assert (curTrace, (buffer != NULL));
1464 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1465 if (handle == NULL) {
1466 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1467 status = PROCESSOR_E_HANDLE;
1468 GT_setFailureReason (curTrace,
1469 GT_4CLASS,
1470 "VAYUDSPPROC_read",
1471 status,
1472 "Invalid handle specified");
1473 }
1474 else if (numBytes == 0) {
1475 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1476 status = PROCESSOR_E_INVALIDARG;
1477 GT_setFailureReason (curTrace,
1478 GT_4CLASS,
1479 "VAYUDSPPROC_read",
1480 status,
1481 "Invalid numBytes specified");
1482 }
1483 else if (buffer == NULL) {
1484 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1485 status = PROCESSOR_E_INVALIDARG;
1486 GT_setFailureReason (curTrace,
1487 GT_4CLASS,
1488 "VAYUDSPPROC_read",
1489 status,
1490 "Invalid buffer specified");
1491 }
1492 else {
1493 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1494 procPtr8 = (UInt8 *) procAddr ;
1495 buffer = Memory_copy (buffer, procPtr8, *numBytes);
1496 GT_assert (curTrace, (buffer != (UInt32) NULL));
1497 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1498 if (buffer == (UInt32) NULL) {
1499 /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1500 status = PROCESSOR_E_FAIL;
1501 GT_setFailureReason (curTrace,
1502 GT_4CLASS,
1503 "VAYUDSPPROC_read",
1504 status,
1505 "Failed in Memory_copy");
1506 *numBytes = 0;
1507 }
1508 }
1509 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1511 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_read",status);
1513 /*! @retval PROCESSOR_SUCCESS Operation successful */
1514 return status;
1515 }
1518 /*!
1519 * @brief Function to write into the slave processor's memory.
1520 *
1521 * Read from the provided buffer and copy into the slave
1522 * processor's memory.
1523 *
1524 * @param handle Handle to the Processor object
1525 * @param procAddr Address in host processor's address space of the
1526 * memory region to write into.
1527 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1528 * number of bytes to be written. When the function
1529 * returns, this parameter contains the number of bytes
1530 * actually written.
1531 * @param buffer User-provided buffer from which the data is to be
1532 * written into the slave processor's memory.
1533 *
1534 * @sa VAYUDSPPROC_read, VAYUDSPPROC_translateAddr
1535 */
1536 Int
1537 VAYUDSPPROC_write (Processor_Handle handle,
1538 UInt32 procAddr,
1539 UInt32 * numBytes,
1540 Ptr buffer)
1541 {
1542 Int status = PROCESSOR_SUCCESS ;
1543 UInt8 * procPtr8 = NULL;
1544 UInt8 temp8_1;
1545 UInt8 temp8_2;
1546 UInt8 temp8_3;
1547 UInt8 temp8_4;
1548 UInt32 temp;
1550 GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_write",
1551 handle, procAddr, numBytes, buffer);
1553 GT_assert (curTrace, (handle != NULL));
1554 GT_assert (curTrace, (numBytes != NULL));
1555 GT_assert (curTrace, (buffer != NULL));
1557 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1558 if (handle == NULL) {
1559 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1560 status = PROCESSOR_E_HANDLE;
1561 GT_setFailureReason (curTrace,
1562 GT_4CLASS,
1563 "VAYUDSPPROC_write",
1564 status,
1565 "Invalid handle specified");
1566 }
1567 else if (numBytes == 0) {
1568 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1569 status = PROCESSOR_E_INVALIDARG;
1570 GT_setFailureReason (curTrace,
1571 GT_4CLASS,
1572 "VAYUDSPPROC_write",
1573 status,
1574 "Invalid numBytes specified");
1575 }
1576 else if (buffer == NULL) {
1577 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1578 status = PROCESSOR_E_INVALIDARG;
1579 GT_setFailureReason (curTrace,
1580 GT_4CLASS,
1581 "VAYUDSPPROC_write",
1582 status,
1583 "Invalid buffer specified");
1584 }
1585 else {
1586 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1587 if (*numBytes != sizeof (UInt32)) {
1588 procPtr8 = (UInt8 *) procAddr ;
1589 procAddr = (UInt32) Memory_copy (procPtr8,
1590 buffer,
1591 *numBytes);
1592 GT_assert (curTrace, (procAddr != (UInt32) NULL));
1593 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1594 if (procAddr == (UInt32) NULL) {
1595 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1596 status = PROCESSOR_E_FAIL;
1597 GT_setFailureReason (curTrace,
1598 GT_4CLASS,
1599 "VAYUDSPPROC_write",
1600 status,
1601 "Failed in Memory_copy");
1602 *numBytes = 0;
1603 }
1604 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1605 }
1606 else {
1607 /* For 4 bytes, directly write as a UInt32 */
1608 temp8_1 = ((UInt8 *) buffer) [0];
1609 temp8_2 = ((UInt8 *) buffer) [1];
1610 temp8_3 = ((UInt8 *) buffer) [2];
1611 temp8_4 = ((UInt8 *) buffer) [3];
1612 temp = (UInt32) ( ((UInt32) temp8_4 << 24)
1613 | ((UInt32) temp8_3 << 16)
1614 | ((UInt32) temp8_2 << 8)
1615 | ((UInt32) temp8_1));
1616 *((UInt32*) procAddr) = temp;
1617 }
1618 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1619 }
1620 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1622 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_write",status);
1624 /*! @retval PROCESSOR_SUCCESS Operation successful */
1625 return status;
1626 }
1629 /*!
1630 * @brief Function to perform device-dependent operations.
1631 *
1632 * Performs device-dependent control operations as exposed by this
1633 * implementation of the Processor module.
1634 *
1635 * @param handle Handle to the Processor object
1636 * @param cmd Device specific processor command
1637 * @param arg Arguments specific to the type of command.
1638 *
1639 * @sa
1640 */
1641 Int
1642 VAYUDSPPROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1643 {
1644 Int status = PROCESSOR_SUCCESS ;
1646 GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_control", handle, cmd, arg);
1648 GT_assert (curTrace, (handle != NULL));
1649 /* cmd and arg can be 0/NULL, so cannot check for validity. */
1651 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1652 if (handle == NULL) {
1653 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1654 status = PROCESSOR_E_HANDLE;
1655 GT_setFailureReason (curTrace,
1656 GT_4CLASS,
1657 "VAYUDSPPROC_control",
1658 status,
1659 "Invalid handle specified");
1660 }
1661 else {
1662 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1663 /* No control operations currently implemented. */
1664 /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1665 for this device. */
1666 status = PROCESSOR_E_NOTSUPPORTED;
1667 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1668 }
1669 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1670 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPROC_control",status);
1672 /*! @retval PROCESSOR_SUCCESS Operation successful */
1673 return status;
1674 }
1677 /*!
1678 * @brief Translate slave virtual address to master physical address.
1679 *
1680 * @param handle Handle to the Processor object
1681 * @param dstAddr Returned: master physical address.
1682 * @param srcAddr Slave virtual address.
1683 *
1684 * @sa
1685 */
1686 Int
1687 VAYUDSPPROC_translate(
1688 Processor_Handle handle,
1689 UInt32 * dstAddr,
1690 UInt32 srcAddr)
1691 {
1692 Int status = PROCESSOR_SUCCESS;
1693 Processor_Object * procHandle= (Processor_Object *)handle;
1694 VAYUDSPPROC_Object * object = NULL;
1695 UInt32 i;
1696 UInt32 startAddr;
1697 UInt32 endAddr;
1698 UInt32 offset;
1699 ProcMgr_AddrInfo * ai;
1701 GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1702 handle, dstAddr, srcAddr);
1704 GT_assert (curTrace, (handle != NULL));
1705 GT_assert (curTrace, (dstAddr != NULL));
1707 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1708 if (handle == NULL) {
1709 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1710 status = PROCESSOR_E_HANDLE;
1711 GT_setFailureReason (curTrace,
1712 GT_4CLASS,
1713 "VAYUDSPPROC_translate",
1714 status,
1715 "Invalid handle specified");
1716 }
1717 else if (dstAddr == NULL) {
1718 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1719 status = PROCESSOR_E_INVALIDARG;
1720 GT_setFailureReason (curTrace,
1721 GT_4CLASS,
1722 "VAYUDSPPROC_translate",
1723 status,
1724 "dstAddr provided as NULL");
1725 }
1726 else {
1727 #endif
1728 object = (VAYUDSPPROC_Object *)procHandle->object;
1729 GT_assert(curTrace, (object != NULL));
1730 *dstAddr = -1u;
1732 for (i = 0; i < AddrTable_count; i++) {
1733 ai = &AddrTable[i];
1734 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1735 endAddr = startAddr + ai->size;
1737 if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1738 offset = srcAddr - startAddr;
1739 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1740 break;
1741 }
1742 }
1744 if (*dstAddr == -1u) {
1745 if (!object->params.mmuEnable) {
1746 /* default to direct mapping (i.e. v=p) */
1747 *dstAddr = srcAddr;
1748 }
1749 else {
1750 /* srcAddr not found in slave address space */
1751 status = PROCESSOR_E_INVALIDARG;
1752 GT_setFailureReason(curTrace, GT_4CLASS,
1753 "VAYUDSPPROC_translate", status,
1754 "srcAddr not found in slave address space");
1755 }
1756 }
1757 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1758 }
1759 #endif
1760 GT_1trace(curTrace, GT_LEAVE,
1761 "VAYUDSPPROC_translate: status=0x%x", status);
1763 /*! @retval PROCESSOR_SUCCESS Operation successful */
1764 return status;
1765 }
1768 /*!
1769 * @brief Map the given address translation into the slave mmu
1770 *
1771 * @param handle Handle to the Processor object
1772 * @param dstAddr Base virtual address
1773 * @param nSegs Number of given segments
1774 * @param sglist Segment list
1775 */
1776 Int
1777 VAYUDSPPROC_map(
1778 Processor_Handle handle,
1779 UInt32 * dstAddr,
1780 UInt32 nSegs,
1781 Memory_SGList * sglist)
1782 {
1783 Int status = PROCESSOR_SUCCESS;
1784 Processor_Object * procHandle = (Processor_Object *)handle;
1785 VAYUDSPPROC_Object * object = NULL;
1786 Bool found = FALSE;
1787 UInt32 startAddr;
1788 UInt32 endAddr;
1789 UInt32 i;
1790 UInt32 j;
1791 ProcMgr_AddrInfo * ai = NULL;
1792 VAYUDSP_HalMmuCtrlArgs_AddEntry addEntryArgs;
1794 GT_4trace (curTrace, GT_ENTER, "VAYUDSPPROC_map",
1795 handle, dstAddr, nSegs, sglist);
1797 GT_assert (curTrace, (handle != NULL));
1798 GT_assert (curTrace, (sglist != NULL));
1799 GT_assert (curTrace, (nSegs > 0));
1801 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1802 if (handle == NULL) {
1803 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1804 status = PROCESSOR_E_HANDLE;
1805 GT_setFailureReason (curTrace,
1806 GT_4CLASS,
1807 "VAYUDSPPROC_map",
1808 status,
1809 "Invalid handle specified");
1810 }
1811 else if (sglist == NULL) {
1812 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1813 status = PROCESSOR_E_INVALIDARG;
1814 GT_setFailureReason (curTrace,
1815 GT_4CLASS,
1816 "VAYUDSPPROC_map",
1817 status,
1818 "sglist provided as NULL");
1819 }
1820 else if (nSegs == 0) {
1821 /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1822 status = PROCESSOR_E_INVALIDARG;
1823 GT_setFailureReason (curTrace,
1824 GT_4CLASS,
1825 "VAYUDSPPROC_map",
1826 status,
1827 "Number of segments provided is 0");
1828 }
1829 else {
1830 #endif
1831 object = (VAYUDSPPROC_Object *)procHandle->object;
1832 GT_assert (curTrace, (object != NULL));
1834 for (i = 0; (i < nSegs) && (status >= 0); i++) {
1835 /* Update the translation table with entries for which mapping
1836 * is required. Add the entry only if the range does not exist
1837 * in the translation table.
1838 */
1840 /* check in static entries first */
1841 for (j = 0; j < AddrTable_STATIC_COUNT; j++) {
1842 ai = &AddrTable [j];
1843 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1844 endAddr = startAddr + ai->size;
1846 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)) {
1847 found = TRUE;
1849 /* refCount does not need to be incremented for static entries */
1851 break;
1852 }
1853 }
1855 /* if not found in static entries, check in dynamic entries */
1856 if (!found) {
1857 for (j = AddrTable_STATIC_COUNT; j < AddrTable_count; j++) {
1858 ai = &AddrTable [j];
1860 if (ai->isMapped == TRUE) {
1861 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1862 endAddr = startAddr + ai->size;
1864 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1865 && ((*dstAddr + sglist[i].size) <= endAddr)) {
1866 found = TRUE;
1867 ai->refCount++;
1868 break;
1869 }
1870 }
1871 }
1872 }
1874 /* if not found and mmu is enabled, add new entry to table */
1875 if (!found) {
1876 if (object->params.mmuEnable) {
1877 if (AddrTable_count != AddrTable_SIZE) {
1878 ai = &AddrTable[AddrTable_count];
1880 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1881 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1882 ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1883 ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1884 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1885 ai->size = sglist[i].size;
1886 ai->isCached = sglist[i].isCached;
1887 ai->refCount++;
1889 AddrTable_count++;
1890 }
1891 else {
1892 status = PROCESSOR_E_FAIL;
1893 GT_setFailureReason(curTrace, GT_4CLASS,
1894 "VAYUDSPPROC_map", status,
1895 "AddrTable_SIZE reached!");
1896 }
1897 }
1898 else {
1899 /* if mmu disabled, AddrTable not updated */
1900 ai = NULL;
1901 }
1902 }
1904 /* if new entry, map into dsp mmu */
1905 if ((ai != NULL) && (ai->refCount == 1) && (status >= 0)) {
1906 ai->isMapped = TRUE;
1908 if (object->params.mmuEnable) {
1909 /* Add entry to Dsp mmu */
1910 addEntryArgs.masterPhyAddr = sglist [i].paddr;
1911 addEntryArgs.size = sglist [i].size;
1912 addEntryArgs.slaveVirtAddr = (UInt32)*dstAddr;
1913 /* TBD: elementSize, endianism, mixedSized are
1914 * hard coded now, must be configurable later
1915 */
1916 addEntryArgs.elementSize = ELEM_SIZE_16BIT;
1917 addEntryArgs.endianism = LITTLE_ENDIAN;
1918 addEntryArgs.mixedSize = MMU_TLBES;
1919 status = VAYUDSP_halMmuCtrl(object->halObject,
1920 Processor_MmuCtrlCmd_AddEntry, &addEntryArgs);
1921 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1922 if (status < 0) {
1923 GT_setFailureReason(curTrace, GT_4CLASS,
1924 "VAYUDSPPROC_map", status,
1925 "Processor_MmuCtrlCmd_AddEntry failed");
1926 }
1927 #endif
1928 }
1929 }
1930 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1931 if (status < 0) {
1932 GT_setFailureReason(curTrace, GT_4CLASS,
1933 "VAYUDSPPROC_map", status,
1934 "DSP MMU configuration failed");
1935 }
1936 #endif
1937 }
1938 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1939 }
1940 #endif
1941 GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_map", status);
1943 /*! @retval PROCESSOR_SUCCESS Operation successful */
1944 return status;
1945 }
1948 /*!
1949 * @brief Function to unmap slave address from host address space
1950 *
1951 * @param handle Handle to the Processor object
1952 * @param dstAddr Return parameter: Pointer to receive the mapped
1953 * address.
1954 * @param size Size of the region to be mapped.
1955 *
1956 * @sa
1957 */
1958 Int
1959 VAYUDSPPROC_unmap(
1960 Processor_Handle handle,
1961 UInt32 addr,
1962 UInt32 size)
1963 {
1964 Int status = PROCESSOR_SUCCESS;
1965 Processor_Object * procHandle = (Processor_Object *)handle;
1966 VAYUDSPPROC_Object * object = NULL;
1967 ProcMgr_AddrInfo * ai;
1968 Int i;
1969 UInt32 startAddr;
1970 UInt32 endAddr;
1971 VAYUDSP_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1973 GT_3trace (curTrace, GT_ENTER, "VAYUDSPPROC_unmap",
1974 handle, addr, size);
1976 GT_assert (curTrace, (handle != NULL));
1977 GT_assert (curTrace, (size != 0));
1979 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1980 if (handle == NULL) {
1981 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1982 status = PROCESSOR_E_HANDLE;
1983 GT_setFailureReason (curTrace,
1984 GT_4CLASS,
1985 "VAYUDSPPROC_unmap",
1986 status,
1987 "Invalid handle specified");
1988 }
1989 else if (size == 0) {
1990 /*! @retval PROCESSOR_E_INVALIDARG Size provided is zero */
1991 status = PROCESSOR_E_INVALIDARG;
1992 GT_setFailureReason (curTrace,
1993 GT_4CLASS,
1994 "VAYUDSPPROC_unmap",
1995 status,
1996 "Size provided is zero");
1997 }
1998 else {
1999 #endif
2000 object = (VAYUDSPPROC_Object *) procHandle->object;
2001 GT_assert (curTrace, (object != NULL));
2003 /* Delete dynamically added non-default entries from translation
2004 * table only in last unmap called on that entry
2005 */
2006 for (i = AddrTable_STATIC_COUNT; i < AddrTable_count; i++) {
2007 ai = &AddrTable[i];
2009 if (!ai->isMapped) {
2010 continue;
2011 }
2013 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
2014 endAddr = startAddr + ai->size;
2016 if ((startAddr <= addr) && (addr < endAddr)) {
2017 ai->refCount--;
2019 if (ai->refCount == 0) {
2020 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
2021 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
2022 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
2023 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2024 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2025 ai->size = 0u;
2026 ai->isCached = FALSE;
2027 ai->mapMask = 0u;
2028 ai->isMapped = FALSE;
2030 if (object->params.mmuEnable) {
2031 /* Remove the entry from the DSP MMU also */
2032 deleteEntryArgs.size = size;
2033 deleteEntryArgs.slaveVirtAddr = addr;
2034 /* TBD: elementSize, endianism, mixedSized are
2035 * hard coded now, must be configurable later
2036 */
2037 deleteEntryArgs.elementSize = ELEM_SIZE_16BIT;
2038 deleteEntryArgs.endianism = LITTLE_ENDIAN;
2039 deleteEntryArgs.mixedSize = MMU_TLBES;
2041 status = VAYUDSP_halMmuCtrl(object->halObject,
2042 Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2043 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2044 if (status < 0) {
2045 GT_setFailureReason(curTrace, GT_4CLASS,
2046 "VAYUDSPPROC_unmap", status,
2047 "DSP MMU configuration failed");
2048 }
2049 #endif
2050 }
2051 }
2052 }
2053 }
2054 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
2055 }
2056 #endif
2057 GT_1trace(curTrace, GT_LEAVE, "VAYUDSPPROC_unmap", status);
2059 /*! @retval PROCESSOR_SUCCESS Operation successful */
2060 return status;
2061 }
2064 #if defined (__cplusplus)
2065 }
2066 #endif /* defined (__cplusplus) */