rk3288_mali_t760_driver_r6p0-02rel0_12_x@0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / backend / gpu / mali_kbase_pm_internal.h
1 /*
2  *
3  * (C) COPYRIGHT 2010-2015 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_hwaccess_internal.h
22  * Power management API definitions used internally by GPU backend
23  */
24
25 #ifndef _KBASE_BACKEND_PM_INTERNAL_H_
26 #define _KBASE_BACKEND_PM_INTERNAL_H_
27
28 #include <mali_kbase_hwaccess_pm.h>
29
30 #include "mali_kbase_pm_ca.h"
31 #include "mali_kbase_pm_policy.h"
32
33
34 /**
35  * The GPU is idle.
36  *
37  * The OS may choose to turn off idle devices
38  *
39  * @param kbdev The kbase device structure for the device (must be a valid
40  *              pointer)
41  */
42 void kbase_pm_dev_idle(struct kbase_device *kbdev);
43
44 /**
45  * The GPU is active.
46  *
47  * The OS should avoid opportunistically turning off the GPU while it is active
48  *
49  * @param kbdev The kbase device structure for the device (must be a valid
50  *              pointer)
51  */
52 void kbase_pm_dev_activate(struct kbase_device *kbdev);
53
54 /**
55  * Get details of the cores that are present in the device.
56  *
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.
60  *
61  * @param kbdev The kbase device structure for the device (must be a valid
62  *              pointer)
63  * @param type  The type of core (see the @ref enum kbase_pm_core_type
64  *              enumeration)
65  *
66  * @return The bit mask of cores present
67  */
68 u64 kbase_pm_get_present_cores(struct kbase_device *kbdev,
69                                                 enum kbase_pm_core_type type);
70
71 /**
72  * Get details of the cores that are currently active in the device.
73  *
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).
77  *
78  * @param kbdev The kbase device structure for the device (must be a valid
79  *              pointer)
80  * @param type  The type of core (see the @ref enum kbase_pm_core_type
81  *              enumeration)
82  *
83  * @return The bit mask of active cores
84  */
85 u64 kbase_pm_get_active_cores(struct kbase_device *kbdev,
86                                                 enum kbase_pm_core_type type);
87
88 /**
89  * Get details of the cores that are currently transitioning between power
90  * states.
91  *
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
94  * power states.
95  *
96  * @param kbdev The kbase device structure for the device (must be a valid
97  *              pointer)
98  * @param type  The type of core (see the @ref enum kbase_pm_core_type
99  *              enumeration)
100  *
101  * @return The bit mask of transitioning cores
102  */
103 u64 kbase_pm_get_trans_cores(struct kbase_device *kbdev,
104                                                 enum kbase_pm_core_type type);
105
106 /**
107  * Get details of the cores that are currently powered and ready for jobs.
108  *
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).
112  *
113  * @param kbdev The kbase device structure for the device (must be a valid
114  *              pointer)
115  * @param type  The type of core (see the @ref enum kbase_pm_core_type
116  *              enumeration)
117  *
118  * @return The bit mask of ready cores
119  */
120 u64 kbase_pm_get_ready_cores(struct kbase_device *kbdev,
121                                                 enum kbase_pm_core_type type);
122
123 /**
124  * Turn the clock for the device on, and enable device interrupts.
125  *
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.
129  *
130  * @param kbdev     The kbase device structure for the device (must be a valid
131  *                  pointer)
132  * @param is_resume true if clock on due to resume after suspend,
133  *                  false otherwise
134  */
135 void kbase_pm_clock_on(struct kbase_device *kbdev, bool is_resume);
136
137 /**
138  * Disable device interrupts, and turn the clock for the device off.
139  *
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).
143  *
144  * @param kbdev      The kbase device structure for the device (must be a valid
145  *                   pointer)
146  * @param is_suspend true if clock off due to suspend, false otherwise
147  *
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
151  */
152 bool kbase_pm_clock_off(struct kbase_device *kbdev, bool is_suspend);
153
154 /**
155  * Enable interrupts on the device.
156  *
157  * Interrupts are also enabled after a call to kbase_pm_clock_on().
158  *
159  * @param kbdev The kbase device structure for the device (must be a valid
160  *              pointer)
161  */
162 void kbase_pm_enable_interrupts(struct kbase_device *kbdev);
163
164 /**
165  * Enable interrupts on the device, using the provided mask to set MMU_IRQ_MASK.
166  *
167  * Interrupts are also enabled after a call to kbase_pm_clock_on().
168  *
169  * @param kbdev The kbase device structure for the device (must be a valid
170  *              pointer)
171  * @param mask  The mask to use for MMU_IRQ_MASK
172  */
173 void kbase_pm_enable_interrupts_mmu_mask(struct kbase_device *kbdev, u32 mask);
174
175 /**
176  * Disable interrupts on the device.
177  *
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.
181  *
182  * Interrupts are also disabled after a call to kbase_pm_clock_off().
183  *
184  * @param kbdev The kbase device structure for the device (must be a valid
185  *              pointer)
186  */
187 void kbase_pm_disable_interrupts(struct kbase_device *kbdev);
188
189 /**
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
193  *
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.
197  *
198  * Return: 0 if the device is supported and successfully reset.
199  */
200 int kbase_pm_init_hw(struct kbase_device *kbdev, unsigned int flags);
201
202 /**
203  * The GPU has been reset successfully.
204  *
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.
208  *
209  * @param kbdev The kbase device structure for the device (must be a valid
210  *              pointer)
211  */
212 void kbase_pm_reset_done(struct kbase_device *kbdev);
213
214
215 /**
216  * Check if there are any power transitions to make, and if so start them.
217  *
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.
222  *
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
225  * Management IRQ).
226  *
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
232  * rotation)
233  *
234  * The caller must hold kbase_device::pm::power_change_lock
235  *
236  * @param kbdev The kbase device structure for the device (must be a valid
237  *              pointer)
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
241  */
242 bool kbase_pm_check_transitions_nolock(struct kbase_device *kbdev);
243
244 /**
245  * Synchronous and locking variant of kbase_pm_check_transitions_nolock()
246  *
247  * On returning, the desired state at the time of the call will have been met.
248  *
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.
253  *
254  * The usual use-case for this is to ensure cores are 'READY' after performing
255  * a GPU Reset.
256  *
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
259  * lock itself.
260  *
261  * @param kbdev The kbase device structure for the device (must be a valid
262  *              pointer)
263  */
264 void kbase_pm_check_transitions_sync(struct kbase_device *kbdev);
265
266 /**
267  * Variant of kbase_pm_update_cores_state() where the caller must hold
268  * kbase_device::pm::power_change_lock
269  *
270  * @param kbdev The kbase device structure for the device (must be a valid
271  *              pointer)
272  */
273 void kbase_pm_update_cores_state_nolock(struct kbase_device *kbdev);
274
275 /**
276  * Update the desired state of shader cores from the Power Policy, and begin
277  * any power transitions.
278  *
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
282  * core state.
283  *
284  * @param kbdev The kbase device structure for the device (must be a valid
285  *              pointer)
286  */
287 void kbase_pm_update_cores_state(struct kbase_device *kbdev);
288
289 /**
290  * Cancel any pending requests to power off the GPU and/or shader cores.
291  *
292  * This should be called by any functions which directly power off the GPU.
293  *
294  * @param kbdev The kbase device structure for the device (must be a valid
295  *              pointer)
296  */
297 void kbase_pm_cancel_deferred_poweroff(struct kbase_device *kbdev);
298
299 /**
300  * Read the bitmasks of present cores.
301  *
302  * This information is cached to avoid having to perform register reads whenever
303  * the information is required.
304  *
305  * @param kbdev The kbase device structure for the device (must be a valid
306  *              pointer)
307  */
308 void kbasep_pm_read_present_cores(struct kbase_device *kbdev);
309
310 /**
311  * Initialize the metrics gathering framework.
312  *
313  * This must be called before other metric gathering APIs are called.
314  *
315  * @param kbdev The kbase device structure for the device (must be a valid
316  *              pointer)
317  *
318  * @return 0 on success, error code on error
319  */
320 int kbasep_pm_metrics_init(struct kbase_device *kbdev);
321
322 /**
323  * Terminate the metrics gathering framework.
324  *
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.
328  *
329  * @param kbdev The kbase device structure for the device (must be a valid
330  *              pointer)
331  */
332 void kbasep_pm_metrics_term(struct kbase_device *kbdev);
333
334 /**
335  * Function to be called by the frame buffer driver to update the vsync metric.
336  *
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.
342  *
343  * @param kbdev          The kbase device structure for the device (must be a
344  *                       valid pointer)
345  * @param buffer_updated True if the buffer has been updated on this VSync,
346  *                       false otherwise
347  */
348 void kbase_pm_report_vsync(struct kbase_device *kbdev, int buffer_updated);
349
350 /**
351  * Configure the frame buffer device to set the vsync callback.
352  *
353  * This function should do whatever is necessary for this integration to ensure
354  * that kbase_pm_report_vsync is called appropriately.
355  *
356  * This function will need porting as part of the integration for a device.
357  *
358  * @param kbdev The kbase device structure for the device (must be a valid
359  *              pointer)
360  */
361 void kbase_pm_register_vsync_callback(struct kbase_device *kbdev);
362
363 /**
364  * Free any resources that kbase_pm_register_vsync_callback allocated.
365  *
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.
369  *
370  * This function will need porting as part of the integration for a device.
371  *
372  * @param kbdev The kbase device structure for the device (must be a valid
373  *              pointer)
374  */
375 void kbase_pm_unregister_vsync_callback(struct kbase_device *kbdev);
376
377 /**
378  * Determine whether the DVFS system should change the clock speed of the GPU.
379  *
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:
383  *
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
388  *                                  possible.
389  * @retval KBASE_PM_DVFS_CLOCK_DOWN The clock frequency should be decreased if
390  *                                  possible.
391  */
392 enum kbase_pm_dvfs_action kbase_pm_get_dvfs_action(struct kbase_device *kbdev);
393
394 /**
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
397  *
398  * The GPU must be powered when calling this function (i.e.
399  * @ref kbase_pm_context_active must have been called).
400  *
401  * @param kbdev The kbase device structure for the device (must be a valid
402  *              pointer)
403  */
404 void kbase_pm_request_gpu_cycle_counter(struct kbase_device *kbdev);
405
406 /**
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.
412  *
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
415  * powered on.
416  *
417  * @param kbdev The kbase device structure for the device (must be a valid
418  *              pointer)
419  */
420 void kbase_pm_request_gpu_cycle_counter_l2_is_on(struct kbase_device *kbdev);
421
422 /**
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.
426  *
427  * @param kbdev The kbase device structure for the device (must be a valid
428  *              pointer)
429  */
430 void kbase_pm_release_gpu_cycle_counter(struct kbase_device *kbdev);
431
432 /**
433  * Enables access to the GPU registers before power management has powered up
434  * the GPU with kbase_pm_powerup().
435  *
436  * Access to registers should be done using kbase_os_reg_read/write() at this
437  * stage, not kbase_reg_read/write().
438  *
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.
442  *
443  * This should only be used before power management is powered up with
444  * kbase_pm_powerup()
445  *
446  * @param kbdev The kbase device structure for the device (must be a valid
447  *              pointer)
448  */
449 void kbase_pm_register_access_enable(struct kbase_device *kbdev);
450
451 /**
452  * Disables access to the GPU registers enabled earlier by a call to
453  * kbase_pm_register_access_enable().
454  *
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
458  *
459  * This should only be used before power management is powered up with
460  * kbase_pm_powerup()
461  *
462  * @param kbdev The kbase device structure for the device (must be a valid
463  *              pointer)
464  */
465 void kbase_pm_register_access_disable(struct kbase_device *kbdev);
466
467 /* NOTE: kbase_pm_is_suspending is in mali_kbase.h, because it is an inline
468  * function */
469
470 /**
471  * Check if the power management metrics collection is active.
472  *
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.
476  *
477  * The caller must handle the consequence that the state may have changed.
478  *
479  * @param kbdev The kbase device structure for the device (must be a valid
480  *              pointer)
481  * @return      true if metrics collection was active else false.
482  */
483 bool kbase_pm_metrics_is_active(struct kbase_device *kbdev);
484
485 /**
486  * Power on the GPU, and any cores that are requested.
487  *
488  * @param kbdev     The kbase device structure for the device (must be a valid
489  *                  pointer)
490  * @param is_resume true if power on due to resume after suspend,
491  *                  false otherwise
492  */
493 void kbase_pm_do_poweron(struct kbase_device *kbdev, bool is_resume);
494
495 /**
496  * Power off the GPU, and any cores that have been requested.
497  *
498  * @param kbdev      The kbase device structure for the device (must be a valid
499  *                   pointer)
500  * @param is_suspend true if power off due to suspend,
501  *                   false otherwise
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
505  */
506 bool kbase_pm_do_poweroff(struct kbase_device *kbdev, bool is_suspend);
507
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);
512 #endif
513
514 #ifdef CONFIG_MALI_MIDGARD_DVFS
515
516 /**
517  * Function provided by platform specific code when DVFS is enabled to allow
518  * the power management metrics system to report utilisation.
519  *
520  * @param kbdev         The kbase device structure for the device (must be a
521  *                      valid pointer)
522  * @param utilisation   The current calculated utilisation by the metrics
523  *                      system.
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
526  *                      group.
527  * @return              Returns 0 on failure and non zero on success.
528  */
529
530 int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation,
531         u32 util_gl_share, u32 util_cl_share[2]);
532 #endif
533
534 void kbase_pm_power_changed(struct kbase_device *kbdev);
535
536 /**
537  * Inform the metrics system that an atom is about to be run.
538  *
539  * @param kbdev The kbase device structure for the device (must be a valid
540  *              pointer)
541  * @param katom The atom that is about to be run
542  */
543 void kbase_pm_metrics_run_atom(struct kbase_device *kbdev,
544                                 struct kbase_jd_atom *katom);
545
546 /**
547  * Inform the metrics system that an atom has been run and is being released.
548  *
549  * @param kbdev The kbase device structure for the device (must be a valid
550  *              pointer)
551  * @param katom The atom that is about to be released
552  */
553 void kbase_pm_metrics_release_atom(struct kbase_device *kbdev,
554                                 struct kbase_jd_atom *katom);
555
556
557 #endif /* _KBASE_BACKEND_PM_INTERNAL_H_ */