[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / ti81xx / ti81xxducati / ti81xxvpssm3 / Dm8168M3DssProc.c
1 /*
2 * @file Dm8168M3DssProc.c
3 *
4 * @brief Processor implementation for DM8168VPSSM3.
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 DM8168VPSSM3.
10 *
11 *
12 * ============================================================================
13 *
14 * Copyright (c) 2008-2012, 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 #if defined(SYSLINK_BUILD_RTOS)
56 #include <xdc/std.h>
57 #include <xdc/runtime/Error.h>
58 #include <xdc/runtime/Memory.h>
59 #include <xdc/runtime/System.h>
60 #include <xdc/runtime/IGateProvider.h>
61 #include <ti/sysbios/gates/GateMutex.h>
62 #endif /* #if defined(SYSLINK_BUILD_RTOS) */
64 #if defined(SYSLINK_BUILD_HLOS)
65 #include <ti/syslink/Std.h>
66 /* OSAL & Utils headers */
67 #include <ti/syslink/utils/Cfg.h>
68 #include <ti/syslink/utils/String.h>
69 #include <ti/syslink/utils/IGateProvider.h>
70 #include <ti/syslink/utils/GateMutex.h>
71 #include <ti/syslink/utils/Memory.h>
72 #endif /* #if defined(SYSLINK_BUILD_HLOS) */
74 #if defined(SYSLINK_BUILDOS_LINUX)
75 #include <linux/string.h>
76 #else
77 #include <string.h>
78 #endif
80 #include <ti/syslink/utils/Trace.h>
82 /* Module level headers */
83 #include <ti/ipc/MultiProc.h>
84 #include <_MultiProc.h>
85 #include <ProcDefs.h>
86 #include <Processor.h>
87 #include <Dm8168M3DssProc.h>
88 #include <_Dm8168M3DssProc.h>
89 #include <Dm8168M3DssHal.h>
90 #include <Dm8168M3DssHalReset.h>
91 #include <Dm8168M3DssHalBoot.h>
94 #if defined (__cplusplus)
95 extern "C" {
96 #endif
99 /* =============================================================================
100 * Macros and types
101 * =============================================================================
102 */
104 /*!
105 * @brief Number of static entries in address translation table.
106 */
107 #define AddrTable_STATIC_COUNT 4
109 /*!
110 * @brief Max entries in address translation table.
111 */
112 #define AddrTable_SIZE 32
114 /* Config param for L2MMU. This is not a typo, we are using the
115 * same name (VPSS-M3) because both Ducati M3 processors use the
116 * same L2MMU. The docs expose VPSS-M3 but not the VIDEO-M3 processor.
117 */
118 #define PARAMS_mmuEnable "ProcMgr.proc[VPSS-M3].mmuEnable="
121 /*!
122 * @brief DM8168VPSSM3PROC Module state object
123 */
124 typedef struct DM8168VPSSM3PROC_ModuleObject_tag {
125 UInt32 configSize;
126 /*!< Size of configuration structure */
127 DM8168VPSSM3PROC_Config cfg;
128 /*!< DM8168VPSSM3PROC configuration structure */
129 DM8168VPSSM3PROC_Config defCfg;
130 /*!< Default module configuration */
131 DM8168VPSSM3PROC_Params defInstParams;
132 /*!< Default parameters for the DM8168VPSSM3PROC instances */
133 Bool isSetup;
134 /*!< Indicates whether the DM8168VPSSM3PROC module is setup. */
135 DM8168VPSSM3PROC_Handle procHandles [MultiProc_MAXPROCESSORS];
136 /*!< Processor handle array. */
137 IGateProvider_Handle gateHandle;
138 /*!< Handle of gate to be used for local thread safety */
139 } DM8168VPSSM3PROC_ModuleObject;
141 /*!
142 * @brief DM8168VPSSM3PROC instance object.
143 */
144 struct DM8168VPSSM3PROC_Object_tag {
145 DM8168VPSSM3PROC_Params params;
146 /*!< Instance parameters (configuration values) */
147 Ptr halObject;
148 /*!< Pointer to the Hardware Abstraction Layer object. */
149 ProcMgr_Handle pmHandle;
150 /*!< Handle to proc manager */
151 };
153 /* Defines the DM8168VPSSM3PROC object type. */
154 typedef struct DM8168VPSSM3PROC_Object_tag DM8168VPSSM3PROC_Object;
157 /* Default memory regions */
158 static UInt32 AddrTable_count = AddrTable_STATIC_COUNT;
160 /* static memory regions
161 * CAUTION: AddrTable_STATIC_COUNT must match number of entries below.
162 */
163 static ProcMgr_AddrInfo AddrTable[AddrTable_SIZE] =
164 {
165 { /* L2 BOOT, 16 KB */
166 .addr = { -1u, -1u, 0x55020000, 0x00000000, 0x55020000 },
167 .size = 0x4000,
168 .isCached = FALSE,
169 .isMapped = FALSE,
170 .mapMask = ProcMgr_MASTERKNLVIRT
171 },
172 { /* L2 RAM, 240 KB */
173 .addr = { -1u, -1u, 0x55024000, 0x20004000, 0x55024000 },
174 .size = 0x3C000,
175 .isCached = FALSE,
176 .isMapped = FALSE,
177 .mapMask = ProcMgr_MASTERKNLVIRT
178 },
179 { /* OCMC0, 256 KB */
180 .addr = { -1u, -1u, 0x40300000, 0x00300000, 0x40300000 },
181 .size = 0x40000,
182 .isCached = FALSE,
183 .isMapped = FALSE,
184 .mapMask = (ProcMgr_MASTERKNLVIRT | ProcMgr_SLAVEVIRT)
185 },
186 { /* OCMC1, 256 KB */
187 .addr = { -1u, -1u, 0x40400000, 0x00400000, 0x40400000 },
188 .size = 0x40000,
189 .isCached = FALSE,
190 .isMapped = FALSE,
191 .mapMask = (ProcMgr_MASTERKNLVIRT | ProcMgr_SLAVEVIRT)
192 }
193 };
195 /* =============================================================================
196 * Globals
197 * =============================================================================
198 */
200 /*!
201 * @var DM8168VPSSM3PROC_state
202 *
203 * @brief DM8168VPSSM3PROC state object variable
204 */
205 #if !defined(SYSLINK_BUILD_DEBUG)
206 static
207 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
208 DM8168VPSSM3PROC_ModuleObject DM8168VPSSM3PROC_state =
209 {
210 .isSetup = FALSE,
211 .configSize = sizeof(DM8168VPSSM3PROC_Config),
212 .gateHandle = NULL,
213 .defInstParams.mmuEnable = FALSE,
214 .defInstParams.numMemEntries = AddrTable_STATIC_COUNT
215 };
217 /* config override specified in SysLinkCfg.c, defined in ProcMgr.c */
218 extern String ProcMgr_sysLinkCfgParams;
220 /* =============================================================================
221 * APIs directly called by applications
222 * =============================================================================
223 */
224 /*!
225 * @brief Function to get the default configuration for the DM8168VPSSM3PROC
226 * module.
227 *
228 * This function can be called by the application to get their
229 * configuration parameter to DM8168VPSSM3PROC_setup filled in by the
230 * DM8168VPSSM3PROC module with the default parameters. If the user
231 * does not wish to make any change in the default parameters, this
232 * API is not required to be called.
233 *
234 * @param cfg Pointer to the DM8168VPSSM3PROC module configuration
235 * structure in which the default config is to be
236 * returned.
237 *
238 * @sa DM8168VPSSM3PROC_setup
239 */
240 Void
241 DM8168VPSSM3PROC_getConfig (DM8168VPSSM3PROC_Config * cfg)
242 {
243 GT_1trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_getConfig", cfg);
245 GT_assert (curTrace, (cfg != NULL));
247 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
248 if (cfg == NULL) {
249 GT_setFailureReason (curTrace,
250 GT_4CLASS,
251 "DM8168VPSSM3PROC_getConfig",
252 PROCESSOR_E_INVALIDARG,
253 "Argument of type (DM8168VPSSM3PROC_Config *) passed "
254 "is null!");
255 }
256 else {
257 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
258 memcpy (cfg,
259 &(DM8168VPSSM3PROC_state.defCfg),
260 sizeof (DM8168VPSSM3PROC_Config));
261 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
262 }
263 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
265 GT_0trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_getConfig");
266 }
269 /*!
270 * @brief Function to setup the DM8168VPSSM3PROC module.
271 *
272 * This function sets up the DM8168VPSSM3PROC module. This function
273 * must be called before any other instance-level APIs can be
274 * invoked.
275 * Module-level configuration needs to be provided to this
276 * function. If the user wishes to change some specific config
277 * parameters, then DM8168VPSSM3PROC_getConfig can be called to get the
278 * configuration filled with the default values. After this, only
279 * the required configuration values can be changed. If the user
280 * does not wish to make any change in the default parameters, the
281 * application can simply call DM8168VPSSM3PROC_setup with NULL
282 * parameters. The default parameters would get automatically used.
283 *
284 * @param cfg Optional DM8168VPSSM3PROC module configuration. If provided as
285 * NULL, default configuration is used.
286 *
287 * @sa DM8168VPSSM3PROC_destroy
288 * GateMutex_create
289 */
290 Int
291 DM8168VPSSM3PROC_setup (DM8168VPSSM3PROC_Config * cfg)
292 {
293 Int status = PROCESSOR_SUCCESS;
294 DM8168VPSSM3PROC_Config tmpCfg;
295 Error_Block eb;
297 GT_1trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_setup", cfg);
298 Error_init(&eb);
299 if (cfg == NULL) {
300 DM8168VPSSM3PROC_getConfig (&tmpCfg);
301 cfg = &tmpCfg;
302 }
304 /* Create a default gate handle for local module protection. */
305 DM8168VPSSM3PROC_state.gateHandle = (IGateProvider_Handle)
306 GateMutex_create ((GateMutex_Params*)NULL, &eb);
307 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
308 if (DM8168VPSSM3PROC_state.gateHandle == NULL) {
309 /*! @retval PROCESSOR_E_FAIL Failed to create GateMutex! */
310 status = PROCESSOR_E_FAIL;
311 GT_setFailureReason (curTrace,
312 GT_4CLASS,
313 "DM8168VPSSM3PROC_setup",
314 status,
315 "Failed to create GateMutex!");
316 }
317 else {
318 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
319 /* Copy the user provided values into the state object. */
320 memcpy (&DM8168VPSSM3PROC_state.cfg,
321 cfg,
322 sizeof (DM8168VPSSM3PROC_Config));
324 /* Initialize the name to handles mapping array. */
325 memset (&DM8168VPSSM3PROC_state.procHandles,
326 0,
327 (sizeof (DM8168VPSSM3PROC_Handle) * MultiProc_MAXPROCESSORS));
328 DM8168VPSSM3PROC_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, "DM8168VPSSM3PROC_setup", status);
335 /*! @retval PROCESSOR_SUCCESS Operation successful */
336 return (status);
337 }
340 /*!
341 * @brief Function to destroy the DM8168VPSSM3PROC module.
342 *
343 * Once this function is called, other DM8168VPSSM3PROC module APIs,
344 * except for the DM8168VPSSM3PROC_getConfig API cannot be called
345 * anymore.
346 *
347 * @sa DM8168VPSSM3PROC_setup
348 * GateMutex_delete
349 */
350 Int
351 DM8168VPSSM3PROC_destroy (Void)
352 {
353 Int status = PROCESSOR_SUCCESS;
354 UInt16 i;
356 GT_0trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_destroy");
358 /* Check if any DM8168VPSSM3PROC instances have not been deleted so far. If not,
359 * delete them.
360 */
361 for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
362 GT_assert (curTrace, (DM8168VPSSM3PROC_state.procHandles [i] == NULL));
363 if (DM8168VPSSM3PROC_state.procHandles [i] != NULL) {
364 DM8168VPSSM3PROC_delete (&(DM8168VPSSM3PROC_state.procHandles [i]));
365 }
366 }
368 if (DM8168VPSSM3PROC_state.gateHandle != NULL) {
369 GateMutex_delete ((GateMutex_Handle *)
370 &(DM8168VPSSM3PROC_state.gateHandle));
371 }
373 DM8168VPSSM3PROC_state.isSetup = FALSE;
375 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_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 DM8168VPSSM3PROC_create
389 */
390 Void
391 DM8168VPSSM3PROC_Params_init(
392 DM8168VPSSM3PROC_Handle handle,
393 DM8168VPSSM3PROC_Params * params)
394 {
395 DM8168VPSSM3PROC_Object *procObject = (DM8168VPSSM3PROC_Object *)handle;
396 Int i = 0;
397 ProcMgr_AddrInfo *ai = NULL;
399 GT_2trace(curTrace, GT_ENTER,
400 "DM8168VPSSM3PROC_Params_init: handle=0x%x, params=0x%x\n",
401 handle, params);
403 GT_assert(curTrace, (params != NULL));
405 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
406 if (params == NULL) {
407 GT_setFailureReason(curTrace, GT_4CLASS,
408 "DM8168VPSSM3PROC_Params_init", PROCESSOR_E_INVALIDARG,
409 "Argument of type (DM8168VPSSM3PROC_Params *) passed is null!");
410 }
411 else {
412 #endif
413 if (handle == NULL) {
415 /* check for instance params override */
416 Cfg_propBool(PARAMS_mmuEnable, ProcMgr_sysLinkCfgParams,
417 &(DM8168VPSSM3PROC_state.defInstParams.mmuEnable));
419 memcpy(params, &(DM8168VPSSM3PROC_state.defInstParams),
420 sizeof (DM8168VPSSM3PROC_Params));
422 /* initialize the translation table */
423 for (i = AddrTable_count; i < AddrTable_SIZE; i++) {
424 ai = &AddrTable[i];
425 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
426 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
427 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
428 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
429 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
430 ai->size = 0u;
431 ai->isCached = FALSE;
432 ai->mapMask = 0u;
433 ai->isMapped = FALSE;
434 }
436 /* initialize refCount for all entries - both static and dynamic */
437 for (i = 0; i < AddrTable_SIZE; i++) {
438 AddrTable[i].refCount = 0u;
439 }
441 memcpy((Ptr)params->memEntries, AddrTable, sizeof(AddrTable));
442 }
443 else {
444 /* return updated DM8168VPSSM3PROC instance specific parameters */
445 memcpy(params, &(procObject->params),
446 sizeof(DM8168VPSSM3PROC_Params));
447 }
448 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
449 }
450 #endif
452 GT_0trace(curTrace, GT_LEAVE, "DM8168VPSSM3PROC_Params_init");
453 }
455 /*!
456 * @brief Function to create an instance of this Processor.
457 *
458 * @param name Name of the Processor instance.
459 * @param params Configuration parameters.
460 *
461 * @sa DM8168VPSSM3PROC_delete
462 */
463 DM8168VPSSM3PROC_Handle
464 DM8168VPSSM3PROC_create ( UInt16 procId,
465 const DM8168VPSSM3PROC_Params * params)
466 {
467 Int status = PROCESSOR_SUCCESS;
468 Processor_Object * handle = NULL;
469 DM8168VPSSM3PROC_Object * object = NULL;
470 IArg key;
471 List_Params listParams;
473 GT_2trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_create", procId, params);
475 GT_assert (curTrace, IS_VALID_PROCID (procId));
476 GT_assert (curTrace, (params != NULL));
478 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
479 if (!IS_VALID_PROCID (procId)) {
480 /* Not setting status here since this function does not return status.*/
481 GT_setFailureReason (curTrace,
482 GT_4CLASS,
483 "DM8168VPSSM3PROC_create",
484 PROCESSOR_E_INVALIDARG,
485 "Invalid procId specified");
486 }
487 else if (params == NULL) {
488 GT_setFailureReason (curTrace,
489 GT_4CLASS,
490 "DM8168VPSSM3PROC_create",
491 PROCESSOR_E_INVALIDARG,
492 "params passed is NULL!");
493 }
494 else {
495 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
496 /* Enter critical section protection. */
497 key = IGateProvider_enter (DM8168VPSSM3PROC_state.gateHandle);
498 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
499 /* Check if the Processor already exists for specified procId. */
500 if (DM8168VPSSM3PROC_state.procHandles [procId] != NULL) {
501 status = PROCESSOR_E_ALREADYEXIST;
502 GT_setFailureReason (curTrace,
503 GT_4CLASS,
504 "DM8168VPSSM3PROC_create",
505 status,
506 "Processor already exists for specified procId!");
507 }
508 else {
509 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
510 /* Allocate memory for the handle */
511 handle = (Processor_Object *) Memory_calloc (NULL,
512 sizeof (Processor_Object),
513 0,
514 NULL);
515 if (handle == NULL) {
516 GT_setFailureReason (curTrace,
517 GT_4CLASS,
518 "DM8168VPSSM3PROC_create",
519 PROCESSOR_E_MEMORY,
520 "Memory allocation failed for handle!");
521 }
522 else {
523 /* Populate the handle fields */
524 handle->procFxnTable.attach = &DM8168VPSSM3PROC_attach;
525 handle->procFxnTable.detach = &DM8168VPSSM3PROC_detach;
526 handle->procFxnTable.start = &DM8168VPSSM3PROC_start;
527 handle->procFxnTable.stop = &DM8168VPSSM3PROC_stop;
528 handle->procFxnTable.read = &DM8168VPSSM3PROC_read;
529 handle->procFxnTable.write = &DM8168VPSSM3PROC_write;
530 handle->procFxnTable.control = &DM8168VPSSM3PROC_control;
531 handle->procFxnTable.map = &DM8168VPSSM3PROC_map;
532 handle->procFxnTable.unmap = &DM8168VPSSM3PROC_unmap;
533 handle->procFxnTable.translateAddr = &DM8168VPSSM3PROC_translate;
534 handle->state = ProcMgr_State_Unknown;
536 /* Allocate memory for the DM8168VPSSM3PROC handle */
537 handle->object = (DM8168VPSSM3PROC_Object *) Memory_calloc (NULL,
538 sizeof (DM8168VPSSM3PROC_Object),
539 0,
540 NULL);
541 if (handle->object == NULL) {
542 status = PROCESSOR_E_MEMORY;
543 GT_setFailureReason (curTrace,
544 GT_4CLASS,
545 "DM8168VPSSM3PROC_create",
546 status,
547 "Memory allocation failed for handle->object!");
548 }
549 else {
550 handle->procId = procId;
551 object = (DM8168VPSSM3PROC_Object *) handle->object;
552 object->halObject = NULL;
553 /* Copy params into instance object. */
554 memcpy (&(object->params),
555 (Ptr) params,
556 sizeof (DM8168VPSSM3PROC_Params));
558 /* Set the handle in the state object. */
559 DM8168VPSSM3PROC_state.procHandles [procId] =
560 (DM8168VPSSM3PROC_Handle) handle;
561 /* Initialize the list of listeners */
562 List_Params_init(&listParams);
563 handle->registeredNotifiers = List_create(&listParams);
565 #if !defined(SYSLINK_BUILD_OPTIMIZE)
566 if (handle->registeredNotifiers == NULL) {
567 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed */
568 status = PROCESSOR_E_FAIL;
569 GT_setFailureReason (curTrace,
570 GT_4CLASS,
571 "DM8168VPSSM3PROC_create",
572 status,
573 "List_create failed");
574 }
575 else {
576 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
578 handle->notifiersLock =
579 OsalMutex_create(OsalMutex_Type_Interruptible);
581 #if !defined(SYSLINK_BUILD_OPTIMIZE)
582 if (handle->notifiersLock == NULL) {
583 /*! @retval PROCESSOR_E_FAIL OsalIsr_create failed*/
584 status = PROCESSOR_E_FAIL;
585 GT_setFailureReason (curTrace,
586 GT_4CLASS,
587 "DM8168VPSSM3PROC_create",
588 status,
589 "OsalMutex_create failed");
590 }
591 }
592 #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
593 }
594 }
595 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
596 }
597 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
599 /* Leave critical section protection. */
600 IGateProvider_leave (DM8168VPSSM3PROC_state.gateHandle, key);
601 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
602 }
603 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
605 if (status < 0) {
606 if (handle != NULL) {
607 if (handle->registeredNotifiers != NULL) {
608 List_delete (&handle->registeredNotifiers);
609 }
610 if (handle->object != NULL) {
611 Memory_free (NULL,
612 handle->object,
613 sizeof (DM8168VPSSM3PROC_Object));
614 }
615 Memory_free (NULL, handle, sizeof (Processor_Object));
616 }
617 /*! @retval NULL Function failed */
618 handle = NULL;
619 }
621 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_create", handle);
623 /*! @retval Valid-Handle Operation successful */
624 return (DM8168VPSSM3PROC_Handle) handle;
625 }
628 /*!
629 * @brief Function to delete an instance of this Processor.
630 *
631 * The user provided pointer to the handle is reset after
632 * successful completion of this function.
633 *
634 * @param handlePtr Pointer to Handle to the Processor instance
635 *
636 * @sa DM8168VPSSM3PROC_create
637 */
638 Int
639 DM8168VPSSM3PROC_delete (DM8168VPSSM3PROC_Handle * handlePtr)
640 {
641 Int status = PROCESSOR_SUCCESS;
642 DM8168VPSSM3PROC_Object * object = NULL;
643 Processor_Object * handle;
644 IArg key;
645 List_Elem * elem = NULL;
646 Processor_RegisterElem * regElem = NULL;
648 GT_1trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_delete", handlePtr);
650 GT_assert (curTrace, (handlePtr != NULL));
651 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
653 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
654 if (handlePtr == NULL) {
655 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
656 specified*/
657 status = PROCESSOR_E_INVALIDARG;
658 GT_setFailureReason (curTrace,
659 GT_4CLASS,
660 "DM8168VPSSM3PROC_delete",
661 status,
662 "Invalid NULL handlePtr pointer specified");
663 }
664 else if (*handlePtr == NULL) {
665 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
666 status = PROCESSOR_E_HANDLE;
667 GT_setFailureReason (curTrace,
668 GT_4CLASS,
669 "DM8168VPSSM3PROC_delete",
670 status,
671 "Invalid NULL *handlePtr specified");
672 }
673 else {
674 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
675 handle = (Processor_Object *) (*handlePtr);
676 /* Enter critical section protection. */
677 key = IGateProvider_enter (DM8168VPSSM3PROC_state.gateHandle);
679 /* Reset handle in PwrMgr handle array. */
680 GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
681 DM8168VPSSM3PROC_state.procHandles [handle->procId] = NULL;
683 /* Free memory used for the DM8168VPSSM3PROC object. */
684 if (handle->object != NULL) {
685 object = (DM8168VPSSM3PROC_Object *) handle->object;
687 Memory_free (NULL,
688 object,
689 sizeof (DM8168VPSSM3PROC_Object));
690 handle->object = NULL;
691 }
693 /*
694 * Check the list of listeners to see if any are remaining
695 * and reply to them
696 */
697 OsalMutex_delete(&handle->notifiersLock);
699 while ((elem = List_dequeue(handle->registeredNotifiers)) != NULL) {
700 regElem = (Processor_RegisterElem *)elem;
702 /* Check if there is an associated timer and cancel it */
703 if (regElem->timer != -1) {
704 struct itimerspec value ;
705 value.it_value.tv_sec = 0;
706 value.it_value.tv_nsec = 0;
707 value.it_interval.tv_sec = 0;
708 value.it_interval.tv_nsec = 0;
709 timer_settime(regElem->timer, 0, &value, NULL);
711 timer_delete(regElem->timer);
712 regElem->timer = -1;
713 }
715 /* Call the callback function so it can clean up. */
716 regElem->info->cbFxn(handle->procId,
717 NULL,
718 handle->state,
719 handle->state,
720 ProcMgr_EventStatus_Canceled,
721 regElem->info->arg);
722 /* Free the memory */
723 Memory_free(NULL, regElem, sizeof(Processor_RegisterElem));
724 }
726 /* Delete the list of listeners */
727 List_delete(&handle->registeredNotifiers);
729 /* Free memory used for the Processor object. */
730 Memory_free (NULL, handle, sizeof (Processor_Object));
731 *handlePtr = NULL;
733 /* Leave critical section protection. */
734 IGateProvider_leave (DM8168VPSSM3PROC_state.gateHandle, key);
735 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
736 }
737 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
739 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_delete", status);
741 /*! @retval PROCESSOR_SUCCESS Operation successful */
742 return (status);
743 }
746 /*!
747 * @brief Function to open a handle to an instance of this Processor. This
748 * function is called when access to the Processor is required from
749 * a different process.
750 *
751 * @param handlePtr Handle to the Processor instance
752 * @param procId Processor ID addressed by this Processor instance.
753 *
754 * @sa DM8168VPSSM3PROC_close
755 */
756 Int
757 DM8168VPSSM3PROC_open (DM8168VPSSM3PROC_Handle * handlePtr, UInt16 procId)
758 {
759 Int status = PROCESSOR_SUCCESS;
761 GT_2trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_open", handlePtr, procId);
763 GT_assert (curTrace, (handlePtr != NULL));
764 GT_assert (curTrace, IS_VALID_PROCID (procId));
766 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
767 if (handlePtr == NULL) {
768 /*! @retval PROCESSOR_E_HANDLE Invalid NULL handlePtr specified */
769 status = PROCESSOR_E_HANDLE;
770 GT_setFailureReason (curTrace,
771 GT_4CLASS,
772 "DM8168VPSSM3PROC_open",
773 status,
774 "Invalid NULL handlePtr specified");
775 }
776 else if (!IS_VALID_PROCID (procId)) {
777 /*! @retval PROCESSOR_E_INVALIDARG Invalid procId specified */
778 status = PROCESSOR_E_INVALIDARG;
779 GT_setFailureReason (curTrace,
780 GT_4CLASS,
781 "DM8168VPSSM3PROC_open",
782 status,
783 "Invalid procId specified");
784 }
785 else {
786 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
787 /* Initialize return parameter handle. */
788 *handlePtr = NULL;
790 /* Check if the PwrMgr exists and return the handle if found. */
791 if (DM8168VPSSM3PROC_state.procHandles [procId] == NULL) {
792 /*! @retval PROCESSOR_E_NOTFOUND Specified instance not found */
793 status = PROCESSOR_E_NOTFOUND;
794 GT_setFailureReason (curTrace,
795 GT_4CLASS,
796 "DM8168VPSSM3PROC_open",
797 status,
798 "Specified DM8168VPSSM3PROC instance does not exist!");
799 }
800 else {
801 *handlePtr = DM8168VPSSM3PROC_state.procHandles [procId];
802 }
803 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
804 }
805 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
807 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_open", status);
809 /*! @retval PROCESSOR_SUCCESS Operation successful */
810 return status;
811 }
814 /*!
815 * @brief Function to close a handle to an instance of this Processor.
816 *
817 * @param handlePtr Pointer to Handle to the Processor instance
818 *
819 * @sa DM8168VPSSM3PROC_open
820 */
821 Int
822 DM8168VPSSM3PROC_close (DM8168VPSSM3PROC_Handle * handlePtr)
823 {
824 Int status = PROCESSOR_SUCCESS;
826 GT_1trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_close", handlePtr);
828 GT_assert (curTrace, (handlePtr != NULL));
829 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
831 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
832 if (handlePtr == NULL) {
833 /*! @retval PROCESSOR_E_INVALIDARG Invalid NULL handlePtr pointer
834 specified*/
835 status = PROCESSOR_E_INVALIDARG;
836 GT_setFailureReason (curTrace,
837 GT_4CLASS,
838 "DM8168VPSSM3PROC_close",
839 status,
840 "Invalid NULL handlePtr pointer specified");
841 }
842 else if (*handlePtr == NULL) {
843 /*! @retval PROCESSOR_E_HANDLE Invalid NULL *handlePtr specified */
844 status = PROCESSOR_E_HANDLE;
845 GT_setFailureReason (curTrace,
846 GT_4CLASS,
847 "DM8168VPSSM3PROC_close",
848 status,
849 "Invalid NULL *handlePtr specified");
850 }
851 else {
852 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
853 /* Nothing to be done for close. */
854 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
855 }
856 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
858 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_close", status);
860 /*! @retval PROCESSOR_SUCCESS Operation successful */
861 return status;
862 }
865 /* =============================================================================
866 * APIs called by Processor module (part of function table interface)
867 * =============================================================================
868 */
869 /*!
870 * @brief Function to initialize the slave processor
871 *
872 * @param handle Handle to the Processor instance
873 * @param params Attach parameters
874 *
875 * @sa DM8168VPSSM3PROC_detach
876 */
877 Int
878 DM8168VPSSM3PROC_attach(
879 Processor_Handle handle,
880 Processor_AttachParams * params)
881 {
883 Int status = PROCESSOR_SUCCESS;
884 Processor_Object * procHandle = (Processor_Object *)handle;
885 DM8168VPSSM3PROC_Object * object = NULL;
886 Int i = 0;
887 Int j = 0;
888 Int index = 0;
889 ProcMgr_AddrInfo * me;
890 SysLink_MemEntry * entry;
891 SysLink_MemEntry_Block * memBlock = NULL;
892 DM8168VPSSM3_HalMmuCtrlArgs_Enable mmuEnableArgs;
894 GT_2trace(curTrace, GT_ENTER,
895 "DM8168VPSSM3PROC_attach: handle=0x%x, parms=0x%x", handle, params);
896 GT_assert (curTrace, (handle != NULL));
897 GT_assert (curTrace, (params != NULL));
899 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
900 if (handle == NULL) {
901 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
902 status = PROCESSOR_E_HANDLE;
903 GT_setFailureReason (curTrace,
904 GT_4CLASS,
905 "DM8168VPSSM3PROC_attach",
906 status,
907 "Invalid handle specified");
908 }
909 else if (params == NULL) {
910 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
911 status = PROCESSOR_E_INVALIDARG;
912 GT_setFailureReason (curTrace,
913 GT_4CLASS,
914 "DM8168VPSSM3PROC_attach",
915 status,
916 "Invalid params specified");
917 }
918 else {
919 #endif
920 object = (DM8168VPSSM3PROC_Object *) procHandle->object;
921 GT_assert (curTrace, (object != NULL));
923 /* Added for Netra Ducati core1 is cortex M3 */
924 params->procArch = Processor_ProcArch_M3;
926 /* check for instance params override */
927 Cfg_propBool(PARAMS_mmuEnable, ProcMgr_sysLinkCfgParams,
928 &(object->params.mmuEnable));
930 object->pmHandle = params->pmHandle;
931 GT_0trace(curTrace, GT_1CLASS,
932 "DM8168VPSSM3PROC_attach: Mapping memory regions");
934 /* update translation tables with memory map */
935 for (i = 0; (memBlock != NULL) && (i < memBlock->numEntries)
936 && (memBlock->memEntries[i].isValid) && (status >= 0); i++) {
938 entry = &memBlock->memEntries[i];
940 if (entry->map == FALSE) {
941 /* update table with entries which don't require mapping */
942 if (AddrTable_count != AddrTable_SIZE) {
943 me = &AddrTable[AddrTable_count];
945 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
946 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
947 me->addr[ProcMgr_AddrType_MasterPhys] =
948 entry->masterPhysAddr;
949 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
950 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
951 me->size = entry->size;
952 me->isCached = entry->isCached;
953 me->mapMask = entry->mapMask;
955 AddrTable_count++;
956 }
957 else {
958 status = PROCESSOR_E_FAIL;
959 GT_setFailureReason(curTrace, GT_4CLASS,
960 "DM8168VPSSM3PROC_attach", status,
961 "AddrTable_SIZE reached!");
962 }
963 }
964 else if (entry->map == TRUE) {
965 /* send these entries back to ProcMgr for mapping */
966 index = object->params.numMemEntries;
968 if (index != ProcMgr_MAX_MEMORY_REGIONS) {
969 me = &object->params.memEntries[index];
971 me->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
972 me->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
973 me->addr[ProcMgr_AddrType_MasterPhys] =
974 entry->masterPhysAddr;
975 me->addr[ProcMgr_AddrType_SlaveVirt] = entry->slaveVirtAddr;
976 me->addr[ProcMgr_AddrType_SlavePhys] = -1u;
977 me->size = entry->size;
978 me->isCached = entry->isCached;
979 me->mapMask = entry->mapMask;
981 object->params.numMemEntries++;
982 }
983 else {
984 status = PROCESSOR_E_FAIL;
985 GT_setFailureReason(curTrace, GT_4CLASS,
986 "DM8168VPSSM3PROC_attach", status,
987 "ProcMgr_MAX_MEMORY_REGIONS reached!");
988 }
989 }
990 else {
991 status = PROCESSOR_E_INVALIDARG;
992 GT_setFailureReason(curTrace, GT_4CLASS,
993 "DM8168VPSSM3PROC_attach", status,
994 "Memory map has entry with invalid 'map' value");
995 }
996 } /* for (...) */
998 if (status >= 0) {
999 /* populate the return params */
1000 params->numMemEntries = object->params.numMemEntries;
1001 memcpy((Ptr)params->memEntries, (Ptr)object->params.memEntries,
1002 sizeof(ProcMgr_AddrInfo) * params->numMemEntries);
1004 status = DM8168VPSSM3_halInit(&(object->halObject), NULL);
1006 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)
1007 if (status < 0) {
1008 GT_setFailureReason(curTrace, GT_4CLASS,
1009 "DM8168VPSSM3PROC_attach", status,
1010 "DM8168VPSSM3_halInit failed");
1011 }
1012 else {
1013 #endif
1014 if ((procHandle->bootMode == ProcMgr_BootMode_Boot)
1015 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1017 /* place the slave processor in reset */
1018 status = DM8168VPSSM3_halResetCtrl(object->halObject,
1019 Processor_ResetCtrlCmd_Reset, NULL);
1021 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1022 if (status < 0) {
1023 GT_setFailureReason(curTrace, GT_4CLASS,
1024 "DM8168VPSSM3PROC_attach", status,
1025 "Failed to reset the slave processor");
1026 }
1027 else {
1028 #endif
1029 GT_0trace(curTrace, GT_1CLASS,
1030 "DM8168VPSSM3PROC_attach: slave is now in reset");
1032 if (object->params.mmuEnable) {
1033 mmuEnableArgs.numMemEntries = 0;
1034 status = DM8168VPSSM3_halMmuCtrl(object->halObject,
1035 Processor_MmuCtrlCmd_Enable, &mmuEnableArgs);
1036 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1037 if (status < 0) {
1038 GT_setFailureReason(curTrace, GT_4CLASS,
1039 "DM8168VPSSM3PROC_attach", status,
1040 "Failed to enable the slave MMU");
1041 }
1042 #endif
1043 GT_0trace(curTrace, GT_2CLASS,
1044 "DM8168VPSSM3PROC_attach: Slave MMU "
1045 "is configured!");
1046 }
1047 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1048 }
1049 #endif
1050 }
1051 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1052 }
1053 #endif
1054 }
1055 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1056 }
1057 #endif
1059 GT_1trace(curTrace, GT_LEAVE,
1060 "DM8168VPSSM3PROC_attach: status=0x%x", status);
1062 /*! @retval PROCESSOR_SUCCESS Operation successful */
1063 return status;
1064 }
1067 /*!
1068 * @brief Function to detach from the Processor.
1069 *
1070 * @param handle Handle to the Processor instance
1071 *
1072 * @sa DM8168VPSSM3PROC_attach
1073 */
1074 Int
1075 DM8168VPSSM3PROC_detach (Processor_Handle handle)
1076 {
1077 Int status = PROCESSOR_SUCCESS;
1078 Int tmpStatus = PROCESSOR_SUCCESS;
1079 Processor_Object * procHandle = (Processor_Object *) handle;
1080 DM8168VPSSM3PROC_Object * object = NULL;
1081 Int i = 0;
1082 ProcMgr_AddrInfo * ai;
1084 GT_1trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_detach", handle);
1085 GT_assert (curTrace, (handle != NULL));
1087 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1088 if (handle == NULL) {
1089 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1090 status = PROCESSOR_E_HANDLE;
1091 GT_setFailureReason (curTrace,
1092 GT_4CLASS,
1093 "DM8168VPSSM3PROC_detach",
1094 PROCESSOR_E_HANDLE,
1095 "Invalid handle specified");
1096 }
1097 else {
1098 #endif
1099 object = (DM8168VPSSM3PROC_Object *) procHandle->object;
1100 GT_assert (curTrace, (object != NULL));
1102 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1103 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)) {
1105 if (object->params.mmuEnable) {
1106 GT_0trace(curTrace, GT_2CLASS,
1107 "DM8168VPSSM3PROC_detach: Disabling Slave MMU ...");
1109 status = DM8168VPSSM3_halMmuCtrl(object->halObject,
1110 Processor_MmuCtrlCmd_Disable, NULL);
1111 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1112 if (status < 0) {
1113 GT_setFailureReason(curTrace, GT_4CLASS,
1114 "DM8168VPSSM3PROC_detach", status,
1115 "Failed to disable the slave MMU");
1116 }
1117 #endif
1118 }
1120 /* delete all dynamically added entries */
1121 for (i = AddrTable_STATIC_COUNT; i < AddrTable_count; i++) {
1122 ai = &AddrTable[i];
1123 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1124 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1125 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1126 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1127 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1128 ai->size = 0u;
1129 ai->isCached = FALSE;
1130 ai->mapMask = 0u;
1131 ai->isMapped = FALSE;
1132 ai->refCount = 0u;
1133 }
1134 object->params.numMemEntries = AddrTable_STATIC_COUNT;
1135 AddrTable_count = AddrTable_STATIC_COUNT;
1137 /* place the slave processor into reset */
1138 tmpStatus = DM8168VPSSM3_halResetCtrl(object->halObject,
1139 Processor_ResetCtrlCmd_Reset, NULL);
1141 GT_0trace(curTrace, GT_2CLASS,
1142 "DM8168VPSSM3PROC_detach: Slave processor is now in reset");
1144 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1145 if ((tmpStatus < 0) && (status >= 0)) {
1146 status = tmpStatus;
1147 GT_setFailureReason (curTrace,
1148 GT_4CLASS,
1149 "DM8168VPSSM3PROC_detach",
1150 status,
1151 "Failed to reset the slave processor");
1152 }
1153 #endif
1154 }
1156 GT_0trace (curTrace,
1157 GT_2CLASS,
1158 " DM8168VPSSM3PROC_detach: Unmapping memory regions\n");
1160 tmpStatus = DM8168VPSSM3_halExit (object->halObject);
1161 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1162 if ((tmpStatus < 0) && (status >= 0)) {
1163 status = tmpStatus;
1164 GT_setFailureReason (curTrace,
1165 GT_4CLASS,
1166 "DM8168VPSSM3PROC_detach",
1167 status,
1168 "Failed to finalize HAL object");
1169 }
1170 }
1171 #endif
1173 GT_1trace(curTrace, GT_LEAVE,
1174 "DM8168VPSSM3PROC_detach: status=0x%x", status);
1176 /*! @retval PROCESSOR_SUCCESS Operation successful */
1177 return status;
1178 }
1181 /*!
1182 * @brief Function to start the slave processor
1183 *
1184 * Start the slave processor running from its entry point.
1185 * Depending on the boot mode, this involves configuring the boot
1186 * address and releasing the slave from reset.
1187 *
1188 * @param handle Handle to the Processor instance
1189 *
1190 * @sa DM8168VPSSM3PROC_stop, DM8168VPSSM3_halBootCtrl, DM8168VPSSM3_halResetCtrl
1191 */
1192 Int
1193 DM8168VPSSM3PROC_start (Processor_Handle handle,
1194 UInt32 entryPt,
1195 Processor_StartParams * params)
1196 {
1197 Int status = PROCESSOR_SUCCESS ;
1198 Processor_Object * procHandle = (Processor_Object *) handle;
1199 DM8168VPSSM3PROC_Object * object = NULL;
1202 GT_3trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_start",
1203 handle, entryPt, params);
1205 GT_assert (curTrace, (handle != NULL));
1206 GT_assert (curTrace, (params != NULL));
1208 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1209 if (handle == NULL) {
1210 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1211 status = PROCESSOR_E_HANDLE;
1212 GT_setFailureReason (curTrace,
1213 GT_4CLASS,
1214 "DM8168VPSSM3PROC_start",
1215 status,
1216 "Invalid handle specified");
1217 }
1218 else if (params == NULL) {
1219 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1220 status = PROCESSOR_E_INVALIDARG;
1221 GT_setFailureReason (curTrace,
1222 GT_4CLASS,
1223 "DM8168VPSSM3PROC_start",
1224 status,
1225 "Invalid params specified");
1226 }
1227 else {
1228 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1229 object = (DM8168VPSSM3PROC_Object *) procHandle->object;
1230 GT_assert (curTrace, (object != NULL));
1231 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1232 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1233 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1234 GT_1trace (curTrace,
1235 GT_2CLASS,
1236 " DM8168VPSSM3PROC_start: Configuring boot register\n"
1237 " Reset vector [0x%x]!\n",
1238 entryPt);
1239 /* Specify the VPSSM3 boot address in the boot config register */
1240 status = DM8168VPSSM3_halBootCtrl (
1241 object->halObject,
1242 Processor_BootCtrlCmd_SetEntryPoint,
1243 (Ptr) entryPt);
1244 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1245 if (status < 0) {
1246 GT_setFailureReason (curTrace,
1247 GT_4CLASS,
1248 "DM8168VPSSM3PROC_start",
1249 status,
1250 "Failed to set slave boot entry point");
1251 }
1252 else {
1253 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1254 /* Write the branch instruction to at the boot address to
1255 * branch to _c_int00
1256 */
1259 /* Release the slave from reset */
1260 status = DM8168VPSSM3_halResetCtrl (object->halObject,
1261 Processor_ResetCtrlCmd_Release,
1262 NULL);
1263 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1264 if (status < 0) {
1265 GT_setFailureReason (curTrace,
1266 GT_4CLASS,
1267 "DM8168VPSSM3PROC_start",
1268 status,
1269 "Failed to release slave from reset");
1270 }
1271 }
1272 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1273 }
1275 /* For NoBoot mode, send an interrupt to the slave.
1276 * TBD: How should Dm8168M3VideoProc interface with Notify for this?
1277 */
1278 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1279 }
1280 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1282 if (status >= 0) {
1283 GT_0trace (curTrace,
1284 GT_1CLASS,
1285 " DM8168VPSSM3PROC_start: Slave successfully started!\n");
1286 }
1287 else {
1288 GT_0trace (curTrace,
1289 GT_1CLASS,
1290 " DM8168VPSSM3PROC_start: Slave could not be started!\n");
1291 }
1293 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_start", status);
1295 /*! @retval PROCESSOR_SUCCESS Operation successful */
1296 return status;
1297 }
1300 /*!
1301 * @brief Function to stop the slave processor
1302 *
1303 * Stop the execution of the slave processor. Depending on the boot
1304 * mode, this may result in placing the slave processor in reset.
1305 *
1306 * @param handle Handle to the Processor instance
1307 *
1308 * @sa DM8168VPSSM3PROC_start, DM8168VPSSM3_halResetCtrl
1309 */
1310 Int
1311 DM8168VPSSM3PROC_stop (Processor_Handle handle)
1312 {
1313 Int status = PROCESSOR_SUCCESS ;
1314 Processor_Object * procHandle = (Processor_Object *) handle;
1315 DM8168VPSSM3PROC_Object * object = NULL;
1317 GT_1trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_stop", handle);
1319 GT_assert (curTrace, (handle != NULL));
1321 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1322 if (handle == NULL) {
1323 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1324 status = PROCESSOR_E_HANDLE;
1325 GT_setFailureReason (curTrace,
1326 GT_4CLASS,
1327 "DM8168VPSSM3PROC_stop",
1328 status,
1329 "Invalid handle specified");
1330 }
1331 else {
1332 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1333 object = (DM8168VPSSM3PROC_Object *) procHandle->object;
1334 GT_assert (curTrace, (object != NULL));
1335 if ( (procHandle->bootMode == ProcMgr_BootMode_Boot)
1336 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_Pwr)
1337 || (procHandle->bootMode == ProcMgr_BootMode_NoLoad_NoPwr)) {
1338 /* Slave is to be stopped only for Boot mode and NoLoad mode. */
1339 /* Place the slave processor in reset. */
1340 status = DM8168VPSSM3_halResetCtrl (object->halObject,
1341 Processor_ResetCtrlCmd_Reset,
1342 NULL);
1343 GT_0trace (curTrace,
1344 GT_1CLASS,
1345 " DM8168VPSSM3PROC_stop: Slave is now in reset!\n");
1346 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1347 if (status < 0) {
1348 GT_setFailureReason (curTrace,
1349 GT_4CLASS,
1350 "DM8168VPSSM3PROC_stop",
1351 status,
1352 "Failed to place slave in reset");
1353 }
1354 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1355 }
1356 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1357 }
1358 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1359 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_stop", status);
1361 /*! @retval PROCESSOR_SUCCESS Operation successful */
1362 return status;
1363 }
1366 /*!
1367 * @brief Function to read from the slave processor's memory.
1368 *
1369 * Read from the slave processor's memory and copy into the
1370 * provided buffer.
1371 *
1372 * @param handle Handle to the Processor instance
1373 * @param procAddr Address in host processor's address space of the
1374 * memory region to read from.
1375 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1376 * number of bytes to be read. When the function
1377 * returns, this parameter contains the number of bytes
1378 * actually read.
1379 * @param buffer User-provided buffer in which the slave processor's
1380 * memory contents are to be copied.
1381 *
1382 * @sa DM8168VPSSM3PROC_write
1383 */
1384 Int
1385 DM8168VPSSM3PROC_read (Processor_Handle handle,
1386 UInt32 procAddr,
1387 UInt32 * numBytes,
1388 Ptr buffer)
1389 {
1390 Int status = PROCESSOR_SUCCESS ;
1391 UInt8 * procPtr8 = NULL;
1393 GT_4trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_read",
1394 handle, procAddr, numBytes, buffer);
1396 GT_assert (curTrace, (handle != NULL));
1397 GT_assert (curTrace, (numBytes != NULL));
1398 GT_assert (curTrace, (buffer != NULL));
1400 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1401 if (handle == NULL) {
1402 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1403 status = PROCESSOR_E_HANDLE;
1404 GT_setFailureReason (curTrace,
1405 GT_4CLASS,
1406 "DM8168VPSSM3PROC_read",
1407 status,
1408 "Invalid handle specified");
1409 }
1410 else if (numBytes == 0) {
1411 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1412 status = PROCESSOR_E_INVALIDARG;
1413 GT_setFailureReason (curTrace,
1414 GT_4CLASS,
1415 "DM8168VPSSM3PROC_read",
1416 status,
1417 "Invalid numBytes specified");
1418 }
1419 else if (buffer == NULL) {
1420 /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
1421 status = PROCESSOR_E_INVALIDARG;
1422 GT_setFailureReason (curTrace,
1423 GT_4CLASS,
1424 "DM8168VPSSM3PROC_read",
1425 status,
1426 "Invalid buffer specified");
1427 }
1428 else {
1429 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1430 procPtr8 = (UInt8 *) procAddr ;
1431 buffer = memcpy (buffer, procPtr8, *numBytes);
1432 GT_assert (curTrace, (buffer != (UInt32) NULL));
1433 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1434 if (buffer == (UInt32) NULL) {
1435 /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1436 status = PROCESSOR_E_FAIL;
1437 GT_setFailureReason (curTrace,
1438 GT_4CLASS,
1439 "DM8168VPSSM3PROC_read",
1440 status,
1441 "Failed in memcpy");
1442 *numBytes = 0;
1443 }
1444 }
1445 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1447 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_read",status);
1449 /*! @retval PROCESSOR_SUCCESS Operation successful */
1450 return status;
1451 }
1454 /*!
1455 * @brief Function to write into the slave processor's memory.
1456 *
1457 * Read from the provided buffer and copy into the slave
1458 * processor's memory.
1459 *
1460 * @param handle Handle to the Processor object
1461 * @param procAddr Address in host processor's address space of the
1462 * memory region to write into.
1463 * @param numBytes IN/OUT parameter. As an IN-parameter, it takes in the
1464 * number of bytes to be written. When the function
1465 * returns, this parameter contains the number of bytes
1466 * actually written.
1467 * @param buffer User-provided buffer from which the data is to be
1468 * written into the slave processor's memory.
1469 *
1470 * @sa DM8168VPSSM3PROC_read, DM8168VPSSM3PROC_translateAddr
1471 */
1472 Int
1473 DM8168VPSSM3PROC_write (Processor_Handle handle,
1474 UInt32 procAddr,
1475 UInt32 * numBytes,
1476 Ptr buffer)
1477 {
1478 Int status = PROCESSOR_SUCCESS ;
1479 UInt8 * procPtr8 = NULL;
1480 UInt8 temp8_1;
1481 UInt8 temp8_2;
1482 UInt8 temp8_3;
1483 UInt8 temp8_4;
1484 UInt32 temp;
1486 GT_4trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_write",
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 "DM8168VPSSM3PROC_write",
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 "DM8168VPSSM3PROC_write",
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 "DM8168VPSSM3PROC_write",
1518 status,
1519 "Invalid buffer specified");
1520 }
1521 else {
1522 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1523 if (*numBytes != sizeof (UInt32)) {
1524 procPtr8 = (UInt8 *) procAddr ;
1525 procAddr = (UInt32) memcpy (procPtr8,
1526 buffer,
1527 *numBytes);
1528 GT_assert (curTrace, (procAddr != (UInt32) NULL));
1529 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1530 if (procAddr == (UInt32) NULL) {
1531 /*! @retval PROCESSOR_E_FAIL Failed in memcpy */
1532 status = PROCESSOR_E_FAIL;
1533 GT_setFailureReason (curTrace,
1534 GT_4CLASS,
1535 "DM8168VPSSM3PROC_write",
1536 status,
1537 "Failed in memcpy");
1538 *numBytes = 0;
1539 }
1540 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1541 }
1542 else {
1543 /* For 4 bytes, directly write as a UInt32 */
1544 temp8_1 = ((UInt8 *) buffer) [0];
1545 temp8_2 = ((UInt8 *) buffer) [1];
1546 temp8_3 = ((UInt8 *) buffer) [2];
1547 temp8_4 = ((UInt8 *) buffer) [3];
1548 temp = (UInt32) ( ((UInt32) temp8_4 << 24)
1549 | ((UInt32) temp8_3 << 16)
1550 | ((UInt32) temp8_2 << 8)
1551 | ((UInt32) temp8_1));
1552 *((UInt32*) procAddr) = temp;
1553 }
1554 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1555 }
1556 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1558 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC_write", status);
1560 /*! @retval PROCESSOR_SUCCESS Operation successful */
1561 return status;
1562 }
1565 /*!
1566 * @brief Function to perform device-dependent operations.
1567 *
1568 * Performs device-dependent control operations as exposed by this
1569 * implementation of the Processor module.
1570 *
1571 * @param handle Handle to the Processor object
1572 * @param cmd Device specific processor command
1573 * @param arg Arguments specific to the type of command.
1574 *
1575 * @sa
1576 */
1577 Int
1578 DM8168VPSSM3PROC_control (Processor_Handle handle, Int32 cmd, Ptr arg)
1579 {
1580 Int status = PROCESSOR_SUCCESS ;
1582 GT_3trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_control", handle, cmd, arg);
1584 GT_assert (curTrace, (handle != NULL));
1585 /* cmd and arg can be 0/NULL, so cannot check for validity. */
1587 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1588 if (handle == NULL) {
1589 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1590 status = PROCESSOR_E_HANDLE;
1591 GT_setFailureReason (curTrace,
1592 GT_4CLASS,
1593 "DM8168VPSSM3PROC_control",
1594 status,
1595 "Invalid handle specified");
1596 }
1597 else {
1598 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1599 /* No control operations currently implemented. */
1600 /*! @retval PROCESSOR_E_NOTSUPPORTED No control operations are supported
1601 for this device. */
1602 status = PROCESSOR_E_NOTSUPPORTED;
1603 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1604 }
1605 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1606 GT_1trace (curTrace, GT_LEAVE, "DM8168VPSSM3PROC ",status);
1608 /*! @retval PROCESSOR_SUCCESS Operation successful */
1609 return status;
1610 }
1613 /*!
1614 * @brief Translate slave virtual address to master physical address.
1615 *
1616 * @param handle Handle to the Processor object
1617 * @param dstAddr Returned: master physical address.
1618 * @param srcAddr Slave virtual address.
1619 *
1620 * @sa
1621 */
1622 Int
1623 DM8168VPSSM3PROC_translate(
1624 Processor_Handle handle,
1625 UInt32 * dstAddr,
1626 UInt32 srcAddr)
1627 {
1628 Int status = PROCESSOR_SUCCESS;
1629 Processor_Object * procHandle= (Processor_Object *)handle;
1630 DM8168VPSSM3PROC_Object * object = NULL;
1631 UInt32 i;
1632 UInt32 startAddr;
1633 UInt32 endAddr;
1634 UInt32 offset;
1635 ProcMgr_AddrInfo * ai;
1637 GT_3trace(curTrace, GT_ENTER,
1638 "DM8168VPSSM3PROC_translate: handle=0x%x, dstAddr=0x%x, srcAddr=0x%x",
1639 handle, dstAddr, srcAddr);
1641 GT_assert (curTrace, (handle != NULL));
1642 GT_assert (curTrace, (dstAddr != NULL));
1644 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1645 if (handle == NULL) {
1646 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1647 status = PROCESSOR_E_HANDLE;
1648 GT_setFailureReason (curTrace,
1649 GT_4CLASS,
1650 "DM8168VPSSM3PROC_translate",
1651 status,
1652 "Invalid handle specified");
1653 }
1654 else if (dstAddr == NULL) {
1655 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1656 status = PROCESSOR_E_INVALIDARG;
1657 GT_setFailureReason (curTrace,
1658 GT_4CLASS,
1659 "DM8168VPSSM3PROC_translate",
1660 status,
1661 "dstAddr provided as NULL");
1662 }
1663 else {
1664 #endif
1665 object = (DM8168VPSSM3PROC_Object *)procHandle->object;
1666 GT_assert(curTrace, (object != NULL));
1667 *dstAddr = -1u;
1669 /* search all entries AddrTable */
1670 for (i = 0; i < AddrTable_count; i++) {
1671 ai = &AddrTable[i];
1672 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1673 endAddr = startAddr + ai->size;
1675 if ((startAddr <= srcAddr) && (srcAddr < endAddr)) {
1676 offset = srcAddr - startAddr;
1677 *dstAddr = ai->addr[ProcMgr_AddrType_MasterPhys] + offset;
1678 GT_3trace(curTrace, GT_1CLASS, "DM8168VPSSM3PROC_translate: "
1679 "translated [%d] srcAddr=0x%x --> dstAddr=0x%x",
1680 i, srcAddr, *dstAddr);
1681 break;
1682 }
1683 }
1685 if (*dstAddr == -1u) {
1686 if (!object->params.mmuEnable) {
1687 /* default to direct mapping (i.e. v=p) */
1688 *dstAddr = srcAddr;
1689 GT_2trace(curTrace, GT_1CLASS, "DM8168VPSSM3PROC_translate: "
1690 "(default) srcAddr=0x%x --> dstAddr=0x%x",
1691 srcAddr, *dstAddr);
1692 }
1693 else {
1694 /* srcAddr not found in slave address space */
1695 status = PROCESSOR_E_INVALIDARG;
1696 GT_setFailureReason(curTrace, GT_4CLASS,
1697 "DM8168VPSSM3PROC_translate", status,
1698 "srcAddr not found in slave address space");
1699 }
1700 }
1701 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1702 }
1703 #endif
1704 GT_1trace(curTrace, GT_LEAVE,
1705 "DM8168VPSSM3PROC_translate: status=0x%x", status);
1707 /*! @retval PROCESSOR_SUCCESS Operation successful */
1708 return status;
1709 }
1712 /*!
1713 * @brief Map the given address translation into the slave mmu
1714 *
1715 * @param handle Handle to the Processor object
1716 * @param dstAddr Base virtual address
1717 * @param nSegs Number of given segments
1718 * @param sglist Segment list
1719 */
1720 Int
1721 DM8168VPSSM3PROC_map(
1722 Processor_Handle handle,
1723 UInt32 * dstAddr,
1724 UInt32 nSegs,
1725 Memory_SGList * sglist)
1726 {
1727 Int status = PROCESSOR_SUCCESS ;
1728 Processor_Object * procHandle = (Processor_Object *)handle;
1729 DM8168VPSSM3PROC_Object * object = NULL;
1730 Bool found = FALSE;
1731 UInt32 startAddr;
1732 UInt32 endAddr;
1733 UInt32 i;
1734 UInt32 j;
1735 ProcMgr_AddrInfo * ai;
1736 DM8168VPSSM3_HalMmuCtrlArgs_AddEntry addEntryArgs;
1738 GT_4trace(curTrace, GT_ENTER, "DM8168VPSSM3PROC_map:",
1739 handle, *dstAddr, nSegs, sglist);
1741 GT_assert (curTrace, (handle != NULL));
1742 GT_assert (curTrace, (sglist != NULL));
1743 GT_assert (curTrace, (nSegs > 0));
1745 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1746 if (handle == NULL) {
1747 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1748 status = PROCESSOR_E_HANDLE;
1749 GT_setFailureReason (curTrace,
1750 GT_4CLASS,
1751 "DM8168VPSSM3PROC_map",
1752 status,
1753 "Invalid handle specified");
1754 }
1755 else if (sglist == NULL) {
1756 /*! @retval PROCESSOR_E_INVALIDARG sglist provided as NULL */
1757 status = PROCESSOR_E_INVALIDARG;
1758 GT_setFailureReason (curTrace,
1759 GT_4CLASS,
1760 "DM8168VPSSM3PROC_map",
1761 status,
1762 "sglist provided as NULL");
1763 }
1764 else if (nSegs == 0) {
1765 /*! @retval PROCESSOR_E_INVALIDARG Number of segments provided is 0 */
1766 status = PROCESSOR_E_INVALIDARG;
1767 GT_setFailureReason (curTrace,
1768 GT_4CLASS,
1769 "DM8168VPSSM3PROC_map",
1770 status,
1771 "Number of segments provided is 0");
1772 }
1773 else {
1774 #endif
1775 object = (DM8168VPSSM3PROC_Object *)procHandle->object;
1776 GT_assert (curTrace, (object != NULL));
1778 for (i = 0; (i < nSegs) && (status >= 0); i++) {
1779 /* Update the translation table with entries for which mapping
1780 * is required. Add the entry only if the range does not exist
1781 * in the translation table.
1782 */
1784 /* check in static entries first */
1785 for (j = 0; j < AddrTable_STATIC_COUNT; j++) {
1786 ai = &AddrTable[j];
1787 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1788 endAddr = startAddr + ai->size;
1790 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)) {
1791 found = TRUE;
1792 ai->refCount++;
1793 GT_4trace(curTrace, GT_1CLASS, "DM8168VPSSM3PROC_map: "
1794 "found static entry: [%d] sva=0x%x, mpa=0x%x size=0x%x",
1795 j, ai->addr[ProcMgr_AddrType_SlaveVirt],
1796 ai->addr[ProcMgr_AddrType_MasterPhys], ai->size);
1797 break;
1798 }
1799 }
1801 /* if not found in static entries, check in dynamic entries */
1802 if (!found) {
1803 for (j = AddrTable_STATIC_COUNT; j < AddrTable_count; j++) {
1804 ai = &AddrTable[j];
1806 if (ai->isMapped == TRUE) {
1807 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1808 endAddr = startAddr + ai->size;
1810 if ((startAddr <= *dstAddr) && (*dstAddr < endAddr)
1811 && ((*dstAddr + sglist[i].size) <= endAddr)) {
1812 found = TRUE;
1813 ai->refCount++;
1814 GT_4trace(curTrace, GT_1CLASS,
1815 "DM8168VPSSM3PROC_map: found dynamic entry: "
1816 "[%d] sva=0x%x, mpa=0x%x, size=0x%x",
1817 j, ai->addr[ProcMgr_AddrType_SlaveVirt],
1818 ai->addr[ProcMgr_AddrType_MasterPhys],ai->size);
1819 break;
1820 }
1821 }
1822 }
1823 }
1825 /* If not found, add new entry to table. If mmu is disabled,
1826 * the assumption is that the ammu will be used.
1827 */
1828 if (!found) {
1829 if (AddrTable_count != AddrTable_SIZE) {
1830 ai = &AddrTable[AddrTable_count];
1832 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1833 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1834 ai->addr[ProcMgr_AddrType_MasterPhys] = sglist[i].paddr;
1835 ai->addr[ProcMgr_AddrType_SlaveVirt] = *dstAddr;
1836 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1837 ai->size = sglist[i].size;
1838 ai->isCached = sglist[i].isCached;
1839 ai->refCount++;
1841 AddrTable_count++;
1843 GT_4trace(curTrace, GT_1CLASS,
1844 "DM8168VPSSM3PROC_map: adding dynamic entry: "
1845 "[%d] sva=0x%x, mpa=0x%x, size=0x%x",
1846 (AddrTable_count - 1), *dstAddr, sglist[i].paddr,
1847 sglist[i].size);
1848 }
1849 else {
1850 status = PROCESSOR_E_FAIL;
1851 ai = NULL;
1852 GT_setFailureReason(curTrace, GT_4CLASS,
1853 "DM8168VPSSM3PROC_map", status,
1854 "AddrTable_SIZE reached!");
1855 }
1856 }
1858 /* if new entry, map into dsp mmu */
1859 if ((ai != NULL) && (ai->refCount == 1) && (status >= 0)) {
1860 ai->isMapped = TRUE;
1862 if (object->params.mmuEnable) {
1863 GT_3trace(curTrace, GT_1CLASS,
1864 "DM8168VPSSM3PROC_map: adding entry to L2MMU: "
1865 "sva=0x%x, spa=0x%x, size=0x%x",
1866 *dstAddr, sglist[i].paddr, sglist[i].size);
1868 /* add entry to L2 MMU */
1869 addEntryArgs.masterPhyAddr = sglist [i].paddr;
1870 addEntryArgs.size = sglist [i].size;
1871 addEntryArgs.slaveVirtAddr = (UInt32)*dstAddr;
1872 /* TBD: elementSize, endianism, mixedSized are
1873 * hard coded now, must be configurable later
1874 */
1875 addEntryArgs.elementSize = ELEM_SIZE_16BIT;
1876 addEntryArgs.endianism = LITTLE_ENDIAN;
1877 addEntryArgs.mixedSize = MMU_TLBES;
1879 status = DM8168VPSSM3_halMmuCtrl(object->halObject,
1880 Processor_MmuCtrlCmd_AddEntry, &addEntryArgs);
1882 GT_3trace(curTrace, GT_1CLASS,
1883 "DM8168VIDEOM3PROC_map: mmu add entry, "
1884 "masterPhyAddr=0x%x, slaveVirAddr=0x%x, size=0x%x",
1885 addEntryArgs.masterPhyAddr, addEntryArgs.slaveVirtAddr,
1886 addEntryArgs.size);
1888 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1889 if (status < 0) {
1890 GT_setFailureReason(curTrace, GT_4CLASS,
1891 "DM8168VPSSM3PROC_map", status,
1892 "Processor_MmuCtrlCmd_AddEntry failed");
1893 }
1894 #endif
1895 }
1896 }
1897 #if !defined(SYSLINK_BUILD_OPTIMIZE)
1898 if (status < 0) {
1899 GT_setFailureReason(curTrace, GT_4CLASS,
1900 "DM8168VPSSM3PROC_map", status,
1901 "VPSSM3 MMU configuration failed");
1902 }
1903 #endif
1904 }
1905 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1906 }
1907 #endif
1908 GT_1trace(curTrace, GT_LEAVE, "DM8168VPSSM3PROC_map:", status);
1910 /*! @retval PROCESSOR_SUCCESS Operation successful */
1911 return status;
1912 }
1915 /*!
1916 * @brief Function to unmap slave address from host address space
1917 *
1918 * @param handle Handle to the Processor object
1919 * @param dstAddr Return parameter: Pointer to receive the mapped
1920 * address.
1921 * @param size Size of the region to be mapped.
1922 *
1923 * @sa
1924 */
1925 Int
1926 DM8168VPSSM3PROC_unmap(
1927 Processor_Handle handle,
1928 UInt32 addr,
1929 UInt32 size)
1930 {
1931 Int status = PROCESSOR_SUCCESS ;
1932 Processor_Object * procHandle = (Processor_Object *)handle;
1933 DM8168VPSSM3PROC_Object * object = NULL;
1934 ProcMgr_AddrInfo * ai;
1935 Int i;
1936 UInt32 startAddr;
1937 UInt32 endAddr;
1938 DM8168VPSSM3_HalMmuCtrlArgs_DeleteEntry deleteEntryArgs;
1940 GT_3trace (curTrace, GT_ENTER, "DM8168VPSSM3PROC_unmap",
1941 handle, addr, size);
1943 GT_assert (curTrace, (handle != NULL));
1944 GT_assert (curTrace, (size != 0));
1946 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1947 if (handle == NULL) {
1948 /*! @retval PROCESSOR_E_HANDLE Invalid argument */
1949 status = PROCESSOR_E_HANDLE;
1950 GT_setFailureReason (curTrace,
1951 GT_4CLASS,
1952 "DM8168VPSSM3PROC_unmap",
1953 status,
1954 "Invalid handle specified");
1955 }
1956 else if (size == 0) {
1957 /*! @retval PROCESSOR_E_INVALIDARG Size provided is zero */
1958 status = PROCESSOR_E_INVALIDARG;
1959 GT_setFailureReason (curTrace,
1960 GT_4CLASS,
1961 "DM8168VPSSM3PROC_unmap",
1962 status,
1963 "Size provided is zero");
1964 }
1965 else {
1966 #endif
1967 object = (DM8168VPSSM3PROC_Object *) procHandle->object;
1968 GT_assert (curTrace, (object != NULL));
1970 /* Delete dynamically added non-default entries from translation
1971 * table only in last unmap called on that entry
1972 */
1973 for (i = AddrTable_STATIC_COUNT; i < AddrTable_count; i++) {
1974 ai = &AddrTable[i];
1976 if (!ai->isMapped) {
1977 continue;
1978 }
1980 startAddr = ai->addr[ProcMgr_AddrType_SlaveVirt];
1981 endAddr = startAddr + ai->size;
1983 if ((startAddr <= addr) && (addr < endAddr)) {
1984 ai->refCount--;
1986 if (ai->refCount == 0) {
1987 ai->addr[ProcMgr_AddrType_MasterKnlVirt] = -1u;
1988 ai->addr[ProcMgr_AddrType_MasterUsrVirt] = -1u;
1989 ai->addr[ProcMgr_AddrType_MasterPhys] = -1u;
1990 ai->addr[ProcMgr_AddrType_SlaveVirt] = -1u;
1991 ai->addr[ProcMgr_AddrType_SlavePhys] = -1u;
1992 ai->size = 0u;
1993 ai->isCached = FALSE;
1994 ai->mapMask = 0u;
1995 ai->isMapped = FALSE;
1997 if (object->params.mmuEnable) {
1998 /* Remove the entry from the VPSSM3 MMU also */
1999 deleteEntryArgs.size = size;
2000 deleteEntryArgs.slaveVirtAddr = addr;
2001 /* TBD: elementSize, endianism, mixedSized are
2002 * hard coded now, must be configurable later
2003 */
2004 deleteEntryArgs.elementSize = ELEM_SIZE_16BIT;
2005 deleteEntryArgs.endianism = LITTLE_ENDIAN;
2006 deleteEntryArgs.mixedSize = MMU_TLBES;
2008 status = DM8168VPSSM3_halMmuCtrl(object->halObject,
2009 Processor_MmuCtrlCmd_DeleteEntry, &deleteEntryArgs);
2010 #if !defined(SYSLINK_BUILD_OPTIMIZE)
2011 if (status < 0) {
2012 GT_setFailureReason(curTrace, GT_4CLASS,
2013 "DM8168VPSSM3PROC_unmap", status,
2014 "VPSSM3 MMU configuration failed");
2015 }
2016 #endif
2017 }
2018 }
2019 }
2020 }
2021 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
2022 }
2023 #endif
2024 GT_1trace(curTrace, GT_LEAVE,
2025 "DM8168VPSSM3PROC_unmap: status=0x%x", status);
2027 /*! @retval PROCESSOR_SUCCESS Operation successful */
2028 return status;
2029 }
2032 #if defined (__cplusplus)
2033 }
2034 #endif /* defined (__cplusplus) */