1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 2014-2015, 2018-2022 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 * DOC: HW access power manager common APIs 24 */ 25 26 #ifndef _KBASE_HWACCESS_PM_H_ 27 #define _KBASE_HWACCESS_PM_H_ 28 29 #include <gpu/mali_kbase_gpu_regmap.h> 30 #include <linux/atomic.h> 31 32 #include <backend/gpu/mali_kbase_pm_defs.h> 33 34 /* Forward definition - see mali_kbase.h */ 35 struct kbase_device; 36 37 /* Functions common to all HW access backends */ 38 39 /** 40 * kbase_hwaccess_pm_init - Initialize the power management framework. 41 * 42 * @kbdev: The kbase device structure for the device (must be a valid pointer) 43 * 44 * Must be called before any other power management function 45 * 46 * Return: 0 if the power management framework was successfully initialized. 47 */ 48 int kbase_hwaccess_pm_init(struct kbase_device *kbdev); 49 50 /** 51 * kbase_hwaccess_pm_term - Terminate the power management framework. 52 * 53 * @kbdev: The kbase device structure for the device (must be a valid pointer) 54 * 55 * No power management functions may be called after this 56 */ 57 void kbase_hwaccess_pm_term(struct kbase_device *kbdev); 58 59 /** 60 * kbase_hwaccess_pm_powerup - Power up the GPU. 61 * @kbdev: The kbase device structure for the device (must be a valid pointer) 62 * @flags: Flags to pass on to kbase_pm_init_hw 63 * 64 * Power up GPU after all modules have been initialized and interrupt handlers 65 * installed. 66 * 67 * Return: 0 if powerup was successful. 68 */ 69 int kbase_hwaccess_pm_powerup(struct kbase_device *kbdev, 70 unsigned int flags); 71 72 /** 73 * kbase_hwaccess_pm_halt - Halt the power management framework. 74 * 75 * @kbdev: The kbase device structure for the device (must be a valid pointer) 76 * 77 * Should ensure that no new interrupts are generated, but allow any currently 78 * running interrupt handlers to complete successfully. The GPU is forced off by 79 * the time this function returns, regardless of whether or not the active power 80 * policy asks for the GPU to be powered off. 81 */ 82 void kbase_hwaccess_pm_halt(struct kbase_device *kbdev); 83 84 /** 85 * kbase_hwaccess_pm_suspend - Perform any backend-specific actions to suspend the GPU 86 * 87 * @kbdev: The kbase device structure for the device (must be a valid pointer) 88 * 89 * Return: 0 if suspend was successful. 90 */ 91 int kbase_hwaccess_pm_suspend(struct kbase_device *kbdev); 92 93 /** 94 * kbase_hwaccess_pm_resume - Perform any backend-specific actions to resume the GPU 95 * from a suspend 96 * 97 * @kbdev: The kbase device structure for the device (must be a valid pointer) 98 */ 99 void kbase_hwaccess_pm_resume(struct kbase_device *kbdev); 100 101 /** 102 * kbase_hwaccess_pm_gpu_active - Perform any required actions for activating the GPU. 103 * Called when the first context goes active. 104 * 105 * @kbdev: The kbase device structure for the device (must be a valid pointer) 106 */ 107 void kbase_hwaccess_pm_gpu_active(struct kbase_device *kbdev); 108 109 /** 110 * kbase_hwaccess_pm_gpu_idle - Perform any required actions for idling the GPU. 111 * Called when the last context goes idle. 112 * 113 * @kbdev: The kbase device structure for the device (must be a valid pointer) 114 */ 115 void kbase_hwaccess_pm_gpu_idle(struct kbase_device *kbdev); 116 117 #if MALI_USE_CSF 118 /** 119 * kbase_pm_set_debug_core_mask - Set the debug core mask. 120 * 121 * @kbdev: The kbase device structure for the device (must be a valid pointer) 122 * @new_core_mask: The core mask to use 123 * 124 * This determines which cores the power manager is allowed to use. 125 */ 126 void kbase_pm_set_debug_core_mask(struct kbase_device *kbdev, 127 u64 new_core_mask); 128 #else 129 /** 130 * kbase_pm_set_debug_core_mask - Set the debug core mask. 131 * 132 * @kbdev: The kbase device structure for the device (must be a valid pointer) 133 * @new_core_mask_js0: The core mask to use for job slot 0 134 * @new_core_mask_js1: The core mask to use for job slot 1 135 * @new_core_mask_js2: The core mask to use for job slot 2 136 * 137 * This determines which cores the power manager is allowed to use. 138 */ 139 void kbase_pm_set_debug_core_mask(struct kbase_device *kbdev, 140 u64 new_core_mask_js0, u64 new_core_mask_js1, 141 u64 new_core_mask_js2); 142 #endif /* MALI_USE_CSF */ 143 144 /** 145 * kbase_pm_ca_get_policy - Get the current policy. 146 * 147 * @kbdev: The kbase device structure for the device (must be a valid pointer) 148 * 149 * Returns the policy that is currently active. 150 * 151 * Return: The current policy 152 */ 153 const struct kbase_pm_ca_policy 154 *kbase_pm_ca_get_policy(struct kbase_device *kbdev); 155 156 /** 157 * kbase_pm_ca_set_policy - Change the policy to the one specified. 158 * 159 * @kbdev: The kbase device structure for the device (must be a valid pointer) 160 * @policy: The policy to change to (valid pointer returned from 161 * @ref kbase_pm_ca_list_policies) 162 */ 163 void kbase_pm_ca_set_policy(struct kbase_device *kbdev, 164 const struct kbase_pm_ca_policy *policy); 165 166 /** 167 * kbase_pm_ca_list_policies - Retrieve a static list of the available policies. 168 * 169 * @policies: An array pointer to take the list of policies. This may be NULL. 170 * The contents of this array must not be modified. 171 * 172 * Return: The number of policies 173 */ 174 int 175 kbase_pm_ca_list_policies(const struct kbase_pm_ca_policy * const **policies); 176 177 /** 178 * kbase_pm_get_policy - Get the current policy. 179 * 180 * @kbdev: The kbase device structure for the device (must be a valid pointer) 181 * 182 * Returns the policy that is currently active. 183 * 184 * Return: The current policy 185 */ 186 const struct kbase_pm_policy *kbase_pm_get_policy(struct kbase_device *kbdev); 187 188 /** 189 * kbase_pm_set_policy - Change the policy to the one specified. 190 * 191 * @kbdev: The kbase device structure for the device (must be a valid 192 * pointer) 193 * @policy: The policy to change to (valid pointer returned from 194 * @ref kbase_pm_list_policies) 195 */ 196 void kbase_pm_set_policy(struct kbase_device *kbdev, 197 const struct kbase_pm_policy *policy); 198 199 /** 200 * kbase_pm_list_policies - Retrieve a static list of the available policies. 201 * 202 * @kbdev: The kbase device structure for the device. 203 * @list: An array pointer to take the list of policies. This may be NULL. 204 * The contents of this array must not be modified. 205 * 206 * Return: The number of policies 207 */ 208 int kbase_pm_list_policies(struct kbase_device *kbdev, 209 const struct kbase_pm_policy * const **list); 210 211 /** 212 * kbase_pm_protected_mode_enable() - Enable protected mode 213 * 214 * @kbdev: Address of the instance of a GPU platform device. 215 * 216 * Return: Zero on success or an error code 217 */ 218 int kbase_pm_protected_mode_enable(struct kbase_device *kbdev); 219 220 /** 221 * kbase_pm_protected_mode_disable() - Disable protected mode 222 * 223 * @kbdev: Address of the instance of a GPU platform device. 224 * 225 * Return: Zero on success or an error code 226 */ 227 int kbase_pm_protected_mode_disable(struct kbase_device *kbdev); 228 229 #endif /* _KBASE_HWACCESS_PM_H_ */ 230