xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_policy.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2010-2015, 2018-2021 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 /*
23  * Power policy API definitions
24  */
25 
26 #ifndef _KBASE_PM_POLICY_H_
27 #define _KBASE_PM_POLICY_H_
28 
29 /**
30  * kbase_pm_policy_init - Initialize power policy framework
31  *
32  * @kbdev: The kbase device structure for the device (must be a valid pointer)
33  *
34  * Must be called before calling any other policy function
35  */
36 void kbase_pm_policy_init(struct kbase_device *kbdev);
37 
38 /**
39  * kbase_pm_policy_term - Terminate power policy framework
40  *
41  * @kbdev: The kbase device structure for the device (must be a valid pointer)
42  */
43 void kbase_pm_policy_term(struct kbase_device *kbdev);
44 
45 /**
46  * kbase_pm_update_active - Update the active power state of the GPU
47  *
48  * @kbdev: The kbase device structure for the device (must be a valid pointer)
49  *
50  * Calls into the current power policy
51  */
52 void kbase_pm_update_active(struct kbase_device *kbdev);
53 
54 /**
55  * kbase_pm_update_cores - Update the desired core state of the GPU
56  *
57  * @kbdev: The kbase device structure for the device (must be a valid pointer)
58  *
59  * Calls into the current power policy
60  */
61 void kbase_pm_update_cores(struct kbase_device *kbdev);
62 
63 /**
64  * kbase_pm_cores_requested - Check that a power request has been locked into
65  *                            the HW.
66  * @kbdev:           Kbase device
67  * @shader_required: true if shaders are required
68  *
69  * Called by the scheduler to check if a power on request has been locked into
70  * the HW.
71  *
72  * Note that there is no guarantee that the cores are actually ready, however
73  * when the request has been locked into the HW, then it is safe to submit work
74  * since the HW will wait for the transition to ready.
75  *
76  * A reference must first be taken prior to making this call.
77  *
78  * Caller must hold the hwaccess_lock.
79  *
80  * Return: true if the request to the HW was successfully made else false if the
81  *         request is still pending.
82  */
kbase_pm_cores_requested(struct kbase_device * kbdev,bool shader_required)83 static inline bool kbase_pm_cores_requested(struct kbase_device *kbdev,
84 		bool shader_required)
85 {
86 	lockdep_assert_held(&kbdev->hwaccess_lock);
87 
88 	/* If the L2 & tiler are not on or pending, then the tiler is not yet
89 	 * available, and shaders are definitely not powered.
90 	 */
91 	if (kbdev->pm.backend.l2_state != KBASE_L2_PEND_ON &&
92 			kbdev->pm.backend.l2_state != KBASE_L2_ON &&
93 			kbdev->pm.backend.l2_state != KBASE_L2_ON_HWCNT_ENABLE)
94 		return false;
95 
96 	if (shader_required &&
97 			kbdev->pm.backend.shaders_state != KBASE_SHADERS_PEND_ON_CORESTACK_ON &&
98 			kbdev->pm.backend.shaders_state != KBASE_SHADERS_ON_CORESTACK_ON &&
99 			kbdev->pm.backend.shaders_state != KBASE_SHADERS_ON_CORESTACK_ON_RECHECK)
100 		return false;
101 
102 	return true;
103 }
104 
105 #endif /* _KBASE_PM_POLICY_H_ */
106