0e1fe065ea165dacbbf76ae7d4fdd86b4c0468ef
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / ti81xx / ti81xxducati / Dm8168DucatiPwr.c
1 /*
2 * @file Dm8168DucatiPwr.c
3 *
4 * @brief PwrMgr implementation for DM8168DUCATI.
5 *
6 * This module is responsible for handling power requests for
7 * the ProcMgr. The implementation is common to DM8168VIDEOM3 and
8 * DM8168VPSSM3.
9 *
10 *
11 * ============================================================================
12 *
13 * Copyright (c) 2008-2012, Texas Instruments Incorporated
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 *
19 * * Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * * Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * * Neither the name of Texas Instruments Incorporated nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * Contact information for paper mail:
42 * Texas Instruments
43 * Post Office Box 655303
44 * Dallas, Texas 75265
45 * Contact information:
46 * http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
47 * DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
48 * ============================================================================
49 *
50 */
53 #if defined(SYSLINK_BUILD_HLOS)
54 #include <ti/syslink/Std.h>
56 /* OSAL & Utils headers */
57 #include <ti/syslink/utils/String.h>
58 #include <ti/syslink/utils/IGateProvider.h>
59 #include <ti/syslink/utils/GateMutex.h>
60 #include <ti/syslink/utils/Memory.h>
61 #include <ti/syslink/utils/Gate.h>
62 #if defined (SYSLINK_BUILDOS_LINUX)
63 #include <ti/syslink/inc/knl/Linux/LinuxClock.h>
64 #endif /* #if defined(SYSLINK_BUILDOS_LINUX) */
65 #endif /* #if defined(SYSLINK_BUILD_HLOS) */
68 #if defined(SYSLINK_BUILD_RTOS)
69 #include <xdc/std.h>
70 #include <xdc/runtime/Error.h>
71 #include <xdc/runtime/Memory.h>
72 #include <xdc/runtime/System.h>
73 #include <xdc/runtime/Gate.h>
74 #include <xdc/runtime/IGateProvider.h>
75 #include <ti/sysbios/gates/GateMutex.h>
76 #include <ti/syslink/utils/_Memory.h>
77 #include <ti/syslink/inc/Dm8168Clock.h>
78 #endif /* #if defined(SYSLINK_BUILD_RTOS) */
80 #if defined(SYSLINK_BUILDOS_LINUX)
81 #include <linux/string.h>
82 #else
83 #include <string.h>
84 #endif
86 #include <ti/syslink/utils/Trace.h>
88 /* Module level headers */
89 #include <ti/ipc/MultiProc.h>
90 #include <ti/syslink/inc/_MultiProc.h>
91 #include <ti/syslink/inc/knl/PwrDefs.h>
92 #include <ti/syslink/inc/knl/PwrMgr.h>
93 #include <ti/syslink/inc/knl/Dm8168DucatiPwr.h>
94 #include <ti/syslink/inc/knl/_Dm8168DucatiPwr.h>
95 #include <ti/syslink/inc/knl/Linux/Dm8168DucatiMmu.h>
97 #if defined (__cplusplus)
98 extern "C" {
99 #endif
102 /* =============================================================================
103 * Macros and types
104 * =============================================================================
105 */
106 /*!
107 * @brief DM8168VIDEOM3 module and mmr addresses (physical)
108 */
110 #define DM8168M3_PRCM_BASE_ADDR 0x48180000
111 #define DM8168M3_PRCM_SIZE 0x00002FFF
113 /* Ducati MMU base */
114 #define DUCATI_MMU_CFG 0x55080000
115 #define DUCATI_MMU_CFG_SIZE 0x00000FFF
118 #define DUCATI_BASE_ADDR 0x55020000
119 #define DUCATI_BASE_ADDR_SIZE 0x00000008
121 #define MAX_WAIT_COUNT 0x50000
123 #define REG(x) *((volatile UInt32 *) (x))
124 #define MEM(x) *((volatile UInt32 *) (x))
126 /* Macro to make a correct module magic number with refCount */
127 #define DM8168DUCATIPWR_MAKE_MAGICSTAMP(x) \
128 ((DM8168DUCATIPWR_MODULEID << 12u) | (x))
130 /*!
131 * @brief DM8168DUCATIPWR Module state object
132 */
133 typedef struct DM8168DUCATIPWR_ModuleObject_tag {
134 UInt32 refCount;
135 /* Module Reference count */
136 UInt32 pwrstateRefCount;
137 /* Reference count */
138 UInt32 configSize;
139 /*!< Size of configuration structure */
140 DM8168DUCATIPWR_Config cfg;
141 /*!< DM8168DUCATIPWR configuration structure */
142 DM8168DUCATIPWR_Config defCfg;
143 /*!< Default module configuration */
144 Bool isSetup;
145 /*!< Indicates whether the DM8168DUCATIPWR module is setup. */
146 DM8168DUCATIPWR_Handle pwrHandles [MultiProc_MAXPROCESSORS];
147 /*!< PwrMgr handle array. */
148 IGateProvider_Handle gateHandle;
149 /*!< Handle of gate to be used for local thread safety */
150 Ptr ducatiClkHandle;
151 /*!< clock handle used to call kernel APIs */
152 Ptr ducatiSpinlockHandle;
153 /*!< dsp Spinlock handle */
154 Ptr ducatiMailboxHandle;
155 /*!< dsp Mailbox handle */
156 } DM8168DUCATIPWR_ModuleObject;
158 /* =============================================================================
159 * Globals
160 * =============================================================================
161 */
162 /*!
163 * @var DM8168DUCATIPWR_state
164 *
165 * @brief DM8168DUCATIPWR state object variable
166 */
167 #if !defined(SYSLINK_BUILD_DEBUG)
168 static
169 #endif /* if !defined(SYSLINK_BUILD_DEBUG) */
170 DM8168DUCATIPWR_ModuleObject DM8168DUCATIPWR_state =
171 {
172 .isSetup = FALSE,
173 .configSize = sizeof (DM8168DUCATIPWR_Config),
174 .refCount = 0,
175 .pwrstateRefCount = 0,
176 .defCfg.reserved = 0,
177 .gateHandle = NULL,
178 };
180 /* =============================================================================
181 * APIs directly called by applications
182 * =============================================================================
183 */
184 /*!
185 * @brief Function to get the default configuration for the DM8168DUCATIPWR
186 * module.
187 *
188 * This function can be called by the application to get their
189 * configuration parameter to DM8168DUCATIPWR_setup filled in by the
190 * DM8168DUCATIPWR module with the default parameters. If the user does
191 * not wish to make any change in the default parameters, this API
192 * is not required to be called.
193 *
194 * @param cfg Pointer to the DM8168DUCATIPWR module configuration
195 * structure in which the default config is to be
196 * returned.
197 *
198 * @sa DM8168DUCATIPWR_setup
199 */
200 Void
201 DM8168DUCATIPWR_getConfig (DM8168DUCATIPWR_Config * cfg)
202 {
203 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_getConfig", cfg);
205 GT_assert (curTrace, (cfg != NULL));
207 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
208 if (cfg == NULL) {
209 GT_setFailureReason (curTrace,
210 GT_4CLASS,
211 "DM8168DUCATIPWR_getConfig",
212 PWRMGR_E_INVALIDARG,
213 "Argument of type (DM8168DUCATIPWR_Config *) passed "
214 "is null!");
215 }
216 else {
217 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
219 if (DM8168DUCATIPWR_state.refCount == 0) {
220 memcpy (cfg,
221 &DM8168DUCATIPWR_state.defCfg,
222 sizeof (DM8168DUCATIPWR_Config));
223 }
224 else {
225 memcpy (cfg,
226 &DM8168DUCATIPWR_state.cfg,
227 sizeof (DM8168DUCATIPWR_Config));
228 }
229 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
230 }
231 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
233 GT_0trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_getConfig");
234 }
236 /*!
237 * @brief Function to setup the DM8168DUCATIPWR module.
238 *
239 * This function sets up the DM8168DUCATIPWR module. This function must
240 * be called before any other instance-level APIs can be invoked.
241 * Module-level configuration needs to be provided to this
242 * function. If the user wishes to change some specific config
243 * parameters, then DM8168DUCATIPWR_getConfig can be called to get the
244 * configuration filled with the default values. After this, only
245 * the required configuration values can be changed. If the user
246 * does not wish to make any change in the default parameters, the
247 * application can simply call DM8168DUCATIPWR_setup with NULL
248 * parameters. The default parameters would get automatically used.
249 *
250 * @param cfg Optional DM8168DUCATIPWR module configuration. If provided as
251 * NULL, default configuration is used.
252 *
253 * @sa DM8168DUCATIPWR_destroy
254 * GateMutex_create
255 */
256 Int
257 DM8168DUCATIPWR_setup (DM8168DUCATIPWR_Config * cfg)
258 {
259 Int status = PWRMGR_SUCCESS;
260 DM8168DUCATIPWR_Config tmpCfg;
261 IArg key;
262 Error_Block eb;
264 #if defined(SYSLINK_BUILD_RTOS)
265 Error_init(&eb);
266 #endif /* #if defined(SYSLINK_BUILD_RTOS) */
267 #if defined(SYSLINK_BUILD_HLOS)
268 eb = 0;
269 #endif /* #if defined(SYSLINK_BUILD_HLOS) */
271 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_setup", cfg);
272 if (cfg == NULL) {
273 DM8168DUCATIPWR_getConfig (&tmpCfg);
274 cfg = &tmpCfg;
275 }
277 /* This sets the refCount variable is not initialized, upper 16 bits is
278 * written with module Id to ensure correctness of refCount variable.
279 */
280 key = Gate_enterSystem();
281 DM8168DUCATIPWR_state.refCount++;
282 if (DM8168DUCATIPWR_state.refCount > 1) {
283 status = DM8168DUCATIPWR_S_ALREADYSETUP;
284 Gate_leaveSystem(key);
285 }
286 else {
287 Gate_leaveSystem(key);
289 /* Create a default gate handle for local module protection. */
290 DM8168DUCATIPWR_state.gateHandle = (IGateProvider_Handle)
291 GateMutex_create ((GateMutex_Params*)NULL, &eb);
292 if (DM8168DUCATIPWR_state.gateHandle == NULL) {
293 key = Gate_enterSystem();
294 DM8168DUCATIPWR_state.refCount = 0;
295 Gate_leaveSystem(key);
296 /*! @retval PWRMGR_E_FAIL Failed to create GateMutex! */
297 status = PWRMGR_E_FAIL;
298 GT_setFailureReason (curTrace,
299 GT_4CLASS,
300 "DM8168DUCATIPWR_setup",
301 status,
302 "Failed to create GateMutex!");
303 }
304 else {
305 /* Copy the user provided values into the state object. */
306 memcpy (&DM8168DUCATIPWR_state.cfg,
307 cfg,
308 sizeof (DM8168DUCATIPWR_Config));
310 /* Initialize the name to handles mapping array. */
311 memset (&DM8168DUCATIPWR_state.pwrHandles,
312 0,
313 (sizeof (DM8168DUCATIPWR_Handle) * MultiProc_MAXPROCESSORS));
314 DM8168DUCATIPWR_state.isSetup = TRUE;
315 }
316 }
318 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_setup", status);
319 /*! @retval PWRMGR_SUCCESS Operation successful */
320 return (status);
321 }
323 /*!
324 * @brief Function to destroy the DM8168DUCATIPWR module.
325 *
326 * Once this function is called, other DM8168DUCATIPWR module APIs, except
327 * for the DM8168DUCATIPWR_getConfig API cannot be called anymore.
328 *
329 * @sa DM8168DUCATIPWR_setup
330 * GateMutex_delete
331 */
332 Int
333 DM8168DUCATIPWR_destroy (Void)
334 {
335 Int status = PWRMGR_SUCCESS;
336 UInt16 i;
337 IArg key;
339 GT_0trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_destroy");
341 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
343 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
344 if (DM8168DUCATIPWR_state.refCount == 0) {
345 status = DM8168DUCATIPWR_E_INVALIDSTATE;
346 GT_setFailureReason (curTrace,
347 GT_4CLASS,
348 "DM8168DUCATIPWR_destroy",
349 status,
350 "Module was not initialized!");
351 }
352 else {
353 #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
354 key = Gate_enterSystem();
355 DM8168DUCATIPWR_state.refCount--;
356 Gate_leaveSystem(key);
358 if (DM8168DUCATIPWR_state.refCount == 0) {
359 /* Temporarily increment refCount here. */
360 key = Gate_enterSystem();
361 DM8168DUCATIPWR_state.refCount = 1;
362 Gate_leaveSystem(key);
364 /* Check if any DM8168DUCATIPWR instances have not been deleted so far. If not,
365 * delete them.
366 */
367 for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
368 GT_assert (curTrace, (DM8168DUCATIPWR_state.pwrHandles [i] == NULL));
369 if (DM8168DUCATIPWR_state.pwrHandles [i] != NULL) {
370 DM8168DUCATIPWR_delete (&(DM8168DUCATIPWR_state.pwrHandles [i]));
371 }
372 }
373 /* restore refCount here. */
374 key = Gate_enterSystem();
375 DM8168DUCATIPWR_state.refCount = 0;
376 Gate_leaveSystem(key);
378 if (DM8168DUCATIPWR_state.gateHandle != NULL) {
379 GateMutex_delete ((GateMutex_Handle *)
380 &(DM8168DUCATIPWR_state.gateHandle));
381 }
382 DM8168DUCATIPWR_state.isSetup = FALSE;
383 }
384 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
385 }
386 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
387 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_destroy", status);
389 /*! @retval PWRMGR_SUCCESS Operation successful */
390 return (status);
391 }
393 /*!
394 * @brief Function to initialize the parameters for this PwrMgr instance.
395 *
396 * @param params Configuration parameters.
397 *
398 * @sa DM8168DUCATIPWR_create
399 */
400 Void
401 DM8168DUCATIPWR_Params_init (DM8168DUCATIPWR_Params * params)
402 {
403 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_Params_init", params);
405 GT_assert (curTrace, (params != NULL));
406 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
408 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
409 if (DM8168DUCATIPWR_state.refCount == 0) {
410 GT_setFailureReason (curTrace,
411 GT_4CLASS,
412 "DM8168DUCATIPWR_Params_initv",
413 DM8168DUCATIPWR_E_INVALIDSTATE,
414 "Module was not initialized!");
415 }
416 else if (params == NULL) {
417 GT_setFailureReason (curTrace,
418 GT_4CLASS,
419 "DM8168DUCATIPWR_Params_init",
420 PWRMGR_E_INVALIDARG,
421 "Argument of type (DM8168DUCATIPWR_Params *) "
422 "passed is null!");
423 }
424 else {
425 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
426 params->reserved = 0;
427 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
428 }
429 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
431 GT_0trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_Params_init");
432 }
434 /*!
435 * @brief Function to create an instance of this PwrMgr.
436 *
437 * @param procId Processor ID addressed by this PwrMgr instance.
438 * @param params Configuration parameters.
439 *
440 * @sa DM8168DUCATIPWR_delete
441 */
442 DM8168DUCATIPWR_Handle
443 DM8168DUCATIPWR_create ( UInt16 procId,
444 const DM8168DUCATIPWR_Params * params)
445 {
446 Int status = PWRMGR_SUCCESS;
447 PwrMgr_Object * handle = NULL;
448 IArg key;
450 GT_2trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_create", procId, params);
452 GT_assert (curTrace, IS_VALID_PROCID (procId));
453 GT_assert (curTrace, (params != NULL));
454 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
456 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
457 if (DM8168DUCATIPWR_state.refCount == 0) {
458 GT_setFailureReason (curTrace,
459 GT_4CLASS,
460 "DM8168DUCATIPWR_create",
461 DM8168DUCATIPWR_E_INVALIDSTATE,
462 "Module was not initialized!");
463 }
464 else if (!IS_VALID_PROCID (procId)) {
465 /* Not setting status here since this function does not return status.*/
466 GT_setFailureReason (curTrace,
467 GT_4CLASS,
468 "DM8168DUCATIPWR_create",
469 PWRMGR_E_INVALIDARG,
470 "Invalid procId specified");
471 }
472 else if (params == NULL) {
473 GT_setFailureReason (curTrace,
474 GT_4CLASS,
475 "DM8168DUCATIPWR_create",
476 PWRMGR_E_INVALIDARG,
477 "params passed is null!");
478 }
479 else {
480 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
481 /* Enter critical section protection. */
482 key = IGateProvider_enter (DM8168DUCATIPWR_state.gateHandle);
483 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
484 /* Check if the PwrMgr already exists for specified procId. */
485 if (DM8168DUCATIPWR_state.pwrHandles [procId] != NULL) {
486 status = PWRMGR_E_ALREADYEXIST;
487 GT_setFailureReason (curTrace,
488 GT_4CLASS,
489 "DM8168DUCATIPWR_create",
490 status,
491 "PwrMgr already exists for specified procId!");
492 }
493 else {
494 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
495 /* Allocate memory for the handle */
496 handle = (PwrMgr_Object *) Memory_calloc (NULL,
497 sizeof (PwrMgr_Object),
498 0,
499 NULL);
500 if (handle == NULL) {
501 GT_setFailureReason (curTrace,
502 GT_4CLASS,
503 "DM8168DUCATIPWR_create",
504 PWRMGR_E_MEMORY,
505 "Memory allocation failed for handle!");
506 }
507 else {
508 /* Populate the handle fields */
509 handle->pwrFxnTable.attach = &DM8168DUCATIPWR_attach;
510 handle->pwrFxnTable.detach = &DM8168DUCATIPWR_detach;
511 handle->pwrFxnTable.on = &DM8168DUCATIPWR_on;
512 handle->pwrFxnTable.off = &DM8168DUCATIPWR_off;
513 /* TBD: Other functions */
515 /* Allocate memory for the DM8168DUCATIPWR handle */
516 handle->object = Memory_calloc (NULL,
517 sizeof (DM8168DUCATIPWR_Object),
518 0,
519 NULL);
520 if (handle == NULL) {
521 status = PWRMGR_E_MEMORY;
522 GT_setFailureReason (curTrace,
523 GT_4CLASS,
524 "DM8168DUCATIPWR_create",
525 status,
526 "Memory allocation failed for handle!");
527 }
528 else {
529 #if defined (SYSLINK_BUILDOS_LINUX)
530 ((DM8168DUCATIPWR_Object *)handle->object)->clockHandle
531 = (ClockOps_Handle) LinuxClock_create();
532 #endif/* #if defined (SYSLINK_BUILDOS_LINUX) */
533 #if defined (SYSLINK_BUILD_RTOS)
534 ((DM8168DUCATIPWR_Object *)handle->object)->clockHandle
535 = (ClockOps_Handle) DM8168CLOCK_create();
536 #endif/* #if defined (SYSLINK_BUILD_RTOS) */
537 handle->procId = procId;
538 DM8168DUCATIPWR_state.pwrHandles [procId] =
539 (DM8168DUCATIPWR_Handle) handle;
540 }
541 }
542 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
543 }
544 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
545 /* Leave critical section protection. */
546 IGateProvider_leave (DM8168DUCATIPWR_state.gateHandle, key);
547 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
548 }
549 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
551 if (status < 0) {
552 if (handle != NULL) {
553 if (handle->object != NULL) {
554 Memory_free (NULL, handle->object, sizeof (DM8168DUCATIPWR_Object));
555 }
556 Memory_free (NULL, handle, sizeof (PwrMgr_Object));
557 }
558 /*! @retval NULL Function failed */
559 handle = NULL;
560 }
562 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_create", handle);
564 /*! @retval Valid-Handle Operation successful */
565 return (DM8168DUCATIPWR_Handle) handle;
566 }
568 /*!
569 * @brief Function to delete an instance of this PwrMgr.
570 *
571 * The user provided pointer to the handle is reset after
572 * successful completion of this function.
573 *
574 * @param handlePtr Pointer to Handle to the PwrMgr instance
575 *
576 * @sa DM8168DUCATIPWR_create
577 */
578 Int
579 DM8168DUCATIPWR_delete (DM8168DUCATIPWR_Handle * handlePtr)
580 {
581 Int status = PWRMGR_SUCCESS;
582 DM8168DUCATIPWR_Object * object = NULL;
583 PwrMgr_Object * handle;
584 IArg key;
586 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_delete", handlePtr);
588 GT_assert (curTrace, (handlePtr != NULL));
589 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
591 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
593 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
594 if (DM8168DUCATIPWR_state.refCount == 0) {
595 GT_setFailureReason (curTrace,
596 GT_4CLASS,
597 "DM8168DUCATIPWR_delete",
598 DM8168DUCATIPWR_E_INVALIDSTATE,
599 "Module was not initialized!");
600 }
601 else if (handlePtr == NULL) {
602 /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr specified*/
603 status = PWRMGR_E_INVALIDARG;
604 GT_setFailureReason (curTrace,
605 GT_4CLASS,
606 "DM8168DUCATIPWR_delete",
607 status,
608 "Invalid NULL handlePtr specified");
609 }
610 else if (*handlePtr == NULL) {
611 /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
612 status = PWRMGR_E_HANDLE;
613 GT_setFailureReason (curTrace,
614 GT_4CLASS,
615 "DM8168DUCATIPWR_delete",
616 status,
617 "Invalid NULL *handlePtr specified");
618 }
619 else {
620 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
621 handle = (PwrMgr_Object *) (*handlePtr);
622 /* Enter critical section protection. */
623 key = IGateProvider_enter (DM8168DUCATIPWR_state.gateHandle);
625 /* Reset handle in PwrMgr handle array. */
626 GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
627 DM8168DUCATIPWR_state.pwrHandles [handle->procId] = NULL;
629 object = (DM8168DUCATIPWR_Object *) handle->object;
630 /* Free memory used for the DM8168DUCATIPWR object. */
631 if (handle->object != NULL) {
632 /* Free memory used for the clock handle */
633 #if defined (SYSLINK_BUILDOS_LINUX)
634 LinuxClock_delete(((DM8168DUCATIPWR_Object *)handle->object)->clockHandle);
635 #endif /* #if defined (SYSLINK_BUILDOS_LINUX) */
636 #if defined (SYSLINK_BUILD_RTOS)
637 DM8168CLOCK_delete(((DM8168DUCATIPWR_Object *)handle->object)->clockHandle);
638 #endif /* #if defined (SYSLINK_BUILD_RTOS) */
639 Memory_free (NULL,
640 object,
641 sizeof (DM8168DUCATIPWR_Object));
642 handle->object = NULL;
643 }
645 /* Free memory used for the PwrMgr object. */
646 Memory_free (NULL, handle, sizeof (PwrMgr_Object));
647 *handlePtr = NULL;
649 /* Leave critical section protection. */
650 IGateProvider_leave (DM8168DUCATIPWR_state.gateHandle, key);
651 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
652 }
653 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
655 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_delete", status);
657 /*! @retval PWRMGR_SUCCESS Operation successful */
658 return (status);
659 }
661 /*!
662 * @brief Function to open a handle to an instance of this PwrMgr. This
663 * function is called when access to the PwrMgr is required from
664 * a different process.
665 *
666 * @param handlePtr Handle to the PwrMgr instance
667 * @param procId Processor ID addressed by this PwrMgr instance.
668 *
669 * @sa DM8168DUCATIPWR_close
670 */
671 Int
672 DM8168DUCATIPWR_open (DM8168DUCATIPWR_Handle * handlePtr, UInt16 procId)
673 {
674 Int status = PWRMGR_SUCCESS;
676 GT_2trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_open", handlePtr, procId);
678 GT_assert (curTrace, (handlePtr != NULL));
679 GT_assert (curTrace, IS_VALID_PROCID (procId));
681 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
683 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
684 if (DM8168DUCATIPWR_state.refCount == 0) {
685 GT_setFailureReason (curTrace,
686 GT_4CLASS,
687 "DM8168DUCATIPWR_open",
688 DM8168DUCATIPWR_E_INVALIDSTATE,
689 "Module was not initialized!");
690 }
691 else if (handlePtr == NULL) {
692 /*! @retval PWRMGR_E_HANDLE Invalid NULL handlePtr specified */
693 status = PWRMGR_E_HANDLE;
694 GT_setFailureReason (curTrace,
695 GT_4CLASS,
696 "DM8168DUCATIPWR_open",
697 status,
698 "Invalid NULL handlePtr specified");
699 }
700 else if (!IS_VALID_PROCID (procId)) {
701 /*! @retval PWRMGR_E_INVALIDARG Invalid procId specified */
702 status = PWRMGR_E_INVALIDARG;
703 GT_setFailureReason (curTrace,
704 GT_4CLASS,
705 "DM8168DUCATIPWR_open",
706 status,
707 "Invalid procId specified");
708 }
709 else {
710 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
711 /* Initialize return parameter handle. */
712 *handlePtr = NULL;
714 /* Check if the PwrMgr exists and return the handle if found. */
715 if (DM8168DUCATIPWR_state.pwrHandles [procId] == NULL) {
716 /*! @retval PWRMGR_E_NOTFOUND Specified instance not found */
717 status = PWRMGR_E_NOTFOUND;
718 GT_setFailureReason (curTrace,
719 GT_4CLASS,
720 "DM8168DUCATIPWR_open",
721 status,
722 "Specified DM8168DUCATIPWR instance does not exist!");
723 }
724 else {
725 *handlePtr = DM8168DUCATIPWR_state.pwrHandles [procId];
726 }
727 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
728 }
729 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
731 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_open", status);
733 /*! @retval PWRMGR_SUCCESS Operation successful */
734 return status;
735 }
737 /*!
738 * @brief Function to close a handle to an instance of this PwrMgr.
739 *
740 * @param handlePtr Pointer to Handle to the PwrMgr instance
741 *
742 * @sa DM8168DUCATIPWR_open
743 */
744 Int
745 DM8168DUCATIPWR_close (DM8168DUCATIPWR_Handle * handlePtr)
746 {
747 Int status = PWRMGR_SUCCESS;
749 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_close", handlePtr);
751 GT_assert (curTrace, (handlePtr != NULL));
752 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
753 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
755 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
756 if (DM8168DUCATIPWR_state.refCount == 0) {
757 GT_setFailureReason (curTrace,
758 GT_4CLASS,
759 "DM8168DUCATIPWR_close",
760 DM8168DUCATIPWR_E_INVALIDSTATE,
761 "Module was not initialized!");
762 }
763 else if (handlePtr == NULL) {
764 /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr pointer
765 specified*/
766 status = PWRMGR_E_INVALIDARG;
767 GT_setFailureReason (curTrace,
768 GT_4CLASS,
769 "DM8168DUCATIPWR_close",
770 status,
771 "Invalid NULL handlePtr pointer specified");
772 }
773 else if (*handlePtr == NULL) {
774 /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
775 status = PWRMGR_E_HANDLE;
776 GT_setFailureReason (curTrace,
777 GT_4CLASS,
778 "DM8168DUCATIPWR_close",
779 status,
780 "Invalid NULL *handlePtr specified");
781 }
782 else {
783 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
784 /* Nothing to be done for close. */
785 *handlePtr = NULL;
786 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
787 }
788 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
790 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_close", status);
792 /*! @retval PWRMGR_SUCCESS Operation successful */
793 return status;
794 }
796 /* =============================================================================
797 * APIs called by PwrMgr module (part of function table interface)
798 * =============================================================================
799 */
800 /*!
801 * @brief Function to attach to the PwrMgr.
802 *
803 * @param handle Handle to the PwrMgr instance
804 * @param params Attach parameters
805 *
806 * @sa DM8168DUCATIPWR_detach
807 */
808 Int
809 DM8168DUCATIPWR_attach (PwrMgr_Handle handle, PwrMgr_AttachParams * params)
810 {
812 Int status = PWRMGR_SUCCESS;
813 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
814 DM8168DUCATIPWR_Object * object = NULL;
815 Memory_MapInfo mapInfo;
816 /* Mapping for prcm base is done in DM8168VIDEOM3_phyShmemInit */
818 GT_2trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_attach", handle, params);
820 GT_assert (curTrace, (handle != NULL));
821 GT_assert (curTrace, (params != NULL));
822 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
824 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
825 if (DM8168DUCATIPWR_state.refCount == 0) {
826 GT_setFailureReason (curTrace,
827 GT_4CLASS,
828 "DM8168DUCATIPWR_attach",
829 DM8168DUCATIPWR_E_INVALIDSTATE,
830 "Module was not initialized!");
831 }
832 else if (handle == NULL) {
833 /*! @retval PWRMGR_E_HANDLE Invalid argument */
834 status = PWRMGR_E_HANDLE;
835 GT_setFailureReason (curTrace,
836 GT_4CLASS,
837 "DM8168DUCATIPWR_attach",
838 status,
839 "Invalid handle specified");
840 }
841 else {
842 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
843 object = (DM8168DUCATIPWR_Object *) pwrMgrHandle->object;
844 GT_assert (curTrace, (object != NULL));
845 /* Map and get the virtual address for system control module */
846 mapInfo.src = DM8168M3_PRCM_BASE_ADDR;
847 mapInfo.size = DM8168M3_PRCM_SIZE;
848 mapInfo.isCached = FALSE;
849 status = Memory_map (&mapInfo);
850 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
851 if (status < 0) {
852 status = DM8168DUCATIPWR_E_FAIL;
853 GT_setFailureReason (curTrace,
854 GT_4CLASS,
855 "DM8168DUCATIPWR_attach",
856 status,
857 "Failure in mapping prcm module");
858 }
859 else {
860 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
861 object->prcmVA = mapInfo.dst;
862 /* Map and get the virtual address for system control module */
863 mapInfo.src = DUCATI_MMU_CFG;
864 mapInfo.size = DUCATI_MMU_CFG_SIZE;
865 mapInfo.isCached = FALSE;
866 status = Memory_map (&mapInfo);
867 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
868 if (status < 0) {
869 status = DM8168DUCATIPWR_E_FAIL;
870 GT_setFailureReason (curTrace,
871 GT_4CLASS,
872 "DM8168DUCATIPWR_attach",
873 status,
874 "Failure in mapping ducatimmu module");
875 }
876 else {
877 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
878 object->ducatiMmuVA = mapInfo.dst;
879 /* Map and get the virtual address for system control module */
880 mapInfo.src = DUCATI_BASE_ADDR;
881 mapInfo.size = DUCATI_BASE_ADDR_SIZE;
882 mapInfo.isCached = FALSE;
883 status = Memory_map (&mapInfo);
884 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
885 if (status < 0) {
886 status = DM8168DUCATIPWR_E_FAIL;
887 GT_setFailureReason (curTrace,
888 GT_4CLASS,
889 "DM8168DUCATIPWR_attach",
890 status,
891 "Failure in mapping ducatibase module");
892 }
893 else {
894 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
895 object->ducatibaseVA = mapInfo.dst;
896 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
897 }
898 }
899 }
900 }
901 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
903 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_attach", status);
904 /*! @retval PWRMGR_SUCCESS Operation successful */
905 return (status);
906 }
908 /*!
909 * @brief Function to detach from the PwrMgr.
910 *
911 * @param handle Handle to the PwrMgr instance
912 *
913 * @sa DM8168DUCATIPWR_attach
914 */
915 Int
916 DM8168DUCATIPWR_detach (PwrMgr_Handle handle)
917 {
918 Int status = PWRMGR_SUCCESS;
919 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
920 DM8168DUCATIPWR_Object * object = NULL;
921 Memory_UnmapInfo unmapInfo;
924 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_detach", handle);
926 GT_assert (curTrace, (handle != NULL));
927 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
929 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
930 if (DM8168DUCATIPWR_state.refCount == 0) {
931 GT_setFailureReason (curTrace,
932 GT_4CLASS,
933 "DM8168DUCATIPWR_detach",
934 DM8168DUCATIPWR_E_INVALIDSTATE,
935 "Module was not initialized!");
936 }
937 else if (handle == NULL) {
938 /*! @retval PWRMGR_E_HANDLE Invalid argument */
939 status = PWRMGR_E_HANDLE;
940 GT_setFailureReason (curTrace,
941 GT_4CLASS,
942 "DM8168DUCATIPWR_detach",
943 status,
944 "Invalid handle specified");
945 }
946 else {
947 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
948 object = (DM8168DUCATIPWR_Object *) pwrMgrHandle->object;
949 GT_assert (curTrace, (object != NULL));
951 /* Unmap the virtual address for prcm module */
952 unmapInfo.addr = object->prcmVA;
953 unmapInfo.size = DM8168M3_PRCM_SIZE;
954 unmapInfo.isCached = FALSE;
955 if (unmapInfo.addr != 0) {
956 status = Memory_unmap (&unmapInfo);
957 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
958 if (status < 0) {
959 status = DM8168DUCATIPWR_E_FAIL;
960 GT_setFailureReason (curTrace,
961 GT_4CLASS,
962 "DM8168DUCATIPWR_detach",
963 status,
964 "Failure in mapping prcm module");
965 }
966 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
967 }
968 /* Unmap the virtual address for mmu base*/
969 unmapInfo.addr = object->ducatiMmuVA;
970 unmapInfo.size = DUCATI_MMU_CFG_SIZE;
971 unmapInfo.isCached = FALSE;
972 if (unmapInfo.addr != 0) {
973 status = Memory_unmap (&unmapInfo);
974 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
975 if (status < 0) {
976 status = DM8168DUCATIPWR_E_FAIL;
977 GT_setFailureReason (curTrace,
978 GT_4CLASS,
979 "DM8168DUCATIPWR_detach",
980 status,
981 "Failure in mapping ducatiMmu module");
982 }
983 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
984 }
986 /* Unmap the virtual address for ducati control base */
987 unmapInfo.addr = object->ducatibaseVA;
988 unmapInfo.size = DUCATI_BASE_ADDR_SIZE;
989 unmapInfo.isCached = FALSE;
990 if (unmapInfo.addr != 0) {
991 status = Memory_unmap (&unmapInfo);
992 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
993 if (status < 0) {
994 status = DM8168DUCATIPWR_E_FAIL;
995 GT_setFailureReason (curTrace,
996 GT_4CLASS,
997 "DM8168DUCATIPWR_detach",
998 status,
999 "Failure in mapping ducatiMmu module");
1000 }
1001 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
1002 }
1003 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1004 }
1005 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
1007 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_detach", status);
1008 /*! @retval PWRMGR_SUCCESS Operation successful */
1009 return (status);
1010 }
1012 /*!
1013 * @brief Function to power on the slave processor.
1014 *
1015 * Power on the IVA subsystem, hold the DSP and SEQ in reset, and
1016 * release IVA2_RST. This is a hostile reset of the IVA. If the IVA
1017 * is already powered on, then it must be powered off in order to
1018 * terminate all current activity and initiate a power-on-reset
1019 * transition to bring the IVA to a know good state.
1020 *
1021 * @param handle Handle to the PwrMgr instance
1022 *
1023 * @sa DM8168DUCATIPWR_off
1024 */
1025 Int
1026 DM8168DUCATIPWR_on (PwrMgr_Handle handle)
1027 {
1028 Int status = PWRMGR_SUCCESS ;
1029 Int32 tmpstatus = 0;
1030 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
1031 DM8168DUCATIPWR_Object * object = NULL;
1032 IArg key;
1033 (Void)tmpstatus;
1034 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_on", handle);
1036 GT_assert (curTrace, (handle != NULL));
1037 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
1039 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1040 if (DM8168DUCATIPWR_state.refCount == 0) {
1041 GT_setFailureReason (curTrace,
1042 GT_4CLASS,
1043 "DM8168DUCATIPWR_on",
1044 DM8168DUCATIPWR_E_INVALIDSTATE,
1045 "Module was not initialized!");
1046 }
1047 else {
1048 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1049 /* This sets the refCount variable is not initialized, upper 16 bits is
1050 * written with module Id to ensure correctness of refCount variable.
1051 */
1052 key = Gate_enterSystem();
1053 DM8168DUCATIPWR_state.pwrstateRefCount++;
1054 if (DM8168DUCATIPWR_state.pwrstateRefCount > 1) {
1055 status = DM8168DUCATIPWR_S_ALREADYSETUP;
1056 Gate_leaveSystem(key);
1057 }
1058 else {
1059 Gate_leaveSystem(key);
1060 #if !defined(SYSLINK_BUILD_OPTIMIZE)&& defined(SYSLINK_BUILD_HLOS)
1061 if (handle == NULL) {
1062 /*! @retval PWRMGR_E_HANDLE Invalid argument */
1063 status = PWRMGR_E_HANDLE;
1064 GT_setFailureReason (curTrace,
1065 GT_4CLASS,
1066 "DM8168DUCATIPWR_on",
1067 status,
1068 "Invalid handle specified");
1069 }
1070 else {
1071 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
1072 object = (DM8168DUCATIPWR_Object *) pwrMgrHandle->object;
1074 GT_assert (curTrace, (object != NULL));
1075 /* Enable spinlocks, mailbox and timers before powering on ducati */
1077 DM8168DUCATIPWR_state.ducatiSpinlockHandle
1078 = ClockOps_get(object->clockHandle, "spinbox_ick");
1079 /* Do not put this check under SYSLINK_BUILD_OPTIMIZE */
1080 GT_assert (curTrace,
1081 (DM8168DUCATIPWR_state.ducatiSpinlockHandle != NULL));
1082 status = ClockOps_enable(object->clockHandle,
1083 DM8168DUCATIPWR_state.ducatiSpinlockHandle);
1084 GT_assert (curTrace, (status >= 0));
1086 DM8168DUCATIPWR_state.ducatiMailboxHandle
1087 = ClockOps_get(object->clockHandle, "mailbox_ick");
1088 /* Do not put this check under SYSLINK_BUILD_OPTIMIZE */
1089 GT_assert (curTrace, (DM8168DUCATIPWR_state.ducatiMailboxHandle != NULL));
1090 status = ClockOps_enable(object->clockHandle,
1091 DM8168DUCATIPWR_state.ducatiMailboxHandle);
1092 GT_assert (curTrace, (status >= 0));
1094 /* poer on ducati */
1095 DM8168DUCATIPWR_state.ducatiClkHandle
1096 = ClockOps_get(object->clockHandle, "ducati_ick");
1097 /* Do not put this check under SYSLINK_BUILD_OPTIMIZE */
1098 if (DM8168DUCATIPWR_state.ducatiClkHandle == NULL) {
1099 /*! @retval PWRMGR_E_HANDLE Invalid argument */
1100 status = PWRMGR_E_HANDLE;
1101 GT_setFailureReason (curTrace,
1102 GT_4CLASS,
1103 "DM8168DUCATIPWR_on",
1104 status,
1105 "object->clkHandle retuned NULL clk_get failed for ducati");
1106 }
1107 else {
1108 tmpstatus = ClockOps_enable(object->clockHandle,
1109 DM8168DUCATIPWR_state.ducatiClkHandle);
1110 GT_assert (curTrace, (tmpstatus >= 0));
1111 /* Complete the remaining power sequence here*/
1112 DM8168DUCATIMMU_enable(pwrMgrHandle);
1113 }
1114 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)
1115 }
1116 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)*/
1117 }
1118 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1119 }
1120 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)*/
1121 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_on", status);
1122 /*! @retval PWRMGR_SUCCESS Operation successful */
1123 return (status);
1124 }
1126 /*!
1127 * @brief Function to power off the slave processor.
1128 *
1129 * Turn the IVA power domain off. To ensure a clean power-off
1130 * transition, the IVA subsystem must first be turned on so that
1131 * the DSP can initiate an autonomous power-off transition.
1132 *
1133 * @param handle Handle to the PwrMgr instance
1134 * @param force Indicates whether power-off is to be forced
1135 *
1136 * @sa DM8168DUCATIPWR_on
1137 */
1138 Int
1139 DM8168DUCATIPWR_off (PwrMgr_Handle handle, Bool force)
1140 {
1141 Int status = PWRMGR_SUCCESS ;
1142 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
1143 DM8168DUCATIPWR_Object * object = NULL;
1144 IArg key;
1146 GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_off", handle);
1148 GT_assert (curTrace, (handle != NULL));
1150 GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0));
1152 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1153 if (DM8168DUCATIPWR_state.refCount == 0) {
1154 GT_setFailureReason (curTrace,
1155 GT_4CLASS,
1156 "DM8168DUCATIPWR_off",
1157 DM8168DUCATIPWR_E_INVALIDSTATE,
1158 "Module was not initialized!");
1159 }
1160 else if (handle == NULL) {
1161 /*! @retval PWRMGR_E_HANDLE Invalid argument */
1162 status = PWRMGR_E_HANDLE;
1163 GT_setFailureReason (curTrace,
1164 GT_4CLASS,
1165 "DM8168DUCATIPWR_off",
1166 status,
1167 "Invalid handle specified");
1168 }
1169 else {
1170 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1171 object = (DM8168DUCATIPWR_Object *) pwrMgrHandle->object;
1172 key = Gate_enterSystem();
1173 DM8168DUCATIPWR_state.pwrstateRefCount--;
1174 Gate_leaveSystem(key);
1176 if (DM8168DUCATIPWR_state.pwrstateRefCount == 0) {
1177 DM8168DUCATIMMU_disable(pwrMgrHandle);
1178 /* Disable Mailbox clocks */
1179 if(DM8168DUCATIPWR_state.ducatiMailboxHandle) {
1180 ClockOps_disable(object->clockHandle,
1181 DM8168DUCATIPWR_state.ducatiMailboxHandle);
1182 ClockOps_put(object->clockHandle,
1183 DM8168DUCATIPWR_state.ducatiMailboxHandle);
1184 }
1185 /* Disable Spinlock clocks */
1186 if(DM8168DUCATIPWR_state.ducatiSpinlockHandle) {
1187 ClockOps_disable(object->clockHandle,
1188 DM8168DUCATIPWR_state.ducatiSpinlockHandle);
1189 ClockOps_put(object->clockHandle,
1190 DM8168DUCATIPWR_state.ducatiSpinlockHandle);
1191 }
1192 if(DM8168DUCATIPWR_state.ducatiClkHandle) {
1193 ClockOps_disable(object->clockHandle,
1194 DM8168DUCATIPWR_state.ducatiClkHandle);
1195 ClockOps_put(object->clockHandle,
1196 DM8168DUCATIPWR_state.ducatiClkHandle);
1197 }
1198 }
1199 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1200 }
1201 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
1202 GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_off", status);
1203 /*! @retval PWRMGR_SUCCESS Operation successful */
1204 return (status);
1205 }
1207 #if defined (__cplusplus)
1208 }
1209 #endif /* defined (__cplusplus) */