Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI: CPPC: Do not use CPUFREQ_ETERNAL as an error value

Instead of using CPUFREQ_ETERNAL for signaling an error condition
in cppc_get_transition_latency(), change the return value type of
that function to int and make it return a proper negative error
code on failures.

No intentional functional impact.

Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Reviewed-by: Jie Zhan <zhanjie9@hisilicon.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Qais Yousef <qyousef@layalina.io>

+16 -18
+7 -9
drivers/acpi/cppc_acpi.c
··· 1876 1876 * If desired_reg is in the SystemMemory or SystemIo ACPI address space, 1877 1877 * then assume there is no latency. 1878 1878 */ 1879 - unsigned int cppc_get_transition_latency(int cpu_num) 1879 + int cppc_get_transition_latency(int cpu_num) 1880 1880 { 1881 1881 /* 1882 1882 * Expected transition latency is based on the PCCT timing values ··· 1889 1889 * completion of a command before issuing the next command, 1890 1890 * in microseconds. 1891 1891 */ 1892 - unsigned int latency_ns = 0; 1893 1892 struct cpc_desc *cpc_desc; 1894 1893 struct cpc_register_resource *desired_reg; 1895 1894 int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu_num); 1896 1895 struct cppc_pcc_data *pcc_ss_data; 1896 + int latency_ns = 0; 1897 1897 1898 1898 cpc_desc = per_cpu(cpc_desc_ptr, cpu_num); 1899 1899 if (!cpc_desc) 1900 - return CPUFREQ_ETERNAL; 1900 + return -ENODATA; 1901 1901 1902 1902 desired_reg = &cpc_desc->cpc_regs[DESIRED_PERF]; 1903 1903 if (CPC_IN_SYSTEM_MEMORY(desired_reg) || CPC_IN_SYSTEM_IO(desired_reg)) 1904 1904 return 0; 1905 - else if (!CPC_IN_PCC(desired_reg)) 1906 - return CPUFREQ_ETERNAL; 1907 1905 1908 - if (pcc_ss_id < 0) 1909 - return CPUFREQ_ETERNAL; 1906 + if (!CPC_IN_PCC(desired_reg) || pcc_ss_id < 0) 1907 + return -ENODATA; 1910 1908 1911 1909 pcc_ss_data = pcc_data[pcc_ss_id]; 1912 1910 if (pcc_ss_data->pcc_mpar) 1913 1911 latency_ns = 60 * (1000 * 1000 * 1000 / pcc_ss_data->pcc_mpar); 1914 1912 1915 - latency_ns = max(latency_ns, pcc_ss_data->pcc_nominal * 1000); 1916 - latency_ns = max(latency_ns, pcc_ss_data->pcc_mrtt * 1000); 1913 + latency_ns = max_t(int, latency_ns, pcc_ss_data->pcc_nominal * 1000); 1914 + latency_ns = max_t(int, latency_ns, pcc_ss_data->pcc_mrtt * 1000); 1917 1915 1918 1916 return latency_ns; 1919 1917 }
+4 -4
drivers/cpufreq/amd-pstate.c
··· 872 872 */ 873 873 static u32 amd_pstate_get_transition_delay_us(unsigned int cpu) 874 874 { 875 - u32 transition_delay_ns; 875 + int transition_delay_ns; 876 876 877 877 transition_delay_ns = cppc_get_transition_latency(cpu); 878 - if (transition_delay_ns == CPUFREQ_ETERNAL) { 878 + if (transition_delay_ns < 0) { 879 879 if (cpu_feature_enabled(X86_FEATURE_AMD_FAST_CPPC)) 880 880 return AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY; 881 881 else ··· 891 891 */ 892 892 static u32 amd_pstate_get_transition_latency(unsigned int cpu) 893 893 { 894 - u32 transition_latency; 894 + int transition_latency; 895 895 896 896 transition_latency = cppc_get_transition_latency(cpu); 897 - if (transition_latency == CPUFREQ_ETERNAL) 897 + if (transition_latency < 0) 898 898 return AMD_PSTATE_TRANSITION_LATENCY; 899 899 900 900 return transition_latency;
+2 -2
drivers/cpufreq/cppc_cpufreq.c
··· 310 310 311 311 static unsigned int __cppc_cpufreq_get_transition_delay_us(unsigned int cpu) 312 312 { 313 - unsigned int transition_latency_ns = cppc_get_transition_latency(cpu); 313 + int transition_latency_ns = cppc_get_transition_latency(cpu); 314 314 315 - if (transition_latency_ns == CPUFREQ_ETERNAL) 315 + if (transition_latency_ns < 0) 316 316 return CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS / NSEC_PER_USEC; 317 317 318 318 return transition_latency_ns / NSEC_PER_USEC;
+3 -3
include/acpi/cppc_acpi.h
··· 160 160 extern bool acpi_cpc_valid(void); 161 161 extern bool cppc_allow_fast_switch(void); 162 162 extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data); 163 - extern unsigned int cppc_get_transition_latency(int cpu); 163 + extern int cppc_get_transition_latency(int cpu); 164 164 extern bool cpc_ffh_supported(void); 165 165 extern bool cpc_supported_by_cpu(void); 166 166 extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val); ··· 216 216 { 217 217 return false; 218 218 } 219 - static inline unsigned int cppc_get_transition_latency(int cpu) 219 + static inline int cppc_get_transition_latency(int cpu) 220 220 { 221 - return CPUFREQ_ETERNAL; 221 + return -ENODATA; 222 222 } 223 223 static inline bool cpc_ffh_supported(void) 224 224 {