1/* SPDX-License-Identifier: GPL-2.0-only */ 2 3%module raw_pylibcpupower 4%{ 5#include "../../lib/cpupower_intern.h" 6#include "../../lib/acpi_cppc.h" 7#include "../../lib/cpufreq.h" 8#include "../../lib/cpuidle.h" 9#include "../../lib/cpupower.h" 10#include "../../lib/powercap.h" 11%} 12 13/* 14 * cpupower_intern.h 15 */ 16 17#define PATH_TO_CPU "/sys/devices/system/cpu/" 18#define MAX_LINE_LEN 4096 19#define SYSFS_PATH_MAX 255 20 21int is_valid_path(const char *path); 22 23unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen); 24 25unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen); 26 27/* 28 * acpi_cppc.h 29 */ 30 31enum acpi_cppc_value { 32 HIGHEST_PERF, 33 LOWEST_PERF, 34 NOMINAL_PERF, 35 LOWEST_NONLINEAR_PERF, 36 LOWEST_FREQ, 37 NOMINAL_FREQ, 38 REFERENCE_PERF, 39 WRAPAROUND_TIME, 40 MAX_CPPC_VALUE_FILES 41}; 42 43unsigned long acpi_cppc_get_data(unsigned int cpu, 44 enum acpi_cppc_value which); 45 46/* 47 * cpufreq.h 48 */ 49 50struct cpufreq_policy { 51 unsigned long min; 52 unsigned long max; 53 char *governor; 54}; 55 56struct cpufreq_available_governors { 57 char *governor; 58 struct cpufreq_available_governors *next; 59 struct cpufreq_available_governors *first; 60}; 61 62struct cpufreq_available_frequencies { 63 unsigned long frequency; 64 struct cpufreq_available_frequencies *next; 65 struct cpufreq_available_frequencies *first; 66}; 67 68 69struct cpufreq_affected_cpus { 70 unsigned int cpu; 71 struct cpufreq_affected_cpus *next; 72 struct cpufreq_affected_cpus *first; 73}; 74 75struct cpufreq_stats { 76 unsigned long frequency; 77 unsigned long long time_in_state; 78 struct cpufreq_stats *next; 79 struct cpufreq_stats *first; 80}; 81 82unsigned long cpufreq_get_freq_kernel(unsigned int cpu); 83 84unsigned long cpufreq_get_freq_hardware(unsigned int cpu); 85 86#define cpufreq_get(cpu) cpufreq_get_freq_kernel(cpu); 87 88unsigned long cpufreq_get_transition_latency(unsigned int cpu); 89 90int cpufreq_get_hardware_limits(unsigned int cpu, 91 unsigned long *min, 92 unsigned long *max); 93 94char *cpufreq_get_driver(unsigned int cpu); 95 96void cpufreq_put_driver(char *ptr); 97 98struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu); 99 100void cpufreq_put_policy(struct cpufreq_policy *policy); 101 102struct cpufreq_available_governors 103*cpufreq_get_available_governors(unsigned int cpu); 104 105void cpufreq_put_available_governors( 106 struct cpufreq_available_governors *first); 107 108struct cpufreq_available_frequencies 109*cpufreq_get_available_frequencies(unsigned int cpu); 110 111void cpufreq_put_available_frequencies( 112 struct cpufreq_available_frequencies *first); 113 114struct cpufreq_available_frequencies 115*cpufreq_get_boost_frequencies(unsigned int cpu); 116 117void cpufreq_put_boost_frequencies( 118 struct cpufreq_available_frequencies *first); 119 120struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned 121 int cpu); 122 123void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first); 124 125struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned 126 int cpu); 127 128void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first); 129 130struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu, 131 unsigned long long *total_time); 132 133void cpufreq_put_stats(struct cpufreq_stats *stats); 134 135unsigned long cpufreq_get_transitions(unsigned int cpu); 136 137char *cpufreq_get_energy_performance_preference(unsigned int cpu); 138void cpufreq_put_energy_performance_preference(char *ptr); 139 140int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy); 141 142int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq); 143 144int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq); 145 146int cpufreq_modify_policy_governor(unsigned int cpu, char *governor); 147 148int cpufreq_set_frequency(unsigned int cpu, 149 unsigned long target_frequency); 150 151unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, 152 const char **table, 153 unsigned int index, 154 unsigned int size); 155 156/* 157 * cpuidle.h 158 */ 159 160int cpuidle_is_state_disabled(unsigned int cpu, 161 unsigned int idlestate); 162int cpuidle_state_disable(unsigned int cpu, unsigned int idlestate, 163 unsigned int disable); 164unsigned long cpuidle_state_latency(unsigned int cpu, 165 unsigned int idlestate); 166unsigned long cpuidle_state_residency(unsigned int cpu, 167 unsigned int idlestate); 168unsigned long cpuidle_state_usage(unsigned int cpu, 169 unsigned int idlestate); 170unsigned long long cpuidle_state_time(unsigned int cpu, 171 unsigned int idlestate); 172char *cpuidle_state_name(unsigned int cpu, 173 unsigned int idlestate); 174char *cpuidle_state_desc(unsigned int cpu, 175 unsigned int idlestate); 176unsigned int cpuidle_state_count(unsigned int cpu); 177 178char *cpuidle_get_governor(void); 179 180char *cpuidle_get_driver(void); 181 182/* 183 * cpupower.h 184 */ 185 186struct cpupower_topology { 187 /* Amount of CPU cores, packages and threads per core in the system */ 188 unsigned int cores; 189 unsigned int pkgs; 190 unsigned int threads; /* per core */ 191 192 /* Array gets mallocated with cores entries, holding per core info */ 193 struct cpuid_core_info *core_info; 194}; 195 196struct cpuid_core_info { 197 int pkg; 198 int core; 199 int cpu; 200 201 /* flags */ 202 unsigned int is_online:1; 203}; 204 205int get_cpu_topology(struct cpupower_topology *cpu_top); 206 207void cpu_topology_release(struct cpupower_topology cpu_top); 208 209int cpupower_is_cpu_online(unsigned int cpu); 210 211/* 212 * powercap.h 213 */ 214 215struct powercap_zone { 216 char name[MAX_LINE_LEN]; 217 /* 218 * sys_name relative to PATH_TO_POWERCAP, 219 * do not forget the / in between 220 */ 221 char sys_name[SYSFS_PATH_MAX]; 222 int tree_depth; 223 struct powercap_zone *parent; 224 struct powercap_zone *children[POWERCAP_MAX_CHILD_ZONES]; 225 /* More possible caps or attributes to be added? */ 226 uint32_t has_power_uw:1, 227 has_energy_uj:1; 228 229}; 230 231int powercap_walk_zones(struct powercap_zone *zone, 232 int (*f)(struct powercap_zone *zone)); 233 234struct powercap_zone *powercap_init_zones(void); 235 236int powercap_get_enabled(int *mode); 237 238int powercap_set_enabled(int mode); 239 240int powercap_get_driver(char *driver, int buflen); 241 242int powercap_get_max_energy_range_uj(struct powercap_zone *zone, uint64_t *val); 243 244int powercap_get_energy_uj(struct powercap_zone *zone, uint64_t *val); 245 246int powercap_get_max_power_range_uw(struct powercap_zone *zone, uint64_t *val); 247 248int powercap_get_power_uw(struct powercap_zone *zone, uint64_t *val); 249 250int powercap_zone_get_enabled(struct powercap_zone *zone, int *mode); 251 252int powercap_zone_set_enabled(struct powercap_zone *zone, int mode); 253