0c13a7e9dd52d533c6ce47e89ea4d1149699b1f8
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayuipu / vayucore0 / VAYUIpuCore0Proc.c
1 /*
2 * @file VAYUIpuCore0Proc.c
3 *
4 * @brief Processor implementation for VAYUIPUCORE0.
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 VAYUIPUCORE0.
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 <VAYUIpuCore0Proc.h>
70 #include <_VAYUIpuCore0Proc.h>
71 #include <VAYUIpuHal.h>
72 #include <VAYUIpuCore0HalReset.h>
73 #include <VAYUIpuHalBoot.h>
74 #include <VAYUIpuEnabler.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 Max entries in address translation table.
92 */
93 #define AddrTable_SIZE 32
95 /* Number of IPUs supported */
96 #define NUM_IPUS 2
98 /* Convert procId to IPU # */
99 #define PROCID_TO_IPU(procId) (procId == VAYUIPUCORE0PROC_state.ipu1ProcId ?\
100 0 : 1)
103 /*!
104 * @brief VAYUIPUCORE0PROC Module state object
105 */
106 typedef struct VAYUIPUCORE0PROC_ModuleObject_tag {
107 UInt32 configSize;
108 /*!< Size of configuration structure */
109 VAYUIPUCORE0PROC_Config cfg;
110 /*!< VAYUIPUCORE0PROC configuration structure */
111 VAYUIPUCORE0PROC_Config defCfg;
112 /*!< Default module configuration */
113 VAYUIPUCORE0PROC_Params defInstParams;
114 /*!< Default parameters for the VAYUIPUCORE0PROC instances */
115 Bool isSetup;
116 /*!< Indicates whether the VAYUIPUCORE0PROC module is setup. */
117 VAYUIPUCORE0PROC_Handle procHandles [MultiProc_MAXPROCESSORS];
118 /*!< Processor handle array. */
119 IGateProvider_Handle gateHandle;
120 /*!< Handle of gate to be used for local thread safety */
121 UInt16 ipu1ProcId;
122 /*!< MultiProc id of IPU1 (to avoid multiple lookups) */
123 } VAYUIPUCORE0PROC_ModuleObject;
125 /* Memory region counters */
126 static UInt32 AddrTable_count[NUM_IPUS] = {
127 0,
128 0
129 };
131 /*
132 * Address translation tables
133 */
134 static ProcMgr_AddrInfo AddrTable_IPU1[AddrTable_SIZE];
135 static ProcMgr_AddrInfo AddrTable_IPU2[AddrTable_SIZE];
137 static ProcMgr_AddrInfo * AddrTable[NUM_IPUS] =
138 {
139 AddrTable_IPU1,
140 AddrTable_IPU2
141 };
143 /* =============================================================================
144 * Globals
145 * =============================================================================
146 */
148 /*!
149 * @var VAYUIPUCORE0PROC_state
150 *
151 * @brief VAYUIPUCORE0PROC state object variable
152 */
153 #if !defined(SYSLINK_BUILD_DEBUG)
154 static
155 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
156 VAYUIPUCORE0PROC_ModuleObject VAYUIPUCORE0PROC_state =
157 {
158 .isSetup = FALSE,
159 .configSize = sizeof(VAYUIPUCORE0PROC_Config),
160 .gateHandle = NULL,
161 .defInstParams.numMemEntries = 0,
162 };
164 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
165 extern String ProcMgr_sysLinkCfgParams;
167 /* =============================================================================
168 * APIs directly called by applications
169 * =============================================================================
170 */
171 /*!
172 * @brief Function to get the default configuration for the VAYUIPUCORE0PROC
173 * module.
174 *
175 * This function can be called by the application to get their
176 * configuration parameter to VAYUIPUCORE0PROC_setup filled in by the
177 * VAYUIPUCORE0PROC module with the default parameters. If the user
178 * does not wish to make any change in the default parameters, this
179 * API is not required to be called.
180 *
181 * @param cfg Pointer to the VAYUIPUCORE0PROC module configuration
182 * structure in which the default config is to be
183 * returned.
184 *
185 * @sa VAYUIPUCORE0PROC_setup
186 */
187 Void
188 VAYUIPUCORE0PROC_getConfig (VAYUIPUCORE0PROC_Config * cfg)
189 {
190 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_getConfig", cfg);
192 GT_assert (curTrace, (cfg != NULL));
194 #if !defined(SYSLINK_BUILD_OPTIMIZE)
195 if (cfg == NULL) {
196 GT_setFailureReason (curTrace,
197 GT_4CLASS,
198 "VAYUIPUCORE0PROC_getConfig",
199 PROCESSOR_E_INVALIDARG,
200 "Argument of type (VAYUIPUCORE0PROC_Config *) passed "
201 "is null!");
202 }
203 else {
204 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
205 Memory_copy (cfg,
206 &(VAYUIPUCORE0PROC_state.defCfg),
207 sizeof (VAYUIPUCORE0PROC_Config));
208 #if !defined(SYSLINK_BUILD_OPTIMIZE)
209 }
210 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
212 GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_getConfig");
213 }
216 /*!
217 * @brief Function to setup the VAYUIPUCORE0PROC module.
218 *
219 * This function sets up the VAYUIPUCORE0PROC module. This function
220 * must be called before any other instance-level APIs can be
221 * invoked.
222 * Module-level configuration needs to be provided to this
223 * function. If the user wishes to change some specific config
224 * parameters, then VAYUIPUCORE0PROC_getConfig can be called to get the
225 * configuration filled with the default values. After this, only
226 * the required configuration values can be changed. If the user
227 * does not wish to make any change in the default parameters, the
228 * application can simply call VAYUIPUCORE0PROC_setup with NULL
229 * parameters. The default parameters would get automatically used.
230 *
231 * @param cfg Optional VAYUIPUCORE0PROC module configuration. If provided as
232 * NULL, default configuration is used.
233 *
234 * @sa VAYUIPUCORE0PROC_destroy
235 * GateMutex_create
236 */
237 Int
238 VAYUIPUCORE0PROC_setup (VAYUIPUCORE0PROC_Config * cfg)
239 {
240 Int status = PROCESSOR_SUCCESS;
241 VAYUIPUCORE0PROC_Config tmpCfg;
242 Error_Block eb;
244 Error_init(&eb);
246 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_setup", cfg);
248 if (cfg == NULL) {
249 VAYUIPUCORE0PROC_getConfig (&tmpCfg);
250 cfg = &tmpCfg;
251 }
253 /* Create a default gate handle for local module protection. */
254 VAYUIPUCORE0PROC_state.gateHandle = (IGateProvider_Handle)
255 GateMutex_create ((GateMutex_Params*)NULL, &eb);
256 #if !defined(SYSLINK_BUILD_OPTIMIZE)
257 if (VAYUIPUCORE0PROC_state.gateHandle == NULL) {
258 /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
259 status = PROCESSOR_E_FAIL;
260 GT_setFailureReason (curTrace,
261 GT_4CLASS,
262 "VAYUIPUCORE0PROC_setup",
263 status,
264 "Failed to create GateMutex!");
265 }
266 else {
267 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
268 /* Copy the user provided values into the state object. */
269 Memory_copy (&VAYUIPUCORE0PROC_state.cfg,
270 cfg,
271 sizeof (VAYUIPUCORE0PROC_Config));
273 /* Initialize the name to handles mapping array. */
274 Memory_set (&VAYUIPUCORE0PROC_state.procHandles,
275 0,
276 (sizeof (VAYUIPUCORE0PROC_Handle) * MultiProc_MAXPROCESSORS));
278 VAYUIPUCORE0PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
279 VAYUIPUCORE0PROC_state.isSetup = TRUE;
280 #if !defined(SYSLINK_BUILD_OPTIMIZE)
281 }
282 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
284 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_setup", status);
286 /*! @retval PROCESSOR_SUCCESS Operation successful */
287 return (status);
288 }
291 /*!
292 * @brief Function to destroy the VAYUIPUCORE0PROC module.
293 *
294 * Once this function is called, other VAYUIPUCORE0PROC module APIs,
295 * except for the VAYUIPUCORE0PROC_getConfig API cannot be called
296 * anymore.
297 *
298 * @sa VAYUIPUCORE0PROC_setup
299 * GateMutex_delete
300 */
301 Int
302 VAYUIPUCORE0PROC_destroy (Void)
303 {
304 Int status = PROCESSOR_SUCCESS;
305 UInt16 i;
307 GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_destroy");
309 /* Check if any VAYUIPUCORE0PROC instances have not been deleted so far. If not,
310 * delete them.
311 */
312 for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
313 GT_assert (curTrace, (VAYUIPUCORE0PROC_state.procHandles [i] == NULL));
314 if (VAYUIPUCORE0PROC_state.procHandles [i] != NULL) {
315 VAYUIPUCORE0PROC_delete (&(VAYUIPUCORE0PROC_state.procHandles [i]));
316 }
317 }
319 if (VAYUIPUCORE0PROC_state.gateHandle != NULL) {
320 GateMutex_delete ((GateMutex_Handle *)
321 &(VAYUIPUCORE0PROC_state.gateHandle));
322 }
324 VAYUIPUCORE0PROC_state.isSetup = FALSE;
326 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_destroy", status);
328 /*! @retval PROCESSOR_SUCCESS Operation successful */
329 return (status);
330 }
333 /*!
334 * @brief Function to initialize the parameters for this Processor
335 * instance.
336 *
337 * @param params Configuration parameters to be returned
338 *
339 * @sa VAYUIPUCORE0PROC_create
340 */
341 Void
342 VAYUIPUCORE0PROC_Params_init(
343 VAYUIPUCORE0PROC_Handle handle,
344 VAYUIPUCORE0PROC_Params * params)
345 {
346 VAYUIPUCORE0PROC_Object *procObject = (VAYUIPUCORE0PROC_Object *)handle;
348 GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_Params_init",
349 handle, params);
351 GT_assert(curTrace, (params != NULL));
353 #if !defined(SYSLINK_BUILD_OPTIMIZE)
354 if (params == NULL) {
355 GT_setFailureReason(curTrace, GT_4CLASS,
356 "VAYUIPUCORE0PROC_Params_init",
357 PROCESSOR_E_INVALIDARG,
358 "Argument of type (VAYUIPUCORE0PROC_Params *) "
359 "passed is null!");
360 }
361 else {
362 #endif
363 if (handle == NULL) {
365 Memory_copy(params, &(VAYUIPUCORE0PROC_state.defInstParams),
366 sizeof (VAYUIPUCORE0PROC_Params));
367 }
368 else {
369 /* return updated VAYUIPUCORE0PROC instance specific parameters */
370 Memory_copy(params, &(procObject->params),
371 sizeof(VAYUIPUCORE0PROC_Params));
372 }
373 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
374 }
375 #endif
377 GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_Params_init");
378 }
380 /*!
381 * @brief Function to create an instance of this Processor.
382 *
383 * @param name Name of the Processor instance.
384 * @param params Configuration parameters.
385 *
386 * @sa VAYUIPUCORE0PROC_delete
387 */
388 VAYUIPUCORE0PROC_Handle
389 VAYUIPUCORE0PROC_create ( UInt16 procId,
390 const VAYUIPUCORE0PROC_Params * params)
391 {
392 Int status = PROCESSOR_SUCCESS;
393 Processor_Object * handle = NULL;
394 VAYUIPUCORE0PROC_Object * object = NULL;
395 Int i = 0;
396 ProcMgr_AddrInfo *ai = NULL;
397 IArg key;
398 List_Params listParams;
400 GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_create", procId, params);
402 GT_assert (curTrace, IS_VALID_PROCID (procId));
403 GT_assert (curTrace, (params != NULL));
405 #if !defined(SYSLINK_BUILD_OPTIMIZE)
406 if (!IS_VALID_PROCID (procId)) {
407 /* Not setting status here since this function does not return status.*/
408 GT_setFailureReason (curTrace,
409 GT_4CLASS,
410 "VAYUIPUCORE0PROC_create",
411 PROCESSOR_E_INVALIDARG,
412 "Invalid procId specified");
413 }
414 else if (params == NULL) {
415 GT_setFailureReason (curTrace,
416 GT_4CLASS,
417 "VAYUIPUCORE0PROC_create",
418 PROCESSOR_E_INVALIDARG,
419 "params passed is NULL!");
420 }
421 else {
422 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
423 /* Enter critical section protection. */
424 key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
425 #if !defined(SYSLINK_BUILD_OPTIMIZE)
426 /* Check if the Processor already exists for specified procId. */
427 if (VAYUIPUCORE0PROC_state.procHandles [procId] != NULL) {
428 status = PROCESSOR_E_ALREADYEXIST;
429 GT_setFailureReason (curTrace,
430 GT_4CLASS,
431 "VAYUIPUCORE0PROC_create",
432 status,
433 "Processor already exists for specified procId!");
434 }
435 else {
436 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
437 /* Allocate memory for the handle */
438 handle = (Processor_Object *) Memory_calloc (NULL,
439 sizeof (Processor_Object),
440 0,
441 NULL);
442 if (handle == NULL) {
443 GT_setFailureReason (curTrace,
444 GT_4CLASS,
445 "VAYUIPUCORE0PROC_create",
446 PROCESSOR_E_MEMORY,
447 "Memory allocation failed for handle!");
448 }
449 else {
450 /* Populate the handle fields */
451 handle->procFxnTable.attach = &VAYUIPUCORE0PROC_attach;
452 handle->procFxnTable.detach = &VAYUIPUCORE0PROC_detach;
453 handle->procFxnTable.start = &VAYUIPUCORE0PROC_start;
454 handle->procFxnTable.stop = &VAYUIPUCORE0PROC_stop;
455 handle->procFxnTable.read = &VAYUIPUCORE0PROC_read;
456 handle->procFxnTable.write = &VAYUIPUCORE0PROC_write;
457 handle->procFxnTable.control = &VAYUIPUCORE0PROC_control;
458 handle->procFxnTable.map = &VAYUIPUCORE0PROC_map;
459 handle->procFxnTable.unmap = &VAYUIPUCORE0PROC_unmap;
460 handle->procFxnTable.translateAddr = &VAYUIPUCORE0PROC_translate;
461 handle->procFxnTable.translateFromPte =
462 &VAYUIPUCORE0PROC_translateFromPte;
463 handle->state = ProcMgr_State_Unknown;
465 /* Allocate memory for the VAYUIPUCORE0PROC handle */
466 handle->object = Memory_calloc (NULL,
467 sizeof (VAYUIPUCORE0PROC_Object),
468 0,
469 NULL);
470 if (handle->object == NULL) {
471 status = PROCESSOR_E_MEMORY;
472 GT_setFailureReason (curTrace,
473 GT_4CLASS,
474 "VAYUIPUCORE0PROC_create",
475 status,
476 "Memory allocation failed for handle->object!");
477 }
478 else {
479 handle->procId = procId;
480 object = (VAYUIPUCORE0PROC_Object *) handle->object;
481 object->procHandle = (Processor_Handle)handle;
482 object->halObject = NULL;
483 /* Copy params into instance object. */
484 Memory_copy (&(object->params),
485 (Ptr) params,
486 sizeof (VAYUIPUCORE0PROC_Params));
488 /* initialize the translation table */
489 for (i = AddrTable_count[PROCID_TO_IPU(procId)];
490 i < AddrTable_SIZE; i++) {
491 ai = &AddrTable[PROCID_TO_IPU(procId)][i];
492 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
493 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
494 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
495 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
496 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
497 ai->size = 0u;
498 ai->isCached = FALSE;
499 ai->mapMask = 0u;
500 ai->isMapped = FALSE;
501 }
503 /*
504 * initialize refCount for all entries
505 */
506 for (i = 0; i < AddrTable_SIZE; i++) {
507 AddrTable[PROCID_TO_IPU(procId)][i].refCount = 0u;
508 }
509 Memory_copy((Ptr)(object->params.memEntries),
510 AddrTable[PROCID_TO_IPU(procId)],
511 (procId == VAYUIPUCORE0PROC_state.ipu1ProcId ?
512 sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
514 /* Set the handle in the state object. */
515 VAYUIPUCORE0PROC_state.procHandles [procId] =
516 (VAYUIPUCORE0PROC_Handle) object;
517 /* Initialize the list of listeners */
518 List_Params_init(&listParams);
519 handle->registeredNotifiers = List_create(&listParams);
521 #if !defined(SYSLINK_BUILD_OPTIMIZE)
522 if (handle->registeredNotifiers == NULL) {
523 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
524 status = PROCESSOR_E_FAIL;
525 GT_setFailureReason (curTrace,
526 GT_4CLASS,
527 "VAYUIPUCORE0PROC_create",
528 status,
529 "List_create failed");
530 }
531 else {
532 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
534 handle->notifiersLock =
535 OsalMutex_create(OsalMutex_Type_Interruptible);
537 #if !defined(SYSLINK_BUILD_OPTIMIZE)
538 if (handle->notifiersLock == NULL) {
539 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
540 status = PROCESSOR_E_FAIL;
541 GT_setFailureReason (curTrace,
542 GT_4CLASS,
543 "VAYUIPUCORE0PROC_create",
544 status,
545 "OsalMutex_create failed");
546 }
547 }
548 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
549 }
550 }
551 #if !defined(SYSLINK_BUILD_OPTIMIZE)
552 }
553 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
555 /* Leave critical section protection. */
556 IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
557 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
558 }
559 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
561 if (status < 0) {
562 if (handle != NULL) {
563 if (handle->registeredNotifiers != NULL) {
564 List_delete (&handle->registeredNotifiers);
565 }
566 if (handle->object != NULL) {
567 Memory_free (NULL,
568 handle->object,
569 sizeof (VAYUIPUCORE0PROC_Object));
570 }
571 Memory_free (NULL, handle, sizeof (Processor_Object));
572 }
573 /*! @retval NULL Function failed */
574 handle = NULL;
575 }
577 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_create", handle);
579 /*! @retval Valid-Handle Operation successful */
580 return (VAYUIPUCORE0PROC_Handle) handle;
581 }
584 /*!
585 * @brief Function to delete an instance of this Processor.
586 *
587 * The user provided pointer to the handle is reset after
588 * successful completion of this function.
589 *
590 * @param handlePtr Pointer to Handle to the Processor instance
591 *
592 * @sa VAYUIPUCORE0PROC_create
593 */
594 Int
595 VAYUIPUCORE0PROC_delete (VAYUIPUCORE0PROC_Handle * handlePtr)
596 {
597 Int status = PROCESSOR_SUCCESS;
598 VAYUIPUCORE0PROC_Object * object = NULL;
599 Processor_Object * handle;
600 IArg key;
601 List_Elem * elem = NULL;
602 Processor_RegisterElem * regElem = NULL;
604 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_delete", handlePtr);
606 GT_assert (curTrace, (handlePtr != NULL));
607 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
609 #if !defined(SYSLINK_BUILD_OPTIMIZE)
610 if (handlePtr == NULL) {
611 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
612 specified*/
613 status = PROCESSOR_E_INVALIDARG;
614 GT_setFailureReason (curTrace,
615 GT_4CLASS,
616 "VAYUIPUCORE0PROC_delete",
617 status,
618 "Invalid NULL handlePtr pointer specified");
619 }
620 else if (*handlePtr == NULL) {
621 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
622 status = PROCESSOR_E_HANDLE;
623 GT_setFailureReason (curTrace,
624 GT_4CLASS,
625 "VAYUIPUCORE0PROC_delete",
626 status,
627 "Invalid NULL *handlePtr specified");
628 }
629 else {
630 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
631 handle = (Processor_Object *) (*handlePtr);
632 /* Enter critical section protection. */
633 key = IGateProvider_enter (VAYUIPUCORE0PROC_state.gateHandle);
635 /* Reset handle in PwrMgr handle array. */
636 GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
637 VAYUIPUCORE0PROC_state.procHandles [handle->procId] = NULL;
639 /* Free memory used for the VAYUIPUCORE0PROC object. */
640 if (handle->object != NULL) {
641 object = (VAYUIPUCORE0PROC_Object *) handle->object;
642 Memory_free (NULL,
643 object,
644 sizeof (VAYUIPUCORE0PROC_Object));
645 handle->object = NULL;
646 }
648 /*
649 * Check the list of listeners to see if any are remaining
650 * and reply to them
651 */
652 OsalMutex_delete(&handle->notifiersLock);
654 while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
655 regElem = (Processor_RegisterElem *)elem;
657 /* Check if there is an associated timer and cancel it */
658 if (regElem->timer != -1) {
659 struct itimerspec value ;
660 value.it_value.tv_sec = 0;
661 value.it_value.tv_nsec = 0;
662 value.it_interval.tv_sec = 0;
663 value.it_interval.tv_nsec = 0;
664 timer_settime(regElem->timer, 0, &value, NULL);
666 timer_delete(regElem->timer);
667 regElem->timer = -1;
668 }
670 /* Call the callback function so it can clean up. */
671 regElem->info->cbFxn(handle->procId,
672 NULL,
673 handle->state,
674 handle->state,
675 ProcMgr_EventStatus_Canceled,
676 regElem->info->arg);
677 /* Free the memory */
678 Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
679 }
681 /* Delete the list of listeners */
682 List_delete(&handle->registeredNotifiers);
684 /* Free memory used for the Processor object. */
685 Memory_free (NULL, handle, sizeof (Processor_Object));
686 *handlePtr = NULL;
688 /* Leave critical section protection. */
689 IGateProvider_leave (VAYUIPUCORE0PROC_state.gateHandle, key);
690 #if !defined(SYSLINK_BUILD_OPTIMIZE)
691 }
692 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
694 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_delete", status);
696 /*! @retval PROCESSOR_SUCCESS Operation successful */
697 return (status);
698 }
701 /*!
702 * @brief Function to open a handle to an instance of this Processor. This
703 * function is called when access to the Processor is required from
704 * a different process.
705 *
706 * @param handlePtr Handle to the Processor instance
707 * @param procId Processor ID addressed by this Processor instance.
708 *
709 * @sa VAYUIPUCORE0PROC_close
710 */
711 Int
712 VAYUIPUCORE0PROC_open (VAYUIPUCORE0PROC_Handle * handlePtr, UInt16 procId)
713 {
714 Int status = PROCESSOR_SUCCESS;
716 GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_open", handlePtr, procId);
718 GT_assert (curTrace, (handlePtr != NULL));
719 GT_assert (curTrace, IS_VALID_PROCID (procId));
721 #if !defined(SYSLINK_BUILD_OPTIMIZE)
722 if (handlePtr == NULL) {
723 /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
724 status = PROCESSOR_E_HANDLE;
725 GT_setFailureReason (curTrace,
726 GT_4CLASS,
727 "VAYUIPUCORE0PROC_open",
728 status,
729 "Invalid NULL handlePtr specified");
730 }
731 else if (!IS_VALID_PROCID (procId)) {
732 /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
733 status = PROCESSOR_E_INVALIDARG;
734 GT_setFailureReason (curTrace,
735 GT_4CLASS,
736 "VAYUIPUCORE0PROC_open",
737 status,
738 "Invalid procId specified");
739 }
740 else {
741 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
742 /* Initialize return parameter handle. */
743 *handlePtr = NULL;
745 /* Check if the PwrMgr exists and return the handle if found. */
746 if (VAYUIPUCORE0PROC_state.procHandles [procId] == NULL) {
747 /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
748 status = PROCESSOR_E_NOTFOUND;
749 GT_setFailureReason (curTrace,
750 GT_4CLASS,
751 "VAYUIPUCORE0PROC_open",
752 status,
753 "Specified VAYUIPUCORE0PROC instance does not exist!");
754 }
755 else {
756 *handlePtr = VAYUIPUCORE0PROC_state.procHandles [procId];
757 }
758 #if !defined(SYSLINK_BUILD_OPTIMIZE)
759 }
760 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
762 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_open", status);
764 /*! @retval PROCESSOR_SUCCESS Operation successful */
765 return status;
766 }
769 /*!
770 * @brief Function to close a handle to an instance of this Processor.
771 *
772 * @param handlePtr Pointer to Handle to the Processor instance
773 *
774 * @sa VAYUIPUCORE0PROC_open
775 */
776 Int
777 VAYUIPUCORE0PROC_close (VAYUIPUCORE0PROC_Handle * handlePtr)
778 {
779 Int status = PROCESSOR_SUCCESS;
781 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_close", handlePtr);
783 GT_assert (curTrace, (handlePtr != NULL));
784 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
786 #if !defined(SYSLINK_BUILD_OPTIMIZE)
787 if (handlePtr == NULL) {
788 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
789 specified*/
790 status = PROCESSOR_E_INVALIDARG;
791 GT_setFailureReason (curTrace,
792 GT_4CLASS,
793 "VAYUIPUCORE0PROC_close",
794 status,
795 "Invalid NULL handlePtr pointer specified");
796 }
797 else if (*handlePtr == NULL) {
798 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
799 status = PROCESSOR_E_HANDLE;
800 GT_setFailureReason (curTrace,
801 GT_4CLASS,
802 "VAYUIPUCORE0PROC_close",
803 status,
804 "Invalid NULL *handlePtr specified");
805 }
806 else {
807 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
808 /* Nothing to be done for close. */
809 #if !defined(SYSLINK_BUILD_OPTIMIZE)
810 }
811 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
813 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_close", status);
815 /*! @retval PROCESSOR_SUCCESS Operation successful */
816 return status;
817 }
820 /* =============================================================================
821 * APIs called by Processor module (part of function table interface)
822 * =============================================================================
823 */
824 /*!
825 * @brief Function to initialize the slave processor
826 *
827 * @param handle Handle to the Processor instance
828 * @param params Attach parameters
829 *
830 * @sa VAYUIPUCORE0PROC_detach
831 */
832 Int
833 VAYUIPUCORE0PROC_attach(
834 Processor_Handle handle,
835 Processor_AttachParams * params)
836 {
838 Int status = PROCESSOR_SUCCESS;
839 Processor_Object * procHandle = (Processor_Object *)handle;
840 VAYUIPUCORE0PROC_Object * object = NULL;
841 UInt32 i = 0;
842 UInt32 index = 0;
843 ProcMgr_AddrInfo * me;
844 SysLink_MemEntry * entry;
845 SysLink_MemEntry_Block memBlock;
846 VAYUIPU_HalMmuCtrlArgs_Enable mmuEnableArgs;
847 VAYUIPU_HalParams halParams;
849 GT_2trace(curTrace, GT_ENTER,
850 "VAYUIPUCORE0PROC_attach", handle, params);
851 GT_assert (curTrace, (handle != NULL));
852 GT_assert (curTrace, (params != NULL));
854 #if !defined(SYSLINK_BUILD_OPTIMIZE)
855 if (handle == NULL) {
856 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
857 status = PROCESSOR_E_HANDLE;
858 GT_setFailureReason (curTrace,
859 GT_4CLASS,
860 "VAYUIPUCORE0PROC_attach",
861 status,
862 "Invalid handle specified");
863 }
864 else if (params == NULL) {
865 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
866 status = PROCESSOR_E_INVALIDARG;
867 GT_setFailureReason (curTrace,
868 GT_4CLASS,
869 "VAYUIPUCORE0PROC_attach",
870 status,
871 "Invalid params specified");
872 }
873 else {
874 #endif
875 object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
876 GT_assert (curTrace, (object != NULL));
878 /* Initialize halObject for Processor_translateFromPte to work */
879 halParams.procId = procHandle->procId;
880 status = VAYUIPU_halInit(&(object->halObject), &halParams);
882 if (status < 0) {
883 GT_setFailureReason(curTrace, GT_4CLASS,
884 "VAYUIPUCORE0PROC_attach", status,
885 "VAYUIPU_halInit failed");
886 }
888 /* Added for Netra Benelli core1 is cortex M4 */
889 params->procArch = Processor_ProcArch_M4;
891 object->pmHandle = params->pmHandle;
892 GT_0trace(curTrace, GT_1CLASS,
893 "VAYUIPUCORE0PROC_attach: Mapping memory regions");
895 if (status >= 0) {
896 /* search for dsp memory map */
897 status = RscTable_process(procHandle->procId,
898 TRUE,
899 &memBlock.numEntries,
900 procHandle,
901 procHandle->bootMode);
902 if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
903 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
904 status = PROCESSOR_E_INVALIDARG;
905 GT_setFailureReason (curTrace,
906 GT_4CLASS,
907 "VAYUIPUCORE0PROC_attach",
908 status,
909 "Failed to process resource table");
910 }
911 else {
912 status = RscTable_getMemEntries(procHandle->procId,
913 memBlock.memEntries,
914 &memBlock.numEntries);
915 if (status < 0) {
916 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
917 status = PROCESSOR_E_INVALIDARG;
918 GT_setFailureReason (curTrace,
919 GT_4CLASS,
920 "VAYUIPUCORE0PROC_attach",
921 status,
922 "Failed to get resource table memEntries");
923 }
924 }
925 }
927 /* update translation tables with memory map */
928 for (i = 0; (i < memBlock.numEntries)
929 && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
931 entry = &memBlock.memEntries[i];
933 if (entry->map == FALSE) {
934 /* update table with entries which don't require mapping */
935 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
936 AddrTable_SIZE) {
937 me = &AddrTable[PROCID_TO_IPU(procHandle->procId)][
938 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]];
940 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
941 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
942 me->addr[ProcMgr_AddrType_MasterPhys] =
943 entry->masterPhysAddr;
944 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
945 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
946 me->size = entry->size;
947 me->isCached = entry->isCached;
948 me->mapMask = entry->mapMask;
950 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
951 }
952 else {
953 status = PROCESSOR_E_FAIL;
954 GT_setFailureReason(curTrace, GT_4CLASS,
955 "VAYUIPUCORE0PROC_attach", status,
956 "AddrTable_SIZE reached!");
957 }
958 }
959 else if (entry->map == TRUE) {
960 /* send these entries back to ProcMgr for mapping */
961 index = object->params.numMemEntries;
963 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
964 me = &object->params.memEntries[index];
966 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
967 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
968 me->addr[ProcMgr_AddrType_MasterPhys] =
969 entry->masterPhysAddr;
970 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
971 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
972 me->size = entry->size;
973 me->isCached = entry->isCached;
974 me->mapMask = entry->mapMask;
976 object->params.numMemEntries++;
977 }
978 else {
979 status = PROCESSOR_E_FAIL;
980 GT_setFailureReason(curTrace, GT_4CLASS,
981 "VAYUIPUCORE0PROC_attach", status,
982 "ProcMgr_MAX_MEMORY_REGIONS reached!");
983 }
984 }
985 else {
986 status = PROCESSOR_E_INVALIDARG;
987 GT_setFailureReason(curTrace, GT_4CLASS,
988 "VAYUIPUCORE0PROC_attach", status,
989 "Memory map has entry with invalid 'map' value");
990 }
991 } /* for (...) */
993 if (status >= 0) {
994 /* populate the return params */
995 params->numMemEntries = object->params.numMemEntries;
996 memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
997 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1000 /* Setup the xbar for MMU fault interrupts */
1001 mmuEnableArgs.numMemEntries = 0;
1002 status = VAYUIPU_halMmuCtrl(object->halObject,
1003 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1005 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1006 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1008 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1009 if (status < 0) {
1010 GT_setFailureReason(curTrace, GT_4CLASS,
1011 "VAYUIPUCORE0PROC_attach", status,
1012 "Failed to enable the slave MMU");
1013 }
1014 else {
1015 #endif
1016 GT_0trace(curTrace, GT_2CLASS,
1017 "VAYUIPUCORE0PROC_attach: Slave MMU "
1018 "is configured!");
1020 /*
1021 * Pull IPU MMU out of reset to make internal
1022 * memory "loadable"
1023 */
1024 status = VAYUIPUCORE0_halResetCtrl(
1025 object->halObject,
1026 Processor_ResetCtrlCmd_MMU_Release);
1027 if (status < 0) {
1028 /*! @retval status */
1029 GT_setFailureReason(curTrace,
1030 GT_4CLASS,
1031 "VAYUIPUCORE0_halResetCtrl",
1032 status,
1033 "Reset MMU_Release failed");
1034 }
1035 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1036 }
1037 #endif
1038 }
1039 else {
1040 /* NoBoot, late-attach */
1041 /*
1042 * Setup MMU fault interrupt now since we won't have a chance
1043 * to do it in ProcMgr_start
1044 */
1045 rproc_enable_fault_interrupt(object->halObject);
1047 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1048 if (status < 0) {
1049 GT_setFailureReason(curTrace, GT_4CLASS,
1050 "VAYUIPUCORE0PROC_attach", status,
1051 "Failed to enable the slave MMU");
1052 }
1053 else {
1054 #endif
1055 GT_0trace(curTrace, GT_1CLASS,
1056 "VAYUIPUCORE0PROC_attach: Slave MMU interrupt is "
1057 "configured");
1058 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1059 }
1060 #endif
1061 }
1062 }
1063 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1064 }
1065 #endif
1067 GT_1trace(curTrace, GT_LEAVE,
1068 "VAYUIPUCORE0PROC_attach", status);
1070 /*! @retval PROCESSOR_SUCCESS Operation successful */
1071 return status;
1072 }
1075 /*!
1076 * @brief Function to detach from the Processor.
1077 *
1078 * @param handle Handle to the Processor instance
1079 *
1080 * @sa VAYUIPUCORE0PROC_attach
1081 */
1082 Int
1083 VAYUIPUCORE0PROC_detach (Processor_Handle handle)
1084 {
1085 Int status = PROCESSOR_SUCCESS;
1086 Int tmpStatus = PROCESSOR_SUCCESS;
1087 Processor_Object * procHandle = (Processor_Object *) handle;
1088 VAYUIPUCORE0PROC_Object * object = NULL;
1089 Int i = 0;
1090 ProcMgr_AddrInfo * ai;
1092 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_detach", handle);
1093 GT_assert (curTrace, (handle != NULL));
1095 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1096 if (handle == NULL) {
1097 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1098 status = PROCESSOR_E_HANDLE;
1099 GT_setFailureReason (curTrace,
1100 GT_4CLASS,
1101 "VAYUIPUCORE0PROC_detach",
1102 PROCESSOR_E_HANDLE,
1103 "Invalid handle specified");
1104 }
1105 else {
1106 #endif
1107 object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1108 GT_assert (curTrace, (object != NULL));
1110 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1111 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1113 GT_0trace(curTrace, GT_2CLASS,
1114 "VAYUIPUCORE0PROC_detach: Disabling Slave MMU ...");
1116 status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1117 Processor_ResetCtrlCmd_MMU_Reset);
1118 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1119 if (status < 0) {
1120 /*! @retval status */
1121 GT_setFailureReason (curTrace,
1122 GT_4CLASS,
1123 "VAYUIPUCORE0PROC_detach",
1124 status,
1125 "Reset MMU failed");
1126 }
1127 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1128 }
1129 else {
1130 status = rproc_disable_fault_interrupt(object->halObject);
1131 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1132 if (status < 0) {
1133 /*! @retval status */
1134 GT_setFailureReason (curTrace,
1135 GT_4CLASS,
1136 "VAYUIPUCORE0PROC_detach",
1137 status,
1138 "rproc_disable_fault_interrupt failed");
1139 }
1140 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1141 }
1143 if (status >= 0) {
1144 status = VAYUIPU_halMmuCtrl(object->halObject,
1145 Processor_MmuCtrlCmd_Disable, NULL);
1146 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1147 if (status < 0) {
1148 GT_setFailureReason(curTrace, GT_4CLASS,
1149 "VAYUIPUCORE0PROC_detach", status,
1150 "Failed to disable the slave MMU");
1151 }
1152 #endif
1153 }
1155 /* delete all dynamically added entries */
1156 for (i = 0; i <
1157 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1158 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1159 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1160 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1161 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1162 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1163 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1164 ai->size = 0u;
1165 ai->isCached = FALSE;
1166 ai->mapMask = 0u;
1167 ai->isMapped = FALSE;
1168 ai->refCount = 0u;
1169 }
1170 object->params.numMemEntries = 0;
1171 AddrTable_count[PROCID_TO_IPU(procHandle->procId)] = 0;
1173 //No need to reset.. that will be done in STOP
1174 /*tmpStatus = VAYUIPUCORE0_halResetCtrl(object->halObject,
1175 Processor_ResetCtrlCmd_Reset, NULL);
1177 GT_0trace(curTrace, GT_2CLASS,
1178 "VAYUIPUCORE0PROC_detach: Slave processor is now in reset");*/
1180 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1181 if ((tmpStatus < 0) && (status >= 0)) {
1182 status = tmpStatus;
1183 GT_setFailureReason (curTrace,
1184 GT_4CLASS,
1185 "VAYUIPUCORE0PROC_detach",
1186 status,
1187 "Failed to reset the slave processor");
1188 }
1189 #endif
1191 GT_0trace (curTrace,
1192 GT_2CLASS,
1193 " VAYUIPUCORE0PROC_detach: Unmapping memory regions\n");
1195 tmpStatus = VAYUIPU_halExit (object->halObject);
1196 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1197 if ((tmpStatus < 0) && (status >= 0)) {
1198 status = tmpStatus;
1199 GT_setFailureReason (curTrace,
1200 GT_4CLASS,
1201 "VAYUIPUCORE0PROC_detach",
1202 status,
1203 "Failed to finalize HAL object");
1204 }
1205 }
1206 #endif
1208 GT_1trace(curTrace, GT_LEAVE,
1209 "VAYUIPUCORE0PROC_detach", status);
1211 /*! @retval PROCESSOR_SUCCESS Operation successful */
1212 return status;
1213 }
1216 /*!
1217 * @brief Function to start the slave processor
1218 *
1219 * Start the slave processor running from its entry point.
1220 * Depending on the boot mode, this involves configuring the boot
1221 * address and releasing the slave from reset.
1222 *
1223 * @param handle Handle to the Processor instance
1224 *
1225 * @sa VAYUIPUCORE0PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE0_halResetCtrl
1226 */
1227 Int
1228 VAYUIPUCORE0PROC_start (Processor_Handle handle,
1229 UInt32 entryPt,
1230 Processor_StartParams * params)
1231 {
1232 Int status = PROCESSOR_SUCCESS ;
1233 Processor_Object * procHandle = (Processor_Object *) handle;
1234 VAYUIPUCORE0PROC_Object * object = NULL;
1237 GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_start",
1238 handle, entryPt, params);
1240 GT_assert (curTrace, (handle != NULL));
1241 GT_assert (curTrace, (params != NULL));
1243 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1244 if (handle == NULL) {
1245 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1246 status = PROCESSOR_E_HANDLE;
1247 GT_setFailureReason (curTrace,
1248 GT_4CLASS,
1249 "VAYUIPUCORE0PROC_start",
1250 status,
1251 "Invalid handle specified");
1252 }
1253 else if (params == NULL) {
1254 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1255 status = PROCESSOR_E_INVALIDARG;
1256 GT_setFailureReason (curTrace,
1257 GT_4CLASS,
1258 "VAYUIPUCORE0PROC_start",
1259 status,
1260 "Invalid params specified");
1261 }
1262 else {
1263 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1264 object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1265 GT_assert (curTrace, (object != NULL));
1266 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1267 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1268 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1269 /* Slave is to be started only for Boot mode and NoLoad mode. */
1270 /* Specify the IPU boot address in the boot config register */
1271 status = VAYUIPU_halBootCtrl (object->halObject,
1272 Processor_BootCtrlCmd_SetEntryPoint,
1273 (Ptr) entryPt);
1274 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1275 if (status < 0) {
1276 GT_setFailureReason (curTrace,
1277 GT_4CLASS,
1278 "VAYUIPUCORE0PROC_start",
1279 status,
1280 "Failed to set slave boot entry point");
1281 }
1282 else {
1283 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1284 status = rproc_ipu_setup(object->halObject,
1285 object->params.memEntries,
1286 object->params.numMemEntries);
1287 if (status < 0) {
1288 /*! @retval status */
1289 GT_setFailureReason (curTrace,
1290 GT_4CLASS,
1291 "VAYUIPUCORE0_halResetCtrl",
1292 status,
1293 "rproc_ipu_setup failed");
1294 }
1295 /* release the slave cpu from reset */
1296 if (status >= 0) {
1297 status = VAYUIPUCORE0_halResetCtrl(object->halObject,
1298 Processor_ResetCtrlCmd_Release);
1299 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1300 if (status < 0) {
1301 GT_setFailureReason (curTrace,
1302 GT_4CLASS,
1303 "VAYUIPUCORE0PROC_start",
1304 status,
1305 "Failed to release slave from reset");
1306 }
1307 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1308 }
1309 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1310 }
1311 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1312 }
1314 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1315 }
1316 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1318 if (status >= 0) {
1319 GT_0trace (curTrace,
1320 GT_1CLASS,
1321 " VAYUIPUCORE0PROC_start: Slave successfully started!\n");
1322 }
1323 else {
1324 GT_0trace (curTrace,
1325 GT_1CLASS,
1326 " VAYUIPUCORE0PROC_start: Slave could not be started!\n");
1327 }
1329 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_start", status);
1331 /*! @retval PROCESSOR_SUCCESS Operation successful */
1332 return status;
1333 }
1336 /*!
1337 * @brief Function to stop the slave processor
1338 *
1339 * Stop the execution of the slave processor. Depending on the boot
1340 * mode, this may result in placing the slave processor in reset.
1341 *
1342 * @param handle Handle to the Processor instance
1343 *
1344 * @sa VAYUIPUCORE0PROC_start, VAYUIPUCORE0_halResetCtrl
1345 */
1346 Int
1347 VAYUIPUCORE0PROC_stop (Processor_Handle handle)
1348 {
1349 Int status = PROCESSOR_SUCCESS ;
1350 Processor_Object * procHandle = (Processor_Object *) handle;
1351 VAYUIPUCORE0PROC_Object * object = NULL;
1353 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_stop", handle);
1355 GT_assert (curTrace, (handle != NULL));
1357 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1358 if (handle == NULL) {
1359 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1360 status = PROCESSOR_E_HANDLE;
1361 GT_setFailureReason (curTrace,
1362 GT_4CLASS,
1363 "VAYUIPUCORE0PROC_stop",
1364 status,
1365 "Invalid handle specified");
1366 }
1367 else {
1368 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1369 object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1370 GT_assert (curTrace, (object != NULL));
1371 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1372 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1373 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1374 /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1375 /* Place the slave processor in reset. */
1376 status = VAYUIPUCORE0_halResetCtrl (object->halObject,
1377 Processor_ResetCtrlCmd_Reset);
1379 GT_0trace (curTrace,
1380 GT_1CLASS,
1381 " VAYUIPUCORE0PROC_stop: Slave is now in reset!\n");
1382 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1383 if (status < 0) {
1384 GT_setFailureReason (curTrace,
1385 GT_4CLASS,
1386 "VAYUIPUCORE0PROC_stop",
1387 status,
1388 "Failed to place slave in reset");
1389 }
1390 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1391 rproc_ipu_destroy(object->halObject);
1392 }
1393 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1394 }
1395 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1396 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_stop", status);
1398 /*! @retval PROCESSOR_SUCCESS Operation successful */
1399 return status;
1400 }
1403 /*!
1404 * @brief Function to read from the slave processor's memory.
1405 *
1406 * Read from the slave processor's memory and copy into the
1407 * provided buffer.
1408 *
1409 * @param handle Handle to the Processor instance
1410 * @param procAddr Address in host processor's address space of the
1411 * memory region to read from.
1412 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1413 * number of bytes to be read. When the function
1414 * returns, this parameter contains the number of bytes
1415 * actually read.
1416 * @param buffer User-provided buffer in which the slave processor's
1417 * memory contents are to be copied.
1418 *
1419 * @sa VAYUIPUCORE0PROC_write
1420 */
1421 Int
1422 VAYUIPUCORE0PROC_read (Processor_Handle handle,
1423 UInt32 procAddr,
1424 UInt32 * numBytes,
1425 Ptr buffer)
1426 {
1427 Int status = PROCESSOR_SUCCESS ;
1428 UInt8 * procPtr8 = NULL;
1430 GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_read",
1431 handle, procAddr, numBytes, buffer);
1433 GT_assert (curTrace, (handle != NULL));
1434 GT_assert (curTrace, (numBytes != NULL));
1435 GT_assert (curTrace, (buffer != NULL));
1437 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1438 if (handle == NULL) {
1439 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1440 status = PROCESSOR_E_HANDLE;
1441 GT_setFailureReason (curTrace,
1442 GT_4CLASS,
1443 "VAYUIPUCORE0PROC_read",
1444 status,
1445 "Invalid handle specified");
1446 }
1447 else if (numBytes == 0) {
1448 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1449 status = PROCESSOR_E_INVALIDARG;
1450 GT_setFailureReason (curTrace,
1451 GT_4CLASS,
1452 "VAYUIPUCORE0PROC_read",
1453 status,
1454 "Invalid numBytes specified");
1455 }
1456 else if (buffer == NULL) {
1457 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1458 status = PROCESSOR_E_INVALIDARG;
1459 GT_setFailureReason (curTrace,
1460 GT_4CLASS,
1461 "VAYUIPUCORE0PROC_read",
1462 status,
1463 "Invalid buffer specified");
1464 }
1465 else {
1466 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1467 procPtr8 = (UInt8 *) procAddr ;
1468 buffer = memcpy (buffer, procPtr8, *numBytes);
1469 GT_assert (curTrace, (buffer != (UInt32) NULL));
1470 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1471 if (buffer == (UInt32) NULL) {
1472 /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1473 status = PROCESSOR_E_FAIL;
1474 GT_setFailureReason (curTrace,
1475 GT_4CLASS,
1476 "VAYUIPUCORE0PROC_read",
1477 status,
1478 "Failed in memcpy");
1479 *numBytes = 0;
1480 }
1481 }
1482 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1484 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_read",status);
1486 /*! @retval PROCESSOR_SUCCESS Operation successful */
1487 return status;
1488 }
1491 /*!
1492 * @brief Function to write into the slave processor's memory.
1493 *
1494 * Read from the provided buffer and copy into the slave
1495 * processor's memory.
1496 *
1497 * @param handle Handle to the Processor object
1498 * @param procAddr Address in host processor's address space of the
1499 * memory region to write into.
1500 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1501 * number of bytes to be written. When the function
1502 * returns, this parameter contains the number of bytes
1503 * actually written.
1504 * @param buffer User-provided buffer from which the data is to be
1505 * written into the slave processor's memory.
1506 *
1507 * @sa VAYUIPUCORE0PROC_read, VAYUIPUCORE0PROC_translateAddr
1508 */
1509 Int
1510 VAYUIPUCORE0PROC_write (Processor_Handle handle,
1511 UInt32 procAddr,
1512 UInt32 * numBytes,
1513 Ptr buffer)
1514 {
1515 Int status = PROCESSOR_SUCCESS ;
1516 UInt8 * procPtr8 = NULL;
1517 UInt8 temp8_1;
1518 UInt8 temp8_2;
1519 UInt8 temp8_3;
1520 UInt8 temp8_4;
1521 UInt32 temp;
1523 GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_write",
1524 handle, procAddr, numBytes, buffer);
1526 GT_assert (curTrace, (handle != NULL));
1527 GT_assert (curTrace, (numBytes != NULL));
1528 GT_assert (curTrace, (buffer != NULL));
1530 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1531 if (handle == NULL) {
1532 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1533 status = PROCESSOR_E_HANDLE;
1534 GT_setFailureReason (curTrace,
1535 GT_4CLASS,
1536 "VAYUIPUCORE0PROC_write",
1537 status,
1538 "Invalid handle specified");
1539 }
1540 else if (numBytes == 0) {
1541 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1542 status = PROCESSOR_E_INVALIDARG;
1543 GT_setFailureReason (curTrace,
1544 GT_4CLASS,
1545 "VAYUIPUCORE0PROC_write",
1546 status,
1547 "Invalid numBytes specified");
1548 }
1549 else if (buffer == NULL) {
1550 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1551 status = PROCESSOR_E_INVALIDARG;
1552 GT_setFailureReason (curTrace,
1553 GT_4CLASS,
1554 "VAYUIPUCORE0PROC_write",
1555 status,
1556 "Invalid buffer specified");
1557 }
1558 else {
1559 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1560 if (*numBytes != sizeof (UInt32)) {
1561 procPtr8 = (UInt8 *) procAddr ;
1562 procAddr = (UInt32) Memory_copy (procPtr8,
1563 buffer,
1564 *numBytes);
1565 GT_assert (curTrace, (procAddr != (UInt32) NULL));
1566 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1567 if (procAddr == (UInt32) NULL) {
1568 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1569 status = PROCESSOR_E_FAIL;
1570 GT_setFailureReason (curTrace,
1571 GT_4CLASS,
1572 "VAYUIPUCORE0PROC_write",
1573 status,
1574 "Failed in Memory_copy");
1575 *numBytes = 0;
1576 }
1577 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1578 }
1579 else {
1580 /* For 4 bytes, directly write as a UInt32 */
1581 temp8_1 = ((UInt8 *) buffer) [0];
1582 temp8_2 = ((UInt8 *) buffer) [1];
1583 temp8_3 = ((UInt8 *) buffer) [2];
1584 temp8_4 = ((UInt8 *) buffer) [3];
1585 temp = (UInt32) ( ((UInt32) temp8_4 << 24)
1586 | ((UInt32) temp8_3 << 16)
1587 | ((UInt32) temp8_2 << 8)
1588 | ((UInt32) temp8_1));
1589 *((UInt32*) procAddr) = temp;
1590 }
1591 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1592 }
1593 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1595 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_write", status);
1597 /*! @retval PROCESSOR_SUCCESS Operation successful */
1598 return status;
1599 }
1602 /*!
1603 * @brief Function to perform device-dependent operations.
1604 *
1605 * Performs device-dependent control operations as exposed by this
1606 * implementation of the Processor module.
1607 *
1608 * @param handle Handle to the Processor object
1609 * @param cmd Device specific processor command
1610 * @param arg Arguments specific to the type of command.
1611 *
1612 * @sa
1613 */
1614 Int
1615 VAYUIPUCORE0PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1616 {
1617 Int status = PROCESSOR_SUCCESS ;
1619 GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_control", handle, cmd, arg);
1621 GT_assert (curTrace, (handle != NULL));
1622 /* cmd and arg can be 0/NULL, so cannot check for validity. */
1624 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1625 if (handle == NULL) {
1626 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1627 status = PROCESSOR_E_HANDLE;
1628 GT_setFailureReason (curTrace,
1629 GT_4CLASS,
1630 "VAYUIPUCORE0PROC_control",
1631 status,
1632 "Invalid handle specified");
1633 }
1634 else {
1635 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1636 /* No control operations currently implemented. */
1637 /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1638 for this device. */
1639 status = PROCESSOR_E_NOTSUPPORTED;
1640 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1641 }
1642 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1643 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_control",status);
1645 /*! @retval PROCESSOR_SUCCESS Operation successful */
1646 return status;
1647 }
1650 /*!
1651 * @brief Translate slave virtual address to master physical address.
1652 *
1653 * @param handle Handle to the Processor object
1654 * @param dstAddr Returned: master physical address.
1655 * @param srcAddr Slave virtual address.
1656 *
1657 * @sa
1658 */
1659 Int
1660 VAYUIPUCORE0PROC_translate(
1661 Processor_Handle handle,
1662 UInt32 * dstAddr,
1663 UInt32 srcAddr)
1664 {
1665 Int status = PROCESSOR_SUCCESS;
1666 Processor_Object * procHandle= (Processor_Object *)handle;
1667 VAYUIPUCORE0PROC_Object * object = NULL;
1668 UInt32 i;
1669 UInt32 startAddr;
1670 UInt32 endAddr;
1671 UInt32 offset;
1672 ProcMgr_AddrInfo * ai;
1674 GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1675 handle, dstAddr, srcAddr);
1677 GT_assert (curTrace, (handle != NULL));
1678 GT_assert (curTrace, (dstAddr != NULL));
1680 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1681 if (handle == NULL) {
1682 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1683 status = PROCESSOR_E_HANDLE;
1684 GT_setFailureReason (curTrace,
1685 GT_4CLASS,
1686 "VAYUIPUCORE0PROC_translate",
1687 status,
1688 "Invalid handle specified");
1689 }
1690 else if (dstAddr == NULL) {
1691 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1692 status = PROCESSOR_E_INVALIDARG;
1693 GT_setFailureReason (curTrace,
1694 GT_4CLASS,
1695 "VAYUIPUCORE0PROC_translate",
1696 status,
1697 "dstAddr provided as NULL");
1698 }
1699 else {
1700 #endif
1701 object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1702 GT_assert(curTrace, (object != NULL));
1703 *dstAddr = -1u;
1705 /* search all entries AddrTable */
1706 for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1707 i++) {
1708 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1709 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1710 endAddr = startAddr + ai->size;
1712 if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1713 offset = srcAddr - startAddr;
1714 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1715 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE0PROC_translate: "
1716 "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1717 i, srcAddr, *dstAddr);
1718 break;
1719 }
1720 }
1722 if (*dstAddr == -1u) {
1723 /* srcAddr not found in slave address space */
1724 status = PROCESSOR_E_INVALIDARG;
1725 GT_setFailureReason(curTrace, GT_4CLASS,
1726 "VAYUIPUCORE0PROC_translate", status,
1727 "srcAddr not found in slave address space");
1728 }
1729 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1730 }
1731 #endif
1732 GT_1trace(curTrace, GT_LEAVE,
1733 "VAYUIPUCORE0PROC_translate: status=0x%x", status);
1735 /*! @retval PROCESSOR_SUCCESS Operation successful */
1736 return status;
1737 }
1739 /*!
1740 * @brief Translate slave virtual address to master physical address
1741 * by inspecting page table entries.
1742 *
1743 * @param handle Handle to the Processor object
1744 * @param dstAddr Returned: master physical address.
1745 * @param srcAddr Slave virtual address.
1746 *
1747 * @sa
1748 */
1749 Int
1750 VAYUIPUCORE0PROC_translateFromPte(
1751 Processor_Handle handle,
1752 UInt32 * dstAddr,
1753 UInt32 srcAddr)
1754 {
1755 Int status = PROCESSOR_SUCCESS;
1756 Processor_Object * procHandle= (Processor_Object *)handle;
1757 VAYUIPUCORE0PROC_Object * object = NULL;
1759 GT_3trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_translateFromPte",
1760 handle, dstAddr, srcAddr);
1762 GT_assert (curTrace, (handle != NULL));
1763 GT_assert (curTrace, (dstAddr != NULL));
1765 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1766 if (handle == NULL) {
1767 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1768 status = PROCESSOR_E_HANDLE;
1769 GT_setFailureReason (curTrace,
1770 GT_4CLASS,
1771 "VAYUIPUCORE0PROC_translateFromPte",
1772 status,
1773 "Invalid handle specified");
1774 }
1775 else if (dstAddr == NULL) {
1776 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1777 status = PROCESSOR_E_INVALIDARG;
1778 GT_setFailureReason (curTrace,
1779 GT_4CLASS,
1780 "VAYUIPUCORE0PROC_translateFromPte",
1781 status,
1782 "dstAddr provided as NULL");
1783 }
1784 else {
1785 #endif
1786 object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1787 GT_assert(curTrace, (object != NULL));
1788 *dstAddr = -1u;
1790 status = rproc_mem_lookup(object->halObject, srcAddr, dstAddr);
1792 if (status < 0) {
1793 /* srcAddr not found in slave address space */
1794 status = PROCESSOR_E_INVALIDARG;
1795 GT_setFailureReason(curTrace, GT_4CLASS,
1796 "VAYUIPUCORE0PROC_translateFromPte", status,
1797 "srcAddr not found in slave address space");
1798 }
1799 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1800 }
1801 #endif
1802 GT_1trace(curTrace, GT_LEAVE,
1803 "VAYUIPUCORE0PROC_translateFromPte: status=0x%x", status);
1805 /*! @retval PROCESSOR_SUCCESS Operation successful */
1806 return status;
1807 }
1811 /*!
1812 * @brief Map the given address translation into the slave mmu
1813 *
1814 * @param handle Handle to the Processor object
1815 * @param dstAddr Base virtual address
1816 * @param nSegs Number of given segments
1817 * @param sglist Segment list
1818 */
1819 Int
1820 VAYUIPUCORE0PROC_map(
1821 Processor_Handle handle,
1822 UInt32 * dstAddr,
1823 UInt32 nSegs,
1824 Memory_SGList * sglist)
1825 {
1826 Int status = PROCESSOR_SUCCESS ;
1827 Processor_Object * procHandle = (Processor_Object *)handle;
1828 VAYUIPUCORE0PROC_Object * object = NULL;
1829 Bool found = FALSE;
1830 UInt32 startAddr;
1831 UInt32 endAddr;
1832 UInt32 i;
1833 UInt32 j;
1834 ProcMgr_AddrInfo * ai = NULL;
1836 GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE0PROC_map:",
1837 handle, *dstAddr, nSegs, sglist);
1839 GT_assert (curTrace, (handle != NULL));
1840 GT_assert (curTrace, (sglist != NULL));
1841 GT_assert (curTrace, (nSegs > 0));
1843 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1844 if (handle == NULL) {
1845 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1846 status = PROCESSOR_E_HANDLE;
1847 GT_setFailureReason (curTrace,
1848 GT_4CLASS,
1849 "VAYUIPUCORE0PROC_map",
1850 status,
1851 "Invalid handle specified");
1852 }
1853 else if (sglist == NULL) {
1854 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1855 status = PROCESSOR_E_INVALIDARG;
1856 GT_setFailureReason (curTrace,
1857 GT_4CLASS,
1858 "VAYUIPUCORE0PROC_map",
1859 status,
1860 "sglist provided as NULL");
1861 }
1862 else if (nSegs == 0) {
1863 /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1864 status = PROCESSOR_E_INVALIDARG;
1865 GT_setFailureReason (curTrace,
1866 GT_4CLASS,
1867 "VAYUIPUCORE0PROC_map",
1868 status,
1869 "Number of segments provided is 0");
1870 }
1871 else {
1872 #endif
1873 object = (VAYUIPUCORE0PROC_Object *)procHandle->object;
1874 GT_assert (curTrace, (object != NULL));
1876 for (i = 0; (i < nSegs) && (status >= 0); i++) {
1877 /* Update the translation table with entries for which mapping
1878 * is required. Add the entry only if the range does not exist
1879 * in the translation table.
1880 */
1881 for (j = 0;
1882 j < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; j++) {
1883 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1885 if (ai->isMapped == TRUE) {
1886 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1887 endAddr = startAddr + ai->size;
1889 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1890 && ((*dstAddr + sglist[i].size) <= endAddr)) {
1891 found = TRUE;
1892 ai->refCount++;
1893 break;
1894 }
1895 }
1896 }
1898 /* If not found, add new entry to table. If mmu is disabled,
1899 * the assumption is that the ammu will be used.
1900 */
1901 if (!found) {
1902 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1903 AddrTable_SIZE) {
1904 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1905 [AddrTable_count[PROCID_TO_IPU
1906 (procHandle->procId)]];
1907 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1908 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1909 ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1910 ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1911 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1912 ai->size = sglist[i].size;
1913 ai->isCached = sglist[i].isCached;
1914 ai->refCount++;
1915 ai->isMapped = TRUE;
1917 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1918 }
1919 else {
1920 status = PROCESSOR_E_FAIL;
1921 GT_setFailureReason(curTrace, GT_4CLASS,
1922 "VAYUIPUCORE0PROC_map", status,
1923 "AddrTable_SIZE reached!");
1924 }
1925 }
1926 }
1927 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1928 }
1929 #endif
1930 GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE0PROC_map", status);
1932 /*! @retval PROCESSOR_SUCCESS Operation successful */
1933 return status;
1934 }
1937 /*!
1938 * @brief Function to unmap slave address from host address space
1939 *
1940 * @param handle Handle to the Processor object
1941 * @param dstAddr Return parameter: Pointer to receive the mapped
1942 * address.
1943 * @param size Size of the region to be mapped.
1944 *
1945 * @sa
1946 */
1947 Int
1948 VAYUIPUCORE0PROC_unmap(
1949 Processor_Handle handle,
1950 UInt32 addr,
1951 UInt32 size)
1952 {
1953 Int status = PROCESSOR_SUCCESS;
1954 Processor_Object * procHandle = (Processor_Object *)handle;
1955 VAYUIPUCORE0PROC_Object * object = NULL;
1956 ProcMgr_AddrInfo * ai;
1957 Int i;
1958 UInt32 startAddr;
1959 UInt32 endAddr;
1960 VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1962 GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE0PROC_unmap",
1963 handle, addr, size);
1965 GT_assert (curTrace, (handle != NULL));
1966 GT_assert (curTrace, (size != 0));
1968 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1969 if (handle == NULL) {
1970 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1971 status = PROCESSOR_E_HANDLE;
1972 GT_setFailureReason (curTrace,
1973 GT_4CLASS,
1974 "VAYUIPUCORE0PROC_unmap",
1975 status,
1976 "Invalid handle specified");
1977 }
1978 else if (size == 0) {
1979 /*! @retval PROCESSOR_E_INVALIDARG Size provided is zero */
1980 status = PROCESSOR_E_INVALIDARG;
1981 GT_setFailureReason (curTrace,
1982 GT_4CLASS,
1983 "VAYUIPUCORE0PROC_unmap",
1984 status,
1985 "Size provided is zero");
1986 }
1987 else {
1988 #endif
1989 object = (VAYUIPUCORE0PROC_Object *) procHandle->object;
1990 GT_assert (curTrace, (object != NULL));
1992 /* Delete added entries from translation
1993 * table only in last unmap called on that entry
1994 */
1995 for (i = 0;
1996 i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1997 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1999 if (!ai->isMapped) {
2000 continue;
2001 }
2003 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
2004 endAddr = startAddr + ai->size;
2006 if ((startAddr <= addr) && (addr < endAddr)) {
2007 ai->refCount--;
2009 if (ai->refCount == 0) {
2010 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
2011 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
2012 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
2013 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2014 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2015 ai->size = 0u;
2016 ai->isCached = FALSE;
2017 ai->mapMask = 0u;
2018 ai->isMapped = FALSE;
2020 /* Remove the entry from the IPUCORE0 MMU also */
2021 deleteEntryArgs.size = size;
2022 deleteEntryArgs.slaveVirtAddr = addr;
2023 /* TBD: elementSize, endianism, mixedSized are
2024 * hard coded now, must be configurable later
2025 */
2026 deleteEntryArgs.elementSize = ELEM_SIZE_16BIT;
2027 deleteEntryArgs.endianism = LITTLE_ENDIAN;
2028 deleteEntryArgs.mixedSize = MMU_TLBES;
2030 status = VAYUIPU_halMmuCtrl(object->halObject,
2031 Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2032 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2033 if (status < 0) {
2034 GT_setFailureReason(curTrace, GT_4CLASS,
2035 "VAYUIPUCORE0PROC_unmap", status,
2036 "IPUCORE0 MMU configuration failed");
2037 }
2038 #endif
2039 }
2040 }
2041 }
2042 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2043 }
2044 #endif
2045 GT_1trace(curTrace, GT_LEAVE,
2046 "VAYUIPUCORE0PROC_unmap", status);
2048 /*! @retval PROCESSOR_SUCCESS Operation successful */
2049 return status;
2050 }
2053 #if defined (__cplusplus)
2054 }
2055 #endif /* defined (__cplusplus) */