3 * (C) COPYRIGHT 2010-2015 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.
21 * @file mali_kbase_pm_hwaccess_internal.h
22 * Power management API definitions used internally by GPU backend
25 #ifndef _KBASE_BACKEND_PM_INTERNAL_H_
26 #define _KBASE_BACKEND_PM_INTERNAL_H_
28 #include <mali_kbase_hwaccess_pm.h>
30 #include "mali_kbase_pm_ca.h"
31 #include "mali_kbase_pm_policy.h"
37 * The OS may choose to turn off idle devices
39 * @param kbdev The kbase device structure for the device (must be a valid
42 void kbase_pm_dev_idle(struct kbase_device *kbdev);
47 * The OS should avoid opportunistically turning off the GPU while it is active
49 * @param kbdev The kbase device structure for the device (must be a valid
52 void kbase_pm_dev_activate(struct kbase_device *kbdev);
55 * Get details of the cores that are present in the device.
57 * This function can be called by the active power policy to return a bitmask of
58 * the cores (of a specified type) present in the GPU device and also a count of
59 * the number of cores.
61 * @param kbdev The kbase device structure for the device (must be a valid
63 * @param type The type of core (see the @ref enum kbase_pm_core_type
66 * @return The bit mask of cores present
68 u64 kbase_pm_get_present_cores(struct kbase_device *kbdev,
69 enum kbase_pm_core_type type);
72 * Get details of the cores that are currently active in the device.
74 * This function can be called by the active power policy to return a bitmask of
75 * the cores (of a specified type) that are actively processing work (i.e.
76 * turned on *and* busy).
78 * @param kbdev The kbase device structure for the device (must be a valid
80 * @param type The type of core (see the @ref enum kbase_pm_core_type
83 * @return The bit mask of active cores
85 u64 kbase_pm_get_active_cores(struct kbase_device *kbdev,
86 enum kbase_pm_core_type type);
89 * Get details of the cores that are currently transitioning between power
92 * This function can be called by the active power policy to return a bitmask of
93 * the cores (of a specified type) that are currently transitioning between
96 * @param kbdev The kbase device structure for the device (must be a valid
98 * @param type The type of core (see the @ref enum kbase_pm_core_type
101 * @return The bit mask of transitioning cores
103 u64 kbase_pm_get_trans_cores(struct kbase_device *kbdev,
104 enum kbase_pm_core_type type);
107 * Get details of the cores that are currently powered and ready for jobs.
109 * This function can be called by the active power policy to return a bitmask of
110 * the cores (of a specified type) that are powered and ready for jobs (they may
111 * or may not be currently executing jobs).
113 * @param kbdev The kbase device structure for the device (must be a valid
115 * @param type The type of core (see the @ref enum kbase_pm_core_type
118 * @return The bit mask of ready cores
120 u64 kbase_pm_get_ready_cores(struct kbase_device *kbdev,
121 enum kbase_pm_core_type type);
124 * Turn the clock for the device on, and enable device interrupts.
126 * This function can be used by a power policy to turn the clock for the GPU on.
127 * It should be modified during integration to perform the necessary actions to
128 * ensure that the GPU is fully powered and clocked.
130 * @param kbdev The kbase device structure for the device (must be a valid
132 * @param is_resume true if clock on due to resume after suspend,
135 void kbase_pm_clock_on(struct kbase_device *kbdev, bool is_resume);
138 * Disable device interrupts, and turn the clock for the device off.
140 * This function can be used by a power policy to turn the clock for the GPU
141 * off. It should be modified during integration to perform the necessary
142 * actions to turn the clock off (if this is possible in the integration).
144 * @param kbdev The kbase device structure for the device (must be a valid
146 * @param is_suspend true if clock off due to suspend, false otherwise
148 * @return true if clock was turned off
149 * false if clock can not be turned off due to pending page/bus fault
150 * workers. Caller must flush MMU workqueues and retry
152 bool kbase_pm_clock_off(struct kbase_device *kbdev, bool is_suspend);
155 * Enable interrupts on the device.
157 * Interrupts are also enabled after a call to kbase_pm_clock_on().
159 * @param kbdev The kbase device structure for the device (must be a valid
162 void kbase_pm_enable_interrupts(struct kbase_device *kbdev);
165 * Enable interrupts on the device, using the provided mask to set MMU_IRQ_MASK.
167 * Interrupts are also enabled after a call to kbase_pm_clock_on().
169 * @param kbdev The kbase device structure for the device (must be a valid
171 * @param mask The mask to use for MMU_IRQ_MASK
173 void kbase_pm_enable_interrupts_mmu_mask(struct kbase_device *kbdev, u32 mask);
176 * Disable interrupts on the device.
178 * This prevents delivery of Power Management interrupts to the CPU so that
179 * kbase_pm_check_transitions_nolock() will not be called from the IRQ handler
180 * until @ref kbase_pm_enable_interrupts or kbase_pm_clock_on() is called.
182 * Interrupts are also disabled after a call to kbase_pm_clock_off().
184 * @param kbdev The kbase device structure for the device (must be a valid
187 void kbase_pm_disable_interrupts(struct kbase_device *kbdev);
190 * kbase_pm_init_hw - Initialize the hardware.
191 * @kbdev: The kbase device structure for the device (must be a valid pointer)
192 * @flags: Flags specifying the type of PM init
194 * This function checks the GPU ID register to ensure that the GPU is supported
195 * by the driver and performs a reset on the device so that it is in a known
196 * state before the device is used.
198 * Return: 0 if the device is supported and successfully reset.
200 int kbase_pm_init_hw(struct kbase_device *kbdev, unsigned int flags);
203 * The GPU has been reset successfully.
205 * This function must be called by the GPU interrupt handler when the
206 * RESET_COMPLETED bit is set. It signals to the power management initialization
207 * code that the GPU has been successfully reset.
209 * @param kbdev The kbase device structure for the device (must be a valid
212 void kbase_pm_reset_done(struct kbase_device *kbdev);
216 * Check if there are any power transitions to make, and if so start them.
218 * This function will check the desired_xx_state members of
219 * struct kbase_pm_device_data and the actual status of the hardware to see if
220 * any power transitions can be made at this time to make the hardware state
221 * closer to the state desired by the power policy.
223 * The return value can be used to check whether all the desired cores are
224 * available, and so whether it's worth submitting a job (e.g. from a Power
227 * Note that this still returns true when desired_xx_state has no
228 * cores. That is: of the no cores desired, none were <em>un</em>available. In
229 * this case, the caller may still need to try submitting jobs. This is because
230 * the Core Availability Policy might have taken us to an intermediate state
231 * where no cores are powered, before powering on more cores (e.g. for core
234 * The caller must hold kbase_device::pm::power_change_lock
236 * @param kbdev The kbase device structure for the device (must be a valid
238 * @return non-zero when all desired cores are available. That is,
239 * it's worthwhile for the caller to submit a job.
240 * @return false otherwise
242 bool kbase_pm_check_transitions_nolock(struct kbase_device *kbdev);
245 * Synchronous and locking variant of kbase_pm_check_transitions_nolock()
247 * On returning, the desired state at the time of the call will have been met.
249 * @note There is nothing to stop the core being switched off by calls to
250 * kbase_pm_release_cores() or kbase_pm_unrequest_cores(). Therefore, the
251 * caller must have already made a call to
252 * kbase_pm_request_cores()/kbase_pm_request_cores_sync() previously.
254 * The usual use-case for this is to ensure cores are 'READY' after performing
257 * Unlike kbase_pm_check_transitions_nolock(), the caller must not hold
258 * kbase_device::pm::power_change_lock, because this function will take that
261 * @param kbdev The kbase device structure for the device (must be a valid
264 void kbase_pm_check_transitions_sync(struct kbase_device *kbdev);
267 * Variant of kbase_pm_update_cores_state() where the caller must hold
268 * kbase_device::pm::power_change_lock
270 * @param kbdev The kbase device structure for the device (must be a valid
273 void kbase_pm_update_cores_state_nolock(struct kbase_device *kbdev);
276 * Update the desired state of shader cores from the Power Policy, and begin
277 * any power transitions.
279 * This function will update the desired_xx_state members of
280 * struct kbase_pm_device_data by calling into the current Power Policy. It will
281 * then begin power transitions to make the hardware acheive the desired shader
284 * @param kbdev The kbase device structure for the device (must be a valid
287 void kbase_pm_update_cores_state(struct kbase_device *kbdev);
290 * Cancel any pending requests to power off the GPU and/or shader cores.
292 * This should be called by any functions which directly power off the GPU.
294 * @param kbdev The kbase device structure for the device (must be a valid
297 void kbase_pm_cancel_deferred_poweroff(struct kbase_device *kbdev);
300 * Read the bitmasks of present cores.
302 * This information is cached to avoid having to perform register reads whenever
303 * the information is required.
305 * @param kbdev The kbase device structure for the device (must be a valid
308 void kbasep_pm_read_present_cores(struct kbase_device *kbdev);
311 * Initialize the metrics gathering framework.
313 * This must be called before other metric gathering APIs are called.
315 * @param kbdev The kbase device structure for the device (must be a valid
318 * @return 0 on success, error code on error
320 int kbasep_pm_metrics_init(struct kbase_device *kbdev);
323 * Terminate the metrics gathering framework.
325 * This must be called when metric gathering is no longer required. It is an
326 * error to call any metrics gathering function (other than
327 * kbasep_pm_metrics_init) after calling this function.
329 * @param kbdev The kbase device structure for the device (must be a valid
332 void kbasep_pm_metrics_term(struct kbase_device *kbdev);
335 * Function to be called by the frame buffer driver to update the vsync metric.
337 * This function should be called by the frame buffer driver to update whether
338 * the system is hitting the vsync target or not. buffer_updated should be true
339 * if the vsync corresponded with a new frame being displayed, otherwise it
340 * should be false. This function does not need to be called every vsync, but
341 * only when the value of buffer_updated differs from a previous call.
343 * @param kbdev The kbase device structure for the device (must be a
345 * @param buffer_updated True if the buffer has been updated on this VSync,
348 void kbase_pm_report_vsync(struct kbase_device *kbdev, int buffer_updated);
351 * Configure the frame buffer device to set the vsync callback.
353 * This function should do whatever is necessary for this integration to ensure
354 * that kbase_pm_report_vsync is called appropriately.
356 * This function will need porting as part of the integration for a device.
358 * @param kbdev The kbase device structure for the device (must be a valid
361 void kbase_pm_register_vsync_callback(struct kbase_device *kbdev);
364 * Free any resources that kbase_pm_register_vsync_callback allocated.
366 * This function should perform any cleanup required from the call to
367 * kbase_pm_register_vsync_callback. No call backs should occur after this
368 * function has returned.
370 * This function will need porting as part of the integration for a device.
372 * @param kbdev The kbase device structure for the device (must be a valid
375 void kbase_pm_unregister_vsync_callback(struct kbase_device *kbdev);
378 * Determine whether the DVFS system should change the clock speed of the GPU.
380 * This function should be called regularly by the DVFS system to check whether
381 * the clock speed of the GPU needs updating. It will return one of three
382 * enumerated values of kbase_pm_dvfs_action:
384 * @param kbdev The kbase device structure for the device
385 * (must be a valid pointer)
386 * @retval KBASE_PM_DVFS_NOP The clock does not need changing
387 * @retval KBASE_PM_DVFS_CLOCK_UP The clock frequency should be increased if
389 * @retval KBASE_PM_DVFS_CLOCK_DOWN The clock frequency should be decreased if
392 enum kbase_pm_dvfs_action kbase_pm_get_dvfs_action(struct kbase_device *kbdev);
395 * Mark that the GPU cycle counter is needed, if the caller is the first caller
396 * then the GPU cycle counters will be enabled along with the l2 cache
398 * The GPU must be powered when calling this function (i.e.
399 * @ref kbase_pm_context_active must have been called).
401 * @param kbdev The kbase device structure for the device (must be a valid
404 void kbase_pm_request_gpu_cycle_counter(struct kbase_device *kbdev);
407 * This is a version of the above function
408 * (@ref kbase_pm_request_gpu_cycle_counter) suitable for being called when the
409 * l2 cache is known to be on and assured to be on until the subsequent call of
410 * kbase_pm_release_gpu_cycle_counter such as when a job is submitted. It does
411 * not sleep and can be called from atomic functions.
413 * The GPU must be powered when calling this function (i.e.
414 * @ref kbase_pm_context_active must have been called) and the l2 cache must be
417 * @param kbdev The kbase device structure for the device (must be a valid
420 void kbase_pm_request_gpu_cycle_counter_l2_is_on(struct kbase_device *kbdev);
423 * Mark that the GPU cycle counter is no longer in use, if the caller is the
424 * last caller then the GPU cycle counters will be disabled. A request must have
425 * been made before a call to this.
427 * @param kbdev The kbase device structure for the device (must be a valid
430 void kbase_pm_release_gpu_cycle_counter(struct kbase_device *kbdev);
433 * Enables access to the GPU registers before power management has powered up
434 * the GPU with kbase_pm_powerup().
436 * Access to registers should be done using kbase_os_reg_read/write() at this
437 * stage, not kbase_reg_read/write().
439 * This results in the power management callbacks provided in the driver
440 * configuration to get called to turn on power and/or clocks to the GPU. See
441 * @ref kbase_pm_callback_conf.
443 * This should only be used before power management is powered up with
446 * @param kbdev The kbase device structure for the device (must be a valid
449 void kbase_pm_register_access_enable(struct kbase_device *kbdev);
452 * Disables access to the GPU registers enabled earlier by a call to
453 * kbase_pm_register_access_enable().
455 * This results in the power management callbacks provided in the driver
456 * configuration to get called to turn off power and/or clocks to the GPU. See
457 * @ref kbase_pm_callback_conf
459 * This should only be used before power management is powered up with
462 * @param kbdev The kbase device structure for the device (must be a valid
465 void kbase_pm_register_access_disable(struct kbase_device *kbdev);
467 /* NOTE: kbase_pm_is_suspending is in mali_kbase.h, because it is an inline
471 * Check if the power management metrics collection is active.
473 * Note that this returns if the power management metrics collection was
474 * active at the time of calling, it is possible that after the call the metrics
475 * collection enable may have changed state.
477 * The caller must handle the consequence that the state may have changed.
479 * @param kbdev The kbase device structure for the device (must be a valid
481 * @return true if metrics collection was active else false.
483 bool kbase_pm_metrics_is_active(struct kbase_device *kbdev);
486 * Power on the GPU, and any cores that are requested.
488 * @param kbdev The kbase device structure for the device (must be a valid
490 * @param is_resume true if power on due to resume after suspend,
493 void kbase_pm_do_poweron(struct kbase_device *kbdev, bool is_resume);
496 * Power off the GPU, and any cores that have been requested.
498 * @param kbdev The kbase device structure for the device (must be a valid
500 * @param is_suspend true if power off due to suspend,
502 * @return true if power was turned off
503 * false if power can not be turned off due to pending page/bus
504 * fault workers. Caller must flush MMU workqueues and retry
506 bool kbase_pm_do_poweroff(struct kbase_device *kbdev, bool is_suspend);
508 #ifdef CONFIG_PM_DEVFREQ
509 void kbase_pm_get_dvfs_utilisation(struct kbase_device *kbdev,
510 unsigned long *total, unsigned long *busy);
511 void kbase_pm_reset_dvfs_utilisation(struct kbase_device *kbdev);
514 #ifdef CONFIG_MALI_MIDGARD_DVFS
517 * Function provided by platform specific code when DVFS is enabled to allow
518 * the power management metrics system to report utilisation.
520 * @param kbdev The kbase device structure for the device (must be a
522 * @param utilisation The current calculated utilisation by the metrics
524 * @param util_gl_share The current calculated gl share of utilisation.
525 * @param util_cl_share The current calculated cl share of utilisation per core
527 * @return Returns 0 on failure and non zero on success.
530 int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation,
531 u32 util_gl_share, u32 util_cl_share[2]);
534 void kbase_pm_power_changed(struct kbase_device *kbdev);
537 * Inform the metrics system that an atom is about to be run.
539 * @param kbdev The kbase device structure for the device (must be a valid
541 * @param katom The atom that is about to be run
543 void kbase_pm_metrics_run_atom(struct kbase_device *kbdev,
544 struct kbase_jd_atom *katom);
547 * Inform the metrics system that an atom has been run and is being released.
549 * @param kbdev The kbase device structure for the device (must be a valid
551 * @param katom The atom that is about to be released
553 void kbase_pm_metrics_release_atom(struct kbase_device *kbdev,
554 struct kbase_jd_atom *katom);
557 #endif /* _KBASE_BACKEND_PM_INTERNAL_H_ */