^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * cpufreq.h - definitions for libcpufreq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef __CPUPOWER_CPUFREQ_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define __CPUPOWER_CPUFREQ_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct cpufreq_policy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) unsigned long min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) unsigned long max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) char *governor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct cpufreq_available_governors {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) char *governor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct cpufreq_available_governors *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct cpufreq_available_governors *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct cpufreq_available_frequencies {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) unsigned long frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct cpufreq_available_frequencies *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct cpufreq_available_frequencies *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct cpufreq_affected_cpus {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct cpufreq_affected_cpus *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct cpufreq_affected_cpus *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct cpufreq_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned long frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned long long time_in_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct cpufreq_stats *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct cpufreq_stats *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #ifdef __cplusplus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) extern "C" {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* determine current CPU frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * - _kernel variant means kernel's opinion of CPU frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * - _hardware variant means actual hardware CPU frequency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * which is only available to root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * returns 0 on failure, else frequency in kHz.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned long cpufreq_get_freq_kernel(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned long cpufreq_get_freq_hardware(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* determine CPU transition latency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned long cpufreq_get_transition_latency(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* determine hardware CPU frequency limits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * These may be limited further by thermal, energy or other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * considerations by cpufreq policy notifiers in the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int cpufreq_get_hardware_limits(unsigned int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned long *min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned long *max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* determine CPUfreq driver used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Remember to call cpufreq_put_driver when no longer needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * to avoid memory leakage, please.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) char *cpufreq_get_driver(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) void cpufreq_put_driver(char *ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* determine CPUfreq policy currently used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * Remember to call cpufreq_put_policy when no longer needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * to avoid memory leakage, please.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void cpufreq_put_policy(struct cpufreq_policy *policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* determine CPUfreq governors currently available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * may be modified by modprobe'ing or rmmod'ing other governors. Please
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * free allocated memory by calling cpufreq_put_available_governors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * after use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct cpufreq_available_governors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *cpufreq_get_available_governors(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void cpufreq_put_available_governors(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct cpufreq_available_governors *first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* determine CPU frequency states available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * Only present on _some_ ->target() cpufreq drivers. For information purposes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * only. Please free allocated memory by calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * cpufreq_put_frequencies after use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct cpufreq_available_frequencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *cpufreq_get_available_frequencies(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void cpufreq_put_available_frequencies(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct cpufreq_available_frequencies *first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct cpufreq_available_frequencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *cpufreq_get_boost_frequencies(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void cpufreq_put_boost_frequencies(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct cpufreq_available_frequencies *first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* determine affected CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * Remember to call cpufreq_put_affected_cpus when no longer needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * to avoid memory leakage, please.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* determine related CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Remember to call cpufreq_put_related_cpus when no longer needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * to avoid memory leakage, please.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* determine stats for cpufreq subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * This is not available in all kernel versions or configurations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) unsigned long long *total_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) void cpufreq_put_stats(struct cpufreq_stats *stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) unsigned long cpufreq_get_transitions(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* set new cpufreq policy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * Tries to set the passed policy as new policy as close as possible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * but results may differ depending e.g. on governors being available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* modify a policy by only changing min/max freq or governor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Does not check whether result is what was intended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* set a specific frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * Does only work if userspace governor can be used and no external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * interference (other calls to this function or to set/modify_policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * occurs. Also does not work on ->range() cpufreq drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int cpufreq_set_frequency(unsigned int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned long target_frequency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #ifdef __cplusplus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #endif /* _CPUFREQ_H */