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 137int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy); 138 139int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq); 140 141int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq); 142 143int cpufreq_modify_policy_governor(unsigned int cpu, char *governor); 144 145int cpufreq_set_frequency(unsigned int cpu, 146 unsigned long target_frequency); 147 148unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, 149 const char **table, 150 unsigned int index, 151 unsigned int size); 152 153/* 154 * cpuidle.h 155 */ 156 157int cpuidle_is_state_disabled(unsigned int cpu, 158 unsigned int idlestate); 159int cpuidle_state_disable(unsigned int cpu, unsigned int idlestate, 160 unsigned int disable); 161unsigned long cpuidle_state_latency(unsigned int cpu, 162 unsigned int idlestate); 163unsigned long cpuidle_state_usage(unsigned int cpu, 164 unsigned int idlestate); 165unsigned long long cpuidle_state_time(unsigned int cpu, 166 unsigned int idlestate); 167char *cpuidle_state_name(unsigned int cpu, 168 unsigned int idlestate); 169char *cpuidle_state_desc(unsigned int cpu, 170 unsigned int idlestate); 171unsigned int cpuidle_state_count(unsigned int cpu); 172 173char *cpuidle_get_governor(void); 174 175char *cpuidle_get_driver(void); 176 177/* 178 * cpupower.h 179 */ 180 181struct cpupower_topology { 182 /* Amount of CPU cores, packages and threads per core in the system */ 183 unsigned int cores; 184 unsigned int pkgs; 185 unsigned int threads; /* per core */ 186 187 /* Array gets mallocated with cores entries, holding per core info */ 188 struct cpuid_core_info *core_info; 189}; 190 191struct cpuid_core_info { 192 int pkg; 193 int core; 194 int cpu; 195 196 /* flags */ 197 unsigned int is_online:1; 198}; 199 200int get_cpu_topology(struct cpupower_topology *cpu_top); 201 202void cpu_topology_release(struct cpupower_topology cpu_top); 203 204int cpupower_is_cpu_online(unsigned int cpu); 205 206/* 207 * powercap.h 208 */ 209 210struct powercap_zone { 211 char name[MAX_LINE_LEN]; 212 /* 213 * sys_name relative to PATH_TO_POWERCAP, 214 * do not forget the / in between 215 */ 216 char sys_name[SYSFS_PATH_MAX]; 217 int tree_depth; 218 struct powercap_zone *parent; 219 struct powercap_zone *children[POWERCAP_MAX_CHILD_ZONES]; 220 /* More possible caps or attributes to be added? */ 221 uint32_t has_power_uw:1, 222 has_energy_uj:1; 223 224}; 225 226int powercap_walk_zones(struct powercap_zone *zone, 227 int (*f)(struct powercap_zone *zone)); 228 229struct powercap_zone *powercap_init_zones(void); 230 231int powercap_get_enabled(int *mode); 232 233int powercap_set_enabled(int mode); 234 235int powercap_get_driver(char *driver, int buflen); 236 237int powercap_get_max_energy_range_uj(struct powercap_zone *zone, uint64_t *val); 238 239int powercap_get_energy_uj(struct powercap_zone *zone, uint64_t *val); 240 241int powercap_get_max_power_range_uw(struct powercap_zone *zone, uint64_t *val); 242 243int powercap_get_power_uw(struct powercap_zone *zone, uint64_t *val); 244 245int powercap_zone_get_enabled(struct powercap_zone *zone, int *mode); 246 247int powercap_zone_set_enabled(struct powercap_zone *zone, int mode); 248