2433986b9ef1d9a01b91183f1ab6c5cc6950950d
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayuipu / vayucore1 / VAYUIpuCore1Proc.c
1 /*
2 * @file VAYUIpuCore1Proc.c
3 *
4 * @brief Processor implementation for VAYUIPUCORE1.
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 VAYUIPUCORE1.
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 <VAYUIpuCore1Proc.h>
70 #include <_VAYUIpuCore1Proc.h>
71 #include <VAYUIpuHal.h>
72 #include <VAYUIpuCore1HalReset.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 Number of static entries in address translation table.
92 */
93 #define AddrTable_STATIC_COUNT 1
95 /*!
96 * @brief Max entries in address translation table.
97 */
98 #define AddrTable_SIZE 32
100 /* Number of IPUs supported */
101 #define NUM_IPUS 2
103 /* Convert procId to IPU # */
104 #define PROCID_TO_IPU(procId) (procId == VAYUIPUCORE1PROC_state.ipu1ProcId ?\
105 0 : 1)
107 #define PARAMS_MAX_NAMELENGTH 64
108 /* Config param for L2MMU. This is not a typo, we are using the
109 * same name (IPU1) because both Benelli M4 processors use the
110 * same L2MMU. The docs expose IPUx but not the IPUx Core1 processor.
111 */
112 #define PARAMS_mmuEnable1 "ProcMgr.proc[IPU1].mmuEnable="
113 #define PARAMS_carveoutAddr1 "ProcMgr.proc[IPU1].carveoutAddr"
114 #define PARAMS_carveoutSize1 "ProcMgr.proc[IPU1].carveoutSize"
115 #define PARAMS_mmuEnable2 "ProcMgr.proc[IPU2].mmuEnable="
116 #define PARAMS_carveoutAddr2 "ProcMgr.proc[IPU2].carveoutAddr"
117 #define PARAMS_carveoutSize2 "ProcMgr.proc[IPU2].carveoutSize"
120 /*!
121 * @brief VAYUIPUCORE1PROC Module state object
122 */
123 typedef struct VAYUIPUCORE1PROC_ModuleObject_tag {
124 UInt32 configSize;
125 /*!< Size of configuration structure */
126 VAYUIPUCORE1PROC_Config cfg;
127 /*!< VAYUIPUCORE1PROC configuration structure */
128 VAYUIPUCORE1PROC_Config defCfg;
129 /*!< Default module configuration */
130 VAYUIPUCORE1PROC_Params defInstParams;
131 /*!< Default parameters for the VAYUIPUCORE1PROC instances */
132 Bool isSetup;
133 /*!< Indicates whether the VAYUIPUCORE1PROC module is setup. */
134 VAYUIPUCORE1PROC_Handle procHandles [MultiProc_MAXPROCESSORS];
135 /*!< Processor handle array. */
136 IGateProvider_Handle gateHandle;
137 /*!< Handle of gate to be used for local thread safety */
138 UInt16 ipu1ProcId;
139 /*!< MultiProc id of IPU1 (to avoid multiple lookups) */
140 } VAYUIPUCORE1PROC_ModuleObject;
142 /* Memory region counters */
143 static UInt32 AddrTable_count[NUM_IPUS] = {
144 AddrTable_STATIC_COUNT,
145 AddrTable_STATIC_COUNT,
146 };
148 /* static memory regions
149 * CAUTION: AddrTable_STATIC_COUNT must match number of entries below.
150 */
151 static ProcMgr_AddrInfo AddrTable_IPU1[AddrTable_SIZE] =
152 {
153 /* L2 RAM */
154 {
155 .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
156 .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
157 .addr[ProcMgr_AddrType_MasterPhys] = 0x55020000u,
158 .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
159 .addr[ProcMgr_AddrType_SlavePhys] = -1u,
160 .size = 0x10000u,
161 .isCached = FALSE,
162 .mapMask = ProcMgr_SLAVEVIRT,
163 .isMapped = TRUE,
164 .refCount = 0u /* refCount set to 0 for static entry */
165 },
166 };
168 static ProcMgr_AddrInfo AddrTable_IPU2[AddrTable_SIZE] =
169 {
170 /* L2 RAM */
171 {
172 .addr[ProcMgr_AddrType_MasterKnlVirt] = -1u,
173 .addr[ProcMgr_AddrType_MasterUsrVirt] = -1u,
174 .addr[ProcMgr_AddrType_MasterPhys] = 0x55020000u,
175 .addr[ProcMgr_AddrType_SlaveVirt] = 0x20000000u,
176 .addr[ProcMgr_AddrType_SlavePhys] = -1u,
177 .size = 0x10000u,
178 .isCached = FALSE,
179 .mapMask = ProcMgr_SLAVEVIRT,
180 .isMapped = TRUE,
181 .refCount = 0u /* refCount set to 0 for static entry */
182 },
183 };
185 static ProcMgr_AddrInfo * AddrTable[NUM_IPUS] =
186 {
187 AddrTable_IPU1,
188 AddrTable_IPU2
189 };
191 /* =============================================================================
192 * Globals
193 * =============================================================================
194 */
196 /*!
197 * @var VAYUIPUCORE1PROC_state
198 *
199 * @brief VAYUIPUCORE1PROC state object variable
200 */
201 #if !defined(SYSLINK_BUILD_DEBUG)
202 static
203 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
204 VAYUIPUCORE1PROC_ModuleObject VAYUIPUCORE1PROC_state =
205 {
206 .isSetup = FALSE,
207 .configSize = sizeof (VAYUIPUCORE1PROC_Config),
208 .gateHandle = NULL,
209 .defInstParams.mmuEnable = FALSE,
210 .defInstParams.numMemEntries = AddrTable_STATIC_COUNT,
211 };
213 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
214 extern String ProcMgr_sysLinkCfgParams;
216 /* =============================================================================
217 * APIs directly called by applications
218 * =============================================================================
219 */
220 /*!
221 * @brief Function to get the default configuration for the VAYUIPUCORE1PROC
222 * module.
223 *
224 * This function can be called by the application to get their
225 * configuration parameter to VAYUIPUCORE1PROC_setup filled in by the
226 * VAYUIPUCORE1PROC module with the default parameters. If the user
227 * does not wish to make any change in the default parameters, this
228 * API is not required to be called.
229 *
230 * @param cfg Pointer to the VAYUIPUCORE1PROC module configuration
231 * structure in which the default config is to be
232 * returned.
233 *
234 * @sa VAYUIPUCORE1PROC_setup
235 */
236 Void
237 VAYUIPUCORE1PROC_getConfig (VAYUIPUCORE1PROC_Config * cfg)
238 {
239 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_getConfig", cfg);
241 GT_assert (curTrace, (cfg != NULL));
243 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
244 if (cfg == NULL) {
245 GT_setFailureReason (curTrace,
246 GT_4CLASS,
247 "VAYUIPUCORE1PROC_getConfig",
248 PROCESSOR_E_INVALIDARG,
249 "Argument of type (VAYUIPUCORE1PROC_Config *) passed "
250 "is null!");
251 }
252 else {
253 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
254 Memory_copy (cfg,
255 &(VAYUIPUCORE1PROC_state.defCfg),
256 sizeof (VAYUIPUCORE1PROC_Config));
257 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
258 }
259 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
261 GT_0trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_getConfig");
262 }
265 /*!
266 * @brief Function to setup the VAYUIPUCORE1PROC module.
267 *
268 * This function sets up the VAYUIPUCORE1PROC module. This function
269 * must be called before any other instance-level APIs can be
270 * invoked.
271 * Module-level configuration needs to be provided to this
272 * function. If the user wishes to change some specific config
273 * parameters, then VAYUIPUCORE1PROC_getConfig can be called to get the
274 * configuration filled with the default values. After this, only
275 * the required configuration values can be changed. If the user
276 * does not wish to make any change in the default parameters, the
277 * application can simply call VAYUIPUCORE1PROC_setup with NULL
278 * parameters. The default parameters would get automatically used.
279 *
280 * @param cfg Optional VAYUIPUCORE1PROC module configuration. If provided as
281 * NULL, default configuration is used.
282 *
283 * @sa VAYUIPUCORE1PROC_destroy
284 * GateMutex_create
285 */
286 Int
287 VAYUIPUCORE1PROC_setup (VAYUIPUCORE1PROC_Config * cfg)
288 {
289 Int status = PROCESSOR_SUCCESS;
290 VAYUIPUCORE1PROC_Config tmpCfg;
291 Error_Block eb;
293 Error_init(&eb);
295 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_setup", cfg);
297 if (cfg == NULL) {
298 VAYUIPUCORE1PROC_getConfig (&tmpCfg);
299 cfg = &tmpCfg;
300 }
302 /* Create a default gate handle for local module protection. */
303 VAYUIPUCORE1PROC_state.gateHandle = (IGateProvider_Handle)
304 GateMutex_create ((GateMutex_Params*)NULL, &eb);
305 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
306 if (VAYUIPUCORE1PROC_state.gateHandle == NULL) {
307 /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
308 status = PROCESSOR_E_FAIL;
309 GT_setFailureReason (curTrace,
310 GT_4CLASS,
311 "VAYUIPUCORE1PROC_setup",
312 status,
313 "Failed to create GateMutex!");
314 }
315 else {
316 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
317 /* Copy the user provided values into the state object. */
318 Memory_copy (&VAYUIPUCORE1PROC_state.cfg,
319 cfg,
320 sizeof (VAYUIPUCORE1PROC_Config));
322 /* Initialize the name to handles mapping array. */
323 Memory_set (&VAYUIPUCORE1PROC_state.procHandles,
324 0,
325 (sizeof (VAYUIPUCORE1PROC_Handle) * MultiProc_MAXPROCESSORS));
327 VAYUIPUCORE1PROC_state.ipu1ProcId = MultiProc_getId("IPU1");
328 VAYUIPUCORE1PROC_state.isSetup = TRUE;
329 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
330 }
331 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
333 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_setup", status);
335 /*! @retval PROCESSOR_SUCCESS Operation successful */
336 return (status);
337 }
340 /*!
341 * @brief Function to destroy the VAYUIPUCORE1PROC module.
342 *
343 * Once this function is called, other VAYUIPUCORE1PROC module APIs,
344 * except for the VAYUIPUCORE1PROC_getConfig API cannot be called
345 * anymore.
346 *
347 * @sa VAYUIPUCORE1PROC_setup
348 * GateMutex_delete
349 */
350 Int
351 VAYUIPUCORE1PROC_destroy (Void)
352 {
353 Int status = PROCESSOR_SUCCESS;
354 UInt16 i;
356 GT_0trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_destroy");
358 /* Check if any VAYUIPUCORE1PROC instances have not been deleted so far. If not,
359 * delete them.
360 */
361 for (i = 0 ; i < MultiProc_getNumProcessors() ; i++) {
362 GT_assert (curTrace, (VAYUIPUCORE1PROC_state.procHandles [i] == NULL));
363 if (VAYUIPUCORE1PROC_state.procHandles [i] != NULL) {
364 VAYUIPUCORE1PROC_delete (&(VAYUIPUCORE1PROC_state.procHandles [i]));
365 }
366 }
368 if (VAYUIPUCORE1PROC_state.gateHandle != NULL) {
369 GateMutex_delete ((GateMutex_Handle *)
370 &(VAYUIPUCORE1PROC_state.gateHandle));
371 }
373 VAYUIPUCORE1PROC_state.isSetup = FALSE;
375 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_destroy", status);
377 /*! @retval PROCESSOR_SUCCESS Operation successful */
378 return (status);
379 }
382 /*!
383 * @brief Function to initialize the parameters for this Processor
384 * instance.
385 *
386 * @param params Configuration parameters to be returned
387 *
388 * @sa VAYUIPUCORE1PROC_create
389 */
390 Void
391 VAYUIPUCORE1PROC_Params_init(
392 VAYUIPUCORE1PROC_Handle handle,
393 VAYUIPUCORE1PROC_Params * params)
394 {
395 VAYUIPUCORE1PROC_Object * procObject = (VAYUIPUCORE1PROC_Object *) handle;
397 GT_2trace(curTrace, GT_ENTER, "VAYUIPUCORE1PROC_Params_init",
398 handle, params);
400 GT_assert(curTrace, (params != NULL));
402 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
403 if (params == NULL) {
404 GT_setFailureReason(curTrace, GT_4CLASS,
405 "VAYUIPUCORE1PROC_Params_init",
406 PROCESSOR_E_INVALIDARG,
407 "Argument of type (VAYUIPUCORE1PROC_Params *) "
408 "passed is null!");
409 }
410 else {
411 #endif
412 if (handle == NULL) {
414 Memory_copy(params, &(VAYUIPUCORE1PROC_state.defInstParams),
415 sizeof(VAYUIPUCORE1PROC_Params));
417 }
418 else {
419 /* return updated VAYUIPUCORE1PROC instance specific parameters */
420 Memory_copy(params, &(procObject->params),
421 sizeof (VAYUIPUCORE1PROC_Params));
422 }
423 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
424 }
425 #endif
427 GT_0trace(curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_Params_init");
428 }
430 /*!
431 * @brief Function to create an instance of this Processor.
432 *
433 * @param name Name of the Processor instance.
434 * @param params Configuration parameters.
435 *
436 * @sa VAYUIPUCORE1PROC_delete
437 */
438 VAYUIPUCORE1PROC_Handle
439 VAYUIPUCORE1PROC_create ( UInt16 procId,
440 const VAYUIPUCORE1PROC_Params * params)
441 {
442 Int status = PROCESSOR_SUCCESS;
443 Processor_Object * handle = NULL;
444 VAYUIPUCORE1PROC_Object * object = NULL;
445 Int i = 0;
446 ProcMgr_AddrInfo *ai = NULL;
447 IArg key;
448 List_Params listParams;
450 GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_create", procId, params);
452 GT_assert (curTrace, IS_VALID_PROCID (procId));
453 GT_assert (curTrace, (params != NULL));
455 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
456 if (!IS_VALID_PROCID (procId)) {
457 /* Not setting status here since this function does not return status.*/
458 GT_setFailureReason (curTrace,
459 GT_4CLASS,
460 "VAYUIPUCORE1PROC_create",
461 PROCESSOR_E_INVALIDARG,
462 "Invalid procId specified");
463 }
464 else if (params == NULL) {
465 GT_setFailureReason (curTrace,
466 GT_4CLASS,
467 "VAYUIPUCORE1PROC_create",
468 PROCESSOR_E_INVALIDARG,
469 "params passed is NULL!");
470 }
471 else {
472 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
473 /* Enter critical section protection. */
474 key = IGateProvider_enter (VAYUIPUCORE1PROC_state.gateHandle);
475 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
476 /* Check if the Processor already exists for specified procId. */
477 if (VAYUIPUCORE1PROC_state.procHandles [procId] != NULL) {
478 status = PROCESSOR_E_ALREADYEXIST;
479 GT_setFailureReason (curTrace,
480 GT_4CLASS,
481 "VAYUIPUCORE1PROC_create",
482 status,
483 "Processor already exists for specified procId!");
484 }
485 else {
486 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
487 /* Allocate memory for the handle */
488 handle = (Processor_Object *) Memory_calloc (NULL,
489 sizeof (Processor_Object),
490 0,
491 NULL);
492 if (handle == NULL) {
493 GT_setFailureReason (curTrace,
494 GT_4CLASS,
495 "VAYUIPUCORE1PROC_create",
496 PROCESSOR_E_MEMORY,
497 "Memory allocation failed for handle!");
498 }
499 else {
500 /* Populate the handle fields */
501 handle->procFxnTable.attach = &VAYUIPUCORE1PROC_attach;
502 handle->procFxnTable.detach = &VAYUIPUCORE1PROC_detach;
503 handle->procFxnTable.start = &VAYUIPUCORE1PROC_start;
504 handle->procFxnTable.stop = &VAYUIPUCORE1PROC_stop;
505 handle->procFxnTable.read = &VAYUIPUCORE1PROC_read;
506 handle->procFxnTable.write = &VAYUIPUCORE1PROC_write;
507 handle->procFxnTable.control = &VAYUIPUCORE1PROC_control;
508 handle->procFxnTable.map = &VAYUIPUCORE1PROC_map;
509 handle->procFxnTable.unmap = &VAYUIPUCORE1PROC_unmap;
510 handle->procFxnTable.translateAddr = &VAYUIPUCORE1PROC_translate;
511 handle->state = ProcMgr_State_Unknown;
513 /* Allocate memory for the VAYUIPUCORE1PROC handle */
514 handle->object = Memory_calloc (NULL,
515 sizeof (VAYUIPUCORE1PROC_Object),
516 0,
517 NULL);
518 if (handle->object == NULL) {
519 status = PROCESSOR_E_MEMORY;
520 GT_setFailureReason (curTrace,
521 GT_4CLASS,
522 "VAYUIPUCORE1PROC_create",
523 status,
524 "Memory allocation failed for handle->object!");
525 }
526 else {
527 handle->procId = procId;
528 object = (VAYUIPUCORE1PROC_Object *) handle->object;
529 object->procHandle = (Processor_Handle)handle;
530 object->halObject = NULL;
531 /* Copy params into instance object. */
532 Memory_copy (&(object->params),
533 (Ptr) params,
534 sizeof (VAYUIPUCORE1PROC_Params));
536 /* initialize the translation table */
537 for (i = AddrTable_count[PROCID_TO_IPU(procId)];
538 i < AddrTable_SIZE; i++) {
539 ai = &AddrTable[PROCID_TO_IPU(procId)][i];
540 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
541 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
542 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
543 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
544 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
545 ai->size = 0u;
546 ai->isCached = FALSE;
547 ai->mapMask = 0u;
548 ai->isMapped = FALSE;
549 }
551 /*
552 * initialize refCount for all entries
553 * both static and dynamic
554 */
555 for (i = 0; i < AddrTable_SIZE; i++) {
556 AddrTable[PROCID_TO_IPU(procId)][i].refCount = 0u;
557 }
558 Memory_copy((Ptr)(object->params.memEntries),
559 AddrTable[PROCID_TO_IPU(procId)],
560 (procId == VAYUIPUCORE1PROC_state.ipu1ProcId ?
561 sizeof(AddrTable_IPU1) : sizeof(AddrTable_IPU2)));
563 /* Set the handle in the state object. */
564 VAYUIPUCORE1PROC_state.procHandles [procId] =
565 (VAYUIPUCORE1PROC_Handle) handle;
566 /* Initialize the list of listeners */
567 List_Params_init(&listParams);
568 handle->registeredNotifiers = List_create(&listParams);
570 #if !defined(SYSLINK_BUILD_OPTIMIZE)
571 if (handle->registeredNotifiers == NULL) {
572 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
573 status = PROCESSOR_E_FAIL;
574 GT_setFailureReason (curTrace,
575 GT_4CLASS,
576 "VAYUIPUCORE1PROC_create",
577 status,
578 "List_create failed");
579 }
580 else {
581 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
583 handle->notifiersLock =
584 OsalMutex_create(OsalMutex_Type_Interruptible);
586 #if !defined(SYSLINK_BUILD_OPTIMIZE)
587 if (handle->notifiersLock == NULL) {
588 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
589 status = PROCESSOR_E_FAIL;
590 GT_setFailureReason (curTrace,
591 GT_4CLASS,
592 "VAYUIPUCORE1PROC_create",
593 status,
594 "OsalMutex_create failed");
595 }
596 }
597 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
598 }
599 }
600 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
601 }
602 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
604 /* Leave critical section protection. */
605 IGateProvider_leave (VAYUIPUCORE1PROC_state.gateHandle, key);
606 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
607 }
608 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
610 if (status < 0) {
611 if (handle != NULL) {
612 if (handle->registeredNotifiers != NULL) {
613 List_delete (&handle->registeredNotifiers);
614 }
615 if (handle->object != NULL) {
616 Memory_free (NULL,
617 handle->object,
618 sizeof (VAYUIPUCORE1PROC_Object));
619 }
620 Memory_free (NULL, handle, sizeof (Processor_Object));
621 }
622 /*! @retval NULL Function failed */
623 handle = NULL;
624 }
626 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_create", handle);
628 /*! @retval Valid-Handle Operation successful */
629 return (VAYUIPUCORE1PROC_Handle) handle;
630 }
633 /*!
634 * @brief Function to delete an instance of this Processor.
635 *
636 * The user provided pointer to the handle is reset after
637 * successful completion of this function.
638 *
639 * @param handlePtr Pointer to Handle to the Processor instance
640 *
641 * @sa VAYUIPUCORE1PROC_create
642 */
643 Int
644 VAYUIPUCORE1PROC_delete (VAYUIPUCORE1PROC_Handle * handlePtr)
645 {
646 Int status = PROCESSOR_SUCCESS;
647 VAYUIPUCORE1PROC_Object * object = NULL;
648 Processor_Object * handle;
649 IArg key;
650 List_Elem * elem = NULL;
651 Processor_RegisterElem * regElem = NULL;
653 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_delete", handlePtr);
655 GT_assert (curTrace, (handlePtr != NULL));
656 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
658 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
659 if (handlePtr == NULL) {
660 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
661 specified*/
662 status = PROCESSOR_E_INVALIDARG;
663 GT_setFailureReason (curTrace,
664 GT_4CLASS,
665 "VAYUIPUCORE1PROC_delete",
666 status,
667 "Invalid NULL handlePtr pointer specified");
668 }
669 else if (*handlePtr == NULL) {
670 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
671 status = PROCESSOR_E_HANDLE;
672 GT_setFailureReason (curTrace,
673 GT_4CLASS,
674 "VAYUIPUCORE1PROC_delete",
675 status,
676 "Invalid NULL *handlePtr specified");
677 }
678 else {
679 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
680 handle = (Processor_Object *) (*handlePtr);
681 /* Enter critical section protection. */
682 key = IGateProvider_enter (VAYUIPUCORE1PROC_state.gateHandle);
684 /* Reset handle in PwrMgr handle array. */
685 GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
686 VAYUIPUCORE1PROC_state.procHandles [handle->procId] = NULL;
688 /* Free memory used for the VAYUIPUCORE1PROC object. */
689 if (handle->object != NULL) {
690 object = (VAYUIPUCORE1PROC_Object *) handle->object;
691 Memory_free (NULL,
692 object,
693 sizeof (VAYUIPUCORE1PROC_Object));
694 handle->object = NULL;
695 }
697 /*
698 * Check the list of listeners to see if any are remaining
699 * and reply to them
700 */
701 OsalMutex_delete(&handle->notifiersLock);
703 while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
704 regElem = (Processor_RegisterElem *)elem;
706 /* Check if there is an associated timer and cancel it */
707 if (regElem->timer != -1) {
708 struct itimerspec value ;
709 value.it_value.tv_sec = 0;
710 value.it_value.tv_nsec = 0;
711 value.it_interval.tv_sec = 0;
712 value.it_interval.tv_nsec = 0;
713 timer_settime(regElem->timer, 0, &value, NULL);
715 timer_delete(regElem->timer);
716 regElem->timer = -1;
717 }
719 /* Call the callback function so it can clean up. */
720 regElem->info->cbFxn(handle->procId,
721 NULL,
722 handle->state,
723 handle->state,
724 ProcMgr_EventStatus_Canceled,
725 regElem->info->arg);
726 /* Free the memory */
727 Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
728 }
730 /* Delete the list of listeners */
731 List_delete(&handle->registeredNotifiers);
733 /* Free memory used for the Processor object. */
734 Memory_free (NULL, handle, sizeof (Processor_Object));
735 *handlePtr = NULL;
737 /* Leave critical section protection. */
738 IGateProvider_leave (VAYUIPUCORE1PROC_state.gateHandle, key);
739 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
740 }
741 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
743 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_delete", status);
745 /*! @retval PROCESSOR_SUCCESS Operation successful */
746 return (status);
747 }
750 /*!
751 * @brief Function to open a handle to an instance of this Processor. This
752 * function is called when access to the Processor is required from
753 * a different process.
754 *
755 * @param handlePtr Handle to the Processor instance
756 * @param procId Processor ID addressed by this Processor instance.
757 *
758 * @sa VAYUIPUCORE1PROC_close
759 */
760 Int
761 VAYUIPUCORE1PROC_open (VAYUIPUCORE1PROC_Handle * handlePtr, UInt16 procId)
762 {
763 Int status = PROCESSOR_SUCCESS;
765 GT_2trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_open", handlePtr, procId);
767 GT_assert (curTrace, (handlePtr != NULL));
768 GT_assert (curTrace, IS_VALID_PROCID (procId));
770 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
771 if (handlePtr == NULL) {
772 /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
773 status = PROCESSOR_E_HANDLE;
774 GT_setFailureReason (curTrace,
775 GT_4CLASS,
776 "VAYUIPUCORE1PROC_open",
777 status,
778 "Invalid NULL handlePtr specified");
779 }
780 else if (!IS_VALID_PROCID (procId)) {
781 /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
782 status = PROCESSOR_E_INVALIDARG;
783 GT_setFailureReason (curTrace,
784 GT_4CLASS,
785 "VAYUIPUCORE1PROC_open",
786 status,
787 "Invalid procId specified");
788 }
789 else {
790 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
791 /* Initialize return parameter handle. */
792 *handlePtr = NULL;
794 /* Check if the PwrMgr exists and return the handle if found. */
795 if (VAYUIPUCORE1PROC_state.procHandles [procId] == NULL) {
796 /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
797 status = PROCESSOR_E_NOTFOUND;
798 GT_setFailureReason (curTrace,
799 GT_4CLASS,
800 "VAYUIPUCORE1PROC_open",
801 status,
802 "Specified VAYUIPUCORE1PROC instance does not exist!");
803 }
804 else {
805 *handlePtr = VAYUIPUCORE1PROC_state.procHandles [procId];
806 }
807 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
808 }
809 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
811 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_open", status);
813 /*! @retval PROCESSOR_SUCCESS Operation successful */
814 return status;
815 }
818 /*!
819 * @brief Function to close a handle to an instance of this Processor.
820 *
821 * @param handlePtr Pointer to Handle to the Processor instance
822 *
823 * @sa VAYUIPUCORE1PROC_open
824 */
825 Int
826 VAYUIPUCORE1PROC_close (VAYUIPUCORE1PROC_Handle * handlePtr)
827 {
828 Int status = PROCESSOR_SUCCESS;
830 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_close", handlePtr);
832 GT_assert (curTrace, (handlePtr != NULL));
833 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
835 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
836 if (handlePtr == NULL) {
837 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
838 specified*/
839 status = PROCESSOR_E_INVALIDARG;
840 GT_setFailureReason (curTrace,
841 GT_4CLASS,
842 "VAYUIPUCORE1PROC_close",
843 status,
844 "Invalid NULL handlePtr pointer specified");
845 }
846 else if (*handlePtr == NULL) {
847 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
848 status = PROCESSOR_E_HANDLE;
849 GT_setFailureReason (curTrace,
850 GT_4CLASS,
851 "VAYUIPUCORE1PROC_close",
852 status,
853 "Invalid NULL *handlePtr specified");
854 }
855 else {
856 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
857 /* Nothing to be done for close. */
858 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
859 }
860 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
862 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_close", status);
864 /*! @retval PROCESSOR_SUCCESS Operation successful */
865 return status;
866 }
869 /* =============================================================================
870 * APIs called by Processor module (part of function table interface)
871 * =============================================================================
872 */
873 /*!
874 * @brief Function to initialize the slave processor
875 *
876 * @param handle Handle to the Processor instance
877 * @param params Attach parameters
878 *
879 * @sa VAYUIPUCORE1PROC_detach
880 */
881 Int
882 VAYUIPUCORE1PROC_attach(
883 Processor_Handle handle,
884 Processor_AttachParams * params)
885 {
887 Int status = PROCESSOR_SUCCESS ;
888 Processor_Object * procHandle = (Processor_Object *)handle;
889 VAYUIPUCORE1PROC_Object * object = NULL;
890 UInt32 i = 0;
891 UInt32 index = 0;
892 ProcMgr_AddrInfo * me;
893 SysLink_MemEntry * entry;
894 SysLink_MemEntry_Block memBlock;
895 Char prop[PARAMS_MAX_NAMELENGTH];
896 Char configProp[PARAMS_MAX_NAMELENGTH];
897 UInt32 numCarveouts = 0;
898 VAYUIPU_HalMmuCtrlArgs_Enable mmuEnableArgs;
899 VAYUIPU_HalParams halParams;
901 GT_2trace(curTrace, GT_ENTER,
902 "VAYUIPUCORE1PROC_attach", handle, params);
903 GT_assert (curTrace, (handle != NULL));
904 GT_assert (curTrace, (params != NULL));
906 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
907 if (handle == NULL) {
908 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
909 status = PROCESSOR_E_HANDLE;
910 GT_setFailureReason (curTrace,
911 GT_4CLASS,
912 "VAYUIPUCORE1PROC_attach",
913 status,
914 "Invalid handle specified");
915 }
916 else if (params == NULL) {
917 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
918 status = PROCESSOR_E_INVALIDARG;
919 GT_setFailureReason (curTrace,
920 GT_4CLASS,
921 "VAYUIPUCORE1PROC_attach",
922 status,
923 "Invalid params specified");
924 }
925 else {
926 #endif
927 object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
928 GT_assert (curTrace, (object != NULL));
930 /* Added for Netra Benelli core0 is cortex M4 */
931 params->procArch = Processor_ProcArch_M4;
933 /* check for instance params override */
934 if (VAYUIPUCORE1PROC_state.ipu1ProcId == procHandle->procId) {
935 Cfg_propBool(PARAMS_mmuEnable1, ProcMgr_sysLinkCfgParams,
936 &(object->params.mmuEnable));
937 }
938 else {
939 Cfg_propBool(PARAMS_mmuEnable2, ProcMgr_sysLinkCfgParams,
940 &(object->params.mmuEnable));
941 }
943 /* check for carveout params override */
944 for (i = 0; i < ProcMgr_MAX_MEMORY_REGIONS; i++) {
945 if (VAYUIPUCORE1PROC_state.ipu1ProcId == procHandle->procId) {
946 snprintf (prop, PARAMS_MAX_NAMELENGTH, PARAMS_carveoutAddr1"%d", i);
947 }
948 else {
949 snprintf (prop, PARAMS_MAX_NAMELENGTH, PARAMS_carveoutAddr2"%d", i);
950 }
951 strcat(prop, "=");
952 if (!Cfg_prop(prop, ProcMgr_sysLinkCfgParams, configProp))
953 break;
954 object->params.carveoutAddr[i] = strtoul(configProp, 0, 16);
955 if (VAYUIPUCORE1PROC_state.ipu1ProcId == procHandle->procId) {
956 snprintf (prop, PARAMS_MAX_NAMELENGTH, PARAMS_carveoutSize1"%d", i);
957 }
958 else {
959 snprintf (prop, PARAMS_MAX_NAMELENGTH, PARAMS_carveoutSize2"%d", i);
960 }
961 strcat(prop, "=");
962 if (!Cfg_prop(prop, ProcMgr_sysLinkCfgParams, configProp))
963 break;
964 object->params.carveoutSize[i] = strtoul(configProp, 0, 16);
965 numCarveouts++;
966 }
968 object->pmHandle = params->pmHandle;
969 GT_0trace(curTrace, GT_1CLASS,
970 "VAYUIPUCORE1PROC_attach: Mapping memory regions");
972 /* search for dsp memory map */
973 status = RscTable_process(procHandle->procId, object->params.mmuEnable,
974 numCarveouts,
975 (Ptr)object->params.carveoutAddr,
976 object->params.carveoutSize, TRUE,
977 &memBlock.numEntries);
978 if (status < 0 || memBlock.numEntries > SYSLINK_MAX_MEMENTRIES) {
979 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
980 status = PROCESSOR_E_INVALIDARG;
981 GT_setFailureReason (curTrace,
982 GT_4CLASS,
983 "VAYUIPUCORE1PROC_attach",
984 status,
985 "Failed to process resource table");
986 }
987 else {
988 status = RscTable_getMemEntries(procHandle->procId,
989 memBlock.memEntries,
990 &memBlock.numEntries);
991 if (status < 0) {
992 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
993 status = PROCESSOR_E_INVALIDARG;
994 GT_setFailureReason (curTrace,
995 GT_4CLASS,
996 "VAYUIPUCORE1PROC_attach",
997 status,
998 "Failed to get resource table memEntries");
999 }
1000 }
1002 /* update translation tables with memory map */
1003 for (i = 0; (i < memBlock.numEntries)
1004 && (memBlock.memEntries[i].isValid) && (status >= 0); i++) {
1006 entry = &memBlock.memEntries[i];
1008 if (entry->map == FALSE) {
1009 /* update table with entries which don't require mapping */
1010 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1011 AddrTable_SIZE) {
1012 me = &AddrTable[PROCID_TO_IPU(procHandle->procId)][
1013 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]];
1015 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1016 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1017 me->addr[ProcMgr_AddrType_MasterPhys] =
1018 entry->masterPhysAddr;
1019 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1020 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1021 me->size = entry->size;
1022 me->isCached = entry->isCached;
1023 me->mapMask = entry->mapMask;
1025 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1026 }
1027 else {
1028 status = PROCESSOR_E_FAIL;
1029 GT_setFailureReason(curTrace, GT_4CLASS,
1030 "VAYUIPUCORE1PROC_attach", status,
1031 "AddrTable_SIZE reached!");
1032 }
1033 }
1034 else if (entry->map == TRUE) {
1035 /* send these entries back to ProcMgr for mapping */
1036 index = object->params.numMemEntries;
1038 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
1039 me = &object->params.memEntries[index];
1041 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1042 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1043 me->addr[ProcMgr_AddrType_MasterPhys] =
1044 entry->masterPhysAddr;
1045 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
1046 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1047 me->size = entry->size;
1048 me->isCached = entry->isCached;
1049 me->mapMask = entry->mapMask;
1051 object->params.numMemEntries++;
1052 }
1053 else {
1054 status = PROCESSOR_E_FAIL;
1055 GT_setFailureReason(curTrace, GT_4CLASS,
1056 "VAYUIPUCORE1PROC_attach", status,
1057 "ProcMgr_MAX_MEMORY_REGIONS reached!");
1058 }
1059 }
1060 else {
1061 status = PROCESSOR_E_INVALIDARG;
1062 GT_setFailureReason(curTrace, GT_4CLASS,
1063 "VAYUIPUCORE1PROC_attach", status,
1064 "Memory map has entry with invalid 'map' value");
1065 }
1066 } /* for (...) */
1068 if (status >= 0) {
1069 /* populate the return params */
1070 params->numMemEntries = object->params.numMemEntries;
1071 memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1072 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1074 halParams.procId = procHandle->procId;
1075 status = VAYUIPU_halInit(&(object->halObject), &halParams);
1077 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)
1078 if (status < 0) {
1079 GT_setFailureReason(curTrace, GT_4CLASS,
1080 "VAYUIPUCORE1PROC_attach", status,
1081 "VAYUIPU_halInit failed");
1082 }
1083 else {
1084 #endif
1085 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1086 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1088 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1089 if (status < 0) {
1090 GT_setFailureReason(curTrace, GT_4CLASS,
1091 "VAYUIPUCORE1PROC_attach", status,
1092 "Failed to reset the slave processor");
1093 }
1094 else {
1095 #endif
1096 GT_0trace(curTrace, GT_1CLASS,
1097 "VAYUIPUCORE1PROC_attach: slave is now in reset");
1099 if (object->params.mmuEnable) {
1100 mmuEnableArgs.numMemEntries = 0;
1101 status = VAYUIPU_halMmuCtrl(object->halObject,
1102 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1103 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1104 if (status < 0) {
1105 GT_setFailureReason(curTrace, GT_4CLASS,
1106 "VAYUIPUCORE1PROC_attach", status,
1107 "Failed to enable the slave MMU");
1108 }
1109 else {
1110 #endif
1111 GT_0trace(curTrace, GT_2CLASS,
1112 "VAYUIPUCORE1PROC_attach: Slave MMU "
1113 "is configured!");
1114 /*
1115 * Pull IPU MMU out of reset to make internal
1116 * memory "loadable"
1117 */
1118 status = VAYUIPUCORE1_halResetCtrl(
1119 object->halObject,
1120 Processor_ResetCtrlCmd_MMU_Release);
1121 if (status < 0) {
1122 /*! @retval status */
1123 GT_setFailureReason(curTrace,
1124 GT_4CLASS,
1125 "VAYUIPUCORE1_halResetCtrl",
1126 status,
1127 "Reset MMU_Release failed");
1128 }
1129 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1130 }
1131 #endif
1132 }
1133 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1134 }
1135 #endif
1136 }
1137 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1138 }
1139 #endif
1140 }
1141 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1142 }
1143 #endif
1145 GT_1trace(curTrace, GT_LEAVE,
1146 "VAYUIPUCORE1PROC_attach", status);
1148 /*! @retval PROCESSOR_SUCCESS Operation successful */
1149 return status;
1150 }
1153 /*!
1154 * @brief Function to detach from the Processor.
1155 *
1156 * @param handle Handle to the Processor instance
1157 *
1158 * @sa VAYUIPUCORE1PROC_attach
1159 */
1160 Int
1161 VAYUIPUCORE1PROC_detach (Processor_Handle handle)
1162 {
1163 Int status = PROCESSOR_SUCCESS;
1164 Int tmpStatus = PROCESSOR_SUCCESS;
1165 Processor_Object * procHandle = (Processor_Object *) handle;
1166 VAYUIPUCORE1PROC_Object * object = NULL;
1167 Int i = 0;
1168 ProcMgr_AddrInfo * ai;
1170 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_detach", handle);
1171 GT_assert (curTrace, (handle != NULL));
1173 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1174 if (handle == NULL) {
1175 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1176 status = PROCESSOR_E_HANDLE;
1177 GT_setFailureReason (curTrace,
1178 GT_4CLASS,
1179 "VAYUIPUCORE1PROC_detach",
1180 PROCESSOR_E_HANDLE,
1181 "Invalid handle specified");
1182 }
1183 else {
1184 #endif
1185 object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1186 GT_assert (curTrace, (object != NULL));
1188 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1189 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1191 if (object->params.mmuEnable) {
1192 GT_0trace(curTrace, GT_2CLASS,
1193 "VAYUIPUCORE1PROC_detach: Disabling Slave MMU ...");
1195 status = VAYUIPUCORE1_halResetCtrl(object->halObject,
1196 Processor_ResetCtrlCmd_MMU_Reset);
1197 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1198 if (status < 0) {
1199 /*! @retval status */
1200 GT_setFailureReason (curTrace,
1201 GT_4CLASS,
1202 "VAYUIPUCORE1_halResetCtrl",
1203 status,
1204 "Reset MMU failed");
1205 }
1206 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
1208 status = VAYUIPU_halMmuCtrl(object->halObject,
1209 Processor_MmuCtrlCmd_Disable, NULL);
1210 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1211 if (status < 0) {
1212 GT_setFailureReason(curTrace, GT_4CLASS,
1213 "VAYUIPUCORE1PROC_detach", status,
1214 "Failed to disable the slave MMU");
1215 }
1216 #endif
1217 }
1219 /* delete all dynamically added entries */
1220 for (i = AddrTable_STATIC_COUNT; i <
1221 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
1222 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1223 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1224 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1225 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1226 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1227 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1228 ai->size = 0u;
1229 ai->isCached = FALSE;
1230 ai->mapMask = 0u;
1231 ai->isMapped = FALSE;
1232 ai->refCount = 0u;
1233 }
1234 object->params.numMemEntries = AddrTable_STATIC_COUNT;
1235 AddrTable_count[PROCID_TO_IPU(procHandle->procId)] =
1236 AddrTable_STATIC_COUNT;
1238 //No need to reset.. that will be done in STOP
1239 /*tmpStatus = VAYUIPUCORE1_halResetCtrl(object->halObject,
1240 Processor_ResetCtrlCmd_Reset, NULL);
1242 GT_0trace(curTrace, GT_2CLASS,
1243 "VAYUIPUCORE1PROC_detach: Slave processor is now in reset");*/
1245 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1246 if ((tmpStatus < 0) && (status >= 0)) {
1247 status = tmpStatus;
1248 GT_setFailureReason (curTrace,
1249 GT_4CLASS,
1250 "VAYUIPUCORE1PROC_detach",
1251 status,
1252 "Failed to reset the slave processor");
1253 }
1254 #endif
1255 }
1257 GT_0trace (curTrace,
1258 GT_2CLASS,
1259 " VAYUIPUCORE1PROC_detach: Unmapping memory regions\n");
1261 tmpStatus = VAYUIPU_halExit (object->halObject);
1262 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1263 if ((tmpStatus < 0) && (status >= 0)) {
1264 status = tmpStatus;
1265 GT_setFailureReason (curTrace,
1266 GT_4CLASS,
1267 "VAYUIPUCORE1PROC_detach",
1268 status,
1269 "Failed to finalize HAL object");
1270 }
1271 }
1272 #endif
1274 GT_1trace(curTrace, GT_LEAVE,
1275 "VAYUIPUCORE1PROC_detach", status);
1277 /*! @retval PROCESSOR_SUCCESS Operation successful */
1278 return status;
1279 }
1282 /*!
1283 * @brief Function to start the slave processor
1284 *
1285 * Start the slave processor running from its entry point.
1286 * Depending on the boot mode, this involves configuring the boot
1287 * address and releasing the slave from reset.
1288 *
1289 * @param handle Handle to the Processor instance
1290 *
1291 * @sa VAYUIPUCORE1PROC_stop, VAYUIPU_halBootCtrl, VAYUIPUCORE1_halResetCtrl
1292 */
1293 Int
1294 VAYUIPUCORE1PROC_start (Processor_Handle handle,
1295 UInt32 entryPt,
1296 Processor_StartParams * params)
1297 {
1298 Int status = PROCESSOR_SUCCESS ;
1299 Processor_Object * procHandle = (Processor_Object *) handle;
1300 VAYUIPUCORE1PROC_Object * object = NULL;
1303 GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_start",
1304 handle, entryPt, params);
1306 GT_assert (curTrace, (handle != NULL));
1307 GT_assert (curTrace, (params != NULL));
1309 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1310 if (handle == NULL) {
1311 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1312 status = PROCESSOR_E_HANDLE;
1313 GT_setFailureReason (curTrace,
1314 GT_4CLASS,
1315 "VAYUIPUCORE1PROC_start",
1316 status,
1317 "Invalid handle specified");
1318 }
1319 else if (params == NULL) {
1320 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1321 status = PROCESSOR_E_INVALIDARG;
1322 GT_setFailureReason (curTrace,
1323 GT_4CLASS,
1324 "VAYUIPUCORE1PROC_start",
1325 status,
1326 "Invalid params specified");
1327 }
1328 else {
1329 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1330 object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1331 GT_assert (curTrace, (object != NULL));
1332 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1333 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1334 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1335 /* Slave is to be started only for Boot mode and NoLoad mode. */
1336 /* Specify the IPUCORE1 boot address in the boot config register */
1337 status = VAYUIPU_halBootCtrl (object->halObject,
1338 Processor_BootCtrlCmd_SetEntryPoint,
1339 (Ptr) entryPt);
1340 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1341 if (status < 0) {
1342 GT_setFailureReason (curTrace,
1343 GT_4CLASS,
1344 "VAYUIPUCORE1PROC_start",
1345 status,
1346 "Failed to set slave boot entry point");
1347 }
1348 else {
1349 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1351 /* release the slave cpu from reset */
1352 if (status >= 0) {
1353 status = VAYUIPUCORE1_halResetCtrl(object->halObject,
1354 Processor_ResetCtrlCmd_Release);
1355 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1356 if (status < 0) {
1357 GT_setFailureReason (curTrace,
1358 GT_4CLASS,
1359 "VAYUIPUCORE1PROC_start",
1360 status,
1361 "Failed to release slave from reset");
1362 }
1363 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1364 }
1365 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1366 }
1367 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1368 }
1370 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1371 }
1372 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1374 if (status >= 0) {
1375 GT_0trace (curTrace,
1376 GT_1CLASS,
1377 " VAYUIPUCORE1PROC_start: Slave successfully started!\n");
1378 }
1379 else {
1380 GT_0trace (curTrace,
1381 GT_1CLASS,
1382 " VAYUIPUCORE1PROC_start: Slave could not be started!\n");
1383 }
1385 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_start", status);
1387 /*! @retval PROCESSOR_SUCCESS Operation successful */
1388 return status;
1389 }
1392 /*!
1393 * @brief Function to stop the slave processor
1394 *
1395 * Stop the execution of the slave processor. Depending on the boot
1396 * mode, this may result in placing the slave processor in reset.
1397 *
1398 * @param handle Handle to the Processor instance
1399 *
1400 * @sa VAYUIPUCORE1PROC_start, VAYUIPUCORE1_halResetCtrl
1401 */
1402 Int
1403 VAYUIPUCORE1PROC_stop (Processor_Handle handle)
1404 {
1405 Int status = PROCESSOR_SUCCESS ;
1406 Processor_Object * procHandle = (Processor_Object *) handle;
1407 VAYUIPUCORE1PROC_Object * object = NULL;
1409 GT_1trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_stop", handle);
1411 GT_assert (curTrace, (handle != NULL));
1413 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1414 if (handle == NULL) {
1415 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1416 status = PROCESSOR_E_HANDLE;
1417 GT_setFailureReason (curTrace,
1418 GT_4CLASS,
1419 "VAYUIPUCORE1PROC_stop",
1420 status,
1421 "Invalid handle specified");
1422 }
1423 else {
1424 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1425 object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
1426 GT_assert (curTrace, (object != NULL));
1427 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1428 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1429 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1430 /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1431 /* Place the slave processor in reset. */
1432 status = VAYUIPUCORE1_halResetCtrl (object->halObject,
1433 Processor_ResetCtrlCmd_Reset);
1435 GT_0trace (curTrace,
1436 GT_1CLASS,
1437 " VAYUIPUCORE1PROC_stop: Slave is now in reset!\n");
1438 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1439 if (status < 0) {
1440 GT_setFailureReason (curTrace,
1441 GT_4CLASS,
1442 "VAYUIPUCORE1PROC_stop",
1443 status,
1444 "Failed to place slave in reset");
1445 }
1446 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1448 }
1449 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1450 }
1451 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1452 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_stop", status);
1454 /*! @retval PROCESSOR_SUCCESS Operation successful */
1455 return status;
1456 }
1459 /*!
1460 * @brief Function to read from the slave processor's memory.
1461 *
1462 * Read from the slave processor's memory and copy into the
1463 * provided buffer.
1464 *
1465 * @param handle Handle to the Processor instance
1466 * @param procAddr Address in host processor's address space of the
1467 * memory region to read from.
1468 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1469 * number of bytes to be read. When the function
1470 * returns, this parameter contains the number of bytes
1471 * actually read.
1472 * @param buffer User-provided buffer in which the slave processor's
1473 * memory contents are to be copied.
1474 *
1475 * @sa VAYUIPUCORE1PROC_write
1476 */
1477 Int
1478 VAYUIPUCORE1PROC_read (Processor_Handle handle,
1479 UInt32 procAddr,
1480 UInt32 * numBytes,
1481 Ptr buffer)
1482 {
1483 Int status = PROCESSOR_SUCCESS ;
1484 UInt8 * procPtr8 = NULL;
1486 GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_read",
1487 handle, procAddr, numBytes, buffer);
1489 GT_assert (curTrace, (handle != NULL));
1490 GT_assert (curTrace, (numBytes != NULL));
1491 GT_assert (curTrace, (buffer != NULL));
1493 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1494 if (handle == NULL) {
1495 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1496 status = PROCESSOR_E_HANDLE;
1497 GT_setFailureReason (curTrace,
1498 GT_4CLASS,
1499 "VAYUIPUCORE1PROC_read",
1500 status,
1501 "Invalid handle specified");
1502 }
1503 else if (numBytes == 0) {
1504 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1505 status = PROCESSOR_E_INVALIDARG;
1506 GT_setFailureReason (curTrace,
1507 GT_4CLASS,
1508 "VAYUIPUCORE1PROC_read",
1509 status,
1510 "Invalid numBytes specified");
1511 }
1512 else if (buffer == NULL) {
1513 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1514 status = PROCESSOR_E_INVALIDARG;
1515 GT_setFailureReason (curTrace,
1516 GT_4CLASS,
1517 "VAYUIPUCORE1PROC_read",
1518 status,
1519 "Invalid buffer specified");
1520 }
1521 else {
1522 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1523 procPtr8 = (UInt8 *) procAddr ;
1524 buffer = memcpy (buffer, procPtr8, *numBytes);
1525 GT_assert (curTrace, (buffer != (UInt32) NULL));
1526 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1527 if (buffer == (UInt32) NULL) {
1528 /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1529 status = PROCESSOR_E_FAIL;
1530 GT_setFailureReason (curTrace,
1531 GT_4CLASS,
1532 "VAYUIPUCORE1PROC_read",
1533 status,
1534 "Failed in memcpy");
1535 *numBytes = 0;
1536 }
1537 }
1538 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1540 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_read",status);
1542 /*! @retval PROCESSOR_SUCCESS Operation successful */
1543 return status;
1544 }
1547 /*!
1548 * @brief Function to write into the slave processor's memory.
1549 *
1550 * Read from the provided buffer and copy into the slave
1551 * processor's memory.
1552 *
1553 * @param handle Handle to the Processor object
1554 * @param procAddr Address in host processor's address space of the
1555 * memory region to write into.
1556 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1557 * number of bytes to be written. When the function
1558 * returns, this parameter contains the number of bytes
1559 * actually written.
1560 * @param buffer User-provided buffer from which the data is to be
1561 * written into the slave processor's memory.
1562 *
1563 * @sa VAYUIPUCORE1PROC_read, VAYUIPUCORE1PROC_translateAddr
1564 */
1565 Int
1566 VAYUIPUCORE1PROC_write (Processor_Handle handle,
1567 UInt32 procAddr,
1568 UInt32 * numBytes,
1569 Ptr buffer)
1570 {
1571 Int status = PROCESSOR_SUCCESS ;
1572 UInt8 * procPtr8 = NULL;
1573 UInt8 temp8_1;
1574 UInt8 temp8_2;
1575 UInt8 temp8_3;
1576 UInt8 temp8_4;
1577 UInt32 temp;
1579 GT_4trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_write",
1580 handle, procAddr, numBytes, buffer);
1582 GT_assert (curTrace, (handle != NULL));
1583 GT_assert (curTrace, (numBytes != NULL));
1584 GT_assert (curTrace, (buffer != NULL));
1586 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1587 if (handle == NULL) {
1588 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1589 status = PROCESSOR_E_HANDLE;
1590 GT_setFailureReason (curTrace,
1591 GT_4CLASS,
1592 "VAYUIPUCORE1PROC_write",
1593 status,
1594 "Invalid handle specified");
1595 }
1596 else if (numBytes == 0) {
1597 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1598 status = PROCESSOR_E_INVALIDARG;
1599 GT_setFailureReason (curTrace,
1600 GT_4CLASS,
1601 "VAYUIPUCORE1PROC_write",
1602 status,
1603 "Invalid numBytes specified");
1604 }
1605 else if (buffer == NULL) {
1606 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1607 status = PROCESSOR_E_INVALIDARG;
1608 GT_setFailureReason (curTrace,
1609 GT_4CLASS,
1610 "VAYUIPUCORE1PROC_write",
1611 status,
1612 "Invalid buffer specified");
1613 }
1614 else {
1615 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1616 if (*numBytes != sizeof (UInt32)) {
1617 procPtr8 = (UInt8 *) procAddr ;
1618 procAddr = (UInt32) Memory_copy (procPtr8,
1619 buffer,
1620 *numBytes);
1621 GT_assert (curTrace, (procAddr != (UInt32) NULL));
1622 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1623 if (procAddr == (UInt32) NULL) {
1624 /*! @retval PROCESSOR_E_FAIL Failed in Memory_copy */
1625 status = PROCESSOR_E_FAIL;
1626 GT_setFailureReason (curTrace,
1627 GT_4CLASS,
1628 "VAYUIPUCORE1PROC_write",
1629 status,
1630 "Failed in Memory_copy");
1631 *numBytes = 0;
1632 }
1633 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1634 }
1635 else {
1636 /* For 4 bytes, directly write as a UInt32 */
1637 temp8_1 = ((UInt8 *) buffer) [0];
1638 temp8_2 = ((UInt8 *) buffer) [1];
1639 temp8_3 = ((UInt8 *) buffer) [2];
1640 temp8_4 = ((UInt8 *) buffer) [3];
1641 temp = (UInt32) ( ((UInt32) temp8_4 << 24)
1642 | ((UInt32) temp8_3 << 16)
1643 | ((UInt32) temp8_2 << 8)
1644 | ((UInt32) temp8_1));
1645 *((UInt32*) procAddr) = temp;
1646 }
1647 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1648 }
1649 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1651 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_write", status);
1653 /*! @retval PROCESSOR_SUCCESS Operation successful */
1654 return status;
1655 }
1658 /*!
1659 * @brief Function to perform device-dependent operations.
1660 *
1661 * Performs device-dependent control operations as exposed by this
1662 * implementation of the Processor module.
1663 *
1664 * @param handle Handle to the Processor object
1665 * @param cmd Device specific processor command
1666 * @param arg Arguments specific to the type of command.
1667 *
1668 * @sa
1669 */
1670 Int
1671 VAYUIPUCORE1PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1672 {
1673 Int status = PROCESSOR_SUCCESS ;
1675 GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_control", handle, cmd, arg);
1677 GT_assert (curTrace, (handle != NULL));
1678 /* cmd and arg can be 0/NULL, so cannot check for validity. */
1680 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1681 if (handle == NULL) {
1682 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1683 status = PROCESSOR_E_HANDLE;
1684 GT_setFailureReason (curTrace,
1685 GT_4CLASS,
1686 "VAYUIPUCORE1PROC_control",
1687 status,
1688 "Invalid handle specified");
1689 }
1690 else {
1691 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1692 /* No control operations currently implemented. */
1693 /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1694 for this device. */
1695 status = PROCESSOR_E_NOTSUPPORTED;
1696 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1697 }
1698 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1699 GT_1trace (curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_control",status);
1701 /*! @retval PROCESSOR_SUCCESS Operation successful */
1702 return status;
1703 }
1706 /*!
1707 * @brief Translate slave virtual address to master physical address.
1708 *
1709 * @param handle Handle to the Processor object
1710 * @param dstAddr Returned: master physical address.
1711 * @param srcAddr Slave virtual address.
1712 *
1713 * @sa
1714 */
1715 Int
1716 VAYUIPUCORE1PROC_translate(
1717 Processor_Handle handle,
1718 UInt32 * dstAddr,
1719 UInt32 srcAddr)
1720 {
1721 Int status = PROCESSOR_SUCCESS;
1722 Processor_Object * procHandle= (Processor_Object *)handle;
1723 VAYUIPUCORE1PROC_Object * object = NULL;
1724 UInt32 i;
1725 UInt32 startAddr;
1726 UInt32 endAddr;
1727 UInt32 offset;
1728 ProcMgr_AddrInfo * ai;
1730 GT_3trace(curTrace, GT_ENTER, "VAYUDSPPROC_translate",
1731 handle, dstAddr, srcAddr);
1733 GT_assert (curTrace, (handle != NULL));
1734 GT_assert (curTrace, (dstAddr != NULL));
1736 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1737 if (handle == NULL) {
1738 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1739 status = PROCESSOR_E_HANDLE;
1740 GT_setFailureReason (curTrace,
1741 GT_4CLASS,
1742 "VAYUIPUCORE1PROC_translate",
1743 status,
1744 "Invalid handle specified");
1745 }
1746 else if (dstAddr == NULL) {
1747 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1748 status = PROCESSOR_E_INVALIDARG;
1749 GT_setFailureReason (curTrace,
1750 GT_4CLASS,
1751 "VAYUIPUCORE1PROC_translate",
1752 status,
1753 "dstAddr provided as NULL");
1754 }
1755 else {
1756 #endif
1757 object = (VAYUIPUCORE1PROC_Object *)procHandle->object;
1758 GT_assert(curTrace, (object != NULL));
1759 *dstAddr = -1u;
1761 /* search all entries AddrTable */
1762 for (i = 0; i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)];
1763 i++) {
1764 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
1765 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1766 endAddr = startAddr + ai->size;
1768 if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1769 offset = srcAddr - startAddr;
1770 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1771 GT_3trace(curTrace, GT_1CLASS, "VAYUIPUCORE1PROC_translate: "
1772 "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1773 i, srcAddr, *dstAddr);
1774 break;
1775 }
1776 }
1778 if (*dstAddr == -1u) {
1779 if (!object->params.mmuEnable) {
1780 /* default to direct mapping (i.e. v=p) */
1781 *dstAddr = srcAddr;
1782 GT_2trace(curTrace, GT_1CLASS, "VAYUIPUCORE1PROC_translate: "
1783 "(default) srcAddr=0x%x --> dstAddr=0x%x",
1784 srcAddr, *dstAddr);
1785 }
1786 else {
1787 /* srcAddr not found in slave address space */
1788 status = PROCESSOR_E_INVALIDARG;
1789 GT_setFailureReason(curTrace, GT_4CLASS,
1790 "VAYUIPUCORE1PROC_translate", status,
1791 "srcAddr not found in slave address space");
1792 }
1793 }
1794 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1795 }
1796 #endif
1797 GT_1trace(curTrace, GT_LEAVE,
1798 "VAYUIPUCORE1PROC_translate: status=0x%x", status);
1800 /*! @retval PROCESSOR_SUCCESS Operation successful */
1801 return status;
1802 }
1805 /*!
1806 * @brief Map the given address translation into the slave mmu
1807 *
1808 * @param handle Handle to the Processor object
1809 * @param dstAddr Base virtual address
1810 * @param nSegs Number of given segments
1811 * @param sglist Segment list
1812 */
1813 Int
1814 VAYUIPUCORE1PROC_map(
1815 Processor_Handle handle,
1816 UInt32 * dstAddr,
1817 UInt32 nSegs,
1818 Memory_SGList * sglist)
1819 {
1820 Int status = PROCESSOR_SUCCESS ;
1821 Processor_Object * procHandle = (Processor_Object *)handle;
1822 VAYUIPUCORE1PROC_Object * object = NULL;
1823 Bool found = FALSE;
1824 UInt32 startAddr;
1825 UInt32 endAddr;
1826 UInt32 i;
1827 UInt32 j;
1828 ProcMgr_AddrInfo * ai = NULL;
1829 VAYUIPU_HalMmuCtrlArgs_AddEntry addEntryArgs;
1831 GT_4trace(curTrace, GT_ENTER, "VAYUIPUCORE1PROC_map:",
1832 handle, *dstAddr, nSegs, sglist);
1834 GT_assert (curTrace, (handle != NULL));
1835 GT_assert (curTrace, (sglist != NULL));
1836 GT_assert (curTrace, (nSegs > 0));
1838 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1839 if (handle == NULL) {
1840 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1841 status = PROCESSOR_E_HANDLE;
1842 GT_setFailureReason (curTrace,
1843 GT_4CLASS,
1844 "VAYUIPUCORE1PROC_map",
1845 status,
1846 "Invalid handle specified");
1847 }
1848 else if (sglist == NULL) {
1849 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1850 status = PROCESSOR_E_INVALIDARG;
1851 GT_setFailureReason (curTrace,
1852 GT_4CLASS,
1853 "VAYUIPUCORE1PROC_map",
1854 status,
1855 "sglist provided as NULL");
1856 }
1857 else if (nSegs == 0) {
1858 /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1859 status = PROCESSOR_E_INVALIDARG;
1860 GT_setFailureReason (curTrace,
1861 GT_4CLASS,
1862 "VAYUIPUCORE1PROC_map",
1863 status,
1864 "Number of segments provided is 0");
1865 }
1866 else {
1867 #endif
1868 object = (VAYUIPUCORE1PROC_Object *)procHandle->object;
1869 GT_assert (curTrace, (object != NULL));
1871 for (i = 0; (i < nSegs) && (status >= 0); i++) {
1872 /* Update the translation table with entries for which mapping
1873 * is required. Add the entry only if the range does not exist
1874 * in the translation table.
1875 */
1877 /* check in static entries first */
1878 for (j = 0; j < AddrTable_STATIC_COUNT; j++) {
1879 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][j];
1880 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1881 endAddr = startAddr + ai->size;
1883 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)) {
1884 found = TRUE;
1885 /* refCount does not need to be incremented for static entries */
1886 break;
1887 }
1888 }
1890 /* if not found in static entries, check in dynamic entries */
1891 if (!found) {
1892 for (j = AddrTable_STATIC_COUNT; j < AddrTable_count; j++) {
1893 ai = &AddrTable[j];
1895 if (ai->isMapped == TRUE) {
1896 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1897 endAddr = startAddr + ai->size;
1899 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1900 && ((*dstAddr + sglist[i].size) <= endAddr)) {
1901 found = TRUE;
1902 ai->refCount++;
1903 break;
1904 }
1905 }
1906 }
1907 }
1909 /* If not found, add new entry to table. If mmu is disabled,
1910 * the assumption is that the ammu will be used.
1911 */
1912 if (!found) {
1913 if (object->params.mmuEnable) {
1914 if (AddrTable_count[PROCID_TO_IPU(procHandle->procId)] !=
1915 AddrTable_SIZE) {
1916 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)]
1917 [AddrTable_count[PROCID_TO_IPU
1918 (procHandle->procId)]];
1919 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1920 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1921 ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1922 ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1923 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1924 ai->size = sglist[i].size;
1925 ai->isCached = sglist[i].isCached;
1926 ai->refCount++;
1928 AddrTable_count[PROCID_TO_IPU(procHandle->procId)]++;
1929 }
1930 else {
1931 status = PROCESSOR_E_FAIL;
1932 GT_setFailureReason(curTrace, GT_4CLASS,
1933 "VAYUIPUCORE1PROC_map", status,
1934 "AddrTable_SIZE reached!");
1935 }
1936 }
1937 else {
1938 /* if mmu disabled, AddrTable not updated */
1939 ai = NULL;
1940 }
1941 }
1943 /* if new entry, map into dsp mmu */
1944 if ((ai != NULL) && (ai->refCount == 1) && (status >= 0)) {
1945 ai->isMapped = TRUE;
1947 if (object->params.mmuEnable) {
1948 /* add entry to L2 MMU */
1949 addEntryArgs.masterPhyAddr = sglist [i].paddr;
1950 addEntryArgs.size = sglist [i].size;
1951 addEntryArgs.slaveVirtAddr = (UInt32)*dstAddr;
1952 /* TBD: elementSize, endianism, mixedSized are
1953 * hard coded now, must be configurable later
1954 */
1955 addEntryArgs.elementSize = ELEM_SIZE_16BIT;
1956 addEntryArgs.endianism = LITTLE_ENDIAN;
1957 addEntryArgs.mixedSize = MMU_TLBES;
1959 status = VAYUIPU_halMmuCtrl(object->halObject,
1960 Processor_MmuCtrlCmd_AddEntry, &addEntryArgs);
1962 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1963 if (status < 0) {
1964 GT_setFailureReason(curTrace, GT_4CLASS,
1965 "VAYUIPUCORE1PROC_map", status,
1966 "Processor_MmuCtrlCmd_AddEntry failed");
1967 }
1968 #endif
1969 }
1970 }
1971 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1972 if (status < 0) {
1973 GT_setFailureReason(curTrace, GT_4CLASS,
1974 "VAYUIPUCORE1PROC_map", status,
1975 "IPUCORE1 MMU configuration failed");
1976 }
1977 #endif
1978 }
1979 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1980 }
1981 #endif
1982 GT_1trace(curTrace, GT_LEAVE, "VAYUIPUCORE1PROC_map", status);
1984 /*! @retval PROCESSOR_SUCCESS Operation successful */
1985 return status;
1986 }
1989 /*!
1990 * @brief Function to unmap slave address from host address space
1991 *
1992 * @param handle Handle to the Processor object
1993 * @param dstAddr Return parameter: Pointer to receive the mapped
1994 * address.
1995 * @param size Size of the region to be mapped.
1996 *
1997 * @sa
1998 */
1999 Int
2000 VAYUIPUCORE1PROC_unmap(
2001 Processor_Handle handle,
2002 UInt32 addr,
2003 UInt32 size)
2004 {
2005 Int status = PROCESSOR_SUCCESS;
2006 Processor_Object * procHandle = (Processor_Object *)handle;
2007 VAYUIPUCORE1PROC_Object * object = NULL;
2008 ProcMgr_AddrInfo * ai;
2009 Int i;
2010 UInt32 startAddr;
2011 UInt32 endAddr;
2012 VAYUIPU_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
2014 GT_3trace (curTrace, GT_ENTER, "VAYUIPUCORE1PROC_unmap",
2015 handle, addr, size);
2017 GT_assert (curTrace, (handle != NULL));
2018 GT_assert (curTrace, (size != 0));
2020 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
2021 if (handle == NULL) {
2022 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
2023 status = PROCESSOR_E_HANDLE;
2024 GT_setFailureReason (curTrace,
2025 GT_4CLASS,
2026 "VAYUIPUCORE1PROC_unmap",
2027 status,
2028 "Invalid handle specified");
2029 }
2030 else if (size == 0) {
2031 /*! @retval PROCESSOR_E_INVALIDARG Size provided is zero */
2032 status = PROCESSOR_E_INVALIDARG;
2033 GT_setFailureReason (curTrace,
2034 GT_4CLASS,
2035 "VAYUIPUCORE1PROC_unmap",
2036 status,
2037 "Size provided is zero");
2038 }
2039 else {
2040 #endif
2041 object = (VAYUIPUCORE1PROC_Object *) procHandle->object;
2042 GT_assert (curTrace, (object != NULL));
2044 /* Delete dynamically added non-default entries from translation
2045 * table only in last unmap called on that entry
2046 */
2047 for (i = AddrTable_STATIC_COUNT;
2048 i < AddrTable_count[PROCID_TO_IPU(procHandle->procId)]; i++) {
2049 ai = &AddrTable[PROCID_TO_IPU(procHandle->procId)][i];
2051 if (!ai->isMapped) {
2052 continue;
2053 }
2055 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
2056 endAddr = startAddr + ai->size;
2058 if ((startAddr <= addr) && (addr < endAddr)) {
2059 ai->refCount--;
2061 if (ai->refCount == 0) {
2062 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
2063 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
2064 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
2065 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
2066 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
2067 ai->size = 0u;
2068 ai->isCached = FALSE;
2069 ai->mapMask = 0u;
2070 ai->isMapped = FALSE;
2072 if (object->params.mmuEnable) {
2073 /* Remove the entry from the IPUCORE1 MMU also */
2074 deleteEntryArgs.size = size;
2075 deleteEntryArgs.slaveVirtAddr = addr;
2076 /* TBD: elementSize, endianism, mixedSized are
2077 * hard coded now, must be configurable later
2078 */
2079 deleteEntryArgs.elementSize = ELEM_SIZE_16BIT;
2080 deleteEntryArgs.endianism = LITTLE_ENDIAN;
2081 deleteEntryArgs.mixedSize = MMU_TLBES;
2083 status = VAYUIPU_halMmuCtrl(object->halObject,
2084 Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2085 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2086 if (status < 0) {
2087 GT_setFailureReason(curTrace, GT_4CLASS,
2088 "VAYUIPUCORE1PROC_unmap", status,
2089 "IPUCORE1 MMU configuration failed");
2090 }
2091 #endif
2092 }
2093 }
2094 }
2095 }
2096 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
2097 }
2098 #endif
2099 GT_1trace(curTrace, GT_LEAVE,
2100 "VAYUIPUCORE1PROC_unmap", status);
2102 /*! @retval PROCESSOR_SUCCESS Operation successful */
2103 return status;
2104 }
2107 #if defined (__cplusplus)
2108 }
2109 #endif /* defined (__cplusplus) */