3 * (C) COPYRIGHT 2014-2017 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 #include "mali_kbase_pm_ca_devfreq.h"
27 #if !MALI_CUSTOMER_RELEASE
28 #include "mali_kbase_pm_ca_random.h"
29 #include "mali_kbase_pm_ca_demand.h"
32 #include "mali_kbase_pm_always_on.h"
33 #include "mali_kbase_pm_coarse_demand.h"
34 #include "mali_kbase_pm_demand.h"
35 #if !MALI_CUSTOMER_RELEASE
36 #include "mali_kbase_pm_demand_always_powered.h"
37 #include "mali_kbase_pm_fast_start.h"
40 /* Forward definition - see mali_kbase.h */
45 * enum kbase_pm_core_type - The types of core in a GPU.
47 * These enumerated values are used in calls to
48 * - kbase_pm_get_present_cores()
49 * - kbase_pm_get_active_cores()
50 * - kbase_pm_get_trans_cores()
51 * - kbase_pm_get_ready_cores().
53 * They specify which type of core should be acted on. These values are set in
54 * a manner that allows core_type_to_reg() function to be simpler and more
57 * @KBASE_PM_CORE_L2: The L2 cache
58 * @KBASE_PM_CORE_SHADER: Shader cores
59 * @KBASE_PM_CORE_TILER: Tiler cores
60 * @KBASE_PM_CORE_STACK: Core stacks
62 enum kbase_pm_core_type
{
63 KBASE_PM_CORE_L2
= L2_PRESENT_LO
,
64 KBASE_PM_CORE_SHADER
= SHADER_PRESENT_LO
,
65 KBASE_PM_CORE_TILER
= TILER_PRESENT_LO
,
66 KBASE_PM_CORE_STACK
= STACK_PRESENT_LO
70 * struct kbasep_pm_metrics_data - Metrics data collected for use by the power
71 * management framework.
73 * @time_period_start: time at which busy/idle measurements started
74 * @time_busy: number of ns the GPU was busy executing jobs since the
75 * @time_period_start timestamp.
76 * @time_idle: number of ns since time_period_start the GPU was not executing
77 * jobs since the @time_period_start timestamp.
78 * @prev_busy: busy time in ns of previous time period.
79 * Updated when metrics are reset.
80 * @prev_idle: idle time in ns of previous time period
81 * Updated when metrics are reset.
82 * @gpu_active: true when the GPU is executing jobs. false when
83 * not. Updated when the job scheduler informs us a job in submitted
84 * or removed from a GPU slot.
85 * @busy_cl: number of ns the GPU was busy executing CL jobs. Note that
86 * if two CL jobs were active for 400ns, this value would be updated
88 * @busy_gl: number of ns the GPU was busy executing GL jobs. Note that
89 * if two GL jobs were active for 400ns, this value would be updated
91 * @active_cl_ctx: number of CL jobs active on the GPU. Array is per-device.
92 * @active_gl_ctx: number of GL jobs active on the GPU. Array is per-slot. As
93 * GL jobs never run on slot 2 this slot is not recorded.
94 * @lock: spinlock protecting the kbasep_pm_metrics_data structure
95 * @timer: timer to regularly make DVFS decisions based on the power
97 * @timer_active: boolean indicating @timer is running
98 * @platform_data: pointer to data controlled by platform specific code
99 * @kbdev: pointer to kbase device for which metrics are collected
102 struct kbasep_pm_metrics_data
{
103 ktime_t time_period_start
;
111 u32 active_cl_ctx
[2];
112 u32 active_gl_ctx
[2]; /* GL jobs can only run on 2 of the 3 job slots */
115 #ifdef CONFIG_MALI_MIDGARD_DVFS
116 struct hrtimer timer
;
121 struct kbase_device
*kbdev
;
124 union kbase_pm_policy_data
{
125 struct kbasep_pm_policy_always_on always_on
;
126 struct kbasep_pm_policy_coarse_demand coarse_demand
;
127 struct kbasep_pm_policy_demand demand
;
128 #if !MALI_CUSTOMER_RELEASE
129 struct kbasep_pm_policy_demand_always_powered demand_always_powered
;
130 struct kbasep_pm_policy_fast_start fast_start
;
134 union kbase_pm_ca_policy_data
{
135 struct kbasep_pm_ca_policy_fixed fixed
;
136 struct kbasep_pm_ca_policy_devfreq devfreq
;
137 #if !MALI_CUSTOMER_RELEASE
138 struct kbasep_pm_ca_policy_random random
;
139 struct kbasep_pm_ca_policy_demand demand
;
144 * struct kbase_pm_backend_data - Data stored per device for power management.
146 * This structure contains data for the power management framework. There is one
147 * instance of this structure per device in the system.
149 * @ca_current_policy: The policy that is currently actively controlling core
151 * @pm_current_policy: The policy that is currently actively controlling the
153 * @ca_policy_data: Private data for current CA policy
154 * @pm_policy_data: Private data for current PM policy
155 * @ca_in_transition: Flag indicating when core availability policy is
156 * transitioning cores. The core availability policy must
157 * set this when a change in core availability is occurring.
158 * power_change_lock must be held when accessing this.
159 * @reset_done: Flag when a reset is complete
160 * @reset_done_wait: Wait queue to wait for changes to @reset_done
161 * @l2_powered_wait: Wait queue for whether the l2 cache has been powered as
163 * @l2_powered: State indicating whether all the l2 caches are powered.
164 * Non-zero indicates they're *all* powered
165 * Zero indicates that some (or all) are not powered
166 * @gpu_cycle_counter_requests: The reference count of active gpu cycle counter
168 * @gpu_cycle_counter_requests_lock: Lock to protect @gpu_cycle_counter_requests
169 * @desired_shader_state: A bit mask identifying the shader cores that the
170 * power policy would like to be on. The current state
171 * of the cores may be different, but there should be
172 * transitions in progress that will eventually achieve
173 * this state (assuming that the policy doesn't change
174 * its mind in the mean time).
175 * @powering_on_shader_state: A bit mask indicating which shader cores are
176 * currently in a power-on transition
177 * @desired_tiler_state: A bit mask identifying the tiler cores that the power
178 * policy would like to be on. See @desired_shader_state
179 * @powering_on_tiler_state: A bit mask indicating which tiler core are
180 * currently in a power-on transition
181 * @powering_on_l2_state: A bit mask indicating which l2-caches are currently
182 * in a power-on transition
183 * @powering_on_stack_state: A bit mask indicating which core stacks are
184 * currently in a power-on transition
185 * @gpu_in_desired_state: This flag is set if the GPU is powered as requested
186 * by the desired_xxx_state variables
187 * @gpu_in_desired_state_wait: Wait queue set when @gpu_in_desired_state != 0
188 * @gpu_powered: Set to true when the GPU is powered and register
189 * accesses are possible, false otherwise
190 * @instr_enabled: Set to true when instrumentation is enabled,
192 * @cg1_disabled: Set if the policy wants to keep the second core group
194 * @driver_ready_for_irqs: Debug state indicating whether sufficient
195 * initialization of the driver has occurred to handle
197 * @gpu_powered_lock: Spinlock that must be held when writing @gpu_powered or
198 * accessing @driver_ready_for_irqs
199 * @metrics: Structure to hold metrics for the GPU
200 * @gpu_poweroff_pending: number of poweroff timer ticks until the GPU is
202 * @shader_poweroff_pending_time: number of poweroff timer ticks until shaders
203 * and/or timers are powered off
204 * @gpu_poweroff_timer: Timer for powering off GPU
205 * @gpu_poweroff_wq: Workqueue to power off GPU on when timer fires
206 * @gpu_poweroff_work: Workitem used on @gpu_poweroff_wq
207 * @shader_poweroff_pending: Bit mask of shaders to be powered off on next
209 * @tiler_poweroff_pending: Bit mask of tilers to be powered off on next timer
211 * @poweroff_timer_needed: true if the poweroff timer is currently required,
213 * @poweroff_timer_running: true if the poweroff timer is currently running,
215 * power_change_lock should be held when accessing,
216 * unless there is no way the timer can be running (eg
217 * hrtimer_cancel() was called immediately before)
218 * @poweroff_wait_in_progress: true if a wait for GPU power off is in progress.
219 * hwaccess_lock must be held when accessing
220 * @poweron_required: true if a GPU power on is required. Should only be set
221 * when poweroff_wait_in_progress is true, and therefore the
222 * GPU can not immediately be powered on. pm.lock must be
223 * held when accessing
224 * @poweroff_is_suspend: true if the GPU is being powered off due to a suspend
225 * request. pm.lock must be held when accessing
226 * @gpu_poweroff_wait_wq: workqueue for waiting for GPU to power off
227 * @gpu_poweroff_wait_work: work item for use with @gpu_poweroff_wait_wq
228 * @poweroff_wait: waitqueue for waiting for @gpu_poweroff_wait_work to complete
229 * @callback_power_on: Callback when the GPU needs to be turned on. See
230 * &struct kbase_pm_callback_conf
231 * @callback_power_off: Callback when the GPU may be turned off. See
232 * &struct kbase_pm_callback_conf
233 * @callback_power_suspend: Callback when a suspend occurs and the GPU needs to
234 * be turned off. See &struct kbase_pm_callback_conf
235 * @callback_power_resume: Callback when a resume occurs and the GPU needs to
236 * be turned on. See &struct kbase_pm_callback_conf
237 * @callback_power_runtime_on: Callback when the GPU needs to be turned on. See
238 * &struct kbase_pm_callback_conf
239 * @callback_power_runtime_off: Callback when the GPU may be turned off. See
240 * &struct kbase_pm_callback_conf
241 * @callback_power_runtime_idle: Optional callback when the GPU may be idle. See
242 * &struct kbase_pm_callback_conf
245 * During an IRQ, @ca_current_policy or @pm_current_policy can be NULL when the
246 * policy is being changed with kbase_pm_ca_set_policy() or
247 * kbase_pm_set_policy(). The change is protected under
248 * kbase_device.pm.power_change_lock. Direct access to this
249 * from IRQ context must therefore check for NULL. If NULL, then
250 * kbase_pm_ca_set_policy() or kbase_pm_set_policy() will re-issue the policy
251 * functions that would have been done under IRQ.
253 struct kbase_pm_backend_data
{
254 const struct kbase_pm_ca_policy
*ca_current_policy
;
255 const struct kbase_pm_policy
*pm_current_policy
;
256 union kbase_pm_ca_policy_data ca_policy_data
;
257 union kbase_pm_policy_data pm_policy_data
;
258 bool ca_in_transition
;
260 wait_queue_head_t reset_done_wait
;
261 wait_queue_head_t l2_powered_wait
;
263 int gpu_cycle_counter_requests
;
264 spinlock_t gpu_cycle_counter_requests_lock
;
266 u64 desired_shader_state
;
267 u64 powering_on_shader_state
;
268 u64 desired_tiler_state
;
269 u64 powering_on_tiler_state
;
270 u64 powering_on_l2_state
;
271 #ifdef CONFIG_MALI_CORESTACK
272 u64 powering_on_stack_state
;
273 #endif /* CONFIG_MALI_CORESTACK */
275 bool gpu_in_desired_state
;
276 wait_queue_head_t gpu_in_desired_state_wait
;
284 #ifdef CONFIG_MALI_DEBUG
285 bool driver_ready_for_irqs
;
286 #endif /* CONFIG_MALI_DEBUG */
288 spinlock_t gpu_powered_lock
;
291 struct kbasep_pm_metrics_data metrics
;
293 int gpu_poweroff_pending
;
294 int shader_poweroff_pending_time
;
296 struct hrtimer gpu_poweroff_timer
;
297 struct workqueue_struct
*gpu_poweroff_wq
;
298 struct work_struct gpu_poweroff_work
;
300 u64 shader_poweroff_pending
;
301 u64 tiler_poweroff_pending
;
303 bool poweroff_timer_needed
;
304 bool poweroff_timer_running
;
306 bool poweroff_wait_in_progress
;
307 bool poweron_required
;
308 bool poweroff_is_suspend
;
310 struct workqueue_struct
*gpu_poweroff_wait_wq
;
311 struct work_struct gpu_poweroff_wait_work
;
313 wait_queue_head_t poweroff_wait
;
315 int (*callback_power_on
)(struct kbase_device
*kbdev
);
316 void (*callback_power_off
)(struct kbase_device
*kbdev
);
317 void (*callback_power_suspend
)(struct kbase_device
*kbdev
);
318 void (*callback_power_resume
)(struct kbase_device
*kbdev
);
319 int (*callback_power_runtime_on
)(struct kbase_device
*kbdev
);
320 void (*callback_power_runtime_off
)(struct kbase_device
*kbdev
);
321 int (*callback_power_runtime_idle
)(struct kbase_device
*kbdev
);
325 /* List of policy IDs */
326 enum kbase_pm_policy_id
{
327 KBASE_PM_POLICY_ID_DEMAND
= 1,
328 KBASE_PM_POLICY_ID_ALWAYS_ON
,
329 KBASE_PM_POLICY_ID_COARSE_DEMAND
,
330 #if !MALI_CUSTOMER_RELEASE
331 KBASE_PM_POLICY_ID_DEMAND_ALWAYS_POWERED
,
332 KBASE_PM_POLICY_ID_FAST_START
336 typedef u32 kbase_pm_policy_flags
;
339 * struct kbase_pm_policy - Power policy structure.
341 * Each power policy exposes a (static) instance of this structure which
342 * contains function pointers to the policy's methods.
344 * @name: The name of this policy
345 * @init: Function called when the policy is selected
346 * @term: Function called when the policy is unselected
347 * @get_core_mask: Function called to get the current shader core mask
348 * @get_core_active: Function called to get the current overall GPU power
350 * @flags: Field indicating flags for this policy
351 * @id: Field indicating an ID for this policy. This is not
352 * necessarily the same as its index in the list returned
353 * by kbase_pm_list_policies().
354 * It is used purely for debugging.
356 struct kbase_pm_policy
{
360 * Function called when the policy is selected
362 * This should initialize the kbdev->pm.pm_policy_data structure. It
363 * should not attempt to make any changes to hardware state.
365 * It is undefined what state the cores are in when the function is
368 * @kbdev: The kbase device structure for the device (must be a
371 void (*init
)(struct kbase_device
*kbdev
);
374 * Function called when the policy is unselected.
376 * @kbdev: The kbase device structure for the device (must be a
379 void (*term
)(struct kbase_device
*kbdev
);
382 * Function called to get the current shader core mask
384 * The returned mask should meet or exceed (kbdev->shader_needed_bitmap
385 * | kbdev->shader_inuse_bitmap).
387 * @kbdev: The kbase device structure for the device (must be a
390 * Return: The mask of shader cores to be powered
392 u64 (*get_core_mask
)(struct kbase_device
*kbdev
);
395 * Function called to get the current overall GPU power state
397 * This function should consider the state of kbdev->pm.active_count. If
398 * this count is greater than 0 then there is at least one active
399 * context on the device and the GPU should be powered. If it is equal
400 * to 0 then there are no active contexts and the GPU could be powered
403 * @kbdev: The kbase device structure for the device (must be a
406 * Return: true if the GPU should be powered, false otherwise
408 bool (*get_core_active
)(struct kbase_device
*kbdev
);
410 kbase_pm_policy_flags flags
;
411 enum kbase_pm_policy_id id
;
415 enum kbase_pm_ca_policy_id
{
416 KBASE_PM_CA_POLICY_ID_FIXED
= 1,
417 KBASE_PM_CA_POLICY_ID_DEVFREQ
,
418 KBASE_PM_CA_POLICY_ID_RANDOM
421 typedef u32 kbase_pm_ca_policy_flags
;
424 * Maximum length of a CA policy names
426 #define KBASE_PM_CA_MAX_POLICY_NAME_LEN 15
429 * struct kbase_pm_ca_policy - Core availability policy structure.
431 * Each core availability policy exposes a (static) instance of this structure
432 * which contains function pointers to the policy's methods.
434 * @name: The name of this policy
435 * @init: Function called when the policy is selected
436 * @term: Function called when the policy is unselected
437 * @get_core_mask: Function called to get the current shader core
439 * @update_core_status: Function called to update the current core status
440 * @flags: Field indicating flags for this policy
441 * @id: Field indicating an ID for this policy. This is not
442 * necessarily the same as its index in the list returned
443 * by kbase_pm_list_policies().
444 * It is used purely for debugging.
446 struct kbase_pm_ca_policy
{
447 char name
[KBASE_PM_CA_MAX_POLICY_NAME_LEN
+ 1];
450 * Function called when the policy is selected
452 * This should initialize the kbdev->pm.ca_policy_data structure. It
453 * should not attempt to make any changes to hardware state.
455 * It is undefined what state the cores are in when the function is
458 * @kbdev The kbase device structure for the device (must be a
461 void (*init
)(struct kbase_device
*kbdev
);
464 * Function called when the policy is unselected.
466 * @kbdev The kbase device structure for the device (must be a
469 void (*term
)(struct kbase_device
*kbdev
);
472 * Function called to get the current shader core availability mask
474 * When a change in core availability is occurring, the policy must set
475 * kbdev->pm.ca_in_transition to true. This is to indicate that
476 * reporting changes in power state cannot be optimized out, even if
477 * kbdev->pm.desired_shader_state remains unchanged. This must be done
478 * by any functions internal to the Core Availability Policy that change
479 * the return value of kbase_pm_ca_policy::get_core_mask.
481 * @kbdev The kbase device structure for the device (must be a
484 * Return: The current core availability mask
486 u64 (*get_core_mask
)(struct kbase_device
*kbdev
);
489 * Function called to update the current core status
491 * If none of the cores in core group 0 are ready or transitioning, then
492 * the policy must ensure that the next call to get_core_mask does not
493 * return 0 for all cores in core group 0. It is an error to disable
494 * core group 0 through the core availability policy.
496 * When a change in core availability has finished, the policy must set
497 * kbdev->pm.ca_in_transition to false. This is to indicate that
498 * changes in power state can once again be optimized out when
499 * kbdev->pm.desired_shader_state is unchanged.
501 * @kbdev: The kbase device structure for the device
502 * (must be a valid pointer)
503 * @cores_ready: The mask of cores currently powered and
505 * @cores_transitioning: The mask of cores currently transitioning
508 void (*update_core_status
)(struct kbase_device
*kbdev
, u64 cores_ready
,
509 u64 cores_transitioning
);
511 kbase_pm_ca_policy_flags flags
;
514 * Field indicating an ID for this policy. This is not necessarily the
515 * same as its index in the list returned by kbase_pm_list_policies().
516 * It is used purely for debugging.
518 enum kbase_pm_ca_policy_id id
;
521 #endif /* _KBASE_PM_HWACCESS_DEFS_H_ */