1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * 3*4882a593Smuzhiyun * (C) COPYRIGHT 2010-2015 ARM Limited. All rights reserved. 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * This program is free software and is provided to you under the terms of the 6*4882a593Smuzhiyun * GNU General Public License version 2 as published by the Free Software 7*4882a593Smuzhiyun * Foundation, and any use by you of this program is subject to the terms 8*4882a593Smuzhiyun * of such GNU licence. 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * A copy of the licence is included with the program, and can also be obtained 11*4882a593Smuzhiyun * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 12*4882a593Smuzhiyun * Boston, MA 02110-1301, USA. 13*4882a593Smuzhiyun * 14*4882a593Smuzhiyun */ 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun /** 21*4882a593Smuzhiyun * @file mali_kbase_pm.h 22*4882a593Smuzhiyun * Power management API definitions 23*4882a593Smuzhiyun */ 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun #ifndef _KBASE_PM_H_ 26*4882a593Smuzhiyun #define _KBASE_PM_H_ 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun #include "mali_kbase_hwaccess_pm.h" 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun #define PM_ENABLE_IRQS 0x01 31*4882a593Smuzhiyun #define PM_HW_ISSUES_DETECT 0x02 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun /** Initialize the power management framework. 35*4882a593Smuzhiyun * 36*4882a593Smuzhiyun * Must be called before any other power management function 37*4882a593Smuzhiyun * 38*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 39*4882a593Smuzhiyun * 40*4882a593Smuzhiyun * @return 0 if the power management framework was successfully initialized. 41*4882a593Smuzhiyun */ 42*4882a593Smuzhiyun int kbase_pm_init(struct kbase_device *kbdev); 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun /** Power up GPU after all modules have been initialized and interrupt handlers installed. 45*4882a593Smuzhiyun * 46*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 47*4882a593Smuzhiyun * 48*4882a593Smuzhiyun * @param flags Flags to pass on to kbase_pm_init_hw 49*4882a593Smuzhiyun * 50*4882a593Smuzhiyun * @return 0 if powerup was successful. 51*4882a593Smuzhiyun */ 52*4882a593Smuzhiyun int kbase_pm_powerup(struct kbase_device *kbdev, unsigned int flags); 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun /** 55*4882a593Smuzhiyun * Halt the power management framework. 56*4882a593Smuzhiyun * Should ensure that no new interrupts are generated, 57*4882a593Smuzhiyun * but allow any currently running interrupt handlers to complete successfully. 58*4882a593Smuzhiyun * The GPU is forced off by the time this function returns, regardless of 59*4882a593Smuzhiyun * whether or not the active power policy asks for the GPU to be powered off. 60*4882a593Smuzhiyun * 61*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 62*4882a593Smuzhiyun */ 63*4882a593Smuzhiyun void kbase_pm_halt(struct kbase_device *kbdev); 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun /** Terminate the power management framework. 66*4882a593Smuzhiyun * 67*4882a593Smuzhiyun * No power management functions may be called after this 68*4882a593Smuzhiyun * (except @ref kbase_pm_init) 69*4882a593Smuzhiyun * 70*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 71*4882a593Smuzhiyun */ 72*4882a593Smuzhiyun void kbase_pm_term(struct kbase_device *kbdev); 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun /** Increment the count of active contexts. 75*4882a593Smuzhiyun * 76*4882a593Smuzhiyun * This function should be called when a context is about to submit a job. It informs the active power policy that the 77*4882a593Smuzhiyun * GPU is going to be in use shortly and the policy is expected to start turning on the GPU. 78*4882a593Smuzhiyun * 79*4882a593Smuzhiyun * This function will block until the GPU is available. 80*4882a593Smuzhiyun * 81*4882a593Smuzhiyun * This function ASSERTS if a suspend is occuring/has occurred whilst this is 82*4882a593Smuzhiyun * in use. Use kbase_pm_contect_active_unless_suspending() instead. 83*4882a593Smuzhiyun * 84*4882a593Smuzhiyun * @note a Suspend is only visible to Kernel threads; user-space threads in a 85*4882a593Smuzhiyun * syscall cannot witness a suspend, because they are frozen before the suspend 86*4882a593Smuzhiyun * begins. 87*4882a593Smuzhiyun * 88*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 89*4882a593Smuzhiyun */ 90*4882a593Smuzhiyun void kbase_pm_context_active(struct kbase_device *kbdev); 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun /** Handler codes for doing kbase_pm_context_active_handle_suspend() */ 94*4882a593Smuzhiyun enum kbase_pm_suspend_handler { 95*4882a593Smuzhiyun /** A suspend is not expected/not possible - this is the same as 96*4882a593Smuzhiyun * kbase_pm_context_active() */ 97*4882a593Smuzhiyun KBASE_PM_SUSPEND_HANDLER_NOT_POSSIBLE, 98*4882a593Smuzhiyun /** If we're suspending, fail and don't increase the active count */ 99*4882a593Smuzhiyun KBASE_PM_SUSPEND_HANDLER_DONT_INCREASE, 100*4882a593Smuzhiyun /** If we're suspending, succeed and allow the active count to increase iff 101*4882a593Smuzhiyun * it didn't go from 0->1 (i.e., we didn't re-activate the GPU). 102*4882a593Smuzhiyun * 103*4882a593Smuzhiyun * This should only be used when there is a bounded time on the activation 104*4882a593Smuzhiyun * (e.g. guarantee it's going to be idled very soon after) */ 105*4882a593Smuzhiyun KBASE_PM_SUSPEND_HANDLER_DONT_REACTIVATE 106*4882a593Smuzhiyun }; 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun /** Suspend 'safe' variant of kbase_pm_context_active() 109*4882a593Smuzhiyun * 110*4882a593Smuzhiyun * If a suspend is in progress, this allows for various different ways of 111*4882a593Smuzhiyun * handling the suspend. Refer to @ref enum kbase_pm_suspend_handler for details. 112*4882a593Smuzhiyun * 113*4882a593Smuzhiyun * We returns a status code indicating whether we're allowed to keep the GPU 114*4882a593Smuzhiyun * active during the suspend, depending on the handler code. If the status code 115*4882a593Smuzhiyun * indicates a failure, the caller must abort whatever operation it was 116*4882a593Smuzhiyun * attempting, and potentially queue it up for after the OS has resumed. 117*4882a593Smuzhiyun * 118*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 119*4882a593Smuzhiyun * @param suspend_handler The handler code for how to handle a suspend that might occur 120*4882a593Smuzhiyun * @return zero Indicates success 121*4882a593Smuzhiyun * @return non-zero Indicates failure due to the system being suspending/suspended. 122*4882a593Smuzhiyun */ 123*4882a593Smuzhiyun int kbase_pm_context_active_handle_suspend(struct kbase_device *kbdev, enum kbase_pm_suspend_handler suspend_handler); 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun /** Decrement the reference count of active contexts. 126*4882a593Smuzhiyun * 127*4882a593Smuzhiyun * This function should be called when a context becomes idle. After this call the GPU may be turned off by the power 128*4882a593Smuzhiyun * policy so the calling code should ensure that it does not access the GPU's registers. 129*4882a593Smuzhiyun * 130*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 131*4882a593Smuzhiyun */ 132*4882a593Smuzhiyun void kbase_pm_context_idle(struct kbase_device *kbdev); 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun /** 135*4882a593Smuzhiyun * Suspend the GPU and prevent any further register accesses to it from Kernel 136*4882a593Smuzhiyun * threads. 137*4882a593Smuzhiyun * 138*4882a593Smuzhiyun * This is called in response to an OS suspend event, and calls into the various 139*4882a593Smuzhiyun * kbase components to complete the suspend. 140*4882a593Smuzhiyun * 141*4882a593Smuzhiyun * @note the mechanisms used here rely on all user-space threads being frozen 142*4882a593Smuzhiyun * by the OS before we suspend. Otherwise, an IOCTL could occur that powers up 143*4882a593Smuzhiyun * the GPU e.g. via atom submission. 144*4882a593Smuzhiyun * 145*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 146*4882a593Smuzhiyun */ 147*4882a593Smuzhiyun void kbase_pm_suspend(struct kbase_device *kbdev); 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun /** 150*4882a593Smuzhiyun * Resume the GPU, allow register accesses to it, and resume running atoms on 151*4882a593Smuzhiyun * the GPU. 152*4882a593Smuzhiyun * 153*4882a593Smuzhiyun * This is called in response to an OS resume event, and calls into the various 154*4882a593Smuzhiyun * kbase components to complete the resume. 155*4882a593Smuzhiyun * 156*4882a593Smuzhiyun * @param kbdev The kbase device structure for the device (must be a valid pointer) 157*4882a593Smuzhiyun */ 158*4882a593Smuzhiyun void kbase_pm_resume(struct kbase_device *kbdev); 159*4882a593Smuzhiyun 160*4882a593Smuzhiyun /** 161*4882a593Smuzhiyun * kbase_pm_vsync_callback - vsync callback 162*4882a593Smuzhiyun * 163*4882a593Smuzhiyun * @buffer_updated: 1 if a new frame was displayed, 0 otherwise 164*4882a593Smuzhiyun * @data: Pointer to the kbase device as returned by kbase_find_device() 165*4882a593Smuzhiyun * 166*4882a593Smuzhiyun * Callback function used to notify the power management code that a vsync has 167*4882a593Smuzhiyun * occurred on the display. 168*4882a593Smuzhiyun */ 169*4882a593Smuzhiyun void kbase_pm_vsync_callback(int buffer_updated, void *data); 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun #endif /* _KBASE_PM_H_ */ 172