1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __ACPI_PROCESSOR_H 3 #define __ACPI_PROCESSOR_H 4 5 #include <linux/cpu.h> 6 #include <linux/cpufreq.h> 7 #include <linux/pm_qos.h> 8 #include <linux/printk.h> 9 #include <linux/sched.h> 10 #include <linux/smp.h> 11 #include <linux/thermal.h> 12 #include <linux/types.h> 13 #include <linux/workqueue.h> 14 15 #include <asm/acpi.h> 16 17 #define ACPI_PROCESSOR_DEVICE_HID "ACPI0007" 18 #define ACPI_PROCESSOR_CONTAINER_HID "ACPI0010" 19 20 #define ACPI_PROCESSOR_BUSY_METRIC 10 21 22 #define ACPI_PROCESSOR_MAX_POWER 8 23 #define ACPI_PROCESSOR_MAX_C2_LATENCY 100 24 #define ACPI_PROCESSOR_MAX_C3_LATENCY 1000 25 26 #define ACPI_PROCESSOR_MAX_THROTTLING 16 27 #define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */ 28 #define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4 29 30 #define ACPI_PDC_REVISION_ID 0x1 31 32 #define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */ 33 #define ACPI_PSD_REV0_ENTRIES 5 34 35 #define ACPI_TSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */ 36 #define ACPI_TSD_REV0_ENTRIES 5 37 /* 38 * Types of coordination defined in ACPI 3.0. Same macros can be used across 39 * P, C and T states 40 */ 41 #define DOMAIN_COORD_TYPE_SW_ALL 0xfc 42 #define DOMAIN_COORD_TYPE_SW_ANY 0xfd 43 #define DOMAIN_COORD_TYPE_HW_ALL 0xfe 44 45 #define ACPI_CSTATE_SYSTEMIO 0 46 #define ACPI_CSTATE_FFH 1 47 #define ACPI_CSTATE_HALT 2 48 #define ACPI_CSTATE_INTEGER 3 49 50 #define ACPI_CX_DESC_LEN 32 51 52 /* Power Management */ 53 54 struct acpi_processor_cx; 55 56 struct acpi_power_register { 57 u8 descriptor; 58 u16 length; 59 u8 space_id; 60 u8 bit_width; 61 u8 bit_offset; 62 u8 access_size; 63 u64 address; 64 } __packed; 65 66 struct acpi_processor_cx { 67 u8 valid; 68 u8 type; 69 u32 address; 70 u8 entry_method; 71 u8 index; 72 u32 latency; 73 u8 bm_sts_skip; 74 char desc[ACPI_CX_DESC_LEN]; 75 }; 76 77 struct acpi_lpi_state { 78 u32 min_residency; 79 u32 wake_latency; /* worst case */ 80 u32 flags; 81 u32 arch_flags; 82 u32 res_cnt_freq; 83 u32 enable_parent_state; 84 u64 address; 85 u8 index; 86 u8 entry_method; 87 char desc[ACPI_CX_DESC_LEN]; 88 }; 89 90 struct acpi_processor_power { 91 int count; 92 union { 93 struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER]; 94 struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER]; 95 }; 96 int timer_broadcast_on_state; 97 }; 98 99 /* Performance Management */ 100 101 struct acpi_psd_package { 102 u64 num_entries; 103 u64 revision; 104 u64 domain; 105 u64 coord_type; 106 u64 num_processors; 107 } __packed; 108 109 struct acpi_pct_register { 110 u8 descriptor; 111 u16 length; 112 u8 space_id; 113 u8 bit_width; 114 u8 bit_offset; 115 u8 reserved; 116 u64 address; 117 } __packed; 118 119 struct acpi_processor_px { 120 u64 core_frequency; /* megahertz */ 121 u64 power; /* milliWatts */ 122 u64 transition_latency; /* microseconds */ 123 u64 bus_master_latency; /* microseconds */ 124 u64 control; /* control value */ 125 u64 status; /* success indicator */ 126 }; 127 128 struct acpi_processor_performance { 129 unsigned int state; 130 unsigned int platform_limit; 131 struct acpi_pct_register control_register; 132 struct acpi_pct_register status_register; 133 unsigned int state_count; 134 struct acpi_processor_px *states; 135 struct acpi_psd_package domain_info; 136 cpumask_var_t shared_cpu_map; 137 unsigned int shared_type; 138 }; 139 140 /* Throttling Control */ 141 142 struct acpi_tsd_package { 143 u64 num_entries; 144 u64 revision; 145 u64 domain; 146 u64 coord_type; 147 u64 num_processors; 148 } __packed; 149 150 struct acpi_ptc_register { 151 u8 descriptor; 152 u16 length; 153 u8 space_id; 154 u8 bit_width; 155 u8 bit_offset; 156 u8 reserved; 157 u64 address; 158 } __packed; 159 160 struct acpi_processor_tx_tss { 161 u64 freqpercentage; /* */ 162 u64 power; /* milliWatts */ 163 u64 transition_latency; /* microseconds */ 164 u64 control; /* control value */ 165 u64 status; /* success indicator */ 166 }; 167 struct acpi_processor_tx { 168 u16 power; 169 u16 performance; 170 }; 171 172 struct acpi_processor; 173 struct acpi_processor_throttling { 174 unsigned int state; 175 unsigned int platform_limit; 176 struct acpi_pct_register control_register; 177 struct acpi_pct_register status_register; 178 unsigned int state_count; 179 struct acpi_processor_tx_tss *states_tss; 180 struct acpi_tsd_package domain_info; 181 cpumask_var_t shared_cpu_map; 182 int (*acpi_processor_get_throttling) (struct acpi_processor * pr); 183 int (*acpi_processor_set_throttling) (struct acpi_processor * pr, 184 int state, bool force); 185 186 u32 address; 187 u8 duty_offset; 188 u8 duty_width; 189 u8 tsd_valid_flag; 190 unsigned int shared_type; 191 struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING]; 192 }; 193 194 /* Limit Interface */ 195 196 struct acpi_processor_lx { 197 int px; /* performance state */ 198 int tx; /* throttle level */ 199 }; 200 201 struct acpi_processor_limit { 202 struct acpi_processor_lx state; /* current limit */ 203 struct acpi_processor_lx thermal; /* thermal limit */ 204 struct acpi_processor_lx user; /* user limit */ 205 }; 206 207 struct acpi_processor_flags { 208 u8 power:1; 209 u8 performance:1; 210 u8 throttling:1; 211 u8 limit:1; 212 u8 bm_control:1; 213 u8 bm_check:1; 214 u8 has_cst:1; 215 u8 has_lpi:1; 216 u8 power_setup_done:1; 217 u8 bm_rld_set:1; 218 u8 previously_online:1; 219 }; 220 221 struct acpi_processor { 222 acpi_handle handle; 223 u32 acpi_id; 224 phys_cpuid_t phys_id; /* CPU hardware ID such as APIC ID for x86 */ 225 u32 id; /* CPU logical ID allocated by OS */ 226 u32 pblk; 227 int performance_platform_limit; 228 int throttling_platform_limit; 229 /* 0 - states 0..n-th state available */ 230 231 struct acpi_processor_flags flags; 232 struct acpi_processor_power power; 233 struct acpi_processor_performance *performance; 234 struct acpi_processor_throttling throttling; 235 struct acpi_processor_limit limit; 236 struct thermal_cooling_device *cdev; 237 struct device *dev; /* Processor device. */ 238 struct freq_qos_request perflib_req; 239 struct freq_qos_request thermal_req; 240 }; 241 242 struct acpi_processor_errata { 243 u8 smp; 244 struct { 245 u8 throttle:1; 246 u8 fdma:1; 247 u8 reserved:6; 248 u32 bmisx; 249 } piix4; 250 }; 251 252 extern int acpi_processor_preregister_performance(struct 253 acpi_processor_performance 254 __percpu *performance); 255 256 extern int acpi_processor_register_performance(struct acpi_processor_performance 257 *performance, unsigned int cpu); 258 extern void acpi_processor_unregister_performance(unsigned int cpu); 259 260 int acpi_processor_pstate_control(void); 261 /* note: this locks both the calling module and the processor module 262 if a _PPC object exists, rmmod is disallowed then */ 263 int acpi_processor_notify_smm(struct module *calling_module); 264 int acpi_processor_get_psd(acpi_handle handle, 265 struct acpi_psd_package *pdomain); 266 267 /* parsing the _P* objects. */ 268 extern int acpi_processor_get_performance_info(struct acpi_processor *pr); 269 270 /* for communication between multiple parts of the processor kernel module */ 271 DECLARE_PER_CPU(struct acpi_processor *, processors); 272 extern struct acpi_processor_errata errata; 273 274 #if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE) 275 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags, 276 unsigned int cpu); 277 int acpi_processor_ffh_cstate_probe(unsigned int cpu, 278 struct acpi_processor_cx *cx, 279 struct acpi_power_register *reg); 280 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate); 281 void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx); 282 #else 283 static inline void acpi_processor_power_init_bm_check(struct 284 acpi_processor_flags 285 *flags, unsigned int cpu) 286 { 287 flags->bm_check = 1; 288 return; 289 } 290 static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu, 291 struct acpi_processor_cx *cx, 292 struct acpi_power_register 293 *reg) 294 { 295 return -1; 296 } 297 static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx 298 *cstate) 299 { 300 return; 301 } 302 static inline void __noreturn acpi_processor_ffh_play_dead(struct acpi_processor_cx *cx) 303 { 304 BUG(); 305 } 306 #endif 307 308 static inline int call_on_cpu(int cpu, long (*fn)(void *), void *arg, 309 bool direct) 310 { 311 if (direct || (is_percpu_thread() && cpu == smp_processor_id())) 312 return fn(arg); 313 return work_on_cpu(cpu, fn, arg); 314 } 315 316 /* in processor_perflib.c */ 317 318 #ifdef CONFIG_CPU_FREQ 319 extern bool acpi_processor_cpufreq_init; 320 void acpi_processor_ignore_ppc_init(void); 321 void acpi_processor_ppc_init(struct cpufreq_policy *policy); 322 void acpi_processor_ppc_exit(struct cpufreq_policy *policy); 323 void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag); 324 extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit); 325 #else 326 static inline void acpi_processor_ignore_ppc_init(void) 327 { 328 return; 329 } 330 static inline void acpi_processor_ppc_init(struct cpufreq_policy *policy) 331 { 332 return; 333 } 334 static inline void acpi_processor_ppc_exit(struct cpufreq_policy *policy) 335 { 336 return; 337 } 338 static inline void acpi_processor_ppc_has_changed(struct acpi_processor *pr, 339 int event_flag) 340 { 341 static unsigned int printout = 1; 342 if (printout) { 343 printk(KERN_WARNING 344 "Warning: Processor Platform Limit event detected, but not handled.\n"); 345 printk(KERN_WARNING 346 "Consider compiling CPUfreq support into your kernel.\n"); 347 printout = 0; 348 } 349 } 350 static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit) 351 { 352 return -ENODEV; 353 } 354 355 #endif /* CONFIG_CPU_FREQ */ 356 357 /* in processor_core.c */ 358 phys_cpuid_t acpi_get_phys_id(acpi_handle, int type, u32 acpi_id); 359 phys_cpuid_t acpi_map_madt_entry(u32 acpi_id); 360 int acpi_map_cpuid(phys_cpuid_t phys_id, u32 acpi_id); 361 int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id); 362 363 #ifdef CONFIG_ACPI_CPPC_LIB 364 extern int acpi_cppc_processor_probe(struct acpi_processor *pr); 365 extern void acpi_cppc_processor_exit(struct acpi_processor *pr); 366 #else 367 static inline int acpi_cppc_processor_probe(struct acpi_processor *pr) 368 { 369 return 0; 370 } 371 static inline void acpi_cppc_processor_exit(struct acpi_processor *pr) 372 { 373 return; 374 } 375 #endif /* CONFIG_ACPI_CPPC_LIB */ 376 377 /* in processor_pdc.c */ 378 void acpi_processor_set_pdc(acpi_handle handle); 379 380 /* in processor_throttling.c */ 381 #ifdef CONFIG_ACPI_CPU_FREQ_PSS 382 int acpi_processor_tstate_has_changed(struct acpi_processor *pr); 383 int acpi_processor_get_throttling_info(struct acpi_processor *pr); 384 extern int acpi_processor_set_throttling(struct acpi_processor *pr, 385 int state, bool force); 386 /* 387 * Reevaluate whether the T-state is invalid after one cpu is 388 * onlined/offlined. In such case the flags.throttling will be updated. 389 */ 390 extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, 391 bool is_dead); 392 extern const struct file_operations acpi_processor_throttling_fops; 393 extern void acpi_processor_throttling_init(void); 394 #else 395 static inline int acpi_processor_tstate_has_changed(struct acpi_processor *pr) 396 { 397 return 0; 398 } 399 400 static inline int acpi_processor_get_throttling_info(struct acpi_processor *pr) 401 { 402 return -ENODEV; 403 } 404 405 static inline int acpi_processor_set_throttling(struct acpi_processor *pr, 406 int state, bool force) 407 { 408 return -ENODEV; 409 } 410 411 static inline void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, 412 bool is_dead) {} 413 414 static inline void acpi_processor_throttling_init(void) {} 415 #endif /* CONFIG_ACPI_CPU_FREQ_PSS */ 416 417 /* in processor_idle.c */ 418 #ifdef CONFIG_ACPI_PROCESSOR_IDLE 419 void acpi_processor_power_init(struct acpi_processor *pr); 420 void acpi_processor_power_exit(struct acpi_processor *pr); 421 int acpi_processor_power_state_has_changed(struct acpi_processor *pr); 422 int acpi_processor_hotplug(struct acpi_processor *pr); 423 void acpi_processor_register_idle_driver(void); 424 void acpi_processor_unregister_idle_driver(void); 425 int acpi_processor_ffh_lpi_probe(unsigned int cpu); 426 int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi); 427 #endif /* CONFIG_ACPI_PROCESSOR_IDLE */ 428 429 /* in processor_thermal.c */ 430 int acpi_processor_thermal_init(struct acpi_processor *pr, 431 struct acpi_device *device); 432 void acpi_processor_thermal_exit(struct acpi_processor *pr, 433 struct acpi_device *device); 434 extern const struct thermal_cooling_device_ops processor_cooling_ops; 435 #ifdef CONFIG_CPU_FREQ 436 void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy); 437 void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy); 438 #else 439 static inline void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy) 440 { 441 return; 442 } 443 static inline void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy) 444 { 445 return; 446 } 447 #endif /* CONFIG_CPU_FREQ */ 448 449 void acpi_processor_init_invariance_cppc(void); 450 451 #endif 452