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