]>
Commit | Line | Data |
---|---|---|
3fb4f7cd SP |
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)) | |
873e391f | 32 | #define BIT_ULL(nr) (1ULL << (nr)) |
3fb4f7cd SP |
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 | ||
645feeb2 SP |
73 | #define READ_PM_CONFIG 0x94 |
74 | #define WRITE_PM_CONFIG 0x95 | |
75 | #define PM_FEATURE 0x03 | |
76 | ||
062e4aac PB |
77 | #define DISP_FREQ_MULTIPLIER 100 |
78 | ||
7fd786df SP |
79 | #define MAX_PACKAGE_COUNT 8 |
80 | #define MAX_DIE_PER_PACKAGE 2 | |
81 | ||
850337ec ZR |
82 | /* Unified structure to specific a CPU or a Power Domain */ |
83 | struct isst_id { | |
84 | int cpu; | |
32d6ab45 ZR |
85 | int pkg; |
86 | int die; | |
850337ec ZR |
87 | }; |
88 | ||
3fb4f7cd SP |
89 | struct isst_clos_config { |
90 | int pkg_id; | |
91 | int die_id; | |
92 | unsigned char epp; | |
93 | unsigned char clos_prop_prio; | |
94 | unsigned char clos_min; | |
95 | unsigned char clos_max; | |
96 | unsigned char clos_desired; | |
97 | }; | |
98 | ||
99 | struct isst_fact_bucket_info { | |
100 | int high_priority_cores_count; | |
101 | int sse_trl; | |
102 | int avx_trl; | |
103 | int avx512_trl; | |
104 | }; | |
105 | ||
106 | struct isst_pbf_info { | |
107 | int pbf_acticated; | |
108 | int pbf_available; | |
109 | size_t core_cpumask_size; | |
110 | cpu_set_t *core_cpumask; | |
111 | int p1_high; | |
112 | int p1_low; | |
113 | int t_control; | |
114 | int t_prochot; | |
115 | int tdp; | |
116 | }; | |
117 | ||
118 | #define ISST_TRL_MAX_ACTIVE_CORES 8 | |
119 | #define ISST_FACT_MAX_BUCKETS 8 | |
120 | struct isst_fact_info { | |
121 | int lp_clipping_ratio_license_sse; | |
122 | int lp_clipping_ratio_license_avx2; | |
123 | int lp_clipping_ratio_license_avx512; | |
124 | struct isst_fact_bucket_info bucket_info[ISST_FACT_MAX_BUCKETS]; | |
125 | }; | |
126 | ||
127 | struct isst_pkg_ctdp_level_info { | |
128 | int processed; | |
129 | int control_cpu; | |
130 | int pkg_id; | |
131 | int die_id; | |
132 | int level; | |
133 | int fact_support; | |
134 | int pbf_support; | |
135 | int fact_enabled; | |
136 | int pbf_enabled; | |
645feeb2 SP |
137 | int sst_cp_support; |
138 | int sst_cp_enabled; | |
3fb4f7cd SP |
139 | int tdp_ratio; |
140 | int active; | |
141 | int tdp_control; | |
142 | int pkg_tdp; | |
143 | int pkg_min_power; | |
144 | int pkg_max_power; | |
145 | int fact; | |
146 | int t_proc_hot; | |
147 | int uncore_p0; | |
148 | int uncore_p1; | |
149 | int sse_p1; | |
150 | int avx2_p1; | |
151 | int avx512_p1; | |
152 | int mem_freq; | |
153 | size_t core_cpumask_size; | |
154 | cpu_set_t *core_cpumask; | |
155 | int cpu_count; | |
1233c7b9 | 156 | unsigned long long buckets_info; |
3fb4f7cd SP |
157 | int trl_sse_active_cores[ISST_TRL_MAX_ACTIVE_CORES]; |
158 | int trl_avx_active_cores[ISST_TRL_MAX_ACTIVE_CORES]; | |
159 | int trl_avx_512_active_cores[ISST_TRL_MAX_ACTIVE_CORES]; | |
160 | int kobj_bucket_index; | |
161 | int active_bucket; | |
162 | int fact_max_index; | |
163 | int fact_max_config; | |
164 | int pbf_found; | |
165 | int pbf_active; | |
166 | struct isst_pbf_info pbf_info; | |
167 | struct isst_fact_info fact_info; | |
168 | }; | |
169 | ||
170 | #define ISST_MAX_TDP_LEVELS (4 + 1) /* +1 for base config */ | |
171 | struct isst_pkg_ctdp { | |
172 | int locked; | |
173 | int version; | |
174 | int processed; | |
175 | int levels; | |
176 | int current_level; | |
177 | int enabled; | |
178 | struct isst_pkg_ctdp_level_info ctdp_level[ISST_MAX_TDP_LEVELS]; | |
179 | }; | |
180 | ||
181 | extern int get_topo_max_cpus(void); | |
182 | extern int get_cpu_count(int pkg_id, int die_id); | |
7566616f | 183 | extern int get_max_punit_core_id(int pkg_id, int die_id); |
3fb4f7cd SP |
184 | |
185 | /* Common interfaces */ | |
87e115b3 | 186 | FILE *get_output_file(void); |
3fb4f7cd SP |
187 | extern void debug_printf(const char *format, ...); |
188 | extern int out_format_is_json(void); | |
189 | extern int get_physical_package_id(int cpu); | |
190 | extern int get_physical_die_id(int cpu); | |
850337ec | 191 | extern void set_isst_id(struct isst_id *id, int cpu); |
3fb4f7cd SP |
192 | extern size_t alloc_cpu_set(cpu_set_t **cpu_set); |
193 | extern void free_cpu_set(cpu_set_t *cpu_set); | |
3fb4f7cd | 194 | extern int find_phy_core_num(int logical_cpu); |
850337ec | 195 | extern void set_cpu_mask_from_punit_coremask(struct isst_id *id, |
3fb4f7cd SP |
196 | unsigned long long core_mask, |
197 | size_t core_cpumask_size, | |
198 | cpu_set_t *core_cpumask, | |
199 | int *cpu_cnt); | |
200 | ||
201 | extern int isst_send_mbox_command(unsigned int cpu, unsigned char command, | |
202 | unsigned char sub_command, | |
203 | unsigned int write, | |
204 | unsigned int req_data, unsigned int *resp); | |
205 | ||
206 | extern int isst_send_msr_command(unsigned int cpu, unsigned int command, | |
207 | int write, unsigned long long *req_resp); | |
208 | ||
850337ec ZR |
209 | extern int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev); |
210 | extern int isst_get_ctdp_control(struct isst_id *id, int config_index, | |
1ba148ae | 211 | struct isst_pkg_ctdp_level_info *ctdp_level); |
850337ec | 212 | extern int isst_get_coremask_info(struct isst_id *id, int config_index, |
3c64c81a | 213 | struct isst_pkg_ctdp_level_info *ctdp_level); |
850337ec | 214 | extern int isst_get_process_ctdp(struct isst_id *id, int tdp_level, |
3fb4f7cd | 215 | struct isst_pkg_ctdp *pkg_dev); |
850337ec | 216 | extern void isst_get_process_ctdp_complete(struct isst_id *id, |
3fb4f7cd | 217 | struct isst_pkg_ctdp *pkg_dev); |
850337ec | 218 | extern void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level, |
3fb4f7cd | 219 | struct isst_pkg_ctdp *pkg_dev); |
850337ec | 220 | extern void isst_ctdp_display_core_info(struct isst_id *id, FILE *outf, char *prefix, |
3d1a8579 | 221 | unsigned int val, char *str0, char *str1); |
3fb4f7cd SP |
222 | extern void isst_ctdp_display_information_start(FILE *outf); |
223 | extern void isst_ctdp_display_information_end(FILE *outf); | |
850337ec | 224 | extern void isst_pbf_display_information(struct isst_id *id, FILE *outf, int level, |
3fb4f7cd | 225 | struct isst_pbf_info *info); |
850337ec ZR |
226 | extern int isst_set_tdp_level(struct isst_id *id, int tdp_level); |
227 | extern int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable); | |
228 | extern int isst_get_pbf_info(struct isst_id *id, int level, | |
3fb4f7cd SP |
229 | struct isst_pbf_info *pbf_info); |
230 | extern void isst_get_pbf_info_complete(struct isst_pbf_info *pbf_info); | |
850337ec | 231 | extern int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket, |
3fb4f7cd | 232 | struct isst_fact_info *fact_info); |
850337ec | 233 | extern int isst_get_fact_bucket_info(struct isst_id *id, int level, |
3fb4f7cd | 234 | struct isst_fact_bucket_info *bucket_info); |
850337ec | 235 | extern void isst_fact_display_information(struct isst_id *id, FILE *outf, int level, |
3fb4f7cd SP |
236 | int fact_bucket, int fact_avx, |
237 | struct isst_fact_info *fact_info); | |
850337ec ZR |
238 | extern int isst_set_trl(struct isst_id *id, unsigned long long trl); |
239 | extern int isst_get_trl(struct isst_id *id, unsigned long long *trl); | |
240 | extern int isst_set_trl_from_current_tdp(struct isst_id *id, unsigned long long trl); | |
241 | extern int isst_get_config_tdp_lock_status(struct isst_id *id); | |
3fb4f7cd | 242 | |
850337ec ZR |
243 | extern int isst_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type); |
244 | extern int isst_pm_get_clos(struct isst_id *id, int clos, | |
3fb4f7cd | 245 | struct isst_clos_config *clos_config); |
850337ec | 246 | extern int isst_set_clos(struct isst_id *id, int clos, |
3fb4f7cd | 247 | struct isst_clos_config *clos_config); |
850337ec ZR |
248 | extern int isst_clos_associate(struct isst_id *id, int clos); |
249 | extern int isst_clos_get_assoc_status(struct isst_id *id, int *clos_id); | |
250 | extern void isst_clos_display_information(struct isst_id *id, FILE *outf, int clos, | |
3fb4f7cd | 251 | struct isst_clos_config *clos_config); |
850337ec | 252 | extern void isst_clos_display_assoc_information(struct isst_id *id, FILE *outf, int clos); |
3fb4f7cd | 253 | |
850337ec | 254 | extern void isst_display_result(struct isst_id *id, FILE *outf, char *feature, char *cmd, |
3fb4f7cd | 255 | int result); |
188afed9 | 256 | |
850337ec ZR |
257 | extern int isst_clos_get_clos_information(struct isst_id *id, int *enable, int *type); |
258 | extern void isst_clos_display_clos_information(struct isst_id *id, FILE *outf, | |
143ad322 SP |
259 | int clos_enable, int type, |
260 | int state, int cap); | |
062e4aac | 261 | extern int is_clx_n_platform(void); |
7af5a95b | 262 | extern int get_cpufreq_base_freq(int cpu); |
850337ec | 263 | extern int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap); |
87e115b3 | 264 | extern void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg); |
07f262d8 | 265 | extern int is_skx_based_platform(void); |
159f130f SP |
266 | extern int is_spr_platform(void); |
267 | extern int is_icx_platform(void); | |
850337ec | 268 | extern void isst_trl_display_information(struct isst_id *id, FILE *outf, unsigned long long trl); |
7fd786df SP |
269 | |
270 | extern void set_cpu_online_offline(int cpu, int state); | |
850337ec | 271 | extern void for_each_online_package_in_set(void (*callback)(struct isst_id *, void *, void *, |
7fd786df SP |
272 | void *, void *), |
273 | void *arg1, void *arg2, void *arg3, | |
274 | void *arg4); | |
275 | extern int isst_daemon(int debug_mode, int poll_interval, int no_daemon); | |
850337ec | 276 | extern void process_level_change(struct isst_id *id); |
7d440da0 SP |
277 | extern int hfi_main(void); |
278 | extern void hfi_exit(void); | |
3fb4f7cd | 279 | #endif |