Remove references to SysLink in QNX code base
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayuipu / VAYUIpuPwr.c
1 /*
2  *  @file   VAYUIpuPwr.c
3  *
4  *  @brief      PwrMgr implementation for VAYUIPU.
5  *
6  *              This module is responsible for handling power requests for
7  *              the ProcMgr. The implementation is common to VAYUIPUCORE1 and
8  *              VAYUIPUCORE0.
9  *
10  *
11  *  ============================================================================
12  *
13  *  Copyright (c) 2013-2015, 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 #include <ti/syslink/Std.h>
55 /* OSAL & Utils headers */
56 #include <ti/syslink/utils/String.h>
57 #include <ti/syslink/utils/IGateProvider.h>
58 #include <ti/syslink/utils/GateMutex.h>
59 #include <ti/syslink/utils/Memory.h>
60 #include <ti/syslink/utils/Gate.h>
63 #include <string.h>
65 #include <ti/syslink/utils/Trace.h>
67 /* Module level headers */
68 #include <ti/ipc/MultiProc.h>
69 #include <ti/syslink/inc/_MultiProc.h>
70 #include <ti/syslink/inc/knl/PwrDefs.h>
71 #include <ti/syslink/inc/knl/PwrMgr.h>
72 #include <ti/syslink/inc/knl/VAYUIpuPwr.h>
73 #include <ti/syslink/inc/knl/_VAYUIpuPwr.h>
74 #include <ti/syslink/inc/knl/Qnx/VAYUIpuMmu.h>
75 #include <ti/syslink/inc/knl/VAYUIpuPhyShmem.h>
77 #if defined (__cplusplus)
78 extern "C" {
79 #endif
82 /* =============================================================================
83  *  Macros and types
84  * =============================================================================
85  */
86 /*!
87  *  @brief  VAYUIPU module and mmr addresses (physical)
88  */
91 #define MAX_WAIT_COUNT              0x50000
93 #define REG(x)              *((volatile UInt32 *) (x))
94 #define MEM(x)              *((volatile UInt32 *) (x))
96 /* Macro to make a correct module magic number with refCount */
97 #define VAYUIPUPWR_MAKE_MAGICSTAMP(x) \
98                             ((VAYUIPUPWR_MODULEID << 12u) | (x))
100 /*!
101  *  @brief  VAYUIPUPWR Module state object
102  */
103 typedef struct VAYUIPUPWR_ModuleObject_tag {
104     UInt32                  refCount;
105     /* Module Reference count */
106     UInt32                  pwrstateRefCount;
107     /* Reference count */
108     UInt32                 configSize;
109     /*!< Size of configuration structure */
110     VAYUIPUPWR_Config      cfg;
111     /*!< VAYUIPUPWR configuration structure */
112     VAYUIPUPWR_Config      defCfg;
113     /*!< Default module configuration */
114     Bool                   isSetup;
115     /*!< Indicates whether the VAYUIPUPWR module is setup. */
116     VAYUIPUPWR_Handle      pwrHandles [MultiProc_MAXPROCESSORS];
117     /*!< PwrMgr handle array. */
118     IGateProvider_Handle   gateHandle;
119     /*!< Handle of gate to be used for local thread safety */
120     Ptr                    ipuClkHandle;
121     /*!< clock handle used to call kernel APIs */
122     Ptr                    ipuSpinlockHandle;
123     /*!< dsp Spinlock handle */
124     Ptr                    ipuMailboxHandle;
125     /*!< dsp Mailbox handle */
126 } VAYUIPUPWR_ModuleObject;
128 /* =============================================================================
129  *  Globals
130  * =============================================================================
131  */
132 /*!
133  *  @var    VAYUIPUPWR_state
134  *
135  *  @brief  VAYUIPUPWR state object variable
136  */
137 #if !defined(IPC_BUILD_DEBUG)
138 static
139 #endif /* if !defined(IPC_BUILD_DEBUG) */
140 VAYUIPUPWR_ModuleObject VAYUIPUPWR_state =
142     .isSetup = FALSE,
143     .configSize = sizeof (VAYUIPUPWR_Config),
144     .refCount   = 0,
145     .pwrstateRefCount = 0,
146     .defCfg.reserved = 0,
147     .gateHandle = NULL,
148 };
150 /* =============================================================================
151  * APIs directly called by applications
152  * =============================================================================
153  */
154 /*!
155  *  @brief      Function to get the default configuration for the VAYUIPUPWR
156  *              module.
157  *
158  *              This function can be called by the application to get their
159  *              configuration parameter to VAYUIPUPWR_setup filled in by the
160  *              VAYUIPUPWR module with the default parameters. If the user does
161  *              not wish to make any change in the default parameters, this API
162  *              is not required to be called.
163  *
164  *  @param      cfg        Pointer to the VAYUIPUPWR module configuration
165  *                         structure in which the default config is to be
166  *                         returned.
167  *
168  *  @sa         VAYUIPUPWR_setup
169  */
170 Void
171 VAYUIPUPWR_getConfig (VAYUIPUPWR_Config * cfg)
173     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_getConfig", cfg);
175     GT_assert (curTrace, (cfg != NULL));
177 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
178     if (cfg == NULL) {
179         GT_setFailureReason (curTrace,
180                              GT_4CLASS,
181                              "VAYUIPUPWR_getConfig",
182                              PWRMGR_E_INVALIDARG,
183                              "Argument of type (VAYUIPUPWR_Config *) passed "
184                              "is null!");
185     }
186     else {
187 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
189         if (VAYUIPUPWR_state.refCount == 0) {
190             memcpy (cfg,
191                          &VAYUIPUPWR_state.defCfg,
192                          sizeof (VAYUIPUPWR_Config));
193         }
194         else {
195             memcpy (cfg,
196                          &VAYUIPUPWR_state.cfg,
197                          sizeof (VAYUIPUPWR_Config));
198         }
199 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
200     }
201 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
203     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUPWR_getConfig");
206 /*!
207  *  @brief      Function to setup the VAYUIPUPWR module.
208  *
209  *              This function sets up the VAYUIPUPWR module. This function must
210  *              be called before any other instance-level APIs can be invoked.
211  *              Module-level configuration needs to be provided to this
212  *              function. If the user wishes to change some specific config
213  *              parameters, then VAYUIPUPWR_getConfig can be called to get the
214  *              configuration filled with the default values. After this, only
215  *              the required configuration values can be changed. If the user
216  *              does not wish to make any change in the default parameters, the
217  *              application can simply call VAYUIPUPWR_setup with NULL
218  *              parameters. The default parameters would get automatically used.
219  *
220  *  @param      cfg   Optional VAYUIPUPWR module configuration. If provided as
221  *                    NULL, default configuration is used.
222  *
223  *  @sa         VAYUIPUPWR_destroy
224  *              GateMutex_create
225  */
226 Int
227 VAYUIPUPWR_setup (VAYUIPUPWR_Config * cfg)
229     Int                      status = PWRMGR_SUCCESS;
230     VAYUIPUPWR_Config   tmpCfg;
231     IArg                     key;
232     Error_Block              eb;
234     eb = 0;
236     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_setup", cfg);
237     if (cfg == NULL) {
238         VAYUIPUPWR_getConfig (&tmpCfg);
239         cfg = &tmpCfg;
240     }
242     /* This sets the refCount variable is not initialized, upper 16 bits is
243      * written with module Id to ensure correctness of refCount variable.
244      */
245     key = Gate_enterSystem();
246     VAYUIPUPWR_state.refCount++;
247     if (VAYUIPUPWR_state.refCount > 1) {
248         status = VAYUIPUPWR_S_ALREADYSETUP;
249         Gate_leaveSystem(key);
250     }
251     else {
252         Gate_leaveSystem(key);
254         /* Create a default gate handle for local module protection. */
255         VAYUIPUPWR_state.gateHandle = (IGateProvider_Handle)
256                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
257         if (VAYUIPUPWR_state.gateHandle == NULL) {
258             key = Gate_enterSystem();
259             VAYUIPUPWR_state.refCount = 0;
260             Gate_leaveSystem(key);
261             /*! @retval PWRMGR_E_FAIL Failed to create GateMutex! */
262             status = PWRMGR_E_FAIL;
263             GT_setFailureReason (curTrace,
264                                  GT_4CLASS,
265                                  "VAYUIPUPWR_setup",
266                                  status,
267                                  "Failed to create GateMutex!");
268         }
269         else {
270             /* Copy the user provided values into the state object. */
271             memcpy (&VAYUIPUPWR_state.cfg,
272                          cfg,
273                          sizeof (VAYUIPUPWR_Config));
275             /* Initialize the name to handles mapping array. */
276             memset (&VAYUIPUPWR_state.pwrHandles,
277                         0,
278                         (sizeof (VAYUIPUPWR_Handle) * MultiProc_MAXPROCESSORS));
279             VAYUIPUPWR_state.isSetup = TRUE;
280         }
281     }
283     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_setup", status);
284     /*! @retval PWRMGR_SUCCESS Operation successful */
285     return (status);
288 /*!
289  *  @brief      Function to destroy the VAYUIPUPWR module.
290  *
291  *              Once this function is called, other VAYUIPUPWR module APIs, except
292  *              for the VAYUIPUPWR_getConfig API cannot be called anymore.
293  *
294  *  @sa         VAYUIPUPWR_setup
295  *              GateMutex_delete
296  */
297 Int
298 VAYUIPUPWR_destroy (Void)
300     Int    status = PWRMGR_SUCCESS;
301     UInt16 i;
302     IArg key;
304     GT_0trace (curTrace, GT_ENTER, "VAYUIPUPWR_destroy");
306     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
308 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
309     if (VAYUIPUPWR_state.refCount == 0) {
310         status = VAYUIPUPWR_E_INVALIDSTATE;
311         GT_setFailureReason (curTrace,
312                              GT_4CLASS,
313                              "VAYUIPUPWR_destroy",
314                              status,
315                              "Module was not initialized!");
316     }
317     else {
318 #endif /* !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
319         key = Gate_enterSystem();
320         VAYUIPUPWR_state.refCount--;
321         Gate_leaveSystem(key);
323         if (VAYUIPUPWR_state.refCount == 0) {
324             /* Temporarily increment refCount here. */
325             key = Gate_enterSystem();
326             VAYUIPUPWR_state.refCount = 1;
327             Gate_leaveSystem(key);
329             /* Check if any VAYUIPUPWR instances have not been deleted so far. If not,
330              * delete them.
331              */
332             for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
333                 GT_assert (curTrace, (VAYUIPUPWR_state.pwrHandles [i] == NULL));
334                 if (VAYUIPUPWR_state.pwrHandles [i] != NULL) {
335                     VAYUIPUPWR_delete (&(VAYUIPUPWR_state.pwrHandles [i]));
336                 }
337             }
338             /* restore refCount here. */
339             key = Gate_enterSystem();
340             VAYUIPUPWR_state.refCount = 0;
341             Gate_leaveSystem(key);
343             if (VAYUIPUPWR_state.gateHandle != NULL) {
344                 GateMutex_delete ((GateMutex_Handle *)
345                                         &(VAYUIPUPWR_state.gateHandle));
346             }
347             VAYUIPUPWR_state.isSetup = FALSE;
348         }
349 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
350     }
351 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
352     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_destroy", status);
354     /*! @retval PWRMGR_SUCCESS Operation successful */
355     return (status);
358 /*!
359  *  @brief      Function to initialize the parameters for this PwrMgr instance.
360  *
361  *  @param      params  Configuration parameters.
362  *
363  *  @sa         VAYUIPUPWR_create
364  */
365 Void
366 VAYUIPUPWR_Params_init (VAYUIPUPWR_Params * params)
368     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_Params_init", params);
370     GT_assert (curTrace, (params != NULL));
371     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
373 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
374     if (VAYUIPUPWR_state.refCount == 0) {
375         GT_setFailureReason (curTrace,
376                              GT_4CLASS,
377                              "VAYUIPUPWR_Params_initv",
378                              VAYUIPUPWR_E_INVALIDSTATE,
379                              "Module was not initialized!");
380     }
381     else if (params == NULL) {
382         GT_setFailureReason (curTrace,
383                              GT_4CLASS,
384                              "VAYUIPUPWR_Params_init",
385                              PWRMGR_E_INVALIDARG,
386                              "Argument of type (VAYUIPUPWR_Params *) "
387                              "passed is null!");
388     }
389     else {
390 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
391         params->reserved = 0;
392 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
393     }
394 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
396     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUPWR_Params_init");
399 /*!
400  *  @brief      Function to create an instance of this PwrMgr.
401  *
402  *  @param      procId  Processor ID addressed by this PwrMgr instance.
403  *  @param      params  Configuration parameters.
404  *
405  *  @sa         VAYUIPUPWR_delete
406  */
407 VAYUIPUPWR_Handle
408 VAYUIPUPWR_create (      UInt16               procId,
409                     const VAYUIPUPWR_Params * params)
411     Int                  status = PWRMGR_SUCCESS;
412     PwrMgr_Object *      handle = NULL;
413     IArg                 key;
415     GT_2trace (curTrace, GT_ENTER, "VAYUIPUPWR_create", procId, params);
417     GT_assert (curTrace, IS_VALID_PROCID (procId));
418     GT_assert (curTrace, (params != NULL));
419     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
421 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
422     if (VAYUIPUPWR_state.refCount == 0) {
423         GT_setFailureReason (curTrace,
424                              GT_4CLASS,
425                              "VAYUIPUPWR_create",
426                              VAYUIPUPWR_E_INVALIDSTATE,
427                              "Module was not initialized!");
428     }
429     else if (!IS_VALID_PROCID (procId)) {
430         /* Not setting status here since this function does not return status.*/
431         GT_setFailureReason (curTrace,
432                              GT_4CLASS,
433                              "VAYUIPUPWR_create",
434                              PWRMGR_E_INVALIDARG,
435                              "Invalid procId specified");
436     }
437     else if (params == NULL) {
438         GT_setFailureReason (curTrace,
439                              GT_4CLASS,
440                              "VAYUIPUPWR_create",
441                              PWRMGR_E_INVALIDARG,
442                              "params passed is null!");
443     }
444     else {
445 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
446         /* Enter critical section protection. */
447         key = IGateProvider_enter (VAYUIPUPWR_state.gateHandle);
448 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
449         /* Check if the PwrMgr already exists for specified procId. */
450         if (VAYUIPUPWR_state.pwrHandles [procId] != NULL) {
451             status = PWRMGR_E_ALREADYEXIST;
452             GT_setFailureReason (curTrace,
453                                  GT_4CLASS,
454                                  "VAYUIPUPWR_create",
455                                  status,
456                                  "PwrMgr already exists for specified procId!");
457         }
458         else {
459 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
460             /* Allocate memory for the handle */
461             handle = (PwrMgr_Object *) Memory_calloc (NULL,
462                                                       sizeof (PwrMgr_Object),
463                                                       0,
464                                                       NULL);
465             if (handle == NULL) {
466                 GT_setFailureReason (curTrace,
467                                      GT_4CLASS,
468                                      "VAYUIPUPWR_create",
469                                      PWRMGR_E_MEMORY,
470                                      "Memory allocation failed for handle!");
471             }
472             else {
473                 /* Populate the handle fields */
474                 handle->pwrFxnTable.attach = &VAYUIPUPWR_attach;
475                 handle->pwrFxnTable.detach = &VAYUIPUPWR_detach;
476                 handle->pwrFxnTable.on     = &VAYUIPUPWR_on;
477                 handle->pwrFxnTable.off    = &VAYUIPUPWR_off;
478                 /* TBD: Other functions */
480                 /* Allocate memory for the VAYUIPUPWR handle */
481                 handle->object = Memory_calloc (NULL,
482                                                 sizeof (VAYUIPUPWR_Object),
483                                                 0,
484                                                 NULL);
485                 if (handle == NULL) {
486                     status = PWRMGR_E_MEMORY;
487                     GT_setFailureReason (curTrace,
488                                         GT_4CLASS,
489                                         "VAYUIPUPWR_create",
490                                         status,
491                                         "Memory allocation failed for handle!");
492                 }
493                 else {
494                     handle->procId = procId;
495                     VAYUIPUPWR_state.pwrHandles [procId] =
496                                                 (VAYUIPUPWR_Handle) handle;
497                 }
498             }
499 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
500         }
501 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
502         /* Leave critical section protection. */
503         IGateProvider_leave (VAYUIPUPWR_state.gateHandle, key);
504 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
505     }
506 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
508     if (status < 0) {
509         if (handle !=  NULL) {
510             if (handle->object != NULL) {
511                 Memory_free (NULL, handle->object, sizeof (VAYUIPUPWR_Object));
512             }
513             Memory_free (NULL, handle, sizeof (PwrMgr_Object));
514         }
515         /*! @retval NULL Function failed */
516         handle = NULL;
517     }
519     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_create", handle);
521     /*! @retval Valid-Handle Operation successful */
522     return (VAYUIPUPWR_Handle) handle;
525 /*!
526  *  @brief      Function to delete an instance of this PwrMgr.
527  *
528  *              The user provided pointer to the handle is reset after
529  *              successful completion of this function.
530  *
531  *  @param      handlePtr  Pointer to Handle to the PwrMgr instance
532  *
533  *  @sa         VAYUIPUPWR_create
534  */
535 Int
536 VAYUIPUPWR_delete (VAYUIPUPWR_Handle * handlePtr)
538     Int                  status = PWRMGR_SUCCESS;
539     VAYUIPUPWR_Object * object = NULL;
540     PwrMgr_Object *      handle;
541     IArg                 key;
543     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_delete", handlePtr);
545     GT_assert (curTrace, (handlePtr != NULL));
546     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
548     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
550 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
551     if (VAYUIPUPWR_state.refCount == 0) {
552         GT_setFailureReason (curTrace,
553                              GT_4CLASS,
554                              "VAYUIPUPWR_delete",
555                              VAYUIPUPWR_E_INVALIDSTATE,
556                              "Module was not initialized!");
557     }
558     else if (handlePtr == NULL) {
559         /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr specified*/
560         status = PWRMGR_E_INVALIDARG;
561         GT_setFailureReason (curTrace,
562                              GT_4CLASS,
563                              "VAYUIPUPWR_delete",
564                              status,
565                              "Invalid NULL handlePtr specified");
566     }
567     else if (*handlePtr == NULL) {
568         /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
569         status = PWRMGR_E_HANDLE;
570         GT_setFailureReason (curTrace,
571                              GT_4CLASS,
572                              "VAYUIPUPWR_delete",
573                              status,
574                              "Invalid NULL *handlePtr specified");
575     }
576     else {
577 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
578         handle = (PwrMgr_Object *) (*handlePtr);
579         /* Enter critical section protection. */
580         key = IGateProvider_enter (VAYUIPUPWR_state.gateHandle);
582         /* Reset handle in PwrMgr handle array. */
583         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
584         VAYUIPUPWR_state.pwrHandles [handle->procId] = NULL;
586         object = (VAYUIPUPWR_Object *) handle->object;
587         /* Free memory used for the VAYUIPUPWR object. */
588         if (handle->object != NULL) {
589             /* Free memory used for the clock handle */
590             Memory_free (NULL,
591                          object,
592                          sizeof (VAYUIPUPWR_Object));
593             handle->object = NULL;
594         }
596         /* Free memory used for the PwrMgr object. */
597         Memory_free (NULL, handle, sizeof (PwrMgr_Object));
598         *handlePtr = NULL;
600         /* Leave critical section protection. */
601         IGateProvider_leave (VAYUIPUPWR_state.gateHandle, key);
602 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
603     }
604 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
606     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_delete", status);
608     /*! @retval PWRMGR_SUCCESS Operation successful */
609     return (status);
612 /*!
613  *  @brief      Function to open a handle to an instance of this PwrMgr. This
614  *              function is called when access to the PwrMgr is required from
615  *              a different process.
616  *
617  *  @param      handlePtr   Handle to the PwrMgr instance
618  *  @param      procId      Processor ID addressed by this PwrMgr instance.
619  *
620  *  @sa         VAYUIPUPWR_close
621  */
622 Int
623 VAYUIPUPWR_open (VAYUIPUPWR_Handle * handlePtr, UInt16 procId)
625     Int status = PWRMGR_SUCCESS;
627     GT_2trace (curTrace, GT_ENTER, "VAYUIPUPWR_open", handlePtr, procId);
629     GT_assert (curTrace, (handlePtr != NULL));
630     GT_assert (curTrace, IS_VALID_PROCID (procId));
632     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
634 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
635     if (VAYUIPUPWR_state.refCount == 0) {
636         GT_setFailureReason (curTrace,
637                              GT_4CLASS,
638                              "VAYUIPUPWR_open",
639                              VAYUIPUPWR_E_INVALIDSTATE,
640                              "Module was not initialized!");
641     }
642     else if (handlePtr == NULL) {
643         /*! @retval PWRMGR_E_HANDLE Invalid NULL handlePtr specified */
644         status = PWRMGR_E_HANDLE;
645         GT_setFailureReason (curTrace,
646                              GT_4CLASS,
647                              "VAYUIPUPWR_open",
648                              status,
649                              "Invalid NULL handlePtr specified");
650     }
651     else if (!IS_VALID_PROCID (procId)) {
652         /*! @retval PWRMGR_E_INVALIDARG Invalid procId specified */
653         status = PWRMGR_E_INVALIDARG;
654         GT_setFailureReason (curTrace,
655                              GT_4CLASS,
656                              "VAYUIPUPWR_open",
657                              status,
658                              "Invalid procId specified");
659     }
660     else {
661 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
662         /* Initialize return parameter handle. */
663         *handlePtr = NULL;
665         /* Check if the PwrMgr exists and return the handle if found. */
666         if (VAYUIPUPWR_state.pwrHandles [procId] == NULL) {
667             /*! @retval PWRMGR_E_NOTFOUND Specified instance not found */
668             status = PWRMGR_E_NOTFOUND;
669             GT_setFailureReason (curTrace,
670                               GT_4CLASS,
671                               "VAYUIPUPWR_open",
672                               status,
673                               "Specified VAYUIPUPWR instance does not exist!");
674         }
675         else {
676             *handlePtr = VAYUIPUPWR_state.pwrHandles [procId];
677         }
678 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
679     }
680 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
682     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_open", status);
684     /*! @retval PWRMGR_SUCCESS Operation successful */
685     return status;
688 /*!
689  *  @brief      Function to close a handle to an instance of this PwrMgr.
690  *
691  *  @param      handlePtr  Pointer to Handle to the PwrMgr instance
692  *
693  *  @sa         VAYUIPUPWR_open
694  */
695 Int
696 VAYUIPUPWR_close (VAYUIPUPWR_Handle * handlePtr)
698     Int status = PWRMGR_SUCCESS;
700     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_close", handlePtr);
702     GT_assert (curTrace, (handlePtr != NULL));
703     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
704     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
706 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
707     if (VAYUIPUPWR_state.refCount == 0) {
708         GT_setFailureReason (curTrace,
709                              GT_4CLASS,
710                              "VAYUIPUPWR_close",
711                              VAYUIPUPWR_E_INVALIDSTATE,
712                              "Module was not initialized!");
713     }
714     else if (handlePtr == NULL) {
715         /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr pointer
716                                          specified*/
717         status = PWRMGR_E_INVALIDARG;
718         GT_setFailureReason (curTrace,
719                              GT_4CLASS,
720                              "VAYUIPUPWR_close",
721                              status,
722                              "Invalid NULL handlePtr pointer specified");
723     }
724     else if (*handlePtr == NULL) {
725         /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
726         status = PWRMGR_E_HANDLE;
727         GT_setFailureReason (curTrace,
728                              GT_4CLASS,
729                              "VAYUIPUPWR_close",
730                              status,
731                              "Invalid NULL *handlePtr specified");
732     }
733     else {
734 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
735         /* Nothing to be done for close. */
736         *handlePtr = NULL;
737 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
738     }
739 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
741     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_close", status);
743     /*! @retval PWRMGR_SUCCESS Operation successful */
744     return status;
747 /* =============================================================================
748  * APIs called by PwrMgr module (part of function table interface)
749  * =============================================================================
750  */
751 /*!
752  *  @brief      Function to attach to the PwrMgr.
753  *
754  *  @param      handle  Handle to the PwrMgr instance
755  *  @param      params  Attach parameters
756  *
757  *  @sa         VAYUIPUPWR_detach
758  */
759 Int
760 VAYUIPUPWR_attach (PwrMgr_Handle handle, PwrMgr_AttachParams * params)
763     Int status                            = PWRMGR_SUCCESS;
764     PwrMgr_Object *          pwrMgrHandle = (PwrMgr_Object *) handle;
765     VAYUIPUPWR_Object *      object       = NULL;
766     UInt16                   ipu1ProcId   = MultiProc_getId("IPU1");
767     Memory_MapInfo           mapInfo;
768     /* Mapping for prcm base is done in VAYUIPUCORE1_phyShmemInit */
770     GT_2trace (curTrace, GT_ENTER, "VAYUIPUPWR_attach", handle, params);
772     GT_assert (curTrace, (handle != NULL));
773     GT_assert (curTrace, (params != NULL));
774     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
776 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
777     if (VAYUIPUPWR_state.refCount == 0) {
778         GT_setFailureReason (curTrace,
779                              GT_4CLASS,
780                              "VAYUIPUPWR_attach",
781                              VAYUIPUPWR_E_INVALIDSTATE,
782                              "Module was not initialized!");
783     }
784     else if (handle == NULL) {
785         /*! @retval PWRMGR_E_HANDLE Invalid argument */
786         status = PWRMGR_E_HANDLE;
787         GT_setFailureReason (curTrace,
788                              GT_4CLASS,
789                              "VAYUIPUPWR_attach",
790                              status,
791                              "Invalid handle specified");
792     }
793     else {
794 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
795         object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
796         GT_assert (curTrace, (object != NULL));
797         /* Map and get the virtual address for PRCM registers */
798         if (handle->procId == ipu1ProcId) {
799             mapInfo.src      = IPU1_PRCM_BASE_ADDR;
800         }
801         else {
802             mapInfo.src      = IPU2_PRCM_BASE_ADDR;
803         }
804         mapInfo.size     = PRCM_SIZE;
805         mapInfo.isCached = FALSE;
806         status = Memory_map (&mapInfo);
807 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
808         if (status < 0) {
809             status = VAYUIPUPWR_E_FAIL;
810             GT_setFailureReason (curTrace,
811                                  GT_4CLASS,
812                                  "VAYUIPUPWR_attach",
813                                  status,
814                                  "Failure in mapping prcm module");
815         }
816         else {
817 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
818             object->prcmVA = mapInfo.dst;
819             /* Map and get the virtual address for MMU registers */
820             if (handle->procId == ipu1ProcId) {
821                 mapInfo.src      = IPU1_MMU_BASE;
822             }
823             else {
824                 mapInfo.src      = IPU2_MMU_BASE;
825             }
826             mapInfo.size     = MMU_SIZE;
827             mapInfo.isCached = FALSE;
828             status = Memory_map (&mapInfo);
829 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
830             if (status < 0) {
831                 status = VAYUIPUPWR_E_FAIL;
832                 GT_setFailureReason (curTrace,
833                                      GT_4CLASS,
834                                      "VAYUIPUPWR_attach",
835                                      status,
836                                      "Failure in mapping ipummu module");
837             }
838             else {
839 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
840                 object->ipuMmuVA = mapInfo.dst;
841                 /* Map and get the virtual address for the control module */
842                 if (handle->procId == ipu1ProcId) {
843                     mapInfo.src      = IPU1_CM_BASE_ADDR;
844                 }
845                 else {
846                     mapInfo.src      = IPU2_CM_BASE_ADDR;
847                 }
848                 mapInfo.size     = CM_SIZE;
849                 mapInfo.isCached = FALSE;
850                 status = Memory_map (&mapInfo);
851 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
852                 if (status < 0) {
853                     status = VAYUIPUPWR_E_FAIL;
854                     GT_setFailureReason (curTrace,
855                                          GT_4CLASS,
856                                          "VAYUIPUPWR_attach",
857                                          status,
858                                          "Failure in mapping ipubase module");
859                 }
860                 else {
861 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
862                     object->ipubaseVA = mapInfo.dst;
863 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
864                 }
865             }
866         }
867     }
868 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
870     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_attach", status);
871     /*! @retval PWRMGR_SUCCESS Operation successful */
872     return (status);
875 /*!
876  *  @brief      Function to detach from the PwrMgr.
877  *
878  *  @param      handle  Handle to the PwrMgr instance
879  *
880  *  @sa         VAYUIPUPWR_attach
881  */
882 Int
883 VAYUIPUPWR_detach (PwrMgr_Handle handle)
885     Int status                     = PWRMGR_SUCCESS;
886     PwrMgr_Object * pwrMgrHandle   = (PwrMgr_Object *) handle;
887     VAYUIPUPWR_Object * object = NULL;
888     Memory_UnmapInfo     unmapInfo;
891     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_detach", handle);
893     GT_assert (curTrace, (handle != NULL));
894     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
896 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
897     if (VAYUIPUPWR_state.refCount == 0) {
898         GT_setFailureReason (curTrace,
899                              GT_4CLASS,
900                              "VAYUIPUPWR_detach",
901                              VAYUIPUPWR_E_INVALIDSTATE,
902                              "Module was not initialized!");
903     }
904     else if (handle == NULL) {
905         /*! @retval PWRMGR_E_HANDLE Invalid argument */
906         status = PWRMGR_E_HANDLE;
907         GT_setFailureReason (curTrace,
908                              GT_4CLASS,
909                              "VAYUIPUPWR_detach",
910                              status,
911                              "Invalid handle specified");
912     }
913     else {
914 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
915         object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
916         GT_assert (curTrace, (object != NULL));
918         /* Unmap the virtual address for prcm module */
919         unmapInfo.addr = object->prcmVA;
920         unmapInfo.size = PRCM_SIZE;
921         unmapInfo.isCached = FALSE;
922         if (unmapInfo.addr != 0) {
923             status = Memory_unmap (&unmapInfo);
924 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
925             if (status < 0) {
926                 status = VAYUIPUPWR_E_FAIL;
927                 GT_setFailureReason (curTrace,
928                                      GT_4CLASS,
929                                      "VAYUIPUPWR_detach",
930                                      status,
931                                      "Failure in mapping prcm module");
932             }
933 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
934         }
935         /* Unmap the virtual address for mmu base*/
936         unmapInfo.addr = object->ipuMmuVA;
937         unmapInfo.size = MMU_SIZE;
938         unmapInfo.isCached = FALSE;
939         if (unmapInfo.addr != 0) {
940             status = Memory_unmap (&unmapInfo);
941 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
942             if (status < 0) {
943                 status = VAYUIPUPWR_E_FAIL;
944                 GT_setFailureReason (curTrace,
945                                      GT_4CLASS,
946                                      "VAYUIPUPWR_detach",
947                                      status,
948                                      "Failure in mapping ipuMmu module");
949             }
950 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
951         }
953         /* Unmap the virtual address for ipu control base */
954         unmapInfo.addr = object->ipubaseVA;
955         unmapInfo.size = CM_SIZE;
956         unmapInfo.isCached = FALSE;
957         if (unmapInfo.addr != 0) {
958             status = Memory_unmap (&unmapInfo);
959 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
960             if (status < 0) {
961                 status = VAYUIPUPWR_E_FAIL;
962                 GT_setFailureReason (curTrace,
963                                      GT_4CLASS,
964                                      "VAYUIPUPWR_detach",
965                                      status,
966                                      "Failure in mapping ipuMmu module");
967             }
968 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
969         }
970 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
971     }
972 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
974     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_detach", status);
975     /*! @retval PWRMGR_SUCCESS Operation successful */
976     return (status);
979 /*!
980  *  @brief      Function to power on the slave processor.
981  *
982  *              Power on the IVA subsystem, hold the DSP and SEQ in reset, and
983  *              release IVA2_RST. This is a hostile reset of the IVA. If the IVA
984  *              is already powered on, then it must be powered off in order to
985  *              terminate all current activity and initiate a power-on-reset
986  *              transition to bring the IVA to a know good state.
987  *
988  *  @param      handle    Handle to the PwrMgr instance
989  *
990  *  @sa         VAYUIPUPWR_off
991  */
992 Int
993 VAYUIPUPWR_on (PwrMgr_Handle handle)
995     Int                  status       = PWRMGR_SUCCESS ;
996     Int32                tmpstatus    = 0;
997     PwrMgr_Object *      pwrMgrHandle = (PwrMgr_Object *) handle;
998     VAYUIPUPWR_Object * object   = NULL;
999     IArg                     key;
1000     (Void)tmpstatus;
1001     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_on", handle);
1003     GT_assert (curTrace, (handle != NULL));
1004     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
1006 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1007     if (VAYUIPUPWR_state.refCount == 0) {
1008         GT_setFailureReason (curTrace,
1009                              GT_4CLASS,
1010                              "VAYUIPUPWR_on",
1011                              VAYUIPUPWR_E_INVALIDSTATE,
1012                              "Module was not initialized!");
1013     }
1014     else {
1015 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1016         /* This sets the refCount variable is not initialized, upper 16 bits is
1017          * written with module Id to ensure correctness of refCount variable.
1018          */
1019         key = Gate_enterSystem();
1020         VAYUIPUPWR_state.pwrstateRefCount++;
1021         if (VAYUIPUPWR_state.pwrstateRefCount > 1) {
1022             status = VAYUIPUPWR_S_ALREADYSETUP;
1023             Gate_leaveSystem(key);
1024         }
1025         else {
1026             Gate_leaveSystem(key);
1027 #if !defined(IPC_BUILD_OPTIMIZE)&& defined(IPC_BUILD_HLOS)
1028             if (handle == NULL) {
1029                 /*! @retval PWRMGR_E_HANDLE Invalid argument */
1030                 status = PWRMGR_E_HANDLE;
1031                 GT_setFailureReason (curTrace,
1032                                      GT_4CLASS,
1033                                      "VAYUIPUPWR_on",
1034                                      status,
1035                                      "Invalid handle specified");
1036             }
1037             else {
1038 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
1039                  object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
1041                  GT_assert (curTrace, (object != NULL));
1042                  /* Enable spinlocks, mailbox and timers before powering on ipu */
1044                  VAYUIPUPWR_state.ipuSpinlockHandle
1045                             = ClockOps_get(object->clockHandle, "spinbox_ick");
1046                      /* Do not put this check under IPC_BUILD_OPTIMIZE */
1047                  GT_assert (curTrace,
1048                                (VAYUIPUPWR_state.ipuSpinlockHandle != NULL));
1049                  status = ClockOps_enable(object->clockHandle,
1050                                          VAYUIPUPWR_state.ipuSpinlockHandle);
1051                  GT_assert (curTrace, (status >= 0));
1053                  VAYUIPUPWR_state.ipuMailboxHandle
1054                             = ClockOps_get(object->clockHandle, "mailbox_ick");
1055                              /* Do not put this check under IPC_BUILD_OPTIMIZE */
1056                  GT_assert (curTrace, (VAYUIPUPWR_state.ipuMailboxHandle != NULL));
1057                  status = ClockOps_enable(object->clockHandle,
1058                                           VAYUIPUPWR_state.ipuMailboxHandle);
1059                  GT_assert (curTrace, (status >= 0));
1061                  /* poer on ipu */
1062                  VAYUIPUPWR_state.ipuClkHandle
1063                              = ClockOps_get(object->clockHandle, "ipu_ick");
1064                  /* Do not put this check under IPC_BUILD_OPTIMIZE */
1065                  if (VAYUIPUPWR_state.ipuClkHandle == NULL) {
1066                          /*! @retval PWRMGR_E_HANDLE Invalid argument */
1067                          status = PWRMGR_E_HANDLE;
1068                          GT_setFailureReason (curTrace,
1069                                               GT_4CLASS,
1070                                               "VAYUIPUPWR_on",
1071                                               status,
1072                                           "object->clkHandle retuned NULL clk_get failed for ipu");
1073                  }
1074                  else {
1075                      tmpstatus = ClockOps_enable(object->clockHandle,
1076                                               VAYUIPUPWR_state.ipuClkHandle);
1077                      GT_assert (curTrace, (tmpstatus >= 0));
1078                      /* Complete the remaining power sequence here*/
1079                      VAYUIPUMMU_enable(pwrMgrHandle);
1080                  }
1081 #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS)
1082             }
1083 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS)*/
1084         }
1085 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1086     }
1087 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)*/
1088     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_on", status);
1089     /*! @retval PWRMGR_SUCCESS Operation successful */
1090     return (status);
1093 /*!
1094  *  @brief      Function to power off the slave processor.
1095  *
1096  *              Turn the IVA power domain off. To ensure a clean power-off
1097  *              transition, the IVA subsystem must first be turned on so that
1098  *              the DSP can initiate an autonomous power-off transition.
1099  *
1100  *  @param      handle    Handle to the PwrMgr instance
1101  *  @param      force     Indicates whether power-off is to be forced
1102  *
1103  *  @sa         VAYUIPUPWR_on
1104  */
1105 Int
1106 VAYUIPUPWR_off (PwrMgr_Handle handle, Bool force)
1108     Int                  status       = PWRMGR_SUCCESS ;
1109     PwrMgr_Object *      pwrMgrHandle = (PwrMgr_Object *) handle;
1110     VAYUIPUPWR_Object * object   = NULL;
1111     IArg                     key;
1113     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_off", handle);
1115     GT_assert (curTrace, (handle != NULL));
1117     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
1119 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1120     if (VAYUIPUPWR_state.refCount == 0) {
1121         GT_setFailureReason (curTrace,
1122                              GT_4CLASS,
1123                              "VAYUIPUPWR_off",
1124                              VAYUIPUPWR_E_INVALIDSTATE,
1125                              "Module was not initialized!");
1126     }
1127     else if (handle == NULL) {
1128         /*! @retval PWRMGR_E_HANDLE Invalid argument */
1129         status = PWRMGR_E_HANDLE;
1130         GT_setFailureReason (curTrace,
1131                              GT_4CLASS,
1132                              "VAYUIPUPWR_off",
1133                              status,
1134                              "Invalid handle specified");
1135     }
1136     else {
1137 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1138                  object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
1139         key = Gate_enterSystem();
1140         VAYUIPUPWR_state.pwrstateRefCount--;
1141         Gate_leaveSystem(key);
1143         if (VAYUIPUPWR_state.pwrstateRefCount == 0) {
1144             VAYUIPUMMU_disable(pwrMgrHandle);
1145             /* Disable Mailbox clocks */
1146             if(VAYUIPUPWR_state.ipuMailboxHandle) {
1147                 ClockOps_disable(object->clockHandle,
1148                                      VAYUIPUPWR_state.ipuMailboxHandle);
1149                 ClockOps_put(object->clockHandle,
1150                                      VAYUIPUPWR_state.ipuMailboxHandle);
1151             }
1152             /* Disable Spinlock clocks */
1153             if(VAYUIPUPWR_state.ipuSpinlockHandle) {
1154                 ClockOps_disable(object->clockHandle,
1155                                     VAYUIPUPWR_state.ipuSpinlockHandle);
1156                 ClockOps_put(object->clockHandle,
1157                                     VAYUIPUPWR_state.ipuSpinlockHandle);
1158             }
1159             if(VAYUIPUPWR_state.ipuClkHandle) {
1160                 ClockOps_disable(object->clockHandle,
1161                                          VAYUIPUPWR_state.ipuClkHandle);
1162                 ClockOps_put(object->clockHandle,
1163                                          VAYUIPUPWR_state.ipuClkHandle);
1164             }
1165         }
1166 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1167     }
1168 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined(IPC_BUILD_HLOS) */
1169     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_off", status);
1170     /*! @retval PWRMGR_SUCCESS Operation successful */
1171     return (status);
1174 #if defined (__cplusplus)
1176 #endif /* defined (__cplusplus) */