1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2022 Advanced Micro Devices, Inc. 4 * 5 * Author: Meng Li <li.meng@amd.com> 6 */ 7 8 #ifndef _LINUX_AMD_PSTATE_H 9 #define _LINUX_AMD_PSTATE_H 10 11 #include <linux/pm_qos.h> 12 13 /********************************************************************* 14 * AMD P-state INTERFACE * 15 *********************************************************************/ 16 /** 17 * struct amd_aperf_mperf 18 * @aperf: actual performance frequency clock count 19 * @mperf: maximum performance frequency clock count 20 * @tsc: time stamp counter 21 */ 22 struct amd_aperf_mperf { 23 u64 aperf; 24 u64 mperf; 25 u64 tsc; 26 }; 27 28 /** 29 * struct amd_cpudata - private CPU data for AMD P-State 30 * @cpu: CPU number 31 * @req: constraint request to apply 32 * @cppc_req_cached: cached performance request hints 33 * @highest_perf: the maximum performance an individual processor may reach, 34 * assuming ideal conditions 35 * For platforms that do not support the preferred core feature, the 36 * highest_pef may be configured with 166 or 255, to avoid max frequency 37 * calculated wrongly. we take the fixed value as the highest_perf. 38 * @nominal_perf: the maximum sustained performance level of the processor, 39 * assuming ideal operating conditions 40 * @lowest_nonlinear_perf: the lowest performance level at which nonlinear power 41 * savings are achieved 42 * @lowest_perf: the absolute lowest performance level of the processor 43 * @prefcore_ranking: the preferred core ranking, the higher value indicates a higher 44 * priority. 45 * @min_limit_perf: Cached value of the performance corresponding to policy->min 46 * @max_limit_perf: Cached value of the performance corresponding to policy->max 47 * @min_limit_freq: Cached value of policy->min (in khz) 48 * @max_limit_freq: Cached value of policy->max (in khz) 49 * @max_freq: the frequency (in khz) that mapped to highest_perf 50 * @min_freq: the frequency (in khz) that mapped to lowest_perf 51 * @nominal_freq: the frequency (in khz) that mapped to nominal_perf 52 * @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf 53 * @cur: Difference of Aperf/Mperf/tsc count between last and current sample 54 * @prev: Last Aperf/Mperf/tsc count value read from register 55 * @freq: current cpu frequency value (in khz) 56 * @boost_supported: check whether the Processor or SBIOS supports boost mode 57 * @hw_prefcore: check whether HW supports preferred core featue. 58 * Only when hw_prefcore and early prefcore param are true, 59 * AMD P-State driver supports preferred core featue. 60 * @epp_policy: Last saved policy used to set energy-performance preference 61 * @epp_cached: Cached CPPC energy-performance preference value 62 * @policy: Cpufreq policy value 63 * @cppc_cap1_cached Cached MSR_AMD_CPPC_CAP1 register value 64 * 65 * The amd_cpudata is key private data for each CPU thread in AMD P-State, and 66 * represents all the attributes and goals that AMD P-State requests at runtime. 67 */ 68 struct amd_cpudata { 69 int cpu; 70 71 struct freq_qos_request req[2]; 72 u64 cppc_req_cached; 73 74 u32 highest_perf; 75 u32 nominal_perf; 76 u32 lowest_nonlinear_perf; 77 u32 lowest_perf; 78 u32 prefcore_ranking; 79 u32 min_limit_perf; 80 u32 max_limit_perf; 81 u32 min_limit_freq; 82 u32 max_limit_freq; 83 84 u32 max_freq; 85 u32 min_freq; 86 u32 nominal_freq; 87 u32 lowest_nonlinear_freq; 88 89 struct amd_aperf_mperf cur; 90 struct amd_aperf_mperf prev; 91 92 u64 freq; 93 bool boost_supported; 94 bool hw_prefcore; 95 96 /* EPP feature related attributes*/ 97 s16 epp_policy; 98 s16 epp_cached; 99 u32 policy; 100 u64 cppc_cap1_cached; 101 bool suspended; 102 s16 epp_default; 103 bool boost_state; 104 }; 105 106 /* 107 * enum amd_pstate_mode - driver working mode of amd pstate 108 */ 109 enum amd_pstate_mode { 110 AMD_PSTATE_UNDEFINED = 0, 111 AMD_PSTATE_DISABLE, 112 AMD_PSTATE_PASSIVE, 113 AMD_PSTATE_ACTIVE, 114 AMD_PSTATE_GUIDED, 115 AMD_PSTATE_MAX, 116 }; 117 const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode); 118 int amd_pstate_update_status(const char *buf, size_t size); 119 120 #endif /* _LINUX_AMD_PSTATE_H */ 121