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