rk3288 gpu : update GPU driver r4p0_eac version
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_pm.h
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
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
8  * of such GNU licence.
9  *
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.
13  *
14  */
15
16
17
18
19
20 /**
21  * @file mali_kbase_pm.h
22  * Power management API definitions
23  */
24
25 #ifndef _KBASE_PM_H_
26 #define _KBASE_PM_H_
27
28 #include <mali_midg_regmap.h>
29 #include <linux/atomic.h>
30
31 /* Forward definition - see mali_kbase.h */
32 struct kbase_device;
33
34 #include "mali_kbase_pm_ca.h"
35 #include "mali_kbase_pm_policy.h"
36
37 #include "mali_kbase_pm_ca_fixed.h"
38 #if MALI_CUSTOMER_RELEASE == 0
39 #include "mali_kbase_pm_ca_random.h"
40 #endif
41
42 #include "mali_kbase_pm_always_on.h"
43 #include "mali_kbase_pm_coarse_demand.h"
44 #include "mali_kbase_pm_demand.h"
45 #if MALI_CUSTOMER_RELEASE == 0
46 #include "mali_kbase_pm_demand_always_powered.h"
47 #include "mali_kbase_pm_fast_start.h"
48 #endif
49
50 /** The types of core in a GPU.
51  *
52  * These enumerated values are used in calls to:
53  * - @ref kbase_pm_get_present_cores
54  * - @ref kbase_pm_get_active_cores
55  * - @ref kbase_pm_get_trans_cores
56  * - @ref kbase_pm_get_ready_cores.
57  *
58  * They specify which type of core should be acted on.  These values are set in
59  * a manner that allows @ref core_type_to_reg function to be simpler and more
60  * efficient.
61  */
62 typedef enum kbase_pm_core_type {
63         KBASE_PM_CORE_L3 = L3_PRESENT_LO,           /**< The L3 cache */
64         KBASE_PM_CORE_L2 = L2_PRESENT_LO,           /**< The L2 cache */
65         KBASE_PM_CORE_SHADER = SHADER_PRESENT_LO,   /**< Shader cores */
66         KBASE_PM_CORE_TILER = TILER_PRESENT_LO      /**< Tiler cores */
67 } kbase_pm_core_type;
68
69 /** Initialize the power management framework.
70  *
71  * Must be called before any other power management function
72  *
73  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
74  *
75  * @return MALI_ERROR_NONE if the power management framework was successfully initialized.
76  */
77 mali_error kbase_pm_init(struct kbase_device *kbdev);
78
79 /** Power up GPU after all modules have been initialized and interrupt handlers installed.
80  *
81  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
82  *
83  * @return MALI_ERROR_NONE if powerup was successful.
84  */
85 mali_error kbase_pm_powerup(struct kbase_device *kbdev);
86
87 /**
88  * Halt the power management framework.
89  * Should ensure that no new interrupts are generated,
90  * but allow any currently running interrupt handlers to complete successfully.
91  * The GPU is forced off by the time this function returns, regardless of
92  * whether or not the active power policy asks for the GPU to be powered off.
93  *
94  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
95  */
96 void kbase_pm_halt(struct kbase_device *kbdev);
97
98 /** Terminate the power management framework.
99  *
100  * No power management functions may be called after this
101  * (except @ref kbase_pm_init)
102  *
103  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
104  */
105 void kbase_pm_term(struct kbase_device *kbdev);
106
107 /** Metrics data collected for use by the power management framework.
108  *
109  */
110 typedef struct kbasep_pm_metrics_data {
111         int vsync_hit;
112         int utilisation;
113         ktime_t time_period_start;
114         u32 time_busy;
115         u32 time_idle;
116         mali_bool gpu_active;
117
118         spinlock_t lock;
119
120         struct hrtimer timer;
121         mali_bool timer_active;
122
123         void *platform_data;
124         struct kbase_device *kbdev;
125 } kbasep_pm_metrics_data;
126
127 /** Actions for DVFS.
128  *
129  * kbase_pm_get_dvfs_action will return one of these enumerated values to
130  * describe the action that the DVFS system should take.
131  */
132 typedef enum kbase_pm_dvfs_action {
133         KBASE_PM_DVFS_NOP,          /**< No change in clock frequency is requested */
134         KBASE_PM_DVFS_CLOCK_UP,     /**< The clock frequency should be increased if possible */
135         KBASE_PM_DVFS_CLOCK_DOWN    /**< The clock frequency should be decreased if possible */
136 } kbase_pm_dvfs_action;
137
138 typedef union kbase_pm_policy_data {
139         kbasep_pm_policy_always_on always_on;
140         kbasep_pm_policy_coarse_demand coarse_demand;
141         kbasep_pm_policy_demand demand;
142 #if MALI_CUSTOMER_RELEASE == 0  
143         kbasep_pm_policy_demand_always_powered demand_always_powered;
144         kbasep_pm_policy_fast_start fast_start;
145 #endif
146 } kbase_pm_policy_data;
147
148 typedef union kbase_pm_ca_policy_data {
149         kbasep_pm_ca_policy_fixed fixed;
150 #if MALI_CUSTOMER_RELEASE == 0
151         kbasep_pm_ca_policy_random random;
152 #endif
153 } kbase_pm_ca_policy_data;
154
155 /** Data stored per device for power management.
156  *
157  * This structure contains data for the power management framework. There is one instance of this structure per device
158  * in the system.
159  */
160 typedef struct kbase_pm_device_data {
161         /** The lock protecting Power Management structures accessed
162          * outside of IRQ.
163          *
164          * This lock must also be held whenever the GPU is being powered on or off.
165          */
166         struct mutex lock;
167
168         /** The policy that is currently actively controlling core availability.
169          *
170          * @note: During an IRQ, this can be NULL when the policy is being changed
171          * with kbase_pm_ca_set_policy(). The change is protected under
172          * kbase_device::pm::power_change_lock. Direct access to this from IRQ
173          * context must therefore check for NULL. If NULL, then
174          * kbase_pm_ca_set_policy() will re-issue the policy functions that would've
175          * been done under IRQ.
176          */
177         const kbase_pm_ca_policy *ca_current_policy;
178
179         /** The policy that is currently actively controlling the power state.
180          *
181          * @note: During an IRQ, this can be NULL when the policy is being changed
182          * with kbase_pm_set_policy(). The change is protected under
183          * kbase_device::pm::power_change_lock. Direct access to this from IRQ
184          * context must therefore check for NULL. If NULL, then
185          * kbase_pm_set_policy() will re-issue the policy functions that would've
186          * been done under IRQ.
187          */
188         const kbase_pm_policy *pm_current_policy;
189
190         /** Private data for current CA policy */
191         kbase_pm_ca_policy_data ca_policy_data;
192
193         /** Private data for current PM policy */
194         kbase_pm_policy_data pm_policy_data;
195
196         /** Flag indicating when core availability policy is transitioning cores.
197          * The core availability policy must set this when a change in core availability
198          * is occuring.
199          *
200          * power_change_lock must be held when accessing this. */
201         mali_bool ca_in_transition;
202
203         /** Waiting for reset and a queue to wait for changes */
204         mali_bool reset_done;
205         wait_queue_head_t reset_done_wait;
206
207         /** Wait queue for whether the l2 cache has been powered as requested */
208         wait_queue_head_t l2_powered_wait;
209         /** State indicating whether all the l2 caches are powered.
210          * Non-zero indicates they're *all* powered
211          * Zero indicates that some (or all) are not powered */
212         int l2_powered;
213
214         /** The reference count of active contexts on this device. */
215         int active_count;
216         /** Flag indicating suspending/suspended */
217         mali_bool suspending;
218         /* Wait queue set when active_count == 0 */
219         wait_queue_head_t zero_active_count_wait;
220
221         /** The reference count of active gpu cycle counter users */
222         int gpu_cycle_counter_requests;
223         /** Lock to protect gpu_cycle_counter_requests */
224         spinlock_t gpu_cycle_counter_requests_lock;
225
226         /** A bit mask identifying the shader cores that the power policy would like to be on.
227          * The current state of the cores may be different, but there should be transitions in progress that will
228          * eventually achieve this state (assuming that the policy doesn't change its mind in the mean time.
229          */
230         u64 desired_shader_state;
231         /** bit mask indicating which shader cores are currently in a power-on transition */
232         u64 powering_on_shader_state;
233         /** A bit mask identifying the tiler cores that the power policy would like to be on.
234          * @see kbase_pm_device_data:desired_shader_state */
235         u64 desired_tiler_state;
236         /** bit mask indicating which tiler core are currently in a power-on transition */
237         u64 powering_on_tiler_state;
238
239         /** bit mask indicating which l2-caches are currently in a power-on transition */
240         u64 powering_on_l2_state;
241         /** bit mask indicating which l3-caches are currently in a power-on transition */
242         u64 powering_on_l3_state;
243
244         /** Lock protecting the power state of the device.
245          *
246          * This lock must be held when accessing the shader_available_bitmap, tiler_available_bitmap, l2_available_bitmap,
247          * shader_inuse_bitmap and tiler_inuse_bitmap fields of kbase_device, and the ca_in_transition and shader_poweroff_pending
248          * fields of kbase_pm_device_data. It is also held when the hardware power registers are being written to, to ensure
249          * that two threads do not conflict over the power transitions that the hardware should make.
250          */
251         spinlock_t power_change_lock;
252
253         /** This flag is set iff the GPU is powered as requested by the
254          * desired_xxx_state variables */
255         mali_bool gpu_in_desired_state;
256         /* Wait queue set when gpu_in_desired_state != 0 */
257         wait_queue_head_t gpu_in_desired_state_wait;
258
259         /** Set to true when the GPU is powered and register accesses are possible, false otherwise */
260         mali_bool gpu_powered;
261
262         /** A bit mask identifying the available shader cores that are specified via sysfs */
263         u64 debug_core_mask;
264
265         /** Set to true when instrumentation is enabled, false otherwise */
266         mali_bool instr_enabled;
267
268         mali_bool cg1_disabled;
269
270 #ifdef CONFIG_MALI_DEBUG
271         /** Debug state indicating whether sufficient initialization of the driver
272          * has occurred to handle IRQs */
273         mali_bool driver_ready_for_irqs;
274 #endif /* CONFIG_MALI_DEBUG */
275
276         /** Spinlock that must be held when:
277          * - writing gpu_powered
278          * - accessing driver_ready_for_irqs (in CONFIG_MALI_DEBUG builds) */
279         spinlock_t gpu_powered_lock;
280
281         /** Time in milliseconds between each dvfs sample */
282
283         u32 platform_dvfs_frequency;
284
285         /** Structure to hold metrics for the GPU */
286
287         kbasep_pm_metrics_data metrics;
288
289         /** Set to the number of poweroff timer ticks until the GPU is powered off */
290         int gpu_poweroff_pending;
291
292         /** Set to the number of poweroff timer ticks until shaders are powered off */
293         int shader_poweroff_pending_time;
294
295         /** Timer for powering off GPU */
296         struct hrtimer gpu_poweroff_timer;
297
298         struct workqueue_struct *gpu_poweroff_wq;
299
300         struct work_struct gpu_poweroff_work;
301
302         /** Period of GPU poweroff timer */
303         ktime_t gpu_poweroff_time;
304
305         /** Bit mask of shaders to be powered off on next timer callback */
306         u64 shader_poweroff_pending;
307
308         /** Set to MALI_TRUE if the poweroff timer is currently running, MALI_FALSE otherwise */
309         mali_bool poweroff_timer_running;
310
311         int poweroff_shader_ticks;
312
313         int poweroff_gpu_ticks;
314
315         /** Callback when the GPU needs to be turned on. See @ref kbase_pm_callback_conf
316          *
317          * @param kbdev         The kbase device
318          *
319          * @return 1 if GPU state was lost, 0 otherwise
320          */
321         int (*callback_power_on) (struct kbase_device *kbdev);
322
323         /** Callback when the GPU may be turned off. See @ref kbase_pm_callback_conf
324          *
325          * @param kbdev         The kbase device
326          */
327         void (*callback_power_off) (struct kbase_device *kbdev);
328
329         /** Callback when a suspend occurs and the GPU needs to be turned off.
330          *  See @ref kbase_pm_callback_conf
331          *
332          * @param kbdev         The kbase device
333          */
334         void (*callback_power_suspend) (struct kbase_device *kbdev);
335
336         /** Callback when a resume occurs and the GPU needs to be turned on.
337          *  See @ref kbase_pm_callback_conf
338          *
339          * @param kbdev         The kbase device
340          */
341         void (*callback_power_resume) (struct kbase_device *kbdev);
342
343         /** Callback for initializing the runtime power management.
344          *
345          * @param kbdev         The kbase device
346          *
347          * @return MALI_ERROR_NONE on success, else error code
348          */
349          mali_error(*callback_power_runtime_init) (struct kbase_device *kbdev);
350
351         /** Callback for terminating the runtime power management.
352          *
353          * @param kbdev         The kbase device
354          */
355         void (*callback_power_runtime_term) (struct kbase_device *kbdev);
356
357         /** Callback when the GPU needs to be turned on. See @ref kbase_pm_callback_conf
358          *
359          * @param kbdev         The kbase device
360          *
361          * @return 1 if GPU state was lost, 0 otherwise
362          */
363         int (*callback_power_runtime_on) (struct kbase_device *kbdev);
364
365         /** Callback when the GPU may be turned off. See @ref kbase_pm_callback_conf
366          *
367          * @param kbdev         The kbase device
368          */
369         void (*callback_power_runtime_off) (struct kbase_device *kbdev);
370
371 } kbase_pm_device_data;
372
373 /** The GPU is idle.
374  *
375  * The OS may choose to turn off idle devices
376  *
377  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
378  */
379 void kbase_pm_dev_idle(struct kbase_device *kbdev);
380
381 /** The GPU is active.
382  *
383  * The OS should avoid opportunistically turning off the GPU while it is active
384  *
385  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
386  */
387 void kbase_pm_dev_activate(struct kbase_device *kbdev);
388
389 /** Get details of the cores that are present in the device.
390  *
391  * This function can be called by the active power policy to return a bitmask of the cores (of a specified type)
392  * present in the GPU device and also a count of the number of cores.
393  *
394  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
395  * @param type      The type of core (see the @ref kbase_pm_core_type enumeration)
396  *
397  * @return          The bit mask of cores present
398  */
399 u64 kbase_pm_get_present_cores(struct kbase_device *kbdev, kbase_pm_core_type type);
400
401 /** Get details of the cores that are currently active in the device.
402  *
403  * This function can be called by the active power policy to return a bitmask of the cores (of a specified type) that
404  * are actively processing work (i.e. turned on *and* busy).
405  *
406  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
407  * @param type      The type of core (see the @ref kbase_pm_core_type enumeration)
408  *
409  * @return          The bit mask of active cores
410  */
411 u64 kbase_pm_get_active_cores(struct kbase_device *kbdev, kbase_pm_core_type type);
412
413 /** Get details of the cores that are currently transitioning between power states.
414  *
415  * This function can be called by the active power policy to return a bitmask of the cores (of a specified type) that
416  * are currently transitioning between power states.
417  *
418  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
419  * @param type      The type of core (see the @ref kbase_pm_core_type enumeration)
420  *
421  * @return          The bit mask of transitioning cores
422  */
423 u64 kbase_pm_get_trans_cores(struct kbase_device *kbdev, kbase_pm_core_type type);
424
425 /** Get details of the cores that are currently powered and ready for jobs.
426  *
427  * This function can be called by the active power policy to return a bitmask of the cores (of a specified type) that
428  * are powered and ready for jobs (they may or may not be currently executing jobs).
429  *
430  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
431  * @param type      The type of core (see the @ref kbase_pm_core_type enumeration)
432  *
433  * @return          The bit mask of ready cores
434  */
435 u64 kbase_pm_get_ready_cores(struct kbase_device *kbdev, kbase_pm_core_type type);
436
437 /** Turn the clock for the device on, and enable device interrupts.
438  *
439  * This function can be used by a power policy to turn the clock for the GPU on. It should be modified during
440  * integration to perform the necessary actions to ensure that the GPU is fully powered and clocked.
441  *
442  * @param kbdev       The kbase device structure for the device (must be a valid pointer)
443  * @param is_resume   MALI_TRUE if clock on due to resume after suspend,
444  *                    MALI_FALSE otherwise
445  */
446 void kbase_pm_clock_on(struct kbase_device *kbdev, mali_bool is_resume);
447
448 /** Disable device interrupts, and turn the clock for the device off.
449  *
450  * This function can be used by a power policy to turn the clock for the GPU off. It should be modified during
451  * integration to perform the necessary actions to turn the clock off (if this is possible in the integration).
452  *
453  * @param kbdev       The kbase device structure for the device (must be a valid pointer)
454  * @param is_suspend  MALI_TRUE if clock off due to suspend, MALI_FALSE otherwise
455  */
456 void kbase_pm_clock_off(struct kbase_device *kbdev, mali_bool is_suspend);
457
458 /** Enable interrupts on the device.
459  *
460  * Interrupts are also enabled after a call to kbase_pm_clock_on().
461  *
462  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
463  */
464 void kbase_pm_enable_interrupts(struct kbase_device *kbdev);
465
466 /** Disable interrupts on the device.
467  *
468  * This prevents delivery of Power Management interrupts to the CPU so that
469  * kbase_pm_check_transitions_nolock() will not be called from the IRQ handler
470  * until @ref kbase_pm_enable_interrupts or kbase_pm_clock_on() is called.
471  *
472  * Interrupts are also disabled after a call to kbase_pm_clock_off().
473  *
474  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
475  */
476 void kbase_pm_disable_interrupts(struct kbase_device *kbdev);
477
478 /** Initialize the hardware
479  *
480  * This function checks the GPU ID register to ensure that the GPU is supported by the driver and performs a reset on
481  * the device so that it is in a known state before the device is used.
482  *
483  * @param kbdev        The kbase device structure for the device (must be a valid pointer)
484  * @param enable_irqs  When set to MALI_TRUE gpu irqs will be enabled after this call, else
485  *                     they will be left disabled.
486  *
487  * @return MALI_ERROR_NONE if the device is supported and successfully reset.
488  */
489 mali_error kbase_pm_init_hw(struct kbase_device *kbdev, mali_bool enable_irqs );
490
491 /** The GPU has been reset successfully.
492  *
493  * This function must be called by the GPU interrupt handler when the RESET_COMPLETED bit is set. It signals to the
494  * power management initialization code that the GPU has been successfully reset.
495  *
496  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
497  */
498 void kbase_pm_reset_done(struct kbase_device *kbdev);
499
500 /** Increment the count of active contexts.
501  *
502  * This function should be called when a context is about to submit a job. It informs the active power policy that the
503  * GPU is going to be in use shortly and the policy is expected to start turning on the GPU.
504  *
505  * This function will block until the GPU is available.
506  *
507  * This function ASSERTS if a suspend is occuring/has occurred whilst this is
508  * in use. Use kbase_pm_contect_active_unless_suspending() instead.
509  *
510  * @note a Suspend is only visible to Kernel threads; user-space threads in a
511  * syscall cannot witness a suspend, because they are frozen before the suspend
512  * begins.
513  *
514  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
515  */
516 void kbase_pm_context_active(struct kbase_device *kbdev);
517
518
519 /** Handler codes for doing kbase_pm_context_active_handle_suspend() */
520 typedef enum {
521         /** A suspend is not expected/not possible - this is the same as
522          * kbase_pm_context_active() */
523         KBASE_PM_SUSPEND_HANDLER_NOT_POSSIBLE,
524         /** If we're suspending, fail and don't increase the active count */
525         KBASE_PM_SUSPEND_HANDLER_DONT_INCREASE,
526         /** If we're suspending, succeed and allow the active count to increase iff
527          * it didn't go from 0->1 (i.e., we didn't re-activate the GPU).
528          *
529          * This should only be used when there is a bounded time on the activation
530          * (e.g. guarantee it's going to be idled very soon after) */
531         KBASE_PM_SUSPEND_HANDLER_DONT_REACTIVATE
532 } kbase_pm_suspend_handler;
533
534 /** Suspend 'safe' variant of kbase_pm_context_active()
535  *
536  * If a suspend is in progress, this allows for various different ways of
537  * handling the suspend. Refer to @ref kbase_pm_suspend_handler for details.
538  *
539  * We returns a status code indicating whether we're allowed to keep the GPU
540  * active during the suspend, depending on the handler code. If the status code
541  * indicates a failure, the caller must abort whatever operation it was
542  * attempting, and potentially queue it up for after the OS has resumed.
543  *
544  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
545  * @param suspend_handler The handler code for how to handle a suspend that might occur
546  * @return zero     Indicates success
547  * @return non-zero Indicates failure due to the system being suspending/suspended.
548  */
549 int kbase_pm_context_active_handle_suspend(struct kbase_device *kbdev, kbase_pm_suspend_handler suspend_handler);
550
551 /** Decrement the reference count of active contexts.
552  *
553  * This function should be called when a context becomes idle. After this call the GPU may be turned off by the power
554  * policy so the calling code should ensure that it does not access the GPU's registers.
555  *
556  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
557  */
558 void kbase_pm_context_idle(struct kbase_device *kbdev);
559
560 /** Check if there are any power transitions to make, and if so start them.
561  *
562  * This function will check the desired_xx_state members of kbase_pm_device_data and the actual status of the
563  * hardware to see if any power transitions can be made at this time to make the hardware state closer to the state
564  * desired by the power policy.
565  *
566  * The return value can be used to check whether all the desired cores are
567  * available, and so whether it's worth submitting a job (e.g. from a Power
568  * Management IRQ).
569  *
570  * Note that this still returns MALI_TRUE when desired_xx_state has no
571  * cores. That is: of the no cores desired, none were <em>un</em>available. In
572  * this case, the caller may still need to try submitting jobs. This is because
573  * the Core Availability Policy might have taken us to an intermediate state
574  * where no cores are powered, before powering on more cores (e.g. for core
575  * rotation)
576  *
577  * The caller must hold kbase_device::pm::power_change_lock
578  *
579  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
580  * @return          non-zero when all desired cores are available. That is,
581  *                  it's worthwhile for the caller to submit a job.
582  * @return          MALI_FALSE otherwise
583  */
584 mali_bool kbase_pm_check_transitions_nolock(struct kbase_device *kbdev);
585
586 /** Synchronous and locking variant of kbase_pm_check_transitions_nolock()
587  *
588  * On returning, the desired state at the time of the call will have been met.
589  *
590  * @note There is nothing to stop the core being switched off by calls to
591  * kbase_pm_release_cores() or kbase_pm_unrequest_cores(). Therefore, the
592  * caller must have already made a call to
593  * kbase_pm_request_cores()/kbase_pm_request_cores_sync() previously.
594  *
595  * The usual use-case for this is to ensure cores are 'READY' after performing
596  * a GPU Reset.
597  *
598  * Unlike kbase_pm_check_transitions_nolock(), the caller must not hold
599  * kbase_device::pm::power_change_lock, because this function will take that
600  * lock itself.
601  *
602  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
603  */
604 void kbase_pm_check_transitions_sync(struct kbase_device *kbdev);
605
606 /** Variant of kbase_pm_update_cores_state() where the caller must hold
607  * kbase_device::pm::power_change_lock
608  *
609  * @param kbdev       The kbase device structure for the device (must be a valid
610  *                    pointer)
611  */
612 void kbase_pm_update_cores_state_nolock(struct kbase_device *kbdev);
613
614 /** Update the desired state of shader cores from the Power Policy, and begin
615  * any power transitions.
616  *
617  * This function will update the desired_xx_state members of
618  * kbase_pm_device_data by calling into the current Power Policy. It will then
619  * begin power transitions to make the hardware acheive the desired shader core
620  * state.
621  *
622  * @param kbdev       The kbase device structure for the device (must be a valid
623  *                    pointer)
624  */
625 void kbase_pm_update_cores_state(struct kbase_device *kbdev);
626
627 /** Cancel any pending requests to power off the GPU and/or shader cores.
628  *
629  * This should be called by any functions which directly power off the GPU.
630  *
631  * @param kbdev       The kbase device structure for the device (must be a valid
632  *                    pointer)
633  */
634 void kbase_pm_cancel_deferred_poweroff(struct kbase_device *kbdev);
635
636 /** Read the bitmasks of present cores.
637  *
638  * This information is cached to avoid having to perform register reads whenever the information is required.
639  *
640  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
641  */
642 void kbasep_pm_read_present_cores(struct kbase_device *kbdev);
643
644 /** Initialize the metrics gathering framework.
645  *
646  * This must be called before other metric gathering APIs are called.
647  *
648  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
649  *
650  * @return MALI_ERROR_NONE on success, MALI_ERROR_FUNCTION_FAILED on error
651  */
652 mali_error kbasep_pm_metrics_init(struct kbase_device *kbdev);
653
654 /** Terminate the metrics gathering framework.
655  *
656  * This must be called when metric gathering is no longer required. It is an error to call any metrics gathering
657  * function (other than kbasep_pm_metrics_init) after calling this function.
658  *
659  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
660  */
661 void kbasep_pm_metrics_term(struct kbase_device *kbdev);
662
663 /** Record that the GPU is active.
664  *
665  * This records that the GPU is now active. The previous GPU state must have been idle, the function will assert if
666  * this is not true in a debug build.
667  *
668  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
669  */
670 void kbasep_pm_record_gpu_active(struct kbase_device *kbdev);
671
672 /** Record that the GPU is idle.
673  *
674  * This records that the GPU is now idle. The previous GPU state must have been active, the function will assert if
675  * this is not true in a debug build.
676  *
677  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
678  */
679 void kbasep_pm_record_gpu_idle(struct kbase_device *kbdev);
680
681 /** Function to be called by the frame buffer driver to update the vsync metric.
682  *
683  * This function should be called by the frame buffer driver to update whether the system is hitting the vsync target
684  * or not. buffer_updated should be true if the vsync corresponded with a new frame being displayed, otherwise it
685  * should be false. This function does not need to be called every vsync, but only when the value of buffer_updated
686  * differs from a previous call.
687  *
688  * @param kbdev             The kbase device structure for the device (must be a valid pointer)
689  * @param buffer_updated    True if the buffer has been updated on this VSync, false otherwise
690  */
691 void kbase_pm_report_vsync(struct kbase_device *kbdev, int buffer_updated);
692
693 /** Configure the frame buffer device to set the vsync callback.
694  *
695  * This function should do whatever is necessary for this integration to ensure that kbase_pm_report_vsync is
696  * called appropriately.
697  *
698  * This function will need porting as part of the integration for a device.
699  *
700  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
701  */
702 void kbase_pm_register_vsync_callback(struct kbase_device *kbdev);
703
704 /** Free any resources that kbase_pm_register_vsync_callback allocated.
705  *
706  * This function should perform any cleanup required from the call to kbase_pm_register_vsync_callback.
707  * No call backs should occur after this function has returned.
708  *
709  * This function will need porting as part of the integration for a device.
710  *
711  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
712  */
713 void kbase_pm_unregister_vsync_callback(struct kbase_device *kbdev);
714
715 /** Determine whether the DVFS system should change the clock speed of the GPU.
716  *
717  * This function should be called regularly by the DVFS system to check whether the clock speed of the GPU needs
718  * updating. It will return one of three enumerated values of kbase_pm_dvfs_action:
719  *
720  * @param kbdev                     The kbase device structure for the device (must be a valid pointer)
721  * @retval KBASE_PM_DVFS_NOP        The clock does not need changing
722  * @retval KBASE_PM_DVFS_CLOCK_UP,  The clock frequency should be increased if possible.
723  * @retval KBASE_PM_DVFS_CLOCK_DOWN The clock frequency should be decreased if possible.
724  */
725 kbase_pm_dvfs_action kbase_pm_get_dvfs_action(struct kbase_device *kbdev);
726
727 /** Mark that the GPU cycle counter is needed, if the caller is the first caller
728  *  then the GPU cycle counters will be enabled.
729  *
730  * The GPU must be powered when calling this function (i.e. @ref kbase_pm_context_active must have been called).
731  *
732  * @param kbdev    The kbase device structure for the device (must be a valid pointer)
733  */
734
735 void kbase_pm_request_gpu_cycle_counter(struct kbase_device *kbdev);
736
737 /** Mark that the GPU cycle counter is no longer in use, if the caller is the last
738  *  caller then the GPU cycle counters will be disabled. A request must have been made
739  *  before a call to this.
740  *
741  * @param kbdev    The kbase device structure for the device (must be a valid pointer)
742  */
743
744 void kbase_pm_release_gpu_cycle_counter(struct kbase_device *kbdev);
745
746 /** Enables access to the GPU registers before power management has powered up the GPU
747  *  with kbase_pm_powerup().
748  *
749  *  Access to registers should be done using kbase_os_reg_read/write() at this stage,
750  *  not kbase_reg_read/write().
751  *
752  *  This results in the power management callbacks provided in the driver configuration
753  *  to get called to turn on power and/or clocks to the GPU.
754  *  See @ref kbase_pm_callback_conf.
755  *
756  * This should only be used before power management is powered up with kbase_pm_powerup()
757  *
758  * @param kbdev    The kbase device structure for the device (must be a valid pointer)
759  */
760 void kbase_pm_register_access_enable(struct kbase_device *kbdev);
761
762 /** Disables access to the GPU registers enabled earlier by a call to
763  *  kbase_pm_register_access_enable().
764  *
765  *  This results in the power management callbacks provided in the driver configuration
766  *  to get called to turn off power and/or clocks to the GPU.
767  *  See @ref kbase_pm_callback_conf
768  *
769  * This should only be used before power management is powered up with kbase_pm_powerup()
770  *
771  * @param kbdev    The kbase device structure for the device (must be a valid pointer)
772  */
773 void kbase_pm_register_access_disable(struct kbase_device *kbdev);
774
775 /**
776  * Suspend the GPU and prevent any further register accesses to it from Kernel
777  * threads.
778  *
779  * This is called in response to an OS suspend event, and calls into the various
780  * kbase components to complete the suspend.
781  *
782  * @note the mechanisms used here rely on all user-space threads being frozen
783  * by the OS before we suspend. Otherwise, an IOCTL could occur that powers up
784  * the GPU e.g. via atom submission.
785  *
786  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
787  */
788 void kbase_pm_suspend(struct kbase_device *kbdev);
789
790 /**
791  * Resume the GPU, allow register accesses to it, and resume running atoms on
792  * the GPU.
793  *
794  * This is called in response to an OS resume event, and calls into the various
795  * kbase components to complete the resume.
796  *
797  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
798  */
799 void kbase_pm_resume(struct kbase_device *kbdev);
800
801 /* NOTE: kbase_pm_is_suspending is in mali_kbase.h, because it is an inline function */
802
803 /**
804  * Check if the power management metrics collection is active.
805  *
806  * Note that this returns if the power management metrics collection was
807  * active at the time of calling, it is possible that after the call the metrics
808  * collection enable may have changed state.
809  *
810  * The caller must handle the consequence that the state may have changed.
811  *
812  * @param kbdev     The kbase device structure for the device (must be a valid pointer)
813  * @return          MALI_TRUE if metrics collection was active else MALI_FALSE.
814  */
815
816 mali_bool kbase_pm_metrics_is_active(struct kbase_device *kbdev);
817
818 /**
819  * Power on the GPU, and any cores that are requested.
820  *
821  * @param kbdev        The kbase device structure for the device (must be a valid pointer)
822  * @param is_resume    MALI_TRUE if power on due to resume after suspend,
823  *                     MALI_FALSE otherwise
824  */
825 void kbase_pm_do_poweron(struct kbase_device *kbdev, mali_bool is_resume);
826
827 /**
828  * Power off the GPU, and any cores that have been requested.
829  *
830  * @param kbdev        The kbase device structure for the device (must be a valid pointer)
831  * @param is_suspend   MALI_TRUE if power off due to suspend,
832  *                     MALI_FALSE otherwise
833  */
834 void kbase_pm_do_poweroff(struct kbase_device *kbdev, mali_bool is_suspend);
835
836 #ifdef CONFIG_MALI_MIDGARD_DVFS
837
838 /**
839  * Function provided by platform specific code when DVFS is enabled to allow
840  * the power management metrics system to report utilisation.
841  *
842  * @param kbdev        The kbase device structure for the device (must be a valid pointer)
843  * @param utilisation  The current calculated utilisation by the metrics system.
844  * @return             Returns 0 on failure and non zero on success.
845  */
846
847 int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation);
848 #endif
849 #endif                          /* _KBASE_PM_H_ */