forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/gpu/arm/bifrost/backend/gpu/mali_kbase_pm_defs.h
....@@ -1,7 +1,7 @@
11 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22 /*
33 *
4
- * (C) COPYRIGHT 2014-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2014-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
....@@ -29,12 +29,21 @@
2929 #include "mali_kbase_pm_always_on.h"
3030 #include "mali_kbase_pm_coarse_demand.h"
3131
32
+#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM)
33
+#define KBASE_PM_RUNTIME 1
34
+#endif
35
+
3236 /* Forward definition - see mali_kbase.h */
3337 struct kbase_device;
3438 struct kbase_jd_atom;
3539
3640 /**
3741 * 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
3847 *
3948 * These enumerated values are used in calls to
4049 * - kbase_pm_get_present_cores()
....@@ -45,11 +54,6 @@
4554 * They specify which type of core should be acted on. These values are set in
4655 * a manner that allows core_type_to_reg() function to be simpler and more
4756 * 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
5357 */
5458 enum kbase_pm_core_type {
5559 KBASE_PM_CORE_L2 = L2_PRESENT_LO,
....@@ -131,7 +135,7 @@
131135 * or removed from a GPU slot.
132136 * @active_cl_ctx: number of CL jobs active on the GPU. Array is per-device.
133137 * @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
135139 * @platform_data: pointer to data controlled by platform specific code
136140 * @kbdev: pointer to kbase device for which metrics are collected
137141 * @values: The current values of the power management metrics. The
....@@ -140,7 +144,7 @@
140144 * @initialized: tracks whether metrics_state has been initialized or not.
141145 * @timer: timer to regularly make DVFS decisions based on the power
142146 * management metrics.
143
- * @timer_active: boolean indicating @timer is running
147
+ * @timer_state: atomic indicating current @timer state, on, off, or stopped.
144148 * @dvfs_last: values of the PM metrics from the last DVFS tick
145149 * @dvfs_diff: different between the current and previous PM metrics.
146150 */
....@@ -164,7 +168,7 @@
164168 #ifdef CONFIG_MALI_BIFROST_DVFS
165169 bool initialized;
166170 struct hrtimer timer;
167
- bool timer_active;
171
+ atomic_t timer_state;
168172 struct kbasep_pm_metrics dvfs_last;
169173 struct kbasep_pm_metrics dvfs_diff;
170174 #endif
....@@ -210,9 +214,6 @@
210214
211215 /**
212216 * 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.
216217 *
217218 * @pm_current_policy: The policy that is currently actively controlling the
218219 * power state.
....@@ -271,10 +272,18 @@
271272 * &struct kbase_pm_callback_conf
272273 * @callback_power_runtime_off: Callback when the GPU may be turned off. See
273274 * &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
276278 * @callback_soft_reset: Optional callback to software reset the GPU. See
277279 * &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.
278287 * @ca_cores_enabled: Cores that are currently available
279288 * @mcu_state: The current state of the micro-control unit, only applicable
280289 * to GPUs that have such a component
....@@ -312,6 +321,38 @@
312321 * @policy_change_lock: Used to serialize the policy change calls. In CSF case,
313322 * the change of policy may involve the scheduler to
314323 * 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.
315356 * @in_reset: True if a GPU is resetting and normal power manager operation is
316357 * suspended
317358 * @partial_shaderoff: True if we want to partial power off shader cores,
....@@ -348,6 +389,9 @@
348389 * work function, kbase_pm_gpu_clock_control_worker.
349390 * @gpu_clock_control_work: work item to set GPU clock during L2 power cycle
350391 * 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.
351395 *
352396 * Note:
353397 * During an IRQ, @pm_current_policy can be NULL when the policy is being
....@@ -398,6 +442,8 @@
398442 void (*callback_power_runtime_off)(struct kbase_device *kbdev);
399443 int (*callback_power_runtime_idle)(struct kbase_device *kbdev);
400444 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);
401447
402448 u64 ca_cores_enabled;
403449
....@@ -413,6 +459,17 @@
413459 bool policy_change_clamp_state_to_off;
414460 unsigned int csf_pm_sched_flags;
415461 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
416473 #endif
417474 bool l2_desired;
418475 bool l2_always_on;
....@@ -420,11 +477,13 @@
420477
421478 bool in_reset;
422479
480
+#if !MALI_USE_CSF
423481 bool partial_shaderoff;
424482
425483 bool protected_entry_transition_override;
426484 bool protected_transition_override;
427485 int protected_l2_override;
486
+#endif
428487
429488 bool hwcnt_desired;
430489 bool hwcnt_disabled;
....@@ -438,7 +497,7 @@
438497 };
439498
440499 #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 */
442501 #define CSF_DYNAMIC_PM_CORE_KEEP_ON (1 << 0)
443502 /* CSF PM flag, signaling no scheduler suspension on idle groups */
444503 #define CSF_DYNAMIC_PM_SCHED_IGNORE_IDLE (1 << 1)
....@@ -494,9 +553,6 @@
494553 /**
495554 * struct kbase_pm_policy - Power policy structure.
496555 *
497
- * Each power policy exposes a (static) instance of this structure which
498
- * contains function pointers to the policy's methods.
499
- *
500556 * @name: The name of this policy
501557 * @init: Function called when the policy is selected
502558 * @term: Function called when the policy is unselected
....@@ -514,6 +570,8 @@
514570 * Pre-defined required flags exist for each of the
515571 * ARM released policies, such as 'always_on', 'coarse_demand'
516572 * and etc.
573
+ * Each power policy exposes a (static) instance of this structure which
574
+ * contains function pointers to the policy's methods.
517575 */
518576 struct kbase_pm_policy {
519577 char *name;
....@@ -566,7 +624,7 @@
566624 */
567625 bool (*get_core_active)(struct kbase_device *kbdev);
568626
569
- /**
627
+ /*
570628 * Function called when a power event occurs
571629 *
572630 * @kbdev: The kbase device structure for the device (must be a