.. | .. |
---|
1 | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
---|
2 | 2 | /* |
---|
3 | 3 | * |
---|
4 | | - * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved. |
---|
| 4 | + * (C) COPYRIGHT 2014-2022 ARM Limited. All rights reserved. |
---|
5 | 5 | * |
---|
6 | 6 | * This program is free software and is provided to you under the terms of the |
---|
7 | 7 | * GNU General Public License version 2 as published by the Free Software |
---|
.. | .. |
---|
29 | 29 | #include "mali_kbase_pm_always_on.h" |
---|
30 | 30 | #include "mali_kbase_pm_coarse_demand.h" |
---|
31 | 31 | |
---|
| 32 | +#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM) |
---|
| 33 | +#define KBASE_PM_RUNTIME 1 |
---|
| 34 | +#endif |
---|
| 35 | + |
---|
32 | 36 | /* Forward definition - see mali_kbase.h */ |
---|
33 | 37 | struct kbase_device; |
---|
34 | 38 | struct kbase_jd_atom; |
---|
35 | 39 | |
---|
36 | 40 | /** |
---|
37 | 41 | * enum kbase_pm_core_type - The types of core in a GPU. |
---|
| 42 | + * |
---|
| 43 | + * @KBASE_PM_CORE_L2: The L2 cache |
---|
| 44 | + * @KBASE_PM_CORE_SHADER: Shader cores |
---|
| 45 | + * @KBASE_PM_CORE_TILER: Tiler cores |
---|
| 46 | + * @KBASE_PM_CORE_STACK: Core stacks |
---|
38 | 47 | * |
---|
39 | 48 | * These enumerated values are used in calls to |
---|
40 | 49 | * - kbase_pm_get_present_cores() |
---|
.. | .. |
---|
45 | 54 | * They specify which type of core should be acted on. These values are set in |
---|
46 | 55 | * a manner that allows core_type_to_reg() function to be simpler and more |
---|
47 | 56 | * efficient. |
---|
48 | | - * |
---|
49 | | - * @KBASE_PM_CORE_L2: The L2 cache |
---|
50 | | - * @KBASE_PM_CORE_SHADER: Shader cores |
---|
51 | | - * @KBASE_PM_CORE_TILER: Tiler cores |
---|
52 | | - * @KBASE_PM_CORE_STACK: Core stacks |
---|
53 | 57 | */ |
---|
54 | 58 | enum kbase_pm_core_type { |
---|
55 | 59 | KBASE_PM_CORE_L2 = L2_PRESENT_LO, |
---|
.. | .. |
---|
131 | 135 | * or removed from a GPU slot. |
---|
132 | 136 | * @active_cl_ctx: number of CL jobs active on the GPU. Array is per-device. |
---|
133 | 137 | * @active_gl_ctx: number of GL jobs active on the GPU. Array is per-slot. |
---|
134 | | - * @lock: spinlock protecting the kbasep_pm_metrics_data structure |
---|
| 138 | + * @lock: spinlock protecting the kbasep_pm_metrics_state structure |
---|
135 | 139 | * @platform_data: pointer to data controlled by platform specific code |
---|
136 | 140 | * @kbdev: pointer to kbase device for which metrics are collected |
---|
137 | 141 | * @values: The current values of the power management metrics. The |
---|
.. | .. |
---|
140 | 144 | * @initialized: tracks whether metrics_state has been initialized or not. |
---|
141 | 145 | * @timer: timer to regularly make DVFS decisions based on the power |
---|
142 | 146 | * management metrics. |
---|
143 | | - * @timer_active: boolean indicating @timer is running |
---|
| 147 | + * @timer_state: atomic indicating current @timer state, on, off, or stopped. |
---|
144 | 148 | * @dvfs_last: values of the PM metrics from the last DVFS tick |
---|
145 | 149 | * @dvfs_diff: different between the current and previous PM metrics. |
---|
146 | 150 | */ |
---|
.. | .. |
---|
164 | 168 | #ifdef CONFIG_MALI_BIFROST_DVFS |
---|
165 | 169 | bool initialized; |
---|
166 | 170 | struct hrtimer timer; |
---|
167 | | - bool timer_active; |
---|
| 171 | + atomic_t timer_state; |
---|
168 | 172 | struct kbasep_pm_metrics dvfs_last; |
---|
169 | 173 | struct kbasep_pm_metrics dvfs_diff; |
---|
170 | 174 | #endif |
---|
.. | .. |
---|
210 | 214 | |
---|
211 | 215 | /** |
---|
212 | 216 | * struct kbase_pm_backend_data - Data stored per device for power management. |
---|
213 | | - * |
---|
214 | | - * This structure contains data for the power management framework. There is one |
---|
215 | | - * instance of this structure per device in the system. |
---|
216 | 217 | * |
---|
217 | 218 | * @pm_current_policy: The policy that is currently actively controlling the |
---|
218 | 219 | * power state. |
---|
.. | .. |
---|
271 | 272 | * &struct kbase_pm_callback_conf |
---|
272 | 273 | * @callback_power_runtime_off: Callback when the GPU may be turned off. See |
---|
273 | 274 | * &struct kbase_pm_callback_conf |
---|
274 | | - * @callback_power_runtime_idle: Optional callback when the GPU may be idle. See |
---|
275 | | - * &struct kbase_pm_callback_conf |
---|
| 275 | + * @callback_power_runtime_idle: Optional callback invoked by runtime PM core |
---|
| 276 | + * when the GPU may be idle. See |
---|
| 277 | + * &struct kbase_pm_callback_conf |
---|
276 | 278 | * @callback_soft_reset: Optional callback to software reset the GPU. See |
---|
277 | 279 | * &struct kbase_pm_callback_conf |
---|
| 280 | + * @callback_power_runtime_gpu_idle: Callback invoked by Kbase when GPU has |
---|
| 281 | + * become idle. |
---|
| 282 | + * See &struct kbase_pm_callback_conf. |
---|
| 283 | + * @callback_power_runtime_gpu_active: Callback when GPU has become active and |
---|
| 284 | + * @callback_power_runtime_gpu_idle was |
---|
| 285 | + * called previously. |
---|
| 286 | + * See &struct kbase_pm_callback_conf. |
---|
278 | 287 | * @ca_cores_enabled: Cores that are currently available |
---|
279 | 288 | * @mcu_state: The current state of the micro-control unit, only applicable |
---|
280 | 289 | * to GPUs that have such a component |
---|
.. | .. |
---|
312 | 321 | * @policy_change_lock: Used to serialize the policy change calls. In CSF case, |
---|
313 | 322 | * the change of policy may involve the scheduler to |
---|
314 | 323 | * suspend running CSGs and then reconfigure the MCU. |
---|
| 324 | + * @core_idle_wq: Workqueue for executing the @core_idle_work. |
---|
| 325 | + * @core_idle_work: Work item used to wait for undesired cores to become inactive. |
---|
| 326 | + * The work item is enqueued when Host controls the power for |
---|
| 327 | + * shader cores and down scaling of cores is performed. |
---|
| 328 | + * @gpu_sleep_supported: Flag to indicate that if GPU sleep feature can be |
---|
| 329 | + * supported by the kernel driver or not. If this |
---|
| 330 | + * flag is not set, then HW state is directly saved |
---|
| 331 | + * when GPU idle notification is received. |
---|
| 332 | + * @gpu_sleep_mode_active: Flag to indicate that the GPU needs to be in sleep |
---|
| 333 | + * mode. It is set when the GPU idle notification is |
---|
| 334 | + * received and is cleared when HW state has been |
---|
| 335 | + * saved in the runtime suspend callback function or |
---|
| 336 | + * when the GPU power down is aborted if GPU became |
---|
| 337 | + * active whilst it was in sleep mode. The flag is |
---|
| 338 | + * guarded with hwaccess_lock spinlock. |
---|
| 339 | + * @exit_gpu_sleep_mode: Flag to indicate the GPU can now exit the sleep |
---|
| 340 | + * mode due to the submission of work from Userspace. |
---|
| 341 | + * The flag is guarded with hwaccess_lock spinlock. |
---|
| 342 | + * The @gpu_sleep_mode_active flag is not immediately |
---|
| 343 | + * reset when this flag is set, this is to ensure that |
---|
| 344 | + * MCU doesn't gets disabled undesirably without the |
---|
| 345 | + * suspend of CSGs. That could happen when |
---|
| 346 | + * scheduler_pm_active() and scheduler_pm_idle() gets |
---|
| 347 | + * called before the Scheduler gets reactivated. |
---|
| 348 | + * @gpu_idled: Flag to ensure that the gpu_idle & gpu_active callbacks are |
---|
| 349 | + * always called in pair. The flag is guarded with pm.lock mutex. |
---|
| 350 | + * @gpu_wakeup_override: Flag to force the power up of L2 cache & reactivation |
---|
| 351 | + * of MCU. This is set during the runtime suspend |
---|
| 352 | + * callback function, when GPU needs to exit the sleep |
---|
| 353 | + * mode for the saving the HW state before power down. |
---|
| 354 | + * @db_mirror_interrupt_enabled: Flag tracking if the Doorbell mirror interrupt |
---|
| 355 | + * is enabled or not. |
---|
315 | 356 | * @in_reset: True if a GPU is resetting and normal power manager operation is |
---|
316 | 357 | * suspended |
---|
317 | 358 | * @partial_shaderoff: True if we want to partial power off shader cores, |
---|
.. | .. |
---|
348 | 389 | * work function, kbase_pm_gpu_clock_control_worker. |
---|
349 | 390 | * @gpu_clock_control_work: work item to set GPU clock during L2 power cycle |
---|
350 | 391 | * using gpu_clock_control |
---|
| 392 | + * |
---|
| 393 | + * This structure contains data for the power management framework. There is one |
---|
| 394 | + * instance of this structure per device in the system. |
---|
351 | 395 | * |
---|
352 | 396 | * Note: |
---|
353 | 397 | * During an IRQ, @pm_current_policy can be NULL when the policy is being |
---|
.. | .. |
---|
398 | 442 | void (*callback_power_runtime_off)(struct kbase_device *kbdev); |
---|
399 | 443 | int (*callback_power_runtime_idle)(struct kbase_device *kbdev); |
---|
400 | 444 | int (*callback_soft_reset)(struct kbase_device *kbdev); |
---|
| 445 | + void (*callback_power_runtime_gpu_idle)(struct kbase_device *kbdev); |
---|
| 446 | + void (*callback_power_runtime_gpu_active)(struct kbase_device *kbdev); |
---|
401 | 447 | |
---|
402 | 448 | u64 ca_cores_enabled; |
---|
403 | 449 | |
---|
.. | .. |
---|
413 | 459 | bool policy_change_clamp_state_to_off; |
---|
414 | 460 | unsigned int csf_pm_sched_flags; |
---|
415 | 461 | struct mutex policy_change_lock; |
---|
| 462 | + struct workqueue_struct *core_idle_wq; |
---|
| 463 | + struct work_struct core_idle_work; |
---|
| 464 | + |
---|
| 465 | +#ifdef KBASE_PM_RUNTIME |
---|
| 466 | + bool gpu_sleep_supported; |
---|
| 467 | + bool gpu_sleep_mode_active; |
---|
| 468 | + bool exit_gpu_sleep_mode; |
---|
| 469 | + bool gpu_idled; |
---|
| 470 | + bool gpu_wakeup_override; |
---|
| 471 | + bool db_mirror_interrupt_enabled; |
---|
| 472 | +#endif |
---|
416 | 473 | #endif |
---|
417 | 474 | bool l2_desired; |
---|
418 | 475 | bool l2_always_on; |
---|
.. | .. |
---|
420 | 477 | |
---|
421 | 478 | bool in_reset; |
---|
422 | 479 | |
---|
| 480 | +#if !MALI_USE_CSF |
---|
423 | 481 | bool partial_shaderoff; |
---|
424 | 482 | |
---|
425 | 483 | bool protected_entry_transition_override; |
---|
426 | 484 | bool protected_transition_override; |
---|
427 | 485 | int protected_l2_override; |
---|
| 486 | +#endif |
---|
428 | 487 | |
---|
429 | 488 | bool hwcnt_desired; |
---|
430 | 489 | bool hwcnt_disabled; |
---|
.. | .. |
---|
438 | 497 | }; |
---|
439 | 498 | |
---|
440 | 499 | #if MALI_USE_CSF |
---|
441 | | -/* CSF PM flag, signaling that the MCU CORE should be kept on */ |
---|
| 500 | +/* CSF PM flag, signaling that the MCU shader Core should be kept on */ |
---|
442 | 501 | #define CSF_DYNAMIC_PM_CORE_KEEP_ON (1 << 0) |
---|
443 | 502 | /* CSF PM flag, signaling no scheduler suspension on idle groups */ |
---|
444 | 503 | #define CSF_DYNAMIC_PM_SCHED_IGNORE_IDLE (1 << 1) |
---|
.. | .. |
---|
494 | 553 | /** |
---|
495 | 554 | * struct kbase_pm_policy - Power policy structure. |
---|
496 | 555 | * |
---|
497 | | - * Each power policy exposes a (static) instance of this structure which |
---|
498 | | - * contains function pointers to the policy's methods. |
---|
499 | | - * |
---|
500 | 556 | * @name: The name of this policy |
---|
501 | 557 | * @init: Function called when the policy is selected |
---|
502 | 558 | * @term: Function called when the policy is unselected |
---|
.. | .. |
---|
514 | 570 | * Pre-defined required flags exist for each of the |
---|
515 | 571 | * ARM released policies, such as 'always_on', 'coarse_demand' |
---|
516 | 572 | * and etc. |
---|
| 573 | + * Each power policy exposes a (static) instance of this structure which |
---|
| 574 | + * contains function pointers to the policy's methods. |
---|
517 | 575 | */ |
---|
518 | 576 | struct kbase_pm_policy { |
---|
519 | 577 | char *name; |
---|
.. | .. |
---|
566 | 624 | */ |
---|
567 | 625 | bool (*get_core_active)(struct kbase_device *kbdev); |
---|
568 | 626 | |
---|
569 | | - /** |
---|
| 627 | + /* |
---|
570 | 628 | * Function called when a power event occurs |
---|
571 | 629 | * |
---|
572 | 630 | * @kbdev: The kbase device structure for the device (must be a |
---|