Remove references to SysLink in QNX code base
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / family / common / vayu / vayudsp / VAYUDspPwr.c
1 /*
2  *  @file   VAYUDspPwr.c
3  *
4  *  @brief      PwrMgr implementation for VAYUDSP.
5  *
6  *              This module is responsible for handling power requests for
7  *              the ProcMgr. The implementation is specific to VAYUDSP.
8  *
9  *
10  *  ============================================================================
11  *
12  *  Copyright (c) 2013-2015, Texas Instruments Incorporated
13  *
14  *  Redistribution and use in source and binary forms, with or without
15  *  modification, are permitted provided that the following conditions
16  *  are met:
17  *
18  *  *  Redistributions of source code must retain the above copyright
19  *     notice, this list of conditions and the following disclaimer.
20  *
21  *  *  Redistributions in binary form must reproduce the above copyright
22  *     notice, this list of conditions and the following disclaimer in the
23  *     documentation and/or other materials provided with the distribution.
24  *
25  *  *  Neither the name of Texas Instruments Incorporated nor the names of
26  *     its contributors may be used to endorse or promote products derived
27  *     from this software without specific prior written permission.
28  *
29  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
31  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
33  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
36  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
37  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
38  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *  Contact information for paper mail:
41  *  Texas Instruments
42  *  Post Office Box 655303
43  *  Dallas, Texas 75265
44  *  Contact information:
45  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
46  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
47  *  ============================================================================
48  *
49  */
53 /* Standard headers */
54 #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 <_MultiProc.h>
61 #include <string.h>
63 #include <ti/syslink/utils/Trace.h>
64 #include <Bitops.h>
66 /* Module level headers */
67 #include <ti/ipc/MultiProc.h>
68 #include <ti/syslink/inc/_MultiProc.h>
69 #include <ti/syslink/inc/knl/PwrDefs.h>
70 #include <ti/syslink/inc/knl/PwrMgr.h>
71 #include <ti/syslink/inc/knl/VAYUDspPwr.h>
72 #include <ti/syslink/inc/knl/_VAYUDspPwr.h>
73 #include <ti/syslink/inc/ClockOps.h>
77 #if defined (__cplusplus)
78 extern "C" {
79 #endif
82 /* =============================================================================
83  *  Macros and types
84  * =============================================================================
85  */
86 /*!
87  *  @brief  VAYUDSP module and mmr addresses (physical)
88  */
89 #define PRCM_BASE_ADDR              0x48180000
90 #define PRCM_SIZE                   0x00003000
91 #define PM_ACTIVE_PWRSTST           0x00000A04
92 #define CM_ACTIVE_GEM_CLKCTRL       0x00000420
95 #define CM_MMU_CLKSTCTRL            0x0000140C
96 #define CM_ALWON_MMUDATA_CLKCTRL    0x0000159C
97 #define CM_MMUCFG_CLKSTCTRL         0x00001410
98 #define CM_ALWON_MMUCFG_CLKCTRL     0x000015A8
101 #define RM_ACTIVE_RSTCTRL           0x00000A10
102 #define RM_ACTIVE_RSTST             0x00000A14
104 #define GEM_L2RAM_BASE_ADDR         0x40800000
105 #define GEM_L2RAM_SIZE              0x00040000
107 #define CTRL_MODULE_BASE_ADDR       0x48140000
108 #define CTRL_MODULE_SIZE            0x00020000
109 #define DSPMEM_SLEEP                0x00000650
111 #define DSP_IDLE_CFG                0x0000061c
113 #define REG(x)              *((volatile UInt32 *) (x))
114 #define MEM(x)              *((volatile UInt32 *) (x))
116 /*!
117  *  @brief  VAYUDSPPWR Module state object
118  */
119 typedef struct VAYUDSPPWR_ModuleObject_tag {
120     UInt32                configSize;
121     /*!< Size of configuration structure */
122     VAYUDSPPWR_Config       cfg;
123     /*!< VAYUDSPPWR configuration structure */
124     VAYUDSPPWR_Config       defCfg;
125     /*!< Default module configuration */
126     Bool                  isSetup;
127     /*!< Indicates whether the VAYUDSPPWR module is setup. */
128     VAYUDSPPWR_Handle       pwrHandles [MultiProc_MAXPROCESSORS];
129     /*!< PwrMgr handle array. */
130     IGateProvider_Handle           gateHandle;
131     /*!< Handle of gate to be used for local thread safety */
132 } VAYUDSPPWR_ModuleObject;
134 /*!
135  *  @brief  VAYUDSPPWR instance object.
136  */
137 struct VAYUDSPPWR_Object_tag {
138     VAYUDSPPWR_Params params;
139     /*!< Instance parameters (configuration values) */
140     UInt32             prcmVA;
141     /*!< Virtual address for prcm module */
142     UInt32             controlVA;
143     /*!< Virtual address for control module */
144     UInt32             l2baseVA;
145     /*!< Virtual address for control module */
146     Ptr                dspClkHandle;
147     /*!< dsp clk handle */
148     Ptr                dspMmuClkHandle;
149     /*!< dsp clk handle */
150     Ptr                dspMmuCfgClkHandle;
151     /*!< dsp clk handle */
152     Ptr                dspSpinlockHandle;
153     /*!< dsp Spinlock handle */
154     Ptr                dspMailboxHandle;
155     /*!< dsp Mailbox handle */
156     Ptr                dspTimerIclkHandle;
157     /*!< dsp Timer4 handle */
158     Ptr                dspTimerFclkHandle;
159     /*!< dsp Timer4 handle */
160     ClockOps_Handle    clockHandle;
161     /*!< Pointer to the Clock object. */
163 };
165 /* Defines the VAYUDSPPWR object type. */
166 typedef struct VAYUDSPPWR_Object_tag VAYUDSPPWR_Object;
169 /* =============================================================================
170  *  Globals
171  * =============================================================================
172  */
173 /*!
174  *  @var    VAYUDSPPWR_state
175  *
176  *  @brief  VAYUDSPPWR state object variable
177  */
178 #if !defined(IPC_BUILD_DEBUG)
179 static
180 #endif /* if !defined(IPC_BUILD_DEBUG) */
181 VAYUDSPPWR_ModuleObject VAYUDSPPWR_state =
183     .isSetup = FALSE,
184     .configSize = sizeof (VAYUDSPPWR_Config),
185     .defCfg.reserved = 0,
186     .gateHandle = NULL,
187 };
190 /* =============================================================================
191  * APIs directly called by applications
192  * =============================================================================
193  */
194 /*!
195  *  @brief      Function to get the default configuration for the VAYUDSPPWR
196  *              module.
197  *
198  *              This function can be called by the application to get their
199  *              configuration parameter to VAYUDSPPWR_setup filled in by the
200  *              VAYUDSPPWR module with the default parameters. If the user does
201  *              not wish to make any change in the default parameters, this API
202  *              is not required to be called.
203  *
204  *  @param      cfg        Pointer to the VAYUDSPPWR module configuration
205  *                         structure in which the default config is to be
206  *                         returned.
207  *
208  *  @sa         VAYUDSPPWR_setup
209  */
210 Void
211 VAYUDSPPWR_getConfig (VAYUDSPPWR_Config * cfg)
213     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_getConfig", cfg);
215     GT_assert (curTrace, (cfg != NULL));
217 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
218     if (cfg == NULL) {
219         GT_setFailureReason (curTrace,
220                              GT_4CLASS,
221                              "VAYUDSPPWR_getConfig",
222                              PWRMGR_E_INVALIDARG,
223                              "Argument of type (VAYUDSPPWR_Config *) passed "
224                              "is null!");
225     }
226     else {
227 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
228         memcpy (cfg,
229                      &VAYUDSPPWR_state.defCfg,
230                      sizeof (VAYUDSPPWR_Config));
231 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
232     }
233 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
235     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPWR_getConfig");
239 /*!
240  *  @brief      Function to setup the VAYUDSPPWR module.
241  *
242  *              This function sets up the VAYUDSPPWR module. This function must
243  *              be called before any other instance-level APIs can be invoked.
244  *              Module-level configuration needs to be provided to this
245  *              function. If the user wishes to change some specific config
246  *              parameters, then VAYUDSPPWR_getConfig can be called to get the
247  *              configuration filled with the default values. After this, only
248  *              the required configuration values can be changed. If the user
249  *              does not wish to make any change in the default parameters, the
250  *              application can simply call VAYUDSPPWR_setup with NULL
251  *              parameters. The default parameters would get automatically used.
252  *
253  *  @param      cfg   Optional VAYUDSPPWR module configuration. If provided as
254  *                    NULL, default configuration is used.
255  *
256  *  @sa         VAYUDSPPWR_destroy
257  *              GateMutex_create
258  */
259 Int
260 VAYUDSPPWR_setup (VAYUDSPPWR_Config * cfg)
262     Int               status = PWRMGR_SUCCESS;
263     VAYUDSPPWR_Config tmpCfg;
264     Error_Block eb;
266     Error_init(&eb);
268     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_setup", cfg);
270     if (cfg == NULL) {
271         VAYUDSPPWR_getConfig (&tmpCfg);
272         cfg = &tmpCfg;
273     }
275     /* Create a default gate handle for local module protection. */
276     VAYUDSPPWR_state.gateHandle = (IGateProvider_Handle)
277                              GateMutex_create ((GateMutex_Params*)NULL, &eb);
278 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
279     if (VAYUDSPPWR_state.gateHandle == NULL) {
280         /*! @retval PWRMGR_E_FAIL Failed to create GateMutex! */
281         status = PWRMGR_E_FAIL;
282         GT_setFailureReason (curTrace,
283                              GT_4CLASS,
284                              "VAYUDSPPWR_setup",
285                              status,
286                              "Failed to create GateMutex!");
287     }
288     else {
289 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
290         /* Copy the user provided values into the state object. */
291         Memory_copy (&VAYUDSPPWR_state.cfg,
292                      cfg,
293                      sizeof (VAYUDSPPWR_Config));
295         /* Initialize the name to handles mapping array. */
296         Memory_set (&VAYUDSPPWR_state.pwrHandles,
297                     0,
298                     (sizeof (VAYUDSPPWR_Handle) * MultiProc_MAXPROCESSORS));
299         VAYUDSPPWR_state.isSetup = TRUE;
300 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
301     }
302 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
304     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_setup", status);
306     /*! @retval PWRMGR_SUCCESS Operation successful */
307     return (status);
311 /*!
312  *  @brief      Function to destroy the VAYUDSPPWR module.
313  *
314  *              Once this function is called, other VAYUDSPPWR module APIs, except
315  *              for the VAYUDSPPWR_getConfig API cannot be called anymore.
316  *
317  *  @sa         VAYUDSPPWR_setup
318  *              GateMutex_delete
319  */
320 Int
321 VAYUDSPPWR_destroy (Void)
323     Int    status = PWRMGR_SUCCESS;
324     UInt16 i;
326     GT_0trace (curTrace, GT_ENTER, "VAYUDSPPWR_destroy");
328     /* Check if any VAYUDSPPWR instances have not been deleted so far. If not,
329      * delete them.
330      */
331     for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
332         GT_assert (curTrace, (VAYUDSPPWR_state.pwrHandles [i] == NULL));
333         if (VAYUDSPPWR_state.pwrHandles [i] != NULL) {
334             VAYUDSPPWR_delete (&(VAYUDSPPWR_state.pwrHandles [i]));
335         }
336     }
338     if (VAYUDSPPWR_state.gateHandle != NULL) {
339         GateMutex_delete ((GateMutex_Handle *)
340                                 &(VAYUDSPPWR_state.gateHandle));
341     }
343     VAYUDSPPWR_state.isSetup = FALSE;
345     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_destroy", status);
347     /*! @retval PWRMGR_SUCCESS Operation successful */
348     return (status);
352 /*!
353  *  @brief      Function to initialize the parameters for this PwrMgr instance.
354  *
355  *  @param      params  Configuration parameters.
356  *
357  *  @sa         VAYUDSPPWR_create
358  */
359 Void
360 VAYUDSPPWR_Params_init (VAYUDSPPWR_Params * params)
362     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_Params_init",params);
364     GT_assert (curTrace, (params != NULL));
366 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
367     if (params == NULL) {
368         GT_setFailureReason (curTrace,
369                              GT_4CLASS,
370                              "VAYUDSPPWR_Params_init",
371                              PWRMGR_E_INVALIDARG,
372                              "Argument of type (VAYUDSPPWR_Params *) "
373                              "passed is null!");
374     }
375     else {
376 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
377         /* Return updated VAYUDSPPWR instance specific parameters. */
378         params->reserved = 0;
379 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
380     }
381 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
383     GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPWR_Params_init");
386 /*!
387  *  @brief      Function to create an instance of this PwrMgr.
388  *
389  *  @param      procId  Processor ID addressed by this PwrMgr instance.
390  *  @param      params  Configuration parameters.
391  *
392  *  @sa         VAYUDSPPWR_delete
393  */
394 VAYUDSPPWR_Handle
395 VAYUDSPPWR_create (      UInt16               procId,
396                     const VAYUDSPPWR_Params * params)
398     Int                  status = PWRMGR_SUCCESS;
399     PwrMgr_Object *      handle = NULL;
400     IArg                 key;
402     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPWR_create", procId, params);
404     GT_assert (curTrace, IS_VALID_PROCID (procId));
405     GT_assert (curTrace, (params != NULL));
407 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
408     if (!IS_VALID_PROCID (procId)) {
409         status = PWRMGR_E_INVALIDARG;
410         GT_setFailureReason (curTrace,
411                              GT_4CLASS,
412                              "VAYUDSPPWR_create",
413                              status,
414                              "Invalid procId specified");
415     }
416     else if (params == NULL) {
417         status = PWRMGR_E_INVALIDARG;
418         GT_setFailureReason (curTrace,
419                              GT_4CLASS,
420                              "VAYUDSPPWR_create",
421                              status,
422                              "params passed is null!");
423     }
424     else {
425 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
426         /* Enter critical section protection. */
427         key = IGateProvider_enter (VAYUDSPPWR_state.gateHandle);
428 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
429         /* Check if the PwrMgr already exists for specified procId. */
430         if (VAYUDSPPWR_state.pwrHandles [procId] != NULL) {
431             status = PWRMGR_E_ALREADYEXIST;
432             GT_setFailureReason (curTrace,
433                                  GT_4CLASS,
434                                  "VAYUDSPPWR_create",
435                                  status,
436                                  "PwrMgr already exists for specified procId!");
437         }
438         else {
439 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
440             /* Allocate memory for the handle */
441             handle = (PwrMgr_Object *) Memory_calloc (NULL,
442                                                       sizeof (PwrMgr_Object),
443                                                       0,
444                                                       NULL);
445             if (handle == NULL) {
446                 status = PWRMGR_E_MEMORY;
447                 GT_setFailureReason (curTrace,
448                                      GT_4CLASS,
449                                      "VAYUDSPPWR_create",
450                                      status,
451                                      "Memory allocation failed for handle!");
452             }
453             else {
454                 /* Populate the handle fields */
455                 handle->pwrFxnTable.attach = &VAYUDSPPWR_attach;
456                 handle->pwrFxnTable.detach = &VAYUDSPPWR_detach;
457                 handle->pwrFxnTable.on     = &VAYUDSPPWR_on;
458                 handle->pwrFxnTable.off    = &VAYUDSPPWR_off;
459                 /* TBD: Other functions */
461                 /* Allocate memory for the VAYUDSPPWR handle */
462                 handle->object = Memory_calloc (NULL,
463                                                 sizeof (VAYUDSPPWR_Object),
464                                                 0,
465                                                 NULL);
466                 if (handle->object == NULL) {
467                     status = PWRMGR_E_MEMORY;
468                     GT_setFailureReason (curTrace,
469                                         GT_4CLASS,
470                                         "VAYUDSPPWR_create",
471                                         status,
472                                         "Memory allocation failed for handle!");
473                 }
474                 else {
475                     handle->procId = procId;
476                     VAYUDSPPWR_state.pwrHandles [procId] =
477                                                 (VAYUDSPPWR_Handle) handle;
478                 }
479             }
480 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
481         }
482 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
483         /* Leave critical section protection. */
484         IGateProvider_leave (VAYUDSPPWR_state.gateHandle, key);
485 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
486     }
487 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
489     if (status < 0) {
490         if (handle !=  NULL) {
491             if (handle->object != NULL) {
492                 Memory_free (NULL, handle->object, sizeof (VAYUDSPPWR_Object));
493             }
494             Memory_free (NULL, handle, sizeof (PwrMgr_Object));
495         }
496         /*! @retval NULL Function failed */
497         handle = NULL;
498     }
500     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_create", handle);
502     /*! @retval Valid-Handle Operation successful */
503     return (VAYUDSPPWR_Handle) handle;
507 /*!
508  *  @brief      Function to delete an instance of this PwrMgr.
509  *
510  *              The user provided pointer to the handle is reset after
511  *              successful completion of this function.
512  *
513  *  @param      handlePtr  Pointer to Handle to the PwrMgr instance
514  *
515  *  @sa         VAYUDSPPWR_create
516  */
517 Int
518 VAYUDSPPWR_delete (VAYUDSPPWR_Handle * handlePtr)
520     Int                  status = PWRMGR_SUCCESS;
521     VAYUDSPPWR_Object * object = NULL;
522     PwrMgr_Object *      handle;
523     IArg                 key;
525     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_delete", handlePtr);
527     GT_assert (curTrace, (handlePtr != NULL));
528     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
530 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
531     if (handlePtr == NULL) {
532         /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr specified*/
533         status = PWRMGR_E_INVALIDARG;
534         GT_setFailureReason (curTrace,
535                              GT_4CLASS,
536                              "VAYUDSPPWR_delete",
537                              status,
538                              "Invalid NULL handlePtr specified");
539     }
540     else if (*handlePtr == NULL) {
541         /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
542         status = PWRMGR_E_HANDLE;
543         GT_setFailureReason (curTrace,
544                              GT_4CLASS,
545                              "VAYUDSPPWR_delete",
546                              status,
547                              "Invalid NULL *handlePtr specified");
548     }
549     else {
550 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
551         handle = (PwrMgr_Object *) (*handlePtr);
552         /* Enter critical section protection. */
553         key = IGateProvider_enter (VAYUDSPPWR_state.gateHandle);
555         /* Reset handle in PwrMgr handle array. */
556         GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
557         VAYUDSPPWR_state.pwrHandles [handle->procId] = NULL;
559         object = (VAYUDSPPWR_Object *) handle->object;
560         /* Free memory used for the VAYUDSPPWR object. */
561         if (handle->object != NULL) {
562             /* Free memory used for the clock handle */
563             Memory_free (NULL,
564                          object,
565                          sizeof (VAYUDSPPWR_Object));
566             handle->object = NULL;
567         }
569         /* Free memory used for the PwrMgr object. */
570         Memory_free (NULL, handle, sizeof (PwrMgr_Object));
571         *handlePtr = NULL;
573         /* Leave critical section protection. */
574         IGateProvider_leave (VAYUDSPPWR_state.gateHandle, key);
575 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
576     }
577 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
579     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_delete", status);
581     /*! @retval PWRMGR_SUCCESS Operation successful */
582     return (status);
586 /*!
587  *  @brief      Function to open a handle to an instance of this PwrMgr. This
588  *              function is called when access to the PwrMgr is required from
589  *              a different process.
590  *
591  *  @param      handlePtr   Handle to the PwrMgr instance
592  *  @param      procId      Processor ID addressed by this PwrMgr instance.
593  *
594  *  @sa         VAYUDSPPWR_close
595  */
596 Int
597 VAYUDSPPWR_open (VAYUDSPPWR_Handle * handlePtr, UInt16 procId)
599     Int status = PWRMGR_SUCCESS;
601     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPWR_open", handlePtr, procId);
603     GT_assert (curTrace, (handlePtr != NULL));
604     GT_assert (curTrace, IS_VALID_PROCID (procId));
606 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
607     if (handlePtr == NULL) {
608         /*! @retval PWRMGR_E_HANDLE Invalid NULL handlePtr specified */
609         status = PWRMGR_E_HANDLE;
610         GT_setFailureReason (curTrace,
611                              GT_4CLASS,
612                              "VAYUDSPPWR_open",
613                              status,
614                              "Invalid NULL handlePtr specified");
615     }
616     else if (!IS_VALID_PROCID (procId)) {
617         /*! @retval PWRMGR_E_INVALIDARG Invalid procId specified */
618         status = PWRMGR_E_INVALIDARG;
619         GT_setFailureReason (curTrace,
620                              GT_4CLASS,
621                              "VAYUDSPPWR_open",
622                              status,
623                              "Invalid procId specified");
624     }
625     else {
626 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
627         /* Initialize return parameter handle. */
628         *handlePtr = NULL;
630         /* Check if the PwrMgr exists and return the handle if found. */
631         if (VAYUDSPPWR_state.pwrHandles [procId] == NULL) {
632             /*! @retval PWRMGR_E_NOTFOUND Specified instance not found */
633             status = PWRMGR_E_NOTFOUND;
634             GT_setFailureReason (curTrace,
635                               GT_4CLASS,
636                               "VAYUDSPPWR_open",
637                               status,
638                               "Specified VAYUDSPPWR instance does not exist!");
639         }
640         else {
641             *handlePtr = VAYUDSPPWR_state.pwrHandles [procId];
642         }
643 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
644     }
645 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
647     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_open", status);
649     /*! @retval PWRMGR_SUCCESS Operation successful */
650     return status;
654 /*!
655  *  @brief      Function to close a handle to an instance of this PwrMgr.
656  *
657  *  @param      handlePtr  Pointer to Handle to the PwrMgr instance
658  *
659  *  @sa         VAYUDSPPWR_open
660  */
661 Int
662 VAYUDSPPWR_close (VAYUDSPPWR_Handle * handlePtr)
664     Int status = PWRMGR_SUCCESS;
666     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_close", handlePtr);
668     GT_assert (curTrace, (handlePtr != NULL));
669     GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
671 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
672     if (handlePtr == NULL) {
673         /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr pointer
674                                          specified*/
675         status = PWRMGR_E_INVALIDARG;
676         GT_setFailureReason (curTrace,
677                              GT_4CLASS,
678                              "VAYUDSPPWR_close",
679                              status,
680                              "Invalid NULL handlePtr pointer specified");
681     }
682     else if (*handlePtr == NULL) {
683         /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
684         status = PWRMGR_E_HANDLE;
685         GT_setFailureReason (curTrace,
686                              GT_4CLASS,
687                              "VAYUDSPPWR_close",
688                              status,
689                              "Invalid NULL *handlePtr specified");
690     }
691     else {
692 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
693         /* Nothing to be done for close. */
694         *handlePtr = NULL;
695 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
696     }
697 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
699     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_close", status);
701     /*! @retval PWRMGR_SUCCESS Operation successful */
702     return status;
706 /* =============================================================================
707  * APIs called by PwrMgr module (part of function table interface)
708  * =============================================================================
709  */
710 /*!
711  *  @brief      Function to attach to the PwrMgr.
712  *
713  *  @param      handle  Handle to the PwrMgr instance
714  *  @param      params  Attach parameters
715  *
716  *  @sa         VAYUDSPPWR_detach
717  */
718 Int
719 VAYUDSPPWR_attach (PwrMgr_Handle handle, PwrMgr_AttachParams * params)
721     Int status                        = PWRMGR_SUCCESS;
722     PwrMgr_Object *      pwrMgrHandle = (PwrMgr_Object *) handle;
723     VAYUDSPPWR_Object *  object    = NULL;
724     Memory_MapInfo       mapInfo;
725     /* Mapping for prcm base is done in VAYUVIDEOM3_phyShmemInit */
727     GT_2trace (curTrace, GT_ENTER, "VAYUDSPPWR_attach", handle, params);
729     GT_assert (curTrace, (handle != NULL));
730     GT_assert (curTrace, (params != NULL));
732 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
733     if (handle == NULL) {
734         /*! @retval PWRMGR_E_HANDLE Invalid argument */
735         status = PWRMGR_E_HANDLE;
736         GT_setFailureReason (curTrace,
737                              GT_4CLASS,
738                              "VAYUDSPPWR_attach",
739                              status,
740                              "Invalid handle specified");
741     }
742     else {
743 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
744         object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
745         GT_assert (curTrace, (object != NULL));
746         /* Map and get the virtual address for system control module */
747         mapInfo.src      = PRCM_BASE_ADDR;
748         mapInfo.size     = PRCM_SIZE;
749         mapInfo.isCached = FALSE;
750         status = Memory_map (&mapInfo);
751 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
752         if (status < 0) {
753             status = VAYUDSPPWR_E_FAIL;
754             GT_setFailureReason (curTrace,
755                                  GT_4CLASS,
756                                  "VAYUDSPPWR_attach",
757                                  status,
758                                  "Failure in mapping prcm module");
759         }
760         else {
761 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
762             object->prcmVA = mapInfo.dst;
764             /* Map and get the virtual address for system control module */
765             mapInfo.src      = CTRL_MODULE_BASE_ADDR;
766             mapInfo.size     = CTRL_MODULE_SIZE;
767             mapInfo.isCached = FALSE;
768             status = Memory_map (&mapInfo);
769 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
770             if (status < 0) {
771                 status = VAYUDSPPWR_E_FAIL;
772                 GT_setFailureReason (curTrace,
773                                      GT_4CLASS,
774                                      "VAYUDSPPWR_attach",
775                                      status,
776                                      "Failure in mapping prcm module");
777             }
778             else {
779 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
780                 object->controlVA = mapInfo.dst;
782                 /* Map and get the virtual address for system l2 ram */
783                 mapInfo.src      = GEM_L2RAM_BASE_ADDR;
784                 mapInfo.size     = GEM_L2RAM_SIZE;
785                 mapInfo.isCached = FALSE;
786                 status = Memory_map (&mapInfo);
787 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
788                 if (status < 0) {
789                     status = VAYUDSPPWR_E_FAIL;
790                     GT_setFailureReason (curTrace,
791                                          GT_4CLASS,
792                                          "VAYUDSPPWR_attach",
793                                          status,
794                                          "Failure in mapping prcm module");
795                 }
796                 else {
797 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
798                 object->l2baseVA = mapInfo.dst;
799 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
800                 }
801             }
802         }
803     }
804 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
805     /*! @retval PWRMGR_SUCCESS Operation successful */
806     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_attach", status);
807     return (status);
812 /*!
813  *  @brief      Function to detach from the PwrMgr.
814  *
815  *  @param      handle  Handle to the PwrMgr instance
816  *
817  *  @sa         VAYUDSPPWR_attach
818  */
819 Int
820 VAYUDSPPWR_detach (PwrMgr_Handle handle)
823     Int status                     = PWRMGR_SUCCESS;
824     PwrMgr_Object * pwrMgrHandle   = (PwrMgr_Object *) handle;
825     VAYUDSPPWR_Object * object = NULL;
826     Memory_UnmapInfo     unmapInfo;
829     /* Mapping for prcm base is done in VAYUVIDEOM3_phyShmemInit */
831     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_detach", handle);
833     GT_assert (curTrace, (handle != NULL));
835 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
836     if (handle == NULL) {
837         /*! @retval PWRMGR_E_HANDLE Invalid argument */
838         status = PWRMGR_E_HANDLE;
839         GT_setFailureReason (curTrace,
840                              GT_4CLASS,
841                              "VAYUDSPPWR_detach",
842                              status,
843                              "Invalid handle specified");
844     }
845     else {
846 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
847         object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
848         GT_assert (curTrace, (object != NULL));
850         if (object->controlVA != 0x0) {
851             /* Unmap the virtual address for control module */
852             unmapInfo.addr = object->controlVA;
853             unmapInfo.size = CTRL_MODULE_SIZE;
854             unmapInfo.isCached = FALSE;
855             if (unmapInfo.addr != 0) {
856                 status = Memory_unmap (&unmapInfo);
857 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
858                 if (status < 0) {
859                     status = VAYUDSPPWR_E_FAIL;
860                     GT_setFailureReason (curTrace,
861                                          GT_4CLASS,
862                                          "VAYUDSPPWR_detach",
863                                          status,
864                                          "Failure in mapping prcm module");
865                 }
866 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
867             }
868         }
869         if (object->prcmVA != 0x0) {
870             /* Unmap the virtual address for prcm module */
871             unmapInfo.addr = object->prcmVA;
872             unmapInfo.size = PRCM_SIZE;
873             unmapInfo.isCached = FALSE;
874             if (unmapInfo.addr != 0) {
875                 status = Memory_unmap (&unmapInfo);
876 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
877                 if (status < 0) {
878                     status = VAYUDSPPWR_E_FAIL;
879                     GT_setFailureReason (curTrace,
880                                          GT_4CLASS,
881                                          "VAYUDSPPWR_detach",
882                                          status,
883                                          "Failure in mapping prcm module");
884                 }
885 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
886             }
887         }
888         if (object->l2baseVA != 0x0) {
889             /* Unmap the virtual address for prcm module */
890             unmapInfo.addr = object->l2baseVA;
891             unmapInfo.size = GEM_L2RAM_SIZE;
892             unmapInfo.isCached = FALSE;
893             if (unmapInfo.addr != 0) {
894                 status = Memory_unmap (&unmapInfo);
895 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
896                 if (status < 0) {
897                     status = VAYUDSPPWR_E_FAIL;
898                     GT_setFailureReason (curTrace,
899                                          GT_4CLASS,
900                                          "VAYUDSPPWR_detach",
901                                          status,
902                                          "Failure in mapping prcm module");
903                 }
904 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
905             }
906         }
907 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
908     }
909 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
911     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_detach", status);
912     /*! @retval PWRMGR_SUCCESS Operation successful */
913     return (status);
918 /*!
919  *  @brief      Function to power on the slave processor.
920  *
921  *              Power on the IVA subsystem, hold the DSP and SEQ in reset, and
922  *              release IVA2_RST. This is a hostile reset of the IVA. If the IVA
923  *              is already powered on, then it must be powered off in order to
924  *              terminate all current activity and initiate a power-on-reset
925  *              transition to bring the IVA to a know good state.
926  *
927  *  @param      handle    Handle to the PwrMgr instance
928  *
929  *  @sa         VAYUDSPPWR_off
930  */
931 Int
932 VAYUDSPPWR_on (PwrMgr_Handle handle)
935     Int                  status       = PWRMGR_SUCCESS ;
937 #if !defined (NETRA_SIMULATOR) /* Commented for simulator */
938     PwrMgr_Object *      pwrMgrHandle = (PwrMgr_Object *) handle;
939     VAYUDSPPWR_Object * object   = NULL;
941     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_on", handle);
943     GT_assert (curTrace, (handle != NULL));
945 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
946     if (handle == NULL) {
947         /*! @retval PWRMGR_E_HANDLE Invalid argument */
948         status = PWRMGR_E_HANDLE;
949         GT_setFailureReason (curTrace,
950                              GT_4CLASS,
951                              "VAYUDSPPWR_on",
952                              status,
953                              "Invalid handle specified");
954     }
955     else {
956 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
957         object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
958         GT_assert (curTrace, (object != NULL));
960         /* Enable spinlocks, mailbox and timers before powering on dsp */
961         object->dspSpinlockHandle = ClockOps_get(object->clockHandle, "spinbox_ick");
963         /* Do not put this check under IPC_BUILD_OPTIMIZE */
964         GT_assert (curTrace, (object->dspSpinlockHandle != NULL));
965         status = ClockOps_enable(object->clockHandle, object->dspSpinlockHandle);
966         if (status < 0) {
967             /*! @retval PWRMGR_E_HANDLE Invalid argument */
968             status = PWRMGR_E_FAIL;
969             GT_setFailureReason (curTrace,
970                                  GT_4CLASS,
971                                  "VAYUDSPPWR_on",
972                                  status,
973                                  "ClockOps_enable failed");
974         }
975         object->dspMailboxHandle = ClockOps_get(object->clockHandle, "mailbox_ick");
976         /* Do not put this check under IPC_BUILD_OPTIMIZE */
977         GT_assert (curTrace, (object->dspMailboxHandle != NULL));
978         status = ClockOps_enable(object->clockHandle, object->dspMailboxHandle);
979         GT_assert (curTrace, (status >= 0));
981         /* GP timer4 is actually timer 3 for bios it will be enabled from bios
982          * Here we are enabling the gptimer 4 clk module
983          */
985         object->dspTimerIclkHandle = ClockOps_get(object->clockHandle, "gpt4_ick");
986         /* Do not put this check under IPC_BUILD_OPTIMIZE */
987         GT_assert (curTrace, (object->dspTimerIclkHandle != NULL));
988         status = ClockOps_enable(object->clockHandle, object->dspTimerIclkHandle);
989         GT_assert (curTrace, (status >= 0));
991         object->dspTimerFclkHandle = ClockOps_get(object->clockHandle, "gpt4_fck");
992         /* Do not put this check under IPC_BUILD_OPTIMIZE */
993         GT_assert (curTrace, (object->dspTimerFclkHandle != NULL));
994         status = ClockOps_enable(object->clockHandle, object->dspTimerFclkHandle);
995         GT_assert (curTrace, (status >= 0));
997         /* Enable Dsp MMU clocks */
999         object->dspMmuCfgClkHandle = ClockOps_get(object->clockHandle, "mmu_cfg_ick");
1000         /* Do not put this check under IPC_BUILD_OPTIMIZE */
1001         GT_assert (curTrace, (object->dspMmuCfgClkHandle != NULL));
1002         status = ClockOps_enable(object->clockHandle, object->dspMmuCfgClkHandle);
1003         GT_assert (curTrace, (status >= 0));
1005         object->dspMmuClkHandle = ClockOps_get(object->clockHandle, "mmu_ick");
1006         /* Do not put this check under IPC_BUILD_OPTIMIZE */
1007         GT_assert (curTrace, (object->dspMmuClkHandle != NULL));
1008         status = ClockOps_enable(object->clockHandle, object->dspMmuClkHandle);
1009         GT_assert (curTrace, (status >= 0));
1010         object->dspClkHandle = ClockOps_get(object->clockHandle, "gem_ick");
1012         GT_assert (curTrace, (object->dspClkHandle != NULL));
1013         status = ClockOps_enable(object->clockHandle, object->dspClkHandle);
1014         GT_assert (curTrace, (status >= 0));
1016         /* Warm Reset to  access Internal RAM of DSP - to access internal RAM */
1017 //      REG((object->prcmVA) + RM_ACTIVE_RSTCTRL) = 0x01;
1019 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1020     }
1021 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1022     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_on", status);
1023     /*! @retval PWRMGR_SUCCESS Operation successful */
1024 #endif /*#if !defined (NETRA_SIMULATOR)*/
1025     return (status);
1029 /*!
1030  *  @brief      Function to power off the slave processor.
1031  *
1032  *              Turn the IVA power domain off. To ensure a clean power-off
1033  *              transition, the IVA subsystem must first be turned on so that
1034  *              the DSP can initiate an autonomous power-off transition.
1035  *
1036  *  @param      handle    Handle to the PwrMgr instance
1037  *  @param      force     Indicates whether power-off is to be forced
1038  *
1039  *  @sa         VAYUDSPPWR_on
1040  */
1041 Int
1042 VAYUDSPPWR_off (PwrMgr_Handle handle, Bool force)
1044     Int                  status       = PWRMGR_SUCCESS ;
1045     PwrMgr_Object *      pwrMgrHandle = (PwrMgr_Object *) handle;
1046     VAYUDSPPWR_Object * object   = NULL;
1048     GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_off", handle);
1050     GT_assert (curTrace, (handle != NULL));
1052 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1053     if (handle == NULL) {
1054         /*! @retval PWRMGR_E_HANDLE Invalid argument */
1055         status = PWRMGR_E_HANDLE;
1056         GT_setFailureReason (curTrace,
1057                              GT_4CLASS,
1058                              "VAYUDSPPWR_off",
1059                              status,
1060                              "Invalid handle specified");
1061     }
1062     else {
1063 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1064         object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
1065         GT_assert (curTrace, (object != NULL));
1068         /* Disable Dsp mmu clocks */
1069         if(object->dspMmuClkHandle) {
1070             ClockOps_disable(object->clockHandle, object->dspMmuClkHandle);
1071             ClockOps_put(object->clockHandle, object->dspMmuClkHandle);
1072         }
1073         /* Disable Dsp mmu cfg clocks */
1074         if(object->dspMmuCfgClkHandle) {
1075             ClockOps_disable(object->clockHandle, object->dspMmuCfgClkHandle);
1076             ClockOps_put(object->clockHandle, object->dspMmuCfgClkHandle);
1077         }
1079         /* assert DSP standby, removed to fix DSP internal memory load, -rams */
1080 //      REG(object->controlVA + DSP_IDLE_CFG) |= 0x8000;
1082         /* Disable GEM clocks */
1083         if(object->dspClkHandle) {
1084             ClockOps_disable(object->clockHandle, object->dspClkHandle);
1085             ClockOps_put(object->clockHandle, object->dspClkHandle);
1086         }
1088         /* Disable  Timer4 functional clocks */
1089         if(object->dspTimerFclkHandle) {
1090             ClockOps_disable(object->clockHandle, object->dspTimerFclkHandle);
1091             ClockOps_put(object->clockHandle, object->dspTimerFclkHandle);
1092         }
1093         /* Disable Timer4 interface clocks */
1094         if(object->dspTimerIclkHandle) {
1095             ClockOps_disable(object->clockHandle, object->dspTimerIclkHandle);
1096             ClockOps_put(object->clockHandle, object->dspTimerIclkHandle);
1097         }
1098         /* Disable Mailbox clocks */
1099         if(object->dspMailboxHandle) {
1100             ClockOps_disable(object->clockHandle, object->dspMailboxHandle);
1101             ClockOps_put(object->clockHandle, object->dspMailboxHandle);
1102         }
1103         /* Disable Spinlock clocks */
1104         if(object->dspSpinlockHandle) {
1105             ClockOps_disable(object->clockHandle, object->dspSpinlockHandle);
1106             ClockOps_put(object->clockHandle, object->dspSpinlockHandle);
1107         }
1109 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1110     }
1111 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1112     GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_off", status);
1113     /*! @retval PWRMGR_SUCCESS Operation successful */
1114     return (status);
1118 #if defined (__cplusplus)
1120 #endif /* defined (__cplusplus) */