[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_DSP1_BASE_ADDR 0x40800000
105 #define GEM_L2RAM_DSP2_BASE_ADDR 0x41000000
106 #define GEM_L2RAM_SIZE 0x00040000
108 #define CTRL_MODULE_BASE_ADDR 0x48140000
109 #define CTRL_MODULE_SIZE 0x00020000
110 #define DSPMEM_SLEEP 0x00000650
112 #define DSP_IDLE_CFG 0x0000061c
114 #define REG(x) *((volatile UInt32 *) (x))
115 #define MEM(x) *((volatile UInt32 *) (x))
117 /*!
118 * @brief VAYUDSPPWR Module state object
119 */
120 typedef struct VAYUDSPPWR_ModuleObject_tag {
121 UInt32 configSize;
122 /*!< Size of configuration structure */
123 VAYUDSPPWR_Config cfg;
124 /*!< VAYUDSPPWR configuration structure */
125 VAYUDSPPWR_Config defCfg;
126 /*!< Default module configuration */
127 Bool isSetup;
128 /*!< Indicates whether the VAYUDSPPWR module is setup. */
129 VAYUDSPPWR_Handle pwrHandles [MultiProc_MAXPROCESSORS];
130 /*!< PwrMgr handle array. */
131 IGateProvider_Handle gateHandle;
132 /*!< Handle of gate to be used for local thread safety */
133 } VAYUDSPPWR_ModuleObject;
135 /*!
136 * @brief VAYUDSPPWR instance object.
137 */
138 struct VAYUDSPPWR_Object_tag {
139 VAYUDSPPWR_Params params;
140 /*!< Instance parameters (configuration values) */
141 UInt32 prcmVA;
142 /*!< Virtual address for prcm module */
143 UInt32 controlVA;
144 /*!< Virtual address for control module */
145 UInt32 l2baseVA;
146 /*!< Virtual address for control module */
147 Ptr dspClkHandle;
148 /*!< dsp clk handle */
149 Ptr dspMmuClkHandle;
150 /*!< dsp clk handle */
151 Ptr dspMmuCfgClkHandle;
152 /*!< dsp clk handle */
153 Ptr dspSpinlockHandle;
154 /*!< dsp Spinlock handle */
155 Ptr dspMailboxHandle;
156 /*!< dsp Mailbox handle */
157 Ptr dspTimerIclkHandle;
158 /*!< dsp Timer4 handle */
159 Ptr dspTimerFclkHandle;
160 /*!< dsp Timer4 handle */
161 ClockOps_Handle clockHandle;
162 /*!< Pointer to the Clock object. */
164 };
166 /* Defines the VAYUDSPPWR object type. */
167 typedef struct VAYUDSPPWR_Object_tag VAYUDSPPWR_Object;
170 /* =============================================================================
171 * Globals
172 * =============================================================================
173 */
174 /*!
175 * @var VAYUDSPPWR_state
176 *
177 * @brief VAYUDSPPWR state object variable
178 */
179 #if !defined(IPC_BUILD_DEBUG)
180 static
181 #endif /* if !defined(IPC_BUILD_DEBUG) */
182 VAYUDSPPWR_ModuleObject VAYUDSPPWR_state =
183 {
184 .isSetup = FALSE,
185 .configSize = sizeof (VAYUDSPPWR_Config),
186 .defCfg.reserved = 0,
187 .gateHandle = NULL,
188 };
191 /* =============================================================================
192 * APIs directly called by applications
193 * =============================================================================
194 */
195 /*!
196 * @brief Function to get the default configuration for the VAYUDSPPWR
197 * module.
198 *
199 * This function can be called by the application to get their
200 * configuration parameter to VAYUDSPPWR_setup filled in by the
201 * VAYUDSPPWR module with the default parameters. If the user does
202 * not wish to make any change in the default parameters, this API
203 * is not required to be called.
204 *
205 * @param cfg Pointer to the VAYUDSPPWR module configuration
206 * structure in which the default config is to be
207 * returned.
208 *
209 * @sa VAYUDSPPWR_setup
210 */
211 Void
212 VAYUDSPPWR_getConfig (VAYUDSPPWR_Config * cfg)
213 {
214 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_getConfig", cfg);
216 GT_assert (curTrace, (cfg != NULL));
218 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
219 if (cfg == NULL) {
220 GT_setFailureReason (curTrace,
221 GT_4CLASS,
222 "VAYUDSPPWR_getConfig",
223 PWRMGR_E_INVALIDARG,
224 "Argument of type (VAYUDSPPWR_Config *) passed "
225 "is null!");
226 }
227 else {
228 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
229 memcpy (cfg,
230 &VAYUDSPPWR_state.defCfg,
231 sizeof (VAYUDSPPWR_Config));
232 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
233 }
234 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
236 GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPWR_getConfig");
237 }
240 /*!
241 * @brief Function to setup the VAYUDSPPWR module.
242 *
243 * This function sets up the VAYUDSPPWR module. This function must
244 * be called before any other instance-level APIs can be invoked.
245 * Module-level configuration needs to be provided to this
246 * function. If the user wishes to change some specific config
247 * parameters, then VAYUDSPPWR_getConfig can be called to get the
248 * configuration filled with the default values. After this, only
249 * the required configuration values can be changed. If the user
250 * does not wish to make any change in the default parameters, the
251 * application can simply call VAYUDSPPWR_setup with NULL
252 * parameters. The default parameters would get automatically used.
253 *
254 * @param cfg Optional VAYUDSPPWR module configuration. If provided as
255 * NULL, default configuration is used.
256 *
257 * @sa VAYUDSPPWR_destroy
258 * GateMutex_create
259 */
260 Int
261 VAYUDSPPWR_setup (VAYUDSPPWR_Config * cfg)
262 {
263 Int status = PWRMGR_SUCCESS;
264 VAYUDSPPWR_Config tmpCfg;
265 Error_Block eb;
267 Error_init(&eb);
269 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_setup", cfg);
271 if (cfg == NULL) {
272 VAYUDSPPWR_getConfig (&tmpCfg);
273 cfg = &tmpCfg;
274 }
276 /* Create a default gate handle for local module protection. */
277 VAYUDSPPWR_state.gateHandle = (IGateProvider_Handle)
278 GateMutex_create ((GateMutex_Params*)NULL, &eb);
279 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
280 if (VAYUDSPPWR_state.gateHandle == NULL) {
281 /*! @retval PWRMGR_E_FAIL Failed to create GateMutex! */
282 status = PWRMGR_E_FAIL;
283 GT_setFailureReason (curTrace,
284 GT_4CLASS,
285 "VAYUDSPPWR_setup",
286 status,
287 "Failed to create GateMutex!");
288 }
289 else {
290 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
291 /* Copy the user provided values into the state object. */
292 Memory_copy (&VAYUDSPPWR_state.cfg,
293 cfg,
294 sizeof (VAYUDSPPWR_Config));
296 /* Initialize the name to handles mapping array. */
297 Memory_set (&VAYUDSPPWR_state.pwrHandles,
298 0,
299 (sizeof (VAYUDSPPWR_Handle) * MultiProc_MAXPROCESSORS));
300 VAYUDSPPWR_state.isSetup = TRUE;
301 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
302 }
303 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
305 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_setup", status);
307 /*! @retval PWRMGR_SUCCESS Operation successful */
308 return (status);
309 }
312 /*!
313 * @brief Function to destroy the VAYUDSPPWR module.
314 *
315 * Once this function is called, other VAYUDSPPWR module APIs, except
316 * for the VAYUDSPPWR_getConfig API cannot be called anymore.
317 *
318 * @sa VAYUDSPPWR_setup
319 * GateMutex_delete
320 */
321 Int
322 VAYUDSPPWR_destroy (Void)
323 {
324 Int status = PWRMGR_SUCCESS;
325 UInt16 i;
327 GT_0trace (curTrace, GT_ENTER, "VAYUDSPPWR_destroy");
329 /* Check if any VAYUDSPPWR instances have not been deleted so far. If not,
330 * delete them.
331 */
332 for (i = 0 ; i < MultiProc_MAXPROCESSORS ; i++) {
333 GT_assert (curTrace, (VAYUDSPPWR_state.pwrHandles [i] == NULL));
334 if (VAYUDSPPWR_state.pwrHandles [i] != NULL) {
335 VAYUDSPPWR_delete (&(VAYUDSPPWR_state.pwrHandles [i]));
336 }
337 }
339 if (VAYUDSPPWR_state.gateHandle != NULL) {
340 GateMutex_delete ((GateMutex_Handle *)
341 &(VAYUDSPPWR_state.gateHandle));
342 }
344 VAYUDSPPWR_state.isSetup = FALSE;
346 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_destroy", status);
348 /*! @retval PWRMGR_SUCCESS Operation successful */
349 return (status);
350 }
353 /*!
354 * @brief Function to initialize the parameters for this PwrMgr instance.
355 *
356 * @param params Configuration parameters.
357 *
358 * @sa VAYUDSPPWR_create
359 */
360 Void
361 VAYUDSPPWR_Params_init (VAYUDSPPWR_Params * params)
362 {
363 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_Params_init",params);
365 GT_assert (curTrace, (params != NULL));
367 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
368 if (params == NULL) {
369 GT_setFailureReason (curTrace,
370 GT_4CLASS,
371 "VAYUDSPPWR_Params_init",
372 PWRMGR_E_INVALIDARG,
373 "Argument of type (VAYUDSPPWR_Params *) "
374 "passed is null!");
375 }
376 else {
377 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
378 /* Return updated VAYUDSPPWR instance specific parameters. */
379 params->reserved = 0;
380 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
381 }
382 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
384 GT_0trace (curTrace, GT_LEAVE, "VAYUDSPPWR_Params_init");
385 }
387 /*!
388 * @brief Function to create an instance of this PwrMgr.
389 *
390 * @param procId Processor ID addressed by this PwrMgr instance.
391 * @param params Configuration parameters.
392 *
393 * @sa VAYUDSPPWR_delete
394 */
395 VAYUDSPPWR_Handle
396 VAYUDSPPWR_create ( UInt16 procId,
397 const VAYUDSPPWR_Params * params)
398 {
399 Int status = PWRMGR_SUCCESS;
400 PwrMgr_Object * handle = NULL;
401 IArg key;
403 GT_2trace (curTrace, GT_ENTER, "VAYUDSPPWR_create", procId, params);
405 GT_assert (curTrace, IS_VALID_PROCID (procId));
406 GT_assert (curTrace, (params != NULL));
408 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
409 if (!IS_VALID_PROCID (procId)) {
410 status = PWRMGR_E_INVALIDARG;
411 GT_setFailureReason (curTrace,
412 GT_4CLASS,
413 "VAYUDSPPWR_create",
414 status,
415 "Invalid procId specified");
416 }
417 else if (params == NULL) {
418 status = PWRMGR_E_INVALIDARG;
419 GT_setFailureReason (curTrace,
420 GT_4CLASS,
421 "VAYUDSPPWR_create",
422 status,
423 "params passed is null!");
424 }
425 else {
426 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
427 /* Enter critical section protection. */
428 key = IGateProvider_enter (VAYUDSPPWR_state.gateHandle);
429 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
430 /* Check if the PwrMgr already exists for specified procId. */
431 if (VAYUDSPPWR_state.pwrHandles [procId] != NULL) {
432 status = PWRMGR_E_ALREADYEXIST;
433 GT_setFailureReason (curTrace,
434 GT_4CLASS,
435 "VAYUDSPPWR_create",
436 status,
437 "PwrMgr already exists for specified procId!");
438 }
439 else {
440 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
441 /* Allocate memory for the handle */
442 handle = (PwrMgr_Object *) Memory_calloc (NULL,
443 sizeof (PwrMgr_Object),
444 0,
445 NULL);
446 if (handle == NULL) {
447 status = PWRMGR_E_MEMORY;
448 GT_setFailureReason (curTrace,
449 GT_4CLASS,
450 "VAYUDSPPWR_create",
451 status,
452 "Memory allocation failed for handle!");
453 }
454 else {
455 /* Populate the handle fields */
456 handle->pwrFxnTable.attach = &VAYUDSPPWR_attach;
457 handle->pwrFxnTable.detach = &VAYUDSPPWR_detach;
458 handle->pwrFxnTable.on = &VAYUDSPPWR_on;
459 handle->pwrFxnTable.off = &VAYUDSPPWR_off;
460 /* TBD: Other functions */
462 /* Allocate memory for the VAYUDSPPWR handle */
463 handle->object = Memory_calloc (NULL,
464 sizeof (VAYUDSPPWR_Object),
465 0,
466 NULL);
467 if (handle->object == NULL) {
468 status = PWRMGR_E_MEMORY;
469 GT_setFailureReason (curTrace,
470 GT_4CLASS,
471 "VAYUDSPPWR_create",
472 status,
473 "Memory allocation failed for handle!");
474 }
475 else {
476 handle->procId = procId;
477 VAYUDSPPWR_state.pwrHandles [procId] =
478 (VAYUDSPPWR_Handle) handle;
479 }
480 }
481 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
482 }
483 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
484 /* Leave critical section protection. */
485 IGateProvider_leave (VAYUDSPPWR_state.gateHandle, key);
486 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
487 }
488 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
490 if (status < 0) {
491 if (handle != NULL) {
492 if (handle->object != NULL) {
493 Memory_free (NULL, handle->object, sizeof (VAYUDSPPWR_Object));
494 }
495 Memory_free (NULL, handle, sizeof (PwrMgr_Object));
496 }
497 /*! @retval NULL Function failed */
498 handle = NULL;
499 }
501 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_create", handle);
503 /*! @retval Valid-Handle Operation successful */
504 return (VAYUDSPPWR_Handle) handle;
505 }
508 /*!
509 * @brief Function to delete an instance of this PwrMgr.
510 *
511 * The user provided pointer to the handle is reset after
512 * successful completion of this function.
513 *
514 * @param handlePtr Pointer to Handle to the PwrMgr instance
515 *
516 * @sa VAYUDSPPWR_create
517 */
518 Int
519 VAYUDSPPWR_delete (VAYUDSPPWR_Handle * handlePtr)
520 {
521 Int status = PWRMGR_SUCCESS;
522 VAYUDSPPWR_Object * object = NULL;
523 PwrMgr_Object * handle;
524 IArg key;
526 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_delete", handlePtr);
528 GT_assert (curTrace, (handlePtr != NULL));
529 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
531 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
532 if (handlePtr == NULL) {
533 /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr specified*/
534 status = PWRMGR_E_INVALIDARG;
535 GT_setFailureReason (curTrace,
536 GT_4CLASS,
537 "VAYUDSPPWR_delete",
538 status,
539 "Invalid NULL handlePtr specified");
540 }
541 else if (*handlePtr == NULL) {
542 /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
543 status = PWRMGR_E_HANDLE;
544 GT_setFailureReason (curTrace,
545 GT_4CLASS,
546 "VAYUDSPPWR_delete",
547 status,
548 "Invalid NULL *handlePtr specified");
549 }
550 else {
551 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
552 handle = (PwrMgr_Object *) (*handlePtr);
553 /* Enter critical section protection. */
554 key = IGateProvider_enter (VAYUDSPPWR_state.gateHandle);
556 /* Reset handle in PwrMgr handle array. */
557 GT_assert (curTrace, IS_VALID_PROCID (handle->procId));
558 VAYUDSPPWR_state.pwrHandles [handle->procId] = NULL;
560 object = (VAYUDSPPWR_Object *) handle->object;
561 /* Free memory used for the VAYUDSPPWR object. */
562 if (handle->object != NULL) {
563 /* Free memory used for the clock handle */
564 Memory_free (NULL,
565 object,
566 sizeof (VAYUDSPPWR_Object));
567 handle->object = NULL;
568 }
570 /* Free memory used for the PwrMgr object. */
571 Memory_free (NULL, handle, sizeof (PwrMgr_Object));
572 *handlePtr = NULL;
574 /* Leave critical section protection. */
575 IGateProvider_leave (VAYUDSPPWR_state.gateHandle, key);
576 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
577 }
578 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
580 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_delete", status);
582 /*! @retval PWRMGR_SUCCESS Operation successful */
583 return (status);
584 }
587 /*!
588 * @brief Function to open a handle to an instance of this PwrMgr. This
589 * function is called when access to the PwrMgr is required from
590 * a different process.
591 *
592 * @param handlePtr Handle to the PwrMgr instance
593 * @param procId Processor ID addressed by this PwrMgr instance.
594 *
595 * @sa VAYUDSPPWR_close
596 */
597 Int
598 VAYUDSPPWR_open (VAYUDSPPWR_Handle * handlePtr, UInt16 procId)
599 {
600 Int status = PWRMGR_SUCCESS;
602 GT_2trace (curTrace, GT_ENTER, "VAYUDSPPWR_open", handlePtr, procId);
604 GT_assert (curTrace, (handlePtr != NULL));
605 GT_assert (curTrace, IS_VALID_PROCID (procId));
607 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
608 if (handlePtr == NULL) {
609 /*! @retval PWRMGR_E_HANDLE Invalid NULL handlePtr specified */
610 status = PWRMGR_E_HANDLE;
611 GT_setFailureReason (curTrace,
612 GT_4CLASS,
613 "VAYUDSPPWR_open",
614 status,
615 "Invalid NULL handlePtr specified");
616 }
617 else if (!IS_VALID_PROCID (procId)) {
618 /*! @retval PWRMGR_E_INVALIDARG Invalid procId specified */
619 status = PWRMGR_E_INVALIDARG;
620 GT_setFailureReason (curTrace,
621 GT_4CLASS,
622 "VAYUDSPPWR_open",
623 status,
624 "Invalid procId specified");
625 }
626 else {
627 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
628 /* Initialize return parameter handle. */
629 *handlePtr = NULL;
631 /* Check if the PwrMgr exists and return the handle if found. */
632 if (VAYUDSPPWR_state.pwrHandles [procId] == NULL) {
633 /*! @retval PWRMGR_E_NOTFOUND Specified instance not found */
634 status = PWRMGR_E_NOTFOUND;
635 GT_setFailureReason (curTrace,
636 GT_4CLASS,
637 "VAYUDSPPWR_open",
638 status,
639 "Specified VAYUDSPPWR instance does not exist!");
640 }
641 else {
642 *handlePtr = VAYUDSPPWR_state.pwrHandles [procId];
643 }
644 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
645 }
646 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
648 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_open", status);
650 /*! @retval PWRMGR_SUCCESS Operation successful */
651 return status;
652 }
655 /*!
656 * @brief Function to close a handle to an instance of this PwrMgr.
657 *
658 * @param handlePtr Pointer to Handle to the PwrMgr instance
659 *
660 * @sa VAYUDSPPWR_open
661 */
662 Int
663 VAYUDSPPWR_close (VAYUDSPPWR_Handle * handlePtr)
664 {
665 Int status = PWRMGR_SUCCESS;
667 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_close", handlePtr);
669 GT_assert (curTrace, (handlePtr != NULL));
670 GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL)));
672 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
673 if (handlePtr == NULL) {
674 /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr pointer
675 specified*/
676 status = PWRMGR_E_INVALIDARG;
677 GT_setFailureReason (curTrace,
678 GT_4CLASS,
679 "VAYUDSPPWR_close",
680 status,
681 "Invalid NULL handlePtr pointer specified");
682 }
683 else if (*handlePtr == NULL) {
684 /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */
685 status = PWRMGR_E_HANDLE;
686 GT_setFailureReason (curTrace,
687 GT_4CLASS,
688 "VAYUDSPPWR_close",
689 status,
690 "Invalid NULL *handlePtr specified");
691 }
692 else {
693 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
694 /* Nothing to be done for close. */
695 *handlePtr = NULL;
696 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
697 }
698 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
700 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_close", status);
702 /*! @retval PWRMGR_SUCCESS Operation successful */
703 return status;
704 }
707 /* =============================================================================
708 * APIs called by PwrMgr module (part of function table interface)
709 * =============================================================================
710 */
711 /*!
712 * @brief Function to attach to the PwrMgr.
713 *
714 * @param handle Handle to the PwrMgr instance
715 * @param params Attach parameters
716 *
717 * @sa VAYUDSPPWR_detach
718 */
719 Int
720 VAYUDSPPWR_attach (PwrMgr_Handle handle, PwrMgr_AttachParams * params)
721 {
722 Int status = PWRMGR_SUCCESS;
723 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
724 VAYUDSPPWR_Object * object = NULL;
725 UInt16 dsp1ProcId = MultiProc_getId("DSP1");
726 Memory_MapInfo mapInfo;
727 /* Mapping for prcm base is done in VAYUVIDEOM3_phyShmemInit */
729 GT_2trace (curTrace, GT_ENTER, "VAYUDSPPWR_attach", handle, params);
731 GT_assert (curTrace, (handle != NULL));
732 GT_assert (curTrace, (params != NULL));
734 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
735 if (handle == NULL) {
736 /*! @retval PWRMGR_E_HANDLE Invalid argument */
737 status = PWRMGR_E_HANDLE;
738 GT_setFailureReason (curTrace,
739 GT_4CLASS,
740 "VAYUDSPPWR_attach",
741 status,
742 "Invalid handle specified");
743 }
744 else {
745 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
746 object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
747 GT_assert (curTrace, (object != NULL));
748 /* Map and get the virtual address for system control module */
749 mapInfo.src = PRCM_BASE_ADDR;
750 mapInfo.size = PRCM_SIZE;
751 mapInfo.isCached = FALSE;
752 status = Memory_map (&mapInfo);
753 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
754 if (status < 0) {
755 status = VAYUDSPPWR_E_FAIL;
756 GT_setFailureReason (curTrace,
757 GT_4CLASS,
758 "VAYUDSPPWR_attach",
759 status,
760 "Failure in mapping prcm module");
761 }
762 else {
763 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
764 object->prcmVA = mapInfo.dst;
766 /* Map and get the virtual address for system control module */
767 mapInfo.src = CTRL_MODULE_BASE_ADDR;
768 mapInfo.size = CTRL_MODULE_SIZE;
769 mapInfo.isCached = FALSE;
770 status = Memory_map (&mapInfo);
771 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
772 if (status < 0) {
773 status = VAYUDSPPWR_E_FAIL;
774 GT_setFailureReason (curTrace,
775 GT_4CLASS,
776 "VAYUDSPPWR_attach",
777 status,
778 "Failure in mapping prcm module");
779 }
780 else {
781 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
782 object->controlVA = mapInfo.dst;
784 /* Map and get the virtual address for system l2 ram */
785 if (handle->procId == dsp1ProcId) {
786 mapInfo.src = GEM_L2RAM_DSP1_BASE_ADDR;
787 }
788 else {
789 mapInfo.src = GEM_L2RAM_DSP2_BASE_ADDR;
790 }
791 mapInfo.size = GEM_L2RAM_SIZE;
792 mapInfo.isCached = FALSE;
793 status = Memory_map (&mapInfo);
794 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
795 if (status < 0) {
796 status = VAYUDSPPWR_E_FAIL;
797 GT_setFailureReason (curTrace,
798 GT_4CLASS,
799 "VAYUDSPPWR_attach",
800 status,
801 "Failure in mapping prcm module");
802 }
803 else {
804 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
805 object->l2baseVA = mapInfo.dst;
806 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
807 }
808 }
809 }
810 }
811 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
812 /*! @retval PWRMGR_SUCCESS Operation successful */
813 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_attach", status);
814 return (status);
816 }
819 /*!
820 * @brief Function to detach from the PwrMgr.
821 *
822 * @param handle Handle to the PwrMgr instance
823 *
824 * @sa VAYUDSPPWR_attach
825 */
826 Int
827 VAYUDSPPWR_detach (PwrMgr_Handle handle)
828 {
830 Int status = PWRMGR_SUCCESS;
831 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
832 VAYUDSPPWR_Object * object = NULL;
833 Memory_UnmapInfo unmapInfo;
836 /* Mapping for prcm base is done in VAYUVIDEOM3_phyShmemInit */
838 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_detach", handle);
840 GT_assert (curTrace, (handle != NULL));
842 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
843 if (handle == NULL) {
844 /*! @retval PWRMGR_E_HANDLE Invalid argument */
845 status = PWRMGR_E_HANDLE;
846 GT_setFailureReason (curTrace,
847 GT_4CLASS,
848 "VAYUDSPPWR_detach",
849 status,
850 "Invalid handle specified");
851 }
852 else {
853 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
854 object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
855 GT_assert (curTrace, (object != NULL));
857 if (object->controlVA != 0x0) {
858 /* Unmap the virtual address for control module */
859 unmapInfo.addr = object->controlVA;
860 unmapInfo.size = CTRL_MODULE_SIZE;
861 unmapInfo.isCached = FALSE;
862 if (unmapInfo.addr != 0) {
863 status = Memory_unmap (&unmapInfo);
864 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
865 if (status < 0) {
866 status = VAYUDSPPWR_E_FAIL;
867 GT_setFailureReason (curTrace,
868 GT_4CLASS,
869 "VAYUDSPPWR_detach",
870 status,
871 "Failure in mapping prcm module");
872 }
873 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
874 }
875 }
876 if (object->prcmVA != 0x0) {
877 /* Unmap the virtual address for prcm module */
878 unmapInfo.addr = object->prcmVA;
879 unmapInfo.size = PRCM_SIZE;
880 unmapInfo.isCached = FALSE;
881 if (unmapInfo.addr != 0) {
882 status = Memory_unmap (&unmapInfo);
883 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
884 if (status < 0) {
885 status = VAYUDSPPWR_E_FAIL;
886 GT_setFailureReason (curTrace,
887 GT_4CLASS,
888 "VAYUDSPPWR_detach",
889 status,
890 "Failure in mapping prcm module");
891 }
892 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
893 }
894 }
895 if (object->l2baseVA != 0x0) {
896 /* Unmap the virtual address for prcm module */
897 unmapInfo.addr = object->l2baseVA;
898 unmapInfo.size = GEM_L2RAM_SIZE;
899 unmapInfo.isCached = FALSE;
900 if (unmapInfo.addr != 0) {
901 status = Memory_unmap (&unmapInfo);
902 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
903 if (status < 0) {
904 status = VAYUDSPPWR_E_FAIL;
905 GT_setFailureReason (curTrace,
906 GT_4CLASS,
907 "VAYUDSPPWR_detach",
908 status,
909 "Failure in mapping prcm module");
910 }
911 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
912 }
913 }
914 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
915 }
916 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
918 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_detach", status);
919 /*! @retval PWRMGR_SUCCESS Operation successful */
920 return (status);
922 }
925 /*!
926 * @brief Function to power on the slave processor.
927 *
928 * Power on the IVA subsystem, hold the DSP and SEQ in reset, and
929 * release IVA2_RST. This is a hostile reset of the IVA. If the IVA
930 * is already powered on, then it must be powered off in order to
931 * terminate all current activity and initiate a power-on-reset
932 * transition to bring the IVA to a know good state.
933 *
934 * @param handle Handle to the PwrMgr instance
935 *
936 * @sa VAYUDSPPWR_off
937 */
938 Int
939 VAYUDSPPWR_on (PwrMgr_Handle handle)
940 {
942 Int status = PWRMGR_SUCCESS ;
944 #if !defined (NETRA_SIMULATOR) /* Commented for simulator */
945 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
946 VAYUDSPPWR_Object * object = NULL;
948 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_on", handle);
950 GT_assert (curTrace, (handle != NULL));
952 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
953 if (handle == NULL) {
954 /*! @retval PWRMGR_E_HANDLE Invalid argument */
955 status = PWRMGR_E_HANDLE;
956 GT_setFailureReason (curTrace,
957 GT_4CLASS,
958 "VAYUDSPPWR_on",
959 status,
960 "Invalid handle specified");
961 }
962 else {
963 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
964 object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
965 GT_assert (curTrace, (object != NULL));
967 /* Enable spinlocks, mailbox and timers before powering on dsp */
968 object->dspSpinlockHandle = ClockOps_get(object->clockHandle, "spinbox_ick");
970 /* Do not put this check under IPC_BUILD_OPTIMIZE */
971 GT_assert (curTrace, (object->dspSpinlockHandle != NULL));
972 status = ClockOps_enable(object->clockHandle, object->dspSpinlockHandle);
973 if (status < 0) {
974 /*! @retval PWRMGR_E_HANDLE Invalid argument */
975 status = PWRMGR_E_FAIL;
976 GT_setFailureReason (curTrace,
977 GT_4CLASS,
978 "VAYUDSPPWR_on",
979 status,
980 "ClockOps_enable failed");
981 }
982 object->dspMailboxHandle = ClockOps_get(object->clockHandle, "mailbox_ick");
983 /* Do not put this check under IPC_BUILD_OPTIMIZE */
984 GT_assert (curTrace, (object->dspMailboxHandle != NULL));
985 status = ClockOps_enable(object->clockHandle, object->dspMailboxHandle);
986 GT_assert (curTrace, (status >= 0));
988 /* GP timer4 is actually timer 3 for bios it will be enabled from bios
989 * Here we are enabling the gptimer 4 clk module
990 */
992 object->dspTimerIclkHandle = ClockOps_get(object->clockHandle, "gpt4_ick");
993 /* Do not put this check under IPC_BUILD_OPTIMIZE */
994 GT_assert (curTrace, (object->dspTimerIclkHandle != NULL));
995 status = ClockOps_enable(object->clockHandle, object->dspTimerIclkHandle);
996 GT_assert (curTrace, (status >= 0));
998 object->dspTimerFclkHandle = ClockOps_get(object->clockHandle, "gpt4_fck");
999 /* Do not put this check under IPC_BUILD_OPTIMIZE */
1000 GT_assert (curTrace, (object->dspTimerFclkHandle != NULL));
1001 status = ClockOps_enable(object->clockHandle, object->dspTimerFclkHandle);
1002 GT_assert (curTrace, (status >= 0));
1004 /* Enable Dsp MMU clocks */
1006 object->dspMmuCfgClkHandle = ClockOps_get(object->clockHandle, "mmu_cfg_ick");
1007 /* Do not put this check under IPC_BUILD_OPTIMIZE */
1008 GT_assert (curTrace, (object->dspMmuCfgClkHandle != NULL));
1009 status = ClockOps_enable(object->clockHandle, object->dspMmuCfgClkHandle);
1010 GT_assert (curTrace, (status >= 0));
1012 object->dspMmuClkHandle = ClockOps_get(object->clockHandle, "mmu_ick");
1013 /* Do not put this check under IPC_BUILD_OPTIMIZE */
1014 GT_assert (curTrace, (object->dspMmuClkHandle != NULL));
1015 status = ClockOps_enable(object->clockHandle, object->dspMmuClkHandle);
1016 GT_assert (curTrace, (status >= 0));
1017 object->dspClkHandle = ClockOps_get(object->clockHandle, "gem_ick");
1019 GT_assert (curTrace, (object->dspClkHandle != NULL));
1020 status = ClockOps_enable(object->clockHandle, object->dspClkHandle);
1021 GT_assert (curTrace, (status >= 0));
1023 /* Warm Reset to access Internal RAM of DSP - to access internal RAM */
1024 // REG((object->prcmVA) + RM_ACTIVE_RSTCTRL) = 0x01;
1026 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1027 }
1028 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1029 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_on", status);
1030 /*! @retval PWRMGR_SUCCESS Operation successful */
1031 #endif /*#if !defined (NETRA_SIMULATOR)*/
1032 return (status);
1033 }
1036 /*!
1037 * @brief Function to power off the slave processor.
1038 *
1039 * Turn the IVA power domain off. To ensure a clean power-off
1040 * transition, the IVA subsystem must first be turned on so that
1041 * the DSP can initiate an autonomous power-off transition.
1042 *
1043 * @param handle Handle to the PwrMgr instance
1044 * @param force Indicates whether power-off is to be forced
1045 *
1046 * @sa VAYUDSPPWR_on
1047 */
1048 Int
1049 VAYUDSPPWR_off (PwrMgr_Handle handle, Bool force)
1050 {
1051 Int status = PWRMGR_SUCCESS ;
1052 PwrMgr_Object * pwrMgrHandle = (PwrMgr_Object *) handle;
1053 VAYUDSPPWR_Object * object = NULL;
1055 GT_1trace (curTrace, GT_ENTER, "VAYUDSPPWR_off", handle);
1057 GT_assert (curTrace, (handle != NULL));
1059 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1060 if (handle == NULL) {
1061 /*! @retval PWRMGR_E_HANDLE Invalid argument */
1062 status = PWRMGR_E_HANDLE;
1063 GT_setFailureReason (curTrace,
1064 GT_4CLASS,
1065 "VAYUDSPPWR_off",
1066 status,
1067 "Invalid handle specified");
1068 }
1069 else {
1070 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1071 object = (VAYUDSPPWR_Object *) pwrMgrHandle->object;
1072 GT_assert (curTrace, (object != NULL));
1075 /* Disable Dsp mmu clocks */
1076 if(object->dspMmuClkHandle) {
1077 ClockOps_disable(object->clockHandle, object->dspMmuClkHandle);
1078 ClockOps_put(object->clockHandle, object->dspMmuClkHandle);
1079 }
1080 /* Disable Dsp mmu cfg clocks */
1081 if(object->dspMmuCfgClkHandle) {
1082 ClockOps_disable(object->clockHandle, object->dspMmuCfgClkHandle);
1083 ClockOps_put(object->clockHandle, object->dspMmuCfgClkHandle);
1084 }
1086 /* assert DSP standby, removed to fix DSP internal memory load, -rams */
1087 // REG(object->controlVA + DSP_IDLE_CFG) |= 0x8000;
1089 /* Disable GEM clocks */
1090 if(object->dspClkHandle) {
1091 ClockOps_disable(object->clockHandle, object->dspClkHandle);
1092 ClockOps_put(object->clockHandle, object->dspClkHandle);
1093 }
1095 /* Disable Timer4 functional clocks */
1096 if(object->dspTimerFclkHandle) {
1097 ClockOps_disable(object->clockHandle, object->dspTimerFclkHandle);
1098 ClockOps_put(object->clockHandle, object->dspTimerFclkHandle);
1099 }
1100 /* Disable Timer4 interface clocks */
1101 if(object->dspTimerIclkHandle) {
1102 ClockOps_disable(object->clockHandle, object->dspTimerIclkHandle);
1103 ClockOps_put(object->clockHandle, object->dspTimerIclkHandle);
1104 }
1105 /* Disable Mailbox clocks */
1106 if(object->dspMailboxHandle) {
1107 ClockOps_disable(object->clockHandle, object->dspMailboxHandle);
1108 ClockOps_put(object->clockHandle, object->dspMailboxHandle);
1109 }
1110 /* Disable Spinlock clocks */
1111 if(object->dspSpinlockHandle) {
1112 ClockOps_disable(object->clockHandle, object->dspSpinlockHandle);
1113 ClockOps_put(object->clockHandle, object->dspSpinlockHandle);
1114 }
1116 #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS)
1117 }
1118 #endif /* #if !defined(IPC_BUILD_OPTIMIZE) && defined (IPC_BUILD_HLOS) */
1119 GT_1trace (curTrace, GT_LEAVE, "VAYUDSPPWR_off", status);
1120 /*! @retval PWRMGR_SUCCESS Operation successful */
1121 return (status);
1122 }
1125 #if defined (__cplusplus)
1126 }
1127 #endif /* defined (__cplusplus) */