hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_internal.h
....@@ -1,7 +1,7 @@
11 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22 /*
33 *
4
- * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2010-2022 ARM Limited. All rights reserved.
55 *
66 * This program is free software and is provided to you under the terms of the
77 * GNU General Public License version 2 as published by the Free Software
....@@ -35,18 +35,18 @@
3535 /**
3636 * kbase_pm_dev_idle - The GPU is idle.
3737 *
38
- * The OS may choose to turn off idle devices
39
- *
4038 * @kbdev: The kbase device structure for the device (must be a valid pointer)
39
+ *
40
+ * The OS may choose to turn off idle devices
4141 */
4242 void kbase_pm_dev_idle(struct kbase_device *kbdev);
4343
4444 /**
4545 * kbase_pm_dev_activate - The GPU is active.
4646 *
47
- * The OS should avoid opportunistically turning off the GPU while it is active
48
- *
4947 * @kbdev: The kbase device structure for the device (must be a valid pointer)
48
+ *
49
+ * The OS should avoid opportunistically turning off the GPU while it is active
5050 */
5151 void kbase_pm_dev_activate(struct kbase_device *kbdev);
5252
....@@ -54,13 +54,13 @@
5454 * kbase_pm_get_present_cores - Get details of the cores that are present in
5555 * the device.
5656 *
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
- *
6157 * @kbdev: The kbase device structure for the device (must be a valid
6258 * pointer)
6359 * @type: The type of core (see the enum kbase_pm_core_type enumeration)
60
+ *
61
+ * This function can be called by the active power policy to return a bitmask of
62
+ * the cores (of a specified type) present in the GPU device and also a count of
63
+ * the number of cores.
6464 *
6565 * Return: The bit mask of cores present
6666 */
....@@ -71,12 +71,12 @@
7171 * kbase_pm_get_active_cores - Get details of the cores that are currently
7272 * active in the device.
7373 *
74
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
75
+ * @type: The type of core (see the enum kbase_pm_core_type enumeration)
76
+ *
7477 * This function can be called by the active power policy to return a bitmask of
7578 * the cores (of a specified type) that are actively processing work (i.e.
7679 * turned on *and* busy).
77
- *
78
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
79
- * @type: The type of core (see the enum kbase_pm_core_type enumeration)
8080 *
8181 * Return: The bit mask of active cores
8282 */
....@@ -87,12 +87,12 @@
8787 * kbase_pm_get_trans_cores - Get details of the cores that are currently
8888 * transitioning between power states.
8989 *
90
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
91
+ * @type: The type of core (see the enum kbase_pm_core_type enumeration)
92
+ *
9093 * This function can be called by the active power policy to return a bitmask of
9194 * the cores (of a specified type) that are currently transitioning between
9295 * power states.
93
- *
94
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
95
- * @type: The type of core (see the enum kbase_pm_core_type enumeration)
9696 *
9797 * Return: The bit mask of transitioning cores
9898 */
....@@ -103,12 +103,12 @@
103103 * kbase_pm_get_ready_cores - Get details of the cores that are currently
104104 * powered and ready for jobs.
105105 *
106
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
107
+ * @type: The type of core (see the enum kbase_pm_core_type enumeration)
108
+ *
106109 * This function can be called by the active power policy to return a bitmask of
107110 * the cores (of a specified type) that are powered and ready for jobs (they may
108111 * or may not be currently executing jobs).
109
- *
110
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
111
- * @type: The type of core (see the enum kbase_pm_core_type enumeration)
112112 *
113113 * Return: The bit mask of ready cores
114114 */
....@@ -119,13 +119,13 @@
119119 * kbase_pm_clock_on - Turn the clock for the device on, and enable device
120120 * interrupts.
121121 *
122
- * This function can be used by a power policy to turn the clock for the GPU on.
123
- * It should be modified during integration to perform the necessary actions to
124
- * ensure that the GPU is fully powered and clocked.
125
- *
126122 * @kbdev: The kbase device structure for the device (must be a valid
127123 * pointer)
128124 * @is_resume: true if clock on due to resume after suspend, false otherwise
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.
129129 */
130130 void kbase_pm_clock_on(struct kbase_device *kbdev, bool is_resume);
131131
....@@ -133,12 +133,16 @@
133133 * kbase_pm_clock_off - Disable device interrupts, and turn the clock for the
134134 * device off.
135135 *
136
+ * @kbdev: The kbase device structure for the device (must be a valid
137
+ * pointer)
138
+ *
136139 * This function can be used by a power policy to turn the clock for the GPU
137140 * off. It should be modified during integration to perform the necessary
138141 * actions to turn the clock off (if this is possible in the integration).
139142 *
140
- * @kbdev: The kbase device structure for the device (must be a valid
141
- * pointer)
143
+ * If runtime PM is enabled and @power_runtime_gpu_idle_callback is used
144
+ * then this function would usually be invoked from the runtime suspend
145
+ * callback function.
142146 *
143147 * Return: true if clock was turned off, or
144148 * false if clock can not be turned off due to pending page/bus fault
....@@ -149,22 +153,22 @@
149153 /**
150154 * kbase_pm_enable_interrupts - Enable interrupts on the device.
151155 *
152
- * Interrupts are also enabled after a call to kbase_pm_clock_on().
153
- *
154156 * @kbdev: The kbase device structure for the device (must be a valid pointer)
157
+ *
158
+ * Interrupts are also enabled after a call to kbase_pm_clock_on().
155159 */
156160 void kbase_pm_enable_interrupts(struct kbase_device *kbdev);
157161
158162 /**
159163 * kbase_pm_disable_interrupts - Disable interrupts on the device.
160164 *
165
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
166
+ *
161167 * This prevents delivery of Power Management interrupts to the CPU so that
162168 * kbase_pm_update_state() will not be called from the IRQ handler
163169 * until kbase_pm_enable_interrupts() or kbase_pm_clock_on() is called.
164170 *
165171 * Interrupts are also disabled after a call to kbase_pm_clock_off().
166
- *
167
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
168172 */
169173 void kbase_pm_disable_interrupts(struct kbase_device *kbdev);
170174
....@@ -172,9 +176,9 @@
172176 * kbase_pm_disable_interrupts_nolock - Version of kbase_pm_disable_interrupts()
173177 * that does not take the hwaccess_lock
174178 *
175
- * Caller must hold the hwaccess_lock.
176
- *
177179 * @kbdev: The kbase device structure for the device (must be a valid pointer)
180
+ *
181
+ * Caller must hold the hwaccess_lock.
178182 */
179183 void kbase_pm_disable_interrupts_nolock(struct kbase_device *kbdev);
180184
....@@ -193,12 +197,11 @@
193197
194198 /**
195199 * kbase_pm_reset_done - The GPU has been reset successfully.
200
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
196201 *
197202 * This function must be called by the GPU interrupt handler when the
198203 * RESET_COMPLETED bit is set. It signals to the power management initialization
199204 * code that the GPU has been successfully reset.
200
- *
201
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
202205 */
203206 void kbase_pm_reset_done(struct kbase_device *kbdev);
204207
....@@ -206,6 +209,7 @@
206209 /**
207210 * kbase_pm_wait_for_desired_state - Wait for the desired power state to be
208211 * reached
212
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
209213 *
210214 * Wait for the L2 and MCU state machines to reach the states corresponding
211215 * to the values of 'kbase_pm_is_l2_desired' and 'kbase_pm_is_mcu_desired'.
....@@ -220,8 +224,6 @@
220224 * power off in progress and kbase_pm_context_active() was called instead of
221225 * kbase_csf_scheduler_pm_active().
222226 *
223
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
224
- *
225227 * Return: 0 on success, error code on error
226228 */
227229 int kbase_pm_wait_for_desired_state(struct kbase_device *kbdev);
....@@ -229,6 +231,7 @@
229231 /**
230232 * kbase_pm_wait_for_desired_state - Wait for the desired power state to be
231233 * reached
234
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
232235 *
233236 * Wait for the L2 and shader power state machines to reach the states
234237 * corresponding to the values of 'l2_desired' and 'shaders_desired'.
....@@ -242,9 +245,7 @@
242245 * NOTE: This may not wait until the correct state is reached if there is a
243246 * power off in progress. To correctly wait for the desired state the caller
244247 * must ensure that this is not the case by, for example, calling
245
- * kbase_pm_wait_for_poweroff_complete()
246
- *
247
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
248
+ * kbase_pm_wait_for_poweroff_work_complete()
248249 *
249250 * Return: 0 on success, error code on error
250251 */
....@@ -254,6 +255,8 @@
254255 /**
255256 * kbase_pm_wait_for_l2_powered - Wait for the L2 cache to be powered on
256257 *
258
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
259
+ *
257260 * Wait for the L2 to be powered on, and for the L2 and the state machines of
258261 * its dependent stack components to stabilise.
259262 *
....@@ -262,23 +265,51 @@
262265 * Unlike kbase_pm_update_state(), the caller must not hold hwaccess_lock,
263266 * because this function will take that lock itself.
264267 *
265
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
266
- *
267268 * Return: 0 on success, error code on error
268269 */
269270 int kbase_pm_wait_for_l2_powered(struct kbase_device *kbdev);
271
+
272
+#if MALI_USE_CSF
273
+/**
274
+ * kbase_pm_wait_for_cores_down_scale - Wait for the downscaling of shader cores
275
+ *
276
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
277
+ *
278
+ * This function can be called to ensure that the downscaling of cores is
279
+ * effectively complete and it would be safe to lower the voltage.
280
+ * The function assumes that caller had exercised the MCU state machine for the
281
+ * downscale request through the kbase_pm_update_state() function.
282
+ *
283
+ * This function needs to be used by the caller to safely wait for the completion
284
+ * of downscale request, instead of kbase_pm_wait_for_desired_state().
285
+ * The downscale request would trigger a state change in MCU state machine
286
+ * and so when MCU reaches the stable ON state, it can be inferred that
287
+ * downscaling is complete. But it has been observed that the wake up of the
288
+ * waiting thread can get delayed by few milli seconds and by the time the
289
+ * thread wakes up the power down transition could have started (after the
290
+ * completion of downscale request).
291
+ * On the completion of power down transition another wake up signal would be
292
+ * sent, but again by the time thread wakes up the power up transition can begin.
293
+ * And the power up transition could then get blocked inside the platform specific
294
+ * callback_power_on() function due to the thread that called into Kbase (from the
295
+ * platform specific code) to perform the downscaling and then ended up waiting
296
+ * for the completion of downscale request.
297
+ *
298
+ * Return: 0 on success, error code on error or remaining jiffies on timeout.
299
+ */
300
+int kbase_pm_wait_for_cores_down_scale(struct kbase_device *kbdev);
301
+#endif
270302
271303 /**
272304 * kbase_pm_update_dynamic_cores_onoff - Update the L2 and shader power state
273305 * machines after changing shader core
274306 * availability
307
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
275308 *
276309 * It can be called in any status, so need to check the l2 and shader core
277310 * power status in this function or it will break shader/l2 state machine
278311 *
279312 * Caller must hold hwaccess_lock
280
- *
281
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
282313 */
283314 void kbase_pm_update_dynamic_cores_onoff(struct kbase_device *kbdev);
284315
....@@ -301,6 +332,8 @@
301332 * kbase_pm_state_machine_init - Initialize the state machines, primarily the
302333 * shader poweroff timer
303334 * @kbdev: Device pointer
335
+ *
336
+ * Return: 0 on success, error code on error
304337 */
305338 int kbase_pm_state_machine_init(struct kbase_device *kbdev);
306339
....@@ -314,22 +347,21 @@
314347 * kbase_pm_update_cores_state - Update the desired state of shader cores from
315348 * the Power Policy, and begin any power
316349 * transitions.
350
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
317351 *
318352 * This function will update the desired_xx_state members of
319353 * struct kbase_pm_device_data by calling into the current Power Policy. It will
320354 * then begin power transitions to make the hardware acheive the desired shader
321355 * core state.
322
- *
323
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
324356 */
325357 void kbase_pm_update_cores_state(struct kbase_device *kbdev);
326358
327359 /**
328360 * kbasep_pm_metrics_init - Initialize the metrics gathering framework.
361
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
329362 *
330363 * This must be called before other metric gathering APIs are called.
331364 *
332
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
333365 *
334366 * Return: 0 on success, error code on error
335367 */
....@@ -337,29 +369,27 @@
337369
338370 /**
339371 * kbasep_pm_metrics_term - Terminate the metrics gathering framework.
372
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
340373 *
341374 * This must be called when metric gathering is no longer required. It is an
342375 * error to call any metrics gathering function (other than
343376 * kbasep_pm_metrics_init()) after calling this function.
344
- *
345
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
346377 */
347378 void kbasep_pm_metrics_term(struct kbase_device *kbdev);
348379
349380 /**
350381 * kbase_pm_report_vsync - Function to be called by the frame buffer driver to
351382 * update the vsync metric.
383
+ * @kbdev: The kbase device structure for the device (must be a
384
+ * valid pointer)
385
+ * @buffer_updated: True if the buffer has been updated on this VSync,
386
+ * false otherwise
352387 *
353388 * This function should be called by the frame buffer driver to update whether
354389 * the system is hitting the vsync target or not. buffer_updated should be true
355390 * if the vsync corresponded with a new frame being displayed, otherwise it
356391 * should be false. This function does not need to be called every vsync, but
357392 * only when the value of @buffer_updated differs from a previous call.
358
- *
359
- * @kbdev: The kbase device structure for the device (must be a
360
- * valid pointer)
361
- * @buffer_updated: True if the buffer has been updated on this VSync,
362
- * false otherwise
363393 */
364394 void kbase_pm_report_vsync(struct kbase_device *kbdev, int buffer_updated);
365395
....@@ -377,6 +407,7 @@
377407 /**
378408 * kbase_pm_request_gpu_cycle_counter - Mark that the GPU cycle counter is
379409 * needed
410
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
380411 *
381412 * If the caller is the first caller then the GPU cycle counters will be enabled
382413 * along with the l2 cache
....@@ -384,13 +415,13 @@
384415 * The GPU must be powered when calling this function (i.e.
385416 * kbase_pm_context_active() must have been called).
386417 *
387
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
388418 */
389419 void kbase_pm_request_gpu_cycle_counter(struct kbase_device *kbdev);
390420
391421 /**
392422 * kbase_pm_request_gpu_cycle_counter_l2_is_on - Mark GPU cycle counter is
393423 * needed (l2 cache already on)
424
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
394425 *
395426 * This is a version of the above function
396427 * (kbase_pm_request_gpu_cycle_counter()) suitable for being called when the
....@@ -401,14 +432,13 @@
401432 * The GPU must be powered when calling this function (i.e.
402433 * kbase_pm_context_active() must have been called) and the l2 cache must be
403434 * powered on.
404
- *
405
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
406435 */
407436 void kbase_pm_request_gpu_cycle_counter_l2_is_on(struct kbase_device *kbdev);
408437
409438 /**
410439 * kbase_pm_release_gpu_cycle_counter - Mark that the GPU cycle counter is no
411440 * longer in use
441
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
412442 *
413443 * If the caller is the last caller then the GPU cycle counters will be
414444 * disabled. A request must have been made before a call to this.
....@@ -416,37 +446,48 @@
416446 * Caller must not hold the hwaccess_lock, as it will be taken in this function.
417447 * If the caller is already holding this lock then
418448 * kbase_pm_release_gpu_cycle_counter_nolock() must be used instead.
419
- *
420
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
421449 */
422450 void kbase_pm_release_gpu_cycle_counter(struct kbase_device *kbdev);
423451
424452 /**
425453 * kbase_pm_release_gpu_cycle_counter_nolock - Version of kbase_pm_release_gpu_cycle_counter()
426454 * that does not take hwaccess_lock
455
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
427456 *
428457 * Caller must hold the hwaccess_lock.
429
- *
430
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
431458 */
432459 void kbase_pm_release_gpu_cycle_counter_nolock(struct kbase_device *kbdev);
433460
434461 /**
435
- * kbase_pm_wait_for_poweroff_complete - Wait for the poweroff workqueue to
436
- * complete
462
+ * kbase_pm_wait_for_poweroff_work_complete - Wait for the poweroff workqueue to
463
+ * complete
437464 *
438465 * @kbdev: The kbase device structure for the device (must be a valid pointer)
466
+ *
467
+ * This function effectively just waits for the @gpu_poweroff_wait_work work
468
+ * item to complete, if it was enqueued. GPU may not have been powered down
469
+ * before this function returns.
439470 */
440
-void kbase_pm_wait_for_poweroff_complete(struct kbase_device *kbdev);
471
+void kbase_pm_wait_for_poweroff_work_complete(struct kbase_device *kbdev);
472
+
473
+/**
474
+ * kbase_pm_wait_for_gpu_power_down - Wait for the GPU power down to complete
475
+ *
476
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
477
+ *
478
+ * This function waits for the actual gpu power down to complete.
479
+ */
480
+void kbase_pm_wait_for_gpu_power_down(struct kbase_device *kbdev);
441481
442482 /**
443483 * kbase_pm_runtime_init - Initialize runtime-pm for Mali GPU platform device
484
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
444485 *
445486 * Setup the power management callbacks and initialize/enable the runtime-pm
446487 * for the Mali GPU platform device, using the callback function. This must be
447488 * called before the kbase_pm_register_access_enable() function.
448489 *
449
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
490
+ * Return: 0 on success, error code on error
450491 */
451492 int kbase_pm_runtime_init(struct kbase_device *kbdev);
452493
....@@ -459,6 +500,7 @@
459500
460501 /**
461502 * kbase_pm_register_access_enable - Enable access to GPU registers
503
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
462504 *
463505 * Enables access to the GPU registers before power management has powered up
464506 * the GPU with kbase_pm_powerup().
....@@ -469,13 +511,12 @@
469511 *
470512 * This should only be used before power management is powered up with
471513 * kbase_pm_powerup()
472
- *
473
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
474514 */
475515 void kbase_pm_register_access_enable(struct kbase_device *kbdev);
476516
477517 /**
478518 * kbase_pm_register_access_disable - Disable early register access
519
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
479520 *
480521 * Disables access to the GPU registers enabled earlier by a call to
481522 * kbase_pm_register_access_enable().
....@@ -486,8 +527,6 @@
486527 *
487528 * This should only be used before power management is powered up with
488529 * kbase_pm_powerup()
489
- *
490
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
491530 */
492531 void kbase_pm_register_access_disable(struct kbase_device *kbdev);
493532
....@@ -498,6 +537,7 @@
498537 /**
499538 * kbase_pm_metrics_is_active - Check if the power management metrics
500539 * collection is active.
540
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
501541 *
502542 * Note that this returns if the power management metrics collection was
503543 * active at the time of calling, it is possible that after the call the metrics
....@@ -505,7 +545,6 @@
505545 *
506546 * The caller must handle the consequence that the state may have changed.
507547 *
508
- * @kbdev: The kbase device structure for the device (must be a valid pointer)
509548 * Return: true if metrics collection was active else false.
510549 */
511550 bool kbase_pm_metrics_is_active(struct kbase_device *kbdev);
....@@ -541,12 +580,13 @@
541580 /**
542581 * kbase_platform_dvfs_event - Report utilisation to DVFS code for CSF GPU
543582 *
544
- * Function provided by platform specific code when DVFS is enabled to allow
545
- * the power management metrics system to report utilisation.
546
- *
547583 * @kbdev: The kbase device structure for the device (must be a
548584 * valid pointer)
549585 * @utilisation: The current calculated utilisation by the metrics system.
586
+ *
587
+ * Function provided by platform specific code when DVFS is enabled to allow
588
+ * the power management metrics system to report utilisation.
589
+ *
550590 * Return: Returns 0 on failure and non zero on success.
551591 */
552592 int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation);
....@@ -554,15 +594,15 @@
554594 /**
555595 * kbase_platform_dvfs_event - Report utilisation to DVFS code for JM GPU
556596 *
557
- * Function provided by platform specific code when DVFS is enabled to allow
558
- * the power management metrics system to report utilisation.
559
- *
560597 * @kbdev: The kbase device structure for the device (must be a
561598 * valid pointer)
562599 * @utilisation: The current calculated utilisation by the metrics system.
563600 * @util_gl_share: The current calculated gl share of utilisation.
564601 * @util_cl_share: The current calculated cl share of utilisation per core
565602 * group.
603
+ * Function provided by platform specific code when DVFS is enabled to allow
604
+ * the power management metrics system to report utilisation.
605
+ *
566606 * Return: Returns 0 on failure and non zero on success.
567607 */
568608 int kbase_platform_dvfs_event(struct kbase_device *kbdev, u32 utilisation,
....@@ -635,6 +675,7 @@
635675 */
636676 void kbase_pm_reset_complete(struct kbase_device *kbdev);
637677
678
+#if !MALI_USE_CSF
638679 /**
639680 * kbase_pm_protected_override_enable - Enable the protected mode override
640681 * @kbdev: Device pointer
....@@ -707,6 +748,7 @@
707748 * to enter protected mode.
708749 */
709750 void kbase_pm_protected_entry_override_disable(struct kbase_device *kbdev);
751
+#endif
710752
711753 /* If true, the driver should explicitly control corestack power management,
712754 * instead of relying on the Power Domain Controller.
....@@ -735,6 +777,21 @@
735777 * Return: true if MCU needs to be enabled.
736778 */
737779 bool kbase_pm_is_mcu_desired(struct kbase_device *kbdev);
780
+
781
+/**
782
+ * kbase_pm_is_mcu_inactive - Check if the MCU is inactive (i.e. either
783
+ * it is disabled or it is in sleep)
784
+ *
785
+ * @kbdev: kbase device
786
+ * @state: state of the MCU state machine.
787
+ *
788
+ * This function must be called with hwaccess_lock held.
789
+ * L2 cache can be turned off if this function returns true.
790
+ *
791
+ * Return: true if MCU is inactive
792
+ */
793
+bool kbase_pm_is_mcu_inactive(struct kbase_device *kbdev,
794
+ enum kbase_mcu_state state);
738795
739796 /**
740797 * kbase_pm_idle_groups_sched_suspendable - Check whether the scheduler can be
....@@ -774,7 +831,7 @@
774831
775832 /**
776833 * kbase_pm_no_mcu_core_pwroff - Check whether the PM is required to keep the
777
- * MCU core powered in accordance to the active
834
+ * MCU shader Core powered in accordance to the active
778835 * power management policy
779836 *
780837 * @kbdev: Device pointer
....@@ -788,7 +845,48 @@
788845 return kbdev->pm.backend.csf_pm_sched_flags &
789846 CSF_DYNAMIC_PM_CORE_KEEP_ON;
790847 }
848
+
849
+/**
850
+ * kbase_pm_mcu_is_in_desired_state - Check if MCU is in stable ON/OFF state.
851
+ *
852
+ * @kbdev: Device pointer
853
+ *
854
+ * Return: true if MCU is in stable ON/OFF state.
855
+ */
856
+static inline bool kbase_pm_mcu_is_in_desired_state(struct kbase_device *kbdev)
857
+{
858
+ bool in_desired_state = true;
859
+
860
+ if (kbase_pm_is_mcu_desired(kbdev) && kbdev->pm.backend.mcu_state != KBASE_MCU_ON)
861
+ in_desired_state = false;
862
+ else if (!kbase_pm_is_mcu_desired(kbdev) &&
863
+ (kbdev->pm.backend.mcu_state != KBASE_MCU_OFF) &&
864
+ (kbdev->pm.backend.mcu_state != KBASE_MCU_IN_SLEEP))
865
+ in_desired_state = false;
866
+
867
+ return in_desired_state;
868
+}
869
+
791870 #endif
871
+
872
+/**
873
+ * kbase_pm_l2_is_in_desired_state - Check if L2 is in stable ON/OFF state.
874
+ *
875
+ * @kbdev: Device pointer
876
+ *
877
+ * Return: true if L2 is in stable ON/OFF state.
878
+ */
879
+static inline bool kbase_pm_l2_is_in_desired_state(struct kbase_device *kbdev)
880
+{
881
+ bool in_desired_state = true;
882
+
883
+ if (kbase_pm_is_l2_desired(kbdev) && kbdev->pm.backend.l2_state != KBASE_L2_ON)
884
+ in_desired_state = false;
885
+ else if (!kbase_pm_is_l2_desired(kbdev) && kbdev->pm.backend.l2_state != KBASE_L2_OFF)
886
+ in_desired_state = false;
887
+
888
+ return in_desired_state;
889
+}
792890
793891 /**
794892 * kbase_pm_lock - Lock all necessary mutexes to perform PM actions
....@@ -818,4 +916,106 @@
818916 #endif /* !MALI_USE_CSF */
819917 }
820918
919
+#if MALI_USE_CSF && defined(KBASE_PM_RUNTIME)
920
+/**
921
+ * kbase_pm_gpu_sleep_allowed - Check if the GPU is allowed to be put in sleep
922
+ *
923
+ * @kbdev: Device pointer
924
+ *
925
+ * This function is called on GPU idle notification and if it returns false then
926
+ * GPU power down will be triggered by suspending the CSGs and halting the MCU.
927
+ *
928
+ * Return: true if the GPU is allowed to be in the sleep state.
929
+ */
930
+static inline bool kbase_pm_gpu_sleep_allowed(struct kbase_device *kbdev)
931
+{
932
+ /* If the autosuspend_delay has been set to 0 then it doesn't make
933
+ * sense to first put GPU to sleep state and then power it down,
934
+ * instead would be better to power it down right away.
935
+ * Also need to do the same when autosuspend_delay is set to a negative
936
+ * value, which implies that runtime pm is effectively disabled by the
937
+ * kernel.
938
+ * A high positive value of autosuspend_delay can be used to keep the
939
+ * GPU in sleep state for a long time.
940
+ */
941
+ if (unlikely(!kbdev->dev->power.autosuspend_delay ||
942
+ (kbdev->dev->power.autosuspend_delay < 0)))
943
+ return false;
944
+
945
+ return kbdev->pm.backend.gpu_sleep_supported;
946
+}
947
+
948
+/**
949
+ * kbase_pm_enable_db_mirror_interrupt - Enable the doorbell mirror interrupt to
950
+ * detect the User doorbell rings.
951
+ *
952
+ * @kbdev: Device pointer
953
+ *
954
+ * This function is called just before sending the sleep request to MCU firmware
955
+ * so that User doorbell rings can be detected whilst GPU remains in the sleep
956
+ * state.
957
+ *
958
+ */
959
+static inline void kbase_pm_enable_db_mirror_interrupt(struct kbase_device *kbdev)
960
+{
961
+ lockdep_assert_held(&kbdev->hwaccess_lock);
962
+
963
+ if (!kbdev->pm.backend.db_mirror_interrupt_enabled) {
964
+ u32 irq_mask = kbase_reg_read(kbdev,
965
+ GPU_CONTROL_REG(GPU_IRQ_MASK));
966
+
967
+ WARN_ON(irq_mask & DOORBELL_MIRROR);
968
+
969
+ kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_IRQ_MASK),
970
+ irq_mask | DOORBELL_MIRROR);
971
+ kbdev->pm.backend.db_mirror_interrupt_enabled = true;
972
+ }
973
+}
974
+
975
+/**
976
+ * kbase_pm_disable_db_mirror_interrupt - Disable the doorbell mirror interrupt.
977
+ *
978
+ * @kbdev: Device pointer
979
+ *
980
+ * This function is called when doorbell mirror interrupt is received or MCU
981
+ * needs to be reactivated by enabling the doorbell notification.
982
+ */
983
+static inline void kbase_pm_disable_db_mirror_interrupt(struct kbase_device *kbdev)
984
+{
985
+ lockdep_assert_held(&kbdev->hwaccess_lock);
986
+
987
+ if (kbdev->pm.backend.db_mirror_interrupt_enabled) {
988
+ u32 irq_mask = kbase_reg_read(kbdev,
989
+ GPU_CONTROL_REG(GPU_IRQ_MASK));
990
+
991
+ kbase_reg_write(kbdev, GPU_CONTROL_REG(GPU_IRQ_MASK),
992
+ irq_mask & ~DOORBELL_MIRROR);
993
+ kbdev->pm.backend.db_mirror_interrupt_enabled = false;
994
+ }
995
+}
996
+#endif
997
+
998
+/**
999
+ * kbase_pm_l2_allow_mmu_page_migration - L2 state allows MMU page migration or not
1000
+ *
1001
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
1002
+ *
1003
+ * Check whether the L2 state is in power transition phase or not. If it is, the MMU
1004
+ * page migration should be deferred. The caller must hold hwaccess_lock, and, if MMU
1005
+ * page migration is intended, immediately start the MMU migration action without
1006
+ * dropping the lock. When page migration begins, a flag is set in kbdev that would
1007
+ * prevent the L2 state machine traversing into power transition phases, until
1008
+ * the MMU migration action ends.
1009
+ *
1010
+ * Return: true if MMU page migration is allowed
1011
+ */
1012
+static inline bool kbase_pm_l2_allow_mmu_page_migration(struct kbase_device *kbdev)
1013
+{
1014
+ struct kbase_pm_backend_data *backend = &kbdev->pm.backend;
1015
+
1016
+ lockdep_assert_held(&kbdev->hwaccess_lock);
1017
+
1018
+ return (backend->l2_state != KBASE_L2_PEND_ON && backend->l2_state != KBASE_L2_PEND_OFF);
1019
+}
1020
+
8211021 #endif /* _KBASE_BACKEND_PM_INTERNAL_H_ */