1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Intel Speed Select -- Enumerate and control features 4 * Copyright (c) 2019 Intel Corporation. 5 */ 6 7 #ifndef _ISST_H_ 8 #define _ISST_H_ 9 10 #include <stdio.h> 11 #include <unistd.h> 12 #include <sys/types.h> 13 #include <sched.h> 14 #include <sys/stat.h> 15 #include <sys/resource.h> 16 #include <getopt.h> 17 #include <err.h> 18 #include <fcntl.h> 19 #include <signal.h> 20 #include <sys/time.h> 21 #include <limits.h> 22 #include <stdlib.h> 23 #include <string.h> 24 #include <cpuid.h> 25 #include <dirent.h> 26 #include <errno.h> 27 28 #include <stdarg.h> 29 #include <sys/ioctl.h> 30 31 #define BIT(x) (1 << (x)) 32 #define BIT_ULL(nr) (1ULL << (nr)) 33 #define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h)))) 34 #define GENMASK_ULL(h, l) \ 35 (((~0ULL) << (l)) & (~0ULL >> (sizeof(long long) * 8 - 1 - (h)))) 36 37 #define CONFIG_TDP 0x7f 38 #define CONFIG_TDP_GET_LEVELS_INFO 0x00 39 #define CONFIG_TDP_GET_TDP_CONTROL 0x01 40 #define CONFIG_TDP_SET_TDP_CONTROL 0x02 41 #define CONFIG_TDP_GET_TDP_INFO 0x03 42 #define CONFIG_TDP_GET_PWR_INFO 0x04 43 #define CONFIG_TDP_GET_TJMAX_INFO 0x05 44 #define CONFIG_TDP_GET_CORE_MASK 0x06 45 #define CONFIG_TDP_GET_TURBO_LIMIT_RATIOS 0x07 46 #define CONFIG_TDP_SET_LEVEL 0x08 47 #define CONFIG_TDP_GET_UNCORE_P0_P1_INFO 0X09 48 #define CONFIG_TDP_GET_P1_INFO 0x0a 49 #define CONFIG_TDP_GET_MEM_FREQ 0x0b 50 51 #define CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES 0x10 52 #define CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS 0x11 53 #define CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO 0x12 54 55 #define CONFIG_TDP_PBF_GET_CORE_MASK_INFO 0x20 56 #define CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO 0x21 57 #define CONFIG_TDP_PBF_GET_TJ_MAX_INFO 0x22 58 #define CONFIG_TDP_PBF_GET_TDP_INFO 0X23 59 60 #define CONFIG_CLOS 0xd0 61 #define CLOS_PQR_ASSOC 0x00 62 #define CLOS_PM_CLOS 0x01 63 #define CLOS_PM_QOS_CONFIG 0x02 64 #define CLOS_STATUS 0x03 65 66 #define MBOX_CMD_WRITE_BIT 0x08 67 68 #define PM_QOS_INFO_OFFSET 0x00 69 #define PM_QOS_CONFIG_OFFSET 0x04 70 #define PM_CLOS_OFFSET 0x08 71 #define PQR_ASSOC_OFFSET 0x20 72 73 #define READ_PM_CONFIG 0x94 74 #define WRITE_PM_CONFIG 0x95 75 #define PM_FEATURE 0x03 76 77 #define DISP_FREQ_MULTIPLIER 100 78 79 #define MAX_PACKAGE_COUNT 8 80 #define MAX_DIE_PER_PACKAGE 2 81 82 struct isst_clos_config { 83 int pkg_id; 84 int die_id; 85 unsigned char epp; 86 unsigned char clos_prop_prio; 87 unsigned char clos_min; 88 unsigned char clos_max; 89 unsigned char clos_desired; 90 }; 91 92 struct isst_fact_bucket_info { 93 int high_priority_cores_count; 94 int sse_trl; 95 int avx_trl; 96 int avx512_trl; 97 }; 98 99 struct isst_pbf_info { 100 int pbf_acticated; 101 int pbf_available; 102 size_t core_cpumask_size; 103 cpu_set_t *core_cpumask; 104 int p1_high; 105 int p1_low; 106 int t_control; 107 int t_prochot; 108 int tdp; 109 }; 110 111 #define ISST_TRL_MAX_ACTIVE_CORES 8 112 #define ISST_FACT_MAX_BUCKETS 8 113 struct isst_fact_info { 114 int lp_clipping_ratio_license_sse; 115 int lp_clipping_ratio_license_avx2; 116 int lp_clipping_ratio_license_avx512; 117 struct isst_fact_bucket_info bucket_info[ISST_FACT_MAX_BUCKETS]; 118 }; 119 120 struct isst_pkg_ctdp_level_info { 121 int processed; 122 int control_cpu; 123 int pkg_id; 124 int die_id; 125 int level; 126 int fact_support; 127 int pbf_support; 128 int fact_enabled; 129 int pbf_enabled; 130 int sst_cp_support; 131 int sst_cp_enabled; 132 int tdp_ratio; 133 int active; 134 int tdp_control; 135 int pkg_tdp; 136 int pkg_min_power; 137 int pkg_max_power; 138 int fact; 139 int t_proc_hot; 140 int uncore_p0; 141 int uncore_p1; 142 int sse_p1; 143 int avx2_p1; 144 int avx512_p1; 145 int mem_freq; 146 size_t core_cpumask_size; 147 cpu_set_t *core_cpumask; 148 int cpu_count; 149 unsigned long long buckets_info; 150 int trl_sse_active_cores[ISST_TRL_MAX_ACTIVE_CORES]; 151 int trl_avx_active_cores[ISST_TRL_MAX_ACTIVE_CORES]; 152 int trl_avx_512_active_cores[ISST_TRL_MAX_ACTIVE_CORES]; 153 int kobj_bucket_index; 154 int active_bucket; 155 int fact_max_index; 156 int fact_max_config; 157 int pbf_found; 158 int pbf_active; 159 struct isst_pbf_info pbf_info; 160 struct isst_fact_info fact_info; 161 }; 162 163 #define ISST_MAX_TDP_LEVELS (4 + 1) /* +1 for base config */ 164 struct isst_pkg_ctdp { 165 int locked; 166 int version; 167 int processed; 168 int levels; 169 int current_level; 170 int enabled; 171 struct isst_pkg_ctdp_level_info ctdp_level[ISST_MAX_TDP_LEVELS]; 172 }; 173 174 extern int get_topo_max_cpus(void); 175 extern int get_cpu_count(int pkg_id, int die_id); 176 extern int get_max_punit_core_id(int pkg_id, int die_id); 177 178 /* Common interfaces */ 179 FILE *get_output_file(void); 180 extern void debug_printf(const char *format, ...); 181 extern int out_format_is_json(void); 182 extern int get_physical_package_id(int cpu); 183 extern int get_physical_die_id(int cpu); 184 extern size_t alloc_cpu_set(cpu_set_t **cpu_set); 185 extern void free_cpu_set(cpu_set_t *cpu_set); 186 extern int find_logical_cpu(int pkg_id, int die_id, int phy_cpu); 187 extern int find_phy_cpu_num(int logical_cpu); 188 extern int find_phy_core_num(int logical_cpu); 189 extern void set_cpu_mask_from_punit_coremask(int cpu, 190 unsigned long long core_mask, 191 size_t core_cpumask_size, 192 cpu_set_t *core_cpumask, 193 int *cpu_cnt); 194 195 extern int isst_send_mbox_command(unsigned int cpu, unsigned char command, 196 unsigned char sub_command, 197 unsigned int write, 198 unsigned int req_data, unsigned int *resp); 199 200 extern int isst_send_msr_command(unsigned int cpu, unsigned int command, 201 int write, unsigned long long *req_resp); 202 203 extern int isst_get_ctdp_levels(int cpu, struct isst_pkg_ctdp *pkg_dev); 204 extern int isst_get_ctdp_control(int cpu, int config_index, 205 struct isst_pkg_ctdp_level_info *ctdp_level); 206 extern int isst_get_coremask_info(int cpu, int config_index, 207 struct isst_pkg_ctdp_level_info *ctdp_level); 208 extern int isst_get_process_ctdp(int cpu, int tdp_level, 209 struct isst_pkg_ctdp *pkg_dev); 210 extern void isst_get_process_ctdp_complete(int cpu, 211 struct isst_pkg_ctdp *pkg_dev); 212 extern void isst_ctdp_display_information(int cpu, FILE *outf, int tdp_level, 213 struct isst_pkg_ctdp *pkg_dev); 214 extern void isst_ctdp_display_core_info(int cpu, FILE *outf, char *prefix, 215 unsigned int val, char *str0, char *str1); 216 extern void isst_ctdp_display_information_start(FILE *outf); 217 extern void isst_ctdp_display_information_end(FILE *outf); 218 extern void isst_pbf_display_information(int cpu, FILE *outf, int level, 219 struct isst_pbf_info *info); 220 extern int isst_set_tdp_level(int cpu, int tdp_level); 221 extern int isst_set_tdp_level_msr(int cpu, int tdp_level); 222 extern int isst_set_pbf_fact_status(int cpu, int pbf, int enable); 223 extern int isst_get_pbf_info(int cpu, int level, 224 struct isst_pbf_info *pbf_info); 225 extern void isst_get_pbf_info_complete(struct isst_pbf_info *pbf_info); 226 extern int isst_get_fact_info(int cpu, int level, int fact_bucket, 227 struct isst_fact_info *fact_info); 228 extern int isst_get_fact_bucket_info(int cpu, int level, 229 struct isst_fact_bucket_info *bucket_info); 230 extern void isst_fact_display_information(int cpu, FILE *outf, int level, 231 int fact_bucket, int fact_avx, 232 struct isst_fact_info *fact_info); 233 extern int isst_set_trl(int cpu, unsigned long long trl); 234 extern int isst_get_trl(int cpu, unsigned long long *trl); 235 extern int isst_set_trl_from_current_tdp(int cpu, unsigned long long trl); 236 extern int isst_get_config_tdp_lock_status(int cpu); 237 238 extern int isst_pm_qos_config(int cpu, int enable_clos, int priority_type); 239 extern int isst_pm_get_clos(int cpu, int clos, 240 struct isst_clos_config *clos_config); 241 extern int isst_set_clos(int cpu, int clos, 242 struct isst_clos_config *clos_config); 243 extern int isst_clos_associate(int cpu, int clos); 244 extern int isst_clos_get_assoc_status(int cpu, int *clos_id); 245 extern void isst_clos_display_information(int cpu, FILE *outf, int clos, 246 struct isst_clos_config *clos_config); 247 extern void isst_clos_display_assoc_information(int cpu, FILE *outf, int clos); 248 extern int isst_read_reg(unsigned short reg, unsigned int *val); 249 extern int isst_write_reg(int reg, unsigned int val); 250 251 extern void isst_display_result(int cpu, FILE *outf, char *feature, char *cmd, 252 int result); 253 254 extern int isst_clos_get_clos_information(int cpu, int *enable, int *type); 255 extern void isst_clos_display_clos_information(int cpu, FILE *outf, 256 int clos_enable, int type, 257 int state, int cap); 258 extern int is_clx_n_platform(void); 259 extern int get_cpufreq_base_freq(int cpu); 260 extern int isst_read_pm_config(int cpu, int *cp_state, int *cp_cap); 261 extern void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg); 262 extern int is_skx_based_platform(void); 263 extern int is_spr_platform(void); 264 extern int is_icx_platform(void); 265 extern void isst_trl_display_information(int cpu, FILE *outf, unsigned long long trl); 266 267 extern void set_cpu_online_offline(int cpu, int state); 268 extern void for_each_online_package_in_set(void (*callback)(int, void *, void *, 269 void *, void *), 270 void *arg1, void *arg2, void *arg3, 271 void *arg4); 272 extern int isst_daemon(int debug_mode, int poll_interval, int no_daemon); 273 extern void process_level_change(int cpu); 274 extern int hfi_main(void); 275 extern void hfi_exit(void); 276 #endif 277