46d6747c3dbff254d2783fb541d5172b833b906e
[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-2014, 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(SYSLINK_BUILD_DEBUG)
138 static
139 #endif /* if !defined(SYSLINK_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(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_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(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_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(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
200     }
201 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_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 #if defined(SYSLINK_BUILD_RTOS)
235     Error_init(&eb);
236 #endif /* #if defined(SYSLINK_BUILD_RTOS) */
237 #if defined(SYSLINK_BUILD_HLOS)
238     eb = 0;
239 #endif /* #if defined(SYSLINK_BUILD_HLOS) */
241     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_setup", cfg);
242     if (cfg == NULL) {
243         VAYUIPUPWR_getConfig (&tmpCfg);
244         cfg = &tmpCfg;
245     }
247     /* This sets the refCount variable is not initialized, upper 16 bits is
248      * written with module Id to ensure correctness of refCount variable.
249      */
250     key = Gate_enterSystem();
251     VAYUIPUPWR_state.refCount++;
252     if (VAYUIPUPWR_state.refCount > 1) {
253         status = VAYUIPUPWR_S_ALREADYSETUP;
254         Gate_leaveSystem(key);
255     }
256     else {
257         Gate_leaveSystem(key);
259         /* Create a default gate handle for local module protection. */
260         VAYUIPUPWR_state.gateHandle = (IGateProvider_Handle)
261                                 GateMutex_create ((GateMutex_Params*)NULL, &eb);
262         if (VAYUIPUPWR_state.gateHandle == NULL) {
263             key = Gate_enterSystem();
264             VAYUIPUPWR_state.refCount = 0;
265             Gate_leaveSystem(key);
266             /*! @retval PWRMGR_E_FAIL Failed to create GateMutex! */
267             status = PWRMGR_E_FAIL;
268             GT_setFailureReason (curTrace,
269                                  GT_4CLASS,
270                                  "VAYUIPUPWR_setup",
271                                  status,
272                                  "Failed to create GateMutex!");
273         }
274         else {
275             /* Copy the user provided values into the state object. */
276             memcpy (&VAYUIPUPWR_state.cfg,
277                          cfg,
278                          sizeof (VAYUIPUPWR_Config));
280             /* Initialize the name to handles mapping array. */
281             memset (&VAYUIPUPWR_state.pwrHandles,
282                         0,
283                         (sizeof (VAYUIPUPWR_Handle) * MultiProc_MAXPROCESSORS));
284             VAYUIPUPWR_state.isSetup = TRUE;
285         }
286     }
288     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_setup", status);
289     /*! @retval PWRMGR_SUCCESS Operation successful */
290     return (status);
293 /*!
294  *  @brief      Function to destroy the VAYUIPUPWR module.
295  *
296  *              Once this function is called, other VAYUIPUPWR module APIs, except
297  *              for the VAYUIPUPWR_getConfig API cannot be called anymore.
298  *
299  *  @sa         VAYUIPUPWR_setup
300  *              GateMutex_delete
301  */
302 Int
303 VAYUIPUPWR_destroy (Void)
305     Int    status = PWRMGR_SUCCESS;
306     UInt16 i;
307     IArg key;
309     GT_0trace (curTrace, GT_ENTER, "VAYUIPUPWR_destroy");
311     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
313 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
314     if (VAYUIPUPWR_state.refCount == 0) {
315         status = VAYUIPUPWR_E_INVALIDSTATE;
316         GT_setFailureReason (curTrace,
317                              GT_4CLASS,
318                              "VAYUIPUPWR_destroy",
319                              status,
320                              "Module was not initialized!");
321     }
322     else {
323 #endif /* !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
324         key = Gate_enterSystem();
325         VAYUIPUPWR_state.refCount--;
326         Gate_leaveSystem(key);
328         if (VAYUIPUPWR_state.refCount == 0) {
329             /* Temporarily increment refCount here. */
330             key = Gate_enterSystem();
331             VAYUIPUPWR_state.refCount = 1;
332             Gate_leaveSystem(key);
334             /* Check if any VAYUIPUPWR instances have not been deleted so far. If not,
335              * delete them.
336              */
337             for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
338                 GT_assert (curTrace, (VAYUIPUPWR_state.pwrHandles [i] == NULL));
339                 if (VAYUIPUPWR_state.pwrHandles [i] != NULL) {
340                     VAYUIPUPWR_delete (&(VAYUIPUPWR_state.pwrHandles [i]));
341                 }
342             }
343             /* restore refCount here. */
344             key = Gate_enterSystem();
345             VAYUIPUPWR_state.refCount = 0;
346             Gate_leaveSystem(key);
348             if (VAYUIPUPWR_state.gateHandle != NULL) {
349                 GateMutex_delete ((GateMutex_Handle *)
350                                         &(VAYUIPUPWR_state.gateHandle));
351             }
352             VAYUIPUPWR_state.isSetup = FALSE;
353         }
354 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
355     }
356 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
357     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_destroy", status);
359     /*! @retval PWRMGR_SUCCESS Operation successful */
360     return (status);
363 /*!
364  *  @brief      Function to initialize the parameters for this PwrMgr instance.
365  *
366  *  @param      params  Configuration parameters.
367  *
368  *  @sa         VAYUIPUPWR_create
369  */
370 Void
371 VAYUIPUPWR_Params_init (VAYUIPUPWR_Params * params)
373     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_Params_init", params);
375     GT_assert (curTrace, (params != NULL));
376     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
378 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
379     if (VAYUIPUPWR_state.refCount == 0) {
380         GT_setFailureReason (curTrace,
381                              GT_4CLASS,
382                              "VAYUIPUPWR_Params_initv",
383                              VAYUIPUPWR_E_INVALIDSTATE,
384                              "Module was not initialized!");
385     }
386     else if (params == NULL) {
387         GT_setFailureReason (curTrace,
388                              GT_4CLASS,
389                              "VAYUIPUPWR_Params_init",
390                              PWRMGR_E_INVALIDARG,
391                              "Argument of type (VAYUIPUPWR_Params *) "
392                              "passed is null!");
393     }
394     else {
395 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
396         params->reserved = 0;
397 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
398     }
399 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
401     GT_0trace (curTrace, GT_LEAVE, "VAYUIPUPWR_Params_init");
404 /*!
405  *  @brief      Function to create an instance of this PwrMgr.
406  *
407  *  @param      procId  Processor ID addressed by this PwrMgr instance.
408  *  @param      params  Configuration parameters.
409  *
410  *  @sa         VAYUIPUPWR_delete
411  */
412 VAYUIPUPWR_Handle
413 VAYUIPUPWR_create (      UInt16               procId,
414                     const VAYUIPUPWR_Params * params)
416     Int                  status = PWRMGR_SUCCESS;
417     PwrMgr_Object *      handle = NULL;
418     IArg                 key;
420     GT_2trace (curTrace, GT_ENTER, "VAYUIPUPWR_create", procId, params);
422     GT_assert (curTrace, IS_VALID_PROCID (procId));
423     GT_assert (curTrace, (params != NULL));
424     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
426 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
427     if (VAYUIPUPWR_state.refCount == 0) {
428         GT_setFailureReason (curTrace,
429                              GT_4CLASS,
430                              "VAYUIPUPWR_create",
431                              VAYUIPUPWR_E_INVALIDSTATE,
432                              "Module was not initialized!");
433     }
434     else if (!IS_VALID_PROCID (procId)) {
435         /* Not setting status here since this function does not return status.*/
436         GT_setFailureReason (curTrace,
437                              GT_4CLASS,
438                              "VAYUIPUPWR_create",
439                              PWRMGR_E_INVALIDARG,
440                              "Invalid procId specified");
441     }
442     else if (params == NULL) {
443         GT_setFailureReason (curTrace,
444                              GT_4CLASS,
445                              "VAYUIPUPWR_create",
446                              PWRMGR_E_INVALIDARG,
447                              "params passed is null!");
448     }
449     else {
450 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
451         /* Enter critical section protection. */
452         key = IGateProvider_enter (VAYUIPUPWR_state.gateHandle);
453 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
454         /* Check if the PwrMgr already exists for specified procId. */
455         if (VAYUIPUPWR_state.pwrHandles [procId] != NULL) {
456             status = PWRMGR_E_ALREADYEXIST;
457             GT_setFailureReason (curTrace,
458                                  GT_4CLASS,
459                                  "VAYUIPUPWR_create",
460                                  status,
461                                  "PwrMgr already exists for specified procId!");
462         }
463         else {
464 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
465             /* Allocate memory for the handle */
466             handle = (PwrMgr_Object *) Memory_calloc (NULL,
467                                                       sizeof (PwrMgr_Object),
468                                                       0,
469                                                       NULL);
470             if (handle == NULL) {
471                 GT_setFailureReason (curTrace,
472                                      GT_4CLASS,
473                                      "VAYUIPUPWR_create",
474                                      PWRMGR_E_MEMORY,
475                                      "Memory allocation failed for handle!");
476             }
477             else {
478                 /* Populate the handle fields */
479                 handle->pwrFxnTable.attach = &VAYUIPUPWR_attach;
480                 handle->pwrFxnTable.detach = &VAYUIPUPWR_detach;
481                 handle->pwrFxnTable.on     = &VAYUIPUPWR_on;
482                 handle->pwrFxnTable.off    = &VAYUIPUPWR_off;
483                 /* TBD: Other functions */
485                 /* Allocate memory for the VAYUIPUPWR handle */
486                 handle->object = Memory_calloc (NULL,
487                                                 sizeof (VAYUIPUPWR_Object),
488                                                 0,
489                                                 NULL);
490                 if (handle == NULL) {
491                     status = PWRMGR_E_MEMORY;
492                     GT_setFailureReason (curTrace,
493                                         GT_4CLASS,
494                                         "VAYUIPUPWR_create",
495                                         status,
496                                         "Memory allocation failed for handle!");
497                 }
498                 else {
499 #if defined (SYSLINK_BUILDOS_LINUX)
500                     ((VAYUIPUPWR_Object *)handle->object)->clockHandle
501                                        = (ClockOps_Handle) LinuxClock_create();
502 #endif/* #if defined (SYSLINK_BUILDOS_LINUX) */
503 #if defined (SYSLINK_BUILD_RTOS)
504                     ((VAYUIPUPWR_Object *)handle->object)->clockHandle
505                                        = (ClockOps_Handle) VAYUCLOCK_create();
506 #endif/* #if defined (SYSLINK_BUILD_RTOS) */
507                     handle->procId = procId;
508                     VAYUIPUPWR_state.pwrHandles [procId] =
509                                                 (VAYUIPUPWR_Handle) handle;
510                 }
511             }
512 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
513         }
514 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
515         /* Leave critical section protection. */
516         IGateProvider_leave (VAYUIPUPWR_state.gateHandle, key);
517 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
518     }
519 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
521     if (status < 0) {
522         if (handle !=  NULL) {
523             if (handle->object != NULL) {
524                 Memory_free (NULL, handle->object, sizeof (VAYUIPUPWR_Object));
525             }
526             Memory_free (NULL, handle, sizeof (PwrMgr_Object));
527         }
528         /*! @retval NULL Function failed */
529         handle = NULL;
530     }
532     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_create", handle);
534     /*! @retval Valid-Handle Operation successful */
535     return (VAYUIPUPWR_Handle) handle;
538 /*!
539  *  @brief      Function to delete an instance of this PwrMgr.
540  *
541  *              The user provided pointer to the handle is reset after
542  *              successful completion of this function.
543  *
544  *  @param      handlePtr  Pointer to Handle to the PwrMgr instance
545  *
546  *  @sa         VAYUIPUPWR_create
547  */
548 Int
549 VAYUIPUPWR_delete (VAYUIPUPWR_Handle * handlePtr)
551     Int                  status = PWRMGR_SUCCESS;
552     VAYUIPUPWR_Object * object = NULL;
553     PwrMgr_Object *      handle;
554     IArg                 key;
556     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_delete", handlePtr);
558     GT_assert (curTrace, (handlePtr != NULL));
559     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
561     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
563 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
564     if (VAYUIPUPWR_state.refCount == 0) {
565         GT_setFailureReason (curTrace,
566                              GT_4CLASS,
567                              "VAYUIPUPWR_delete",
568                              VAYUIPUPWR_E_INVALIDSTATE,
569                              "Module was not initialized!");
570     }
571     else if (handlePtr == NULL) {
572         /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr specified*/
573         status = PWRMGR_E_INVALIDARG;
574         GT_setFailureReason (curTrace,
575                              GT_4CLASS,
576                              "VAYUIPUPWR_delete",
577                              status,
578                              "Invalid NULL handlePtr specified");
579     }
580     else if (*handlePtr == NULL) {
581         /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
582         status = PWRMGR_E_HANDLE;
583         GT_setFailureReason (curTrace,
584                              GT_4CLASS,
585                              "VAYUIPUPWR_delete",
586                              status,
587                              "Invalid NULL *handlePtr specified");
588     }
589     else {
590 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
591         handle = (PwrMgr_Object *) (*handlePtr);
592         /* Enter critical section protection. */
593         key = IGateProvider_enter (VAYUIPUPWR_state.gateHandle);
595         /* Reset handle in PwrMgr handle array. */
596         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
597         VAYUIPUPWR_state.pwrHandles [handle->procId] = NULL;
599         object = (VAYUIPUPWR_Object *) handle->object;
600         /* Free memory used for the VAYUIPUPWR object. */
601         if (handle->object != NULL) {
602             /* Free memory used for the clock handle */
603 #if defined (SYSLINK_BUILDOS_LINUX)
604             LinuxClock_delete(((VAYUIPUPWR_Object *)handle->object)->clockHandle);
605 #endif /* #if defined (SYSLINK_BUILDOS_LINUX) */
606 #if defined (SYSLINK_BUILD_RTOS)
607             VAYUCLOCK_delete(((VAYUIPUPWR_Object *)handle->object)->clockHandle);
608 #endif /* #if defined (SYSLINK_BUILD_RTOS) */
609             Memory_free (NULL,
610                          object,
611                          sizeof (VAYUIPUPWR_Object));
612             handle->object = NULL;
613         }
615         /* Free memory used for the PwrMgr object. */
616         Memory_free (NULL, handle, sizeof (PwrMgr_Object));
617         *handlePtr = NULL;
619         /* Leave critical section protection. */
620         IGateProvider_leave (VAYUIPUPWR_state.gateHandle, key);
621 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
622     }
623 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
625     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_delete", status);
627     /*! @retval PWRMGR_SUCCESS Operation successful */
628     return (status);
631 /*!
632  *  @brief      Function to open a handle to an instance of this PwrMgr. This
633  *              function is called when access to the PwrMgr is required from
634  *              a different process.
635  *
636  *  @param      handlePtr   Handle to the PwrMgr instance
637  *  @param      procId      Processor ID addressed by this PwrMgr instance.
638  *
639  *  @sa         VAYUIPUPWR_close
640  */
641 Int
642 VAYUIPUPWR_open (VAYUIPUPWR_Handle * handlePtr, UInt16 procId)
644     Int status = PWRMGR_SUCCESS;
646     GT_2trace (curTrace, GT_ENTER, "VAYUIPUPWR_open", handlePtr, procId);
648     GT_assert (curTrace, (handlePtr != NULL));
649     GT_assert (curTrace, IS_VALID_PROCID (procId));
651     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
653 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
654     if (VAYUIPUPWR_state.refCount == 0) {
655         GT_setFailureReason (curTrace,
656                              GT_4CLASS,
657                              "VAYUIPUPWR_open",
658                              VAYUIPUPWR_E_INVALIDSTATE,
659                              "Module was not initialized!");
660     }
661     else if (handlePtr == NULL) {
662         /*! @retval PWRMGR_E_HANDLE Invalid NULL handlePtr specified */
663         status = PWRMGR_E_HANDLE;
664         GT_setFailureReason (curTrace,
665                              GT_4CLASS,
666                              "VAYUIPUPWR_open",
667                              status,
668                              "Invalid NULL handlePtr specified");
669     }
670     else if (!IS_VALID_PROCID (procId)) {
671         /*! @retval PWRMGR_E_INVALIDARG Invalid procId specified */
672         status = PWRMGR_E_INVALIDARG;
673         GT_setFailureReason (curTrace,
674                              GT_4CLASS,
675                              "VAYUIPUPWR_open",
676                              status,
677                              "Invalid procId specified");
678     }
679     else {
680 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
681         /* Initialize return parameter handle. */
682         *handlePtr = NULL;
684         /* Check if the PwrMgr exists and return the handle if found. */
685         if (VAYUIPUPWR_state.pwrHandles [procId] == NULL) {
686             /*! @retval PWRMGR_E_NOTFOUND Specified instance not found */
687             status = PWRMGR_E_NOTFOUND;
688             GT_setFailureReason (curTrace,
689                               GT_4CLASS,
690                               "VAYUIPUPWR_open",
691                               status,
692                               "Specified VAYUIPUPWR instance does not exist!");
693         }
694         else {
695             *handlePtr = VAYUIPUPWR_state.pwrHandles [procId];
696         }
697 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
698     }
699 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
701     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_open", status);
703     /*! @retval PWRMGR_SUCCESS Operation successful */
704     return status;
707 /*!
708  *  @brief      Function to close a handle to an instance of this PwrMgr.
709  *
710  *  @param      handlePtr  Pointer to Handle to the PwrMgr instance
711  *
712  *  @sa         VAYUIPUPWR_open
713  */
714 Int
715 VAYUIPUPWR_close (VAYUIPUPWR_Handle * handlePtr)
717     Int status = PWRMGR_SUCCESS;
719     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_close", handlePtr);
721     GT_assert (curTrace, (handlePtr != NULL));
722     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
723     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
725 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
726     if (VAYUIPUPWR_state.refCount == 0) {
727         GT_setFailureReason (curTrace,
728                              GT_4CLASS,
729                              "VAYUIPUPWR_close",
730                              VAYUIPUPWR_E_INVALIDSTATE,
731                              "Module was not initialized!");
732     }
733     else if (handlePtr == NULL) {
734         /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr pointer
735                                          specified*/
736         status = PWRMGR_E_INVALIDARG;
737         GT_setFailureReason (curTrace,
738                              GT_4CLASS,
739                              "VAYUIPUPWR_close",
740                              status,
741                              "Invalid NULL handlePtr pointer specified");
742     }
743     else if (*handlePtr == NULL) {
744         /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
745         status = PWRMGR_E_HANDLE;
746         GT_setFailureReason (curTrace,
747                              GT_4CLASS,
748                              "VAYUIPUPWR_close",
749                              status,
750                              "Invalid NULL *handlePtr specified");
751     }
752     else {
753 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
754         /* Nothing to be done for close. */
755         *handlePtr = NULL;
756 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
757     }
758 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
760     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_close", status);
762     /*! @retval PWRMGR_SUCCESS Operation successful */
763     return status;
766 /* =============================================================================
767  * APIs called by PwrMgr module (part of function table interface)
768  * =============================================================================
769  */
770 /*!
771  *  @brief      Function to attach to the PwrMgr.
772  *
773  *  @param      handle  Handle to the PwrMgr instance
774  *  @param      params  Attach parameters
775  *
776  *  @sa         VAYUIPUPWR_detach
777  */
778 Int
779 VAYUIPUPWR_attach (PwrMgr_Handle handle, PwrMgr_AttachParams * params)
782     Int status                            = PWRMGR_SUCCESS;
783     PwrMgr_Object *          pwrMgrHandle = (PwrMgr_Object *) handle;
784     VAYUIPUPWR_Object *      object       = NULL;
785     UInt16                   ipu1ProcId   = MultiProc_getId("IPU1");
786     Memory_MapInfo           mapInfo;
787     /* Mapping for prcm base is done in VAYUIPUCORE1_phyShmemInit */
789     GT_2trace (curTrace, GT_ENTER, "VAYUIPUPWR_attach", handle, params);
791     GT_assert (curTrace, (handle != NULL));
792     GT_assert (curTrace, (params != NULL));
793     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
795 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
796     if (VAYUIPUPWR_state.refCount == 0) {
797         GT_setFailureReason (curTrace,
798                              GT_4CLASS,
799                              "VAYUIPUPWR_attach",
800                              VAYUIPUPWR_E_INVALIDSTATE,
801                              "Module was not initialized!");
802     }
803     else if (handle == NULL) {
804         /*! @retval PWRMGR_E_HANDLE Invalid argument */
805         status = PWRMGR_E_HANDLE;
806         GT_setFailureReason (curTrace,
807                              GT_4CLASS,
808                              "VAYUIPUPWR_attach",
809                              status,
810                              "Invalid handle specified");
811     }
812     else {
813 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
814         object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
815         GT_assert (curTrace, (object != NULL));
816         /* Map and get the virtual address for PRCM registers */
817         if (handle->procId == ipu1ProcId) {
818             mapInfo.src      = IPU1_PRCM_BASE_ADDR;
819         }
820         else {
821             mapInfo.src      = IPU2_PRCM_BASE_ADDR;
822         }
823         mapInfo.size     = PRCM_SIZE;
824         mapInfo.isCached = FALSE;
825         status = Memory_map (&mapInfo);
826 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
827         if (status < 0) {
828             status = VAYUIPUPWR_E_FAIL;
829             GT_setFailureReason (curTrace,
830                                  GT_4CLASS,
831                                  "VAYUIPUPWR_attach",
832                                  status,
833                                  "Failure in mapping prcm module");
834         }
835         else {
836 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
837             object->prcmVA = mapInfo.dst;
838             /* Map and get the virtual address for MMU registers */
839             if (handle->procId == ipu1ProcId) {
840                 mapInfo.src      = IPU1_MMU_BASE;
841             }
842             else {
843                 mapInfo.src      = IPU2_MMU_BASE;
844             }
845             mapInfo.size     = MMU_SIZE;
846             mapInfo.isCached = FALSE;
847             status = Memory_map (&mapInfo);
848 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
849             if (status < 0) {
850                 status = VAYUIPUPWR_E_FAIL;
851                 GT_setFailureReason (curTrace,
852                                      GT_4CLASS,
853                                      "VAYUIPUPWR_attach",
854                                      status,
855                                      "Failure in mapping ipummu module");
856             }
857             else {
858 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
859                 object->ipuMmuVA = mapInfo.dst;
860                 /* Map and get the virtual address for the control module */
861                 if (handle->procId == ipu1ProcId) {
862                     mapInfo.src      = IPU1_CM_BASE_ADDR;
863                 }
864                 else {
865                     mapInfo.src      = IPU2_CM_BASE_ADDR;
866                 }
867                 mapInfo.size     = CM_SIZE;
868                 mapInfo.isCached = FALSE;
869                 status = Memory_map (&mapInfo);
870 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
871                 if (status < 0) {
872                     status = VAYUIPUPWR_E_FAIL;
873                     GT_setFailureReason (curTrace,
874                                          GT_4CLASS,
875                                          "VAYUIPUPWR_attach",
876                                          status,
877                                          "Failure in mapping ipubase module");
878                 }
879                 else {
880 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
881                     object->ipubaseVA = mapInfo.dst;
882 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
883                 }
884             }
885         }
886     }
887 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
889     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_attach", status);
890     /*! @retval PWRMGR_SUCCESS Operation successful */
891     return (status);
894 /*!
895  *  @brief      Function to detach from the PwrMgr.
896  *
897  *  @param      handle  Handle to the PwrMgr instance
898  *
899  *  @sa         VAYUIPUPWR_attach
900  */
901 Int
902 VAYUIPUPWR_detach (PwrMgr_Handle handle)
904     Int status                     = PWRMGR_SUCCESS;
905     PwrMgr_Object * pwrMgrHandle   = (PwrMgr_Object *) handle;
906     VAYUIPUPWR_Object * object = NULL;
907     Memory_UnmapInfo     unmapInfo;
910     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_detach", handle);
912     GT_assert (curTrace, (handle != NULL));
913     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
915 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
916     if (VAYUIPUPWR_state.refCount == 0) {
917         GT_setFailureReason (curTrace,
918                              GT_4CLASS,
919                              "VAYUIPUPWR_detach",
920                              VAYUIPUPWR_E_INVALIDSTATE,
921                              "Module was not initialized!");
922     }
923     else if (handle == NULL) {
924         /*! @retval PWRMGR_E_HANDLE Invalid argument */
925         status = PWRMGR_E_HANDLE;
926         GT_setFailureReason (curTrace,
927                              GT_4CLASS,
928                              "VAYUIPUPWR_detach",
929                              status,
930                              "Invalid handle specified");
931     }
932     else {
933 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
934         object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
935         GT_assert (curTrace, (object != NULL));
937         /* Unmap the virtual address for prcm module */
938         unmapInfo.addr = object->prcmVA;
939         unmapInfo.size = PRCM_SIZE;
940         unmapInfo.isCached = FALSE;
941         if (unmapInfo.addr != 0) {
942             status = Memory_unmap (&unmapInfo);
943 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
944             if (status < 0) {
945                 status = VAYUIPUPWR_E_FAIL;
946                 GT_setFailureReason (curTrace,
947                                      GT_4CLASS,
948                                      "VAYUIPUPWR_detach",
949                                      status,
950                                      "Failure in mapping prcm module");
951             }
952 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
953         }
954         /* Unmap the virtual address for mmu base*/
955         unmapInfo.addr = object->ipuMmuVA;
956         unmapInfo.size = MMU_SIZE;
957         unmapInfo.isCached = FALSE;
958         if (unmapInfo.addr != 0) {
959             status = Memory_unmap (&unmapInfo);
960 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
961             if (status < 0) {
962                 status = VAYUIPUPWR_E_FAIL;
963                 GT_setFailureReason (curTrace,
964                                      GT_4CLASS,
965                                      "VAYUIPUPWR_detach",
966                                      status,
967                                      "Failure in mapping ipuMmu module");
968             }
969 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
970         }
972         /* Unmap the virtual address for ipu control base */
973         unmapInfo.addr = object->ipubaseVA;
974         unmapInfo.size = CM_SIZE;
975         unmapInfo.isCached = FALSE;
976         if (unmapInfo.addr != 0) {
977             status = Memory_unmap (&unmapInfo);
978 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
979             if (status < 0) {
980                 status = VAYUIPUPWR_E_FAIL;
981                 GT_setFailureReason (curTrace,
982                                      GT_4CLASS,
983                                      "VAYUIPUPWR_detach",
984                                      status,
985                                      "Failure in mapping ipuMmu module");
986             }
987 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
988         }
989 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
990     }
991 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
993     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_detach", status);
994     /*! @retval PWRMGR_SUCCESS Operation successful */
995     return (status);
998 /*!
999  *  @brief      Function to power on the slave processor.
1000  *
1001  *              Power on the IVA subsystem, hold the DSP and SEQ in reset, and
1002  *              release IVA2_RST. This is a hostile reset of the IVA. If the IVA
1003  *              is already powered on, then it must be powered off in order to
1004  *              terminate all current activity and initiate a power-on-reset
1005  *              transition to bring the IVA to a know good state.
1006  *
1007  *  @param      handle    Handle to the PwrMgr instance
1008  *
1009  *  @sa         VAYUIPUPWR_off
1010  */
1011 Int
1012 VAYUIPUPWR_on (PwrMgr_Handle handle)
1014     Int                  status       = PWRMGR_SUCCESS ;
1015     Int32                tmpstatus    = 0;
1016     PwrMgr_Object *      pwrMgrHandle = (PwrMgr_Object *) handle;
1017     VAYUIPUPWR_Object * object   = NULL;
1018     IArg                     key;
1019     (Void)tmpstatus;
1020     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_on", handle);
1022     GT_assert (curTrace, (handle != NULL));
1023     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
1025 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1026     if (VAYUIPUPWR_state.refCount == 0) {
1027         GT_setFailureReason (curTrace,
1028                              GT_4CLASS,
1029                              "VAYUIPUPWR_on",
1030                              VAYUIPUPWR_E_INVALIDSTATE,
1031                              "Module was not initialized!");
1032     }
1033     else {
1034 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1035         /* This sets the refCount variable is not initialized, upper 16 bits is
1036          * written with module Id to ensure correctness of refCount variable.
1037          */
1038         key = Gate_enterSystem();
1039         VAYUIPUPWR_state.pwrstateRefCount++;
1040         if (VAYUIPUPWR_state.pwrstateRefCount > 1) {
1041             status = VAYUIPUPWR_S_ALREADYSETUP;
1042             Gate_leaveSystem(key);
1043         }
1044         else {
1045             Gate_leaveSystem(key);
1046 #if !defined(SYSLINK_BUILD_OPTIMIZE)&& defined(SYSLINK_BUILD_HLOS)
1047             if (handle == NULL) {
1048                 /*! @retval PWRMGR_E_HANDLE Invalid argument */
1049                 status = PWRMGR_E_HANDLE;
1050                 GT_setFailureReason (curTrace,
1051                                      GT_4CLASS,
1052                                      "VAYUIPUPWR_on",
1053                                      status,
1054                                      "Invalid handle specified");
1055             }
1056             else {
1057 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
1058                  object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
1060                  GT_assert (curTrace, (object != NULL));
1061                  /* Enable spinlocks, mailbox and timers before powering on ipu */
1063                  VAYUIPUPWR_state.ipuSpinlockHandle
1064                             = ClockOps_get(object->clockHandle, "spinbox_ick");
1065                      /* Do not put this check under SYSLINK_BUILD_OPTIMIZE */
1066                  GT_assert (curTrace,
1067                                (VAYUIPUPWR_state.ipuSpinlockHandle != NULL));
1068                  status = ClockOps_enable(object->clockHandle,
1069                                          VAYUIPUPWR_state.ipuSpinlockHandle);
1070                  GT_assert (curTrace, (status >= 0));
1072                  VAYUIPUPWR_state.ipuMailboxHandle
1073                             = ClockOps_get(object->clockHandle, "mailbox_ick");
1074                              /* Do not put this check under SYSLINK_BUILD_OPTIMIZE */
1075                  GT_assert (curTrace, (VAYUIPUPWR_state.ipuMailboxHandle != NULL));
1076                  status = ClockOps_enable(object->clockHandle,
1077                                           VAYUIPUPWR_state.ipuMailboxHandle);
1078                  GT_assert (curTrace, (status >= 0));
1080                  /* poer on ipu */
1081                  VAYUIPUPWR_state.ipuClkHandle
1082                              = ClockOps_get(object->clockHandle, "ipu_ick");
1083                  /* Do not put this check under SYSLINK_BUILD_OPTIMIZE */
1084                  if (VAYUIPUPWR_state.ipuClkHandle == NULL) {
1085                          /*! @retval PWRMGR_E_HANDLE Invalid argument */
1086                          status = PWRMGR_E_HANDLE;
1087                          GT_setFailureReason (curTrace,
1088                                               GT_4CLASS,
1089                                               "VAYUIPUPWR_on",
1090                                               status,
1091                                           "object->clkHandle retuned NULL clk_get failed for ipu");
1092                  }
1093                  else {
1094                      tmpstatus = ClockOps_enable(object->clockHandle,
1095                                               VAYUIPUPWR_state.ipuClkHandle);
1096                      GT_assert (curTrace, (tmpstatus >= 0));
1097                      /* Complete the remaining power sequence here*/
1098                      VAYUIPUMMU_enable(pwrMgrHandle);
1099                  }
1100 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)
1101             }
1102 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS)*/
1103         }
1104 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1105     }
1106 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)*/
1107     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_on", status);
1108     /*! @retval PWRMGR_SUCCESS Operation successful */
1109     return (status);
1112 /*!
1113  *  @brief      Function to power off the slave processor.
1114  *
1115  *              Turn the IVA power domain off. To ensure a clean power-off
1116  *              transition, the IVA subsystem must first be turned on so that
1117  *              the DSP can initiate an autonomous power-off transition.
1118  *
1119  *  @param      handle    Handle to the PwrMgr instance
1120  *  @param      force     Indicates whether power-off is to be forced
1121  *
1122  *  @sa         VAYUIPUPWR_on
1123  */
1124 Int
1125 VAYUIPUPWR_off (PwrMgr_Handle handle, Bool force)
1127     Int                  status       = PWRMGR_SUCCESS ;
1128     PwrMgr_Object *      pwrMgrHandle = (PwrMgr_Object *) handle;
1129     VAYUIPUPWR_Object * object   = NULL;
1130     IArg                     key;
1132     GT_1trace (curTrace, GT_ENTER, "VAYUIPUPWR_off", handle);
1134     GT_assert (curTrace, (handle != NULL));
1136     GT_assert (curTrace, (VAYUIPUPWR_state.refCount != 0));
1138 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1139     if (VAYUIPUPWR_state.refCount == 0) {
1140         GT_setFailureReason (curTrace,
1141                              GT_4CLASS,
1142                              "VAYUIPUPWR_off",
1143                              VAYUIPUPWR_E_INVALIDSTATE,
1144                              "Module was not initialized!");
1145     }
1146     else if (handle == NULL) {
1147         /*! @retval PWRMGR_E_HANDLE Invalid argument */
1148         status = PWRMGR_E_HANDLE;
1149         GT_setFailureReason (curTrace,
1150                              GT_4CLASS,
1151                              "VAYUIPUPWR_off",
1152                              status,
1153                              "Invalid handle specified");
1154     }
1155     else {
1156 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */
1157                  object = (VAYUIPUPWR_Object *) pwrMgrHandle->object;
1158         key = Gate_enterSystem();
1159         VAYUIPUPWR_state.pwrstateRefCount--;
1160         Gate_leaveSystem(key);
1162         if (VAYUIPUPWR_state.pwrstateRefCount == 0) {
1163             VAYUIPUMMU_disable(pwrMgrHandle);
1164             /* Disable Mailbox clocks */
1165             if(VAYUIPUPWR_state.ipuMailboxHandle) {
1166                 ClockOps_disable(object->clockHandle,
1167                                      VAYUIPUPWR_state.ipuMailboxHandle);
1168                 ClockOps_put(object->clockHandle,
1169                                      VAYUIPUPWR_state.ipuMailboxHandle);
1170             }
1171             /* Disable Spinlock clocks */
1172             if(VAYUIPUPWR_state.ipuSpinlockHandle) {
1173                 ClockOps_disable(object->clockHandle,
1174                                     VAYUIPUPWR_state.ipuSpinlockHandle);
1175                 ClockOps_put(object->clockHandle,
1176                                     VAYUIPUPWR_state.ipuSpinlockHandle);
1177             }
1178             if(VAYUIPUPWR_state.ipuClkHandle) {
1179                 ClockOps_disable(object->clockHandle,
1180                                          VAYUIPUPWR_state.ipuClkHandle);
1181                 ClockOps_put(object->clockHandle,
1182                                          VAYUIPUPWR_state.ipuClkHandle);
1183             }
1184         }
1185 #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS)
1186     }
1187 #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined(SYSLINK_BUILD_HLOS) */
1188     GT_1trace (curTrace, GT_LEAVE, "VAYUIPUPWR_off", status);
1189     /*! @retval PWRMGR_SUCCESS Operation successful */
1190     return (status);
1193 #if defined (__cplusplus)
1195 #endif /* defined (__cplusplus) */