xref: /dpdk/drivers/power/amd_pstate/amd_pstate_cpufreq.h (revision 6f987b594fa6751b49769755fe1d1bf9f9d15ac4)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2021 Intel Corporation
3  * Copyright(c) 2021 Arm Limited
4  * Copyright(c) 2024 Advanced Micro Devices, Inc.
5  */
6 
7 #ifndef AMD_PSTATE_CPUFREQ_H
8 #define AMD_PSTATE_CPUFREQ_H
9 
10 /**
11  * @file
12  * Power Management via userspace AMD pstate cpufreq
13  */
14 
15 #include "power_cpufreq.h"
16 
17 /**
18  * Check if amd p-state power management is supported.
19  *
20  * @return
21  *   - 1 if supported
22  *   - 0 if unsupported
23  *   - -1 if error, with rte_errno indicating reason for error.
24  */
25 int power_amd_pstate_cpufreq_check_supported(void);
26 
27 /**
28  * Initialize power management for a specific lcore. It will check and set the
29  * governor to userspace for the lcore, get the available frequencies, and
30  * prepare to set new lcore frequency.
31  *
32  * @param lcore_id
33  *  lcore id.
34  *
35  * @return
36  *  - 0 on success.
37  *  - Negative on error.
38  */
39 int power_amd_pstate_cpufreq_init(unsigned int lcore_id);
40 
41 /**
42  * Exit power management on a specific lcore. It will set the governor to which
43  * is before initialized.
44  *
45  * @param lcore_id
46  *  lcore id.
47  *
48  * @return
49  *  - 0 on success.
50  *  - Negative on error.
51  */
52 int power_amd_pstate_cpufreq_exit(unsigned int lcore_id);
53 
54 /**
55  * Get the available frequencies of a specific lcore. The return value will be
56  * the minimal one of the total number of available frequencies and the number
57  * of buffer. The index of available frequencies used in other interfaces
58  * should be in the range of 0 to this return value.
59  * It should be protected outside of this function for threadsafe.
60  *
61  * @param lcore_id
62  *  lcore id.
63  * @param freqs
64  *  The buffer array to save the frequencies.
65  * @param num
66  *  The number of frequencies to get.
67  *
68  * @return
69  *  The number of available frequencies.
70  */
71 uint32_t power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs,
72 		uint32_t num);
73 
74 /**
75  * Return the current index of available frequencies of a specific lcore. It
76  * will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)' if error.
77  * It should be protected outside of this function for threadsafe.
78  *
79  * @param lcore_id
80  *  lcore id.
81  *
82  * @return
83  *  The current index of available frequencies.
84  */
85 uint32_t power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id);
86 
87 /**
88  * Set the new frequency for a specific lcore by indicating the index of
89  * available frequencies.
90  * It should be protected outside of this function for threadsafe.
91  *
92  * @param lcore_id
93  *  lcore id.
94  * @param index
95  *  The index of available frequencies.
96  *
97  * @return
98  *  - 1 on success with frequency changed.
99  *  - 0 on success without frequency changed.
100  *  - Negative on error.
101  */
102 int power_amd_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index);
103 
104 /**
105  * Scale up the frequency of a specific lcore according to the available
106  * frequencies.
107  * It should be protected outside of this function for threadsafe.
108  *
109  * @param lcore_id
110  *  lcore id.
111  *
112  * @return
113  *  - 1 on success with frequency changed.
114  *  - 0 on success without frequency changed.
115  *  - Negative on error.
116  */
117 int power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id);
118 
119 /**
120  * Scale down the frequency of a specific lcore according to the available
121  * frequencies.
122  * It should be protected outside of this function for threadsafe.
123  *
124  * @param lcore_id
125  *  lcore id.
126  *
127  * @return
128  *  - 1 on success with frequency changed.
129  *  - 0 on success without frequency changed.
130  *  - Negative on error.
131  */
132 int power_amd_pstate_cpufreq_freq_down(unsigned int lcore_id);
133 
134 /**
135  * Scale up the frequency of a specific lcore to the highest according to the
136  * available frequencies.
137  * It should be protected outside of this function for threadsafe.
138  *
139  * @param lcore_id
140  *  lcore id.
141  *
142  * @return
143  *  - 1 on success with frequency changed.
144  *  - 0 on success without frequency changed.
145  *  - Negative on error.
146  */
147 int power_amd_pstate_cpufreq_freq_max(unsigned int lcore_id);
148 
149 /**
150  * Scale down the frequency of a specific lcore to the lowest according to the
151  * available frequencies.
152  * It should be protected outside of this function for threadsafe.
153  *
154  * @param lcore_id
155  *  lcore id.
156  *
157  * @return
158  *  - 1 on success with frequency changed.
159  *  - 0 on success without frequency changed.
160  *  - Negative on error.
161  */
162 int power_amd_pstate_cpufreq_freq_min(unsigned int lcore_id);
163 
164 /**
165  * Get the turbo status of a specific lcore.
166  * It should be protected outside of this function for threadsafe.
167  *
168  * @param lcore_id
169  *  lcore id.
170  *
171  * @return
172  *  - 1 Turbo Boost is enabled on this lcore.
173  *  - 0 Turbo Boost is disabled on this lcore.
174  *  - Negative on error.
175  */
176 int power_amd_pstate_turbo_status(unsigned int lcore_id);
177 
178 /**
179  * Enable Turbo Boost on a specific lcore.
180  * It should be protected outside of this function for threadsafe.
181  *
182  * @param lcore_id
183  *  lcore id.
184  *
185  * @return
186  *  - 0 Turbo Boost is enabled successfully on this lcore.
187  *  - Negative on error.
188  */
189 int power_amd_pstate_enable_turbo(unsigned int lcore_id);
190 
191 /**
192  * Disable Turbo Boost on a specific lcore.
193  * It should be protected outside of this function for threadsafe.
194  *
195  * @param lcore_id
196  *  lcore id.
197  *
198  * @return
199  *  - 0 Turbo Boost disabled successfully on this lcore.
200  *  - Negative on error.
201  */
202 int power_amd_pstate_disable_turbo(unsigned int lcore_id);
203 
204 /**
205  * Returns power capabilities for a specific lcore.
206  *
207  * @param lcore_id
208  *  lcore id.
209  * @param caps
210  *  pointer to rte_power_core_capabilities object.
211  *
212  * @return
213  *  - 0 on success.
214  *  - Negative on error.
215  */
216 int power_amd_pstate_get_capabilities(unsigned int lcore_id,
217 		struct rte_power_core_capabilities *caps);
218 
219 #endif /* AMD_PSTATE_CPUFREQ_H */
220