hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/include/linux/cpufreq.h
....@@ -1,12 +1,9 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * linux/include/linux/cpufreq.h
34 *
45 * Copyright (C) 2001 Russell King
56 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118 #ifndef _LINUX_CPUFREQ_H
129 #define _LINUX_CPUFREQ_H
....@@ -16,6 +13,7 @@
1613 #include <linux/completion.h>
1714 #include <linux/kobject.h>
1815 #include <linux/notifier.h>
16
+#include <linux/pm_qos.h>
1917 #include <linux/spinlock.h>
2018 #include <linux/sysfs.h>
2119
....@@ -42,24 +40,12 @@
4240 CPUFREQ_TABLE_SORTED_DESCENDING
4341 };
4442
45
-struct cpufreq_freqs {
46
- unsigned int cpu; /* cpu nr */
47
- unsigned int old;
48
- unsigned int new;
49
- u8 flags; /* flags of cpufreq_driver, see below. */
50
-};
51
-
5243 struct cpufreq_cpuinfo {
5344 unsigned int max_freq;
5445 unsigned int min_freq;
5546
5647 /* in 10^(-9) s = nanoseconds */
5748 unsigned int transition_latency;
58
-};
59
-
60
-struct cpufreq_user_policy {
61
- unsigned int min; /* in kHz */
62
- unsigned int max; /* in kHz */
6349 };
6450
6551 struct cpufreq_policy {
....@@ -91,7 +77,10 @@
9177 struct work_struct update; /* if update_policy() needs to be
9278 * called, but you're in IRQ context */
9379
94
- struct cpufreq_user_policy user_policy;
80
+ struct freq_constraints constraints;
81
+ struct freq_qos_request *min_freq_req;
82
+ struct freq_qos_request *max_freq_req;
83
+
9584 struct cpufreq_frequency_table *freq_table;
9685 enum cpufreq_table_sorting freq_table_sorted;
9786
....@@ -121,6 +110,12 @@
121110 bool fast_switch_enabled;
122111
123112 /*
113
+ * Set if the CPUFREQ_GOV_STRICT_TARGET flag is set for the current
114
+ * governor.
115
+ */
116
+ bool strict_target;
117
+
118
+ /*
124119 * Preferred average time interval between consecutive invocations of
125120 * the driver to set the frequency for this policy. To be set by the
126121 * scaling driver (0, which is the default, means no preference).
....@@ -138,7 +133,7 @@
138133
139134 /* Cached frequency lookup from cpufreq_driver_resolve_freq. */
140135 unsigned int cached_target_freq;
141
- int cached_resolved_idx;
136
+ unsigned int cached_resolved_idx;
142137
143138 /* Synchronization for frequency transitions */
144139 bool transition_ongoing; /* Tracks transition status */
....@@ -154,6 +149,30 @@
154149
155150 /* Pointer to the cooling device if used for thermal mitigation */
156151 struct thermal_cooling_device *cdev;
152
+
153
+ struct notifier_block nb_min;
154
+ struct notifier_block nb_max;
155
+};
156
+
157
+/*
158
+ * Used for passing new cpufreq policy data to the cpufreq driver's ->verify()
159
+ * callback for sanitization. That callback is only expected to modify the min
160
+ * and max values, if necessary, and specifically it must not update the
161
+ * frequency table.
162
+ */
163
+struct cpufreq_policy_data {
164
+ struct cpufreq_cpuinfo cpuinfo;
165
+ struct cpufreq_frequency_table *freq_table;
166
+ unsigned int cpu;
167
+ unsigned int min; /* in kHz */
168
+ unsigned int max; /* in kHz */
169
+};
170
+
171
+struct cpufreq_freqs {
172
+ struct cpufreq_policy *policy;
173
+ unsigned int old;
174
+ unsigned int new;
175
+ u8 flags; /* flags of cpufreq_driver, see below. */
157176 };
158177
159178 /* Only for ACPI */
....@@ -178,24 +197,33 @@
178197 static inline void cpufreq_cpu_put(struct cpufreq_policy *policy) { }
179198 #endif
180199
200
+static inline bool policy_is_inactive(struct cpufreq_policy *policy)
201
+{
202
+ return cpumask_empty(policy->cpus);
203
+}
204
+
181205 static inline bool policy_is_shared(struct cpufreq_policy *policy)
182206 {
183207 return cpumask_weight(policy->cpus) > 1;
184208 }
185209
186
-/* /sys/devices/system/cpu/cpufreq: entry point for global variables */
187
-extern struct kobject *cpufreq_global_kobject;
188
-
189210 #ifdef CONFIG_CPU_FREQ
190211 unsigned int cpufreq_get(unsigned int cpu);
191212 unsigned int cpufreq_quick_get(unsigned int cpu);
192213 unsigned int cpufreq_quick_get_max(unsigned int cpu);
214
+unsigned int cpufreq_get_hw_max_freq(unsigned int cpu);
193215 void disable_cpufreq(void);
194216
195217 u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
218
+
219
+struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu);
220
+void cpufreq_cpu_release(struct cpufreq_policy *policy);
196221 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
222
+void refresh_frequency_limits(struct cpufreq_policy *policy);
197223 void cpufreq_update_policy(unsigned int cpu);
224
+void cpufreq_update_limits(unsigned int cpu);
198225 bool have_governor_per_policy(void);
226
+bool cpufreq_supports_freq_invariance(void);
199227 struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
200228 void cpufreq_enable_fast_switch(struct cpufreq_policy *policy);
201229 void cpufreq_disable_fast_switch(struct cpufreq_policy *policy);
....@@ -212,8 +240,15 @@
212240 {
213241 return 0;
214242 }
243
+static inline unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
244
+{
245
+ return 0;
246
+}
247
+static inline bool cpufreq_supports_freq_invariance(void)
248
+{
249
+ return false;
250
+}
215251 static inline void disable_cpufreq(void) { }
216
-static inline void cpufreq_update_policy(unsigned int cpu) { }
217252 #endif
218253
219254 #ifdef CONFIG_CPU_FREQ_STAT
....@@ -269,12 +304,12 @@
269304
270305 struct cpufreq_driver {
271306 char name[CPUFREQ_NAME_LEN];
272
- u8 flags;
307
+ u16 flags;
273308 void *driver_data;
274309
275310 /* needed by all drivers */
276311 int (*init)(struct cpufreq_policy *policy);
277
- int (*verify)(struct cpufreq_policy *policy);
312
+ int (*verify)(struct cpufreq_policy_data *policy);
278313
279314 /* define one out of two */
280315 int (*setpolicy)(struct cpufreq_policy *policy);
....@@ -306,7 +341,7 @@
306341 *
307342 * get_intermediate should return a stable intermediate frequency
308343 * platform wants to switch to and target_intermediate() should set CPU
309
- * to to that frequency, before jumping to the frequency corresponding
344
+ * to that frequency, before jumping to the frequency corresponding
310345 * to 'index'. Core will take care of sending notifications and driver
311346 * doesn't have to handle them in target_intermediate() or
312347 * target_index().
....@@ -323,9 +358,14 @@
323358 /* should be defined, if possible */
324359 unsigned int (*get)(unsigned int cpu);
325360
361
+ /* Called to update policy limits on firmware notifications. */
362
+ void (*update_limits)(unsigned int cpu);
363
+
326364 /* optional */
327365 int (*bios_limit)(int cpu, unsigned int *limit);
328366
367
+ int (*online)(struct cpufreq_policy *policy);
368
+ int (*offline)(struct cpufreq_policy *policy);
329369 int (*exit)(struct cpufreq_policy *policy);
330370 void (*stop_cpu)(struct cpufreq_policy *policy);
331371 int (*suspend)(struct cpufreq_policy *policy);
....@@ -338,18 +378,19 @@
338378
339379 /* platform specific boost support code */
340380 bool boost_enabled;
341
- int (*set_boost)(int state);
381
+ int (*set_boost)(struct cpufreq_policy *policy, int state);
342382 };
343383
344384 /* flags */
345
-#define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
346
- all ->init() calls failed */
347
-#define CPUFREQ_CONST_LOOPS (1 << 1) /* loops_per_jiffy or other
348
- kernel "constants" aren't
349
- affected by frequency
350
- transitions */
351
-#define CPUFREQ_PM_NO_WARN (1 << 2) /* don't warn on suspend/resume
352
- speed mismatches */
385
+
386
+/* driver isn't removed even if all ->init() calls failed */
387
+#define CPUFREQ_STICKY BIT(0)
388
+
389
+/* loops_per_jiffy or other kernel "constants" aren't affected by frequency transitions */
390
+#define CPUFREQ_CONST_LOOPS BIT(1)
391
+
392
+/* don't warn on suspend/resume speed mismatches */
393
+#define CPUFREQ_PM_NO_WARN BIT(2)
353394
354395 /*
355396 * This should be set by platforms having multiple clock-domains, i.e.
....@@ -357,14 +398,14 @@
357398 * be created in cpu/cpu<num>/cpufreq/ directory and so they can use the same
358399 * governor with different tunables for different clusters.
359400 */
360
-#define CPUFREQ_HAVE_GOVERNOR_PER_POLICY (1 << 3)
401
+#define CPUFREQ_HAVE_GOVERNOR_PER_POLICY BIT(3)
361402
362403 /*
363404 * Driver will do POSTCHANGE notifications from outside of their ->target()
364405 * routine and so must set cpufreq_driver->flags with this flag, so that core
365406 * can handle them specially.
366407 */
367
-#define CPUFREQ_ASYNC_NOTIFICATION (1 << 4)
408
+#define CPUFREQ_ASYNC_NOTIFICATION BIT(4)
368409
369410 /*
370411 * Set by drivers which want cpufreq core to check if CPU is running at a
....@@ -373,13 +414,13 @@
373414 * from the table. And if that fails, we will stop further boot process by
374415 * issuing a BUG_ON().
375416 */
376
-#define CPUFREQ_NEED_INITIAL_FREQ_CHECK (1 << 5)
417
+#define CPUFREQ_NEED_INITIAL_FREQ_CHECK BIT(5)
377418
378419 /*
379420 * Set by drivers to disallow use of governors with "dynamic_switching" flag
380421 * set.
381422 */
382
-#define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING (1 << 6)
423
+#define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING BIT(6)
383424
384425 /*
385426 * Set by drivers that want the core to automatically register the cpufreq
....@@ -387,14 +428,30 @@
387428 */
388429 #define CPUFREQ_IS_COOLING_DEV BIT(7)
389430
431
+/*
432
+ * Set by drivers that need to update internale upper and lower boundaries along
433
+ * with the target frequency and so the core and governors should also invoke
434
+ * the diver if the target frequency does not change, but the policy min or max
435
+ * may have changed.
436
+ */
437
+#define CPUFREQ_NEED_UPDATE_LIMITS BIT(8)
438
+
390439 int cpufreq_register_driver(struct cpufreq_driver *driver_data);
391440 int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
392441
442
+bool cpufreq_driver_test_flags(u16 flags);
393443 const char *cpufreq_get_current_driver(void);
394444 void *cpufreq_get_driver_data(void);
395445
396
-static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy,
397
- unsigned int min, unsigned int max)
446
+static inline int cpufreq_thermal_control_enabled(struct cpufreq_driver *drv)
447
+{
448
+ return IS_ENABLED(CONFIG_CPU_THERMAL) &&
449
+ (drv->flags & CPUFREQ_IS_COOLING_DEV);
450
+}
451
+
452
+static inline void cpufreq_verify_within_limits(struct cpufreq_policy_data *policy,
453
+ unsigned int min,
454
+ unsigned int max)
398455 {
399456 if (policy->min < min)
400457 policy->min = min;
....@@ -410,10 +467,10 @@
410467 }
411468
412469 static inline void
413
-cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy)
470
+cpufreq_verify_within_cpu_limits(struct cpufreq_policy_data *policy)
414471 {
415472 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
416
- policy->cpuinfo.max_freq);
473
+ policy->cpuinfo.max_freq);
417474 }
418475
419476 #ifdef CONFIG_CPU_FREQ
....@@ -437,8 +494,8 @@
437494 #define CPUFREQ_POSTCHANGE (1)
438495
439496 /* Policy Notifiers */
440
-#define CPUFREQ_ADJUST (0)
441
-#define CPUFREQ_NOTIFY (1)
497
+#define CPUFREQ_CREATE_POLICY (0)
498
+#define CPUFREQ_REMOVE_POLICY (1)
442499
443500 #ifdef CONFIG_CPU_FREQ
444501 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
....@@ -491,6 +548,7 @@
491548 * CPUFREQ GOVERNORS *
492549 *********************************************************************/
493550
551
+#define CPUFREQ_POLICY_UNKNOWN (0)
494552 /*
495553 * If (cpufreq_driver->target) exists, the ->governor decides what frequency
496554 * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
....@@ -518,11 +576,19 @@
518576 char *buf);
519577 int (*store_setspeed) (struct cpufreq_policy *policy,
520578 unsigned int freq);
521
- /* For governors which change frequency dynamically by themselves */
522
- bool dynamic_switching;
523579 struct list_head governor_list;
524580 struct module *owner;
581
+ u8 flags;
525582 };
583
+
584
+/* Governor flags */
585
+
586
+/* For governors which change frequency dynamically by themselves */
587
+#define CPUFREQ_GOV_DYNAMIC_SWITCHING BIT(0)
588
+
589
+/* For governors wanting the target frequency to be set exactly */
590
+#define CPUFREQ_GOV_STRICT_TARGET BIT(1)
591
+
526592
527593 /* Pass a target to the cpufreq driver */
528594 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
....@@ -538,6 +604,22 @@
538604 unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy);
539605 int cpufreq_register_governor(struct cpufreq_governor *governor);
540606 void cpufreq_unregister_governor(struct cpufreq_governor *governor);
607
+int cpufreq_start_governor(struct cpufreq_policy *policy);
608
+void cpufreq_stop_governor(struct cpufreq_policy *policy);
609
+
610
+#define cpufreq_governor_init(__governor) \
611
+static int __init __governor##_init(void) \
612
+{ \
613
+ return cpufreq_register_governor(&__governor); \
614
+} \
615
+core_initcall(__governor##_init)
616
+
617
+#define cpufreq_governor_exit(__governor) \
618
+static void __exit __governor##_exit(void) \
619
+{ \
620
+ return cpufreq_unregister_governor(&__governor); \
621
+} \
622
+module_exit(__governor##_exit)
541623
542624 struct cpufreq_governor *cpufreq_default_governor(void);
543625 struct cpufreq_governor *cpufreq_fallback_governor(void);
....@@ -662,9 +744,9 @@
662744 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
663745 struct cpufreq_frequency_table *table);
664746
665
-int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
747
+int cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy,
666748 struct cpufreq_frequency_table *table);
667
-int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy);
749
+int cpufreq_generic_frequency_table_verify(struct cpufreq_policy_data *policy);
668750
669751 int cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
670752 unsigned int target_freq,
....@@ -902,8 +984,8 @@
902984 case CPUFREQ_RELATION_C:
903985 return cpufreq_table_find_index_c(policy, target_freq);
904986 default:
905
- pr_err("%s: Invalid relation: %d\n", __func__, relation);
906
- return -EINVAL;
987
+ WARN_ON_ONCE(1);
988
+ return 0;
907989 }
908990 }
909991
....@@ -941,29 +1023,17 @@
9411023 }
9421024 #endif
9431025
944
-#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
945
-void sched_cpufreq_governor_change(struct cpufreq_policy *policy,
946
- struct cpufreq_governor *old_gov);
947
-#else
948
-static inline void sched_cpufreq_governor_change(struct cpufreq_policy *policy,
949
- struct cpufreq_governor *old_gov) { }
950
-#endif
951
-
952
-#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_CPU_FREQ_GOV_INTERACTIVE)
953
-void cpufreq_task_boost(int cpu, unsigned long util);
954
-#else
955
-static inline void cpufreq_task_boost(int cpu, unsigned long util)
956
-{
957
-}
958
-#endif
959
-
9601026 extern void arch_freq_prepare_all(void);
9611027 extern unsigned int arch_freq_get_on_cpu(int cpu);
9621028
963
-extern void arch_set_freq_scale(struct cpumask *cpus, unsigned long cur_freq,
964
- unsigned long max_freq);
965
-extern void arch_set_max_freq_scale(struct cpumask *cpus,
966
- unsigned long policy_max_freq);
1029
+#ifndef arch_set_freq_scale
1030
+static __always_inline
1031
+void arch_set_freq_scale(const struct cpumask *cpus,
1032
+ unsigned long cur_freq,
1033
+ unsigned long max_freq)
1034
+{
1035
+}
1036
+#endif
9671037
9681038 /* the following are really really optional */
9691039 extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
....@@ -972,7 +1042,7 @@
9721042 int cpufreq_table_validate_and_sort(struct cpufreq_policy *policy);
9731043
9741044 unsigned int cpufreq_generic_get(unsigned int cpu);
975
-int cpufreq_generic_init(struct cpufreq_policy *policy,
1045
+void cpufreq_generic_init(struct cpufreq_policy *policy,
9761046 struct cpufreq_frequency_table *table,
9771047 unsigned int transition_latency);
9781048 #endif /* _LINUX_CPUFREQ_H */