3 * (C) COPYRIGHT 2014-2016 ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
19 * Backend-specific Power Manager definitions
22 #ifndef _KBASE_PM_HWACCESS_DEFS_H_
23 #define _KBASE_PM_HWACCESS_DEFS_H_
25 #include "mali_kbase_pm_ca_fixed.h"
26 #if !MALI_CUSTOMER_RELEASE
27 #include "mali_kbase_pm_ca_random.h"
30 #include "mali_kbase_pm_always_on.h"
31 #include "mali_kbase_pm_coarse_demand.h"
32 #include "mali_kbase_pm_demand.h"
33 #if !MALI_CUSTOMER_RELEASE
34 #include "mali_kbase_pm_demand_always_powered.h"
35 #include "mali_kbase_pm_fast_start.h"
38 /* Forward definition - see mali_kbase.h */
43 * enum kbase_pm_core_type - The types of core in a GPU.
45 * These enumerated values are used in calls to
46 * - kbase_pm_get_present_cores()
47 * - kbase_pm_get_active_cores()
48 * - kbase_pm_get_trans_cores()
49 * - kbase_pm_get_ready_cores().
51 * They specify which type of core should be acted on. These values are set in
52 * a manner that allows core_type_to_reg() function to be simpler and more
55 * @KBASE_PM_CORE_L2: The L2 cache
56 * @KBASE_PM_CORE_SHADER: Shader cores
57 * @KBASE_PM_CORE_TILER: Tiler cores
59 enum kbase_pm_core_type {
60 KBASE_PM_CORE_L2 = L2_PRESENT_LO,
61 KBASE_PM_CORE_SHADER = SHADER_PRESENT_LO,
62 KBASE_PM_CORE_TILER = TILER_PRESENT_LO
66 * struct kbasep_pm_metrics_data - Metrics data collected for use by the power
67 * management framework.
69 * @time_period_start: time at which busy/idle measurements started
70 * @time_busy: number of ns the GPU was busy executing jobs since the
71 * @time_period_start timestamp.
72 * @time_idle: number of ns since time_period_start the GPU was not executing
73 * jobs since the @time_period_start timestamp.
74 * @prev_busy: busy time in ns of previous time period.
75 * Updated when metrics are reset.
76 * @prev_idle: idle time in ns of previous time period
77 * Updated when metrics are reset.
78 * @gpu_active: true when the GPU is executing jobs. false when
79 * not. Updated when the job scheduler informs us a job in submitted
80 * or removed from a GPU slot.
81 * @busy_cl: number of ns the GPU was busy executing CL jobs. Note that
82 * if two CL jobs were active for 400ns, this value would be updated
84 * @busy_gl: number of ns the GPU was busy executing GL jobs. Note that
85 * if two GL jobs were active for 400ns, this value would be updated
87 * @active_cl_ctx: number of CL jobs active on the GPU. Array is per-device.
88 * @active_gl_ctx: number of GL jobs active on the GPU. Array is per-slot. As
89 * GL jobs never run on slot 2 this slot is not recorded.
90 * @lock: spinlock protecting the kbasep_pm_metrics_data structure
91 * @timer: timer to regularly make DVFS decisions based on the power
93 * @timer_active: boolean indicating @timer is running
94 * @platform_data: pointer to data controlled by platform specific code
95 * @kbdev: pointer to kbase device for which metrics are collected
98 struct kbasep_pm_metrics_data {
99 ktime_t time_period_start;
107 u32 active_cl_ctx[2];
108 u32 active_gl_ctx[2]; /* GL jobs can only run on 2 of the 3 job slots */
111 #ifdef CONFIG_MALI_MIDGARD_DVFS
112 struct hrtimer timer;
117 struct kbase_device *kbdev;
120 union kbase_pm_policy_data {
121 struct kbasep_pm_policy_always_on always_on;
122 struct kbasep_pm_policy_coarse_demand coarse_demand;
123 struct kbasep_pm_policy_demand demand;
124 #if !MALI_CUSTOMER_RELEASE
125 struct kbasep_pm_policy_demand_always_powered demand_always_powered;
126 struct kbasep_pm_policy_fast_start fast_start;
130 union kbase_pm_ca_policy_data {
131 struct kbasep_pm_ca_policy_fixed fixed;
132 #if !MALI_CUSTOMER_RELEASE
133 struct kbasep_pm_ca_policy_random random;
138 * struct kbase_pm_backend_data - Data stored per device for power management.
140 * This structure contains data for the power management framework. There is one
141 * instance of this structure per device in the system.
143 * @ca_current_policy: The policy that is currently actively controlling core
145 * @pm_current_policy: The policy that is currently actively controlling the
147 * @ca_policy_data: Private data for current CA policy
148 * @pm_policy_data: Private data for current PM policy
149 * @ca_in_transition: Flag indicating when core availability policy is
150 * transitioning cores. The core availability policy must
151 * set this when a change in core availability is occurring.
152 * power_change_lock must be held when accessing this.
153 * @reset_done: Flag when a reset is complete
154 * @reset_done_wait: Wait queue to wait for changes to @reset_done
155 * @l2_powered_wait: Wait queue for whether the l2 cache has been powered as
157 * @l2_powered: State indicating whether all the l2 caches are powered.
158 * Non-zero indicates they're *all* powered
159 * Zero indicates that some (or all) are not powered
160 * @gpu_cycle_counter_requests: The reference count of active gpu cycle counter
162 * @gpu_cycle_counter_requests_lock: Lock to protect @gpu_cycle_counter_requests
163 * @desired_shader_state: A bit mask identifying the shader cores that the
164 * power policy would like to be on. The current state
165 * of the cores may be different, but there should be
166 * transitions in progress that will eventually achieve
167 * this state (assuming that the policy doesn't change
168 * its mind in the mean time).
169 * @powering_on_shader_state: A bit mask indicating which shader cores are
170 * currently in a power-on transition
171 * @desired_tiler_state: A bit mask identifying the tiler cores that the power
172 * policy would like to be on. See @desired_shader_state
173 * @powering_on_tiler_state: A bit mask indicating which tiler core are
174 * currently in a power-on transition
175 * @powering_on_l2_state: A bit mask indicating which l2-caches are currently
176 * in a power-on transition
177 * @gpu_in_desired_state: This flag is set if the GPU is powered as requested
178 * by the desired_xxx_state variables
179 * @gpu_in_desired_state_wait: Wait queue set when @gpu_in_desired_state != 0
180 * @gpu_powered: Set to true when the GPU is powered and register
181 * accesses are possible, false otherwise
182 * @instr_enabled: Set to true when instrumentation is enabled,
184 * @cg1_disabled: Set if the policy wants to keep the second core group
186 * @driver_ready_for_irqs: Debug state indicating whether sufficient
187 * initialization of the driver has occurred to handle
189 * @gpu_powered_lock: Spinlock that must be held when writing @gpu_powered or
190 * accessing @driver_ready_for_irqs
191 * @metrics: Structure to hold metrics for the GPU
192 * @gpu_poweroff_pending: number of poweroff timer ticks until the GPU is
194 * @shader_poweroff_pending_time: number of poweroff timer ticks until shaders
195 * and/or timers are powered off
196 * @gpu_poweroff_timer: Timer for powering off GPU
197 * @gpu_poweroff_wq: Workqueue to power off GPU on when timer fires
198 * @gpu_poweroff_work: Workitem used on @gpu_poweroff_wq
199 * @shader_poweroff_pending: Bit mask of shaders to be powered off on next
201 * @tiler_poweroff_pending: Bit mask of tilers to be powered off on next timer
203 * @poweroff_timer_needed: true if the poweroff timer is currently required,
205 * @poweroff_timer_running: true if the poweroff timer is currently running,
207 * power_change_lock should be held when accessing,
208 * unless there is no way the timer can be running (eg
209 * hrtimer_cancel() was called immediately before)
210 * @callback_power_on: Callback when the GPU needs to be turned on. See
211 * &struct kbase_pm_callback_conf
212 * @callback_power_off: Callback when the GPU may be turned off. See
213 * &struct kbase_pm_callback_conf
214 * @callback_power_suspend: Callback when a suspend occurs and the GPU needs to
215 * be turned off. See &struct kbase_pm_callback_conf
216 * @callback_power_resume: Callback when a resume occurs and the GPU needs to
217 * be turned on. See &struct kbase_pm_callback_conf
218 * @callback_power_runtime_on: Callback when the GPU needs to be turned on. See
219 * &struct kbase_pm_callback_conf
220 * @callback_power_runtime_off: Callback when the GPU may be turned off. See
221 * &struct kbase_pm_callback_conf
222 * @callback_power_runtime_idle: Optional callback when the GPU may be idle. See
223 * &struct kbase_pm_callback_conf
226 * During an IRQ, @ca_current_policy or @pm_current_policy can be NULL when the
227 * policy is being changed with kbase_pm_ca_set_policy() or
228 * kbase_pm_set_policy(). The change is protected under
229 * kbase_device.pm.power_change_lock. Direct access to this
230 * from IRQ context must therefore check for NULL. If NULL, then
231 * kbase_pm_ca_set_policy() or kbase_pm_set_policy() will re-issue the policy
232 * functions that would have been done under IRQ.
234 struct kbase_pm_backend_data {
235 const struct kbase_pm_ca_policy *ca_current_policy;
236 const struct kbase_pm_policy *pm_current_policy;
237 union kbase_pm_ca_policy_data ca_policy_data;
238 union kbase_pm_policy_data pm_policy_data;
239 bool ca_in_transition;
241 wait_queue_head_t reset_done_wait;
242 wait_queue_head_t l2_powered_wait;
244 int gpu_cycle_counter_requests;
245 spinlock_t gpu_cycle_counter_requests_lock;
247 u64 desired_shader_state;
248 u64 powering_on_shader_state;
249 u64 desired_tiler_state;
250 u64 powering_on_tiler_state;
251 u64 powering_on_l2_state;
253 bool gpu_in_desired_state;
254 wait_queue_head_t gpu_in_desired_state_wait;
262 #ifdef CONFIG_MALI_DEBUG
263 bool driver_ready_for_irqs;
264 #endif /* CONFIG_MALI_DEBUG */
266 spinlock_t gpu_powered_lock;
269 struct kbasep_pm_metrics_data metrics;
271 int gpu_poweroff_pending;
272 int shader_poweroff_pending_time;
274 struct hrtimer gpu_poweroff_timer;
275 struct workqueue_struct *gpu_poweroff_wq;
276 struct work_struct gpu_poweroff_work;
278 u64 shader_poweroff_pending;
279 u64 tiler_poweroff_pending;
281 bool poweroff_timer_needed;
282 bool poweroff_timer_running;
284 int (*callback_power_on)(struct kbase_device *kbdev);
285 void (*callback_power_off)(struct kbase_device *kbdev);
286 void (*callback_power_suspend)(struct kbase_device *kbdev);
287 void (*callback_power_resume)(struct kbase_device *kbdev);
288 int (*callback_power_runtime_on)(struct kbase_device *kbdev);
289 void (*callback_power_runtime_off)(struct kbase_device *kbdev);
290 int (*callback_power_runtime_idle)(struct kbase_device *kbdev);
294 /* List of policy IDs */
295 enum kbase_pm_policy_id {
296 KBASE_PM_POLICY_ID_DEMAND = 1,
297 KBASE_PM_POLICY_ID_ALWAYS_ON,
298 KBASE_PM_POLICY_ID_COARSE_DEMAND,
299 #if !MALI_CUSTOMER_RELEASE
300 KBASE_PM_POLICY_ID_DEMAND_ALWAYS_POWERED,
301 KBASE_PM_POLICY_ID_FAST_START
305 typedef u32 kbase_pm_policy_flags;
308 * struct kbase_pm_policy - Power policy structure.
310 * Each power policy exposes a (static) instance of this structure which
311 * contains function pointers to the policy's methods.
313 * @name: The name of this policy
314 * @init: Function called when the policy is selected
315 * @term: Function called when the policy is unselected
316 * @get_core_mask: Function called to get the current shader core mask
317 * @get_core_active: Function called to get the current overall GPU power
319 * @flags: Field indicating flags for this policy
320 * @id: Field indicating an ID for this policy. This is not
321 * necessarily the same as its index in the list returned
322 * by kbase_pm_list_policies().
323 * It is used purely for debugging.
325 struct kbase_pm_policy {
329 * Function called when the policy is selected
331 * This should initialize the kbdev->pm.pm_policy_data structure. It
332 * should not attempt to make any changes to hardware state.
334 * It is undefined what state the cores are in when the function is
337 * @kbdev: The kbase device structure for the device (must be a
340 void (*init)(struct kbase_device *kbdev);
343 * Function called when the policy is unselected.
345 * @kbdev: The kbase device structure for the device (must be a
348 void (*term)(struct kbase_device *kbdev);
351 * Function called to get the current shader core mask
353 * The returned mask should meet or exceed (kbdev->shader_needed_bitmap
354 * | kbdev->shader_inuse_bitmap).
356 * @kbdev: The kbase device structure for the device (must be a
359 * Return: The mask of shader cores to be powered
361 u64 (*get_core_mask)(struct kbase_device *kbdev);
364 * Function called to get the current overall GPU power state
366 * This function should consider the state of kbdev->pm.active_count. If
367 * this count is greater than 0 then there is at least one active
368 * context on the device and the GPU should be powered. If it is equal
369 * to 0 then there are no active contexts and the GPU could be powered
372 * @kbdev: The kbase device structure for the device (must be a
375 * Return: true if the GPU should be powered, false otherwise
377 bool (*get_core_active)(struct kbase_device *kbdev);
379 kbase_pm_policy_flags flags;
380 enum kbase_pm_policy_id id;
384 enum kbase_pm_ca_policy_id {
385 KBASE_PM_CA_POLICY_ID_FIXED = 1,
386 KBASE_PM_CA_POLICY_ID_RANDOM
389 typedef u32 kbase_pm_ca_policy_flags;
392 * struct kbase_pm_ca_policy - Core availability policy structure.
394 * Each core availability policy exposes a (static) instance of this structure
395 * which contains function pointers to the policy's methods.
397 * @name: The name of this policy
398 * @init: Function called when the policy is selected
399 * @term: Function called when the policy is unselected
400 * @get_core_mask: Function called to get the current shader core
402 * @update_core_status: Function called to update the current core status
403 * @flags: Field indicating flags for this policy
404 * @id: Field indicating an ID for this policy. This is not
405 * necessarily the same as its index in the list returned
406 * by kbase_pm_list_policies().
407 * It is used purely for debugging.
409 struct kbase_pm_ca_policy {
413 * Function called when the policy is selected
415 * This should initialize the kbdev->pm.ca_policy_data structure. It
416 * should not attempt to make any changes to hardware state.
418 * It is undefined what state the cores are in when the function is
421 * @kbdev The kbase device structure for the device (must be a
424 void (*init)(struct kbase_device *kbdev);
427 * Function called when the policy is unselected.
429 * @kbdev The kbase device structure for the device (must be a
432 void (*term)(struct kbase_device *kbdev);
435 * Function called to get the current shader core availability mask
437 * When a change in core availability is occurring, the policy must set
438 * kbdev->pm.ca_in_transition to true. This is to indicate that
439 * reporting changes in power state cannot be optimized out, even if
440 * kbdev->pm.desired_shader_state remains unchanged. This must be done
441 * by any functions internal to the Core Availability Policy that change
442 * the return value of kbase_pm_ca_policy::get_core_mask.
444 * @kbdev The kbase device structure for the device (must be a
447 * Return: The current core availability mask
449 u64 (*get_core_mask)(struct kbase_device *kbdev);
452 * Function called to update the current core status
454 * If none of the cores in core group 0 are ready or transitioning, then
455 * the policy must ensure that the next call to get_core_mask does not
456 * return 0 for all cores in core group 0. It is an error to disable
457 * core group 0 through the core availability policy.
459 * When a change in core availability has finished, the policy must set
460 * kbdev->pm.ca_in_transition to false. This is to indicate that
461 * changes in power state can once again be optimized out when
462 * kbdev->pm.desired_shader_state is unchanged.
464 * @kbdev: The kbase device structure for the device
465 * (must be a valid pointer)
466 * @cores_ready: The mask of cores currently powered and
468 * @cores_transitioning: The mask of cores currently transitioning
471 void (*update_core_status)(struct kbase_device *kbdev, u64 cores_ready,
472 u64 cores_transitioning);
474 kbase_pm_ca_policy_flags flags;
477 * Field indicating an ID for this policy. This is not necessarily the
478 * same as its index in the list returned by kbase_pm_list_policies().
479 * It is used purely for debugging.
481 enum kbase_pm_ca_policy_id id;
484 #endif /* _KBASE_PM_HWACCESS_DEFS_H_ */