Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __ACPI_PROCESSOR_H
0003 #define __ACPI_PROCESSOR_H
0004 
0005 #include <linux/cpu.h>
0006 #include <linux/cpufreq.h>
0007 #include <linux/pm_qos.h>
0008 #include <linux/printk.h>
0009 #include <linux/sched.h>
0010 #include <linux/smp.h>
0011 #include <linux/thermal.h>
0012 #include <linux/types.h>
0013 #include <linux/workqueue.h>
0014 
0015 #include <asm/acpi.h>
0016 
0017 #define ACPI_PROCESSOR_CLASS        "processor"
0018 #define ACPI_PROCESSOR_DEVICE_NAME  "Processor"
0019 #define ACPI_PROCESSOR_DEVICE_HID   "ACPI0007"
0020 #define ACPI_PROCESSOR_CONTAINER_HID    "ACPI0010"
0021 
0022 #define ACPI_PROCESSOR_BUSY_METRIC  10
0023 
0024 #define ACPI_PROCESSOR_MAX_POWER    8
0025 #define ACPI_PROCESSOR_MAX_C2_LATENCY   100
0026 #define ACPI_PROCESSOR_MAX_C3_LATENCY   1000
0027 
0028 #define ACPI_PROCESSOR_MAX_THROTTLING   16
0029 #define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */
0030 #define ACPI_PROCESSOR_MAX_DUTY_WIDTH   4
0031 
0032 #define ACPI_PDC_REVISION_ID        0x1
0033 
0034 #define ACPI_PSD_REV0_REVISION      0   /* Support for _PSD as in ACPI 3.0 */
0035 #define ACPI_PSD_REV0_ENTRIES       5
0036 
0037 #define ACPI_TSD_REV0_REVISION      0   /* Support for _PSD as in ACPI 3.0 */
0038 #define ACPI_TSD_REV0_ENTRIES       5
0039 /*
0040  * Types of coordination defined in ACPI 3.0. Same macros can be used across
0041  * P, C and T states
0042  */
0043 #define DOMAIN_COORD_TYPE_SW_ALL    0xfc
0044 #define DOMAIN_COORD_TYPE_SW_ANY    0xfd
0045 #define DOMAIN_COORD_TYPE_HW_ALL    0xfe
0046 
0047 #define ACPI_CSTATE_SYSTEMIO    0
0048 #define ACPI_CSTATE_FFH     1
0049 #define ACPI_CSTATE_HALT    2
0050 #define ACPI_CSTATE_INTEGER 3
0051 
0052 #define ACPI_CX_DESC_LEN    32
0053 
0054 /* Power Management */
0055 
0056 struct acpi_processor_cx;
0057 
0058 struct acpi_power_register {
0059     u8 descriptor;
0060     u16 length;
0061     u8 space_id;
0062     u8 bit_width;
0063     u8 bit_offset;
0064     u8 access_size;
0065     u64 address;
0066 } __packed;
0067 
0068 struct acpi_processor_cx {
0069     u8 valid;
0070     u8 type;
0071     u32 address;
0072     u8 entry_method;
0073     u8 index;
0074     u32 latency;
0075     u8 bm_sts_skip;
0076     char desc[ACPI_CX_DESC_LEN];
0077 };
0078 
0079 struct acpi_lpi_state {
0080     u32 min_residency;
0081     u32 wake_latency; /* worst case */
0082     u32 flags;
0083     u32 arch_flags;
0084     u32 res_cnt_freq;
0085     u32 enable_parent_state;
0086     u64 address;
0087     u8 index;
0088     u8 entry_method;
0089     char desc[ACPI_CX_DESC_LEN];
0090 };
0091 
0092 struct acpi_processor_power {
0093     int count;
0094     union {
0095         struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
0096         struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER];
0097     };
0098     int timer_broadcast_on_state;
0099 };
0100 
0101 /* Performance Management */
0102 
0103 struct acpi_psd_package {
0104     u64 num_entries;
0105     u64 revision;
0106     u64 domain;
0107     u64 coord_type;
0108     u64 num_processors;
0109 } __packed;
0110 
0111 struct acpi_pct_register {
0112     u8 descriptor;
0113     u16 length;
0114     u8 space_id;
0115     u8 bit_width;
0116     u8 bit_offset;
0117     u8 reserved;
0118     u64 address;
0119 } __packed;
0120 
0121 struct acpi_processor_px {
0122     u64 core_frequency; /* megahertz */
0123     u64 power;  /* milliWatts */
0124     u64 transition_latency; /* microseconds */
0125     u64 bus_master_latency; /* microseconds */
0126     u64 control;    /* control value */
0127     u64 status; /* success indicator */
0128 };
0129 
0130 struct acpi_processor_performance {
0131     unsigned int state;
0132     unsigned int platform_limit;
0133     struct acpi_pct_register control_register;
0134     struct acpi_pct_register status_register;
0135     unsigned int state_count;
0136     struct acpi_processor_px *states;
0137     struct acpi_psd_package domain_info;
0138     cpumask_var_t shared_cpu_map;
0139     unsigned int shared_type;
0140 };
0141 
0142 /* Throttling Control */
0143 
0144 struct acpi_tsd_package {
0145     u64 num_entries;
0146     u64 revision;
0147     u64 domain;
0148     u64 coord_type;
0149     u64 num_processors;
0150 } __packed;
0151 
0152 struct acpi_ptc_register {
0153     u8 descriptor;
0154     u16 length;
0155     u8 space_id;
0156     u8 bit_width;
0157     u8 bit_offset;
0158     u8 reserved;
0159     u64 address;
0160 } __packed;
0161 
0162 struct acpi_processor_tx_tss {
0163     u64 freqpercentage; /* */
0164     u64 power;  /* milliWatts */
0165     u64 transition_latency; /* microseconds */
0166     u64 control;    /* control value */
0167     u64 status; /* success indicator */
0168 };
0169 struct acpi_processor_tx {
0170     u16 power;
0171     u16 performance;
0172 };
0173 
0174 struct acpi_processor;
0175 struct acpi_processor_throttling {
0176     unsigned int state;
0177     unsigned int platform_limit;
0178     struct acpi_pct_register control_register;
0179     struct acpi_pct_register status_register;
0180     unsigned int state_count;
0181     struct acpi_processor_tx_tss *states_tss;
0182     struct acpi_tsd_package domain_info;
0183     cpumask_var_t shared_cpu_map;
0184     int (*acpi_processor_get_throttling) (struct acpi_processor * pr);
0185     int (*acpi_processor_set_throttling) (struct acpi_processor * pr,
0186                           int state, bool force);
0187 
0188     u32 address;
0189     u8 duty_offset;
0190     u8 duty_width;
0191     u8 tsd_valid_flag;
0192     unsigned int shared_type;
0193     struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
0194 };
0195 
0196 /* Limit Interface */
0197 
0198 struct acpi_processor_lx {
0199     int px;         /* performance state */
0200     int tx;         /* throttle level */
0201 };
0202 
0203 struct acpi_processor_limit {
0204     struct acpi_processor_lx state; /* current limit */
0205     struct acpi_processor_lx thermal;   /* thermal limit */
0206     struct acpi_processor_lx user;  /* user limit */
0207 };
0208 
0209 struct acpi_processor_flags {
0210     u8 power:1;
0211     u8 performance:1;
0212     u8 throttling:1;
0213     u8 limit:1;
0214     u8 bm_control:1;
0215     u8 bm_check:1;
0216     u8 has_cst:1;
0217     u8 has_lpi:1;
0218     u8 power_setup_done:1;
0219     u8 bm_rld_set:1;
0220     u8 need_hotplug_init:1;
0221 };
0222 
0223 struct acpi_processor {
0224     acpi_handle handle;
0225     u32 acpi_id;
0226     phys_cpuid_t phys_id;   /* CPU hardware ID such as APIC ID for x86 */
0227     u32 id;     /* CPU logical ID allocated by OS */
0228     u32 pblk;
0229     int performance_platform_limit;
0230     int throttling_platform_limit;
0231     /* 0 - states 0..n-th state available */
0232 
0233     struct acpi_processor_flags flags;
0234     struct acpi_processor_power power;
0235     struct acpi_processor_performance *performance;
0236     struct acpi_processor_throttling throttling;
0237     struct acpi_processor_limit limit;
0238     struct thermal_cooling_device *cdev;
0239     struct device *dev; /* Processor device. */
0240     struct freq_qos_request perflib_req;
0241     struct freq_qos_request thermal_req;
0242 };
0243 
0244 struct acpi_processor_errata {
0245     u8 smp;
0246     struct {
0247         u8 throttle:1;
0248         u8 fdma:1;
0249         u8 reserved:6;
0250         u32 bmisx;
0251     } piix4;
0252 };
0253 
0254 extern int acpi_processor_preregister_performance(struct
0255                           acpi_processor_performance
0256                           __percpu *performance);
0257 
0258 extern int acpi_processor_register_performance(struct acpi_processor_performance
0259                            *performance, unsigned int cpu);
0260 extern void acpi_processor_unregister_performance(unsigned int cpu);
0261 
0262 int acpi_processor_pstate_control(void);
0263 /* note: this locks both the calling module and the processor module
0264          if a _PPC object exists, rmmod is disallowed then */
0265 int acpi_processor_notify_smm(struct module *calling_module);
0266 int acpi_processor_get_psd(acpi_handle handle,
0267                struct acpi_psd_package *pdomain);
0268 
0269 /* parsing the _P* objects. */
0270 extern int acpi_processor_get_performance_info(struct acpi_processor *pr);
0271 
0272 /* for communication between multiple parts of the processor kernel module */
0273 DECLARE_PER_CPU(struct acpi_processor *, processors);
0274 extern struct acpi_processor_errata errata;
0275 
0276 #if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE)
0277 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
0278                     unsigned int cpu);
0279 int acpi_processor_ffh_cstate_probe(unsigned int cpu,
0280                     struct acpi_processor_cx *cx,
0281                     struct acpi_power_register *reg);
0282 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
0283 #else
0284 static inline void acpi_processor_power_init_bm_check(struct
0285                               acpi_processor_flags
0286                               *flags, unsigned int cpu)
0287 {
0288     flags->bm_check = 1;
0289     return;
0290 }
0291 static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu,
0292                           struct acpi_processor_cx *cx,
0293                           struct acpi_power_register
0294                           *reg)
0295 {
0296     return -1;
0297 }
0298 static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
0299                            *cstate)
0300 {
0301     return;
0302 }
0303 #endif
0304 
0305 static inline int call_on_cpu(int cpu, long (*fn)(void *), void *arg,
0306                   bool direct)
0307 {
0308     if (direct || (is_percpu_thread() && cpu == smp_processor_id()))
0309         return fn(arg);
0310     return work_on_cpu(cpu, fn, arg);
0311 }
0312 
0313 /* in processor_perflib.c */
0314 
0315 #ifdef CONFIG_CPU_FREQ
0316 extern bool acpi_processor_cpufreq_init;
0317 void acpi_processor_ignore_ppc_init(void);
0318 void acpi_processor_ppc_init(struct cpufreq_policy *policy);
0319 void acpi_processor_ppc_exit(struct cpufreq_policy *policy);
0320 void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag);
0321 extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit);
0322 #else
0323 static inline void acpi_processor_ignore_ppc_init(void)
0324 {
0325     return;
0326 }
0327 static inline void acpi_processor_ppc_init(struct cpufreq_policy *policy)
0328 {
0329     return;
0330 }
0331 static inline void acpi_processor_ppc_exit(struct cpufreq_policy *policy)
0332 {
0333     return;
0334 }
0335 static inline void acpi_processor_ppc_has_changed(struct acpi_processor *pr,
0336                                 int event_flag)
0337 {
0338     static unsigned int printout = 1;
0339     if (printout) {
0340         printk(KERN_WARNING
0341                "Warning: Processor Platform Limit event detected, but not handled.\n");
0342         printk(KERN_WARNING
0343                "Consider compiling CPUfreq support into your kernel.\n");
0344         printout = 0;
0345     }
0346 }
0347 static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
0348 {
0349     return -ENODEV;
0350 }
0351 
0352 #endif              /* CONFIG_CPU_FREQ */
0353 
0354 /* in processor_core.c */
0355 phys_cpuid_t acpi_get_phys_id(acpi_handle, int type, u32 acpi_id);
0356 phys_cpuid_t acpi_map_madt_entry(u32 acpi_id);
0357 int acpi_map_cpuid(phys_cpuid_t phys_id, u32 acpi_id);
0358 int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);
0359 
0360 #ifdef CONFIG_ACPI_CPPC_LIB
0361 extern int acpi_cppc_processor_probe(struct acpi_processor *pr);
0362 extern void acpi_cppc_processor_exit(struct acpi_processor *pr);
0363 #else
0364 static inline int acpi_cppc_processor_probe(struct acpi_processor *pr)
0365 {
0366     return 0;
0367 }
0368 static inline void acpi_cppc_processor_exit(struct acpi_processor *pr)
0369 {
0370     return;
0371 }
0372 #endif  /* CONFIG_ACPI_CPPC_LIB */
0373 
0374 /* in processor_pdc.c */
0375 void acpi_processor_set_pdc(acpi_handle handle);
0376 
0377 /* in processor_throttling.c */
0378 #ifdef CONFIG_ACPI_CPU_FREQ_PSS
0379 int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
0380 int acpi_processor_get_throttling_info(struct acpi_processor *pr);
0381 extern int acpi_processor_set_throttling(struct acpi_processor *pr,
0382                      int state, bool force);
0383 /*
0384  * Reevaluate whether the T-state is invalid after one cpu is
0385  * onlined/offlined. In such case the flags.throttling will be updated.
0386  */
0387 extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
0388             bool is_dead);
0389 extern const struct file_operations acpi_processor_throttling_fops;
0390 extern void acpi_processor_throttling_init(void);
0391 #else
0392 static inline int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
0393 {
0394     return 0;
0395 }
0396 
0397 static inline int acpi_processor_get_throttling_info(struct acpi_processor *pr)
0398 {
0399     return -ENODEV;
0400 }
0401 
0402 static inline int acpi_processor_set_throttling(struct acpi_processor *pr,
0403                      int state, bool force)
0404 {
0405     return -ENODEV;
0406 }
0407 
0408 static inline void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
0409             bool is_dead) {}
0410 
0411 static inline void acpi_processor_throttling_init(void) {}
0412 #endif  /* CONFIG_ACPI_CPU_FREQ_PSS */
0413 
0414 /* in processor_idle.c */
0415 extern struct cpuidle_driver acpi_idle_driver;
0416 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
0417 int acpi_processor_power_init(struct acpi_processor *pr);
0418 int acpi_processor_power_exit(struct acpi_processor *pr);
0419 int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
0420 int acpi_processor_hotplug(struct acpi_processor *pr);
0421 #else
0422 static inline int acpi_processor_power_init(struct acpi_processor *pr)
0423 {
0424     return -ENODEV;
0425 }
0426 
0427 static inline int acpi_processor_power_exit(struct acpi_processor *pr)
0428 {
0429     return -ENODEV;
0430 }
0431 
0432 static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
0433 {
0434     return -ENODEV;
0435 }
0436 
0437 static inline int acpi_processor_hotplug(struct acpi_processor *pr)
0438 {
0439     return -ENODEV;
0440 }
0441 #endif /* CONFIG_ACPI_PROCESSOR_IDLE */
0442 
0443 /* in processor_thermal.c */
0444 int acpi_processor_thermal_init(struct acpi_processor *pr,
0445                 struct acpi_device *device);
0446 void acpi_processor_thermal_exit(struct acpi_processor *pr,
0447                  struct acpi_device *device);
0448 extern const struct thermal_cooling_device_ops processor_cooling_ops;
0449 #ifdef CONFIG_CPU_FREQ
0450 void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy);
0451 void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy);
0452 #else
0453 static inline void acpi_thermal_cpufreq_init(struct cpufreq_policy *policy)
0454 {
0455     return;
0456 }
0457 static inline void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy)
0458 {
0459     return;
0460 }
0461 #endif  /* CONFIG_CPU_FREQ */
0462 
0463 #endif