/* SPDX-License-Identifier: GPL-2.0-only */1/*2* cpufreq.h - definitions for libcpufreq3*4* Copyright (C) 2004-2009 Dominik Brodowski <[email protected]>5*/67#ifndef __CPUPOWER_CPUFREQ_H__8#define __CPUPOWER_CPUFREQ_H__910struct cpufreq_policy {11unsigned long min;12unsigned long max;13char *governor;14};1516struct cpufreq_available_governors {17char *governor;18struct cpufreq_available_governors *next;19struct cpufreq_available_governors *first;20};2122struct cpufreq_available_frequencies {23unsigned long frequency;24struct cpufreq_available_frequencies *next;25struct cpufreq_available_frequencies *first;26};272829struct cpufreq_affected_cpus {30unsigned int cpu;31struct cpufreq_affected_cpus *next;32struct cpufreq_affected_cpus *first;33};3435struct cpufreq_stats {36unsigned long frequency;37unsigned long long time_in_state;38struct cpufreq_stats *next;39struct cpufreq_stats *first;40};41424344#ifdef __cplusplus45extern "C" {46#endif4748/* determine current CPU frequency49* - _kernel variant means kernel's opinion of CPU frequency50* - _hardware variant means actual hardware CPU frequency,51* which is only available to root.52*53* returns 0 on failure, else frequency in kHz.54*/5556unsigned long cpufreq_get_freq_kernel(unsigned int cpu);5758unsigned long cpufreq_get_freq_hardware(unsigned int cpu);5960#define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu);616263/* determine CPU transition latency64*65* returns 0 on failure, else transition latency in 10^(-9) s = nanoseconds66*/67unsigned long cpufreq_get_transition_latency(unsigned int cpu);686970/* determine energy performance preference71*72* returns NULL on failure, else the string that represents the energy performance73* preference requested.74*/75char *cpufreq_get_energy_performance_preference(unsigned int cpu);76void cpufreq_put_energy_performance_preference(char *ptr);7778/* determine hardware CPU frequency limits79*80* These may be limited further by thermal, energy or other81* considerations by cpufreq policy notifiers in the kernel.82*/8384int cpufreq_get_hardware_limits(unsigned int cpu,85unsigned long *min,86unsigned long *max);878889/* determine CPUfreq driver used90*91* Remember to call cpufreq_put_driver when no longer needed92* to avoid memory leakage, please.93*/9495char *cpufreq_get_driver(unsigned int cpu);9697void cpufreq_put_driver(char *ptr);9899100/* determine CPUfreq policy currently used101*102* Remember to call cpufreq_put_policy when no longer needed103* to avoid memory leakage, please.104*/105106107struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);108109void cpufreq_put_policy(struct cpufreq_policy *policy);110111112/* determine CPUfreq governors currently available113*114* may be modified by modprobe'ing or rmmod'ing other governors. Please115* free allocated memory by calling cpufreq_put_available_governors116* after use.117*/118119120struct cpufreq_available_governors121*cpufreq_get_available_governors(unsigned int cpu);122123void cpufreq_put_available_governors(124struct cpufreq_available_governors *first);125126127/* determine CPU frequency states available128*129* Only present on _some_ ->target() cpufreq drivers. For information purposes130* only. Please free allocated memory by calling131* cpufreq_put_frequencies after use.132*/133134struct cpufreq_available_frequencies135*cpufreq_get_available_frequencies(unsigned int cpu);136137void cpufreq_put_available_frequencies(138struct cpufreq_available_frequencies *first);139140struct cpufreq_available_frequencies141*cpufreq_get_boost_frequencies(unsigned int cpu);142143void cpufreq_put_boost_frequencies(144struct cpufreq_available_frequencies *first);145146147/* determine affected CPUs148*149* Remember to call cpufreq_put_affected_cpus when no longer needed150* to avoid memory leakage, please.151*/152153struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned154int cpu);155156void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);157158159/* determine related CPUs160*161* Remember to call cpufreq_put_related_cpus when no longer needed162* to avoid memory leakage, please.163*/164165struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned166int cpu);167168void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);169170171/* determine stats for cpufreq subsystem172*173* This is not available in all kernel versions or configurations.174*/175176struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,177unsigned long long *total_time);178179void cpufreq_put_stats(struct cpufreq_stats *stats);180181unsigned long cpufreq_get_transitions(unsigned int cpu);182183184/* set new cpufreq policy185*186* Tries to set the passed policy as new policy as close as possible,187* but results may differ depending e.g. on governors being available.188*/189190int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);191192193/* modify a policy by only changing min/max freq or governor194*195* Does not check whether result is what was intended.196*/197198int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq);199int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq);200int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);201202203/* set a specific frequency204*205* Does only work if userspace governor can be used and no external206* interference (other calls to this function or to set/modify_policy)207* occurs. Also does not work on ->range() cpufreq drivers.208*/209210int cpufreq_set_frequency(unsigned int cpu,211unsigned long target_frequency);212213/*214* get the sysfs value from specific table215*216* Read the value with the sysfs file name from specific table. Does217* only work if the cpufreq driver has the specific sysfs interfaces.218*/219220unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,221const char **table,222unsigned int index,223unsigned int size);224225#ifdef __cplusplus226}227#endif228229#endif /* _CPUFREQ_H */230231232